X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=tool%2Fcompiler.cpp;h=ed5710b97d3bd8d3ffac53d88f4c41855b2866fd;hp=53c1b5388c4792829743b2db13092c005b125573;hb=4371289ed39d8135d407bc7bbbfbedea0cfd6dde;hpb=52e6bd3e02522f68166c70f83d2ef3d7cf0c15ff diff --git a/tool/compiler.cpp b/tool/compiler.cpp index 53c1b53..ed5710b 100644 --- a/tool/compiler.cpp +++ b/tool/compiler.cpp @@ -15,7 +15,8 @@ using namespace std; using namespace Msp; Compiler::Compiler(DataFile::Writer &w): - writer(w) + writer(w), + reset_src(false) { add("file", &Compiler::file); add("for_each", &Compiler::for_each); @@ -36,6 +37,12 @@ void Compiler::for_each(const vector &patterns) void Compiler::write(const DataFile::Statement &st) { + if(reset_src) + { + writer.write((DataFile::Statement("__src"), string())); + reset_src=false; + } + for(list::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) writer.write(*i); } @@ -89,15 +96,23 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) void Compiler::process_file(const FS::Path &fn, const list &st) { - for(list::const_iterator i=st.begin(); i!=st.end(); ++i) + writer.write((DataFile::Statement("__src"), FS::basename(fn.str()))); + reset_src=true; + + if(st.empty()) + process_file(fn); + else { - if(i->keyword=="_content") - process_file(fn); - else + for(list::const_iterator i=st.begin(); i!=st.end(); ++i) { - DataFile::Statement s=*i; - process_statement(fn, s); - writer.write(s); + if(i->keyword=="_content") + process_file(fn); + else + { + DataFile::Statement s=*i; + process_statement(fn, s); + writer.write(s); + } } } } @@ -126,10 +141,7 @@ File::File(Compiler &c, const FS::Path &fn): void File::finish() { - if(write_st.empty()) - compiler.process_file(filename); - else - compiler.process_file(filename, write_st); + compiler.process_file(filename, write_st); } void File::write(const DataFile::Statement &st)