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_isMessageControlFlag (flagcode f)
227 ** True if opt controls the display of messages.
228 ** These flags must be processed first.
231 return (f == FLG_SHOWSCAN
233 || f == FLG_PARENFILEFORMAT
234 || f == FLG_MESSAGESTREAMSTDERR
235 || f == FLG_MESSAGESTREAMSTDOUT
236 || f == FLG_WARNINGSTREAMSTDERR
237 || f == FLG_WARNINGSTREAMSTDOUT
238 || f == FLG_ERRORSTREAMSTDERR
239 || f == FLG_ERRORSTREAMSTDOUT
240 || f == FLG_MESSAGESTREAM
241 || f == FLG_WARNINGSTREAM
242 || f == FLG_ERRORSTREAM
243 || f == FLG_STREAMOVERWRITE);
247 ** Internal consistency check on the flags.
250 void flags_initMod ()
255 if (flags[code].code != code)
258 "*** ERROR: inconsistent flag %s / %d / %d",
260 flags[code].code, code);
262 llbug (message ("*** ERROR: inconsistent flag %s / %d / %d",
263 cstring_fromChars (flags[code].flag),
264 flags[code].code, code));
277 char *buf = mstring_create (128);
281 if (f.nreported > 0 || f.nsuppressed > 0)
283 int nrep = f.nreported;
284 int nsup = f.nsuppressed;
285 cstring fs = cstring_fill (cstring_fromChars (f.flag), 23);
289 llmsgplain (cstring_makeLiteral
290 ("\nError Type Reported Suppressed\n"
291 "=================== ======== ========="));
295 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (fs), nrep, nsup);
301 llmsg (cstring_copy (cstring_fromChars (buf)));
307 cstring ts = cstring_fill (cstring_makeLiteralTemp ("Total"), 23);
309 llmsglit (" ======== =========");
311 sprintf (buf, "%s%7d %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
313 llmsgplain (cstring_copy (cstring_fromChars (buf)));
322 flagcode_recordError (flagcode f)
324 if (f != INVALID_FLAG)
326 if (f == FLG_WARNFLAGS)
328 ; /* don't count these */
334 flags[f].nreported = flags[f].nreported + 1;
339 llcontbug (message ("flagcode_recordError: invalid flag: %d", (int) f));
344 flagcode_recordSuppressed (flagcode f)
346 llassertprint (f != INVALID_FLAG, ("flagcode: %s", flagcode_unparse (f)));
349 /*drl bee: ec*/ flags[f].nsuppressed = flags[f].nsuppressed + 1;
353 flagcode_numReported (flagcode f)
355 llassert (f != INVALID_FLAG);
357 return (flags[f].nreported);
360 /*@observer@*/ cstring
361 flagcodeHint (flagcode f)
363 llassert (f != INVALID_FLAG);
366 if (mstring_isDefined (flags[f].hint))
368 return (cstring_fromChars (flags[f].hint));
372 return (cstring_fromChars (flags[f].desc));
376 static int categorySize (flagkind kind) /*@*/
383 if (f.main == kind || f.sub == kind)
392 flagkind identifyCategory (cstring s)
396 for (i = 0; categories[i].kind != FK_NONE; i++)
399 if (mstring_isDefined (categories[i].name))
401 if (cstring_equalLit (s, categories[i].name))
403 return categories[i].kind;
411 static /*@observer@*/ cstring categoryName (flagkind kind)
415 for (i = 0; categories[i].kind != FK_NONE; i++)
418 if (categories[i].kind == kind)
420 return (cstring_fromChars (categories[i].name));
424 return (cstring_makeLiteralTemp ("<No Category>"));
427 static int categoryIndex (flagkind kind)
431 for (i = 0; categories[i].kind != FK_NONE; i++)
434 if (categories[i].kind == kind)
443 void printCategory (flagkind kind)
445 int index = categoryIndex (kind);
447 llassert (index >= 0);
449 llmsg (message ("%s (%d flags)\n\3%s\n\n",
450 cstring_fromChars (categories[index].name),
452 cstring_fromChars (categories[index].describe)));
456 if (f.main == kind || f.sub == kind)
458 llmsg (message (" %s\n\6%q", cstring_fromChars (f.flag),
459 describeFlagCode (f.code)));
465 listAllCategories (void)
469 for (i = 0; categories[i].kind != FK_NONE; i++)
472 flagkind kind = categories[i].kind ;
474 if (categories[i].describe != NULL)
476 llmsg (message ("%s (%d flags)\n\3%s",
479 cstring_fromChars (categories[i].describe)));
485 printAllFlags (bool desc, bool full)
489 cstringSList fl = sortedFlags ();
491 cstringSList_elements (fl, el)
493 /*@i22@*/ /*find out why this is necessary*/
495 tmp = cstring_copy(el);
496 llmsg (message ("%q\n\n", describeFlag (tmp)));
498 } end_cstringSList_elements ;
500 cstringSList_free (fl);
506 if (f.code != INVALID_FLAG && f.main != FK_OBSOLETE)
508 if (mstring_isDefined (f.desc))
512 llmsg (message ("%s --- %s", cstring_fromChars (f.flag),
513 cstring_fromChars (f.desc)));
522 printFlagManual (bool html)
525 ** Prints all flags by category, in order they appear in flags.def
528 flagkind lastCategory = FK_NONE;
532 cstring flagtype = cstring_undefined;
534 if (f.main != lastCategory)
538 llmsg (message ("\n<h4>%s</h4>\n", categoryName (f.main)));
542 llmsg (message ("\n%s\n%s\n",
543 categoryName (f.main),
544 cstring_makeLiteralTemp ("===================================")));
547 lastCategory = f.main;
550 if (f.argtype == ARG_NONE || f.argtype == ARG_SPECIAL)
554 flagname = message ("<tt>%s</tt>", cstring_fromChars (f.flag));
558 flagname = cstring_fromCharsNew (f.flag);
563 if (flagcode_hasString (f.code))
567 flagname = message ("<tt>%s <em><%s></em></tt>",
568 cstring_fromChars (f.flag), argcode_unparse (f.argtype));
572 flagname = message ("%s <%s>", cstring_fromChars (f.flag), argcode_unparse (f.argtype));
575 if (cstring_isDefined (context_getString (f.code)))
579 flagname = message ("%q <font color=\"blue\">[%s]</font>", flagname,
580 context_getString (f.code));
584 flagname = message ("%q [%s]", flagname,
585 context_getString (f.code));
589 else if (f.argtype == ARG_CHAR)
593 flagname = message ("<tt>%s <em><%s></em></tt> <font color=\"blue\">[%c]</font>",
594 cstring_fromChars (f.flag), argcode_unparse (f.argtype),
595 (char) context_getValue (f.code));
599 flagname = message ("%s <%s> [%c]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
600 (char) context_getValue (f.code));
605 llassert (f.argtype == ARG_NUMBER);
609 flagname = message ("<tt>%s <em><%s></em> <font color=\"blue\">[%d]</font>",
610 cstring_fromChars (f.flag), argcode_unparse (f.argtype),
611 context_getValue (f.code));
615 flagname = message ("%s <%s> [%d]", cstring_fromChars (f.flag), argcode_unparse (f.argtype),
616 context_getValue (f.code));
625 flagtype = message("%q<font color=\"green\">-</font>", flagtype);
629 flagtype = message("%q<->", flagtype);
637 flagtype = message ("%q<font color=\"green\"><em>global</em></font>", flagtype);
641 flagtype = message ("%q<G>", flagtype);
649 flagtype = message ("%q<font color=\"orange\"><em>shortcut</em></font>", flagtype);
653 flagtype = message("%q<S>", flagtype);
661 flagtype = message ("%q mode:<tt>%q</tt>>", flagtype, getFlagModeSettings (f.code));
665 flagtype = message ("%q<M:%q>", flagtype, getFlagModeSettings (f.code));
668 else /* its a plain flag */
672 flagtype = message ("%q plain:<tt>%s</tt>", flagtype,
673 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
677 flagtype = message ("%q<P:%s>", flagtype,
678 cstring_makeLiteralTemp (context_getFlag (f.code) ? "+" : "-"));
682 llmsg (message ("%s: %s", flagname, flagtype));
686 llgenindentmsgnoloc (cstring_makeLiteral ("<blockquote>"));
689 if (mstring_isDefined (f.hint))
691 llgenindentmsgnoloc (cstring_fromCharsNew (f.hint));
695 llgenindentmsgnoloc (message ("%q.", cstring_capitalize (cstring_fromChars (f.desc))));
700 llgenindentmsgnoloc (cstring_makeLiteral ("</blockquote>"));
706 describeFlagCode (flagcode flag)
708 cstring ret = cstring_undefined;
711 if (flagcode_isInvalid (flag))
713 return (cstring_makeLiteral ("<invalid>"));
716 context_resetAllFlags ();
720 ret = cstring_copy (cstring_fromChars (f.desc));
722 if (f.sub != FK_NONE)
724 ret = message ("%q\nCategories: %s, %s",
726 categoryName (f.main),
727 categoryName (f.sub));
731 if (f.main != FK_NONE)
733 cstring cname = categoryName (f.main);
735 if (cstring_isDefined (cname))
737 ret = message ("%q\nCategory: %s",
745 ret = message ("%q\nMode Settings: %q",
746 ret, getFlagModeSettings (flag));
750 ret = message ("%q\nDefault Setting: %s",
752 cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
757 ret = message("%q\nSet globally only", ret);
761 ret = message("%q\nSet locally", ret);
770 ret = message("%q\nNumeric Argument. Default: %d",
772 context_getValue (flag));
775 ret = message("%q\nCharacter Argument. Default: %h",
776 ret, (char) context_getValue (flag));
783 if (cstring_isDefined (context_getString (flag)))
785 ret = message("%q\n%q argument. Default: %s",
787 cstring_capitalize (argcode_unparse (f.argtype)),
788 context_getString (flag));
792 ret = message("%q\n%s argument. No default.",
794 cstring_capitalize (argcode_unparse (f.argtype)));
800 if (mstring_isDefined (f.hint))
802 ret = message("%q\n\3%s", ret, cstring_fromChars (f.hint));
808 static cstring getFlagModeSettings (flagcode flag)
810 cstring res = cstring_undefined;
814 context_setModeNoWarn (cstring_fromChars (mname));
816 res = message ("%q%s", res, cstring_makeLiteralTemp (context_getFlag (flag) ? "+" : "-"));
823 describeFlag (cstring flagname)
825 cstring oflagname = cstring_copy (flagname);
826 flagcode f = flags_identifyFlag (flagname);
828 if (flagcode_isSkip (f))
830 cstring_free (oflagname);
831 return cstring_undefined;
833 else if (flagcode_isValid (f))
835 if (cstring_equal (flagname, oflagname))
837 cstring_free (oflagname);
838 return (message ("%s\n\3%q", flagname, describeFlagCode (f)));
842 return (message ("%q (standardized name: %s)\n\3%q",
843 oflagname, flagname, describeFlagCode (f)));
848 if (isMode (flagname))
850 cstring_free (oflagname);
853 (message ("%s: predefined mode (see Manual for information)",
858 return (message ("%q: <invalid flag>", oflagname));
866 cstringSList s = cstringSList_new ();
872 s = cstringSList_add (s, cstring_fromChars (f.flag));
876 cstringSList_alphabetize (s);
881 void printAlphaFlags ()
883 cstringSList fl = sortedFlags ();
885 cstringSList_printSpaced (fl, 3, 1, context_getLineLen () - 25);
886 cstringSList_free (fl);
889 /*@observer@*/ cstring
890 flagcode_unparse (flagcode code)
892 if (code == INVALID_FLAG)
894 return cstring_makeLiteralTemp ("<invalid flag>");
897 return cstring_fromChars (flags[code].flag);
901 ** Transforms a flag into its cannonical form.
903 ** The following transformations are made:
909 ** parameter -> param
910 ** unrecognized -> unrecog
912 ** declaration -> decl
913 ** globalias -> (no change)
921 ** unconstrained -> unspec
927 static /*@only@*/ cstring
928 canonicalizeFlag (cstring s)
931 cstring res = cstring_copy (s);
932 static bn_mstring transform[] =
938 "parameter", "param",
939 "unrecognized", "unrecog",
941 "declaration", "decl",
949 "unconstrained", "uncon",
960 while ((current = transform[i]) != NULL)
962 if (cstring_containsLit (res, current))
964 cstring_replaceLit (res, current, transform[i+1]);
969 /* remove whitespace, -'s, and _'s */
970 cstring_stripChars (res, " -_");
975 flags_identifyFlag (cstring s)
977 return flags_identifyFlagAux (s, FALSE);
981 flags_identifyFlagQuiet (cstring s)
983 return flags_identifyFlagAux (s, TRUE);
987 flags_identifyFlagAux (cstring s, bool quiet)
992 if (cstring_length (s) == 0) {
993 /* evs 2000-06-25: A malformed flag. */
997 if (cstring_firstChar (s) == 'I')
999 return FLG_INCLUDEPATH; /* no space after -I */
1002 if (cstring_firstChar (s) == 'S')
1004 return FLG_SPECPATH; /* no space after -S */
1007 if (cstring_firstChar (s) == 'D')
1009 return FLG_DEFINE; /* no space after -D */
1012 if (cstring_firstChar (s) == 'U')
1014 return FLG_UNDEFINE; /* no space after -D */
1017 cflag = canonicalizeFlag (s);
1022 if (cstring_equal (cstring_fromChars (f.flag), cflag))
1029 if (res == INVALID_FLAG)
1035 if (cstring_equalLit (cflag, "pred"))
1039 else if (cstring_equalLit (cflag, "modobserverstrict"))
1041 res = FLG_MODOBSERVERUNCON;
1043 else if (cstring_equalLit (cflag, "czechnames"))
1047 else if (cstring_equalLit (cflag, "slovaknames"))
1051 else if (cstring_equalLit (cflag, "czechoslovaknames"))
1053 res = FLG_CZECHOSLOVAK;
1055 else if (cstring_equalLit (cflag, "globunspec")
1056 || cstring_equalLit (cflag, "globuncon"))
1058 res = FLG_GLOBUNSPEC;
1060 else if (cstring_equalLit (cflag, "modglobsunspec")
1061 || cstring_equalLit (cflag, "modglobsuncon")
1062 || cstring_equalLit (cflag, "modglobsnomods"))
1064 res = FLG_MODGLOBSUNSPEC;
1066 else if (cstring_equalLit (cflag, "export"))
1068 res = FLG_EXPORTANY;
1070 else if (cstring_equalLit (cflag, "macrospec"))
1072 res = FLG_MACRODECL;
1074 else if (cstring_equalLit (cflag, "ansireservedlocal"))
1076 res = FLG_ISORESERVEDLOCAL;
1078 else if (cstring_equalLit (cflag, "warnposix"))
1080 res = FLG_WARNPOSIX;
1082 else if (cstring_equalLit (cflag, "defuse"))
1086 else if (cstring_equalLit (cflag, "macroundef"))
1088 res = FLG_MACROUNDEF;
1090 else if (cstring_equalLit (cflag, "showcol"))
1094 else if (cstring_equalLit (cflag, "intbool"))
1098 else if (cstring_equalLit (cflag, "intchar"))
1102 else if (cstring_equalLit (cflag, "intenum"))
1107 ** Backwards compatibility for our American friends...
1110 else if (cstring_equalLit (cflag, "ansilib"))
1114 else if (cstring_equalLit (cflag, "ansistrictlib"))
1116 res = FLG_STRICTLIB;
1118 else if (cstring_equalLit (cflag, "skipansiheaders"))
1120 res = FLG_SKIPISOHEADERS;
1122 else if (cstring_equalLit (cflag, "ansireserved"))
1124 res = FLG_ISORESERVED;
1126 else if (cstring_equalLit (cflag, "ansireservedinternal"))
1128 res = FLG_ISORESERVEDLOCAL;
1135 else if (cstring_equalLit (cflag, "accessunspec"))
1140 (cstring_makeLiteral
1141 ("accessunspec flag is no longer supported. It has been replaced by accessmodule, accessfile and "
1142 "accessfunction to provide more precise control of accessibility "
1143 "of representations. For more information, "
1144 "see splint -help accessmodule"));
1149 else if (cstring_equalLit (cflag, "ansilimits"))
1152 (cstring_makeLiteral
1153 ("ansilimits flag is no longer supported. It has been replaced by ansi89limits and "
1154 "iso99limits to select either the lower translation limits imposed by the ANSI89 "
1155 "standard or the typically higher limits prescribed by ISO C99."));
1159 else if (cstring_equalLit (cflag, "staticmods"))
1164 (cstring_makeLiteral
1165 ("staticmods flag is obsolete. You probably "
1166 "want impcheckmodstatics. For more information, "
1167 "see splint -help impcheckmodstatics"));
1172 else if (cstring_equalLit (cflag, "bool"))
1177 (cstring_makeLiteral ("bool flag is obsolete. It never really "
1178 "made sense in the first place."));
1183 else if (cstring_equalLit (cflag, "shiftsigned"))
1188 (cstring_makeLiteral ("shiftsigned flag is obsolete. You probably "
1189 "want bitwisesigned, shiftnegative or shiftimplementation."));
1194 else if (cstring_equalLit (cflag, "ansi"))
1199 (cstring_makeLiteral ("ansi flag is obsolete. You probably "
1200 "want noparams and/or oldstyle."));
1205 else if (cstring_equalLit (cflag, "usestderr"))
1210 (cstring_makeLiteral
1211 ("usestderr flag is obsolete. This has been replaced "
1212 "by more precise flags for controlling the warning, "
1213 "status message and fatal error streams independently: message-stream-stdout, "
1214 "message-stream-stderr, message-stream <file>, "
1215 "warning-stream-stdout, warning-stream-stderr, warning-stream <file>, "
1216 "error-stream-stdout, error-stream-stderr, error-stream <file>."));
1222 else if (cstring_equalLit (cflag, "stdio"))
1227 (cstring_makeLiteral
1228 ("stdio flag is obsolete. You may "
1229 "want strictlib or one of the gloabls "
1230 "checking flags. For more information, "
1231 "see splint -help strictlib or splint -help flags globals"));
1242 cstring_free (cflag);
1246 void setValueFlag (flagcode opt, cstring arg)
1254 case FLG_INDENTSPACES:
1256 case FLG_EXTERNALNAMELEN:
1257 case FLG_INTERNALNAMELEN:
1258 case FLG_CONTROLNESTDEPTH:
1259 case FLG_STRINGLITERALLEN:
1260 case FLG_NUMSTRUCTFIELDS:
1261 case FLG_NUMENUMMEMBERS:
1262 case FLG_INCLUDENEST:
1264 int val = cstring_toPosInt (arg);
1271 ("Flag %s must be followed by a positive number number. "
1273 flagcode_unparse (opt), arg));
1277 context_setValueAndFlag (opt, val);
1281 case FLG_COMMENTCHAR:
1283 if (cstring_length (arg) != 1)
1287 ("Flag %s should be followed by a single character. Followed by %s",
1288 flagcode_unparse (opt), arg));
1292 context_setCommentMarkerChar (cstring_firstChar (arg));
1300 void setStringFlag (flagcode opt, /*@only@*/ cstring arg)
1306 if (cstring_lastChar (arg) == CONNECTCHAR)
1308 context_setString (opt, arg);
1312 context_setString (opt, cstring_appendChar (arg, CONNECTCHAR));
1318 context_setString (opt, arg);
1327 cstring s = cstring_makeLiteral ("Flag ");
1328 cstringSList sflags = sortedFlags ();
1332 s = message ("%q%9s", s, cstring_fromChars (modename));
1335 s = message ("%q\n", s);
1337 cstringSList_elements (sflags, flagname)
1339 flagcode code = flags_identifyFlag (flagname);
1340 fflag currentflag = flags[code];
1342 if (mstring_isDefined (currentflag.desc) && flagcode_isModeFlag (code))
1344 s = message ("%q\n%27s", s,
1345 cstring_fromChars (currentflag.flag));
1349 context_setMode (cstring_fromChars (modename));
1351 if (context_getFlag (code))
1353 s = message ("%q%9s", s, cstring_makeLiteralTemp ("+"));
1357 s = message ("%q%9s", s, cstring_makeLiteralTemp (" "));
1360 context_resetModeFlags ();
1363 } end_cstringSList_elements;
1365 cstringSList_free (sflags);
1367 s = cstring_appendChar (s, '\n');
1373 static /*@unused@*/ cstring
1376 cstring s = cstring_makeLiteral ("\t");
1381 if (i != 0 && (i % 4 == 0))
1383 s = message ("%q\n\t%15s", s, cstring_fromChars (modename));
1387 s = message ("%q%15s", s, cstring_fromChars (modename));
1401 if (mstring_isDefined (modename))
1403 if (cstring_equalLit (s, modename))
1413 extern bool flagcode_hasArgument (flagcode f)
1415 return (flags[f].argtype != ARG_NONE);
1418 extern bool flagcode_hasNumber (flagcode f)
1420 return (flags[f].argtype == ARG_NUMBER);
1423 extern bool flagcode_hasChar (flagcode f)
1425 return (flags[f].argtype == ARG_CHAR);
1428 extern bool flagcode_hasString (flagcode f)
1430 return (flags[f].argtype == ARG_STRING
1431 || flags[f].argtype == ARG_FILE
1432 || flags[f].argtype == ARG_DIRECTORY
1433 || flags[f].argtype == ARG_PATH);
1436 extern int flagcode_valueIndex (flagcode f)
1438 /*@unchecked@*/ static bool initialized = FALSE;
1440 /*@unchecked@*/ static flagcode valueFlags[NUMVALUEFLAGS];
1448 if (flagcode_hasNumber (code) || flagcode_hasChar (code))
1450 llassert (nv < NUMVALUEFLAGS);
1451 DPRINTF (("Value flag: %s [%d]", flagcode_unparse (code), (int) code));
1452 valueFlags[nv] = code;
1457 llassertprint (nv == NUMVALUEFLAGS,
1458 ("Number of value flags: %d (expected %d)",
1459 nv, (int) NUMVALUEFLAGS));
1463 for (i = 0; i < NUMVALUEFLAGS; i++)
1465 /* static valueFlags must be defined */
1468 if (f == valueFlags[i]) /*@=usedef@*/
1474 fprintf (stderr, "Cannot find value flag: %d", (int) f);
1475 exit (EXIT_FAILURE);
1476 /* Cannot do this...might call recursively...
1477 llfatalbug (message ("Cannot fine value flag: %d", (int) f));
1482 extern int flagcode_stringIndex (flagcode f)
1484 /*@unchecked@*/ static bool initialized = FALSE;
1485 /*@unchecked@*/ static flagcode stringFlags[NUMSTRINGFLAGS];
1495 if (flagcode_hasString (code))
1497 llassertprint (nv < NUMSTRINGFLAGS, ("Incorrect number of string flags: %d (need at least %d)", NUMSTRINGFLAGS, nv));
1498 stringFlags[nv] = code;
1503 llassertprint (nv == NUMSTRINGFLAGS,
1504 ("number of string flags: %d (expected %d)",
1505 nv, NUMSTRINGFLAGS));
1509 for (i = 0; i < NUMSTRINGFLAGS; i++)
1512 /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
1518 llbug (message ("Bad string flag: %s", flagcode_unparse (f)));
1522 bool flagcode_isNamePrefixFlag (flagcode f)
1526 case FLG_MACROVARPREFIX:
1528 case FLG_ENUMPREFIX:
1529 case FLG_FILESTATICPREFIX:
1530 case FLG_GLOBPREFIX:
1531 case FLG_TYPEPREFIX:
1532 case FLG_EXTERNALPREFIX:
1533 case FLG_LOCALPREFIX:
1534 case FLG_UNCHECKEDMACROPREFIX:
1535 case FLG_CONSTPREFIX:
1536 case FLG_ITERPREFIX:
1537 case FLG_DECLPARAMPREFIX: