static int get_range(char *s, long *a, long *b, long *cmpl, long lx) { long max = lx - 1; *a = 1; *b = max; if (*s == '^') { *cmpl = 1; s++; } else *cmpl = 0; if (!*s) return 0; if (*s != '.') { *a = str_to_long(s, &s); if (*a < 0) *a += lx; if (*a<1 || *a>max) return 0; } if (*s == '.') { s++; if (*s != '.') return 0; do s++; while (isspace((int)*s)); if (*s) { *b = str_to_long(s, &s); if (*b < 0) *b += lx; if (*b<1 || *b>max || *s) return 0; } return 1; } if (*s) return 0; *b = *a; return 1; }
long input_manager::get_keycode(const std::string &name) const { const t_name_to_key_map::const_iterator a = keyname_to_keycode.find(name); if (a != keyname_to_keycode.end()) { return a->second; } // Not found in map, try to parse as long if (name.compare(0, 8, "UNKNOWN_") == 0) { return str_to_long(name.substr(8)); } return 0; }
int xml_config_get_int(const xml_config_t *config, const char *pattern) { char *str; long l; int ret; if (!(str = xml_config_get_str(config, pattern))) { return -1; } ret = str_to_long(str, &l); free(str); return (ret == 0) ? l : ret; }
int str_to_int(const char *string, int *number, const int base) { long num; *number = 0; if (!str_to_long(string, &num, base)) return 0; if ( num < INT_MIN || num > INT_MAX ) { errno = ERANGE; return 0; } *number = num; return 1; }
bool str_to_ulong(const char *s, int base, unsigned long *ul) { return str_to_long(s, base, (long *) ul); }
int str_is_long(const char *string, const int base) { long number; return str_to_long(string, &number, base); }