2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 /* CPP main program, using CPP Library.
28 Copyright (C) 1995 Free Software Foundation, Inc.
29 Written by Per Bothner, 1994-95.
31 This program is free software; you can redistribute it and/or modify it
32 under the terms of the GNU General Public License as published by the
33 Free Software Foundation; either version 2, or (at your option) any
36 This program is distributed in the hope that it will be useful,
37 but WITHOUT ANY WARRANTY; without even the implied warranty of
38 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 GNU General Public License for more details.
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
45 In other words, you are welcome to use, share and improve this program.
46 You are forbidden to forbid anyone else to use, share and improve
47 what you give them. Help stamp out software-hoarding! */
49 # include "splintMacros.nf"
58 static cppReader s_cppState
;
60 void cppReader_initMod (cstringList
*cppArgs
)
62 cpplib_initializeReader (&s_cppState
, cppArgs
);
64 if (!context_getFlag (FLG_SINGLEINCLUDE
))
70 void cppReader_destroyMod (void)
71 /*@globals killed s_cppState@*/
73 if (CPPOPTIONS (&s_cppState
) != NULL
) {
74 cppCleanup (&s_cppState
);
78 int cppProcess (/*@dependent@*/ cstring infile
,
79 /*@dependent@*/ cstring outfile
)
82 struct cppOptions
*opts
= CPPOPTIONS (&s_cppState
);
84 llassert (opts
!= NULL
);
86 opts
->out_fname
= outfile
;
87 opts
->in_fname
= infile
;
88 opts
->out_fname
= outfile
;
90 if (cpplib_fatalErrors (&s_cppState
))
95 s_cppState
.show_column
= TRUE
;
97 if (cppReader_startProcess (&s_cppState
, opts
->in_fname
) == 0)
102 ofile
= fileTable_createTempFile (context_fileTable (), outfile
, FALSE
);
106 fileTable_noDelete (context_fileTable (), outfile
);
107 llfatalerror (message ("Cannot create temporary file for "
108 "pre-processor output. Trying to "
109 "open: %s. Use -tmpdir to change "
110 "the directory for temporary files.",
118 llassert (s_cppState
.token_buffer
!= NULL
);
120 if (!opts
->no_output
)
122 DPRINTF (("Writing: %s", cstring_copyLength (s_cppState
.token_buffer
, cpplib_getWritten (&s_cppState
))));
124 (void) fwrite (s_cppState
.token_buffer
, (size_t) 1,
125 cpplib_getWritten (&s_cppState
), ofile
);
128 cppReader_setWritten (&s_cppState
, 0);
129 kind
= cpplib_getToken (&s_cppState
);
135 cppReader_finish (&s_cppState
);
136 check (fileTable_closeFile (context_fileTable (), ofile
));
138 /* Restore the original definition table. */
140 if (!context_getFlag (FLG_SINGLEINCLUDE
))
142 cpphash_restoreTable ();
146 /* Undefine everything from this file! */
148 if (s_cppState
.errors
!= 0) {