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 |
|
29 | char buf[MAX_LINELEN+1]; |
28 |
|
30 | memmove(buf,pb,pe-pb); buf[pe-pb]=0; |
29 |
|
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 |
|
37 | fwrite(pb,1,commas[0],stdout); putchar(','); |
36 |
|
38 | for(i=1;i<*commacnt;i++) { |
37 |
|
39 | fwrite(pb+commas[i-1],1,commas[i]-commas[i-1],stdout); putchar(','); |
38 |
|
40 | } |
39 |
|
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 |
|
59 | if(*p2=='.' || isdigit(*p2)) { |
58 |
|
60 | (void)strtod(p2,&p3); continue; |
59 |
|
61 | } |
60 |
|
62 | if(*p2=='(') { |
61 |
|
63 | p3=find_matching(p2+1,')'); lt=exp_paren; |
62 |
|
64 | paren: if(p3==NULL) error("Unmatched parentheses."); |
63 |
|
65 | p2++; memmove(buf,p2,p3-p2); buf[p3-p2]=0; |
64 |
|
66 | _extract(buf,p2-p+dist); |
65 |
|
67 | if(expl2==lt) extrout(p2,p3,dist+p2-p,commas,&commacnt); |
66 |
|
68 | p3++; continue; |
67 |
|
69 | } |
68 |
|
70 | if(*p2=='[') { |
69 |
|
71 | p3=find_matching(p2+1,']'); lt=exp_matrix; goto paren; |
70 |
|
72 | } |
71 |
|
73 | if(*p2=='{') { |
72 |
|
74 | p3=find_matching(p2+1,'}'); lt=exp_set; goto paren; |
73 |
|
75 | } |
74 |
|
76 | if(isalpha(*p2)) { |
75 |
|
77 | for(p3=p2; *p3=='_' || isalnum(*p3); p3++); |
76 |
|
78 | if(p3-p2>=16) goto notdefined; |
77 |
|
79 | memmove(buf,p2,p3-p2); buf[p3-p2]=0; |
78 |
|
80 | for(i=0;i<opalphano && strcmp(buf,opalpha[i].name)!=0; i++); |
79 |
|
81 | if(i<opalphano) { |
80 |
|
82 | l=opalpha[i].lvl; if(l>expl2) { |
81 |
|
83 | if(got) extrout(p1,p2,dist+p1-p,commas,&commacnt); |
82 |
|
84 | if(expl1>0) got=0; p1=find_word_start(p3); |
83 |
|
85 | } |
84 |
|
86 | if(l>=expl1 && l<=expl2) { |
85 |
|
87 | got=1; |
86 |
|
88 | if(l>0 && commacnt<MAX_COMMAS-2) { |
87 |
|
89 | commas[commacnt++]=p2-p1; |
88 |
|
90 | commas[commacnt++]=p3-p1; |
89 |
|
91 | } |
90 |
|
92 | } |
91 |
|
93 | continue; |
92 |
|
94 | } |
93 |
|
95 | notdefined: p4=find_word_start(p3); |
94 |
|
96 | if(*p4=='(') { |
95 |
|
97 | p3=find_matching(p4+1,')'); |
96 |
|
98 | if(p3==NULL) error("Unmatched parentheses."); |
97 |
|
99 | p4++; memmove(buf,p4,p3-p2); buf[p3-p4]=0; |
98 |
|
100 | _extract(buf,p2-p+dist); |
99 |
|
101 | p3++; |
100 |
|
102 | if(expl2==exp_fn) extrout(p2,p3,dist+p2-p,commas,&commacnt); |
101 |
|
103 | } |
102 |
|
104 | else if(expl2==exp_variable) extrout(p2,p3,dist+p2-p,commas,&commacnt); |
103 |
|
105 | continue; |
104 |
|
106 | } |
105 |
|
107 | for(i=0;i<oppunctno && strncmp(p2,oppunct[i].name,strlen(oppunct[i].name))!=0; i++); |
106 |
|
108 | if(i>=oppunctno) error("Unknown operator."); |
107 |
|
109 | p3=p2+strlen(oppunct[i].name); l=oppunct[i].lvl; |
108 |
|
110 | if(l>expl2) { |
109 |
|
111 | if(got) extrout(p1,p2,dist+p1-p,commas,&commacnt); |
110 |
|
112 | if(expl1>0) got=0; p1=find_word_start(p3); |
111 |
|
113 | } |
112 |
|
114 | if(l>=expl1 && l<=expl2) { |
113 |
|
115 | got=1; |
114 |
|
116 | if(l>0 && commacnt<MAX_COMMAS-2) { |
115 |
|
117 | commas[commacnt++]=p2-p1; |
116 |
|
118 | commas[commacnt++]=p3-p1; |
117 |
|
119 | } |
118 |
|
120 | } |
119 |
|
121 | } |
120 |
|
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 |
|
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 |
|
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 |
|
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 |
|
147 | thisobjline=i; p=find_word_start(objline[i]); |
146 |
|
148 | linelogdir=0; |
147 |
|
149 | if(*p=='>') { |
148 |
|
150 | if(logdir<0) continue; |
149 |
|
151 | p=find_word_start(p+1); linelogdir=1; |
150 |
|
152 | } |
151 |
|
153 | else if(*p=='<') { |
152 |
|
154 | if(logdir>0) continue; |
153 |
|
155 | p=find_word_start(p+1); linelogdir=-1; |
154 |
|
156 | } |
155 |
|
157 | thislinelen=strlen(p); if(thislinelen<=0) continue; |
156 |
|
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 | { |