preliminary release 3.6 10/18/80
[unix-history] / usr / src / usr.bin / ex / ex_vops2.c
index a83a65f..575b5a9 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 1980 Regents of the University of California */
 /* Copyright (c) 1980 Regents of the University of California */
-static char *sccsid = "@(#)ex_vops2.c  5.1 %G%";
+static char *sccsid = "@(#)ex_vops2.c  6.1 %G%";
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -110,7 +110,7 @@ vappend(ch, cnt, indent)
        register int i;
        register char *gcursor;
        bool escape;
        register int i;
        register char *gcursor;
        bool escape;
-       int repcnt;
+       int repcnt, savedoomed;
        short oldhold = hold;
 
        /*
        short oldhold = hold;
 
        /*
@@ -212,7 +212,7 @@ vappend(ch, cnt, indent)
                if (ch == 'r' && repcnt == 0)
                        escape = 0;
                else {
                if (ch == 'r' && repcnt == 0)
                        escape = 0;
                else {
-                       gcursor = vgetline(repcnt, gcursor, &escape);
+                       gcursor = vgetline(repcnt, gcursor, &escape, ch);
 
                        /*
                         * After an append, stick information
 
                        /*
                         * After an append, stick information
@@ -277,6 +277,7 @@ vappend(ch, cnt, indent)
                 */
                if (state != HARDOPEN) {
                        DEPTH(vcline) = 0;
                 */
                if (state != HARDOPEN) {
                        DEPTH(vcline) = 0;
+                       savedoomed = doomed;
                        if (doomed > 0) {
                                register int cind = cindent();
 
                        if (doomed > 0) {
                                register int cind = cindent();
 
@@ -284,6 +285,7 @@ vappend(ch, cnt, indent)
                                doomed = 0;
                        }
                        i = vreopen(LINE(vcline), lineDOT(), vcline);
                                doomed = 0;
                        }
                        i = vreopen(LINE(vcline), lineDOT(), vcline);
+                       doomed = savedoomed;
                }
 
                /*
                }
 
                /*
@@ -396,17 +398,19 @@ back1()
  * are careful about the way we do this so that it is
  * repeatable.  (I.e. so that your kill doesn't happen,
  * when you repeat an insert if it was escaped with \ the
  * are careful about the way we do this so that it is
  * repeatable.  (I.e. so that your kill doesn't happen,
  * when you repeat an insert if it was escaped with \ the
- * first time you did it.
+ * first time you did it.  commch is the command character
+ * involved, including the prompt for readline.
  */
 char *
  */
 char *
-vgetline(cnt, gcursor, aescaped)
+vgetline(cnt, gcursor, aescaped, commch)
        int cnt;
        register char *gcursor;
        bool *aescaped;
        int cnt;
        register char *gcursor;
        bool *aescaped;
+       char commch;
 {
        register int c, ch;
        register char *cp;
 {
        register int c, ch;
        register char *cp;
-       int x, y, iwhite;
+       int x, y, iwhite, backsl=0;
        char *iglobp;
        char cstr[2];
        int (*OO)() = Outchar;
        char *iglobp;
        char cstr[2];
        int (*OO)() = Outchar;
@@ -437,6 +441,7 @@ vgetline(cnt, gcursor, aescaped)
                vprepins();
        }
        for (;;) {
                vprepins();
        }
        for (;;) {
+               backsl = 0;
                if (gobblebl)
                        gobblebl--;
                if (cnt != 0) {
                if (gobblebl)
                        gobblebl--;
                if (cnt != 0) {
@@ -449,7 +454,7 @@ vgetline(cnt, gcursor, aescaped)
                        c &= (QUOTE|TRIM);
                ch = c;
                maphopcnt = 0;
                        c &= (QUOTE|TRIM);
                ch = c;
                maphopcnt = 0;
-               if (vglobp == 0 && Peekkey == 0)
+               if (vglobp == 0 && Peekkey == 0 && commch != 'r')
                        while ((ch = map(c, immacs)) != c) {
                                c = ch;
                                if (!value(REMAP))
                        while ((ch = map(c, immacs)) != c) {
                                c = ch;
                                if (!value(REMAP))
@@ -560,18 +565,20 @@ vbackup:
                                vcsync();
                                c = getkey();
 #ifndef USG3TTY
                                vcsync();
                                c = getkey();
 #ifndef USG3TTY
-                               if (c == tty.sg_erase || c == tty.sg_kill) {
+                               if (c == tty.sg_erase || c == tty.sg_kill)
 #else
                                if (c == tty.c_cc[VERASE]
 #else
                                if (c == tty.c_cc[VERASE]
-                                   || c == tty.c_cc[VKILL]) {
+                                   || c == tty.c_cc[VKILL])
 #endif
 #endif
+                               {
                                        vgoto(y, x);
                                        if (doomed >= 0)
                                                doomed++;
                                        goto def;
                                }
                                ungetkey(c), c = '\\';
                                        vgoto(y, x);
                                        if (doomed >= 0)
                                                doomed++;
                                        goto def;
                                }
                                ungetkey(c), c = '\\';
-                               goto noput;
+                               backsl = 1;
+                               break;
 
                        /*
                         * ^Q           Super quote following character
 
                        /*
                         * ^Q           Super quote following character
@@ -609,21 +616,25 @@ vbackup:
                                gobbled = 1;
                                continue;
                        }
                                gobbled = 1;
                                continue;
                        }
-                       if (/* c <= ' ' && */ value(WRAPMARGIN) &&
-                               outcol >= OCOLUMNS - value(WRAPMARGIN)) {
+                       if (value(WRAPMARGIN) &&
+                               (outcol >= OCOLUMNS - value(WRAPMARGIN) ||
+                                backsl && outcol==0) &&
+                               commch != 'r') {
                                /*
                                 * At end of word and hit wrapmargin.
                                 * Move the word to next line and keep going.
                                 */
                                wdkind = 1;
                                *gcursor++ = c;
                                /*
                                 * At end of word and hit wrapmargin.
                                 * Move the word to next line and keep going.
                                 */
                                wdkind = 1;
                                *gcursor++ = c;
+                               if (backsl)
+                                       *gcursor++ = getkey();
                                *gcursor = 0;
                                /*
                                 * Find end of previous word if we are past it.
                                 */
                                for (cp=gcursor; cp>ogcursor && isspace(cp[-1]); cp--)
                                        ;
                                *gcursor = 0;
                                /*
                                 * Find end of previous word if we are past it.
                                 */
                                for (cp=gcursor; cp>ogcursor && isspace(cp[-1]); cp--)
                                        ;
-                               if (outcol - (gcursor-cp) >= OCOLUMNS - value(WRAPMARGIN)) {
+                               if (outcol+(backsl?OCOLUMNS:0) - (gcursor-cp) >= OCOLUMNS - value(WRAPMARGIN)) {
                                        /*
                                         * Find beginning of previous word.
                                         */
                                        /*
                                         * Find beginning of previous word.
                                         */
@@ -790,9 +801,10 @@ vbackup:
                                continue;
                        }
 def:
                                continue;
                        }
 def:
-                       putchar(c);
-                       flush();
-noput:
+                       if (!backsl) {
+                               putchar(c);
+                               flush();
+                       }
                        if (gcursor > &genbuf[LBSIZE - 2])
                                error("Line too long");
                        *gcursor++ = c & TRIM;
                        if (gcursor > &genbuf[LBSIZE - 2])
                                error("Line too long");
                        *gcursor++ = c & TRIM;