summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-11-08 15:53:37 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-11-08 15:53:37 +0000
commit1b57a009e0473b03e5a66657a9a2ad444ee51c0d (patch)
tree65aaf122a386d158e405006717d307b4e6466de4
parent792eb4400bc6ec3508c79d87ab0caae7ccb582d1 (diff)
downloadmailutils-1b57a009e0473b03e5a66657a9a2ad444ee51c0d.tar.gz
mailutils-1b57a009e0473b03e5a66657a9a2ad444ee51c0d.tar.bz2
Fixed grammar. Added union, types and the basic actions.
-rw-r--r--libsieve/sieve.l153
-rw-r--r--libsieve/sieve.y115
2 files changed, 236 insertions, 32 deletions
diff --git a/libsieve/sieve.l b/libsieve/sieve.l
index 4e1d10dbb..b9e18ee60 100644
--- a/libsieve/sieve.l
+++ b/libsieve/sieve.l
@@ -3,16 +3,16 @@
3 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 3 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 2, or (at your option)
8 any later version. 8 any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 18
@@ -25,15 +25,25 @@
25#include <unistd.h> 25#include <unistd.h>
26#include <sys/file.h> 26#include <sys/file.h>
27#include <sys/stat.h> 27#include <sys/stat.h>
28#include <errno.h> 28#include <errno.h>
29#include <string.h>
29#include <sieve.h> 30#include <sieve.h>
30#include <sieve-gram.h> 31#include <sieve-gram.h>
31 32
32
33char *sieve_filename; 33char *sieve_filename;
34int sieve_line_num; 34int sieve_line_num;
35ino_t sieve_source_inode; 35ino_t sieve_source_inode;
36 36
37static list_t string_list;
38
39static int number __P ((void));
40static int string __P ((void));
41static void multiline_begin __P ((void));
42static void multiline_add __P ((void));
43static void multiline_finish __P ((void));
44static void ident __P((const char *text));
45static void sieve_include __P((void));
46
37#ifdef FLEX_SCANNER 47#ifdef FLEX_SCANNER
38#define xinput() (yyin ? getc(yyin) : EOF) 48#define xinput() (yyin ? getc(yyin) : EOF)
39#undef YY_INPUT 49#undef YY_INPUT
@@ -185,7 +195,7 @@ struct buffer_ctx {
185static struct buffer_ctx *context_stack; 195static struct buffer_ctx *context_stack;
186 196
187static struct buffer_ctx *ctx_lookup __P((ino_t ino)); 197static struct buffer_ctx *ctx_lookup __P((ino_t ino));
188static int push_source __P((char *name)); 198static int push_source __P((const char *name));
189static int pop_source __P((void)); 199static int pop_source __P((void));
190 200
191struct buffer_ctx * 201struct buffer_ctx *
@@ -200,7 +210,7 @@ ctx_lookup (ino_t ino)
200} 210}
201 211
202int 212int
203push_source (char *name) 213push_source (const char *name)
204{ 214{
205 FILE *fp; 215 FILE *fp;
206 struct buffer_ctx *ctx; 216 struct buffer_ctx *ctx;
@@ -300,6 +310,7 @@ pop_source ()
300 310
301WS [ \t][ \t]* 311WS [ \t][ \t]*
302IDENT [a-zA-Z_][a-zA-Z_0-9]+ 312IDENT [a-zA-Z_][a-zA-Z_0-9]+
313SIZESUF [kKmMgG]
303 314
304%% 315%%
305 /* C-style comments */ 316 /* C-style comments */
@@ -320,18 +331,20 @@ elsif return ELSIF;
320else return ELSE; 331else return ELSE;
321anyof return ANYOF; 332anyof return ANYOF;
322allof return ALLOF; 333allof return ALLOF;
323true return TRUE;
324false return FALSE;
325not return NOT; 334not return NOT;
326 /* Other tokens */ 335 /* Other tokens */
327{IDENT} return IDENT; 336{IDENT} { ident (yytext); return IDENT; }
328:{IDENT} { return TAG; } 337:{IDENT} { ident (yytext + 1); return TAG; }
3290[0-7]* { return NUMBER; } 3380[0-7]*{SIZESUF}* { return number (); }
3300x[0-9a-fA-F][0-9a-fA-F]+ { return NUMBER; } 3390x[0-9a-fA-F][0-9a-fA-F]+{SIZESUF}* { return number (); }
331[1-9][0-9]* { return NUMBER; } 340[1-9][0-9]*{SIZESUF}* { return number (); }
332\"[^"\n]*\" { return STRING; } 341\"[^"\n]*\" { return string (); }
333text: { BEGIN(ML); } 342text: { BEGIN(ML); multiline_begin (); }
334<ML>.[ \t]*\n { BEGIN(INITIAL); sieve_line_num++; return MULTILINE; } 343<ML>.[ \t]*\n { BEGIN(INITIAL);
344 sieve_line_num++;
345 multiline_add ();
346 multiline_finish ();
347 return MULTILINE; }
335<ML>.*\n { sieve_line_num++; } 348<ML>.*\n { sieve_line_num++; }
336{WS} ; 349{WS} ;
337\n { sieve_line_num++; } 350\n { sieve_line_num++; }
@@ -394,5 +407,107 @@ sieve_open_source (const char *name)
394 return push_source (name); 407 return push_source (name);
395} 408}
396 409
410int
411number ()
412{
413 char *p;
414 yylval.number = strtol (yytext, &p, 0);
415 switch (*p)
416 {
417 case 'k':
418 case 'K':
419 yylval.number *= 1024L;
420 break;
421
422 case 'm':
423 case 'M':
424 yylval.number *= 1024*1024L;
425 break;
426
427 case 'g':
428 case 'G':
429 yylval.number *= 1024*1024*1024L;
430 }
431 return NUMBER;
432}
433
434int
435string ()
436{
437 yylval.string = sieve_alloc (yyleng - 1);
438 memcpy (yylval.string, yytext + 1, yyleng - 2);
439 yylval.string[yyleng - 2] = 0;
440 return STRING;
441}
442
443void
444multiline_add ()
445{
446 char *s = strdup (yytext);
447 if (!s)
448 {
449 yyerror ("not enough memory");
450 exit (1);
451 }
452 list_append (string_list, s);
453}
454
455void
456multiline_begin ()
457{
458 int status;
459
460 if (string_list)
461 sieve_slist_destroy (&string_list);
462 status = list_create (&string_list);
463 if (status)
464 {
465 sieve_error ("list_create: %s", mu_errstring (status));
466 exit (1);
467 }
468}
469
470void
471multiline_finish ()
472{
473 iterator_t itr;
474 int length = 0;
475 char *p;
397 476
477 if (!string_list || iterator_create (&itr, string_list))
478 return;
398 479
480 /* Count number of characters in the multiline */
481 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
482 {
483 char *s;
484 iterator_current (itr, (void **)&s);
485 length += strlen (s);
486 }
487
488 /* Copy the contents */
489 yylval.string = sieve_alloc (length + 1);
490 p = yylval.string;
491 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
492 {
493 char *s;
494 iterator_current (itr, (void **)&s);
495 strcpy (p, s);
496 p += strlen (s);
497 free (s);
498 }
499 *p = 0;
500 iterator_destroy (&itr);
501 list_destroy (&string_list);
502}
503
504void
505ident (const char *text)
506{
507 yylval.string = strdup (text);
508 if (!yylval.string)
509 {
510 yyerror ("not enough memory");
511 exit (1);
512 }
513}
diff --git a/libsieve/sieve.y b/libsieve/sieve.y
index 1341a5c0c..0fb8408d7 100644
--- a/libsieve/sieve.y
+++ b/libsieve/sieve.y
@@ -3,16 +3,16 @@
3 Co