parse 'str' as a regular expression to check whether it's valid; compiled regexp gets thrown away regardless of the outcome */
| 7868 | /* parse 'str' as a regular expression to check whether it's valid; |
| 7869 | compiled regexp gets thrown away regardless of the outcome */ |
| 7870 | staticfn boolean |
| 7871 | test_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' */ |
| 7904 | staticfn boolean |
no test coverage detected