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