support for multiple : modifiers
authorChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Tue, 23 Jul 1991 02:47:12 +0000 (18:47 -0800)
committerChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Tue, 23 Jul 1991 02:47:12 +0000 (18:47 -0800)
SCCS-vsn: bin/csh/dol.c 5.15

usr/src/bin/csh/dol.c

index 7a4fb91..3094002 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)dol.c      5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)dol.c      5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -48,10 +48,13 @@ static Char *Dcp, **Dvp;    /* Input vector for Dreadc */
  * words within this expansion, the count of remaining words, and the
  * information about any : modifier which is being applied.
  */
  * words within this expansion, the count of remaining words, and the
  * information about any : modifier which is being applied.
  */
+#define MAXWLEN (BUFSIZ - 4)
+#define MAXMOD MAXWLEN         /* This cannot overflow */
 static Char *dolp;             /* Remaining chars from this word */
 static Char **dolnxt;          /* Further words */
 static int dolcnt;             /* Count of further words */
 static Char *dolp;             /* Remaining chars from this word */
 static Char **dolnxt;          /* Further words */
 static int dolcnt;             /* Count of further words */
-static Char dolmod;            /* : modifier character */
+static Char dolmod[MAXMOD];    /* : modifier character */
+static int dolnmod;            /* Number of modifiers */
 static int dolmcnt;            /* :gx -> 10000, else 1 */
 
 static void     Dfix2 __P((Char **));
 static int dolmcnt;            /* :gx -> 10000, else 1 */
 
 static void     Dfix2 __P((Char **));
@@ -134,7 +137,6 @@ Dfix2(v)
        continue;
 }
 
        continue;
 }
 
-#define MAXWLEN (BUFSIZ - 4)
 /*
  * Pack up more characters in this word
  */
 /*
  * Pack up more characters in this word
  */
@@ -373,7 +375,7 @@ Dgetdol()
     char    tnp;
     Char    wbuf[BUFSIZ];
 
     char    tnp;
     Char    wbuf[BUFSIZ];
 
-    dolmod = dolmcnt = 0;
+    dolnmod = dolmcnt = 0;
     c = sc = DgetC(0);
     if (c == '{')
        c = DgetC(0);           /* sc is { to take } later */
     c = sc = DgetC(0);
     if (c == '{')
        c = DgetC(0);           /* sc is { to take } later */
@@ -409,7 +411,7 @@ Dgetdol()
         * it. The actual function of the 'q' causes filename expansion not to
         * be done on the interpolated value.
         */
         * it. The actual function of the 'q' causes filename expansion not to
         * be done on the interpolated value.
         */
-       dolmod = 'q';
+       dolmod[dolnmod++] = 'q';
        dolmcnt = 10000;
        setDolp(wbuf);
        goto eatbrac;
        dolmcnt = 10000;
        setDolp(wbuf);
        goto eatbrac;
@@ -587,14 +589,18 @@ fixDolMod()
 
     c = DgetC(0);
     if (c == ':') {
 
     c = DgetC(0);
     if (c == ':') {
-       c = DgetC(0), dolmcnt = 1;
-       if (c == 'g')
-           c = DgetC(0), dolmcnt = 10000;
-       if (!any("htrqxe", c))
-           stderror(ERR_BADMOD, c);
-       dolmod = c;
-       if (c == 'q')
-           dolmcnt = 10000;
+       do {
+           c = DgetC(0), dolmcnt = 1;
+           if (c == 'g')
+               c = DgetC(0), dolmcnt = 10000;
+           if (!any("htrqxe", c))
+               stderror(ERR_BADMOD, c);
+           dolmod[dolnmod++] = c;
+           if (c == 'q')
+               dolmcnt = 10000;
+       }
+       while ((c = DgetC(0)) == ':');
+       unDredc(c);
     }
     else
        unDredc(c);
     }
     else
        unDredc(c);
@@ -605,19 +611,28 @@ setDolp(cp)
     register Char *cp;
 {
     register Char *dp;
     register Char *cp;
 {
     register Char *dp;
+    int i;
 
 
-    if (dolmod == 0 || dolmcnt == 0) {
+    if (dolnmod == 0 || dolmcnt == 0) {
        dolp = cp;
        return;
     }
        dolp = cp;
        return;
     }
-    dp = domod(cp, dolmod);
+    dp = cp = Strsave(cp);
+    for (i = 0; i < dolnmod; i++)
+       if ((dp = domod(cp, dolmod[i]))) {
+           xfree((ptr_t) cp);
+           cp = dp;
+           dolmcnt--;
+       }
+       else {
+           dp = cp;
+           break;
+       }
+
     if (dp) {
     if (dp) {
-       dolmcnt--;
        addla(dp);
        xfree((ptr_t) dp);
     }
        addla(dp);
        xfree((ptr_t) dp);
     }
-    else
-       addla(cp);
     dolp = STRNULL;
     if (seterr)
        stderror(ERR_OLD);
     dolp = STRNULL;
     if (seterr)
        stderror(ERR_OLD);