push some things into the rx lib.
horrors--.
Signed-off-by: Pierre Habouzit <madcoder@madism.org>
WHERE rx_t *UnMailLists INITVAL (0);
WHERE rx_t *SubscribedLists INITVAL (0);
WHERE rx_t *UnSubscribedLists INITVAL (0);
-WHERE SPAM_LIST *SpamList INITVAL (0);
+WHERE rx_t *SpamList INITVAL (0);
WHERE rx_t *NoSpamList INITVAL (0);
/* bit vector for boolean variables */
return 0;
}
-static int add_to_spam_list (SPAM_LIST ** list, const char *pat,
+static int add_to_spam_list(rx_t **list, const char *pat,
const char *templ, BUFFER * err)
{
- SPAM_LIST *t = NULL, *last = NULL;
- rx_t* rx;
- int n;
- const char *p;
-
- if (!pat || !*pat || !templ)
- return 0;
+ rx_t **last, *rx;
- if (!(rx = rx_compile (pat, REG_ICASE))) {
- snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat);
- return -1;
- }
+ if (!pat || !*pat || !templ)
+ return 0;
- /* check to make sure the item is not already on this list */
- for (last = *list; last; last = last->next) {
- if (ascii_strcasecmp (rx->pattern, last->rx->pattern) == 0) {
- /* Already on the list. Formerly we just skipped this case, but
- * now we're supporting removals, which means we're supporting
- * re-adds conceptually. So we probably want this to imply a
- * removal, then do an add. We can achieve the removal by freeing
- * the template, and leaving t pointed at the current item.
- */
- t = last;
- p_delete(&t->template);
- break;
+ if (!(rx = rx_compile (pat, REG_ICASE))) {
+ snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat);
+ return -1;
}
- if (!last->next)
- break;
- }
-
- /* If t is set, it's pointing into an extant SPAM_LIST* that we want to
- * update. Otherwise we want to make a new one to link at the list's end.
- */
- if (!t) {
- t = mutt_new_spam_list ();
- t->rx = rx;
- if (last)
- last->next = t;
- else
- *list = t;
- }
-
- /* Now t is the SPAM_LIST* that we want to modify. It is prepared. */
- t->template = m_strdup(templ);
- /* Find highest match number in template string */
- t->nmatch = 0;
- for (p = templ; *p;) {
- if (*p == '%') {
- n = atoi (++p);
- if (n > t->nmatch)
- t->nmatch = n;
- while (*p && isdigit ((int) *p))
- ++p;
+ /* check to make sure the item is not already on this list */
+ for (last = list; *last; last = &(*last)->next) {
+ if (!ascii_strcasecmp(rx->pattern, (*last)->pattern) == 0) {
+ rx_t *tmp = rx_list_pop(last);
+ rx_delete(&tmp);
+ last = rx_list_last(last);
+ break;
+ }
}
- else
- ++p;
- }
- t->nmatch++; /* match 0 is always the whole expr */
- return 0;
+ *last = rx;
+ rx_set_template(rx, templ);
+ return 0;
}
-static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
+static int remove_from_spam_list (rx_t ** list, const char *pat)
{
- SPAM_LIST *spam, *prev;
int nremoved = 0;
- /* Being first is a special case. */
- spam = *list;
- if (!spam)
- return 0;
- if (spam->rx && !m_strcmp(spam->rx->pattern, pat)) {
- *list = spam->next;
- rx_delete(&spam->rx);
- p_delete(&spam->template);
- p_delete(&spam);
- return 1;
- }
-
- prev = spam;
- for (spam = prev->next; spam;) {
- if (!m_strcmp(spam->rx->pattern, pat)) {
- prev->next = spam->next;
- rx_delete(&spam->rx);
- p_delete(&spam->template);
- p_delete(&spam);
- spam = prev->next;
- ++nremoved;
- }
- else
- spam = spam->next;
+ while (*list) {
+ if (!m_strcmp((*list)->pattern, pat)) {
+ rx_t *spam = rx_list_pop(list);
+ rx_delete(&spam);
+ nremoved++;
+ } else {
+ list = &(*list)->next;
+ }
}
return nremoved;
/* "*" is a special case. */
if (!m_strcmp(buf->data, "*")) {
- mutt_free_spam_list (&SpamList);
+ rx_list_wipe(&SpamList);
rx_list_wipe(&NoSpamList);
return 0;
}
DTYPE (option->type == DT_SYN))
{
struct option_t* newopt = hash_find (ConfigOptions, (char*) option->data);
- syn_t* tmp = syn_new();
- tmp->f = m_strdup(CurRCFile);
- tmp->l = CurRCLine;
- tmp->n = newopt;
- tmp->o = option;
- syn_list_push(&Synonyms, tmp);
+ syn_t* syn = syn_new();
+ syn->f = m_strdup(CurRCFile);
+ syn->l = CurRCLine;
+ syn->n = newopt;
+ syn->o = option;
+ syn_list_push(&Synonyms, syn);
option = newopt;
}
return pp;
}
+void rx_set_template(rx_t *rx, const char *tpl)
+{
+ const char *p = tpl;
+
+ m_strreplace(&rx->template, tpl);
+ rx->nmatch = 0;
+
+ while ((p = strchr(p, '%'))) {
+ if (isdigit(*++p)) {
+ int n = strtol(p, (char **)&p, 10);
+ rx->nmatch = MAX(n, rx->nmatch);
+ } else {
+ if (*p == '%')
+ p++;
+ }
+ }
+
+ rx->nmatch++; /* match 0 is always the whole expr */
+}
+
void rx_delete(rx_t **p)
{
p_delete(&(*p)->pattern);
regfree((*p)->rx);
p_delete(&(*p)->rx);
+ p_delete(&(*p)->template);
p_delete(p);
}
char *pattern; /* printable version */
regex_t *rx; /* compiled expression */
int not; /* do not match */
+
+ int nmatch; /* nb matches */
+ char *template; /* out template */
} rx_t;
-rx_t* rx_compile (const char*, int);
+rx_t* rx_compile(const char*, int);
+void rx_set_template(rx_t *, const char*);
void rx_delete(rx_t **);
DO_SLIST(rx_t, rx, rx_delete);
#define toggle_option(x) mutt_bit_toggle(Options,x)
#define option(x) mutt_bit_isset(Options,x)
-typedef struct spam_list_t {
- rx_t *rx;
- int nmatch;
- char *template;
- struct spam_list_t *next;
-} SPAM_LIST;
-
-
-#define mutt_new_spam_list() p_new(SPAM_LIST, 1)
-void mutt_free_spam_list (SPAM_LIST **);
-
int mutt_matches_ignore (const char *, string_list_t *);
void mutt_init (int, string_list_t *);
}
}
-void mutt_expand_file_fmt(char *dest, ssize_t destlen,
- const char *fmt, const char *src)
+void
+mutt_expand_file_fmt(char *dst, ssize_t n, const char *fmt, const char *src)
{
char tmp[LONG_STRING];
-
mutt_quote_filename(tmp, sizeof(tmp), src);
- m_snsubst(dest, destlen, fmt, tmp);
+ m_snsubst(dst, n, fmt, tmp);
}
/* return 0 on success, -1 on abort, 1 on error */
}
}
else
- if ((rc =
- mutt_yesorno (_("File is a directory, save under it?"),
- M_YES)) != M_YES)
+ if ((rc = mutt_yesorno(_("File is a directory, save under it?"),
+ M_YES)) != M_YES)
return (rc == M_NO) ? 1 : -1;
if (!attname || !attname[0]) {
}
}
*wptr = 0;
-
-#if 0
- if (flags & M_FORMAT_MAKEPRINT) {
- /* Make sure that the string is printable by changing all non-printable
- chars to dots, or spaces for non-printable whitespace */
- for (cp = dest; *cp; cp++)
- if (!isprint(*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
- *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
- }
-#endif
}
/* returns 0 if OK to proceed, -1 to abort, 1 to retry */
mutt_error (_("%s is not a mailbox!"), s);
return 1;
}
- }
- else {
+ } else {
if (magic != M_IMAP)
{
st->st_mtime = 0;
else if (rc == -1)
ret = -1;
}
- }
- else {
+ } else {
mutt_perror (s);
return 1;
}
return vstring;
}
-void mutt_free_spam_list (SPAM_LIST ** list)
-{
- SPAM_LIST *p;
-
- if (!list)
- return;
- while (*list) {
- p = *list;
- *list = (*list)->next;
- rx_delete(&p->rx);
- p_delete(&p->template);
- p_delete(&p);
- }
-}
-
-int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
+int mutt_match_spam_list (const char *s, rx_t * l, char *text, int x)
{
static regmatch_t *pmatch = NULL;
static int nmatch = 0;
}
/* Does this pattern match? */
- if (regexec(l->rx->rx, s, l->nmatch, (regmatch_t *)pmatch, (int) 0) == 0)
- {
+ if (regexec(l->rx, s, l->nmatch, (regmatch_t *)pmatch, (int) 0) == 0) {
/* Copy template into text, with substitutions. */
for (p = l->template; *p;) {
if (*p == '%') {
int mutt_is_list_cc (int, address_t *, address_t *);
int mutt_is_list_recipient (int, address_t *, address_t *);
int mutt_lookup_mime_type (BODY *, const char *);
-int mutt_match_spam_list (const char *, SPAM_LIST *, char *, int);
+int mutt_match_spam_list (const char *, rx_t *, char *, int);
int mutt_num_postponed (int);
int mutt_parse_bind (BUFFER *, BUFFER *, unsigned long, BUFFER *);
int mutt_parse_exec (BUFFER *, BUFFER *, unsigned long, BUFFER *);