From 34c8cf9fd2cecb6e08dde4c37cb0546c25efcf0f Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 6 Oct 2014 07:56:31 +0200 Subject: [PATCH] style fix --- libserpent/util.cpp | 7 +- sc/cmdline.cpp | 189 +++++++++++++++++++++----------------------- 2 files changed, 94 insertions(+), 102 deletions(-) diff --git a/libserpent/util.cpp b/libserpent/util.cpp index dbd87ea2e..693427c3f 100644 --- a/libserpent/util.cpp +++ b/libserpent/util.cpp @@ -6,7 +6,6 @@ #include "bignum.h" #include #include -#include //Token or value node constructor Node token(std::string val, Metadata met) { @@ -212,7 +211,7 @@ std::string get_file_contents(std::string filename) in.close(); return(contents); } - BOOST_THROW_EXCEPTION(dev::FileError() << boost::errinfo_file_name(filename) << boost::errinfo_errno(errno)); + throw(errno); } //Report error @@ -220,8 +219,8 @@ void err(std::string errtext, Metadata met) { std::string err = "Error (file \"" + met.file + "\", line " + unsignedToDecimal(met.ln + 1) + ", char " + unsignedToDecimal(met.ch) + "): " + errtext; - std::cerr << err << "\n"; - BOOST_THROW_EXCEPTION(dev::Exception() << dev::errinfo_comment(err)); + std::cerr << err << "\n"; + throw(err); } //Bin to hex diff --git a/sc/cmdline.cpp b/sc/cmdline.cpp index cfa5f2db0..d6602c56d 100644 --- a/sc/cmdline.cpp +++ b/sc/cmdline.cpp @@ -7,103 +7,96 @@ #include #include -int main(int argv, char** argc) { - if (argv == 1) { - std::cerr << "Must provide a command and arguments! Try parse, rewrite, compile, assemble\n"; - return 0; - } - std::string flag = ""; - std::string command = argc[1]; - std::string input; - std::string secondInput; - if (std::string(argc[1]) == "-s") { - flag = command.substr(1); - command = argc[2]; - input = ""; - std::string line; - while (std::getline(std::cin, line)) { - input += line + "\n"; - } - secondInput = argv == 3 ? "" : argc[3]; - } - else { - if (argv == 2) { - std::cerr << "Not enough arguments for serpent cmdline\n"; +int main(int argv, char** argc) +{ + if (argv == 1) + { + std::cerr << "Must provide a command and arguments! Try parse, rewrite, compile, assemble\n"; + return 0; + } + std::string flag = ""; + std::string command = argc[1]; + std::string input; + std::string secondInput; + if (std::string(argc[1]) == "-s") + { + flag = command.substr(1); + command = argc[2]; + input = ""; + std::string line; + while (std::getline(std::cin, line)) + { + input += line + "\n"; + } + secondInput = argv == 3 ? "" : argc[3]; + } + else + { + if (argv == 2) + { + std::cerr << "Not enough arguments for serpent cmdline\n"; BOOST_THROW_EXCEPTION(dev::Exception() << dev::errinfo_comment("Not enough arguments for serpent cmdline")); - } - input = argc[2]; - secondInput = argv == 3 ? "" : argc[3]; - } - bool haveSec = secondInput.length() > 0; - if (command == "parse" || command == "parse_serpent") { - std::cout << printAST(parseSerpent(input), haveSec) << "\n"; - } - else if (command == "rewrite") { - std::cout << printAST(rewrite(parseLLL(input, true)), haveSec) << "\n"; - } - else if (command == "compile_to_lll") { - std::cout << printAST(compileToLLL(input), haveSec) << "\n"; - } - else if (command == "build_fragtree") { - std::cout << printAST(buildFragmentTree(parseLLL(input, true))) << "\n"; - } - else if (command == "compile_lll") { - std::cout << binToHex(compileLLL(parseLLL(input, true))) << "\n"; - } - else if (command == "dereference") { - std::cout << printAST(dereference(parseLLL(input, true)), haveSec) <<"\n"; - } - else if (command == "pretty_assemble") { - std::cout << printTokens(prettyAssemble(parseLLL(input, true))) <<"\n"; - } - else if (command == "pretty_compile_lll") { - std::cout << printTokens(prettyCompileLLL(parseLLL(input, true))) << "\n"; - } - else if (command == "pretty_compile") { - std::cout << printTokens(prettyCompile(input)) << "\n"; - } - else if (command == "assemble") { - std::cout << assemble(parseLLL(input, true)) << "\n"; - } - else if (command == "serialize") { - std::cout << binToHex(serialize(tokenize(input, Metadata(), false))) << "\n"; - } - else if (command == "flatten") { - std::cout << printTokens(flatten(parseLLL(input, true))) << "\n"; - } - else if (command == "deserialize") { - std::cout << printTokens(deserialize(hexToBin(input))) << "\n"; - } - else if (command == "compile") { - std::cout << binToHex(compile(input)) << "\n"; - } - else if (command == "encode_datalist") { - std::vector tokens = tokenize(input); - std::vector o; - for (int i = 0; i < (int)tokens.size(); i++) { - o.push_back(tokens[i].val); - } - std::cout << binToHex(encodeDatalist(o)) << "\n"; - } - else if (command == "decode_datalist") { - std::vector o = decodeDatalist(hexToBin(input)); - std::vector tokens; - for (int i = 0; i < (int)o.size(); i++) - tokens.push_back(token(o[i])); - std::cout << printTokens(tokens) << "\n"; - } - else if (command == "tokenize") { - std::cout << printTokens(tokenize(input)); - } - else if (command == "biject") { - if (argv == 3) - std::cerr << "Not enough arguments for biject\n"; - int pos = decimalToUnsigned(secondInput); - std::vector n = prettyCompile(input); - if (pos >= (int)n.size()) - std::cerr << "Code position too high\n"; - Metadata m = n[pos].metadata; - std::cout << "Opcode: " << n[pos].val << ", file: " << m.file << - ", line: " << m.ln << ", char: " << m.ch << "\n"; - } + } + input = argc[2]; + secondInput = argv == 3 ? "" : argc[3]; + } + bool haveSec = secondInput.length() > 0; + if (command == "parse" || command == "parse_serpent") + std::cout << printAST(parseSerpent(input), haveSec) << "\n"; + else if (command == "rewrite") + std::cout << printAST(rewrite(parseLLL(input, true)), haveSec) << "\n"; + else if (command == "compile_to_lll") + std::cout << printAST(compileToLLL(input), haveSec) << "\n"; + else if (command == "build_fragtree") + std::cout << printAST(buildFragmentTree(parseLLL(input, true))) << "\n"; + else if (command == "compile_lll") + std::cout << binToHex(compileLLL(parseLLL(input, true))) << "\n"; + else if (command == "dereference") + std::cout << printAST(dereference(parseLLL(input, true)), haveSec) <<"\n"; + else if (command == "pretty_assemble") + std::cout << printTokens(prettyAssemble(parseLLL(input, true))) <<"\n"; + else if (command == "pretty_compile_lll") + std::cout << printTokens(prettyCompileLLL(parseLLL(input, true))) << "\n"; + else if (command == "pretty_compile") + std::cout << printTokens(prettyCompile(input)) << "\n"; + else if (command == "assemble") + std::cout << assemble(parseLLL(input, true)) << "\n"; + else if (command == "serialize") + std::cout << binToHex(serialize(tokenize(input, Metadata(), false))) << "\n"; + else if (command == "flatten") + std::cout << printTokens(flatten(parseLLL(input, true))) << "\n"; + else if (command == "deserialize") + std::cout << printTokens(deserialize(hexToBin(input))) << "\n"; + else if (command == "compile") + std::cout << binToHex(compile(input)) << "\n"; + else if (command == "encode_datalist") + { + std::vector tokens = tokenize(input); + std::vector o; + for (int i = 0; i < (int)tokens.size(); i++) + o.push_back(tokens[i].val); + std::cout << binToHex(encodeDatalist(o)) << "\n"; + } + else if (command == "decode_datalist") + { + std::vector o = decodeDatalist(hexToBin(input)); + std::vector tokens; + for (int i = 0; i < (int)o.size(); i++) + tokens.push_back(token(o[i])); + std::cout << printTokens(tokens) << "\n"; + } + else if (command == "tokenize") + std::cout << printTokens(tokenize(input)); + else if (command == "biject") + { + if (argv == 3) + std::cerr << "Not enough arguments for biject\n"; + int pos = decimalToUnsigned(secondInput); + std::vector n = prettyCompile(input); + if (pos >= (int)n.size()) + std::cerr << "Code position too high\n"; + Metadata m = n[pos].metadata; + std::cout << "Opcode: " << n[pos].val << ", file: " << m.file << + ", line: " << m.ln << ", char: " << m.ch << "\n"; + } }