Commit db64ad5b db64ad5bd3c436feb02716dff8d10ac8a96eece0 by Alain Magloire

* mail/msgset.y: Draft implementation of a proposition

	to allow regular implementation.
	(REGEXP): Passing the address of the pointer instead of the pointer.
	(INDENT): Likewised.
	* mail/Makefile.am: Add in EXTRA_DIST msgset.c to force its
	generation when doing the distribution, having yacc should
	not be required.
1 parent 8a028fab
......@@ -10,6 +10,8 @@ bin_PROGRAMS = mail
mail_LDADD = @ARGPLIBS@ ../mailbox/libmailbox.la ../lib/libmailutils.a \
@READLINE_LIBS@
EXTRA_DIST = msgset.c
mail_SOURCES = alias.c alt.c cd.c copy.c delete.c dp.c echo.c \
edit.c eq.c exit.c file.c folders.c followup.c from.c headers.c help.c \
hold.c if.c inc.c list.c mail.c mail.h mailline.c mbox.c msgset.y next.c \
......
......@@ -18,6 +18,9 @@
%{
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_REGEXEC
#include <regex.h>
#endif
#include <xalloc.h>
#include <mail.h>
......@@ -102,8 +105,7 @@ msgspec : msg
msg : REGEXP /* /.../ */
{
util_strupper ($1);
$$ = msgset_select (select_subject, &$1, 0, 0);
$$ = msgset_select (select_subject, (void *)$1, 0, 0);
free ($1);
}
| TYPE /* :n, :d, etc */
......@@ -113,11 +115,11 @@ msg : REGEXP /* /.../ */
yyerror ("unknown message type");
YYERROR;
}
$$ = msgset_select (select_type, &$1, 0, 0);
$$ = msgset_select (select_type, (void *)$1, 0, 0);
}
| IDENT /* Sender name */
{
$$ = msgset_select (select_sender, &$1, 0, 0);
$$ = msgset_select (select_sender, (void *)$1, 0, 0);
free ($1);
}
;
......@@ -442,11 +444,26 @@ select_subject (message_t msg, void *closure)
message_get_header (msg, &hdr);
if (header_aget_value (hdr, MU_HEADER_SUBJECT, &subject) == 0)
{
#ifdef HAVE_REGEXEC
/* Match string against the extended regular expression(ignoring
case) in pattern, treating errors as no match.
Return 1 for match, 0 for no match.
*/
regex_t re;
int status;
if (regcomp (&re, expr, REG_EXTENDED | REG_ICASE) != 0)
return 0;
status = regexec (&re, subject, 0, NULL, 0);
if (status != 0)
return 0;
return status == 0;
#else
int rc;
util_strupper (subject);
rc = strstr (subject, expr) != NULL;
free (subject);
return rc;
#endif
}
return 0;
}
......