]> mj.ucw.cz Git - umpf.git/blobdiff - cond.y
fix content length after filtering mail
[umpf.git] / cond.y
diff --git a/cond.y b/cond.y
index ec5bc8e34a53b32580e55c56f46b705ef66d3360..4c1d3d221d188a976ff7fd96d5b42e3e8c07a714 100644 (file)
--- a/cond.y
+++ b/cond.y
@@ -2,10 +2,12 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "umpf.h"
 
 static struct tree* tree_malloc(int type);
+static enum var_type get_var_type(char* var);
 
 %}
 %error-verbose
@@ -16,34 +18,34 @@ static struct tree* tree_malloc(int type);
        struct tree* tr;        
 }
 
+%right <n> '!'
 %token <str> CONST
 %token <n> NUM
 %token <str> VAR
 %token <n> KW_DISCARD
-%token <n> KW_PIPE KW_MAIL KW_COPY
+%token <n> KW_PIPE KW_MAIL KW_COPY KW_FILTER
 %token '(' ')' '{' '}' ';'
 %nonassoc KW_IF
 %nonassoc KW_ELSE
 %left ARROW
 %left <n> EQ NEQ GE LE '<' '>' RE NRE
-%left '='
+%left <n> '='
 %left <n> '.'
 %left <n> '+' '-' 
 %left <n> '*' '/'
 %left <n> '|'
 %left <n> '^'
 %left <n> '&'
-%left <n> '!'
 %type <tr> input 
 %type <tr> command 
 %type <tr> next 
 %type <tr> ass 
 %type <tr> ass_right 
+%type <tr> ass_right_p
 %type <tr> cif
 %type <tr> arrow 
 %type <tr> cond
 %type <n> rop 
-%type <n> bop 
 %type <n> left
 %type <n> right 
 %type <tr> leaves 
@@ -147,13 +149,13 @@ rop:      '>'
 ;
 
 ass:
-       VAR '=' ass_right       {
+       VAR '=' ass_right_p     {
                                        $$ = tree_malloc(ST_ASS);
 
                                        $$->pt.ass.left = tree_malloc(ST_LEAF);
                                        $$->pt.ass.left->pt.leaf.type = L_VAR;
                                        $$->pt.ass.left->pt.leaf.value = $1;
-                                       $$->pt.ass.left->pt.leaf.n = find_var($1, var_hash);
+                                       $$->pt.ass.left->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
                                        $$->pt.ass.right = $3;
                                }
 ;
@@ -162,7 +164,7 @@ leaves:             VAR     {
                                $$ = tree_malloc(ST_LEAF);
                                $$->pt.leaf.type = L_VAR;
                                $$->pt.leaf.value = $1;
-                               $$->pt.leaf.n = find_var($1, var_hash);
+                               $$->pt.leaf.n = find_var($1, get_var_type($1), var_hash);
                        }
                | CONST { 
                                $$ = tree_malloc(ST_LEAF);
@@ -194,22 +196,44 @@ left:     /* empty */ { $$ = K_EMPTY;}
 right: /* empty */ { $$ = K_EMPTY; }
        | KW_PIPE { $$ = K_PIPE; }
        | KW_MAIL { $$ = K_MAIL; }
+       | KW_FILTER { $$ = K_FILTER; }
+;
+
+ass_right_p:   '(' ass_right ')'       {$$ = $2; }
+               | ass_right     {$$ = $1; }
 ;
 
 ass_right:     leaves
-               | ass_right bop ass_right       {
+               | ass_right '.' ass_right       {
+                                       $$ = tree_malloc(ST_OP);
+                                       $$->pt.op.op = $2;
+                                       $$->pt.op.left = $1;    
+                                       $$->pt.op.right = $3;   
+                               }
+               | ass_right '+' ass_right       {
+                                       $$ = tree_malloc(ST_OP);
+                                       $$->pt.op.op = $2;
+                                       $$->pt.op.left = $1;    
+                                       $$->pt.op.right = $3;   
+                               }
+               | ass_right '-' ass_right       {
+                                       $$ = tree_malloc(ST_OP);
+                                       $$->pt.op.op = $2;
+                                       $$->pt.op.left = $1;    
+                                       $$->pt.op.right = $3;   
+                               }
+               | ass_right '*' ass_right       {
+                                       $$ = tree_malloc(ST_OP);
+                                       $$->pt.op.op = $2;
+                                       $$->pt.op.left = $1;    
+                                       $$->pt.op.right = $3;   
+                               }
+               | ass_right '/' ass_right       {
                                        $$ = tree_malloc(ST_OP);
                                        $$->pt.op.op = $2;
                                        $$->pt.op.left = $1;    
                                        $$->pt.op.right = $3;   
                                }
-;
-
-bop:   '.'   {$$ = $1} 
-       | '+' {$$ = $1}
-       | '-' {$$ = $1}
-       | '*' {$$ = $1}
-       | '/' {$$ = $1}
 ;
 
 %%
@@ -224,6 +248,28 @@ tree_malloc(int type)
        return temp;
 }
 
+enum var_type
+get_var_type(char* var)
+{
+       int upper = 0;
+       int lower = 0;
+
+       if (islower(*var))
+               return VAR_USER;
+
+       while (*var) {
+               if (isupper(*var))      
+                       upper++;
+               if (islower(*var))
+                       lower++;
+               var++;
+       }
+       if (upper && lower)
+               return VAR_HEADER;
+
+       return VAR_INTERN;
+}
+
 void
 yyerror (char const *s)
 {