Quellcode durchsuchen

Adjust preprocessor logic to initialize QUAL_CHARS correctly for Erik's alpha
port. Also, explicitly use the macro versions of isdigit and isspace in the
printf and scanf code.

Manuel Novoa III vor 22 Jahren
Ursprung
Commit
fd2907fec2
3 geänderte Dateien mit 42 neuen und 19 gelöschten Zeilen
  1. 2 1
      libc/stdio/old_vfprintf.c
  2. 32 10
      libc/stdio/printf.c
  3. 8 8
      libc/stdio/scanf.c

+ 2 - 1
libc/stdio/old_vfprintf.c

@@ -128,6 +128,7 @@
 #include <limits.h>
 #include <string.h>
 #include <errno.h>
+#include <ctype.h>
 
 #define __PRINTF_INFO_NO_BITFIELD
 #include <printf.h>
@@ -140,7 +141,7 @@
 /*  #undef WANT_FLOAT_ERROR */
 /*  #define WANT_FLOAT_ERROR      1 */
 
-#define __isdigit(c) (((unsigned int)(c - '0')) < 10)
+/*  #define __isdigit(c) (((unsigned int)(c - '0')) < 10) */
 
 extern size_t _dtostr(FILE * fp, long double x, struct printf_info *info);
 

+ 32 - 10
libc/stdio/printf.c

@@ -36,6 +36,10 @@
  *    reported by Erik Andersen (andersen@codepoet.com)
  * Fix an arg promotion handling bug in _do_one_spec for %c. 
  *    reported by Ilguiz Latypov <ilatypov@superbt.com>
+ *
+ * 5-10-2002
+ * Remove __isdigit and use new ctype.h version.
+ * Add conditional setting of QUAL_CHARS for size_t and ptrdiff_t.
  */
 
 
@@ -173,12 +177,6 @@ enum {
  */
 
 /* TODO -- Fix the table below to take into account stdint.h. */
-#if PTRDIFF_MAX != INT_MAX
-#error fix QUAL_CHARS ptrdiff_t entry 't'!
-#endif
-#if SIZE_MAX != UINT_MAX
-#error fix QUAL_CHARS size_t entries 'z', 'Z'!
-#endif
 #ifndef LLONG_MAX
 #error fix QUAL_CHARS for no long long!  Affects 'L', 'j', 'q', 'll'.
 #else
@@ -187,11 +185,38 @@ enum {
 #endif
 #endif
 
+#ifdef PDS
+#error PDS already defined!
+#endif
+#ifdef SS
+#error SS already defined!
+#endif
+
+#if PTRDIFF_MAX == INT_MAX
+#define PDS		0
+#elif PTRDIFF_MAX == LONG_MAX
+#define PDS		4
+#elif defined(LLONG_MAX) && (PTRDIFF_MAX == LLONG_MAX)
+#define PDS		8
+#else
+#error fix QUAL_CHARS ptrdiff_t entry 't'!
+#endif
+
+#if SIZE_MAX == UINT_MAX
+#define SS		0
+#elif SIZE_MAX == ULONG_MAX
+#define SS		4
+#elif defined(LLONG_MAX) && (SIZE_MAX == ULLONG_MAX)
+#define SS		8
+#else
+#error fix QUAL_CHARS size_t entries 'z', 'Z'!
+#endif
+
 #define QUAL_CHARS		{ \
 	/* j:(u)intmax_t z:(s)size_t  t:ptrdiff_t  \0:int */ \
 	/* q:long_long  Z:(s)size_t */ \
 	'h',   'l',  'L',  'j',  'z',  't',  'q', 'Z',  0, \
-	 2,     4,    8,    8,    0,    0,    8,   0,   0, /* TODO -- fix!!! */\
+	 2,     4,    8,    8,   SS,  PDS,    8,  SS,   0, /* TODO -- fix!!! */\
      1,     8 \
 }
 
@@ -262,9 +287,6 @@ typedef struct {
 /* TODO: fix printf to return 0 and set errno if format error.  Standard says
    only returns -1 if sets error indicator for the stream. */
 
-/* TODO -- __isdigit() macro */
-#define __isdigit(c) (((unsigned int)(c - '0')) < 10)
-
 #ifdef __STDIO_PRINTF_FLOAT
 extern size_t _dtostr(FILE * fp, long double x, struct printf_info *info);
 #endif

+ 8 - 8
libc/stdio/scanf.c

@@ -165,7 +165,7 @@ static int valid_digit(char c, char base)
 	if (base == 16) {
 		return isxdigit(c);
 	} else {
-		return (isdigit(c) && (c < '0' + base));
+		return (__isdigit(c) && (c < '0' + base));
 	}
 }
 
@@ -321,7 +321,7 @@ va_list ap;
 				store = 0;
 				++fmt;
 			}
-			for (i = 0 ; isdigit(*fmt) ; sc.width = i) {
+			for (i = 0 ; __isdigit(*fmt) ; sc.width = i) {
 				i = (i * 10) + (*fmt++ - '0'); /* Get specified width. */
 			}
 			for (i = 0 ; i < sizeof(qual) ; i++) { /* Optional qualifier. */
@@ -348,7 +348,7 @@ va_list ap;
 				if (p-spec > 3) { /* skip white space if not c or [ */
 					do {
 						i = scan_getc_nw(&sc);
-					} while (isspace(i));
+					} while (__isspace(i));
 					scan_ungetc(&sc);
 				}
 				if (p-spec < 5) { /* [,c,s - string conversions */
@@ -360,7 +360,7 @@ va_list ap;
 						}
 					}
 					for (i=0 ; i<= UCHAR_MAX ; i++) {
-						scanset[i] = ((*p == 's') ? (isspace(i) == 0) : 0);
+						scanset[i] = ((*p == 's') ? (__isspace(i) == 0) : 0);
 					}
 					if (*p == '[') { /* need to build a scanset */
 						if (*++fmt == '^') {
@@ -588,10 +588,10 @@ va_list ap;
 			}
 			/* Unrecognized specifier! */
 			goto RETURN_cnt;
-		} if (isspace(*fmt)) {	/* Consume all whitespace. */
+		} if (__isspace(*fmt)) {	/* Consume all whitespace. */
 			do {
 				i = scan_getc_nw(&sc);
-			} while (isspace(i));
+			} while (__isspace(i));
 		} else {				/* Match the current fmt char. */
 		matchchar:
 			if (scan_getc_nw(&sc) != *fmt) {
@@ -660,7 +660,7 @@ int __strtold(long double *ld, struct scan_cookie *sc)
     since_decimal = INT_MIN;
 
  LOOP:
-    while (isdigit(c)) {		/* Process string of digits. */
+    while (__isdigit(c)) {		/* Process string of digits. */
 		++since_decimal;
 		if (num_digits < 0) {	/* First time through? */
 			++num_digits;		/* We've now seen a digit. */
@@ -707,7 +707,7 @@ int __strtold(long double *ld, struct scan_cookie *sc)
 
 		num_digits = 0;
 		exponent_temp = 0;
-		while (isdigit(c)) {	/* Process string of digits. */
+		while (__isdigit(c)) {	/* Process string of digits. */
 			if (exponent_temp < MAX_ALLOWED_EXP) { /* overflow check */
 				exponent_temp = exponent_temp * 10 + (c - '0');
 			}