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 ...@@ -10,6 +10,8 @@ bin_PROGRAMS = mail
10 mail_LDADD = @ARGPLIBS@ ../mailbox/libmailbox.la ../lib/libmailutils.a \ 10 mail_LDADD = @ARGPLIBS@ ../mailbox/libmailbox.la ../lib/libmailutils.a \
11 @READLINE_LIBS@ 11 @READLINE_LIBS@
12 12
13 EXTRA_DIST = msgset.c
14
13 mail_SOURCES = alias.c alt.c cd.c copy.c delete.c dp.c echo.c \ 15 mail_SOURCES = alias.c alt.c cd.c copy.c delete.c dp.c echo.c \
14 edit.c eq.c exit.c file.c folders.c followup.c from.c headers.c help.c \ 16 edit.c eq.c exit.c file.c folders.c followup.c from.c headers.c help.c \
15 hold.c if.c inc.c list.c mail.c mail.h mailline.c mbox.c msgset.y next.c \ 17 hold.c if.c inc.c list.c mail.c mail.h mailline.c mbox.c msgset.y next.c \
......
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
18 %{ 18 %{
19 #include <stdio.h> 19 #include <stdio.h>
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #ifdef HAVE_REGEXEC
22 #include <regex.h>
23 #endif
21 24
22 #include <xalloc.h> 25 #include <xalloc.h>
23 #include <mail.h> 26 #include <mail.h>
24 27
25 static msgset_t *msgset_select (int (*sel)(), void *closure, int rev, 28 static msgset_t *msgset_select (int (*sel)(), void *closure, int rev,
...@@ -28,7 +31,7 @@ static int select_subject (message_t msg, void *closure); ...@@ -28,7 +31,7 @@ static int select_subject (message_t msg, void *closure);
28 static int select_type (message_t msg, void *closure); 31 static int select_type (message_t msg, void *closure);
29 static int select_sender (message_t msg, void *closure); 32 static int select_sender (message_t msg, void *closure);
30 static int select_deleted (message_t msg, void *closure); 33 static int select_deleted (message_t msg, void *closure);
31 34
32 static msgset_t *result; 35 static msgset_t *result;
33 %} 36 %}
34 37
...@@ -102,8 +105,7 @@ msgspec : msg ...@@ -102,8 +105,7 @@ msgspec : msg
102 105
103 msg : REGEXP /* /.../ */ 106 msg : REGEXP /* /.../ */
104 { 107 {
105 util_strupper ($1); 108 $$ = msgset_select (select_subject, (void *)$1, 0, 0);
106 $$ = msgset_select (select_subject, &$1, 0, 0);
107 free ($1); 109 free ($1);
108 } 110 }
109 | TYPE /* :n, :d, etc */ 111 | TYPE /* :n, :d, etc */
...@@ -113,11 +115,11 @@ msg : REGEXP /* /.../ */ ...@@ -113,11 +115,11 @@ msg : REGEXP /* /.../ */
113 yyerror ("unknown message type"); 115 yyerror ("unknown message type");
114 YYERROR; 116 YYERROR;
115 } 117 }
116 $$ = msgset_select (select_type, &$1, 0, 0); 118 $$ = msgset_select (select_type, (void *)$1, 0, 0);
117 } 119 }
118 | IDENT /* Sender name */ 120 | IDENT /* Sender name */
119 { 121 {
120 $$ = msgset_select (select_sender, &$1, 0, 0); 122 $$ = msgset_select (select_sender, (void *)$1, 0, 0);
121 free ($1); 123 free ($1);
122 } 124 }
123 ; 125 ;
...@@ -224,7 +226,7 @@ yylex() ...@@ -224,7 +226,7 @@ yylex()
224 { 226 {
225 char *p = cur_p; 227 char *p = cur_p;
226 int len; 228 int len;
227 229
228 while (*cur_p && *cur_p != ',' && *cur_p != '-') 230 while (*cur_p && *cur_p != ',' && *cur_p != '-')
229 cur_p++; 231 cur_p++;
230 len = cur_p - p + 1; 232 len = cur_p - p + 1;
...@@ -238,7 +240,7 @@ yylex() ...@@ -238,7 +240,7 @@ yylex()
238 { 240 {
239 char *p = ++cur_p; 241 char *p = ++cur_p;
240 int len; 242 int len;
241 243
242 while (*cur_p && *cur_p != '/') 244 while (*cur_p && *cur_p != '/')
243 cur_p++; 245 cur_p++;
244 len = cur_p - p + 1; 246 len = cur_p - p + 1;
...@@ -248,14 +250,14 @@ yylex() ...@@ -248,14 +250,14 @@ yylex()
248 yylval.string[len-1] = 0; 250 yylval.string[len-1] = 0;
249 return REGEXP; 251 return REGEXP;
250 } 252 }
251 253
252 if (*cur_p == ':') 254 if (*cur_p == ':')
253 { 255 {
254 cur_p++; 256 cur_p++;
255 yylval.type = *cur_p++; 257 yylval.type = *cur_p++;
256 return TYPE; 258 return TYPE;
257 } 259 }
258 260
259 return *cur_p++; 261 return *cur_p++;
260 } 262 }
261 263
...@@ -279,7 +281,7 @@ msgset_free (msgset_t *msg_set) ...@@ -279,7 +281,7 @@ msgset_free (msgset_t *msg_set)
279 { 281 {
280 int i; 282 int i;
281 msgset_t *next; 283 msgset_t *next;
282 284
283 if (!msg_set) 285 if (!msg_set)
284 return; 286 return;
285 while (msg_set) 287 while (msg_set)
...@@ -339,7 +341,7 @@ msgset_range (int low, int high) ...@@ -339,7 +341,7 @@ msgset_range (int low, int high)
339 341
340 if (low == high) 342 if (low == high)
341 return msgset_make_1 (low); 343 return msgset_make_1 (low);
342 344
343 if (low >= high) 345 if (low >= high)
344 { 346 {
345 yyerror ("range error"); 347 yyerror ("range error");
...@@ -357,13 +359,13 @@ msgset_range (int low, int high) ...@@ -357,13 +359,13 @@ msgset_range (int low, int high)
357 } 359 }
358 return first; 360 return first;
359 } 361 }
360 362
361 msgset_t * 363 msgset_t *
362 msgset_expand (msgset_t *set, msgset_t *expand_by) 364 msgset_expand (msgset_t *set, msgset_t *expand_by)
363 { 365 {
364 msgset_t *i, *j; 366 msgset_t *i, *j;
365 msgset_t *first = NULL, *last, *mp; 367 msgset_t *first = NULL, *last, *mp;
366 368
367 for (i = set; i; i = i->next) 369 for (i = set; i; i = i->next)
368 for (j = expand_by; j; j = j->next) 370 for (j = expand_by; j; j = j->next)
369 { 371 {
...@@ -431,7 +433,7 @@ msgset_select (int (*sel)(), void *closure, int rev, int max_matches) ...@@ -431,7 +433,7 @@ msgset_select (int (*sel)(), void *closure, int rev, int max_matches)
431 } 433 }
432 } 434 }
433 return first; 435 return first;
434 } 436 }
435 437
436 int 438 int
437 select_subject (message_t msg, void *closure) 439 select_subject (message_t msg, void *closure)
...@@ -442,13 +444,28 @@ select_subject (message_t msg, void *closure) ...@@ -442,13 +444,28 @@ select_subject (message_t msg, void *closure)
442 message_get_header (msg, &hdr); 444 message_get_header (msg, &hdr);
443 if (header_aget_value (hdr, MU_HEADER_SUBJECT, &subject) == 0) 445 if (header_aget_value (hdr, MU_HEADER_SUBJECT, &subject) == 0)
444 { 446 {
447 #ifdef HAVE_REGEXEC
448 /* Match string against the extended regular expression(ignoring
449 case) in pattern, treating errors as no match.
450 Return 1 for match, 0 for no match.
451 */
452 regex_t re;
453 int status;
454 if (regcomp (&re, expr, REG_EXTENDED | REG_ICASE) != 0)
455 return 0;
456 status = regexec (&re, subject, 0, NULL, 0);
457 if (status != 0)
458 return 0;
459 return status == 0;
460 #else
445 int rc; 461 int rc;
446 util_strupper (subject); 462 util_strupper (subject);
447 rc = strstr (subject, expr) != NULL; 463 rc = strstr (subject, expr) != NULL;
448 free (subject); 464 free (subject);
449 return rc; 465 return rc;
466 #endif
450 } 467 }
451 return 0; 468 return 0;
452 } 469 }
453 470
454 int 471 int
...@@ -458,7 +475,7 @@ select_sender (message_t msg, void *closure) ...@@ -458,7 +475,7 @@ select_sender (message_t msg, void *closure)
458 /* FIXME: all messages from sender argv[i] */ 475 /* FIXME: all messages from sender argv[i] */
459 /* Annoying we can use address_create() for that 476 /* Annoying we can use address_create() for that
460 but to compare against what? The email ? */ 477 but to compare against what? The email ? */
461 return 0; 478 return 0;
462 } 479 }
463 480
464 int 481 int
...@@ -490,7 +507,7 @@ select_deleted (message_t msg, void *closure) ...@@ -490,7 +507,7 @@ select_deleted (message_t msg, void *closure)
490 { 507 {
491 attribute_t attr= NULL; 508 attribute_t attr= NULL;
492 int rc; 509 int rc;
493 510
494 message_get_attribute (msg, &attr); 511 message_get_attribute (msg, &attr);
495 rc = attribute_is_deleted (attr); 512 rc = attribute_is_deleted (attr);
496 return strcmp (xargv[0], "undelete") == 0 ? rc : !rc; 513 return strcmp (xargv[0], "undelete") == 0 ? rc : !rc;
......