From 154d5a606dccb3af0d18c82e3d3fedc8a7178eb2 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Mon, 22 Jul 1991 18:47:12 -0800 Subject: [PATCH] support for multiple : modifiers SCCS-vsn: bin/csh/dol.c 5.15 --- usr/src/bin/csh/dol.c | 51 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/usr/src/bin/csh/dol.c b/usr/src/bin/csh/dol.c index 7a4fb91d0f..3094002ee4 100644 --- a/usr/src/bin/csh/dol.c +++ b/usr/src/bin/csh/dol.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)dol.c 5.14 (Berkeley) %G%"; +static char sccsid[] = "@(#)dol.c 5.15 (Berkeley) %G%"; #endif /* not lint */ #include @@ -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. */ +#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 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 **)); @@ -134,7 +137,6 @@ Dfix2(v) continue; } -#define MAXWLEN (BUFSIZ - 4) /* * Pack up more characters in this word */ @@ -373,7 +375,7 @@ Dgetdol() 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 */ @@ -409,7 +411,7 @@ Dgetdol() * 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; @@ -587,14 +589,18 @@ fixDolMod() 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); @@ -605,19 +611,28 @@ setDolp(cp) register Char *cp; { register Char *dp; + int i; - if (dolmod == 0 || dolmcnt == 0) { + if (dolnmod == 0 || dolmcnt == 0) { 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) { - dolmcnt--; addla(dp); xfree((ptr_t) dp); } - else - addla(cp); dolp = STRNULL; if (seterr) stderror(ERR_OLD); -- 2.20.1