Commit | Line | Data |
---|---|---|
aa149fde | 1 | #ifndef lint |
224ba859 | 2 | static char *sccsid = "@(#)wwenviron.c 3.3 83/08/31"; |
aa149fde EW |
3 | #endif |
4 | ||
5 | #include "ww.h" | |
6 | ||
7 | extern char **environ; | |
8 | ||
224ba859 EW |
9 | /* |
10 | * Set up the environment of this process to run in window 'wp'. | |
11 | * Can't report errors in any intelligent way, so don't. | |
12 | */ | |
aa149fde EW |
13 | wwenviron(wp) |
14 | register struct ww *wp; | |
15 | { | |
16 | register i; | |
17 | register char **p, **q; | |
18 | char **termcap = 0; | |
19 | char **env; | |
20 | char *tbuf; | |
21 | ||
22 | (void) dup2(wp->ww_tty, 0); | |
23 | (void) dup2(wp->ww_tty, 1); | |
24 | (void) dup2(wp->ww_tty, 2); | |
25 | for (i = wwdtablesize - 1; i > 2; i--) | |
26 | (void) close(i); | |
27 | ||
224ba859 EW |
28 | i = open("/dev/tty", 0); |
29 | if (i < 0) { | |
30 | perror("/dev/tty"); | |
31 | return; | |
32 | } | |
33 | if (ioctl(i, (int)TIOCNOTTY, (char *)0) < 0) { | |
34 | perror("ioctl(TIOCNOTTY)"); | |
35 | return; | |
36 | } | |
aa149fde | 37 | (void) close(i); |
224ba859 EW |
38 | if (open(wp->ww_ttyname, 0) < 0) { |
39 | perror(wp->ww_ttyname); | |
40 | return; | |
41 | } | |
aa149fde EW |
42 | |
43 | for (i = 0, p = environ; *p; p++, i++) | |
44 | ; | |
45 | if ((env = (char **)malloc((unsigned)(i + 3) * sizeof (char *))) == 0) | |
224ba859 | 46 | return; |
aa149fde | 47 | if ((tbuf = malloc((unsigned) 1024)) == 0) |
224ba859 | 48 | return; |
aa149fde EW |
49 | for (p = environ, q = env; *p; p++, q++) { |
50 | if (strncmp(*p, "TERM=", 5) == 0) | |
51 | *q = WWT_TERM; | |
52 | else if (strncmp(*p, "TERMCAP=", 8) == 0) | |
53 | termcap = q; | |
54 | else | |
55 | *q = *p; | |
56 | } | |
57 | if (termcap == 0) | |
58 | termcap = q++; | |
59 | *q = 0; | |
a598c465 EW |
60 | *termcap = sprintf(tbuf, "TERMCAP=%sco#%d:li#%d:", |
61 | WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr); | |
aa149fde EW |
62 | if (wwavailmodes & WWM_REV) |
63 | (void) strcat(tbuf, WWT_REV); | |
64 | if (wwavailmodes & WWM_UL) | |
65 | (void) strcat(tbuf, WWT_UL); | |
66 | (void) strcat(tbuf, wwkeys); | |
67 | environ = env; | |
68 | } |