added linesize argument to readline()
[unix-history] / usr / src / usr.bin / window / wwenviron.c
index 7270c18..8dc4956 100644 (file)
@@ -1,13 +1,24 @@
-#ifndef lint
-static char sccsid[] = "@(#)wwenviron.c        3.15 %G%";
-#endif
-
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California,
- * All rights reserved.  Redistribution permitted subject to
- * the terms of the Berkeley Software License Agreement.
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
+#ifndef lint
+static char sccsid[] = "@(#)wwenviron.c        3.20 (Berkeley) %G%";
+#endif /* not lint */
+
 #include "ww.h"
 #include <sys/signal.h>
 
 #include "ww.h"
 #include <sys/signal.h>
 
@@ -19,6 +30,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;
@@ -34,16 +46,19 @@ register struct ww *wp;
                (void) close(i);
        (void) ioctl(0, TIOCSPGRP, (char *)&pgrp);
        (void) setpgrp(pgrp, pgrp);
                (void) close(i);
        (void) ioctl(0, TIOCSPGRP, (char *)&pgrp);
        (void) setpgrp(pgrp, pgrp);
+       /* SIGPIPE is the only one we ignore */
        (void) signal(SIGPIPE, SIG_DFL);
        (void) signal(SIGPIPE, SIG_DFL);
-       (void) sprintf(wwwintermcap, "TERMCAP=%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 : "",
-               wwavailmodes & WWM_UL ? WWT_UL : "",
-               wwavailmodes & WWM_GRP ? WWT_GRP : "",
-               wwavailmodes & WWM_DIM ? WWT_DIM : "",
-               wwavailmodes & WWM_USR ? WWT_USR : "",
-               wwkeys);
+       (void) sigsetmask(0);
+       /*
+        * 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",
+               WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr, wwwintermcap);
+       (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;