diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-12-14 03:11:43 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-12-14 03:11:43 +0000 |
commit | a3b7a686b1f0e746c512c93cd1f36367834d8f33 (patch) | |
tree | 65c8102ee063a68d9ca695bea0fa601049947e97 /usr.bin/xlint | |
parent | 780b1420c7b61e40ddfa14878c0dcc6738c12d90 (diff) |
update from netbsd
Diffstat (limited to 'usr.bin/xlint')
-rw-r--r-- | usr.bin/xlint/lint1/scan.l | 6 | ||||
-rw-r--r-- | usr.bin/xlint/xlint/lint.1 | 71 | ||||
-rw-r--r-- | usr.bin/xlint/xlint/xlint.c | 185 |
3 files changed, 167 insertions, 95 deletions
diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l index 642671201c0..5e23c6b6b4b 100644 --- a/usr.bin/xlint/lint1/scan.l +++ b/usr.bin/xlint/lint1/scan.l @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.7 1995/10/02 17:29:59 jpo Exp $ */ +/* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: scan.l,v 1.7 1995/10/02 17:29:59 jpo Exp $"; +static char rcsid[] = "$NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $"; #endif #include <stdlib.h> @@ -741,7 +741,7 @@ ccon() static int wccon() { - static char buf[MB_CUR_MAX + 1]; + static char buf[MB_LEN_MAX + 1]; int i, c; wchar_t wc; diff --git a/usr.bin/xlint/xlint/lint.1 b/usr.bin/xlint/xlint/lint.1 index a1f6589018b..99d459cb004 100644 --- a/usr.bin/xlint/xlint/lint.1 +++ b/usr.bin/xlint/xlint/lint.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: lint.1,v 1.2 1995/07/03 21:25:17 cgd Exp $ +.\" $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $ .\" .\" Copyright (c) 1994, 1995 Jochen Pohl .\" All Rights Reserved. @@ -40,7 +40,7 @@ .Op Fl abceghprvxzHFV .Op Fl s Ns | Ns Fl t .Op Fl i Ns | Ns Fl nu -.Op Fl D Ns Ar name Ns Bq =def +.Op Fl D Ns Ar name Ns Op =def .Op Fl U Ns Ar name .Op Fl I Ns Ar directory .Op Fl L Ns Ar directory @@ -51,7 +51,7 @@ .Op Fl abceghprvzHFV .Op Fl s Ns | Ns Fl t .Fl C Ns Ar library -.Op Fl D Ns Ar name Ns Bq =def +.Op Fl D Ns Ar name Ns Op =def .Op Fl I Ns Ar directory .Op Fl U Ns Ar name .Ar @@ -176,12 +176,23 @@ and combinations of and .Sy integer Ns -Types. .It Fl g -Print warnings instead of errors for some extensions of +Don't print warnings for some extensions of .Xr gcc 1 -to the C language. -Currently these are nonconstant initialzers in automatic aggregat -initialisations, arithmetic on pointer to void, zero sized -structures and subscripting of non-lvalue arrays. +to the C language. Currently these are nonconstant initializers in +automatic aggregate initializations, arithmetic on pointer to void, +zero sized structures, subscripting of non-lvalue arrays, prototypes +overriding old style function declarations and long long +integer types. The +.Fl g +flag also turns on the keywords +.Sy asm +and +.Sy inline +(alternate keywords with leading underscores for both +.Sy asm +and +.Sy inline +are always available). .It Fl h Apply a number of heuristic tests to attempt to intuit bugs, improve style, and reduce waste. @@ -206,17 +217,31 @@ previous declaration. .It Fl s Strict ANSI C mode. Issue warnings and errors required by ANSI C. Also do not produce warnings for constructs which behave -differently in traditional C and ANSI C. +differently in traditional C and ANSI C. With the +.Fl s +flag, +.Li __STRICT_ANSI__ +is a predefined preprocessor macro. .It Fl t Traditional C mode. .Li __STDC__ -is not predefined in this mode. Warnings are printed for -constructs not allowed in traditional C. Warnings for constructs -which behave differently in traditional C and ANSI C are -suppressed. +is not predefined in this mode. Warnings are printed for constructs +not allowed in traditional C. Warnings for constructs which behave +differently in traditional C and ANSI C are suppressed. Preprocessor +macros describing the machine type (e.g. +.Li sun3 Ns ) +and machine architecture (e.g. +.Li m68k Ns ) +are defined without leading and trailing underscores. The keywords +.Sy const Ns , +.Sy volatile +and +.Sy signed +are not available in traditional C mode (although the alternate +keywords with leading underscores still are). .It Fl u Do not complain about functions and external variables used -and not defined, or defined and not used. (this is suitable +and not defined, or defined and not used (this is suitable for running .Nm on a subset of files comprising part of a larger program). @@ -235,7 +260,7 @@ Create a .Nm library with the name .Pa llib-l Ns Ar library Ns Pa .ln . -These library is built of all +This library is built from all .Pa \&.c and .Pa \&.ln @@ -245,7 +270,7 @@ variables in these files are written to the newly created library, checks all input files, including libraries specified with the .Fl l option, for mutual compatibility. -.It Fl D Ns Ar name Ns Bq =def +.It Fl D Ns Ar name Ns Op =def Define .Ar name for @@ -273,7 +298,7 @@ Print pathnames of files. .Nm normally prints the filename without the path. .It Fl H -If an complaint stems from an included file +If a complaint stems from an included file .Nm prints the name of the included file instead of the source file name followed by a question mark. @@ -300,7 +325,7 @@ Remove any initial definition of .Ar name for the preprocessor. .It Fl V -Print the command lines constructred by the controller program to +Print the command lines constructed by the controller program to run the C preprocessor and .Nm lint Ns 's first and second pass. @@ -324,8 +349,8 @@ is taken to be 0 (this option acts like the .Fl v option for the next function). .It Li /* CONSTCOND */ No or Xo -.Li /* CONSTANDCOND */ No or -.Li /* CONSTANDCONDITION */ +.Li /* CONSTANTCOND */ No or +.Li /* CONSTANTCONDITION */ .Xc suppress complaints about constant operands for the next expression. .It Li /*\ FALLTHRU\ */ No or Xo @@ -349,9 +374,11 @@ Also shut off complaints about unused function arguments. .Op Ar comment .Li */ .Xc -suppresses any intra-file warning except those dealing with +Suppresses any intra-file warning except those dealing with unused variables or functions. This directive should be placed on the line immediately preceding where the lint warning occured. +.It Li /* LONGLONG */ +Suppress complaints about use of long long integer types. .It Li /* NOTREACHED */ At appropriate points, inhibit complaints about unreachable code. (This comment is typically placed just after calls to functions @@ -426,7 +453,7 @@ options. this will print all the inter-file inconsistencies. This scheme works well with .Xr make 1 ; it allows -.Xr make +.Xr make 1 to be used to .Nm only the source files that have been modified since the last diff --git a/usr.bin/xlint/xlint/xlint.c b/usr.bin/xlint/xlint/xlint.c index 37645ee8f62..3e577974d69 100644 --- a/usr.bin/xlint/xlint/xlint.c +++ b/usr.bin/xlint/xlint/xlint.c @@ -1,4 +1,4 @@ -/* $NetBSD: xlint.c,v 1.2 1995/07/03 21:25:23 cgd Exp $ */ +/* $NetBSD: xlint.c,v 1.3 1995/10/23 14:29:30 jpo Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -32,12 +32,13 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: xlint.c,v 1.2 1995/07/03 21:25:23 cgd Exp $"; +static char rcsid[] = "$NetBSD: xlint.c,v 1.3 1995/10/23 14:29:30 jpo Exp $"; #endif -#include <sys/types.h> +#include <sys/param.h> #include <sys/wait.h> #include <sys/stat.h> +#include <sys/utsname.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> @@ -109,12 +110,15 @@ static int first = 1; static const char *currfn; -static void appstrg __P((char ***, const char *)); -static void app2strg __P((char ***, const char *, const char *)); +static void appstrg __P((char ***, char *)); +static void appcstrg __P((char ***, const char *)); static void applst __P((char ***, char *const *)); static void freelst __P((char ***)); +static char *concat2 __P((const char *, const char *)); +static char *concat3 __P((const char *, const char *, const char *)); static void terminate __P((int)); static const char *basename __P((const char *, int)); +static void appdef __P((char ***, const char *)); static void usage __P((void)); static void fname __P((const char *, int)); static void runchild __P((const char *, char *const *, const char *)); @@ -129,8 +133,7 @@ static void cat __P((char *const *, const char *)); */ static void appstrg(lstp, s) - char ***lstp; - const char *s; + char ***lstp, *s; { char **lst, **olst; int i; @@ -139,32 +142,17 @@ appstrg(lstp, s) for (i = 0; olst[i] != NULL; i++) ; lst = xmalloc((i + 2) * sizeof (char *)); (void)memcpy(lst, olst, i * sizeof (char *)); - lst[i] = xstrdup(s); + lst[i] = s; lst[i + 1] = NULL; *lstp = lst; - free(olst); -} +} static void -app2strg(lstp, s1, s2) +appcstrg(lstp, s) char ***lstp; - const char *s1, *s2; + const char *s; { - int i; - char *s, **lst, **olst; - - s = xmalloc(strlen(s1) + strlen(s2) + 1); - (void)strcpy(s, s1); - (void)strcat(s, s2); - - olst = *lstp; - for (i = 0; olst[i] != NULL; i++) ; - lst = xmalloc((i + 2) * sizeof (char *)); - (void)memcpy(lst, olst, i * sizeof (char *)); - lst[i] = s; - lst[i + 1] = NULL; - *lstp = lst; - free(olst); + appstrg(lstp, xstrdup(s)); } static void @@ -202,6 +190,33 @@ freelst(lstp) } } +static char * +concat2(s1, s2) + const char *s1, *s2; +{ + char *s; + + s = xmalloc(strlen(s1) + strlen(s2) + 1); + (void)strcpy(s, s1); + (void)strcat(s, s2); + + return (s); +} + +static char * +concat3(s1, s2, s3) + const char *s1, *s2, *s3; +{ + char *s; + + s = xmalloc(strlen(s1) + strlen(s2) + strlen(s3) + 1); + (void)strcpy(s, s1); + (void)strcat(s, s2); + (void)strcat(s, s3); + + return (s); +} + /* * Clean up after a signal. */ @@ -250,6 +265,15 @@ basename(strg, delim) } static void +appdef(lstp, def) + char ***lstp; + const char *def; +{ + appstrg(lstp, concat2("-D__", def)); + appstrg(lstp, concat3("-D__", def, "__")); +} + +static void usage() { (void)printf("lint [-abceghprvxzHF] [-s|-t] [-i|-nu] [-Dname[=def]] [-Uname]\n"); @@ -268,6 +292,7 @@ main(argc, argv) int c; char flgbuf[3], *tmp, *s; size_t len; + struct utsname un; if ((tmp = getenv("TMPDIR")) == NULL || (len = strlen(tmp)) == 0) { tmpdir = xstrdup(_PATH_TMP); @@ -295,14 +320,31 @@ main(argc, argv) libs = xcalloc(1, sizeof (char *)); libsrchpath = xcalloc(1, sizeof (char *)); - appstrg(&cppflags, "-C"); - appstrg(&cppflags, "-Dlint"); - appstrg(&cppflags, "-U__GNUC__"); - appstrg(&cppflags, "-Wcomment"); - - appstrg(&lcppflgs, "-Wtraditional"); - - appstrg(&deflibs, "c"); + appcstrg(&cppflags, "-lang-c"); + appcstrg(&cppflags, "-undef"); + appcstrg(&cppflags, "-$"); + appcstrg(&cppflags, "-C"); + appcstrg(&cppflags, "-Wcomment"); + appcstrg(&cppflags, "-D__NetBSD__"); + appcstrg(&cppflags, "-Dlint"); /* XXX don't def. with -s */ + appdef(&cppflags, "lint"); + appdef(&cppflags, "unix"); + + appcstrg(&lcppflgs, "-Wtraditional"); + + if (uname(&un) == -1) + err(1, "uname"); + appdef(&cppflags, un.machine); + appstrg(&lcppflgs, concat2("-D", un.machine)); + +#ifdef MACHINE_ARCH + if (strcmp(un.machine, MACHINE_ARCH) != 0) { + appdef(&cppflags, MACHINE_ARCH); + appstrg(&lcppflgs, concat2("-D", MACHINE_ARCH)); + } +#endif + + appcstrg(&deflibs, "c"); if (signal(SIGHUP, terminate) == SIG_IGN) (void)signal(SIGHUP, SIG_IGN); @@ -329,7 +371,7 @@ main(argc, argv) case 'v': case 'z': (void)sprintf(flgbuf, "-%c", c); - appstrg(&l1flags, flgbuf); + appcstrg(&l1flags, flgbuf); break; case 'F': @@ -338,8 +380,8 @@ main(argc, argv) case 'u': case 'h': (void)sprintf(flgbuf, "-%c", c); - appstrg(&l1flags, flgbuf); - appstrg(&l2flags, flgbuf); + appcstrg(&l1flags, flgbuf); + appcstrg(&l2flags, flgbuf); break; case 'i': @@ -353,11 +395,11 @@ main(argc, argv) break; case 'p': - appstrg(&l1flags, "-p"); - appstrg(&l2flags, "-p"); + appcstrg(&l1flags, "-p"); + appcstrg(&l2flags, "-p"); if (*deflibs != NULL) { freelst(&deflibs); - appstrg(&deflibs, "c"); + appcstrg(&deflibs, "c"); } break; @@ -365,11 +407,12 @@ main(argc, argv) if (tflag) usage(); freelst(&lcppflgs); - appstrg(&lcppflgs, "-trigraphs"); - appstrg(&lcppflgs, "-Wtrigraphs"); - appstrg(&lcppflgs, "-pedantic"); - appstrg(&l1flags, "-s"); - appstrg(&l2flags, "-s"); + appcstrg(&lcppflgs, "-trigraphs"); + appcstrg(&lcppflgs, "-Wtrigraphs"); + appcstrg(&lcppflgs, "-pedantic"); + appcstrg(&lcppflgs, "-D__STRICT_ANSI__"); + appcstrg(&l1flags, "-s"); + appcstrg(&l2flags, "-s"); sflag = 1; break; @@ -377,21 +420,23 @@ main(argc, argv) if (sflag) usage(); freelst(&lcppflgs); - appstrg(&lcppflgs, "-traditional"); - appstrg(&l1flags, "-t"); - appstrg(&l2flags, "-t"); + appcstrg(&lcppflgs, "-traditional"); + appstrg(&lcppflgs, concat2("-D", MACHINE)); + appstrg(&lcppflgs, concat2("-D", MACHINE_ARCH)); + appcstrg(&l1flags, "-t"); + appcstrg(&l2flags, "-t"); tflag = 1; break; case 'x': - appstrg(&l2flags, "-x"); + appcstrg(&l2flags, "-x"); break; case 'C': if (Cflag || oflag || iflag) usage(); Cflag = 1; - app2strg(&l2flags, "-C", optarg); + appstrg(&l2flags, concat2("-C", optarg)); p2out = xmalloc(sizeof ("llib-l.ln") + strlen(optarg)); (void)sprintf(p2out, "llib-l%s.ln", optarg); freelst(&deflibs); @@ -401,11 +446,11 @@ main(argc, argv) case 'I': case 'U': (void)sprintf(flgbuf, "-%c", c); - app2strg(&cppflags, flgbuf, optarg); + appstrg(&cppflags, concat2(flgbuf, optarg)); break; case 'l': - appstrg(&libs, optarg); + appcstrg(&libs, optarg); break; case 'o': @@ -416,11 +461,11 @@ main(argc, argv) break; case 'L': - appstrg(&libsrchpath, optarg); + appcstrg(&libsrchpath, optarg); break; case 'H': - appstrg(&l2flags, "-H"); + appcstrg(&l2flags, "-H"); break; case 'V': @@ -449,7 +494,7 @@ main(argc, argv) if (!oflag) { if ((s = getenv("LIBDIR")) == NULL || strlen(s) == 0) s = PATH_LINTLIB; - appstrg(&libsrchpath, s); + appcstrg(&libsrchpath, s); findlibs(libs); findlibs(deflibs); } @@ -486,7 +531,7 @@ fname(name, last) if (strcmp(suff, "ln") == 0) { /* only for lint2 */ if (!iflag) - appstrg(&p2in, name); + appcstrg(&p2in, name); return; } @@ -518,20 +563,20 @@ fname(name, last) } } if (!iflag) - appstrg(&p1out, ofn); + appcstrg(&p1out, ofn); args = xcalloc(1, sizeof (char *)); /* run cpp */ - path = xmalloc(sizeof (PATH_LIBEXEC) + sizeof ("cpp")); + path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/cpp")); (void)sprintf(path, "%s/cpp", PATH_LIBEXEC); - appstrg(&args, path); + appcstrg(&args, path); applst(&args, cppflags); applst(&args, lcppflgs); - appstrg(&args, name); - appstrg(&args, cppout); + appcstrg(&args, name); + appcstrg(&args, cppout); runchild(path, args, cppout); free(path); @@ -539,19 +584,19 @@ fname(name, last) /* run lint1 */ - path = xmalloc(sizeof (PATH_LIBEXEC) + sizeof ("lint1")); + path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1")); (void)sprintf(path, "%s/lint1", PATH_LIBEXEC); - appstrg(&args, path); + appcstrg(&args, path); applst(&args, l1flags); - appstrg(&args, cppout); - appstrg(&args, ofn); + appcstrg(&args, cppout); + appcstrg(&args, ofn); runchild(path, args, ofn); free(path); freelst(&args); - appstrg(&p2in, ofn); + appcstrg(&p2in, ofn); free(ofn); free(args); @@ -629,7 +674,7 @@ findlibs(liblst) break; } if (path != NULL) { - app2strg(&l2libs, "-l", lfn); + appstrg(&l2libs, concat2("-l", lfn)); } else { warnx("cannot find llib-l%s.ln", lib); } @@ -660,10 +705,10 @@ lint2() args = xcalloc(1, sizeof (char *)); - path = xmalloc(sizeof (PATH_LIBEXEC) + sizeof ("lint2")); + path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2")); (void)sprintf(path, "%s/lint2", PATH_LIBEXEC); - appstrg(&args, path); + appcstrg(&args, path); applst(&args, l2flags); applst(&args, l2libs); applst(&args, p2in); |