Subversion Repositories wimsdev

Rev

Rev 3840 | Rev 8185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3840 Rev 8136
Line 12... Line 12...
12
 *
12
 *
13
 *  You should have received a copy of the GNU General Public License
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
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
16
 */
-
 
17
#include "../../Lib/libwims.h"
-
 
18
#include "mathexp.h"
17
 
19
 
18
int nopart=0, nonesting=0, nocomma=0, nocoord=0, _estart;
20
int nopart=0, nonesting=0, nocomma=0, nocoord=0, _estart;
19
 
21
 
20
void extrout(char *pb, char *pe, int dist, int commas[], int *commacnt)
22
void extrout(char *pb, char *pe, int dist, int commas[], int *commacnt)
21
{
23
{
22
    int i;
24
    int i;
23
    if(pe-pb<thislinelen && nopart) return;
25
    if(pe-pb<thislinelen && nopart) return;
24
    while(pe>pb && isspace(*(pe-1))) pe--;
26
    while(pe>pb && isspace(*(pe-1))) pe--;
25
    if(pe<=pb) return;
27
    if(pe<=pb) return;
26
    if(regexcnt>0 && pe-pb<MAX_LINELEN) {
28
    if(regexcnt>0 && pe-pb<MAX_LINELEN) {
27
        char buf[MAX_LINELEN+1];
29
     char buf[MAX_LINELEN+1];
28
        memmove(buf,pb,pe-pb); buf[pe-pb]=0;
30
     memmove(buf,pb,pe-pb); buf[pe-pb]=0;
29
        if(!checkregex(buf)) return;
31
     if(!checkregex(buf)) return;
30
    }
32
    }
31
    if(!nocoord)
33
    if(!nocoord)
32
      printf("%d %d %d, ",thisobjline,dist+_estart,(int)(pe-pb)+dist+_estart);
34
      printf("%d %d %d, ",thisobjline,dist+_estart,(int)(pe-pb)+dist+_estart);
33
    while(*commacnt>0 && commas[*commacnt-1]>pe-pb) (*commacnt)--;
35
    while(*commacnt>0 && commas[*commacnt-1]>pe-pb) (*commacnt)--;
34
    if(*commacnt>0 && !nocomma) {
36
    if(*commacnt>0 && !nocomma) {
35
        fwrite(pb,1,commas[0],stdout); putchar(',');
37
     fwrite(pb,1,commas[0],stdout); putchar(',');
36
        for(i=1;i<*commacnt;i++) {
38
     for(i=1;i<*commacnt;i++) {
37
            fwrite(pb+commas[i-1],1,commas[i]-commas[i-1],stdout); putchar(',');
39
         fwrite(pb+commas[i-1],1,commas[i]-commas[i-1],stdout); putchar(',');
38
        }
40
     }
39
        pb+=commas[*commacnt-1];
41
     pb+=commas[*commacnt-1];
40
    }
42
    }
41
    fwrite(pb,1,pe-pb,stdout); printf("\n");
43
    fwrite(pb,1,pe-pb,stdout); printf("\n");
42
    *commacnt=0;
44
    *commacnt=0;
43
}
45
}
44
 
46
 
Line 52... Line 54...
52
 
54
 
53
    if(dist>0 && (nonesting || nopart)) return;
55
    if(dist>0 && (nonesting || nopart)) return;
54
    commacnt=0;
56
    commacnt=0;
55
    if(expl1<=0) got=1; else got=0;
57
    if(expl1<=0) got=1; else got=0;
56
    for(p1=find_word_start(p), p2=p1; *p2; p2=find_word_start(p3)) {
58
    for(p1=find_word_start(p), p2=p1; *p2; p2=find_word_start(p3)) {
57
        if(*p2=='.' || isdigit(*p2)) {
59
     if(*p2=='.' || isdigit(*p2)) {
58
            (void)strtod(p2,&p3); continue;
60
         (void)strtod(p2,&p3); continue;
59
        }
61
     }
60
        if(*p2=='(') {
62
     if(*p2=='(') {
61
            p3=find_matching(p2+1,')'); lt=exp_paren;
63
         p3=find_matching(p2+1,')'); lt=exp_paren;
62
            paren: if(p3==NULL) error("Unmatched parentheses.");
64
         paren: if(p3==NULL) error("Unmatched parentheses.");
63
            p2++; memmove(buf,p2,p3-p2); buf[p3-p2]=0;
65
         p2++; memmove(buf,p2,p3-p2); buf[p3-p2]=0;
64
            _extract(buf,p2-p+dist);
66
         _extract(buf,p2-p+dist);
65
            if(expl2==lt) extrout(p2,p3,dist+p2-p,commas,&commacnt);
67
         if(expl2==lt) extrout(p2,p3,dist+p2-p,commas,&commacnt);
66
            p3++; continue;
68
         p3++; continue;
67
        }
69
     }
68
        if(*p2=='[') {
70
     if(*p2=='[') {
69
            p3=find_matching(p2+1,']'); lt=exp_matrix; goto paren;
71
         p3=find_matching(p2+1,']'); lt=exp_matrix; goto paren;
70
        }
72
     }
71
        if(*p2=='{') {
73
     if(*p2=='{') {
72
            p3=find_matching(p2+1,'}'); lt=exp_set; goto paren;
74
         p3=find_matching(p2+1,'}'); lt=exp_set; goto paren;
73
        }
75
     }
74
        if(isalpha(*p2)) {
76
     if(isalpha(*p2)) {
75
            for(p3=p2; *p3=='_' || isalnum(*p3); p3++);
77
         for(p3=p2; *p3=='_' || isalnum(*p3); p3++);
76
            if(p3-p2>=16) goto notdefined;
78
         if(p3-p2>=16) goto notdefined;
77
            memmove(buf,p2,p3-p2); buf[p3-p2]=0;
79
         memmove(buf,p2,p3-p2); buf[p3-p2]=0;
78
            for(i=0;i<opalphano && strcmp(buf,opalpha[i].name)!=0; i++);
80
         for(i=0;i<opalphano && strcmp(buf,opalpha[i].name)!=0; i++);
79
            if(i<opalphano) {
81
         if(i<opalphano) {
80
                l=opalpha[i].lvl; if(l>expl2) {
82
          l=opalpha[i].lvl; if(l>expl2) {
81
                    if(got) extrout(p1,p2,dist+p1-p,commas,&commacnt);
83
              if(got) extrout(p1,p2,dist+p1-p,commas,&commacnt);
82
                    if(expl1>0) got=0; p1=find_word_start(p3);
84
              if(expl1>0) got=0; p1=find_word_start(p3);
83
                }
85
          }
84
                if(l>=expl1 && l<=expl2) {
86
          if(l>=expl1 && l<=expl2) {
85
                    got=1;
87
              got=1;
86
                    if(l>0 && commacnt<MAX_COMMAS-2) {
88
              if(l>0 && commacnt<MAX_COMMAS-2) {
87
                        commas[commacnt++]=p2-p1;
89
               commas[commacnt++]=p2-p1;
88
                        commas[commacnt++]=p3-p1;
90
               commas[commacnt++]=p3-p1;
89
                    }
91
              }
90
                }
92
          }
91
                continue;
93
          continue;
92
            }
94
         }
93
            notdefined: p4=find_word_start(p3);
95
         notdefined: p4=find_word_start(p3);
94
            if(*p4=='(') {
96
         if(*p4=='(') {
95
                p3=find_matching(p4+1,')');
97
          p3=find_matching(p4+1,')');
96
                if(p3==NULL) error("Unmatched parentheses.");
98
          if(p3==NULL) error("Unmatched parentheses.");
97
                p4++; memmove(buf,p4,p3-p2); buf[p3-p4]=0;
99
          p4++; memmove(buf,p4,p3-p2); buf[p3-p4]=0;
98
                _extract(buf,p2-p+dist);
100
          _extract(buf,p2-p+dist);
99
                p3++;
101
          p3++;
100
                if(expl2==exp_fn) extrout(p2,p3,dist+p2-p,commas,&commacnt);
102
          if(expl2==exp_fn) extrout(p2,p3,dist+p2-p,commas,&commacnt);
101
            }
103
         }
102
            else if(expl2==exp_variable) extrout(p2,p3,dist+p2-p,commas,&commacnt);
104
         else if(expl2==exp_variable) extrout(p2,p3,dist+p2-p,commas,&commacnt);
103
            continue;
105
         continue;
104
        }
106
     }
105
        for(i=0;i<oppunctno && strncmp(p2,oppunct[i].name,strlen(oppunct[i].name))!=0; i++);
107
     for(i=0;i<oppunctno && strncmp(p2,oppunct[i].name,strlen(oppunct[i].name))!=0; i++);
106
        if(i>=oppunctno) error("Unknown operator.");
108
     if(i>=oppunctno) error("Unknown operator.");
107
        p3=p2+strlen(oppunct[i].name); l=oppunct[i].lvl;
109
     p3=p2+strlen(oppunct[i].name); l=oppunct[i].lvl;
108
        if(l>expl2) {
110
     if(l>expl2) {
109
            if(got) extrout(p1,p2,dist+p1-p,commas,&commacnt);
111
         if(got) extrout(p1,p2,dist+p1-p,commas,&commacnt);
110
            if(expl1>0) got=0; p1=find_word_start(p3);
112
         if(expl1>0) got=0; p1=find_word_start(p3);
111
        }
113
     }
112
        if(l>=expl1 && l<=expl2) {
114
     if(l>=expl1 && l<=expl2) {
113
            got=1;
115
         got=1;
114
            if(l>0 && commacnt<MAX_COMMAS-2) {
116
         if(l>0 && commacnt<MAX_COMMAS-2) {
115
                commas[commacnt++]=p2-p1;
117
          commas[commacnt++]=p2-p1;
116
                commas[commacnt++]=p3-p1;
118
          commas[commacnt++]=p3-p1;
117
            }
119
         }
118
        }
120
     }
119
    }
121
  }
120
    if(got) extrout(p1,p1+strlen(p1),dist+p1-p,commas,&commacnt);
122
  if(got) extrout(p1,p1+strlen(p1),dist+p1-p,commas,&commacnt);
121
}
123
}
122
 
124
 
123
void req_extract(void)
125
void req_extract(void)
124
{
126
{
125
    int i;
127
    int i;
Line 129... Line 131...
129
    if(*reqtype==0) error("Missing extraction type.");
131
    if(*reqtype==0) error("Missing extraction type.");
130
    for(i=0;i<exptypeno && strcmp(reqtype,exptype[i].name)!=0; i++);
132
    for(i=0;i<exptypeno && strcmp(reqtype,exptype[i].name)!=0; i++);
131
    if(i>=exptypeno) error("Bad extraction type.");
133
    if(i>=exptypeno) error("Bad extraction type.");
132
    if(logdir!=0) nopart=1;
134
    if(logdir!=0) nopart=1;
133
    while((p=wordchr(objline[0],"nopart"))!=NULL) {
135
    while((p=wordchr(objline[0],"nopart"))!=NULL) {
134
        nopart=1; ovlstrcpy(p,p+strlen("nopart"));
136
     nopart=1; ovlstrcpy(p,p+strlen("nopart"));
135
    }
137
    }
136
    while((p=wordchr(objline[0],"nonesting"))!=NULL) {
138
    while((p=wordchr(objline[0],"nonesting"))!=NULL) {
137
        nonesting=1; ovlstrcpy(p,p+strlen("nonesting"));
139
     nonesting=1; ovlstrcpy(p,p+strlen("nonesting"));
138
    }
140
    }
139
    while((p=wordchr(objline[0],"nocomma"))!=NULL) {
141
    while((p=wordchr(objline[0],"nocomma"))!=NULL) {
140
        nocomma=1; ovlstrcpy(p,p+strlen("nocomma"));
142
     nocomma=1; ovlstrcpy(p,p+strlen("nocomma"));
141
    }
143
    }
142
    getregex(objline[0]);
144
    getregex(objline[0]);
143
    expl1=exptype[i].lvl1; expl2=exptype[i].lvl2;
145
    expl1=exptype[i].lvl1; expl2=exptype[i].lvl2;
144
    for(i=1;i<objlinecnt;i++) {
146
    for(i=1;i<objlinecnt;i++) {
145
        thisobjline=i; p=find_word_start(objline[i]);
147
     thisobjline=i; p=find_word_start(objline[i]);
146
        linelogdir=0;
148
     linelogdir=0;
147
        if(*p=='>') {
149
     if(*p=='>') {
148
            if(logdir<0) continue;
150
         if(logdir<0) continue;
149
            p=find_word_start(p+1); linelogdir=1;
151
         p=find_word_start(p+1); linelogdir=1;
150
        }
152
     }
151
        else if(*p=='<') {
153
     else if(*p=='<') {
152
            if(logdir>0) continue;
154
         if(logdir>0) continue;
153
            p=find_word_start(p+1); linelogdir=-1;
155
         p=find_word_start(p+1); linelogdir=-1;
154
        }
156
     }
155
        thislinelen=strlen(p); if(thislinelen<=0) continue;
157
     thislinelen=strlen(p); if(thislinelen<=0) continue;
156
        _estart=p-objline[i]; _extract(p, 0);
158
     _estart=p-objline[i]; _extract(p, 0);
157
    }
159
    }
158
}
160
}
159
 
161
 
160
void req_cut(void)
162
void req_cut(void)
161
{
163
{