#include #include #include #include #include "psargs.h" static char *program_name = "pscat"; /* Originally designed to use parentheses but changed to brackets to escape the * hassle of escaping them from the Bourne shell. */ #define L_PAREN '[' #define R_PAREN ']' int main(int argc, char *argv[]){ char **psstart; int child; int i; unsigned int retval; int terms; retval = 0; if((terms = check_arg(++argv, L_PAREN, R_PAREN)) == 0){ fprintf(stderr, "Usage: %s \"[\" [utility [argument...]] \"]\" ...\n", argv[-1] == NULL ? program_name : argv[-1] ); return EX_USAGE; } /* loop starts with *argv -> the next L_PAREN */ for(i = 0; i < terms; ++i){ psstart = argv + 1; argv = corresponding_arg(argv, L_PAREN, R_PAREN); /* *argv -> the corresponding R_PAREN. turn it into NULL to * terminate the argument list to send to execvp(3) */ *argv = NULL; if(fork() == 0){ execvp(psstart[0], psstart); }else wait(&child); /* interpret status information from wait(2) */ if(WIFEXITED(child)) retval += WEXITSTATUS(child); ++argv; } return retval; }