use setenv() to set up environment, WINDOW_ID added (from mips!dce)
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 2 Oct 1987 14:46:03 +0000 (06:46 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 2 Oct 1987 14:46:03 +0000 (06:46 -0800)
SCCS-vsn: usr.bin/window/ww.h 3.41
SCCS-vsn: usr.bin/window/wwenviron.c 3.17
SCCS-vsn: usr.bin/window/wwinit.c 3.27

usr/src/usr.bin/window/ww.h
usr/src/usr.bin/window/wwenviron.c
usr/src/usr.bin/window/wwinit.c

index b6ffbdb..8cf27b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)ww.h    3.40 %G%        
+ * @(#)ww.h    3.41 %G%        
  */
 
 /*
  */
 
 /*
@@ -171,7 +171,6 @@ struct ww_tty wwwintty;             /* the terminal settings for windows */
 char *wwterm;                  /* the terminal name */
 char wwtermcap[1024];          /* place for the termcap */
 char wwkeys[512];              /* termcap fields for the function keys */
 char *wwterm;                  /* the terminal name */
 char wwtermcap[1024];          /* place for the termcap */
 char wwkeys[512];              /* termcap fields for the function keys */
-char wwwintermcap[1024];       /* termcap for windows */
 
        /* generally useful variables */
 int wwnrow, wwncol;            /* the screen size */
 
        /* generally useful variables */
 int wwnrow, wwncol;            /* the screen size */
index c5fa0ec..3ef1df2 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)wwenviron.c        3.16 %G%";
+static char sccsid[] = "@(#)wwenviron.c        3.17 %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -19,6 +19,7 @@ register struct ww *wp;
 {
        register i;
        int pgrp = getpid();
 {
        register i;
        int pgrp = getpid();
+       char buf[1024];
 
        if ((i = open("/dev/tty", 0)) < 0)
                goto bad;
 
        if ((i = open("/dev/tty", 0)) < 0)
                goto bad;
@@ -37,7 +38,12 @@ register struct ww *wp;
        /* SIGPIPE is the only one we ignore */
        (void) signal(SIGPIPE, SIG_DFL);
        (void) sigsetmask(0);
        /* SIGPIPE is the only one we ignore */
        (void) signal(SIGPIPE, SIG_DFL);
        (void) sigsetmask(0);
-       (void) sprintf(wwwintermcap, "TERMCAP=%sco#%d:li#%d:%s%s%s%s%s%s%s",
+       /*
+        * Two conditions that make destructive setenv ok:
+        * 1. setenv() copies the string,
+        * 2. we've already called tgetent which copies the termcap entry.
+        */
+       (void) sprintf(buf, "%sco#%d:li#%d:%s%s%s%s%s%s%s",
                WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr,
                wwavailmodes & WWM_REV ? WWT_REV : "",
                wwavailmodes & WWM_BLK ? WWT_BLK : "",
                WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr,
                wwavailmodes & WWM_REV ? WWT_REV : "",
                wwavailmodes & WWM_BLK ? WWT_BLK : "",
@@ -46,6 +52,9 @@ register struct ww *wp;
                wwavailmodes & WWM_DIM ? WWT_DIM : "",
                wwavailmodes & WWM_USR ? WWT_USR : "",
                wwkeys);
                wwavailmodes & WWM_DIM ? WWT_DIM : "",
                wwavailmodes & WWM_USR ? WWT_USR : "",
                wwkeys);
+       (void) setenv("TERMCAP", buf, 1);
+       (void) sprintf(buf, "%d", wp->ww_id + 1);
+       (void) setenv("WINDOW_ID", buf, 1);
        return 0;
 bad:
        wwerrno = WWE_SYS;
        return 0;
 bad:
        wwerrno = WWE_SYS;
index b966095..e76b3f8 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.26 %G%";
+static char sccsid[] = "@(#)wwinit.c   3.27 %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -18,9 +18,6 @@ wwinit()
 {
        register i, j;
        char *kp;
 {
        register i, j;
        char *kp;
-       register char **p, **q;
-       char **env, **termcap = 0;
-       extern char **environ;
        int s;
 
        wwdtablesize = getdtablesize();
        int s;
 
        wwdtablesize = getdtablesize();
@@ -138,21 +135,12 @@ wwinit()
                        wwaddcap(cap, &kp);
                }
        }
                        wwaddcap(cap, &kp);
                }
        }
-       for (i = 0, p = environ; *p++; i++)
-               ;
-       if ((env = (char **)malloc((unsigned)(i + 3) * sizeof (char *))) == 0)
-               goto bad;
-       for (p = environ, q = env; *p; p++, q++) {
-               if (strncmp(*p, "TERM=", 5) == 0)
-                       *q = WWT_TERM;
-               else if (strncmp(*p, "TERMCAP=", 8) == 0)
-                       termcap = q;
-               else
-                       *q = *p;
-       }
-       *(termcap ? termcap : q++) = wwwintermcap;
-       *q = 0;
-       environ = env;
+       /*
+        * It's ok to do this here even if setenv() is destructive
+        * since tt_init() has already made its own copy of it and
+        * wwterm now points to the copy.
+        */
+       (void) setenv("TERM", "window", 1);
 
        (void) signal(SIGPIPE, SIG_IGN);
        (void) sigsetmask(s);
 
        (void) signal(SIGPIPE, SIG_IGN);
        (void) sigsetmask(s);