Show regex error before asking for color

When entering a new menucolor via options, show regex error
immediately afterwards, instead of asking for color and attribute
before showing the error.

Also actually show config errors even if config error handler
hasn't been initialized.
This commit is contained in:
Pasi Kallinen
2017-09-17 13:20:25 +03:00
parent 78e5c9a10a
commit 45401a13bb
2 changed files with 32 additions and 1 deletions

View File

@@ -2777,8 +2777,11 @@ VA_DECL(const char *, str)
Vsprintf(buf, str, VA_ARGS);
if (!config_error_data)
if (!config_error_data) {
pline("%s.", *buf ? buf : "Unknown error");
wait_synch();
return;
}
config_error_data->num_errors++;
if (!config_error_data->origline_shown

View File

@@ -524,6 +524,7 @@ STATIC_DCL int NDECL(query_msgtype);
STATIC_DCL boolean FDECL(msgtype_add, (int, char *));
STATIC_DCL void FDECL(free_one_msgtype, (int));
STATIC_DCL int NDECL(msgtype_count);
STATIC_DCL boolean FDECL(test_regex_pattern, (const char *, const char *));
STATIC_DCL boolean FDECL(add_menu_coloring_parsed, (char *, int, int));
STATIC_DCL void FDECL(free_one_menu_coloring, (int));
STATIC_DCL int NDECL(count_menucolors);
@@ -1629,6 +1630,32 @@ char *str;
return FALSE;
}
STATIC_OVL boolean
test_regex_pattern(str, errmsg)
const char *str;
const char *errmsg;
{
static const char re_error[] = "Regex error";
struct nhregex *match;
boolean retval = TRUE;
if (!str)
return FALSE;
match = regex_init();
if (!match) {
config_error_add("NHregex error");
return FALSE;
}
if (!regex_compile(str, match)) {
config_error_add("%s: %s", errmsg ? errmsg : re_error, regex_error_desc(match));
retval = FALSE;
}
regex_free(match);
return retval;
}
boolean
add_menu_coloring_parsed(str, c, a)
char *str;
@@ -4707,6 +4734,7 @@ boolean setinitial, setfromfile;
if (*mcbuf == '\033')
return TRUE;
if (*mcbuf
&& test_regex_pattern(mcbuf, (const char *)0)
&& (mcclr = query_color()) != -1
&& (mcattr = query_attr((char *) 0)) != -1
&& !add_menu_coloring_parsed(mcbuf, mcclr, mcattr)) {