Deleted Added
full compact
printf-pos.c (112224) printf-pos.c (113142)
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 112224 2003-03-14 04:48:09Z das $");
41__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 113142 2003-04-05 22:03:43Z das $");
42
43/*
44 * Actual printf innards.
45 *
46 * This code is large and complicated...
47 */
48
49#include "namespace.h"

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

405 FUNLOCKFILE(fp);
406 return (ret);
407}
408
409#ifdef FLOATING_POINT
410#include <math.h>
411#include "floatio.h"
412
42
43/*
44 * Actual printf innards.
45 *
46 * This code is large and complicated...
47 */
48
49#include "namespace.h"

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

405 FUNLOCKFILE(fp);
406 return (ret);
407}
408
409#ifdef FLOATING_POINT
410#include <math.h>
411#include "floatio.h"
412
413#define BUF ((MAXEXP*2)+MAXFRACT+1) /* + decimal point */
414#define DEFPREC 6
415
416extern char *__dtoa(double, int, int, int *, int *, char **);
417extern void __freedtoa(char *s);
418
419static char *cvt(double, int, int, char *, int *, int, int *);
420static int exponent(char *, int, int);
421
413#define DEFPREC 6
414
415extern char *__dtoa(double, int, int, int *, int *, char **);
416extern void __freedtoa(char *s);
417
418static char *cvt(double, int, int, char *, int *, int, int *);
419static int exponent(char *, int, int);
420
422#else /* no FLOATING_POINT */
423
424#define BUF 136
425
426#endif /* FLOATING_POINT */
427
421#endif /* FLOATING_POINT */
422
423/*
424 * The size of the buffer we use as scratch space for integer
425 * conversions, among other things. Technically, we would need the
426 * most space for base 10 conversions with thousands' grouping
427 * characters between each pair of digits. 100 bytes is a
428 * conservative overestimate even for a 128-bit uintmax_t.
429 */
430#define BUF 100
431
428#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
429
430/*
431 * Flags used during conversion.
432 */
433#define ALT 0x001 /* alternate form */
434#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
435#define LADJUST 0x004 /* left adjustment */

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

466 const char *grouping; /* locale specific numeric grouping rules */
467#ifdef FLOATING_POINT
468 char *decimal_point; /* locale specific decimal point */
469 char softsign; /* temporary negative sign for floats */
470 double _double; /* double precision arguments %[eEfgG] */
471 int expt; /* integer value of exponent */
472 int expsize; /* character count for expstr */
473 int ndig; /* actual number of digits returned by cvt */
432#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */
433
434/*
435 * Flags used during conversion.
436 */
437#define ALT 0x001 /* alternate form */
438#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
439#define LADJUST 0x004 /* left adjustment */

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

470 const char *grouping; /* locale specific numeric grouping rules */
471#ifdef FLOATING_POINT
472 char *decimal_point; /* locale specific decimal point */
473 char softsign; /* temporary negative sign for floats */
474 double _double; /* double precision arguments %[eEfgG] */
475 int expt; /* integer value of exponent */
476 int expsize; /* character count for expstr */
477 int ndig; /* actual number of digits returned by cvt */
474 char expstr[7]; /* buffer for exponent string */
478 char expstr[MAXEXPDIG+2]; /* buffer for exponent string */
475 char *dtoaresult; /* buffer allocated by dtoa */
476#endif
477 u_long ulval; /* integer arguments %[diouxX] */
478 uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */
479 int base; /* base for [diouxX] conversion */
480 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
481 int realsz; /* field size expanded by dprec, sign, etc */
482 int size; /* size of converted field or string */
483 int prsize; /* max size of printed field */
484 char *xdigs; /* digits for [xX] conversion */
485#define NIOV 8
486 struct __suio uio; /* output information: summary */
487 struct __siov iov[NIOV];/* ... and individual io vectors */
479 char *dtoaresult; /* buffer allocated by dtoa */
480#endif
481 u_long ulval; /* integer arguments %[diouxX] */
482 uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */
483 int base; /* base for [diouxX] conversion */
484 int dprec; /* a copy of prec if [diouxX], 0 otherwise */
485 int realsz; /* field size expanded by dprec, sign, etc */
486 int size; /* size of converted field or string */
487 int prsize; /* max size of printed field */
488 char *xdigs; /* digits for [xX] conversion */
489#define NIOV 8
490 struct __suio uio; /* output information: summary */
491 struct __siov iov[NIOV];/* ... and individual io vectors */
488 char buf[BUF]; /* space for %c, %[diouxX], %[eEfFgG] */
492 char buf[BUF]; /* buffer with space for digits of uintmax_t */
489 char ox[2]; /* space for 0x hex-prefix */
490 union arg *argtable; /* args, built due to positional arg */
491 union arg statargtable [STATIC_ARG_TBL_SIZE];
492 int nextarg; /* 1-based argument index */
493 va_list orgap; /* original argument pointer */
494 char *convbuf; /* wide to multibyte conversion result */
495
496 /*

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

1017 } else {
1018 if (ulval != 0 || prec != 0)
1019 cp = __ultoa(ulval, cp, base,
1020 flags & ALT, xdigs,
1021 flags & GROUPING, thousands_sep,
1022 grouping);
1023 }
1024 size = buf + BUF - cp;
493 char ox[2]; /* space for 0x hex-prefix */
494 union arg *argtable; /* args, built due to positional arg */
495 union arg statargtable [STATIC_ARG_TBL_SIZE];
496 int nextarg; /* 1-based argument index */
497 va_list orgap; /* original argument pointer */
498 char *convbuf; /* wide to multibyte conversion result */
499
500 /*

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

1021 } else {
1022 if (ulval != 0 || prec != 0)
1023 cp = __ultoa(ulval, cp, base,
1024 flags & ALT, xdigs,
1025 flags & GROUPING, thousands_sep,
1026 grouping);
1027 }
1028 size = buf + BUF - cp;
1029 if (size > BUF) /* should never happen */
1030 abort();
1025 break;
1026 default: /* "%?" prints ?, unless ? is NUL */
1027 if (ch == '\0')
1028 goto done;
1029 /* pretend it was %c with argument ch */
1030 cp = buf;
1031 *cp = ch;
1032 size = 1;

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

1548 *length = rve - digits;
1549 return (digits);
1550}
1551
1552static int
1553exponent(char *p0, int exp, int fmtch)
1554{
1555 char *p, *t;
1031 break;
1032 default: /* "%?" prints ?, unless ? is NUL */
1033 if (ch == '\0')
1034 goto done;
1035 /* pretend it was %c with argument ch */
1036 cp = buf;
1037 *cp = ch;
1038 size = 1;

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

1554 *length = rve - digits;
1555 return (digits);
1556}
1557
1558static int
1559exponent(char *p0, int exp, int fmtch)
1560{
1561 char *p, *t;
1556 char expbuf[MAXEXP];
1562 char expbuf[MAXEXPDIG];
1557
1558 p = p0;
1559 *p++ = fmtch;
1560 if (exp < 0) {
1561 exp = -exp;
1562 *p++ = '-';
1563 }
1564 else
1565 *p++ = '+';
1563
1564 p = p0;
1565 *p++ = fmtch;
1566 if (exp < 0) {
1567 exp = -exp;
1568 *p++ = '-';
1569 }
1570 else
1571 *p++ = '+';
1566 t = expbuf + MAXEXP;
1572 t = expbuf + MAXEXPDIG;
1567 if (exp > 9) {
1568 do {
1569 *--t = to_char(exp % 10);
1570 } while ((exp /= 10) > 9);
1571 *--t = to_char(exp);
1573 if (exp > 9) {
1574 do {
1575 *--t = to_char(exp % 10);
1576 } while ((exp /= 10) > 9);
1577 *--t = to_char(exp);
1572 for (; t < expbuf + MAXEXP; *p++ = *t++);
1578 for (; t < expbuf + MAXEXPDIG; *p++ = *t++);
1573 }
1574 else {
1575 *p++ = '0';
1576 *p++ = to_char(exp);
1577 }
1578 return (p - p0);
1579}
1580#endif /* FLOATING_POINT */
1579 }
1580 else {
1581 *p++ = '0';
1582 *p++ = to_char(exp);
1583 }
1584 return (p - p0);
1585}
1586#endif /* FLOATING_POINT */