about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-12-07 16:25:53 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-12-07 16:25:53 +0000
commit36b2667e6f7734597f987ee1e6189a6f93200b03 (patch)
tree297fa2c325286a096767e04fccfcf9b4e2506e67 /Src
parent18e6f5f1ee7f58a5416c4a0341bc79827dfd3a8f (diff)
downloadzsh-36b2667e6f7734597f987ee1e6189a6f93200b03.tar.gz
zsh-36b2667e6f7734597f987ee1e6189a6f93200b03.tar.xz
zsh-36b2667e6f7734597f987ee1e6189a6f93200b03.zip
zsh-workers/8932
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/computil.c45
-rw-r--r--Src/Zle/zle_tricky.c2
2 files changed, 46 insertions, 1 deletions
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index c43fdfd0c..ae7dba5a8 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -2810,6 +2810,50 @@ bin_comptry(char *nam, char **args, char *ops, int func)
     return 0;
 }
 
+static char *
+fmtstr(char *str, char c, char *repl)
+{
+    int len, num, rlen;
+    char *s, *ret, *rp;
+
+    len = strlen(str);
+    rlen = strlen(repl);
+
+    for (num = 0, s = str; *s; s++)
+	if (*s == '%' && s[1] == c)
+	    num++, s++;
+
+    ret = (char *) zhalloc((num * (rlen - 2)) + len + 1);
+
+    for (s = str, rp = ret; *s; s++) {
+	if (*s == '%' && s[1] == c) {
+	    strcpy(rp, repl);
+	    rp += rlen;
+	    s++;
+	} else
+	    *rp++ = *s;
+    }
+    *rp = '\0';
+
+    return ret;
+}
+
+static int
+bin_compfmt(char *nam, char **args, char *ops, int func)
+{
+    char *param = args[0], *str = args[1];
+
+    for (args += 2; *args; args++) {
+	if (args[0][1] != ':') {
+	    zerrnam(nam, "invalid argument `%s'", args[0], 0);
+	    return 1;
+	}
+	str = fmtstr(str, **args, *args + 2);
+    }
+    setsparam(param, ztrdup(str));
+    return 0;
+}
+
 static struct builtin bintab[] = {
     BUILTIN("compdisplay", 0, bin_compdisplay, 2, -1, 0, NULL, NULL),
     BUILTIN("compdescribe", 0, bin_compdescribe, 3, -1, 0, NULL, NULL),
@@ -2819,6 +2863,7 @@ static struct builtin bintab[] = {
     BUILTIN("compstyles", 0, bin_compstyles, 1, -1, 0, NULL, NULL),
     BUILTIN("comptags", 0, bin_comptags, 1, -1, 0, NULL, NULL),
     BUILTIN("comptry", 0, bin_comptry, 0, -1, 0, NULL, NULL),
+    BUILTIN("compfmt", 0, bin_compfmt, 2, -1, 0, NULL, NULL),
 };
 
 
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 6c8e6fd0a..264b2f06d 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -1815,7 +1815,7 @@ printfmt(char *fmt, int n, int dopr, int doesc)
 			tcout(TCUNDERLINEEND);
 		    break;
 		case '{':
-		    for (p++; *p && (*p != '%' || p[1] != '}'); p++, cc++)
+		    for (p++; *p && (*p != '%' || p[1] != '}'); p++)
 			if (dopr)
 			    putc(*p, shout);
 		    if (*p)