support nesting
This commit is contained in:
parent
a018ed7506
commit
2cb44c6fd1
26
src/pscat.c
26
src/pscat.c
@ -27,8 +27,8 @@ int
|
|||||||
check_arg(char **argv){
|
check_arg(char **argv){
|
||||||
enum {
|
enum {
|
||||||
UNINITIALIZED = 0,
|
UNINITIALIZED = 0,
|
||||||
INLPAREN = 1,
|
NORMAL = 1,
|
||||||
NORMAL = 2
|
INLPAREN = 2
|
||||||
} s;
|
} s;
|
||||||
int terms;
|
int terms;
|
||||||
|
|
||||||
@ -40,9 +40,12 @@ check_arg(char **argv){
|
|||||||
else
|
else
|
||||||
return 0; /* syntax error */
|
return 0; /* syntax error */
|
||||||
break;
|
break;
|
||||||
case INLPAREN:
|
default: /* >= INLPAREN */
|
||||||
if(scmpflat(*argv, R_PAREN))
|
if(scmpflat(*argv, R_PAREN)){
|
||||||
{ ++s; ++terms; }
|
--s;
|
||||||
|
terms += s == NORMAL;
|
||||||
|
}else if(scmpflat(*argv, L_PAREN)) /* ineligant */
|
||||||
|
++s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +57,7 @@ int main(int argc, char *argv[]){
|
|||||||
char **psstart;
|
char **psstart;
|
||||||
int child;
|
int child;
|
||||||
int i;
|
int i;
|
||||||
|
int p;
|
||||||
int retval;
|
int retval;
|
||||||
int terms;
|
int terms;
|
||||||
|
|
||||||
@ -70,7 +74,17 @@ int main(int argc, char *argv[]){
|
|||||||
/* loop starts with *argv -> the next L_PAREN */
|
/* loop starts with *argv -> the next L_PAREN */
|
||||||
for(i = 0; i < terms; ++i){
|
for(i = 0; i < terms; ++i){
|
||||||
psstart = ++argv;
|
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
|
/* *argv -> the corresponding R_PAREN. turn it into NULL to
|
||||||
* terminate the argument list to send to execvp(3) */
|
* terminate the argument list to send to execvp(3) */
|
||||||
*argv = NULL;
|
*argv = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user