author | Michael Krelin <hacker@klever.net> | 2005-03-30 21:58:44 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-03-30 21:58:44 (UTC) |
commit | 5c757590c7561f6d85b3f9011aa0695c4111b379 (patch) (unidiff) | |
tree | e0bf20ca58b3e7bd9cc4eda54db5674ba1d71db0 /lib/sitecing_enflesher.ll | |
parent | 3ddbfeafde93d1aab16a710498d86eef4e787406 (diff) | |
download | sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.zip sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.tar.gz sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.tar.bz2 |
1. fixed a bug just introduced, preventing the last skeleton-generated file
from being written.
2. introduced pragma directive and pragma main=class
3. minor changes of no importance
-rw-r--r-- | lib/sitecing_enflesher.ll | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/sitecing_enflesher.ll b/lib/sitecing_enflesher.ll index 46489c7..bb667be 100644 --- a/lib/sitecing_enflesher.ll +++ b/lib/sitecing_enflesher.ll | |||
@@ -166,42 +166,43 @@ ID [A-Za-z_][A-Za-z0-9_]* | |||
166 | ECHO; | 166 | ECHO; |
167 | } | 167 | } |
168 | . ECHO; | 168 | . ECHO; |
169 | 169 | ||
170 | %% | 170 | %% |
171 | 171 | ||
172 | void sitecing_enflesher::LexerOutput(const char *buf,int size) { | 172 | void sitecing_enflesher::LexerOutput(const char *buf,int size) { |
173 | outs.write(buf,size); | 173 | outs.write(buf,size); |
174 | } | 174 | } |
175 | 175 | ||
176 | void sitecing_enflesher::enflesh() { | 176 | void sitecing_enflesher::enflesh() { |
177 | ifstream ifs(parser.skeleton.c_str()); | 177 | ifstream ifs(parser.skeleton.c_str()); |
178 | if(!ifs.good()) | 178 | if(!ifs.good()) |
179 | throw preprocessor_error(CODEPOINT,"failed to open skeleton file"); | 179 | throw preprocessor_error(CODEPOINT,"failed to open skeleton file"); |
180 | switch_streams(&ifs,NULL); | 180 | switch_streams(&ifs,NULL); |
181 | yylex(); | 181 | yylex(); |
182 | outs_close(); | ||
182 | } | 183 | } |
183 | 184 | ||
184 | void sitecing_enflesher::anchor() { | 185 | void sitecing_enflesher::anchor() { |
185 | if(!anchoraged) | 186 | if(!anchoraged) |
186 | return; | 187 | return; |
187 | outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n"; | 188 | outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n"; |
188 | anchor_time = false; | 189 | anchor_time = false; |
189 | } | 190 | } |
190 | 191 | ||
191 | void sitecing_enflesher::outs_open(const string& nfile) { | 192 | void sitecing_enflesher::outs_close() { |
192 | if(!outs_filename.empty()) { | 193 | if(!outs_filename.empty()) { |
193 | outs.flush(); | 194 | outs.flush(); |
194 | outs.close(); | 195 | outs.close(); |
195 | outs.clear(); | 196 | outs.clear(); |
196 | /* | 197 | /* |
197 | * compare source and destination files. | 198 | * compare source and destination files. |
198 | * | 199 | * |
199 | * one can also keep a hash for the old one and compute one for the | 200 | * one can also keep a hash for the old one and compute one for the |
200 | * output while writing, but I'm not sure if it's any better. Surely a | 201 | * output while writing, but I'm not sure if it's any better. Surely a |
201 | * bit less accurate, unless we're going to compare it in case of | 202 | * bit less accurate, unless we're going to compare it in case of |
202 | * difference, anyway. | 203 | * difference, anyway. |
203 | */ | 204 | */ |
204 | bool overwrite = false; | 205 | bool overwrite = false; |
205 | struct stat st_s, st_d; | 206 | struct stat st_s, st_d; |
206 | string fn_s = outs_filename+".new"; | 207 | string fn_s = outs_filename+".new"; |
207 | string fn_d = outs_filename; | 208 | string fn_d = outs_filename; |
@@ -231,24 +232,29 @@ void sitecing_enflesher::outs_open(const string& nfile) { | |||
231 | if(i_d.read(t2,rb).gcount()!=rb) | 232 | if(i_d.read(t2,rb).gcount()!=rb) |
232 | throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source"); | 233 | throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source"); |
233 | if(memcmp(t1,t2,rb)) { | 234 | if(memcmp(t1,t2,rb)) { |
234 | overwrite = true; | 235 | overwrite = true; |
235 | break; | 236 | break; |
236 | } | 237 | } |
237 | remaining -= rb; | 238 | remaining -= rb; |
238 | } | 239 | } |
239 | } | 240 | } |
240 | } | 241 | } |
241 | if(overwrite) { | 242 | if(overwrite) { |
242 | cerr << "renaming '" << fn_s << "'" << endl; | 243 | cerr << "renaming '" << fn_s << "'" << endl; |
243 | if(rename(fn_s.c_str(),fn_d.c_str())) | 244 | if(rename(fn_s.c_str(),fn_d.c_str())) |
244 | throw preprocessor_error(CODEPOINT,"failed to rename() generated output"); | 245 | throw preprocessor_error(CODEPOINT,"failed to rename() generated output"); |
245 | } | 246 | } |
246 | } | 247 | } |
248 | outs_filename.erase(); | ||
249 | } | ||
250 | |||
251 | void sitecing_enflesher::outs_open(const string& nfile) { | ||
252 | outs_close(); | ||
247 | outs_filename = nfile; | 253 | outs_filename = nfile; |
248 | outs.open((nfile+".new").c_str(),ios::trunc); | 254 | outs.open((nfile+".new").c_str(),ios::trunc); |
249 | if(!outs.good()) | 255 | if(!outs.good()) |
250 | throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); | 256 | throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); |
251 | } | 257 | } |
252 | /* | 258 | /* |
253 | * vim:set ft=lex: | 259 | * vim:set ft=lex: |
254 | */ | 260 | */ |