/* See LICENSE file for copyright and license details. */ #include #include #include #include #include "text.h" #include "util.h" static void usage(void) { eprintf("usage: %s predicate\n", argv0); } int main(int argc, char *argv[]) { char *buf = NULL; size_t size = 0; int i, status; pid_t pid; ARGBEGIN { default: usage(); } ARGEND; if(!argc) usage(); argv = memmove(argv-1, argv, argc * sizeof(char *)); while(afgets(&buf, &size, stdin)) { if(buf[i = strlen(buf)-1] == '\n') buf[i] = 0; argv[argc] = buf; if((pid = fork()) == -1) eprintf("fork:"); if(pid == 0) { execvp(*argv, argv); eprintf("%s %s:", argv0, *argv); } while(wait(&status) != pid); if(!status) puts(buf); } return EXIT_SUCCESS; }