Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

cppmain.c File Reference

#include "lclintMacros.nf"
#include "llbasic.h"
#include "cpp.h"
#include "cpplib.h"
#include "cpphash.h"
#include "cpperror.h"
#include "llmain.h"
#include <stdio.h>

Go to the source code of this file.

Functions

void cppReader_initMod ()
void cppReader_initialize ()
int cppProcess ( cstring infile, cstring outfile)
void cppAddIncludeDir (cstring dir)
void cppDoDefine (cstring str)
void cppDoUndefine (cstring str)
void cppReader_saveDefinitions ()

Variables

cppReader g_cppState


Function Documentation

void cppAddIncludeDir ( cstring dir )
 

Definition at line 170 of file cppmain.c.

Referenced by main().

00171 {
00172   /* -I option (Add directory to include path) */
00173   struct file_name_list *dirtmp = (struct file_name_list *) dmalloc (sizeof (*dirtmp));
00174 
00175   DPRINTF (("Add include: %s", dir));
00176 
00177   dirtmp->next = 0;             /* New one goes on the end */
00178   dirtmp->control_macro = 0;
00179   dirtmp->c_system_include_path = FALSE;
00180   
00181   /* This copy is necessary...but shouldn't be? */
00182   /*@-onlytrans@*/
00183   dirtmp->fname = cstring_copy (dir);
00184   /*@=onlytrans@*/
00185   
00186   dirtmp->got_name_map = FALSE;
00187   cppReader_addIncludeChain (&g_cppState, dirtmp);
00188 }

void cppDoDefine ( cstring str )
 

Definition at line 190 of file cppmain.c.

00191 {
00192   cppBuffer *tbuf = g_cppState.buffer;
00193 
00194   g_cppState.buffer = NULL;
00195   cppReader_define (&g_cppState, cstring_toCharsSafe (str));
00196   g_cppState.buffer = tbuf;
00197 }

void cppDoUndefine ( cstring str )
 

Definition at line 199 of file cppmain.c.

00200 {
00201   int sym_length;
00202   HASHNODE *hp;
00203   char *buf = cstring_toCharsSafe (str);
00204 
00205   sym_length = cppReader_checkMacroName (&g_cppState, buf,
00206                                  cstring_makeLiteralTemp ("macro"));
00207   
00208   while ((hp = cppReader_lookup (buf, sym_length, -1)) != NULL)
00209     {
00210       /*@-exposetrans@*/ /*@-dependenttrans@*/
00211       cppReader_deleteMacro (hp);
00212       /*@=exposetrans@*/ /*@=dependenttrans@*/
00213     }
00214 }

int cppProcess ( cstring infile,
cstring outfile )
 

Definition at line 97 of file cppmain.c.

00099 {
00100   FILE *ofile;
00101   struct cppOptions *opts = CPPOPTIONS (&g_cppState);
00102   
00103   opts->out_fname = outfile;
00104   opts->in_fname = infile;
00105   opts->out_fname = outfile;
00106   
00107   if (cppFatalErrors (&g_cppState))
00108     {
00109       llexit (LLFAILURE);
00110     }
00111   
00112   g_cppState.show_column = TRUE;
00113 
00114   if (cppReader_startProcess (&g_cppState, opts->in_fname) == 0) 
00115     {
00116       llexit (LLFAILURE);
00117     }
00118 
00119   ofile = fopen (cstring_toCharsSafe (outfile), "w");
00120   
00121   if (ofile == NULL) 
00122     {
00123       fileTable_noDelete (context_fileTable (), outfile);
00124       llfatalerror (message ("Cannot create temporary file for "
00125                              "pre-processor output.  Trying to "
00126                              "open: %s.  Use -tmpdir to change "
00127                              "the directory for temporary files.",
00128                              outfile));
00129     }
00130   
00131   for (;;)
00132     {
00133       enum cpp_token kind;
00134       
00135       llassert (g_cppState.token_buffer != NULL);
00136 
00137       if (!opts->no_output)
00138         {
00139           (void) fwrite (g_cppState.token_buffer, (size_t) 1,
00140                          cppReader_getWritten (&g_cppState), ofile);
00141         }
00142       
00143       cppReader_setWritten (&g_cppState, 0);
00144       kind = cppGetToken (&g_cppState);
00145       
00146       if (kind == CPP_EOF)
00147         break;
00148     }
00149 
00150   cppReader_finish (&g_cppState);
00151   check (fclose (ofile) == 0);
00152 
00153   /* Resotre the original definition table. */
00154 
00155   if (!context_getFlag (FLG_SINGLEINCLUDE))
00156     {
00157       cppReader_restoreHashtab ();  
00158     }
00159 
00160   
00161   /* Undefine everything from this file! */
00162 
00163   if (g_cppState.errors != 0) {
00164     return -1;
00165   }
00166 
00167   return 0;
00168 }

void cppReader_initMod ( )
 

Definition at line 80 of file cppmain.c.

Referenced by main().

00081 {
00082   struct cppOptions *opts = (struct cppOptions *) dmalloc (sizeof (*opts));
00083 
00084   cppReader_init (&g_cppState);
00085   llassert (g_cppState.opts == NULL);
00086   g_cppState.opts = opts;
00087 
00088   cppOptions_init (opts);
00089   /*@-compdef@*/ /* g_cppState is not yet innitialized */
00090 }

void cppReader_initialize ( )
 

Definition at line 92 of file cppmain.c.

Referenced by main().

00093 {
00094   cppReader_initializeReader (&g_cppState);
00095 }

void cppReader_saveDefinitions ( )
 

Definition at line 216 of file cppmain.c.

Referenced by main().

00217 {
00218   if (!context_getFlag (FLG_SINGLEINCLUDE))
00219     {
00220       cppReader_saveHashtab ();
00221     }
00222 }


Variable Documentation

cppReader g_cppState
 

Definition at line 67 of file cppmain.c.


Generated at Fri Nov 3 18:57:54 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000