vfprintf.c (178287) | vfprintf.c (180102) |
---|---|
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 --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#if defined(LIBC_SCCS) && !defined(lint) 34static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; 35#endif /* LIBC_SCCS and not lint */ 36#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 --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#if defined(LIBC_SCCS) && !defined(lint) 34static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; 35#endif /* LIBC_SCCS and not lint */ 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 178287 2008-04-17 22:17:54Z jhb $"); | 37__FBSDID("$FreeBSD: head/lib/libc/stdio/vfprintf.c 180102 2008-06-29 21:01:27Z das $"); |
38 39/* 40 * Actual printf innards. 41 * 42 * This code is large and complicated... 43 */ 44 45#include "namespace.h" --- 52 unchanged lines hidden (view full) --- 98enum typeid { 99 T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT, 100 T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG, 101 T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET, 102 T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR, 103 T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR 104}; 105 | 38 39/* 40 * Actual printf innards. 41 * 42 * This code is large and complicated... 43 */ 44 45#include "namespace.h" --- 52 unchanged lines hidden (view full) --- 98enum typeid { 99 T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT, 100 T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG, 101 T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET, 102 T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR, 103 T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR 104}; 105 |
106#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ 107 108/* An expandable array of types. */ 109struct typetable { 110 enum typeid *table; /* table of types */ 111 enum typeid stattable[STATIC_ARG_TBL_SIZE]; 112 int tablesize; /* current size of type table */ 113 int tablemax; /* largest used index in table */ 114 int nextarg; /* 1-based argument index */ 115}; 116 |
|
106static int __sprint(FILE *, struct __suio *); 107static int __sbprintf(FILE *, const char *, va_list) __printflike(2, 0); 108static char *__ujtoa(uintmax_t, char *, int, int, const char *, int, char, 109 const char *); 110static char *__ultoa(u_long, char *, int, int, const char *, int, char, 111 const char *); 112static char *__wcsconv(wchar_t *, int); 113static void __find_arguments(const char *, va_list, union arg **); | 117static int __sprint(FILE *, struct __suio *); 118static int __sbprintf(FILE *, const char *, va_list) __printflike(2, 0); 119static char *__ujtoa(uintmax_t, char *, int, int, const char *, int, char, 120 const char *); 121static char *__ultoa(u_long, char *, int, int, const char *, int, char, 122 const char *); 123static char *__wcsconv(wchar_t *, int); 124static void __find_arguments(const char *, va_list, union arg **); |
114static void __grow_type_table(int, enum typeid **, int *); | 125static void __grow_type_table(struct typetable *); |
115 116/* 117 * Flush out all the vectors defined by the given uio, 118 * then reset it so that it can be reused. 119 */ 120static int 121__sprint(FILE *fp, struct __suio *uio) 122{ --- 298 unchanged lines hidden (view full) --- 421 * The size of the buffer we use as scratch space for integer 422 * conversions, among other things. Technically, we would need the 423 * most space for base 10 conversions with thousands' grouping 424 * characters between each pair of digits. 100 bytes is a 425 * conservative overestimate even for a 128-bit uintmax_t. 426 */ 427#define BUF 100 428 | 126 127/* 128 * Flush out all the vectors defined by the given uio, 129 * then reset it so that it can be reused. 130 */ 131static int 132__sprint(FILE *fp, struct __suio *uio) 133{ --- 298 unchanged lines hidden (view full) --- 432 * The size of the buffer we use as scratch space for integer 433 * conversions, among other things. Technically, we would need the 434 * most space for base 10 conversions with thousands' grouping 435 * characters between each pair of digits. 100 bytes is a 436 * conservative overestimate even for a 128-bit uintmax_t. 437 */ 438#define BUF 100 439 |
429#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ 430 | |
431/* 432 * Flags used during conversion. 433 */ 434#define ALT 0x001 /* alternate form */ 435#define LADJUST 0x004 /* left adjustment */ 436#define LONGDBL 0x008 /* long double */ 437#define LONGINT 0x010 /* long integer */ 438#define LLONGINT 0x020 /* long long integer */ --- 812 unchanged lines hidden (view full) --- 1251 ret = EOF; 1252 if ((argtable != NULL) && (argtable != statargtable)) 1253 free (argtable); 1254 return (ret); 1255 /* NOTREACHED */ 1256} 1257 1258/* | 440/* 441 * Flags used during conversion. 442 */ 443#define ALT 0x001 /* alternate form */ 444#define LADJUST 0x004 /* left adjustment */ 445#define LONGDBL 0x008 /* long double */ 446#define LONGINT 0x010 /* long integer */ 447#define LLONGINT 0x020 /* long long integer */ --- 812 unchanged lines hidden (view full) --- 1260 ret = EOF; 1261 if ((argtable != NULL) && (argtable != statargtable)) 1262 free (argtable); 1263 return (ret); 1264 /* NOTREACHED */ 1265} 1266 1267/* |
1268 * Initialize a struct typetable. 1269 */ 1270static inline void 1271inittypes(struct typetable *types) 1272{ 1273 int n; 1274 1275 types->table = types->stattable; 1276 types->tablesize = STATIC_ARG_TBL_SIZE; 1277 types->tablemax = 0; 1278 types->nextarg = 1; 1279 for (n = 0; n < STATIC_ARG_TBL_SIZE; n++) 1280 types->table[n] = T_UNUSED; 1281} 1282 1283/* 1284 * struct typetable destructor. 1285 */ 1286static inline void 1287freetypes(struct typetable *types) 1288{ 1289 1290 if (types->table != types->stattable) 1291 free (types->table); 1292} 1293 1294/* 1295 * Add an argument type to the table, expanding if necessary. 1296 */ 1297static inline void 1298addtype(struct typetable *types, enum typeid type) 1299{ 1300 1301 if (types->nextarg >= types->tablesize) 1302 __grow_type_table(types); 1303 if (types->nextarg > types->tablemax) 1304 types->tablemax = types->nextarg; 1305 types->table[types->nextarg++] = type; 1306} 1307 1308static inline void 1309addsarg(struct typetable *types, int flags) 1310{ 1311 1312 if (flags & INTMAXT) 1313 addtype(types, T_INTMAXT); 1314 else if (flags & SIZET) 1315 addtype(types, T_SIZET); 1316 else if (flags & PTRDIFFT) 1317 addtype(types, T_PTRDIFFT); 1318 else if (flags & LLONGINT) 1319 addtype(types, T_LLONG); 1320 else if (flags & LONGINT) 1321 addtype(types, T_LONG); 1322 else 1323 addtype(types, T_INT); 1324} 1325 1326static inline void 1327adduarg(struct typetable *types, int flags) 1328{ 1329 1330 if (flags & INTMAXT) 1331 addtype(types, T_UINTMAXT); 1332 else if (flags & SIZET) 1333 addtype(types, T_SIZET); 1334 else if (flags & PTRDIFFT) 1335 addtype(types, T_PTRDIFFT); 1336 else if (flags & LLONGINT) 1337 addtype(types, T_U_LLONG); 1338 else if (flags & LONGINT) 1339 addtype(types, T_U_LONG); 1340 else 1341 addtype(types, T_U_INT); 1342} 1343 1344/* 1345 * Add * arguments to the type array. 1346 */ 1347static inline void 1348addaster(struct typetable *types, char **fmtp) 1349{ 1350 char *cp; 1351 int n2; 1352 1353 n2 = 0; 1354 cp = *fmtp; 1355 while (is_digit(*cp)) { 1356 n2 = 10 * n2 + to_digit(*cp); 1357 cp++; 1358 } 1359 if (*cp == '$') { 1360 int hold = types->nextarg; 1361 types->nextarg = n2; 1362 addtype(types, T_INT); 1363 types->nextarg = hold; 1364 *fmtp = ++cp; 1365 } else { 1366 addtype(types, T_INT); 1367 } 1368} 1369 1370/* |
|
1259 * Find all arguments when a positional parameter is encountered. Returns a 1260 * table, indexed by argument number, of pointers to each arguments. The 1261 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. 1262 * It will be replaces with a malloc-ed one if it overflows. 1263 */ 1264static void 1265__find_arguments (const char *fmt0, va_list ap, union arg **argtable) 1266{ 1267 char *fmt; /* format string */ 1268 int ch; /* character from fmt */ | 1371 * Find all arguments when a positional parameter is encountered. Returns a 1372 * table, indexed by argument number, of pointers to each arguments. The 1373 * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. 1374 * It will be replaces with a malloc-ed one if it overflows. 1375 */ 1376static void 1377__find_arguments (const char *fmt0, va_list ap, union arg **argtable) 1378{ 1379 char *fmt; /* format string */ 1380 int ch; /* character from fmt */ |
1269 int n, n2; /* handy integer (short term usage) */ 1270 char *cp; /* handy char pointer (short term usage) */ | 1381 int n; /* handy integer (short term usage) */ |
1271 int flags; /* flags as above */ 1272 int width; /* width from format (%8d), or 0 */ | 1382 int flags; /* flags as above */ 1383 int width; /* width from format (%8d), or 0 */ |
1273 enum typeid *typetable; /* table of types */ 1274 enum typeid stattypetable [STATIC_ARG_TBL_SIZE]; 1275 int tablesize; /* current size of type table */ 1276 int tablemax; /* largest used index in table */ 1277 int nextarg; /* 1-based argument index */ | 1384 struct typetable types; /* table of types */ |
1278 | 1385 |
1279 /* 1280 * Add an argument type to the table, expanding if necessary. 1281 */ 1282#define ADDTYPE(type) \ 1283 ((nextarg >= tablesize) ? \ 1284 __grow_type_table(nextarg, &typetable, &tablesize) : (void)0, \ 1285 (nextarg > tablemax) ? tablemax = nextarg : 0, \ 1286 typetable[nextarg++] = type) 1287 1288#define ADDSARG() \ 1289 ((flags&INTMAXT) ? ADDTYPE(T_INTMAXT) : \ 1290 ((flags&SIZET) ? ADDTYPE(T_SIZET) : \ 1291 ((flags&PTRDIFFT) ? ADDTYPE(T_PTRDIFFT) : \ 1292 ((flags&LLONGINT) ? ADDTYPE(T_LLONG) : \ 1293 ((flags&LONGINT) ? ADDTYPE(T_LONG) : ADDTYPE(T_INT)))))) 1294 1295#define ADDUARG() \ 1296 ((flags&INTMAXT) ? ADDTYPE(T_UINTMAXT) : \ 1297 ((flags&SIZET) ? ADDTYPE(T_SIZET) : \ 1298 ((flags&PTRDIFFT) ? ADDTYPE(T_PTRDIFFT) : \ 1299 ((flags&LLONGINT) ? ADDTYPE(T_U_LLONG) : \ 1300 ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : ADDTYPE(T_U_INT)))))) 1301 1302 /* 1303 * Add * arguments to the type array. 1304 */ 1305#define ADDASTER() \ 1306 n2 = 0; \ 1307 cp = fmt; \ 1308 while (is_digit(*cp)) { \ 1309 n2 = 10 * n2 + to_digit(*cp); \ 1310 cp++; \ 1311 } \ 1312 if (*cp == '$') { \ 1313 int hold = nextarg; \ 1314 nextarg = n2; \ 1315 ADDTYPE (T_INT); \ 1316 nextarg = hold; \ 1317 fmt = ++cp; \ 1318 } else { \ 1319 ADDTYPE (T_INT); \ 1320 } | |
1321 fmt = (char *)fmt0; | 1386 fmt = (char *)fmt0; |
1322 typetable = stattypetable; 1323 tablesize = STATIC_ARG_TBL_SIZE; 1324 tablemax = 0; 1325 nextarg = 1; 1326 for (n = 0; n < STATIC_ARG_TBL_SIZE; n++) 1327 typetable[n] = T_UNUSED; | 1387 inittypes(&types); |
1328 1329 /* 1330 * Scan the format for conversions (`%' character). 1331 */ 1332 for (;;) { | 1388 1389 /* 1390 * Scan the format for conversions (`%' character). 1391 */ 1392 for (;;) { |
1333 for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) 1334 /* void */; | 1393 while ((ch = *fmt) != '\0' && ch != '%') 1394 fmt++; |
1335 if (ch == '\0') 1336 goto done; 1337 fmt++; /* skip over '%' */ 1338 1339 flags = 0; 1340 width = 0; 1341 1342rflag: ch = *fmt++; 1343reswitch: switch (ch) { 1344 case ' ': 1345 case '#': 1346 goto rflag; 1347 case '*': | 1395 if (ch == '\0') 1396 goto done; 1397 fmt++; /* skip over '%' */ 1398 1399 flags = 0; 1400 width = 0; 1401 1402rflag: ch = *fmt++; 1403reswitch: switch (ch) { 1404 case ' ': 1405 case '#': 1406 goto rflag; 1407 case '*': |
1348 ADDASTER (); | 1408 addaster(&types, &fmt); |
1349 goto rflag; 1350 case '-': 1351 case '+': 1352 case '\'': 1353 goto rflag; 1354 case '.': 1355 if ((ch = *fmt++) == '*') { | 1409 goto rflag; 1410 case '-': 1411 case '+': 1412 case '\'': 1413 goto rflag; 1414 case '.': 1415 if ((ch = *fmt++) == '*') { |
1356 ADDASTER (); | 1416 addaster(&types, &fmt); |
1357 goto rflag; 1358 } 1359 while (is_digit(ch)) { 1360 ch = *fmt++; 1361 } 1362 goto reswitch; 1363 case '0': 1364 goto rflag; 1365 case '1': case '2': case '3': case '4': 1366 case '5': case '6': case '7': case '8': case '9': 1367 n = 0; 1368 do { 1369 n = 10 * n + to_digit(ch); 1370 ch = *fmt++; 1371 } while (is_digit(ch)); 1372 if (ch == '$') { | 1417 goto rflag; 1418 } 1419 while (is_digit(ch)) { 1420 ch = *fmt++; 1421 } 1422 goto reswitch; 1423 case '0': 1424 goto rflag; 1425 case '1': case '2': case '3': case '4': 1426 case '5': case '6': case '7': case '8': case '9': 1427 n = 0; 1428 do { 1429 n = 10 * n + to_digit(ch); 1430 ch = *fmt++; 1431 } while (is_digit(ch)); 1432 if (ch == '$') { |
1373 nextarg = n; | 1433 types.nextarg = n; |
1374 goto rflag; 1375 } 1376 width = n; 1377 goto reswitch; 1378#ifndef NO_FLOATING_POINT 1379 case 'L': 1380 flags |= LONGDBL; 1381 goto rflag; --- 24 unchanged lines hidden (view full) --- 1406 case 'z': 1407 flags |= SIZET; 1408 goto rflag; 1409 case 'C': 1410 flags |= LONGINT; 1411 /*FALLTHROUGH*/ 1412 case 'c': 1413 if (flags & LONGINT) | 1434 goto rflag; 1435 } 1436 width = n; 1437 goto reswitch; 1438#ifndef NO_FLOATING_POINT 1439 case 'L': 1440 flags |= LONGDBL; 1441 goto rflag; --- 24 unchanged lines hidden (view full) --- 1466 case 'z': 1467 flags |= SIZET; 1468 goto rflag; 1469 case 'C': 1470 flags |= LONGINT; 1471 /*FALLTHROUGH*/ 1472 case 'c': 1473 if (flags & LONGINT) |
1414 ADDTYPE(T_WINT); | 1474 addtype(&types, T_WINT); |
1415 else | 1475 else |
1416 ADDTYPE(T_INT); | 1476 addtype(&types, T_INT); |
1417 break; 1418 case 'D': 1419 flags |= LONGINT; 1420 /*FALLTHROUGH*/ 1421 case 'd': 1422 case 'i': | 1477 break; 1478 case 'D': 1479 flags |= LONGINT; 1480 /*FALLTHROUGH*/ 1481 case 'd': 1482 case 'i': |
1423 ADDSARG(); | 1483 addsarg(&types, flags); |
1424 break; 1425#ifndef NO_FLOATING_POINT 1426 case 'a': 1427 case 'A': 1428 case 'e': 1429 case 'E': 1430 case 'f': 1431 case 'g': 1432 case 'G': 1433 if (flags & LONGDBL) | 1484 break; 1485#ifndef NO_FLOATING_POINT 1486 case 'a': 1487 case 'A': 1488 case 'e': 1489 case 'E': 1490 case 'f': 1491 case 'g': 1492 case 'G': 1493 if (flags & LONGDBL) |
1434 ADDTYPE(T_LONG_DOUBLE); | 1494 addtype(&types, T_LONG_DOUBLE); |
1435 else | 1495 else |
1436 ADDTYPE(T_DOUBLE); | 1496 addtype(&types, T_DOUBLE); |
1437 break; 1438#endif /* !NO_FLOATING_POINT */ 1439 case 'n': 1440 if (flags & INTMAXT) | 1497 break; 1498#endif /* !NO_FLOATING_POINT */ 1499 case 'n': 1500 if (flags & INTMAXT) |
1441 ADDTYPE(TP_INTMAXT); | 1501 addtype(&types, TP_INTMAXT); |
1442 else if (flags & PTRDIFFT) | 1502 else if (flags & PTRDIFFT) |
1443 ADDTYPE(TP_PTRDIFFT); | 1503 addtype(&types, TP_PTRDIFFT); |
1444 else if (flags & SIZET) | 1504 else if (flags & SIZET) |
1445 ADDTYPE(TP_SIZET); | 1505 addtype(&types, TP_SIZET); |
1446 else if (flags & LLONGINT) | 1506 else if (flags & LLONGINT) |
1447 ADDTYPE(TP_LLONG); | 1507 addtype(&types, TP_LLONG); |
1448 else if (flags & LONGINT) | 1508 else if (flags & LONGINT) |
1449 ADDTYPE(TP_LONG); | 1509 addtype(&types, TP_LONG); |
1450 else if (flags & SHORTINT) | 1510 else if (flags & SHORTINT) |
1451 ADDTYPE(TP_SHORT); | 1511 addtype(&types, TP_SHORT); |
1452 else if (flags & CHARINT) | 1512 else if (flags & CHARINT) |
1453 ADDTYPE(TP_SCHAR); | 1513 addtype(&types, TP_SCHAR); |
1454 else | 1514 else |
1455 ADDTYPE(TP_INT); | 1515 addtype(&types, TP_INT); |
1456 continue; /* no output */ 1457 case 'O': 1458 flags |= LONGINT; 1459 /*FALLTHROUGH*/ 1460 case 'o': | 1516 continue; /* no output */ 1517 case 'O': 1518 flags |= LONGINT; 1519 /*FALLTHROUGH*/ 1520 case 'o': |
1461 ADDUARG(); | 1521 adduarg(&types, flags); |
1462 break; 1463 case 'p': | 1522 break; 1523 case 'p': |
1464 ADDTYPE(TP_VOID); | 1524 addtype(&types, TP_VOID); |
1465 break; 1466 case 'S': 1467 flags |= LONGINT; 1468 /*FALLTHROUGH*/ 1469 case 's': 1470 if (flags & LONGINT) | 1525 break; 1526 case 'S': 1527 flags |= LONGINT; 1528 /*FALLTHROUGH*/ 1529 case 's': 1530 if (flags & LONGINT) |
1471 ADDTYPE(TP_WCHAR); | 1531 addtype(&types, TP_WCHAR); |
1472 else | 1532 else |
1473 ADDTYPE(TP_CHAR); | 1533 addtype(&types, TP_CHAR); |
1474 break; 1475 case 'U': 1476 flags |= LONGINT; 1477 /*FALLTHROUGH*/ 1478 case 'u': 1479 case 'X': 1480 case 'x': | 1534 break; 1535 case 'U': 1536 flags |= LONGINT; 1537 /*FALLTHROUGH*/ 1538 case 'u': 1539 case 'X': 1540 case 'x': |
1481 ADDUARG(); | 1541 adduarg(&types, flags); |
1482 break; 1483 default: /* "%?" prints ?, unless ? is NUL */ 1484 if (ch == '\0') 1485 goto done; 1486 break; 1487 } 1488 } 1489done: 1490 /* 1491 * Build the argument table. 1492 */ | 1542 break; 1543 default: /* "%?" prints ?, unless ? is NUL */ 1544 if (ch == '\0') 1545 goto done; 1546 break; 1547 } 1548 } 1549done: 1550 /* 1551 * Build the argument table. 1552 */ |
1493 if (tablemax >= STATIC_ARG_TBL_SIZE) { | 1553 if (types.tablemax >= STATIC_ARG_TBL_SIZE) { |
1494 *argtable = (union arg *) | 1554 *argtable = (union arg *) |
1495 malloc (sizeof (union arg) * (tablemax + 1)); | 1555 malloc (sizeof (union arg) * (types.tablemax + 1)); |
1496 } 1497 1498 (*argtable) [0].intarg = 0; | 1556 } 1557 1558 (*argtable) [0].intarg = 0; |
1499 for (n = 1; n <= tablemax; n++) { 1500 switch (typetable [n]) { | 1559 for (n = 1; n <= types.tablemax; n++) { 1560 switch (types.table[n]) { |
1501 case T_UNUSED: /* whoops! */ 1502 (*argtable) [n].intarg = va_arg (ap, int); 1503 break; 1504 case TP_SCHAR: 1505 (*argtable) [n].pschararg = va_arg (ap, signed char *); 1506 break; 1507 case TP_SHORT: 1508 (*argtable) [n].pshortarg = va_arg (ap, short *); --- 66 unchanged lines hidden (view full) --- 1575 (*argtable) [n].wintarg = va_arg (ap, wint_t); 1576 break; 1577 case TP_WCHAR: 1578 (*argtable) [n].pwchararg = va_arg (ap, wchar_t *); 1579 break; 1580 } 1581 } 1582 | 1561 case T_UNUSED: /* whoops! */ 1562 (*argtable) [n].intarg = va_arg (ap, int); 1563 break; 1564 case TP_SCHAR: 1565 (*argtable) [n].pschararg = va_arg (ap, signed char *); 1566 break; 1567 case TP_SHORT: 1568 (*argtable) [n].pshortarg = va_arg (ap, short *); --- 66 unchanged lines hidden (view full) --- 1635 (*argtable) [n].wintarg = va_arg (ap, wint_t); 1636 break; 1637 case TP_WCHAR: 1638 (*argtable) [n].pwchararg = va_arg (ap, wchar_t *); 1639 break; 1640 } 1641 } 1642 |
1583 if ((typetable != NULL) && (typetable != stattypetable)) 1584 free (typetable); | 1643 freetypes(&types); |
1585} 1586 1587/* 1588 * Increase the size of the type table. 1589 */ 1590static void | 1644} 1645 1646/* 1647 * Increase the size of the type table. 1648 */ 1649static void |
1591__grow_type_table (int nextarg, enum typeid **typetable, int *tablesize) | 1650__grow_type_table(struct typetable *types) |
1592{ | 1651{ |
1593 enum typeid *const oldtable = *typetable; 1594 const int oldsize = *tablesize; | 1652 enum typeid *const oldtable = types->table; 1653 const int oldsize = types->tablesize; |
1595 enum typeid *newtable; 1596 int n, newsize = oldsize * 2; 1597 | 1654 enum typeid *newtable; 1655 int n, newsize = oldsize * 2; 1656 |
1598 if (newsize < nextarg + 1) 1599 newsize = nextarg + 1; | 1657 if (newsize < types->nextarg + 1) 1658 newsize = types->nextarg + 1; |
1600 if (oldsize == STATIC_ARG_TBL_SIZE) { 1601 if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL) 1602 abort(); /* XXX handle better */ 1603 bcopy(oldtable, newtable, oldsize * sizeof(enum typeid)); 1604 } else { 1605 newtable = reallocf(oldtable, newsize * sizeof(enum typeid)); 1606 if (newtable == NULL) 1607 abort(); /* XXX handle better */ 1608 } 1609 for (n = oldsize; n < newsize; n++) 1610 newtable[n] = T_UNUSED; 1611 | 1659 if (oldsize == STATIC_ARG_TBL_SIZE) { 1660 if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL) 1661 abort(); /* XXX handle better */ 1662 bcopy(oldtable, newtable, oldsize * sizeof(enum typeid)); 1663 } else { 1664 newtable = reallocf(oldtable, newsize * sizeof(enum typeid)); 1665 if (newtable == NULL) 1666 abort(); /* XXX handle better */ 1667 } 1668 for (n = oldsize; n < newsize; n++) 1669 newtable[n] = T_UNUSED; 1670 |
1612 *typetable = newtable; 1613 *tablesize = newsize; | 1671 types->table = newtable; 1672 types->tablesize = newsize; |
1614} 1615 1616 1617#ifndef NO_FLOATING_POINT 1618 1619static int 1620exponent(char *p0, int exp, int fmtch) 1621{ --- 33 unchanged lines hidden --- | 1673} 1674 1675 1676#ifndef NO_FLOATING_POINT 1677 1678static int 1679exponent(char *p0, int exp, int fmtch) 1680{ --- 33 unchanged lines hidden --- |