23#define float_start(m_c) (isdigit(*(m_c)) || *(m_c) == '.' || ((*(m_c) == '-' || *(m_c) == '+') && (isdigit(*((m_c) + 1)) || *((m_c) + 1) == '.')))
24#define int_start(m_c) (isdigit(*(m_c)) || ((*(m_c) == '-' || *(m_c) == '+') && isdigit(*((m_c) + 1))))
26#define skip_it(m_c) (isspace(m_c) || (m_c) == ',' || (m_c) == ';')
27#define nskip_it(m_c) (!isspace(m_c) && (m_c) != ',' && (m_c) != ';')
42 register int was_point = 0;
46 while (!float_start(s) && *s)
52 sscanf(s,
"%lf", dptr);
57 if (*s ==
'-' || *s ==
'+')
61 while (isdigit(*s) || (*s ==
'.' && !was_point))
65 if (*s ==
'e' || *s ==
'E') {
67 if (*s ==
'+' || *s ==
'-')
90 register int was_point = 0;
94 while (!float_start(s) && *s)
99 sscanf(s,
"%Lf", dptr);
103 if (*s ==
'-' || *s ==
'+')
107 while (isdigit(*s) || (*s ==
'.' && !was_point))
111 if (*s ==
'e' || *s ==
'E') {
113 if (*s ==
'+' || *s ==
'-')
137 if (s == NULL || *s ==
'\0')
141 char *p = s + strlen(s) - 1;
142 while (p >= s && isspace((
unsigned char)*p))
149 val = strtod(start, &endptr);
151 if (endptr != start) {
153 if (*endptr ==
'\0') {
163int get_double1_old(
double *dptr,
char *s) {
164 register int was_point = 0;
167 while (!float_start(s) && *s)
173 sscanf(s,
"%lf", dptr);
178 if (*s ==
'-' || *s ==
'+')
182 while (isdigit(*s) || (*s ==
'.' && !was_point))
186 if (*s ==
'e' || *s ==
'E') {
188 if (*s ==
'+' || *s ==
'-')
210 register int was_point = 0;
214 while (!float_start(s) && *s)
220 sscanf(s,
"%f", fptr);
225 if (*s ==
'-' || *s ==
'+')
229 while (isdigit(*s) || (*s ==
'.' && !was_point))
233 if (*s ==
'e' || *s ==
'E') {
235 if (*s ==
'+' || *s ==
'-')
260 while (!int_start(s) && *s)
266 sscanf(s,
"%ld", iptr);
269 if (*s ==
'-' || *s ==
'+')
292 if (s == NULL || *s ==
'\0')
296 char *p = s + strlen(s) - 1;
297 while (p >= s && isspace((
unsigned char)*p))
304 val = strtol(start, &endptr, 10);
306 if (endptr != start) {
308 if (*endptr ==
'\0') {
318int get_long1_old(
long *iptr,
char *s) {
321 while (!int_start(s) && *s)
327 sscanf(s,
"%ld", iptr);
330 if (*s ==
'-' || *s ==
'+')
352 while (!int_start(s) && *s)
358 sscanf(s,
"%hd", iptr);
361 if (*s ==
'-' || *s ==
'+')
385 while (!int_start(s) && *s)
391 sscanf(s,
"%d", iptr);
394 if (*s ==
'-' || *s ==
'+')
414 char *ptr0, *ptr1, *ptr;
424 if (*s ==
'"' && (ptr0 == s || *(s - 1) !=
'\\')) {
429 }
while (*s && (*s !=
'"' || *(s - 1) ==
'\\'));
430 if (*s ==
'"' && *(s - 1) !=
'\\')
436 if (*s ==
'"' && *(s - 1) !=
'\\') {
437 while (*++s && (*s !=
'"' || *(s - 1) ==
'\\'))
440 }
while (*s && nskip_it(*s));
443 ptr =
tmalloc((
unsigned)
sizeof(*ptr) * (s - ptr1 + 1));
444 strncpy(ptr, ptr1, s - ptr1);
479 }
while (*s !=
'"' && *s);
486 }
while (*s && nskip_it(*s));
489 if ((s - ptr1 + 1) > lbuf) {
490 printf(
"buffer overflow in get_token_buf()\nstring was %s\n", ptr0);
493 strncpy(buf, ptr1, s - ptr1);
510 if (!isdigit(*token) && *token !=
'-' && *token !=
'+')
512 if (!isdigit(*token) && !isdigit(*(token + 1)))
516 if (!isdigit(*token++))
531 long pointSeen, digitSeen;
533 if (!(digitSeen = isdigit(*token)) && *token !=
'-' && *token !=
'+' && *token !=
'.')
535 pointSeen = *token ==
'.';
539 if (isdigit(*token)) {
542 }
else if (*token ==
'.') {
547 }
else if (*token ==
'e' || *token ==
'E') {
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
int get_short(short *iptr, char *s)
Parses a short integer value from the given string.
int get_longdouble(long double *dptr, char *s)
Parses a long double value from the given string.
int get_long(long *iptr, char *s)
Parses a long integer value from the given string.
int get_long1(long *lptr, char *s)
Parses a long integer value from the given string without modifying the string.
int get_double(double *dptr, char *s)
Parses a double value from the given string.
long tokenIsNumber(char *token)
Checks if the given token represents a valid number.
int get_double1(double *dptr, char *s)
Parses a double value from the given string without modifying the string.
int get_float(float *fptr, char *s)
Parses a float value from the given string.
int get_int(int *iptr, char *s)
Parses an integer value from the given string.
char * get_token_buf(char *s, char *buf, long lbuf)
Extracts the next token from the input string into a provided buffer.
char * get_token(char *s)
Extracts the next token from the input string.
long tokenIsInteger(char *token)
Checks if the given token represents a valid integer.
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.