changes from Brian Buhrow, primitive yank and put, Posix MIN and TIME,
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 17 Aug 1992 08:43:39 +0000 (00:43 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 17 Aug 1992 08:43:39 +0000 (00:43 -0800)
and others

SCCS-vsn: usr.bin/window/Makefile 5.8
SCCS-vsn: usr.bin/window/wwend.c 3.17
SCCS-vsn: usr.bin/window/cmd.c 3.41
SCCS-vsn: usr.bin/window/cmd7.c 3.8
SCCS-vsn: usr.bin/window/local.h 3.12
SCCS-vsn: usr.bin/window/wwinit.c 3.41
SCCS-vsn: usr.bin/window/wwsuspend.c 3.16
SCCS-vsn: usr.bin/window/main.c 3.43
SCCS-vsn: usr.bin/window/wwrint.c 3.13
SCCS-vsn: usr.bin/window/ww.h 3.65

usr/src/usr.bin/window/Makefile
usr/src/usr.bin/window/cmd.c
usr/src/usr.bin/window/cmd7.c
usr/src/usr.bin/window/local.h
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/ww.h
usr/src/usr.bin/window/wwend.c
usr/src/usr.bin/window/wwinit.c
usr/src/usr.bin/window/wwrint.c
usr/src/usr.bin/window/wwsuspend.c

index 3c6e4ac..b398451 100644 (file)
@@ -1,7 +1,7 @@
-#      @(#)Makefile    5.7 (Berkeley) %G%
+#      @(#)Makefile    5.8 (Berkeley) %G%
 
 PROG=  window
 
 PROG=  window
-CFLAGS+=-R
+CFLAGS+=-R -DVMIN_BUG
 SRCS=  char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c \
        context.c error.c lcmd.c lcmd1.c lcmd2.c main.c mloop.c parser1.c \
        parser2.c parser3.c parser4.c parser5.c scanner.c startup.c string.c \
 SRCS=  char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c \
        context.c error.c lcmd.c lcmd1.c lcmd2.c main.c mloop.c parser1.c \
        parser2.c parser3.c parser4.c parser5.c scanner.c startup.c string.c \
@@ -13,7 +13,8 @@ SRCS= char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c \
        wwinschar.c wwinsline.c wwiomux.c wwlabel.c wwmisc.c wwmove.c \
        wwopen.c wwprintf.c wwpty.c wwputc.c wwputs.c wwredraw.c \
        wwredrawwin.c wwrint.c wwscroll.c wwsize.c wwspawn.c wwsuspend.c \
        wwinschar.c wwinsline.c wwiomux.c wwlabel.c wwmisc.c wwmove.c \
        wwopen.c wwprintf.c wwpty.c wwputc.c wwputs.c wwredraw.c \
        wwredrawwin.c wwrint.c wwscroll.c wwsize.c wwspawn.c wwsuspend.c \
-       wwtty.c wwunframe.c wwupdate.c wwwrite.c xx.c xxflush.c compress.c
+       wwterminfo.c wwtty.c wwunframe.c wwupdate.c wwwrite.c xx.c xxflush.c \
+       compress.c
 MAN=   window.0
 DPADD= ${LIBTERMCAP}
 LDADD= -ltermcap
 MAN=   window.0
 DPADD= ${LIBTERMCAP}
 LDADD= -ltermcap
index b36023f..567ae75 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd.c      3.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd.c      3.41 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -40,6 +40,7 @@ docmd()
                        if (c != escapec)
                                break;
                case 'h': case 'j': case 'k': case 'l':
                        if (c != escapec)
                                break;
                case 'h': case 'j': case 'k': case 'l':
+               case 'y': case 'p':
                case ctrl('y'):
                case ctrl('e'):
                case ctrl('u'):
                case ctrl('y'):
                case ctrl('e'):
                case ctrl('u'):
@@ -100,6 +101,12 @@ docmd()
                        if ((w = getwin()) != 0)
                                sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                        break;
                        if ((w = getwin()) != 0)
                                sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                        break;
+               case 'y':
+                       c_yank();
+                       break;
+               case 'p':
+                       c_put();
+                       break;
                case ':':
                        c_colon();
                        break;
                case ':':
                        c_colon();
                        break;
index c18a5dd..3a191e8 100644 (file)
@@ -9,10 +9,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd7.c     3.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd7.c     3.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
+#include "string.h"
 
 /*
  * Window size.
 
 /*
  * Window size.
@@ -56,3 +57,189 @@ register struct ww *w;
        wwcurtowin(cmdwin);
        sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1);
 }
        wwcurtowin(cmdwin);
        sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1);
 }
+
+/*
+ * Yank and put
+ */
+
+struct yb {
+       char *line;
+       int length;
+       struct yb *link;
+};
+struct yb *yb_head, *yb_tail;
+
+c_yank()
+{
+       struct ww *w = selwin;
+       int col1, row1;
+       int col2, row2;
+       int r, c;
+
+       if (!terse)
+               wwputs("Yank starting position: ", cmdwin);
+       wwcursor(w, 0);
+       row1 = w->ww_cur.r;
+       col1 = w->ww_cur.c;
+       for (;;) {
+               wwsetcursor(row1, col1);
+               while (wwpeekc() < 0)
+                       wwiomux();
+               switch (getpos(&row1, &col1, w->ww_i.t, w->ww_i.l,
+                              w->ww_i.b - 1, w->ww_i.r - 1)) {
+               case 3:
+                       goto out;
+               case 2:
+                       break;
+               case 1:
+               case 0:
+                       continue;
+               }
+               break;
+       }
+       if (!terse)
+               wwputs("\nYank ending position: ", cmdwin);
+       row2 = row1;
+       col2 = col1;
+       for (;;) {
+               wwsetcursor(row2, col2);
+               while (wwpeekc() < 0)
+                       wwiomux();
+               r = row2;
+               c = col2;
+               switch (getpos(&row2, &col2, w->ww_i.t, w->ww_i.l,
+                              w->ww_i.b - 1, w->ww_i.r - 1)) {
+               case 3:
+                       yank_highlight(row1, col1, r, c);
+                       goto out;
+               case 2:
+                       break;
+               case 1:
+                       yank_highlight(row1, col1, r, c);
+                       yank_highlight(row1, col1, row2, col2);
+               case 0:
+                       continue;
+               }
+               break;
+       }
+       if (row2 < row1 || row2 == row1 && col2 < col1) {
+               r = row1;
+               c = col1;
+               row1 = row2;
+               col1 = col2;
+               row2 = r;
+               col2 = c;
+       }
+       unyank();
+       c = col1;
+       for (r = row1; r < row2; r++) {
+               yank_line(r, c, w->ww_b.r);
+               c = w->ww_b.l;
+       }
+       yank_line(r, c, col2);
+       yank_highlight(row1, col1, row2, col2);
+       if (!terse)
+               wwputc('\n', cmdwin);
+out:
+       wwcursor(w, 1);
+}
+
+yank_highlight(row1, col1, row2, col2)
+{
+       struct ww *w = selwin;
+       int r, c;
+
+       if ((wwavailmodes & WWM_REV) == 0)
+               return;
+       if (row2 < row1 || row2 == row1 && col2 < col1) {
+               r = row1;
+               c = col1;
+               row1 = row2;
+               col1 = col2;
+               row2 = r;
+               col2 = c;
+       }
+       c = col1;
+       for (r = row1; r < row2; r++) {
+               yank_highlight_line(r, c, w->ww_b.r);
+               c = w->ww_b.l;
+       }
+       yank_highlight_line(r, c, col2);
+}
+
+yank_highlight_line(r, c, cend)
+{
+       struct ww *w = selwin;
+       char *win;
+
+       if (r < w->ww_i.t || r >= w->ww_i.b)
+               return;
+       if (c < w->ww_i.l)
+               c = w->ww_i.l;
+       if (cend >= w->ww_i.r)
+               cend = w->ww_i.r;
+       for (win = w->ww_win[r] + c; c < cend; c++, win++) {
+               *win ^= WWM_REV;
+               if (wwsmap[r][c] == w->ww_index) {
+                       if (*win == 0)
+                               w->ww_nvis[r]++;
+                       else if (*win == WWM_REV)
+                               w->ww_nvis[r]--;
+                       wwns[r][c].c_m ^= WWM_REV;
+                       wwtouched[r] |= WWU_TOUCHED;
+               }
+       }
+}
+
+unyank()
+{
+       struct yb *yp, *yq;
+
+       for (yp = yb_head; yp; yp = yq) {
+               yq = yp->link;
+               str_free(yp->line);
+               free((char *) yp);
+       }
+       yb_head = yb_tail = 0;
+}
+
+yank_line(r, c, cend)
+{
+       struct yb *yp;
+       int nl = 0;
+       int n;
+       union ww_char *bp;
+       char *cp;
+
+       if (c == cend)
+               return;
+       if ((yp = (struct yb *) malloc(sizeof *yp)) == 0)
+               return;
+       yp->link = 0;
+       nl = cend == selwin->ww_b.r;
+       bp = selwin->ww_buf[r];
+       for (cend--; cend >= c; cend--)
+               if (bp[cend].c_c != ' ')
+                       break;
+       yp->length = n = cend - c + 1;
+       if (nl)
+               yp->length++;
+       yp->line = str_alloc(yp->length + 1);
+       for (bp += c, cp = yp->line; --n >= 0;)
+               *cp++ = bp++->c_c;
+       if (nl)
+               *cp++ = '\n';
+       *cp = 0;
+       if (yb_head)
+               yb_tail = yb_tail->link = yp;
+       else
+               yb_head = yb_tail = yp;
+}
+
+c_put()
+{
+       struct yb *yp;
+
+       for (yp = yb_head; yp; yp = yp->link)
+               (void) write(selwin->ww_pty, yp->line, yp->length);
+}
index 91fc8ec..4eee581 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)local.h     3.11 (Berkeley) %G%
+ *     @(#)local.h     3.12 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -17,3 +17,9 @@
 #define RUNCOM         ".windowrc"
 #define ESCAPEC                ctrl('p')
 #define NLINE          48                      /* default text buffer size */
 #define RUNCOM         ".windowrc"
 #define ESCAPEC                ctrl('p')
 #define NLINE          48                      /* default text buffer size */
+
+#ifdef TERMINFO
+#define _PATH_CAPTOINFO        "/usr/5bin/captoinfo"
+#define _PATH_TIC      "/usr/5bin/tic"
+#define _PATH_RM       "/bin/rm"
+#endif
index 152da77..0d13cd3 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     3.42 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     3.43 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -158,7 +158,7 @@ char **argv;
        mloop();
 
 bad:
        mloop();
 
 bad:
-       wwend();
+       wwend(1);
        return 0;
 }
 
        return 0;
 }
 
index 76557c5..a6ca428 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ww.h        3.64 (Berkeley) %G%
+ *     @(#)ww.h        3.65 (Berkeley) %G%
  */
 
 #ifdef OLD_TTY
  */
 
 #ifdef OLD_TTY
@@ -261,11 +261,15 @@ jmp_buf wwjmpbuf; /* jmpbuf for above */
 #define WWT_DC         "dc=\\EN:"
 char wwwintermcap[1024];       /* terminal-specific but window-independent
                                   part of the window termcap */
 #define WWT_DC         "dc=\\EN:"
 char wwwintermcap[1024];       /* terminal-specific but window-independent
                                   part of the window termcap */
+#ifdef TERMINFO
+       /* where to put the temporary terminfo directory */
+char wwterminfopath[1024];
+#endif
 
        /* our functions */
 struct ww *wwopen();
 void wwchild();
 
        /* our functions */
 struct ww *wwopen();
 void wwchild();
-void wwsuspend();
+void wwquit();
 char **wwalloc();
 char *wwerror();
 
 char **wwalloc();
 char *wwerror();
 
index 0d2c680..eb5d634 100644 (file)
@@ -9,14 +9,26 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwend.c    3.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwend.c    3.17 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 
-wwend()
+/*ARGSUSED*/
+wwend(exit)
 {
        xxend();
        (void) wwsettty(0, &wwoldtty);
 {
        xxend();
        (void) wwsettty(0, &wwoldtty);
+#ifdef TERMINFO
+       if (exit)
+               wwterminfoend();
+#endif
+}
+
+void
+wwquit()
+{
+       wwend(1);
+       exit(1);
 }
 }
index 76315ba..78ddcc9 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwinit.c   3.41 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -28,9 +28,12 @@ wwinit()
        wwhead.ww_forw = &wwhead;
        wwhead.ww_back = &wwhead;
 
        wwhead.ww_forw = &wwhead;
        wwhead.ww_back = &wwhead;
 
-       s = sigblock(sigmask(SIGIO));
+       s = sigblock(sigmask(SIGIO) | sigmask(SIGCHLD) |
+               sigmask(SIGHUP) | sigmask(SIGTERM));
        if (signal(SIGIO, wwrint) == BADSIG ||
            signal(SIGCHLD, wwchild) == BADSIG ||
        if (signal(SIGIO, wwrint) == BADSIG ||
            signal(SIGCHLD, wwchild) == BADSIG ||
+           signal(SIGHUP, wwquit) == BADSIG ||
+           signal(SIGTERM, wwquit) == BADSIG ||
            signal(SIGPIPE, SIG_IGN) == BADSIG) {
                wwerrno = WWE_SYS;
                return -1;
            signal(SIGPIPE, SIG_IGN) == BADSIG) {
                wwerrno = WWE_SYS;
                return -1;
@@ -71,13 +74,14 @@ wwinit()
        wwnewtty.ww_termios = wwoldtty.ww_termios;
        wwnewtty.ww_termios.c_iflag &=
                ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL);
        wwnewtty.ww_termios = wwoldtty.ww_termios;
        wwnewtty.ww_termios.c_iflag &=
                ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL);
-       wwnewtty.ww_termios.c_iflag |= INPCK;
        wwnewtty.ww_termios.c_oflag = 0;
        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        wwnewtty.ww_termios.c_cflag |= CS8;
        wwnewtty.ww_termios.c_lflag = 0;
        for (i = 0; i < NCCS; i++)
                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
        wwnewtty.ww_termios.c_oflag = 0;
        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        wwnewtty.ww_termios.c_cflag |= CS8;
        wwnewtty.ww_termios.c_lflag = 0;
        for (i = 0; i < NCCS; i++)
                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
+       wwnewtty.ww_termios.c_cc[VMIN] = 0;
+       wwnewtty.ww_termios.c_cc[VTIME] = 0;
 #endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        if (wwsettty(0, &wwnewtty) < 0)
 #endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        if (wwsettty(0, &wwnewtty) < 0)
@@ -257,6 +261,10 @@ wwinit()
         * wwterm now points to the copy.
         */
        (void) setenv("TERM", WWT_TERM, 1);
         * wwterm now points to the copy.
         */
        (void) setenv("TERM", WWT_TERM, 1);
+#ifdef TERMINFO
+       if (wwterminfoinit() < 0)
+               goto bad;
+#endif
 
        (void) sigsetmask(s);
        /* catch typeahead before ASYNC was set */
 
        (void) sigsetmask(s);
        /* catch typeahead before ASYNC was set */
index 4d0b5f6..19ef3ca 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwrint.c   3.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwrint.c   3.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
index 8aec0cc..3cdbafa 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwsuspend.c        3.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwsuspend.c        3.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -22,7 +22,7 @@ wwsuspend()
        sig_t oldsig;
 
        oldsig = signal(SIGTSTP, SIG_IGN);
        sig_t oldsig;
 
        oldsig = signal(SIGTSTP, SIG_IGN);
-       wwend();
+       wwend(0);
        (void) signal(SIGTSTP, SIG_DFL);
        (void) kill(0, SIGTSTP);
        (void) signal(SIGTSTP, SIG_IGN);
        (void) signal(SIGTSTP, SIG_DFL);
        (void) kill(0, SIGTSTP);
        (void) signal(SIGTSTP, SIG_IGN);