Changeset View
Changeset View
Standalone View
Standalone View
contrib/one-true-awk/lib.c
Show First 20 Lines • Show All 787 Lines • ▼ Show 20 Lines | bool is_valid_number(const char *s, bool trailing_stuff_ok, | ||||
bool is_inf = false; | bool is_inf = false; | ||||
if (no_trailing) | if (no_trailing) | ||||
*no_trailing = false; | *no_trailing = false; | ||||
while (isspace(*s)) | while (isspace(*s)) | ||||
s++; | s++; | ||||
/* | |||||
* This test, while allowed by newer POSIX standards, represents a regression | |||||
* where hex strings were treated as numbers in nawk the whole time it has been | |||||
* in FreeBSD (since 2001). The POSIX 2001 through 2004 standards mandated this | |||||
* behavior and the current standard allows it. Deviate from upstream by restoring | |||||
* the prior FreeBSD behavior. | |||||
kevans: `prior` | |||||
*/ | |||||
#if 0 | |||||
// no hex floating point, sorry | // no hex floating point, sorry | ||||
if (s[0] == '0' && tolower(s[1]) == 'x') | if (s[0] == '0' && tolower(s[1]) == 'x') | ||||
return false; | return false; | ||||
#endif | |||||
// allow +nan, -nan, +inf, -inf, any other letter, no | // allow +nan, -nan, +inf, -inf, any other letter, no | ||||
if (s[0] == '+' || s[0] == '-') { | if (s[0] == '+' || s[0] == '-') { | ||||
is_nan = (strncasecmp(s+1, "nan", 3) == 0); | is_nan = (strncasecmp(s+1, "nan", 3) == 0); | ||||
is_inf = (strncasecmp(s+1, "inf", 3) == 0); | is_inf = (strncasecmp(s+1, "inf", 3) == 0); | ||||
if ((is_nan || is_inf) | if ((is_nan || is_inf) | ||||
&& (isspace(s[4]) || s[4] == '\0')) | && (isspace(s[4]) || s[4] == '\0')) | ||||
goto convert; | goto convert; | ||||
Show All 32 Lines |
prior