]> andersk Git - splint.git/blobdiff - src/llmain.c
*** empty log message ***
[splint.git] / src / llmain.c
index ab163dece79a45e93d207c0961c5c46ddcb6e907..8340ea3b0df77dbf35d71d393dcdfb41e1b9b18e 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2000 University of Virginia,
+** Copyright (C) 1994-2001 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -28,7 +28,7 @@
 */
 
 # include <signal.h>
-
+# include <time.h>
 /*
 ** Ensure that WIN32 and _WIN32 are both defined or both undefined.
 */
@@ -76,8 +76,7 @@
 # include "cgrammar.h"
 # include "llmain.h"
 # include "portab.h"
-# include "cpp.h"
-# include <time.h>
+
 
 extern /*@external@*/ int yydebug;
 
@@ -92,17 +91,22 @@ static void describePrefixCodes (void);
 static void cleanupFiles (void);
 static void showHelp (void);
 static void interrupt (int p_i);
-static void loadrc (FILE *p_rcfile, cstringSList *p_passThroughArgs);
+
+static void loadrc (FILE *p_rcfile, cstringSList *p_passThroughArgs)
+     /*@ensures closed p_rcfile@*/ ;
+
 static void describeVars (void);
 static bool specialFlagsHelp (char *p_next);
 static bool hasShownHerald = FALSE;
+static char *specFullName (char *p_specfile, /*@out@*/ char **p_inpath) 
+     /*@modifies *p_inpath@*/ ;
 
 static bool anylcl = FALSE;
 static clock_t inittime;
 
-static /*@only@*/ /*@null@*/ tsource *initFile = (tsource *) 0;
+static /*@only@*/ /*@null@*/ inputStream initFile = inputStream_undefined;
 
-static fileIdList preprocessFiles (fileIdList)
+static fileIdList preprocessFiles (fileIdList, bool)
   /*@modifies fileSystem@*/ ;
 
 # ifndef NOLCL
@@ -150,34 +154,36 @@ static
   */
   
   cstring larchpath = context_getLarchPath ();
-  tsource *LSLinitFile = (tsource *) 0;
+  inputStream LSLinitFile = inputStream_undefined;
 
   setCodePoint ();
 
-  if (initFile == (tsource *) 0)
+  if (inputStream_isUndefined (initFile))
     {
-      initFile = tsource_create (INITFILENAME, LCLINIT_SUFFIX, FALSE);
+      initFile = inputStream_create (cstring_makeLiteral (INITFILENAME), 
+                                    cstring_makeLiteralTemp (LCLINIT_SUFFIX),
+                                    FALSE);
       
-      if (!tsource_getPath (cstring_toCharsSafe (larchpath), initFile))
+      if (!inputStream_getPath (larchpath, initFile))
        {
          lldiagmsg (message ("Continuing without LCL init file: %s",
-                             cstring_fromChars (tsource_fileName (initFile))));
+                             inputStream_fileName (initFile)));
        }
       else 
        {
-         if (!tsource_open (initFile))
+         if (!inputStream_open (initFile))
            {
              lldiagmsg (message ("Continuing without LCL init file: %s",
-                                 cstring_fromChars (tsource_fileName (initFile))));
+                                 inputStream_fileName (initFile)));
            }
        }
     }
   else 
     {
-      if (!tsource_open (initFile))
+      if (!inputStream_open (initFile))
        {
          lldiagmsg (message ("Continuing without LCL init file: %s",
-                             cstring_fromChars (tsource_fileName (initFile))));
+                             inputStream_fileName (initFile)));
        }
     }
 
@@ -202,9 +208,9 @@ static
   setCodePoint ();
 
   /* need this to initialize LCL checker */
-  llassert (initFile != NULL);
-      
-  if (tsource_isOpen (initFile))
+
+  llassert (inputStream_isDefined (initFile));      
+  if (inputStream_isOpen (initFile))
     {
       setCodePoint ();
 
@@ -217,24 +223,26 @@ static
       LCLProcessInitFileCleanup ();
 
       setCodePoint ();
-      check (tsource_close (initFile));
+      check (inputStream_close (initFile));
     }
   
   /* Initialize LSL init files, for parsing LSL signatures from LSL */
   
-  LSLinitFile = tsource_create ("lslinit.lsi", ".lsi", FALSE);
+  LSLinitFile = inputStream_create (cstring_makeLiteral ("lslinit.lsi"), 
+                                   cstring_makeLiteralTemp (".lsi"),
+                                   FALSE);
   
-  if (!tsource_getPath (cstring_toCharsSafe (larchpath), LSLinitFile))
+  if (!inputStream_getPath (larchpath, LSLinitFile))
     {
       lldiagmsg (message ("Continuing without LSL init file: %s",
-                         cstring_fromChars (tsource_fileName (LSLinitFile))));
+                         inputStream_fileName (LSLinitFile)));
     }
   else 
     {
-      if (!tsource_open (LSLinitFile))
+      if (!inputStream_open (LSLinitFile))
        {
          lldiagmsg (message ("Continuing without LSL init file: %s",
-                             cstring_fromChars (tsource_fileName (LSLinitFile))));
+                             inputStream_fileName (LSLinitFile)));
        }
     }
       
@@ -250,7 +258,7 @@ static
   lscanLineReset ();
   LSLScanInit ();
 
-  if (tsource_isOpen (LSLinitFile))
+  if (inputStream_isOpen (LSLinitFile))
     {
       setCodePoint ();
       LSLScanReset (LSLinitFile);
@@ -258,10 +266,10 @@ static
       setCodePoint ();
       LSLProcessInitFile ();
       setCodePoint ();
-      check (tsource_close (LSLinitFile));
+      check (inputStream_close (LSLinitFile));
     }
       
-  tsource_free (LSLinitFile);
+  inputStream_free (LSLinitFile);
   
   if (lclHadError ())
     {
@@ -309,38 +317,42 @@ lslProcess (fileIdList lclfiles)
 
   fileIdList_elements (lclfiles, fid)
     {
-      char *actualName = (char *) dmalloc (sizeof (*actualName));
-      char *oactualName = actualName;
-      char *fname = cstring_toCharsSafe (fileName (fid));
+      cstring actualName = cstring_undefined;
+      cstring fname = fileName (fid);
       
-      if (osd_getPath (g_localSpecPath, fname, &actualName) == OSD_FILENOTFOUND)
+      if (osd_getPath (cstring_fromChars (g_localSpecPath), 
+                      fname, &actualName) == OSD_FILENOTFOUND)
        {
          if (mstring_equal (g_localSpecPath, "."))
            {
-             lldiagmsg (message ("Spec file not found: %s",
-                                 cstring_fromChars (fname)));
+             lldiagmsg (message ("Spec file not found: %s", fname));
            }
          else
            {
              lldiagmsg (message ("Spec file not found: %s (on %s)", 
-                                 cstring_fromChars (fname)
+                                 fname
                                  cstring_fromChars (g_localSpecPath)));
            }
        }
       else
        {
-         tsource *specFile;
-         
-         while (*actualName == '.' && *(actualName + 1) == CONNECTCHAR) 
+         inputStream specFile;
+         /*@access cstring@*/
+         char *namePtr = actualName;
+
+         while (*namePtr == '.' && *(namePtr + 1) == CONNECTCHAR) 
            {
-             actualName += 2;
+             namePtr += 2;
            }
+         /*@noaccess cstring@*/
+
+         g_currentSpec = cstring_fromCharsNew (namePtr);
+
+         specFile = inputStream_create (cstring_copy (g_currentSpec),
+                                        LCL_EXTENSION, TRUE);
          
-         specFile = tsource_create (actualName, LCL_SUFFIX, TRUE);
-         llassert (specFile != (tsource *) 0);
+         llassert (inputStream_isDefined (specFile));
          
-         g_currentSpec = cstring_fromChars (mstring_copy (actualName));
-
          g_currentSpecName = specFullName 
            (cstring_toCharsSafe (g_currentSpec),
             &path);
@@ -354,11 +366,11 @@ lslProcess (fileIdList lclfiles)
          
          /* Open source file */
          
-         if (!tsource_open (specFile))
+         if (!inputStream_open (specFile))
            {
              lldiagmsg (message ("Cannot open file: %s",
-                                 cstring_fromChars (tsource_fileName (specFile))));
-             tsource_free (specFile);
+                                 inputStream_fileName (specFile)));
+             inputStream_free (specFile);
            }
          else
            {
@@ -387,32 +399,31 @@ lslProcess (fileIdList lclfiles)
                {
                  if (overallStatus)
                    {
-                     outputLCSFile (path, "%%FAILED Output from ",
+                     outputLCSFile (path, "%FAILED Output from ",
                                     g_currentSpecName);
                    }
                  else
                    {
-                     outputLCSFile (path, "%%PASSED Output from ", 
+                     outputLCSFile (path, "%PASSED Output from ", 
                                     g_currentSpecName);
                    }
                }
 
-             (void) tsource_close (specFile);
-             tsource_free (specFile);
+             (void) inputStream_close (specFile);
+             inputStream_free (specFile);
 
              symtable_exitScope (g_symtab);
-           }
+           }      
        }
-      
-      sfree (oactualName);
+      cstring_free (actualName);
     } end_fileIdList_elements; 
-  
+    
     /* Can cleanup lsl stuff right away */
-
-      lslCleanup ();
-  
-  g_currentSpec = cstring_undefined;
-  g_currentSpecName = NULL;
+    
+    lslCleanup ();
+    
+    g_currentSpec = cstring_undefined;
+    g_currentSpecName = NULL;
 }
 # endif
 
@@ -422,6 +433,7 @@ static void handlePassThroughFlag (char *arg)
   char *quotechar = strchr (curarg, '\"');
   int offset = 0;
   bool open = FALSE;
+  char *freearg = NULL;
 
   while (quotechar != NULL)
     {
@@ -444,6 +456,7 @@ static void handlePassThroughFlag (char *arg)
            }
        }
       
+      llassert (quotechar != NULL);
       *quotechar = '\0';
       offset = (quotechar - arg) + 2;
       
@@ -453,6 +466,7 @@ static void handlePassThroughFlag (char *arg)
            (message ("%s\"\'%s", 
                      cstring_fromChars (arg), 
                      cstring_fromChars (quotechar + 1))); 
+         freearg = arg;
          open = FALSE;
        }
       else
@@ -461,6 +475,7 @@ static void handlePassThroughFlag (char *arg)
            (message ("%s\'\"%s", 
                      cstring_fromChars (arg), 
                      cstring_fromChars (quotechar + 1)));
+         freearg = arg;
          open = TRUE;
        }
       
@@ -471,9 +486,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
     {
@@ -485,7 +501,7 @@ static void handlePassThroughFlag (char *arg)
        ** them.  This is an artifact of UNIX command line?
        */
 
-       def = osd_fixDefine (arg + 1);
+       def = osd_fixDefine (cstring_fromChars (arg + 1));
        DPRINTF (("Do define: %s", def));
        cppDoDefine (def);
        DPRINTF (("After define"));
@@ -496,6 +512,8 @@ static void handlePassThroughFlag (char *arg)
        BADBRANCH;
       }
     }
+  
+  sfree (freearg);
 }
 
 void showHerald (void)
@@ -524,6 +542,21 @@ static void addFile (fileIdList files, /*@only@*/ cstring s)
     }
 }
 
+static void addXHFile (fileIdList files, /*@only@*/ cstring s)
+{
+  if (fileTable_exists (context_fileTable (), s))
+    {
+      showHerald ();
+      lldiagmsg (message ("File listed multiple times: %s", s));
+      cstring_free (s);
+    }
+  else
+    {
+      fileIdList_add (files, fileTable_addXHFile (context_fileTable (), s));
+      cstring_free (s);
+    }
+}
+
 /*
 ** Disable MSVC++ warning about return value.  Methinks humbly lclint control
 ** comments are a mite more legible.
@@ -561,13 +594,12 @@ int main (int argc, char *argv[])
   bool showhelp = FALSE;
   bool allhelp = TRUE;
   bool expsuccess;
-  tsource *sourceFile = (tsource *) 0;
+  inputStream sourceFile = inputStream_undefined;
  
   fileIdList dercfiles;
   cstringSList fl = cstringSList_undefined;
   cstringSList passThroughArgs = cstringSList_undefined;
-  fileIdList cfiles;
-  fileIdList lclfiles;
+  fileIdList cfiles, xfiles, lclfiles, mtfiles;
   clock_t before, lcltime, libtime, pptime, cptime, rstime;
   int i = 0;
 
@@ -577,18 +609,21 @@ int main (int argc, char *argv[])
   (void) signal (SIGSEGV, interrupt); 
 
   cfiles = fileIdList_create ();
+  xfiles = fileIdList_create ();
   lclfiles = fileIdList_create ();
+  mtfiles = fileIdList_create ();
 
   flags_initMod ();
+  clabstract_initMod ();
   typeIdSet_initMod ();
   cppReader_initMod ();
-
   setCodePoint ();
-
+  
   g_currentloc = fileloc_createBuiltin ();
-
+  
   before = clock ();
   context_initMod ();
+
   context_setInCommandLine ();
 
   if (argc <= 1)
@@ -605,26 +640,28 @@ int main (int argc, char *argv[])
   */
 
   {
-    char *incval = mstring_copy (osd_getEnvironmentVariable (INCLUDE_VAR));
+    cstring incval = cstring_copy (osd_getEnvironmentVariable (INCLUDEPATH_VAR));
+    cstring oincval = incval;
 
-    if (incval != NULL)
+    if (cstring_isDefined (incval))
       {
        /*
        ** Each directory on the include path is a system include directory.
        */
 
        DPRINTF (("include: %s", incval));
-       context_setString (FLG_SYSTEMDIRS, cstring_fromCharsNew (incval));
+       context_setString (FLG_SYSTEMDIRS, cstring_copy (incval));
 
-       while (incval != NULL)
+       while (cstring_isDefined (incval))
          {
-           char *nextsep = strchr (incval, SEPCHAR);
+           /*@access cstring@*/
+           char *nextsep = strchr (incval, PATH_SEPARATOR);
 
            if (nextsep != NULL)
              {
                cstring dir;
                *nextsep = '\0';
-               dir = cstring_fromCharsNew (incval);
+               dir = cstring_copy (incval);
 
                if (cstring_length (dir) == 0
                    || !isalpha ((int) cstring_firstChar (dir)))
@@ -636,20 +673,23 @@ int main (int argc, char *argv[])
                  }
                else
                  {
-                   DPRINTF (("Add include: %s", dir));
                    cppAddIncludeDir (dir);
                  }
 
-               *nextsep = SEPCHAR;
-               incval = nextsep + 1;
+               *nextsep = PATH_SEPARATOR;
+               incval = cstring_fromChars (nextsep + 1);
                cstring_free (dir);
              }
            else
              {
                break;
              }
+
+           /*@noaccess cstring@*/
          }
       }
+
+    cstring_free (oincval);
   }
 
   /*
@@ -657,7 +697,7 @@ int main (int argc, char *argv[])
   */
 
   {
-    cstring home = cstring_fromChars (osd_getHomeDir ());
+    cstring home = osd_getHomeDir ();
     char *fname  = NULL;
     FILE *rcfile;
     bool defaultf = TRUE;
@@ -869,23 +909,30 @@ int main (int argc, char *argv[])
              
              thisarg++;        /* skip '-' */
              flagname = cstring_fromChars (thisarg);
-             
+
+             DPRINTF (("Flag: %s", flagname));
              opt = identifyFlag (flagname);
-             
+             DPRINTF (("Flag: %s", flagcode_unparse (opt)));
+
              if (flagcode_isSkip (opt))
                {
-                 ;
+                 DPRINTF (("Skipping!"));
                }
              else if (flagcode_isInvalid (opt))
                {
+                 DPRINTF (("Invalid: %s", flagname));
+
                  if (isMode (flagname))
                    {
                      context_setMode (flagname);
                    }
                  else
                    {
-                     llgloberror (message ("Unrecognized option: %s", 
-                                           cstring_fromChars (thisarg)));
+                     DPRINTF (("Error!"));
+                     voptgenerror (FLG_BADFLAG,
+                                   message ("Unrecognized option: %s", 
+                                            cstring_fromChars (thisarg)),
+                                   g_currentloc);
                    }
                }
              else
@@ -931,7 +978,7 @@ int main (int argc, char *argv[])
                              g_localSpecPath = cstring_toCharsSafe
                                (message ("%s%h%s", 
                                          cstring_fromChars (g_localSpecPath), 
-                                         SEPCHAR,
+                                         PATH_SEPARATOR,
                                          dir));
                              /*@=mustfree@*/
                              /*@switchbreak@*/ break;
@@ -952,15 +999,30 @@ int main (int argc, char *argv[])
                              else if (opt == FLG_INIT)
                                {
 # ifndef NOLCL
-                                 initFile = tsource_create 
-                                   (cstring_toCharsSafe (arg), 
-                                    LCLINIT_SUFFIX, FALSE);
+                                 initFile = inputStream_create 
+                                   (arg, 
+                                    cstring_makeLiteralTemp (LCLINIT_SUFFIX),
+                                    FALSE);
 # endif
                                  break;
                                }
                              else
                                {
-                                 setStringFlag (opt, arg);
+                                 DPRINTF (("String flag: %s / %s",
+                                           flagcode_unparse (opt), arg));
+                                 if (opt == FLG_MTSFILE)
+                                   {
+                                     /*
+                                     ** arg identifies mts files
+                                     */
+                                     
+                                     addFile (mtfiles, message ("%s%s", arg, MTS_EXTENSION));
+                                     addXHFile (xfiles, message ("%s%s", arg, XH_EXTENSION));
+                                   }
+                                 else
+                                   {
+                                     setStringFlag (opt, arg);
+                                   }
                                }
                            }
                          else
@@ -980,6 +1042,7 @@ int main (int argc, char *argv[])
            }
          else /* its a filename */
            {
+             DPRINTF (("Adding filename: %s", thisarg));
              fl = cstringSList_add (fl, cstring_fromChars (thisarg));
            }
        }
@@ -993,35 +1056,44 @@ int main (int argc, char *argv[])
 
   cstringSList_elements (fl, current)
     {
-      char *fname = cstring_toCharsSafe (current);
-      char *ext = strrchr (fname, '.');
-
-      if (ext == NULL)
+      cstring ext = fileLib_getExtension (current);
+      
+      if (cstring_isUndefined (ext))
        {
          /* no extension --- both C and LCL with default extensions */
          
-         addFile (cfiles, message ("%s.c", cstring_fromChars (fname)));
-         addFile (lclfiles, message ("%s.lcl", cstring_fromChars (fname)));
+         addFile (cfiles, message ("%s%s", current, C_EXTENSION));
+         addFile (lclfiles, message ("%s%s", current, LCL_EXTENSION));
+       }
+      else if (cstring_equal (ext, XH_EXTENSION))
+       {
+         addXHFile (xfiles, cstring_copy (current));
        }
-      else if (isCext (ext))
+      else if (cstring_equal (ext, LCL_EXTENSION)) 
        {
-         addFile (cfiles, cstring_fromCharsNew (fname));
+         addFile (lclfiles, cstring_copy (current));
+       }
+      else if (fileLib_isCExtension (ext))
+       {
+         addFile (cfiles, cstring_copy (current));
+       }
+      else if (cstring_equal (ext, MTS_EXTENSION))
+       {
+         addFile (mtfiles, cstring_copy (current));
        }
       else 
        {
-         if (!mstring_equal (ext, ".lcl"))
-           {
-             lldiagmsg (message ("Unrecognized file extension: %s (assuming lcl)", 
-                                 cstring_fromChars (ext)));
-           }
-
-         addFile (lclfiles, cstring_fromCharsNew (fname));
+         voptgenerror 
+           (FLG_FILEEXTENSIONS,
+            message ("Unrecognized file extension: %s (assuming %s is C source code)", 
+                     current, ext),
+            g_currentloc);
+         
+         addFile (cfiles, cstring_copy (current));
        }
     } end_cstringSList_elements;
   
-  
-  showHerald ();
-
+    showHerald (); /*@i723 move earlier? */
   
   if (showhelp)
     {
@@ -1032,6 +1104,7 @@ int main (int argc, char *argv[])
       fprintf (g_msgstream, "\n");
 
       fileIdList_free (cfiles);
+      fileIdList_free (xfiles);
       fileIdList_free (lclfiles);
       
       llexit (LLSUCCESS);
@@ -1087,8 +1160,24 @@ int main (int argc, char *argv[])
   fileloc_free (g_currentloc);
   g_currentloc = fileloc_createBuiltin ();
 
+  /*
+  ** Read metastate files (must happen before loading libraries) 
+  */
+
+  fileIdList_elements (mtfiles, mtfile)
+    {
+      context_setFileId (mtfile);
+
+      if (context_getFlag (FLG_SHOWSCAN))
+       {
+         lldiagmsg (message ("< processing %s >", rootFileName (mtfile)));
+       }
+      
+      mtreader_readFile (cstring_copy (fileName (mtfile)));
+    } end_fileIdList_elements;
+
   libtime = clock ();
-  
+
   if (anylcl)
     {
 # ifdef NOLCL
@@ -1098,6 +1187,8 @@ int main (int argc, char *argv[])
 # endif
     }
 
+  usymtab_initGlobalMarker ();
+
   /*
   ** pre-processing
   **
@@ -1108,8 +1199,6 @@ int main (int argc, char *argv[])
 
   context_setInCommandLine ();
 
-  cppReader_initialize ();
-
   DPRINTF (("Pass through: %s", cstringSList_unparse (passThroughArgs)));
   
   cstringSList_elements (passThroughArgs, thisarg) {
@@ -1120,12 +1209,16 @@ int main (int argc, char *argv[])
 
   cleanupMessages ();
 
+  DPRINTF (("Initializing cpp reader!"));
+  cppReader_initialize ();
   cppReader_saveDefinitions ();
   
   context_clearInCommandLine ();
 
   if (!context_getFlag (FLG_NOPP))
     {
+      fileIdList tfiles;
+
       llflush ();
 
       if (context_getFlag (FLG_SHOWSCAN))
@@ -1136,7 +1229,11 @@ int main (int argc, char *argv[])
       lcltime = clock ();
 
       context_setPreprocessing ();
-      dercfiles = preprocessFiles (cfiles);
+      dercfiles = preprocessFiles (xfiles, TRUE);
+      tfiles = preprocessFiles (cfiles, FALSE);
+      dercfiles = fileIdList_append (dercfiles, tfiles);
+      fileIdList_free (tfiles);
+
       context_clearPreprocessing ();
 
       fileIdList_free (cfiles);
@@ -1151,10 +1248,10 @@ int main (int argc, char *argv[])
   else
     {
       lcltime = clock ();
-      dercfiles = cfiles;
+      dercfiles = fileIdList_append (cfiles, xfiles);
       pptime = clock ();
     }
-  
+
   /*
   ** now, check all the corresponding C files
   **
@@ -1173,30 +1270,33 @@ int main (int argc, char *argv[])
 # endif
   }
 
+  DPRINTF (("Initializing..."));
+
   exprNode_initMod ();
 
+  DPRINTF (("Okay..."));
+
   fileIdList_elements (dercfiles, fid)
     {
-      sourceFile = tsource_create (cstring_toCharsSafe (fileName (fid)),
-                                  C_SUFFIX, TRUE);
+      sourceFile = inputStream_create (cstring_copy (fileName (fid)), C_EXTENSION, TRUE);
       context_setFileId (fid);
       
       /* Open source file  */
       
-      if (sourceFile == (tsource *) 0 || (!tsource_open (sourceFile)))
+      if (inputStream_isUndefined (sourceFile) || (!inputStream_open (sourceFile)))
        {
          /* previously, this was ignored  ?! */
          llbug (message ("Could not open temp file: %s", fileName (fid)));
        }
       else
        {
-         yyin = sourceFile->file; /*< shared <- only */
+         yyin = inputStream_getFile (sourceFile); /*< shared <- only */
        
          llassert (yyin != NULL);
 
          if (context_getFlag (FLG_SHOWSCAN))
            {
-                     lldiagmsg (message ("< checking %s >", rootFileName (fid)));
+             lldiagmsg (message ("< checking %s >", rootFileName (fid)));
            }
          
          /*
@@ -1213,13 +1313,13 @@ int main (int argc, char *argv[])
              first_time = FALSE;
            }
          
+         DPRINTF (("Entering..."));
          context_enterFile ();
          (void) yyparse ();
-         context_exitFile ();
+         context_exitCFile ();
                    
-         (void) tsource_close (sourceFile);
-       }
-      
+         (void) inputStream_close (sourceFile);
+       }      
     } end_fileIdList_elements;
 
   cptime = clock ();
@@ -1313,7 +1413,7 @@ int main (int argc, char *argv[])
        if (nspecErrors == context_getLCLExpect ())
          {
            specErrors = 
-             message ("%d spec error%p found, as expected\n       ", 
+             message ("%d spec error%& found, as expected\n       ", 
                       nspecErrors);
          }
        else
@@ -1321,13 +1421,13 @@ int main (int argc, char *argv[])
            if (context_getLCLExpect () > 0)
              {
                specErrors = 
-                 message ("%d spec error%p found, expected %d\n       ", 
+                 message ("%d spec error%& found, expected %d\n       ", 
                           nspecErrors,
                           (int) context_getLCLExpect ());
              }
            else
              {
-               specErrors = message ("%d spec error%p found\n       ",
+               specErrors = message ("%d spec error%& found\n       ",
                                      nspecErrors);
                expsuccess = FALSE;
              }
@@ -1350,7 +1450,7 @@ int main (int argc, char *argv[])
            {
              if (!isQuiet) {
                llmsg (message ("Finished LCLint checking --- "
-                               "%s%d code error%p found, as expected",
+                               "%s%d code error%& found, as expected",
                                specErrors, context_numErrors ()));
              }
            }
@@ -1361,7 +1461,7 @@ int main (int argc, char *argv[])
                  if (!isQuiet) {
                    llmsg (message 
                           ("Finished LCLint checking --- "
-                           "%s%d code error%p found, expected %d",
+                           "%s%d code error%& found, expected %d",
                            specErrors, context_numErrors (), 
                            (int) context_getExpect ()));
                  }
@@ -1371,11 +1471,12 @@ int main (int argc, char *argv[])
              else
                {
                  
-                 if (!isQuiet) {
-                   llmsg (message ("Finished LCLint checking --- "
-                                   "%s%d code error%p found", 
-                                   specErrors, context_numErrors ()));
-                 }
+                 if (!isQuiet)
+                   {
+                     llmsg (message ("Finished LCLint checking --- "
+                                     "%s%d code error%& found", 
+                                     specErrors, context_numErrors ()));
+                   }
 
                  expsuccess = FALSE;
                }
@@ -1481,19 +1582,21 @@ int main (int argc, char *argv[])
   llexit (expsuccess ? LLSUCCESS : LLFAILURE);
 }
 
+# ifdef WIN32
 /*
 ** Reenable return value warnings.
 */
-
-#pragma warning (default:4035)
+# pragma warning (default:4035)
+# endif 
 
 void
 showHelp (void)
 {
   showHerald ();
   
-  llmsglit ("Source files are .c, .h and .lcl files.  If there is no suffix,");
-  llmsglit ("   LCLint will look for <file>.c and <file>.lcl.");
+  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));
   llmsglit ("");
   llmsglit ("Use lclint -help <topic or flag name> for more information");
   llmsglit ("");
@@ -1578,8 +1681,9 @@ printParseErrors (void)
   llmsglit ("   ...");
   llmsglit ("   # endif");
   llmsglit ("");
+  /* evans 2000-12-21 fixed typo reported by Jeroen Ruigrok/Asmodai */
   llmsglit ("Missing type definitions --- an undefined type name will usually "
-           "lead to a parse error. This ofter occurs when a standard header "
+           "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 "
            "to standard library headers, but uses a library specification "
@@ -1623,7 +1727,7 @@ printAnnotations (void)
   llmsglit ("Annotations");
   llmsglit ("-----------");
   llmsglit ("");
-  llmsglit ("Annotations are stylized comments that document certain "
+  llmsglit ("Annotations are semantic comments that document certain "
            "assumptions about functions, variables, parameters, and types. ");
   llmsglit ("");
   llmsglit ("They may be used to indicate where the representation of a "
@@ -1881,12 +1985,12 @@ void
 describeVars (void)
 {
   cstring eval;
-  char *def;
+  cstring def;
 
   eval = context_getLarchPath ();
   def = osd_getEnvironmentVariable (LARCH_PATH);
 
-  if (def != NULL || 
+  if (cstring_isDefined (def) || 
       !cstring_equal (eval, cstring_fromChars (DEFAULT_LARCHPATH)))
     {
       llmsg (message ("LARCH_PATH = %s", eval));
@@ -1900,9 +2004,9 @@ describeVars (void)
   llmsglit ("   --- path used to find larch initialization files and LSL traits");
 
   eval = context_getLCLImportDir ();
-  def = osd_getEnvironmentVariable (LCLIMPORTDIR);
+  def = osd_getEnvironmentVariable (cstring_makeLiteralTemp (LCLIMPORTDIR));
 
-  if (def != NULL ||
+  if (cstring_isDefined (def) ||
       !cstring_equal (eval, cstring_fromChars (DEFAULT_LCLIMPORTDIR)))
     {
       llmsg (message ("%q = %s", cstring_makeLiteral (LCLIMPORTDIR), eval));
@@ -1916,13 +2020,18 @@ describeVars (void)
   llmsglit ("   --- directory containing lcl standard library files "
            "(import with < ... >)");;
 
-  {
-    cstring dirs = context_getString (FLG_SYSTEMDIRS);
-    llmsg (message 
-          ("systemdirs = %s (set by include envirnoment variable or -systemdirs)",
-           dirs));
+  llmsg (message 
+        ("include path = %q (set by environment variable %s and -I flags)",
+         cppReader_getIncludePath (), INCLUDEPATH_VAR));
 
-  }
+  llmsglit ("   --- path used to find #include'd files");
+
+  llmsg (message 
+        ("systemdirs = %s (set by -systemdirs or envirnoment variable %s)", /*@i413223@*/
+         context_getString (FLG_SYSTEMDIRS),
+         INCLUDEPATH_VAR));
+
+  llmsglit ("   --- if file is found on this path, it is treated as a system file for error reporting");
 }
 
 void
@@ -2035,7 +2144,8 @@ llexit (int status)
 }
 
 void
-loadrc (FILE *rcfile, cstringSList *passThroughArgs)
+loadrc (/*:open:*/ FILE *rcfile, cstringSList *passThroughArgs)
+   /*@ensures closed rcfile@*/
 {
   char *s = mstring_create (MAX_LINE_LENGTH);
   char *os = s;
@@ -2044,7 +2154,7 @@ loadrc (FILE *rcfile, cstringSList *passThroughArgs)
 
   s = os;
 
-  while (fgets (s, MAX_LINE_LENGTH, rcfile) != NULL)
+  while (reader_readLine (rcfile, s, MAX_LINE_LENGTH) != NULL)
     {
       char c;
       bool set = FALSE;            
@@ -2053,9 +2163,8 @@ loadrc (FILE *rcfile, cstringSList *passThroughArgs)
 
       DPRINTF (("Line: %s", s));
       DPRINTF (("Pass through: %s", cstringSList_unparse (*passThroughArgs)));
-      incLine ();
             
-      while (*s == ' ' || *s == '\t' || *s == '\n') 
+      while (*s == ' ' || *s == '\t')
        {
          s++;
          incColumn ();
@@ -2083,10 +2192,11 @@ loadrc (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;
            }
@@ -2152,15 +2262,18 @@ loadrc (FILE *rcfile, cstringSList *passThroughArgs)
            }
          else if (flagcode_isInvalid (opt))
            {
+             DPRINTF (("Invalid: %s", thisflag));
+
              if (isMode (cstring_fromChars (thisflag)))
                {
                  context_setMode (cstring_fromChars (thisflag));
                }
              else
                {
-                 llerror (FLG_BADFLAG,
-                          message ("Unrecognized option: %s", 
-                                   cstring_fromChars (thisflag)));
+                 voptgenerror (FLG_BADFLAG,
+                               message ("Unrecognized option: %s", 
+                                        cstring_fromChars (thisflag)),
+                               g_currentloc);
                }
            }
          else
@@ -2172,8 +2285,9 @@ loadrc (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 */
                    {
@@ -2239,11 +2353,12 @@ loadrc (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
                        {
@@ -2273,21 +2388,22 @@ loadrc (FILE *rcfile, cstringSList *passThroughArgs)
                              else 
                                {
                                  showHerald ();
-                                 llerror
-                                   (FLG_SYNTAX
+                                 voptgenerror
+                                   (FLG_BADFLAG
                                     message ("Options file not found: %s", 
-                                             extra));
+                                             extra),
+                                    g_currentloc);
                                }
                            }
                          else if (opt == FLG_INIT)
                            {
 # ifndef NOLCL
-                             llassert (initFile == NULL);
+                             llassert (inputStream_isUndefined (initFile));
                              
-                             initFile = tsource_create 
-                               (cstring_toCharsSafe (extra)
-                                LCLINIT_SUFFIX, FALSE);
-                             cstring_markOwned (extra);
+                             initFile = inputStream_create 
+                               (extra
+                                cstring_makeLiteralTemp (LCLINIT_SUFFIX),
+                                FALSE);
 # else
                              cstring_free (extra);
 # endif
@@ -2307,10 +2423,11 @@ loadrc (FILE *rcfile, cstringSList *passThroughArgs)
                                    }
                                  else
                                    {
-                                     llerror
-                                       (FLG_SYNTAX
+                                     voptgenerror
+                                       (FLG_BADFLAG
                                         message ("Unmatched \" in option string: %s", 
-                                                 extra));
+                                                 extra),
+                                        g_currentloc);
                                    }
                                }
                              
@@ -2347,7 +2464,7 @@ loadrc (FILE *rcfile, cstringSList *passThroughArgs)
   check (fclose (rcfile) == 0);
 }
 
-static fileIdList preprocessFiles (fileIdList fl)
+static fileIdList preprocessFiles (fileIdList fl, bool xhfiles)
   /*@modifies fileSystem@*/
 {
   bool msg = (context_getFlag (FLG_SHOWSCAN) && fileIdList_size (fl) > 10);
@@ -2360,18 +2477,46 @@ static fileIdList preprocessFiles (fileIdList fl)
 
   fileIdList_elements (fl, fid)
     {
-      char *ppfname = cstring_toCharsSafe (fileName (fid));
+      cstring ppfname = fileName (fid);
 
-      if (!(osd_fileIsReadable (ppfname)))
+      if (xhfiles)
        {
-         lldiagmsg (message ("Cannot open file: %s",
-                             cstring_fromChars (ppfname)));
+         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
        {
-         fileId  dfile = fileTable_addCTempFile (context_fileTable (), fid);
+         if (!(osd_fileIsReadable (ppfname)))
+           {
+             lldiagmsg (message ("Cannot open file: %s", ppfname));
+             ppfname = cstring_undefined;
+           }
+       }
+
+      if (cstring_isDefined (ppfname))
+       {
+         fileId dfile = fileTable_addCTempFile (context_fileTable (), fid);
          
-         llassert (!mstring_isEmpty (ppfname));
+         llassert (cstring_isNonEmpty (ppfname));
          
          if (msg)
            {
@@ -2389,8 +2534,7 @@ static fileIdList preprocessFiles (fileIdList fl)
              filesprocessed++;
            }
 
-         if (cppProcess (cstring_fromChars (ppfname), 
-                         fileName (dfile)) != 0) 
+         if (cppProcess (ppfname, fileName (dfile)) != 0) 
            {
              llfatalerror (message ("Preprocessing error for file: %s", 
                                     rootFileName (fid)));
@@ -2402,3 +2546,75 @@ static fileIdList preprocessFiles (fileIdList fl)
     
     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 */
+  char *specname = (char *) dmalloc (sizeof (*specname) 
+                                    * (strlen (specfile) + 9));
+  char *ospecname = specname;
+  char *path = (char *) dmalloc (sizeof (*path) * (strlen (specfile)));
+  size_t size;
+  long int i, j;
+  
+  /* initialized path to empty string or may have accidental garbage */
+  *path = '\0';
+
+  /*@-mayaliasunique@*/ 
+  strcpy (specname, specfile);
+  /*@=mayaliasunique@*/ 
+
+  /* trim off pathnames in specfile */
+  size = strlen (specname);
+
+  for (i = size_toInt (size) - 1; i >= 0; i--)
+    {
+      if (specname[i] == CONNECTCHAR)
+       {
+         /* strcpy (specname, (char *)specname+i+1); */
+         for (j = 0; j <= i; j++)      /* include '/'  */
+           {
+             path[j] = specname[j];
+           }
+
+         path[i + 1] = '\0';
+         specname += i + 1;
+         break;
+       }
+    }
+
+  /* 
+  ** also remove .lcl file extension, assume it's the last extension
+  ** of the file name 
+  */
+
+  size = strlen (specname);
+
+  for (i = size_toInt (size) - 1; i >= 0; i--)
+    {
+      if (specname[i] == '.')
+       {
+         specname[i] = '\0';
+         break;
+       }
+    }
+  
+  *inpath = path;
+
+  /*
+  ** If specname no longer points to the original char,
+  ** we need to allocate a new pointer and copy the string.
+  */
+
+  if (specname != ospecname) {
+    char *rspecname = (char *) dmalloc (sizeof (*rspecname) * (strlen (specname) + 1));
+    strcpy (rspecname, specname); /* evs 2000-05-16: Bug: was ospecname! */
+    sfree (ospecname);
+    return rspecname;
+  } 
+
+  return specname;
+}
+# endif
This page took 0.170081 seconds and 4 git commands to generate.