2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: l_comment.c,v 1.3 1994/06/27 08:00:38 ceriel Exp $ */
6 /* Lint-specific comment handling */
15 #include "interface.h"
18 #include "l_comment.h"
20 extern char loptions[];
22 /* Since the lexical analyser does a one-token look-ahead, pseudo-
23 comments are read too soon. This is remedied by first storing them
24 in static variables and then moving them to the real variables
28 PRIVATE int notreached;
29 PRIVATE int varargsN = -1;
32 PRIVATE int formatVAR;
34 PRIVATE char *prev_format;
36 PRIVATE make_format();
38 int LINTLIB; /* file is lint library */
39 int s_NOTREACHED; /* statement not reached */
40 int f_VARARGSn; /* function with variable # of args */
41 int f_ARGSUSED; /* function does not use all args */
42 int f_FORMATn; /* argument f_FORMATn is f_FORMAT */
44 int f_FORMATvar; /* but the formal argument may be
45 absent because of varargs.h */
49 LINTLIB = loptions['L'];
54 s_NOTREACHED = notreached;
58 lint_comment_function()
60 f_ARGSUSED = argsused | loptions['v'];
63 f_VARARGSn = varargsN;
73 f_FORMATvar = formatVAR;
77 PRIVATE char buf[1000];
78 PRIVATE char *bufpos; /* next free position in buf */
88 /* This function is called with every character between /_* and *_/ */
89 if (bufpos - &buf[0] < sizeof(buf)-1)
98 /* skip initial blanks */
99 while (*bufpos && isspace(*bufpos)) {
103 /* now test for one of the pseudo-comments */
104 if (strncmp(bufpos, "NOTREACHED", 10) == 0) {
108 if (strncmp(bufpos, "ARGSUSED", 8) == 0) {
112 if (strncmp(bufpos, "LINTLIBRARY", 11) == 0) {
116 if (strncmp(bufpos, "VARARGS", 7) == 0) {
118 varargsN = isdigit(*bufpos) ? atoi(bufpos) : 0;
121 if (strncmp(bufpos, "FORMAT", 6) == 0 && isdigit(bufpos[6])) {
125 argn = *bufpos++ - '0';
127 if (*bufpos == 'v') {
128 /* something like FORMAT3v */
132 make_format(argn, bufpos);
137 /* We use a small FSA to skip layout inside formats, but to preserve
138 a space between letters and digits.
143 #define LETGITSPACE 2
146 make_format(argn, oldf)
151 register int last_stat;
153 while (*oldf && *oldf != '$') {
157 /* no format given, repeat previous format */
159 warning("format missing and no previous format");
162 format = prev_format;
165 if (*oldf++ != '$') {
166 warning("no format in FORMAT pseudo-comment");
171 /* there is a new format to be composed */
172 newf = Malloc(strlen(oldf));
173 /* certainly enough and probably not overly too much */
178 while (*oldf && *oldf != '$') {
179 register char ch = *oldf++;
182 if (last_stat == LETGIT)
183 last_stat = LETGITSPACE;
204 warning("no end of format in FORMAT pseudo-comment");