summaryrefslogtreecommitdiff
path: root/usr.bin/printf/printf.c
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-06-19 09:24:30 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-06-19 09:24:30 +0000
commit98dd638658653826222a40d8e1ca59347e8539ea (patch)
treede8ae064b14b7b99505d75daafbc0e78f98208aa /usr.bin/printf/printf.c
parentc4bacc1871e0285b69a2bee531ad2f81c74b8e74 (diff)
Notes
Diffstat (limited to 'usr.bin/printf/printf.c')
-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 ad38200bb07b..288792137fc0 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);