MCPcopy Index your code
hub / github.com/NetHack/NetHack / test_regex_pattern

Function test_regex_pattern

src/options.c:7870–7901  ·  view source on GitHub ↗

parse 'str' as a regular expression to check whether it's valid; compiled regexp gets thrown away regardless of the outcome */

Source from the content-addressed store, hash-verified

7868/* parse 'str' as a regular expression to check whether it's valid;
7869 compiled regexp gets thrown away regardless of the outcome */
7870staticfn boolean
7871test_regex_pattern(const char *str, const char *errmsg)
7872{
7873 static const char def_errmsg[] = "NHregex error";
7874 struct nhregex *match;
7875 char *re_error_desc, errbuf[BUFSZ];
7876 boolean retval;
7877
7878 if (!str)
7879 return FALSE;
7880 if (!errmsg)
7881 errmsg = def_errmsg;
7882
7883 match = regex_init();
7884 if (!match) {
7885 config_error_add("%s", errmsg);
7886 return FALSE;
7887 }
7888
7889 retval = regex_compile(str, match);
7890 /* get potential error message before freeing regexp and free regexp
7891 before issuing message in case the error is "ran out of memory"
7892 since message delivery might need to allocate some memory */
7893 re_error_desc = !retval ? regex_error_desc(match, errbuf) : 0;
7894 /* discard regexp; caller will re-parse it after validating other stuff */
7895 regex_free(match);
7896 /* if returning failure, tell player */
7897 if (!retval)
7898 config_error_add("%s: %s", errmsg, re_error_desc);
7899
7900 return retval;
7901}
7902
7903/* parse 'role' or 'race' or 'gender' or 'alignment' */
7904staticfn boolean

Callers 2

handler_menu_colorsFunction · 0.85
handler_msgtypeFunction · 0.85

Calls 5

config_error_addFunction · 0.85
regex_initFunction · 0.50
regex_compileFunction · 0.50
regex_error_descFunction · 0.50
regex_freeFunction · 0.50

Tested by

no test coverage detected