diff options
-rw-r--r-- | lib/libc/stdio/vfscanf.c | 108 | ||||
-rw-r--r-- | lib/libc/stdlib/strtod.c | 48 | ||||
-rw-r--r-- | lib/libc/stdlib/strtoimax.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/strtol.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/strtoll.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/strtoul.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/strtoull.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/strtoumax.c | 2 | ||||
-rw-r--r-- | share/mklocale/hi_IN.ISCII-DEV.src | 4 |
9 files changed, 87 insertions, 85 deletions
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index 6072112..5181a4e 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -470,6 +470,55 @@ literal: */ switch (c) { + /* + * The digit 0 is always legal, but is + * special. For %i conversions, if no + * digits (zero or nonzero) have been + * scanned (only signs), we will have + * base==0. In that case, we should set + * it to 8 and enable 0x prefixing. + * Also, if we have not scanned zero digits + * before this, do not turn off prefixing + * (someone else will turn it off if we + * have scanned any nonzero digits). + */ + case '0': + if (base == 0) { + base = 8; + flags |= PFXOK; + } + if (flags & NZDIGITS) + flags &= ~(SIGNOK|NZDIGITS|NDIGITS); + else + flags &= ~(SIGNOK|PFXOK|NDIGITS); + goto ok; + + /* 1 through 7 always legal */ + case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + base = basefix[base]; + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* digits 8 and 9 ok iff decimal or hex */ + case '8': case '9': + base = basefix[base]; + if (base <= 8) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* letters ok iff hex */ + case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': + case 'd': case 'e': case 'f': + /* no need to fix base here */ + if (base <= 10) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + /* sign ok only as first character */ case '+': case '-': if (flags & SIGNOK) { @@ -486,56 +535,6 @@ literal: goto ok; } break; - - default: - if (!isdigit(c) && (base != 16 || !isxdigit(c))) - break; - n = digittoint(c); - if (n >= 16) - break; - else if (n >= 10) { - /* letters ok iff hex */ - /* no need to fix base here */ - if (base <= 10) - break; /* not legal here */ - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - } else if (n >= 8) { - /* digits 8 and 9 ok iff decimal or hex */ - base = basefix[base]; - if (base <= 8) - break; /* not legal here */ - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - } else if (n > 0) { - /* 1 through 7 always legal */ - base = basefix[base]; - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - } else { - /* - * The digit 0 is always legal, but is - * special. For %i conversions, if no - * digits (zero or nonzero) have been - * scanned (only signs), we will have - * base==0. In that case, we should set - * it to 8 and enable 0x prefixing. - * Also, if we have not scanned zero digits - * before this, do not turn off prefixing - * (someone else will turn it off if we - * have scanned any nonzero digits). - */ - if (base == 0) { - base = 8; - flags |= PFXOK; - } - if (flags & NZDIGITS) - flags &= ~(SIGNOK|NZDIGITS|NDIGITS); - else - flags &= ~(SIGNOK|PFXOK|NDIGITS); - goto ok; - } - /* NOTREACHED */ } /* @@ -612,6 +611,12 @@ literal: */ switch (c) { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + case '8': case '9': + flags &= ~(SIGNOK | NDIGITS); + goto fok; + case '+': case '-': if (flags & SIGNOK) { flags &= ~SIGNOK; @@ -632,9 +637,6 @@ literal: (flags & DPTOK)) { flags &= ~(SIGNOK | DPTOK); goto fok; - } else if (isdigit(c) && digittoint(c) <= 9) { - flags &= ~(SIGNOK | NDIGITS); - goto fok; } break; } diff --git a/lib/libc/stdlib/strtod.c b/lib/libc/stdlib/strtod.c index 72bb8bf..97b668c87 100644 --- a/lib/libc/stdlib/strtod.c +++ b/lib/libc/stdlib/strtod.c @@ -481,13 +481,13 @@ s2b if (9 < nd0) { s += 9; do - b = multadd(b, 10, digittoint((unsigned char)*s++)); + b = multadd(b, 10, *s++ - '0'); while (++i < nd0); s++; } else s += 10; for (; i < nd; i++) - b = multadd(b, 10, digittoint((unsigned char)*s++)); + b = multadd(b, 10, *s++ - '0'); return b; } @@ -1192,7 +1192,7 @@ strtod #endif { int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, - e, e1, esign, i, j, k, n, nd, nd0, nf, nz, nz0, sign; + e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; CONST char *s, *s0, *s1; double aadj, aadj1, adj, rv, rv0; long L; @@ -1219,26 +1219,26 @@ strtod goto break2; } break2: - if (isdigit(c = (unsigned char)*s) && digittoint(c) == 0) { + if (*s == '0') { nz0 = 1; - while (isdigit(c = (unsigned char)*++s) && digittoint(c) == 0) ; + while (*++s == '0') ; if (!*s) goto ret; } s0 = s; y = z = 0; - for (nd = nf = 0; isdigit(c = (unsigned char)*s) && (n = digittoint(c)) <= 9; nd++, s++) + for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) if (nd < 9) - y = 10*y + n; + y = 10*y + c - '0'; else if (nd < 16) - z = 10*z + n; + z = 10*z + c - '0'; nd0 = nd; if ((char)c == decimal_point) { - c = (unsigned char)*++s; + c = *++s; if (!nd) { - for (; isdigit(c) && digittoint(c) == 0; c = (unsigned char)*++s) + for (; c == '0'; c = *++s) nz++; - if (isdigit(c) && (n = digittoint(c)) <= 9) { + if (c > '0' && c <= '9') { s0 = s; nf += nz; nz = 0; @@ -1246,10 +1246,10 @@ strtod } goto dig_done; } - for (; isdigit(c) && (n = digittoint(c)) <= 9; c = (unsigned char)*++s) { + for (; c >= '0' && c <= '9'; c = *++s) { have_dig: nz++; - if (n > 0) { + if (c - '0' > 0) { nf += nz; for (i = 1; i < nz; i++) if (nd++ < 9) @@ -1257,9 +1257,9 @@ strtod else if (nd <= DBL_DIG + 1) z *= 10; if (nd++ < 9) - y = 10*y + n; + y = 10*y + c - '0'; else if (nd <= DBL_DIG + 1) - z = 10*z + n; + z = 10*z + c - '0'; nz = 0; } } @@ -1273,20 +1273,20 @@ strtod } s00 = s; esign = 0; - switch(c = (unsigned char)*++s) { + switch(c = *++s) { case '-': esign = 1; case '+': - c = (unsigned char)*++s; + c = *++s; } - if (isdigit(c) && digittoint(c) <= 9) { - while (isdigit(c) && digittoint(c) == 0) - c = (unsigned char)*++s; - if (isdigit(c) && (n = digittoint(c)) <= 9) { - L = n; + if (c >= '0' && c <= '9') { + while (c == '0') + c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; s1 = s; - while (isdigit(c = (unsigned char)*++s) && (n = digittoint(c)) <= 9) - L = 10*L + n; + while ((c = *++s) >= '0' && c <= '9') + L = 10*L + c - '0'; if (s - s1 > 8 || L > 19999) /* Avoid confusion from exponents * so large that e might overflow. diff --git a/lib/libc/stdlib/strtoimax.c b/lib/libc/stdlib/strtoimax.c index e5e0442..f8ff09b 100644 --- a/lib/libc/stdlib/strtoimax.c +++ b/lib/libc/stdlib/strtoimax.c @@ -112,7 +112,7 @@ strtoimax(nptr, endptr, base) cutlim = cutoff % base; cutoff /= base; for ( ; ; c = *s++) { - if (isdigit(c) || (base == 16 && isxdigit(c))) + if (isxdigit(c)) c = digittoint(c); else if (isascii(c) && isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c index 9ff4ec4..3d19693 100644 --- a/lib/libc/stdlib/strtol.c +++ b/lib/libc/stdlib/strtol.c @@ -112,7 +112,7 @@ strtol(nptr, endptr, base) cutlim = cutoff % base; cutoff /= base; for ( ; ; c = *s++) { - if (isdigit(c) || (base == 16 && isxdigit(c))) + if (isxdigit(c)) c = digittoint(c); else if (isascii(c) && isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; diff --git a/lib/libc/stdlib/strtoll.c b/lib/libc/stdlib/strtoll.c index c4fcfef..1fd7d9c 100644 --- a/lib/libc/stdlib/strtoll.c +++ b/lib/libc/stdlib/strtoll.c @@ -112,7 +112,7 @@ strtoll(nptr, endptr, base) cutlim = cutoff % base; cutoff /= base; for ( ; ; c = *s++) { - if (isdigit(c) || (base == 16 && isxdigit(c))) + if (isxdigit(c)) c = digittoint(c); else if (isascii(c) && isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c index 4d08b2c..e431dc8 100644 --- a/lib/libc/stdlib/strtoul.c +++ b/lib/libc/stdlib/strtoul.c @@ -90,7 +90,7 @@ strtoul(nptr, endptr, base) cutoff = ULONG_MAX / base; cutlim = ULONG_MAX % base; for ( ; ; c = *s++) { - if (isdigit(c) || (base == 16 && isxdigit(c))) + if (isxdigit(c)) c = digittoint(c); else if (isascii(c) && isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c index 34678fe..adb6556 100644 --- a/lib/libc/stdlib/strtoull.c +++ b/lib/libc/stdlib/strtoull.c @@ -90,7 +90,7 @@ strtoull(nptr, endptr, base) cutoff = ULLONG_MAX / base; cutlim = ULLONG_MAX % base; for ( ; ; c = *s++) { - if (isdigit(c) || (base == 16 && isxdigit(c))) + if (isxdigit(c)) c = digittoint(c); else if (isascii(c) && isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; diff --git a/lib/libc/stdlib/strtoumax.c b/lib/libc/stdlib/strtoumax.c index bdcfbd7..ea59245 100644 --- a/lib/libc/stdlib/strtoumax.c +++ b/lib/libc/stdlib/strtoumax.c @@ -90,7 +90,7 @@ strtoumax(nptr, endptr, base) cutoff = UINTMAX_MAX / base; cutlim = UINTMAX_MAX % base; for ( ; ; c = *s++) { - if (isdigit(c) || (base == 16 && isxdigit(c))) + if (isxdigit(c)) c = digittoint(c); else if (isascii(c) && isalpha(c)) c -= isupper(c) ? 'A' - 10 : 'a' - 10; diff --git a/share/mklocale/hi_IN.ISCII-DEV.src b/share/mklocale/hi_IN.ISCII-DEV.src index 6f85300..9dee7c9 100644 --- a/share/mklocale/hi_IN.ISCII-DEV.src +++ b/share/mklocale/hi_IN.ISCII-DEV.src @@ -11,13 +11,13 @@ ENCODING "NONE" ALPHA 'A' - 'Z' 'a' - 'z' '¡' - 'ê' CONTROL 0x00 - 0x1f 0x7f -DIGIT '0' - '9' 'ñ' - 'ú' +DIGIT '0' - '9' GRAPH 0x21 - 0x7e LOWER 'a' - 'z' PUNCT 0x21 - 0x2f 0x3a - 0x40 0x5b - 0x60 0x7b - 0x7e SPACE 0x09 - 0x0d 0x20 UPPER 'A' - 'Z' -XDIGIT '0' - '9' 'a' - 'f' 'A' - 'F' 'ñ' - 'ú' +XDIGIT '0' - '9' 'a' - 'f' 'A' - 'F' BLANK ' ' '\t' PRINT 0x20 - 0xfa # IDEOGRAM |