Deleted Added
sdiff udiff text old ( 81975 ) new ( 84922 )
full compact
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

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

34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38#if 0
39static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
40#endif
41static const char rcsid[] =
42 "$FreeBSD: head/lib/libc/stdio/vfprintf.c 81975 2001-08-20 12:53:36Z kris $";
43#endif /* LIBC_SCCS and not lint */
44
45/*
46 * Actual printf innards.
47 *
48 * This code is large and complicated...
49 */
50

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

65
66#include "libc_private.h"
67#include "local.h"
68#include "fvwrite.h"
69
70/* Define FLOATING_POINT to get floating point. */
71#define FLOATING_POINT
72
73static int __sprint __P((FILE *, struct __suio *));
74static int __sbprintf __P((FILE *, const char *, va_list)) __printflike(2, 0);
75static char * __ultoa __P((u_long, char *, int, int, char *));
76static char * __uqtoa __P((u_quad_t, char *, int, int, char *));
77static void __find_arguments __P((const char *, va_list, void ***));
78static void __grow_type_table __P((int, unsigned char **, int *));
79
80/*
81 * Flush out all the vectors defined by the given uio,
82 * then reset it so that it can be reused.
83 */
84static int
85__sprint(FILE *fp, struct __suio *uio)

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

325 int size; /* size of converted field or string */
326 int prsize; /* max size of printed field */
327 char *xdigs; /* digits for [xX] conversion */
328#define NIOV 8
329 struct __suio uio; /* output information: summary */
330 struct __siov iov[NIOV];/* ... and individual io vectors */
331 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
332 char ox[2]; /* space for 0x hex-prefix */
333 void **argtable; /* args, built due to positional arg */
334 void *statargtable [STATIC_ARG_TBL_SIZE];
335 int nextarg; /* 1-based argument index */
336 va_list orgap; /* original argument pointer */
337
338 /*
339 * Choose PADSIZE to trade efficiency vs. size. If larger printf
340 * fields occur frequently, increase PADSIZE and make the initialisers
341 * below longer.
342 */

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

377}
378
379 /*
380 * Get the argument indexed by nextarg. If the argument table is
381 * built, use it to get the argument. If its not, get the next
382 * argument (and arguments must be gotten sequentially).
383 */
384#define GETARG(type) \
385 ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
386 (nextarg++, va_arg(ap, type)))
387
388 /*
389 * To extend shorts properly, we need both signed and unsigned
390 * argument extraction methods.
391 */
392#define SARG() \
393 (flags&LONGINT ? GETARG(long) : \

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

907
908/*
909 * Find all arguments when a positional parameter is encountered. Returns a
910 * table, indexed by argument number, of pointers to each arguments. The
911 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
912 * It will be replaces with a malloc-ed one if it overflows.
913 */
914static void
915__find_arguments (const char *fmt0, va_list ap, void ***argtable)
916{
917 char *fmt; /* format string */
918 int ch; /* character from fmt */
919 int n, n2; /* handy integer (short term usage) */
920 char *cp; /* handy char pointer (short term usage) */
921 int flags; /* flags as above */
922 int width; /* width from format (%8d), or 0 */
923 unsigned char *typetable; /* table of types */

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

1107 break;
1108 }
1109 }
1110done:
1111 /*
1112 * Build the argument table.
1113 */
1114 if (tablemax >= STATIC_ARG_TBL_SIZE) {
1115 *argtable = (void **)
1116 malloc (sizeof (void *) * (tablemax + 1));
1117 }
1118
1119 (*argtable) [0] = NULL;
1120 for (n = 1; n <= tablemax; n++) {
1121 switch (typetable [n]) {
1122 case T_UNUSED:
1123 (*argtable) [n] = (void *) &va_arg (ap, int);
1124 break;
1125 case T_SHORT:
1126 (*argtable) [n] = (void *) &va_arg (ap, int);
1127 break;
1128 case T_U_SHORT:
1129 (*argtable) [n] = (void *) &va_arg (ap, int);
1130 break;
1131 case TP_SHORT:
1132 (*argtable) [n] = (void *) &va_arg (ap, short *);
1133 break;
1134 case T_INT:
1135 (*argtable) [n] = (void *) &va_arg (ap, int);
1136 break;
1137 case T_U_INT:
1138 (*argtable) [n] = (void *) &va_arg (ap, unsigned int);
1139 break;
1140 case TP_INT:
1141 (*argtable) [n] = (void *) &va_arg (ap, int *);
1142 break;
1143 case T_LONG:
1144 (*argtable) [n] = (void *) &va_arg (ap, long);
1145 break;
1146 case T_U_LONG:
1147 (*argtable) [n] = (void *) &va_arg (ap, unsigned long);
1148 break;
1149 case TP_LONG:
1150 (*argtable) [n] = (void *) &va_arg (ap, long *);
1151 break;
1152 case T_QUAD:
1153 (*argtable) [n] = (void *) &va_arg (ap, quad_t);
1154 break;
1155 case T_U_QUAD:
1156 (*argtable) [n] = (void *) &va_arg (ap, u_quad_t);
1157 break;
1158 case TP_QUAD:
1159 (*argtable) [n] = (void *) &va_arg (ap, quad_t *);
1160 break;
1161 case T_DOUBLE:
1162 (*argtable) [n] = (void *) &va_arg (ap, double);
1163 break;
1164 case T_LONG_DOUBLE:
1165 (*argtable) [n] = (void *) &va_arg (ap, long double);
1166 break;
1167 case TP_CHAR:
1168 (*argtable) [n] = (void *) &va_arg (ap, char *);
1169 break;
1170 case TP_VOID:
1171 (*argtable) [n] = (void *) &va_arg (ap, void *);
1172 break;
1173 }
1174 }
1175
1176 if ((typetable != NULL) && (typetable != stattypetable))
1177 free (typetable);
1178}
1179

--- 104 unchanged lines hidden ---