]> andersk Git - splint.git/blobdiff - src/fileTable.c
noexpand always false.
[splint.git] / src / fileTable.c
index 3256cd6c637f1db1efe14a29dc3669f5ed6940f9..0b23d1b7365f6d9534349539dfe61c951e87ceb3 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
 # include <sys/stat.h>
 # include <fcntl.h>
 # include "splintMacros.nf"
-# include "llbasic.h"
+# include "basic.h"
 # include "osd.h"
 # include "llmain.h"
-# include "portab.h"
 
+# ifdef WIN32
+# include <io.h>
+# else
 # if defined(__IBMC__) && defined(OS2)
 # include <process.h>
 # include <io.h>
@@ -61,6 +63,7 @@
 # define S_IWUSR S_IWRITE 
 # define S_IXUSR S_IEXEC
 # endif
+# endif
 
 /*@access fileId*/
 
@@ -101,6 +104,12 @@ fileTable_getIndex (fileTable ft, cstring s)
   cstring abspath;
   if (ft == NULL) return NOT_FOUND;
   abspath = osd_absolutePath (cstring_undefined, s);
+  
+  if (context_getFlag (FLG_CASEINSENSITIVEFILENAMES))
+    {
+      abspath = cstring_downcase (abspath);
+    }
+
   DPRINTF (("Absolute path: %s: %s", s, abspath));
   res = cstringTable_lookup (ft->htable, abspath);
   cstring_free (abspath);
@@ -186,7 +195,6 @@ ftentry_create (/*@keep@*/ cstring tn, bool temp, fileType typ, fileId der)
     }
   
   t->fname = tn;
-  
   t->basename = cstring_undefined;
   t->ftemp = temp;
   t->ftype = typ;
@@ -220,10 +228,11 @@ fileTable_create ()
   ft->nopen = 0;
   ft->nopenspace = FTBASESIZE;
   ft->openelements = (foentry *) dmalloc (FTBASESIZE * sizeof (*ft->openelements));
-  
+
   return (ft);
 }
 
+/*@-bounds@*/
 static void
 fileTable_grow (fileTable ft)
 {
@@ -244,7 +253,7 @@ fileTable_grow (fileTable ft)
   sfree (ft->elements);
   ft->elements = newent;
 }
-
+/*@=bounds@*/
 static void
 fileTable_growOpen (fileTable ft)
 {
@@ -277,7 +286,22 @@ fileTable_internAddEntry (fileTable ft, /*@only@*/ ftentry e)
   ft->nspace--;
 
   DPRINTF (("Adding: %s", e->fname));
-  cstringTable_insert (ft->htable, e->fname, ft->nentries);
+
+  if (context_getFlag (FLG_CASEINSENSITIVEFILENAMES))
+    {
+      cstring sd = cstring_downcase (e->fname);
+      cstringTable_insert (ft->htable, sd, ft->nentries);
+    }
+  else
+    {
+      cstringTable_insert (ft->htable, cstring_copy (e->fname), ft->nentries); 
+    }
+
+  /* evans 2002-07-12:
+     Before, there was no cstring_copy above, and e->fname was free'd in the if branch.
+     Splint should have caught this, and produced a warning for this assignment.
+     Why not?
+  */
   ft->elements[ft->nentries] = e;
 
   ft->nentries++;
@@ -307,7 +331,6 @@ fileTable_addFilePrim (fileTable ft, /*@temp@*/ cstring name,
   cstring absname = osd_absolutePath (NULL, name);
   int tindex = fileTable_getIndex (ft, absname);
   
-  DPRINTF (("Got abs path: %s", absname));
   llassert (ft != fileTable_undefined);
 
   if (tindex != NOT_FOUND)
@@ -468,7 +491,6 @@ fileTable_addXHFile (fileTable ft, cstring name)
   return (fileTable_addFilePrim (ft, name, FALSE, FILE_XH, fileId_invalid));
 }
 
-# ifndef NOLCL
 fileId
 fileTable_addImportFile (fileTable ft, cstring name)
 {
@@ -480,11 +502,8 @@ fileTable_addLCLFile (fileTable ft, cstring name)
 {
   return (fileTable_addFilePrim (ft, name, FALSE, FILE_HEADER, fileId_invalid));
 }
-# endif
 
-# ifndef NOLCL
 static int tmpcounter = 0;
-# endif
 
 fileId
 fileTable_addMacrosFile (fileTable ft)
@@ -546,7 +565,6 @@ fileTable_addCTempFile (fileTable ft, fileId fid)
   return res;
 }
 
-# ifndef NOLCL
 fileId
 fileTable_addltemp (fileTable ft)
 {
@@ -593,7 +611,6 @@ fileTable_addltemp (fileTable ft)
   cstring_free (newname);
   return (ret);
 }
-# endif
 
 bool
 fileTable_exists (fileTable ft, cstring s)
@@ -644,7 +661,18 @@ fileTable_setFilePath (fileTable ft, fileId fid, cstring path)
 fileId
 fileTable_lookupBase (fileTable ft, cstring base)
 {
-  int tindex = fileTable_getIndex (ft, base);
+  int tindex;
+
+  if (context_getFlag (FLG_CASEINSENSITIVEFILENAMES))
+    {
+      cstring dbase = cstring_downcase (base);
+      tindex = fileTable_getIndex (ft, dbase);
+      cstring_free (dbase);
+    }
+  else
+    {
+      tindex = fileTable_getIndex (ft, base);
+    }
 
   if (tindex == NOT_FOUND)
     {
@@ -781,7 +809,7 @@ fileTable_cleanup (fileTable ft)
   if (msg)
     {
       (void) fflush (g_warningstream);
-      fprintf (stderr, "< cleaning");
+      displayScanOpen (cstring_makeLiteral ("cleaning"));
     }
 
   for (i = 0; i < ft->nentries; i++)
@@ -803,7 +831,7 @@ fileTable_cleanup (fileTable ft)
            }
          else if (fileId_isValid (fe->fder)) 
            {
-             /*@i423 this should use close (fd) also... */
+             /* this should use close (fd) also... */
              (void) osd_unlink (fe->fname);
            }
          else if (fe->ftype == FILE_MACROS)
@@ -823,21 +851,13 @@ fileTable_cleanup (fileTable ft)
 
       if (msg && ((i % skip) == 0))
        {
-         (void) fflush (g_warningstream);
-
-         if (i == 0) {
-           fprintf (stderr, " ");
-         } else {
-           fprintf (stderr, ".");
-         }
-
-         (void) fflush (stderr);
+         displayScanContinue (cstring_makeLiteral (i == 0 ? " " : "."));
        }
     }
-  
+
   if (msg)
     {
-      fprintf (stderr, " >\n");
+      displayScanClose ();
     }
 }
 
@@ -859,6 +879,7 @@ fileTable_free (/*@only@*/ fileTable f)
   
   cstringTable_free (f->htable);
   sfree (f->elements);
+  sfree (f->openelements); /*!! why didn't splint report this? */
   sfree (f);
 }
 
@@ -910,7 +931,7 @@ static /*@only@*/ cstring makeTempName (cstring dir, cstring pre, cstring suf)
   static int pid = 0; 
   static /*@owned@*/ char *msg = NULL; 
   static /*@only@*/ cstring pidname = NULL;
-  int maxlen;
+  size_t maxlen;
   cstring smsg;
 
   llassert (cstring_length (pre) <= 3);
@@ -993,7 +1014,15 @@ fileTable_addOpen (fileTable ft, /*@observer@*/ FILE *f, /*@only@*/ cstring fnam
 
 FILE *fileTable_createFile (fileTable ft, cstring fname)
 {
-  int fdesc = open (cstring_toCharsSafe (fname), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR);
+# if defined (WIN32) && !defined (BCC32)
+  int fdesc = _open (cstring_toCharsSafe (fname), 
+                    O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 
+                    _S_IWRITE | S_IREAD);
+# else
+   int fdesc = open (cstring_toCharsSafe (fname), 
+                    O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
+                    S_IRUSR | S_IWUSR);
+# endif
 
   if (fdesc == -1)
     {
@@ -1025,7 +1054,15 @@ FILE *fileTable_createFile (fileTable ft, cstring fname)
 
 FILE *fileTable_createMacrosFile (fileTable ft, cstring fname)
 {
-  int fdesc = open (cstring_toCharsSafe (fname), O_RDWR | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR);
+# if defined (WIN32) && !defined (BCC32)
+  int fdesc = _open (cstring_toCharsSafe (fname), 
+                    O_RDWR | O_CREAT | O_TRUNC | O_EXCL,
+                    _S_IREAD | _S_IWRITE);
+# else
+  int fdesc = open (cstring_toCharsSafe (fname), 
+                   O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 
+                   S_IRUSR | S_IWUSR);
+# endif
 
   if (fdesc == -1)
     {
This page took 0.035609 seconds and 4 git commands to generate.