From: Mikko Rasa Date: Wed, 3 Feb 2010 11:54:06 +0000 (+0000) Subject: Style update: add spaces around assignments X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cbd0ddd6ee033e46646bfb85d19232c816ea1eda;p=libs%2Fdatafile.git Style update: add spaces around assignments --- diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index 4073689..ed1d71c 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -19,32 +19,32 @@ BinaryParser::BinaryParser(Input &i, const string &s): ParserMode(i, s), first(true) { - dict[1]=DictEntry("__kwd", "iss"); - dict[2]=DictEntry("__str", "is"); + dict[1] = DictEntry("__kwd", "iss"); + dict[2] = DictEntry("__str", "is"); } Statement BinaryParser::parse() { while(1) { - Statement st=parse_statement(); + Statement st = parse_statement(); if(st.keyword=="__kwd") { if(st.args.size()!=3) throw_at(TypeError("Keyword definition must have three arguments"), src); - const unsigned id=st.args[0].get(); - const string &kw=st.args[1].get(); - const string &args=st.args[2].get(); - dict[id]=DictEntry(kw, args); + const unsigned id = st.args[0].get(); + const string &kw = st.args[1].get(); + const string &args = st.args[2].get(); + dict[id] = DictEntry(kw, args); } else if(st.keyword=="__str") { if(st.args.size()!=2) throw_at(TypeError("String definition must have two arguments"), src); - const unsigned id=st.args[0].get(); - strings[id]=st.args[1].get(); + const unsigned id = st.args[0].get(); + strings[id] = st.args[1].get(); } else return st; @@ -55,22 +55,22 @@ Statement BinaryParser::parse_statement() { while(first && in.peek()=='\n') in.get(); - first=false; + first = false; - unsigned id=parse_int(); + unsigned id = parse_int(); if(!in) return Statement(); - Dictionary::const_iterator i=dict.find(id); + Dictionary::const_iterator i = dict.find(id); if(i==dict.end()) throw_at(KeyError("Unknown statement ID", lexical_cast(id)), src); - const DictEntry &de=i->second; + const DictEntry &de = i->second; Statement result; - result.keyword=de.keyword; - result.source=src; + result.keyword = de.keyword; + result.source = src; - for(unsigned j=0; j=0) { string result; result.reserve(len); - for(int i=0; isecond; diff --git a/source/binarywriter.cpp b/source/binarywriter.cpp index 98dd2a9..0e118c9 100644 --- a/source/binarywriter.cpp +++ b/source/binarywriter.cpp @@ -18,8 +18,8 @@ BinaryWriter::BinaryWriter(IO::Base &o): next_kwd_id(3), next_str_id(1) { - dict[DictEntry("__kwd", "iss")]=1; - dict[DictEntry("__str", "is")]=2; + dict[DictEntry("__kwd", "iss")] = 1; + dict[DictEntry("__str", "is")] = 2; } void BinaryWriter::write(const Statement &st) @@ -30,12 +30,12 @@ void BinaryWriter::write(const Statement &st) void BinaryWriter::write_(const Statement &st) { - Dictionary::iterator i=dict.find(create_entry(st)); + Dictionary::iterator i = dict.find(create_entry(st)); if(i==dict.end()) throw InvalidParameterValue("Unknown statement"); write_int(i->second); - for(ValueArray::const_iterator j=st.args.begin(); j!=st.args.end(); ++j) + for(ValueArray::const_iterator j = st.args.begin(); j!=st.args.end(); ++j) switch(j->get_type()) { case INTEGER: write_int (j->get()); break; @@ -46,20 +46,20 @@ void BinaryWriter::write_(const Statement &st) } write_int(st.sub.size()); - for(list::const_iterator j=st.sub.begin(); j!=st.sub.end(); ++j) + for(list::const_iterator j = st.sub.begin(); j!=st.sub.end(); ++j) write(*j); } DictEntry BinaryWriter::create_entry(const Statement &st) { - static const char types[]="ifsbe"; + static const char types[] = "ifsbe"; string args; - for(ValueArray::const_iterator i=st.args.begin(); i!=st.args.end(); ++i) + for(ValueArray::const_iterator i = st.args.begin(); i!=st.args.end(); ++i) { if(i->get_type()>=5) throw InvalidParameterValue("Invalid argument type"); - args+=types[i->get_type()]; + args += types[i->get_type()]; } return DictEntry(st.keyword, args); @@ -67,43 +67,43 @@ DictEntry BinaryWriter::create_entry(const Statement &st) void BinaryWriter::collect_keywords(const Statement &st) { - DictEntry de=create_entry(st); + DictEntry de = create_entry(st); if(!dict.count(de)) { Statement kst; - kst.keyword="__kwd"; + kst.keyword = "__kwd"; kst.args.push_back(next_kwd_id); kst.args.push_back(de.keyword); kst.args.push_back(de.args); write_(kst); - dict[de]=next_kwd_id++; + dict[de] = next_kwd_id++; } - for(ValueArray::const_iterator i=st.args.begin(); i!=st.args.end(); ++i) + for(ValueArray::const_iterator i = st.args.begin(); i!=st.args.end(); ++i) { - const Type t=i->get_type(); - const string &r=i->get_raw(); + const Type t = i->get_type(); + const string &r = i->get_raw(); if((t==ENUM || (t==STRING && r.size()<32)) && !strings.count(r)) { Statement sst; - sst.keyword="__str"; + sst.keyword = "__str"; sst.args.push_back(next_str_id); sst.args.push_back(r); write_(sst); - strings[r]=next_str_id++; + strings[r] = next_str_id++; } } - for(list::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) + for(list::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i) collect_keywords(*i); } void BinaryWriter::write_int(long long n) { - unsigned i=sizeof(long long)-1; + unsigned i = sizeof(long long)-1; if(n>=0) for(; (i>0 && (n>>(i*7-1))==0); --i) ; @@ -116,7 +116,7 @@ void BinaryWriter::write_int(long long n) void BinaryWriter::write_string(const string &s) { - StringMap::const_iterator i=strings.find(s); + StringMap::const_iterator i = strings.find(s); if(i!=strings.end()) write_int(-static_cast(i->second)); else @@ -134,19 +134,19 @@ void BinaryWriter::write_float(float f) char d[sizeof(float)]; }; - v=f; + v = f; #if BYTE_ORDER == LITTLE_ENDIAN - for(unsigned i=sizeof(float); i--;) + for(unsigned i = sizeof(float); i--;) out.put(d[i]); #else - for(unsigned i=0; isecond); diff --git a/source/collection.cpp b/source/collection.cpp index ea1095b..2a567b5 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -12,11 +12,11 @@ namespace DataFile { Collection::~Collection() { - for(ItemMap::iterator i=items.begin(); i!=items.end(); ++i) + for(ItemMap::iterator i = items.begin(); i!=items.end(); ++i) delete i->second; - for(ItemKeywordSeq::iterator i=keywords.begin(); i!=keywords.end(); ++i) + for(ItemKeywordSeq::iterator i = keywords.begin(); i!=keywords.end(); ++i) delete *i; - for(ItemCreatorSeq::iterator i=creators.begin(); i!=creators.end(); ++i) + for(ItemCreatorSeq::iterator i = creators.begin(); i!=creators.end(); ++i) delete *i; } @@ -29,7 +29,7 @@ bool Collection::contains(const std::string &n) const Collection::Loader::Loader(Collection &c): coll(c) { - for(ItemKeywordSeq::const_iterator i=coll.keywords.begin(); i!=coll.keywords.end(); ++i) + for(ItemKeywordSeq::const_iterator i = coll.keywords.begin(); i!=coll.keywords.end(); ++i) (*i)->add_to_loader(*this); } diff --git a/source/input.cpp b/source/input.cpp index f3f8f23..d74c8ef 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -17,9 +17,9 @@ Input::Input(IO::Base &i): int Input::get() { - int c=next; - next=-1; - if(c<0) c=in.get(); + int c = next; + next = -1; + if(c<0) c = in.get(); if(c=='\n') ++line; @@ -30,7 +30,7 @@ int Input::get() int Input::peek() { if(next<0) - next=in.get(); + next = in.get(); return next; } diff --git a/source/loader.cpp b/source/loader.cpp index 8d4f2be..6b0557f 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -14,7 +14,7 @@ namespace DataFile { void Loader::load(const Statement &st) { - for(list::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) + for(list::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i) load_statement(*i); finish(); } @@ -23,7 +23,7 @@ void Loader::load(Parser &p) { while(p) { - Statement st=p.parse(); + Statement st = p.parse(); if(st.valid) load_statement(st); } @@ -32,7 +32,7 @@ void Loader::load(Parser &p) Loader::~Loader() { - for(ActionMap::iterator i=actions.begin(); i!=actions.end(); ++i) + for(ActionMap::iterator i = actions.begin(); i!=actions.end(); ++i) delete i->second; } @@ -46,20 +46,20 @@ void Loader::load_sub_with(Loader &ldr) void Loader::add(const string &k, LoaderAction *a) { - ActionMap::iterator i=actions.find(k); + ActionMap::iterator i = actions.find(k); if(i!=actions.end()) { delete i->second; - i->second=a; + i->second = a; } else - actions[k]=a; + actions[k] = a; } void Loader::load_statement(const Statement &st) { - cur_st=&st; - ActionMap::iterator j=actions.find(st.keyword); + cur_st = &st; + ActionMap::iterator j = actions.find(st.keyword); if(j==actions.end()) throw_at(KeyError("Unknown keyword", st.keyword), st.get_location()); if(j->second) @@ -75,7 +75,7 @@ void Loader::load_statement(const Statement &st) throw; } } - cur_st=0; + cur_st = 0; } } // namespace DataFile diff --git a/source/parser.cpp b/source/parser.cpp index ade1dd9..1d225cb 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -37,24 +37,24 @@ Statement Parser::parse() { while(1) { - Statement st=mode->parse(); + Statement st = mode->parse(); if(st.keyword=="__bin") { delete mode; - mode=new BinaryParser(in, src); + mode = new BinaryParser(in, src); } else if(st.keyword=="__text") { delete mode; - mode=new TextParser(in, src); + mode = new TextParser(in, src); } else if(st.keyword=="__src") { - string s=st.args[0].get(); + string s = st.args[0].get(); if(s.empty()) - src=main_src; + src = main_src; else - src=format("%s[%s]", main_src, s); + src = format("%s[%s]", main_src, s); } else return st; @@ -62,7 +62,7 @@ Statement Parser::parse() } catch(const Exception &e) { - good=false; + good = false; throw; } } diff --git a/source/statement.cpp b/source/statement.cpp index 2df8b4c..d485a20 100644 --- a/source/statement.cpp +++ b/source/statement.cpp @@ -13,9 +13,9 @@ namespace DataFile { std::string Statement::get_location() const { - std::string result=source; + std::string result = source; if(line) - result+=format(":%d", line); + result += format(":%d", line); return result; } diff --git a/source/textparser.cpp b/source/textparser.cpp index 0f17d3f..d8e422e 100644 --- a/source/textparser.cpp +++ b/source/textparser.cpp @@ -28,19 +28,19 @@ Statement TextParser::parse() Statement TextParser::parse_statement(const Token *t) { Statement result; - bool sub=false; - bool finish=false; + bool sub = false; + bool finish = false; while(in) { Token token; if(t) { - token=*t; - t=0; + token = *t; + t = 0; } else - token=parse_token(); + token = parse_token(); if(result.keyword.empty()) { @@ -48,21 +48,21 @@ Statement TextParser::parse_statement(const Token *t) break; else if(token.type!=Token::IDENTIFIER) throw_at(ParseError(format("Syntax error at token '%s' (expected an identifier)", token.str)), get_location()); - result.keyword=token.str; - result.valid=true; - result.source=src; - result.line=in.get_line_number(); + result.keyword = token.str; + result.valid = true; + result.source = src; + result.line = in.get_line_number(); } else if(sub) { if(token.str=="}") { - sub=false; - finish=true; + sub = false; + finish = true; } else { - Statement ss=parse_statement(&token); + Statement ss = parse_statement(&token); result.sub.push_back(ss); } } @@ -73,7 +73,7 @@ Statement TextParser::parse_statement(const Token *t) break; } else if(token.str=="{") - sub=true; + sub = true; else if(token.str==";") break; else if(token.type==Token::INTEGER) @@ -103,27 +103,27 @@ Statement TextParser::parse_statement(const Token *t) Token TextParser::parse_token() { - int c=0; - int comment=0; + int c = 0; + int comment = 0; // Skip over comments and whitespace while(in && comment>=0) { - c=in.get(); - int next=in.peek(); + c = in.get(); + int next = in.peek(); if(c=='/' && next=='/') - comment=1; + comment = 1; else if(c=='/' && next=='*') - comment=2; + comment = 2; else if(c=='\n' && comment==1) - comment=0; + comment = 0; else if(c=='*' && next=='/' && comment==2) - comment=3; + comment = 3; else if(comment==3) // Skip the second character of block comment end - comment=0; + comment = 0; else if(!isspace(c) && !comment) - comment=-1; + comment = -1; } if(comment>0) // EOF while in comment @@ -165,64 +165,64 @@ Token TextParser::parse_token() Token::IDENTIFIER }; - ParseState state=INIT; + ParseState state = INIT; string buf; - bool escape=false; + bool escape = false; while(in || state==INIT) { if(state!=INIT) - c=in.get(); - int next=in.peek(); + c = in.get(); + int next = in.peek(); - buf+=c; + buf += c; switch(state) { case INIT: if(c=='0') - state=ZERO; + state = ZERO; else if(c=='-' || c=='+') - state=SIGN; + state = SIGN; else if(c=='.') - state=FLOAT; + state = FLOAT; else if(c=='"') - state=STRING; + state = STRING; else if(c=='{' || c=='}' || c==';') return Token(Token::SPECIAL, string(1, c)); else if(isdigit(c)) - state=DECIMAL; + state = DECIMAL; else if(isalpha(c) || c=='_') - state=IDENTIFIER; + state = IDENTIFIER; else parse_error(c, "0-9A-Za-z_.\"{};+-"); break; case SIGN: if(c=='0') - state=ZERO; + state = ZERO; else if(isdigit(c)) - state=DECIMAL; + state = DECIMAL; else if(c=='.') - state=FLOAT; + state = FLOAT; else parse_error(c, "0-9."); break; case ZERO: if(c=='x') - state=HEXADECIMAL; + state = HEXADECIMAL; else if(isdigit(c)) - state=OCTAL; + state = OCTAL; else if(c=='.') - state=FLOAT; + state = FLOAT; else parse_error(c, "0-9A-Fa-f."); break; case DECIMAL: if(c=='.') - state=FLOAT; + state = FLOAT; else if(!isdigit(c)) parse_error(c, "0-9."); break; @@ -239,23 +239,23 @@ Token TextParser::parse_token() case FLOAT: if(c=='e' || c=='E') - state=FLOATEXPINIT; + state = FLOATEXPINIT; else if(!isdigit(c)) parse_error(c, "0-9Ee"); break; case FLOATEXPINIT: if(c=='+' || c=='-') - state=FLOATEXPSIGN; + state = FLOATEXPSIGN; else if(isdigit(c)) - state=FLOATEXP; + state = FLOATEXP; else parse_error(c, "0-9+-"); break; case FLOATEXPSIGN: if(isdigit(c)) - state=FLOATEXP; + state = FLOATEXP; else parse_error(c, "0-9"); break; @@ -267,7 +267,7 @@ Token TextParser::parse_token() case STRING: if(c=='\\') - escape=!escape; + escape = !escape; else if(c=='"' && !escape) { try @@ -281,7 +281,7 @@ Token TextParser::parse_token() } } else - escape=false; + escape = false; break; case IDENTIFIER: diff --git a/source/textwriter.cpp b/source/textwriter.cpp index 890c417..2768462 100644 --- a/source/textwriter.cpp +++ b/source/textwriter.cpp @@ -29,7 +29,7 @@ void TextWriter::write_(const Statement &st, unsigned level) string indent(level, '\t'); IO::print(out, "%s%s", indent, st.keyword); - for(ValueArray::const_iterator i=st.args.begin(); i!=st.args.end(); ++i) + for(ValueArray::const_iterator i = st.args.begin(); i!=st.args.end(); ++i) { out.put(' '); if(i->get_type()==STRING) @@ -42,7 +42,7 @@ void TextWriter::write_(const Statement &st, unsigned level) if(!st.sub.empty()) { IO::print(out, "\n%s{\n", indent); - for(list::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) + for(list::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i) write_(*i, level+1); IO::print(out, "%s}", indent); } diff --git a/source/writer.cpp b/source/writer.cpp index bfd0eda..bcbccc2 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -36,21 +36,21 @@ void Writer::set_binary(bool b) if(b==binary) return; - binary=b; + binary = b; Statement st; if(binary) - st.keyword="__bin"; + st.keyword = "__bin"; else - st.keyword="__text"; + st.keyword = "__text"; mode->write(st); delete mode; if(binary) - mode=new BinaryWriter(out); + mode = new BinaryWriter(out); else - mode=new TextWriter(out); + mode = new TextWriter(out); } } // namespace DataFile diff --git a/tool/compiler.cpp b/tool/compiler.cpp index ed5710b..8c280c4 100644 --- a/tool/compiler.cpp +++ b/tool/compiler.cpp @@ -40,10 +40,10 @@ void Compiler::write(const DataFile::Statement &st) if(reset_src) { writer.write((DataFile::Statement("__src"), string())); - reset_src=false; + reset_src = false; } - for(list::const_iterator i=st.sub.begin(); i!=st.sub.end(); ++i) + for(list::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i) writer.write(*i); } @@ -52,11 +52,11 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) if(st.keyword=="_content") return true; - for(vector::iterator i=st.args.begin(); i!=st.args.end(); ++i) + for(vector::iterator i = st.args.begin(); i!=st.args.end(); ++i) if(i->get_type()==DataFile::STRING) { if(i->get_raw()=="$filename") - *i=DataFile::Value(FS::basename(fn.str())); + *i = DataFile::Value(FS::basename(fn.str())); else if(i->get_raw()=="$content") { IO::File in(fn.str()); @@ -64,14 +64,14 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) while(!in.eof()) { char buf[4096]; - unsigned len=in.read(buf, sizeof(buf)); + unsigned len = in.read(buf, sizeof(buf)); data.append(buf, len); } - *i=DataFile::Value(data); + *i = DataFile::Value(data); } } - for(list::iterator i=st.sub.begin(); i!=st.sub.end();) + for(list::iterator i = st.sub.begin(); i!=st.sub.end();) { if(process_statement(fn, *i)) { @@ -81,11 +81,11 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) DataFile::Parser parser(in, fn.str()); while(parser) { - DataFile::Statement ss=parser.parse(); + DataFile::Statement ss = parser.parse(); if(ss.valid) st.sub.insert(i, ss); } - i=st.sub.erase(i); + i = st.sub.erase(i); } else ++i; @@ -97,19 +97,19 @@ bool Compiler::process_statement(const FS::Path &fn, DataFile::Statement &st) void Compiler::process_file(const FS::Path &fn, const list &st) { writer.write((DataFile::Statement("__src"), FS::basename(fn.str()))); - reset_src=true; + reset_src = true; if(st.empty()) process_file(fn); else { - for(list::const_iterator i=st.begin(); i!=st.end(); ++i) + for(list::const_iterator i = st.begin(); i!=st.end(); ++i) { if(i->keyword=="_content") process_file(fn); else { - DataFile::Statement s=*i; + DataFile::Statement s = *i; process_statement(fn, s); writer.write(s); } @@ -125,7 +125,7 @@ void Compiler::process_file(const FS::Path &fn) DataFile::Parser parser(in, fn.str()); while(parser) { - DataFile::Statement st=parser.parse(); + DataFile::Statement st = parser.parse(); if(st.valid) writer.write(st); } @@ -162,14 +162,14 @@ ForEach::ForEach(Compiler &c, const FS::Path &b, const list &p): void ForEach::finish() { - list files=FS::list_files(base); - for(list::iterator i=files.begin(); i!=files.end(); ++i) + list files = FS::list_files(base); + for(list::iterator i = files.begin(); i!=files.end(); ++i) { - bool match=false; - for(list::const_iterator j=patterns.begin(); (j!=patterns.end() && !match); ++j) - match=Regex(*j).match(*i); - for(list::const_iterator j=excludes.begin(); (j!=excludes.end() && match); ++j) - match=!Regex(*j).match(*i); + bool match = false; + for(list::const_iterator j = patterns.begin(); (j!=patterns.end() && !match); ++j) + match = Regex(*j).match(*i); + for(list::const_iterator j = excludes.begin(); (j!=excludes.end() && match); ++j) + match = !Regex(*j).match(*i); if(match) compiler.process_file(base / *i, write_st); } diff --git a/tool/tool.cpp b/tool/tool.cpp index 36ee5c4..02fba07 100644 --- a/tool/tool.cpp +++ b/tool/tool.cpp @@ -30,24 +30,24 @@ DataTool::DataTool(int argc, char **argv): getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG); getopt(argc, argv); - const vector &args=getopt.get_args(); + const vector &args = getopt.get_args(); if(!args.empty()) - in_fn=args[0]; + in_fn = args[0]; } int DataTool::main() { IO::Base *in; if(in_fn=="-") - in=&IO::cin; + in = &IO::cin; else - in=new IO::File(in_fn); + in = new IO::File(in_fn); IO::Base *out; if(out_fn=="-") - out=&IO::cout; + out = &IO::cout; else - out=new IO::File(out_fn, IO::M_WRITE); + out = new IO::File(out_fn, IO::M_WRITE); { IO::Buffered in_buf(*in); @@ -66,7 +66,7 @@ int DataTool::main() { while(parser) { - DataFile::Statement st=parser.parse(); + DataFile::Statement st = parser.parse(); if(st.valid) { writer.write(st);