-.\" $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.
.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
.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
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.
.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).
.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
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
.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.
.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.
.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
.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
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
-/* $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
*/
#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>
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 *));
*/
static void
appstrg(lstp, s)
- char ***lstp;
- const char *s;
+ char ***lstp, *s;
{
char **lst, **olst;
int i;
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
}
}
+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.
*/
return (*cp1 == '\0' ? cp2 : cp1);
}
+static void
+appdef(lstp, def)
+ char ***lstp;
+ const char *def;
+{
+ appstrg(lstp, concat2("-D__", def));
+ appstrg(lstp, concat3("-D__", def, "__"));
+}
+
static void
usage()
{
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);
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);
case 'v':
case 'z':
(void)sprintf(flgbuf, "-%c", c);
- appstrg(&l1flags, flgbuf);
+ appcstrg(&l1flags, flgbuf);
break;
case 'F':
case 'u':
case 'h':
(void)sprintf(flgbuf, "-%c", c);
- appstrg(&l1flags, flgbuf);
- appstrg(&l2flags, flgbuf);
+ appcstrg(&l1flags, flgbuf);
+ appcstrg(&l2flags, flgbuf);
break;
case 'i':
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;
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;
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);
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':
break;
case 'L':
- appstrg(&libsrchpath, optarg);
+ appcstrg(&libsrchpath, optarg);
break;
case 'H':
- appstrg(&l2flags, "-H");
+ appcstrg(&l2flags, "-H");
break;
case 'V':
if (!oflag) {
if ((s = getenv("LIBDIR")) == NULL || strlen(s) == 0)
s = PATH_LINTLIB;
- appstrg(&libsrchpath, s);
+ appcstrg(&libsrchpath, s);
findlibs(libs);
findlibs(deflibs);
}
if (strcmp(suff, "ln") == 0) {
/* only for lint2 */
if (!iflag)
- appstrg(&p2in, name);
+ appcstrg(&p2in, name);
return;
}
}
}
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);
/* 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);
break;
}
if (path != NULL) {
- app2strg(&l2libs, "-l", lfn);
+ appstrg(&l2libs, concat2("-l", lfn));
} else {
warnx("cannot find llib-l%s.ln", lib);
}
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);