Deleted Added
full compact
vfprintf.c (81975) vfprintf.c (84922)
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[] =
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 $";
42 "$FreeBSD: head/lib/libc/stdio/vfprintf.c 84922 2001-10-14 13:45:33Z dfr $";
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
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
73union arg {
74 int intarg;
75 unsigned int uintarg;
76 long longarg;
77 unsigned long ulongarg;
78 quad_t quadarg;
79 u_quad_t uquadarg;
80 void *pvoidarg;
81 char *pchararg;
82 short *pshortarg;
83 int *pintarg;
84 long *plongarg;
85 quad_t *pquadarg;
86#ifdef FLOATING_POINT
87 double doublearg;
88 long double longdoublearg;
89#endif
90};
91
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 *));
92static int __sprint __P((FILE *, struct __suio *));
93static int __sbprintf __P((FILE *, const char *, va_list)) __printflike(2, 0);
94static char * __ultoa __P((u_long, char *, int, int, char *));
95static char * __uqtoa __P((u_quad_t, char *, int, int, char *));
77static void __find_arguments __P((const char *, va_list, void ***));
96static void __find_arguments __P((const char *, va_list, union arg **));
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 */
97static void __grow_type_table __P((int, unsigned char **, int *));
98
99/*
100 * Flush out all the vectors defined by the given uio,
101 * then reset it so that it can be reused.
102 */
103static int
104__sprint(FILE *fp, struct __suio *uio)

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

344 int size; /* size of converted field or string */
345 int prsize; /* max size of printed field */
346 char *xdigs; /* digits for [xX] conversion */
347#define NIOV 8
348 struct __suio uio; /* output information: summary */
349 struct __siov iov[NIOV];/* ... and individual io vectors */
350 char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
351 char ox[2]; /* space for 0x hex-prefix */
333 void **argtable; /* args, built due to positional arg */
334 void *statargtable [STATIC_ARG_TBL_SIZE];
352 union arg *argtable; /* args, built due to positional arg */
353 union arg 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) \
354 int nextarg; /* 1-based argument index */
355 va_list orgap; /* original argument pointer */
356
357 /*
358 * Choose PADSIZE to trade efficiency vs. size. If larger printf
359 * fields occur frequently, increase PADSIZE and make the initialisers
360 * below longer.
361 */

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

396}
397
398 /*
399 * Get the argument indexed by nextarg. If the argument table is
400 * built, use it to get the argument. If its not, get the next
401 * argument (and arguments must be gotten sequentially).
402 */
403#define GETARG(type) \
385 ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \
404 ((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
405 (nextarg++, va_arg(ap, type)))
406
407 /*
408 * To extend shorts properly, we need both signed and unsigned
409 * argument extraction methods.
410 */
411#define SARG() \
412 (flags&LONGINT ? GETARG(long) : \

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

926
927/*
928 * Find all arguments when a positional parameter is encountered. Returns a
929 * table, indexed by argument number, of pointers to each arguments. The
930 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
931 * It will be replaces with a malloc-ed one if it overflows.
932 */
933static void
915__find_arguments (const char *fmt0, va_list ap, void ***argtable)
934__find_arguments (const char *fmt0, va_list ap, union arg **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) {
935{
936 char *fmt; /* format string */
937 int ch; /* character from fmt */
938 int n, n2; /* handy integer (short term usage) */
939 char *cp; /* handy char pointer (short term usage) */
940 int flags; /* flags as above */
941 int width; /* width from format (%8d), or 0 */
942 unsigned char *typetable; /* table of types */

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

1126 break;
1127 }
1128 }
1129done:
1130 /*
1131 * Build the argument table.
1132 */
1133 if (tablemax >= STATIC_ARG_TBL_SIZE) {
1115 *argtable = (void **)
1116 malloc (sizeof (void *) * (tablemax + 1));
1134 *argtable = (union arg *)
1135 malloc (sizeof (union arg) * (tablemax + 1));
1117 }
1118
1136 }
1137
1119 (*argtable) [0] = NULL;
1138 (*argtable) [0].intarg = 0;
1120 for (n = 1; n <= tablemax; n++) {
1121 switch (typetable [n]) {
1122 case T_UNUSED:
1139 for (n = 1; n <= tablemax; n++) {
1140 switch (typetable [n]) {
1141 case T_UNUSED:
1123 (*argtable) [n] = (void *) &va_arg (ap, int);
1142 (*argtable) [n].intarg = va_arg (ap, int);
1124 break;
1125 case T_SHORT:
1143 break;
1144 case T_SHORT:
1126 (*argtable) [n] = (void *) &va_arg (ap, int);
1145 (*argtable) [n].intarg = va_arg (ap, int);
1127 break;
1128 case T_U_SHORT:
1146 break;
1147 case T_U_SHORT:
1129 (*argtable) [n] = (void *) &va_arg (ap, int);
1148 (*argtable) [n].intarg = va_arg (ap, int);
1130 break;
1131 case TP_SHORT:
1149 break;
1150 case TP_SHORT:
1132 (*argtable) [n] = (void *) &va_arg (ap, short *);
1151 (*argtable) [n].pshortarg = va_arg (ap, short *);
1133 break;
1134 case T_INT:
1152 break;
1153 case T_INT:
1135 (*argtable) [n] = (void *) &va_arg (ap, int);
1154 (*argtable) [n].intarg = va_arg (ap, int);
1136 break;
1137 case T_U_INT:
1155 break;
1156 case T_U_INT:
1138 (*argtable) [n] = (void *) &va_arg (ap, unsigned int);
1157 (*argtable) [n].uintarg = va_arg (ap, unsigned int);
1139 break;
1140 case TP_INT:
1158 break;
1159 case TP_INT:
1141 (*argtable) [n] = (void *) &va_arg (ap, int *);
1160 (*argtable) [n].pintarg = va_arg (ap, int *);
1142 break;
1143 case T_LONG:
1161 break;
1162 case T_LONG:
1144 (*argtable) [n] = (void *) &va_arg (ap, long);
1163 (*argtable) [n].longarg = va_arg (ap, long);
1145 break;
1146 case T_U_LONG:
1164 break;
1165 case T_U_LONG:
1147 (*argtable) [n] = (void *) &va_arg (ap, unsigned long);
1166 (*argtable) [n].ulongarg = va_arg (ap, unsigned long);
1148 break;
1149 case TP_LONG:
1167 break;
1168 case TP_LONG:
1150 (*argtable) [n] = (void *) &va_arg (ap, long *);
1169 (*argtable) [n].plongarg = va_arg (ap, long *);
1151 break;
1152 case T_QUAD:
1170 break;
1171 case T_QUAD:
1153 (*argtable) [n] = (void *) &va_arg (ap, quad_t);
1172 (*argtable) [n].quadarg = va_arg (ap, quad_t);
1154 break;
1155 case T_U_QUAD:
1173 break;
1174 case T_U_QUAD:
1156 (*argtable) [n] = (void *) &va_arg (ap, u_quad_t);
1175 (*argtable) [n].uquadarg = va_arg (ap, u_quad_t);
1157 break;
1158 case TP_QUAD:
1176 break;
1177 case TP_QUAD:
1159 (*argtable) [n] = (void *) &va_arg (ap, quad_t *);
1178 (*argtable) [n].pquadarg = va_arg (ap, quad_t *);
1160 break;
1179 break;
1180#ifdef FLOATING_POINT
1161 case T_DOUBLE:
1181 case T_DOUBLE:
1162 (*argtable) [n] = (void *) &va_arg (ap, double);
1182 (*argtable) [n].doublearg = va_arg (ap, double);
1163 break;
1164 case T_LONG_DOUBLE:
1183 break;
1184 case T_LONG_DOUBLE:
1165 (*argtable) [n] = (void *) &va_arg (ap, long double);
1185 (*argtable) [n].longdoublearg = va_arg (ap, long double);
1166 break;
1186 break;
1187#endif
1167 case TP_CHAR:
1188 case TP_CHAR:
1168 (*argtable) [n] = (void *) &va_arg (ap, char *);
1189 (*argtable) [n].pchararg = va_arg (ap, char *);
1169 break;
1170 case TP_VOID:
1190 break;
1191 case TP_VOID:
1171 (*argtable) [n] = (void *) &va_arg (ap, void *);
1192 (*argtable) [n].pvoidarg = va_arg (ap, void *);
1172 break;
1173 }
1174 }
1175
1176 if ((typetable != NULL) && (typetable != stattypetable))
1177 free (typetable);
1178}
1179

--- 104 unchanged lines hidden ---
1193 break;
1194 }
1195 }
1196
1197 if ((typetable != NULL) && (typetable != stattypetable))
1198 free (typetable);
1199}
1200

--- 104 unchanged lines hidden ---