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