version 1.42, 2020/12/09 20:00:11 |
version 1.43, 2020/12/17 20:06:09 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdarg.h> |
#include <stdarg.h> |
#include <limits.h> |
#include <limits.h> |
#include <math.h> |
|
#include "awk.h" |
#include "awk.h" |
|
|
char EMPTY[] = { '\0' }; |
char EMPTY[] = { '\0' }; |
|
|
if (no_trailing) |
if (no_trailing) |
*no_trailing = false; |
*no_trailing = false; |
|
|
while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r') |
while (isspace((uschar)*s)) |
s++; |
s++; |
|
|
if (s[0] == '0' && tolower(s[1]) == 'x') // no hex floating point, sorry |
// no hex floating point, sorry |
|
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) |
return false; |
return false; |
|
|
// 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] == '-') { |
if (strcasecmp(s+1, "nan") == 0 || strcasecmp(s+1, "inf") == 0) |
if ((strncasecmp(s+1, "nan", 3) == 0 || |
return true; |
strncasecmp(s+1, "inf", 3) == 0)) { |
else if (! isdigit(s[1]) && s[1] != '.') |
trailing_stuff_ok = false; |
|
ep = (char *)(long)s + 4; |
|
if (isspace((uschar)*ep)) { |
|
trailing_stuff_ok = true; |
|
do { |
|
ep++; |
|
} while (isspace((uschar)*ep)); |
|
} |
|
if (no_trailing) |
|
*no_trailing = (*ep == '\0'); |
|
if (*ep != '\0' && !trailing_stuff_ok) |
|
return false; |
|
} else if (! isdigit((uschar)s[1]) && s[1] != '.') |
return false; |
return false; |
} |
} else if (! isdigit((uschar)s[0]) && s[0] != '.') |
else if (! isdigit(s[0]) && s[0] != '.') |
|
return false; |
return false; |
|
|
errno = 0; |
errno = 0; |
r = strtod(s, &ep); |
r = strtod(s, &ep); |
if (ep == s || r == HUGE_VAL || errno == ERANGE) |
if (ep == s || errno == ERANGE) |
return false; |
return false; |
|
|
if (result != NULL) |
if (result != NULL) |
*result = r; |
*result = r; |
|
|
/* |
// check for trailing stuff |
* check for trailing stuff |
while (isspace((uschar)*ep)) |
* allow \r as well. windows files aren't going to go away. |
|
*/ |
|
while (*ep == ' ' || *ep == '\t' || *ep == '\n' || *ep == '\r') |
|
ep++; |
ep++; |
|
|
if (no_trailing) |
if (no_trailing) |