Subversion Repositories wimsdev

Rev

Rev 8148 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
8135 bpr 18
#include "../Lib/libwims.h"
19
 
10 reyssat 20
char *relation_type[]={
21
    "sametext","samecase",
22
    "in",  "wordof","itemof","lineof","varof","variableof"
23
};
24
#define total_relations (sizeof(relation_type)/sizeof(relation_type[0]))
25
 
7677 bpr 26
/* Here we only check syntax correctness. Returns 1 if OK. */
10 reyssat 27
int _check_compare(char *p, int lvl)
28
{
29
    char *p1, *p2, *pp, *pt;
30
    char *r1, *r2;
31
    int i, l, k, gotl;
7677 bpr 32
 
33
/* Check global pairs of parentheses */
10 reyssat 34
    p2=strip_trailing_spaces(p);
35
    p1=find_word_start(p);
36
    while(*p1=='(' && *p2==')' && p2==parend(p1)) {
7677 bpr 37
      lvl=0; p1=find_word_start(++p1);
38
      do p2--; while(p2>=p1 && myisspace(*p2));
39
      p2[1]=0;
10 reyssat 40
    }
41
    gotl=100; r1=r2=p1;
42
    for(pp=p1; *pp; pp++) {
7677 bpr 43
      if(*pp==')') return 0;
44
      if(*pp=='(') {
45
          pp=parend(pp); if(pp==NULL) return 0;
46
          continue;
47
      }
48
      if(gotl>3) {
49
          switch(*pp) {
50
            case '<': {
51
                gotl=3; r1=pp; r2=r1+1;
52
                if(*r2=='=') {r2++;break;}
53
                if(*r2=='>') r2++;
54
                break;
55
            }
56
            case '>': {
57
                gotl=3; r1=pp; r2=r1+1;
58
                if(*r2=='=') r2++;
59
                break;
60
            }
61
            case '=': {
62
                gotl=3; r1=pp; r2=r1+1; if(*r2=='=') r2++;
63
                break;
64
            }
65
            case '!': {
66
                if(pp[1]=='=') {
67
                  gotl=3; r1=pp; r2=pp+2;
68
                }
69
                break;
70
            }
71
          }
72
          if(r2>p1) {
73
            if(lvl==2) break;
74
            pp=r2-1; continue;
75
          }
76
      }
77
      if(!myisspace(*pp)) continue;
78
      pp=find_word_start(pp);
79
      if(gotl>3) {
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
          goto rel;
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
          {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
      }
10 reyssat 108
    }
109
    switch(gotl) {
7677 bpr 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. */
123
      }
10 reyssat 124
    }
125
    return 0;
126
}
127
 
128
int check_compare(char *p)
129
{
130
    char buf[MAX_LINELEN+1];
131
    char *pp;
132
    snprintf(buf,sizeof(buf),"%s",p);
133
    pp=strparchr(buf,'?'); if(pp) *pp=0;
134
    return _check_compare(buf,0);
135
}
136
 
137