]> andersk Git - splint.git/blobdiff - src/cppmain.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / cppmain.c
index 5774c31401e4b55b7b33396756a05c2fa3dd1e52..61bca213413d65e034b683cb6220c42e0d34071f 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-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -17,9 +17,9 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** 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 information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
+** For more information: http://www.splint.org
 */
 /*
 ** cppmain.c
@@ -46,13 +46,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  You are forbidden to forbid anyone else to use, share and improve
  what you give them.   Help stamp out software-hoarding!  */
 
-# include "lclintMacros.nf"
-# include "llbasic.h"
-# include "cpp.h"
+# include "splintMacros.nf"
+# include "basic.h"
 # include "cpplib.h"
 # include "cpphash.h"
 # include "cpperror.h"
 # include "llmain.h"
+# include "osd.h"
 
 # include <stdio.h>
 
@@ -81,7 +81,7 @@ void cppReader_initMod ()
 {
   struct cppOptions *opts = (struct cppOptions *) dmalloc (sizeof (*opts));
 
-  cppReader_init (&g_cppState);
+  cpplib_init (&g_cppState);
   llassert (g_cppState.opts == NULL);
   g_cppState.opts = opts;
 
@@ -89,9 +89,15 @@ void cppReader_initMod ()
   /*@-compdef@*/ /* g_cppState is not yet innitialized */
 } /*@=compdef@*/
 
+void cppReader_destroyMod () 
+  /*@globals killed g_cppState@*/
+{
+  cppCleanup (&g_cppState);
+}
+
 void cppReader_initialize ()
 {
-  cppReader_initializeReader (&g_cppState);
+  cpplib_initializeReader (&g_cppState);
 }
 
 int cppProcess (/*@dependent@*/ cstring infile, 
@@ -104,7 +110,7 @@ int cppProcess (/*@dependent@*/ cstring infile,
   opts->in_fname = infile;
   opts->out_fname = outfile;
   
-  if (cppFatalErrors (&g_cppState))
+  if (cpplib_fatalErrors (&g_cppState))
     {
       llexit (LLFAILURE);
     }
@@ -116,11 +122,12 @@ int cppProcess (/*@dependent@*/ cstring infile,
       llexit (LLFAILURE);
     }
 
-  ofile = fopen (cstring_toCharsSafe (outfile), "w");
+  ofile = fileTable_createFile (context_fileTable (), outfile);
   
   if (ofile == NULL) 
     {
       fileTable_noDelete (context_fileTable (), outfile);
+      osd_setTempError ();
       llfatalerror (message ("Cannot create temporary file for "
                             "pre-processor output.  Trying to "
                             "open: %s.  Use -tmpdir to change "
@@ -136,19 +143,21 @@ int cppProcess (/*@dependent@*/ cstring infile,
 
       if (!opts->no_output)
        {
+         DPRINTF (("Writing: %s", cstring_copyLength (g_cppState.token_buffer, cpplib_getWritten (&g_cppState))));
+
          (void) fwrite (g_cppState.token_buffer, (size_t) 1,
-                        cppReader_getWritten (&g_cppState), ofile);
+                        cpplib_getWritten (&g_cppState), ofile);
        }
       
       cppReader_setWritten (&g_cppState, 0);
-      kind = cppGetToken (&g_cppState);
+      kind = cpplib_getToken (&g_cppState);
       
       if (kind == CPP_EOF)
        break;
     }
 
   cppReader_finish (&g_cppState);
-  check (fclose (ofile) == 0);
+  check (fileTable_closeFile (context_fileTable (), ofile));
 
   /* Restore the original definition table. */
 
@@ -167,24 +176,37 @@ int cppProcess (/*@dependent@*/ cstring infile,
   return 0;
 }
 
-void cppAddIncludeDir (cstring dir) 
+void cppAddIncludeDir (cstring dir)
 {
-  /* -I option (Add directory to include path) */
-  struct file_name_list *dirtmp = (struct file_name_list *) dmalloc (sizeof (*dirtmp));
+  /* evans 2001-08-26
+  ** Add the -I- code.  This code provided by Robin Watts <Robin.Watts@wss.co.uk>
+  */
 
-  DPRINTF (("Add include: %s", dir));
+  DPRINTF (("Adding include: %s", dir));
 
-  dirtmp->next = 0;            /* New one goes on the end */
-  dirtmp->control_macro = 0;
-  dirtmp->c_system_include_path = FALSE;
-  
-  /* This copy is necessary...but shouldn't be? */
-  /*@-onlytrans@*/
-  dirtmp->fname = cstring_copy (dir);
-  /*@=onlytrans@*/
-  
-  dirtmp->got_name_map = FALSE;
-  cppReader_addIncludeChain (&g_cppState, dirtmp);
+  if (cstring_equalLit (dir, "-I-"))
+    {
+      struct cppOptions *opts = CPPOPTIONS (&g_cppState);    
+      opts->ignore_srcdir = TRUE;
+    } 
+  else 
+    {
+      struct file_name_list *dirtmp = (struct file_name_list *) dmalloc (sizeof (*dirtmp));
+      
+      DPRINTF (("Add include: %s", dir));
+
+      dirtmp->next = 0;                /* New one goes on the end */
+      dirtmp->control_macro = 0;
+      dirtmp->c_system_include_path = FALSE;
+      
+      /* This copy is necessary...but shouldn't be? */
+      /*@-onlytrans@*/
+      dirtmp->fname = cstring_copy (dir);
+      /*@=onlytrans@*/
+      
+      dirtmp->got_name_map = FALSE;
+      cppReader_addIncludeChain (&g_cppState, dirtmp);
+    }
 }
 
 void cppDoDefine (cstring str)
@@ -198,14 +220,14 @@ void cppDoDefine (cstring str)
 
 void cppDoUndefine (cstring str)
 {
-  int sym_length;
+  size_t sym_length;
   hashNode hp;
   char *buf = cstring_toCharsSafe (str);
 
   sym_length = cppReader_checkMacroName (&g_cppState, buf,
-                                cstring_makeLiteralTemp ("macro"));
+                                        cstring_makeLiteralTemp ("macro"));
   
-  while ((hp = cppReader_lookup (buf, sym_length, -1)) != NULL)
+  while ((hp = cpphash_lookup (buf, size_toInt (sym_length), -1)) != NULL)
     {
       /*@-exposetrans@*/ /*@-dependenttrans@*/
       cppReader_deleteMacro (hp);
This page took 0.178241 seconds and 4 git commands to generate.