diff options
| -rw-r--r-- | booki.c | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -462,15 +462,38 @@ bool match_string(const char* pattern, const struct es text) { return valid; } -bool match_int(const char* pattern, const int candidate) { - // need to parse the pattern to an int +bool match_int(char* pattern, int candidate) { + // we don't want to match the zero value, unless the pattern is also 0 + if (candidate == 0 && strcmp(pattern, "0") != 0) + return false; + + // check for leading signs + char* current_pos = pattern; + bool lt = false; + bool gt = false; + if (*current_pos == '+') { + gt = true; + current_pos++; + } else if (*current_pos == ',') { + lt = true; + current_pos++; + } + + // parse the string to an int char* endptr; - long ret = strtol(pattern, &endptr, 10); + long ret = strtol(current_pos, &endptr, 10); if (*endptr != '\0') { - printf("couldn't parse int!\n"); + printf("couldn't parse pattern as int: '%s'\n", pattern); return false; } - return ret == candidate; + + // do compares + if (lt) + return candidate < ret; + else if (gt) + return candidate > ret; + else + return ret == candidate; } static struct option search_options[] = { |
