diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/subst.c | 31 |
1 files changed, 16 insertions, 15 deletions
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; } |