2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
33 ** from the CC man page:
35 ** -Idir Search for #include files whose names do not begin with a
36 ** slash (/) in the following order: (1) in the directory of
37 ** the dir argument, (2) in the directories specified by -I
38 ** options, (3) in the standard directory (/usr/include).
41 /* needed for string literals literals */
45 /*@null@*/ /*@observer@*/ char *name;
46 /*@null@*/ /*@observer@*/ char *describe;
49 static flagcatinfo categories[] =
51 { FK_ABSTRACT, "abstract", "abstraction violations, representation access" } ,
52 { FK_ALIAS, "aliasing", "unexpected or dangerous aliasing" } ,
53 { FK_USE, "alluse", "all declarations are used" } ,
54 { FK_ANSI, "ansi", "violations of constraints imposed by ANSI/ISO standard" } ,
55 { FK_ARRAY, "arrays", "special checking involving arrays" } ,
56 { FK_BOOL, "booleans", "checking and naming of boolean types" } ,
57 { FK_COMMENTS, "comments", "warnings about (normal) comments" } ,
58 { FK_SYNCOMMENTS, "syncomments", "interpretation of annotation comments" } ,
59 { FK_COMPLETE, "complete", "completely defined, used, or specified system" } ,
60 { FK_CONTROL, "controlflow", "suspicious control structures" } ,
61 { FK_DEBUG, "debug", "flags for debugging splint" } ,
62 { FK_DECL, "declarations", "consistency of declarations" } ,
63 { FK_DEF, "definition", "undefined storage errors" } ,
64 { FK_DIRECT, "directories", "set directores" } ,
65 { FK_DISPLAY, "display", "control what is displayed" } ,
66 { FK_EFFECT, "effect", "statements with no effects" } ,
67 { FK_ERRORS, "errors", "control expected errors, summary reporting" } ,
68 { FK_EXPORT, "export", "control what may be exported" } ,
69 { FK_EXPOSURE, "exposure", "representation exposure" } ,
70 { FK_EXTENSIBLE, "extensible", "user-defined checks and annotations" },
71 { FK_FILES, "files", "control system files" } ,
72 { FK_FORMAT, "format", "control format of warning messages" } ,
73 { FK_GLOBALS, "globals", "use of global and file static variables" },
74 { FK_HEADERS, "headers", "control inclusion and generation of header files" },
75 { FK_HELP, "help", "on-line help" },
76 { FK_BOUNDS, "memorybounds", "out-of-bounds memory accesses" },
77 { FK_HINTS, "hints", "control display of warning hints" },
78 { FK_SYSTEMFUNCTIONS, "systemfunctions", "special properties of exit and main" },
79 { FK_IMPLICIT, "implicit", "control implicit annotations and interpretations" } ,
80 { FK_INIT, "initializations", "initialization files" } ,
81 { FK_ITER, "iterators", "checking iterator definitions and uses" } ,
82 { FK_LEAK, "leaks", "memory leaks" } ,
83 { FK_LIBS, "libraries", "loading and dumping of user and standard libraries" } ,
84 { FK_LIMITS, "limits", "violations of set limits" } ,
85 { FK_MACROS, "macros", "expansion, definition and use of macros" },
86 { FK_MEMORY, "memory", "memory management" } ,
87 { FK_MODIFIES, "modification", "modification errors" } ,
88 { FK_NAMES, "names", "naming conventions and limits" } ,
89 { FK_NULL, "null", "misuses of null pointers" } ,
90 { FK_NUMBERS, "numbers", "control type-checking of numeric types" } ,
91 { FK_OPS, "operations", "checking of primitive operations" } ,
92 { FK_PARAMS, "parameters", "function and macro parameters" } ,
93 { FK_SPEED, "performance", "speeding up checking" } ,
94 { FK_POINTER, "pointers", "pointers" } ,
95 { FK_PRED, "predicates", "condition test expressions" } ,
96 { FK_PREFIX, "prefixes", "set naming prefixes and control checking" } ,
97 { FK_PREPROC, "preproc", "defines and undefines for the preprocessor" } ,
98 { FK_PROTOS, "prototypes", "function prototypes" } ,
99 { FK_DEAD, "released", "using storage that has been deallocated" } ,
100 { FK_IGNORERET, "returnvals", "ignored return values" },
101 { FK_SECURITY, "security", "possible security vulnerability" },
102 { FK_SPEC, "specifications", "checks involving .lcl specifications" } ,
103 { FK_SUPPRESS, "suppress", "local and global suppression of messages" } ,
104 { FK_TYPEEQ, "typeequivalence", "control what types are equivalent" } ,
105 { FK_BEHAVIOR, "undefined", "code with undefined or implementation-defined behavior" } ,
106 { FK_UNRECOG, "unrecognized", "unrecognized identifiers" } ,
107 { FK_UNSPEC, "unconstrained", "checking in the presence of unconstrained functions" } ,
108 { FK_WARNUSE, "warnuse", "use of possibly problematic function" } ,
109 { FK_ITS4, "its4", "its4 compatibility flags (report warnings for uses of possibly insecure functions)" } ,
110 { FK_SYNTAX, NULL, NULL } ,
111 { FK_TYPE, NULL, NULL } ,
112 { FK_SECRET, NULL, NULL } ,
113 { FK_OBSOLETE, NULL, NULL } ,
114 { FK_NONE, NULL, NULL } /* must be last */
119 ARG_NUMBER, /* number */
121 ARG_STRING, /* string */
122 ARG_FILE, /* filename (also a string) */
123 ARG_DIRECTORY, /* directory (also a string) */
128 static /*@observer@*/ cstring argcode_unparse (argcode arg)
132 case ARG_STRING: return cstring_makeLiteralTemp ("string");
133 case ARG_FILE: return cstring_makeLiteralTemp ("filename");
134 case ARG_DIRECTORY: return cstring_makeLiteralTemp ("directory");
135 case ARG_PATH: return cstring_makeLiteralTemp ("path");
136 case ARG_NUMBER: return cstring_makeLiteralTemp ("number");
137 case ARG_CHAR: return cstring_makeLiteralTemp ("character");
144 /* Make Microsoft VC++ happy */
145 # pragma warning (disable:4715)
152 bool isSpecial; /* setting this flag may set other flags (or values) */
153 bool isIdem; /* idempotent - always sets to TRUE */
154 bool isGlobal; /* cannot be set locally (using control comments) */
155 bool isModeFlag; /* set by modes */
157 /*@observer@*/ char *flag;
159 /*@observer@*/ /*@null@*/ char *desc;
165 typedef fflag flaglist[];
167 # include "flags.def"
169 /*@iter allFlags (yield observer fflag f); @*/
170 # define allFlags(m_f) \
171 { /*@+enumint@*/ flagcode m_i; for (m_i = 0; m_i < NUMFLAGS; m_i++) { fflag m_f = flags[m_i]; /*@=enumint@*/
172 # define end_allFlags }}
174 static bn_mstring mode_names[] =
176 "weak", "standard", "checks", "strict", NULL,
179 /*@iter allModes (yield bn_mstring modename)@*/
180 # define allModes(m_m) \
181 { int m_ii = 0; while (mstring_isDefined (mode_names[m_ii])) \
182 { bn_mstring m_m = mode_names[m_ii]; m_ii++;
184 # define end_allModes }}
188 static cstring getFlagModeSettings (flagcode p_flag) /*@modifies internalState@*/ ;
189 static cstring describeFlagCode (flagcode p_flag) /*@*/ ;
190 static cstringSList sortedFlags (void) /*@*/ ;
191 static /*@observer@*/ cstring categoryName (flagkind p_kind) /*@*/ ;
193 static flagcode flags_identifyFlagAux (cstring p_s, bool p_quiet) /*@modifies g_warningstream@*/ ;
196 static /*@unused@*/ cstring listModes (void) /*@*/ ;
199 bool flagcode_isSpecialFlag (flagcode f)
201 return (flags[f].isSpecial);
204 bool flagcode_isGlobalFlag (flagcode f)
206 return (flags[f].isGlobal);
209 bool flagcode_isIdemFlag (flagcode f)
211 return (flags[f].isIdem);
214 bool flagcode_isModeFlag (flagcode f)
216 return (flags[f].isModeFlag);
219 bool flagcode_isNameChecksFlag (flagcode f)
221 return (flags[f].main == FK_NAMES);
224 bool flagcode_isHelpFlag (flagcode f)
226 return f == FLG_HELP;
229 bool flagcode_isMessageControlFlag (flagcode f)
232 ** True if opt controls the display of messages.
233 ** These flags must be processed first.
236 return (f == FLG_SHOWSCAN
238 || f == FLG_PARENFILEFORMAT
239 || f == FLG_MESSAGESTREAMSTDERR
240 || f == FLG_MESSAGESTREAMSTDOUT
241 || f == FLG_WARNINGSTREAMSTDERR
242 || f == FLG_WARNINGSTREAMSTDOUT
243 || f == FLG_ERRORSTREAMSTDERR
244 || f == FLG_ERRORSTREAMSTDOUT
245 || f == FLG_MESSAGESTREAM
246 || f == FLG_WARNINGSTREAM
247 || f == FLG_ERRORSTREAM
248 || f == FLG_STREAMOVERWRITE);
252 ** Internal consistency check on the flags.
255 void flags_initMod ()
260 if (flags[code].code != code)
263 "*** ERROR: inconsistent flag %s / %d / %d",
265 flags[code].code, code);
267 llbug (message ("*** ERROR: inconsistent flag %s / %d / %d",
268 cstring_fromChars (flags[code].flag),
269 flags[code].code, code));
282 char *buf = mstring_create (128);
286 if (f.nreported > 0 || f.nsuppressed > 0)
288 int nrep = f.nreported;
289 int nsup = f.nsuppressed;
290 cstring fs = cstring_fill (cstring_fromChars (f.flag), 23);
294 llmsgplain (cstring_makeLiteral
295 ("\nError Type Reported Suppressed\n"
296 "=================== ======== ========="));
300 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (fs), nrep, nsup);
306 llmsg (cstring_copy (cstring_fromChars (buf)));
312 cstring ts = cstring_fill (cstring_makeLiteralTemp ("Total"), 23);
314 llmsglit (" ======== =========");
316 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
318 llmsgplain (cstring_copy (cstring_fromChars (buf)));
327 flagcode_recordError (flagcode f)
329 if (f != INVALID_FLAG)
331 if (f == FLG_WARNFLAGS)
333 ; /* don't count these */
339 flags[f].nreported = flags[f].nreported + 1;
344 llcontbug (message ("flagcode_recordError: invalid flag: %d", (int) f));
349 flagcode_recordSuppressed (flagcode f)
351 llassertprint (f != INVALID_FLAG, ("flagcode: %s", flagcode_unparse (f)));
354 /*drl bee: ec*/ flags[f].nsuppressed = flags[f].nsuppressed + 1;
358 flagcode_numReported (flagcode f)
360 llassert (f != INVALID_FLAG);
362 return (flags[f].nreported);
365 /*@observer@*/ cstring
366 flagcodeHint (flagcode f)
368 llassert (f != INVALID_FLAG);
371 if (mstring_isDefined (flags[f].hint))
373 return (cstring_fromChars (flags[f].hint));
377 return (cstring_fromChars (flags[f].desc));
381 static int categorySize (flagkind kind) /*@*/
388 if (f.main == kind || f.sub == kind)
397 flagkind identifyCategory (cstring s)
401 for (i = 0; categories[i].kind != FK_NONE; i++)
404 if (mstring_isDefined (categories[i].name))
406 if (cstring_equalLit (s, categories[i].name))
408 return categories[i].kind;
416 static /*@observer@*/ cstring categoryName (flagkind kind)
420 for (i = 0; categories[i].kind != FK_NONE; i++)
423 if (categories[i].kind == kind)
425 return (cstring_fromChars (categories[i].name));
429 return (cstring_makeLiteralTemp ("<No Category>"));
432 static int categoryIndex (flagkind kind)
436 for (i = 0; categories[i].kind != FK_NONE; i++)
439 if (categories[i].kind == kind)
448 void printCategory (flagkind kind)
450 int index = categoryIndex (kind);
452 llassert (index >= 0);
454 llmsg (message ("%s (%d flags)\n\3%s\n\n",
455 cstring_fromChars (categories[index].name),
457 cstring_fromChars (categories[index].describe)));
461 if (f.main == kind || f.sub == kind)
463 llmsg (message (" %s\n\6%q", cstring_fromChars (f.flag),
464 describeFlagCode (f.code)));
470 listAllCategories (void)
474 for (i = 0; categories[i].kind != FK_NONE; i++)
477 flagkind kind = categories[i].kind ;
479 if (categories[i].describe != NULL)
481 llmsg (message ("%s (%d flags)\n\3%s",
484 cstring_fromChars (categories[i].describe)));
490 printAllFlags (bool desc, bool full)
494 cstringSList fl = sortedFlags ();
496 cstringSList_elements (fl, el)
498 /*@i22@*/ /*find out why this is necessary*/
500 tmp = cstring_copy(el);
501 llmsg (message ("%q\n\n", describeFlag (tmp)));
503 } end_cstringSList_elements ;
505 cstringSList_free (fl);
511 if (f.code != INVALID_FLAG && f.main != FK_OBSOLETE)
513 if (mstring_isDefined (f.desc))
517 llmsg (message ("%s --- %s", cstring_fromChars (f.flag),
518 cstring_fromChars (f.desc)));
527 printFlagManual (bool html)
530 ** Prints all flags by category, in order they appear in flags.def
533 flagkind lastCategory = FK_NONE;
537 cstring flagtype = cstring_undefined;
539 if (f.main != lastCategory)
543 llmsg (message ("\n<h4>%s</h4>\n", categoryName (f.main)));
547 llmsg (message ("\n%s\n%s\n",
548 categoryName (f.main),
549 cstring_makeLiteralTemp ("===================================")));
552 lastCategory = f.main;
555 if (f.argtype == ARG_NONE || f.argtype == ARG_SPECIAL)
559 flagname = message ("<tt>%s</tt>", cstring_fromChars (f.flag));
563 flagname = cstring_fromCharsNew (f.flag);
568 if (flagcode_hasString (f.code))
572 flagname = message ("<tt>%s <em><%s></em></tt>",
573 cstring_fromChars (f.flag), argcode_unparse (f.argtype));
577 flagname = message ("%s <%s>", cstring_fromChars (f.flag), argcode_unparse (f.argtype));
580 if (cstring_isDefined (context_getString (f.code)))
584 flagname = message ("%q <font color=\"blue\">[%s]</font>", flagname,
585 context_getString (f.code));
589 flagname = message ("%q [%s]", flagname,
590 context_getString (f.code));
594 else if (f.argtype == ARG_CHAR)
598 flagname = message ("<tt>%s <em><%s></em></tt> <font color=\"blue\">[%c]</font>",
599 cstring_fromChars (f.flag), argcode_unparse (f.argtype),
600 (char) context_getValue (f.code));
604 flagname = message ("%s <%s> [%c]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
605 (char) context_getValue (f.code));
610 llassert (f.argtype == ARG_NUMBER);
614 flagname = message ("<tt>%s <em><%s></em> <font color=\"blue\">[%d]</font>",
615 cstring_fromChars (f.flag), argcode_unparse (f.argtype),
616 context_getValue (f.code));
620 flagname = message ("%s <%s> [%d]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
621 context_getValue (f.code));
630 flagtype = message("%q<font color=\"green\">-</font>", flagtype);
634 flagtype = message("%q<->", flagtype);
642 flagtype = message ("%q<font color=\"green\"><em>global</em></font>", flagtype);
646 flagtype = message ("%q<G>", flagtype);
654 flagtype = message ("%q<font color=\"orange\"><em>shortcut</em></font>", flagtype);
658 flagtype = message("%q<S>", flagtype);
666 flagtype = message ("%q mode:<tt>%q</tt>>", flagtype, getFlagModeSettings (f.code));
670 flagtype = message ("%q<M:%q>", flagtype, getFlagModeSettings (f.code));
673 else /* its a plain flag */
677 flagtype = message ("%q plain:<tt>%s</tt>", flagtype,
678 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
682 flagtype = message ("%q<P:%s>", flagtype,
683 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
687 llmsg (message ("%s: %s", flagname, flagtype));
691 llgenindentmsgnoloc (cstring_makeLiteral ("<blockquote>"));
694 if (mstring_isDefined (f.hint))
696 llgenindentmsgnoloc (cstring_fromCharsNew (f.hint));
700 llgenindentmsgnoloc (message ("%q.", cstring_capitalize (cstring_fromChars (f.desc))));
705 llgenindentmsgnoloc (cstring_makeLiteral ("</blockquote>"));
711 describeFlagCode (flagcode flag)
713 cstring ret = cstring_undefined;
716 if (flagcode_isInvalid (flag))
718 return (cstring_makeLiteral ("<invalid>"));
721 context_resetAllFlags ();
725 ret = cstring_copy (cstring_fromChars (f.desc));
727 if (f.sub != FK_NONE)
729 ret = message ("%q\nCategories: %s, %s",
731 categoryName (f.main),
732 categoryName (f.sub));
736 if (f.main != FK_NONE)
738 cstring cname = categoryName (f.main);
740 if (cstring_isDefined (cname))
742 ret = message ("%q\nCategory: %s",
750 ret = message ("%q\nMode Settings: %q",
751 ret, getFlagModeSettings (flag));
755 ret = message ("%q\nDefault Setting: %s",
757 cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
762 ret = message("%q\nSet globally only", ret);
766 ret = message("%q\nSet locally", ret);
775 ret = message("%q\nNumeric Argument. Default: %d",
777 context_getValue (flag));
780 ret = message("%q\nCharacter Argument. Default: %h",
781 ret, (char) context_getValue (flag));
788 if (cstring_isDefined (context_getString (flag)))
790 ret = message("%q\n%q argument. Default: %s",
792 cstring_capitalize (argcode_unparse (f.argtype)),
793 context_getString (flag));
797 ret = message("%q\n%s argument. No default.",
799 cstring_capitalize (argcode_unparse (f.argtype)));
805 if (mstring_isDefined (f.hint))
807 ret = message("%q\n\3%s", ret, cstring_fromChars (f.hint));
813 static cstring getFlagModeSettings (flagcode flag)
815 cstring res = cstring_undefined;
819 context_setModeNoWarn (cstring_fromChars (mname));
821 res = message ("%q%s", res, cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
828 describeFlag (cstring flagname)
830 cstring oflagname = cstring_copy (flagname);
831 flagcode f = flags_identifyFlag (flagname);
833 if (flagcode_isSkip (f))
835 cstring_free (oflagname);
836 return cstring_undefined;
838 else if (flagcode_isValid (f))
840 if (cstring_equal (flagname, oflagname))
842 cstring_free (oflagname);
843 return (message ("%s\n\3%q", flagname, describeFlagCode (f)));
847 return (message ("%q (standardized name: %s)\n\3%q",
848 oflagname, flagname, describeFlagCode (f)));
853 if (flags_isModeName (flagname))
855 cstring_free (oflagname);
858 (message ("%s: predefined mode (see Manual for information)",
863 return (message ("%q: <invalid flag>", oflagname));
871 cstringSList s = cstringSList_new ();
877 s = cstringSList_add (s, cstring_fromChars (f.flag));
881 cstringSList_alphabetize (s);
886 void printAlphaFlags ()
888 cstringSList fl = sortedFlags ();
890 cstringSList_printSpaced (fl, 3, 1, context_getLineLen () - 25);
891 cstringSList_free (fl);
894 /*@observer@*/ cstring
895 flagcode_unparse (flagcode code)
897 if (code == INVALID_FLAG)
899 return cstring_makeLiteralTemp ("<invalid flag>");
902 return cstring_fromChars (flags[code].flag);
906 ** Transforms a flag into its cannonical form.
908 ** The following transformations are made:
914 ** parameter -> param
915 ** unrecognized -> unrecog
917 ** declaration -> decl
918 ** globalias -> (no change)
926 ** unconstrained -> unspec
932 static /*@only@*/ cstring
933 canonicalizeFlag (cstring s)
936 cstring res = cstring_copy (s);
937 static bn_mstring transform[] =
943 "parameter", "param",
944 "unrecognized", "unrecog",
946 "declaration", "decl",
954 "unconstrained", "uncon",
965 while ((current = transform[i]) != NULL)
967 if (cstring_containsLit (res, current))
969 cstring_replaceLit (res, current, transform[i+1]);
974 /* remove whitespace, -'s, and _'s */
975 cstring_stripChars (res, " -_");
980 flags_identifyFlag (cstring s)
982 return flags_identifyFlagAux (s, FALSE);
986 flags_identifyFlagQuiet (cstring s)
988 return flags_identifyFlagAux (s, TRUE);
992 flags_identifyFlagAux (cstring s, bool quiet)
997 if (cstring_length (s) == 0) {
998 /* evs 2000-06-25: A malformed flag. */
1002 if (cstring_firstChar (s) == 'I')
1004 return FLG_INCLUDEPATH; /* no space required after -I */
1007 if (cstring_firstChar (s) == 'S')
1009 return FLG_SPECPATH; /* no space required after -S */
1012 if (cstring_firstChar (s) == 'D')
1014 return FLG_DEFINE; /* no space required after -D */
1017 if (cstring_firstChar (s) == 'U')
1019 return FLG_UNDEFINE; /* no space required after -D */
1022 cflag = canonicalizeFlag (s);
1027 if (cstring_equal (cstring_fromChars (f.flag), cflag))
1034 if (res == INVALID_FLAG)
1040 if (cstring_equalLit (cflag, "pred"))
1044 else if (cstring_equalLit (cflag, "modobserverstrict"))
1046 res = FLG_MODOBSERVERUNCON;
1048 else if (cstring_equalLit (cflag, "czechnames"))
1052 else if (cstring_equalLit (cflag, "slovaknames"))
1056 else if (cstring_equalLit (cflag, "czechoslovaknames"))
1058 res = FLG_CZECHOSLOVAK;
1060 else if (cstring_equalLit (cflag, "globunspec")
1061 || cstring_equalLit (cflag, "globuncon"))
1063 res = FLG_GLOBUNSPEC;
1065 else if (cstring_equalLit (cflag, "modglobsunspec")
1066 || cstring_equalLit (cflag, "modglobsuncon")
1067 || cstring_equalLit (cflag, "modglobsnomods"))
1069 res = FLG_MODGLOBSUNSPEC;
1071 else if (cstring_equalLit (cflag, "export"))
1073 res = FLG_EXPORTANY;
1075 else if (cstring_equalLit (cflag, "macrospec"))
1077 res = FLG_MACRODECL;
1079 else if (cstring_equalLit (cflag, "ansireservedlocal"))
1081 res = FLG_ISORESERVEDLOCAL;
1083 else if (cstring_equalLit (cflag, "warnposix"))
1085 res = FLG_WARNPOSIX;
1087 else if (cstring_equalLit (cflag, "defuse"))
1091 else if (cstring_equalLit (cflag, "macroundef"))
1093 res = FLG_MACROUNDEF;
1095 else if (cstring_equalLit (cflag, "showcol"))
1099 else if (cstring_equalLit (cflag, "intbool"))
1103 else if (cstring_equalLit (cflag, "intchar"))
1107 else if (cstring_equalLit (cflag, "intenum"))
1112 ** Backwards compatibility for our American friends...
1115 else if (cstring_equalLit (cflag, "ansilib"))
1119 else if (cstring_equalLit (cflag, "ansistrictlib"))
1121 res = FLG_STRICTLIB;
1123 else if (cstring_equalLit (cflag, "skipansiheaders"))
1125 res = FLG_SKIPISOHEADERS;
1127 else if (cstring_equalLit (cflag, "ansireserved"))
1129 res = FLG_ISORESERVED;
1131 else if (cstring_equalLit (cflag, "ansireservedinternal"))
1133 res = FLG_ISORESERVEDLOCAL;
1140 else if (cstring_equalLit (cflag, "accessunspec"))
1145 (cstring_makeLiteral
1146 ("accessunspec flag is no longer supported. It has been replaced by accessmodule, accessfile and "
1147 "accessfunction to provide more precise control of accessibility "
1148 "of representations. For more information, "
1149 "see splint -help accessmodule"));
1154 else if (cstring_equalLit (cflag, "ansilimits"))
1157 (cstring_makeLiteral
1158 ("ansilimits flag is no longer supported. It has been replaced by ansi89limits and "
1159 "iso99limits to select either the lower translation limits imposed by the ANSI89 "
1160 "standard or the typically higher limits prescribed by ISO C99."));
1164 else if (cstring_equalLit (cflag, "staticmods"))
1169 (cstring_makeLiteral
1170 ("staticmods flag is obsolete. You probably "
1171 "want impcheckmodstatics. For more information, "
1172 "see splint -help impcheckmodstatics"));
1177 else if (cstring_equalLit (cflag, "bool"))
1182 (cstring_makeLiteral ("bool flag is obsolete. It never really "
1183 "made sense in the first place."));
1188 else if (cstring_equalLit (cflag, "shiftsigned"))
1193 (cstring_makeLiteral ("shiftsigned flag is obsolete. You probably "
1194 "want bitwisesigned, shiftnegative or shiftimplementation."));
1199 else if (cstring_equalLit (cflag, "ansi"))
1204 (cstring_makeLiteral ("ansi flag is obsolete. You probably "
1205 "want noparams and/or oldstyle."));
1210 else if (cstring_equalLit (cflag, "usestderr"))
1215 (cstring_makeLiteral
1216 ("usestderr flag is obsolete. This has been replaced "
1217 "by more precise flags for controlling the warning, "
1218 "status message and fatal error streams independently: message-stream-stdout, "
1219 "message-stream-stderr, message-stream <file>, "
1220 "warning-stream-stdout, warning-stream-stderr, warning-stream <file>, "
1221 "error-stream-stdout, error-stream-stderr, error-stream <file>."));
1227 else if (cstring_equalLit (cflag, "stdio"))
1232 (cstring_makeLiteral
1233 ("stdio flag is obsolete. You may "
1234 "want strictlib or one of the gloabls "
1235 "checking flags. For more information, "
1236 "see splint -help strictlib or splint -help flags globals"));
1241 else if (flags_isModeName (cflag))
1243 res = MODENAME_FLAG;
1250 cstring_free (cflag);
1254 void setValueFlag (flagcode opt, cstring arg)
1262 case FLG_INDENTSPACES:
1264 case FLG_EXTERNALNAMELEN:
1265 case FLG_INTERNALNAMELEN:
1266 case FLG_CONTROLNESTDEPTH:
1267 case FLG_STRINGLITERALLEN:
1268 case FLG_NUMSTRUCTFIELDS:
1269 case FLG_NUMENUMMEMBERS:
1270 case FLG_INCLUDENEST:
1272 int val = cstring_toPosInt (arg);
1279 ("Flag %s must be followed by a positive number number. "
1281 flagcode_unparse (opt), arg));
1285 context_setValueAndFlag (opt, val);
1289 case FLG_COMMENTCHAR:
1291 if (cstring_length (arg) != 1)
1295 ("Flag %s should be followed by a single character. Followed by %s",
1296 flagcode_unparse (opt), arg));
1300 context_setCommentMarkerChar (cstring_firstChar (arg));
1308 void setStringFlag (flagcode opt, /*@only@*/ cstring arg)
1314 if (cstring_lastChar (arg) == CONNECTCHAR)
1316 context_setString (opt, arg);
1320 context_setString (opt, cstring_appendChar (arg, CONNECTCHAR));
1326 context_setString (opt, arg);
1335 cstring s = cstring_makeLiteral ("Flag ");
1336 cstringSList sflags = sortedFlags ();
1340 s = message ("%q%9s", s, cstring_fromChars (modename));
1343 s = message ("%q\n", s);
1345 cstringSList_elements (sflags, flagname)
1347 flagcode code = flags_identifyFlag (flagname);
1348 fflag currentflag = flags[code];
1350 if (mstring_isDefined (currentflag.desc) && flagcode_isModeFlag (code))
1352 s = message ("%q\n%27s", s,
1353 cstring_fromChars (currentflag.flag));
1357 context_setMode (cstring_fromChars (modename));
1359 if (context_getFlag (code))
1361 s = message ("%q%9s", s, cstring_makeLiteralTemp ("+"));
1365 s = message ("%q%9s", s, cstring_makeLiteralTemp (" "));
1368 context_resetModeFlags ();
1371 } end_cstringSList_elements;
1373 cstringSList_free (sflags);
1375 s = cstring_appendChar (s, '\n');
1381 static /*@unused@*/ cstring
1384 cstring s = cstring_makeLiteral ("\t");
1389 if (i != 0 && (i % 4 == 0))
1391 s = message ("%q\n\t%15s", s, cstring_fromChars (modename));
1395 s = message ("%q%15s", s, cstring_fromChars (modename));
1405 flags_isModeName (cstring s)
1409 if (mstring_isDefined (modename))
1411 if (cstring_equalLit (s, modename))
1421 extern bool flagcode_hasArgument (flagcode f)
1423 return (flags[f].argtype != ARG_NONE);
1426 extern bool flagcode_hasNumber (flagcode f)
1428 return (flags[f].argtype == ARG_NUMBER);
1431 extern bool flagcode_hasChar (flagcode f)
1433 return (flags[f].argtype == ARG_CHAR);
1436 extern bool flagcode_hasString (flagcode f)
1438 return (flags[f].argtype == ARG_STRING
1439 || flags[f].argtype == ARG_FILE
1440 || flags[f].argtype == ARG_DIRECTORY
1441 || flags[f].argtype == ARG_PATH);
1444 extern int flagcode_valueIndex (flagcode f)
1446 /*@unchecked@*/ static bool initialized = FALSE;
1448 /*@unchecked@*/ static flagcode valueFlags[NUMVALUEFLAGS];
1456 if (flagcode_hasNumber (code) || flagcode_hasChar (code))
1458 llassert (nv < NUMVALUEFLAGS);
1459 DPRINTF (("Value flag: %s [%d]", flagcode_unparse (code), (int) code));
1460 valueFlags[nv] = code;
1465 llassertprint (nv == NUMVALUEFLAGS,
1466 ("Number of value flags: %d (expected %d)",
1467 nv, (int) NUMVALUEFLAGS));
1471 for (i = 0; i < NUMVALUEFLAGS; i++)
1473 /* static valueFlags must be defined */
1476 if (f == valueFlags[i]) /*@=usedef@*/
1482 fprintf (stderr, "Cannot find value flag: %d", (int) f);
1483 exit (EXIT_FAILURE);
1484 /* Cannot do this...might call recursively...
1485 llfatalbug (message ("Cannot fine value flag: %d", (int) f));
1490 extern int flagcode_stringIndex (flagcode f)
1492 /*@unchecked@*/ static bool initialized = FALSE;
1493 /*@unchecked@*/ static flagcode stringFlags[NUMSTRINGFLAGS];
1503 if (flagcode_hasString (code))
1505 llassertprint (nv < NUMSTRINGFLAGS, ("Incorrect number of string flags: %d (need at least %d)", NUMSTRINGFLAGS, nv));
1506 stringFlags[nv] = code;
1511 llassertprint (nv == NUMSTRINGFLAGS,
1512 ("number of string flags: %d (expected %d)",
1513 nv, NUMSTRINGFLAGS));
1517 for (i = 0; i < NUMSTRINGFLAGS; i++)
1520 /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
1526 llbug (message ("Bad string flag: %s", flagcode_unparse (f)));
1530 bool flagcode_isNamePrefixFlag (flagcode f)
1534 case FLG_MACROVARPREFIX:
1536 case FLG_ENUMPREFIX:
1537 case FLG_FILESTATICPREFIX:
1538 case FLG_GLOBPREFIX:
1539 case FLG_TYPEPREFIX:
1540 case FLG_EXTERNALPREFIX:
1541 case FLG_LOCALPREFIX:
1542 case FLG_UNCHECKEDMACROPREFIX:
1543 case FLG_CONSTPREFIX:
1544 case FLG_ITERPREFIX:
1545 case FLG_DECLPARAMPREFIX:
1552 bool flags_processFlags (bool inCommandLine, int argc, char **argv)
1556 for (i = 0; i < argc; i++)
1558 char *thisarg = argv[i];
1560 if (*thisarg == '-' || *thisarg == '+')
1562 bool set = (*thisarg == '+');
1563 cstring flagname = cstring_fromChars (thisarg + 1); /* skip '-' or '+' */
1564 flagcode opt = flags_identifyFlag (flagname);
1566 DPRINTF (("Flag: %s", flagcode_unparse (opt)));
1568 if (flagcode_isInvalid (opt))
1570 DPRINTF (("Error!"));
1571 voptgenerror (FLG_BADFLAG,
1572 message ("Unrecognized option: %s",
1573 cstring_fromChars (thisarg)),
1576 else if (flagcode_isHelpFlag (opt))
1580 voptgenerror (FLG_BADFLAG,
1581 message ("Help flag must be first on the command line: %s",
1582 cstring_fromChars (thisarg)),
1587 voptgenerror (FLG_BADFLAG,
1588 message ("Help flags can only be used on the command line: %s",
1589 cstring_fromChars (thisarg)),
1593 else if (flagcode_isModeNameFlag (opt))
1595 context_setMode (flagname);
1597 else if (flagcode_isMessageControlFlag (opt))
1600 ** Processed on first pass
1603 if (flagcode_hasArgument (opt))
1611 ** A normal control flag
1614 context_userSetFlag (opt, set);
1616 if (flagcode_hasArgument (opt))
1618 if (flagcode_isPassThrough (opt)) /* -D or -U */
1621 ** Following space is optional
1624 flags_recordPassThroughArg (flagname);
1626 passThroughArgs = cstringSList_add
1627 (passThroughArgs, cstring_fromChars (thisarg));
1629 else if (flagcode_hasNumber (opt))
1633 setValueFlag (opt, cstring_fromChars (argv[i]));
1639 ("Flag %s must be followed by a number",
1640 flagcode_unparse (opt)));
1643 else if (flagcode_hasChar (opt))
1647 setValueFlag (opt, cstring_fromChars (argv[i]));
1653 ("Flag %s must be followed by a character",
1654 flagcode_unparse (opt)));
1657 else if (opt == FLG_INCLUDEPATH || opt == FLG_SPECPATH)
1659 cstring dir = cstring_suffix (cstring_fromChars (thisarg), 1); /* skip over I */
1663 case FLG_INCLUDEPATH:
1664 cppAddIncludeDir (dir);
1665 /*@switchbreak@*/ break;
1668 g_localSpecPath = cstring_toCharsSafe
1670 cstring_fromChars (g_localSpecPath),
1674 /*@switchbreak@*/ break;
1678 else if (flagcode_hasString (opt)
1679 || opt == FLG_INIT || opt == FLG_OPTF)
1683 cstring arg = cstring_fromChars (argv[i]);
1685 if (opt == FLG_OPTF)
1687 ; /* -f already processed */
1689 else if (opt == FLG_INIT)
1692 initFile = inputStream_create
1694 cstring_makeLiteralTemp (LCLINIT_SUFFIX),
1701 DPRINTF (("String flag: %s / %s",
1702 flagcode_unparse (opt), arg));
1703 if (opt == FLG_MTSFILE)
1706 ** arg identifies mts files
1708 cstring tmp = message ("%s%s", arg, MTS_EXTENSION);
1709 addLarchPathFile (mtfiles, tmp);
1711 tmp = message ("%s%s", arg, XH_EXTENSION);
1712 addXHFile (xfiles, tmp);
1717 setStringFlag (opt, cstring_copy (arg));
1725 ("Flag %s must be followed by a string",
1726 flagcode_unparse (opt)));
1736 else /* its a filename */
1738 DPRINTF (("Adding filename: %s", thisarg));
1739 fl = cstringSList_add (fl, cstring_fromChars (thisarg));
1745 void flags_processHelp (int argc, char **argv)
1758 if (*thisarg == '-' || *thisarg == '+')
1760 thisarg++; /* skip '-' */
1762 if (mstring_equal (thisarg, "modes"))
1764 llmsg (describeModes ());
1766 else if (mstring_equal (thisarg, "vars") || mstring_equal (thisarg, "env"))
1770 else if (mstring_equal (thisarg, "annotations"))
1772 printAnnotations ();
1774 else if (mstring_equal (thisarg, "parseerrors"))
1776 printParseErrors ();
1778 else if (mstring_equal (thisarg, "comments"))
1782 else if (mstring_equal (thisarg, "prefixcodes"))
1784 describePrefixCodes ();
1786 else if (mstring_equal (thisarg, "references")
1787 || mstring_equal (thisarg, "refs"))
1791 else if (mstring_equal (thisarg, "mail"))
1795 else if (mstring_equal (thisarg, "maintainer")
1796 || mstring_equal (thisarg, "version"))
1800 else if (mstring_equal (thisarg, "flags"))
1804 char *next = argv[i + 1];
1806 if (specialFlagsHelp (next))
1812 flagkind k = identifyCategory (cstring_fromChars (next));
1828 cstring s = describeFlag (cstring_fromChars (thisarg));
1830 if (cstring_isDefined (s))