/[mailutils]/mailutils/libsieve/sieve.l
ViewVC logotype

Diff of /mailutils/libsieve/sieve.l

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by polak, Sun Feb 9 20:39:57 2003 UTC revision 1.16 by gray, Wed Aug 20 14:36:40 2003 UTC
# Line 26  Line 26 
26  #include <sys/file.h>  #include <sys/file.h>
27  #include <sys/stat.h>  #include <sys/stat.h>
28  #include <errno.h>  #include <errno.h>
29  #include <string.h>    #include <string.h>
30    #include <mailutils/argcv.h>
31  #include <sieve.h>  #include <sieve.h>
32  #include <sieve-gram.h>  #include <sieve-gram.h>
33        
# Line 40  static int strip_tabs; Line 41  static int strip_tabs;
41    
42  static int number __P ((void));  static int number __P ((void));
43  static int string __P ((void));  static int string __P ((void));
44    static void line_begin __P ((void));
45    static void line_add __P((char *text, size_t len));
46    static void line_finish __P ((void));
47  static void multiline_begin __P ((void));  static void multiline_begin __P ((void));
48  static void multiline_add __P ((char *));  static void multiline_add __P ((char *));
49  static void multiline_finish __P ((void));  static void multiline_finish __P ((void));
# Line 47  static char *multiline_strip_tabs __P((c Line 51  static char *multiline_strip_tabs __P((c
51  static void ident __P((const char *text));  static void ident __P((const char *text));
52  static void sieve_include __P((void));  static void sieve_include __P((void));
53  static void sieve_searchpath __P((void));  static void sieve_searchpath __P((void));
54  static char *str_escape __P((void));  static char *str_unescape __P((char *text, size_t len));
55  static int isemptystr __P((char *text));  static int isemptystr __P((char *text));
56    
57  #ifdef FLEX_SCANNER  #ifdef FLEX_SCANNER
# Line 352  not     return NOT; Line 356  not     return NOT;
356           /* Quoted strings */           /* Quoted strings */
357  \"[^\\"\n]*\"                 { return string (); }  \"[^\\"\n]*\"                 { return string (); }
358  \"[^\\"\n]*\\.    { BEGIN(STR);  \"[^\\"\n]*\\.    { BEGIN(STR);
359                     multiline_begin ();                     line_begin ();
360                     multiline_add (str_escape ()); }                     line_add (str_unescape (yytext + 1, yyleng - 1), 0); }
361  <STR>[^\\"\n]*\\. { multiline_add (str_escape ()); }  <STR>[^\\"\n]*\\. { line_add (str_unescape (yytext, yyleng), 0); }
362  <STR>[^\\"\n]*\" { BEGIN(INITIAL);  <STR>[^\\"\n]*\" { BEGIN(INITIAL);
363                     multiline_add (NULL);                     if (yyleng > 1)
364                     multiline_finish ();                       line_add (yytext, yyleng - 1);
365                       line_finish ();
366                     return STRING; }                     return STRING; }
367           /* Multiline strings */           /* Multiline strings */
368  text:-?[ \t]*#.*\n       { BEGIN(ML); multiline_begin (); sieve_line_num++; }  text:-?[ \t]*#.*\n       { BEGIN(ML); multiline_begin (); sieve_line_num++; }
# Line 576  multiline_strip_tabs (char *text) Line 581  multiline_strip_tabs (char *text)
581  }  }
582    
583  void  void
584  multiline_add (char *s)  line_add (char *text, size_t len)
585  {  {
586      char *s;
587      
588      if (len == 0)
589        len = strlen (text);
590      s = malloc (len + 1);
591    if (!s)    if (!s)
592      {      {
593        s = strdup (multiline_strip_tabs (yytext));        yyerror (_("not enough memory"));
594        if (!s)        exit (1);
         {  
           yyerror (_("not enough memory"));  
           exit (1);  
         }  
595      }      }
596      memcpy (s, text, len);
597      s[len] = 0;
598    list_append (string_list, s);    list_append (string_list, s);
599  }  }
600    
601  void  void
602  multiline_begin ()  multiline_add (char *s)
603    {
604      if (!s)
605        s = multiline_strip_tabs (yytext);
606      line_add (s, 0);
607    }
608    
609    void
610    line_begin ()
611  {  {
612    int status;    int status;
613    
614      if (string_list)
615        sieve_slist_destroy (&string_list);
616      status = list_create (&string_list);
617      if (status)
618        {
619          sieve_compile_error (sieve_filename, sieve_line_num,
620                               "list_create: %s", mu_strerror (status));
621          exit (1);
622        }
623    }
624    
625    void
626    multiline_begin ()
627    {
628    char *p = yytext + 5; /* past the text: keyword */    char *p = yytext + 5; /* past the text: keyword */
629    
630    if (*p == '-')    if (*p == '-')
# Line 627  multiline_begin () Line 658  multiline_begin ()
658            exit (1);            exit (1);
659          }          }
660      }      }
     
   if (string_list)  
     sieve_slist_destroy (&string_list);  
   status = list_create (&string_list);  
   if (status)  
     {  
       sieve_compile_error (sieve_filename, sieve_line_num,  
                            "list_create: %s", mu_strerror (status));  
       exit (1);  
     }  
661    
662      line_begin ();
663  }  }
664    
665  void  void
666  multiline_finish ()  line_finish ()
667  {  {
668    iterator_t itr;    iterator_t itr;
669    int length = 0;    int length = 0;
# Line 675  multiline_finish () Line 697  multiline_finish ()
697  }  }
698    
699  void  void
700    multiline_finish ()
701    {
702      line_finish ();
703    }
704    
705    void
706  ident (const char *text)  ident (const char *text)
707  {  {
708    yylval.string = strdup (text);    yylval.string = strdup (text);
# Line 687  ident (const char *text) Line 715  ident (const char *text)
715    
716  /* Escapes the last character from yytext */  /* Escapes the last character from yytext */
717  char *  char *
718  str_escape ()  str_unescape (char *text, size_t len)
719  {  {
720    char *str = sieve_alloc (yyleng - 1);    char *str = sieve_alloc (len);
721    memcpy (str, yytext, yyleng - 2);    memcpy (str, text, len - 2);
722    str[yyleng - 2] = yytext[yyleng - 1];    str[len - 2] = argcv_unescape_char (text[len - 1]);
723    str[yyleng - 1] = 0;    str[len - 1] = 0;
724    return str;    return str;
725  }  }

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26