]> andersk Git - splint.git/blobdiff - src/fileTable.c
os2/makeos2.cmd: also make in ../lib with `-o' option.
[splint.git] / src / fileTable.c
index 4f85aa4a50cbc803a123051931b426cff1d65fd9..3256cd6c637f1db1efe14a29dc3669f5ed6940f9 100644 (file)
@@ -17,8 +17,8 @@
 ** 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
 */
 /*
  * - Added conditional stuff (#define and #include) for IBM's compiler.
  */
 
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <fcntl.h>
 # include "splintMacros.nf"
 # include "llbasic.h"
 # include "osd.h"
 # include "llmain.h"
 # include "portab.h"
+
 # if defined(__IBMC__) && defined(OS2)
 # include <process.h>
+# include <io.h>
 # define getpid _getpid
+# define S_IRUSR S_IREAD
+# define S_IWUSR S_IWRITE 
+# define S_IXUSR S_IEXEC
 # endif
 
 /*@access fileId*/
 
+static void 
+fileTable_addOpen (fileTable p_ft, /*@observer@*/ FILE *p_f, /*@only@*/ cstring p_fname) 
+  /*@modifies p_ft@*/ ;
+
 static bool fileTable_inRange (fileTable ft, fileId fid) /*@*/ 
 {
   return (fileTable_isDefined (ft) && (fid >= 0) && (fid < ft->nentries));
@@ -99,6 +111,8 @@ static cstring ftentry_unparse (fileTable ft, ftentry fte)
 {
   if (fileId_isValid (fte->fder))
     {
+      llassert (fileTable_isDefined (ft));
+
       return message ("%s %q %d (%s)", 
                      fte->fname, 
                      fileType_unparse (fte->ftype),
@@ -311,6 +325,17 @@ fileTable_addFilePrim (fileTable ft, /*@temp@*/ cstring name,
 
          e->basename = fileLib_removePathFree (fileLib_removeAnyExtension (absname));
          e->fsystem = context_isSystemDir (absname);
+
+         /*
+         ** evans 2002-03-15: change suggested by Jim Zelenka
+         **                   support relative paths for system directories
+         */
+
+         if (!e->fsystem)
+           {
+             e->fsystem = context_isSystemDir (name);
+           }
+
          e->fspecial = context_isSpecialFile (absname);
 
          if (e->fspecial)
@@ -370,6 +395,12 @@ fileTable_addHeaderFile (fileTable ft, cstring name)
 
 }
 
+void
+fileTable_addStreamFile (fileTable ft, FILE *fstream, cstring name)
+{
+  fileTable_addOpen (ft, fstream, cstring_copy (name));
+}
+
 bool
 fileTable_isHeader (fileTable ft, fileId fid)
 {
@@ -749,7 +780,7 @@ fileTable_cleanup (fileTable ft)
 
   if (msg)
     {
-      (void) fflush (g_msgstream);
+      (void) fflush (g_warningstream);
       fprintf (stderr, "< cleaning");
     }
 
@@ -792,7 +823,7 @@ fileTable_cleanup (fileTable ft)
 
       if (msg && ((i % skip) == 0))
        {
-         (void) fflush (g_msgstream);
+         (void) fflush (g_warningstream);
 
          if (i == 0) {
            fprintf (stderr, " ");
@@ -925,7 +956,6 @@ static /*@only@*/ cstring makeTempName (cstring dir, cstring pre, cstring suf)
       smsg = message ("%s%s%s%s%s", dir, pre, pidname, cstring_fromChars (msg), suf);
       nextMsg (msg);
     }
-  
 
   return smsg;
 }
@@ -961,9 +991,106 @@ fileTable_addOpen (fileTable ft, /*@observer@*/ FILE *f, /*@only@*/ cstring fnam
   ft->nopen++;
 }
 
-FILE *fileTable_openFile (fileTable ft, cstring fname, char *mode)
+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 (fdesc == -1)
+    {
+      osd_setTempError ();
+      llfatalerror (message ("Temporary file for "
+                            "pre-processor output already exists.  Trying to "
+                            "open: %s.",
+                            fname));
+
+      /*@notreached@*/ return NULL;
+    }
+  else
+    {
+      FILE *res = fdopen (fdesc, "w");
+  
+      if (res != NULL) 
+       {
+         fileTable_addOpen (ft, res, cstring_copy (fname));
+         DPRINTF (("Opening file: %s / %p", fname, res));
+       }
+      else
+       {
+         DPRINTF (("Error opening: %s", fname));
+       }
+
+      return res;
+    }
+}
+
+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 (fdesc == -1)
+    {
+      osd_setTempError ();
+      llfatalerror (message ("Temporary file for "
+                            "pre-processor output already exists.  Trying to "
+                            "open: %s.",
+                            fname));
+
+      /*@notreached@*/ return NULL;
+    }
+  else
+    {
+      FILE *res = fdopen (fdesc, "w+");
+  
+      if (res != NULL) 
+       {
+         fileTable_addOpen (ft, res, cstring_copy (fname));
+         DPRINTF (("Opening file: %s / %p", fname, res));
+       }
+      else
+       {
+         DPRINTF (("Error opening: %s", fname));
+       }
+
+      return res;
+    }
+}
+
+FILE *fileTable_openReadFile (fileTable ft, cstring fname)
 {
-  FILE *res = fopen (cstring_toCharsSafe (fname), mode);
+  FILE *res = fopen (cstring_toCharsSafe (fname), "r");
+
+  if (res != NULL) 
+    {
+      fileTable_addOpen (ft, res, cstring_copy (fname));
+      DPRINTF (("Opening read file: %s / %p", fname, res));
+    }
+  else
+    {
+      DPRINTF (("Cannot open read file: %s", fname));
+    }
+
+  return res;
+}
+
+/*
+** Allows overwriting
+*/
+
+FILE *fileTable_openWriteFile (fileTable ft, cstring fname)
+{
+  FILE *res = fopen (cstring_toCharsSafe (fname), "w");
+
+  if (res != NULL) {
+    fileTable_addOpen (ft, res, cstring_copy (fname));
+    DPRINTF (("Opening file: %s / %p", fname, res));
+  }
+
+  return res;
+}
+
+FILE *fileTable_openWriteUpdateFile (fileTable ft, cstring fname)
+{
+  FILE *res = fopen (cstring_toCharsSafe (fname), "w+");
 
   if (res != NULL) {
     fileTable_addOpen (ft, res, cstring_copy (fname));
@@ -987,7 +1114,7 @@ bool fileTable_closeFile (fileTable ft, FILE *f)
       if (ft->openelements[i]->f == f)
        {
          DPRINTF (("Closing file: %p = %s", f, ft->openelements[i]->fname));
-
+         
          if (i == ft->nopen - 1)
            {
              foentry_free (ft->openelements[i]);
@@ -1015,13 +1142,19 @@ void fileTable_closeAll (fileTable ft)
 {
   int i = 0;
 
+  llassert (fileTable_isDefined (ft));
+
   for (i = 0; i < ft->nopen; i++) 
     {
       /* 
         lldiagmsg (message ("Unclosed file at exit: %s", ft->openelements[i]->fname)); 
       */
+      
+      if (ft->openelements[i]->f != NULL)
+       {
+         (void) fclose (ft->openelements[i]->f); /* No check - cleaning up after errors */
+       }
 
-      (void) fclose (ft->openelements[i]->f); /* No check - cleaning up after errors */
       ft->openelements[i]->f = NULL;
       foentry_free (ft->openelements[i]);
       ft->openelements[i] = NULL;
This page took 0.066178 seconds and 4 git commands to generate.