Bill added more buffers, and I put in sccs.
[unix-history] / usr / src / usr.bin / ex / ex_cmds.c
index 3939db5..b959374 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/* Copyright (c) 1980 Regents of the University of California */
+static char *sccsid = "@(#)ex_cmds.c   4.2 %G%";
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
@@ -137,7 +138,15 @@ choice:
 
                case 'a':
 
 
                case 'a':
 
-                       if (peekchar() == 'r') {
+                       switch(peekchar()) {
+                       case 'b':
+/* abbreviate */
+                               tail("abbreviate");
+                               setnoaddr();
+                               mapcmd(0, 1);
+                               anyabbrs = 1;
+                               continue;
+                       case 'r':
 /* args */
                                tail("args");
                                setnoaddr();
 /* args */
                                tail("args");
                                setnoaddr();
@@ -153,9 +162,12 @@ choice:
                        setdot();
                        aiflag = exclam();
                        newline();
                        setdot();
                        aiflag = exclam();
                        newline();
+                       vmacchng(0);
                        deletenone();
                        setin(addr2);
                        deletenone();
                        setin(addr2);
+                       inappend = 1;
                        ignore(append(gettty, addr2));
                        ignore(append(gettty, addr2));
+                       inappend = 0;
                        nochng();
                        continue;
 
                        nochng();
                        continue;
 
@@ -165,6 +177,7 @@ choice:
 /* copy */
                        case 'o':
                                tail("copy");
 /* copy */
                        case 'o':
                                tail("copy");
+                               vmacchng(0);
                                move();
                                continue;
 
                                move();
                                continue;
 
@@ -213,9 +226,12 @@ changdir:
 /* change */
                        aiflag = exclam();
                        setCNL();
 /* change */
                        aiflag = exclam();
                        setCNL();
+                       vmacchng(0);
                        setin(addr1);
                        delete(0);
                        setin(addr1);
                        delete(0);
+                       inappend = 1;
                        ignore(append(gettty, addr1 - 1));
                        ignore(append(gettty, addr1 - 1));
+                       inappend = 0;
                        nochng();
                        continue;
 
                        nochng();
                        continue;
 
@@ -227,6 +243,7 @@ changdir:
                        tail("delete");
                        c = cmdreg();
                        setCNL();
                        tail("delete");
                        c = cmdreg();
                        setCNL();
+                       vmacchng(0);
                        if (c)
                                YANKreg(c);
                        delete(0);
                        if (c)
                                YANKreg(c);
                        delete(0);
@@ -237,6 +254,7 @@ changdir:
 /* ex */
                case 'e':
                        tail(peekchar() == 'x' ? "ex" : "edit");
 /* ex */
                case 'e':
                        tail(peekchar() == 'x' ? "ex" : "edit");
+editcmd:
                        if (!exclam() && chng)
                                c = 'E';
                        filename(c);
                        if (!exclam() && chng)
                                c = 'E';
                        filename(c);
@@ -260,7 +278,9 @@ doecmd:
                        setnoaddr();
                        filename(c);
                        noonl();
                        setnoaddr();
                        filename(c);
                        noonl();
+/*
                        synctmp();
                        synctmp();
+*/
                        continue;
 
 /* global */
                        continue;
 
 /* global */
@@ -279,9 +299,12 @@ doecmd:
                        nonzero();
                        aiflag = exclam();
                        newline();
                        nonzero();
                        aiflag = exclam();
                        newline();
+                       vmacchng(0);
                        deletenone();
                        setin(addr2);
                        deletenone();
                        setin(addr2);
+                       inappend = 1;
                        ignore(append(gettty, addr2 - 1));
                        ignore(append(gettty, addr2 - 1));
+                       inappend = 0;
                        if (dot == zero && dol > zero)
                                dot = one;
                        nochng();
                        if (dot == zero && dol > zero)
                                dot = one;
                        nochng();
@@ -294,6 +317,7 @@ doecmd:
                        setcount();
                        nonzero();
                        newline();
                        setcount();
                        nonzero();
                        newline();
+                       vmacchng(0);
                        if (given < 2 && addr2 != dol)
                                addr2++;
                        join(c);
                        if (given < 2 && addr2 != dol)
                                addr2++;
                        join(c);
@@ -330,7 +354,7 @@ casek:
 /* map */
                                        tail2of("map");
                                        setnoaddr();
 /* map */
                                        tail2of("map");
                                        setnoaddr();
-                                       mapcmd(0);
+                                       mapcmd(0, 0);
                                        continue;
                                }
 /* mark */
                                        continue;
                                }
 /* mark */
@@ -339,6 +363,7 @@ casek:
                        }
 /* move */
                        tail("move");
                        }
 /* move */
                        tail("move");
+                       vmacchng(0);
                        move();
                        continue;
 
                        move();
                        continue;
 
@@ -377,6 +402,7 @@ casek:
                                setdot();
                                c = cmdreg();
                                eol();
                                setdot();
                                c = cmdreg();
                                eol();
+                               vmacchng(0);
                                if (c)
                                        putreg(c);
                                else
                                if (c)
                                        putreg(c);
                                else
@@ -427,8 +453,11 @@ quit:
                                if (!ateopr())
                                        vnfl();
                                else {
                                if (!ateopr())
                                        vnfl();
                                else {
+                                       tostop();
+                                       /* replaced by tostop
                                        putpad(VE);
                                        putpad(KE);
                                        putpad(VE);
                                        putpad(KE);
+                                       */
                                }
                                flush();
                                setty(normf);
                                }
                                flush();
                                setty(normf);
@@ -445,8 +474,9 @@ quit:
                                case 'w':
                                        tail2of("rewind");
                                        setnoaddr();
                                case 'w':
                                        tail2of("rewind");
                                        setnoaddr();
-                                       ignore(quickly());
                                        eol();
                                        eol();
+                                       ckaw();
+                                       ignore(quickly());
                                        erewind();
                                        next();
                                        c = 'e';
                                        erewind();
                                        next();
                                        c = 'e';
@@ -487,6 +517,7 @@ quit:
                        if (savedfile[0] == 0 && dol == zero)
                                c = 'e';
                        pastwh();
                        if (savedfile[0] == 0 && dol == zero)
                                c = 'e';
                        pastwh();
+                       vmacchng(0);
                        if (peekchar() == '!') {
                                setdot();
                                ignchar();
                        if (peekchar() == '!') {
                                setdot();
                                ignchar();
@@ -524,7 +555,6 @@ quit:
                                flush();
                                unixwt(1, unixex("-i", (char *) 0, 0, 0));
                                vcontin(0);
                                flush();
                                unixwt(1, unixex("-i", (char *) 0, 0, 0));
                                vcontin(0);
-                               putpad(TI);
                                continue;
 
 /* source */
                                continue;
 
 /* source */
@@ -537,6 +567,21 @@ quit:
                                eol();
                                source(file, 0);
                                continue;
                                eol();
                                source(file, 0);
                                continue;
+#ifdef TIOCLGET
+/* stop */
+                       case 't':
+                               tail("stop");
+                               if (!ldisc)
+                                       error("Old tty driver|Not using new tty driver/shell");
+                               c = exclam();
+                               eol();
+                               if (!c)
+                                       ckaw();
+                               eol();
+                               onsusp();
+                               continue;
+#endif
+
                        }
                        /* fall into ... */
 
                        }
                        /* fall into ... */
 
@@ -548,6 +593,7 @@ quit:
                        Command = "substitute";
                        if (c == 's')
                                tail(Command);
                        Command = "substitute";
                        if (c == 's')
                                tail(Command);
+                       vmacchng(0);
                        if (!substitute(c))
                                pflag = 0;
                        continue;
                        if (!substitute(c))
                                pflag = 0;
                        continue;
@@ -564,17 +610,26 @@ quit:
                                continue;
                        }
                        tail("t");
                                continue;
                        }
                        tail("t");
+                       vmacchng(0);
                        move();
                        continue;
 
                case 'u':
                        if (peekchar() == 'n') {
                        move();
                        continue;
 
                case 'u':
                        if (peekchar() == 'n') {
-/* unmap */
                                ignchar();
                                ignchar();
-                               if (peekchar() == 'm') {
+                               switch(peekchar()) {
+/* unmap */
+                               case 'm':
                                        tail2of("unmap");
                                        setnoaddr();
                                        tail2of("unmap");
                                        setnoaddr();
-                                       mapcmd(1);
+                                       mapcmd(1, 0);
+                                       continue;
+/* unabbreviate */
+                               case 'a':
+                                       tail2of("unabbreviate");
+                                       setnoaddr();
+                                       mapcmd(1, 1);
+                                       anyabbrs = 1;
                                        continue;
                                }
 /* undo */
                                        continue;
                                }
 /* undo */
@@ -595,14 +650,17 @@ quit:
 /* version */
                                tail("version");
                                setNAEOL();
 /* version */
                                tail("version");
                                setNAEOL();
-                               /* should use SCCS subst here */
-                               printf("Version 3.1, November 11, 1979");
+                               printf("@(#) Version 3.4, %G%"+5);
                                noonl();
                                continue;
 
 /* visual */
                        case 'i':
                                tail("visual");
                                noonl();
                                continue;
 
 /* visual */
                        case 'i':
                                tail("visual");
+                               if (inopen) {
+                                       c = 'e';
+                                       goto editcmd;
+                               }
                                vop();
                                pflag = 0;
                                nochng();
                                vop();
                                pflag = 0;
                                nochng();
@@ -618,7 +676,9 @@ quit:
                case 'w':
                        c = peekchar();
                        tail(c == 'q' ? "wq" : "write");
                case 'w':
                        c = peekchar();
                        tail(c == 'q' ? "wq" : "write");
+wq:
                        if (skipwh() && peekchar() == '!') {
                        if (skipwh() && peekchar() == '!') {
+                               pofix();
                                ignchar();
                                setall();
                                unix0(0);
                                ignchar();
                                setall();
                                unix0(0);
@@ -632,12 +692,21 @@ quit:
                                goto quit;
                        continue;
 
                                goto quit;
                        continue;
 
+/* xit */
+               case 'x':
+                       tail("xit");
+                       if (!chng)
+                               goto quit;
+                       c = 'q';
+                       goto wq;
+
 /* yank */
                case 'y':
                        tail("yank");
                        c = cmdreg();
                        setcount();
                        eol();
 /* yank */
                case 'y':
                        tail("yank");
                        c = cmdreg();
                        setcount();
                        eol();
+                       vmacchng(0);
                        if (c)
                                YANKreg(c);
                        else
                        if (c)
                                YANKreg(c);
                        else
@@ -679,14 +748,15 @@ quit:
 caseline:
                        notempty();
                        if (addr2 == 0) {
 caseline:
                        notempty();
                        if (addr2 == 0) {
-                               if (dot == dol)
-                                       error("At EOF|At end-of-file");
                                if (UP != NOSTR && c == '\n' && !inglobal)
                                        c = CTRL(k);
                                if (inglobal)
                                        addr1 = addr2 = dot;
                                if (UP != NOSTR && c == '\n' && !inglobal)
                                        c = CTRL(k);
                                if (inglobal)
                                        addr1 = addr2 = dot;
-                               else
+                               else {
+                                       if (dot == dol)
+                                               error("At EOF|At end-of-file");
                                        addr1 = addr2 = dot + 1;
                                        addr1 = addr2 = dot + 1;
+                               }
                        }
                        setdot();
                        nonzero();
                        }
                        setdot();
                        nonzero();
@@ -702,6 +772,11 @@ caseline:
                        plines(addr1, addr2, 1);
                        continue;
 
                        plines(addr1, addr2, 1);
                        continue;
 
+/* " */
+               case '"':
+                       comment();
+                       continue;
+
 /* # */
                case '#':
 numberit:
 /* # */
                case '#':
 numberit:
@@ -714,6 +789,8 @@ numberit:
                case '=':
                        newline();
                        setall();
                case '=':
                        newline();
                        setall();
+                       if (inglobal == 2)
+                               pofix();
                        printf("%d", lineno(addr2));
                        noonl();
                        continue;
                        printf("%d", lineno(addr2));
                        noonl();
                        continue;
@@ -721,17 +798,17 @@ numberit:
 /* ! */
                case '!':
                        if (addr2 != 0) {
 /* ! */
                case '!':
                        if (addr2 != 0) {
+                               vmacchng(0);
                                unix0(0);
                                setdot();
                                filter(2);
                        } else {
                                unix0(1);
                                unix0(0);
                                setdot();
                                filter(2);
                        } else {
                                unix0(1);
-                               vnfl();
+                               pofix();
                                putpad(TE);
                                flush();
                                unixwt(1, unixex("-c", uxb, 0, 0));
                                putpad(TE);
                                flush();
                                unixwt(1, unixex("-c", uxb, 0, 0));
-                               vcontin(1);
-                               putpad(TI);
+                               vclrech(1);     /* vcontin(0); */
                                nochng();
                        }
                        continue;
                                nochng();
                        }
                        continue;
@@ -743,6 +820,7 @@ numberit:
                        for (cnt = 1; peekchar() == c; cnt++)
                                ignchar();
                        setCNL();
                        for (cnt = 1; peekchar() == c; cnt++)
                                ignchar();
                        setCNL();
+                       vmacchng(0);
                        shift(c, cnt);
                        continue;
 
                        shift(c, cnt);
                        continue;