cleanups, add manual page
[unix-history] / usr / src / usr.bin / ex / ex_cmds.c
index b959374..64c3919 100644 (file)
@@ -1,9 +1,18 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char *sccsid = "@(#)ex_cmds.c   4.2 %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)ex_cmds.c   7.12 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex_tty.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex_tty.h"
+#include "ex_vis.h"
 
 bool   pflag, nflag;
 int    poffset;
 
 bool   pflag, nflag;
 int    poffset;
@@ -68,7 +77,7 @@ error("Offset out-of-bounds|Offset after command too large");
                if (inglobal == 0) {
                        flush();
                        if (!hush && value(PROMPT) && !globp && !noprompt && endline) {
                if (inglobal == 0) {
                        flush();
                        if (!hush && value(PROMPT) && !globp && !noprompt && endline) {
-                               putchar(':');
+                               ex_putchar(':');
                                hadpr = 1;
                        }
                        TSYNC();
                                hadpr = 1;
                        }
                        TSYNC();
@@ -82,7 +91,7 @@ error("Offset out-of-bounds|Offset after command too large");
                given = seensemi = 0;
                do {
                        addr1 = addr2;
                given = seensemi = 0;
                do {
                        addr1 = addr2;
-                       addr = address(0);
+                       addr = address((char *) 0);
                        c = getcd();
                        if (addr == 0)
                                if (c == ',')
                        c = getcd();
                        if (addr == 0)
                                if (c == ',')
@@ -105,12 +114,12 @@ error("Offset out-of-bounds|Offset after command too large");
                        addr1 = one;
                        addr2 = dol;
                        given = 2;
                        addr1 = one;
                        addr2 = dol;
                        given = 2;
-                       c = getchar();
+                       c = ex_getchar();
                }
                if (addr1 == 0)
                        addr1 = addr2;
                if (c == ':')
                }
                if (addr1 == 0)
                        addr1 = addr2;
                if (c == ':')
-                       c = getchar();
+                       c = ex_getchar();
 
                /*
                 * Set command name for special character commands.
 
                /*
                 * Set command name for special character commands.
@@ -122,7 +131,7 @@ error("Offset out-of-bounds|Offset after command too large");
                 * the set of available commands here to save work below.
                 */
                if (inopen) {
                 * the set of available commands here to save work below.
                 */
                if (inopen) {
-                       if (c=='\n' || c=='\r' || c==CTRL(d) || c==EOF) {
+                       if (c=='\n' || c=='\r' || c==CTRL('d') || c==EOF) {
                                if (addr2)
                                        dot = addr2;
                                if (c == EOF)
                                if (addr2)
                                        dot = addr2;
                                if (c == EOF)
@@ -133,7 +142,6 @@ error("Offset out-of-bounds|Offset after command too large");
 notinvis:
                                tailprim(Command, 1, 1);
                }
 notinvis:
                                tailprim(Command, 1, 1);
                }
-choice:
                switch (c) {
 
                case 'a':
                switch (c) {
 
                case 'a':
@@ -228,7 +236,7 @@ changdir:
                        setCNL();
                        vmacchng(0);
                        setin(addr1);
                        setCNL();
                        vmacchng(0);
                        setin(addr1);
-                       delete(0);
+                       ex_delete(0);
                        inappend = 1;
                        ignore(append(gettty, addr1 - 1));
                        inappend = 0;
                        inappend = 1;
                        ignore(append(gettty, addr1 - 1));
                        inappend = 0;
@@ -246,7 +254,7 @@ changdir:
                        vmacchng(0);
                        if (c)
                                YANKreg(c);
                        vmacchng(0);
                        if (c)
                                YANKreg(c);
-                       delete(0);
+                       ex_delete(0);
                        appendnone();
                        continue;
 
                        appendnone();
                        continue;
 
@@ -267,8 +275,13 @@ doecmd:
                        init();
                        addr2 = zero;
                        laste++;
                        init();
                        addr2 = zero;
                        laste++;
-                       sync();
+                       ex_sync();
                        rop(c);
                        rop(c);
+#ifdef VMUNIX
+                       tlaste();
+#endif
+                       laste = 0;
+                       ex_sync();
                        nochng();
                        continue;
 
                        nochng();
                        continue;
 
@@ -327,7 +340,7 @@ doecmd:
                case 'k':
 casek:
                        pastwh();
                case 'k':
 casek:
                        pastwh();
-                       c = getchar();
+                       c = ex_getchar();
                        if (endcmd(c))
                                serror("Mark what?|%s requires following letter", Command);
                        newline();
                        if (endcmd(c))
                                serror("Mark what?|%s requires following letter", Command);
                        newline();
@@ -454,16 +467,12 @@ quit:
                                        vnfl();
                                else {
                                        tostop();
                                        vnfl();
                                else {
                                        tostop();
-                                       /* replaced by tostop
-                                       putpad(VE);
-                                       putpad(KE);
-                                       */
                                }
                                flush();
                                }
                                flush();
-                               setty(normf);
+                               ignore(setty(normf));
                        }
                        cleanup(1);
                        }
                        cleanup(1);
-                       exit(0);
+                       ex_exit(0);
 
                case 'r':
                        if (peekchar() == 'e') {
 
                case 'r':
                        if (peekchar() == 'e') {
@@ -474,9 +483,12 @@ quit:
                                case 'w':
                                        tail2of("rewind");
                                        setnoaddr();
                                case 'w':
                                        tail2of("rewind");
                                        setnoaddr();
+                                       if (!exclam()) {
+                                               ckaw();
+                                               if (chng && dol > zero)
+                                                       error("No write@since last chage (:rewind! overrides)");
+                                       }
                                        eol();
                                        eol();
-                                       ckaw();
-                                       ignore(quickly());
                                        erewind();
                                        next();
                                        c = 'e';
                                        erewind();
                                        next();
                                        c = 'e';
@@ -499,7 +511,7 @@ quit:
                                        init();
                                        addr2 = zero;
                                        laste++;
                                        init();
                                        addr2 = zero;
                                        laste++;
-                                       sync();
+                                       ex_sync();
                                        recover();
                                        rop2();
                                        revocer();
                                        recover();
                                        rop2();
                                        revocer();
@@ -507,6 +519,10 @@ quit:
                                                rop3(c);
                                        if (dol != zero)
                                                change();
                                                rop3(c);
                                        if (dol != zero)
                                                change();
+#ifdef VMUNIX
+                                       tlaste();
+#endif
+                                       laste = 0;
                                        nochng();
                                        continue;
                                }
                                        nochng();
                                        continue;
                                }
@@ -559,25 +575,30 @@ quit:
 
 /* source */
                        case 'o':
 
 /* source */
                        case 'o':
+#ifdef notdef
                                if (inopen)
                                        goto notinvis;
                                if (inopen)
                                        goto notinvis;
+#endif
                                tail("source");
                                setnoaddr();
                                getone();
                                eol();
                                source(file, 0);
                                continue;
                                tail("source");
                                setnoaddr();
                                getone();
                                eol();
                                source(file, 0);
                                continue;
-#ifdef TIOCLGET
-/* stop */
+#ifdef SIGTSTP
+/* stop, suspend */
                        case 't':
                                tail("stop");
                        case 't':
                                tail("stop");
+                               goto suspend;
+                       case 'u':
+                               tail("suspend");
+suspend:
                                if (!ldisc)
                                        error("Old tty driver|Not using new tty driver/shell");
                                c = exclam();
                                eol();
                                if (!c)
                                        ckaw();
                                if (!ldisc)
                                        error("Old tty driver|Not using new tty driver/shell");
                                c = exclam();
                                eol();
                                if (!c)
                                        ckaw();
-                               eol();
                                onsusp();
                                continue;
 #endif
                                onsusp();
                                continue;
 #endif
@@ -650,7 +671,7 @@ quit:
 /* version */
                                tail("version");
                                setNAEOL();
 /* version */
                                tail("version");
                                setNAEOL();
-                               printf("@(#) Version 3.4, %G%"+5);
+                               ex_printf("@(#) Version 3.7, 6/7/85."+5);
                                noonl();
                                continue;
 
                                noonl();
                                continue;
 
@@ -723,7 +744,7 @@ wq:
 /* @ */
                case '*':
                case '@':
 /* @ */
                case '*':
                case '@':
-                       c = getchar();
+                       c = ex_getchar();
                        if (c=='\n' || c=='\r')
                                ungetchar(c);
                        if (any(c, "@*\n\r"))
                        if (c=='\n' || c=='\r')
                                ungetchar(c);
                        if (any(c, "@*\n\r"))
@@ -749,7 +770,7 @@ caseline:
                        notempty();
                        if (addr2 == 0) {
                                if (UP != NOSTR && c == '\n' && !inglobal)
                        notempty();
                        if (addr2 == 0) {
                                if (UP != NOSTR && c == '\n' && !inglobal)
-                                       c = CTRL(k);
+                                       c = CTRL('k');
                                if (inglobal)
                                        addr1 = addr2 = dot;
                                else {
                                if (inglobal)
                                        addr1 = addr2 = dot;
                                else {
@@ -763,7 +784,7 @@ caseline:
                        if (seensemi)
                                addr1 = addr2;
                        getline(*addr1);
                        if (seensemi)
                                addr1 = addr2;
                        getline(*addr1);
-                       if (c == CTRL(k)) {
+                       if (c == CTRL('k')) {
                                flush1();
                                destline--;
                                if (hadpr)
                                flush1();
                                destline--;
                                if (hadpr)
@@ -791,7 +812,7 @@ numberit:
                        setall();
                        if (inglobal == 2)
                                pofix();
                        setall();
                        if (inglobal == 2)
                                pofix();
-                       printf("%d", lineno(addr2));
+                       ex_printf("%d", lineno(addr2));
                        noonl();
                        continue;
 
                        noonl();
                        continue;
 
@@ -826,7 +847,7 @@ numberit:
 
 /* ^D */
 /* EOF */
 
 /* ^D */
 /* EOF */
-               case CTRL(d):
+               case CTRL('d'):
                case EOF:
                        if (exitoneof) {
                                if (addr2 != 0)
                case EOF:
                        if (exitoneof) {
                                if (addr2 != 0)