Some consistency changes to library & headers flags.
[splint-patched.git] / src / rcfiles.c
blob66e86b0b6c27075179d902d83c2f427e840bb504
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
5 **
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.
10 **
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.
15 **
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
25 ** rcfiles.c
28 # include "splintMacros.nf"
29 # include "basic.h"
30 # include "rcfiles.h"
33 static void rcfiles_loadFile (FILE *p_rcfile, cstringList *p_cppArgs)
34 /*@modifies *p_cppArgs, p_rcfile@*/
35 /*@ensures closed p_rcfile@*/ ;
37 bool rcfiles_read (cstring fname, cstringList *cppArgs, bool report)
39 bool res = FALSE;
41 if (fileTable_exists (context_fileTable (), fname))
43 if (report)
45 voptgenerror
46 (FLG_WARNRC,
47 message ("Multiple attempts to read options file: %s", fname),
48 g_currentloc);
51 else
53 FILE *innerf = fileTable_openReadFile (context_fileTable (), fname);
55 if (innerf != NULL)
57 fileloc fc = g_currentloc;
58 g_currentloc = fileloc_createRc (fname);
60 displayScan (message ("reading options from %q",
61 fileloc_outputFilename (g_currentloc)));
63 rcfiles_loadFile (innerf, cppArgs);
64 fileloc_reallyFree (g_currentloc);
65 g_currentloc = fc;
66 res = TRUE;
68 else
70 if (report)
72 voptgenerror
73 (FLG_WARNRC,
74 message ("Cannot open options file: %s", fname),
75 g_currentloc);
80 return res;
83 static void rcfiles_loadFile (/*:open:*/ FILE *rcfile, cstringList *cppArgs)
84 /*@modifies rcfile@*/
85 /*@ensures closed rcfile@*/
87 char *s = mstring_create (MAX_LINE_LENGTH);
88 char *os = s;
89 cstringList args = cstringList_new ();
91 DPRINTF (("Loading rc file..."));
93 s = os;
95 while (reader_readLine (rcfile, s, MAX_LINE_LENGTH) != NULL)
97 char c;
99 DPRINTF (("Line: %s", s));
100 DPRINTF (("args: %s", cstringList_unparse (args)));
102 while (*s == ' ' || *s == '\t')
104 s++;
105 incColumn ();
108 while (*s != '\0')
110 char *thisflag;
111 bool escaped = FALSE;
112 bool quoted = FALSE;
113 c = *s;
115 /* comment characters */
116 if (c == '#' || c == ';' || c == '\n')
118 /*@innerbreak@*/
119 break;
122 thisflag = s;
124 while ((c = *s) != '\0')
125 { /* remember to handle spaces and quotes in -D and -U ... */
126 if (escaped)
128 escaped = FALSE;
130 else if (quoted)
132 if (c == '\\')
134 escaped = TRUE;
136 else if (c == '\"')
138 quoted = FALSE;
140 else
145 else if (c == '\"')
147 quoted = TRUE;
149 else
151 if (c == ' ' || c == '\t' || c == '\n')
153 /*@innerbreak@*/ break;
157 s++;
158 incColumn ();
161 DPRINTF (("Nulling: %c", *s));
162 *s = '\0';
164 if (mstring_isEmpty (thisflag))
166 llfatalerror (message ("Missing flag: %s",
167 cstring_fromChars (os)));
169 else
171 args = cstringList_add (args, cstring_fromCharsNew (thisflag));
172 DPRINTF (("args: %s", cstringList_unparse (args)));
175 *s = c;
176 DPRINTF (("Pass through: %s", cstringList_unparse (*cppArgs)));
178 while ((c == ' ') || (c == '\t'))
180 c = *(++s);
181 incColumn ();
185 s = os;
188 sfree (os);
190 DPRINTF (("args: %s", cstringList_unparse (args)));
191 flags_processFlags (FALSE,
192 fileIdList_undefined,
193 fileIdList_undefined,
194 fileIdList_undefined,
195 cppArgs,
196 cstringList_size (args),
197 /*@-nullstate@*/ /*@-type@*/ /* exposes cstring type */
198 cstringList_getElements (args)
199 /*@=nullstate@*/ /*@=type@*/
201 cstringList_free (args);
202 check (fileTable_closeFile (context_fileTable (), rcfile));