BSD 4 release
[unix-history] / usr / src / cmd / ex / ex_cmds2.c
index 95deb53..86dbca8 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_cmds2.c  6.1 10/18/80";
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
@@ -39,6 +40,7 @@ endcmd(ch)
                return (1);
        
        case '|':
                return (1);
        
        case '|':
+       case '"':
                endline = 0;
                return (1);
        }
                endline = 0;
                return (1);
        }
@@ -72,6 +74,10 @@ error(str, i)
 
        error0();
        merror(str, i);
 
        error0();
        merror(str, i);
+       if (writing) {
+               serror(" [Warning - %s is incomplete]", file);
+               writing = 0;
+       }
        error1(str);
 }
 
        error1(str);
 }
 
@@ -102,6 +108,13 @@ erewind()
 error0()
 {
 
 error0()
 {
 
+       if (laste) {
+#ifdef VMUNIX
+               tlaste();
+#endif
+               laste = 0;
+               sync();
+       }
        if (vcatch) {
                if (splitw == 0)
                        fixech();
        if (vcatch) {
                if (splitw == 0)
                        fixech();
@@ -118,10 +131,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 +141,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,11 +169,13 @@ 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);
        }
                fixol();
                longjmp(vreslab,1);
        }
@@ -173,8 +186,6 @@ error1(str)
        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 +239,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);
@@ -277,6 +290,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);
@@ -378,7 +396,7 @@ skipend()
 {
 
        pastwh();
 {
 
        pastwh();
-       return (endcmd(peekchar()));
+       return (endcmd(peekchar()) && peekchar() != '"');
 }
 
 /*
 }
 
 /*
@@ -449,7 +467,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 +477,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 +505,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)
                         */
                        while (peekkey() == CTRL(Q) || peekkey() == CTRL(S))
                                ignore(getkey());
                        /*
                         * 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))
                                ignore(getkey());
-                       if(getkey() == ':')
+#endif
+                       if(getkey() == ':') {
+                               /* Ugh. Extra newlines, but no other way */
+                               putch('\n');
+                               outline = WECHO;
                                ungetkey(':');
                                ungetkey(':');
+                       }
+               }
+               vclrech(1);
+               if (Peekkey != ':') {
+                       putpad(TI);
+                       tostart();
+                       /* replaced by ostart.
+                       putpad(VS);
+                       putpad(KS);
+                       */
                }
                }
-               putpad(VS);
-               putpad(KS);
        }
 }
 
        }
 }
 
@@ -501,8 +546,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();
 }