version 1.7, 2000/06/28 10:01:27 |
version 1.8, 2000/07/24 23:08:25 |
|
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <sys/wait.h> |
#include <ctype.h> |
#include <ctype.h> |
|
#include <paths.h> |
#include <regex.h> |
#include <regex.h> |
#include <stddef.h> |
#include <stddef.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
#include <err.h> |
#include <err.h> |
|
#include <errno.h> |
|
#include <unistd.h> |
#include "mdef.h" |
#include "mdef.h" |
#include "stdd.h" |
#include "stdd.h" |
#include "extern.h" |
#include "extern.h" |
|
|
do_regexp(argv[2], &re, argv[4], pmatch); |
do_regexp(argv[2], &re, argv[4], pmatch); |
free(pmatch); |
free(pmatch); |
regfree(&re); |
regfree(&re); |
|
} |
|
|
|
void |
|
doesyscmd(cmd) |
|
const char *cmd; |
|
{ |
|
int p[2]; |
|
pid_t pid, cpid; |
|
char *argv[4]; |
|
int cc; |
|
int status; |
|
|
|
/* Follow gnu m4 documentation: first flush buffers. */ |
|
fflush(NULL); |
|
|
|
argv[0] = "sh"; |
|
argv[1] = "-c"; |
|
argv[2] = (char *)cmd; |
|
argv[3] = NULL; |
|
|
|
/* Just set up standard output, share stderr and stdin with m4 */ |
|
if (pipe(p) == -1) |
|
err(1, "bad pipe"); |
|
switch(cpid = fork()) { |
|
case -1: |
|
err(1, "bad fork"); |
|
/* NOTREACHED */ |
|
case 0: |
|
(void) close(p[0]); |
|
(void) dup2(p[1], 1); |
|
(void) close(p[1]); |
|
execv(_PATH_BSHELL, argv); |
|
exit(1); |
|
default: |
|
/* Read result in two stages, since m4's buffer is |
|
* pushback-only. */ |
|
(void) close(p[1]); |
|
do { |
|
char result[BUFSIZE]; |
|
cc = read(p[0], result, sizeof result); |
|
if (cc > 0) |
|
addchars(result, cc); |
|
} while (cc > 0 || (cc == -1 && errno == EINTR)); |
|
|
|
(void) close(p[0]); |
|
while ((pid = wait(&status)) != cpid && pid >= 0) |
|
continue; |
|
pbstr(getstring()); |
|
} |
} |
} |