Bill added more buffers, and I put in sccs.
[unix-history] / usr / src / usr.bin / ex / ex_re.c
index 93abfaa..60415b3 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_re.c     4.2 %G%";
 #include "ex.h"
 #include "ex_re.h"
 
 #include "ex.h"
 #include "ex_re.h"
 
@@ -73,6 +74,7 @@ out:
        newline();
        *gp++ = c;
        *gp++ = 0;
        newline();
        *gp++ = c;
        *gp++ = 0;
+       saveall();
        inglobal = 2;
        for (a1 = one; a1 <= dol; a1++) {
                *a1 &= ~01;
        inglobal = 2;
        for (a1 = one; a1 <= dol; a1++) {
                *a1 &= ~01;
@@ -80,7 +82,6 @@ out:
                        *a1 |= 01;
        }
        /* should use gdelete from ed to avoid n**2 here on g/.../d */
                        *a1 |= 01;
        }
        /* should use gdelete from ed to avoid n**2 here on g/.../d */
-       saveall();
        if (inopen)
                inopen = -1;
        for (a1 = one; a1 <= dol; a1++) {
        if (inopen)
                inopen = -1;
        for (a1 = one; a1 <= dol; a1++) {
@@ -104,7 +105,7 @@ out:
        }
 }
 
        }
 }
 
-bool   xflag;
+bool   cflag;
 int    scount, slines, stotal;
 
 substitute(c)
 int    scount, slines, stotal;
 
 substitute(c)
@@ -115,7 +116,7 @@ substitute(c)
        int gsubf;
 
        gsubf = compsub(c);
        int gsubf;
 
        gsubf = compsub(c);
-       if (!inglobal)
+       if(FIXUNDO)
                save12(), undkind = UNDCHANGE;
        stotal = 0;
        slines = 0;
                save12(), undkind = UNDCHANGE;
        stotal = 0;
        slines = 0;
@@ -145,7 +146,7 @@ substitute(c)
                        addr2 += n;
                }
        }
                        addr2 += n;
                }
        }
-       if (stotal == 0 && !inglobal && !xflag)
+       if (stotal == 0 && !inglobal && !cflag)
                error("Fail|Substitute pattern match failed");
        snote(stotal, slines);
        return (stotal);
                error("Fail|Substitute pattern match failed");
        snote(stotal, slines);
        return (stotal);
@@ -157,7 +158,7 @@ compsub(ch)
        static int gsubf;
 
        if (!value(EDCOMPATIBLE))
        static int gsubf;
 
        if (!value(EDCOMPATIBLE))
-               gsubf = xflag = 0;
+               gsubf = cflag = 0;
        uselastre = 0;
        switch (ch) {
 
        uselastre = 0;
        switch (ch) {
 
@@ -174,7 +175,7 @@ compsub(ch)
                uselastre = 1;
                comprhs(seof);
                gsubf = 0;
                uselastre = 1;
                comprhs(seof);
                gsubf = 0;
-               xflag = 0;
+               cflag = 0;
                break;
 
        case '~':
                break;
 
        case '~':
@@ -184,6 +185,8 @@ compsub(ch)
        redo:
                if (re.Expbuf[0] == 0)
                        error("No previous re|No previous regular expression");
        redo:
                if (re.Expbuf[0] == 0)
                        error("No previous re|No previous regular expression");
+               if (subre.Expbuf[0] == 0)
+                       error("No previous substitute re|No previous substitute to repeat");
                break;
        }
        for (;;) {
                break;
        }
        for (;;) {
@@ -195,7 +198,7 @@ compsub(ch)
                        continue;
 
                case 'c':
                        continue;
 
                case 'c':
-                       xflag = !xflag;
+                       cflag = !cflag;
                        continue;
 
                case 'r':
                        continue;
 
                case 'r':
@@ -257,8 +260,10 @@ magic:
 
                case '\n':
                case EOF:
 
                case '\n':
                case EOF:
-                       ungetchar(c);
-                       goto endrhs;
+                       if (!(globp && globp[0])) {
+                               ungetchar(c);
+                               goto endrhs;
+                       }
 
                case '~':
                case '&':
 
                case '~':
                case '&':
@@ -305,7 +310,7 @@ confirmed(a)
 {
        register int c, ch;
 
 {
        register int c, ch;
 
-       if (xflag == 0)
+       if (cflag == 0)
                return (1);
        pofix();
        pline(lineno(a));
                return (1);
        pofix();
        pline(lineno(a));
@@ -520,7 +525,7 @@ complex:
                if (c == eof || c == EOF) {
                        if (bracketp != bracket)
 cerror("Unmatched \\(|More \\('s than \\)'s in regular expression");
                if (c == eof || c == EOF) {
                        if (bracketp != bracket)
 cerror("Unmatched \\(|More \\('s than \\)'s in regular expression");
-                       *ep++ = CEOF;
+                       *ep++ = CEOFC;
                        if (c == EOF)
                                ungetchar(c);
                        return (eof);
                        if (c == EOF)
                                ungetchar(c);
                        return (eof);
@@ -645,7 +650,7 @@ cerror("Bad \\n|\\n in regular expression with n greater than the number of \\('
                case '\n':
                        if (oknl) {
                                ungetchar(c);
                case '\n':
                        if (oknl) {
                                ungetchar(c);
-                               *ep++ = CEOF;
+                               *ep++ = CEOFC;
                                return (eof);
                        }
 cerror("Badly formed re|Missing closing delimiter for regular expression");
                                return (eof);
                        }
 cerror("Badly formed re|Missing closing delimiter for regular expression");
@@ -699,10 +704,6 @@ execute(gf, addr)
        if (gf) {
                if (circfl)
                        return (0);
        if (gf) {
                if (circfl)
                        return (0);
-#ifdef notdef
-               if (loc1 == loc2)
-                       loc2++;
-#endif
                locs = p1 = loc2;
        } else {
                if (addr == zero)
                locs = p1 = loc2;
        } else {
                if (addr == zero)
@@ -781,7 +782,7 @@ advance(lp, ep)
                        continue;
                return (0);
 
                        continue;
                return (0);
 
-       case CEOF:
+       case CEOFC:
                loc2 = lp;
                return (1);
 
                loc2 = lp;
                return (1);