diff --git a/include/struc.hpp b/include/struc.hpp index 902d845..72d1480 100644 --- a/include/struc.hpp +++ b/include/struc.hpp @@ -119,7 +119,7 @@ public: // case arg carg; - std::vector< std::pair > cases; + std::vector< std::pair, list_t> > cases; // main: shebang // function: name diff --git a/src/generate.cpp b/src/generate.cpp index 1329db4..40f6542 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -274,7 +274,10 @@ std::string block::generate_case(int ind) { // case definition : foo) if(!opt_minimize) ret += INDENT; - ret += cs.first.generate(ind) + ')'; + for(auto it: cs.first) + ret += it.generate(ind) + '|'; + ret.pop_back(); + ret += ')'; if(!opt_minimize) ret += '\n'; // commands for(auto it: cs.second) diff --git a/src/main.cpp b/src/main.cpp index cb83856..241ed04 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -117,10 +117,18 @@ int main(int argc, char* argv[]) { return execute(sh, args); } - else if(options['o']) + else if(options['c']) { std::cout << sh.generate(); } + else if(options['o']) + { + std::string destfile=options['o']; + if(destfile == "-") + destfile = "/dev/stdout"; + std::ofstream(destfile) << sh.generate(); + ztd::exec("chmod", "+x", destfile); + } else { if(binshebang == curbin) diff --git a/src/options.cpp b/src/options.cpp index a48e218..a99e685 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -10,7 +10,8 @@ ztd::option_set gen_options() ret.add(ztd::option('h', "help", false, "Display this help message")); ret.add(ztd::option('m', "minimize", false, "Minimize code")); ret.add(ztd::option('e', "exec", false, "Directly execute script")); - ret.add(ztd::option('o', "output", false, "Output result script to stdout")); + ret.add(ztd::option('o', "output", true , "Output result script to file", "file")); + ret.add(ztd::option('c', "stdout", false, "Output result script to stdout")); ret.add(ztd::option("help-commands", false, "Print help for linker commands")); return ret; } @@ -43,7 +44,8 @@ ztd::option_set create_resolve_opts() void print_help(const char* arg0) { printf("%s [options] [arg...]\n", arg0); - printf("Link extended shell, allows file including and command resolving\n"); + printf("Link extended shell\n"); + printf("Allows file including and command resolving\n"); printf("See --help-commands for help on linker commands\n"); printf("\n"); printf("Options:\n"); diff --git a/src/parse.cpp b/src/parse.cpp index fc8c7e1..c9d1bff 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -110,7 +110,7 @@ std::pair parse_arg(const char* in, uint32_t size, uint32_t start if(is_in(in[i], "&|;\n#()")) throw ztd::format_error( strf("Unexpected token '%c'", in[i]) , g_origin, in, i); - while(i") && in[i+1]=='&') // special case for <& and >& { @@ -422,15 +422,22 @@ std::pair parse_case(const char* in, uint32_t size, uint32_t st while(i cc; - pa = parse_arg(in, size, i); - if(pa.first.raw == "") - throw ztd::format_error("Empty case value", g_origin, in, i); - cc.first = pa.first; - i=skip_unread(in, size, pa.second); - - if(in[i] != ')') - throw ztd::format_error( strf("Unexpected token '%c', expecting ')'", in[i]), g_origin, in, i ); + std::pair, list_t> cc; + while(true) + { + pa = parse_arg(in, size, i); + if(pa.first.raw == "") + throw ztd::format_error("Empty case value", g_origin, in, i); + cc.first.push_back(pa.first); + i=skip_unread(in, size, pa.second); + if(i>=size ) + throw ztd::format_error("Unexpected end of file. Expecting 'esac'", g_origin, in, i); + if(is_in(in[i], "&;\n#(")) + throw ztd::format_error( strf("Unexpected token '%c', expecting ')'", in[i]), g_origin, in, i ); + if(in[i] == ')') + break; + i=skip_unread(in, size, i+1); + } i++; while(true) // blocks