Rev 3717 | Rev 8068 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3717 | Rev 7840 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | */ |
16 | */ |
17 | 17 | ||
18 | char t_buf[4][MAX_LINELEN+1]; |
18 | char t_buf[4][MAX_LINELEN+1]; |
19 | char maskbuf[MAX_LINELEN+1]; |
19 | char maskbuf[MAX_LINELEN+1]; |
20 | 20 | ||
21 |
|
21 | /* internal routine. */ |
22 | void _text_cut(char *p, char *w) |
22 | void _text_cut(char *p, char *w) |
23 | { |
23 | { |
24 | char *p1, *p2; |
24 | char *p1, *p2; |
25 | p1=wordchr(p,w); if(p1==NULL) error2("syntax_error"); |
25 | p1=wordchr(p,w); if(p1==NULL) error2("syntax_error"); |
26 | *p1=0; p2=find_word_start(p1+strlen(w)); |
26 | *p1=0; p2=find_word_start(p1+strlen(w)); |
27 | ovlstrcpy(t_buf[0],p); ovlstrcpy(t_buf[1],p2); |
27 | ovlstrcpy(t_buf[0],p); ovlstrcpy(t_buf[1],p2); |
28 | strip_trailing_spaces(t_buf[0]); |
28 | strip_trailing_spaces(t_buf[0]); |
29 | substitute(t_buf[0]); substitute(t_buf[1]); |
29 | substitute(t_buf[0]); substitute(t_buf[1]); |
30 | } |
30 | } |
31 | 31 | ||
32 |
|
32 | /* Extract characters in buf[0] which are identical to |
33 |
|
33 | * corresponding characters in buf[1]. */ |
34 | void text_common(char *p) |
34 | void text_common(char *p) |
35 | { |
35 | { |
36 | int i,j,n1,n2; |
36 | int i,j,n1,n2; |
37 | _text_cut(p,"and"); |
37 | _text_cut(p,"and"); |
38 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
38 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
39 | if(n2<n1) n1=n2; |
39 | if(n2<n1) n1=n2; |
40 | for(i=j=0;i<n1;i++) { |
40 | for(i=j=0;i<n1;i++) { |
41 |
|
41 | if(t_buf[0][i]==t_buf[1][i] && maskbuf[i]!='0') p[j++]=t_buf[0][i]; |
42 | } |
42 | } |
43 | p[j]=0; |
43 | p[j]=0; |
44 | } |
44 | } |
45 | 45 | ||
46 |
|
46 | /* Returns a mask string composed of '0's and '1's, where |
47 |
|
47 | * '0' means corresponding positions of buf[0] and buf[1] are |
48 |
|
48 | * equal. */ |
49 | void text_compare(char *p) |
49 | void text_compare(char *p) |
50 | { |
50 | { |
51 | int min,max, i; |
51 | int min,max, i; |
52 | _text_cut(p,"and"); |
52 | _text_cut(p,"and"); |
53 | min=strlen(t_buf[0]); max=strlen(t_buf[1]); |
53 | min=strlen(t_buf[0]); max=strlen(t_buf[1]); |
54 | if(min>max) { |
54 | if(min>max) { |
55 |
|
55 | i=min; min=max; max=i; |
56 | } |
56 | } |
57 | for(i=0; i<min; i++) { |
57 | for(i=0; i<min; i++) { |
58 |
|
58 | if(t_buf[0][i]==t_buf[1][i]) p[i]='0'; else p[i]='1'; |
59 | } |
59 | } |
60 | for(; i<max; i++) p[i]='1'; |
60 | for(; i<max; i++) p[i]='1'; |
61 | p[max]=0; |
61 | p[max]=0; |
62 | } |
62 | } |
63 | 63 | ||
64 |
|
64 | /* copy text according to mask. */ |
65 | void text_copy(char *p) |
65 | void text_copy(char *p) |
66 | { |
66 | { |
67 | int i, j, n; |
67 | int i, j, n; |
68 | 68 | ||
69 | snprintf(t_buf[0],MAX_LINELEN,"%s",p); |
69 | snprintf(t_buf[0],MAX_LINELEN,"%s",p); |
70 | strip_trailing_spaces(t_buf[0]); substitute(t_buf[0]); |
70 | strip_trailing_spaces(t_buf[0]); substitute(t_buf[0]); |
71 | n=strlen(t_buf[0]); |
71 | n=strlen(t_buf[0]); |
72 | for(i=j=0;i<n;i++) { |
72 | for(i=j=0;i<n;i++) { |
73 |
|
73 | if(maskbuf[i]!='0') p[j++]=t_buf[0][i]; |
74 | } |
74 | } |
75 | p[j]=0; |
75 | p[j]=0; |
76 | } |
76 | } |
77 | 77 | ||
78 |
|
78 | /* returns count of characters in buf[1] which appear in buf[0]. */ |
79 | void text_count(char *p) |
79 | void text_count(char *p) |
80 | { |
80 | { |
81 | int i, n, c; |
81 | int i, n, c; |
82 | _text_cut(p,"in"); |
82 | _text_cut(p,"in"); |
83 | n=strlen(t_buf[1]); |
83 | n=strlen(t_buf[1]); |
84 | for(i=c=0;i<n;i++) { |
84 | for(i=c=0;i<n;i++) { |
85 |
|
85 | if(strchr(t_buf[0],t_buf[1][i])!=NULL && maskbuf[i]!='0') c++; |
86 | } |
86 | } |
87 | snprintf(p,MAX_LINELEN,"%d",c); |
87 | snprintf(p,MAX_LINELEN,"%d",c); |
88 | } |
88 | } |
89 | 89 | ||
90 |
|
90 | /* Extract characters in buf[0] which are different than |
91 | |
91 | * corresponding characters in buf[1]. |
- | 92 | */ |
|
92 | void text_diff(char *p) |
93 | void text_diff(char *p) |
93 | { |
94 | { |
94 | int i,j,n1,n2; |
95 | int i,j,n1,n2; |
95 | _text_cut(p,"from"); |
96 | _text_cut(p,"from"); |
96 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
97 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
97 | if(n2<n1) n1=n2; |
98 | if(n2<n1) n1=n2; |
98 | for(i=j=0;i<n1;i++) { |
99 | for(i=j=0;i<n1;i++) { |
99 |
|
100 | if(t_buf[0][i]!=t_buf[1][i] && maskbuf[i]!='0') p[j++]=t_buf[0][i]; |
100 | } |
101 | } |
101 | p[j]=0; |
102 | p[j]=0; |
102 | } |
103 | } |
103 | 104 | ||
104 |
|
105 | /* put chars in buf[0] in a new string, into positions |
105 |
|
106 | * corresponding to '1's in the mask buf[1]. |
106 |
|
107 | * Positions corresponding to '0's are filled by space. |
107 |
|
108 | * Fill stops at the end of buf[0]. If buf[1] is |
108 |
|
109 | * too short, it is reused from the start. |
- | 110 | */ |
|
109 | void text_expand(char *p) |
111 | void text_expand(char *p) |
110 | { |
112 | { |
111 | int i,j,k,n1,n2; |
113 | int i,j,k,n1,n2; |
112 | _text_cut(p,"using"); |
114 | _text_cut(p,"using"); |
113 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
115 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
114 | if(n2==0) {p[0]=0; return;} |
116 | if(n2==0) {p[0]=0; return;} |
115 | for(i=j=k=0;i<n1 && j<MAX_LINELEN;j++,k=j%n2) { |
117 | for(i=j=k=0;i<n1 && j<MAX_LINELEN;j++,k=j%n2) { |
116 |
|
118 | if(t_buf[1][k]=='0') p[j]=' '; |
117 |
|
119 | else p[j]=t_buf[0][i++]; |
118 | } |
120 | } |
119 | p[j]=0; |
121 | p[j]=0; |
120 | } |
122 | } |
121 | 123 | ||
122 |
|
124 | /* character by character replacement of buf[1] by buf[0], |
123 |
|
125 | * replacing only mask-effective chars. |
124 |
|
126 | * The resulting string is as long as buf[1], and the replacement |
125 |
|
127 | * stops when chars buf[0] has run out. |
- | 128 | */ |
|
126 | void text_insert(char *p) |
129 | void text_insert(char *p) |
127 | { |
130 | { |
128 | int i,j,n1,n2; |
131 | int i,j,n1,n2; |
129 | _text_cut(p,"into"); |
132 | _text_cut(p,"into"); |
130 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
133 | n1=strlen(t_buf[0]);n2=strlen(t_buf[1]); |
131 | for(i=j=0; i<n2 && j<n1; i++) { |
134 | for(i=j=0; i<n2 && j<n1; i++) { |
132 |
|
135 | if(maskbuf[i]!='0') t_buf[1][i]=t_buf[0][j++]; |
133 | } |
136 | } |
134 | snprintf(p,MAX_LINELEN,"%s",t_buf[1]); |
137 | snprintf(p,MAX_LINELEN,"%s",t_buf[1]); |
135 | } |
138 | } |
136 | 139 | ||
137 | #define MAX_TLEN 96 |
140 | #define MAX_TLEN 96 |
138 | 141 | ||
139 |
|
142 | /* interact of two strings according to rules |
140 | |
143 | * defined a table. |
- | 144 | */ |
|
141 | void text_interact(char *p) |
145 | void text_interact(char *p) |
142 | { |
146 | { |
143 | char *table, *dline, *tline[MAX_TLEN]; |
147 | char *table, *dline, *tline[MAX_TLEN]; |
144 | char *p1, *p2; |
148 | char *p1, *p2; |
145 | int i,j1,j2,k,l,l2,n; |
149 | int i,j1,j2,k,l,l2,n; |
146 | 150 | ||
147 | table=wordchr(p,"table"); |
151 | table=wordchr(p,"table"); |
148 | if(table==NULL) error2("syntax_error"); |
152 | if(table==NULL) error2("syntax_error"); |
149 | *table=0; strip_trailing_spaces(p); |
153 | *table=0; strip_trailing_spaces(p); |
150 | table=find_word_start(table+strlen("table")); |
154 | table=find_word_start(table+strlen("table")); |
151 | snprintf(t_buf[2],MAX_LINELEN,"%s",table); |
155 | snprintf(t_buf[2],MAX_LINELEN,"%s",table); |
Line 155... | Line 159... | ||
155 | if(n>=MAX_TLEN) error2("text_bad_table"); |
159 | if(n>=MAX_TLEN) error2("text_bad_table"); |
156 | p2=strchr(t_buf[2],'\n'); if(p2!=NULL) *p2++=0; |
160 | p2=strchr(t_buf[2],'\n'); if(p2!=NULL) *p2++=0; |
157 | if(strlen(t_buf[2])!=n) error2("text_bad_table"); |
161 | if(strlen(t_buf[2])!=n) error2("text_bad_table"); |
158 | dline=t_buf[2]; |
162 | dline=t_buf[2]; |
159 | for(i=0,p1=p2;i<n;i++,p1=p2) { |
163 | for(i=0,p1=p2;i<n;i++,p1=p2) { |
160 |
|
164 | if(p1==NULL) error2("text_bad_table"); |
161 |
|
165 | p2=strchr(p1,'\n'); |
162 |
|
166 | if(p2!=NULL) *p2++=0; |
163 |
|
167 | if(strlen(p1)!=n) error2("text_bad_table"); |
164 |
|
168 | tline[i]=p1; |
165 | } |
169 | } |
166 | l=strlen(t_buf[0]); l2=strlen(t_buf[1]); if(l2<l) l=l2; |
170 | l=strlen(t_buf[0]); l2=strlen(t_buf[1]); if(l2<l) l=l2; |
167 | for(i=k=0;i<l;i++) { |
171 | for(i=k=0;i<l;i++) { |
168 |
|
172 | if(maskbuf[i]!='0') { |
169 |
|
173 | p1=strchr(dline,t_buf[0][i]); |
170 |
|
174 | p2=strchr(dline,t_buf[1][i]); |
171 |
|
175 | if(p1==NULL || p2==NULL) continue; |
172 |
|
176 | j1=p1-dline; j2=p2-dline; |
173 |
|
177 | if(j1>=n || j2>=n) continue; /* should not occur */ |
174 |
|
178 | p[k++]=tline[j1][j2]; |
175 |
|
179 | } |
176 | } |
180 | } |
177 | p[k]=0; |
181 | p[k]=0; |
178 | } |
182 | } |
179 | 183 | ||
180 |
|
184 | /* returns a mask string composed of '0's and '1's, where |
181 |
|
185 | * '0' means corresponding char in buf[1] appears in buf[0]. */ |
182 | void text_mark(char *p) |
186 | void text_mark(char *p) |
183 | { |
187 | { |
184 | int i, n; |
188 | int i, n; |
185 | _text_cut(p,"in"); |
189 | _text_cut(p,"in"); |
186 | n=strlen(t_buf[1]); |
190 | n=strlen(t_buf[1]); |
187 | for(i=0;i<n;i++) { |
191 | for(i=0;i<n;i++) { |
188 |
|
192 | if(strchr(t_buf[0],t_buf[1][i])!=NULL) p[i]='1'; |
189 |
|
193 | else p[i]='0'; |
190 | } |
194 | } |
191 | p[i]=0; |
195 | p[i]=0; |
192 | } |
196 | } |
193 | 197 | ||
194 |
|
198 | /* Returns a string whose characters are the maximum |
195 |
|
199 | * of the two corresponding chars in buf[0] and buf[1]. |
196 |
|
200 | * Length of the string is the longuest one. |
- | 201 | */ |
|
197 | void text_max(char *p) |
202 | void text_max(char *p) |
198 | { |
203 | { |
199 | int min,max, i, j, k; |
204 | int min,max, i, j, k; |
200 | _text_cut(p,"and"); |
205 | _text_cut(p,"and"); |
201 | min=strlen(t_buf[0]); max=strlen(t_buf[1]); |
206 | min=strlen(t_buf[0]); max=strlen(t_buf[1]); |
202 | if(min>max) { |
207 | if(min>max) { |
203 |
|
208 | i=min; min=max; max=i; j=0; |
204 | } |
209 | } |
205 | else j=1; |
210 | else j=1; |
206 | for(i=k=0; i<min; i++) { |
211 | for(i=k=0; i<min; i++) { |
207 |
|
212 | if(maskbuf[i]=='0') continue; |
208 |
|
213 | if((unsigned char)t_buf[0][i]>(unsigned char)t_buf[1][i]) |
209 | p[k++]=t_buf[0][i]; |
214 | p[k++]=t_buf[0][i]; |
210 |
|
215 | else p[k++]=t_buf[1][i]; |
211 | } |
216 | } |
212 | for(;i<max;i++) { |
217 | for(;i<max;i++) { |
213 |
|
218 | if(maskbuf[i]!='0') p[k++]=t_buf[j][i]; |
214 | } |
219 | } |
215 | p[k]=0; |
220 | p[k]=0; |
216 | } |
221 | } |
217 | 222 | ||
218 |
|
223 | /* Returns a string whose characters are the minimum |
219 |
|
224 | * of the two corresponding chars in buf[0] and buf[1]. |
220 |
|
225 | * Length of the string is the shortest one. |
- | 226 | */ |
|
221 | void text_min(char *p) |
227 | void text_min(char *p) |
222 | { |
228 | { |
223 | int min,max, i,k; |
229 | int min,max, i,k; |
224 | _text_cut(p,"and"); |
230 | _text_cut(p,"and"); |
225 | min=strlen(t_buf[0]); max=strlen(t_buf[1]); |
231 | min=strlen(t_buf[0]); max=strlen(t_buf[1]); |
226 | if(min>max) { |
232 | if(min>max) { |
227 |
|
233 | i=min; min=max; max=i; |
228 | } |
234 | } |
229 | for(i=k=0; i<min; i++) { |
235 | for(i=k=0; i<min; i++) { |
230 |
|
236 | if(maskbuf[i]=='0') continue; |
231 |
|
237 | if((unsigned char)t_buf[0][i]< (unsigned char)t_buf[1][i]) |
232 | p[k++]=t_buf[0][i]; |
238 | p[k++]=t_buf[0][i]; |
233 |
|
239 | else p[k++]=t_buf[1][i]; |
234 | } |
240 | } |
235 | p[k]=0; |
241 | p[k]=0; |
236 | } |
242 | } |
237 | 243 | ||
238 |
|
244 | /* extract chars in buf[0] which occur in buf[1]. */ |
239 | void text_occur(char *p) |
245 | void text_occur(char *p) |
240 | { |
246 | { |
241 | int i,j,n; |
247 | int i,j,n; |
242 | char buf[MAX_LINELEN+1]; |
248 | char buf[MAX_LINELEN+1]; |
243 | memset(buf,0,sizeof(buf)); |
249 | memset(buf,0,sizeof(buf)); |
244 | _text_cut(p,"in"); |
250 | _text_cut(p,"in"); |
245 | n=strlen(t_buf[1]); |
251 | n=strlen(t_buf[1]); |
246 | for(i=0;i<n;i++) { |
252 | for(i=0;i<n;i++) { |
247 |
|
253 | char *pp; |
248 |
|
254 | if(maskbuf[i]=='0') continue; |
249 |
|
255 | pp=strchr(t_buf[0],t_buf[1][i]); |
250 |
|
256 | if(pp!=NULL) buf[pp - t_buf[0]]=1; |
251 | } |
257 | } |
252 | n=strlen(t_buf[0]); |
258 | n=strlen(t_buf[0]); |
253 | for(i=j=0;i<n;i++) { |
259 | for(i=j=0;i<n;i++) { |
254 |
|
260 | if(buf[i]) p[j++]=t_buf[0][i]; |
255 | } |
261 | } |
256 | p[j]=0; |
262 | p[j]=0; |
257 | } |
263 | } |
258 | 264 | ||
259 |
|
265 | /* remove characters of buf[1] in buf[0]. */ |
260 | void text_remove(char *p) |
266 | void text_remove(char *p) |
261 | { |
267 | { |
262 | int i, j, n; |
268 | int i, j, n; |
263 | _text_cut(p,"in"); |
269 | _text_cut(p,"in"); |
264 | n=strlen(t_buf[1]); |
270 | n=strlen(t_buf[1]); |
265 | for(i=j=0;i<n;i++) { |
271 | for(i=j=0;i<n;i++) { |
266 |
|
272 | if(strchr(t_buf[0],t_buf[1][i])==NULL |
267 |
|
273 | && maskbuf[i]!='0') p[j++]=t_buf[1][i]; |
268 | } |
274 | } |
269 | p[j]=0; |
275 | p[j]=0; |
270 | } |
276 | } |
271 | 277 | ||
272 |
|
278 | /* Cyclic reordering of text. */ |
273 | void text_reorder(char *p) |
279 | void text_reorder(char *p) |
274 | { |
280 | { |
275 | int i,j,k,l,n,t; |
281 | int i,j,k,l,n,t; |
276 | int list[10240]; |
282 | int list[10240]; |
277 | char buf[MAX_LINELEN+1]; |
283 | char buf[MAX_LINELEN+1]; |
278 | _text_cut(p,"by"); *p=0; |
284 | _text_cut(p,"by"); *p=0; |
279 | n=itemnum(t_buf[1]); if(n<=0 || n>=10240) return; |
285 | n=itemnum(t_buf[1]); if(n<=0 || n>=10240) return; |
280 | for(i=0;i<n;i++) { |
286 | for(i=0;i<n;i++) { |
281 | buf[0]=0; fnd_item(t_buf[1],i+1,buf); |
287 | buf[0]=0; fnd_item(t_buf[1],i+1,buf); |
282 |
|
288 | j=atoi(buf); if(j<=0 || j>n) return; |
283 |
|
289 | list[i]=j; |
284 | } |
290 | } |
285 | t=strlen(t_buf[0]); |
291 | t=strlen(t_buf[0]); |
286 | for(i=l=0;l<t && i<t+n;i++) { |
292 | for(i=l=0;l<t && i<t+n;i++) { |
287 |
|
293 | j=i/n; k=j*n+list[i%n]; |
288 |
|
294 | if(k>t || k<=0) continue; |
289 |
|
295 | p[l++]=t_buf[0][k-1]; |
290 | } |
296 | } |
291 | p[l]=0; |
297 | p[l]=0; |
292 | } |
298 | } |
293 | 299 | ||
294 |
|
300 | /* repeat a string to a given length. */ |
295 | void text_repeat(char *p) |
301 | void text_repeat(char *p) |
296 | { |
302 | { |
297 | int n,i,k; |
303 | int n,i,k; |
298 | _text_cut(p,"to"); |
304 | _text_cut(p,"to"); |
299 | n=strevalue(t_buf[1]); if(n>MAX_LINELEN) n=MAX_LINELEN; |
305 | n=strevalue(t_buf[1]); if(n>MAX_LINELEN) n=MAX_LINELEN; |
300 | if(n<0) n=0; |
306 | if(n<0) n=0; |
301 | k=strlen(t_buf[0]); if(k<=0) {*p=0; return;} |
307 | k=strlen(t_buf[0]); if(k<=0) {*p=0; return;} |
302 | for(i=0;i<n;i++) { |
308 | for(i=0;i<n;i++) { |
303 |
|
309 | p[i]=t_buf[0][i%k]; |
304 | } |
310 | } |
305 | p[i]=0; |
311 | p[i]=0; |
306 | } |
312 | } |
307 | 313 | ||
308 |
|
314 | /* reverse a string */ |
309 | void text_reverse(char *p) |
315 | void text_reverse(char *p) |
310 | { |
316 | { |
311 | int i,n; |
317 | int i,n; |
312 | char buf[MAX_LINELEN+1]; |
318 | char buf[MAX_LINELEN+1]; |
313 | snprintf(t_buf[0],sizeof(t_buf[0]),"%s",p); |
319 | snprintf(t_buf[0],sizeof(t_buf[0]),"%s",p); |
Line 316... | Line 322... | ||
316 | for(i=0;i<n;i++) buf[i]=t_buf[0][n-1-i]; |
322 | for(i=0;i<n;i++) buf[i]=t_buf[0][n-1-i]; |
317 | buf[n]=0; |
323 | buf[n]=0; |
318 | ovlstrcpy(p,buf); |
324 | ovlstrcpy(p,buf); |
319 | } |
325 | } |
320 | 326 | ||
321 |
|
327 | /* remove characters of buf[1] not in buf[0]. */ |
322 | void text_select(char *p) |
328 | void text_select(char *p) |
323 | { |
329 | { |
324 | int i, j, n; |
330 | int i, j, n; |
325 | _text_cut(p,"in"); |
331 | _text_cut(p,"in"); |
326 | n=strlen(t_buf[1]); |
332 | n=strlen(t_buf[1]); |
327 | for(i=j=0;i<n;i++) { |
333 | for(i=j=0;i<n;i++) { |
328 |
|
334 | if(strchr(t_buf[0],t_buf[1][i])!=NULL |
329 |
|
335 | && maskbuf[i]!='0') p[j++]=t_buf[1][i]; |
330 | } |
336 | } |
331 | p[j]=0; |
337 | p[j]=0; |
332 | } |
338 | } |
333 | 339 | ||
334 |
|
340 | /* tag: bit 0 is mask. */ |
335 | struct { |
341 | struct { |
336 | char *name; |
342 | char *name; |
337 | int tag; |
343 | int tag; |
338 | void (*routine) (char *p); |
344 | void (*routine) (char *p); |
339 | } text_proc[]={ |
345 | } text_proc[]={ |
340 | {"appear", |
346 | {"appear", 1, text_occur}, |
341 | {"common", |
347 | {"common", 1, text_common}, |
342 | {"compare", |
348 | {"compare", 0, text_compare}, |
343 | {"copy", |
349 | {"copy", 1, text_copy}, |
344 | {"count", |
350 | {"count", 1, text_count}, |
345 | {"delete", |
351 | {"delete", 1, text_remove}, |
346 | {"diff", |
352 | {"diff", 1, text_diff}, |
347 | {"differ", |
353 | {"differ", 1, text_diff}, |
348 | {"drop", |
354 | {"drop", 1, text_remove}, |
349 | {"expand", |
355 | {"expand", 0, text_expand}, |
350 | {"extract", |
356 | {"extract", 1, text_select}, |
351 | {"insert", |
357 | {"insert", 1, text_insert}, |
352 | {"interact", |
358 | {"interact", 1, text_interact}, |
353 | {"mark", |
359 | {"mark", 0, text_mark}, |
354 | {"max", |
360 | {"max", 1, text_max}, |
355 | {"min", |
361 | {"min", 1, text_min}, |
356 | {"occur", |
362 | {"occur", 1, text_occur}, |
357 | {"occurrence", |
363 | {"occurrence",1, text_occur}, |
358 | {"pick", |
364 | {"pick", 1, text_select}, |
359 | {"pickup", |
365 | {"pickup", 1, text_select}, |
360 | {"remove", |
366 | {"remove", 1, text_remove}, |
361 | {"reorder", |
367 | {"reorder", 0, text_reorder}, |
362 | {"repeat", |
368 | {"repeat", 0, text_repeat}, |
363 | {"reverse", |
369 | {"reverse", 0, text_reverse}, |
364 | {"select", |
370 | {"select", 1, text_select} |
365 | }; |
371 | }; |
366 | #define TEXT_PROC_NO (sizeof(text_proc)/sizeof(text_proc[0])) |
372 | #define TEXT_PROC_NO (sizeof(text_proc)/sizeof(text_proc[0])) |
367 | 373 | ||
368 | int textab_verify(void) { |
374 | int textab_verify(void) { |
369 | return verify_order(text_proc,TEXT_PROC_NO,sizeof(text_proc[0])); |
375 | return verify_order(text_proc,TEXT_PROC_NO,sizeof(text_proc[0])); |
370 | } |
376 | } |
371 | 377 | ||
372 |
|
378 | /* main entry point for text routines */ |
373 | void text(char *p) |
379 | void text(char *p) |
374 | { |
380 | { |
375 | int i,j,n; |
381 | int i,j,n; |
376 | char *p1, *p2; |
382 | char *p1, *p2; |
377 | char c,cc; |
383 | char c,cc; |
Line 381... | Line 387... | ||
381 | *p2=0; |
387 | *p2=0; |
382 | i=search_list(text_proc,TEXT_PROC_NO,sizeof(text_proc[0]),p1); |
388 | i=search_list(text_proc,TEXT_PROC_NO,sizeof(text_proc[0]),p1); |
383 | if(i<0) error2("syntax_error"); |
389 | if(i<0) error2("syntax_error"); |
384 | snprintf(buf,sizeof(buf),"%s",find_word_start(p2+1)); |
390 | snprintf(buf,sizeof(buf),"%s",find_word_start(p2+1)); |
385 | if((text_proc[i].tag&1)!=0 && (p1=wordchr(buf,"mask"))!=NULL) { |
391 | if((text_proc[i].tag&1)!=0 && (p1=wordchr(buf,"mask"))!=NULL) { |
386 |
|
392 | *p1=0; strip_trailing_spaces(buf); |
387 |
|
393 | p2=find_word_start(p1+strlen("mask")); |
388 |
|
394 | strip_trailing_spaces(p2); |
389 |
|
395 | snprintf(maskbuf,sizeof(maskbuf),"%s",p2); |
390 |
|
396 | substitute(maskbuf); |
391 |
|
397 | n=strlen(maskbuf); if(n==0) goto zeromask; |
392 |
|
398 | c=maskbuf[n-1]; cc=0; |
393 |
|
399 | if(c=='+') cc='1'; if(c=='-') cc='0'; |
394 |
|
400 | if(cc!=0) memset(maskbuf+n-1,cc,sizeof(maskbuf)-n); |
395 |
|
401 | else for(j=n;j<MAX_LINELEN;j++) maskbuf[j]=maskbuf[j%n]; |
396 |
|
402 | maskbuf[sizeof(maskbuf)-1]=0; |
397 | } |
403 | } |
398 | else zeromask: memset(maskbuf,0,sizeof(maskbuf)); |
404 | else zeromask: memset(maskbuf,0,sizeof(maskbuf)); |
399 | text_proc[i].routine(buf); |
405 | text_proc[i].routine(buf); |
400 | buf[MAX_LINELEN]=0;ovlstrcpy(p,buf); |
406 | buf[MAX_LINELEN]=0;ovlstrcpy(p,buf); |
401 | } |
407 | } |
402 | - |