summaryrefslogtreecommitdiffabout
path: root/lib/sitecing_enflesher.ll
Side-by-side diff
Diffstat (limited to 'lib/sitecing_enflesher.ll') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/sitecing_enflesher.ll8
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_]*
ECHO;
}
. ECHO;
%%
void sitecing_enflesher::LexerOutput(const char *buf,int size) {
outs.write(buf,size);
}
void sitecing_enflesher::enflesh() {
ifstream ifs(parser.skeleton.c_str());
if(!ifs.good())
throw preprocessor_error(CODEPOINT,"failed to open skeleton file");
switch_streams(&ifs,NULL);
yylex();
+ outs_close();
}
void sitecing_enflesher::anchor() {
if(!anchoraged)
return;
outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n";
anchor_time = false;
}
-void sitecing_enflesher::outs_open(const string& nfile) {
+void sitecing_enflesher::outs_close() {
if(!outs_filename.empty()) {
outs.flush();
outs.close();
outs.clear();
/*
* compare source and destination files.
*
* one can also keep a hash for the old one and compute one for the
* output while writing, but I'm not sure if it's any better. Surely a
* bit less accurate, unless we're going to compare it in case of
* difference, anyway.
*/
bool overwrite = false;
struct stat st_s, st_d;
string fn_s = outs_filename+".new";
string fn_d = outs_filename;
@@ -231,24 +232,29 @@ void sitecing_enflesher::outs_open(const string& nfile) {
if(i_d.read(t2,rb).gcount()!=rb)
throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source");
if(memcmp(t1,t2,rb)) {
overwrite = true;
break;
}
remaining -= rb;
}
}
}
if(overwrite) {
cerr << "renaming '" << fn_s << "'" << endl;
if(rename(fn_s.c_str(),fn_d.c_str()))
throw preprocessor_error(CODEPOINT,"failed to rename() generated output");
}
}
+ outs_filename.erase();
+}
+
+void sitecing_enflesher::outs_open(const string& nfile) {
+ outs_close();
outs_filename = nfile;
outs.open((nfile+".new").c_str(),ios::trunc);
if(!outs.good())
throw preprocessor_error(CODEPOINT,"failed to write preprocessor output");
}
/*
* vim:set ft=lex:
*/