Commit | Line | Data |
---|---|---|
2dd7d7a6 | 1 | #ifndef lint |
c417b691 | 2 | static char *sccsid = "@(#)wwspawn.c 1.5 83/07/22"; |
2dd7d7a6 EW |
3 | #endif |
4 | ||
5 | #include "ww.h" | |
6 | ||
b4be6cd6 EW |
7 | extern int _wwdtablesize; |
8 | ||
2dd7d7a6 EW |
9 | wwfork(wp) |
10 | register struct ww *wp; | |
11 | { | |
12 | switch (wp->ww_pid = fork()) { | |
13 | case -1: | |
14 | return -1; | |
15 | case 0: | |
16 | wp->ww_state = WW_INCHILD; | |
4711df8b | 17 | wwenviron(wp); |
2dd7d7a6 EW |
18 | return 0; |
19 | default: | |
20 | wp->ww_state = WW_HASPROC; | |
2b44d852 EW |
21 | close(wp->ww_tty); |
22 | wp->ww_tty = -1; | |
2dd7d7a6 EW |
23 | return wp->ww_pid; |
24 | } | |
25 | } | |
4711df8b | 26 | |
2b44d852 EW |
27 | #define TERM "TERM=window" |
28 | #define TERMCAP "TERMCAP=WW|window|window package:\ | |
4711df8b EW |
29 | :cr=^M:nl=^J:bl=^G:\ |
30 | :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%%+ %%+ :\ | |
2b44d852 | 31 | :co#%d:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:li#%d:im=\\E@:mi:\ |
4711df8b EW |
32 | :nd=\\EC:ta=^I:pt:up=\\EA:" |
33 | static char *env[100]; | |
34 | static char buf[sizeof TERMCAP + 10]; | |
35 | extern char **environ; | |
36 | ||
37 | wwenviron(wp) | |
38 | register struct ww *wp; | |
39 | { | |
40 | register i; | |
41 | register char **p, **q; | |
42 | char **termcap = 0; | |
43 | ||
44 | dup2(wp->ww_tty, 0); | |
45 | dup2(wp->ww_tty, 1); | |
46 | dup2(wp->ww_tty, 2); | |
b4be6cd6 | 47 | for (i = _wwdtablesize - 1; i > 2; i--) |
4711df8b | 48 | close(i); |
c417b691 | 49 | |
2b44d852 EW |
50 | i = open("/dev/tty"); |
51 | ioctl(i, TIOCNOTTY, 0); | |
52 | close(i); | |
c417b691 | 53 | open(wp->ww_ttyname, 0); |
4711df8b EW |
54 | |
55 | for (p = environ, q = env; *p; p++, q++) { | |
56 | if (strncmp(*p, "TERM=", 5) == 0) | |
57 | *q = TERM; | |
58 | else if (strncmp(*p, "TERMCAP=", 8) == 0) | |
59 | termcap = q; | |
60 | else | |
61 | *q = *p; | |
62 | } | |
63 | if (termcap == 0) | |
64 | termcap = q++; | |
65 | *q = 0; | |
c417b691 | 66 | *termcap = sprintf(buf, TERMCAP, wp->ww_i.ncol, wp->ww_i.nrow); |
4711df8b EW |
67 | environ = env; |
68 | } |