| OLD | NEW |
| 1 /************************************************************************* | 1 /************************************************************************* |
| 2 * | 2 * |
| 3 * $Id$ | 3 * $Id$ |
| 4 * | 4 * |
| 5 * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. | 5 * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. |
| 6 * | 6 * |
| 7 * Permission to use, copy, modify, and distribute this software for any | 7 * Permission to use, copy, modify, and distribute this software for any |
| 8 * purpose with or without fee is hereby granted, provided that the above | 8 * purpose with or without fee is hereby granted, provided that the above |
| 9 * copyright notice and this permission notice appear in all copies. | 9 * copyright notice and this permission notice appear in all copies. |
| 10 * | 10 * |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 #if !defined(TRIO_COMPILER_SUPPORTS_C99) | 92 #if !defined(TRIO_COMPILER_SUPPORTS_C99) |
| 93 # define isblank(x) (((x)==32) || ((x)==9)) | 93 # define isblank(x) (((x)==32) || ((x)==9)) |
| 94 #endif | 94 #endif |
| 95 #if defined(TRIO_COMPILER_ANCIENT) | 95 #if defined(TRIO_COMPILER_ANCIENT) |
| 96 # include <varargs.h> | 96 # include <varargs.h> |
| 97 #else | 97 #else |
| 98 # include <stdarg.h> | 98 # include <stdarg.h> |
| 99 #endif | 99 #endif |
| 100 #include <stddef.h> | 100 #include <stddef.h> |
| 101 | 101 |
| 102 #ifdef HAVE_ERRNO_H | 102 #if defined( HAVE_ERRNO_H ) || defined( __VMS ) |
| 103 #include <errno.h> | 103 #include <errno.h> |
| 104 #endif | 104 #endif |
| 105 | 105 |
| 106 #ifndef NULL | 106 #ifndef NULL |
| 107 # define NULL 0 | 107 # define NULL 0 |
| 108 #endif | 108 #endif |
| 109 #define NIL ((char)0) | 109 #define NIL ((char)0) |
| 110 #ifndef FALSE | 110 #ifndef FALSE |
| 111 # define FALSE (1 == 0) | 111 # define FALSE (1 == 0) |
| 112 # define TRUE (! FALSE) | 112 # define TRUE (! FALSE) |
| 113 #endif | 113 #endif |
| 114 #define BOOLEAN_T int | 114 #define BOOLEAN_T int |
| 115 | 115 |
| 116 /* mincore() can be used for debugging purposes */ | 116 /* mincore() can be used for debugging purposes */ |
| 117 #define VALID(x) (NULL != (x)) | 117 #define VALID(x) (NULL != (x)) |
| 118 | 118 |
| 119 #if TRIO_ERRORS | 119 #if TRIO_ERRORS |
| 120 /* | 120 /* |
| 121 * Encode the error code and the position. This is decoded | 121 * Encode the error code and the position. This is decoded |
| 122 * with TRIO_ERROR_CODE and TRIO_ERROR_POSITION. | 122 * with TRIO_ERROR_CODE and TRIO_ERROR_POSITION. |
| 123 */ | 123 */ |
| 124 # define TRIO_ERROR_RETURN(x,y) (- ((x) + ((y) << 8))) | 124 # define TRIO_ERROR_RETURN(x,y) (- ((x) + ((y) << 8))) |
| 125 #else | 125 #else |
| 126 # define TRIO_ERROR_RETURN(x,y) (-1) | 126 # define TRIO_ERROR_RETURN(x,y) (-1) |
| 127 #endif | 127 #endif |
| 128 | 128 |
| 129 #ifndef VA_LIST_IS_ARRAY |
| 130 #define TRIO_VA_LIST_PTR va_list * |
| 131 #define TRIO_VA_LIST_ADDR(l) (&(l)) |
| 132 #define TRIO_VA_LIST_DEREF(l) (*(l)) |
| 133 #else |
| 134 #define TRIO_VA_LIST_PTR va_list |
| 135 #define TRIO_VA_LIST_ADDR(l) (l) |
| 136 #define TRIO_VA_LIST_DEREF(l) (l) |
| 137 #endif |
| 138 |
| 129 typedef unsigned long trio_flags_t; | 139 typedef unsigned long trio_flags_t; |
| 130 | 140 |
| 131 | 141 |
| 132 /************************************************************************* | 142 /************************************************************************* |
| 133 * Platform specific definitions | 143 * Platform specific definitions |
| 134 */ | 144 */ |
| 135 #if defined(TRIO_PLATFORM_UNIX) | 145 #if defined(TRIO_PLATFORM_UNIX) || defined(TRIO_PLATFORM_OS400) |
| 136 # include <unistd.h> | 146 # include <unistd.h> |
| 137 # include <signal.h> | 147 # include <signal.h> |
| 138 # include <locale.h> | 148 # include <locale.h> |
| 139 # define USE_LOCALE | 149 # define USE_LOCALE |
| 140 #endif /* TRIO_PLATFORM_UNIX */ | 150 #endif /* TRIO_PLATFORM_UNIX */ |
| 141 #if defined(TRIO_PLATFORM_VMS) | 151 #if defined(TRIO_PLATFORM_VMS) |
| 142 # include <unistd.h> | 152 # include <unistd.h> |
| 143 #endif | 153 #endif |
| 144 #if defined(TRIO_PLATFORM_WIN32) | 154 #if defined(TRIO_PLATFORM_WIN32) |
| 145 # if defined(_WIN32_WCE) | 155 # if defined(_WIN32_WCE) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 typedef unsigned long long int trio_ulonglong_t; | 211 typedef unsigned long long int trio_ulonglong_t; |
| 202 #elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT) | 212 #elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT) |
| 203 typedef signed __int64 trio_longlong_t; | 213 typedef signed __int64 trio_longlong_t; |
| 204 typedef unsigned __int64 trio_ulonglong_t; | 214 typedef unsigned __int64 trio_ulonglong_t; |
| 205 #else | 215 #else |
| 206 typedef TRIO_SIGNED long int trio_longlong_t; | 216 typedef TRIO_SIGNED long int trio_longlong_t; |
| 207 typedef unsigned long int trio_ulonglong_t; | 217 typedef unsigned long int trio_ulonglong_t; |
| 208 #endif | 218 #endif |
| 209 | 219 |
| 210 /* Maximal and fixed integer types */ | 220 /* Maximal and fixed integer types */ |
| 211 #if defined(TRIO_COMPILER_SUPPORTS_C99) | 221 #if defined(TRIO_COMPILER_SUPPORTS_C99) && !defined( __VMS ) |
| 212 # include <stdint.h> | 222 # include <stdint.h> |
| 213 typedef intmax_t trio_intmax_t; | 223 typedef intmax_t trio_intmax_t; |
| 214 typedef uintmax_t trio_uintmax_t; | 224 typedef uintmax_t trio_uintmax_t; |
| 215 typedef int8_t trio_int8_t; | 225 typedef int8_t trio_int8_t; |
| 216 typedef int16_t trio_int16_t; | 226 typedef int16_t trio_int16_t; |
| 217 typedef int32_t trio_int32_t; | 227 typedef int32_t trio_int32_t; |
| 218 typedef int64_t trio_int64_t; | 228 typedef int64_t trio_int64_t; |
| 219 #elif defined(TRIO_COMPILER_SUPPORTS_UNIX98) | 229 #elif defined(TRIO_COMPILER_SUPPORTS_UNIX98) || defined( __VMS ) |
| 220 # include <inttypes.h> | 230 # include <inttypes.h> |
| 231 #ifdef __VMS |
| 232 typedef long long int intmax_t; |
| 233 typedef unsigned long long int uintmax_t; |
| 234 #endif |
| 221 typedef intmax_t trio_intmax_t; | 235 typedef intmax_t trio_intmax_t; |
| 222 typedef uintmax_t trio_uintmax_t; | 236 typedef uintmax_t trio_uintmax_t; |
| 223 typedef int8_t trio_int8_t; | 237 typedef int8_t trio_int8_t; |
| 224 typedef int16_t trio_int16_t; | 238 typedef int16_t trio_int16_t; |
| 225 typedef int32_t trio_int32_t; | 239 typedef int32_t trio_int32_t; |
| 226 typedef int64_t trio_int64_t; | 240 typedef int64_t trio_int64_t; |
| 227 #elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT) | 241 #elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT) |
| 228 typedef trio_longlong_t trio_intmax_t; | 242 typedef trio_longlong_t trio_intmax_t; |
| 229 typedef trio_ulonglong_t trio_uintmax_t; | 243 typedef trio_ulonglong_t trio_uintmax_t; |
| 230 typedef __int8 trio_int8_t; | 244 typedef __int8 trio_int8_t; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 #define POINTER_WIDTH ((sizeof("0x") - 1) + sizeof(trio_pointer_t) * CHAR_BIT /
4) | 314 #define POINTER_WIDTH ((sizeof("0x") - 1) + sizeof(trio_pointer_t) * CHAR_BIT /
4) |
| 301 | 315 |
| 302 /* Infinite and Not-A-Number for floating-point */ | 316 /* Infinite and Not-A-Number for floating-point */ |
| 303 #define INFINITE_LOWER "inf" | 317 #define INFINITE_LOWER "inf" |
| 304 #define INFINITE_UPPER "INF" | 318 #define INFINITE_UPPER "INF" |
| 305 #define LONG_INFINITE_LOWER "infinite" | 319 #define LONG_INFINITE_LOWER "infinite" |
| 306 #define LONG_INFINITE_UPPER "INFINITE" | 320 #define LONG_INFINITE_UPPER "INFINITE" |
| 307 #define NAN_LOWER "nan" | 321 #define NAN_LOWER "nan" |
| 308 #define NAN_UPPER "NAN" | 322 #define NAN_UPPER "NAN" |
| 309 | 323 |
| 324 #if !defined(HAVE_ISASCII) && !defined(isascii) |
| 325 #ifndef __VMS |
| 326 # define isascii(x) ((unsigned int)(x) < 128) |
| 327 #endif |
| 328 #endif |
| 329 |
| 310 /* Various constants */ | 330 /* Various constants */ |
| 311 enum { | 331 enum { |
| 312 TYPE_PRINT = 1, | 332 TYPE_PRINT = 1, |
| 313 TYPE_SCAN = 2, | 333 TYPE_SCAN = 2, |
| 314 | 334 |
| 315 /* Flags. FLAGS_LAST must be less than ULONG_MAX */ | 335 /* Flags. FLAGS_LAST must be less than ULONG_MAX */ |
| 316 FLAGS_NEW = 0, | 336 FLAGS_NEW = 0, |
| 317 FLAGS_STICKY = 1, | 337 FLAGS_STICKY = 1, |
| 318 FLAGS_SPACE = 2 * FLAGS_STICKY, | 338 FLAGS_SPACE = 2 * FLAGS_STICKY, |
| 319 FLAGS_SHOWSIGN = 2 * FLAGS_SPACE, | 339 FLAGS_SHOWSIGN = 2 * FLAGS_SPACE, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 BASE_HEX = 16, | 389 BASE_HEX = 16, |
| 370 | 390 |
| 371 /* Maximal number of allowed parameters */ | 391 /* Maximal number of allowed parameters */ |
| 372 MAX_PARAMETERS = 64, | 392 MAX_PARAMETERS = 64, |
| 373 /* Maximal number of characters in class */ | 393 /* Maximal number of characters in class */ |
| 374 MAX_CHARACTER_CLASS = UCHAR_MAX + 1, | 394 MAX_CHARACTER_CLASS = UCHAR_MAX + 1, |
| 375 | 395 |
| 376 /* Maximal string lengths for user-defined specifiers */ | 396 /* Maximal string lengths for user-defined specifiers */ |
| 377 MAX_USER_NAME = 64, | 397 MAX_USER_NAME = 64, |
| 378 MAX_USER_DATA = 256, | 398 MAX_USER_DATA = 256, |
| 379 | 399 |
| 380 /* Maximal length of locale separator strings */ | 400 /* Maximal length of locale separator strings */ |
| 381 MAX_LOCALE_SEPARATOR_LENGTH = MB_LEN_MAX, | 401 MAX_LOCALE_SEPARATOR_LENGTH = MB_LEN_MAX, |
| 382 /* Maximal number of integers in grouping */ | 402 /* Maximal number of integers in grouping */ |
| 383 MAX_LOCALE_GROUPS = 64, | 403 MAX_LOCALE_GROUPS = 64, |
| 384 | 404 |
| 385 /* Initial size of asprintf buffer */ | 405 /* Initial size of asprintf buffer */ |
| 386 DYNAMIC_START_SIZE = 32 | 406 DYNAMIC_START_SIZE = 32 |
| 387 }; | 407 }; |
| 388 | 408 |
| 389 #define NO_GROUPING ((int)CHAR_MAX) | 409 #define NO_GROUPING ((int)CHAR_MAX) |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 * Find registered user-defined specifier. | 1033 * Find registered user-defined specifier. |
| 1014 * The prev argument is used for optimization only. | 1034 * The prev argument is used for optimization only. |
| 1015 */ | 1035 */ |
| 1016 TRIO_PRIVATE trio_userdef_t * | 1036 TRIO_PRIVATE trio_userdef_t * |
| 1017 TrioFindNamespace | 1037 TrioFindNamespace |
| 1018 TRIO_ARGS2((name, prev), | 1038 TRIO_ARGS2((name, prev), |
| 1019 TRIO_CONST char *name, | 1039 TRIO_CONST char *name, |
| 1020 trio_userdef_t **prev) | 1040 trio_userdef_t **prev) |
| 1021 { | 1041 { |
| 1022 trio_userdef_t *def; | 1042 trio_userdef_t *def; |
| 1023 | 1043 |
| 1024 if (internalEnterCriticalRegion) | 1044 if (internalEnterCriticalRegion) |
| 1025 (void)internalEnterCriticalRegion(NULL); | 1045 (void)internalEnterCriticalRegion(NULL); |
| 1026 | 1046 |
| 1027 for (def = internalUserDef; def; def = def->next) | 1047 for (def = internalUserDef; def; def = def->next) |
| 1028 { | 1048 { |
| 1029 /* Case-sensitive string comparison */ | 1049 /* Case-sensitive string comparison */ |
| 1030 if (trio_equal_case(def->name, name)) | 1050 if (trio_equal_case(def->name, name)) |
| 1031 break; | 1051 break; |
| 1032 | 1052 |
| 1033 if (prev) | 1053 if (prev) |
| 1034 *prev = def; | 1054 *prev = def; |
| 1035 } | 1055 } |
| 1036 | 1056 |
| 1037 if (internalLeaveCriticalRegion) | 1057 if (internalLeaveCriticalRegion) |
| 1038 (void)internalLeaveCriticalRegion(NULL); | 1058 (void)internalLeaveCriticalRegion(NULL); |
| 1039 | 1059 |
| 1040 return def; | 1060 return def; |
| 1041 } | 1061 } |
| 1042 #endif | 1062 #endif |
| 1043 | 1063 |
| 1044 /************************************************************************* | 1064 /************************************************************************* |
| 1045 * TrioPower | 1065 * TrioPower |
| 1046 * | 1066 * |
| 1047 * Description: | 1067 * Description: |
| 1048 * Calculate pow(base, exponent), where number and exponent are integers. | 1068 * Calculate pow(base, exponent), where number and exponent are integers. |
| 1049 */ | 1069 */ |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 * | 1176 * |
| 1157 * Description: | 1177 * Description: |
| 1158 * Parse the format string | 1178 * Parse the format string |
| 1159 */ | 1179 */ |
| 1160 TRIO_PRIVATE int | 1180 TRIO_PRIVATE int |
| 1161 TrioParse | 1181 TrioParse |
| 1162 TRIO_ARGS5((type, format, parameters, arglist, argarray), | 1182 TRIO_ARGS5((type, format, parameters, arglist, argarray), |
| 1163 int type, | 1183 int type, |
| 1164 TRIO_CONST char *format, | 1184 TRIO_CONST char *format, |
| 1165 trio_parameter_t *parameters, | 1185 trio_parameter_t *parameters, |
| 1166 » va_list *arglist, | 1186 » TRIO_VA_LIST_PTR arglist, |
| 1167 trio_pointer_t *argarray) | 1187 trio_pointer_t *argarray) |
| 1168 { | 1188 { |
| 1169 /* Count the number of times a parameter is referenced */ | 1189 /* Count the number of times a parameter is referenced */ |
| 1170 unsigned short usedEntries[MAX_PARAMETERS]; | 1190 unsigned short usedEntries[MAX_PARAMETERS]; |
| 1171 /* Parameter counters */ | 1191 /* Parameter counters */ |
| 1172 int parameterPosition; | 1192 int parameterPosition; |
| 1173 int currentParam; | 1193 int currentParam; |
| 1174 int maxParam = -1; | 1194 int maxParam = -1; |
| 1175 /* Utility variables */ | 1195 /* Utility variables */ |
| 1176 trio_flags_t flags; | 1196 trio_flags_t flags; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1193 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 1213 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 1194 int charlen; | 1214 int charlen; |
| 1195 #endif | 1215 #endif |
| 1196 int save_errno; | 1216 int save_errno; |
| 1197 int i = -1; | 1217 int i = -1; |
| 1198 int num; | 1218 int num; |
| 1199 char *tmpformat; | 1219 char *tmpformat; |
| 1200 | 1220 |
| 1201 /* One and only one of arglist and argarray must be used */ | 1221 /* One and only one of arglist and argarray must be used */ |
| 1202 assert((arglist != NULL) ^ (argarray != NULL)); | 1222 assert((arglist != NULL) ^ (argarray != NULL)); |
| 1203 | 1223 |
| 1204 /* | 1224 /* |
| 1205 * The 'parameters' array is not initialized, but we need to | 1225 * The 'parameters' array is not initialized, but we need to |
| 1206 * know which entries we have used. | 1226 * know which entries we have used. |
| 1207 */ | 1227 */ |
| 1208 memset(usedEntries, 0, sizeof(usedEntries)); | 1228 memset(usedEntries, 0, sizeof(usedEntries)); |
| 1209 | 1229 |
| 1210 save_errno = errno; | 1230 save_errno = errno; |
| 1211 index = 0; | 1231 index = 0; |
| 1212 parameterPosition = 0; | 1232 parameterPosition = 0; |
| 1213 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 1233 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 1214 (void)mblen(NULL, 0); | 1234 (void)mblen(NULL, 0); |
| 1215 #endif | 1235 #endif |
| 1216 | 1236 |
| 1217 while (format[index]) | 1237 while (format[index]) |
| 1218 { | 1238 { |
| 1219 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 1239 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 1220 if (! isascii(format[index])) | 1240 if (! isascii(format[index])) |
| 1221 { | 1241 { |
| 1222 /* | 1242 /* |
| 1223 * Multibyte characters cannot be legal specifiers or | 1243 * Multibyte characters cannot be legal specifiers or |
| 1224 * modifiers, so we skip over them. | 1244 * modifiers, so we skip over them. |
| 1225 */ | 1245 */ |
| 1226 charlen = mblen(&format[index], MB_LEN_MAX); | 1246 charlen = mblen(&format[index], MB_LEN_MAX); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 break; | 1304 break; |
| 1285 | 1305 |
| 1286 case QUALIFIER_DOT: | 1306 case QUALIFIER_DOT: |
| 1287 if (dots == 0) /* Precision */ | 1307 if (dots == 0) /* Precision */ |
| 1288 { | 1308 { |
| 1289 dots++; | 1309 dots++; |
| 1290 | 1310 |
| 1291 /* Skip if no precision */ | 1311 /* Skip if no precision */ |
| 1292 if (QUALIFIER_DOT == format[index]) | 1312 if (QUALIFIER_DOT == format[index]) |
| 1293 break; | 1313 break; |
| 1294 » » | 1314 |
| 1295 /* After the first dot we have the precision */ | 1315 /* After the first dot we have the precision */ |
| 1296 flags |= FLAGS_PRECISION; | 1316 flags |= FLAGS_PRECISION; |
| 1297 if ((QUALIFIER_STAR == format[index]) | 1317 if ((QUALIFIER_STAR == format[index]) |
| 1298 #if defined(QUALIFIER_PARAM) | 1318 #if defined(QUALIFIER_PARAM) |
| 1299 || (QUALIFIER_PARAM == format[index]) | 1319 || (QUALIFIER_PARAM == format[index]) |
| 1300 #endif | 1320 #endif |
| 1301 ) | 1321 ) |
| 1302 { | 1322 { |
| 1303 index++; | 1323 index++; |
| 1304 flags |= FLAGS_PRECISION_PARAMETER; | 1324 flags |= FLAGS_PRECISION_PARAMETER; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1329 { | 1349 { |
| 1330 precision = trio_to_long(&format[index], | 1350 precision = trio_to_long(&format[index], |
| 1331 &tmpformat, | 1351 &tmpformat, |
| 1332 BASE_DECIMAL); | 1352 BASE_DECIMAL); |
| 1333 index = (int)(tmpformat - format); | 1353 index = (int)(tmpformat - format); |
| 1334 } | 1354 } |
| 1335 } | 1355 } |
| 1336 else if (dots == 1) /* Base */ | 1356 else if (dots == 1) /* Base */ |
| 1337 { | 1357 { |
| 1338 dots++; | 1358 dots++; |
| 1339 » » | 1359 |
| 1340 /* After the second dot we have the base */ | 1360 /* After the second dot we have the base */ |
| 1341 flags |= FLAGS_BASE; | 1361 flags |= FLAGS_BASE; |
| 1342 if ((QUALIFIER_STAR == format[index]) | 1362 if ((QUALIFIER_STAR == format[index]) |
| 1343 #if defined(QUALIFIER_PARAM) | 1363 #if defined(QUALIFIER_PARAM) |
| 1344 || (QUALIFIER_PARAM == format[index]) | 1364 || (QUALIFIER_PARAM == format[index]) |
| 1345 #endif | 1365 #endif |
| 1346 ) | 1366 ) |
| 1347 { | 1367 { |
| 1348 index++; | 1368 index++; |
| 1349 flags |= FLAGS_BASE_PARAMETER; | 1369 flags |= FLAGS_BASE_PARAMETER; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 varsize = sizeof(trio_int16_t); | 1548 varsize = sizeof(trio_int16_t); |
| 1529 index += 2; | 1549 index += 2; |
| 1530 } | 1550 } |
| 1531 else if (format[index] == '8') | 1551 else if (format[index] == '8') |
| 1532 { | 1552 { |
| 1533 varsize = sizeof(trio_int8_t); | 1553 varsize = sizeof(trio_int8_t); |
| 1534 index++; | 1554 index++; |
| 1535 } | 1555 } |
| 1536 else | 1556 else |
| 1537 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); | 1557 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); |
| 1538 » » | 1558 |
| 1539 flags |= FLAGS_FIXED_SIZE; | 1559 flags |= FLAGS_FIXED_SIZE; |
| 1540 break; | 1560 break; |
| 1541 #endif | 1561 #endif |
| 1542 | 1562 |
| 1543 #if defined(QUALIFIER_WIDECHAR) | 1563 #if defined(QUALIFIER_WIDECHAR) |
| 1544 case QUALIFIER_WIDECHAR: | 1564 case QUALIFIER_WIDECHAR: |
| 1545 flags |= FLAGS_WIDECHAR; | 1565 flags |= FLAGS_WIDECHAR; |
| 1546 break; | 1566 break; |
| 1547 #endif | 1567 #endif |
| 1548 | 1568 |
| 1549 #if defined(QUALIFIER_SIZE_T_UPPER) | 1569 #if defined(QUALIFIER_SIZE_T_UPPER) |
| 1550 case QUALIFIER_SIZE_T_UPPER: | 1570 case QUALIFIER_SIZE_T_UPPER: |
| 1551 break; | 1571 break; |
| 1552 #endif | 1572 #endif |
| 1553 | 1573 |
| 1554 #if defined(QUALIFIER_QUOTE) | 1574 #if defined(QUALIFIER_QUOTE) |
| 1555 case QUALIFIER_QUOTE: | 1575 case QUALIFIER_QUOTE: |
| 1556 flags |= FLAGS_QUOTE; | 1576 flags |= FLAGS_QUOTE; |
| 1557 break; | 1577 break; |
| 1558 #endif | 1578 #endif |
| 1559 | 1579 |
| 1560 #if defined(QUALIFIER_STICKY) | 1580 #if defined(QUALIFIER_STICKY) |
| 1561 case QUALIFIER_STICKY: | 1581 case QUALIFIER_STICKY: |
| 1562 flags |= FLAGS_STICKY; | 1582 flags |= FLAGS_STICKY; |
| 1563 gotSticky = TRUE; | 1583 gotSticky = TRUE; |
| 1564 break; | 1584 break; |
| 1565 #endif | 1585 #endif |
| 1566 » » | 1586 |
| 1567 #if defined(QUALIFIER_VARSIZE) | 1587 #if defined(QUALIFIER_VARSIZE) |
| 1568 case QUALIFIER_VARSIZE: | 1588 case QUALIFIER_VARSIZE: |
| 1569 flags |= FLAGS_VARSIZE_PARAMETER; | 1589 flags |= FLAGS_VARSIZE_PARAMETER; |
| 1570 parameterPosition++; | 1590 parameterPosition++; |
| 1571 if (positional) | 1591 if (positional) |
| 1572 varsize = parameterPosition; | 1592 varsize = parameterPosition; |
| 1573 else | 1593 else |
| 1574 { | 1594 { |
| 1575 varsize = currentParam; | 1595 varsize = currentParam; |
| 1576 currentParam = varsize + 1; | 1596 currentParam = varsize + 1; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 base = pos++; | 1641 base = pos++; |
| 1622 } | 1642 } |
| 1623 if (flags & FLAGS_VARSIZE_PARAMETER) | 1643 if (flags & FLAGS_VARSIZE_PARAMETER) |
| 1624 { | 1644 { |
| 1625 usedEntries[varsize] += 1; | 1645 usedEntries[varsize] += 1; |
| 1626 parameters[pos].type = FORMAT_PARAMETER; | 1646 parameters[pos].type = FORMAT_PARAMETER; |
| 1627 parameters[pos].flags = 0; | 1647 parameters[pos].flags = 0; |
| 1628 indices[varsize] = pos; | 1648 indices[varsize] = pos; |
| 1629 varsize = pos++; | 1649 varsize = pos++; |
| 1630 } | 1650 } |
| 1631 » | 1651 |
| 1632 indices[currentParam] = pos; | 1652 indices[currentParam] = pos; |
| 1633 » | 1653 |
| 1634 switch (format[index++]) | 1654 switch (format[index++]) |
| 1635 { | 1655 { |
| 1636 #if defined(SPECIFIER_CHAR_UPPER) | 1656 #if defined(SPECIFIER_CHAR_UPPER) |
| 1637 case SPECIFIER_CHAR_UPPER: | 1657 case SPECIFIER_CHAR_UPPER: |
| 1638 flags |= FLAGS_WIDECHAR; | 1658 flags |= FLAGS_WIDECHAR; |
| 1639 /* FALLTHROUGH */ | 1659 /* FALLTHROUGH */ |
| 1640 #endif | 1660 #endif |
| 1641 case SPECIFIER_CHAR: | 1661 case SPECIFIER_CHAR: |
| 1642 if (flags & FLAGS_LONG) | 1662 if (flags & FLAGS_LONG) |
| 1643 flags |= FLAGS_WIDECHAR; | 1663 flags |= FLAGS_WIDECHAR; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 if (--depth <= 0) | 1702 if (--depth <= 0) |
| 1683 { | 1703 { |
| 1684 index++; | 1704 index++; |
| 1685 break; | 1705 break; |
| 1686 } | 1706 } |
| 1687 } | 1707 } |
| 1688 index++; | 1708 index++; |
| 1689 } | 1709 } |
| 1690 } | 1710 } |
| 1691 break; | 1711 break; |
| 1692 » | 1712 |
| 1693 case SPECIFIER_INTEGER: | 1713 case SPECIFIER_INTEGER: |
| 1694 parameters[pos].type = FORMAT_INT; | 1714 parameters[pos].type = FORMAT_INT; |
| 1695 break; | 1715 break; |
| 1696 » | 1716 |
| 1697 case SPECIFIER_UNSIGNED: | 1717 case SPECIFIER_UNSIGNED: |
| 1698 flags |= FLAGS_UNSIGNED; | 1718 flags |= FLAGS_UNSIGNED; |
| 1699 parameters[pos].type = FORMAT_INT; | 1719 parameters[pos].type = FORMAT_INT; |
| 1700 break; | 1720 break; |
| 1701 | 1721 |
| 1702 case SPECIFIER_DECIMAL: | 1722 case SPECIFIER_DECIMAL: |
| 1703 /* Disable base modifier */ | 1723 /* Disable base modifier */ |
| 1704 flags &= ~FLAGS_BASE_PARAMETER; | 1724 flags &= ~FLAGS_BASE_PARAMETER; |
| 1705 base = BASE_DECIMAL; | 1725 base = BASE_DECIMAL; |
| 1706 parameters[pos].type = FORMAT_INT; | 1726 parameters[pos].type = FORMAT_INT; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 case SPECIFIER_ERRNO: | 1806 case SPECIFIER_ERRNO: |
| 1787 parameters[pos].type = FORMAT_ERRNO; | 1807 parameters[pos].type = FORMAT_ERRNO; |
| 1788 break; | 1808 break; |
| 1789 #endif | 1809 #endif |
| 1790 | 1810 |
| 1791 #if defined(SPECIFIER_USER_DEFINED_BEGIN) | 1811 #if defined(SPECIFIER_USER_DEFINED_BEGIN) |
| 1792 case SPECIFIER_USER_DEFINED_BEGIN: | 1812 case SPECIFIER_USER_DEFINED_BEGIN: |
| 1793 { | 1813 { |
| 1794 unsigned int max; | 1814 unsigned int max; |
| 1795 int without_namespace = TRUE; | 1815 int without_namespace = TRUE; |
| 1796 » » | 1816 |
| 1797 parameters[pos].type = FORMAT_USER_DEFINED; | 1817 parameters[pos].type = FORMAT_USER_DEFINED; |
| 1798 parameters[pos].user_name[0] = NIL; | 1818 parameters[pos].user_name[0] = NIL; |
| 1799 tmpformat = (char *)&format[index]; | 1819 tmpformat = (char *)&format[index]; |
| 1800 » | 1820 |
| 1801 while ((ch = format[index])) | 1821 while ((ch = format[index])) |
| 1802 { | 1822 { |
| 1803 index++; | 1823 index++; |
| 1804 if (ch == SPECIFIER_USER_DEFINED_END) | 1824 if (ch == SPECIFIER_USER_DEFINED_END) |
| 1805 { | 1825 { |
| 1806 if (without_namespace) | 1826 if (without_namespace) |
| 1807 { | 1827 { |
| 1808 /* We must get the handle first */ | 1828 /* We must get the handle first */ |
| 1809 parameters[pos].type = FORMAT_PARAMETER; | 1829 parameters[pos].type = FORMAT_PARAMETER; |
| 1810 parameters[pos].indexAfterSpecifier = index; | 1830 parameters[pos].indexAfterSpecifier = index; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1838 max, | 1858 max, |
| 1839 tmpformat); | 1859 tmpformat); |
| 1840 tmpformat = (char *)&format[index]; | 1860 tmpformat = (char *)&format[index]; |
| 1841 } | 1861 } |
| 1842 } | 1862 } |
| 1843 if (ch != SPECIFIER_USER_DEFINED_END) | 1863 if (ch != SPECIFIER_USER_DEFINED_END) |
| 1844 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); | 1864 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); |
| 1845 } | 1865 } |
| 1846 break; | 1866 break; |
| 1847 #endif /* defined(SPECIFIER_USER_DEFINED_BEGIN) */ | 1867 #endif /* defined(SPECIFIER_USER_DEFINED_BEGIN) */ |
| 1848 » | 1868 |
| 1849 default: | 1869 default: |
| 1850 /* Bail out completely to make the error more obvious */ | 1870 /* Bail out completely to make the error more obvious */ |
| 1851 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); | 1871 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); |
| 1852 } | 1872 } |
| 1853 | 1873 |
| 1854 /* Count the number of times this entry has been used */ | 1874 /* Count the number of times this entry has been used */ |
| 1855 usedEntries[currentParam] += 1; | 1875 usedEntries[currentParam] += 1; |
| 1856 » | 1876 |
| 1857 /* Find last sticky parameters */ | 1877 /* Find last sticky parameters */ |
| 1858 if (gotSticky && !(flags & FLAGS_STICKY)) | 1878 if (gotSticky && !(flags & FLAGS_STICKY)) |
| 1859 { | 1879 { |
| 1860 for (i = pos - 1; i >= 0; i--) | 1880 for (i = pos - 1; i >= 0; i--) |
| 1861 { | 1881 { |
| 1862 if (parameters[i].type == FORMAT_PARAMETER) | 1882 if (parameters[i].type == FORMAT_PARAMETER) |
| 1863 continue; | 1883 continue; |
| 1864 if ((parameters[i].flags & FLAGS_STICKY) && | 1884 if ((parameters[i].flags & FLAGS_STICKY) && |
| 1865 (parameters[i].type == parameters[pos].type)) | 1885 (parameters[i].type == parameters[pos].type)) |
| 1866 { | 1886 { |
| 1867 /* Do not overwrite current qualifiers */ | 1887 /* Do not overwrite current qualifiers */ |
| 1868 flags |= (parameters[i].flags & (unsigned long)~FLAGS_STIC
KY); | 1888 flags |= (parameters[i].flags & (unsigned long)~FLAGS_STIC
KY); |
| 1869 if (width == NO_WIDTH) | 1889 if (width == NO_WIDTH) |
| 1870 width = parameters[i].width; | 1890 width = parameters[i].width; |
| 1871 if (precision == NO_PRECISION) | 1891 if (precision == NO_PRECISION) |
| 1872 precision = parameters[i].precision; | 1892 precision = parameters[i].precision; |
| 1873 if (base == NO_BASE) | 1893 if (base == NO_BASE) |
| 1874 base = parameters[i].base; | 1894 base = parameters[i].base; |
| 1875 break; | 1895 break; |
| 1876 } | 1896 } |
| 1877 } | 1897 } |
| 1878 } | 1898 } |
| 1879 » | 1899 |
| 1880 parameters[pos].indexAfterSpecifier = index; | 1900 parameters[pos].indexAfterSpecifier = index; |
| 1881 parameters[pos].flags = flags; | 1901 parameters[pos].flags = flags; |
| 1882 parameters[pos].width = width; | 1902 parameters[pos].width = width; |
| 1883 parameters[pos].precision = precision; | 1903 parameters[pos].precision = precision; |
| 1884 parameters[pos].base = (base == NO_BASE) ? BASE_DECIMAL : base; | 1904 parameters[pos].base = (base == NO_BASE) ? BASE_DECIMAL : base; |
| 1885 parameters[pos].varsize = varsize; | 1905 parameters[pos].varsize = varsize; |
| 1886 pos++; | 1906 pos++; |
| 1887 » | 1907 |
| 1888 if (! positional) | 1908 if (! positional) |
| 1889 parameterPosition++; | 1909 parameterPosition++; |
| 1890 » | 1910 |
| 1891 } /* if identifier */ | 1911 } /* if identifier */ |
| 1892 | 1912 |
| 1893 } /* while format characters left */ | 1913 } /* while format characters left */ |
| 1894 | 1914 |
| 1895 for (num = 0; num <= maxParam; num++) | 1915 for (num = 0; num <= maxParam; num++) |
| 1896 { | 1916 { |
| 1897 if (usedEntries[num] != 1) | 1917 if (usedEntries[num] != 1) |
| 1898 { | 1918 { |
| 1899 if (usedEntries[num] == 0) /* gap detected */ | 1919 if (usedEntries[num] == 0) /* gap detected */ |
| 1900 return TRIO_ERROR_RETURN(TRIO_EGAP, num); | 1920 return TRIO_ERROR_RETURN(TRIO_EGAP, num); |
| 1901 else /* double references detected */ | 1921 else /* double references detected */ |
| 1902 return TRIO_ERROR_RETURN(TRIO_EDBLREF, num); | 1922 return TRIO_ERROR_RETURN(TRIO_EDBLREF, num); |
| 1903 } | 1923 } |
| 1904 | 1924 |
| 1905 i = indices[num]; | 1925 i = indices[num]; |
| 1906 | 1926 |
| 1907 /* | 1927 /* |
| 1908 * FORMAT_PARAMETERS are only present if they must be read, | 1928 * FORMAT_PARAMETERS are only present if they must be read, |
| 1909 * so it makes no sense to check the ignore flag (besides, | 1929 * so it makes no sense to check the ignore flag (besides, |
| 1910 * the flags variable is not set for that particular type) | 1930 * the flags variable is not set for that particular type) |
| 1911 */ | 1931 */ |
| 1912 if ((parameters[i].type != FORMAT_PARAMETER) && | 1932 if ((parameters[i].type != FORMAT_PARAMETER) && |
| 1913 (parameters[i].flags & FLAGS_IGNORE)) | 1933 (parameters[i].flags & FLAGS_IGNORE)) |
| 1914 continue; /* for all arguments */ | 1934 continue; /* for all arguments */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1934 * intmax_t | 1954 * intmax_t |
| 1935 */ | 1955 */ |
| 1936 switch (parameters[i].type) | 1956 switch (parameters[i].type) |
| 1937 { | 1957 { |
| 1938 case FORMAT_GROUP: | 1958 case FORMAT_GROUP: |
| 1939 case FORMAT_STRING: | 1959 case FORMAT_STRING: |
| 1940 #if TRIO_WIDECHAR | 1960 #if TRIO_WIDECHAR |
| 1941 if (flags & FLAGS_WIDECHAR) | 1961 if (flags & FLAGS_WIDECHAR) |
| 1942 { | 1962 { |
| 1943 parameters[i].data.wstring = (argarray == NULL) | 1963 parameters[i].data.wstring = (argarray == NULL) |
| 1944 » » ? va_arg(*arglist, trio_wchar_t *) | 1964 » » ? va_arg(TRIO_VA_LIST_DEREF(arglist), trio_wchar_t *) |
| 1945 : (trio_wchar_t *)(argarray[num]); | 1965 : (trio_wchar_t *)(argarray[num]); |
| 1946 } | 1966 } |
| 1947 else | 1967 else |
| 1948 #endif | 1968 #endif |
| 1949 { | 1969 { |
| 1950 parameters[i].data.string = (argarray == NULL) | 1970 parameters[i].data.string = (argarray == NULL) |
| 1951 » » ? va_arg(*arglist, char *) | 1971 » » ? va_arg(TRIO_VA_LIST_DEREF(arglist), char *) |
| 1952 : (char *)(argarray[num]); | 1972 : (char *)(argarray[num]); |
| 1953 } | 1973 } |
| 1954 break; | 1974 break; |
| 1955 | 1975 |
| 1956 #if defined(FORMAT_USER_DEFINED) | 1976 #if defined(FORMAT_USER_DEFINED) |
| 1957 case FORMAT_USER_DEFINED: | 1977 case FORMAT_USER_DEFINED: |
| 1958 #endif | 1978 #endif |
| 1959 case FORMAT_POINTER: | 1979 case FORMAT_POINTER: |
| 1960 case FORMAT_COUNT: | 1980 case FORMAT_COUNT: |
| 1961 case FORMAT_UNKNOWN: | 1981 case FORMAT_UNKNOWN: |
| 1962 parameters[i].data.pointer = (argarray == NULL) | 1982 parameters[i].data.pointer = (argarray == NULL) |
| 1963 » ? va_arg(*arglist, trio_pointer_t ) | 1983 » ? va_arg(TRIO_VA_LIST_DEREF(arglist), trio_pointer_t ) |
| 1964 : argarray[num]; | 1984 : argarray[num]; |
| 1965 break; | 1985 break; |
| 1966 | 1986 |
| 1967 case FORMAT_CHAR: | 1987 case FORMAT_CHAR: |
| 1968 case FORMAT_INT: | 1988 case FORMAT_INT: |
| 1969 if (TYPE_SCAN == type) | 1989 if (TYPE_SCAN == type) |
| 1970 { | 1990 { |
| 1971 if (argarray == NULL) | 1991 if (argarray == NULL) |
| 1972 parameters[i].data.pointer = | 1992 parameters[i].data.pointer = |
| 1973 (trio_pointer_t)va_arg(*arglist, trio_pointer_t); | 1993 (trio_pointer_t)va_arg(TRIO_VA_LIST_DEREF(arglist), trio_point
er_t); |
| 1974 else | 1994 else |
| 1975 { | 1995 { |
| 1976 if (parameters[i].type == FORMAT_CHAR) | 1996 if (parameters[i].type == FORMAT_CHAR) |
| 1977 parameters[i].data.pointer = | 1997 parameters[i].data.pointer = |
| 1978 (trio_pointer_t)((char *)argarray[num]); | 1998 (trio_pointer_t)((char *)argarray[num]); |
| 1979 else if (parameters[i].flags & FLAGS_SHORT) | 1999 else if (parameters[i].flags & FLAGS_SHORT) |
| 1980 parameters[i].data.pointer = | 2000 parameters[i].data.pointer = |
| 1981 (trio_pointer_t)((short *)argarray[num]); | 2001 (trio_pointer_t)((short *)argarray[num]); |
| 1982 else | 2002 else |
| 1983 parameters[i].data.pointer = | 2003 parameters[i].data.pointer = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2002 * big-endian, then this will fail. | 2022 * big-endian, then this will fail. |
| 2003 */ | 2023 */ |
| 2004 varsize = (int)parameters[parameters[i].varsize].data.numb
er.as_unsigned; | 2024 varsize = (int)parameters[parameters[i].varsize].data.numb
er.as_unsigned; |
| 2005 } | 2025 } |
| 2006 else | 2026 else |
| 2007 { | 2027 { |
| 2008 /* Used for the I<bits> modifiers */ | 2028 /* Used for the I<bits> modifiers */ |
| 2009 varsize = parameters[i].varsize; | 2029 varsize = parameters[i].varsize; |
| 2010 } | 2030 } |
| 2011 parameters[i].flags &= ~FLAGS_ALL_VARSIZES; | 2031 parameters[i].flags &= ~FLAGS_ALL_VARSIZES; |
| 2012 » » | 2032 |
| 2013 if (varsize <= (int)sizeof(int)) | 2033 if (varsize <= (int)sizeof(int)) |
| 2014 ; | 2034 ; |
| 2015 else if (varsize <= (int)sizeof(long)) | 2035 else if (varsize <= (int)sizeof(long)) |
| 2016 parameters[i].flags |= FLAGS_LONG; | 2036 parameters[i].flags |= FLAGS_LONG; |
| 2017 #if defined(QUALIFIER_INTMAX_T) | 2037 #if defined(QUALIFIER_INTMAX_T) |
| 2018 else if (varsize <= (int)sizeof(trio_longlong_t)) | 2038 else if (varsize <= (int)sizeof(trio_longlong_t)) |
| 2019 parameters[i].flags |= FLAGS_QUAD; | 2039 parameters[i].flags |= FLAGS_QUAD; |
| 2020 else | 2040 else |
| 2021 parameters[i].flags |= FLAGS_INTMAX_T; | 2041 parameters[i].flags |= FLAGS_INTMAX_T; |
| 2022 #else | 2042 #else |
| 2023 else | 2043 else |
| 2024 parameters[i].flags |= FLAGS_QUAD; | 2044 parameters[i].flags |= FLAGS_QUAD; |
| 2025 #endif | 2045 #endif |
| 2026 } | 2046 } |
| 2027 #endif /* defined(QUALIFIER_VARSIZE) */ | 2047 #endif /* defined(QUALIFIER_VARSIZE) */ |
| 2028 #if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER) | 2048 #if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER) |
| 2029 if (parameters[i].flags & FLAGS_SIZE_T) | 2049 if (parameters[i].flags & FLAGS_SIZE_T) |
| 2030 parameters[i].data.number.as_unsigned = (argarray == NULL) | 2050 parameters[i].data.number.as_unsigned = (argarray == NULL) |
| 2031 » » ? (trio_uintmax_t)va_arg(*arglist, size_t) | 2051 » » ? (trio_uintmax_t)va_arg(TRIO_VA_LIST_DEREF(arglist), size_t) |
| 2032 : (trio_uintmax_t)(*((size_t *)argarray[num])); | 2052 : (trio_uintmax_t)(*((size_t *)argarray[num])); |
| 2033 else | 2053 else |
| 2034 #endif | 2054 #endif |
| 2035 #if defined(QUALIFIER_PTRDIFF_T) | 2055 #if defined(QUALIFIER_PTRDIFF_T) |
| 2036 if (parameters[i].flags & FLAGS_PTRDIFF_T) | 2056 if (parameters[i].flags & FLAGS_PTRDIFF_T) |
| 2037 parameters[i].data.number.as_unsigned = (argarray == NULL) | 2057 parameters[i].data.number.as_unsigned = (argarray == NULL) |
| 2038 » » ? (trio_uintmax_t)va_arg(*arglist, ptrdiff_t) | 2058 » » ? (trio_uintmax_t)va_arg(TRIO_VA_LIST_DEREF(arglist), ptrdiff_
t) |
| 2039 : (trio_uintmax_t)(*((ptrdiff_t *)argarray[num])); | 2059 : (trio_uintmax_t)(*((ptrdiff_t *)argarray[num])); |
| 2040 else | 2060 else |
| 2041 #endif | 2061 #endif |
| 2042 #if defined(QUALIFIER_INTMAX_T) | 2062 #if defined(QUALIFIER_INTMAX_T) |
| 2043 if (parameters[i].flags & FLAGS_INTMAX_T) | 2063 if (parameters[i].flags & FLAGS_INTMAX_T) |
| 2044 parameters[i].data.number.as_unsigned = (argarray == NULL) | 2064 parameters[i].data.number.as_unsigned = (argarray == NULL) |
| 2045 » » ? (trio_uintmax_t)va_arg(*arglist, trio_intmax_t) | 2065 » » ? (trio_uintmax_t)va_arg(TRIO_VA_LIST_DEREF(arglist), trio_int
max_t) |
| 2046 : (trio_uintmax_t)(*((trio_intmax_t *)argarray[num])); | 2066 : (trio_uintmax_t)(*((trio_intmax_t *)argarray[num])); |
| 2047 else | 2067 else |
| 2048 #endif | 2068 #endif |
| 2049 if (parameters[i].flags & FLAGS_QUAD) | 2069 if (parameters[i].flags & FLAGS_QUAD) |
| 2050 parameters[i].data.number.as_unsigned = (argarray == NULL) | 2070 parameters[i].data.number.as_unsigned = (argarray == NULL) |
| 2051 » » ? (trio_uintmax_t)va_arg(*arglist, trio_ulonglong_t) | 2071 » » ? (trio_uintmax_t)va_arg(TRIO_VA_LIST_DEREF(arglist), trio_ulo
nglong_t) |
| 2052 : (trio_uintmax_t)(*((trio_ulonglong_t *)argarray[num])); | 2072 : (trio_uintmax_t)(*((trio_ulonglong_t *)argarray[num])); |
| 2053 else if (parameters[i].flags & FLAGS_LONG) | 2073 else if (parameters[i].flags & FLAGS_LONG) |
| 2054 parameters[i].data.number.as_unsigned = (argarray == NULL) | 2074 parameters[i].data.number.as_unsigned = (argarray == NULL) |
| 2055 » » ? (trio_uintmax_t)va_arg(*arglist, long) | 2075 » » ? (trio_uintmax_t)va_arg(TRIO_VA_LIST_DEREF(arglist), long) |
| 2056 : (trio_uintmax_t)(*((long *)argarray[num])); | 2076 : (trio_uintmax_t)(*((long *)argarray[num])); |
| 2057 else | 2077 else |
| 2058 { | 2078 { |
| 2059 if (argarray == NULL) | 2079 if (argarray == NULL) |
| 2060 » » parameters[i].data.number.as_unsigned = (trio_uintmax_t)va_a
rg(*arglist, int); | 2080 » » parameters[i].data.number.as_unsigned = (trio_uintmax_t)va_a
rg(TRIO_VA_LIST_DEREF(arglist), int); |
| 2061 else | 2081 else |
| 2062 { | 2082 { |
| 2063 if (parameters[i].type == FORMAT_CHAR) | 2083 if (parameters[i].type == FORMAT_CHAR) |
| 2064 parameters[i].data.number.as_unsigned = (trio_uintmax_t)
(*((char *)argarray[num])); | 2084 parameters[i].data.number.as_unsigned = (trio_uintmax_t)
(*((char *)argarray[num])); |
| 2065 else if (parameters[i].flags & FLAGS_SHORT) | 2085 else if (parameters[i].flags & FLAGS_SHORT) |
| 2066 parameters[i].data.number.as_unsigned = (trio_uintmax_t)
(*((short *)argarray[num])); | 2086 parameters[i].data.number.as_unsigned = (trio_uintmax_t)
(*((short *)argarray[num])); |
| 2067 else | 2087 else |
| 2068 parameters[i].data.number.as_unsigned = (trio_uintmax_t)
(*((int *)argarray[num])); | 2088 parameters[i].data.number.as_unsigned = (trio_uintmax_t)
(*((int *)argarray[num])); |
| 2069 } | 2089 } |
| 2070 } | 2090 } |
| 2071 } | 2091 } |
| 2072 break; | 2092 break; |
| 2073 | 2093 |
| 2074 case FORMAT_PARAMETER: | 2094 case FORMAT_PARAMETER: |
| 2075 /* | 2095 /* |
| 2076 * The parameter for the user-defined specifier is a pointer, | 2096 * The parameter for the user-defined specifier is a pointer, |
| 2077 * whereas the rest (width, precision, base) uses an integer. | 2097 * whereas the rest (width, precision, base) uses an integer. |
| 2078 */ | 2098 */ |
| 2079 if (parameters[i].flags & FLAGS_USER_DEFINED) | 2099 if (parameters[i].flags & FLAGS_USER_DEFINED) |
| 2080 parameters[i].data.pointer = (argarray == NULL) | 2100 parameters[i].data.pointer = (argarray == NULL) |
| 2081 » ? va_arg(*arglist, trio_pointer_t ) | 2101 » ? va_arg(TRIO_VA_LIST_DEREF(arglist), trio_pointer_t ) |
| 2082 : argarray[num]; | 2102 : argarray[num]; |
| 2083 else | 2103 else |
| 2084 parameters[i].data.number.as_unsigned = (argarray == NULL) | 2104 parameters[i].data.number.as_unsigned = (argarray == NULL) |
| 2085 » ? (trio_uintmax_t)va_arg(*arglist, int) | 2105 » ? (trio_uintmax_t)va_arg(TRIO_VA_LIST_DEREF(arglist), int) |
| 2086 : (trio_uintmax_t)(*((int *)argarray[num])); | 2106 : (trio_uintmax_t)(*((int *)argarray[num])); |
| 2087 break; | 2107 break; |
| 2088 | 2108 |
| 2089 case FORMAT_DOUBLE: | 2109 case FORMAT_DOUBLE: |
| 2090 if (TYPE_SCAN == type) | 2110 if (TYPE_SCAN == type) |
| 2091 { | 2111 { |
| 2092 if (parameters[i].flags & FLAGS_LONGDOUBLE) | 2112 if (parameters[i].flags & FLAGS_LONGDOUBLE) |
| 2093 parameters[i].data.longdoublePointer = (argarray == NULL) | 2113 parameters[i].data.longdoublePointer = (argarray == NULL) |
| 2094 » » ? va_arg(*arglist, trio_long_double_t *) | 2114 » » ? va_arg(TRIO_VA_LIST_DEREF(arglist), trio_long_double_t *) |
| 2095 : (trio_long_double_t *)argarray[num]; | 2115 : (trio_long_double_t *)argarray[num]; |
| 2096 else | 2116 else |
| 2097 { | 2117 { |
| 2098 if (parameters[i].flags & FLAGS_LONG) | 2118 if (parameters[i].flags & FLAGS_LONG) |
| 2099 parameters[i].data.doublePointer = (argarray == NULL) | 2119 parameters[i].data.doublePointer = (argarray == NULL) |
| 2100 » » ? va_arg(*arglist, double *) | 2120 » » ? va_arg(TRIO_VA_LIST_DEREF(arglist), double *) |
| 2101 : (double *)argarray[num]; | 2121 : (double *)argarray[num]; |
| 2102 else | 2122 else |
| 2103 parameters[i].data.doublePointer = (argarray == NULL) | 2123 parameters[i].data.doublePointer = (argarray == NULL) |
| 2104 » » ? (double *)va_arg(*arglist, float *) | 2124 » » ? (double *)va_arg(TRIO_VA_LIST_DEREF(arglist), float *) |
| 2105 : (double *)((float *)argarray[num]); | 2125 : (double *)((float *)argarray[num]); |
| 2106 } | 2126 } |
| 2107 } | 2127 } |
| 2108 else | 2128 else |
| 2109 { | 2129 { |
| 2110 if (parameters[i].flags & FLAGS_LONGDOUBLE) | 2130 if (parameters[i].flags & FLAGS_LONGDOUBLE) |
| 2111 parameters[i].data.longdoubleNumber = (argarray == NULL) | 2131 parameters[i].data.longdoubleNumber = (argarray == NULL) |
| 2112 » » ? va_arg(*arglist, trio_long_double_t) | 2132 » » ? va_arg(TRIO_VA_LIST_DEREF(arglist), trio_long_double_t) |
| 2113 : (trio_long_double_t)(*((trio_long_double_t *)argarray[num]))
; | 2133 : (trio_long_double_t)(*((trio_long_double_t *)argarray[num]))
; |
| 2114 else | 2134 else |
| 2115 { | 2135 { |
| 2116 if (argarray == NULL) | 2136 if (argarray == NULL) |
| 2117 parameters[i].data.longdoubleNumber = | 2137 parameters[i].data.longdoubleNumber = |
| 2118 » » (trio_long_double_t)va_arg(*arglist, double); | 2138 » » (trio_long_double_t)va_arg(TRIO_VA_LIST_DEREF(arglist), do
uble); |
| 2119 else | 2139 else |
| 2120 { | 2140 { |
| 2121 if (parameters[i].flags & FLAGS_SHORT) | 2141 if (parameters[i].flags & FLAGS_SHORT) |
| 2122 parameters[i].data.longdoubleNumber = | 2142 parameters[i].data.longdoubleNumber = |
| 2123 (trio_long_double_t)(*((float *)argarray[num])); | 2143 (trio_long_double_t)(*((float *)argarray[num])); |
| 2124 else | 2144 else |
| 2125 parameters[i].data.longdoubleNumber = | 2145 parameters[i].data.longdoubleNumber = |
| 2126 (trio_long_double_t)(*((double *)argarray[num])); | 2146 (trio_long_double_t)(*((double *)argarray[num])); |
| 2127 } | 2147 } |
| 2128 } | 2148 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2206 if (isNegative) | 2226 if (isNegative) |
| 2207 number = -((trio_intmax_t)number); | 2227 number = -((trio_intmax_t)number); |
| 2208 } | 2228 } |
| 2209 | 2229 |
| 2210 if (flags & FLAGS_QUAD) | 2230 if (flags & FLAGS_QUAD) |
| 2211 number &= (trio_ulonglong_t)-1; | 2231 number &= (trio_ulonglong_t)-1; |
| 2212 else if (flags & FLAGS_LONG) | 2232 else if (flags & FLAGS_LONG) |
| 2213 number &= (unsigned long)-1; | 2233 number &= (unsigned long)-1; |
| 2214 else | 2234 else |
| 2215 number &= (unsigned int)-1; | 2235 number &= (unsigned int)-1; |
| 2216 | 2236 |
| 2217 /* Build number */ | 2237 /* Build number */ |
| 2218 pointer = bufferend = &buffer[sizeof(buffer) - 1]; | 2238 pointer = bufferend = &buffer[sizeof(buffer) - 1]; |
| 2219 *pointer-- = NIL; | 2239 *pointer-- = NIL; |
| 2220 for (i = 1; i < (int)sizeof(buffer); i++) | 2240 for (i = 1; i < (int)sizeof(buffer); i++) |
| 2221 { | 2241 { |
| 2222 *pointer-- = digits[number % base]; | 2242 *pointer-- = digits[number % base]; |
| 2223 number /= base; | 2243 number /= base; |
| 2224 if (number == 0) | 2244 if (number == 0) |
| 2225 break; | 2245 break; |
| 2226 | 2246 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2253 precision -= (bufferend - pointer) - 1; | 2273 precision -= (bufferend - pointer) - 1; |
| 2254 if (precision < 0) | 2274 if (precision < 0) |
| 2255 precision = 0; | 2275 precision = 0; |
| 2256 flags |= FLAGS_NILPADDING; | 2276 flags |= FLAGS_NILPADDING; |
| 2257 } | 2277 } |
| 2258 | 2278 |
| 2259 /* Calculate padding */ | 2279 /* Calculate padding */ |
| 2260 count = (! ((flags & FLAGS_LEFTADJUST) || (precision == NO_PRECISION))) | 2280 count = (! ((flags & FLAGS_LEFTADJUST) || (precision == NO_PRECISION))) |
| 2261 ? precision | 2281 ? precision |
| 2262 : 0; | 2282 : 0; |
| 2263 | 2283 |
| 2264 /* Adjust width further */ | 2284 /* Adjust width further */ |
| 2265 if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) | 2285 if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) |
| 2266 width--; | 2286 width--; |
| 2267 if ((flags & FLAGS_ALTERNATIVE) && !isNumberZero) | 2287 if ((flags & FLAGS_ALTERNATIVE) && !isNumberZero) |
| 2268 { | 2288 { |
| 2269 switch (base) | 2289 switch (base) |
| 2270 { | 2290 { |
| 2271 case BASE_BINARY: | 2291 case BASE_BINARY: |
| 2272 case BASE_HEX: | 2292 case BASE_HEX: |
| 2273 width -= 2; | 2293 width -= 2; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2488 int width) | 2508 int width) |
| 2489 { | 2509 { |
| 2490 int size; | 2510 int size; |
| 2491 int i; | 2511 int i; |
| 2492 int ch; | 2512 int ch; |
| 2493 char *string; | 2513 char *string; |
| 2494 char buffer[MB_LEN_MAX + 1]; | 2514 char buffer[MB_LEN_MAX + 1]; |
| 2495 | 2515 |
| 2496 if (width == NO_WIDTH) | 2516 if (width == NO_WIDTH) |
| 2497 width = sizeof(buffer); | 2517 width = sizeof(buffer); |
| 2498 | 2518 |
| 2499 size = wctomb(buffer, wch); | 2519 size = wctomb(buffer, wch); |
| 2500 if ((size <= 0) || (size > width) || (buffer[0] == NIL)) | 2520 if ((size <= 0) || (size > width) || (buffer[0] == NIL)) |
| 2501 return 0; | 2521 return 0; |
| 2502 | 2522 |
| 2503 string = buffer; | 2523 string = buffer; |
| 2504 i = size; | 2524 i = size; |
| 2505 while ((width >= i) && (width-- > 0) && (i-- > 0)) | 2525 while ((width >= i) && (width-- > 0) && (i-- > 0)) |
| 2506 { | 2526 { |
| 2507 /* The ctype parameters must be an unsigned char (or EOF) */ | 2527 /* The ctype parameters must be an unsigned char (or EOF) */ |
| 2508 ch = (int)((unsigned char)(*string++)); | 2528 ch = (int)((unsigned char)(*string++)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2530 { | 2550 { |
| 2531 int length; | 2551 int length; |
| 2532 int size; | 2552 int size; |
| 2533 | 2553 |
| 2534 assert(VALID(self)); | 2554 assert(VALID(self)); |
| 2535 assert(VALID(self->OutStream)); | 2555 assert(VALID(self->OutStream)); |
| 2536 | 2556 |
| 2537 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 2557 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 2538 (void)mblen(NULL, 0); | 2558 (void)mblen(NULL, 0); |
| 2539 #endif | 2559 #endif |
| 2540 | 2560 |
| 2541 if (wstring == NULL) | 2561 if (wstring == NULL) |
| 2542 { | 2562 { |
| 2543 TrioWriteString(self, NULL, flags, width, precision); | 2563 TrioWriteString(self, NULL, flags, width, precision); |
| 2544 return; | 2564 return; |
| 2545 } | 2565 } |
| 2546 | 2566 |
| 2547 if (NO_PRECISION == precision) | 2567 if (NO_PRECISION == precision) |
| 2548 { | 2568 { |
| 2549 length = INT_MAX; | 2569 length = INT_MAX; |
| 2550 } | 2570 } |
| 2551 else | 2571 else |
| 2552 { | 2572 { |
| 2553 length = precision; | 2573 length = precision; |
| 2554 width -= length; | 2574 width -= length; |
| 2555 } | 2575 } |
| 2556 | 2576 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2631 TRIO_CONST char *digits; | 2651 TRIO_CONST char *digits; |
| 2632 char *groupingPointer; | 2652 char *groupingPointer; |
| 2633 int i; | 2653 int i; |
| 2634 int index; | 2654 int index; |
| 2635 BOOLEAN_T hasOnlyZeroes; | 2655 BOOLEAN_T hasOnlyZeroes; |
| 2636 int zeroes = 0; | 2656 int zeroes = 0; |
| 2637 register int trailingZeroes; | 2657 register int trailingZeroes; |
| 2638 BOOLEAN_T keepTrailingZeroes; | 2658 BOOLEAN_T keepTrailingZeroes; |
| 2639 BOOLEAN_T keepDecimalPoint; | 2659 BOOLEAN_T keepDecimalPoint; |
| 2640 trio_long_double_t epsilon; | 2660 trio_long_double_t epsilon; |
| 2641 | 2661 |
| 2642 assert(VALID(self)); | 2662 assert(VALID(self)); |
| 2643 assert(VALID(self->OutStream)); | 2663 assert(VALID(self->OutStream)); |
| 2644 assert(((base >= MIN_BASE) && (base <= MAX_BASE)) || (base == NO_BASE)); | 2664 assert(((base >= MIN_BASE) && (base <= MAX_BASE)) || (base == NO_BASE)); |
| 2645 | 2665 |
| 2646 /* Determine sign and look for special quantities */ | 2666 /* Determine sign and look for special quantities */ |
| 2647 switch (trio_fpclassify_and_signbit(number, &isNegative)) | 2667 switch (trio_fpclassify_and_signbit(number, &isNegative)) |
| 2648 { | 2668 { |
| 2649 case TRIO_FP_NAN: | 2669 case TRIO_FP_NAN: |
| 2650 TrioWriteString(self, | 2670 TrioWriteString(self, |
| 2651 (flags & FLAGS_UPPER) | 2671 (flags & FLAGS_UPPER) |
| 2652 ? NAN_UPPER | 2672 ? NAN_UPPER |
| 2653 : NAN_LOWER, | 2673 : NAN_LOWER, |
| 2654 flags, width, precision); | 2674 flags, width, precision); |
| 2655 return; | 2675 return; |
| 2656 | 2676 |
| 2657 case TRIO_FP_INFINITE: | 2677 case TRIO_FP_INFINITE: |
| 2658 if (isNegative) | 2678 if (isNegative) |
| 2659 { | 2679 { |
| 2660 /* Negative infinity */ | 2680 /* Negative infinity */ |
| 2661 TrioWriteString(self, | 2681 TrioWriteString(self, |
| 2662 (flags & FLAGS_UPPER) | 2682 (flags & FLAGS_UPPER) |
| 2663 ? "-" INFINITE_UPPER | 2683 ? "-" INFINITE_UPPER |
| 2664 : "-" INFINITE_LOWER, | 2684 : "-" INFINITE_LOWER, |
| 2665 flags, width, precision); | 2685 flags, width, precision); |
| 2666 return; | 2686 return; |
| 2667 } | 2687 } |
| 2668 else | 2688 else |
| 2669 { | 2689 { |
| 2670 /* Positive infinity */ | 2690 /* Positive infinity */ |
| 2671 TrioWriteString(self, | 2691 TrioWriteString(self, |
| 2672 (flags & FLAGS_UPPER) | 2692 (flags & FLAGS_UPPER) |
| 2673 ? INFINITE_UPPER | 2693 ? INFINITE_UPPER |
| 2674 : INFINITE_LOWER, | 2694 : INFINITE_LOWER, |
| 2675 flags, width, precision); | 2695 flags, width, precision); |
| 2676 return; | 2696 return; |
| 2677 } | 2697 } |
| 2678 | 2698 |
| 2679 default: | 2699 default: |
| 2680 /* Finitude */ | 2700 /* Finitude */ |
| 2681 break; | 2701 break; |
| 2682 } | 2702 } |
| 2683 | 2703 |
| 2684 /* Normal numbers */ | 2704 /* Normal numbers */ |
| 2685 if (flags & FLAGS_LONGDOUBLE) | 2705 if (flags & FLAGS_LONGDOUBLE) |
| 2686 { | 2706 { |
| 2687 baseDigits = (base == 10) | 2707 baseDigits = (base == 10) |
| 2688 ? LDBL_DIG | 2708 ? LDBL_DIG |
| 2689 : (int)floor(LDBL_MANT_DIG / TrioLogarithmBase(base)); | 2709 : (int)floor(LDBL_MANT_DIG / TrioLogarithmBase(base)); |
| 2690 epsilon = LDBL_EPSILON; | 2710 epsilon = LDBL_EPSILON; |
| 2691 } | 2711 } |
| 2692 else if (flags & FLAGS_SHORT) | 2712 else if (flags & FLAGS_SHORT) |
| 2693 { | 2713 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2721 if (isHex) | 2741 if (isHex) |
| 2722 { | 2742 { |
| 2723 keepTrailingZeroes = FALSE; | 2743 keepTrailingZeroes = FALSE; |
| 2724 precision = FLT_MANT_DIG; | 2744 precision = FLT_MANT_DIG; |
| 2725 } | 2745 } |
| 2726 else | 2746 else |
| 2727 { | 2747 { |
| 2728 precision = FLT_DIG; | 2748 precision = FLT_DIG; |
| 2729 } | 2749 } |
| 2730 } | 2750 } |
| 2731 | 2751 |
| 2732 if (isNegative) | 2752 if (isNegative) |
| 2733 number = -number; | 2753 number = -number; |
| 2734 | 2754 |
| 2735 if (isHex) | 2755 if (isHex) |
| 2736 flags |= FLAGS_FLOAT_E; | 2756 flags |= FLAGS_FLOAT_E; |
| 2737 | 2757 |
| 2738 if (flags & FLAGS_FLOAT_G) | 2758 if (flags & FLAGS_FLOAT_G) |
| 2739 { | 2759 { |
| 2740 if (precision == 0) | 2760 if (precision == 0) |
| 2741 precision = 1; | 2761 precision = 1; |
| 2742 | 2762 |
| 2743 if ((number < 1.0E-4) || (number > powl(base, | 2763 if ((number < 1.0E-4) || (number > powl(base, |
| 2744 (trio_long_double_t)precision))) | 2764 (trio_long_double_t)precision))) |
| 2745 { | 2765 { |
| 2746 /* Use scientific notation */ | 2766 /* Use scientific notation */ |
| 2747 flags |= FLAGS_FLOAT_E; | 2767 flags |= FLAGS_FLOAT_E; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2780 uExponent = (isExponentNegative) ? -exponent : exponent; | 2800 uExponent = (isExponentNegative) ? -exponent : exponent; |
| 2781 if (isHex) | 2801 if (isHex) |
| 2782 uExponent *= 4; /* log16(2) */ | 2802 uExponent *= 4; /* log16(2) */ |
| 2783 /* No thousand separators */ | 2803 /* No thousand separators */ |
| 2784 flags &= ~FLAGS_QUOTE; | 2804 flags &= ~FLAGS_QUOTE; |
| 2785 } | 2805 } |
| 2786 } | 2806 } |
| 2787 | 2807 |
| 2788 integerNumber = floorl(number); | 2808 integerNumber = floorl(number); |
| 2789 fractionNumber = number - integerNumber; | 2809 fractionNumber = number - integerNumber; |
| 2790 | 2810 |
| 2791 /* | 2811 /* |
| 2792 * Truncated number. | 2812 * Truncated number. |
| 2793 * | 2813 * |
| 2794 * Precision is number of significant digits for FLOAT_G | 2814 * Precision is number of significant digits for FLOAT_G |
| 2795 * and number of fractional digits for others. | 2815 * and number of fractional digits for others. |
| 2796 */ | 2816 */ |
| 2797 integerDigits = (integerNumber > epsilon) | 2817 integerDigits = (integerNumber > epsilon) |
| 2798 ? 1 + (int)TrioLogarithm(integerNumber, base) | 2818 ? 1 + (int)TrioLogarithm(integerNumber, base) |
| 2799 : 1; | 2819 : 1; |
| 2800 fractionDigits = ((flags & FLAGS_FLOAT_G) && (zeroes == 0)) | 2820 fractionDigits = ((flags & FLAGS_FLOAT_G) && (zeroes == 0)) |
| 2801 ? precision - integerDigits | 2821 ? precision - integerDigits |
| 2802 : zeroes + precision; | 2822 : zeroes + precision; |
| 2803 | 2823 |
| 2804 dblFractionBase = TrioPower(base, fractionDigits); | 2824 dblFractionBase = TrioPower(base, fractionDigits); |
| 2805 | 2825 |
| 2806 workNumber = number + 0.5 / dblFractionBase; | 2826 workNumber = number + 0.5 / dblFractionBase; |
| 2807 if (floorl(number) != floorl(workNumber)) | 2827 if (floorl(number) != floorl(workNumber)) |
| 2808 { | 2828 { |
| 2809 if (flags & FLAGS_FLOAT_E) | 2829 if (flags & FLAGS_FLOAT_E) |
| 2810 { | 2830 { |
| 2811 /* Adjust if number was rounded up one digit (ie. 0.99 to 1.00) */ | 2831 /* Adjust if number was rounded up one digit (ie. 0.99 to 1.00) */ |
| 2812 exponent++; | 2832 exponent++; |
| 2813 isExponentNegative = (exponent < 0); | 2833 isExponentNegative = (exponent < 0); |
| 2814 uExponent = (isExponentNegative) ? -exponent : exponent; | 2834 uExponent = (isExponentNegative) ? -exponent : exponent; |
| 2815 if (isHex) | 2835 if (isHex) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2848 integerThreshold = integerDigits; | 2868 integerThreshold = integerDigits; |
| 2849 fractionThreshold = fractionDigits - integerThreshold; | 2869 fractionThreshold = fractionDigits - integerThreshold; |
| 2850 fractionAdjust = 1.0; | 2870 fractionAdjust = 1.0; |
| 2851 } | 2871 } |
| 2852 } | 2872 } |
| 2853 else | 2873 else |
| 2854 { | 2874 { |
| 2855 integerThreshold = INT_MAX; | 2875 integerThreshold = INT_MAX; |
| 2856 fractionThreshold = INT_MAX; | 2876 fractionThreshold = INT_MAX; |
| 2857 } | 2877 } |
| 2858 | 2878 |
| 2859 /* | 2879 /* |
| 2860 * Calculate expected width. | 2880 * Calculate expected width. |
| 2861 * sign + integer part + thousands separators + decimal point | 2881 * sign + integer part + thousands separators + decimal point |
| 2862 * + fraction + exponent | 2882 * + fraction + exponent |
| 2863 */ | 2883 */ |
| 2864 fractionAdjust /= dblFractionBase; | 2884 fractionAdjust /= dblFractionBase; |
| 2865 hasOnlyZeroes = (floorl((fractionNumber + fractionAdjust) * dblFractionBase) <
epsilon); | 2885 hasOnlyZeroes = (floorl((fractionNumber + fractionAdjust) * dblFractionBase) <
epsilon); |
| 2866 keepDecimalPoint = ( (flags & FLAGS_ALTERNATIVE) || | 2886 keepDecimalPoint = ( (flags & FLAGS_ALTERNATIVE) || |
| 2867 !((precision == 0) || | 2887 !((precision == 0) || |
| 2868 (!keepTrailingZeroes && hasOnlyZeroes)) ); | 2888 (!keepTrailingZeroes && hasOnlyZeroes)) ); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2884 + ((flags & FLAGS_QUOTE) | 2904 + ((flags & FLAGS_QUOTE) |
| 2885 ? TrioCalcThousandSeparatorLength(integerDigits) | 2905 ? TrioCalcThousandSeparatorLength(integerDigits) |
| 2886 : 0); | 2906 : 0); |
| 2887 if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) | 2907 if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) |
| 2888 expectedWidth += sizeof("-") - 1; | 2908 expectedWidth += sizeof("-") - 1; |
| 2889 if (exponentDigits > 0) | 2909 if (exponentDigits > 0) |
| 2890 expectedWidth += exponentDigits + | 2910 expectedWidth += exponentDigits + |
| 2891 ((requireTwoDigitExponent ? sizeof("E+0") : sizeof("E+")) - 1); | 2911 ((requireTwoDigitExponent ? sizeof("E+0") : sizeof("E+")) - 1); |
| 2892 if (isHex) | 2912 if (isHex) |
| 2893 expectedWidth += sizeof("0X") - 1; | 2913 expectedWidth += sizeof("0X") - 1; |
| 2894 | 2914 |
| 2895 /* Output prefixing */ | 2915 /* Output prefixing */ |
| 2896 if (flags & FLAGS_NILPADDING) | 2916 if (flags & FLAGS_NILPADDING) |
| 2897 { | 2917 { |
| 2898 /* Leading zeros must be after sign */ | 2918 /* Leading zeros must be after sign */ |
| 2899 if (isNegative) | 2919 if (isNegative) |
| 2900 self->OutStream(self, '-'); | 2920 self->OutStream(self, '-'); |
| 2901 else if (flags & FLAGS_SHOWSIGN) | 2921 else if (flags & FLAGS_SHOWSIGN) |
| 2902 self->OutStream(self, '+'); | 2922 self->OutStream(self, '+'); |
| 2903 else if (flags & FLAGS_SPACE) | 2923 else if (flags & FLAGS_SPACE) |
| 2904 self->OutStream(self, ' '); | 2924 self->OutStream(self, ' '); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2930 else if (flags & FLAGS_SHOWSIGN) | 2950 else if (flags & FLAGS_SHOWSIGN) |
| 2931 self->OutStream(self, '+'); | 2951 self->OutStream(self, '+'); |
| 2932 else if (flags & FLAGS_SPACE) | 2952 else if (flags & FLAGS_SPACE) |
| 2933 self->OutStream(self, ' '); | 2953 self->OutStream(self, ' '); |
| 2934 if (isHex) | 2954 if (isHex) |
| 2935 { | 2955 { |
| 2936 self->OutStream(self, '0'); | 2956 self->OutStream(self, '0'); |
| 2937 self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); | 2957 self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); |
| 2938 } | 2958 } |
| 2939 } | 2959 } |
| 2940 | 2960 |
| 2941 /* Output the integer part and thousand separators */ | 2961 /* Output the integer part and thousand separators */ |
| 2942 dblIntegerBase = 1.0 / TrioPower(base, integerDigits - 1); | 2962 dblIntegerBase = 1.0 / TrioPower(base, integerDigits - 1); |
| 2943 for (i = 0; i < integerDigits; i++) | 2963 for (i = 0; i < integerDigits; i++) |
| 2944 { | 2964 { |
| 2945 workNumber = floorl(((integerNumber + integerAdjust) * dblIntegerBase)); | 2965 workNumber = floorl(((integerNumber + integerAdjust) * dblIntegerBase)); |
| 2946 if (i > integerThreshold) | 2966 if (i > integerThreshold) |
| 2947 { | 2967 { |
| 2948 /* Beyond accuracy */ | 2968 /* Beyond accuracy */ |
| 2949 self->OutStream(self, digits[0]); | 2969 self->OutStream(self, digits[0]); |
| 2950 } | 2970 } |
| 2951 else | 2971 else |
| 2952 { | 2972 { |
| 2953 self->OutStream(self, digits[(int)fmodl(workNumber, dblBase)]); | 2973 self->OutStream(self, digits[(int)fmodl(workNumber, dblBase)]); |
| 2954 } | 2974 } |
| 2955 dblIntegerBase *= dblBase; | 2975 dblIntegerBase *= dblBase; |
| 2956 | 2976 |
| 2957 if (((flags & (FLAGS_FLOAT_E | FLAGS_QUOTE)) == FLAGS_QUOTE) | 2977 if (((flags & (FLAGS_FLOAT_E | FLAGS_QUOTE)) == FLAGS_QUOTE) |
| 2958 && TrioFollowedBySeparator(integerDigits - i)) | 2978 && TrioFollowedBySeparator(integerDigits - i)) |
| 2959 { | 2979 { |
| 2960 for (groupingPointer = internalThousandSeparator; | 2980 for (groupingPointer = internalThousandSeparator; |
| 2961 *groupingPointer != NIL; | 2981 *groupingPointer != NIL; |
| 2962 groupingPointer++) | 2982 groupingPointer++) |
| 2963 { | 2983 { |
| 2964 self->OutStream(self, *groupingPointer); | 2984 self->OutStream(self, *groupingPointer); |
| 2965 } | 2985 } |
| 2966 } | 2986 } |
| 2967 } | 2987 } |
| 2968 | 2988 |
| 2969 /* Insert decimal point and build the fraction part */ | 2989 /* Insert decimal point and build the fraction part */ |
| 2970 trailingZeroes = 0; | 2990 trailingZeroes = 0; |
| 2971 | 2991 |
| 2972 if (keepDecimalPoint) | 2992 if (keepDecimalPoint) |
| 2973 { | 2993 { |
| 2974 if (internalDecimalPoint) | 2994 if (internalDecimalPoint) |
| 2975 { | 2995 { |
| 2976 self->OutStream(self, internalDecimalPoint); | 2996 self->OutStream(self, internalDecimalPoint); |
| 2977 } | 2997 } |
| 2978 else | 2998 else |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3007 while (trailingZeroes > 0) | 3027 while (trailingZeroes > 0) |
| 3008 { | 3028 { |
| 3009 /* Not trailing zeroes after all */ | 3029 /* Not trailing zeroes after all */ |
| 3010 self->OutStream(self, digits[0]); | 3030 self->OutStream(self, digits[0]); |
| 3011 trailingZeroes--; | 3031 trailingZeroes--; |
| 3012 } | 3032 } |
| 3013 self->OutStream(self, digits[index]); | 3033 self->OutStream(self, digits[index]); |
| 3014 } | 3034 } |
| 3015 } | 3035 } |
| 3016 } | 3036 } |
| 3017 | 3037 |
| 3018 if (keepTrailingZeroes) | 3038 if (keepTrailingZeroes) |
| 3019 { | 3039 { |
| 3020 while (trailingZeroes > 0) | 3040 while (trailingZeroes > 0) |
| 3021 { | 3041 { |
| 3022 self->OutStream(self, digits[0]); | 3042 self->OutStream(self, digits[0]); |
| 3023 trailingZeroes--; | 3043 trailingZeroes--; |
| 3024 } | 3044 } |
| 3025 } | 3045 } |
| 3026 | 3046 |
| 3027 /* Output exponent */ | 3047 /* Output exponent */ |
| 3028 if (exponentDigits > 0) | 3048 if (exponentDigits > 0) |
| 3029 { | 3049 { |
| 3030 self->OutStream(self, | 3050 self->OutStream(self, |
| 3031 isHex | 3051 isHex |
| 3032 ? ((flags & FLAGS_UPPER) ? 'P' : 'p') | 3052 ? ((flags & FLAGS_UPPER) ? 'P' : 'p') |
| 3033 : ((flags & FLAGS_UPPER) ? 'E' : 'e')); | 3053 : ((flags & FLAGS_UPPER) ? 'E' : 'e')); |
| 3034 self->OutStream(self, (isExponentNegative) ? '-' : '+'); | 3054 self->OutStream(self, (isExponentNegative) ? '-' : '+'); |
| 3035 | 3055 |
| 3036 /* The exponent must contain at least two digits */ | 3056 /* The exponent must contain at least two digits */ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3073 int charlen; | 3093 int charlen; |
| 3074 #endif | 3094 #endif |
| 3075 int i; | 3095 int i; |
| 3076 TRIO_CONST char *string; | 3096 TRIO_CONST char *string; |
| 3077 trio_pointer_t pointer; | 3097 trio_pointer_t pointer; |
| 3078 trio_flags_t flags; | 3098 trio_flags_t flags; |
| 3079 int width; | 3099 int width; |
| 3080 int precision; | 3100 int precision; |
| 3081 int base; | 3101 int base; |
| 3082 int index; | 3102 int index; |
| 3083 | 3103 |
| 3084 index = 0; | 3104 index = 0; |
| 3085 i = 0; | 3105 i = 0; |
| 3086 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 3106 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 3087 (void)mblen(NULL, 0); | 3107 (void)mblen(NULL, 0); |
| 3088 #endif | 3108 #endif |
| 3089 | 3109 |
| 3090 while (format[index]) | 3110 while (format[index]) |
| 3091 { | 3111 { |
| 3092 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 3112 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 3093 if (! isascii(format[index])) | 3113 if (! isascii(format[index])) |
| 3094 { | 3114 { |
| 3095 charlen = mblen(&format[index], MB_LEN_MAX); | 3115 charlen = mblen(&format[index], MB_LEN_MAX); |
| 3096 /* | 3116 /* |
| 3097 * Only valid multibyte characters are handled here. Invalid | 3117 * Only valid multibyte characters are handled here. Invalid |
| 3098 * multibyte characters (charlen == -1) are handled as normal | 3118 * multibyte characters (charlen == -1) are handled as normal |
| 3099 * characters. | 3119 * characters. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3113 if (CHAR_IDENTIFIER == format[index + 1]) | 3133 if (CHAR_IDENTIFIER == format[index + 1]) |
| 3114 { | 3134 { |
| 3115 data->OutStream(data, CHAR_IDENTIFIER); | 3135 data->OutStream(data, CHAR_IDENTIFIER); |
| 3116 index += 2; | 3136 index += 2; |
| 3117 } | 3137 } |
| 3118 else | 3138 else |
| 3119 { | 3139 { |
| 3120 /* Skip the parameter entries */ | 3140 /* Skip the parameter entries */ |
| 3121 while (parameters[i].type == FORMAT_PARAMETER) | 3141 while (parameters[i].type == FORMAT_PARAMETER) |
| 3122 i++; | 3142 i++; |
| 3123 » | 3143 |
| 3124 flags = parameters[i].flags; | 3144 flags = parameters[i].flags; |
| 3125 | 3145 |
| 3126 /* Find width */ | 3146 /* Find width */ |
| 3127 width = parameters[i].width; | 3147 width = parameters[i].width; |
| 3128 if (flags & FLAGS_WIDTH_PARAMETER) | 3148 if (flags & FLAGS_WIDTH_PARAMETER) |
| 3129 { | 3149 { |
| 3130 /* Get width from parameter list */ | 3150 /* Get width from parameter list */ |
| 3131 width = (int)parameters[width].data.number.as_signed; | 3151 width = (int)parameters[width].data.number.as_signed; |
| 3132 if (width < 0) | 3152 if (width < 0) |
| 3133 { | 3153 { |
| 3134 /* | 3154 /* |
| 3135 * A negative width is the same as the - flag and | 3155 * A negative width is the same as the - flag and |
| 3136 * a positive width. | 3156 * a positive width. |
| 3137 */ | 3157 */ |
| 3138 flags |= FLAGS_LEFTADJUST; | 3158 flags |= FLAGS_LEFTADJUST; |
| 3139 flags &= ~FLAGS_NILPADDING; | 3159 flags &= ~FLAGS_NILPADDING; |
| 3140 width = -width; | 3160 width = -width; |
| 3141 } | 3161 } |
| 3142 } | 3162 } |
| 3143 » | 3163 |
| 3144 /* Find precision */ | 3164 /* Find precision */ |
| 3145 if (flags & FLAGS_PRECISION) | 3165 if (flags & FLAGS_PRECISION) |
| 3146 { | 3166 { |
| 3147 precision = parameters[i].precision; | 3167 precision = parameters[i].precision; |
| 3148 if (flags & FLAGS_PRECISION_PARAMETER) | 3168 if (flags & FLAGS_PRECISION_PARAMETER) |
| 3149 { | 3169 { |
| 3150 /* Get precision from parameter list */ | 3170 /* Get precision from parameter list */ |
| 3151 precision = (int)parameters[precision].data.number.as_sign
ed; | 3171 precision = (int)parameters[precision].data.number.as_sign
ed; |
| 3152 if (precision < 0) | 3172 if (precision < 0) |
| 3153 { | 3173 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3164 precision = NO_PRECISION; | 3184 precision = NO_PRECISION; |
| 3165 } | 3185 } |
| 3166 | 3186 |
| 3167 /* Find base */ | 3187 /* Find base */ |
| 3168 base = parameters[i].base; | 3188 base = parameters[i].base; |
| 3169 if (flags & FLAGS_BASE_PARAMETER) | 3189 if (flags & FLAGS_BASE_PARAMETER) |
| 3170 { | 3190 { |
| 3171 /* Get base from parameter list */ | 3191 /* Get base from parameter list */ |
| 3172 base = (int)parameters[base].data.number.as_signed; | 3192 base = (int)parameters[base].data.number.as_signed; |
| 3173 } | 3193 } |
| 3174 » | 3194 |
| 3175 switch (parameters[i].type) | 3195 switch (parameters[i].type) |
| 3176 { | 3196 { |
| 3177 case FORMAT_CHAR: | 3197 case FORMAT_CHAR: |
| 3178 if (flags & FLAGS_QUOTE) | 3198 if (flags & FLAGS_QUOTE) |
| 3179 data->OutStream(data, CHAR_QUOTE); | 3199 data->OutStream(data, CHAR_QUOTE); |
| 3180 if (! (flags & FLAGS_LEFTADJUST)) | 3200 if (! (flags & FLAGS_LEFTADJUST)) |
| 3181 { | 3201 { |
| 3182 while (--width > 0) | 3202 while (--width > 0) |
| 3183 data->OutStream(data, CHAR_ADJUST); | 3203 data->OutStream(data, CHAR_ADJUST); |
| 3184 } | 3204 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3244 parameters[i].data.string, | 3264 parameters[i].data.string, |
| 3245 flags, | 3265 flags, |
| 3246 width, | 3266 width, |
| 3247 precision); | 3267 precision); |
| 3248 } | 3268 } |
| 3249 break; /* FORMAT_STRING */ | 3269 break; /* FORMAT_STRING */ |
| 3250 | 3270 |
| 3251 case FORMAT_POINTER: | 3271 case FORMAT_POINTER: |
| 3252 { | 3272 { |
| 3253 trio_reference_t reference; | 3273 trio_reference_t reference; |
| 3254 » » | 3274 |
| 3255 reference.data = data; | 3275 reference.data = data; |
| 3256 reference.parameter = ¶meters[i]; | 3276 reference.parameter = ¶meters[i]; |
| 3257 trio_print_pointer(&reference, parameters[i].data.pointer); | 3277 trio_print_pointer(&reference, parameters[i].data.pointer); |
| 3258 } | 3278 } |
| 3259 break; /* FORMAT_POINTER */ | 3279 break; /* FORMAT_POINTER */ |
| 3260 | 3280 |
| 3261 case FORMAT_COUNT: | 3281 case FORMAT_COUNT: |
| 3262 pointer = parameters[i].data.pointer; | 3282 pointer = parameters[i].data.pointer; |
| 3263 if (NULL != pointer) | 3283 if (NULL != pointer) |
| 3264 { | 3284 { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3347 def = TrioFindNamespace(parameters[i].user_name, NULL); | 3367 def = TrioFindNamespace(parameters[i].user_name, NULL); |
| 3348 } | 3368 } |
| 3349 if (def) { | 3369 if (def) { |
| 3350 reference.data = data; | 3370 reference.data = data; |
| 3351 reference.parameter = ¶meters[i]; | 3371 reference.parameter = ¶meters[i]; |
| 3352 def->callback(&reference); | 3372 def->callback(&reference); |
| 3353 } | 3373 } |
| 3354 } | 3374 } |
| 3355 break; | 3375 break; |
| 3356 #endif /* defined(FORMAT_USER_DEFINED) */ | 3376 #endif /* defined(FORMAT_USER_DEFINED) */ |
| 3357 » » | 3377 |
| 3358 default: | 3378 default: |
| 3359 break; | 3379 break; |
| 3360 } /* switch parameter type */ | 3380 } /* switch parameter type */ |
| 3361 | 3381 |
| 3362 /* Prepare for next */ | 3382 /* Prepare for next */ |
| 3363 index = parameters[i].indexAfterSpecifier; | 3383 index = parameters[i].indexAfterSpecifier; |
| 3364 i++; | 3384 i++; |
| 3365 } | 3385 } |
| 3366 } | 3386 } |
| 3367 else /* not identifier */ | 3387 else /* not identifier */ |
| 3368 { | 3388 { |
| 3369 data->OutStream(data, format[index++]); | 3389 data->OutStream(data, format[index++]); |
| 3370 } | 3390 } |
| 3371 } | 3391 } |
| 3372 return data->processed; | 3392 return data->processed; |
| 3373 } | 3393 } |
| 3374 | 3394 |
| 3375 /************************************************************************* | 3395 /************************************************************************* |
| 3376 * TrioFormatRef | 3396 * TrioFormatRef |
| 3377 */ | 3397 */ |
| 3378 TRIO_PRIVATE int | 3398 TRIO_PRIVATE int |
| 3379 TrioFormatRef | 3399 TrioFormatRef |
| 3380 TRIO_ARGS4((reference, format, arglist, argarray), | 3400 TRIO_ARGS4((reference, format, arglist, argarray), |
| 3381 trio_reference_t *reference, | 3401 trio_reference_t *reference, |
| 3382 TRIO_CONST char *format, | 3402 TRIO_CONST char *format, |
| 3383 » va_list *arglist, | 3403 » TRIO_VA_LIST_PTR arglist, |
| 3384 trio_pointer_t *argarray) | 3404 trio_pointer_t *argarray) |
| 3385 { | 3405 { |
| 3386 int status; | 3406 int status; |
| 3387 trio_parameter_t parameters[MAX_PARAMETERS]; | 3407 trio_parameter_t parameters[MAX_PARAMETERS]; |
| 3388 | 3408 |
| 3389 status = TrioParse(TYPE_PRINT, format, parameters, arglist, argarray); | 3409 status = TrioParse(TYPE_PRINT, format, parameters, arglist, argarray); |
| 3390 if (status < 0) | 3410 if (status < 0) |
| 3391 return status; | 3411 return status; |
| 3392 | 3412 |
| 3393 status = TrioFormatProcess(reference->data, format, parameters); | 3413 status = TrioFormatProcess(reference->data, format, parameters); |
| 3394 if (reference->data->error != 0) | 3414 if (reference->data->error != 0) |
| 3395 { | 3415 { |
| 3396 status = reference->data->error; | 3416 status = reference->data->error; |
| 3397 } | 3417 } |
| 3398 return status; | 3418 return status; |
| 3399 } | 3419 } |
| 3400 | 3420 |
| 3401 /************************************************************************* | 3421 /************************************************************************* |
| 3402 * TrioFormat | 3422 * TrioFormat |
| 3403 */ | 3423 */ |
| 3404 TRIO_PRIVATE int | 3424 TRIO_PRIVATE int |
| 3405 TrioFormat | 3425 TrioFormat |
| 3406 TRIO_ARGS6((destination, destinationSize, OutStream, format, arglist, argarray), | 3426 TRIO_ARGS6((destination, destinationSize, OutStream, format, arglist, argarray), |
| 3407 trio_pointer_t destination, | 3427 trio_pointer_t destination, |
| 3408 size_t destinationSize, | 3428 size_t destinationSize, |
| 3409 void (*OutStream) TRIO_PROTO((trio_class_t *, int)), | 3429 void (*OutStream) TRIO_PROTO((trio_class_t *, int)), |
| 3410 TRIO_CONST char *format, | 3430 TRIO_CONST char *format, |
| 3411 » va_list *arglist, | 3431 » TRIO_VA_LIST_PTR arglist, |
| 3412 trio_pointer_t *argarray) | 3432 trio_pointer_t *argarray) |
| 3413 { | 3433 { |
| 3414 int status; | 3434 int status; |
| 3415 trio_class_t data; | 3435 trio_class_t data; |
| 3416 trio_parameter_t parameters[MAX_PARAMETERS]; | 3436 trio_parameter_t parameters[MAX_PARAMETERS]; |
| 3417 | 3437 |
| 3418 assert(VALID(OutStream)); | 3438 assert(VALID(OutStream)); |
| 3419 assert(VALID(format)); | 3439 assert(VALID(format)); |
| 3420 | 3440 |
| 3421 memset(&data, 0, sizeof(data)); | 3441 memset(&data, 0, sizeof(data)); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3557 TRIO_PRIVATE void | 3577 TRIO_PRIVATE void |
| 3558 TrioOutStreamStringMax | 3578 TrioOutStreamStringMax |
| 3559 TRIO_ARGS2((self, output), | 3579 TRIO_ARGS2((self, output), |
| 3560 trio_class_t *self, | 3580 trio_class_t *self, |
| 3561 int output) | 3581 int output) |
| 3562 { | 3582 { |
| 3563 char **buffer; | 3583 char **buffer; |
| 3564 | 3584 |
| 3565 assert(VALID(self)); | 3585 assert(VALID(self)); |
| 3566 assert(VALID(self->location)); | 3586 assert(VALID(self->location)); |
| 3567 | 3587 |
| 3568 buffer = (char **)self->location; | 3588 buffer = (char **)self->location; |
| 3569 | 3589 |
| 3570 if (self->processed < self->max) | 3590 if (self->processed < self->max) |
| 3571 { | 3591 { |
| 3572 **buffer = (char)output; | 3592 **buffer = (char)output; |
| 3573 (*buffer)++; | 3593 (*buffer)++; |
| 3574 self->committed++; | 3594 self->committed++; |
| 3575 } | 3595 } |
| 3576 self->processed++; | 3596 self->processed++; |
| 3577 } | 3597 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3625 TRIO_PUBLIC int | 3645 TRIO_PUBLIC int |
| 3626 trio_printf | 3646 trio_printf |
| 3627 TRIO_VARGS2((format, va_alist), | 3647 TRIO_VARGS2((format, va_alist), |
| 3628 TRIO_CONST char *format, | 3648 TRIO_CONST char *format, |
| 3629 TRIO_VA_DECL) | 3649 TRIO_VA_DECL) |
| 3630 { | 3650 { |
| 3631 int status; | 3651 int status; |
| 3632 va_list args; | 3652 va_list args; |
| 3633 | 3653 |
| 3634 assert(VALID(format)); | 3654 assert(VALID(format)); |
| 3635 | 3655 |
| 3636 TRIO_VA_START(args, format); | 3656 TRIO_VA_START(args, format); |
| 3637 status = TrioFormat(stdout, 0, TrioOutStreamFile, format, &args, NULL); | 3657 status = TrioFormat(stdout, 0, TrioOutStreamFile, format, TRIO_VA_LIST_ADDR(ar
gs), NULL); |
| 3638 TRIO_VA_END(args); | 3658 TRIO_VA_END(args); |
| 3639 return status; | 3659 return status; |
| 3640 } | 3660 } |
| 3641 | 3661 |
| 3642 /** | 3662 /** |
| 3643 Print to standard output stream. | 3663 Print to standard output stream. |
| 3644 | 3664 |
| 3645 @param format Formatting string. | 3665 @param format Formatting string. |
| 3646 @param args Arguments. | 3666 @param args Arguments. |
| 3647 @return Number of printed characters. | 3667 @return Number of printed characters. |
| 3648 */ | 3668 */ |
| 3649 TRIO_PUBLIC int | 3669 TRIO_PUBLIC int |
| 3650 trio_vprintf | 3670 trio_vprintf |
| 3651 TRIO_ARGS2((format, args), | 3671 TRIO_ARGS2((format, args), |
| 3652 TRIO_CONST char *format, | 3672 TRIO_CONST char *format, |
| 3653 va_list args) | 3673 va_list args) |
| 3654 { | 3674 { |
| 3655 assert(VALID(format)); | 3675 assert(VALID(format)); |
| 3656 | 3676 |
| 3657 return TrioFormat(stdout, 0, TrioOutStreamFile, format, &args, NULL); | 3677 return TrioFormat(stdout, 0, TrioOutStreamFile, format, TRIO_VA_LIST_ADDR(args
), NULL); |
| 3658 } | 3678 } |
| 3659 | 3679 |
| 3660 /** | 3680 /** |
| 3661 Print to standard output stream. | 3681 Print to standard output stream. |
| 3662 | 3682 |
| 3663 @param format Formatting string. | 3683 @param format Formatting string. |
| 3664 @param args Arguments. | 3684 @param args Arguments. |
| 3665 @return Number of printed characters. | 3685 @return Number of printed characters. |
| 3666 */ | 3686 */ |
| 3667 TRIO_PUBLIC int | 3687 TRIO_PUBLIC int |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3692 TRIO_VARGS3((file, format, va_alist), | 3712 TRIO_VARGS3((file, format, va_alist), |
| 3693 FILE *file, | 3713 FILE *file, |
| 3694 TRIO_CONST char *format, | 3714 TRIO_CONST char *format, |
| 3695 TRIO_VA_DECL) | 3715 TRIO_VA_DECL) |
| 3696 { | 3716 { |
| 3697 int status; | 3717 int status; |
| 3698 va_list args; | 3718 va_list args; |
| 3699 | 3719 |
| 3700 assert(VALID(file)); | 3720 assert(VALID(file)); |
| 3701 assert(VALID(format)); | 3721 assert(VALID(format)); |
| 3702 | 3722 |
| 3703 TRIO_VA_START(args, format); | 3723 TRIO_VA_START(args, format); |
| 3704 status = TrioFormat(file, 0, TrioOutStreamFile, format, &args, NULL); | 3724 status = TrioFormat(file, 0, TrioOutStreamFile, format, TRIO_VA_LIST_ADDR(args
), NULL); |
| 3705 TRIO_VA_END(args); | 3725 TRIO_VA_END(args); |
| 3706 return status; | 3726 return status; |
| 3707 } | 3727 } |
| 3708 | 3728 |
| 3709 /** | 3729 /** |
| 3710 Print to file. | 3730 Print to file. |
| 3711 | 3731 |
| 3712 @param file File pointer. | 3732 @param file File pointer. |
| 3713 @param format Formatting string. | 3733 @param format Formatting string. |
| 3714 @param args Arguments. | 3734 @param args Arguments. |
| 3715 @return Number of printed characters. | 3735 @return Number of printed characters. |
| 3716 */ | 3736 */ |
| 3717 TRIO_PUBLIC int | 3737 TRIO_PUBLIC int |
| 3718 trio_vfprintf | 3738 trio_vfprintf |
| 3719 TRIO_ARGS3((file, format, args), | 3739 TRIO_ARGS3((file, format, args), |
| 3720 FILE *file, | 3740 FILE *file, |
| 3721 TRIO_CONST char *format, | 3741 TRIO_CONST char *format, |
| 3722 va_list args) | 3742 va_list args) |
| 3723 { | 3743 { |
| 3724 assert(VALID(file)); | 3744 assert(VALID(file)); |
| 3725 assert(VALID(format)); | 3745 assert(VALID(format)); |
| 3726 | 3746 |
| 3727 return TrioFormat(file, 0, TrioOutStreamFile, format, &args, NULL); | 3747 return TrioFormat(file, 0, TrioOutStreamFile, format, TRIO_VA_LIST_ADDR(args),
NULL); |
| 3728 } | 3748 } |
| 3729 | 3749 |
| 3730 /** | 3750 /** |
| 3731 Print to file. | 3751 Print to file. |
| 3732 | 3752 |
| 3733 @param file File pointer. | 3753 @param file File pointer. |
| 3734 @param format Formatting string. | 3754 @param format Formatting string. |
| 3735 @param args Arguments. | 3755 @param args Arguments. |
| 3736 @return Number of printed characters. | 3756 @return Number of printed characters. |
| 3737 */ | 3757 */ |
| 3738 TRIO_PUBLIC int | 3758 TRIO_PUBLIC int |
| 3739 trio_fprintfv | 3759 trio_fprintfv |
| 3740 TRIO_ARGS3((file, format, args), | 3760 TRIO_ARGS3((file, format, args), |
| 3741 FILE *file, | 3761 FILE *file, |
| 3742 TRIO_CONST char *format, | 3762 TRIO_CONST char *format, |
| 3743 trio_pointer_t * args) | 3763 trio_pointer_t * args) |
| 3744 { | 3764 { |
| 3745 assert(VALID(file)); | 3765 assert(VALID(file)); |
| 3746 assert(VALID(format)); | 3766 assert(VALID(format)); |
| 3747 | 3767 |
| 3748 return TrioFormat(file, 0, TrioOutStreamFile, format, NULL, args); | 3768 return TrioFormat(file, 0, TrioOutStreamFile, format, NULL, args); |
| 3749 } | 3769 } |
| 3750 | 3770 |
| 3751 /************************************************************************* | 3771 /************************************************************************* |
| 3752 * dprintf | 3772 * dprintf |
| 3753 */ | 3773 */ |
| 3754 | 3774 |
| 3755 /** | 3775 /** |
| 3756 Print to file descriptor. | 3776 Print to file descriptor. |
| 3757 | 3777 |
| 3758 @param fd File descriptor. | 3778 @param fd File descriptor. |
| 3759 @param format Formatting string. | 3779 @param format Formatting string. |
| 3760 @param ... Arguments. | 3780 @param ... Arguments. |
| 3761 @return Number of printed characters. | 3781 @return Number of printed characters. |
| 3762 */ | 3782 */ |
| 3763 TRIO_PUBLIC int | 3783 TRIO_PUBLIC int |
| 3764 trio_dprintf | 3784 trio_dprintf |
| 3765 TRIO_VARGS3((fd, format, va_alist), | 3785 TRIO_VARGS3((fd, format, va_alist), |
| 3766 int fd, | 3786 int fd, |
| 3767 TRIO_CONST char *format, | 3787 TRIO_CONST char *format, |
| 3768 TRIO_VA_DECL) | 3788 TRIO_VA_DECL) |
| 3769 { | 3789 { |
| 3770 int status; | 3790 int status; |
| 3771 va_list args; | 3791 va_list args; |
| 3772 | 3792 |
| 3773 assert(VALID(format)); | 3793 assert(VALID(format)); |
| 3774 | 3794 |
| 3775 TRIO_VA_START(args, format); | 3795 TRIO_VA_START(args, format); |
| 3776 status = TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, &args, NULL); | 3796 status = TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, TRIO_VA_LIST_
ADDR(args), NULL); |
| 3777 TRIO_VA_END(args); | 3797 TRIO_VA_END(args); |
| 3778 return status; | 3798 return status; |
| 3779 } | 3799 } |
| 3780 | 3800 |
| 3781 /** | 3801 /** |
| 3782 Print to file descriptor. | 3802 Print to file descriptor. |
| 3783 | 3803 |
| 3784 @param fd File descriptor. | 3804 @param fd File descriptor. |
| 3785 @param format Formatting string. | 3805 @param format Formatting string. |
| 3786 @param args Arguments. | 3806 @param args Arguments. |
| 3787 @return Number of printed characters. | 3807 @return Number of printed characters. |
| 3788 */ | 3808 */ |
| 3789 TRIO_PUBLIC int | 3809 TRIO_PUBLIC int |
| 3790 trio_vdprintf | 3810 trio_vdprintf |
| 3791 TRIO_ARGS3((fd, format, args), | 3811 TRIO_ARGS3((fd, format, args), |
| 3792 int fd, | 3812 int fd, |
| 3793 TRIO_CONST char *format, | 3813 TRIO_CONST char *format, |
| 3794 va_list args) | 3814 va_list args) |
| 3795 { | 3815 { |
| 3796 assert(VALID(format)); | 3816 assert(VALID(format)); |
| 3797 | 3817 |
| 3798 return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, &args, NULL); | 3818 return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, TRIO_VA_LIST_AD
DR(args), NULL); |
| 3799 } | 3819 } |
| 3800 | 3820 |
| 3801 /** | 3821 /** |
| 3802 Print to file descriptor. | 3822 Print to file descriptor. |
| 3803 | 3823 |
| 3804 @param fd File descriptor. | 3824 @param fd File descriptor. |
| 3805 @param format Formatting string. | 3825 @param format Formatting string. |
| 3806 @param args Arguments. | 3826 @param args Arguments. |
| 3807 @return Number of printed characters. | 3827 @return Number of printed characters. |
| 3808 */ | 3828 */ |
| 3809 TRIO_PUBLIC int | 3829 TRIO_PUBLIC int |
| 3810 trio_dprintfv | 3830 trio_dprintfv |
| 3811 TRIO_ARGS3((fd, format, args), | 3831 TRIO_ARGS3((fd, format, args), |
| 3812 int fd, | 3832 int fd, |
| 3813 TRIO_CONST char *format, | 3833 TRIO_CONST char *format, |
| 3814 trio_pointer_t *args) | 3834 trio_pointer_t *args) |
| 3815 { | 3835 { |
| 3816 assert(VALID(format)); | 3836 assert(VALID(format)); |
| 3817 | 3837 |
| 3818 return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, NULL, args); | 3838 return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, NULL, args); |
| 3819 } | 3839 } |
| 3820 | 3840 |
| 3821 /************************************************************************* | 3841 /************************************************************************* |
| 3822 * cprintf | 3842 * cprintf |
| 3823 */ | 3843 */ |
| 3824 TRIO_PUBLIC int | 3844 TRIO_PUBLIC int |
| 3825 trio_cprintf | 3845 trio_cprintf |
| 3826 TRIO_VARGS4((stream, closure, format, va_alist), | 3846 TRIO_VARGS4((stream, closure, format, va_alist), |
| 3827 trio_outstream_t stream, | 3847 trio_outstream_t stream, |
| 3828 trio_pointer_t closure, | 3848 trio_pointer_t closure, |
| 3829 TRIO_CONST char *format, | 3849 TRIO_CONST char *format, |
| 3830 TRIO_VA_DECL) | 3850 TRIO_VA_DECL) |
| 3831 { | 3851 { |
| 3832 int status; | 3852 int status; |
| 3833 va_list args; | 3853 va_list args; |
| 3834 trio_custom_t data; | 3854 trio_custom_t data; |
| 3835 | 3855 |
| 3836 assert(VALID(stream)); | 3856 assert(VALID(stream)); |
| 3837 assert(VALID(format)); | 3857 assert(VALID(format)); |
| 3838 | 3858 |
| 3839 TRIO_VA_START(args, format); | 3859 TRIO_VA_START(args, format); |
| 3840 data.stream.out = stream; | 3860 data.stream.out = stream; |
| 3841 data.closure = closure; | 3861 data.closure = closure; |
| 3842 status = TrioFormat(&data, 0, TrioOutStreamCustom, format, &args, NULL); | 3862 status = TrioFormat(&data, 0, TrioOutStreamCustom, format, TRIO_VA_LIST_ADDR(a
rgs), NULL); |
| 3843 TRIO_VA_END(args); | 3863 TRIO_VA_END(args); |
| 3844 return status; | 3864 return status; |
| 3845 } | 3865 } |
| 3846 | 3866 |
| 3847 TRIO_PUBLIC int | 3867 TRIO_PUBLIC int |
| 3848 trio_vcprintf | 3868 trio_vcprintf |
| 3849 TRIO_ARGS4((stream, closure, format, args), | 3869 TRIO_ARGS4((stream, closure, format, args), |
| 3850 trio_outstream_t stream, | 3870 trio_outstream_t stream, |
| 3851 trio_pointer_t closure, | 3871 trio_pointer_t closure, |
| 3852 TRIO_CONST char *format, | 3872 TRIO_CONST char *format, |
| 3853 va_list args) | 3873 va_list args) |
| 3854 { | 3874 { |
| 3855 trio_custom_t data; | 3875 trio_custom_t data; |
| 3856 | 3876 |
| 3857 assert(VALID(stream)); | 3877 assert(VALID(stream)); |
| 3858 assert(VALID(format)); | 3878 assert(VALID(format)); |
| 3859 | 3879 |
| 3860 data.stream.out = stream; | 3880 data.stream.out = stream; |
| 3861 data.closure = closure; | 3881 data.closure = closure; |
| 3862 return TrioFormat(&data, 0, TrioOutStreamCustom, format, &args, NULL); | 3882 return TrioFormat(&data, 0, TrioOutStreamCustom, format, TRIO_VA_LIST_ADDR(arg
s), NULL); |
| 3863 } | 3883 } |
| 3864 | 3884 |
| 3865 TRIO_PUBLIC int | 3885 TRIO_PUBLIC int |
| 3866 trio_cprintfv | 3886 trio_cprintfv |
| 3867 TRIO_ARGS4((stream, closure, format, args), | 3887 TRIO_ARGS4((stream, closure, format, args), |
| 3868 trio_outstream_t stream, | 3888 trio_outstream_t stream, |
| 3869 trio_pointer_t closure, | 3889 trio_pointer_t closure, |
| 3870 TRIO_CONST char *format, | 3890 TRIO_CONST char *format, |
| 3871 void **args) | 3891 void **args) |
| 3872 { | 3892 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3897 TRIO_VARGS3((buffer, format, va_alist), | 3917 TRIO_VARGS3((buffer, format, va_alist), |
| 3898 char *buffer, | 3918 char *buffer, |
| 3899 TRIO_CONST char *format, | 3919 TRIO_CONST char *format, |
| 3900 TRIO_VA_DECL) | 3920 TRIO_VA_DECL) |
| 3901 { | 3921 { |
| 3902 int status; | 3922 int status; |
| 3903 va_list args; | 3923 va_list args; |
| 3904 | 3924 |
| 3905 assert(VALID(buffer)); | 3925 assert(VALID(buffer)); |
| 3906 assert(VALID(format)); | 3926 assert(VALID(format)); |
| 3907 | 3927 |
| 3908 TRIO_VA_START(args, format); | 3928 TRIO_VA_START(args, format); |
| 3909 status = TrioFormat(&buffer, 0, TrioOutStreamString, format, &args, NULL); | 3929 status = TrioFormat(&buffer, 0, TrioOutStreamString, format, TRIO_VA_LIST_ADDR
(args), NULL); |
| 3910 *buffer = NIL; /* Terminate with NIL character */ | 3930 *buffer = NIL; /* Terminate with NIL character */ |
| 3911 TRIO_VA_END(args); | 3931 TRIO_VA_END(args); |
| 3912 return status; | 3932 return status; |
| 3913 } | 3933 } |
| 3914 | 3934 |
| 3915 /** | 3935 /** |
| 3916 Print to string. | 3936 Print to string. |
| 3917 | 3937 |
| 3918 @param buffer Output string. | 3938 @param buffer Output string. |
| 3919 @param format Formatting string. | 3939 @param format Formatting string. |
| 3920 @param args Arguments. | 3940 @param args Arguments. |
| 3921 @return Number of printed characters. | 3941 @return Number of printed characters. |
| 3922 */ | 3942 */ |
| 3923 TRIO_PUBLIC int | 3943 TRIO_PUBLIC int |
| 3924 trio_vsprintf | 3944 trio_vsprintf |
| 3925 TRIO_ARGS3((buffer, format, args), | 3945 TRIO_ARGS3((buffer, format, args), |
| 3926 char *buffer, | 3946 char *buffer, |
| 3927 TRIO_CONST char *format, | 3947 TRIO_CONST char *format, |
| 3928 va_list args) | 3948 va_list args) |
| 3929 { | 3949 { |
| 3930 int status; | 3950 int status; |
| 3931 | 3951 |
| 3932 assert(VALID(buffer)); | 3952 assert(VALID(buffer)); |
| 3933 assert(VALID(format)); | 3953 assert(VALID(format)); |
| 3934 | 3954 |
| 3935 status = TrioFormat(&buffer, 0, TrioOutStreamString, format, &args, NULL); | 3955 status = TrioFormat(&buffer, 0, TrioOutStreamString, format, TRIO_VA_LIST_ADDR
(args), NULL); |
| 3936 *buffer = NIL; | 3956 *buffer = NIL; |
| 3937 return status; | 3957 return status; |
| 3938 } | 3958 } |
| 3939 | 3959 |
| 3940 /** | 3960 /** |
| 3941 Print to string. | 3961 Print to string. |
| 3942 | 3962 |
| 3943 @param buffer Output string. | 3963 @param buffer Output string. |
| 3944 @param format Formatting string. | 3964 @param format Formatting string. |
| 3945 @param args Arguments. | 3965 @param args Arguments. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3984 TRIO_VA_DECL) | 4004 TRIO_VA_DECL) |
| 3985 { | 4005 { |
| 3986 int status; | 4006 int status; |
| 3987 va_list args; | 4007 va_list args; |
| 3988 | 4008 |
| 3989 assert(VALID(buffer)); | 4009 assert(VALID(buffer)); |
| 3990 assert(VALID(format)); | 4010 assert(VALID(format)); |
| 3991 | 4011 |
| 3992 TRIO_VA_START(args, format); | 4012 TRIO_VA_START(args, format); |
| 3993 status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, | 4013 status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, |
| 3994 » » TrioOutStreamStringMax, format, &args, NULL); | 4014 » » TrioOutStreamStringMax, format, TRIO_VA_LIST_ADDR(args), N
ULL); |
| 3995 if (max > 0) | 4015 if (max > 0) |
| 3996 *buffer = NIL; | 4016 *buffer = NIL; |
| 3997 TRIO_VA_END(args); | 4017 TRIO_VA_END(args); |
| 3998 return status; | 4018 return status; |
| 3999 } | 4019 } |
| 4000 | 4020 |
| 4001 /** | 4021 /** |
| 4002 Print at most @p max characters to string. | 4022 Print at most @p max characters to string. |
| 4003 | 4023 |
| 4004 @param buffer Output string. | 4024 @param buffer Output string. |
| 4005 @param max Maximum number of characters to print. | 4025 @param max Maximum number of characters to print. |
| 4006 @param format Formatting string. | 4026 @param format Formatting string. |
| 4007 @param args Arguments. | 4027 @param args Arguments. |
| 4008 @return Number of printed characters. | 4028 @return Number of printed characters. |
| 4009 */ | 4029 */ |
| 4010 TRIO_PUBLIC int | 4030 TRIO_PUBLIC int |
| 4011 trio_vsnprintf | 4031 trio_vsnprintf |
| 4012 TRIO_ARGS4((buffer, max, format, args), | 4032 TRIO_ARGS4((buffer, max, format, args), |
| 4013 char *buffer, | 4033 char *buffer, |
| 4014 size_t max, | 4034 size_t max, |
| 4015 TRIO_CONST char *format, | 4035 TRIO_CONST char *format, |
| 4016 va_list args) | 4036 va_list args) |
| 4017 { | 4037 { |
| 4018 int status; | 4038 int status; |
| 4019 | 4039 |
| 4020 assert(VALID(buffer)); | 4040 assert(VALID(buffer)); |
| 4021 assert(VALID(format)); | 4041 assert(VALID(format)); |
| 4022 | 4042 |
| 4023 status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, | 4043 status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, |
| 4024 » » TrioOutStreamStringMax, format, &args, NULL); | 4044 » » TrioOutStreamStringMax, format, TRIO_VA_LIST_ADDR(args), N
ULL); |
| 4025 if (max > 0) | 4045 if (max > 0) |
| 4026 *buffer = NIL; | 4046 *buffer = NIL; |
| 4027 return status; | 4047 return status; |
| 4028 } | 4048 } |
| 4029 | 4049 |
| 4030 /** | 4050 /** |
| 4031 Print at most @p max characters to string. | 4051 Print at most @p max characters to string. |
| 4032 | 4052 |
| 4033 @param buffer Output string. | 4053 @param buffer Output string. |
| 4034 @param max Maximum number of characters to print. | 4054 @param max Maximum number of characters to print. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4075 | 4095 |
| 4076 TRIO_VA_START(args, format); | 4096 TRIO_VA_START(args, format); |
| 4077 | 4097 |
| 4078 assert(VALID(buffer)); | 4098 assert(VALID(buffer)); |
| 4079 assert(VALID(format)); | 4099 assert(VALID(format)); |
| 4080 | 4100 |
| 4081 buf_len = trio_length(buffer); | 4101 buf_len = trio_length(buffer); |
| 4082 buffer = &buffer[buf_len]; | 4102 buffer = &buffer[buf_len]; |
| 4083 | 4103 |
| 4084 status = TrioFormat(&buffer, max - 1 - buf_len, | 4104 status = TrioFormat(&buffer, max - 1 - buf_len, |
| 4085 » » TrioOutStreamStringMax, format, &args, NULL); | 4105 » » TrioOutStreamStringMax, format, TRIO_VA_LIST_ADDR(args), N
ULL); |
| 4086 TRIO_VA_END(args); | 4106 TRIO_VA_END(args); |
| 4087 *buffer = NIL; | 4107 *buffer = NIL; |
| 4088 return status; | 4108 return status; |
| 4089 } | 4109 } |
| 4090 | 4110 |
| 4091 TRIO_PUBLIC int | 4111 TRIO_PUBLIC int |
| 4092 trio_vsnprintfcat | 4112 trio_vsnprintfcat |
| 4093 TRIO_ARGS4((buffer, max, format, args), | 4113 TRIO_ARGS4((buffer, max, format, args), |
| 4094 char *buffer, | 4114 char *buffer, |
| 4095 size_t max, | 4115 size_t max, |
| 4096 TRIO_CONST char *format, | 4116 TRIO_CONST char *format, |
| 4097 va_list args) | 4117 va_list args) |
| 4098 { | 4118 { |
| 4099 int status; | 4119 int status; |
| 4100 size_t buf_len; | 4120 size_t buf_len; |
| 4101 | 4121 |
| 4102 assert(VALID(buffer)); | 4122 assert(VALID(buffer)); |
| 4103 assert(VALID(format)); | 4123 assert(VALID(format)); |
| 4104 | 4124 |
| 4105 buf_len = trio_length(buffer); | 4125 buf_len = trio_length(buffer); |
| 4106 buffer = &buffer[buf_len]; | 4126 buffer = &buffer[buf_len]; |
| 4107 status = TrioFormat(&buffer, max - 1 - buf_len, | 4127 status = TrioFormat(&buffer, max - 1 - buf_len, |
| 4108 » » TrioOutStreamStringMax, format, &args, NULL); | 4128 » » TrioOutStreamStringMax, format, TRIO_VA_LIST_ADDR(args), N
ULL); |
| 4109 *buffer = NIL; | 4129 *buffer = NIL; |
| 4110 return status; | 4130 return status; |
| 4111 } | 4131 } |
| 4112 | 4132 |
| 4113 /************************************************************************* | 4133 /************************************************************************* |
| 4114 * trio_aprintf | 4134 * trio_aprintf |
| 4115 */ | 4135 */ |
| 4116 | 4136 |
| 4117 /* Deprecated */ | 4137 /* Deprecated */ |
| 4118 TRIO_PUBLIC char * | 4138 TRIO_PUBLIC char * |
| 4119 trio_aprintf | 4139 trio_aprintf |
| 4120 TRIO_VARGS2((format, va_alist), | 4140 TRIO_VARGS2((format, va_alist), |
| 4121 TRIO_CONST char *format, | 4141 TRIO_CONST char *format, |
| 4122 TRIO_VA_DECL) | 4142 TRIO_VA_DECL) |
| 4123 { | 4143 { |
| 4124 va_list args; | 4144 va_list args; |
| 4125 trio_string_t *info; | 4145 trio_string_t *info; |
| 4126 char *result = NULL; | 4146 char *result = NULL; |
| 4127 | 4147 |
| 4128 assert(VALID(format)); | 4148 assert(VALID(format)); |
| 4129 | 4149 |
| 4130 info = trio_xstring_duplicate(""); | 4150 info = trio_xstring_duplicate(""); |
| 4131 if (info) | 4151 if (info) |
| 4132 { | 4152 { |
| 4133 TRIO_VA_START(args, format); | 4153 TRIO_VA_START(args, format); |
| 4134 (void)TrioFormat(info, 0, TrioOutStreamStringDynamic, | 4154 (void)TrioFormat(info, 0, TrioOutStreamStringDynamic, |
| 4135 » » format, &args, NULL); | 4155 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 4136 TRIO_VA_END(args); | 4156 TRIO_VA_END(args); |
| 4137 | 4157 |
| 4138 trio_string_terminate(info); | 4158 trio_string_terminate(info); |
| 4139 result = trio_string_extract(info); | 4159 result = trio_string_extract(info); |
| 4140 trio_string_destroy(info); | 4160 trio_string_destroy(info); |
| 4141 } | 4161 } |
| 4142 return result; | 4162 return result; |
| 4143 } | 4163 } |
| 4144 | 4164 |
| 4145 /* Deprecated */ | 4165 /* Deprecated */ |
| 4146 TRIO_PUBLIC char * | 4166 TRIO_PUBLIC char * |
| 4147 trio_vaprintf | 4167 trio_vaprintf |
| 4148 TRIO_ARGS2((format, args), | 4168 TRIO_ARGS2((format, args), |
| 4149 TRIO_CONST char *format, | 4169 TRIO_CONST char *format, |
| 4150 va_list args) | 4170 va_list args) |
| 4151 { | 4171 { |
| 4152 trio_string_t *info; | 4172 trio_string_t *info; |
| 4153 char *result = NULL; | 4173 char *result = NULL; |
| 4154 | 4174 |
| 4155 assert(VALID(format)); | 4175 assert(VALID(format)); |
| 4156 | 4176 |
| 4157 info = trio_xstring_duplicate(""); | 4177 info = trio_xstring_duplicate(""); |
| 4158 if (info) | 4178 if (info) |
| 4159 { | 4179 { |
| 4160 (void)TrioFormat(info, 0, TrioOutStreamStringDynamic, | 4180 (void)TrioFormat(info, 0, TrioOutStreamStringDynamic, |
| 4161 » » format, &args, NULL); | 4181 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 4162 trio_string_terminate(info); | 4182 trio_string_terminate(info); |
| 4163 result = trio_string_extract(info); | 4183 result = trio_string_extract(info); |
| 4164 trio_string_destroy(info); | 4184 trio_string_destroy(info); |
| 4165 } | 4185 } |
| 4166 return result; | 4186 return result; |
| 4167 } | 4187 } |
| 4168 | 4188 |
| 4169 TRIO_PUBLIC int | 4189 TRIO_PUBLIC int |
| 4170 trio_asprintf | 4190 trio_asprintf |
| 4171 TRIO_VARGS3((result, format, va_alist), | 4191 TRIO_VARGS3((result, format, va_alist), |
| 4172 char **result, | 4192 char **result, |
| 4173 TRIO_CONST char *format, | 4193 TRIO_CONST char *format, |
| 4174 TRIO_VA_DECL) | 4194 TRIO_VA_DECL) |
| 4175 { | 4195 { |
| 4176 va_list args; | 4196 va_list args; |
| 4177 int status; | 4197 int status; |
| 4178 trio_string_t *info; | 4198 trio_string_t *info; |
| 4179 | 4199 |
| 4180 assert(VALID(format)); | 4200 assert(VALID(format)); |
| 4181 | 4201 |
| 4182 *result = NULL; | 4202 *result = NULL; |
| 4183 | 4203 |
| 4184 info = trio_xstring_duplicate(""); | 4204 info = trio_xstring_duplicate(""); |
| 4185 if (info == NULL) | 4205 if (info == NULL) |
| 4186 { | 4206 { |
| 4187 status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); | 4207 status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); |
| 4188 } | 4208 } |
| 4189 else | 4209 else |
| 4190 { | 4210 { |
| 4191 TRIO_VA_START(args, format); | 4211 TRIO_VA_START(args, format); |
| 4192 status = TrioFormat(info, 0, TrioOutStreamStringDynamic, | 4212 status = TrioFormat(info, 0, TrioOutStreamStringDynamic, |
| 4193 » » » format, &args, NULL); | 4213 » » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 4194 TRIO_VA_END(args); | 4214 TRIO_VA_END(args); |
| 4195 if (status >= 0) | 4215 if (status >= 0) |
| 4196 { | 4216 { |
| 4197 trio_string_terminate(info); | 4217 trio_string_terminate(info); |
| 4198 *result = trio_string_extract(info); | 4218 *result = trio_string_extract(info); |
| 4199 } | 4219 } |
| 4200 trio_string_destroy(info); | 4220 trio_string_destroy(info); |
| 4201 } | 4221 } |
| 4202 return status; | 4222 return status; |
| 4203 } | 4223 } |
| 4204 | 4224 |
| 4205 TRIO_PUBLIC int | 4225 TRIO_PUBLIC int |
| 4206 trio_vasprintf | 4226 trio_vasprintf |
| 4207 TRIO_ARGS3((result, format, args), | 4227 TRIO_ARGS3((result, format, args), |
| 4208 char **result, | 4228 char **result, |
| 4209 TRIO_CONST char *format, | 4229 TRIO_CONST char *format, |
| 4210 va_list args) | 4230 va_list args) |
| 4211 { | 4231 { |
| 4212 int status; | 4232 int status; |
| 4213 trio_string_t *info; | 4233 trio_string_t *info; |
| 4214 | 4234 |
| 4215 assert(VALID(format)); | 4235 assert(VALID(format)); |
| 4216 | 4236 |
| 4217 *result = NULL; | 4237 *result = NULL; |
| 4218 | 4238 |
| 4219 info = trio_xstring_duplicate(""); | 4239 info = trio_xstring_duplicate(""); |
| 4220 if (info == NULL) | 4240 if (info == NULL) |
| 4221 { | 4241 { |
| 4222 status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); | 4242 status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); |
| 4223 } | 4243 } |
| 4224 else | 4244 else |
| 4225 { | 4245 { |
| 4226 status = TrioFormat(info, 0, TrioOutStreamStringDynamic, | 4246 status = TrioFormat(info, 0, TrioOutStreamStringDynamic, |
| 4227 » » » format, &args, NULL); | 4247 » » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 4228 if (status >= 0) | 4248 if (status >= 0) |
| 4229 { | 4249 { |
| 4230 trio_string_terminate(info); | 4250 trio_string_terminate(info); |
| 4231 *result = trio_string_extract(info); | 4251 *result = trio_string_extract(info); |
| 4232 } | 4252 } |
| 4233 trio_string_destroy(info); | 4253 trio_string_destroy(info); |
| 4234 } | 4254 } |
| 4235 return status; | 4255 return status; |
| 4236 } | 4256 } |
| 4237 | 4257 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4257 * trio_register | 4277 * trio_register |
| 4258 */ | 4278 */ |
| 4259 | 4279 |
| 4260 /** | 4280 /** |
| 4261 Register new user-defined specifier. | 4281 Register new user-defined specifier. |
| 4262 | 4282 |
| 4263 @param callback | 4283 @param callback |
| 4264 @param name | 4284 @param name |
| 4265 @return Handle. | 4285 @return Handle. |
| 4266 */ | 4286 */ |
| 4267 TRIO_PUBLIC trio_pointer_t | 4287 TRIO_PUBLIC trio_pointer_t |
| 4268 trio_register | 4288 trio_register |
| 4269 TRIO_ARGS2((callback, name), | 4289 TRIO_ARGS2((callback, name), |
| 4270 trio_callback_t callback, | 4290 trio_callback_t callback, |
| 4271 TRIO_CONST char *name) | 4291 TRIO_CONST char *name) |
| 4272 { | 4292 { |
| 4273 trio_userdef_t *def; | 4293 trio_userdef_t *def; |
| 4274 trio_userdef_t *prev = NULL; | 4294 trio_userdef_t *prev = NULL; |
| 4275 | 4295 |
| 4276 if (callback == NULL) | 4296 if (callback == NULL) |
| 4277 return NULL; | 4297 return NULL; |
| 4278 | 4298 |
| 4279 if (name) | 4299 if (name) |
| 4280 { | 4300 { |
| 4281 /* Handle built-in namespaces */ | 4301 /* Handle built-in namespaces */ |
| 4282 if (name[0] == ':') | 4302 if (name[0] == ':') |
| 4283 { | 4303 { |
| 4284 if (trio_equal(name, ":enter")) | 4304 if (trio_equal(name, ":enter")) |
| 4285 { | 4305 { |
| 4286 internalEnterCriticalRegion = callback; | 4306 internalEnterCriticalRegion = callback; |
| 4287 } | 4307 } |
| 4288 else if (trio_equal(name, ":leave")) | 4308 else if (trio_equal(name, ":leave")) |
| 4289 { | 4309 { |
| 4290 internalLeaveCriticalRegion = callback; | 4310 internalLeaveCriticalRegion = callback; |
| 4291 } | 4311 } |
| 4292 return NULL; | 4312 return NULL; |
| 4293 } | 4313 } |
| 4294 | 4314 |
| 4295 /* Bail out if namespace is too long */ | 4315 /* Bail out if namespace is too long */ |
| 4296 if (trio_length(name) >= MAX_USER_NAME) | 4316 if (trio_length(name) >= MAX_USER_NAME) |
| 4297 return NULL; | 4317 return NULL; |
| 4298 | 4318 |
| 4299 /* Bail out if namespace already is registered */ | 4319 /* Bail out if namespace already is registered */ |
| 4300 def = TrioFindNamespace(name, &prev); | 4320 def = TrioFindNamespace(name, &prev); |
| 4301 if (def) | 4321 if (def) |
| 4302 return NULL; | 4322 return NULL; |
| 4303 } | 4323 } |
| 4304 | 4324 |
| 4305 def = (trio_userdef_t *)TRIO_MALLOC(sizeof(trio_userdef_t)); | 4325 def = (trio_userdef_t *)TRIO_MALLOC(sizeof(trio_userdef_t)); |
| 4306 if (def) | 4326 if (def) |
| 4307 { | 4327 { |
| 4308 if (internalEnterCriticalRegion) | 4328 if (internalEnterCriticalRegion) |
| 4309 (void)internalEnterCriticalRegion(NULL); | 4329 (void)internalEnterCriticalRegion(NULL); |
| 4310 | 4330 |
| 4311 if (name) | 4331 if (name) |
| 4312 { | 4332 { |
| 4313 /* Link into internal list */ | 4333 /* Link into internal list */ |
| 4314 if (prev == NULL) | 4334 if (prev == NULL) |
| 4315 internalUserDef = def; | 4335 internalUserDef = def; |
| 4316 else | 4336 else |
| 4317 prev->next = def; | 4337 prev->next = def; |
| 4318 } | 4338 } |
| 4319 /* Initialize */ | 4339 /* Initialize */ |
| 4320 def->callback = callback; | 4340 def->callback = callback; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4345 | 4365 |
| 4346 assert(VALID(self)); | 4366 assert(VALID(self)); |
| 4347 | 4367 |
| 4348 if (self->name) | 4368 if (self->name) |
| 4349 { | 4369 { |
| 4350 def = TrioFindNamespace(self->name, &prev); | 4370 def = TrioFindNamespace(self->name, &prev); |
| 4351 if (def) | 4371 if (def) |
| 4352 { | 4372 { |
| 4353 if (internalEnterCriticalRegion) | 4373 if (internalEnterCriticalRegion) |
| 4354 (void)internalEnterCriticalRegion(NULL); | 4374 (void)internalEnterCriticalRegion(NULL); |
| 4355 » | 4375 |
| 4356 if (prev == NULL) | 4376 if (prev == NULL) |
| 4357 internalUserDef = NULL; | 4377 internalUserDef = NULL; |
| 4358 else | 4378 else |
| 4359 prev->next = def->next; | 4379 prev->next = def->next; |
| 4360 » | 4380 |
| 4361 if (internalLeaveCriticalRegion) | 4381 if (internalLeaveCriticalRegion) |
| 4362 (void)internalLeaveCriticalRegion(NULL); | 4382 (void)internalLeaveCriticalRegion(NULL); |
| 4363 } | 4383 } |
| 4364 trio_destroy(self->name); | 4384 trio_destroy(self->name); |
| 4365 } | 4385 } |
| 4366 TRIO_FREE(self); | 4386 TRIO_FREE(self); |
| 4367 } | 4387 } |
| 4368 | 4388 |
| 4369 /************************************************************************* | 4389 /************************************************************************* |
| 4370 * trio_get_format [public] | 4390 * trio_get_format [public] |
| 4371 */ | 4391 */ |
| 4372 TRIO_CONST char * | 4392 TRIO_CONST char * |
| 4373 trio_get_format | 4393 trio_get_format |
| 4374 TRIO_ARGS1((ref), | 4394 TRIO_ARGS1((ref), |
| 4375 trio_pointer_t ref) | 4395 trio_pointer_t ref) |
| 4376 { | 4396 { |
| 4377 #if defined(FORMAT_USER_DEFINED) | 4397 #if defined(FORMAT_USER_DEFINED) |
| 4378 assert(((trio_reference_t *)ref)->parameter->type == FORMAT_USER_DEFINED); | 4398 assert(((trio_reference_t *)ref)->parameter->type == FORMAT_USER_DEFINED); |
| 4379 #endif | 4399 #endif |
| 4380 | 4400 |
| 4381 return (((trio_reference_t *)ref)->parameter->user_data); | 4401 return (((trio_reference_t *)ref)->parameter->user_data); |
| 4382 } | 4402 } |
| 4383 | 4403 |
| 4384 /************************************************************************* | 4404 /************************************************************************* |
| 4385 * trio_get_argument [public] | 4405 * trio_get_argument [public] |
| 4386 */ | 4406 */ |
| 4387 trio_pointer_t | 4407 trio_pointer_t |
| 4388 trio_get_argument | 4408 trio_get_argument |
| 4389 TRIO_ARGS1((ref), | 4409 TRIO_ARGS1((ref), |
| 4390 trio_pointer_t ref) | 4410 trio_pointer_t ref) |
| 4391 { | 4411 { |
| 4392 #if defined(FORMAT_USER_DEFINED) | 4412 #if defined(FORMAT_USER_DEFINED) |
| 4393 assert(((trio_reference_t *)ref)->parameter->type == FORMAT_USER_DEFINED); | 4413 assert(((trio_reference_t *)ref)->parameter->type == FORMAT_USER_DEFINED); |
| 4394 #endif | 4414 #endif |
| 4395 | 4415 |
| 4396 return ((trio_reference_t *)ref)->parameter->data.pointer; | 4416 return ((trio_reference_t *)ref)->parameter->data.pointer; |
| 4397 } | 4417 } |
| 4398 | 4418 |
| 4399 /************************************************************************* | 4419 /************************************************************************* |
| 4400 * trio_get_width / trio_set_width [public] | 4420 * trio_get_width / trio_set_width [public] |
| 4401 */ | 4421 */ |
| 4402 int | 4422 int |
| 4403 trio_get_width | 4423 trio_get_width |
| 4404 TRIO_ARGS1((ref), | 4424 TRIO_ARGS1((ref), |
| 4405 trio_pointer_t ref) | 4425 trio_pointer_t ref) |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4917 trio_print_ref | 4937 trio_print_ref |
| 4918 TRIO_VARGS3((ref, format, va_alist), | 4938 TRIO_VARGS3((ref, format, va_alist), |
| 4919 trio_pointer_t ref, | 4939 trio_pointer_t ref, |
| 4920 TRIO_CONST char *format, | 4940 TRIO_CONST char *format, |
| 4921 TRIO_VA_DECL) | 4941 TRIO_VA_DECL) |
| 4922 { | 4942 { |
| 4923 int status; | 4943 int status; |
| 4924 va_list arglist; | 4944 va_list arglist; |
| 4925 | 4945 |
| 4926 assert(VALID(format)); | 4946 assert(VALID(format)); |
| 4927 | 4947 |
| 4928 TRIO_VA_START(arglist, format); | 4948 TRIO_VA_START(arglist, format); |
| 4929 status = TrioFormatRef((trio_reference_t *)ref, format, &arglist, NULL); | 4949 status = TrioFormatRef((trio_reference_t *)ref, format, TRIO_VA_LIST_ADDR(argl
ist), NULL); |
| 4930 TRIO_VA_END(arglist); | 4950 TRIO_VA_END(arglist); |
| 4931 return status; | 4951 return status; |
| 4932 } | 4952 } |
| 4933 | 4953 |
| 4934 /************************************************************************* | 4954 /************************************************************************* |
| 4935 * trio_vprint_ref [public] | 4955 * trio_vprint_ref [public] |
| 4936 */ | 4956 */ |
| 4937 int | 4957 int |
| 4938 trio_vprint_ref | 4958 trio_vprint_ref |
| 4939 TRIO_ARGS3((ref, format, arglist), | 4959 TRIO_ARGS3((ref, format, arglist), |
| 4940 trio_pointer_t ref, | 4960 trio_pointer_t ref, |
| 4941 TRIO_CONST char *format, | 4961 TRIO_CONST char *format, |
| 4942 va_list arglist) | 4962 va_list arglist) |
| 4943 { | 4963 { |
| 4944 assert(VALID(format)); | 4964 assert(VALID(format)); |
| 4945 | 4965 |
| 4946 return TrioFormatRef((trio_reference_t *)ref, format, &arglist, NULL); | 4966 return TrioFormatRef((trio_reference_t *)ref, format, TRIO_VA_LIST_ADDR(arglis
t), NULL); |
| 4947 } | 4967 } |
| 4948 | 4968 |
| 4949 /************************************************************************* | 4969 /************************************************************************* |
| 4950 * trio_printv_ref [public] | 4970 * trio_printv_ref [public] |
| 4951 */ | 4971 */ |
| 4952 int | 4972 int |
| 4953 trio_printv_ref | 4973 trio_printv_ref |
| 4954 TRIO_ARGS3((ref, format, argarray), | 4974 TRIO_ARGS3((ref, format, argarray), |
| 4955 trio_pointer_t ref, | 4975 trio_pointer_t ref, |
| 4956 TRIO_CONST char *format, | 4976 TRIO_CONST char *format, |
| 4957 trio_pointer_t *argarray) | 4977 trio_pointer_t *argarray) |
| 4958 { | 4978 { |
| 4959 assert(VALID(format)); | 4979 assert(VALID(format)); |
| 4960 | 4980 |
| 4961 return TrioFormatRef((trio_reference_t *)ref, format, NULL, argarray); | 4981 return TrioFormatRef((trio_reference_t *)ref, format, NULL, argarray); |
| 4962 } | 4982 } |
| 4963 | 4983 |
| 4964 #endif /* TRIO_EXTENSION */ | 4984 #endif /* TRIO_EXTENSION */ |
| 4965 | 4985 |
| 4966 /************************************************************************* | 4986 /************************************************************************* |
| 4967 * trio_print_pointer [public] | 4987 * trio_print_pointer [public] |
| 4968 */ | 4988 */ |
| 4969 void | 4989 void |
| 4970 trio_print_pointer | 4990 trio_print_pointer |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5199 index++; | 5219 index++; |
| 5200 } | 5220 } |
| 5201 /* Collect characters */ | 5221 /* Collect characters */ |
| 5202 for (ch = format[index]; | 5222 for (ch = format[index]; |
| 5203 (ch != SPECIFIER_UNGROUP) && (ch != NIL); | 5223 (ch != SPECIFIER_UNGROUP) && (ch != NIL); |
| 5204 ch = format[++index]) | 5224 ch = format[++index]) |
| 5205 { | 5225 { |
| 5206 switch (ch) | 5226 switch (ch) |
| 5207 { | 5227 { |
| 5208 case QUALIFIER_MINUS: /* Scanlist ranges */ | 5228 case QUALIFIER_MINUS: /* Scanlist ranges */ |
| 5209 » | 5229 |
| 5210 /* | 5230 /* |
| 5211 * Both C99 and UNIX98 describes ranges as implementation- | 5231 * Both C99 and UNIX98 describes ranges as implementation- |
| 5212 * defined. | 5232 * defined. |
| 5213 * | 5233 * |
| 5214 * We support the following behaviour (although this may | 5234 * We support the following behaviour (although this may |
| 5215 * change as we become wiser) | 5235 * change as we become wiser) |
| 5216 * - only increasing ranges, ie. [a-b] but not [b-a] | 5236 * - only increasing ranges, ie. [a-b] but not [b-a] |
| 5217 * - transitive ranges, ie. [a-b-c] == [a-c] | 5237 * - transitive ranges, ie. [a-b-c] == [a-c] |
| 5218 * - trailing minus, ie. [a-] is interpreted as an 'a' | 5238 * - trailing minus, ie. [a-] is interpreted as an 'a' |
| 5219 * and a '-' | 5239 * and a '-' |
| 5220 * - duplicates (although we can easily convert these | 5240 * - duplicates (although we can easily convert these |
| 5221 * into errors) | 5241 * into errors) |
| 5222 */ | 5242 */ |
| 5223 range_begin = format[index - 1]; | 5243 range_begin = format[index - 1]; |
| 5224 range_end = format[++index]; | 5244 range_end = format[++index]; |
| 5225 if (range_end == SPECIFIER_UNGROUP) | 5245 if (range_end == SPECIFIER_UNGROUP) |
| 5226 { | 5246 { |
| 5227 /* Trailing minus is included */ | 5247 /* Trailing minus is included */ |
| 5228 characterclass[(int)ch]++; | 5248 characterclass[(int)ch]++; |
| 5229 ch = range_end; | 5249 ch = range_end; |
| 5230 break; /* for */ | 5250 break; /* for */ |
| 5231 } | 5251 } |
| 5232 if (range_end == NIL) | 5252 if (range_end == NIL) |
| 5233 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); | 5253 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); |
| 5234 if (range_begin > range_end) | 5254 if (range_begin > range_end) |
| 5235 return TRIO_ERROR_RETURN(TRIO_ERANGE, index); | 5255 return TRIO_ERROR_RETURN(TRIO_ERANGE, index); |
| 5236 » | 5256 |
| 5237 for (i = (int)range_begin; i <= (int)range_end; i++) | 5257 for (i = (int)range_begin; i <= (int)range_end; i++) |
| 5238 characterclass[i]++; | 5258 characterclass[i]++; |
| 5239 » | 5259 |
| 5240 ch = range_end; | 5260 ch = range_end; |
| 5241 break; | 5261 break; |
| 5242 » | 5262 |
| 5243 #if TRIO_EXTENSION | 5263 #if TRIO_EXTENSION |
| 5244 | 5264 |
| 5245 case SPECIFIER_GROUP: | 5265 case SPECIFIER_GROUP: |
| 5246 » | 5266 |
| 5247 switch (format[index + 1]) | 5267 switch (format[index + 1]) |
| 5248 { | 5268 { |
| 5249 case QUALIFIER_DOT: /* Collating symbol */ | 5269 case QUALIFIER_DOT: /* Collating symbol */ |
| 5250 /* | 5270 /* |
| 5251 * FIXME: This will be easier to implement when multibyte | 5271 * FIXME: This will be easier to implement when multibyte |
| 5252 * characters have been implemented. Until now, we ignore | 5272 * characters have been implemented. Until now, we ignore |
| 5253 * this feature. | 5273 * this feature. |
| 5254 */ | 5274 */ |
| 5255 for (i = index + 2; ; i++) | 5275 for (i = index + 2; ; i++) |
| 5256 { | 5276 { |
| 5257 if (format[i] == NIL) | 5277 if (format[i] == NIL) |
| 5258 /* Error in syntax */ | 5278 /* Error in syntax */ |
| 5259 return -1; | 5279 return -1; |
| 5260 else if (format[i] == QUALIFIER_DOT) | 5280 else if (format[i] == QUALIFIER_DOT) |
| 5261 break; /* for */ | 5281 break; /* for */ |
| 5262 } | 5282 } |
| 5263 if (format[++i] != SPECIFIER_UNGROUP) | 5283 if (format[++i] != SPECIFIER_UNGROUP) |
| 5264 return -1; | 5284 return -1; |
| 5265 » | 5285 |
| 5266 index = i; | 5286 index = i; |
| 5267 break; | 5287 break; |
| 5268 » | 5288 |
| 5269 case QUALIFIER_EQUAL: /* Equivalence class expressions */ | 5289 case QUALIFIER_EQUAL: /* Equivalence class expressions */ |
| 5270 { | 5290 { |
| 5271 unsigned int j; | 5291 unsigned int j; |
| 5272 unsigned int k; | 5292 unsigned int k; |
| 5273 » | 5293 |
| 5274 if (internalCollationUnconverted) | 5294 if (internalCollationUnconverted) |
| 5275 { | 5295 { |
| 5276 /* Lazy evaluation of collation array */ | 5296 /* Lazy evaluation of collation array */ |
| 5277 TrioGetCollation(); | 5297 TrioGetCollation(); |
| 5278 internalCollationUnconverted = FALSE; | 5298 internalCollationUnconverted = FALSE; |
| 5279 } | 5299 } |
| 5280 for (i = index + 2; ; i++) | 5300 for (i = index + 2; ; i++) |
| 5281 { | 5301 { |
| 5282 if (format[i] == NIL) | 5302 if (format[i] == NIL) |
| 5283 /* Error in syntax */ | 5303 /* Error in syntax */ |
| 5284 return -1; | 5304 return -1; |
| 5285 else if (format[i] == QUALIFIER_EQUAL) | 5305 else if (format[i] == QUALIFIER_EQUAL) |
| 5286 break; /* for */ | 5306 break; /* for */ |
| 5287 else | 5307 else |
| 5288 { | 5308 { |
| 5289 /* Mark any equivalent character */ | 5309 /* Mark any equivalent character */ |
| 5290 k = (unsigned int)format[i]; | 5310 k = (unsigned int)format[i]; |
| 5291 for (j = 0; internalCollationArray[k][j] != NIL; j++) | 5311 for (j = 0; internalCollationArray[k][j] != NIL; j++) |
| 5292 characterclass[(int)internalCollationArray[k][j]]++; | 5312 characterclass[(int)internalCollationArray[k][j]]++; |
| 5293 } | 5313 } |
| 5294 } | 5314 } |
| 5295 if (format[++i] != SPECIFIER_UNGROUP) | 5315 if (format[++i] != SPECIFIER_UNGROUP) |
| 5296 return -1; | 5316 return -1; |
| 5297 » » | 5317 |
| 5298 index = i; | 5318 index = i; |
| 5299 } | 5319 } |
| 5300 break; | 5320 break; |
| 5301 » | 5321 |
| 5302 case QUALIFIER_COLON: /* Character class expressions */ | 5322 case QUALIFIER_COLON: /* Character class expressions */ |
| 5303 » | 5323 |
| 5304 if (trio_equal_max(CLASS_ALNUM, sizeof(CLASS_ALNUM) - 1, | 5324 if (trio_equal_max(CLASS_ALNUM, sizeof(CLASS_ALNUM) - 1, |
| 5305 &format[index])) | 5325 &format[index])) |
| 5306 { | 5326 { |
| 5307 for (i = 0; i < MAX_CHARACTER_CLASS; i++) | 5327 for (i = 0; i < MAX_CHARACTER_CLASS; i++) |
| 5308 if (isalnum(i)) | 5328 if (isalnum(i)) |
| 5309 characterclass[i]++; | 5329 characterclass[i]++; |
| 5310 index += sizeof(CLASS_ALNUM) - 1; | 5330 index += sizeof(CLASS_ALNUM) - 1; |
| 5311 } | 5331 } |
| 5312 else if (trio_equal_max(CLASS_ALPHA, sizeof(CLASS_ALPHA) - 1, | 5332 else if (trio_equal_max(CLASS_ALPHA, sizeof(CLASS_ALPHA) - 1, |
| 5313 &format[index])) | 5333 &format[index])) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5393 { | 5413 { |
| 5394 characterclass[(int)ch]++; | 5414 characterclass[(int)ch]++; |
| 5395 } | 5415 } |
| 5396 break; | 5416 break; |
| 5397 | 5417 |
| 5398 default: | 5418 default: |
| 5399 characterclass[(int)ch]++; | 5419 characterclass[(int)ch]++; |
| 5400 break; | 5420 break; |
| 5401 } | 5421 } |
| 5402 break; | 5422 break; |
| 5403 » | 5423 |
| 5404 #endif /* TRIO_EXTENSION */ | 5424 #endif /* TRIO_EXTENSION */ |
| 5405 » | 5425 |
| 5406 default: | 5426 default: |
| 5407 characterclass[(int)ch]++; | 5427 characterclass[(int)ch]++; |
| 5408 break; | 5428 break; |
| 5409 } | 5429 } |
| 5410 } | 5430 } |
| 5411 return 0; | 5431 return 0; |
| 5412 } | 5432 } |
| 5413 | 5433 |
| 5414 /************************************************************************* | 5434 /************************************************************************* |
| 5415 * TrioReadNumber | 5435 * TrioReadNumber |
| (...skipping 25 matching lines...) Expand all Loading... |
| 5441 { | 5461 { |
| 5442 /* Lazy evaluation of digits array */ | 5462 /* Lazy evaluation of digits array */ |
| 5443 memset(internalDigitArray, -1, sizeof(internalDigitArray)); | 5463 memset(internalDigitArray, -1, sizeof(internalDigitArray)); |
| 5444 for (j = 0; j < (int)sizeof(internalDigitsLower) - 1; j++) | 5464 for (j = 0; j < (int)sizeof(internalDigitsLower) - 1; j++) |
| 5445 { | 5465 { |
| 5446 internalDigitArray[(int)internalDigitsLower[j]] = j; | 5466 internalDigitArray[(int)internalDigitsLower[j]] = j; |
| 5447 internalDigitArray[(int)internalDigitsUpper[j]] = j; | 5467 internalDigitArray[(int)internalDigitsUpper[j]] = j; |
| 5448 } | 5468 } |
| 5449 internalDigitsUnconverted = FALSE; | 5469 internalDigitsUnconverted = FALSE; |
| 5450 } | 5470 } |
| 5451 | 5471 |
| 5452 TrioSkipWhitespaces(self); | 5472 TrioSkipWhitespaces(self); |
| 5453 | 5473 |
| 5454 if (!(flags & FLAGS_UNSIGNED)) | 5474 if (!(flags & FLAGS_UNSIGNED)) |
| 5455 { | 5475 { |
| 5456 /* Leading sign */ | 5476 /* Leading sign */ |
| 5457 if (self->current == '+') | 5477 if (self->current == '+') |
| 5458 { | 5478 { |
| 5459 self->InStream(self, NULL); | 5479 self->InStream(self, NULL); |
| 5460 } | 5480 } |
| 5461 else if (self->current == '-') | 5481 else if (self->current == '-') |
| 5462 { | 5482 { |
| 5463 self->InStream(self, NULL); | 5483 self->InStream(self, NULL); |
| 5464 isNegative = TRUE; | 5484 isNegative = TRUE; |
| 5465 } | 5485 } |
| 5466 } | 5486 } |
| 5467 | 5487 |
| 5468 count = self->processed; | 5488 count = self->processed; |
| 5469 | 5489 |
| 5470 if (flags & FLAGS_ALTERNATIVE) | 5490 if (flags & FLAGS_ALTERNATIVE) |
| 5471 { | 5491 { |
| 5472 switch (base) | 5492 switch (base) |
| 5473 { | 5493 { |
| 5474 case NO_BASE: | 5494 case NO_BASE: |
| 5475 case BASE_OCTAL: | 5495 case BASE_OCTAL: |
| 5476 case BASE_HEX: | 5496 case BASE_HEX: |
| 5477 case BASE_BINARY: | 5497 case BASE_BINARY: |
| 5478 if (self->current == '0') | 5498 if (self->current == '0') |
| 5479 { | 5499 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5520 | 5540 |
| 5521 self->InStream(self, NULL); | 5541 self->InStream(self, NULL); |
| 5522 } | 5542 } |
| 5523 if (internalThousandSeparator[j]) | 5543 if (internalThousandSeparator[j]) |
| 5524 break; /* Mismatch */ | 5544 break; /* Mismatch */ |
| 5525 else | 5545 else |
| 5526 continue; /* Match */ | 5546 continue; /* Match */ |
| 5527 } | 5547 } |
| 5528 else | 5548 else |
| 5529 break; | 5549 break; |
| 5530 | 5550 |
| 5531 number *= base; | 5551 number *= base; |
| 5532 number += digit; | 5552 number += digit; |
| 5533 gotNumber = TRUE; /* we need at least one digit */ | 5553 gotNumber = TRUE; /* we need at least one digit */ |
| 5534 | 5554 |
| 5535 self->InStream(self, NULL); | 5555 self->InStream(self, NULL); |
| 5536 } | 5556 } |
| 5537 | 5557 |
| 5538 /* Was anything read at all? */ | 5558 /* Was anything read at all? */ |
| 5539 if (!gotNumber) | 5559 if (!gotNumber) |
| 5540 return FALSE; | 5560 return FALSE; |
| 5541 | 5561 |
| 5542 if (target) | 5562 if (target) |
| 5543 *target = (isNegative) ? -((trio_intmax_t)number) : number; | 5563 *target = (isNegative) ? -((trio_intmax_t)number) : number; |
| 5544 return TRUE; | 5564 return TRUE; |
| 5545 } | 5565 } |
| 5546 | 5566 |
| 5547 /************************************************************************* | 5567 /************************************************************************* |
| 5548 * TrioReadChar | 5568 * TrioReadChar |
| 5549 */ | 5569 */ |
| 5550 TRIO_PRIVATE int | 5570 TRIO_PRIVATE int |
| 5551 TrioReadChar | 5571 TrioReadChar |
| 5552 TRIO_ARGS4((self, target, flags, width), | 5572 TRIO_ARGS4((self, target, flags, width), |
| 5553 trio_class_t *self, | 5573 trio_class_t *self, |
| 5554 char *target, | 5574 char *target, |
| 5555 trio_flags_t flags, | 5575 trio_flags_t flags, |
| 5556 int width) | 5576 int width) |
| 5557 { | 5577 { |
| 5558 int i; | 5578 int i; |
| 5559 char ch; | 5579 char ch; |
| 5560 trio_uintmax_t number; | 5580 trio_uintmax_t number; |
| 5561 | 5581 |
| 5562 assert(VALID(self)); | 5582 assert(VALID(self)); |
| 5563 assert(VALID(self->InStream)); | 5583 assert(VALID(self->InStream)); |
| 5564 | 5584 |
| 5565 for (i = 0; | 5585 for (i = 0; |
| 5566 (self->current != EOF) && (i < width); | 5586 (self->current != EOF) && (i < width); |
| 5567 i++) | 5587 i++) |
| 5568 { | 5588 { |
| 5569 ch = (char)self->current; | 5589 ch = (char)self->current; |
| 5570 self->InStream(self, NULL); | 5590 self->InStream(self, NULL); |
| 5571 if ((flags & FLAGS_ALTERNATIVE) && (ch == CHAR_BACKSLASH)) | 5591 if ((flags & FLAGS_ALTERNATIVE) && (ch == CHAR_BACKSLASH)) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5596 return 0; | 5616 return 0; |
| 5597 ch = (char)number; | 5617 ch = (char)number; |
| 5598 } | 5618 } |
| 5599 else | 5619 else |
| 5600 { | 5620 { |
| 5601 ch = (char)self->current; | 5621 ch = (char)self->current; |
| 5602 } | 5622 } |
| 5603 break; | 5623 break; |
| 5604 } | 5624 } |
| 5605 } | 5625 } |
| 5606 | 5626 |
| 5607 if (target) | 5627 if (target) |
| 5608 target[i] = ch; | 5628 target[i] = ch; |
| 5609 } | 5629 } |
| 5610 return i + 1; | 5630 return i + 1; |
| 5611 } | 5631 } |
| 5612 | 5632 |
| 5613 /************************************************************************* | 5633 /************************************************************************* |
| 5614 * TrioReadString | 5634 * TrioReadString |
| 5615 */ | 5635 */ |
| 5616 TRIO_PRIVATE BOOLEAN_T | 5636 TRIO_PRIVATE BOOLEAN_T |
| 5617 TrioReadString | 5637 TrioReadString |
| 5618 TRIO_ARGS4((self, target, flags, width), | 5638 TRIO_ARGS4((self, target, flags, width), |
| 5619 trio_class_t *self, | 5639 trio_class_t *self, |
| 5620 char *target, | 5640 char *target, |
| 5621 trio_flags_t flags, | 5641 trio_flags_t flags, |
| 5622 int width) | 5642 int width) |
| 5623 { | 5643 { |
| 5624 int i; | 5644 int i; |
| 5625 | 5645 |
| 5626 assert(VALID(self)); | 5646 assert(VALID(self)); |
| 5627 assert(VALID(self->InStream)); | 5647 assert(VALID(self->InStream)); |
| 5628 | 5648 |
| 5629 TrioSkipWhitespaces(self); | 5649 TrioSkipWhitespaces(self); |
| 5630 | 5650 |
| 5631 /* | 5651 /* |
| 5632 * Continue until end of string is reached, a whitespace is encountered, | 5652 * Continue until end of string is reached, a whitespace is encountered, |
| 5633 * or width is exceeded | 5653 * or width is exceeded |
| 5634 */ | 5654 */ |
| 5635 for (i = 0; | 5655 for (i = 0; |
| 5636 ((width == NO_WIDTH) || (i < width)) && | 5656 ((width == NO_WIDTH) || (i < width)) && |
| 5637 (! ((self->current == EOF) || isspace(self->current))); | 5657 (! ((self->current == EOF) || isspace(self->current))); |
| 5638 i++) | 5658 i++) |
| 5639 { | 5659 { |
| 5640 if (TrioReadChar(self, (target ? &target[i] : 0), flags, 1) == 0) | 5660 if (TrioReadChar(self, (target ? &target[i] : 0), flags, 1) == 0) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5656 trio_wchar_t *target, | 5676 trio_wchar_t *target, |
| 5657 trio_flags_t flags, | 5677 trio_flags_t flags, |
| 5658 int width) | 5678 int width) |
| 5659 { | 5679 { |
| 5660 int i; | 5680 int i; |
| 5661 int j; | 5681 int j; |
| 5662 int size; | 5682 int size; |
| 5663 int amount = 0; | 5683 int amount = 0; |
| 5664 trio_wchar_t wch; | 5684 trio_wchar_t wch; |
| 5665 char buffer[MB_LEN_MAX + 1]; | 5685 char buffer[MB_LEN_MAX + 1]; |
| 5666 | 5686 |
| 5667 assert(VALID(self)); | 5687 assert(VALID(self)); |
| 5668 assert(VALID(self->InStream)); | 5688 assert(VALID(self->InStream)); |
| 5669 | 5689 |
| 5670 for (i = 0; | 5690 for (i = 0; |
| 5671 (self->current != EOF) && (i < width); | 5691 (self->current != EOF) && (i < width); |
| 5672 i++) | 5692 i++) |
| 5673 { | 5693 { |
| 5674 if (isascii(self->current)) | 5694 if (isascii(self->current)) |
| 5675 { | 5695 { |
| 5676 if (TrioReadChar(self, buffer, flags, 1) == 0) | 5696 if (TrioReadChar(self, buffer, flags, 1) == 0) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5713 TRIO_PRIVATE BOOLEAN_T | 5733 TRIO_PRIVATE BOOLEAN_T |
| 5714 TrioReadWideString | 5734 TrioReadWideString |
| 5715 TRIO_ARGS4((self, target, flags, width), | 5735 TRIO_ARGS4((self, target, flags, width), |
| 5716 trio_class_t *self, | 5736 trio_class_t *self, |
| 5717 trio_wchar_t *target, | 5737 trio_wchar_t *target, |
| 5718 trio_flags_t flags, | 5738 trio_flags_t flags, |
| 5719 int width) | 5739 int width) |
| 5720 { | 5740 { |
| 5721 int i; | 5741 int i; |
| 5722 int size; | 5742 int size; |
| 5723 | 5743 |
| 5724 assert(VALID(self)); | 5744 assert(VALID(self)); |
| 5725 assert(VALID(self->InStream)); | 5745 assert(VALID(self->InStream)); |
| 5726 | 5746 |
| 5727 TrioSkipWhitespaces(self); | 5747 TrioSkipWhitespaces(self); |
| 5728 | 5748 |
| 5729 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) | 5749 #if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) |
| 5730 (void)mblen(NULL, 0); | 5750 (void)mblen(NULL, 0); |
| 5731 #endif | 5751 #endif |
| 5732 | 5752 |
| 5733 /* | 5753 /* |
| 5734 * Continue until end of string is reached, a whitespace is encountered, | 5754 * Continue until end of string is reached, a whitespace is encountered, |
| 5735 * or width is exceeded | 5755 * or width is exceeded |
| 5736 */ | 5756 */ |
| 5737 for (i = 0; | 5757 for (i = 0; |
| 5738 ((width == NO_WIDTH) || (i < width)) && | 5758 ((width == NO_WIDTH) || (i < width)) && |
| 5739 (! ((self->current == EOF) || isspace(self->current))); | 5759 (! ((self->current == EOF) || isspace(self->current))); |
| 5740 ) | 5760 ) |
| 5741 { | 5761 { |
| 5742 size = TrioReadWideChar(self, &target[i], flags, 1); | 5762 size = TrioReadWideChar(self, &target[i], flags, 1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5760 TrioReadGroup | 5780 TrioReadGroup |
| 5761 TRIO_ARGS5((self, target, characterclass, flags, width), | 5781 TRIO_ARGS5((self, target, characterclass, flags, width), |
| 5762 trio_class_t *self, | 5782 trio_class_t *self, |
| 5763 char *target, | 5783 char *target, |
| 5764 int *characterclass, | 5784 int *characterclass, |
| 5765 trio_flags_t flags, | 5785 trio_flags_t flags, |
| 5766 int width) | 5786 int width) |
| 5767 { | 5787 { |
| 5768 int ch; | 5788 int ch; |
| 5769 int i; | 5789 int i; |
| 5770 | 5790 |
| 5771 assert(VALID(self)); | 5791 assert(VALID(self)); |
| 5772 assert(VALID(self->InStream)); | 5792 assert(VALID(self->InStream)); |
| 5773 | 5793 |
| 5774 ch = self->current; | 5794 ch = self->current; |
| 5775 for (i = 0; | 5795 for (i = 0; |
| 5776 ((width == NO_WIDTH) || (i < width)) && | 5796 ((width == NO_WIDTH) || (i < width)) && |
| 5777 (! ((ch == EOF) || | 5797 (! ((ch == EOF) || |
| 5778 (((flags & FLAGS_EXCLUDE) != 0) ^ (characterclass[ch] == 0)))); | 5798 (((flags & FLAGS_EXCLUDE) != 0) ^ (characterclass[ch] == 0)))); |
| 5779 i++) | 5799 i++) |
| 5780 { | 5800 { |
| 5781 if (target) | 5801 if (target) |
| 5782 target[i] = (char)ch; | 5802 target[i] = (char)ch; |
| 5783 self->InStream(self, &ch); | 5803 self->InStream(self, &ch); |
| 5784 } | 5804 } |
| 5785 | 5805 |
| 5786 if (target) | 5806 if (target) |
| 5787 target[i] = NIL; | 5807 target[i] = NIL; |
| 5788 return TRUE; | 5808 return TRUE; |
| 5789 } | 5809 } |
| 5790 | 5810 |
| 5791 /************************************************************************* | 5811 /************************************************************************* |
| 5792 * TrioReadDouble | 5812 * TrioReadDouble |
| 5793 * | 5813 * |
| 5794 * FIXME: | 5814 * FIXME: |
| 5795 * add long double | 5815 * add long double |
| 5796 * handle base | 5816 * handle base |
| 5797 */ | 5817 */ |
| 5798 TRIO_PRIVATE BOOLEAN_T | 5818 TRIO_PRIVATE BOOLEAN_T |
| 5799 TrioReadDouble | 5819 TrioReadDouble |
| 5800 TRIO_ARGS4((self, target, flags, width), | 5820 TRIO_ARGS4((self, target, flags, width), |
| 5801 trio_class_t *self, | 5821 trio_class_t *self, |
| 5802 trio_pointer_t target, | 5822 trio_pointer_t target, |
| 5803 trio_flags_t flags, | 5823 trio_flags_t flags, |
| 5804 int width) | 5824 int width) |
| 5805 { | 5825 { |
| 5806 int ch; | 5826 int ch; |
| 5807 char doubleString[512]; | 5827 char doubleString[512]; |
| 5808 int index = 0; | 5828 int index = 0; |
| 5809 int start; | 5829 int start; |
| 5810 int j; | 5830 int j; |
| 5811 BOOLEAN_T isHex = FALSE; | 5831 BOOLEAN_T isHex = FALSE; |
| 5812 | 5832 |
| 5813 doubleString[0] = 0; | 5833 doubleString[0] = 0; |
| 5814 | 5834 |
| 5815 if ((width == NO_WIDTH) || (width > (int)sizeof(doubleString) - 1)) | 5835 if ((width == NO_WIDTH) || (width > (int)sizeof(doubleString) - 1)) |
| 5816 width = sizeof(doubleString) - 1; | 5836 width = sizeof(doubleString) - 1; |
| 5817 | 5837 |
| 5818 TrioSkipWhitespaces(self); | 5838 TrioSkipWhitespaces(self); |
| 5819 | 5839 |
| 5820 /* | 5840 /* |
| 5821 * Read entire double number from stream. trio_to_double requires | 5841 * Read entire double number from stream. trio_to_double requires |
| 5822 * a string as input, but InStream can be anything, so we have to | 5842 * a string as input, but InStream can be anything, so we have to |
| 5823 * collect all characters. | 5843 * collect all characters. |
| 5824 */ | 5844 */ |
| 5825 ch = self->current; | 5845 ch = self->current; |
| 5826 if ((ch == '+') || (ch == '-')) | 5846 if ((ch == '+') || (ch == '-')) |
| 5827 { | 5847 { |
| 5828 doubleString[index++] = (char)ch; | 5848 doubleString[index++] = (char)ch; |
| 5829 self->InStream(self, &ch); | 5849 self->InStream(self, &ch); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5895 case '0': | 5915 case '0': |
| 5896 doubleString[index++] = (char)ch; | 5916 doubleString[index++] = (char)ch; |
| 5897 self->InStream(self, &ch); | 5917 self->InStream(self, &ch); |
| 5898 if (trio_to_upper(ch) == 'X') | 5918 if (trio_to_upper(ch) == 'X') |
| 5899 { | 5919 { |
| 5900 isHex = TRUE; | 5920 isHex = TRUE; |
| 5901 doubleString[index++] = (char)ch; | 5921 doubleString[index++] = (char)ch; |
| 5902 self->InStream(self, &ch); | 5922 self->InStream(self, &ch); |
| 5903 } | 5923 } |
| 5904 break; | 5924 break; |
| 5905 | 5925 |
| 5906 default: | 5926 default: |
| 5907 break; | 5927 break; |
| 5908 } | 5928 } |
| 5909 | 5929 |
| 5910 while ((ch != EOF) && (index - start < width)) | 5930 while ((ch != EOF) && (index - start < width)) |
| 5911 { | 5931 { |
| 5912 /* Integer part */ | 5932 /* Integer part */ |
| 5913 if (isHex ? isxdigit(ch) : isdigit(ch)) | 5933 if (isHex ? isxdigit(ch) : isdigit(ch)) |
| 5914 { | 5934 { |
| 5915 doubleString[index++] = (char)ch; | 5935 doubleString[index++] = (char)ch; |
| 5916 self->InStream(self, &ch); | 5936 self->InStream(self, &ch); |
| 5917 } | 5937 } |
| 5918 else if (flags & FLAGS_QUOTE) | 5938 else if (flags & FLAGS_QUOTE) |
| 5919 { | 5939 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5959 doubleString[index++] = (char)ch; | 5979 doubleString[index++] = (char)ch; |
| 5960 self->InStream(self, &ch); | 5980 self->InStream(self, &ch); |
| 5961 } | 5981 } |
| 5962 } | 5982 } |
| 5963 } | 5983 } |
| 5964 | 5984 |
| 5965 if ((index == start) || (*doubleString == NIL)) | 5985 if ((index == start) || (*doubleString == NIL)) |
| 5966 return FALSE; | 5986 return FALSE; |
| 5967 | 5987 |
| 5968 doubleString[index] = 0; | 5988 doubleString[index] = 0; |
| 5969 | 5989 |
| 5970 if (flags & FLAGS_LONGDOUBLE) | 5990 if (flags & FLAGS_LONGDOUBLE) |
| 5971 { | 5991 { |
| 5972 *((trio_long_double_t *)target) = trio_to_long_double(doubleString, NULL); | 5992 *((trio_long_double_t *)target) = trio_to_long_double(doubleString, NULL); |
| 5973 } | 5993 } |
| 5974 else | 5994 else |
| 5975 { | 5995 { |
| 5976 *((double *)target) = trio_to_double(doubleString, NULL); | 5996 *((double *)target) = trio_to_double(doubleString, NULL); |
| 5977 } | 5997 } |
| 5978 return TRUE; | 5998 return TRUE; |
| 5979 } | 5999 } |
| 5980 | 6000 |
| 5981 /************************************************************************* | 6001 /************************************************************************* |
| 5982 * TrioReadPointer | 6002 * TrioReadPointer |
| 5983 */ | 6003 */ |
| 5984 TRIO_PRIVATE BOOLEAN_T | 6004 TRIO_PRIVATE BOOLEAN_T |
| 5985 TrioReadPointer | 6005 TrioReadPointer |
| 5986 TRIO_ARGS3((self, target, flags), | 6006 TRIO_ARGS3((self, target, flags), |
| 5987 trio_class_t *self, | 6007 trio_class_t *self, |
| 5988 trio_pointer_t *target, | 6008 trio_pointer_t *target, |
| 5989 trio_flags_t flags) | 6009 trio_flags_t flags) |
| 5990 { | 6010 { |
| 5991 trio_uintmax_t number; | 6011 trio_uintmax_t number; |
| 5992 char buffer[sizeof(internalNullString)]; | 6012 char buffer[sizeof(internalNullString)]; |
| 5993 | 6013 |
| 5994 flags |= (FLAGS_UNSIGNED | FLAGS_ALTERNATIVE | FLAGS_NILPADDING); | 6014 flags |= (FLAGS_UNSIGNED | FLAGS_ALTERNATIVE | FLAGS_NILPADDING); |
| 5995 | 6015 |
| 5996 if (TrioReadNumber(self, | 6016 if (TrioReadNumber(self, |
| 5997 &number, | 6017 &number, |
| 5998 flags, | 6018 flags, |
| 5999 POINTER_WIDTH, | 6019 POINTER_WIDTH, |
| 6000 BASE_HEX)) | 6020 BASE_HEX)) |
| 6001 { | 6021 { |
| 6002 /* | 6022 /* |
| 6003 * The strange assignment of number is a workaround for a compiler | 6023 * The strange assignment of number is a workaround for a compiler |
| 6004 * warning | 6024 * warning |
| 6005 */ | 6025 */ |
| 6006 if (target) | 6026 if (target) |
| 6007 *target = (char *)0 + number; | 6027 *target = (char *)0 + number; |
| 6008 return TRUE; | 6028 return TRUE; |
| 6009 } | 6029 } |
| 6010 else if (TrioReadString(self, | 6030 else if (TrioReadString(self, |
| 6011 (flags & FLAGS_IGNORE) | 6031 (flags & FLAGS_IGNORE) |
| 6012 ? NULL | 6032 ? NULL |
| 6013 : buffer, | 6033 : buffer, |
| 6014 0, | 6034 0, |
| 6015 sizeof(internalNullString) - 1)) | 6035 sizeof(internalNullString) - 1)) |
| 6016 { | 6036 { |
| 6017 if (trio_equal_case(buffer, internalNullString)) | 6037 if (trio_equal_case(buffer, internalNullString)) |
| 6018 { | 6038 { |
| 6019 if (target) | 6039 if (target) |
| 6020 *target = NULL; | 6040 *target = NULL; |
| 6021 return TRUE; | 6041 return TRUE; |
| 6022 } | 6042 } |
| 6023 } | 6043 } |
| 6024 return FALSE; | 6044 return FALSE; |
| 6025 } | 6045 } |
| 6026 | 6046 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6070 if (ch != format[index + cnt]) | 6090 if (ch != format[index + cnt]) |
| 6071 { | 6091 { |
| 6072 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); | 6092 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); |
| 6073 } | 6093 } |
| 6074 data->InStream(data, &ch); | 6094 data->InStream(data, &ch); |
| 6075 } | 6095 } |
| 6076 continue; /* while characters left in formatting string */ | 6096 continue; /* while characters left in formatting string */ |
| 6077 } | 6097 } |
| 6078 } | 6098 } |
| 6079 #endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */ | 6099 #endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */ |
| 6080 | 6100 |
| 6081 if ((EOF == ch) && (parameters[i].type != FORMAT_COUNT)) | 6101 if ((EOF == ch) && (parameters[i].type != FORMAT_COUNT)) |
| 6082 { | 6102 { |
| 6083 return (assignment > 0) ? assignment : EOF; | 6103 return (assignment > 0) ? assignment : EOF; |
| 6084 } | 6104 } |
| 6085 | 6105 |
| 6086 if (CHAR_IDENTIFIER == format[index]) | 6106 if (CHAR_IDENTIFIER == format[index]) |
| 6087 { | 6107 { |
| 6088 if (CHAR_IDENTIFIER == format[index + 1]) | 6108 if (CHAR_IDENTIFIER == format[index + 1]) |
| 6089 { | 6109 { |
| 6090 /* Two % in format matches one % in input stream */ | 6110 /* Two % in format matches one % in input stream */ |
| 6091 if (CHAR_IDENTIFIER == ch) | 6111 if (CHAR_IDENTIFIER == ch) |
| 6092 { | 6112 { |
| 6093 data->InStream(data, &ch); | 6113 data->InStream(data, &ch); |
| 6094 index += 2; | 6114 index += 2; |
| 6095 continue; /* while format chars left */ | 6115 continue; /* while format chars left */ |
| 6096 } | 6116 } |
| 6097 else | 6117 else |
| 6098 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); | 6118 return TRIO_ERROR_RETURN(TRIO_EINVAL, index); |
| 6099 } | 6119 } |
| 6100 | 6120 |
| 6101 /* Skip the parameter entries */ | 6121 /* Skip the parameter entries */ |
| 6102 while (parameters[i].type == FORMAT_PARAMETER) | 6122 while (parameters[i].type == FORMAT_PARAMETER) |
| 6103 i++; | 6123 i++; |
| 6104 » | 6124 |
| 6105 flags = parameters[i].flags; | 6125 flags = parameters[i].flags; |
| 6106 /* Find width */ | 6126 /* Find width */ |
| 6107 width = parameters[i].width; | 6127 width = parameters[i].width; |
| 6108 if (flags & FLAGS_WIDTH_PARAMETER) | 6128 if (flags & FLAGS_WIDTH_PARAMETER) |
| 6109 { | 6129 { |
| 6110 /* Get width from parameter list */ | 6130 /* Get width from parameter list */ |
| 6111 width = (int)parameters[width].data.number.as_signed; | 6131 width = (int)parameters[width].data.number.as_signed; |
| 6112 } | 6132 } |
| 6113 /* Find base */ | 6133 /* Find base */ |
| 6114 base = parameters[i].base; | 6134 base = parameters[i].base; |
| 6115 if (flags & FLAGS_BASE_PARAMETER) | 6135 if (flags & FLAGS_BASE_PARAMETER) |
| 6116 { | 6136 { |
| 6117 /* Get base from parameter list */ | 6137 /* Get base from parameter list */ |
| 6118 base = (int)parameters[base].data.number.as_signed; | 6138 base = (int)parameters[base].data.number.as_signed; |
| 6119 } | 6139 } |
| 6120 » | 6140 |
| 6121 switch (parameters[i].type) | 6141 switch (parameters[i].type) |
| 6122 { | 6142 { |
| 6123 case FORMAT_INT: | 6143 case FORMAT_INT: |
| 6124 { | 6144 { |
| 6125 trio_uintmax_t number; | 6145 trio_uintmax_t number; |
| 6126 | 6146 |
| 6127 if (0 == base) | 6147 if (0 == base) |
| 6128 base = BASE_DECIMAL; | 6148 base = BASE_DECIMAL; |
| 6129 | 6149 |
| 6130 if (!TrioReadNumber(data, | 6150 if (!TrioReadNumber(data, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 6158 *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)number; | 6178 *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)number; |
| 6159 else if (flags & FLAGS_LONG) | 6179 else if (flags & FLAGS_LONG) |
| 6160 *(long int *)pointer = (long int)number; | 6180 *(long int *)pointer = (long int)number; |
| 6161 else if (flags & FLAGS_SHORT) | 6181 else if (flags & FLAGS_SHORT) |
| 6162 *(short int *)pointer = (short int)number; | 6182 *(short int *)pointer = (short int)number; |
| 6163 else | 6183 else |
| 6164 *(int *)pointer = (int)number; | 6184 *(int *)pointer = (int)number; |
| 6165 } | 6185 } |
| 6166 } | 6186 } |
| 6167 break; /* FORMAT_INT */ | 6187 break; /* FORMAT_INT */ |
| 6168 » | 6188 |
| 6169 case FORMAT_STRING: | 6189 case FORMAT_STRING: |
| 6170 #if TRIO_WIDECHAR | 6190 #if TRIO_WIDECHAR |
| 6171 if (flags & FLAGS_WIDECHAR) | 6191 if (flags & FLAGS_WIDECHAR) |
| 6172 { | 6192 { |
| 6173 if (!TrioReadWideString(data, | 6193 if (!TrioReadWideString(data, |
| 6174 (flags & FLAGS_IGNORE) | 6194 (flags & FLAGS_IGNORE) |
| 6175 ? NULL | 6195 ? NULL |
| 6176 : parameters[i].data.wstring, | 6196 : parameters[i].data.wstring, |
| 6177 flags, | 6197 flags, |
| 6178 width)) | 6198 width)) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6222 int characterclass[MAX_CHARACTER_CLASS + 1]; | 6242 int characterclass[MAX_CHARACTER_CLASS + 1]; |
| 6223 int rc; | 6243 int rc; |
| 6224 | 6244 |
| 6225 /* Skip over modifiers */ | 6245 /* Skip over modifiers */ |
| 6226 while (format[index] != SPECIFIER_GROUP) | 6246 while (format[index] != SPECIFIER_GROUP) |
| 6227 { | 6247 { |
| 6228 index++; | 6248 index++; |
| 6229 } | 6249 } |
| 6230 /* Skip over group specifier */ | 6250 /* Skip over group specifier */ |
| 6231 index++; | 6251 index++; |
| 6232 » » | 6252 |
| 6233 memset(characterclass, 0, sizeof(characterclass)); | 6253 memset(characterclass, 0, sizeof(characterclass)); |
| 6234 rc = TrioGetCharacterClass(format, | 6254 rc = TrioGetCharacterClass(format, |
| 6235 &index, | 6255 &index, |
| 6236 &flags, | 6256 &flags, |
| 6237 characterclass); | 6257 characterclass); |
| 6238 if (rc < 0) | 6258 if (rc < 0) |
| 6239 return rc; | 6259 return rc; |
| 6240 | 6260 |
| 6241 if (!TrioReadGroup(data, | 6261 if (!TrioReadGroup(data, |
| 6242 (flags & FLAGS_IGNORE) | 6262 (flags & FLAGS_IGNORE) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6284 else if (flags & FLAGS_SHORT) | 6304 else if (flags & FLAGS_SHORT) |
| 6285 { | 6305 { |
| 6286 *(short int *)pointer = (short int)count; | 6306 *(short int *)pointer = (short int)count; |
| 6287 } | 6307 } |
| 6288 else | 6308 else |
| 6289 { | 6309 { |
| 6290 *(int *)pointer = (int)count; | 6310 *(int *)pointer = (int)count; |
| 6291 } | 6311 } |
| 6292 } | 6312 } |
| 6293 break; /* FORMAT_COUNT */ | 6313 break; /* FORMAT_COUNT */ |
| 6294 » | 6314 |
| 6295 case FORMAT_CHAR: | 6315 case FORMAT_CHAR: |
| 6296 #if TRIO_WIDECHAR | 6316 #if TRIO_WIDECHAR |
| 6297 if (flags & FLAGS_WIDECHAR) | 6317 if (flags & FLAGS_WIDECHAR) |
| 6298 { | 6318 { |
| 6299 if (TrioReadWideChar(data, | 6319 if (TrioReadWideChar(data, |
| 6300 (flags & FLAGS_IGNORE) | 6320 (flags & FLAGS_IGNORE) |
| 6301 ? NULL | 6321 ? NULL |
| 6302 : parameters[i].data.wstring, | 6322 : parameters[i].data.wstring, |
| 6303 flags, | 6323 flags, |
| 6304 (width == NO_WIDTH) ? 1 : width) == 0) | 6324 (width == NO_WIDTH) ? 1 : width) == 0) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6346 { | 6366 { |
| 6347 /* Whitespaces may match any amount of whitespaces */ | 6367 /* Whitespaces may match any amount of whitespaces */ |
| 6348 ch = TrioSkipWhitespaces(data); | 6368 ch = TrioSkipWhitespaces(data); |
| 6349 } | 6369 } |
| 6350 else if (ch == format[index]) | 6370 else if (ch == format[index]) |
| 6351 { | 6371 { |
| 6352 data->InStream(data, &ch); | 6372 data->InStream(data, &ch); |
| 6353 } | 6373 } |
| 6354 else | 6374 else |
| 6355 return assignment; | 6375 return assignment; |
| 6356 » | 6376 |
| 6357 index++; | 6377 index++; |
| 6358 } | 6378 } |
| 6359 } | 6379 } |
| 6360 return assignment; | 6380 return assignment; |
| 6361 } | 6381 } |
| 6362 | 6382 |
| 6363 /************************************************************************* | 6383 /************************************************************************* |
| 6364 * TrioScan | 6384 * TrioScan |
| 6365 */ | 6385 */ |
| 6366 TRIO_PRIVATE int | 6386 TRIO_PRIVATE int |
| 6367 TrioScan | 6387 TrioScan |
| 6368 TRIO_ARGS6((source, sourceSize, InStream, format, arglist, argarray), | 6388 TRIO_ARGS6((source, sourceSize, InStream, format, arglist, argarray), |
| 6369 trio_pointer_t source, | 6389 trio_pointer_t source, |
| 6370 size_t sourceSize, | 6390 size_t sourceSize, |
| 6371 void (*InStream) TRIO_PROTO((trio_class_t *, int *)), | 6391 void (*InStream) TRIO_PROTO((trio_class_t *, int *)), |
| 6372 TRIO_CONST char *format, | 6392 TRIO_CONST char *format, |
| 6373 » va_list *arglist, | 6393 » TRIO_VA_LIST_PTR arglist, |
| 6374 trio_pointer_t *argarray) | 6394 trio_pointer_t *argarray) |
| 6375 { | 6395 { |
| 6376 int status; | 6396 int status; |
| 6377 trio_parameter_t parameters[MAX_PARAMETERS]; | 6397 trio_parameter_t parameters[MAX_PARAMETERS]; |
| 6378 trio_class_t data; | 6398 trio_class_t data; |
| 6379 | 6399 |
| 6380 assert(VALID(InStream)); | 6400 assert(VALID(InStream)); |
| 6381 assert(VALID(format)); | 6401 assert(VALID(format)); |
| 6382 | 6402 |
| 6383 memset(&data, 0, sizeof(data)); | 6403 memset(&data, 0, sizeof(data)); |
| 6384 data.InStream = InStream; | 6404 data.InStream = InStream; |
| 6385 data.location = (trio_pointer_t)source; | 6405 data.location = (trio_pointer_t)source; |
| 6386 data.max = sourceSize; | 6406 data.max = sourceSize; |
| 6387 data.error = 0; | 6407 data.error = 0; |
| 6388 | 6408 |
| 6389 #if defined(USE_LOCALE) | 6409 #if defined(USE_LOCALE) |
| 6390 if (NULL == internalLocaleValues) | 6410 if (NULL == internalLocaleValues) |
| 6391 { | 6411 { |
| 6392 TrioSetLocale(); | 6412 TrioSetLocale(); |
| 6393 } | 6413 } |
| 6394 #endif | 6414 #endif |
| 6395 | 6415 |
| 6396 status = TrioParse(TYPE_SCAN, format, parameters, arglist, argarray); | 6416 status = TrioParse(TYPE_SCAN, format, parameters, arglist, argarray); |
| 6397 if (status < 0) | 6417 if (status < 0) |
| 6398 return status; | 6418 return status; |
| 6399 | 6419 |
| 6400 status = TrioScanProcess(&data, format, parameters); | 6420 status = TrioScanProcess(&data, format, parameters); |
| 6401 if (data.error != 0) | 6421 if (data.error != 0) |
| 6402 { | 6422 { |
| 6403 status = data.error; | 6423 status = data.error; |
| 6404 } | 6424 } |
| 6405 return status; | 6425 return status; |
| 6406 } | 6426 } |
| 6407 | 6427 |
| 6408 /************************************************************************* | 6428 /************************************************************************* |
| 6409 * TrioInStreamFile | 6429 * TrioInStreamFile |
| 6410 */ | 6430 */ |
| 6411 TRIO_PRIVATE void | 6431 TRIO_PRIVATE void |
| 6412 TrioInStreamFile | 6432 TrioInStreamFile |
| 6413 TRIO_ARGS2((self, intPointer), | 6433 TRIO_ARGS2((self, intPointer), |
| 6414 trio_class_t *self, | 6434 trio_class_t *self, |
| 6415 int *intPointer) | 6435 int *intPointer) |
| 6416 { | 6436 { |
| 6417 FILE *file = (FILE *)self->location; | 6437 FILE *file; |
| 6418 | 6438 |
| 6419 assert(VALID(self)); | 6439 assert(VALID(self)); |
| 6440 assert(VALID(self->location)); |
| 6420 assert(VALID(file)); | 6441 assert(VALID(file)); |
| 6421 | 6442 |
| 6443 file = (FILE *)self->location; |
| 6444 |
| 6422 self->current = fgetc(file); | 6445 self->current = fgetc(file); |
| 6423 if (self->current == EOF) | 6446 if (self->current == EOF) |
| 6424 { | 6447 { |
| 6425 self->error = (ferror(file)) | 6448 self->error = (ferror(file)) |
| 6426 ? TRIO_ERROR_RETURN(TRIO_ERRNO, 0) | 6449 ? TRIO_ERROR_RETURN(TRIO_ERRNO, 0) |
| 6427 : TRIO_ERROR_RETURN(TRIO_EOF, 0); | 6450 : TRIO_ERROR_RETURN(TRIO_EOF, 0); |
| 6428 } | 6451 } |
| 6429 else | 6452 else |
| 6430 { | 6453 { |
| 6431 self->processed++; | 6454 self->processed++; |
| 6432 self->committed++; | 6455 self->committed++; |
| 6433 } | 6456 } |
| 6434 | 6457 |
| 6435 if (VALID(intPointer)) | 6458 if (VALID(intPointer)) |
| 6436 { | 6459 { |
| 6437 *intPointer = self->current; | 6460 *intPointer = self->current; |
| 6438 } | 6461 } |
| 6439 } | 6462 } |
| 6440 | 6463 |
| 6441 /************************************************************************* | 6464 /************************************************************************* |
| 6442 * TrioInStreamFileDescriptor | 6465 * TrioInStreamFileDescriptor |
| 6443 */ | 6466 */ |
| 6444 TRIO_PRIVATE void | 6467 TRIO_PRIVATE void |
| 6445 TrioInStreamFileDescriptor | 6468 TrioInStreamFileDescriptor |
| 6446 TRIO_ARGS2((self, intPointer), | 6469 TRIO_ARGS2((self, intPointer), |
| 6447 trio_class_t *self, | 6470 trio_class_t *self, |
| 6448 int *intPointer) | 6471 int *intPointer) |
| 6449 { | 6472 { |
| 6450 int fd = *((int *)self->location); | 6473 int fd; |
| 6451 int size; | 6474 int size; |
| 6452 unsigned char input; | 6475 unsigned char input; |
| 6453 | 6476 |
| 6454 assert(VALID(self)); | 6477 assert(VALID(self)); |
| 6478 assert(VALID(self->location)); |
| 6479 |
| 6480 fd = *((int *)self->location); |
| 6455 | 6481 |
| 6456 size = read(fd, &input, sizeof(char)); | 6482 size = read(fd, &input, sizeof(char)); |
| 6457 if (size == -1) | 6483 if (size == -1) |
| 6458 { | 6484 { |
| 6459 self->error = TRIO_ERROR_RETURN(TRIO_ERRNO, 0); | 6485 self->error = TRIO_ERROR_RETURN(TRIO_ERRNO, 0); |
| 6460 self->current = EOF; | 6486 self->current = EOF; |
| 6461 } | 6487 } |
| 6462 else | 6488 else |
| 6463 { | 6489 { |
| 6464 self->current = (size == 0) ? EOF : input; | 6490 self->current = (size == 0) ? EOF : input; |
| 6465 } | 6491 } |
| 6466 if (self->current != EOF) | 6492 if (self->current != EOF) |
| 6467 { | 6493 { |
| 6468 self->committed++; | 6494 self->committed++; |
| 6469 self->processed++; | 6495 self->processed++; |
| 6470 } | 6496 } |
| 6471 | 6497 |
| 6472 if (VALID(intPointer)) | 6498 if (VALID(intPointer)) |
| 6473 { | 6499 { |
| 6474 *intPointer = self->current; | 6500 *intPointer = self->current; |
| 6475 } | 6501 } |
| 6476 } | 6502 } |
| 6477 | 6503 |
| 6478 /************************************************************************* | 6504 /************************************************************************* |
| 6479 * TrioInStreamCustom | 6505 * TrioInStreamCustom |
| 6480 */ | 6506 */ |
| 6481 TRIO_PRIVATE void | 6507 TRIO_PRIVATE void |
| 6482 TrioInStreamCustom | 6508 TrioInStreamCustom |
| 6483 TRIO_ARGS2((self, intPointer), | 6509 TRIO_ARGS2((self, intPointer), |
| 6484 trio_class_t *self, | 6510 trio_class_t *self, |
| 6485 int *intPointer) | 6511 int *intPointer) |
| 6486 { | 6512 { |
| 6487 trio_custom_t *data; | 6513 trio_custom_t *data; |
| 6488 | 6514 |
| 6489 assert(VALID(self)); | 6515 assert(VALID(self)); |
| 6490 assert(VALID(self->location)); | 6516 assert(VALID(self->location)); |
| 6491 | 6517 |
| 6492 data = (trio_custom_t *)self->location; | 6518 data = (trio_custom_t *)self->location; |
| 6493 | 6519 |
| 6494 self->current = (data->stream.in == NULL) | 6520 self->current = (data->stream.in == NULL) |
| 6495 ? NIL | 6521 ? NIL |
| 6496 : (data->stream.in)(data->closure); | 6522 : (data->stream.in)(data->closure); |
| 6497 | 6523 |
| 6498 if (self->current == NIL) | 6524 if (self->current == NIL) |
| 6499 { | 6525 { |
| 6500 self->current = EOF; | 6526 self->current = EOF; |
| 6501 } | 6527 } |
| 6502 else | 6528 else |
| 6503 { | 6529 { |
| 6504 self->processed++; | 6530 self->processed++; |
| 6505 self->committed++; | 6531 self->committed++; |
| 6506 } | 6532 } |
| 6507 | 6533 |
| 6508 if (VALID(intPointer)) | 6534 if (VALID(intPointer)) |
| 6509 { | 6535 { |
| 6510 *intPointer = self->current; | 6536 *intPointer = self->current; |
| 6511 } | 6537 } |
| 6512 } | 6538 } |
| 6513 | 6539 |
| 6514 /************************************************************************* | 6540 /************************************************************************* |
| 6515 * TrioInStreamString | 6541 * TrioInStreamString |
| 6516 */ | 6542 */ |
| 6517 TRIO_PRIVATE void | 6543 TRIO_PRIVATE void |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6530 if (self->current == NIL) | 6556 if (self->current == NIL) |
| 6531 { | 6557 { |
| 6532 self->current = EOF; | 6558 self->current = EOF; |
| 6533 } | 6559 } |
| 6534 else | 6560 else |
| 6535 { | 6561 { |
| 6536 (*buffer)++; | 6562 (*buffer)++; |
| 6537 self->processed++; | 6563 self->processed++; |
| 6538 self->committed++; | 6564 self->committed++; |
| 6539 } | 6565 } |
| 6540 | 6566 |
| 6541 if (VALID(intPointer)) | 6567 if (VALID(intPointer)) |
| 6542 { | 6568 { |
| 6543 *intPointer = self->current; | 6569 *intPointer = self->current; |
| 6544 } | 6570 } |
| 6545 } | 6571 } |
| 6546 | 6572 |
| 6547 /************************************************************************* | 6573 /************************************************************************* |
| 6548 * | 6574 * |
| 6549 * Formatted scanning functions | 6575 * Formatted scanning functions |
| 6550 * | 6576 * |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6571 TRIO_PUBLIC int | 6597 TRIO_PUBLIC int |
| 6572 trio_scanf | 6598 trio_scanf |
| 6573 TRIO_VARGS2((format, va_alist), | 6599 TRIO_VARGS2((format, va_alist), |
| 6574 TRIO_CONST char *format, | 6600 TRIO_CONST char *format, |
| 6575 TRIO_VA_DECL) | 6601 TRIO_VA_DECL) |
| 6576 { | 6602 { |
| 6577 int status; | 6603 int status; |
| 6578 va_list args; | 6604 va_list args; |
| 6579 | 6605 |
| 6580 assert(VALID(format)); | 6606 assert(VALID(format)); |
| 6581 | 6607 |
| 6582 TRIO_VA_START(args, format); | 6608 TRIO_VA_START(args, format); |
| 6583 status = TrioScan((trio_pointer_t)stdin, 0, | 6609 status = TrioScan((trio_pointer_t)stdin, 0, |
| 6584 TrioInStreamFile, | 6610 TrioInStreamFile, |
| 6585 » » format, &args, NULL); | 6611 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6586 TRIO_VA_END(args); | 6612 TRIO_VA_END(args); |
| 6587 return status; | 6613 return status; |
| 6588 } | 6614 } |
| 6589 | 6615 |
| 6590 TRIO_PUBLIC int | 6616 TRIO_PUBLIC int |
| 6591 trio_vscanf | 6617 trio_vscanf |
| 6592 TRIO_ARGS2((format, args), | 6618 TRIO_ARGS2((format, args), |
| 6593 TRIO_CONST char *format, | 6619 TRIO_CONST char *format, |
| 6594 va_list args) | 6620 va_list args) |
| 6595 { | 6621 { |
| 6596 assert(VALID(format)); | 6622 assert(VALID(format)); |
| 6597 | 6623 |
| 6598 return TrioScan((trio_pointer_t)stdin, 0, | 6624 return TrioScan((trio_pointer_t)stdin, 0, |
| 6599 TrioInStreamFile, | 6625 TrioInStreamFile, |
| 6600 » » format, &args, NULL); | 6626 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6601 } | 6627 } |
| 6602 | 6628 |
| 6603 TRIO_PUBLIC int | 6629 TRIO_PUBLIC int |
| 6604 trio_scanfv | 6630 trio_scanfv |
| 6605 TRIO_ARGS2((format, args), | 6631 TRIO_ARGS2((format, args), |
| 6606 TRIO_CONST char *format, | 6632 TRIO_CONST char *format, |
| 6607 trio_pointer_t *args) | 6633 trio_pointer_t *args) |
| 6608 { | 6634 { |
| 6609 assert(VALID(format)); | 6635 assert(VALID(format)); |
| 6610 | 6636 |
| 6611 return TrioScan((trio_pointer_t)stdin, 0, | 6637 return TrioScan((trio_pointer_t)stdin, 0, |
| 6612 TrioInStreamFile, | 6638 TrioInStreamFile, |
| 6613 format, NULL, args); | 6639 format, NULL, args); |
| 6614 } | 6640 } |
| 6615 | 6641 |
| 6616 /************************************************************************* | 6642 /************************************************************************* |
| 6617 * fscanf | 6643 * fscanf |
| 6618 */ | 6644 */ |
| 6619 TRIO_PUBLIC int | 6645 TRIO_PUBLIC int |
| 6620 trio_fscanf | 6646 trio_fscanf |
| 6621 TRIO_VARGS3((file, format, va_alist), | 6647 TRIO_VARGS3((file, format, va_alist), |
| 6622 FILE *file, | 6648 FILE *file, |
| 6623 TRIO_CONST char *format, | 6649 TRIO_CONST char *format, |
| 6624 TRIO_VA_DECL) | 6650 TRIO_VA_DECL) |
| 6625 { | 6651 { |
| 6626 int status; | 6652 int status; |
| 6627 va_list args; | 6653 va_list args; |
| 6628 | 6654 |
| 6629 assert(VALID(file)); | 6655 assert(VALID(file)); |
| 6630 assert(VALID(format)); | 6656 assert(VALID(format)); |
| 6631 | 6657 |
| 6632 TRIO_VA_START(args, format); | 6658 TRIO_VA_START(args, format); |
| 6633 status = TrioScan((trio_pointer_t)file, 0, | 6659 status = TrioScan((trio_pointer_t)file, 0, |
| 6634 TrioInStreamFile, | 6660 TrioInStreamFile, |
| 6635 » » format, &args, NULL); | 6661 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6636 TRIO_VA_END(args); | 6662 TRIO_VA_END(args); |
| 6637 return status; | 6663 return status; |
| 6638 } | 6664 } |
| 6639 | 6665 |
| 6640 TRIO_PUBLIC int | 6666 TRIO_PUBLIC int |
| 6641 trio_vfscanf | 6667 trio_vfscanf |
| 6642 TRIO_ARGS3((file, format, args), | 6668 TRIO_ARGS3((file, format, args), |
| 6643 FILE *file, | 6669 FILE *file, |
| 6644 TRIO_CONST char *format, | 6670 TRIO_CONST char *format, |
| 6645 va_list args) | 6671 va_list args) |
| 6646 { | 6672 { |
| 6647 assert(VALID(file)); | 6673 assert(VALID(file)); |
| 6648 assert(VALID(format)); | 6674 assert(VALID(format)); |
| 6649 | 6675 |
| 6650 return TrioScan((trio_pointer_t)file, 0, | 6676 return TrioScan((trio_pointer_t)file, 0, |
| 6651 TrioInStreamFile, | 6677 TrioInStreamFile, |
| 6652 » » format, &args, NULL); | 6678 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6653 } | 6679 } |
| 6654 | 6680 |
| 6655 TRIO_PUBLIC int | 6681 TRIO_PUBLIC int |
| 6656 trio_fscanfv | 6682 trio_fscanfv |
| 6657 TRIO_ARGS3((file, format, args), | 6683 TRIO_ARGS3((file, format, args), |
| 6658 FILE *file, | 6684 FILE *file, |
| 6659 TRIO_CONST char *format, | 6685 TRIO_CONST char *format, |
| 6660 trio_pointer_t *args) | 6686 trio_pointer_t *args) |
| 6661 { | 6687 { |
| 6662 assert(VALID(file)); | 6688 assert(VALID(file)); |
| 6663 assert(VALID(format)); | 6689 assert(VALID(format)); |
| 6664 | 6690 |
| 6665 return TrioScan((trio_pointer_t)file, 0, | 6691 return TrioScan((trio_pointer_t)file, 0, |
| 6666 TrioInStreamFile, | 6692 TrioInStreamFile, |
| 6667 format, NULL, args); | 6693 format, NULL, args); |
| 6668 } | 6694 } |
| 6669 | 6695 |
| 6670 /************************************************************************* | 6696 /************************************************************************* |
| 6671 * dscanf | 6697 * dscanf |
| 6672 */ | 6698 */ |
| 6673 TRIO_PUBLIC int | 6699 TRIO_PUBLIC int |
| 6674 trio_dscanf | 6700 trio_dscanf |
| 6675 TRIO_VARGS3((fd, format, va_alist), | 6701 TRIO_VARGS3((fd, format, va_alist), |
| 6676 int fd, | 6702 int fd, |
| 6677 TRIO_CONST char *format, | 6703 TRIO_CONST char *format, |
| 6678 TRIO_VA_DECL) | 6704 TRIO_VA_DECL) |
| 6679 { | 6705 { |
| 6680 int status; | 6706 int status; |
| 6681 va_list args; | 6707 va_list args; |
| 6682 | 6708 |
| 6683 assert(VALID(format)); | 6709 assert(VALID(format)); |
| 6684 | 6710 |
| 6685 TRIO_VA_START(args, format); | 6711 TRIO_VA_START(args, format); |
| 6686 status = TrioScan((trio_pointer_t)&fd, 0, | 6712 status = TrioScan((trio_pointer_t)&fd, 0, |
| 6687 TrioInStreamFileDescriptor, | 6713 TrioInStreamFileDescriptor, |
| 6688 » » format, &args, NULL); | 6714 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6689 TRIO_VA_END(args); | 6715 TRIO_VA_END(args); |
| 6690 return status; | 6716 return status; |
| 6691 } | 6717 } |
| 6692 | 6718 |
| 6693 TRIO_PUBLIC int | 6719 TRIO_PUBLIC int |
| 6694 trio_vdscanf | 6720 trio_vdscanf |
| 6695 TRIO_ARGS3((fd, format, args), | 6721 TRIO_ARGS3((fd, format, args), |
| 6696 int fd, | 6722 int fd, |
| 6697 TRIO_CONST char *format, | 6723 TRIO_CONST char *format, |
| 6698 va_list args) | 6724 va_list args) |
| 6699 { | 6725 { |
| 6700 assert(VALID(format)); | 6726 assert(VALID(format)); |
| 6701 | 6727 |
| 6702 return TrioScan((trio_pointer_t)&fd, 0, | 6728 return TrioScan((trio_pointer_t)&fd, 0, |
| 6703 TrioInStreamFileDescriptor, | 6729 TrioInStreamFileDescriptor, |
| 6704 » » format, &args, NULL); | 6730 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6705 } | 6731 } |
| 6706 | 6732 |
| 6707 TRIO_PUBLIC int | 6733 TRIO_PUBLIC int |
| 6708 trio_dscanfv | 6734 trio_dscanfv |
| 6709 TRIO_ARGS3((fd, format, args), | 6735 TRIO_ARGS3((fd, format, args), |
| 6710 int fd, | 6736 int fd, |
| 6711 TRIO_CONST char *format, | 6737 TRIO_CONST char *format, |
| 6712 trio_pointer_t *args) | 6738 trio_pointer_t *args) |
| 6713 { | 6739 { |
| 6714 assert(VALID(format)); | 6740 assert(VALID(format)); |
| 6715 | 6741 |
| 6716 return TrioScan((trio_pointer_t)&fd, 0, | 6742 return TrioScan((trio_pointer_t)&fd, 0, |
| 6717 TrioInStreamFileDescriptor, | 6743 TrioInStreamFileDescriptor, |
| 6718 format, NULL, args); | 6744 format, NULL, args); |
| 6719 } | 6745 } |
| 6720 | 6746 |
| 6721 /************************************************************************* | 6747 /************************************************************************* |
| 6722 * cscanf | 6748 * cscanf |
| 6723 */ | 6749 */ |
| 6724 TRIO_PUBLIC int | 6750 TRIO_PUBLIC int |
| 6725 trio_cscanf | 6751 trio_cscanf |
| 6726 TRIO_VARGS4((stream, closure, format, va_alist), | 6752 TRIO_VARGS4((stream, closure, format, va_alist), |
| 6727 trio_instream_t stream, | 6753 trio_instream_t stream, |
| 6728 trio_pointer_t closure, | 6754 trio_pointer_t closure, |
| 6729 TRIO_CONST char *format, | 6755 TRIO_CONST char *format, |
| 6730 TRIO_VA_DECL) | 6756 TRIO_VA_DECL) |
| 6731 { | 6757 { |
| 6732 int status; | 6758 int status; |
| 6733 va_list args; | 6759 va_list args; |
| 6734 trio_custom_t data; | 6760 trio_custom_t data; |
| 6735 | 6761 |
| 6736 assert(VALID(stream)); | 6762 assert(VALID(stream)); |
| 6737 assert(VALID(format)); | 6763 assert(VALID(format)); |
| 6738 | 6764 |
| 6739 TRIO_VA_START(args, format); | 6765 TRIO_VA_START(args, format); |
| 6740 data.stream.in = stream; | 6766 data.stream.in = stream; |
| 6741 data.closure = closure; | 6767 data.closure = closure; |
| 6742 status = TrioScan(&data, 0, TrioInStreamCustom, format, &args, NULL); | 6768 status = TrioScan(&data, 0, TrioInStreamCustom, format, TRIO_VA_LIST_ADDR(args
), NULL); |
| 6743 TRIO_VA_END(args); | 6769 TRIO_VA_END(args); |
| 6744 return status; | 6770 return status; |
| 6745 } | 6771 } |
| 6746 | 6772 |
| 6747 TRIO_PUBLIC int | 6773 TRIO_PUBLIC int |
| 6748 trio_vcscanf | 6774 trio_vcscanf |
| 6749 TRIO_ARGS4((stream, closure, format, args), | 6775 TRIO_ARGS4((stream, closure, format, args), |
| 6750 trio_instream_t stream, | 6776 trio_instream_t stream, |
| 6751 trio_pointer_t closure, | 6777 trio_pointer_t closure, |
| 6752 TRIO_CONST char *format, | 6778 TRIO_CONST char *format, |
| 6753 va_list args) | 6779 va_list args) |
| 6754 { | 6780 { |
| 6755 trio_custom_t data; | 6781 trio_custom_t data; |
| 6756 | 6782 |
| 6757 assert(VALID(stream)); | 6783 assert(VALID(stream)); |
| 6758 assert(VALID(format)); | 6784 assert(VALID(format)); |
| 6759 | 6785 |
| 6760 data.stream.in = stream; | 6786 data.stream.in = stream; |
| 6761 data.closure = closure; | 6787 data.closure = closure; |
| 6762 return TrioScan(&data, 0, TrioInStreamCustom, format, &args, NULL); | 6788 return TrioScan(&data, 0, TrioInStreamCustom, format, TRIO_VA_LIST_ADDR(args),
NULL); |
| 6763 } | 6789 } |
| 6764 | 6790 |
| 6765 TRIO_PUBLIC int | 6791 TRIO_PUBLIC int |
| 6766 trio_cscanfv | 6792 trio_cscanfv |
| 6767 TRIO_ARGS4((stream, closure, format, args), | 6793 TRIO_ARGS4((stream, closure, format, args), |
| 6768 trio_instream_t stream, | 6794 trio_instream_t stream, |
| 6769 trio_pointer_t closure, | 6795 trio_pointer_t closure, |
| 6770 TRIO_CONST char *format, | 6796 TRIO_CONST char *format, |
| 6771 trio_pointer_t *args) | 6797 trio_pointer_t *args) |
| 6772 { | 6798 { |
| 6773 trio_custom_t data; | 6799 trio_custom_t data; |
| 6774 | 6800 |
| 6775 assert(VALID(stream)); | 6801 assert(VALID(stream)); |
| 6776 assert(VALID(format)); | 6802 assert(VALID(format)); |
| 6777 | 6803 |
| 6778 data.stream.in = stream; | 6804 data.stream.in = stream; |
| 6779 data.closure = closure; | 6805 data.closure = closure; |
| 6780 return TrioScan(&data, 0, TrioInStreamCustom, format, NULL, args); | 6806 return TrioScan(&data, 0, TrioInStreamCustom, format, NULL, args); |
| 6781 } | 6807 } |
| 6782 | 6808 |
| 6783 /************************************************************************* | 6809 /************************************************************************* |
| 6784 * sscanf | 6810 * sscanf |
| 6785 */ | 6811 */ |
| 6786 TRIO_PUBLIC int | 6812 TRIO_PUBLIC int |
| 6787 trio_sscanf | 6813 trio_sscanf |
| 6788 TRIO_VARGS3((buffer, format, va_alist), | 6814 TRIO_VARGS3((buffer, format, va_alist), |
| 6789 TRIO_CONST char *buffer, | 6815 TRIO_CONST char *buffer, |
| 6790 TRIO_CONST char *format, | 6816 TRIO_CONST char *format, |
| 6791 TRIO_VA_DECL) | 6817 TRIO_VA_DECL) |
| 6792 { | 6818 { |
| 6793 int status; | 6819 int status; |
| 6794 va_list args; | 6820 va_list args; |
| 6795 | 6821 |
| 6796 assert(VALID(buffer)); | 6822 assert(VALID(buffer)); |
| 6797 assert(VALID(format)); | 6823 assert(VALID(format)); |
| 6798 | 6824 |
| 6799 TRIO_VA_START(args, format); | 6825 TRIO_VA_START(args, format); |
| 6800 status = TrioScan((trio_pointer_t)&buffer, 0, | 6826 status = TrioScan((trio_pointer_t)&buffer, 0, |
| 6801 TrioInStreamString, | 6827 TrioInStreamString, |
| 6802 » » format, &args, NULL); | 6828 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6803 TRIO_VA_END(args); | 6829 TRIO_VA_END(args); |
| 6804 return status; | 6830 return status; |
| 6805 } | 6831 } |
| 6806 | 6832 |
| 6807 TRIO_PUBLIC int | 6833 TRIO_PUBLIC int |
| 6808 trio_vsscanf | 6834 trio_vsscanf |
| 6809 TRIO_ARGS3((buffer, format, args), | 6835 TRIO_ARGS3((buffer, format, args), |
| 6810 TRIO_CONST char *buffer, | 6836 TRIO_CONST char *buffer, |
| 6811 TRIO_CONST char *format, | 6837 TRIO_CONST char *format, |
| 6812 va_list args) | 6838 va_list args) |
| 6813 { | 6839 { |
| 6814 assert(VALID(buffer)); | 6840 assert(VALID(buffer)); |
| 6815 assert(VALID(format)); | 6841 assert(VALID(format)); |
| 6816 | 6842 |
| 6817 return TrioScan((trio_pointer_t)&buffer, 0, | 6843 return TrioScan((trio_pointer_t)&buffer, 0, |
| 6818 TrioInStreamString, | 6844 TrioInStreamString, |
| 6819 » » format, &args, NULL); | 6845 » » format, TRIO_VA_LIST_ADDR(args), NULL); |
| 6820 } | 6846 } |
| 6821 | 6847 |
| 6822 TRIO_PUBLIC int | 6848 TRIO_PUBLIC int |
| 6823 trio_sscanfv | 6849 trio_sscanfv |
| 6824 TRIO_ARGS3((buffer, format, args), | 6850 TRIO_ARGS3((buffer, format, args), |
| 6825 TRIO_CONST char *buffer, | 6851 TRIO_CONST char *buffer, |
| 6826 TRIO_CONST char *format, | 6852 TRIO_CONST char *format, |
| 6827 trio_pointer_t *args) | 6853 trio_pointer_t *args) |
| 6828 { | 6854 { |
| 6829 assert(VALID(buffer)); | 6855 assert(VALID(buffer)); |
| 6830 assert(VALID(format)); | 6856 assert(VALID(format)); |
| 6831 | 6857 |
| 6832 return TrioScan((trio_pointer_t)&buffer, 0, | 6858 return TrioScan((trio_pointer_t)&buffer, 0, |
| 6833 TrioInStreamString, | 6859 TrioInStreamString, |
| 6834 format, NULL, args); | 6860 format, NULL, args); |
| 6835 } | 6861 } |
| 6836 | 6862 |
| 6837 /** @} End of Scanf documentation module */ | 6863 /** @} End of Scanf documentation module */ |
| 6838 | 6864 |
| 6839 /************************************************************************* | 6865 /************************************************************************* |
| 6840 * trio_strerror | 6866 * trio_strerror |
| 6841 */ | 6867 */ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 6860 case TRIO_ENOMEM: | 6886 case TRIO_ENOMEM: |
| 6861 return "Out of memory"; | 6887 return "Out of memory"; |
| 6862 case TRIO_ERANGE: | 6888 case TRIO_ERANGE: |
| 6863 return "Invalid range"; | 6889 return "Invalid range"; |
| 6864 case TRIO_ECUSTOM: | 6890 case TRIO_ECUSTOM: |
| 6865 return "Custom error"; | 6891 return "Custom error"; |
| 6866 default: | 6892 default: |
| 6867 return "Unknown"; | 6893 return "Unknown"; |
| 6868 } | 6894 } |
| 6869 } | 6895 } |
| OLD | NEW |