diff --git a/src/pscat.c b/src/pscat.c index ad8c2bd..f33a4c3 100644 --- a/src/pscat.c +++ b/src/pscat.c @@ -27,8 +27,8 @@ int check_arg(char **argv){ enum { UNINITIALIZED = 0, - INLPAREN = 1, - NORMAL = 2 + NORMAL = 1, + INLPAREN = 2 } s; int terms; @@ -40,9 +40,12 @@ check_arg(char **argv){ else return 0; /* syntax error */ break; - case INLPAREN: - if(scmpflat(*argv, R_PAREN)) - { ++s; ++terms; } + default: /* >= INLPAREN */ + if(scmpflat(*argv, R_PAREN)){ + --s; + terms += s == NORMAL; + }else if(scmpflat(*argv, L_PAREN)) /* ineligant */ + ++s; break; } @@ -54,6 +57,7 @@ int main(int argc, char *argv[]){ char **psstart; int child; int i; + int p; int retval; int terms; @@ -70,7 +74,17 @@ int main(int argc, char *argv[]){ /* loop starts with *argv -> the next L_PAREN */ for(i = 0; i < terms; ++i){ psstart = ++argv; - while(!scmpflat(*++argv, R_PAREN)); + p = 1; + while(p > 0){ + ++argv; + /* branching here potentially saves a comparison. + * this seems like the most optimal way to do this, + * maybe it isn't, i don't care too much */ + if(scmpflat(*argv, L_PAREN)) + ++p; + else if(scmpflat(*argv, R_PAREN)) + --p; + } /* *argv -> the corresponding R_PAREN. turn it into NULL to * terminate the argument list to send to execvp(3) */ *argv = NULL;