** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
** MA 02111-1307, USA.
**
-** For information on splint: splint@cs.virginia.edu
-** To report a bug: splint-bug@cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
** For more information: http://www.splint.org
*/
/*
# include "imports.h"
# endif
-# include "version.h"
+# include "Headers/version.h" /* Visual C++ finds the wrong version.h */
# include "fileIdList.h"
# include "lcllib.h"
# include "cgrammar.h"
static fileIdList preprocessFiles (fileIdList, bool)
/*@modifies fileSystem@*/ ;
+static void warnSysFiles(fileIdList p_files) /*@modifies fileSystem@*/;
+
# ifndef NOLCL
static
fileIdList_elements (lclfiles, fid)
{
cstring actualName = cstring_undefined;
- cstring fname = fileName (fid);
+ cstring fname = fileTable_fileName (fid);
if (osd_getPath (cstring_fromChars (g_localSpecPath),
fname, &actualName) == OSD_FILENOTFOUND)
setSpecFileId (fid);
- if (context_getFlag (FLG_SHOWSCAN))
- {
- lldiagmsg (message ("< reading spec %s >", g_currentSpec));
- }
+ displayScan (message ("reading spec %s", g_currentSpec));
- /* Open source file */
+ /* Open the source file */
if (!inputStream_open (specFile))
{
void showHerald (void)
{
- if (hasShownHerald || context_getFlag (FLG_QUIET)) return;
-
+ if (hasShownHerald || context_getFlag (FLG_QUIET))
+ {
+ return;
+ }
else
{
- fprintf (g_msgstream, "%s\n\n", SPLINT_VERSION);
+ fprintf (g_messagestream, "%s\n\n", SPLINT_VERSION);
hasShownHerald = TRUE;
llflush ();
}
else if (status == OSD_FILENOTFOUND)
{
showHerald ();
- lldiagmsg (message ("Cannot find file on LARCHPATH: %s", s));
+ lldiagmsg (message ("Cannot find file on LARCH_PATH: %s", s));
}
else if (status == OSD_PATHTOOLONG)
{
# ifdef NOLCL
/*@globals killed undef g_currentloc,
killed undef yyin,
- undef g_msgstream;
+ undef g_warningstream, g_messagestream, g_errorstream;
@*/
/*@modifies g_currentloc, fileSystem,
yyin;
killed undef g_currentSpec,
killed undef g_currentSpecName,
killed undef yyin,
- undef g_msgstream;
+ undef g_warningstream, g_messagestream, g_errorstream;
@*/
/*@modifies g_currentloc, initFile,
g_localSpecPath, g_currentSpec, g_currentSpecName, fileSystem,
# endif
{
bool first_time = TRUE;
- bool showhelp = FALSE;
- bool allhelp = TRUE;
bool expsuccess;
inputStream sourceFile = inputStream_undefined;
_wildcard (&argc, &argv);
# endif
- g_msgstream = stdout;
+ g_warningstream = stdout;
+ g_messagestream = stderr;
+ g_errorstream = stderr;
(void) signal (SIGINT, interrupt);
(void) signal (SIGSEGV, interrupt);
setCodePoint ();
g_currentloc = fileloc_createBuiltin ();
-
+
before = clock ();
context_initMod ();
if (argc <= 1)
{
showHelp ();
- llexit (LLGIVEUP);
+ llexit (LLSUCCESS);
+ }
+
+ /* -help must be the first flag to get help */
+ if (flagcode_isHelpFlag (flags_identifyFlag (argv[1])))
+ {
+ flags_processHelp (argc - 1, argv + 1);
+ llexit (LLSUCCESS);
}
setCodePoint ();
{
/* Put C_INCLUDE_PATH directories in sysdirs */
cstring cincval = osd_getEnvironmentVariable (cstring_makeLiteralTemp ("C_INCLUDE_PATH"));
+
if (cstring_isDefined (cincval))
{
context_setString (FLG_SYSTEMDIRS, cstring_copy (cincval));
{
nof = TRUE;
}
- else if (opt == FLG_SHOWSCAN || opt == FLG_WARNRC)
+ else if (flagcode_isMessageControlFlag (opt))
{
/*
** Need to set it immediately, so rc file scan is displayed
*/
context_userSetFlag (opt, set);
+
+ if (flagcode_hasArgument (opt))
+ {
+ llassert (flagcode_hasString (opt));
+
+ if (++i < argc)
+ {
+ fname = cstring_fromChars (argv[i]);
+ setStringFlag (opt, fname);
+ }
+ else
+ {
+ llfatalerror
+ (message
+ ("Flag %s must be followed by a string",
+ flagcode_unparse (opt)));
+ }
+ }
}
else if (opt == FLG_OPTF)
{
}
setCodePoint ();
-
- for (i = 1; i < argc; i++)
- {
- char *thisarg;
- flagcode opt;
-
- thisarg = argv[i];
-
- if (showhelp)
- {
- if (allhelp)
- {
- showHerald ();
- }
-
- allhelp = FALSE;
-
- if (*thisarg == '-' || *thisarg == '+')
- {
- thisarg++; /* skip '-' */
- }
- if (mstring_equal (thisarg, "modes"))
- {
- llmsg (describeModes ());
- }
- else if (mstring_equal (thisarg, "vars")
- || mstring_equal (thisarg, "env"))
- {
- describeVars ();
- }
- else if (mstring_equal (thisarg, "annotations"))
- {
- printAnnotations ();
- }
- else if (mstring_equal (thisarg, "parseerrors"))
- {
- printParseErrors ();
- }
- else if (mstring_equal (thisarg, "comments"))
- {
- printComments ();
- }
- else if (mstring_equal (thisarg, "prefixcodes"))
- {
- describePrefixCodes ();
- }
- else if (mstring_equal (thisarg, "references")
- || mstring_equal (thisarg, "refs"))
- {
- printReferences ();
- }
- else if (mstring_equal (thisarg, "mail"))
- {
- printMail ();
- }
- else if (mstring_equal (thisarg, "maintainer")
- || mstring_equal (thisarg, "version"))
- {
- printMaintainer ();
- }
- else if (mstring_equal (thisarg, "flags"))
- {
- if (i + 1 < argc)
- {
- char *next = argv[i + 1];
-
- if (specialFlagsHelp (next))
- {
- i++;
- }
- else
- {
- flagkind k = identifyCategory (cstring_fromChars (next));
-
- if (k != FK_NONE)
- {
- printCategory (k);
- i++;
- }
- }
- }
- else
- {
- printFlags ();
- }
- }
- else
- {
- cstring s = describeFlag (cstring_fromChars (thisarg));
-
- if (cstring_isDefined (s))
- {
- llmsg (s);
- }
- }
- }
- else
- {
- if (*thisarg == '-' || *thisarg == '+')
- {
- bool set = (*thisarg == '+');
- cstring flagname;
-
- thisarg++; /* skip '-' */
- flagname = cstring_fromChars (thisarg);
-
- DPRINTF (("Flag: %s", flagname));
- opt = flags_identifyFlag (flagname);
- DPRINTF (("Flag: %s", flagcode_unparse (opt)));
- if (flagcode_isSkip (opt) || opt == FLG_SHOWSCAN || opt == FLG_WARNRC)
- {
- /* showscan already processed */
- DPRINTF (("Skipping!"));
- }
- else if (flagcode_isInvalid (opt))
- {
- DPRINTF (("Invalid: %s", flagname));
+ /* argv[0] is the program name, don't pass it to flags_processFlags */
+ flags_processFlags (argc - 1, argv + 1);
- if (isMode (flagname))
- {
- context_setMode (flagname);
- }
- else
- {
- DPRINTF (("Error!"));
- voptgenerror (FLG_BADFLAG,
- message ("Unrecognized option: %s",
- cstring_fromChars (thisarg)),
- g_currentloc);
- }
- }
- else
- {
- context_userSetFlag (opt, set);
-
- if (flagcode_hasArgument (opt))
- {
- if (opt == FLG_HELP)
- {
- showhelp = TRUE;
- }
- else if (flagcode_isPassThrough (opt)) /* -D or -U */
- {
- passThroughArgs = cstringSList_add
- (passThroughArgs, cstring_fromChars (thisarg));
- }
- else if (flagcode_hasNumber (opt))
- {
- if (++i < argc)
- {
- setValueFlag (opt, cstring_fromChars (argv[i]));
- }
- else
- {
- llfatalerror
- (message
- ("Flag %s must be followed by a number",
- flagcode_unparse (opt)));
- }
- }
- else if (flagcode_hasChar (opt))
- {
- if (++i < argc)
- {
- setValueFlag (opt, cstring_fromChars (argv[i]));
- }
- else
- {
- llfatalerror
- (message
- ("Flag %s must be followed by a character",
- flagcode_unparse (opt)));
- }
- }
- else if (opt == FLG_INCLUDEPATH || opt == FLG_SPECPATH)
- {
- cstring dir = cstring_suffix (cstring_fromChars (thisarg), 1); /* skip over I */
-
- switch (opt)
- {
- case FLG_INCLUDEPATH:
- cppAddIncludeDir (dir);
- /*@switchbreak@*/ break;
- case FLG_SPECPATH:
- /*@-mustfree@*/
- g_localSpecPath = cstring_toCharsSafe
- (message ("%s%h%s",
- cstring_fromChars (g_localSpecPath),
- PATH_SEPARATOR,
- dir));
- /*@=mustfree@*/
- /*@switchbreak@*/ break;
- BADDEFAULT;
- }
- }
- else if (flagcode_hasString (opt)
- || opt == FLG_INIT || opt == FLG_OPTF)
- {
- if (++i < argc)
- {
- cstring arg = cstring_fromChars (argv[i]);
-
- if (opt == FLG_OPTF)
- {
- ; /* -f already processed */
- }
- else if (opt == FLG_INIT)
- {
-# ifndef NOLCL
- initFile = inputStream_create
- (arg,
- cstring_makeLiteralTemp (LCLINIT_SUFFIX),
- FALSE);
-# endif
- break;
- }
- else
- {
- DPRINTF (("String flag: %s / %s",
- flagcode_unparse (opt), arg));
- if (opt == FLG_MTSFILE)
- {
- /*
- ** arg identifies mts files
- */
- cstring tmp = message ("%s%s", arg, MTS_EXTENSION);
- addLarchPathFile (mtfiles, tmp);
- cstring_free (tmp);
- tmp = message ("%s%s", arg, XH_EXTENSION);
- addXHFile (xfiles, tmp);
- cstring_free (tmp);
- }
- else
- {
- setStringFlag (opt, arg);
- }
- }
- }
- else
- {
- llfatalerror
- (message
- ("Flag %s must be followed by a string",
- flagcode_unparse (opt)));
- }
- }
- else
- {
- /* no argument */
- }
- }
- }
- }
- else /* its a filename */
- {
- DPRINTF (("Adding filename: %s", thisarg));
- fl = cstringSList_add (fl, cstring_fromChars (thisarg));
- }
- }
- }
-
- setCodePoint ();
showHerald ();
/*
{
showHelp ();
}
- fprintf (g_msgstream, "\n");
+ fprintf (g_warningstream, "\n");
fileIdList_free (cfiles);
fileIdList_free (xfiles);
{
cstring m = context_getMerge ();
- if (context_getFlag (FLG_SHOWSCAN))
- {
- fprintf (g_msgstream, "< loading %s ", cstring_toCharsSafe (m));
- }
-
+ displayScanOpen (message ("< loading %s ", m));
loadState (m);
-
- if (context_getFlag (FLG_SHOWSCAN))
- {
- fprintf (g_msgstream, " >\n");
- }
+ displayScanClose ();
if (!usymtab_existsType (context_getBoolName ()))
{
fileIdList_elements (mtfiles, mtfile)
{
context_setFileId (mtfile);
-
- if (context_getFlag (FLG_SHOWSCAN))
- {
- lldiagmsg (message ("< processing %s >", rootFileName (mtfile)));
- }
-
- mtreader_readFile (cstring_copy (fileName (mtfile)));
+ displayScan (message ("processing %s", fileTable_rootFileName (mtfile)));
+ mtreader_readFile (cstring_copy (fileTable_fileName (mtfile)));
} end_fileIdList_elements;
libtime = clock ();
llflush ();
- if (context_getFlag (FLG_SHOWSCAN))
- {
- fprintf (stderr, "< preprocessing");
- }
+ displayScanOpen (cstring_makeLiteral ("preprocessing"));
lcltime = clock ();
context_setPreprocessing ();
dercfiles = preprocessFiles (xfiles, TRUE);
tfiles = preprocessFiles (cfiles, FALSE);
+ warnSysFiles(cfiles);
dercfiles = fileIdList_append (dercfiles, tfiles);
fileIdList_free (tfiles);
fileIdList_free (cfiles);
- if (context_getFlag (FLG_SHOWSCAN))
- {
- fprintf (stderr, " >\n");
- }
-
+ displayScanClose ();
pptime = clock ();
}
else
fileIdList_elements (dercfiles, fid)
{
- sourceFile = inputStream_create (cstring_copy (fileName (fid)), C_EXTENSION, TRUE);
+ sourceFile = inputStream_create (cstring_copy (fileTable_fileName (fid)), C_EXTENSION, TRUE);
context_setFileId (fid);
/* Open source file */
if (inputStream_isUndefined (sourceFile) || (!inputStream_open (sourceFile)))
{
/* previously, this was ignored ?! */
- llbug (message ("Could not open temp file: %s", fileName (fid)));
+ llbug (message ("Could not open temp file: %s", fileTable_fileName (fid)));
}
else
{
llassert (yyin != NULL);
- if (context_getFlag (FLG_SHOWSCAN))
- {
- lldiagmsg (message ("< checking %q >", osd_outputPath (rootFileName (fid))));
- }
+ displayScan (message ("checking %q", osd_outputPath (fileTable_rootFileName (fid))));
/*
** Every time, except the first time, through the loop,
** is this correct behaviour?
*/
- if (context_getFlag (FLG_SHOWSCAN))
- {
- lldiagmsg (cstring_makeLiteral ("< global checks >"));
- }
+ displayScan (cstring_makeLiteral ("global checks"));
cleanupMessages ();
expsuccess = TRUE;
if (context_neednl ())
- fprintf (g_msgstream, "\n");
+ fprintf (g_warningstream, "\n");
# ifndef NOLCL
if (nspecErrors > 0)
if (specLines > 0)
{
- fprintf (g_msgstream, "%d spec, ", specLines);
+ fprintf (g_warningstream, "%d spec, ", specLines);
}
# ifndef CLOCKS_PER_SEC
- fprintf (g_msgstream, "%d source lines in %ld time steps (steps/sec unknown)\n",
+ fprintf (g_warningstream, "%d source lines in %ld time steps (steps/sec unknown)\n",
context_getLinesProcessed (),
(long) ttime);
# else
- fprintf (g_msgstream, "%d source lines in %.2f s.\n",
+ fprintf (g_warningstream, "%d source lines in %.2f s.\n",
context_getLinesProcessed (),
(double) ttime / CLOCKS_PER_SEC);
# endif
switch (i)
{
case SIGINT:
- fprintf (stderr, "*** Interrupt\n");
+ fprintf (g_errorstream, "*** Interrupt\n");
llexit (LLINTERRUPT);
case SIGSEGV:
{
/* Cheat when there are parse errors */
checkParseError ();
- fprintf (stderr, "*** Segmentation Violation\n");
+ fprintf (g_errorstream, "*** Segmentation Violation\n");
/* Don't catch it if fileloc_unparse causes a signal */
(void) signal (SIGSEGV, NULL);
loc = fileloc_unparse (g_currentloc);
- fprintf (stderr, "*** Location (not trusted): %s\n",
+ fprintf (g_errorstream, "*** Location (not trusted): %s\n",
cstring_toCharsSafe (loc));
cstring_free (loc);
printCodePoint ();
- fprintf (stderr, "*** Please report bug to %s\n", SPLINT_MAINTAINER);
+ fprintf (g_errorstream, "*** Please report bug to %s\n", SPLINT_MAINTAINER);
exit (LLGIVEUP);
}
default:
- fprintf (stderr, "*** Signal: %d\n", i);
+ fprintf (g_errorstream, "*** Signal: %d\n", i);
/*@-mustfree@*/
- fprintf (stderr, "*** Location (not trusted): %s\n",
+ fprintf (g_errorstream, "*** Location (not trusted): %s\n",
cstring_toCharsSafe (fileloc_unparse (g_currentloc)));
/*@=mustfree@*/
printCodePoint ();
- fprintf (stderr, "*** Please report bug to %s ***\n", SPLINT_MAINTAINER);
+ fprintf (g_errorstream, "*** Please report bug to %s ***\n", SPLINT_MAINTAINER);
exit (LLGIVEUP);
}
}
if (context_getFlag (FLG_KEEP))
{
- check (fputs ("Temporary files kept:\n", stderr) != EOF);
+ check (fputs ("Temporary files kept:\n", g_messagestream) != EOF);
fileTable_printTemps (context_fileTable ());
}
else
}
else
{
- FILE *innerf = fileTable_openFile (context_fileTable (), fname, "r");
+ FILE *innerf = fileTable_openReadFile (context_fileTable (), fname);
if (innerf != NULL)
{
fileloc fc = g_currentloc;
g_currentloc = fileloc_createRc (fname);
- if (context_getFlag (FLG_SHOWSCAN))
- {
- lldiagmsg (message ("< reading options from %q >",
- fileloc_outputFilename (g_currentloc)));
- }
+ displayScan (message ("< reading options from %q >",
+ fileloc_outputFilename (g_currentloc)));
loadrc (innerf, passThroughArgs);
fileloc_reallyFree (g_currentloc);
{
DPRINTF (("Invalid: %s", thisflag));
- if (isMode (cstring_fromChars (thisflag)))
+ if (flags_isModeName (cstring_fromChars (thisflag)))
{
context_setMode (cstring_fromChars (thisflag));
}
else if (opt == FLG_INCLUDEPATH
|| opt == FLG_SPECPATH)
{
- cstring dir = cstring_suffix (cstring_fromChars (thisflag), 1); /* skip over I/S */
+ cstring dir;
+
+ /*
+ ** Either -I<dir> or -I <dir>
+ */
+
+ if (cstring_length (thisflag) > 1)
+ {
+ dir = cstring_suffix (cstring_fromChars (thisflag), 1); /* skip over I/S */
+ }
+ else
+ {
+ BADBRANCH; /*@!!!!@*/
+ }
switch (opt)
{
fileIdList_elements (fl, fid)
{
- cstring ppfname = fileName (fid);
+ cstring ppfname = fileTable_fileName (fid);
if (!(osd_fileIsReadable (ppfname)))
{
if ((filesprocessed % skip) == 0)
{
if (filesprocessed == 0) {
- fprintf (stderr, " ");
+ fprintf (g_messagestream, " ");
}
else {
- fprintf (stderr, ".");
+ fprintf (g_messagestream, ".");
}
- (void) fflush (stderr);
+ (void) fflush (g_messagestream);
}
filesprocessed++;
}
- if (cppProcess (ppfname, fileName (dfile)) != 0)
+ DPRINTF (("outfile: %s", fileTable_fileName (dfile)));
+
+ if (cppProcess (ppfname, fileTable_fileName (dfile)) != 0)
{
llfatalerror (message ("Preprocessing error for file: %s",
- rootFileName (fid)));
+ fileTable_rootFileName (fid)));
}
fileIdList_add (dfiles, dfile);
return specname;
}
# endif
+
+void warnSysFiles(fileIdList files)
+{
+ fileIdList_elements (files, file)
+ {
+
+ if (fileTable_isSystemFile (context_fileTable (), file) )
+ {
+ if (!context_getFlag( FLG_SYSTEMDIRERRORS ) )
+ {
+ 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);
+ }
+ }
+ }
+ end_fileIdList_elements;
+}