summaryrefslogtreecommitdiffstats
path: root/usr.bin/printf
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-19 09:24:30 +0000
committertjr <tjr@FreeBSD.org>2002-06-19 09:24:30 +0000
commit80af7bc382685a69865e5f3cf600e8f8efb39dd1 (patch)
treede8ae064b14b7b99505d75daafbc0e78f98208aa /usr.bin/printf
parent1f4e9c0c72c46d8157e0c5cca3ab6dc9b1faeb96 (diff)
downloadFreeBSD-src-80af7bc382685a69865e5f3cf600e8f8efb39dd1.zip
FreeBSD-src-80af7bc382685a69865e5f3cf600e8f8efb39dd1.tar.gz
Let printf(1) tell the difference between zero width/precision and
unspecified width/precision. PR: 39116 Submitted by: Egil Brendsdal <egilb@ife.no> MFC after: 1 week
Diffstat (limited to 'usr.bin/printf')
-rw-r--r--usr.bin/printf/printf.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c
index ad38200..2887921 100644
--- a/usr.bin/printf/printf.c
+++ b/usr.bin/printf/printf.c
@@ -73,12 +73,12 @@ static const char rcsid[] =
#define PF(f, func) do { \
char *b = NULL; \
- if (fieldwidth) \
- if (precision) \
+ if (havewidth) \
+ if (haveprec) \
(void)asprintf(&b, f, fieldwidth, precision, func); \
else \
(void)asprintf(&b, f, fieldwidth, func); \
- else if (precision) \
+ else if (haveprec) \
(void)asprintf(&b, f, precision, func); \
else \
(void)asprintf(&b, f, func); \
@@ -111,7 +111,7 @@ main(argc, argv)
char *argv[];
{
static const char *skip1, *skip2;
- int ch, chopped, end, fieldwidth, precision, rval;
+ int ch, chopped, end, fieldwidth, haveprec, havewidth, precision, rval;
char convch, nextch, *format, *fmt, *start;
#ifndef BUILTIN
@@ -184,9 +184,10 @@ next: for (start = fmt;; ++fmt) {
if (*fmt == '*') {
if (getint(&fieldwidth))
return (1);
+ havewidth = 1;
++fmt;
} else {
- fieldwidth = 0;
+ havewidth = 0;
/* skip to possible '.', get following precision */
for (; strchr(skip2, *fmt); ++fmt);
@@ -197,15 +198,16 @@ next: for (start = fmt;; ++fmt) {
if (*fmt == '*') {
if (getint(&precision))
return (1);
+ haveprec = 1;
++fmt;
} else {
- precision = 0;
+ haveprec = 0;
/* skip to conversion char */
for (; strchr(skip2, *fmt); ++fmt);
}
} else
- precision = 0;
+ haveprec = 0;
if (!*fmt) {
warnx1("missing format character", NULL, NULL);
return (1);
OpenPOWER on IntegriCloud