printf-pos.c (50476) | printf-pos.c (70725) |
---|---|
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 50476 1999-08-28 00:22:10Z peter $"; | 42 "$FreeBSD: head/lib/libc/stdio/vfprintf.c 70725 2001-01-06 20:48:00Z archie $"; |
43#endif /* LIBC_SCCS and not lint */ 44 45/* 46 * Actual printf innards. 47 * 48 * This code is large and complicated... 49 */ 50 --- 843 unchanged lines hidden (view full) --- 894#define T_LONG_DOUBLE 14 895#define TP_CHAR 15 896#define TP_VOID 16 897 898/* 899 * Find all arguments when a positional parameter is encountered. Returns a 900 * table, indexed by argument number, of pointers to each arguments. The 901 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. | 43#endif /* LIBC_SCCS and not lint */ 44 45/* 46 * Actual printf innards. 47 * 48 * This code is large and complicated... 49 */ 50 --- 843 unchanged lines hidden (view full) --- 894#define T_LONG_DOUBLE 14 895#define TP_CHAR 15 896#define TP_VOID 16 897 898/* 899 * Find all arguments when a positional parameter is encountered. Returns a 900 * table, indexed by argument number, of pointers to each arguments. The 901 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. |
902 * It will be replaces with a malloc-ed on if it overflows. | 902 * It will be replaces with a malloc-ed one if it overflows. |
903 */ 904static void 905__find_arguments (fmt0, ap, argtable) 906 const char *fmt0; 907 va_list ap; 908 void ***argtable; 909{ 910 register char *fmt; /* format string */ --- 9 unchanged lines hidden (view full) --- 920 int nextarg; /* 1-based argument index */ 921 922 /* 923 * Add an argument type to the table, expanding if necessary. 924 */ 925#define ADDTYPE(type) \ 926 ((nextarg >= tablesize) ? \ 927 __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ | 903 */ 904static void 905__find_arguments (fmt0, ap, argtable) 906 const char *fmt0; 907 va_list ap; 908 void ***argtable; 909{ 910 register char *fmt; /* format string */ --- 9 unchanged lines hidden (view full) --- 920 int nextarg; /* 1-based argument index */ 921 922 /* 923 * Add an argument type to the table, expanding if necessary. 924 */ 925#define ADDTYPE(type) \ 926 ((nextarg >= tablesize) ? \ 927 __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ |
928 typetable[nextarg++] = type, \ 929 (nextarg > tablemax) ? tablemax = nextarg : 0) | 928 (nextarg > tablemax) ? tablemax = nextarg : 0, \ 929 typetable[nextarg++] = type) |
930 931#define ADDSARG() \ 932 ((flags&LONGINT) ? ADDTYPE(T_LONG) : \ 933 ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT))) 934 935#define ADDUARG() \ 936 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \ 937 ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT))) --- 236 unchanged lines hidden (view full) --- 1174 * Increase the size of the type table. 1175 */ 1176static void 1177__grow_type_table (nextarg, typetable, tablesize) 1178 int nextarg; 1179 unsigned char **typetable; 1180 int *tablesize; 1181{ | 930 931#define ADDSARG() \ 932 ((flags&LONGINT) ? ADDTYPE(T_LONG) : \ 933 ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT))) 934 935#define ADDUARG() \ 936 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \ 937 ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT))) --- 236 unchanged lines hidden (view full) --- 1174 * Increase the size of the type table. 1175 */ 1176static void 1177__grow_type_table (nextarg, typetable, tablesize) 1178 int nextarg; 1179 unsigned char **typetable; 1180 int *tablesize; 1181{ |
1182 unsigned char *oldtable = *typetable; 1183 int newsize = *tablesize * 2; | 1182 unsigned char *const oldtable = *typetable; 1183 const int oldsize = *tablesize; 1184 unsigned char *newtable; 1185 int newsize = oldsize * 2; |
1184 | 1186 |
1185 if (*tablesize == STATIC_ARG_TBL_SIZE) { 1186 *typetable = (unsigned char *) 1187 malloc (sizeof (unsigned char) * newsize); 1188 bcopy (oldtable, *typetable, *tablesize); | 1187 if (newsize < nextarg + 1) 1188 newsize = nextarg + 1; 1189 if (oldsize == STATIC_ARG_TBL_SIZE) { 1190 if ((newtable = malloc(newsize)) == NULL) 1191 abort(); /* XXX handle better */ 1192 bcopy(oldtable, newtable, oldsize); |
1189 } else { | 1193 } else { |
1190 *typetable = (unsigned char *) 1191 reallocf (typetable, sizeof (unsigned char) * newsize); 1192 | 1194 if ((newtable = reallocf(oldtable, newsize)) == NULL) 1195 abort(); /* XXX handle better */ |
1193 } | 1196 } |
1194 memset (&typetable [*tablesize], T_UNUSED, (newsize - *tablesize)); | 1197 memset(&newtable[oldsize], T_UNUSED, newsize - oldsize); |
1195 | 1198 |
1199 *typetable = newtable; |
|
1196 *tablesize = newsize; 1197} 1198 1199 1200#ifdef FLOATING_POINT 1201 1202extern char *__dtoa __P((double, int, int, int *, int *, char **)); 1203 --- 75 unchanged lines hidden --- | 1200 *tablesize = newsize; 1201} 1202 1203 1204#ifdef FLOATING_POINT 1205 1206extern char *__dtoa __P((double, int, int, int *, int *, char **)); 1207 --- 75 unchanged lines hidden --- |