1: #include <stdio.h>
2: #include <unistd.h>
3: #include <string.h>
4: #include <errno.h>
5: #include <aitio.h>
6: #include <sys/wait.h>
7:
8:
9: int
10: main(int argc, char **argv)
11: {
12: prog_t *p;
13: FILE *f;
14: int ret = 0;
15: char str[BUFSIZ];
16:
17: if (argc < 2)
18: return 1;
19:
20: p = io_progInit(argv[1], 3, 10);
21: if (!p) {
22: ELIBERR(io);
23: return 2;
24: } else if ((ret = io_progCheck(p))) {
25: printf("0.exited procs=%d\n", ret);
26: goto end;
27: } else {
28: printf("wait for keystroke %p ", p);
29: getchar();
30: }
31:
32: ret = io_progCheck(p);
33: if (ret) {
34: printf("1.exited procs=%d\n", ret);
35: goto end;
36: }
37:
38: printf("last=%d\n", array_Last(p->prog_fds));
39:
40: ret = io_progGrow(p, 8);
41: printf("+grow_progs=%d\n", ret);
42:
43: printf("wait for keystroke %p ", p);
44: getchar();
45:
46: ret = io_progVacuum(p, 5);
47: printf("+vacuum_progs=%d\n", ret);
48:
49: printf("wait for keystroke %p ", p);
50: getchar();
51:
52: again:
53: f = io_progAttach(p);
54: printf("f=%p\n", f);
55: while (read(fileno(f), str, sizeof str) > 0) {
56: printf(">>> %s", str);
57: fgets(str, sizeof str, stdin);
58: if (*str == '.')
59: break;
60: write(fileno(f), str, strlen(str));
61: }
62: io_progDetach(p, f);
63:
64: printf("wait for keystroke %p ", p);
65: if (getchar() == 'a')
66: goto again;
67: end:
68: io_progDestroy(&p);
69: return ret;
70: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>