Subversion Repositories wimsdev

Rev

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

Rev 3813 Rev 8161
Line 13... Line 13...
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
 
17
 
-
 
18
#include "symtext.h"
18
        /* Block parsing routines
19
/* Block parsing routines
19
         * Return value:
20
 * Return value:
20
         * 0 if no match.
21
 * 0 if no match.
21
         * 1 if match.
22
 * 1 if match.
22
         * -1 if error. */
23
 * -1 if error.
-
 
24
 */
23
 
25
 
24
struct npool {
26
struct npool {
25
    listtype nextblock,last;
27
    listtype nextblock,last;
26
} npool[MAX_POOLS];
28
} npool[MAX_POOLS];
27
int nextnpool, currnpool;
29
int nextnpool, currnpool;
Line 30... Line 32...
30
{
32
{
31
    char *p, l, r;
33
    char *p, l, r;
32
    val=find_word_start(val);
34
    val=find_word_start(val);
33
    strip_trailing_spaces(val);
35
    strip_trailing_spaces(val);
34
    if(*val==0) {
36
    if(*val==0) {
35
        snprintf(outptr,sizeof(outbuf)-(outptr-outbuf)-1,"%s=_EMPTY_ ",tit);
37
      snprintf(outptr,OUTSIZE-(outptr-outbuf)-1,"%s=_EMPTY_ ",tit);
36
        goto outend;
38
      goto outend;
37
    }
39
    }
38
    if(*find_word_end(val)==0) {
40
    if(*find_word_end(val)==0) {
39
        snprintf(outptr,sizeof(outbuf)-(outptr-outbuf)-1,"%s=%s ",tit,val);
41
      snprintf(outptr,OUTSIZE-(outptr-outbuf)-1,"%s=%s ",tit,val);
40
    }
42
    }
41
    else {
43
    else {
42
        l='('; r=')';
44
      l='('; r=')';
43
        if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
45
      if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
44
            l='['; r=']';
46
          l='['; r=']';
45
            if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
47
          if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
46
                l='{'; r='}';
48
             l='{'; r='}';
47
                if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
49
             if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
48
                    l='"'; r='"';
50
                l='"'; r='"';
49
                    if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
51
                if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
50
                        l=r=' ';
52
                  l=r=' ';
51
                        for(p=val;*p;p++) if(*p==' ') *p='_';
53
                  for(p=val;*p;p++) if(*p==' ') *p='_';
52
                    }
54
                }
53
                }
55
            }
54
            }
56
          }
55
        }
57
      }
56
        snprintf(outptr,sizeof(outbuf)-(outptr-outbuf)-1,"%s=%c%s%c ",tit,l,val,r);
58
      snprintf(outptr,OUTSIZE-(outptr-outbuf)-1,"%s=%c%s%c ",tit,l,val,r);
57
    }
59
    }
58
    outend: outptr+=strlen(outptr);
60
    outend: outptr+=strlen(outptr);
59
}
61
}
60
 
62
 
61
void cleartag(struct poolstruct *pl)
63
void cleartag(struct poolstruct *pl)
62
{
64
{
63
    int i, len, level;
65
    int i, len, level;
64
    listtype *tag;
66
    listtype *tag;
65
    len=pl->len; tag=pl->tag; level=pl->ind2;
67
    len=pl->len; tag=pl->tag; level=pl->ind2;
66
    if(level==0) {
68
    if(level==0) {
67
        memset(tag,0,pl->len*sizeof(listtype));
69
      memset(tag,0,pl->len*sizeof(listtype));
68
    }
70
    }
69
    else for(i=0; i<len; i++) {
71
    else for(i=0; i<len; i++) {
70
        if(tag[i]>=level) tag[i]=0;
72
      if(tag[i]>=level) tag[i]=0;
71
    }
73
    }
72
}
74
}
73
 
75
 
74
struct poolstruct *getpool(struct block *blk)
76
struct poolstruct *getpool(struct block *blk)
75
{
77
{
76
    struct poolstruct *pl;
78
    struct poolstruct *pl;
77
   
79
 
78
    if(nextpool>=MAX_POOLS) error("pool_overflow");
80
    if(nextpool>=MAX_POOLS) error("pool_overflow");
79
    pl=poolbuf+nextpool;
81
    pl=poolbuf+nextpool;
80
    pl->lastpool=blk->pool;
82
    pl->lastpool=blk->pool;
81
    blk->pool=nextpool; nextpool++;
83
    blk->pool=nextpool; nextpool++;
82
    pl->block=blk-blockbuf;
84
    pl->block=blk-blockbuf;
83
    pl->string=NULL;
85
    pl->string=NULL;
84
    pl->ind1=pl->ind2=pl->dirty=pl->len=0;
86
    pl->ind1=pl->ind2=pl->dirty=pl->len=0;
85
    return pl;
87
    return pl;
86
}
88
}
87
 
89
 
88
void putpool(struct poolstruct *pl)
90
void putpool(struct poolstruct *pl)
89
{
91
{
90
    nextpool--;
92
    nextpool--;
91
    if(nextpool!=pl-poolbuf) error("internal_error pool leaking");
93
    if(nextpool!=pl-poolbuf) error("internal_error pool leaking");
92
    blockbuf[pl->block].pool=pl->lastpool;
94
    blockbuf[pl->block].pool=pl->lastpool;
93
}
95
}
94
 
96
 
95
int mt_this(struct block *blk, char *start, int level)
97
int mt_this(struct block *blk, char *start, int level)
96
{
98
{
97
    int r;
99
    int r;
98
    if(level > MAX_LEVELS) error("level_overflow %.20s",start);
100
    if(level > MAX_LEVELS) error("level_overflow %.20s",start);
99
    start=find_word_start(start);
101
    start=find_word_start(start);
100
    if(debug>=2) fprintf(stderr,"lvl=%d. Checking against block %d for %.10s.\n",level,(int)(blk-blockbuf),start);
102
    if(debug>=2) fprintf(stderr,"lvl=%d. Checking against block %d for %.10s.\n",level,(int)(blk-blockbuf),start);
101
    r = blk->fn(blk,start,level);
103
    r = blk->fn(blk,start,level);
102
    if(debug) fprintf(stderr,"lvl=%d. Tested %d block %d for %.10s.\n",level,r,(int)(blk-blockbuf),start);
104
    if(debug) fprintf(stderr,"lvl=%d. Tested %d block %d for %.10s.\n",level,r,(int)(blk-blockbuf),start);
103
    return r;
105
    return r;
104
}
106
}
105
 
107
 
106
int mt_next(struct block *blk, char *start, int level)
108
int mt_next(struct block *blk, char *start, int level)
107
{
109
{
108
    int r,cp,next;
110
    int r,cp,next;
109
    next=blk->nextblock;
111
    next=blk->nextblock;
110
    cp=currnpool;
112
    cp=currnpool;
111
    if(next==-2) {
113
    if(next==-2) {
112
        do {
114
      do {
113
            next=npool[currnpool].nextblock; currnpool=npool[currnpool].last;
115
          next=npool[currnpool].nextblock; currnpool=npool[currnpool].last;
114
        }
116
      }
115
        while (next==-2 && currnpool>0);
117
      while (next==-2 && currnpool>0);
116
        if(next==-2) error("internal_error npool disorder");
118
      if(next==-2) error("internal_error npool disorder");
117
        if(debug>=3) fprintf(stderr,"Calling macro %d: next=%d.\n",
119
      if(debug>=3) fprintf(stderr,"Calling macro %d: next=%d.\n",
118
                             (int)(blk-blockbuf),next);
120
                       (int)(blk-blockbuf),next);
119
    }
121
    }
120
    if(next<0) {
122
    if(next<0) {
121
        if(*start) return 0; else return 1;
123
      if(*start) return 0; else return 1;
122
    }
124
    }
123
    r=mt_this(blockbuf+next,start,level);
125
    r=mt_this(blockbuf+next,start,level);
124
    currnpool=cp;
126
    currnpool=cp;
125
    return r;
127
    return r;
126
}
128
}
Line 128... Line 130...
128
int mt_string(struct block *blk, char *start, int level)
130
int mt_string(struct block *blk, char *start, int level)
129
{
131
{
130
    char *p;
132
    char *p;
131
    int r;
133
    int r;
132
    if(blk->len>0) {
134
    if(blk->len>0) {
133
        if(memcmp(blk->string,start,blk->len)!=0) return 0;
135
      if(memcmp(blk->string,start,blk->len)!=0) return 0;
134
        p=start+blk->len; if(*p && !myisspace(*p)) return 0;
136
      p=start+blk->len; if(*p && !myisspace(*p)) return 0;
135
    }
137
    }
136
    else p=start;
138
    else p=start;
137
    r = mt_next(blk,p,level+1);
139
    r = mt_next(blk,p,level+1);
138
    if(debug) fprintf(stderr,"Strcmp %d %.20s. <-> %.20s.\n",r, blk->string,start);
140
    if(debug) fprintf(stderr,"Strcmp %d %.20s. <-> %.20s.\n",r, blk->string,start);
139
    return r;
141
    return r;
Line 142... Line 144...
142
int mt_dic(struct block *blk, char *start, int level)
144
int mt_dic(struct block *blk, char *start, int level)
143
{
145
{
144
    int i,t;
146
    int i,t;
145
    struct entry *et;
147
    struct entry *et;
146
    char *p;
148
    char *p;
147
   
149
 
148
    i=blk->lind1;
150
    i=blk->lind1;
149
    t=search_dic(entry+dic[i].start,dic[i].len,sizeof(entry[0]),start);
151
    t=search_dic(entry+dic[i].start,dic[i].len,sizeof(entry[0]),start);
150
    if(t>=0) {
152
    if(t>=0) {
151
        et=entry+(dic[i].start+t);
153
      et=entry+(dic[i].start+t);
152
        if(itemchr((char*)et->replace,blk->string)==NULL) return 0;
154
      if(itemchr((char*)et->replace,blk->string)==NULL) return 0;
153
        p=start+et->olen;
155
      p=start+et->olen;
154
        return mt_next(blk,p,level+1);
156
      return mt_next(blk,p,level+1);
155
    }
157
    }
156
    switch(dic[i].unknown_type) {
158
    switch(dic[i].unknown_type) {
157
        case unk_leave: {
159
      case unk_leave: {
158
            if(memcmp(start,blk->string,blk->len)==0 ||
160
          if(memcmp(start,blk->string,blk->len)==0 ||
159
               (start[blk->len]!=0 && !myisspace(start[blk->len])))
161
             (start[blk->len]!=0 && !myisspace(start[blk->len])))
160
              return 0;
162
            return 0;
161
            return mt_next(blk,find_word_start(start+blk->len),level+1);           
163
          return mt_next(blk,find_word_start(start+blk->len),level+1);
162
        }
164
      }
163
        case unk_replace: {
165
      case unk_replace: {
164
            if(strcmp(dic[i].unknown,blk->string)!=0) return 0;
166
          if(strcmp(dic[i].unknown,blk->string)!=0) return 0;
165
            return mt_next(blk,start,level+1);
167
          return mt_next(blk,start,level+1);
166
        }
168
      }
167
        case unk_delete: return 0;
169
      case unk_delete: return 0;
168
    }
170
    }
169
    return 0;
171
    return 0;
170
}
172
}
171
 
173
 
172
int _permpick1(struct block *blk, char *start, int level)
174
int _permpick1(struct block *blk, char *start, int level)
173
{
175
{
174
    int i, j, k, r, re;
176
    int i, j, k, r, re;
175
    struct poolstruct *pl;
177
    struct poolstruct *pl;
176
   
178
 
177
    level++;
179
    level++;
178
    for(i=blk->pool+1; i<nextpool;i++) poolbuf[i].dirty++;
180
    for(i=blk->pool+1; i<nextpool;i++) poolbuf[i].dirty++;
179
    pl=poolbuf+blk->pool;
181
    pl=poolbuf+blk->pool;
180
    i=blk->lists[pl->ind1][pl->ind2];
182
    i=blk->lists[pl->ind1][pl->ind2];
181
    pl->ind2++; cleartag(pl);
183
    pl->ind2++; cleartag(pl);
182
ppstart:
184
ppstart:
183
    if(i>=blk->len) {           /* optional match */
185
    if(i>=blk->len) {            /* optional match */
184
        i-=blk->len;
186
      i-=blk->len;
185
        r=mt_next(blk,start,level);
187
      r=mt_next(blk,start,level);
186
        if(r) goto end;
188
      if(r) goto end;
187
    }
189
    }
188
    if(i>=0) {
190
    if(i>=0) {
189
        r=mt_this(blockbuf+blk->sublock+i,start,level);
191
      r=mt_this(blockbuf+blk->sublock+i,start,level);
190
        goto end;
192
      goto end;
191
    }
193
    }
192
    r=0;
194
    r=0;
193
    switch(i) {
195
    switch(i) {
194
        case -1: {      /* any */
196
      case -1: {      /* any */
195
            any:
197
          any:
196
            for(k=blk->lstart;k<blk->len;k++) {
198
          for(k=blk->lstart;k<blk->len;k++) {
197
                pl->tag[k]=pl->ind2;
199
            pl->tag[k]=pl->ind2;
198
                r=mt_this(blockbuf+blk->sublock+k,start,level);
200
            r=mt_this(blockbuf+blk->sublock+k,start,level);
199
                cleartag(pl);
201
            cleartag(pl);
200
                if(r) break;
202
            if(r) break;
201
            }
203
          }
202
            goto end;
204
          goto end;
203
        }
205
      }
204
        case -2: {      /* any unused */
206
      case -2: {      /* any unused */
205
            unused:
207
          unused:
206
            for(k=blk->lstart;k<blk->len;k++) {
208
          for(k=blk->lstart;k<blk->len;k++) {
207
                if(pl->tag[k]>0) continue;
209
            if(pl->tag[k]>0) continue;
208
                pl->tag[k]=pl->ind2;
210
            pl->tag[k]=pl->ind2;
209
                r=mt_this(blockbuf+blk->sublock+k,start,level);
211
            r=mt_this(blockbuf+blk->sublock+k,start,level);
210
                cleartag(pl);
212
            cleartag(pl);
211
                if(r) break;
213
            if(r) break;
212
            }
214
          }
213
            goto end;
215
          goto end;
214
        }
216
      }
215
        case -3: {      /* any unused bigger */
217
      case -3: {      /* any unused bigger */
216
            unused_bigger:
218
          unused_bigger:
217
            for(k=blk->len-1;k>=blk->lstart && pl->tag[k]==0;k--);
219
          for(k=blk->len-1;k>=blk->lstart && pl->tag[k]==0;k--);
218
            for(k++;k<blk->len;k++) {
220
          for(k++;k<blk->len;k++) {
219
                pl->tag[k]=pl->ind2;
221
            pl->tag[k]=pl->ind2;
220
                r=mt_this(blockbuf+blk->sublock+k,start,level);
222
            r=mt_this(blockbuf+blk->sublock+k,start,level);
221
                cleartag(pl);
223
            cleartag(pl);
222
                if(r) break;
224
            if(r) break;
223
            }
225
          }
224
            goto end;
226
          goto end;
225
        }
227
      }
226
        case -4: {      /* any unused smaller; not used */
228
      case -4: {      /* any unused smaller; not used */
227
            unused_smaller:
229
          unused_smaller:
228
            for(j=0; j<blk->len && pl->tag[j]==0;j++);
230
          for(j=0; j<blk->len && pl->tag[j]==0;j++);
229
            for(k=blk->lstart;k<j;k++) {
231
          for(k=blk->lstart;k<j;k++) {
230
                pl->tag[k]=pl->ind2;
232
            pl->tag[k]=pl->ind2;
231
                r=mt_this(blockbuf+blk->sublock+k,start,level);
233
            r=mt_this(blockbuf+blk->sublock+k,start,level);
232
                cleartag(pl);
234
            cleartag(pl);
233
                if(r) break;
235
            if(r) break;
234
            }
236
          }
235
            goto end;
237
          goto end;
236
        }
238
      }
237
        case -5: {      /* repeat */
239
      case -5: {      /* repeat */
238
            re=pl->ind2-1;
240
          re=pl->ind2-1;
239
            if(pl->ind2<2 || pl->string >= start) goto end;
241
          if(pl->ind2<2 || pl->string >= start) goto end;
240
            pl->string=start;
242
          pl->string=start;
241
            r=mt_next(blk,start,level);
243
          r=mt_next(blk,start,level);
242
            if(r) goto end;
244
          if(r) goto end;
243
            pl->ind2=re;
245
          pl->ind2=re;
244
            i=blk->lists[pl->ind1][pl->ind2 - 1];
246
          i=blk->lists[pl->ind1][pl->ind2 - 1];
245
            goto ppstart;
247
          goto ppstart;
246
        }
248
      }
247
        case -6: {
249
      case -6: {
248
            r=mt_next(blk,start,level);
250
          r=mt_next(blk,start,level);
249
            if(r) goto end;
251
          if(r) goto end;
250
            goto any;
252
          goto any;
251
        }
253
      }
252
        case -7: {
254
      case -7: {
253
            r=mt_next(blk,start,level);
255
          r=mt_next(blk,start,level);
254
            if(r) goto end;
256
          if(r) goto end;
255
            goto unused;
257
          goto unused;
256
        }
258
      }
257
        case -8: {
259
      case -8: {
258
            r=mt_next(blk,start,level);
260
          r=mt_next(blk,start,level);
259
            if(r) goto end;
261
          if(r) goto end;
260
            goto unused_bigger;
262
          goto unused_bigger;
261
        }
263
      }
262
        case -9: {
264
      case -9: {
263
            r=mt_next(blk,start,level);
265
          r=mt_next(blk,start,level);
264
            if(r) goto end;
266
          if(r) goto end;
265
            goto unused_smaller;
267
          goto unused_smaller;
266
        }
268
      }
267
        case -10: {     /* unused. */
269
      case -10: {      /* unused. */
268
            goto end;
270
          goto end;
269
        }
271
      }
270
        case -11: {     /* unused. */
272
      case -11: {      /* unused. */
271
            goto end;
273
          goto end;
272
        }
274
      }
273
        case -12: {     /* insertion */
275
      case -12: {      /* insertion */
274
            if(pl->tag[0]==0) {
276
           if(pl->tag[0]==0) {
275
                pl->tag[0]=pl->ind2;
277
            pl->tag[0]=pl->ind2;
276
                r=mt_this(blockbuf+blk->sublock,start,level);
278
            r=mt_this(blockbuf+blk->sublock,start,level);
277
                cleartag(pl);
279
            cleartag(pl);
278
                if(r) goto end;
280
            if(r) goto end;
279
            }
281
          }
280
            r=_permpick1(blk,start,level+1);
282
          r=_permpick1(blk,start,level+1);
281
            goto end;
283
          goto end;
282
        }
284
      }
283
        case -13: {     /* insertion end */
285
      case -13: {      /* insertion end */
284
            if(pl->tag[0]) r=mt_next(blk,start,level+1);
286
          if(pl->tag[0]) r=mt_next(blk,start,level+1);
285
            else r=0;
287
          else r=0;
286
            goto end;
288
          goto end;
287
        }
289
      }
288
    }
290
    }
289
end:
291
end:
290
    if(r==0) pl->ind2--;
292
    if(r==0) pl->ind2--;
291
    for(i=blk->pool+1; i<nextpool;i++) if(poolbuf[i].dirty) poolbuf[i].dirty--;
293
    for(i=blk->pool+1; i<nextpool;i++) if(poolbuf[i].dirty) poolbuf[i].dirty--;
292
    return r;
294
    return r;
Line 294... Line 296...
294
 
296
 
295
int mt_permpick(struct block *blk, char *start, int level)
297
int mt_permpick(struct block *blk, char *start, int level)
296
{
298
{
297
    int r, n, newpool;
299
    int r, n, newpool;
298
    struct poolstruct *pl;
300
    struct poolstruct *pl;
299
   
301
 
300
    newpool=n=0;
302
    newpool=n=0;
301
    pl=poolbuf+blk->pool;
303
    pl=poolbuf+blk->pool;
302
    if(pl==poolbuf || pl->dirty>0) {
304
    if(pl==poolbuf || pl->dirty>0) {
303
        pl=getpool(blk); newpool=1;
305
      pl=getpool(blk); newpool=1;
304
        n=pl->len=blk->len;
306
      n=pl->len=blk->len;
305
        if(nexttag + n >= MAX_BLOCKS) error("tag_overflow");
307
      if(nexttag + n >= MAX_BLOCKS) error("tag_overflow");
306
        pl->tag=tagbuf+nexttag; nexttag+=n;
308
      pl->tag=tagbuf+nexttag; nexttag+=n;
307
    }
309
    }
308
    if(pl->ind1==0 && pl->ind2==0) {
310
    if(pl->ind1==0 && pl->ind2==0) {
309
        for(r=0;pl->ind1<blk->lcnt;pl->ind1++,pl->ind2=0){
311
      for(r=0;pl->ind1<blk->lcnt;pl->ind1++,pl->ind2=0){
310
            r=_permpick1(blk,start,level);
312
          r=_permpick1(blk,start,level);
311
            if(r) break;
313
          if(r) break;
312
        }
314
      }
313
        pl->ind1=pl->ind2=0;
315
      pl->ind1=pl->ind2=0;
314
        if(newpool) {
316
      if(newpool) {
315
            putpool(pl); nexttag-=n;
317
          putpool(pl); nexttag-=n;
316
        }
318
      }
317
        return r;
319
      return r;
318
    }
320
    }
319
    if(pl->ind2>=blk->listlen[pl->ind1]) {
321
    if(pl->ind2>=blk->listlen[pl->ind1]) {
320
        return mt_next(blk,start,level);
322
      return mt_next(blk,start,level);
321
    }
323
    }
322
    return _permpick1(blk,start,level);
324
    return _permpick1(blk,start,level);
323
}
325
}
324
 
326
 
325
int mt_neg(struct block *blk, char *start, int level)
327
int mt_neg(struct block *blk, char *start, int level)
326
{
328
{
327
    int r, newpool;
329
    int r, newpool;
328
    struct poolstruct *pl;
330
    struct poolstruct *pl;
329
   
331
 
330
    newpool=0;
332
    newpool=0;
331
    pl=poolbuf+blk->pool;
333
    pl=poolbuf+blk->pool;
332
    if(pl==poolbuf || pl->dirty>0) {
334
    if(pl==poolbuf || pl->dirty>0) {
333
        pl=getpool(blk); newpool=1;
335
      pl=getpool(blk); newpool=1;
334
    }
336
    }
335
    if(pl->ind2) return 1;
337
    if(pl->ind2) return 1;
336
    pl->ind2=1;
338
    pl->ind2=1;
337
    r=mt_this(blockbuf+blk->sublock,start,level+1);
339
    r=mt_this(blockbuf+blk->sublock,start,level+1);
338
    pl->ind2=0; if(newpool) putpool(pl);
340
    pl->ind2=0;      if(newpool) putpool(pl);
339
    if(r==0) return mt_next(blk,start,level+1);
341
    if(r==0) return mt_next(blk,start,level+1);
340
    if(r==1) return 0;
342
    if(r==1) return 0;
341
    else return r;
343
    else return r;
342
}
344
}
343
 
345
 
344
int mt_nomatch(struct block *blk, char *start, int level)
346
int mt_nomatch(struct block *blk, char *start, int level)
345
{
347
{
346
    return 0;
348
    return 0;
347
}
349
}
348
 
350
 
Line 354... Line 356...
354
    currnpool=nextnpool;
356
    currnpool=nextnpool;
355
    nextnpool++;
357
    nextnpool++;
356
}
358
}
357
 
359
 
358
void putnpool(void)
360
void putnpool(void)
359
{
361
{
360
    if(nextnpool<=0) error("npool_underflow");
362
    if(nextnpool<=0) error("npool_underflow");
361
    nextnpool--;
363
    nextnpool--;
362
}
364
}
363
 
365
 
364
int mt_m(struct block *blk, char *start, int level)
366
int mt_m(struct block *blk, char *start, int level)
365
{
367
{
366
    int i,r,pl,b,e,cp;
368
    int i,r,pl,b,e,cp;
367
    char *bkstart;
369
    char *bkstart;
368
   
370
 
369
    if(blk->string>=start) return 0;
371
    if(blk->string>=start) return 0;
370
    bkstart=blk->string; blk->string=start;
372
    bkstart=blk->string; blk->string=start;
371
    cp=currnpool;
373
    cp=currnpool;
372
    getnpool(blk->nextblock);
374
    getnpool(blk->nextblock);
373
    b=blk->sublock; pl=blockbuf[b].mpool; blockbuf[b].mpool=nextpool+1;
375
    b=blk->sublock; pl=blockbuf[b].mpool; blockbuf[b].mpool=nextpool+1;
374
    e=blockbuf[b].mend;
376
    e=blockbuf[b].mend;
375
    if(pl>0) for(i=pl-1;i<nextpool;i++) {
377
    if(pl>0) for(i=pl-1;i<nextpool;i++) {
376
        if(poolbuf[i].block>=b && poolbuf[i].block<e) poolbuf[i].dirty++;
378
      if(poolbuf[i].block>=b && poolbuf[i].block<e) poolbuf[i].dirty++;
377
    }
379
    }
378
    if(debug>=3) fprintf(stderr, "Entering macro %d npool=%d, next=%d.\n",
380
    if(debug>=3) fprintf(stderr, "Entering macro %d npool=%d, next=%d.\n",
379
                         b, currnpool, npool[currnpool].nextblock);
381
                   b, currnpool, npool[currnpool].nextblock);
380
    r = mt_this(blockbuf+b,start,level+1);
382
    r = mt_this(blockbuf+b,start,level+1);
381
    if(pl>0) for(i=pl-1;i<nextpool;i++) {
383
    if(pl>0) for(i=pl-1;i<nextpool;i++) {
382
        if(poolbuf[i].block>=b && poolbuf[i].block<e && poolbuf[i].dirty>0) poolbuf[i].dirty--;
384
      if(poolbuf[i].block>=b && poolbuf[i].block<e && poolbuf[i].dirty>0) poolbuf[i].dirty--;
383
    }
385
    }
384
    blockbuf[b].mpool=pl;
386
    blockbuf[b].mpool=pl;
385
    putnpool(); currnpool=cp; blk->string=bkstart;
387
    putnpool(); currnpool=cp; blk->string=bkstart;
386
    if(debug>=3) fprintf(stderr, "macro %d returns %d, npool=%d, next=%d.\n",
388
    if(debug>=3) fprintf(stderr, "macro %d returns %d, npool=%d, next=%d.\n",
387
                         b, r, nextnpool, npool[nextnpool].nextblock);
389
                   b, r, nextnpool, npool[nextnpool].nextblock);
388
    return r;
390
    return r;
389
}
391
}
390
 
392
 
391
int mt_out(struct block *blk, char *start, int level)
393
int mt_out(struct block *blk, char *start, int level)
392
{
394
{
393
    int r, l, newpool;
395
    int r, l, newpool;
394
    char buf[MAX_LINELEN+1];
396
    char buf[MAX_LINELEN+1];
395
    struct poolstruct *pl;
397
    struct poolstruct *pl;
396
   
398
 
397
    newpool=0;
399
    newpool=0;
398
    pl=poolbuf+blk->pool;
400
    pl=poolbuf+blk->pool;
399
    if(pl==poolbuf || pl->dirty>0) {
401
    if(pl==poolbuf || pl->dirty>0) {
400
        pl=getpool(blk); newpool=1;
402
      pl=getpool(blk); newpool=1;
401
    }
403
    }
402
    if(pl->ind2) {
404
    if(pl->ind2) {
403
        pl->string=start;
405
      pl->string=start;
404
        return mt_next(blk,start,level+1);
406
      return mt_next(blk,start,level+1);
405
    }
407
    }
406
    pl->ind2++;
408
    pl->ind2++;
407
    r=mt_this(blockbuf+blk->sublock,start,level+1);
409
    r=mt_this(blockbuf+blk->sublock,start,level+1);
408
    pl->ind2=0; if(newpool) putpool(pl);
410
    pl->ind2=0;      if(newpool) putpool(pl);
409
    if(r) {
411
    if(r) {
410
        l=pl->string - start;
412
      l=pl->string - start;
411
        if(l>=0 && l<MAX_LINELEN) {
413
      if(l>=0 && l<MAX_LINELEN) {
412
            memmove(buf,start,l); buf[l]=0;
414
          memmove(buf,start,l); buf[l]=0;
413
            outval(blk->string, buf);
415
          outval(blk->string, buf);
414
        }
416
      }
415
    }
417
    }
416
    return r;
418
    return r;
417
}
419
}
418
 
420
 
419
int mt_w(struct block *blk, char *start, int level)
421
int mt_w(struct block *blk, char *start, int level)
Line 434... Line 436...
434
    char *p;
436
    char *p;
435
    int i,l,r;
437
    int i,l,r;
436
 
438
 
437
    l=blk->lstart;
439
    l=blk->lstart;
438
    for(i=0,p=find_word_start(start);i<l;i++,p=find_word_start(find_word_end(p))) {
440
    for(i=0,p=find_word_start(start);i<l;i++,p=find_word_start(find_word_end(p))) {
439
        if(*p==0) return 0;
441
      if(*p==0) return 0;
440
    }
442
    }
441
    l=blk->len;
443
    l=blk->len;
442
    if(l==0) return mt_next(blk,p,level+1);
444
    if(l==0) return mt_next(blk,p,level+1);
443
    for(i=0; i<=l && *p; i++, p=find_word_start(find_word_end(p))) {
445
    for(i=0; i<=l && *p; i++, p=find_word_start(find_word_end(p))) {
444
        r=mt_next(blk,p,level+1);
446
      r=mt_next(blk,p,level+1);
445
        if(r) return r;
447
      if(r) return r;
446
    }
448
    }
447
    if(i<=l) return mt_next(blk,p,level+1);
449
    if(i<=l) return mt_next(blk,p,level+1);
448
    else return 0;
450
    else return 0;
449
}
451
}
450
 
452
 
Line 454... Line 456...
454
    outptr=outbuf; *outptr=0; nextpool=nextnpool=1; nexttag=0;
456
    outptr=outbuf; *outptr=0; nextpool=nextnpool=1; nexttag=0;
455
    currnpool=0;
457
    currnpool=0;
456
    for(i=0;i<nextblock;i++) blockbuf[i].pool=blockbuf[i].mpool=0;
458
    for(i=0;i<nextblock;i++) blockbuf[i].pool=blockbuf[i].mpool=0;
457
    return mt_this(blockbuf,find_word_start(p),0);
459
    return mt_this(blockbuf,find_word_start(p),0);
458
}
460
}
459
 
-