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