Deleted Added
full compact
vfprintf.c (113146) vfprintf.c (113191)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 24 unchanged lines hidden (view full) ---

33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
39#endif /* LIBC_SCCS and not lint */
40#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 24 unchanged lines hidden (view full) ---

33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
39#endif /* LIBC_SCCS and not lint */
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 113146 2003-04-05 22:11:42Z das $");
41__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 113191 2003-04-07 00:42:19Z das $");
42
43/*
44 * Actual printf innards.
45 *
46 * This code is large and complicated...
47 */
48
49#include "namespace.h"

--- 502 unchanged lines hidden (view full) ---

552 if ((n = (howmany)) > 0) { \
553 while (n > PADSIZE) { \
554 PRINT(with, PADSIZE); \
555 n -= PADSIZE; \
556 } \
557 PRINT(with, n); \
558 } \
559}
42
43/*
44 * Actual printf innards.
45 *
46 * This code is large and complicated...
47 */
48
49#include "namespace.h"

--- 502 unchanged lines hidden (view full) ---

552 if ((n = (howmany)) > 0) { \
553 while (n > PADSIZE) { \
554 PRINT(with, PADSIZE); \
555 n -= PADSIZE; \
556 } \
557 PRINT(with, n); \
558 } \
559}
560#define PRINTANDPAD(p, ep, len, with) do { \
561 n2 = (ep) - (p); \
562 if (n2 > (len)) \
563 n2 = (len); \
564 if (n2 > 0) \
565 PRINT((p), n2); \
566 PAD((len) - (n2 > 0 ? n2 : 0), (with)); \
567} while(0)
560#define FLUSH() { \
561 if (uio.uio_resid && __sprint(fp, &uio)) \
562 goto error; \
563 uio.uio_iovcnt = 0; \
564 iovp = iov; \
565}
566
567 /*

--- 141 unchanged lines hidden (view full) ---

709 goto rflag;
710 case '\'':
711 flags |= GROUPING;
712 thousands_sep = *(localeconv()->thousands_sep);
713 grouping = localeconv()->grouping;
714 goto rflag;
715 case '.':
716 if ((ch = *fmt++) == '*') {
568#define FLUSH() { \
569 if (uio.uio_resid && __sprint(fp, &uio)) \
570 goto error; \
571 uio.uio_iovcnt = 0; \
572 iovp = iov; \
573}
574
575 /*

--- 141 unchanged lines hidden (view full) ---

717 goto rflag;
718 case '\'':
719 flags |= GROUPING;
720 thousands_sep = *(localeconv()->thousands_sep);
721 grouping = localeconv()->grouping;
722 goto rflag;
723 case '.':
724 if ((ch = *fmt++) == '*') {
717 GETASTER (n);
718 prec = n < 0 ? -1 : n;
725 GETASTER (prec);
719 goto rflag;
720 }
726 goto rflag;
727 }
721 n = 0;
728 prec = 0;
722 while (is_digit(ch)) {
729 while (is_digit(ch)) {
723 n = 10 * n + to_digit(ch);
730 prec = 10 * prec + to_digit(ch);
724 ch = *fmt++;
725 }
731 ch = *fmt++;
732 }
726 prec = n < 0 ? -1 : n;
727 goto reswitch;
728 case '0':
729 /*-
730 * ``Note that 0 is taken as a flag, not as the
731 * beginning of a field width.''
732 * -- ANSI X3J11
733 */
734 flags |= ZEROPAD;

--- 177 unchanged lines hidden (view full) ---

912 prec = ndig - expt;
913 if (prec < 0)
914 prec = 0;
915 }
916 }
917 if (expchar) {
918 expsize = exponent(expstr, expt - 1, expchar);
919 size = expsize + prec;
733 goto reswitch;
734 case '0':
735 /*-
736 * ``Note that 0 is taken as a flag, not as the
737 * beginning of a field width.''
738 * -- ANSI X3J11
739 */
740 flags |= ZEROPAD;

--- 177 unchanged lines hidden (view full) ---

918 prec = ndig - expt;
919 if (prec < 0)
920 prec = 0;
921 }
922 }
923 if (expchar) {
924 expsize = exponent(expstr, expt - 1, expchar);
925 size = expsize + prec;
920 if (prec || flags & ALT)
926 if (prec > 1 || flags & ALT)
921 ++size;
922 } else {
923 if (expt > 0) {
924 size = expt;
925 if (prec || flags & ALT)
926 size += prec + 1;
927 } else /* "0.X" */
928 size = prec + 2;

--- 8 unchanged lines hidden (view full) ---

937 if (*(grouping+1)) {
938 nseps++;
939 grouping++;
940 } else
941 nrepeats++;
942 }
943 size += nseps + nrepeats;
944 } else
927 ++size;
928 } else {
929 if (expt > 0) {
930 size = expt;
931 if (prec || flags & ALT)
932 size += prec + 1;
933 } else /* "0.X" */
934 size = prec + 2;

--- 8 unchanged lines hidden (view full) ---

943 if (*(grouping+1)) {
944 nseps++;
945 grouping++;
946 } else
947 nrepeats++;
948 }
949 size += nseps + nrepeats;
950 } else
945 lead = (expt < ndig) ? expt : ndig;
951 lead = expt /*(expt < ndig) ? expt : ndig*/;
946 }
947 break;
948#endif /* FLOATING_POINT */
949 case 'n':
950 /*
951 * Assignment-like behavior is specified if the
952 * value overflows or is otherwise unrepresentable.
953 * C99 says to use `signed char' for %hhn conversions.

--- 200 unchanged lines hidden (view full) ---

1154 PRINT(cp, size);
1155 } else { /* glue together f_p fragments */
1156 if (!expchar) { /* %[fF] or sufficiently short %[gG] */
1157 if (expt <= 0) {
1158 buf[0] = '0';
1159 buf[1] = *decimal_point;
1160 PRINT(buf, 2);
1161 PAD(-expt, zeroes);
952 }
953 break;
954#endif /* FLOATING_POINT */
955 case 'n':
956 /*
957 * Assignment-like behavior is specified if the
958 * value overflows or is otherwise unrepresentable.
959 * C99 says to use `signed char' for %hhn conversions.

--- 200 unchanged lines hidden (view full) ---

1160 PRINT(cp, size);
1161 } else { /* glue together f_p fragments */
1162 if (!expchar) { /* %[fF] or sufficiently short %[gG] */
1163 if (expt <= 0) {
1164 buf[0] = '0';
1165 buf[1] = *decimal_point;
1166 PRINT(buf, 2);
1167 PAD(-expt, zeroes);
1162 if (ndig > 0)
1163 PRINT(cp, ndig);
1168 /* already handled initial 0's */
1169 prec += expt;
1164 } else {
1170 } else {
1165 PRINT(cp, lead);
1171 PRINTANDPAD(cp, dtoaend, lead, zeroes);
1166 cp += lead;
1167 if (grouping) {
1168 while (nseps>0 || nrepeats>0) {
1169 if (nrepeats > 0)
1170 nrepeats--;
1171 else {
1172 grouping--;
1173 nseps--;
1174 }
1175 PRINT(&thousands_sep,
1176 1);
1172 cp += lead;
1173 if (grouping) {
1174 while (nseps>0 || nrepeats>0) {
1175 if (nrepeats > 0)
1176 nrepeats--;
1177 else {
1178 grouping--;
1179 nseps--;
1180 }
1181 PRINT(&thousands_sep,
1182 1);
1177 PRINT(cp, *grouping);
1183 PRINTANDPAD(cp,dtoaend,
1184 *grouping, zeroes);
1178 cp += *grouping;
1179 }
1185 cp += *grouping;
1186 }
1180 } else {
1181 PAD(expt - lead, zeroes);
1187 if (cp > dtoaend)
1188 cp = dtoaend;
1182 }
1183 if (prec || flags & ALT)
1184 PRINT(decimal_point,1);
1189 }
1190 if (prec || flags & ALT)
1191 PRINT(decimal_point,1);
1185 if (ndig > lead)
1186 PRINT(cp, ndig - lead);
1187 }
1192 }
1188 PAD(prec - ndig + expt, zeroes);
1193 PRINTANDPAD(cp, dtoaend, prec, zeroes);
1189 } else { /* %[eE] or sufficiently long %[gG] */
1194 } else { /* %[eE] or sufficiently long %[gG] */
1190 if (prec || flags & ALT) {
1195 if (prec > 1 || flags & ALT) {
1191 buf[0] = *cp++;
1192 buf[1] = *decimal_point;
1193 PRINT(buf, 2);
1194 PRINT(cp, ndig-1);
1195 PAD(prec - ndig, zeroes);
1196 } else /* XeYYY */
1197 PRINT(cp, 1);
1196 buf[0] = *cp++;
1197 buf[1] = *decimal_point;
1198 PRINT(buf, 2);
1199 PRINT(cp, ndig-1);
1200 PAD(prec - ndig, zeroes);
1201 } else /* XeYYY */
1202 PRINT(cp, 1);
1198
1199 PRINT(expstr, expsize);
1200 }
1201 }
1202#else
1203 PRINT(cp, size);
1204#endif
1205 /* left-adjusting padding (always blank) */
1206 if (flags & LADJUST)

--- 418 unchanged lines hidden ---
1203 PRINT(expstr, expsize);
1204 }
1205 }
1206#else
1207 PRINT(cp, size);
1208#endif
1209 /* left-adjusting padding (always blank) */
1210 if (flags & LADJUST)

--- 418 unchanged lines hidden ---