X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tool%2Fcompiler.cpp;h=8360ee6ce35931b52f5867bfb75ffdddeb713df1;hb=256b44a5009467171af53316141277027bcc0ba4;hp=03328e85ff369c6eed1981083a8c6415a15338fe;hpb=a582163d380833b1370ba067a1fd0ad5c2984723;p=libs%2Fdatafile.git diff --git a/tool/compiler.cpp b/tool/compiler.cpp index 03328e8..8360ee6 100644 --- a/tool/compiler.cpp +++ b/tool/compiler.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include @@ -52,6 +45,14 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) if(st.keyword=="_content") return true; + if(st.keyword=="_extension") + { + string ext = FS::extpart(FS::basename(fn)); + if(ext.empty() || ext.size()==1) + throw invalid_argument("Compiler::process_statement"); + st.keyword = ext.substr(1); + } + for(vector::iterator i = st.args.begin(); i!=st.args.end(); ++i) if(i->get_signature()==DataFile::StringType::signature) { @@ -158,21 +159,22 @@ ForEach::ForEach(Compiler &c, const FS::Path &b, const list &p): { add("exclude", &ForEach::exclude); add("pattern", &ForEach::pattern); + add("wrap", &ForEach::wrap); + add("wrap", &ForEach::wrap_keyword); add("write", &ForEach::write); } void ForEach::finish() { - list files = FS::list_files(base); - for(list::iterator i = files.begin(); i!=files.end(); ++i) + for(const string &f: FS::list_files(base)) { bool match = false; for(list::const_iterator j = patterns.begin(); (j!=patterns.end() && !match); ++j) - match = Regex(*j).match(*i); + match = Regex(*j).match(f); for(list::const_iterator j = excludes.begin(); (j!=excludes.end() && match); ++j) - match = !Regex(*j).match(*i); + match = !Regex(*j).match(f); if(match) - compiler.process_file(base / *i, write_st); + compiler.process_file(base/f, write_st); } } @@ -186,6 +188,19 @@ void ForEach::pattern(const string &p) patterns.push_back(p); } +void ForEach::wrap() +{ + wrap_keyword("_extension"); +} + +void ForEach::wrap_keyword(const string &kwd) +{ + DataFile::Statement st(kwd); + st.append("$filename"); + st.sub.push_back(DataFile::Statement("_content")); + write_st.push_back(st); +} + void ForEach::write(const DataFile::Statement &st) { write_st.insert(write_st.end(), st.sub.begin(), st.sub.end());