X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tool%2Fcompiler.cpp;h=49dd19031cc0408fc958e84afd3fcfa4063bc403;hb=1a3b30ea35fbc19e56bbd35e4ee1811d8d5e02a4;hp=8c280c4a2ec2a3d0ec3ed07fd72235d15a8bc92c;hpb=cbd0ddd6ee033e46646bfb85d19232c816ea1eda;p=libs%2Fdatafile.git diff --git a/tool/compiler.cpp b/tool/compiler.cpp index 8c280c4..49dd190 100644 --- a/tool/compiler.cpp +++ b/tool/compiler.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include @@ -52,12 +45,21 @@ 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_type()==DataFile::STRING) + if(i->get_signature()==DataFile::StringType::signature) { - if(i->get_raw()=="$filename") + string value = i->get(); + if(value=="$filename") *i = DataFile::Value(FS::basename(fn.str())); - else if(i->get_raw()=="$content") + else if(value=="$content") { IO::File in(fn.str()); string data; @@ -157,6 +159,8 @@ 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); } @@ -185,6 +189,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());