X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/f9264521e093e570a8831d5238ccc3bc20e01119..ed62d3fbeda6bb085991cdd683ceacfc57f7afbe:/src/llmain.c diff --git a/src/llmain.c b/src/llmain.c index 5d4c546..a5cd809 100644 --- a/src/llmain.c +++ b/src/llmain.c @@ -1,6 +1,6 @@ /* ** Splint - annotation-assisted static program checker -** Copyright (C) 1994-2002 University of Virginia, +** Copyright (C) 1994-2003 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -49,11 +49,9 @@ # endif # include "splintMacros.nf" -# include "llbasic.h" +# include "basic.h" # include "osd.h" # include "help.h" - -# ifndef NOLCL # include "gram.h" # include "lclscan.h" # include "scanline.h" @@ -68,14 +66,12 @@ # include "lclinit.h" # include "lh.h" # include "imports.h" -# endif # include "Headers/version.h" /* Visual C++ finds the wrong version.h */ # include "lcllib.h" # include "cgrammar.h" +# include "rcfiles.h" # include "llmain.h" -# include "portab.h" - extern /*@external@*/ int yydebug; static void cleanupFiles (void); @@ -100,8 +96,6 @@ static fileIdList preprocessFiles (fileIdList, bool) static void warnSysFiles(fileIdList p_files) /*@modifies fileSystem@*/; -# ifndef NOLCL - static void lslCleanup (void) /*@globals killed g_symtab@*/ @@ -257,7 +251,6 @@ lslProcess (fileIdList lclfiles) g_currentSpec = cstring_undefined; g_currentSpecName = NULL; } -# endif static void handlePassThroughFlag (char *arg) { @@ -372,15 +365,6 @@ void showHerald (void) # endif int main (int argc, char *argv[]) -# ifdef NOLCL - /*@globals killed undef g_currentloc, - killed undef yyin, - undef g_warningstream, g_messagestream, g_errorstream; - @*/ - /*@modifies g_currentloc, fileSystem, - yyin; - @*/ -# else /*@globals killed undef g_currentloc, killed g_localSpecPath, killed undef g_currentSpec, @@ -391,14 +375,13 @@ int main (int argc, char *argv[]) /*@modifies g_currentloc, g_localSpecPath, g_currentSpec, g_currentSpecName, fileSystem, yyin; @*/ -# endif { bool first_time = TRUE; bool expsuccess; inputStream sourceFile = inputStream_undefined; fileIdList dercfiles; - cstringSList passThroughArgs = cstringSList_undefined; + cstringList passThroughArgs = cstringList_undefined; fileIdList cfiles, xfiles, lclfiles, mtfiles; clock_t before, lcltime, libtime, pptime, cptime, rstime; int i = 0; @@ -415,10 +398,11 @@ int main (int argc, char *argv[]) (void) signal (SIGSEGV, llinterrupt); flags_initMod (); + qual_initMod (); clabstract_initMod (); typeIdSet_initMod (); - cppReader_initMod (); osd_initMod (); + cppReader_initMod (); setCodePoint (); @@ -568,7 +552,7 @@ int main (int argc, char *argv[]) if (++i < argc) { fname = cstring_fromChars (argv[i]); - setStringFlag (opt, fname); + flags_setStringFlag (opt, fname); } else { @@ -687,7 +671,29 @@ int main (int argc, char *argv[]) argc - 1, argv + 1); showHerald (); - + + if (context_getFlag (FLG_CSV)) { + cstring fname = context_getString (FLG_CSV); + + if (cstring_isDefined (fname)) { + if (osd_fileExists (fname) && !context_getFlag (FLG_CSVOVERWRITE)) { + lldiagmsg (message ("Specified CSV output file already exists (use +csvoverwrite to automatically overwrite): %s", + fname)); + } else { + g_csvstream = fopen (cstring_toCharsSafe (fname), "w"); + + DPRINTF (("Creating: %s", fname)); + if (g_csvstream == NULL) { + lldiagmsg (message ("Cannot open file for CSV output: %s", fname)); + } else { + displayScan (message ("Starting CSV output file: %s", context_getString (FLG_CSV))); + fprintf (g_csvstream, + "Warning, Flag Code, Flag Name, Priority, File, Line, Column, Warning Text, Additional Text\n"); + } + } + } + } + # ifdef DOANNOTS initAnnots (); # endif @@ -745,11 +751,7 @@ int main (int argc, char *argv[]) if (anylcl) { -# ifdef NOLCL - llfatalerror (cstring_makeLiteral ("This version of Splint does not handle LCL files.")); -# else lslProcess (lclfiles); -# endif } usymtab_initGlobalMarker (); @@ -766,13 +768,13 @@ int main (int argc, char *argv[]) DPRINTF (("Pass through: %s", cstringSList_unparse (passThroughArgs))); - cstringSList_elements (passThroughArgs, thisarg) + cstringList_elements (passThroughArgs, thisarg) { handlePassThroughFlag (cstring_toCharsSafe (thisarg)); } - end_cstringSList_elements; + end_cstringList_elements; - cstringSList_free (passThroughArgs); + cstringList_free (passThroughArgs); cleanupMessages (); @@ -878,8 +880,11 @@ int main (int argc, char *argv[]) (void) inputStream_close (sourceFile); } + + inputStream_free (sourceFile); /* evans 2002-07-12: why no warning without this?!! */ } end_fileIdList_elements; + fileIdList_free (dercfiles); /* evans 2002-07-12: why no warning without this?!! */ cptime = clock (); /* process any leftover macros */ @@ -943,26 +948,27 @@ int main (int argc, char *argv[]) # endif cleanupFiles (); - + + if (g_csvstream != NULL) { + displayScan (message ("Closing CSV file: %s", context_getString (FLG_CSV))); + check (fclose (g_csvstream) == 0); + } + if (context_getFlag (FLG_SHOWSUMMARY)) { summarizeErrors (); } - { bool isQuiet = context_getFlag (FLG_QUIET); cstring specErrors = cstring_undefined; -# ifndef NOLCL int nspecErrors = lclNumberErrors (); -# endif expsuccess = TRUE; if (context_neednl ()) fprintf (g_warningstream, "\n"); -# ifndef NOLCL if (nspecErrors > 0) { if (nspecErrors == context_getLCLExpect ()) @@ -997,7 +1003,6 @@ int main (int argc, char *argv[]) expsuccess = FALSE; } } -# endif if (context_anyErrors ()) { @@ -1097,17 +1102,29 @@ int main (int argc, char *argv[]) specmsg = message ("%d spec, ", specLines); } + /* The clock might wrap around, not platform-independent easy way to deal with this... */ + if (ttime > 0) + { # ifndef CLOCKS_PER_SEC - lldiagmsg (message ("%s%d source lines in %d time steps (steps/sec unknown)\n", - specmsg, - context_getLinesProcessed (), - (int) ttime)); + lldiagmsg (message ("%s%d source lines in %d time steps (steps/sec unknown)\n", + specmsg, + context_getLinesProcessed (), + (int) ttime)); # else - lldiagmsg (message ("%s%d source lines in %f s.\n", - specmsg, - context_getLinesProcessed (), - (double) ttime / CLOCKS_PER_SEC)); + lldiagmsg (message ("%s%d source lines in %f s.\n", + specmsg, + context_getLinesProcessed (), + (double) ttime / CLOCKS_PER_SEC)); + DPRINTF (("Time: %ld [%ld - %ld]", ttime, rstime, before)); # endif + } + else + { + lldiagmsg (message ("%s%d source lines\n", + specmsg, + context_getLinesProcessed ())); + } + } else { @@ -1124,7 +1141,12 @@ int main (int argc, char *argv[]) if (anylcl) { + /* Gack: really should figure out how to make configure find snprintf... */ +# ifdef WIN32 + (void) _snprintf (msg, 256, +# else (void) snprintf (msg, 256, +# endif "Time distribution (percent): initialize %.2f / lcl %.2f / " "pre-process %.2f / c check %.2f / finalize %.2f \n", (100.0 * (double) (libtime - before) / ttime), @@ -1135,7 +1157,11 @@ int main (int argc, char *argv[]) } else { +# ifdef WIN32 + (void) _snprintf (msg, 256, +# else (void) snprintf (msg, 256, +# endif "Time distribution (percent): initialize %.2f / " "pre-process %.2f / c check %.2f / finalize %.2f \n", (100.0 * (double) (libtime - before) / ttime), @@ -1259,13 +1285,22 @@ llexit (int status) if (status != LLFAILURE) { - context_destroyMod (); + usymtab_destroyMod (); + + /*drl I'm commenting this line out + because it is causing Splint to crash when built with + 2.95 I'm not sure if this is a compiler bug or if if has to do with bool + Any way if we're going to exist the program why do we bother freeing stuff... + */ + /* context_destroyMod (); */ exprNode_destroyMod (); - + cppReader_destroyMod (); sRef_destroyMod (); uentry_destroyMod (); typeIdSet_destroyMod (); - + qual_destroyMod (); + osd_destroyMod (); + fileloc_destroyMod (); # ifdef USEDMALLOC dmalloc_shutdown (); # endif @@ -1331,12 +1366,11 @@ static fileIdList preprocessFiles (fileIdList fl, bool xhfiles) fileIdList_add (dfiles, dfile); } } end_fileIdList_elements; - - return dfiles; + + return dfiles; } /* This should be in an lclUtils.c file... */ -# ifndef NOLCL char *specFullName (char *specfile, /*@out@*/ char **inpath) { /* extract the path and the specname associated with the given file */ @@ -1405,7 +1439,6 @@ char *specFullName (char *specfile, /*@out@*/ char **inpath) return specname; } -# endif void warnSysFiles(fileIdList files) {