]> granicus.if.org Git - nethack/commitdiff
Show regex error before asking for color
authorPasi Kallinen <paxed@alt.org>
Sun, 17 Sep 2017 10:20:25 +0000 (13:20 +0300)
committerPasi Kallinen <paxed@alt.org>
Sun, 17 Sep 2017 10:20:28 +0000 (13:20 +0300)
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.

src/files.c
src/options.c

index 7e8ffdc2cd1727b79736f88643c6e9c837079879..56978e46996ec3bee17daf281d162381a42d0a34 100644 (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
index 827e885ca608fbc6e085694eacb7a59ec41f52bf..6e426982e69505522459d16f05557fa04683c2d4 100644 (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)) {