Rev 8880 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8880 | Rev 12247 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | */ |
16 | */ |
17 | 17 | ||
18 | #include "../Lib/libwims.h" |
18 | #include "../Lib/libwims.h" |
19 | 19 | ||
20 | char *relation_type[]={ |
20 | char *relation_type[]={ |
21 |
|
21 | "sametext","samecase", |
22 |
|
22 | "in", "wordof","itemof","lineof","varof","variableof" |
23 | }; |
23 | }; |
24 | #define total_relations (sizeof(relation_type)/sizeof(relation_type[0])) |
24 | #define total_relations (sizeof(relation_type)/sizeof(relation_type[0])) |
25 | 25 | ||
26 | /* Here we only check syntax correctness. Returns 1 if OK. */ |
26 | /* Here we only check syntax correctness. Returns 1 if OK. */ |
27 | int _check_compare(char *p, int lvl) |
27 | int _check_compare(char *p, int lvl) |
28 | { |
28 | { |
29 |
|
29 | char *p1, *p2, *pp, *pt; |
30 |
|
30 | char *r1, *r2; |
31 |
|
31 | int i, l, k, gotl; |
32 | 32 | ||
33 | /* Check global pairs of parentheses */ |
33 | /* Check global pairs of parentheses */ |
34 |
|
34 | p2=strip_trailing_spaces(p); |
35 |
|
35 | p1=find_word_start(p); |
36 |
|
36 | while(*p1=='(' && *p2==')' && p2==parend(p1)) { |
37 |
|
37 | lvl=0; p1=find_word_start(++p1); |
38 |
|
38 | do p2--; while(p2>=p1 && myisspace(*p2)); |
39 |
|
39 | p2[1]=0; |
- | 40 | } |
|
- | 41 | gotl=100; r1=r2=p1; |
|
- | 42 | for(pp=p1; *pp; pp++) { |
|
- | 43 | if(*pp==')') return 0; |
|
- | 44 | if(*pp=='(') { |
|
- | 45 | pp=parend(pp); if(pp==NULL) return 0; |
|
- | 46 | continue; |
|
40 | } |
47 | } |
41 | gotl=100; r1=r2=p1; |
- | |
42 | for(pp=p1; *pp; pp++) { |
- | |
43 | if(*pp==')') return 0; |
- | |
44 | if(*pp=='(') { |
- | |
45 | pp=parend(pp); if(pp==NULL) return 0; |
- | |
46 | continue; |
- | |
47 | } |
- | |
48 |
|
48 | if(gotl>3) { |
49 |
|
49 | switch(*pp) { |
50 |
|
50 | case '<': { |
51 |
|
51 | gotl=3; r1=pp; r2=r1+1; |
52 |
|
52 | if(*r2=='=') {r2++;break;} |
53 |
|
53 | if(*r2=='>') r2++; |
54 |
|
54 | break; |
55 |
|
55 | } |
56 |
|
56 | case '>': { |
57 |
|
57 | gotl=3; r1=pp; r2=r1+1; |
58 |
|
58 | if(*r2=='=') r2++; |
59 |
|
59 | break; |
60 |
|
60 | } |
61 |
|
61 | case '=': { |
62 |
|
62 | gotl=3; r1=pp; r2=r1+1; if(*r2=='=') r2++; |
63 |
|
63 | break; |
64 |
|
64 | } |
65 |
|
65 | case '!': { |
66 |
|
66 | if(pp[1]=='=') { |
67 |
|
67 | gotl=3; r1=pp; r2=pp+2; |
68 | } |
- | |
69 | break; |
- | |
70 | } |
- | |
71 | } |
68 | } |
72 |
|
69 | break; |
73 | if(lvl==2) break; |
- | |
74 | pp=r2-1; continue; |
- | |
75 |
|
70 | } |
76 | } |
71 | } |
77 | if(!myisspace(*pp)) continue; |
- | |
78 | pp=find_word_start(pp); |
- | |
79 | if( |
72 | if(r2>p1) { |
80 | if(pp[0]=='i' && pp[1]=='s') {k=2; goto isnot;} |
- | |
81 | if(pp[0]=='n' && pp[1]=='o' && pp[2]=='t') {k=3; goto isnot;} |
- | |
82 |
|
73 | if(lvl==2) break; |
83 | isnot: |
- | |
84 | if(strchr("siwlv",pp[k])==NULL) goto rel; |
- | |
85 | pt=pp; pp+=k; l=0; |
- | |
86 | for(i=0;i<total_relations;i++) { |
- | |
87 | l=strlen(relation_type[i]); |
- | |
88 | if(strncmp(pp, relation_type[i], l)==0 && |
- | |
89 | ((!myisalnum(pp[l]) && pp[l]!='_') || pp[l]==0)) break; |
- | |
90 | } |
- | |
91 | if(i>=total_relations) {pp--; continue;} |
- | |
92 | gotl=3; pp+=l; r1=pt; r2=pp; |
- | |
93 | if(lvl==2) break; else {pp--; continue;} |
- | |
94 | } |
- | |
95 | rel: |
- | |
96 | if(*pp!='|' && *pp!='&' && *pp!='a' && *pp!='o') |
- | |
97 |
|
74 | pp=r2-1; continue; |
98 | if(gotl>2 && |
- | |
99 | ((myisspace(pp[3]) && strncmp(pp,"and",3)==0) || |
- | |
100 | (myisspace(pp[2]) && strncmp(pp,"&&",2)==0))) { |
- | |
101 | gotl=2; r1=pp; pp=r2=find_word_end(r1); |
- | |
102 | if(lvl==1) break; else {pp--;continue;} |
- | |
103 | } |
- | |
104 | if(gotl>1 && myisspace(pp[2]) && |
- | |
105 | (strncmp(pp,"or",2)==0 || strncmp(pp,"||",2)==0)) { |
- | |
106 | gotl=1; r1=pp; r2=pp=r1+2; break; |
- | |
107 | } |
75 | } |
108 | } |
76 | } |
109 |
|
77 | if(!myisspace(*pp)) continue; |
110 |
|
78 | pp=find_word_start(pp); |
111 |
|
79 | if(gotl>3) { |
112 |
|
80 | if(pp[0]=='i' && pp[1]=='s') {k=2; goto isnot;} |
113 |
|
81 | if(pp[0]=='n' && pp[1]=='o' && pp[2]=='t') {k=3; goto isnot;} |
114 |
|
82 | goto rel; |
115 |
|
83 | isnot: |
116 |
|
84 | if(strchr("siwlv",pp[k])==NULL) goto rel; |
117 |
|
85 | pt=pp; pp+=k; l=0; |
118 |
|
86 | for(i=0;i<total_relations;i++) { |
119 |
|
87 | l=strlen(relation_type[i]); |
120 | } |
- | |
121 |
|
88 | if(strncmp(pp, relation_type[i], l)==0 && |
122 |
|
89 | ((!myisalnum(pp[l]) && pp[l]!='_') || pp[l]==0)) break; |
123 | } |
90 | } |
- | 91 | if(i>=total_relations) {pp--; continue;} |
|
- | 92 | gotl=3; pp+=l; r1=pt; r2=pp; |
|
- | 93 | if(lvl==2) break; else {pp--; continue;} |
|
- | 94 | } |
|
- | 95 | rel: |
|
- | 96 | if(*pp!='|' && *pp!='&' && *pp!='a' && *pp!='o') |
|
- | 97 | {pp--; continue;} |
|
- | 98 | if(gotl>2 && |
|
- | 99 | ((myisspace(pp[3]) && strncmp(pp,"and",3)==0) || |
|
- | 100 | (myisspace(pp[2]) && strncmp(pp,"&&",2)==0))) { |
|
- | 101 | gotl=2; r1=pp; pp=r2=find_word_end(r1); |
|
- | 102 | if(lvl==1) break; else {pp--;continue;} |
|
- | 103 | } |
|
- | 104 | if(gotl>1 && myisspace(pp[2]) && |
|
- | 105 | (strncmp(pp,"or",2)==0 || strncmp(pp,"||",2)==0)) { |
|
- | 106 | gotl=1; r1=pp; r2=pp=r1+2; break; |
|
- | 107 | } |
|
- | 108 | } |
|
- | 109 | switch(gotl) { |
|
- | 110 | case 1: { /* or */ |
|
- | 111 | *r1=0; |
|
- | 112 | if(!_check_compare(p1,1)) return 0; |
|
- | 113 | if(!_check_compare(r2,0)) return 0; |
|
- | 114 | return 1; |
|
- | 115 | } |
|
- | 116 | case 2: { /* and */ |
|
- | 117 | *r1=0; |
|
- | 118 | if(!_check_compare(p1,2)) return 0; |
|
- | 119 | if(!_check_compare(r2,1)) return 0; |
|
- | 120 | } |
|
- | 121 | case 3: { |
|
- | 122 | return 1; /* this is considered as OK. */ |
|
124 | } |
123 | } |
- | 124 | } |
|
125 |
|
125 | return 0; |
126 | } |
126 | } |
127 | 127 | ||
128 | int check_compare(char *p) |
128 | int check_compare(char *p) |
129 | { |
129 | { |
130 |
|
130 | char buf[MAX_LINELEN+1]; |
131 |
|
131 | char *pp; |
132 |
|
132 | snprintf(buf,sizeof(buf),"%s",p); |
133 |
|
133 | pp=strparchr(buf,'?'); if(pp) *pp=0; |
134 |
|
134 | return _check_compare(buf,0); |
135 | } |
135 | } |
136 | 136 | ||
137 | 137 |