version 1.1.2.3, 2013/12/05 14:12:25
|
version 1.2, 2013/12/15 22:57:20
|
Line 1
|
Line 1
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <unistd.h> |
|
#include <string.h> |
|
#include <errno.h> |
#include <aitio.h> |
#include <aitio.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
|
Line 7 int
|
Line 10 int
|
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
prog_t *p; |
prog_t *p; |
int stat; | int f; |
| int ret = 0; |
| char str[BUFSIZ]; |
|
|
if (argc < 2) |
if (argc < 2) |
return 1; |
return 1; |
Line 16 main(int argc, char **argv)
|
Line 21 main(int argc, char **argv)
|
if (!p) { |
if (!p) { |
ELIBERR(io); |
ELIBERR(io); |
return 2; |
return 2; |
|
} else if ((ret = io_progCheck(p, 0))) { |
|
printf("0.exited procs=%d\n", ret); |
|
goto end; |
} else { |
} else { |
printf("wait for keystroke %p ", p); |
printf("wait for keystroke %p ", p); |
getchar(); |
getchar(); |
} |
} |
|
|
printf("%d\n", waitpid(-1, &stat, WNOHANG)); | ret = io_progCheck(p, 0); |
printf("%d\n", waitpid(-1, &stat, WNOHANG)); | if (ret) { |
printf("%d\n", waitpid(-1, &stat, WNOHANG)); | printf("1.exited procs=%d\n", ret); |
printf("%d\n", waitpid(-1, &stat, WNOHANG)); | goto end; |
printf("%d\n", waitpid(-1, &stat, WNOHANG)); | } |
|
|
|
printf("last=%d\n", array_Last(p->prog_fds)); |
|
|
|
ret = io_progGrow(p, 8); |
|
printf("+grow_progs=%d\n", ret); |
|
|
|
printf("wait for keystroke %p ", p); |
|
getchar(); |
|
|
|
ret = io_progVacuum(p, 5); |
|
printf("+vacuum_progs=%d\n", ret); |
|
|
|
printf("wait for keystroke %p ", p); |
|
getchar(); |
|
|
|
again: |
|
f = io_progAttach(p, 0); |
|
printf("f=%d\n", f); |
|
write(f, "v\n", 1); |
|
memset(str, 0, sizeof str); |
|
while (read(f, str, sizeof str) > 0) { |
|
printf(">>> %s", str); |
|
memset(str, 0, sizeof str); |
|
read(0, str, sizeof str); |
|
if (*str == '.') |
|
break; |
|
write(f, str, strlen(str)); |
|
} |
|
io_progDetach(p, f); |
|
|
|
printf("(r) wait for keystroke %p ", p); |
|
if (getchar() == 'a') |
|
goto again; |
|
end: |
io_progDestroy(&p); |
io_progDestroy(&p); |
return 0; | return ret; |
} |
} |