-c flag, incmd, setcmd(), setterse() added
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Thu, 5 Apr 1984 15:32:09 +0000 (07:32 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Thu, 5 Apr 1984 15:32:09 +0000 (07:32 -0800)
SCCS-vsn: usr.bin/window/main.c 3.18
SCCS-vsn: usr.bin/window/cmd.c 3.23
SCCS-vsn: usr.bin/window/cmd2.c 3.24
SCCS-vsn: usr.bin/window/defs.h 3.11
SCCS-vsn: usr.bin/window/cmd4.c 3.9
SCCS-vsn: usr.bin/window/lcmd1.c 3.17
SCCS-vsn: usr.bin/window/mloop.c 3.4

usr/src/usr.bin/window/cmd.c
usr/src/usr.bin/window/cmd2.c
usr/src/usr.bin/window/cmd4.c
usr/src/usr.bin/window/defs.h
usr/src/usr.bin/window/lcmd1.c
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/mloop.c

index f3b6d1b..5797488 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       3.22 84/03/29";
+static char *sccsid = "@(#)cmd.c       3.23 84/04/05";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -8,11 +8,8 @@ docmd()
 {
        register char c;
        register struct ww *w;
 {
        register char c;
        register struct ww *w;
+       char out = 0;
 
 
-       if (!terse)
-               wwadd(cmdwin, &wwhead);
-       if (selwin != 0)
-               wwcursor(selwin, 1);
        for (;;) {
                while ((c = wwgetc()) >= 0) {
                        if (!terse)
        for (;;) {
                while ((c = wwgetc()) >= 0) {
                        if (!terse)
@@ -47,7 +44,7 @@ docmd()
                                }
                                setselwin(w);
                                if (checkproc(selwin) >= 0)
                                }
                                setselwin(w);
                                if (checkproc(selwin) >= 0)
-                                        wwcurwin = selwin;
+                                        out = 1;
                                break;
                        case '%':
                                if ((w = getwin()) != 0)
                                break;
                        case '%':
                                if ((w = getwin()) != 0)
@@ -57,7 +54,7 @@ docmd()
                                if (lastselwin != 0) {
                                        setselwin(lastselwin);
                                        if (checkproc(selwin) >= 0)
                                if (lastselwin != 0) {
                                        setselwin(lastselwin);
                                        if (checkproc(selwin) >= 0)
-                                               wwcurwin = selwin;
+                                               out = 1;
                                } else
                                        error("No previous window.");
                                break;
                                } else
                                        error("No previous window.");
                                break;
@@ -138,7 +135,7 @@ docmd()
                                break;
                        case CTRL([):
                                if (checkproc(selwin) >= 0)
                                break;
                        case CTRL([):
                                if (checkproc(selwin) >= 0)
-                                       wwcurwin = selwin;
+                                       out = 1;
                                break;
                        case CTRL(z):
                                wwsuspend();
                                break;
                        case CTRL(z):
                                wwsuspend();
@@ -169,7 +166,7 @@ docmd()
                                        if (checkproc(selwin) >= 0) {
                                                (void) write(selwin->ww_pty,
                                                        &escapec, 1);
                                        if (checkproc(selwin) >= 0) {
                                                (void) write(selwin->ww_pty,
                                                        &escapec, 1);
-                                               wwcurwin = selwin;
+                                               out = 1;
                                        }
                                } else {
                                        if (!terse)
                                        }
                                } else {
                                        if (!terse)
@@ -178,7 +175,7 @@ docmd()
                                }
                        }
                }
                                }
                        }
                }
-               if (wwcurwin != 0 || quit)
+               if (out || quit)
                        break;
                if (terse)
                        wwsetcursor(0, 0);
                        break;
                if (terse)
                        wwsetcursor(0, 0);
@@ -189,13 +186,8 @@ docmd()
                while (wwpeekc() < 0)
                        wwiomux();
        }
                while (wwpeekc() < 0)
                        wwiomux();
        }
-       if (!quit) {
-               if (!terse) {
-                       wwdelete(cmdwin);
-                       reframe();
-               }
-               wwcursor(selwin, 0);
-       }
+       if (!quit)
+               setcmd(0);
 }
 
 struct ww *
 }
 
 struct ww *
@@ -233,3 +225,48 @@ struct ww *w;
        }
        return 0;
 }
        }
        return 0;
 }
+
+setcmd(new)
+char new;
+{
+       if (new && !incmd) {
+               if (!terse)
+                       wwadd(cmdwin, &wwhead);
+               if (selwin != 0)
+                       wwcursor(selwin, 1);
+               wwcurwin = 0;
+       } else if (!new && incmd) {
+               if (!terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               }
+               if (selwin != 0)
+                       wwcursor(selwin, 0);
+               wwcurwin = selwin;
+       }
+       incmd = new;
+}
+
+setterse(new)
+char new;
+{
+       if (incmd)
+               if (new && !terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               } else if (!new && terse)
+                       wwadd(cmdwin, &wwhead);
+       terse = new;
+}
+
+/*
+ * Set the current window.
+ */
+setselwin(w)
+struct ww *w;
+{
+       if (selwin == w)
+               return;
+       lastselwin = selwin;
+       front(selwin = w, 1);
+}
index 05c3644..8efefa9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd2.c      3.23 84/03/03";
+static char *sccsid = "@(#)cmd2.c      3.24 84/04/05";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -216,8 +216,9 @@ c_list()
 
 c_quit()
 {
 
 c_quit()
 {
-       if (terse)
-               wwadd(cmdwin, &wwhead);
+       char oldterse = terse;
+
+       setterse(0);
        wwputs("Really quit [yn]? ", cmdwin);
        wwcurtowin(cmdwin);
        while (wwpeekc() < 0)
        wwputs("Really quit [yn]? ", cmdwin);
        wwcurtowin(cmdwin);
        while (wwpeekc() < 0)
@@ -227,6 +228,5 @@ c_quit()
                quit++;
        } else
                wwputs("\r\n", cmdwin);
                quit++;
        } else
                wwputs("\r\n", cmdwin);
-       if (terse && !quit)
-               wwdelete(cmdwin);
+       setterse(!quit && oldterse);
 }
 }
index cbea99c..41db355 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd4.c      3.8 84/03/03";
+static char *sccsid = "@(#)cmd4.c      3.9 84/04/05";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -57,17 +57,15 @@ out:
 
 c_colon()
 {
 
 c_colon()
 {
+       char oldterse = terse;
        char buf[512];
 
        char buf[512];
 
-       if (terse)
-               wwadd(cmdwin, &wwhead);
+       setterse(0);
        wwputc(':', cmdwin);
        wwgets(buf, wwncol - 3, cmdwin);
        wwputs("\r\n", cmdwin);
        wwputc(':', cmdwin);
        wwgets(buf, wwncol - 3, cmdwin);
        wwputs("\r\n", cmdwin);
-       if (terse)
-               wwdelete(cmdwin);
-       else
-               wwcurtowin(cmdwin);
+       wwcurtowin(cmdwin);
+       setterse(oldterse);
        if (dolongcmd(buf) < 0)
                error("Out of memory.");
 }
        if (dolongcmd(buf) < 0)
                error("Out of memory.");
 }
index d62e14b..2d8e8f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *     @(#)defs.h      3.10 84/03/29   
+ *     @(#)defs.h      3.11 84/04/05   
  */
 
 #include "ww.h"
  */
 
 #include "ww.h"
@@ -35,6 +35,7 @@ char escapec;                 /* the escape character */
 char quit;                     /* quit command issued */
 char terse;                    /* terse mode */
 char debug;                    /* debug mode */
 char quit;                     /* quit command issued */
 char terse;                    /* terse mode */
 char debug;                    /* debug mode */
+char incmd;                    /* in command mode */
 
 struct ww *getwin();
 struct ww *openwin();
 
 struct ww *getwin();
 struct ww *openwin();
index b5372e8..98a8e51 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd1.c     3.16 84/03/29";
+static char *sccsid = "@(#)lcmd1.c     3.17 84/04/05";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -177,12 +177,7 @@ register struct value *v, *a;
 {
        v->v_type = V_NUM;
        v->v_num = terse;
 {
        v->v_type = V_NUM;
        v->v_num = terse;
-       terse = vtobool(a, 1, terse);
-       if (!terse && v->v_num)
-               wwadd(cmdwin, &wwhead);
-       else if (!v->v_num && terse)
-               wwdelete(cmdwin);
-       reframe();
+       setterse(vtobool(a, 1, terse));
 }
 
 struct lcmd_arg arg_source[] = {
 }
 
 struct lcmd_arg arg_source[] = {
index 48b008d..3d21a1c 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      3.17 84/03/29";
+static char *sccsid = "@(#)main.c      3.18 84/04/05";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -16,6 +16,8 @@ char **argv;
        char fflag = 0;
        char dflag = 0;
        char xflag = 0;
        char fflag = 0;
        char dflag = 0;
        char xflag = 0;
+       char *cmd = 0;
+       char tflag = 0;
 
        if (p = rindex(*argv, '/'))
                p++;
 
        if (p = rindex(*argv, '/'))
                p++;
@@ -28,11 +30,19 @@ char **argv;
                        case 'f':
                                fflag++;
                                break;
                        case 'f':
                                fflag++;
                                break;
+                       case 'c':
+                               if (cmd != 0) {
+                                       (void) fprintf(stderr,
+                                               "Only one -c allowed.\n");
+                                       (void) usage();
+                               }
+                               cmd = next(argv);
+                               break;
                        case 'e':
                                setescape(next(argv));
                                break;
                        case 't':
                        case 'e':
                                setescape(next(argv));
                                break;
                        case 't':
-                               terse++;
+                               tflag++;
                                break;
                        case 'd':
                                dflag++;
                                break;
                        case 'd':
                                dflag++;
@@ -98,21 +108,16 @@ char **argv;
        wwflush();
        (void) signal(SIGCHLD, wwchild);
        setvars();
        wwflush();
        (void) signal(SIGCHLD, wwchild);
        setvars();
-       if (fflag)
-               wwcurwin = 0;
-       else {
-               if (!terse)
-                       wwadd(cmdwin, &wwhead);
+
+       setterse(tflag);
+       setcmd(1);
+       if (cmd != 0)
+               dolongcmd(cmd);
+       if (!fflag) {
                if (dflag || doconfig() < 0)
                        dodefault();
                if (dflag || doconfig() < 0)
                        dodefault();
-               if (selwin != 0) {
-                       wwcurwin = selwin;
-                       wwcursor(selwin, 0);
-               }
-               if (!terse) {
-                       wwdelete(cmdwin);
-                       reframe();
-               }
+               if (selwin != 0)
+                       setcmd(0);
        }
 
        mloop();
        }
 
        mloop();
index 61b1a98..d0de604 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)mloop.c     3.3 84/03/03";
+static char *sccsid = "@(#)mloop.c     3.4 84/04/05";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -7,10 +7,10 @@ static        char *sccsid = "@(#)mloop.c     3.3 84/03/03";
 mloop()
 {
        while (!quit) {
 mloop()
 {
        while (!quit) {
-               if (wwcurwin == 0) {
+               if (incmd) {
                        docmd();
                } else if (wwcurwin->ww_state != WWS_HASPROC) {
                        docmd();
                } else if (wwcurwin->ww_state != WWS_HASPROC) {
-                       wwcurwin = 0;
+                       setcmd(1);
                        if (wwpeekc() == escapec)
                                (void) wwgetc();
                        error("Process died.");
                        if (wwpeekc() == escapec)
                                (void) wwgetc();
                        error("Process died.");
@@ -29,8 +29,8 @@ mloop()
                                        wwibp = p;
                                }
                                if (wwpeekc() == escapec) {
                                        wwibp = p;
                                }
                                if (wwpeekc() == escapec) {
-                                       wwcurwin = 0;
                                        (void) wwgetc();
                                        (void) wwgetc();
+                                       setcmd(1);
                                }
                        }
                }
                                }
                        }
                }