From 5a83e2bbe2ff16067c71aecf3dfdd9fabb639af7 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Tue, 7 Sep 1999 09:50:06 +0000 Subject: zsh-users/2578 --- Src/subst.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'Src/subst.c') diff --git a/Src/subst.c b/Src/subst.c index 91a368d72..b808cb233 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1142,27 +1142,28 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) case PM_RIGHT_B: case PM_RIGHT_Z: case PM_RIGHT_Z | PM_RIGHT_B: - if (strlen(val) < fwidth) { - t = NULL; - if (v->pm->flags & PM_RIGHT_Z) { - for (t = val; iblank(*t); t++); - if (t && idigit(*t)) - val = t, t = NULL; - } - if (!t) { + { + int zero = 1; + + if (strlen(val) < fwidth) { + if (v->pm->flags & PM_RIGHT_Z) { + for (t = val; iblank(*t); t++); + if (!*t || !idigit(*t)) + zero = 0; + } t = (char *)ncalloc(fwidth + 1); - memset(t, (v->pm->flags & PM_RIGHT_B) ? ' ' : '0', - fwidth); + memset(t, (((v->pm->flags & PM_RIGHT_B) || !zero) ? + ' ' : '0'), fwidth); if ((t0 = strlen(val)) > fwidth) t0 = fwidth; strcpy(t + (fwidth - t0), val); val = t; + } else { + t = (char *)ncalloc(fwidth + 1); + t[fwidth] = '\0'; + strncpy(t, val + strlen(val) - fwidth, fwidth); + val = t; } - } else { - t = (char *)ncalloc(fwidth + 1); - t[fwidth] = '\0'; - strncpy(t, val + strlen(val) - fwidth, fwidth); - val = t; } break; } -- cgit 1.4.1