]> andersk Git - splint.git/blobdiff - src/llmain.c
Fixed state clauses. Added obvious loop exec checking.
[splint.git] / src / llmain.c
index 013fedd27da2d37052118c53f53b67fa44302e31..5bf2b57dde01c930d53a5585f8f1a4e0882a2232 100644 (file)
@@ -1,6 +1,6 @@
 /*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2001 University of Virginia,
+** Splint - annotation-assisted static program checker
+** Copyright (C) 1994-2002 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
 **
 ** For information on lclint: lclint-request@cs.virginia.edu
 ** To report a bug: lclint-bug@cs.virginia.edu
-** For more information: http://lclint.cs.virginia.edu
+** For more information: http://www.splint.org
 */
 /*
 ** llmain.c
 **
-** Main module for LCLint checker
+** Main module for Splint annotation-assisted program checker
 */
 
 # include <signal.h>
-
+# include <time.h>
 /*
 ** Ensure that WIN32 and _WIN32 are both defined or both undefined.
 */
 # endif
 
 # include "version.h"
-# include "herald.h"
 # include "fileIdList.h"
 # include "lcllib.h"
 # include "cgrammar.h"
 # include "llmain.h"
 # include "portab.h"
-# include "mtreader.h"
-# include <time.h>
+
 
 extern /*@external@*/ int yydebug;
 
@@ -93,7 +91,13 @@ static void cleanupFiles (void);
 static void showHelp (void);
 static void interrupt (int p_i);
 
-static void loadrc (/*@open@*/ FILE *p_rcfile, cstringSList *p_passThroughArgs)
+static bool readOptionsFile (cstring p_fname,
+                            cstringSList *p_passThroughArgs,
+                            bool p_report) 
+   /*@modifies fileSystem, internalState, *p_passThroughArgs@*/ ;
+   
+static void loadrc (FILE *p_rcfile, cstringSList *p_passThroughArgs)
+   /*@modifies *p_passThroughArgs, p_rcfile@*/
    /*@ensures closed p_rcfile@*/ ;
 
 static void describeVars (void);
@@ -326,12 +330,12 @@ lslProcess (fileIdList lclfiles)
        {
          if (mstring_equal (g_localSpecPath, "."))
            {
-             lldiagmsg (message ("Spec file not found: %s", fname));
+             lldiagmsg (message ("Spec file not found: %q", osd_outputPath (fname)));
            }
          else
            {
-             lldiagmsg (message ("Spec file not found: %s (on %s)", 
-                                 fname
+             lldiagmsg (message ("Spec file not found: %q (on %s)", 
+                                 osd_outputPath (fname)
                                  cstring_fromChars (g_localSpecPath)));
            }
        }
@@ -369,8 +373,8 @@ lslProcess (fileIdList lclfiles)
          
          if (!inputStream_open (specFile))
            {
-             lldiagmsg (message ("Cannot open file: %s",
-                                 inputStream_fileName (specFile)));
+             lldiagmsg (message ("Cannot open file: %q",
+                                 osd_outputPath (inputStream_fileName (specFile))));
              inputStream_free (specFile);
            }
          else
@@ -487,9 +491,10 @@ static void handlePassThroughFlag (char *arg)
   if (open)
     {
       showHerald ();
-      llerror (FLG_BADFLAG,
-              message ("Unclosed quote in flag: %s",
-                       cstring_fromChars (arg)));
+      voptgenerror (FLG_BADFLAG,
+                   message ("Unclosed quote in flag: %s",
+                            cstring_fromChars (arg)),
+                   g_currentloc);
     }
   else
     {
@@ -522,27 +527,61 @@ void showHerald (void)
 
   else
     {
-      fprintf (g_msgstream, "%s\n\n", LCL_VERSION);
+      fprintf (g_msgstream, "%s\n\n", SPLINT_VERSION);
       hasShownHerald = TRUE;
       llflush ();
     }
 }
 
-static void addFile (fileIdList files, /*@only@*/ cstring s)
+static cstring findLarchPathFile (/*@temp@*/ cstring s)
 {
-  if (fileTable_exists (context_fileTable (), s))
+  cstring pathName;
+  filestatus status;
+  
+  status = osd_getPath (context_getLarchPath (), s, &pathName);
+  
+  if (status == OSD_FILEFOUND)
+    {
+      return pathName;
+    }
+  else if (status == OSD_FILENOTFOUND)
     {
       showHerald ();
-      lldiagmsg (message ("File listed multiple times: %s", s));
-      cstring_free (s);
+      lldiagmsg        (message ("Cannot find file on LARCHPATH: %s", s));
+    }
+  else if (status == OSD_PATHTOOLONG)
+    {
+      /* Directory and filename are too long.  Report error. */
+      llbuglit ("soure_getPath: Filename plus directory from search path too long");
     }
   else
     {
-      fileIdList_add (files, fileTable_addFileOnly (context_fileTable (), s));
+      BADBRANCH;
+    }
+
+  return cstring_undefined;
+}
+
+static void addLarchPathFile (fileIdList files, /*@temp@*/ cstring s)
+{
+  cstring pathName = findLarchPathFile (s);
+
+  if (cstring_isDefined (pathName))
+    {
+      if (fileTable_exists (context_fileTable (), pathName))
+       {
+         showHerald ();
+         lldiagmsg (message ("File listed multiple times: %s", pathName));
+         cstring_free (pathName);
+       }
+      else
+       {
+         fileIdList_add (files, fileTable_addFileOnly (context_fileTable (), pathName));
+       }
     }
 }
 
-static void addXHFile (fileIdList files, /*@only@*/ cstring s)
+static void addFile (fileIdList files, /*@only@*/ cstring s)
 {
   if (fileTable_exists (context_fileTable (), s))
     {
@@ -552,11 +591,30 @@ static void addXHFile (fileIdList files, /*@only@*/ cstring s)
     }
   else
     {
-      fileIdList_add (files, fileTable_addXHFile (context_fileTable (), s));
-      cstring_free (s);
+      fileIdList_add (files, fileTable_addFileOnly (context_fileTable (), s));
     }
 }
 
+static void addXHFile (fileIdList files, /*@temp@*/ cstring s)
+{
+  cstring pathName = findLarchPathFile (s);
+
+  if (cstring_isDefined (pathName))
+    {
+      if (fileTable_exists (context_fileTable (), pathName))
+       {
+         showHerald ();
+         lldiagmsg (message ("File listed multiple times: %s", s));
+       }
+      else
+       {
+         fileIdList_add (files, fileTable_addXHFile (context_fileTable (), pathName));
+       }
+    }
+
+  cstring_free (pathName);
+}
+
 /*
 ** Disable MSVC++ warning about return value.  Methinks humbly lclint control
 ** comments are a mite more legible.
@@ -603,6 +661,10 @@ int main (int argc, char *argv[])
   clock_t before, lcltime, libtime, pptime, cptime, rstime;
   int i = 0;
 
+# ifdef __EMX__
+  _wildcard (&argc, &argv);
+# endif
+
   g_msgstream = stdout;
 
   (void) signal (SIGINT, interrupt);
@@ -617,6 +679,8 @@ int main (int argc, char *argv[])
   clabstract_initMod ();
   typeIdSet_initMod ();
   cppReader_initMod ();
+  osd_initMod ();
+
   setCodePoint ();
   
   g_currentloc = fileloc_createBuiltin ();
@@ -688,6 +752,16 @@ int main (int argc, char *argv[])
            /*@noaccess cstring@*/
          }
       }
+    else /* 2001-09-09: herbert */
+      {
+       /* 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));
+         }
+      }
+    /* /herbert */
 
     cstring_free (oincval);
   }
@@ -698,8 +772,7 @@ int main (int argc, char *argv[])
 
   {
     cstring home = osd_getHomeDir ();
-    char *fname  = NULL;
-    FILE *rcfile;
+    cstring fname  = cstring_undefined;
     bool defaultf = TRUE;
     bool nof = FALSE;
 
@@ -710,35 +783,31 @@ int main (int argc, char *argv[])
        
        if (*thisarg == '-' || *thisarg == '+')
          {
+           bool set = (*thisarg == '+');
+           flagcode opt;
+
            thisarg++;
+           opt = identifyFlag (cstring_fromChars (thisarg));
 
-           if (mstring_equal (thisarg, "nof"))
+           if (opt == FLG_NOF)
              {
                nof = TRUE;
              }
-           else if (mstring_equal (thisarg, "f"))
+           else if (opt == FLG_SHOWSCAN || opt == FLG_WARNRC)
+             {
+               /*
+               ** Need to set it immediately, so rc file scan is displayed
+               */
+
+               context_userSetFlag (opt, set);
+             }
+           else if (opt == FLG_OPTF)
              {
                if (++i < argc)
                  {
                    defaultf = FALSE;
-                   fname = argv[i];
-                   rcfile = fopen (fname, "r");
-
-                   if (rcfile != NULL)
-                     {
-                       fileloc oloc = g_currentloc;
-                       
-                       g_currentloc = fileloc_createRc (cstring_fromChars (fname));
-                       loadrc (rcfile, &passThroughArgs);
-                       fileloc_reallyFree (g_currentloc); 
-                       g_currentloc = oloc;
-                     }
-                   else 
-                     {
-                       showHerald ();
-                       lldiagmsg (message ("Options file not found: %s", 
-                                           cstring_fromChars (fname)));
-                     }
+                   fname = cstring_fromChars (argv[i]);
+                   (void) readOptionsFile (fname, &passThroughArgs, TRUE);
                  }
                else
                  llfatalerror
@@ -751,55 +820,75 @@ int main (int argc, char *argv[])
              }
          }
       }
-    
-    if (fname == NULL)
-      {
-       if (!cstring_isEmpty (home)) {
-         fname = cstring_toCharsSafe (message ("%s%h%s", home, CONNECTCHAR,
-                                               cstring_fromChars (RCFILE)));
-         mstring_markFree (fname);
-       }
-      }
-
+        
     setCodePoint ();
 
     if (!nof && defaultf)
       {
-       if (!mstring_isEmpty (fname)) {
-         rcfile = fopen (fname, "r");
-         
-         if (rcfile != NULL)
-           {
-             fileloc oloc = g_currentloc;
-             
-             g_currentloc = fileloc_createRc (cstring_fromChars (fname));
-             loadrc (rcfile, &passThroughArgs);
-             fileloc_reallyFree (g_currentloc);
-             g_currentloc = oloc;
-           }
-       }
-
-# if defined(MSDOS) || defined(OS2)
-       fname = cstring_toCharsSafe (message ("%s",
-                                             cstring_fromChars (RCFILE)));
-# else
-       fname = cstring_toCharsSafe (message ("./%s", 
-                                             cstring_fromChars (RCFILE)));
-# endif
-
-       rcfile = fopen (fname, "r");
+       /*
+       ** No explicit rc file, first try reading ~/.splintrc
+       */
 
-       if (rcfile != NULL)
+       if (cstring_isUndefined (fname))
          {
-           fileloc oloc = g_currentloc;
+           if (!cstring_isEmpty (home)) 
+             {
+               bool readhomerc, readaltrc;
+               cstring homename, altname;
+
+               homename = message ("%s%h%s", home, CONNECTCHAR,
+                                cstring_fromChars (RCFILE));
+               readhomerc = readOptionsFile (homename, &passThroughArgs, FALSE);
+               
+               /*
+               ** Try ~/.lclintrc also for historical accuracy
+               */
+               
+               altname = message ("%s%h%s", home, CONNECTCHAR,
+                                cstring_fromChars (ALTRCFILE));
+               readaltrc = readOptionsFile (altname, &passThroughArgs, FALSE);
+
+               if (readhomerc && readaltrc)
+                 {
+
+                   voptgenerror 
+                     (FLG_WARNRC,
+                      message ("Found both %s and %s files. Using both files, "
+                               "but recommend using only %s to avoid confusion.",
+                               homename, altname, homename),
+                      g_currentloc);
+                 }
 
-           g_currentloc = fileloc_createRc (cstring_fromChars (fname));
-           loadrc (rcfile, &passThroughArgs);
-           fileloc_reallyFree (g_currentloc);
-           g_currentloc = oloc;
+               cstring_free (homename);
+               cstring_free (altname);
+             }
          }
+       
+       /*
+       ** Next, read .splintrc in the current working directory
+       */
+       
+       {
+         cstring rcname = message ("%s%s",osd_getCurrentDirectory (), cstring_fromChars (RCFILE));
+         cstring altname = message ("%s%s",osd_getCurrentDirectory (), cstring_fromChars (ALTRCFILE));
+         bool readrc, readaltrc;
+         
+         readrc = readOptionsFile (rcname, &passThroughArgs, FALSE);
+         readaltrc = readOptionsFile (altname, &passThroughArgs, FALSE);
+         
+         if (readrc && readaltrc)
+           {
+             voptgenerror (FLG_WARNRC,
+                           message ("Found both %s and %s files. Using both files, "
+                                    "but recommend using only %s to avoid confusion.",
+                                    rcname, altname, rcname),
+                           g_currentloc);
+             
+           }
 
-       sfree (fname); 
+         cstring_free (rcname);
+         cstring_free (altname);
+       }
       }
   }
   
@@ -914,8 +1003,9 @@ int main (int argc, char *argv[])
              opt = identifyFlag (flagname);
              DPRINTF (("Flag: %s", flagcode_unparse (opt)));
 
-             if (flagcode_isSkip (opt))
+             if (flagcode_isSkip (opt) || opt == FLG_SHOWSCAN || opt == FLG_WARNRC)
                {
+                 /* showscan already processed */
                  DPRINTF (("Skipping!"));
                }
              else if (flagcode_isInvalid (opt))
@@ -929,8 +1019,10 @@ int main (int argc, char *argv[])
                  else
                    {
                      DPRINTF (("Error!"));
-                     llgloberror (message ("Unrecognized option: %s", 
-                                           cstring_fromChars (thisarg)));
+                     voptgenerror (FLG_BADFLAG,
+                                   message ("Unrecognized option: %s", 
+                                            cstring_fromChars (thisarg)),
+                                   g_currentloc);
                    }
                }
              else
@@ -1013,9 +1105,12 @@ int main (int argc, char *argv[])
                                      /*
                                      ** arg identifies mts files
                                      */
-                                     
-                                     addFile (mtfiles, message ("%s%s", arg, MTS_EXTENSION));
-                                     addXHFile (xfiles, message ("%s%s", arg, XH_EXTENSION));
+                                     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
                                    {
@@ -1047,7 +1142,8 @@ int main (int argc, char *argv[])
     }
 
   setCodePoint ();  
-
+  showHerald (); 
+  
   /*
   ** create lists of C and LCL files
   */
@@ -1065,7 +1161,20 @@ int main (int argc, char *argv[])
        }
       else if (cstring_equal (ext, XH_EXTENSION))
        {
-         addXHFile (xfiles, cstring_copy (current));
+         addXHFile (xfiles, current);
+       }
+      else if (cstring_equal (ext, PP_EXTENSION))
+       {
+         if (!context_getFlag (FLG_NOPP))
+           {
+             voptgenerror 
+               (FLG_FILEEXTENSIONS,
+                message ("File extension %s used without +nopp flag (will be processed as C source code): %s", 
+                         ext, current),
+                g_currentloc);
+           }
+         
+         addFile (cfiles, cstring_copy (current));
        }
       else if (cstring_equal (ext, LCL_EXTENSION)) 
        {
@@ -1077,7 +1186,7 @@ int main (int argc, char *argv[])
        }
       else if (cstring_equal (ext, MTS_EXTENSION))
        {
-         addFile (mtfiles, cstring_copy (current));
+         addLarchPathFile (mtfiles, current);
        }
       else 
        {
@@ -1091,8 +1200,6 @@ int main (int argc, char *argv[])
        }
     } end_cstringSList_elements;
   
-    showHerald (); /*@i723 move earlier? */
-  
   if (showhelp)
     {
       if (allhelp)
@@ -1179,7 +1286,7 @@ int main (int argc, char *argv[])
   if (anylcl)
     {
 # ifdef NOLCL
-      llfatalerror (cstring_makeLiteral ("This version of LCLint does not handle LCL files."));
+      llfatalerror (cstring_makeLiteral ("This version of Splint does not handle LCL files."));
 # else
       lslProcess (lclfiles);
 # endif
@@ -1294,7 +1401,7 @@ int main (int argc, char *argv[])
 
          if (context_getFlag (FLG_SHOWSCAN))
            {
-             lldiagmsg (message ("< checking %s >", rootFileName (fid)));
+             lldiagmsg (message ("< checking %q >", osd_outputPath (rootFileName (fid))));
            }
          
          /*
@@ -1411,7 +1518,7 @@ int main (int argc, char *argv[])
        if (nspecErrors == context_getLCLExpect ())
          {
            specErrors = 
-             message ("%d spec error%& found, as expected\n       ", 
+             message ("%d spec warning%&, as expected\n       ", 
                       nspecErrors);
          }
        else
@@ -1419,13 +1526,13 @@ int main (int argc, char *argv[])
            if (context_getLCLExpect () > 0)
              {
                specErrors = 
-                 message ("%d spec error%& found, expected %d\n       ", 
+                 message ("%d spec warning%&, expected %d\n       ", 
                           nspecErrors,
                           (int) context_getLCLExpect ());
              }
            else
              {
-               specErrors = message ("%d spec error%& found\n       ",
+               specErrors = message ("%d spec warning%& found\n       ",
                                      nspecErrors);
                expsuccess = FALSE;
              }
@@ -1435,7 +1542,7 @@ int main (int argc, char *argv[])
        {
          if (context_getLCLExpect () > 0)
            {
-             specErrors = message ("No spec errors found, expected %d\n       ", 
+             specErrors = message ("No spec warnings, expected %d\n       ", 
                                    (int) context_getLCLExpect ());
              expsuccess = FALSE;
            }
@@ -1447,8 +1554,8 @@ int main (int argc, char *argv[])
          if (context_numErrors () == context_getExpect ())
            {
              if (!isQuiet) {
-               llmsg (message ("Finished LCLint checking --- "
-                               "%s%d code error%& found, as expected",
+               llmsg (message ("Finished checking --- "
+                               "%s%d code warning%&, as expected",
                                specErrors, context_numErrors ()));
              }
            }
@@ -1458,8 +1565,8 @@ int main (int argc, char *argv[])
                {
                  if (!isQuiet) {
                    llmsg (message 
-                          ("Finished LCLint checking --- "
-                           "%s%d code error%& found, expected %d",
+                          ("Finished checking --- "
+                           "%s%d code warning%&, expected %d",
                            specErrors, context_numErrors (), 
                            (int) context_getExpect ()));
                  }
@@ -1471,8 +1578,8 @@ int main (int argc, char *argv[])
                  
                  if (!isQuiet)
                    {
-                     llmsg (message ("Finished LCLint checking --- "
-                                     "%s%d code error%& found", 
+                     llmsg (message ("Finished checking --- "
+                                     "%s%d code warning%& found", 
                                      specErrors, context_numErrors ()));
                    }
 
@@ -1486,8 +1593,8 @@ int main (int argc, char *argv[])
            {
              if (!isQuiet) {
                llmsg (message
-                      ("Finished LCLint checking --- "
-                       "%sno code errors found, expected %d", 
+                      ("Finished checking --- "
+                       "%sno code warnings, expected %d", 
                        specErrors,
                        (int) context_getExpect ()));
              }
@@ -1498,15 +1605,26 @@ int main (int argc, char *argv[])
            {
              if (context_getLinesProcessed () > 0)
                {
-                 if (!isQuiet) {
-                   llmsg (message ("Finished LCLint checking --- %sno code errors found", 
-                                   specErrors));
-                 }
+                 if (cstring_isEmpty (specErrors))
+                   {
+                     if (!isQuiet) 
+                       {
+                         llmsg (message ("Finished checking --- no warnings"));
+                       } 
+                   }
+                 else
+                   {
+                     if (!isQuiet) 
+                       {
+                         llmsg (message ("Finished checking --- %sno code warnings",
+                                         specErrors));
+                       }
+                   }
                }
              else
                {
                  if (!isQuiet) {
-                   llmsg (message ("Finished LCLint checking --- %sno code processed", 
+                   llmsg (message ("Finished checking --- %sno code processed", 
                                    specErrors));
                  }
                }
@@ -1578,6 +1696,7 @@ int main (int argc, char *argv[])
     }
 
   llexit (expsuccess ? LLSUCCESS : LLFAILURE);
+  BADBRANCHRET (LLFAILURE);
 }
 
 # ifdef WIN32
@@ -1594,9 +1713,9 @@ showHelp (void)
   
   llmsg (message ("Source files are .c, .h and %s files.  If there is no suffix,",
                  LCL_EXTENSION));
-  llmsg (message ("   LCLint will look for <file>.c and <file>%s.", LCL_EXTENSION));
+  llmsg (message ("   Splint will look for <file>.c and <file>%s.", LCL_EXTENSION));
   llmsglit ("");
-  llmsglit ("Use lclint -help <topic or flag name> for more information");
+  llmsglit ("Use splint -help <topic or flag name> for more information");
   llmsglit ("");
   llmsglit ("Topics:");
   llmsglit ("");
@@ -1670,12 +1789,12 @@ printParseErrors (void)
            "it is not advisible to use these, oftentimes one has no choice "
            "when the system header files use compiler extensions. ");
   llmsglit ("");
-  llmsglit ("LCLint supports some of the GNU (gcc) compiler extensions, "
+  llmsglit ("Splint supports some of the GNU (gcc) compiler extensions, "
            "if the +gnuextensions flag is set. You may be able to workaround "
            "other compiler extensions by using a pre-processor define. "
            "Alternately, you can surround the unparseable code with");
   llmsglit ("");
-  llmsglit ("   # ifndef __LCLINT__");
+  llmsglit ("   # ifndef S_SPLINT_S");
   llmsglit ("   ...");
   llmsglit ("   # endif");
   llmsglit ("");
@@ -1683,7 +1802,7 @@ printParseErrors (void)
   llmsglit ("Missing type definitions --- an undefined type name will usually "
            "lead to a parse error. This often occurs when a standard header "
            "file defines some type that is not part of the standard library. ");
-  llmsglit ("By default, LCLint does not process the local files corresponding "
+  llmsglit ("By default, Splint does not process the local files corresponding "
            "to standard library headers, but uses a library specification "
            "instead so dependencies on local system headers can be detected. "
            "If another system header file that does not correspond to a "
@@ -1691,7 +1810,7 @@ printParseErrors (void)
            "a parse error will result.");
   llmsglit ("");
   llmsglit ("If the parse error is inside a posix standard header file, the "
-           "first thing to try is +posixlib. This make LCLint use "
+           "first thing to try is +posixlib. This makes Splint use "
            "the posix library specification instead of reading the posix "
            "header files.");
   llmsglit ("");
@@ -1711,9 +1830,9 @@ printParseErrors (void)
   llmsglit ("   /*@=skipposixheaders@*/");
   llmsglit ("   # include <sys/local.h>");
   llmsglit ("");
-  llmsglit ("to force LCLint to process <sys/types.h>.");
+  llmsglit ("to force Splint to process <sys/types.h>.");
   llmsglit ("");
-  llmsglit ("At last resort, +trytorecover can be used to make LCLint attempt "
+  llmsglit ("At last resort, +trytorecover can be used to make Splint attempt "
            "to continue after a parse error.  This is usually not successful "
            "and the author does not consider assertion failures when +trytorecover "
            "is used to be bugs.");
@@ -1871,7 +1990,7 @@ printComments (void)
   llmsglit ("/*@i<n>@*/");
   llgenindentmsgnoloc
     (cstring_makeLiteral 
-     ("No errors will be reported from an /*@i<n>@*/ (e.g., /*@i3@*/) comment to the end of the line. If there are not exactly n errors suppressed from the comment point to the end of the line, LCLint will report an error."));
+     ("No errors will be reported from an /*@i<n>@*/ (e.g., /*@i3@*/) comment to the end of the line. If there are not exactly n errors suppressed from the comment point to the end of the line, Splint will report an error."));
   llmsglit ("/*@t@*/, /*@t<n>@*/");
   llgenindentmsgnoloc
     (cstring_makeLiteral 
@@ -1919,7 +2038,7 @@ printMail (void)
   llmsglit ("Mailing Lists");
   llmsglit ("-------------");
   llmsglit ("");
-  llmsglit ("There are two mailing lists associated with LCLint: ");
+  llmsglit ("There are two mailing lists associated with Splint: ");
   llmsglit ("");
   llmsglit ("   lclint-announce@virginia.edu");
   llmsglit ("");
@@ -1940,24 +2059,7 @@ printReferences (void)
   llmsglit ("References");
   llmsglit ("----------");
   llmsglit ("");
-  llmsglit ("The LCLint web site is http://lclint.cs.virginia.edu");
-  llmsglit ("");
-  llmsglit ("Technical papers relating to LCLint include:");
-  llmsglit ("");
-  llmsglit ("   David Evans. \"Static Detection of Dynamic Memory Errors\".");  
-  llmsglit ("   SIGPLAN Conference on Programming Language Design and ");
-  llmsglit ("   Implementation (PLDI '96), Philadelphia, PA, May 1996.");
-  llmsglit ("");
-  llmsglit ("   David Evans, John Guttag, Jim Horning and Yang Meng Tan. ");
-  llmsglit ("   \"LCLint: A Tool for Using Specifications to Check Code\".");
-  llmsglit ("   SIGSOFT Symposium on the Foundations of Software Engineering,");
-  llmsglit ("   December 1994.");
-  llmsglit ("");
-  llmsglit ("A general book on Larch is:");
-  llmsglit ("");
-  llmsglit ("   Guttag, John V., Horning, James J., (with Garland, S. J., Jones, ");
-  llmsglit ("   K. D., Modet, A., and Wing, J. M.), \"Larch: Languages and Tools ");
-  llmsglit ("   for Formal Specification\", Springer-Verlag, 1993.");
+  llmsglit ("For more information, see the Splint web site: http://www.splint.org");
 }
 
 void
@@ -2025,7 +2127,7 @@ describeVars (void)
   llmsglit ("   --- path used to find #include'd files");
 
   llmsg (message 
-        ("systemdirs = %s (set by -systemdirs or envirnoment variable %s)", /*@i413223@*/
+        ("systemdirs = %s (set by -systemdirs or environment variable %s)", /*@i413223@*/
          context_getString (FLG_SYSTEMDIRS),
          INCLUDEPATH_VAR));
 
@@ -2084,6 +2186,13 @@ cleanupFiles (void)
 
   setCodePoint ();
 
+  /*
+  ** Close all open files
+  **    (There should only be open files, if we exited after a fatal error.)
+  */
+
+  fileTable_closeAll (context_fileTable ());
+
   if (context_getFlag (FLG_KEEP))
     {
       check (fputs ("Temporary files kept:\n", stderr) != EOF);
@@ -2106,8 +2215,7 @@ cleanupFiles (void)
 }
 
 /*
-** cleans up temp files (if necessary)
-** exits lclint
+** cleans up temp files (if necessary) and exits
 */
 
 /*@exits@*/ void
@@ -2141,13 +2249,67 @@ llexit (int status)
   exit ((status == LLSUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
+bool readOptionsFile (cstring fname, cstringSList *passThroughArgs, bool report)
+{
+  bool res = FALSE;
+
+  if (fileTable_exists (context_fileTable (), fname))
+    {
+      if (report)
+       {
+         voptgenerror
+           (FLG_WARNRC, 
+            message ("Multiple attempts to read options file: %s", fname),
+            g_currentloc);
+       }
+    }
+  else
+    {
+      FILE *innerf = fileTable_openFile (context_fileTable (), fname, "r");
+      
+      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)));
+           }
+         
+         loadrc (innerf, passThroughArgs);
+         fileloc_reallyFree (g_currentloc);
+         g_currentloc = fc;
+         res = TRUE;
+       }
+      else 
+       {
+         if (report)
+           {
+             voptgenerror
+               (FLG_WARNRC, 
+                message ("Cannot open options file: %s", fname),
+                g_currentloc);
+           }
+       }
+    }
+
+  return res;
+}
+
+/*
+** This shouldn't be necessary, but Apple Darwin can't handle '"''s.
+*/
+
 void
-loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
-    /*@ensures closed rcfile@*/
+loadrc (/*:open:*/ FILE *rcfile, cstringSList *passThroughArgs)
+   /*@modifies rcfile@*/
+   /*@ensures closed rcfile@*/
 {
   char *s = mstring_create (MAX_LINE_LENGTH);
   char *os = s;
-
+  
   DPRINTF (("Pass through: %s", cstringSList_unparse (*passThroughArgs)));
 
   s = os;
@@ -2190,10 +2352,11 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
          else
            {
              showHerald ();
-             llerror (FLG_SYNTAX, 
-                      message ("Bad flag syntax (+ or - expected, "
-                               "+ is assumed): %s", 
-                               cstring_fromChars (s)));
+             voptgenerror (FLG_BADFLAG, 
+                           message ("Bad flag syntax (+ or - expected, "
+                                    "+ is assumed): %s", 
+                                    cstring_fromChars (s)),
+                           g_currentloc);
              s--;
              set = TRUE;
            }
@@ -2267,9 +2430,10 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
                }
              else
                {
-                 llerror (FLG_BADFLAG,
-                          message ("Unrecognized option: %s", 
-                                   cstring_fromChars (thisflag)));
+                 voptgenerror (FLG_BADFLAG,
+                               message ("Unrecognized option: %s", 
+                                        cstring_fromChars (thisflag)),
+                               g_currentloc);
                }
            }
          else
@@ -2281,8 +2445,9 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
                  if (opt == FLG_HELP)
                    {
                      showHerald ();
-                     llerror (FLG_BADFLAG,
-                              message ("Cannot use help in rc files"));
+                     voptgenerror (FLG_BADFLAG,
+                                   message ("Cannot use help in rc files"),
+                                   g_currentloc);
                    }
                  else if (flagcode_isPassThrough (opt)) /* -D or -U */
                    {
@@ -2348,11 +2513,12 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
                      if (cstring_isUndefined (extra))
                        {
                          showHerald ();
-                         llerror 
+                         voptgenerror 
                            (FLG_BADFLAG,
                             message
                             ("Flag %s must be followed by an argument",
-                             flagcode_unparse (opt)));
+                             flagcode_unparse (opt)),
+                            g_currentloc);
                        }
                      else
                        {
@@ -2364,29 +2530,10 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
                            {
                              DPRINTF (("Set value flag: %s", extra));
                              setValueFlag (opt, extra);
-                             cstring_free (extra);
                            }
                          else if (opt == FLG_OPTF)
                            {
-                             FILE *innerf = fopen (cstring_toCharsSafe (extra), "r");
-                             cstring_markOwned (extra);
-                             
-                             if (innerf != NULL)
-                               {
-                                 fileloc fc = g_currentloc;
-                                 g_currentloc = fileloc_createRc (extra);
-                                 loadrc (innerf, passThroughArgs);
-                                 fileloc_reallyFree (g_currentloc);
-                                 g_currentloc = fc;
-                               }
-                             else 
-                               {
-                                 showHerald ();
-                                 llerror
-                                   (FLG_SYNTAX, 
-                                    message ("Options file not found: %s", 
-                                             extra));
-                               }
+                             (void) readOptionsFile (extra, passThroughArgs, TRUE);
                            }
                          else if (opt == FLG_INIT)
                            {
@@ -2394,43 +2541,56 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
                              llassert (inputStream_isUndefined (initFile));
                              
                              initFile = inputStream_create 
-                               (extra
+                               (cstring_copy (extra)
                                 cstring_makeLiteralTemp (LCLINIT_SUFFIX),
                                 FALSE);
-# else
-                             cstring_free (extra);
 # endif
                            }
                          else if (flagcode_hasString (opt))
                            {
-                             if (cstring_firstChar (extra) == '"')
+                             DPRINTF (("Here: %s", extra));
+
+                             /*
+                             ** If it has "'s, we need to remove them.
+                             */
+
+                             if (cstring_firstChar (extra) == '\"')
                                {
-                                 if (cstring_lastChar (extra) == '"')
+                                 if (cstring_lastChar (extra) == '\"')
                                    {
-                                     char *extras = cstring_toCharsSafe (extra);
-                                     
-                                     llassert (extras[strlen(extras) - 1] == '"');
-                                     extras[strlen(extras) - 1] = '\0';
-                                     extra = cstring_fromChars (extras + 1); 
-                                     DPRINTF (("Remove quites: %s", extra));
+                                     cstring unquoted = cstring_copyLength 
+                                       (cstring_toCharsSafe (cstring_suffix (extra, 1)),
+                                        cstring_length (extra) - 2);
+
+                                     DPRINTF (("string flag: %s -> %s", extra, unquoted));
+                                     setStringFlag (opt, unquoted);
+                                     cstring_free (extra);
                                    }
                                  else
                                    {
-                                     llerror
-                                       (FLG_SYNTAX
+                                     voptgenerror
+                                       (FLG_BADFLAG
                                         message ("Unmatched \" in option string: %s", 
-                                                 extra));
+                                                 extra),
+                                        g_currentloc);
+                                     setStringFlag (opt, extra);
                                    }
                                }
-                             
-                             setStringFlag (opt, extra);
+                             else
+                               {
+                                 DPRINTF (("No quotes: %s", extra));
+                                 setStringFlag (opt, extra);
+                               }
+
+                             extra = cstring_undefined;
                            }
                          else
                            {
-                             cstring_free (extra);
                              BADEXIT;
                            }
                        }
+
+                     cstring_free (extra); 
                    }
                  else
                    {
@@ -2453,7 +2613,7 @@ loadrc (/*@open@*/ FILE *rcfile, cstringSList *passThroughArgs)
 
   DPRINTF (("Pass through: %s", cstringSList_unparse (*passThroughArgs)));
   sfree (os); 
-  check (fclose (rcfile) == 0);
+  check (fileTable_closeFile (context_fileTable (), rcfile));
 }
 
 static fileIdList preprocessFiles (fileIdList fl, bool xhfiles)
@@ -2471,43 +2631,21 @@ static fileIdList preprocessFiles (fileIdList fl, bool xhfiles)
     {
       cstring ppfname = fileName (fid);
 
-      if (xhfiles)
-       {
-         cstring fpath;
-         
-         if (osd_findOnLarchPath (ppfname, &fpath) == OSD_FILEFOUND)
-           {
-             if (cstring_equal (ppfname, fpath))
-               {
-                 ;
-               }
-             else
-               {
-                 DPRINTF (("xh file: %s", fpath));
-                 ppfname = fpath;
-                 fileTable_setFilePath (context_fileTable (), fid, fpath);
-               }
-           }
-         else
-           {
-             lldiagmsg (message ("Cannot find .xh file on LARCH_PATH: %s", ppfname));
-             lldiagmsg (cstring_makeLiteral ("     Check LARCH_PATH environment variable."));
-             ppfname = cstring_undefined;
-           }
-       }
-      else
+      if (!(osd_fileIsReadable (ppfname)))
        {
-         if (!(osd_fileIsReadable (ppfname)))
-           {
-             lldiagmsg (message ("Cannot open file: %s", ppfname));
-             ppfname = cstring_undefined;
-           }
+         lldiagmsg (message ("Cannot open file: %q", osd_outputPath (ppfname)));
+         ppfname = cstring_undefined;
        }
 
       if (cstring_isDefined (ppfname))
        {
          fileId dfile = fileTable_addCTempFile (context_fileTable (), fid);
-         
+
+         if (xhfiles)
+           {
+             llassert (fileTable_isXHFile (context_fileTable (), dfile));
+           }
+
          llassert (cstring_isNonEmpty (ppfname));
          
          if (msg)
This page took 0.102098 seconds and 4 git commands to generate.