BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / ex / ex_cmds2.c
index 95deb53..81e34e3 100644 (file)
@@ -1,12 +1,21 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*
+ * 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_cmds2.c  7.6 (Berkeley) 1/2/88";
+#endif not lint
+
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex_tty.h"
 #include "ex_vis.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;
+extern bool    pflag, nflag;           /* mjm: extern; also in ex_cmds.c */
+extern int     poffset;                /* mjm: extern; also in ex_cmds.c */
 
 /*
  * Subroutines for major command loop.
 
 /*
  * Subroutines for major command loop.
@@ -21,7 +30,7 @@ cmdreg()
        register int wh = skipwh();
 
        if (wh && isalpha(peekchar()))
        register int wh = skipwh();
 
        if (wh && isalpha(peekchar()))
-               c = getchar();
+               c = ex_getchar();
        return (c);
 }
 
        return (c);
 }
 
@@ -39,6 +48,7 @@ endcmd(ch)
                return (1);
        
        case '|':
                return (1);
        
        case '|':
+       case '"':
                endline = 0;
                return (1);
        }
                endline = 0;
                return (1);
        }
@@ -62,16 +72,24 @@ eol()
  */
 /*VARARGS2*/
 error(str, i)
  */
 /*VARARGS2*/
 error(str, i)
-#ifdef lint
-       register char *str;
+#ifndef EXSTRINGS
+       char *str;
 #else
 #else
-       register int str;
+# ifdef lint
+       char *str;
+# else
+       int str;
+# endif
 #endif
        int i;
 {
 
        error0();
        merror(str, i);
 #endif
        int i;
 {
 
        error0();
        merror(str, i);
+       if (writing) {
+               serror(" [Warning - %s is incomplete]", file);
+               writing = 0;
+       }
        error1(str);
 }
 
        error1(str);
 }
 
@@ -85,9 +103,9 @@ erewind()
        argv = argv0;
        args = args0;
        if (argc > 1 && !hush) {
        argv = argv0;
        args = args0;
        if (argc > 1 && !hush) {
-               printf(mesg("%d files@to edit"), argc);
+               ex_printf(mesg("%d files@to edit"), argc);
                if (inopen)
                if (inopen)
-                       putchar(' ');
+                       ex_putchar(' ');
                else
                        putNFL();
        }
                else
                        putNFL();
        }
@@ -118,10 +136,6 @@ error0()
        setoutt();
        flush();
        resetflav();
        setoutt();
        flush();
        resetflav();
-       if (laste) {
-               laste = 0;
-               sync();
-       }
        if (!SO || !SE)
                dingdong();
        if (inopen) {
        if (!SO || !SE)
                dingdong();
        if (inopen) {
@@ -132,8 +146,10 @@ error0()
                COLUMNS = OCOLUMNS;
                undvis();
                ostop(normf);
                COLUMNS = OCOLUMNS;
                undvis();
                ostop(normf);
+               /* ostop should be doing this
                putpad(VE);
                putpad(KE);
                putpad(VE);
                putpad(KE);
+               */
                putnl();
        }
        inopen = 0;
                putnl();
        }
        inopen = 0;
@@ -158,23 +174,23 @@ error1(str)
                io = -1;
        }
        die = (getpid() != ppid);       /* Only children die */
                io = -1;
        }
        die = (getpid() != ppid);       /* Only children die */
+       inappend = inglobal = 0;
+       globp = vglobp = vmacp = 0;
        if (vcatch && !die) {
        if (vcatch && !die) {
-               inglobal = 0;
-               vglobp = vmacp = 0;
                inopen = 1;
                vcatch = 0;
                inopen = 1;
                vcatch = 0;
+               if (str)
+                       noonl();
                fixol();
                longjmp(vreslab,1);
        }
        if (str && !vcatch)
                putNFL();
        if (die)
                fixol();
                longjmp(vreslab,1);
        }
        if (str && !vcatch)
                putNFL();
        if (die)
-               exit(1);
+               ex_exit(1);
        lseek(0, 0L, 2);
        if (inglobal)
                setlastchar('\n');
        lseek(0, 0L, 2);
        if (inglobal)
                setlastchar('\n');
-       inglobal = 0;
-       globp = 0;
        while (lastchar() != '\n' && lastchar() != EOF)
                ignchar();
        ungetchar(0);
        while (lastchar() != '\n' && lastchar() != EOF)
                ignchar();
        ungetchar(0);
@@ -228,10 +244,12 @@ makargs()
  */
 next()
 {
  */
 next()
 {
+       extern short isalt;     /* defined in ex_io.c */
 
        if (argc == 0)
                error("No more files@to edit");
        morargc = argc;
 
        if (argc == 0)
                error("No more files@to edit");
        morargc = argc;
+       isalt = (strcmp(altfile, args)==0) + 1;
        if (savedfile[0])
                CP(altfile, savedfile);
        CP(savedfile, args);
        if (savedfile[0])
                CP(altfile, savedfile);
        CP(savedfile, args);
@@ -249,7 +267,7 @@ newline()
 
        resetflav();
        for (;;) {
 
        resetflav();
        for (;;) {
-               c = getchar();
+               c = ex_getchar();
                switch (c) {
 
                case '^':
                switch (c) {
 
                case '^':
@@ -277,6 +295,11 @@ newline()
                case '\t':
                        continue;
 
                case '\t':
                        continue;
 
+               case '"':
+                       comment();
+                       setflav();
+                       return;
+
                default:
                        if (!endcmd(c))
 serror("Extra chars|Extra characters at end of \"%s\" command", Command);
                default:
                        if (!endcmd(c))
 serror("Extra chars|Extra characters at end of \"%s\" command", Command);
@@ -317,7 +340,7 @@ quickly()
                chng = 0;
 */
                xchng = 0;
                chng = 0;
 */
                xchng = 0;
-               error("No write@since last change (:%s! overrides)", Command);
+               serror("No write@since last change (:%s! overrides)", Command);
        }
        return (0);
 }
        }
        return (0);
 }
@@ -366,8 +389,8 @@ setflav()
 
        if (inopen)
                return;
 
        if (inopen)
                return;
-       setnumb(nflag || value(NUMBER));
-       setlist(listf || value(LIST));
+       ignorf(setnumb(nflag || value(NUMBER)));
+       ignorf(setlist(listf || value(LIST)));
        setoutt();
 }
 
        setoutt();
 }
 
@@ -378,7 +401,7 @@ skipend()
 {
 
        pastwh();
 {
 
        pastwh();
-       return (endcmd(peekchar()));
+       return (endcmd(peekchar()) && peekchar() != '"');
 }
 
 /*
 }
 
 /*
@@ -425,7 +448,7 @@ tailprim(comm, i, notinvis)
        for (cp = tcommand; i > 0; i--)
                *cp++ = *comm++;
        while (*comm && peekchar() == *comm)
        for (cp = tcommand; i > 0; i--)
                *cp++ = *comm++;
        while (*comm && peekchar() == *comm)
-               *cp++ = getchar(), comm++;
+               *cp++ = ex_getchar(), comm++;
        c = peekchar();
        if (notinvis || isalpha(c)) {
                /*
        c = peekchar();
        if (notinvis || isalpha(c)) {
                /*
@@ -437,7 +460,7 @@ tailprim(comm, i, notinvis)
                if (tcommand[0] == 's' && any(c, "gcr"))
                        goto ret;
                while (cp < &tcommand[19] && isalpha(peekchar()))
                if (tcommand[0] == 's' && any(c, "gcr"))
                        goto ret;
                while (cp < &tcommand[19] && isalpha(peekchar()))
-                       *cp++ = getchar();
+                       *cp++ = ex_getchar();
                *cp = 0;
                if (notinvis)
                        serror("What?|%s: No such command from open/visual", tcommand);
                *cp = 0;
                if (notinvis)
                        serror("What?|%s: No such command from open/visual", tcommand);
@@ -449,7 +472,7 @@ ret:
 }
 
 /*
 }
 
 /*
- * Continue after a shell escape from open/visual.
+ * Continue after a : command from open/visual.
  */
 vcontin(ask)
        bool ask;
  */
 vcontin(ask)
        bool ask;
@@ -459,10 +482,24 @@ vcontin(ask)
                vcnt = -vcnt;
        if (inopen) {
                if (state != VISUAL) {
                vcnt = -vcnt;
        if (inopen) {
                if (state != VISUAL) {
-/*
-                       vtube[WECHO][0] = '*';
-                       vnfl();
-*/
+                       /*
+                        * We don't know what a shell command may have left on
+                        * the screen, so we move the cursor to the right place
+                        * and then put out a newline.  But this makes an extra
+                        * blank line most of the time so we only do it for :sh
+                        * since the prompt gets left on the screen.
+                        *
+                        * BUG: :!echo longer than current line \\c
+                        * will screw it up, but be reasonable!
+                        */
+                       if (state == CRTOPEN) {
+                               termreset();
+                               vgoto(WECHO, 0);
+                       }
+                       if (!ask) {
+                               putch('\r');
+                               putch('\n');
+                       }
                        return;
                }
                if (ask) {
                        return;
                }
                if (ask) {
@@ -473,17 +510,30 @@ vcontin(ask)
                vraw();
 #endif
                if (ask) {
                vraw();
 #endif
                if (ask) {
+#ifdef EATQS
                        /*
                         * Gobble ^Q/^S since the tty driver should be eating
                         * them (as far as the user can see)
                         */
                        /*
                         * Gobble ^Q/^S since the tty driver should be eating
                         * them (as far as the user can see)
                         */
-                       while (peekkey() == CTRL(Q) || peekkey() == CTRL(S))
+                       while (peekkey() == CTRL('Q') || peekkey() == CTRL('S'))
                                ignore(getkey());
                                ignore(getkey());
-                       if(getkey() == ':')
+#endif
+                       if(getkey() == ':') {
+                               /* Ugh. Extra newlines, but no other way */
+                               putch('\n');
+                               outline = WECHO;
                                ungetkey(':');
                                ungetkey(':');
+                       }
+               }
+               vclrech(1);
+               if (Peek_key != ':') {
+                       putpad(TI);
+                       tostart();
+                       /* replaced by ostart.
+                       putpad(VS);
+                       putpad(KS);
+                       */
                }
                }
-               putpad(VS);
-               putpad(KS);
        }
 }
 
        }
 }
 
@@ -501,8 +551,11 @@ vnfl()
                        vmoveitup(1, 0);
                vgoto(WECHO, 0);
                vclrbyte(vtube[WECHO], WCOLS);
                        vmoveitup(1, 0);
                vgoto(WECHO, 0);
                vclrbyte(vtube[WECHO], WCOLS);
+               tostop();
+               /* replaced by the ostop above
                putpad(VE);
                putpad(KE);
                putpad(VE);
                putpad(KE);
+               */
        }
        flush();
 }
        }
        flush();
 }