51 double w32strtod(
const char *,
char **);
57 #include "dods-limits.h" 69 double w32strtod(
const char *val,
char **ptr)
72 string *sval =
new string(val);
73 string *snan =
new string(
"NaN");
77 if (stricmp(sval->c_str(), snan->c_str()) != 0)
78 return (strtod(val, ptr));
82 *ptr = (
char *) val + strlen(val);
83 return (std::numeric_limits < double >::quiet_NaN());
91 parse_error(parser_arg * arg,
const char *msg,
const int line_num,
100 arg->set_status(FALSE);
105 oss +=
"Error parsing the text on line ";
106 append_long_to_string(line_num, 10, oss);
109 oss +=
"Parse error.";
113 oss += (string)
" at or near: " + context + (
string)
"\n" + msg
116 oss += (string)
"\n" + msg + (
string)
"\n";
118 arg->set_error(
new Error(unknown_error, oss));
122 parse_error(
const char *msg,
const int line_num,
const char *context)
132 oss +=
"Error parsing the text on line ";
133 append_long_to_string(line_num, 10, oss);
136 oss +=
"Parse error.";
140 oss += (string)
" at or near: " + context + (
string)
"\n" + msg
143 oss += (string)
"\n" + msg + (
string)
"\n";
145 throw Error(malformed_expr, oss);
151 parse_error(
const string & msg,
const int line_num,
const char *context)
153 parse_error(msg.c_str(), line_num, context);
156 void save_str(
char *dst,
const char *src,
const int line_num)
158 if (strlen(src) >= ID_MAX)
159 parse_error(
string(
"The word `") +
string(src)
160 +
string(
"' is too long (it should be no longer than ")
161 + long_to_string(ID_MAX) +
string(
")."), line_num);
163 strncpy(dst, src, ID_MAX);
164 dst[ID_MAX - 1] =
'\0';
167 void save_str(
string & dst,
const char *src,
const int)
172 bool is_keyword(
string id,
const string & keyword)
176 DBG(cerr <<
"is_keyword: " << keyword <<
" = " <<
id << endl);
177 return id == keyword;
193 long v = strtol(val, &ptr, 0);
195 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
199 DBG(cerr <<
"v: " << v << endl);
206 if ((v < 0 && v < DODS_SCHAR_MIN)
207 || (v > 0 && static_cast < unsigned long >(v) > DODS_UCHAR_MAX))
216 int check_int16(
const char *val)
219 long v = strtol(val, &ptr, 0);
221 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
225 if (v > DODS_SHRT_MAX || v < DODS_SHRT_MIN) {
232 int check_uint16(
const char *val)
235 unsigned long v = strtol(val, &ptr, 0);
237 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
241 if (v > DODS_USHRT_MAX) {
248 int check_int32(
const char *val)
252 long v = strtol(val, &ptr, 0);
254 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
261 if (errno == ERANGE) {
267 else if (v > DODS_INT_MAX || v < DODS_INT_MIN) {
275 int check_uint32(
const char *val)
280 while (c && isspace(*c)) {
283 if (c && (*c ==
'-')) {
289 unsigned long v = strtoul(val, &ptr, 0);
291 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
298 if (errno == ERANGE) {
302 else if (v > DODS_UINT_MAX) {
310 int check_int64(
const char *val)
314 long long v = strtoll(val, &ptr, 0);
316 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
323 if (errno == ERANGE) {
332 else if (v <= DODS_LLONG_MAX && v >= DODS_LLONG_MIN) {
341 int check_uint64(
const char *val)
346 while (c && isspace(*c)) {
349 if (c && (*c ==
'-')) {
355 unsigned long long v = strtoull(val, &ptr, 0);
357 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
361 if (errno == ERANGE) {
364 else if (v > DODS_ULLONG_MAX) {
376 int check_float32(
const char *val)
383 double v = w32strtod(val, &ptr);
385 double v = strtod(val, &ptr);
388 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr
389 <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
391 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
395 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
401 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
402 double abs_val = fabs(v);
403 if (abs_val > DODS_FLT_MAX
404 || (abs_val != 0.0 && abs_val < DODS_FLT_MIN))
410 int check_float64(
const char *val)
412 DBG(cerr <<
"val: " << val << endl);
417 double v = w32strtod(val, &ptr);
419 double v = strtod(val, &ptr);
422 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr
423 <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
426 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
429 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
434 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
435 double abs_val = fabs(v);
436 if (abs_val > DODS_DBL_MAX
437 || (abs_val != 0.0 && abs_val < DODS_DBL_MIN))
443 long long get_int64(
const char *val)
447 long long v = strtoll(val, &ptr, 0);
449 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
450 throw Error(
"The value '" +
string(val) +
"' contains extra characters.");
456 if (errno == ERANGE) {
457 throw Error(
"The value '" +
string(val) +
"' is out of range.");
467 else if (v > DODS_LLONG_MAX || v < DODS_LLONG_MIN) {
468 throw Error(
"The value '" +
string(val) +
"' is out of range.");
477 unsigned long long get_uint64(
const char *val)
482 while (c && isspace(*c)) {
485 if (c && (*c ==
'-')) {
486 throw Error(
"The value '" +
string(val) +
"' is not a valid array index.");
491 unsigned long long v = strtoull(val, &ptr, 0);
493 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
494 throw Error(
"The value '" +
string(val) +
"' contains extra characters.");
497 if (errno == ERANGE) {
498 throw Error(
"The value '" +
string(val) +
"' is out of range.");
502 else if (v > DODS_MAX_ARRAY_INDEX) {
503 throw Error(
"The value '" +
string(val) +
"' is out of range.");
511 double get_float64(
const char *val)
513 DBG(cerr <<
"val: " << val << endl);
518 double v = w32strtod(val, &ptr);
520 double v = strtod(val, &ptr);
523 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
524 throw Error(
"The value '" +
string(val) +
"' is out of range.");;
526 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
527 double abs_val = fabs(v);
528 if (abs_val > DODS_DBL_MAX || (abs_val != 0.0 && abs_val < DODS_DBL_MIN))
529 throw Error(
"The value '" +
string(val) +
"' is out of range.");;
string prune_spaces(const string &name)
top level DAP object to house generic methods
int check_url(const char *)
Is the value a valid URL?
int check_byte(const char *val)
Is the value a valid byte?
void save_str(char *dst, const char *src, const int line_num)
Save a string to a temporary variable during the parse.