1988-09-20 16:44:27 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
|
|
|
/* $Header$ */
|
|
|
|
/* Lint-specific comment handling */
|
|
|
|
|
|
|
|
#include "lint.h"
|
|
|
|
|
|
|
|
#ifdef LINT
|
|
|
|
|
|
|
|
#include "arith.h"
|
|
|
|
#include "l_state.h"
|
|
|
|
|
1988-09-26 11:37:38 +00:00
|
|
|
/* Since the lexical analyser does a one-token look-ahead, pseudo-
|
|
|
|
comments are read too soon. This is remedied by first storing them
|
|
|
|
in static variables and then moving them to the real variables
|
|
|
|
one token later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int notreached;
|
|
|
|
static int varargsN = -1;
|
|
|
|
static int argsused;
|
|
|
|
static check_pseudo();
|
|
|
|
|
|
|
|
int LINTLIB; /* file is lint library */
|
|
|
|
int s_NOTREACHED; /* statement not reached */
|
|
|
|
int f_VARARGSn; /* function with variable # of args */
|
|
|
|
int f_ARGSUSED; /* function does not use all args */
|
1988-09-20 16:44:27 +00:00
|
|
|
|
|
|
|
set_not_reached()
|
|
|
|
{
|
1988-09-26 11:37:38 +00:00
|
|
|
notreached = 1;
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
move_NOT2s()
|
|
|
|
{
|
1988-09-26 11:37:38 +00:00
|
|
|
s_NOTREACHED = notreached;
|
|
|
|
notreached = 0;
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_varargs(n)
|
|
|
|
{
|
1988-09-26 11:37:38 +00:00
|
|
|
varargsN = n;
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
move_VAR2f()
|
|
|
|
{
|
1988-09-26 11:37:38 +00:00
|
|
|
f_VARARGSn = varargsN;
|
|
|
|
varargsN = -1;
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_argsused(n)
|
|
|
|
{
|
1988-09-26 11:37:38 +00:00
|
|
|
argsused = n;
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
move_ARG2f()
|
|
|
|
{
|
1988-09-26 11:37:38 +00:00
|
|
|
f_ARGSUSED = argsused;
|
|
|
|
argsused = 0;
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_lintlib()
|
|
|
|
{
|
|
|
|
LINTLIB = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IN_SPACE 0
|
|
|
|
#define IN_WORD 1
|
|
|
|
#define IN_COMMENT 2
|
|
|
|
|
|
|
|
lint_comment(c)
|
|
|
|
int c;
|
|
|
|
{
|
|
|
|
/* This function is called with every character between /_* and *_/ (the
|
|
|
|
* _underscores are used because comment in C doesn't nest).
|
|
|
|
* It looks for pseudocomments.
|
|
|
|
* In this version it is allowed that 'keyword' is followed by rubbish.
|
|
|
|
* At the start of each comment the function should be initialized by
|
|
|
|
* calling it with c = -2.
|
|
|
|
* I am not sure if this way of information hiding is a good solution.
|
|
|
|
*/
|
|
|
|
static int position; /* IN_SPACE, IN_WORD, IN_COMMENT */
|
|
|
|
static char buf[12];
|
|
|
|
static int i; /* next free position in buf */
|
|
|
|
|
|
|
|
if (c == -2) {
|
|
|
|
position = IN_SPACE;
|
|
|
|
i = 0;
|
|
|
|
return;
|
|
|
|
}
|
1988-09-26 11:37:38 +00:00
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
if (position == IN_COMMENT)
|
|
|
|
return;
|
1988-09-26 11:37:38 +00:00
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
if (position == IN_SPACE) {
|
|
|
|
if (c == ' ' || c == '\t')
|
|
|
|
return;
|
|
|
|
position = IN_WORD;
|
|
|
|
}
|
|
|
|
/* position == IN_WORD */
|
|
|
|
if (c == ' ' || c == '\t' || c == '*') {
|
|
|
|
position = IN_COMMENT;
|
|
|
|
check_pseudo(buf, i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (i < 12)
|
|
|
|
buf[i++] = (char)c;
|
|
|
|
else
|
|
|
|
position = IN_COMMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
1988-09-26 11:37:38 +00:00
|
|
|
static
|
1988-09-20 16:44:27 +00:00
|
|
|
check_pseudo(buf, i)
|
|
|
|
char *buf;
|
|
|
|
{
|
|
|
|
/* Look if the i characters in buf are aequivalent with one of the
|
|
|
|
* strings N_OTREACHED, V_ARARGS[n], A_RGSUSED, L_INTLIBRARY
|
|
|
|
* (the u_nderscores are there to not confuse (UNIX) lint)
|
|
|
|
*/
|
|
|
|
buf[i++] = '\0';
|
1988-09-26 11:37:38 +00:00
|
|
|
if (strcmp(buf, "NOTREACHED") == 0) {
|
1988-09-20 16:44:27 +00:00
|
|
|
set_not_reached();
|
1988-09-26 11:37:38 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(buf, "ARGSUSED") == 0) {
|
1988-09-20 16:44:27 +00:00
|
|
|
set_argsused(1);
|
1988-09-26 11:37:38 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(buf, "LINTLIBRARY") == 0) {
|
1988-09-20 16:44:27 +00:00
|
|
|
set_lintlib();
|
1988-09-26 11:37:38 +00:00
|
|
|
}
|
|
|
|
else if (strncmp(buf, "VARARGS", 7) == 0) {
|
|
|
|
if (i == 8) {
|
1988-09-20 16:44:27 +00:00
|
|
|
set_varargs(0);
|
1988-09-26 11:37:38 +00:00
|
|
|
}
|
|
|
|
else if (i == 9 && isdigit(buf[7])) {
|
1988-09-20 16:44:27 +00:00
|
|
|
set_varargs(atoi(&buf[7]));
|
1988-09-26 11:37:38 +00:00
|
|
|
}
|
1988-09-20 16:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif LINT
|