Fix multi case value
This commit is contained in:
parent
72a77c7088
commit
374647e30a
5 changed files with 35 additions and 15 deletions
|
|
@ -119,7 +119,7 @@ public:
|
|||
|
||||
// case
|
||||
arg carg;
|
||||
std::vector< std::pair<arg, list_t> > cases;
|
||||
std::vector< std::pair<std::vector<arg>, list_t> > cases;
|
||||
|
||||
// main: shebang
|
||||
// function: name
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
10
src/main.cpp
10
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)
|
||||
|
|
|
|||
|
|
@ -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] <file> [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");
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ std::pair<arg, uint32_t> 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<size && !is_in(in[i], " \t|&;\n()"))
|
||||
while(i<size && !is_in(in[i], " \t&|;\n#()"))
|
||||
{
|
||||
if(i+1<size && is_in(in[i], "<>") && in[i+1]=='&') // special case for <& and >&
|
||||
{
|
||||
|
|
@ -422,15 +422,22 @@ std::pair<block, uint32_t> parse_case(const char* in, uint32_t size, uint32_t st
|
|||
while(i<size && !word_eq("esac", in, size, i, " \t\n;()&") )
|
||||
{
|
||||
// toto)
|
||||
std::pair<arg, list_t> 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<std::vector<arg>, 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
|
||||
|
|
|
|||
Loading…
Reference in a new issue