Snapshot of NetBSD's (x)lint. Little functionality, just some code

tidy-ups.
This commit is contained in:
Mark Murray 2002-07-19 15:19:23 +00:00
parent fdd1668006
commit e07f5fa8bb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/JPO/; revision=100360
7 changed files with 53 additions and 46 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lint.h,v 1.3 2002/01/31 22:44:00 tv Exp $ */ /* $NetBSD: lint.h,v 1.5 2002/03/07 18:29:56 tv Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl

View File

@ -1,4 +1,4 @@
/* $NetBSD: param.h,v 1.1 2002/01/18 20:39:24 thorpej Exp $ */ /* $NetBSD: param.h,v 1.2 2002/02/05 03:04:26 thorpej Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -67,11 +67,9 @@
#define WCHAR INT #define WCHAR INT
/* /*
* long double only in ANSI C.
*
* And the sparc64 long double code generation is broken. * And the sparc64 long double code generation is broken.
*/ */
#if !defined(__sparc64__) && defined(__STDC__) #if !defined(__sparc64__)
typedef long double ldbl_t; typedef long double ldbl_t;
#else #else
typedef double ldbl_t; typedef double ldbl_t;
@ -80,9 +78,4 @@ typedef double ldbl_t;
/* /*
* Some traditional compilers are not able to assign structures. * Some traditional compilers are not able to assign structures.
*/ */
#ifdef __STDC__
#define STRUCT_ASSIGN(dest, src) (dest) = (src) #define STRUCT_ASSIGN(dest, src) (dest) = (src)
#else
#define STRUCT_ASSIGN(dest, src) (void)memcpy(&(dest), &(src), \
sizeof (dest));
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $ */ /* $NetBSD: err.c,v 1.17 2002/01/31 19:36:54 tv Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -33,7 +33,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $"); __RCSID("$NetBSD: err.c,v 1.17 2002/01/31 19:36:54 tv Exp $");
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -49,7 +49,7 @@ int nerr;
int sytxerr; int sytxerr;
static const char *basename(const char *); static const char *lbasename(const char *);
static void verror(int, va_list); static void verror(int, va_list);
static void vwarning(int, va_list); static void vwarning(int, va_list);
@ -383,11 +383,11 @@ msglist(void)
} }
/* /*
* If Fflag is not set basename() returns a pointer to the last * If Fflag is not set lbasename() returns a pointer to the last
* component of the path, otherwise it returns the argument. * component of the path, otherwise it returns the argument.
*/ */
static const char * static const char *
basename(const char *path) lbasename(const char *path)
{ {
const char *cp, *cp1, *cp2; const char *cp, *cp1, *cp2;
@ -412,7 +412,7 @@ verror( int n, va_list ap)
if (ERR_ISSET(n, &msgset)) if (ERR_ISSET(n, &msgset))
return; return;
fn = basename(curr_pos.p_file); fn = lbasename(curr_pos.p_file);
(void)printf("%s(%d): ", fn, curr_pos.p_line); (void)printf("%s(%d): ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap); (void)vprintf(msgs[n], ap);
(void)printf(" [%d]\n", n); (void)printf(" [%d]\n", n);
@ -431,7 +431,7 @@ vwarning( int n, va_list ap)
/* this warning is suppressed by a LINTED comment */ /* this warning is suppressed by a LINTED comment */
return; return;
fn = basename(curr_pos.p_file); fn = lbasename(curr_pos.p_file);
(void)printf("%s(%d): warning: ", fn, curr_pos.p_line); (void)printf("%s(%d): warning: ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap); (void)vprintf(msgs[n], ap);
(void)printf(" [%d]\n", n); (void)printf(" [%d]\n", n);
@ -456,7 +456,7 @@ lerror(const char *msg, ...)
const char *fn; const char *fn;
va_start(ap, msg); va_start(ap, msg);
fn = basename(curr_pos.p_file); fn = lbasename(curr_pos.p_file);
(void)fprintf(stderr, "%s(%d): lint error: ", fn, curr_pos.p_line); (void)fprintf(stderr, "%s(%d): lint error: ", fn, curr_pos.p_line);
(void)vfprintf(stderr, msg, ap); (void)vfprintf(stderr, msg, ap);
(void)fprintf(stderr, "\n"); (void)fprintf(stderr, "\n");
@ -484,7 +484,7 @@ message(int n, ...)
return; return;
va_start(ap, n); va_start(ap, n);
fn = basename(curr_pos.p_file); fn = lbasename(curr_pos.p_file);
(void)printf("%s(%d): ", fn, curr_pos.p_line); (void)printf("%s(%d): ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap); (void)vprintf(msgs[n], ap);
(void)printf(" [%d]\n", n); (void)printf(" [%d]\n", n);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $ */ /* $NetBSD: mem1.c,v 1.7 2002/01/31 19:36:54 tv Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -33,7 +33,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $"); __RCSID("$NetBSD: mem1.c,v 1.7 2002/01/31 19:36:54 tv Exp $");
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -196,11 +196,18 @@ xgetblk(mbl_t **mbp, size_t s)
{ {
mbl_t *mb; mbl_t *mb;
void *p; void *p;
size_t t = 0;
s = ALIGN(s); s = ALIGN(s);
if ((mb = *mbp) == NULL || mb->nfree < s) { if ((mb = *mbp) == NULL || mb->nfree < s) {
if ((mb = frmblks) == NULL) { if ((mb = frmblks) == NULL) {
if (s > mblklen) {
t = mblklen;
mblklen = s;
}
mb = xnewblk(); mb = xnewblk();
if (t)
mblklen = t;
(void)memset(mb->blk, 0, mb->size); (void)memset(mb->blk, 0, mb->size);
} else { } else {
frmblks = mb->nxt; frmblks = mb->nxt;

View File

@ -1,13 +1,15 @@
# $NetBSD: Makefile,v 1.11 2001/10/25 02:22:56 thorpej Exp $ # $NetBSD: Makefile,v 1.12 2001/11/12 23:16:37 tv Exp $
.PATH: ${.CURDIR}/../lint1 .PATH: ${.CURDIR}/../lint1
.PATH: ${.CURDIR}/../../mkdep
PROG= xlint PROG= xlint
SRCS= xlint.c mem.c SRCS= xlint.c mem.c findcc.c
PROGNAME= lint PROGNAME= lint
MAN= lint.1 MAN= lint.1
CPPFLAGS+= -I${.CURDIR}/../lint1 CPPFLAGS+= -I${.CURDIR}/../lint1
CPPFLAGS+= -I${.CURDIR}/../../mkdep
.ifndef HOSTPROG .ifndef HOSTPROG
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
.\" $NetBSD: lint.1,v 1.20 2001/12/08 19:27:56 wiz Exp $ .\" $NetBSD: lint.1,v 1.21 2002/01/03 04:25:18 thorpej Exp $
.\" .\"
.\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. .\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
.\" Copyright (c) 1994, 1995 Jochen Pohl .\" Copyright (c) 1994, 1995 Jochen Pohl
@ -294,11 +294,11 @@ is not predefined in this mode. Warnings are printed for constructs
not allowed in traditional C. Warnings for constructs which behave not allowed in traditional C. Warnings for constructs which behave
differently in traditional C and ANSI C are suppressed. Preprocessor differently in traditional C and ANSI C are suppressed. Preprocessor
macros describing the machine type (e.g. macros describing the machine type (e.g.
.Li sun3 Ns ) .Li sun3 )
and machine architecture (e.g. and machine architecture (e.g.
.Li m68k Ns ) .Li m68k )
are defined without leading and trailing underscores. The keywords are defined without leading and trailing underscores. The keywords
.Sy const Ns , .Sy const ,
.Sy volatile .Sy volatile
and and
.Sy signed .Sy signed

View File

@ -1,4 +1,4 @@
/* $NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $ */ /* $NetBSD: xlint.c,v 1.27 2002/01/31 19:09:33 tv Exp $ */
/* /*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -34,7 +34,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $"); __RCSID("$NetBSD: xlint.c,v 1.27 2002/01/31 19:09:33 tv Exp $");
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -52,6 +52,9 @@ __RCSID("$NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $");
#include "lint.h" #include "lint.h"
#include "pathnames.h" #include "pathnames.h"
#include "findcc.h"
#define DEFAULT_PATH _PATH_DEFPATH
int main(int, char *[]); int main(int, char *[]);
@ -581,7 +584,7 @@ static void
fname(const char *name) fname(const char *name)
{ {
const char *bn, *suff; const char *bn, *suff;
char **args, *ofn, *path; char **args, *ofn, *pathname, *CC;
size_t len; size_t len;
int is_stdin; int is_stdin;
int fd; int fd;
@ -637,15 +640,17 @@ fname(const char *name)
args = xcalloc(1, sizeof (char *)); args = xcalloc(1, sizeof (char *));
/* run cc */ /* run cc */
if ((CC = getenv("CC")) == NULL)
if (getenv("CC") == NULL) { CC = DEFAULT_CC;
path = xmalloc(strlen(PATH_USRBIN) + sizeof ("/cc")); if ((pathname = findcc(CC)) == NULL)
(void)sprintf(path, "%s/cc", PATH_USRBIN); if (!setenv("PATH", DEFAULT_PATH, 1))
} else { pathname = findcc(CC);
path = strdup(getenv("CC")); if (pathname == NULL) {
(void)fprintf(stderr, "%s: %s: not found\n", getprogname(), CC);
exit(EXIT_FAILURE);
} }
appcstrg(&args, path); appcstrg(&args, pathname);
applst(&args, cflags); applst(&args, cflags);
applst(&args, lcflags); applst(&args, lcflags);
appcstrg(&args, name); appcstrg(&args, name);
@ -660,33 +665,33 @@ fname(const char *name)
terminate(-1); terminate(-1);
} }
runchild(path, args, cppout, cppoutfd); runchild(pathname, args, cppout, cppoutfd);
free(path); free(pathname);
freelst(&args); freelst(&args);
/* run lint1 */ /* run lint1 */
if (!Bflag) { if (!Bflag) {
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") + pathname = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") +
strlen(target_prefix)); strlen(target_prefix));
(void)sprintf(path, "%s/%slint1", PATH_LIBEXEC, (void)sprintf(pathname, "%s/%slint1", PATH_LIBEXEC,
target_prefix); target_prefix);
} else { } else {
/* /*
* XXX Unclear whether we should be using target_prefix * XXX Unclear whether we should be using target_prefix
* XXX here. --thorpej@wasabisystems.com * XXX here. --thorpej@wasabisystems.com
*/ */
path = xmalloc(strlen(libexec_path) + sizeof ("/lint1")); pathname = xmalloc(strlen(libexec_path) + sizeof ("/lint1"));
(void)sprintf(path, "%s/lint1", libexec_path); (void)sprintf(pathname, "%s/lint1", libexec_path);
} }
appcstrg(&args, path); appcstrg(&args, pathname);
applst(&args, l1flags); applst(&args, l1flags);
appcstrg(&args, cppout); appcstrg(&args, cppout);
appcstrg(&args, ofn); appcstrg(&args, ofn);
runchild(path, args, ofn, -1); runchild(pathname, args, ofn, -1);
free(path); free(pathname);
freelst(&args); freelst(&args);
appcstrg(&p2in, ofn); appcstrg(&p2in, ofn);