Skip to content

Commit

Permalink
Use a new constraint check for the "lines" option
Browse files Browse the repository at this point in the history
  • Loading branch information
p-gen committed Apr 23, 2020
1 parent b8ddfbe commit bcb0c7c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
16 changes: 15 additions & 1 deletion smenu.c
Expand Up @@ -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. */
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions smenu.h
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions utils.c
Expand Up @@ -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');
}
3 changes: 3 additions & 0 deletions utils.h
Expand Up @@ -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

0 comments on commit bcb0c7c

Please sign in to comment.