reset fieldwidth/precision for each new format
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 24 Feb 1989 08:51:48 +0000 (00:51 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 24 Feb 1989 08:51:48 +0000 (00:51 -0800)
SCCS-vsn: usr.bin/printf/printf.c 5.5

usr/src/usr.bin/printf/printf.c

index cec7c51..3e0d504 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)printf.c   5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)printf.c   5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -97,14 +97,14 @@ next:               for (start = fmt;; ++fmt) {
 
                /* skip to field width */
                for (; index(skip1, *fmt); ++fmt);
 
                /* skip to field width */
                for (; index(skip1, *fmt); ++fmt);
-               if (*fmt == '*')
-                       fieldwidth = getint();
-               /* skip to possible '.' */
+               fieldwidth = *fmt == '*' ? getint() : 0;
+
+               /* skip to possible '.', get following precision */
                for (; index(skip2, *fmt); ++fmt);
                if (*fmt == '.')
                        ++fmt;
                for (; index(skip2, *fmt); ++fmt);
                if (*fmt == '.')
                        ++fmt;
-               if (*fmt == '*')
-                       precision = getint();
+               precision = *fmt == '*' ? getint() : 0;
+
                /* skip to conversion char */
                for (; index(skip2, *fmt); ++fmt);
                if (!*fmt) {
                /* skip to conversion char */
                for (; index(skip2, *fmt); ++fmt);
                if (!*fmt) {