]>
Commit | Line | Data |
---|---|---|
140c27a8 | 1 | /* |
2 | ** Splint - annotation-assisted static program checker | |
c59f5181 | 3 | ** Copyright (C) 1994-2003 University of Virginia, |
140c27a8 | 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. | |
19 | ** | |
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 | |
23 | */ | |
24 | /* | |
25 | ** rcfiles.c | |
26 | */ | |
27 | ||
28 | # include "splintMacros.nf" | |
29 | # include "basic.h" | |
30 | # include "rcfiles.h" | |
31 | ||
32 | ||
6fcd0b1e | 33 | static void rcfiles_loadFile (FILE *p_rcfile, cstringList *p_passThroughArgs) |
140c27a8 | 34 | /*@modifies *p_passThroughArgs, p_rcfile@*/ |
35 | /*@ensures closed p_rcfile@*/ ; | |
36 | ||
6fcd0b1e | 37 | bool rcfiles_read (cstring fname, cstringList *passThroughArgs, bool report) |
140c27a8 | 38 | { |
39 | bool res = FALSE; | |
40 | ||
41 | if (fileTable_exists (context_fileTable (), fname)) | |
42 | { | |
43 | if (report) | |
44 | { | |
45 | voptgenerror | |
46 | (FLG_WARNRC, | |
47 | message ("Multiple attempts to read options file: %s", fname), | |
48 | g_currentloc); | |
49 | } | |
50 | } | |
51 | else | |
52 | { | |
53 | FILE *innerf = fileTable_openReadFile (context_fileTable (), fname); | |
54 | ||
55 | if (innerf != NULL) | |
56 | { | |
57 | fileloc fc = g_currentloc; | |
58 | g_currentloc = fileloc_createRc (fname); | |
59 | ||
ce7034f0 | 60 | displayScan (message ("reading options from %q", |
140c27a8 | 61 | fileloc_outputFilename (g_currentloc))); |
62 | ||
63 | rcfiles_loadFile (innerf, passThroughArgs); | |
64 | fileloc_reallyFree (g_currentloc); | |
65 | g_currentloc = fc; | |
66 | res = TRUE; | |
67 | } | |
68 | else | |
69 | { | |
70 | if (report) | |
71 | { | |
72 | voptgenerror | |
73 | (FLG_WARNRC, | |
74 | message ("Cannot open options file: %s", fname), | |
75 | g_currentloc); | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | return res; | |
81 | } | |
82 | ||
6fcd0b1e | 83 | static void rcfiles_loadFile (/*:open:*/ FILE *rcfile, cstringList *passThroughArgs) |
140c27a8 | 84 | /*@modifies rcfile@*/ |
85 | /*@ensures closed rcfile@*/ | |
86 | { | |
87 | char *s = mstring_create (MAX_LINE_LENGTH); | |
88 | char *os = s; | |
89 | cstringList args = cstringList_new (); | |
90 | ||
91 | DPRINTF (("Loading rc file...")); | |
ce7034f0 | 92 | |
140c27a8 | 93 | s = os; |
94 | ||
95 | while (reader_readLine (rcfile, s, MAX_LINE_LENGTH) != NULL) | |
96 | { | |
97 | char c; | |
98 | ||
99 | DPRINTF (("Line: %s", s)); | |
100 | DPRINTF (("args: %s", cstringList_unparse (args))); | |
101 | ||
102 | while (*s == ' ' || *s == '\t') | |
103 | { | |
104 | s++; | |
105 | incColumn (); | |
106 | } | |
107 | ||
108 | while (*s != '\0') | |
109 | { | |
110 | char *thisflag; | |
111 | bool escaped = FALSE; | |
112 | bool quoted = FALSE; | |
113 | c = *s; | |
114 | ||
115 | /* comment characters */ | |
116 | if (c == '#' || c == ';' || c == '\n') | |
117 | { | |
118 | /*@innerbreak@*/ | |
119 | break; | |
120 | } | |
121 | ||
122 | thisflag = s; | |
123 | ||
124 | while ((c = *s) != '\0') | |
125 | { /* remember to handle spaces and quotes in -D and -U ... */ | |
126 | if (escaped) | |
127 | { | |
128 | escaped = FALSE; | |
129 | } | |
130 | else if (quoted) | |
131 | { | |
132 | if (c == '\\') | |
133 | { | |
134 | escaped = TRUE; | |
135 | } | |
136 | else if (c == '\"') | |
137 | { | |
138 | quoted = FALSE; | |
139 | } | |
140 | else | |
141 | { | |
142 | ; | |
143 | } | |
144 | } | |
145 | else if (c == '\"') | |
146 | { | |
147 | quoted = TRUE; | |
148 | } | |
149 | else | |
150 | { | |
151 | if (c == ' ' || c == '\t' || c == '\n') | |
152 | { | |
153 | /*@innerbreak@*/ break; | |
154 | } | |
155 | } | |
156 | ||
157 | s++; | |
158 | incColumn (); | |
159 | } | |
160 | ||
161 | DPRINTF (("Nulling: %c", *s)); | |
162 | *s = '\0'; | |
163 | ||
164 | if (mstring_isEmpty (thisflag)) | |
165 | { | |
166 | llfatalerror (message ("Missing flag: %s", | |
167 | cstring_fromChars (os))); | |
168 | } | |
169 | else | |
170 | { | |
171 | args = cstringList_add (args, cstring_fromCharsNew (thisflag)); | |
172 | DPRINTF (("args: %s", cstringList_unparse (args))); | |
173 | } | |
174 | ||
175 | *s = c; | |
6fcd0b1e | 176 | DPRINTF (("Pass through: %s", cstringList_unparse (*passThroughArgs))); |
140c27a8 | 177 | |
178 | while ((c == ' ') || (c == '\t')) | |
179 | { | |
180 | c = *(++s); | |
181 | incColumn (); | |
182 | } | |
183 | } | |
184 | ||
185 | s = os; | |
186 | } | |
187 | ||
188 | sfree (os); | |
189 | ||
190 | DPRINTF (("args: %s", cstringList_unparse (args))); | |
191 | flags_processFlags (FALSE, | |
192 | fileIdList_undefined, | |
193 | fileIdList_undefined, | |
194 | fileIdList_undefined, | |
195 | fileIdList_undefined, | |
196 | passThroughArgs, | |
197 | cstringList_size (args), | |
198 | cstringList_getElements (args)); | |
199 | cstringList_free (args); | |
200 | check (fileTable_closeFile (context_fileTable (), rcfile)); | |
201 | } | |
202 | ||
203 | ||
204 |