return pp;
}
+int rx_validate(const char *s, char *errbuf, ssize_t errlen)
+{
+ regex_t re;
+ int res;
+
+ p_clear(&re, 1);
+ res = REGCOMP(&re, NONULL(s), 0);
+ if (res) {
+ regerror(res, &re, errbuf, errlen);
+ }
+ regfree(&re);
+
+ return res;
+}
+
void rx_set_template(rx_t *rx, const char *tpl)
{
const char *p = tpl;
- m_strreplace(&rx->template, tpl);
+ m_strreplace(&rx->tpl, tpl);
rx->nmatch = 0;
while ((p = strchr(p, '%'))) {
rx->nmatch++; /* match 0 is always the whole expr */
}
-void rx_delete(rx_t **p)
+void rx_wipe(rx_t *rx)
{
- p_delete(&(*p)->pattern);
- regfree((*p)->rx);
- p_delete(&(*p)->rx);
- p_delete(&(*p)->template);
- p_delete(p);
+ p_delete(&rx->pattern);
+ regfree(rx->rx);
+ p_delete(&rx->rx);
+ p_delete(&rx->tpl);
}
int rx_list_match(rx_t *l, const char *s)
if (regexec(l->rx, s, l->nmatch, pmatch, 0) == 0) {
/* Copy template into dst, with substitutions. */
- const char *p = l->template, *q;
+ const char *p = l->tpl, *q;
for (q = strchr(p, '%'); q; q = strchr(p + 1, '%')) {
int n;
rx_t **rx_lookup(rx_t **l, const char *pat)
{
- if (!pat || !*pat)
+ if (m_strisempty(pat))
return NULL;
while (*l) {
- if (!strcmp((*l)->pattern, pat))
+ if (!m_strcmp((*l)->pattern, pat))
return l;
l = &(*l)->next;
}