Introduction
Introduction Statistics Contact Development Disclaimer Help
printf: allow flags for the %s format string aswell - sbase - suckless unix too…
git clone git://git.suckless.org/sbase
Log
Files
Refs
README
LICENSE
---
commit 1cc5a57fd7f0c72d9e4c383cfb5c7decf39fa346
parent 61be841f5cc4019890c769cec33744616614ea10
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 25 Jul 2021 14:24:41 +0200
printf: allow flags for the %s format string aswell
This is useful for example to left-align strings and pad them with spaces.
printf '%-12.12s: %s\n' 'user' "$USER"
Diffstat:
M printf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/printf.c b/printf.c
@@ -127,7 +127,11 @@ main(int argc, char *argv[])
free(rarg);
break;
case 's':
- printf("%*.*s", width, precision, arg);
+ fmt = estrdup(flag ? "%#*.*s" : "%*.*s");
+ if (flag)
+ fmt[1] = flag;
+ printf(fmt, width, precision, arg);
+ free(fmt);
break;
case 'd': case 'i': case 'o': case 'u': case 'x': case 'X':
for (j = 0; isspace(arg[j]); j++);
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.