diff --git a/smenu.c b/smenu.c index 5f0230d..86234c6 100644 --- a/smenu.c +++ b/smenu.c @@ -849,6 +849,20 @@ beep(toggle_t * toggle) } } +/* ========================================== */ +/* Integer verification constraint for ctxopt */ +/* ========================================== */ +int +check_integer_constraint(int nb_args, char ** args, char * value, char * par) +{ + if (!is_integer(value)) + { + fprintf(stderr, "This argument of %s is not an integer: %s", par, value); + return 0; + } + return 1; +} + /* ======================================================================== */ /* Update the bitmap associated with a word. This bitmap indicates the */ /* positions of the UFT-8 glyphs of the search buffer in each word. */ @@ -6413,7 +6427,7 @@ main(int argc, char * argv[]) "[^:]+:.+"); ctxopt_add_opt_settings(constraints, "da_options", ctxopt_re_constraint, "[^:]+:.+"); - ctxopt_add_opt_settings(constraints, "lines", ctxopt_format_constraint, "%u"); + ctxopt_add_opt_settings(constraints, "lines", check_integer_constraint, ""); ctxopt_add_opt_settings(constraints, "tab_mode", ctxopt_format_constraint, "%ld"); diff --git a/smenu.h b/smenu.h index a39700e..9f50787 100644 --- a/smenu.h +++ b/smenu.h @@ -215,6 +215,9 @@ void disp_message(ll_t * message_lines_list, long width, long max_len, term_t * term, win_t * win); +int +check_integer_constraint(int nb_args, char ** args, char * value, char * par); + void update_bitmaps(search_mode_t search_mode, search_data_t * search_data, bitmap_affinity_t affinity); diff --git a/utils.c b/utils.c index 7309d80..2d74cdb 100644 --- a/utils.c +++ b/utils.c @@ -302,3 +302,18 @@ xwcscasecmp(const wchar_t * s1, const wchar_t * s2) } return (-*s2); } + +/* ====================================== */ +/* Returns 1 if s represents an integer */ +/* else 0. */ +/* s != NULL is assumed. */ +/* 0 and 0x prefixes are not understood. */ +/* ====================================== */ +int +is_integer(const char * const s) +{ + char * end; + + strtol(s, &end, 10); + return (*end == '\0'); +} diff --git a/utils.h b/utils.h index 17e52dd..8c69b8e 100644 --- a/utils.h +++ b/utils.h @@ -62,4 +62,7 @@ isprint8(int i); int xwcscasecmp(const wchar_t * w1s, const wchar_t * w2s); +int +is_integer(const char * const s); + #endif