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
27 ** Main module for Splint annotation-assisted program checker
33 ** Ensure that WIN32 and _WIN32 are both defined or both undefined.
38 # error "Inconsistent definitions."
42 # error "Inconsistent definitions."
51 # include "splintMacros.nf"
58 # include "scanline.h"
59 # include "lclscanline.h"
60 # include "lclsyntable.h"
61 # include "lcltokentable.h"
62 # include "lslparse.h"
64 # include "syntable.h"
65 # include "tokentable.h"
71 # include "Headers/version.h" /* Visual C++ finds the wrong version.h */
73 # include "cgrammar.h"
78 extern /*@external@*/ int yydebug;
79 static void cleanupFiles (void);
81 ** evans 2002-07-03: renamed from interrupt to avoid conflict with WATCOM compiler keyword
82 ** (Suggested by Adam Clarke)
85 static void llinterrupt (int p_i);
87 static void describeVars (void);
88 static bool specialFlagsHelp (char *p_next);
89 static bool hasShownHerald = FALSE;
90 static char *specFullName (char *p_specfile, /*@out@*/ char **p_inpath)
91 /*@modifies *p_inpath@*/ ;
93 static bool anylcl = FALSE;
94 static clock_t inittime;
96 static fileIdList preprocessFiles (fileIdList, bool)
97 /*@modifies fileSystem@*/ ;
99 static void warnSysFiles(fileIdList p_files) /*@modifies fileSystem@*/;
102 void lslCleanup (void)
103 /*@globals killed g_symtab@*/
104 /*@modifies internalState, g_symtab@*/
107 ** Cleanup all the LCL/LSL.
110 static bool didCleanup = FALSE;
112 llassert (!didCleanup);
117 lsymbol_destroyMod ();
118 LCLSynTableCleanup ();
119 LCLTokenTableCleanup ();
120 LCLScanLineCleanup ();
123 /* clean up LSL parsing */
126 ltokenTableCleanup ();
130 symtable_free (g_symtab);
135 lslProcess (fileIdList lclfiles)
136 /*@globals undef g_currentSpec, undef g_currentSpecName, g_currentloc,
137 undef killed g_symtab; @*/
138 /*@modifies g_currentSpec, g_currentSpecName, g_currentloc, internalState, fileSystem; @*/
141 bool parser_status = FALSE;
142 bool overallStatus = FALSE;
147 context_resetSpecLines ();
149 fileIdList_elements (lclfiles, fid)
151 cstring actualName = cstring_undefined;
152 cstring fname = fileTable_fileName (fid);
154 if (osd_getPath (cstring_fromChars (g_localSpecPath),
155 fname, &actualName) == OSD_FILENOTFOUND)
157 if (mstring_equal (g_localSpecPath, "."))
159 lldiagmsg (message ("Spec file not found: %q", osd_outputPath (fname)));
163 lldiagmsg (message ("Spec file not found: %q (on %s)",
164 osd_outputPath (fname),
165 cstring_fromChars (g_localSpecPath)));
170 inputStream specFile;
172 char *namePtr = actualName;
174 while (*namePtr == '.' && *(namePtr + 1) == CONNECTCHAR)
178 /*@noaccess cstring@*/
180 g_currentSpec = cstring_fromCharsNew (namePtr);
182 specFile = inputStream_create (cstring_copy (g_currentSpec),
183 LCL_EXTENSION, TRUE);
185 llassert (inputStream_isDefined (specFile));
187 g_currentSpecName = specFullName
188 (cstring_toCharsSafe (g_currentSpec),
193 displayScan (message ("reading spec %s", g_currentSpec));
195 /* Open the source file */
197 if (!inputStream_open (specFile))
199 lldiagmsg (message ("Cannot open file: %q",
200 osd_outputPath (inputStream_fileName (specFile))));
201 inputStream_free (specFile);
205 scopeInfo dummy_scope = (scopeInfo) dmalloc (sizeof (*dummy_scope));
206 dummy_scope->kind = SPE_INVALID;
209 LCLScanReset (specFile);
212 ** Minor hacks to allow more than one LCL file to
213 ** be scanned, while keeping initializations
216 symtable_enterScope (g_symtab, dummy_scope);
217 resetImports (cstring_fromChars (g_currentSpecName));
218 context_enterLCLfile ();
219 (void) lclHadNewError ();
221 parser_status = (ylparse () != 0);
222 context_exitLCLfile ();
224 overallStatus = parser_status || lclHadNewError ();
226 if (context_getFlag (FLG_DOLCS))
230 outputLCSFile (path, "%FAILED Output from ",
235 outputLCSFile (path, "%PASSED Output from ",
240 (void) inputStream_close (specFile);
241 inputStream_free (specFile);
243 symtable_exitScope (g_symtab);
246 cstring_free (actualName);
247 } end_fileIdList_elements;
249 /* Can cleanup lsl stuff right away */
253 g_currentSpec = cstring_undefined;
254 g_currentSpecName = NULL;
257 static void handlePassThroughFlag (char *arg)
260 char *quotechar = strchr (curarg, '\"');
263 char *freearg = NULL;
265 while (quotechar != NULL)
267 if (*(quotechar - 1) == '\\')
269 char *tp = quotechar - 2;
280 curarg = quotechar + 1;
281 quotechar = strchr (curarg, '\"');
286 llassert (quotechar != NULL);
288 offset = (quotechar - arg) + 2;
292 arg = cstring_toCharsSafe
293 (message ("%s\"\'%s",
294 cstring_fromChars (arg),
295 cstring_fromChars (quotechar + 1)));
301 arg = cstring_toCharsSafe
302 (message ("%s\'\"%s",
303 cstring_fromChars (arg),
304 cstring_fromChars (quotechar + 1)));
309 curarg = arg + offset;
310 quotechar = strchr (curarg, '\"');
316 voptgenerror (FLG_BADFLAG,
317 message ("Unclosed quote in flag: %s",
318 cstring_fromChars (arg)),
327 ** If the value is surrounded by single quotes ('), remove
328 ** them. This is an artifact of UNIX command line?
331 def = osd_fixDefine (cstring_fromChars (arg + 1));
332 DPRINTF (("Do define: %s", def));
334 DPRINTF (("After define"));
336 } else if (arg[0] == 'U') {
337 cppDoUndefine (cstring_fromChars (arg + 1));
346 void showHerald (void)
348 if (hasShownHerald || context_getFlag (FLG_QUIET))
354 fprintf (g_messagestream, "%s\n\n", SPLINT_VERSION);
355 hasShownHerald = TRUE;
361 ** Disable MSVC++ warning about return value. Methinks humbly splint control
362 ** comments are a mite more legible.
366 # pragma warning (disable:4035)
369 int main (int argc, char *argv[])
370 /*@globals killed undef g_currentloc,
371 killed g_localSpecPath,
372 killed undef g_currentSpec,
373 killed undef g_currentSpecName,
375 undef g_warningstream, g_messagestream, g_errorstream;
377 /*@modifies g_currentloc, g_localSpecPath, g_currentSpec, g_currentSpecName,
381 bool first_time = TRUE;
383 inputStream sourceFile = inputStream_undefined;
385 fileIdList dercfiles;
386 cstringList passThroughArgs = cstringList_undefined;
387 fileIdList cfiles, xfiles, lclfiles, mtfiles;
388 clock_t before, lcltime, libtime, pptime, cptime, rstime;
392 _wildcard (&argc, &argv);
395 g_warningstream = stdout;
396 g_messagestream = stderr;
397 g_errorstream = stderr;
399 (void) signal (SIGINT, llinterrupt);
400 (void) signal (SIGSEGV, llinterrupt);
404 clabstract_initMod ();
405 typeIdSet_initMod ();
407 cppReader_initMod ();
411 g_currentloc = fileloc_createBuiltin ();
416 context_setInCommandLine ();
420 help_showAvailableHelp ();
424 /* -help must be the first flag to get help */
425 if (flagcode_isHelpFlag (flags_identifyFlag (cstring_fromChars (argv[1]))))
428 ** Skip first flag and help flag
431 help_processFlags (argc - 2, argv + 2);
439 ** Add include directories from environment.
443 cstring incval = cstring_copy (osd_getEnvironmentVariable (INCLUDEPATH_VAR));
444 cstring oincval = incval;
446 if (cstring_isDefined (incval))
449 ** Each directory on the include path is a system include directory.
452 DPRINTF (("include: %s", incval));
453 context_setString (FLG_SYSTEMDIRS, cstring_copy (incval));
455 while (cstring_isDefined (incval))
458 char *nextsep = strchr (incval, PATH_SEPARATOR);
464 dir = cstring_copy (incval);
466 if (cstring_length (dir) == 0
467 || !isalpha ((int) cstring_firstChar (dir)))
470 ** win32 environment values can have special values,
476 cppAddIncludeDir (dir);
479 *nextsep = PATH_SEPARATOR;
480 incval = cstring_fromChars (nextsep + 1);
488 /*@noaccess cstring@*/
491 else /* 2001-09-09: herbert */
493 /* Put C_INCLUDE_PATH directories in sysdirs */
494 cstring cincval = osd_getEnvironmentVariable (cstring_makeLiteralTemp ("C_INCLUDE_PATH"));
496 if (cstring_isDefined (cincval))
498 context_setString (FLG_SYSTEMDIRS, cstring_copy (cincval));
503 cstring_free (oincval);
507 ** check RCFILE for default flags
511 ** Process command line message formatting flags before reading rc file
515 cstring home = osd_getHomeDir ();
516 cstring fname = cstring_undefined;
517 bool defaultf = TRUE;
520 for (i = 1; i < argc; i++)
525 if (*thisarg == '-' || *thisarg == '+')
527 bool set = (*thisarg == '+');
533 ** Don't report warnings this time
536 opt = flags_identifyFlagQuiet (cstring_fromChars (thisarg));
542 else if (flagcode_isMessageControlFlag (opt))
545 ** Need to set it immediately, so rc file scan is displayed
548 context_userSetFlag (opt, set);
550 if (flagcode_hasArgument (opt))
552 llassert (flagcode_hasString (opt));
556 fname = cstring_fromChars (argv[i]);
557 setStringFlag (opt, fname);
564 ("Flag %s must be followed by a string",
565 flagcode_unparse (opt)),
570 else if (opt == FLG_OPTF)
575 fname = cstring_fromChars (argv[i]);
576 (void) rcfiles_read (fname, &passThroughArgs, TRUE);
580 (cstring_makeLiteral ("Flag f to select options file "
581 "requires an argument"));
585 ; /* wait to process later */
592 if (!nof && defaultf)
595 ** No explicit rc file, first try reading ~/.splintrc
598 if (cstring_isUndefined (fname))
600 if (!cstring_isEmpty (home))
602 bool readhomerc, readaltrc;
603 cstring homename, altname;
605 homename = message ("%s%h%s", home, CONNECTCHAR,
606 cstring_fromChars (RCFILE));
607 readhomerc = rcfiles_read (homename, &passThroughArgs, FALSE);
610 ** Try ~/.splintrc also for historical accuracy
613 altname = message ("%s%h%s", home, CONNECTCHAR,
614 cstring_fromChars (ALTRCFILE));
615 readaltrc = rcfiles_read (altname, &passThroughArgs, FALSE);
617 if (readhomerc && readaltrc)
622 message ("Found both %s and %s files. Using both files, "
623 "but recommend using only %s to avoid confusion.",
624 homename, altname, homename),
628 cstring_free (homename);
629 cstring_free (altname);
634 ** Next, read .splintrc in the current working directory
638 cstring rcname = message ("%s%s",osd_getCurrentDirectory (), cstring_fromChars (RCFILE));
639 cstring altname = message ("%s%s",osd_getCurrentDirectory (), cstring_fromChars (ALTRCFILE));
640 bool readrc, readaltrc;
642 readrc = rcfiles_read (rcname, &passThroughArgs, FALSE);
643 readaltrc = rcfiles_read (altname, &passThroughArgs, FALSE);
645 if (readrc && readaltrc)
647 voptgenerror (FLG_WARNRC,
648 message ("Found both %s and %s files. Using both files, "
649 "but recommend using only %s to avoid confusion.",
650 rcname, altname, rcname),
655 cstring_free (rcname);
656 cstring_free (altname);
662 llassert (fileloc_isBuiltin (g_currentloc));
664 cfiles = fileIdList_create ();
665 xfiles = fileIdList_create ();
666 lclfiles = fileIdList_create ();
667 mtfiles = fileIdList_create ();
669 /* argv[0] is the program name, don't pass it to flags_processFlags */
670 flags_processFlags (TRUE, xfiles, cfiles,
677 if (context_getFlag (FLG_CSV)) {
678 cstring fname = context_getString (FLG_CSV);
680 if (cstring_isDefined (fname)) {
681 if (osd_fileExists (fname) && !context_getFlag (FLG_CSVOVERWRITE)) {
682 lldiagmsg (message ("Specified CSV output file already exists (use +csvoverwrite to automatically overwrite): %s",
685 g_csvstream = fopen (cstring_toCharsSafe (fname), "w");
687 DPRINTF (("Creating: %s", fname));
688 if (g_csvstream == NULL) {
689 lldiagmsg (message ("Cannot open file for CSV output: %s", fname));
691 displayScan (message ("Starting CSV output file: %s", context_getString (FLG_CSV)));
692 fprintf (g_csvstream,
693 "Warning, Flag Code, Flag Name, Priority, File, Line, Column, Warning Text, Additional Text\n");
705 context_resetErrors ();
706 context_clearInCommandLine ();
708 anylcl = !fileIdList_isEmpty (lclfiles);
710 if (context_doMerge ())
712 cstring m = context_getMerge ();
714 displayScanOpen (message ("< loading %s ", m));
718 if (!usymtab_existsType (context_getBoolName ()))
725 if (!context_getFlag (FLG_NOLIB) && loadStandardState ())
734 /* setup bool type and constants */
738 fileloc_free (g_currentloc);
739 g_currentloc = fileloc_createBuiltin ();
742 ** Read metastate files (must happen before loading libraries)
745 fileIdList_elements (mtfiles, mtfile)
747 context_setFileId (mtfile);
748 displayScan (message ("processing %s", fileTable_rootFileName (mtfile)));
749 mtreader_readFile (cstring_copy (fileTable_fileName (mtfile)));
750 } end_fileIdList_elements;
756 lslProcess (lclfiles);
759 usymtab_initGlobalMarker ();
764 ** call the pre-preprocessor and /lib/cpp to generate appropriate
769 context_setInCommandLine ();
771 DPRINTF (("Pass through: %s", cstringSList_unparse (passThroughArgs)));
773 cstringList_elements (passThroughArgs, thisarg)
775 handlePassThroughFlag (cstring_toCharsSafe (thisarg));
777 end_cstringList_elements;
779 cstringList_free (passThroughArgs);
783 DPRINTF (("Initializing cpp reader!"));
784 cppReader_initialize ();
785 cppReader_saveDefinitions ();
787 context_clearInCommandLine ();
789 if (!context_getFlag (FLG_NOPP))
795 displayScanOpen (cstring_makeLiteral ("preprocessing"));
799 context_setPreprocessing ();
800 dercfiles = preprocessFiles (xfiles, TRUE);
801 tfiles = preprocessFiles (cfiles, FALSE);
802 warnSysFiles(cfiles);
803 dercfiles = fileIdList_append (dercfiles, tfiles);
804 fileIdList_free (tfiles);
806 context_clearPreprocessing ();
808 fileIdList_free (cfiles);
816 dercfiles = fileIdList_append (cfiles, xfiles);
821 ** now, check all the corresponding C files
823 ** (for now these are just <file>.c, but after pre-processing
824 ** will be <tmpprefix>.<file>.c)
829 int nfiles = /*@-unrecog@*/ _fcloseall (); /*@=unrecog@*/
833 llbug (message ("Files unclosed: %d", nfiles));
838 DPRINTF (("Initializing..."));
842 DPRINTF (("Okay..."));
844 fileIdList_elements (dercfiles, fid)
846 sourceFile = inputStream_create (cstring_copy (fileTable_fileName (fid)), C_EXTENSION, TRUE);
847 context_setFileId (fid);
849 /* Open source file */
851 if (inputStream_isUndefined (sourceFile) || (!inputStream_open (sourceFile)))
853 /* previously, this was ignored ?! */
854 llbug (message ("Could not open temp file: %s", fileTable_fileName (fid)));
858 yyin = inputStream_getFile (sourceFile); /*< shared <- only */
860 llassert (yyin != NULL);
862 displayScan (message ("checking %q", osd_outputPath (fileTable_rootFileName (fid))));
865 ** Every time, except the first time, through the loop,
866 ** need to call yyrestart to clean up the parse buffer.
871 (void) yyrestart (yyin);
878 DPRINTF (("Entering..."));
879 context_enterFile ();
881 context_exitCFile ();
883 (void) inputStream_close (sourceFile);
886 inputStream_free (sourceFile); /* evans 2002-07-12: why no warning without this?!! */
887 } end_fileIdList_elements;
889 fileIdList_free (dercfiles); /* evans 2002-07-12: why no warning without this?!! */
892 /* process any leftover macros */
894 context_processAllMacros ();
896 /* check everything that was specified was defined */
898 /* don't check if no c files were processed ?
899 ** is this correct behaviour?
902 displayScan (cstring_makeLiteral ("global checks"));
906 if (context_getLinesProcessed () > 0)
908 usymtab_allDefined ();
911 if (context_maybeSet (FLG_TOPUNUSED))
913 uentry ue = usymtab_lookupSafe (cstring_makeLiteralTemp ("main"));
915 if (uentry_isValid (ue))
917 uentry_setUsed (ue, fileloc_observeBuiltin ());
923 if (context_maybeSet (FLG_EXPORTLOCAL))
925 usymtab_exportLocal ();
929 if (context_maybeSet (FLG_EXPORTHEADER))
931 usymtab_exportHeader ();
934 if (context_getFlag (FLG_SHOWUSES))
936 usymtab_displayAllUses ();
939 context_checkSuppressCounts ();
941 if (context_doDump ())
943 cstring dump = context_getDump ();
954 if (g_csvstream != NULL) {
955 displayScan (message ("Closing CSV file: %s", context_getString (FLG_CSV)));
956 check (fclose (g_csvstream) == 0);
959 if (context_getFlag (FLG_SHOWSUMMARY))
965 bool isQuiet = context_getFlag (FLG_QUIET);
966 cstring specErrors = cstring_undefined;
967 int nspecErrors = lclNumberErrors ();
971 if (context_neednl ())
972 fprintf (g_warningstream, "\n");
976 if (nspecErrors == context_getLCLExpect ())
979 message ("%d spec warning%&, as expected\n ",
984 if (context_getLCLExpect () > 0)
987 message ("%d spec warning%&, expected %d\n ",
989 (int) context_getLCLExpect ());
993 specErrors = message ("%d spec warning%&\n ",
1001 if (context_getLCLExpect () > 0)
1003 specErrors = message ("No spec warnings, expected %d\n ",
1004 (int) context_getLCLExpect ());
1009 if (context_anyErrors ())
1011 if (context_numErrors () == context_getExpect ())
1014 llmsg (message ("Finished checking --- "
1015 "%s%d code warning%&, as expected",
1016 specErrors, context_numErrors ()));
1021 if (context_getExpect () > 0)
1025 ("Finished checking --- "
1026 "%s%d code warning%&, expected %d",
1027 specErrors, context_numErrors (),
1028 (int) context_getExpect ()));
1038 llmsg (message ("Finished checking --- "
1039 "%s%d code warning%&",
1040 specErrors, context_numErrors ()));
1049 if (context_getExpect () > 0)
1053 ("Finished checking --- "
1054 "%sno code warnings, expected %d",
1056 (int) context_getExpect ()));
1063 if (context_getLinesProcessed () > 0)
1065 if (cstring_isEmpty (specErrors))
1069 llmsg (message ("Finished checking --- no warnings"));
1076 llmsg (message ("Finished checking --- %sno code warnings",
1084 llmsg (message ("Finished checking --- %sno code processed",
1091 cstring_free (specErrors);
1094 if (context_getFlag (FLG_STATS))
1096 clock_t ttime = clock () - before;
1097 int specLines = context_getSpecLinesProcessed ();
1098 cstring specmsg = cstring_undefined;
1104 specmsg = message ("%d spec, ", specLines);
1107 /* The clock might wrap around, not platform-independent easy way to deal with this... */
1110 # ifndef CLOCKS_PER_SEC
1111 lldiagmsg (message ("%s%d source lines in %d time steps (steps/sec unknown)\n",
1113 context_getLinesProcessed (),
1116 lldiagmsg (message ("%s%d source lines in %f s.\n",
1118 context_getLinesProcessed (),
1119 (double) ttime / CLOCKS_PER_SEC));
1120 DPRINTF (("Time: %ld [%ld - %ld]", ttime, rstime, before));
1125 lldiagmsg (message ("%s%d source lines\n",
1127 context_getLinesProcessed ()));
1136 if (context_getFlag (FLG_TIMEDIST))
1138 clock_t ttime = clock () - before;
1142 char *msg = (char *) dmalloc (256 * sizeof (*msg));
1146 (void) snprintf (msg, 256,
1147 "Time distribution (percent): initialize %.2f / lcl %.2f / "
1148 "pre-process %.2f / c check %.2f / finalize %.2f \n",
1149 (100.0 * (double) (libtime - before) / ttime),
1150 (100.0 * (double) (lcltime - libtime) / ttime),
1151 (100.0 * (double) (pptime - lcltime) / ttime),
1152 (100.0 * (double) (cptime - pptime) / ttime),
1153 (100.0 * (double) (rstime - cptime) / ttime));
1157 (void) snprintf (msg, 256,
1158 "Time distribution (percent): initialize %.2f / "
1159 "pre-process %.2f / c check %.2f / finalize %.2f \n",
1160 (100.0 * (double) (libtime - before) / ttime),
1161 (100.0 * (double) (pptime - libtime) / ttime),
1162 (100.0 * (double) (cptime - pptime) / ttime),
1163 (100.0 * (double) (rstime - cptime) / ttime));
1166 llgenindentmsgnoloc (cstring_fromCharsO (msg));
1170 llexit (expsuccess ? LLSUCCESS : LLFAILURE);
1171 BADBRANCHRET (LLFAILURE);
1176 ** Reenable return value warnings.
1178 # pragma warning (default:4035)
1187 fprintf (g_errorstream, "*** Interrupt\n");
1188 llexit (LLINTERRUPT);
1193 /* Cheat when there are parse errors */
1196 fprintf (g_errorstream, "*** Segmentation Violation\n");
1198 /* Don't catch it if fileloc_unparse causes a signal */
1199 (void) signal (SIGSEGV, NULL);
1201 loc = fileloc_unparse (g_currentloc);
1203 fprintf (g_errorstream, "*** Location (not trusted): %s\n",
1204 cstring_toCharsSafe (loc));
1207 fprintf (g_errorstream, "*** Please report bug to %s\n", SPLINT_MAINTAINER);
1211 fprintf (g_errorstream, "*** Signal: %d\n", i);
1213 fprintf (g_errorstream, "*** Location (not trusted): %s\n",
1214 cstring_toCharsSafe (fileloc_unparse (g_currentloc)));
1217 fprintf (g_errorstream, "*** Please report bug to %s ***\n", SPLINT_MAINTAINER);
1225 static bool doneCleanup = FALSE;
1227 /* make sure this is only called once! */
1229 if (doneCleanup) return;
1234 ** Close all open files
1235 ** (There should only be open files, if we exited after a fatal error.)
1238 fileTable_closeAll (context_fileTable ());
1240 if (context_getFlag (FLG_KEEP))
1242 check (fputs ("Temporary files kept:\n", g_messagestream) != EOF);
1243 fileTable_printTemps (context_fileTable ());
1248 int nfiles = /*@-unrecog@*/ _fcloseall (); /*@=unrecog@*/
1252 llbug (message ("Files unclosed: %d", nfiles));
1255 fileTable_cleanup (context_fileTable ());
1262 ** cleans up temp files (if necessary) and exits
1268 DPRINTF (("llexit: %d", status));
1271 if (status == LLFAILURE)
1279 if (status != LLFAILURE)
1281 usymtab_destroyMod ();
1282 context_destroyMod ();
1283 exprNode_destroyMod ();
1284 cppReader_destroyMod ();
1286 uentry_destroyMod ();
1287 typeIdSet_destroyMod ();
1290 fileloc_destroyMod ();
1292 dmalloc_shutdown ();
1296 exit ((status == LLSUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
1299 static fileIdList preprocessFiles (fileIdList fl, bool xhfiles)
1300 /*@modifies fileSystem@*/
1302 bool msg = (context_getFlag (FLG_SHOWSCAN) && fileIdList_size (fl) > 10);
1303 int skip = (fileIdList_size (fl) / 5);
1304 int filesprocessed = 0;
1305 fileIdList dfiles = fileIdList_create ();
1307 fileloc_free (g_currentloc);
1308 g_currentloc = fileloc_createBuiltin ();
1310 fileIdList_elements (fl, fid)
1312 cstring ppfname = fileTable_fileName (fid);
1314 if (!(osd_fileIsReadable (ppfname)))
1316 lldiagmsg (message ("Cannot open file: %q", osd_outputPath (ppfname)));
1317 ppfname = cstring_undefined;
1320 if (cstring_isDefined (ppfname))
1322 fileId dfile = fileTable_addCTempFile (context_fileTable (), fid);
1326 llassert (fileTable_isXHFile (context_fileTable (), dfile));
1329 llassert (cstring_isNonEmpty (ppfname));
1333 if ((filesprocessed % skip) == 0)
1335 if (filesprocessed == 0) {
1336 displayScanContinue (cstring_makeLiteral (" "));
1339 displayScanContinue (cstring_makeLiteral ("."));
1345 DPRINTF (("outfile: %s", fileTable_fileName (dfile)));
1347 if (cppProcess (ppfname, fileTable_fileName (dfile)) != 0)
1349 llfatalerror (message ("Preprocessing error for file: %s",
1350 fileTable_rootFileName (fid)));
1353 fileIdList_add (dfiles, dfile);
1355 } end_fileIdList_elements;
1360 /* This should be in an lclUtils.c file... */
1361 char *specFullName (char *specfile, /*@out@*/ char **inpath)
1363 /* extract the path and the specname associated with the given file */
1364 char *specname = (char *) dmalloc (sizeof (*specname)
1365 * (strlen (specfile) + 9));
1366 char *ospecname = specname;
1367 char *path = (char *) dmalloc (sizeof (*path) * (strlen (specfile)));
1371 /* initialized path to empty string or may have accidental garbage */
1374 /*@-mayaliasunique@*/
1375 strcpy (specname, specfile);
1376 /*@=mayaliasunique@*/
1378 /* trim off pathnames in specfile */
1379 size = strlen (specname);
1381 for (i = size_toInt (size) - 1; i >= 0; i--)
1383 if (specname[i] == CONNECTCHAR)
1385 /* strcpy (specname, (char *)specname+i+1); */
1386 for (j = 0; j <= i; j++) /* include '/' */
1388 path[j] = specname[j];
1398 ** also remove .lcl file extension, assume it's the last extension
1402 size = strlen (specname);
1404 for (i = size_toInt (size) - 1; i >= 0; i--)
1406 if (specname[i] == '.')
1416 ** If specname no longer points to the original char,
1417 ** we need to allocate a new pointer and copy the string.
1420 if (specname != ospecname) {
1421 char *rspecname = (char *) dmalloc (sizeof (*rspecname) * (strlen (specname) + 1));
1422 strcpy (rspecname, specname); /* evs 2000-05-16: Bug: was ospecname! */
1430 void warnSysFiles(fileIdList files)
1432 fileIdList_elements (files, file)
1435 if (fileTable_isSystemFile (context_fileTable (), file) )
1437 if (!context_getFlag( FLG_SYSTEMDIRERRORS ) )
1439 voptgenerror (FLG_WARNSYSFILES, message ("Warning %s is a considered a system file. No errors in this file will be reported.", fileTable_rootFileName (file) ), g_currentloc);
1443 end_fileIdList_elements;