Merge conflicts, fix Makefiles and remove (re)moved file(s).

This commit is contained in:
Mark Murray 2002-03-03 15:12:50 +00:00
parent 95f78da7d8
commit f84f50e683
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=91592
17 changed files with 1601 additions and 1331 deletions

View File

@ -1,21 +1,12 @@
# $NetBSD: Makefile.inc,v 1.8 2002/02/04 00:18:32 thorpej Exp $
# $FreeBSD$
WARNS= 0
.include <bsd.own.mk>
.PATH: ${.CURDIR}/../common
# On the m68000, MACHINE_CPU is "m68k", but we have different
# target parameters (namely, long double is a different size
# on the m68000), so we special case the directory name here.
.if ${MACHINE_ARCH} == "m68000"
ARCHSUBDIR= m68000
.else
ARCHSUBDIR= ${MACHINE_CPU}
.endif
CFLAGS+= -I${.CURDIR}/../arch/${MACHINE_ARCH}
CFLAGS+= -I${.CURDIR}/../common
CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR}
CPPFLAGS+= -I${.CURDIR}/../common
.if exists(${.CURDIR}/../../Makefile.inc)
.include "${.CURDIR}/../../Makefile.inc"
.endif
OBJECT_FMT= ELF

View File

@ -3,13 +3,19 @@
PROG= lint1
SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \
init.c emit.c emit1.c y.tab.h
NOMAN=
LDADD+= -ll
DPADD+= ${LIBL}
init.c emit.c emit1.c inittyp.c
MAN= lint.7
LDADD+= -ll -lm
DPADD+= ${LIBL} ${LIBM}
CFLAGS+= -I. -I${.CURDIR}
LINTFLAGS=-aehpz
BINDIR= /usr/libexec
.include <bsd.prog.mk>
.PATH: ../common
lint.7: makeman
sh ${.CURDIR}/makeman ${.OBJDIR}/${PROG} -m >${.TARGET}

View File

@ -1,7 +1,8 @@
%{
/* $NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $ */
/* $NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,11 +33,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "lint1.h"
@ -55,10 +59,52 @@ int blklev;
*/
int mblklev;
static int toicon __P((tnode_t *));
static void idecl __P((sym_t *, int));
static void ignuptorp __P((void));
/*
* Save the no-warns state and restore it to avoid the problem where
* if (expr) { stmt } / * NOLINT * / stmt;
*/
static int onowarn = -1;
static int toicon(tnode_t *);
static void idecl(sym_t *, int, sbuf_t *);
static void ignuptorp(void);
#ifdef DEBUG
static __inline void CLRWFLGS(void);
static __inline void CLRWFLGS(void)
{
printf("%s, %d: clear flags %s %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__);
clrwflgs();
onowarn = -1;
}
static __inline void SAVE(void);
static __inline void SAVE(void)
{
if (onowarn != -1)
abort();
printf("%s, %d: save flags %s %d = %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__, nowarn);
onowarn = nowarn;
}
static __inline void RESTORE(void);
static __inline void RESTORE(void)
{
if (onowarn != -1) {
nowarn = onowarn;
printf("%s, %d: restore flags %s %d = %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__, nowarn);
onowarn = -1;
} else
CLRWFLGS();
}
#else
#define CLRWFLGS() clrwflgs(), onowarn = -1
#define SAVE() onowarn = nowarn
#define RESTORE() (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn))
#endif
%}
%union {
@ -129,6 +175,7 @@ static void ignuptorp __P((void));
%token T_BREAK
%token T_RETURN
%token T_ASM
%token T_SYMBOLRENAME
%left T_COMMA
%right T_ASSIGN T_OPASS
@ -205,6 +252,7 @@ static void ignuptorp __P((void));
%type <y_tnode> opt_expr
%type <y_strg> string
%type <y_strg> string2
%type <y_sb> opt_asm_or_symbolrename
%%
@ -228,13 +276,14 @@ translation_unit:
;
ext_decl:
func_def {
asm_stmnt
| func_def {
glclup(0);
clrwflgs();
CLRWFLGS();
}
| data_def {
glclup(0);
clrwflgs();
CLRWFLGS();
}
;
@ -278,7 +327,7 @@ data_def:
}
| declspecs deftyp type_init_decls T_SEMI
| error T_SEMI {
globclup();
globclup();
}
| error T_RBRACE {
globclup();
@ -712,7 +761,7 @@ enums_with_opt_comma:
error(54);
} else {
/* trailing "," prohibited in enum declaration */
warning(54);
(void)gnuism(54);
}
$$ = $1;
}
@ -757,24 +806,24 @@ type_init_decls:
;
notype_init_decl:
notype_decl opt_asm_spec {
idecl($1, 0);
notype_decl opt_asm_or_symbolrename {
idecl($1, 0, $2);
chksz($1);
}
| notype_decl opt_asm_spec {
idecl($1, 1);
| notype_decl opt_asm_or_symbolrename {
idecl($1, 1, $2);
} T_ASSIGN initializer {
chksz($1);
}
;
type_init_decl:
type_decl opt_asm_spec {
idecl($1, 0);
type_decl opt_asm_or_symbolrename {
idecl($1, 0, $2);
chksz($1);
}
| type_decl opt_asm_spec {
idecl($1, 1);
| type_decl opt_asm_or_symbolrename {
idecl($1, 1, $2);
} T_ASSIGN initializer {
chksz($1);
}
@ -920,8 +969,7 @@ pointer:
asterisk:
T_MULT {
if (($$ = calloc(1, sizeof (pqinf_t))) == NULL)
nomem();
$$ = xcalloc(1, sizeof (pqinf_t));
$$->p_pcnt = 1;
}
;
@ -937,8 +985,7 @@ type_qualifier_list:
type_qualifier:
T_QUAL {
if (($$ = calloc(1, sizeof (pqinf_t))) == NULL)
nomem();
$$ = xcalloc(1, sizeof (pqinf_t));
if ($1 == CONST) {
$$->p_const = 1;
} else {
@ -1017,10 +1064,10 @@ vararg_parameter_type_list:
;
parameter_type_list:
parameter_declaration opt_asm_spec {
parameter_declaration {
$$ = $1;
}
| parameter_type_list T_COMMA parameter_declaration opt_asm_spec {
| parameter_type_list T_COMMA parameter_declaration {
$$ = lnklst($1, $3);
}
;
@ -1053,10 +1100,16 @@ parameter_declaration:
}
;
opt_asm_spec:
/* empty */
opt_asm_or_symbolrename: /* expect only one */
/* empty */ {
$$ = NULL;
}
| T_ASM T_LPARN T_STRING T_RPARN {
freeyyv(&$3, T_STRING);
$$ = NULL;
}
| T_SYMBOLRENAME T_LPARN T_NAME T_RPARN {
$$ = $3;
}
;
@ -1214,15 +1267,11 @@ opt_stmnt_list:
;
stmnt_list:
stmnt {
clrwflgs();
}
stmnt
| stmnt_list stmnt {
clrwflgs();
}
| stmnt_list error T_SEMI {
clrwflgs();
RESTORE();
}
| stmnt_list error T_SEMI
;
expr_stmnt:
@ -1237,21 +1286,27 @@ expr_stmnt:
selection_stmnt:
if_without_else {
SAVE();
if2();
if3(0);
}
| if_without_else T_ELSE {
SAVE();
if2();
} stmnt {
CLRWFLGS();
if3(1);
}
| if_without_else T_ELSE error {
CLRWFLGS();
if3(0);
}
| switch_expr stmnt {
CLRWFLGS();
switch2();
}
| switch_expr error {
CLRWFLGS();
switch2();
}
;
@ -1264,35 +1319,46 @@ if_without_else:
if_expr:
T_IF T_LPARN expr T_RPARN {
if1($3);
clrwflgs();
CLRWFLGS();
}
;
switch_expr:
T_SWITCH T_LPARN expr T_RPARN {
switch1($3);
clrwflgs();
CLRWFLGS();
}
;
do_stmnt:
do stmnt {
CLRWFLGS();
}
;
iteration_stmnt:
while_expr stmnt {
CLRWFLGS();
while2();
}
| while_expr error {
CLRWFLGS();
while2();
}
| do stmnt do_while_expr {
do2($3);
| do_stmnt do_while_expr {
do2($2);
ftflg = 0;
}
| do error {
CLRWFLGS();
do2(NULL);
}
| for_exprs stmnt {
CLRWFLGS();
for2();
}
| for_exprs error {
CLRWFLGS();
for2();
}
;
@ -1300,7 +1366,7 @@ iteration_stmnt:
while_expr:
T_WHILE T_LPARN expr T_RPARN {
while1($3);
clrwflgs();
CLRWFLGS();
}
;
@ -1319,7 +1385,7 @@ do_while_expr:
for_exprs:
T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
for1($3, $5, $7);
clrwflgs();
CLRWFLGS();
}
;
@ -1377,10 +1443,10 @@ read_until_rparn:
declaration_list:
declaration {
clrwflgs();
CLRWFLGS();
}
| declaration_list declaration {
clrwflgs();
CLRWFLGS();
}
;
@ -1443,7 +1509,7 @@ expr:
term:
T_NAME {
/* XXX realy neccessary? */
/* XXX really necessary? */
if (yychar < 0)
yychar = yylex();
$$ = getnnode(getsym($1), yychar);
@ -1567,15 +1633,34 @@ identifier:
/* ARGSUSED */
int
yyerror(msg)
char *msg;
yyerror(char *msg)
{
error(249);
if (++sytxerr >= 5)
norecover();
return (0);
}
static inline int uq_gt(uint64_t, uint64_t);
static inline int q_gt(int64_t, int64_t);
static inline int
uq_gt(uint64_t a, uint64_t b)
{
return (a > b);
}
static inline int
q_gt(int64_t a, int64_t b)
{
return (a > b);
}
#define q_lt(a, b) q_gt(b, a)
/*
* Gets a node for a constant and returns the value of this constant
* as integer.
@ -1586,8 +1671,7 @@ yyerror(msg)
* expressions, it frees the memory used for the expression.
*/
static int
toicon(tn)
tnode_t *tn;
toicon(tnode_t *tn)
{
int i;
tspec_t t;
@ -1609,26 +1693,17 @@ toicon(tn)
} else {
i = (int)v->v_quad;
if (isutyp(t)) {
if ((u_quad_t)v->v_quad > INT_MAX) {
if (uq_gt((uint64_t)v->v_quad,
(uint64_t)INT_MAX)) {
/* integral constant too large */
warning(56);
}
} else {
#ifdef XXX_BROKEN_GCC
if (v->v_quad > INT_MAX) {
if (q_gt(v->v_quad, (int64_t)INT_MAX) ||
q_lt(v->v_quad, (int64_t)INT_MIN)) {
/* integral constant too large */
warning(56);
}
else if (v->v_quad < INT_MIN) {
/* integral constant too large */
warning(56);
}
#else
if (v->v_quad > INT_MAX || v->v_quad < INT_MIN) {
/* integral constant too large */
warning(56);
}
#endif
}
}
free(v);
@ -1636,25 +1711,46 @@ toicon(tn)
}
static void
idecl(decl, initflg)
sym_t *decl;
int initflg;
idecl(sym_t *decl, int initflg, sbuf_t *rename)
{
char *s;
initerr = 0;
initsym = decl;
switch (dcs->d_ctx) {
case EXTERN:
if (rename != NULL) {
if (decl->s_rename != NULL)
lerror("idecl() 1");
s = getlblk(1, rename->sb_len + 1);
(void)memcpy(s, rename->sb_name, rename->sb_len + 1);
decl->s_rename = s;
freeyyv(&rename, T_NAME);
}
decl1ext(decl, initflg);
break;
case ARG:
if (rename != NULL) {
/* symbol renaming can't be used on function arguments */
error(310);
freeyyv(&rename, T_NAME);
break;
}
(void)decl1arg(decl, initflg);
break;
case AUTO:
if (rename != NULL) {
/* symbol renaming can't be used on automatic variables */
error(311);
freeyyv(&rename, T_NAME);
break;
}
decl1loc(decl, initflg);
break;
default:
lerror("idecl()");
lerror("idecl() 2");
}
if (initflg && !initerr)
@ -1665,8 +1761,8 @@ idecl(decl, initflg)
* Discard all input tokens up to and including the next
* unmatched right paren
*/
void
ignuptorp()
static void
ignuptorp(void)
{
int level;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $ */
/* $NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,10 +31,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <stdlib.h>
#include <stdarg.h>
#include "lint1.h"
/* number of errors found */
int nerr;
@ -42,18 +49,10 @@ int nerr;
/* number of syntax errors */
int sytxerr;
#include <stdlib.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "lint1.h"
static const char *basename __P((const char *));
static void verror __P((int, va_list));
static void vwarning __P((int, va_list));
static const char *basename(const char *);
static void verror(int, va_list);
static void vwarning(int, va_list);
const char *msgs[] = {
@ -367,15 +366,29 @@ const char *msgs[] = {
"static variable %s set but not used", /* 307 */
"", /* 308 */
"extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */
"symbol renaming can't be used on function arguments", /* 310 */
"symbol renaming can't be used on automatic variables", /* 311 */
"%s C does not support // comments", /* 312 */
};
/*
* print a list of the messages with their ids
*/
void
msglist(void)
{
int i;
for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
printf("%d\t%s\n", i, msgs[i]);
}
/*
* If Fflag is not set basename() returns a pointer to the last
* component of the path, otherwise it returns the argument.
*/
static const char *
basename(path)
const char *path;
basename(const char *path)
{
const char *cp, *cp1, *cp2;
@ -393,26 +406,28 @@ basename(path)
}
static void
verror(n, ap)
int n;
va_list ap;
verror( int n, va_list ap)
{
const char *fn;
if (ERR_ISSET(n, &msgset))
return;
fn = basename(curr_pos.p_file);
(void)printf("%s:%d: ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap);
(void)printf("\n");
(void)printf(" [%d]\n", n);
nerr++;
}
static void
vwarning(n, ap)
int n;
va_list ap;
vwarning( int n, va_list ap)
{
const char *fn;
if (ERR_ISSET(n, &msgset))
return;
if (nowarn)
/* this warning is suppressed by a LINTED comment */
return;
@ -420,46 +435,28 @@ vwarning(n, ap)
fn = basename(curr_pos.p_file);
(void)printf("%s:%d: warning: ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap);
(void)printf("\n");
(void)printf(" [%d]\n", n);
if (wflag)
nerr++;
}
void
#ifdef __STDC__
error(int n, ...)
#else
error(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
#endif
verror(n, ap);
va_end(ap);
}
void
#ifdef __STDC__
lerror(const char *msg, ...)
#else
lerror(msg, va_alist)
const char *msg;
va_dcl
#endif
{
va_list ap;
const char *fn;
#ifdef __STDC__
va_start(ap, msg);
#else
va_start(ap);
#endif
fn = basename(curr_pos.p_file);
(void)fprintf(stderr, "%s:%d: lint error: ", fn, curr_pos.p_line);
(void)vfprintf(stderr, msg, ap);
@ -469,66 +466,39 @@ lerror(msg, va_alist)
}
void
#ifdef __STDC__
warning(int n, ...)
#else
warning(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
#endif
vwarning(n, ap);
va_end(ap);
}
void
#ifdef __STDC__
message(int n, ...)
#else
message(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
const char *fn;
#ifdef __STDC__
if (ERR_ISSET(n, &msgset))
return;
va_start(ap, n);
#else
va_start(ap);
#endif
fn = basename(curr_pos.p_file);
(void)printf("%s:%d: ", fn, curr_pos.p_line);
(void)vprintf(msgs[n], ap);
(void)printf("\n");
(void)printf(" [%d]\n", n);
va_end(ap);
}
int
#ifdef __STDC__
gnuism(int n, ...)
#else
gnuism(n, va_alist)
int n;
va_dcl
#endif
{
va_list ap;
int msg;
#ifdef __STDC__
va_start(ap, n);
#else
va_start(ap);
#endif
if (sflag && !gflag) {
verror(n, ap);
msg = 1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $ */
/* $NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,16 +31,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include "lint1.h"
#include "y.tab.h"
#include "cgram.h"
/*
* Contains a pointer to the symbol table entry of the current function
@ -129,6 +130,12 @@ int llibflg;
*/
int nowarn;
/*
* Nonzero if bitfield type errors are suppressed by a BITFIELDTYPE
* directive.
*/
int bitfieldtype_ok;
/*
* Nonzero if complaints about use of "long long" are suppressed in
* the next statement or declaration.
@ -139,8 +146,7 @@ int quadflg;
* Puts a new element at the top of the stack used for control statements.
*/
void
pushctrl(env)
int env;
pushctrl(int env)
{
cstk_t *ci;
@ -155,8 +161,7 @@ pushctrl(env)
* Removes the top element of the stack used for control statements.
*/
void
popctrl(env)
int env;
popctrl(int env)
{
cstk_t *ci;
clst_t *cl;
@ -181,7 +186,7 @@ popctrl(env)
* Prints a warning if a statement cannot be reached.
*/
void
chkreach()
chkreach(void)
{
if (!reached && !rchflg) {
/* statement not reached */
@ -201,8 +206,7 @@ chkreach()
* redeclaration etc..
*/
void
funcdef(fsym)
sym_t *fsym;
funcdef(sym_t *fsym)
{
int n, warn;
sym_t *arg, *sym, *rdsym;
@ -324,7 +328,7 @@ funcdef(fsym)
}
if (dcs->d_notyp)
/* return value is implizitly declared to be int */
/* return value is implicitly declared to be int */
fsym->s_rimpl = 1;
reached = 1;
@ -334,7 +338,7 @@ funcdef(fsym)
* Called at the end of a function definition.
*/
void
funcend()
funcend(void)
{
sym_t *arg;
int n;
@ -370,7 +374,7 @@ funcend()
/*
* write the information about the function definition to the
* output file
* inline functions explicitely declared extern are written as
* inline functions explicitly declared extern are written as
* declarations only.
*/
if (dcs->d_scl == EXTERN && funcsym->s_inline) {
@ -400,14 +404,12 @@ funcend()
* tn expression if typ == T_CASE
*/
void
label(typ, sym, tn)
int typ;
sym_t *sym;
tnode_t *tn;
label(int typ, sym_t *sym, tnode_t *tn)
{
cstk_t *ci;
clst_t *cl;
val_t *v, *nv;
val_t *v;
val_t nv;
tspec_t t;
switch (typ) {
@ -424,7 +426,8 @@ label(typ, sym, tn)
case T_CASE:
/* find the stack entry for the innermost switch statement */
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ;
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt)
continue;
if (ci == NULL) {
/* case not in switch */
@ -464,30 +467,28 @@ label(typ, sym, tn)
* to the type of the switch expression
*/
v = constant(tn);
if ((nv = calloc(1, sizeof (val_t))) == NULL)
nomem();
cvtcon(CASE, 0, ci->c_swtype, nv, v);
(void) memset(&nv, 0, sizeof nv);
cvtcon(CASE, 0, ci->c_swtype, &nv, v);
free(v);
/* look if we had this value already */
for (cl = ci->c_clst; cl != NULL; cl = cl->cl_nxt) {
if (cl->cl_val.v_quad == nv->v_quad)
if (cl->cl_val.v_quad == nv.v_quad)
break;
}
if (cl != NULL && isutyp(nv->v_tspec)) {
if (cl != NULL && isutyp(nv.v_tspec)) {
/* duplicate case in switch, %lu */
error(200, (u_long)nv->v_quad);
error(200, (u_long)nv.v_quad);
} else if (cl != NULL) {
/* duplicate case in switch, %ld */
error(199, (long)nv->v_quad);
error(199, (long)nv.v_quad);
} else {
/*
* append the value to the list of
* case values
*/
if ((cl = calloc(1, sizeof (clst_t))) == NULL)
nomem();
STRUCT_ASSIGN(cl->cl_val, *nv);
cl = xcalloc(1, sizeof (clst_t));
STRUCT_ASSIGN(cl->cl_val, nv);
cl->cl_nxt = ci->c_clst;
ci->c_clst = cl;
}
@ -498,7 +499,8 @@ label(typ, sym, tn)
case T_DEFAULT:
/* find the stack entry for the innermost switch statement */
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ;
for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt)
continue;
if (ci == NULL) {
/* default outside switch */
@ -523,9 +525,9 @@ label(typ, sym, tn)
* T_IF T_LPARN expr T_RPARN
*/
void
if1(tn)
tnode_t *tn;
if1(tnode_t *tn)
{
if (tn != NULL)
tn = cconv(tn);
if (tn != NULL)
@ -539,8 +541,9 @@ if1(tn)
* if_without_else T_ELSE
*/
void
if2()
if2(void)
{
cstk->c_rchif = reached ? 1 : 0;
reached = 1;
}
@ -550,9 +553,9 @@ if2()
* if_without_else T_ELSE stmnt
*/
void
if3(els)
int els;
if3(int els)
{
if (els) {
reached |= cstk->c_rchif;
} else {
@ -565,8 +568,7 @@ if3(els)
* T_SWITCH T_LPARN expr T_RPARN
*/
void
switch1(tn)
tnode_t *tn;
switch1(tnode_t *tn)
{
tspec_t t;
type_t *tp;
@ -618,9 +620,9 @@ switch1(tn)
* switch_expr stmnt
*/
void
switch2()
switch2(void)
{
int nenum, nclab;
int nenum = 0, nclab = 0;
sym_t *esym;
clst_t *cl;
@ -673,9 +675,9 @@ switch2()
* T_WHILE T_LPARN expr T_RPARN
*/
void
while1(tn)
tnode_t *tn;
while1(tnode_t *tn)
{
if (!reached) {
/* loop not entered at top */
warning(207);
@ -710,8 +712,9 @@ while1(tn)
* while_expr error
*/
void
while2()
while2(void)
{
/*
* The end of the loop can be reached if it is no endless loop
* or there was a break statement which was reached.
@ -726,8 +729,9 @@ while2()
* T_DO
*/
void
do1()
do1(void)
{
if (!reached) {
/* loop not entered at top */
warning(207);
@ -743,9 +747,9 @@ do1()
* do error
*/
void
do2(tn)
tnode_t *tn;
do2(tnode_t *tn)
{
/*
* If there was a continue statement the expression controlling the
* loop is reached.
@ -787,9 +791,9 @@ do2(tn)
* T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN
*/
void
for1(tn1, tn2, tn3)
tnode_t *tn1, *tn2, *tn3;
for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
{
/*
* If there is no initialisation expression it is possible that
* it is intended not to enter the loop at top.
@ -848,7 +852,7 @@ for1(tn1, tn2, tn3)
* for_exprs error
*/
void
for2()
for2(void)
{
pos_t cpos, cspos;
tnode_t *tn3;
@ -893,9 +897,9 @@ for2()
* T_GOTO error T_SEMI
*/
void
dogoto(lab)
sym_t *lab;
dogoto(sym_t *lab)
{
setuflg(lab, 0, 0);
chkreach();
@ -907,7 +911,7 @@ dogoto(lab)
* T_BREAK T_SEMI
*/
void
dobreak()
dobreak(void)
{
cstk_t *ci;
@ -933,11 +937,12 @@ dobreak()
* T_CONTINUE T_SEMI
*/
void
docont()
docont(void)
{
cstk_t *ci;
for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) ;
for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt)
continue;
if (ci == NULL) {
/* continue outside loop */
@ -956,14 +961,14 @@ docont()
* T_RETURN expr T_SEMI
*/
void
doreturn(tn)
tnode_t *tn;
doreturn(tnode_t *tn)
{
tnode_t *ln, *rn;
cstk_t *ci;
op_t op;
for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt) ;
for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt)
continue;
if (tn != NULL) {
ci->c_retval = 1;
@ -1025,8 +1030,7 @@ doreturn(tn)
* Especially remove informations about unused lint comments.
*/
void
glclup(silent)
int silent;
glclup(int silent)
{
pos_t cpos;
@ -1077,9 +1081,9 @@ glclup(silent)
* for usage. A missing argument is taken to be 0.
*/
void
argsused(n)
int n;
argsused(int n)
{
if (n == -1)
n = 0;
@ -1103,9 +1107,9 @@ argsused(n)
* to the function definition. A missing argument is taken to be 0.
*/
void
varargs(n)
int n;
varargs(int n)
{
if (n == -1)
n = 0;
@ -1129,9 +1133,9 @@ varargs(n)
* used the check the types of remaining arguments.
*/
void
printflike(n)
int n;
printflike(int n)
{
if (n == -1)
n = 0;
@ -1155,9 +1159,9 @@ printflike(n)
* used the check the types of remaining arguments.
*/
void
scanflike(n)
int n;
scanflike(int n)
{
if (n == -1)
n = 0;
@ -1180,9 +1184,9 @@ scanflike(n)
*/
/* ARGSUSED */
void
constcond(n)
int n;
constcond(int n)
{
ccflg = 1;
}
@ -1192,9 +1196,9 @@ constcond(n)
*/
/* ARGSUSED */
void
fallthru(n)
int n;
fallthru(int n)
{
ftflg = 1;
}
@ -1204,18 +1208,18 @@ fallthru(n)
*/
/* ARGSUSED */
void
notreach(n)
int n;
notreach(int n)
{
reached = 0;
rchflg = 1;
}
/* ARGSUSED */
void
lintlib(n)
int n;
lintlib(int n)
{
if (dcs->d_ctx != EXTERN) {
/* must be outside function: ** %s ** */
warning(280, "LINTLIBRARY");
@ -1230,21 +1234,39 @@ lintlib(n)
*/
/* ARGSUSED */
void
linted(n)
int n;
linted(int n)
{
#ifdef DEBUG
printf("%s, %d: nowarn = 1\n", curr_pos.p_file, curr_pos.p_line);
#endif
nowarn = 1;
}
/*
* Suppress bitfield type errors on the current line.
*/
/* ARGSUSED */
void
bitfieldtype(int n)
{
#ifdef DEBUG
printf("%s, %d: bitfieldtype_ok = 1\n", curr_pos.p_file,
curr_pos.p_line);
#endif
bitfieldtype_ok = 1;
}
/*
* PROTOTLIB in conjunction with LINTLIBRARY can be used to handle
* prototypes like function definitions. This is done if the argument
* to PROTOLIB is nonzero. Otherwise prototypes are handled normaly.
*/
void
protolib(n)
int n;
protolib(int n)
{
if (dcs->d_ctx != EXTERN) {
/* must be outside function: ** %s ** */
warning(280, "PROTOLIB");
@ -1259,8 +1281,8 @@ protolib(n)
*/
/* ARGSUSED */
void
longlong(n)
int n;
longlong(int n)
{
quadflg = 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $ */
/* $NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,10 +31,11 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/mman.h>
@ -42,7 +43,6 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include "lint1.h"
@ -58,15 +58,13 @@ typedef struct fn {
static fn_t *fnames;
static fn_t *srchfn __P((const char *, size_t));
static fn_t *srchfn(const char *, size_t);
/*
* Look for a Filename of length l.
*/
static fn_t *
srchfn(s, len)
const char *s;
size_t len;
srchfn(const char *s, size_t len)
{
fn_t *fn;
@ -81,16 +79,14 @@ srchfn(s, len)
* Return a shared string for filename s.
*/
const char *
fnalloc(s)
const char *s;
fnalloc(const char *s)
{
return (s != NULL ? fnnalloc(s, strlen(s)) : NULL);
}
const char *
fnnalloc(s, len)
const char *s;
size_t len;
fnnalloc(const char *s, size_t len)
{
fn_t *fn;
@ -124,8 +120,7 @@ fnnalloc(s, len)
* Get id of a filename.
*/
int
getfnid(s)
const char *s;
getfnid(const char *s)
{
fn_t *fn;
@ -166,12 +161,12 @@ static mbl_t *frmblks;
/* length of new allocated memory blocks */
static size_t mblklen;
static void *xgetblk __P((mbl_t **, size_t));
static void xfreeblk __P((mbl_t **));
static mbl_t *xnewblk __P((void));
static void *xgetblk(mbl_t **, size_t);
static void xfreeblk(mbl_t **);
static mbl_t *xnewblk(void);
static mbl_t *
xnewblk()
xnewblk(void)
{
mbl_t *mb;
int prot, flags;
@ -186,8 +181,6 @@ xnewblk()
mb->blk = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
if (mb->blk == (void *)MAP_FAILED)
err(1, "can't map memory");
if (ALIGN((u_long)mb->blk) != (u_long)mb->blk)
errx(1, "mapped address is not aligned");
mb->size = mblklen;
@ -203,9 +196,7 @@ xnewblk()
* zero'd in xfreeblk().
*/
static void *
xgetblk(mbp, s)
mbl_t **mbp;
size_t s;
xgetblk(mbl_t **mbp, size_t s)
{
mbl_t *mb;
void *p;
@ -234,8 +225,7 @@ xgetblk(mbp, s)
* used memory to zero.
*/
static void
xfreeblk(fmbp)
mbl_t **fmbp;
xfreeblk(mbl_t **fmbp)
{
mbl_t *mb;
@ -248,7 +238,7 @@ xfreeblk(fmbp)
}
void
initmem()
initmem(void)
{
int pgsz;
@ -259,15 +249,14 @@ initmem()
nomem();
}
/*
* Allocate memory associated with level l.
*/
void *
getlblk(l, s)
int l;
size_t s;
getlblk(int l, size_t s)
{
while (l >= nmblks) {
if ((mblks = realloc(mblks, (nmblks + ML_INC) *
sizeof (mbl_t *))) == NULL)
@ -279,9 +268,9 @@ getlblk(l, s)
}
void *
getblk(s)
size_t s;
getblk(size_t s)
{
return (getlblk(mblklev, s));
}
@ -289,15 +278,16 @@ getblk(s)
* Free all memory associated with level l.
*/
void
freelblk(l)
int l;
freelblk(int l)
{
xfreeblk(&mblks[l]);
}
void
freeblk()
freeblk(void)
{
freelblk(mblklev);
}
@ -308,9 +298,9 @@ freeblk()
static mbl_t *tmblk;
void *
tgetblk(s)
size_t s;
tgetblk(size_t s)
{
return (xgetblk(&tmblk, s));
}
@ -318,17 +308,19 @@ tgetblk(s)
* Get memory for a new tree node.
*/
tnode_t *
getnode()
getnode(void)
{
return (tgetblk(sizeof (tnode_t)));
}
/*
* Free all memory which is allocated by the the current expression.
* Free all memory which is allocated by the current expression.
*/
void
tfreeblk()
tfreeblk(void)
{
xfreeblk(&tmblk);
}
@ -338,7 +330,7 @@ tfreeblk()
* used to restore the memory.
*/
mbl_t *
tsave()
tsave(void)
{
mbl_t *tmem;
@ -353,9 +345,9 @@ tsave()
* tfreeblk() frees the restored memory.
*/
void
trestor(tmem)
mbl_t *tmem;
trestor(mbl_t *tmem)
{
tfreeblk();
if (tmblk != NULL) {
free(tmblk->blk);

View File

@ -1,7 +1,8 @@
%{
/* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */
/* $NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,9 +33,11 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static char rcsid[] = "$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
@ -46,38 +49,40 @@ static char rcsid[] = "$FreeBSD$";
#include <math.h>
#include "lint1.h"
#include "y.tab.h"
#include "cgram.h"
#define CHAR_MASK (~(~0 << CHAR_BIT))
#define YY_NO_UNPUT
/* Current position (its also updated when an included file is parsed) */
pos_t curr_pos = { 1, "" };
pos_t curr_pos = { 1, "", 0 };
/*
* Current position in C source (not updated when an included file is
* parsed).
*/
pos_t csrc_pos = { 1, "" };
pos_t csrc_pos = { 1, "", 0 };
static void incline __P((void));
static void badchar __P((int));
static sbuf_t *allocsb __P((void));
static void freesb __P((sbuf_t *));
static int inpc __P((void));
static int hash __P((const char *));
static sym_t *search __P((sbuf_t *));
static int name __P((void));
static int keyw __P((sym_t *));
static int icon __P((int));
static int fcon __P((void));
static int operator __P((int, op_t));
static int ccon __P((void));
static int wccon __P((void));
static int getescc __P((int));
static void directive __P((void));
static void comment __P((void));
static int string __P((void));
static int wcstrg __P((void));
static void incline(void);
static void badchar(int);
static sbuf_t *allocsb(void);
static void freesb(sbuf_t *);
static int inpc(void);
static int hash(const char *);
static sym_t *search(sbuf_t *);
static int name(void);
static int keyw(sym_t *);
static int icon(int);
static int fcon(void);
static int operator(int, op_t);
static int ccon(void);
static int wccon(void);
static int getescc(int);
static void directive(void);
static void comment(void);
static void slashslashcomment(void);
static int string(void);
static int wcstrg(void);
%}
@ -151,22 +156,26 @@ EX ([eE][+-]?[0-9]+)
\n incline();
\t|" "|\f|\v ;
"/*" comment();
"//" slashslashcomment();
. badchar(yytext[0]);
%%
static void
incline()
incline(void)
{
curr_pos.p_line++;
if (curr_pos.p_file == csrc_pos.p_file)
curr_pos.p_uniq = 0;
if (curr_pos.p_file == csrc_pos.p_file) {
csrc_pos.p_line++;
csrc_pos.p_uniq = 0;
}
}
static void
badchar(c)
int c;
badchar(int c)
{
/* unknown character \%o */
error(250, c);
}
@ -209,6 +218,7 @@ static struct kwtab {
{ "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 },
{ "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 },
{ "int", T_TYPE, 0, INT, 0, 0, 0 },
{ "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0 },
{ "long", T_TYPE, 0, LONG, 0, 0, 0 },
{ "register", T_SCLASS, REG, 0, 0, 0, 0 },
{ "return", T_RETURN, 0, 0, 0, 0, 0 },
@ -235,13 +245,13 @@ static struct kwtab {
static sym_t *symtab[HSHSIZ1];
/* bit i of the entry with index i is set */
u_quad_t qbmasks[sizeof(u_quad_t) * CHAR_BIT];
uint64_t qbmasks[sizeof(uint64_t) * CHAR_BIT];
/* least significant i bits are set in the entry with index i */
u_quad_t qlmasks[sizeof(u_quad_t) * CHAR_BIT + 1];
uint64_t qlmasks[sizeof(uint64_t) * CHAR_BIT + 1];
/* least significant i bits are not set in the entry with index i */
u_quad_t qumasks[sizeof(u_quad_t) * CHAR_BIT + 1];
uint64_t qumasks[sizeof(uint64_t) * CHAR_BIT + 1];
/* free list for sbuf structures */
static sbuf_t *sbfrlst;
@ -255,12 +265,12 @@ symt_t symtyp;
* in a extra table for each name we found.
*/
void
initscan()
initscan(void)
{
struct kwtab *kw;
sym_t *sym;
int h, i;
u_quad_t uq;
uint64_t uq;
for (kw = kwtab; kw->kw_name != NULL; kw++) {
if (kw->kw_stdc && tflag)
@ -285,21 +295,21 @@ initscan()
}
/* initialize bit-masks for quads */
for (i = 0; i < sizeof (u_quad_t) * CHAR_BIT; i++) {
qbmasks[i] = (u_quad_t)1 << i;
uq = ~(u_quad_t)0 << i;
for (i = 0; i < sizeof (uint64_t) * CHAR_BIT; i++) {
qbmasks[i] = (uint64_t)1 << i;
uq = ~(uint64_t)0 << i;
qumasks[i] = uq;
qlmasks[i] = ~uq;
}
qumasks[i] = 0;
qlmasks[i] = ~(u_quad_t)0;
qlmasks[i] = ~(uint64_t)0;
}
/*
* Get a free sbuf structure, if possible from the free list
*/
static sbuf_t *
allocsb()
allocsb(void)
{
sbuf_t *sb;
@ -317,9 +327,9 @@ allocsb()
* Put a sbuf structure to the free list
*/
static void
freesb(sb)
sbuf_t *sb;
freesb(sbuf_t *sb)
{
sb->sb_nxt = sbfrlst;
sbfrlst = sb;
}
@ -329,7 +339,7 @@ freesb(sb)
* Increment line count(s) if necessary.
*/
static int
inpc()
inpc(void)
{
int c;
@ -339,8 +349,7 @@ inpc()
}
static int
hash(s)
const char *s;
hash(const char *s)
{
u_int v;
const u_char *us;
@ -369,7 +378,7 @@ hash(s)
* to the symbol table entry.
*/
static int
name()
name(void)
{
char *s;
sbuf_t *sb;
@ -407,8 +416,7 @@ name()
}
static sym_t *
search(sb)
sbuf_t *sb;
search(sbuf_t *sb)
{
sym_t *sym;
@ -421,10 +429,9 @@ search(sb)
return (NULL);
}
static int
keyw(sym)
sym_t *sym;
keyw(sym_t *sym)
{
int t;
@ -443,16 +450,15 @@ keyw(sym)
* The value is returned in yylval. icon() (and yylex()) returns T_CON.
*/
static int
icon(base)
int base;
icon(int base)
{
int l_suffix, u_suffix;
int len;
const char *cp;
char c, *eptr;
tspec_t typ;
u_long ul;
u_quad_t uq;
u_long ul = 0;
uint64_t uq = 0;
int ansiu;
static tspec_t contypes[2][3] = {
{ INT, LONG, QUAD },
@ -507,7 +513,7 @@ icon(base)
warning(252);
/*
* If the value is to big for the current type, we must choose
* If the value is to big for the current type, we must choose
* another type.
*/
ansiu = 0;
@ -553,24 +559,47 @@ icon(base)
}
break;
/* LINTED (enumeration values not handled in switch) */
default:
case STRUCT:
case VOID:
case LDOUBLE:
case FUNC:
case ARRAY:
case PTR:
case ENUM:
case UNION:
case SIGNED:
case NOTSPEC:
case DOUBLE:
case FLOAT:
case UQUAD:
case ULONG:
case USHORT:
case SHORT:
case UCHAR:
case SCHAR:
case CHAR:
case UNSIGN:
break;
case NTSPEC: /* this value unused */
break;
}
if (typ != QUAD && typ != UQUAD) {
if (isutyp(typ)) {
uq = ul;
} else {
uq = (quad_t)(long)ul;
uq = (int64_t)(long)ul;
}
}
uq = (u_quad_t)xsign((quad_t)uq, typ, -1);
uq = (uint64_t)xsign((int64_t)uq, typ, -1);
if ((yylval.y_val = calloc(1, sizeof(val_t))) == NULL)
nomem();
yylval.y_val->v_tspec = typ;
yylval.y_val->v_ansiu = ansiu;
yylval.y_val->v_quad = (quad_t)uq;
yylval.y_val->v_quad = (int64_t)uq;
return (T_CON);
}
@ -582,22 +611,18 @@ icon(base)
* to the width of type t.
*/
int
sign(q, t, len)
quad_t q;
tspec_t t;
int len;
sign(int64_t q, tspec_t t, int len)
{
if (t == PTR || isutyp(t))
return (0);
return (msb(q, t, len));
}
int
msb(q, t, len)
quad_t q;
tspec_t t;
int len;
msb(int64_t q, tspec_t t, int len)
{
if (len <= 0)
len = size(t);
return ((q & qbmasks[len - 1]) != 0);
@ -606,12 +631,10 @@ msb(q, t, len)
/*
* Extends the sign of q.
*/
quad_t
xsign(q, t, len)
quad_t q;
tspec_t t;
int len;
int64_t
xsign(int64_t q, tspec_t t, int len)
{
if (len <= 0)
len = size(t);
@ -628,17 +651,17 @@ xsign(q, t, len)
* representation. Type and value are returned in yylval. fcon()
* (and yylex()) returns T_CON.
* XXX Currently it is not possible to convert constants of type
* long double which are greater then DBL_MAX.
* long double which are greater than DBL_MAX.
*/
static int
fcon()
fcon(void)
{
const char *cp;
int len;
tspec_t typ;
char c, *eptr;
double d;
float f;
float f = 0;
cp = yytext;
len = yyleng;
@ -668,7 +691,7 @@ fcon()
if (typ == FLOAT) {
f = (float)d;
if (isinf(f)) {
if (!finite(f)) {
/* floating-point constant out of range */
warning(248);
f = f > 0 ? FLT_MAX : -FLT_MAX;
@ -688,10 +711,9 @@ fcon()
}
static int
operator(t, o)
int t;
op_t o;
operator(int t, op_t o)
{
yylval.y_op = o;
return (t);
}
@ -700,7 +722,7 @@ operator(t, o)
* Called if lex found a leading \'.
*/
static int
ccon()
ccon(void)
{
int n, val, c;
char cv;
@ -730,9 +752,8 @@ ccon()
cv = (char)val;
val = cv;
}
if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL)
nomem();
yylval.y_val = xcalloc(1, sizeof (val_t));
yylval.y_val->v_tspec = INT;
yylval.y_val->v_quad = val;
@ -743,7 +764,7 @@ ccon()
* Called if lex found a leading L\'
*/
static int
wccon()
wccon(void)
{
static char buf[MB_LEN_MAX + 1];
int i, c;
@ -794,11 +815,10 @@ wccon()
* string.
*
* Returns -1 if the end of the character constant or string is reached,
* -2 if the EOF is reached, and the charachter otherwise.
* -2 if the EOF is reached, and the character otherwise.
*/
static int
getescc(d)
int d;
getescc(int d)
{
static int pbc = -1;
int n, c, v;
@ -813,9 +833,12 @@ getescc(d)
return (-1);
switch (c) {
case '\n':
/* newline in string or char constant */
error(254);
return (-2);
if (tflag) {
/* newline in string or char constant */
error(254);
return (-2);
}
return (c);
case EOF:
return (-2);
case '\\':
@ -838,11 +861,7 @@ getescc(d)
if (tflag)
/* \a undefined in traditional C */
warning(81);
#ifdef __STDC__
return ('\a');
#else
return ('\007');
#endif
case 'b':
return ('\b');
case 'f':
@ -857,11 +876,7 @@ getescc(d)
if (tflag)
/* \v undefined in traditional C */
warning(264);
#ifdef __STDC__
return ('\v');
#else
return ('\013');
#endif
case '8': case '9':
/* bad octal digit %c */
warning(77, c);
@ -935,7 +950,7 @@ getescc(d)
* # lineno "filename"
*/
static void
directive()
directive(void)
{
const char *cp, *fn;
char c, *eptr;
@ -944,9 +959,10 @@ directive()
static int first = 1;
/* Go to first non-whitespace after # */
for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++) ;
for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++)
continue;
if (!isdigit(c)) {
if (!isdigit((unsigned char)c)) {
error:
/* undefined or invalid # directive */
warning(255);
@ -957,7 +973,8 @@ directive()
goto error;
if ((c = *(cp = eptr)) != ' ' && c != '\t' && c != '\0')
goto error;
while ((c = *cp++) == ' ' || c == '\t') ;
while ((c = *cp++) == ' ' || c == '\t')
continue;
if (c != '\0') {
if (c != '"')
goto error;
@ -968,11 +985,18 @@ directive()
goto error;
if ((fnl = cp++ - fn) > PATH_MAX)
goto error;
while ((c = *cp++) == ' ' || c == '\t') ;
while ((c = *cp++) == ' ' || c == '\t')
continue;
#if 0
if (c != '\0')
warning("extra character(s) after directive");
#endif
/* empty string means stdin */
if (fnl == 0) {
fn = "{standard input}";
fnl = 16; /* strlen (fn) */
}
curr_pos.p_file = fnnalloc(fn, fnl);
/*
* If this is the first directive, the name is the name
@ -986,13 +1010,17 @@ directive()
}
}
curr_pos.p_line = (int)ln - 1;
if (curr_pos.p_file == csrc_pos.p_file)
curr_pos.p_uniq = 0;
if (curr_pos.p_file == csrc_pos.p_file) {
csrc_pos.p_line = (int)ln - 1;
csrc_pos.p_uniq = 0;
}
}
/*
* Handle lint comments. Following comments are currently understood:
* ARGSUSEDn
* BITFIELDTYPE
* CONSTCOND CONSTANTCOND CONSTANTCONDITION
* FALLTHRU FALLTHROUGH
* LINTLIBRARY
@ -1007,15 +1035,16 @@ directive()
* parsed and a function which handles this comment is called.
*/
static void
comment()
comment(void)
{
int c, lc;
static struct {
const char *keywd;
int arg;
void (*func) __P((int));
void (*func)(int);
} keywtab[] = {
{ "ARGSUSED", 1, argsused },
{ "BITFIELDTYPE", 0, bitfieldtype },
{ "CONSTCOND", 0, constcond },
{ "CONSTANTCOND", 0, constcond },
{ "CONSTANTCONDITION", 0, constcond },
@ -1039,7 +1068,8 @@ comment()
eoc = 0;
/* Skip white spaces after the start of the comment */
while ((c = inpc()) != EOF && isspace(c)) ;
while ((c = inpc()) != EOF && isspace(c))
continue;
/* Read the potential keyword to keywd */
l = 0;
@ -1104,6 +1134,22 @@ comment()
}
}
/*
* Handle // style comments
*/
static void
slashslashcomment(void)
{
int c;
if (sflag < 2 && !gflag)
/* // comments only supported in C99 */
(void)gnuism(312, tflag ? "traditional" : "ANSI");
while ((c = inpc()) != EOF && c != '\n')
continue;
}
/*
* Clear flags for lint comments LINTED, LONGLONG and CONSTCOND.
* clrwflgs() is called after function definitions and global and
@ -1112,8 +1158,9 @@ comment()
* (if, switch, for, while).
*/
void
clrwflgs()
clrwflgs(void)
{
nowarn = 0;
quadflg = 0;
ccflg = 0;
@ -1125,7 +1172,7 @@ clrwflgs()
* by the parser are responsible for freeing this buffer.
*/
static int
string()
string(void)
{
u_char *s;
int c;
@ -1159,7 +1206,7 @@ string()
}
static int
wcstrg()
wcstrg(void)
{
char *s;
int c, i, n, wi;
@ -1233,8 +1280,7 @@ wcstrg()
* XXX calls to getsym() should be delayed until decl1*() is called
*/
sym_t *
getsym(sb)
sbuf_t *sb;
getsym(sbuf_t *sb)
{
dinfo_t *di;
char *s;
@ -1282,7 +1328,7 @@ getsym(sb)
di = dcs;
}
STRUCT_ASSIGN(sym->s_dpos, curr_pos);
UNIQUE_CURR_POS(sym->s_dpos);
if ((sym->s_kind = symtyp) != FLAB)
sym->s_type = gettyp(INT);
@ -1305,9 +1351,9 @@ getsym(sb)
* back to the symbol table.
*/
void
rmsym(sym)
sym_t *sym;
rmsym(sym_t *sym)
{
if ((*sym->s_rlink = sym->s_link) != NULL)
sym->s_link->s_rlink = sym->s_rlink;
sym->s_blklev = -1;
@ -1319,8 +1365,7 @@ rmsym(sym)
* table.
*/
void
rmsyms(syms)
sym_t *syms;
rmsyms(sym_t *syms)
{
sym_t *sym;
@ -1338,9 +1383,7 @@ rmsyms(syms)
* Put a symbol into the symbol table
*/
void
inssym(bl, sym)
int bl;
sym_t *sym;
inssym(int bl, sym_t *sym)
{
int h;
@ -1360,7 +1403,7 @@ inssym(bl, sym)
* level 0.
*/
void
cleanup()
cleanup(void)
{
sym_t *sym, *nsym;
int i;
@ -1383,8 +1426,7 @@ cleanup()
* Create a new symbol with the name of an existing symbol.
*/
sym_t *
pushdown(sym)
sym_t *sym;
pushdown(sym_t *sym)
{
int h;
sym_t *nsym;
@ -1394,7 +1436,7 @@ pushdown(sym)
if (sym->s_blklev > blklev)
lerror("pushdown()");
nsym->s_name = sym->s_name;
STRUCT_ASSIGN(nsym->s_dpos, curr_pos);
UNIQUE_CURR_POS(nsym->s_dpos);
nsym->s_kind = sym->s_kind;
nsym->s_blklev = blklev;
@ -1414,9 +1456,7 @@ pushdown(sym)
* The type of information in yylval is described by tok.
*/
void
freeyyv(sp, tok)
void *sp;
int tok;
freeyyv(void *sp, int tok)
{
if (tok == T_NAME || tok == T_TYPENAME) {
sbuf_t *sb = *(sbuf_t **)sp;
@ -1434,5 +1474,5 @@ freeyyv(sp, tok)
lerror("fryylv() 1");
}
free(strg);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
.PATH: ${.CURDIR}/../lint1
PROG= lint2
SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c
SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c inittyp.c
NOMAN=
CFLAGS+=-I${.CURDIR}/../lint1
LINTFLAGS=-abehrz

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $ */
/* $NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -31,17 +31,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
#include <err.h>
#include "lint2.h"
@ -55,7 +55,7 @@ static size_t nxtfree;
static void *mbuf;
void
initmem()
initmem(void)
{
int pgsz;
@ -71,13 +71,13 @@ initmem()
* need never to be freed.
*/
void *
xalloc(sz)
size_t sz;
xalloc(size_t sz)
{
void *ptr;
int prot, flags;
sz = ALIGN(sz);
/* Align to at least 8 bytes. */
sz = (sz + 7) & ~7L;
if (nxtfree + sz > mblklen) {
/* use mmap() instead of malloc() to avoid malloc overhead. */
prot = PROT_READ | PROT_WRITE;
@ -85,8 +85,6 @@ xalloc(sz)
mbuf = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
if (mbuf == (void *)MAP_FAILED)
err(1, "can't map memory");
if (ALIGN((u_long)mbuf) != (u_long)mbuf)
errx(1, "mapped address is not aligned");
(void)memset(mbuf, 0, mblklen);
nxtfree = 0;
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $ */
/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,17 +32,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include "lint2.h"
@ -79,33 +80,34 @@ static thtab_t **thtab; /* hash table */
type_t **tlst; /* array for indexed access */
static size_t tlstlen; /* length of tlst */
static hte_t **renametab;
/* index of current C source file (as spezified at the command line) */
static int csrcfile;
static void inperr __P((void));
static void setsrc __P((const char *));
static void setfnid __P((int, const char *));
static void funccall __P((pos_t *, const char *));
static void decldef __P((pos_t *, const char *));
static void usedsym __P((pos_t *, const char *));
static u_short inptype __P((const char *, const char **));
static int gettlen __P((const char *, const char **));
static u_short findtype __P((const char *, size_t, int));
static u_short storetyp __P((type_t *, const char *, size_t, int));
static int thash __P((const char *, size_t));
static char *inpqstrg __P((const char *, const char **));
static const char *inpname __P((const char *, const char **));
static int getfnidx __P((const char *));
static void inperr(void);
static void setsrc(const char *);
static void setfnid(int, const char *);
static void funccall(pos_t *, const char *);
static void decldef(pos_t *, const char *);
static void usedsym(pos_t *, const char *);
static u_short inptype(const char *, const char **);
static int gettlen(const char *, const char **);
static u_short findtype(const char *, size_t, int);
static u_short storetyp(type_t *, const char *, size_t, int);
static int thash(const char *, size_t);
static char *inpqstrg(const char *, const char **);
static const char *inpname(const char *, const char **);
static int getfnidx(const char *);
void
readfile(name)
const char *name;
readfile(const char *name)
{
FILE *inp;
size_t len;
const char *cp;
char *line, *eptr, rt;
char *line, *eptr, rt = '\0';
int cline, isrc, iline;
pos_t pos;
@ -122,6 +124,8 @@ readfile(name)
if ((thtab = calloc(THSHSIZ2, sizeof (thtab_t))) == NULL)
nomem();
_inithash(&renametab);
srcfile = getfnidx(name);
if ((inp = fopen(name, "r")) == NULL)
@ -198,6 +202,8 @@ readfile(name)
}
_destroyhash(renametab);
if (ferror(inp))
err(1, "read error on %s", name);
@ -206,8 +212,9 @@ readfile(name)
static void
inperr()
inperr(void)
{
errx(1, "input file error: %s", fnames[srcfile]);
}
@ -216,23 +223,22 @@ inperr()
* currently read.
*/
static void
setsrc(cp)
const char *cp;
setsrc(const char *cp)
{
csrcfile = getfnidx(cp);
}
/*
* setfnid() gets as input an index as used in an input file and the
* associated file name. If neccessary, it creates a new lint2 file
* associated file name. If necessary, it creates a new lint2 file
* name index for this file name and creates the mapping of the index
* as used in the input file to the index used in lint2.
*/
static void
setfnid(fid, cp)
int fid;
const char *cp;
setfnid(int fid, const char *cp)
{
if (fid == -1)
inperr();
@ -256,15 +262,14 @@ setfnid(fid, cp)
* Process a function call record (c-record).
*/
static void
funccall(posp, cp)
pos_t *posp;
const char *cp;
funccall(pos_t *posp, const char *cp)
{
arginf_t *ai, **lai;
char c, *eptr;
int rused, rdisc;
hte_t *hte;
fcall_t *fcall;
const char *name;
fcall = xalloc(sizeof (fcall_t));
STRUCT_ASSIGN(fcall->f_pos, *posp);
@ -318,7 +323,14 @@ funccall(posp, cp)
fcall->f_rdisc = rdisc;
/* read name of function */
hte = hsearch(inpname(cp, &cp), 1);
name = inpname(cp, &cp);
/* first look it up in the renaming table, then in the normal table */
hte = _hsearch(renametab, name, 0);
if (hte != NULL)
hte = hte->h_hte;
else
hte = hsearch(name, 1);
hte->h_used = 1;
fcall->f_type = inptype(cp, &cp);
@ -334,14 +346,13 @@ funccall(posp, cp)
* Process a declaration or definition (d-record).
*/
static void
decldef(posp, cp)
pos_t *posp;
const char *cp;
decldef(pos_t *posp, const char *cp)
{
sym_t *symp, sym;
char c, *ep;
int used;
hte_t *hte;
char c, *ep, *pos1;
int used, renamed;
hte_t *hte, *renamehte = NULL;
const char *name, *rename;
(void)memset(&sym, 0, sizeof (sym));
STRUCT_ASSIGN(sym.s_pos, *posp);
@ -419,8 +430,35 @@ decldef(posp, cp)
}
}
/* read symbol name */
hte = hsearch(inpname(cp, &cp), 1);
/* read symbol name, doing renaming if necessary */
name = inpname(cp, &cp);
renamed = 0;
if (*cp == 'r') {
cp++;
name = xstrdup(name);
rename = inpname(cp, &cp);
/* enter it and see if it's already been renamed */
renamehte = _hsearch(renametab, name, 1);
if (renamehte->h_hte == NULL) {
hte = hsearch(rename, 1);
renamehte->h_hte = hte;
renamed = 1;
} else if (strcmp((hte = renamehte->h_hte)->h_name, rename)) {
pos1 = xstrdup(mkpos(&renamehte->h_syms->s_pos));
/* %s renamed multiple times\t%s :: %s */
msg(18, name, pos1, mkpos(&sym.s_pos));
free(pos1);
}
free((char *)name);
} else {
/* it might be a previously-done rename */
hte = _hsearch(renametab, name, 0);
if (hte != NULL)
hte = hte->h_hte;
else
hte = hsearch(name, 1);
}
hte->h_used |= used;
if (sym.s_def == DEF || sym.s_def == TDEF)
hte->h_def = 1;
@ -456,6 +494,10 @@ decldef(posp, cp)
}
*hte->h_lsym = symp;
hte->h_lsym = &symp->s_nxt;
/* XXX hack so we can remember where a symbol was renamed */
if (renamed)
renamehte->h_syms = symp;
}
if (*cp != '\0')
@ -466,12 +508,11 @@ decldef(posp, cp)
* Read an u-record (emited by lint1 if a symbol was used).
*/
static void
usedsym(posp, cp)
pos_t *posp;
const char *cp;
usedsym(pos_t *posp, const char *cp)
{
usym_t *usym;
hte_t *hte;
const char *name;
usym = xalloc(sizeof (usym_t));
STRUCT_ASSIGN(usym->u_pos, *posp);
@ -480,7 +521,12 @@ usedsym(posp, cp)
if (*cp++ != 'x')
inperr();
hte = hsearch(inpname(cp, &cp), 1);
name = inpname(cp, &cp);
hte = _hsearch(renametab, name, 0);
if (hte != NULL)
hte = hte->h_hte;
else
hte = hsearch(name, 1);
hte->h_used = 1;
*hte->h_lusym = usym;
@ -491,13 +537,12 @@ usedsym(posp, cp)
* Read a type and return the index of this type.
*/
static u_short
inptype(cp, epp)
const char *cp, **epp;
inptype(const char *cp, const char **epp)
{
char c, s, *eptr;
const char *ep;
type_t *tp;
int narg, i, osdef;
int narg, i, osdef = 0;
size_t tlen;
u_short tidx;
int h;
@ -608,8 +653,6 @@ inptype(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
case '0':
break;
case '1':
tp->t_istag = 1;
tp->t_tag = hsearch(inpname(cp, &cp), 1);
@ -618,10 +661,42 @@ inptype(cp, epp)
tp->t_istynam = 1;
tp->t_tynam = hsearch(inpname(cp, &cp), 1);
break;
case '3':
tp->t_isuniqpos = 1;
tp->t_uniqpos.p_line = strtol(cp, &eptr, 10);
cp = eptr;
cp++;
/* xlate to 'global' file name. */
tp->t_uniqpos.p_file =
addoutfile(inpfns[strtol(cp, &eptr, 10)]);
cp = eptr;
cp++;
tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10);
cp = eptr;
break;
}
break;
/* LINTED (enumeration value(s) not handled in switch) */
default:
case LONG:
case VOID:
case LDOUBLE:
case DOUBLE:
case FLOAT:
case UQUAD:
case QUAD:
case ULONG:
case UINT:
case INT:
case USHORT:
case SHORT:
case UCHAR:
case SCHAR:
case CHAR:
case UNSIGN:
case SIGNED:
case NOTSPEC:
break;
case NTSPEC:
abort();
}
*epp = cp;
@ -632,8 +707,7 @@ inptype(cp, epp)
* Get the length of a type string.
*/
static int
gettlen(cp, epp)
const char *cp, **epp;
gettlen(const char *cp, const char **epp)
{
const char *cp1;
char c, s, *eptr;
@ -778,20 +852,56 @@ gettlen(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
case '0':
break;
case '1':
(void)inpname(cp, &cp);
break;
case '2':
(void)inpname(cp, &cp);
break;
case '3':
/* unique position: line.file.uniquifier */
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
if (*cp++ != '.')
inperr();
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
if (*cp++ != '.')
inperr();
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
break;
default:
inperr();
}
break;
/* LINTED (enumeration value(s) not handled in switch) */
default:
case FLOAT:
case USHORT:
case SHORT:
case UCHAR:
case SCHAR:
case CHAR:
case UNSIGN:
case SIGNED:
case NOTSPEC:
case INT:
case UINT:
case DOUBLE:
case LDOUBLE:
case VOID:
case ULONG:
case QUAD:
case UQUAD:
case LONG:
break;
case NTSPEC:
abort();
}
*epp = cp;
@ -802,10 +912,7 @@ gettlen(cp, epp)
* Search a type by it's type string.
*/
static u_short
findtype(cp, len, h)
const char *cp;
size_t len;
int h;
findtype(const char *cp, size_t len, int h)
{
thtab_t *thte;
@ -824,14 +931,9 @@ findtype(cp, len, h)
* if we read the same type string from the input file.
*/
static u_short
storetyp(tp, cp, len, h)
type_t *tp;
const char *cp;
size_t len;
int h;
storetyp(type_t *tp, const char *cp, size_t len, int h)
{
/* 0 ist reserved */
static u_int tidx = 1;
static u_int tidx = 1; /* 0 is reserved */
thtab_t *thte;
char *name;
@ -866,9 +968,7 @@ storetyp(tp, cp, len, h)
* Hash function for types
*/
static int
thash(s, len)
const char *s;
size_t len;
thash(const char *s, size_t len)
{
u_int v;
@ -884,8 +984,7 @@ thash(s, len)
* Read a string enclosed by "". This string may contain quoted chars.
*/
static char *
inpqstrg(src, epp)
const char *src, **epp;
inpqstrg(const char *src, const char **epp)
{
char *strg, *dst;
size_t slen;
@ -912,11 +1011,7 @@ inpqstrg(src, epp)
c = '\t';
break;
case 'v':
#ifdef __STDC__
c = '\v';
#else
c = '\013';
#endif
break;
case 'b':
c = '\b';
@ -928,11 +1023,7 @@ inpqstrg(src, epp)
c = '\f';
break;
case 'a':
#ifdef __STDC__
c = '\a';
#else
c = '\007';
#endif
break;
case '\\':
c = '\\';
@ -978,8 +1069,7 @@ inpqstrg(src, epp)
* Read the name of a symbol in static memory.
*/
static const char *
inpname(cp, epp)
const char *cp, **epp;
inpname(const char *cp, const char **epp)
{
static char *buf;
static size_t blen = 0;
@ -995,7 +1085,7 @@ inpname(cp, epp)
nomem();
for (i = 0; i < len; i++) {
c = *cp++;
if (!isalnum(c) && c != '_')
if (!isalnum((unsigned char)c) && c != '_')
inperr();
buf[i] = c;
}
@ -1010,8 +1100,7 @@ inpname(cp, epp)
* a new entry and return the index of the newly created entry.
*/
static int
getfnidx(fn)
const char *fn;
getfnidx(const char *fn)
{
int i;
@ -1040,8 +1129,7 @@ getfnidx(fn)
* Separate symbols with static and external linkage.
*/
void
mkstatic(hte)
hte_t *hte;
mkstatic(hte_t *hte)
{
sym_t *sym1, **symp, *sym;
fcall_t **callp, *call;
@ -1085,16 +1173,22 @@ mkstatic(hte)
* XXX this entry should be put at the beginning of the list to
* avoid to process the same symbol twice.
*/
for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link) ;
nhte->h_link = xalloc(sizeof (hte_t));
for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link)
continue;
nhte->h_link = xmalloc(sizeof (hte_t));
nhte = nhte->h_link;
nhte->h_name = hte->h_name;
nhte->h_static = 1;
nhte->h_used = 1;
nhte->h_def = 1; /* error in lint1 */
nhte->h_static = 1;
nhte->h_syms = NULL;
nhte->h_lsym = &nhte->h_syms;
nhte->h_calls = NULL;
nhte->h_lcall = &nhte->h_calls;
nhte->h_usyms = NULL;
nhte->h_lusym = &nhte->h_usyms;
nhte->h_link = NULL;
nhte->h_hte = NULL;
/*
* move all symbols used in this translation unit into the new

View File

@ -1,22 +1,25 @@
# $NetBSD: Makefile,v 1.2 1995/07/03 21:25:05 cgd Exp $
# $NetBSD: Makefile,v 1.7 2000/06/14 20:22:19 matt Exp $
# $FreeBSD$
.include <bsd.own.mk>
LIBS= llib-lposix.ln llib-lstdc.ln
LINT= ${.OBJDIR}/../xlint/xlint
all: ${LIBS}
.if ${MKLINT} != "no"
FILES= ${LIBS}
FILESDIR= ${LINTLIBDIR}
install:
${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${LIBMODE} \
${LIBS} ${DESTDIR}${LINTLIBDIR}
clean cleanall:
rm -f ${LIBS}
CLEANFILES+= ${LIBS}
llib-lposix.ln: llib-lposix
${LINT} -Cposix ${.ALLSRC}
${LINT} ${LINTFLAGS} -Cposix ${.ALLSRC}
llib-lstdc.ln: llib-lstdc
${LINT} -Cstdc ${.ALLSRC}
${LINT} ${LINTFLAGS} -Cstdc ${.ALLSRC}
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: llib-lstdc,v 1.3 1995/07/03 21:39:28 cgd Exp $ */
/* $NetBSD: llib-lstdc,v 1.2 1995/07/03 21:25:11 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl

View File

@ -1,5 +1,6 @@
.\" $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $
.\" $NetBSD: lint.1,v 1.20 2001/12/08 19:27:56 wiz Exp $
.\"
.\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
.\" Copyright (c) 1994, 1995 Jochen Pohl
.\" All Rights Reserved.
.\"
@ -31,40 +32,82 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 28, 1994
.Dd May 24, 2001
.Dt LINT 1
.Os
.Sh NAME
.Nm lint
.Nd a C program verifier
.Sh SYNOPSIS
.Nm
.Op Fl abceghprvwxzHFV
.Bk -words
.Op Fl s | Fl t
.Ek
.Bk -words
.Op Fl i | Fl nu
.Ek
.Bk -words
.Op Fl D Ar name Ns Op =def
.Ek
.Bk -words
.Nm
.Op Fl abceghprvxzHFV
.Op Fl s | t
.Op Fl i | nu
.Op Fl D Ar name Ns Op = Ns Ar def
.Op Fl U Ar name
.Ek
.Bk -words
.Op Fl I Ar directory
.Ek
.Bk -words
.Op Fl d Ar directory
.Ek
.Bk -words
.Op Fl L Ar directory
.Ek
.Bk -words
.Op Fl l Ar library
.Ek
.Bk -words
.Op Fl o Ar outputfile
.Ek
.Bk -words
.Op Fl B Ar directory
.Ek
.Bk -words
.Op Fl X Ar id Ns Op ,id ...
.Ek
.Ar
.Nm
.Op Fl abceghprvzHFV
.Op Fl s | t
.Nm lint
.Op Fl abceghprvwzHFV
.Bk -words
.Op Fl s | Fl t
.Ek
.Bk -words
.Fl C Ar library
.Op Fl D Ar name Ns Op = Ns Ar def
.Op Fl I Ar directory
.Ek
.Bk -words
.Op Fl D Ar name Ns Op =def
.Ek
.Bk -words
.Op Fl U Ar name
.Ek
.Bk -words
.Op Fl I Ar directory
.Ek
.Bk -words
.Op Fl d Ar directory
.Ek
.Bk -words
.Op Fl B Ar directory
.Ek
.Bk -words
.Op Fl X Ar id Ns Op ,id ...
.Ek
.Ar
.Ek
.Sh DESCRIPTION
.Nm
attempts to detect features of the named C program files
that are likely to be bugs, to be non-portable, or to be
wasteful.
It also performs stricter type checking than
wasteful. It also performs stricter type checking than does
the C compiler.
.Nm
runs the C preprocessor as its first phase, with the
@ -75,7 +118,7 @@ or skipped by
.Nm .
Therefore, this symbol should be thought of as a reserved
word for all code that is to be checked by
.Nm .
.Nm "" .
.Pp
Among the possible problems that are currently noted are
unreachable statements, loops not entered at the top,
@ -97,7 +140,7 @@ Filename arguments with
names ending with
.Pa .ln
are taken to be the result of an earlier invocation of
.Nm ,
.Nm "" ,
with either the
.Fl i , o ,
or
@ -153,8 +196,24 @@ if a complaint stems not from a given source file, but from one of
its included files, the source filename will be printed followed by
a question mark.
.Pp
The options are as follows:
.Bl -tag -width indent
The special input file name
.Dq Pa -
causes
.Nm
to take input from standard input (until end of file) and process
it as if it were a
.Pa \&.c
file.
If the
.Fl i
flag is given and
.Dq Pa -
is named as one of the input files, the
.Fl o
flag must also be specified to provide an output file name.
.Pp
.Sy Options
.Bl -tag -width Fl
.It Fl a
Report assignments of
.Vt long
@ -185,13 +244,16 @@ Complain about unusual operations on
and combinations of
.Vt enum Ns -
and
.Vt int Ns eger-Types .
.Sy integer Ns -Types .
.It Fl g
Don't print warnings for some extensions of
.Xr gcc 1
to the C language.
Currently these are nonconstant initializers in
automatic aggregate initializations, arithmetic on pointer to void,
trailing commas in enum declarations, C++ -style
.Dq //
comments,
zero sized structures, subscripting of non-lvalue arrays, prototypes
overriding old style function declarations and long long
integer types.
@ -200,9 +262,9 @@ The
flag also turns on the keywords
.Ic asm
and
.Ic inline
(alternate keywords with leading underscores for both
.Ic asm
.Sy inline
(alternative keywords with leading underscores for both
.Sy asm
and
.Ic inline
are always available).
@ -218,7 +280,7 @@ file on the command line.
These
.Pa .ln
files are the product of
.Nm Ns 's
.Nm "" Ns 's
first pass only, and are not checked for compatibility
between functions.
.It Fl n
@ -255,8 +317,8 @@ are defined without leading and trailing underscores.
The keywords
.Ic const , volatile
and
.Ic signed
are not available in traditional C mode (although the alternate
.Sy signed
are not available in traditional C mode (although the alternative
keywords with leading underscores still are).
.It Fl u
Do not complain about functions and external variables used
@ -268,13 +330,16 @@ on a subset of files comprising part of a larger program).
Suppress complaints about unused arguments in functions.
.It Fl x
Report variables referred to by
.Ic extern
.Sy extern
declarations, but never used.
.It Fl z
Do not complain about structures that are never defined
(for example, using a structure pointer without knowing
its contents).
.It Fl C Ar library
.It Fl B Ns Ar path
Path to use when looking for the lint1 and lint2 binaries. Defualts to
.Pa /usr/libexec .
.It Fl C Ns Ar library
Create a
.Nm
library with the name
@ -305,7 +370,11 @@ is defined as 1.
Add
.Ar directory
to the list of directories in which to search for include files.
.It Fl l Ar library
.It Fl d Ns Ar directory
Use
.Ar directory
instead of /usr/include as the default place to find include files.
.It Fl l Ns Ar library
Include the lint library
.Pa llib-l Ns Ar library Ns Pa .ln .
.It Fl L Ar directory
@ -327,9 +396,8 @@ followed by a question mark.
Name the output file
.Ar outputfile .
The output file produced is the input that is given to
.Nm Ns 's
second pass.
The
.Nm "" Ns 's
second pass. The
.Fl o
option simply saves this file in the named output file.
If the
@ -351,11 +419,19 @@ for the preprocessor.
.It Fl V
Print the command lines constructed by the controller program to
run the C preprocessor and
.Nm Ns 's
.Nm "" Ns 's
first and second pass.
.It Fl w
Treat warnings as errors.
.It Fl X Ar id Ns Op ,id ...
Suppress error messages identified by the list of ids. A list of messages
and ids can be found in
.Xr lint 7 .
.El
.Ss Input Grammar
.Nm Ns 's
.Pp
.Sy Input Grammar
.Pp
.Nm "" Ns 's
first pass reads standard C source files.
.Nm
recognizes the following C comments as commands.
@ -370,11 +446,11 @@ arguments for usage; a missing
is taken to be 0 (this option acts like the
.Fl v
option for the next function).
.It Xo
.Li /* CONSTCOND */
or
.Li /* CONSTANTCOND */
or
.It Li /* BITFIELDTYPE */
Suppress error messages about illegal bitfield types if the type
is an integer type, and suppress non-portable bitfield type warnings.
.It Li /* CONSTCOND */ No or Xo
.Li /* CONSTANTCOND */ No or
.Li /* CONSTANTCONDITION */
.Xc
suppress complaints about constant operands for the next expression.
@ -401,11 +477,8 @@ or
.Li /* NOSTRICT Oo Ar comment Oc Li */
.Xc
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
.Nm
warning occurred.
unused variables or functions. This directive should be placed
on the line immediately preceding where the lint warning occurred.
.It Li /* LONGLONG */
Suppress complaints about use of long long integer types.
.It Li /* NOTREACHED */
@ -479,7 +552,7 @@ file, and prints all messages that are about just that
source file.
After all the source files have been separately
run through
.Nm ,
.Nm "" ,
it is invoked once more (without the
.Fl i
option), listing all the
@ -497,7 +570,7 @@ to be used to
.Nm
only the source files that have been modified since the last
time the set of source files were
.Nm Ns ed .
.Nm "" Ns No ed .
.Sh ENVIRONMENT
.Bl -tag -width LIBDIR
.It Ev LIBDIR
@ -513,6 +586,9 @@ will be used to search for the libraries.
.It Ev TMPDIR
usually the path for temporary files can be redefined by setting
this environment variable.
.It Ev CC
Location of the C compiler program. Defaults to
.Pa /usr/bin/cc .
.El
.Sh FILES
.Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact

View File

@ -1,4 +1,4 @@
/* $NetBSD: pathnames.h,v 1.2 1995/07/03 21:25:20 cgd Exp $ */
/* $NetBSD: pathnames.h,v 1.3 1999/04/22 04:40:58 mrg Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -34,7 +34,12 @@
*/
/* directory where lint1 and lint2 reside */
#ifndef PATH_LIBEXEC
#define PATH_LIBEXEC "/usr/libexec"
#endif
/* directory where cc(1) resides */
#define PATH_USRBIN "/usr/bin"
/* directory where cc(1) resides */
#define PATH_USRBIN "/usr/bin"

View File

@ -1,6 +1,7 @@
/* $NetBSD: xlint.c,v 1.3 1995/10/23 14:29:30 jpo Exp $ */
/* $NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -31,35 +32,37 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $");
#endif
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <paths.h>
#include "lint.h"
#include "pathnames.h"
int main(int, char *[]);
/* directory for temporary files */
static const char *tmpdir;
/* path name for cpp output */
static char *cppout;
/* filedescriptor for cpp output */
/* file descriptor for cpp output */
static int cppoutfd = -1;
/* files created by 1st pass */
@ -95,8 +98,10 @@ static char **libs;
/* search path for libraries */
static char **libsrchpath;
static char *libexec_path;
/* flags */
static int iflag, oflag, Cflag, sflag, tflag, Fflag;
static int iflag, oflag, Cflag, sflag, tflag, Fflag, dflag, Bflag;
/* print the commands executed to run the stages of compilation */
static int Vflag;
@ -113,88 +118,81 @@ static int first = 1;
*/
static const char *currfn;
#if !defined(TARGET_PREFIX)
#define TARGET_PREFIX ""
#endif
static const char target_prefix[] = TARGET_PREFIX;
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 *,
int));
static void findlibs __P((char *const *));
static int rdok __P((const char *));
static void lint2 __P((void));
static void cat __P((char *const *, const char *));
static void appstrg(char ***, char *);
static void appcstrg(char ***, const char *);
static void applst(char ***, char *const *);
static void freelst(char ***);
static char *concat2(const char *, const char *);
static char *concat3(const char *, const char *, const char *);
static void terminate(int) __attribute__((__noreturn__));
static const char *lbasename(const char *, int);
static void appdef(char ***, const char *);
static void usage(void);
static void fname(const char *);
static void runchild(const char *, char *const *, const char *, int);
static void findlibs(char *const *);
static int rdok(const char *);
static void lint2(void);
static void cat(char *const *, const char *);
/*
* Some functions to deal with lists of strings.
* Take care that we get no surprises in case of asyncron signals.
*/
static void
appstrg(lstp, s)
char ***lstp, *s;
appstrg(char ***lstp, char *s)
{
char **lst, **olst;
int i;
olst = *lstp;
for (i = 0; olst[i] != NULL; i++) ;
if ((lst = malloc((i + 2) * sizeof (char *))) == NULL)
nomem();
(void)memcpy(lst, olst, i * sizeof (char *));
for (i = 0; olst[i] != NULL; i++)
continue;
lst = xrealloc(olst, (i + 2) * sizeof (char *));
lst[i] = s;
lst[i + 1] = NULL;
*lstp = lst;
}
static void
appcstrg(lstp, s)
char ***lstp;
const char *s;
{
char *p;
if ((p = strdup(s)) == NULL)
nomem();
appstrg(lstp, p);
}
static void
applst(destp, src)
char ***destp;
char *const *src;
appcstrg(char ***lstp, const char *s)
{
appstrg(lstp, xstrdup(s));
}
static void
applst(char ***destp, char *const *src)
{
int i, k;
char **dest, **odest;
odest = *destp;
for (i = 0; odest[i] != NULL; i++) ;
for (k = 0; src[k] != NULL; k++) ;
if ((dest = malloc((i + k + 1) * sizeof (char *))) == NULL)
nomem();
(void)memcpy(dest, odest, i * sizeof (char *));
for (i = 0; odest[i] != NULL; i++)
continue;
for (k = 0; src[k] != NULL; k++)
continue;
dest = xrealloc(odest, (i + k + 1) * sizeof (char *));
for (k = 0; src[k] != NULL; k++)
if ((dest[i + k] = strdup(src[k])) == NULL)
nomem();
dest[i + k] = NULL;
*destp = dest;
free(odest);
}
static void
freelst(lstp)
char ***lstp;
freelst(char ***lstp)
{
char *s;
int i;
for (i = 0; (*lstp)[i] != NULL; i++) ;
for (i = 0; (*lstp)[i] != NULL; i++)
continue;
while (i-- > 0) {
s = (*lstp)[i];
(*lstp)[i] = NULL;
@ -203,8 +201,7 @@ freelst(lstp)
}
static char *
concat2(s1, s2)
const char *s1, *s2;
concat2(const char *s1, const char *s2)
{
char *s;
@ -217,8 +214,7 @@ concat2(s1, s2)
}
static char *
concat3(s1, s2, s3)
const char *s1, *s2, *s3;
concat3(const char *s1, const char *s2, const char *s3)
{
char *s;
@ -235,8 +231,7 @@ concat3(s1, s2, s3)
* Clean up after a signal.
*/
static void
terminate(signo)
int signo;
terminate(int signo)
{
int i;
@ -264,9 +259,7 @@ terminate(signo)
* Returns strg if the string does not contain delim.
*/
static const char *
basename(strg, delim)
const char *strg;
int delim;
lbasename(const char *strg, int delim)
{
const char *cp, *cp1, *cp2;
@ -281,34 +274,41 @@ basename(strg, delim)
}
static void
appdef(lstp, def)
char ***lstp;
const char *def;
appdef(char ***lstp, const char *def)
{
appstrg(lstp, concat2("-D__", def));
appstrg(lstp, concat3("-D__", def, "__"));
}
static void
usage()
usage(void)
{
(void)printf("lint [-abceghprvxzHF] [-s|-t] [-i|-nu] [-Dname[=def]] [-Uname]\n");
(void)printf(" [-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile] file ...\n");
(void)printf("\n");
(void)printf("lint [-abceghprvzHF] [-s|-t] -Clibrary [-Dname[=def]]\n");
(void)printf(" [-Idirectory] [-Uname] file ...\n");
(void)fprintf(stderr,
"Usage: %s [-abceghprvwxzHF] [-s|-t] [-i|-nu] [-Dname[=def]]"
" [-Uname] [-X <id>[,<id>]...\n", getprogname());
(void)fprintf(stderr,
"\t[-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile]"
" file...\n");
(void)fprintf(stderr,
" %s [-abceghprvwzHF] [-s|-t] -Clibrary [-Dname[=def]]\n"
" [-X <id>[,<id>]...\n", getprogname());
(void)fprintf(stderr, "\t[-Idirectory] [-Uname] [-Bpath] file"
" ...\n");
terminate(-1);
}
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int c;
char flgbuf[3], *tmp, *s;
size_t len;
setprogname(argv[0]);
if ((tmp = getenv("TMPDIR")) == NULL || (len = strlen(tmp)) == 0) {
if ((tmpdir = strdup(_PATH_TMP)) == NULL)
nomem();
@ -328,34 +328,30 @@ main(argc, argv)
terminate(-1);
}
if ((p1out = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((p2in = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((cflags = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((lcflags = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((l1flags = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((l2flags = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((l2libs = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((deflibs = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((libs = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((libsrchpath = calloc(1, sizeof (char *))) == NULL)
nomem();
p1out = xcalloc(1, sizeof (char *));
p2in = xcalloc(1, sizeof (char *));
cflags = xcalloc(1, sizeof (char *));
lcflags = xcalloc(1, sizeof (char *));
l1flags = xcalloc(1, sizeof (char *));
l2flags = xcalloc(1, sizeof (char *));
l2libs = xcalloc(1, sizeof (char *));
deflibs = xcalloc(1, sizeof (char *));
libs = xcalloc(1, sizeof (char *));
libsrchpath = xcalloc(1, sizeof (char *));
appcstrg(&cflags, "-E");
appcstrg(&cflags, "-x");
appcstrg(&cflags, "c");
#if 0
appcstrg(&cflags, "-D__attribute__(x)=");
appcstrg(&cflags, "-D__extension__(x)=/*NOSTRICT*/0");
#else
appcstrg(&cflags, "-U__GNUC__");
#endif
appcstrg(&cflags, "-Wp,-$");
appcstrg(&cflags, "-Wp,-Cc");
appcstrg(&cflags, "-Wp,-CC");
appcstrg(&cflags, "-Wcomment");
appcstrg(&cflags, "-D__LINT__");
appcstrg(&cflags, "-Dlint"); /* XXX don't def. with -s */
appdef(&cflags, "lint");
@ -370,14 +366,7 @@ main(argc, argv)
(void)signal(SIGQUIT, terminate);
(void)signal(SIGTERM, terminate);
while (argc > optind) {
argc -= optind;
argv += optind;
optind = 0;
c = getopt(argc, argv, "abceghil:no:prstuvxzC:D:FHI:L:U:V");
while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:U:VX:")) != -1) {
switch (c) {
case 'a':
@ -387,6 +376,7 @@ main(argc, argv)
case 'g':
case 'r':
case 'v':
case 'w':
case 'z':
(void)sprintf(flgbuf, "-%c", c);
appcstrg(&l1flags, flgbuf);
@ -402,6 +392,12 @@ main(argc, argv)
appcstrg(&l2flags, flgbuf);
break;
case 'X':
(void)sprintf(flgbuf, "-%c", c);
appcstrg(&l1flags, flgbuf);
appcstrg(&l1flags, optarg);
break;
case 'i':
if (Cflag)
usage();
@ -434,19 +430,19 @@ main(argc, argv)
sflag = 1;
break;
#if !HAVE_CONFIG_H
case 't':
if (sflag)
usage();
freelst(&lcflags);
appcstrg(&lcflags, "-traditional");
appstrg(&lcflags, concat2("-D", MACHINE));
#ifdef MACHINE_ARCH
appstrg(&lcflags, concat2("-D", MACHINE_ARCH));
#endif
appcstrg(&l1flags, "-t");
appcstrg(&l2flags, "-t");
tflag = 1;
break;
#endif
case 'x':
appcstrg(&l2flags, "-x");
@ -464,6 +460,15 @@ main(argc, argv)
freelst(&deflibs);
break;
case 'd':
if (dflag)
usage();
dflag = 1;
appcstrg(&cflags, "-nostdinc");
appcstrg(&cflags, "-idirafter");
appcstrg(&cflags, optarg);
break;
case 'D':
case 'I':
case 'U':
@ -491,21 +496,64 @@ main(argc, argv)
appcstrg(&l2flags, "-H");
break;
case 'B':
Bflag = 1;
libexec_path = xstrdup(optarg);
break;
case 'V':
Vflag = 1;
break;
case '?':
default:
usage();
/* NOTREACHED */
case -1:
/* filename */
fname(argv[0], argc == 1);
first = 0;
optind = 1;
}
}
argc -= optind;
argv += optind;
/*
* To avoid modifying getopt(3)'s state engine midstream, we
* explicitly accept just a few options after the first source file.
*
* In particular, only -l<lib> and -L<libdir> (and these with a space
* after -l or -L) are allowed.
*/
while (argc > 0) {
const char *arg = argv[0];
if (arg[0] == '-') {
char ***list;
/* option */
switch (arg[1]) {
case 'l':
list = &libs;
break;
case 'L':
list = &libsrchpath;
break;
default:
usage();
/* NOTREACHED */
}
if (arg[2])
appcstrg(list, arg + 2);
else if (argc > 1) {
argc--;
appcstrg(list, *++argv);
} else
usage();
} else {
/* filename */
fname(arg);
first = 0;
}
argc--;
argv++;
}
if (first)
@ -541,17 +589,17 @@ main(argc, argv)
* and pass it through lint1 if it is a C source.
*/
static void
fname(name, last)
const char *name;
int last;
fname(const char *name)
{
const char *bn, *suff;
char **args, *ofn, *path;
size_t len;
int is_stdin;
int fd;
bn = basename(name, '/');
suff = basename(bn, '.');
is_stdin = (strcmp(name, "-") == 0);
bn = lbasename(name, '/');
suff = lbasename(bn, '.');
if (strcmp(suff, "ln") == 0) {
/* only for lint2 */
@ -560,14 +608,15 @@ fname(name, last)
return;
}
if (strcmp(suff, "c") != 0 &&
if (!is_stdin && strcmp(suff, "c") != 0 &&
(strncmp(bn, "llib-l", 6) != 0 || bn != suff)) {
warnx("unknown file type: %s\n", name);
return;
}
if (!iflag || !first || !last)
(void)printf("%s:\n", Fflag ? name : bn);
if (!iflag || !first)
(void)printf("%s:\n",
is_stdin ? "{standard input}" : Fflag ? name : bn);
/* build the name of the output file of lint1 */
if (oflag) {
@ -575,8 +624,11 @@ fname(name, last)
outputfn = NULL;
oflag = 0;
} else if (iflag) {
if ((ofn = malloc(strlen(bn) + (bn == suff ? 4 : 2))) == NULL)
nomem();
if (is_stdin) {
warnx("-i not supported without -o for standard input");
return;
}
ofn = xmalloc(strlen(bn) + (bn == suff ? 4 : 2));
len = bn == suff ? strlen(bn) : (suff - 1) - bn;
(void)sprintf(ofn, "%.*s", (int)len, bn);
(void)strcat(ofn, ".ln");
@ -600,9 +652,12 @@ fname(name, last)
/* run cc */
if ((path = malloc(strlen(PATH_USRBIN) + sizeof ("/cc"))) == NULL)
nomem();
(void)sprintf(path, "%s/cc", PATH_USRBIN);
if (getenv("CC") == NULL) {
path = xmalloc(strlen(PATH_USRBIN) + sizeof ("/cc"));
(void)sprintf(path, "%s/cc", PATH_USRBIN);
} else {
path = strdup(getenv("CC"));
}
appcstrg(&args, path);
applst(&args, cflags);
@ -625,9 +680,19 @@ fname(name, last)
/* run lint1 */
if ((path = malloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1"))) == NULL)
nomem();
(void)sprintf(path, "%s/lint1", PATH_LIBEXEC);
if (!Bflag) {
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") +
strlen(target_prefix));
(void)sprintf(path, "%s/%slint1", PATH_LIBEXEC,
target_prefix);
} else {
/*
* XXX Unclear whether we should be using target_prefix
* XXX here. --thorpej@wasabisystems.com
*/
path = xmalloc(strlen(libexec_path) + sizeof ("/lint1"));
(void)sprintf(path, "%s/lint1", libexec_path);
}
appcstrg(&args, path);
applst(&args, l1flags);
@ -645,10 +710,7 @@ fname(name, last)
}
static void
runchild(path, args, crfn, fdout)
const char *path, *crfn;
char *const *args;
int fdout;
runchild(const char *path, char *const *args, const char *crfn, int fdout)
{
int status, rv, signo, i;
@ -678,7 +740,7 @@ runchild(path, args, crfn, fdout)
dup2(fdout, STDOUT_FILENO);
close(fdout);
}
(void)execv(path, args);
(void)execvp(path, args);
warn("cannot exec %s", path);
_exit(1);
/* NOTREACHED */
@ -691,7 +753,11 @@ runchild(path, args, crfn, fdout)
}
if (WIFSIGNALED(status)) {
signo = WTERMSIG(status);
#if HAVE_DECL_SYS_SIGNAME
warnx("%s got SIG%s", path, sys_signame[signo]);
#else
warnx("%s got signal %d", path, signo);
#endif
terminate(-1);
}
if (WEXITSTATUS(status) != 0)
@ -700,8 +766,7 @@ runchild(path, args, crfn, fdout)
}
static void
findlibs(liblst)
char *const *liblst;
findlibs(char *const *liblst)
{
int i, k;
const char *lib, *path;
@ -737,14 +802,13 @@ findlibs(liblst)
}
static int
rdok(path)
const char *path;
rdok(const char *path)
{
struct stat sbuf;
if (stat(path, &sbuf) == -1)
return (0);
if ((sbuf.st_mode & S_IFMT) != S_IFREG)
if (!S_ISREG(sbuf.st_mode))
return (0);
if (access(path, R_OK) == -1)
return (0);
@ -752,17 +816,27 @@ rdok(path)
}
static void
lint2()
lint2(void)
{
char *path, **args;
if ((args = calloc(1, sizeof (char *))) == NULL)
nomem();
if ((path = malloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2"))) == NULL)
nomem();
(void)sprintf(path, "%s/lint2", PATH_LIBEXEC);
if (!Bflag) {
path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2") +
strlen(target_prefix));
(void)sprintf(path, "%s/%slint2", PATH_LIBEXEC,
target_prefix);
} else {
/*
* XXX Unclear whether we should be using target_prefix
* XXX here. --thorpej@wasabisystems.com
*/
path = xmalloc(strlen(libexec_path) + sizeof ("/lint2"));
(void)sprintf(path, "%s/lint2", libexec_path);
}
appcstrg(&args, path);
applst(&args, l2flags);
applst(&args, l2libs);
@ -775,9 +849,7 @@ lint2()
}
static void
cat(srcs, dest)
char *const *srcs;
const char *dest;
cat(char *const *srcs, const char *dest)
{
int ifd, ofd, i;
char *src, *buf;
@ -814,4 +886,3 @@ cat(srcs, dest)
(void)close(ofd);
free(buf);
}