Back to index

wims  3.65+svn20090927
Classes | Functions | Variables
match.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  npool

Functions

void outval (char *tit, char *val)
void cleartag (struct poolstruct *pl)
struct poolstructgetpool (struct block *blk)
void putpool (struct poolstruct *pl)
int mt_this (struct block *blk, char *start, int level)
int mt_next (struct block *blk, char *start, int level)
int mt_string (struct block *blk, char *start, int level)
int mt_dic (struct block *blk, char *start, int level)
int _permpick1 (struct block *blk, char *start, int level)
int mt_permpick (struct block *blk, char *start, int level)
int mt_neg (struct block *blk, char *start, int level)
int mt_nomatch (struct block *blk, char *start, int level)
void getnpool (int b)
void putnpool (void)
int mt_m (struct block *blk, char *start, int level)
int mt_out (struct block *blk, char *start, int level)
int mt_w (struct block *blk, char *start, int level)
int mt_wild (struct block *blk, char *start, int level)
int match (char *p)

Variables

struct npool npool [MAX_POOLS]
int nextnpool
int currnpool

Class Documentation

struct npool

Definition at line 24 of file match.c.

Class Members
listtype last
listtype nextblock

Function Documentation

int _permpick1 ( struct block blk,
char *  start,
int  level 
)

Definition at line 172 of file match.c.

{
    int i, j, k, r, re;
    struct poolstruct *pl;
    
    level++;
    for(i=blk->pool+1; i<nextpool;i++) poolbuf[i].dirty++;
    pl=poolbuf+blk->pool;
    i=blk->lists[pl->ind1][pl->ind2];
    pl->ind2++; cleartag(pl);
ppstart:
    if(i>=blk->len) {              /* optional match */
       i-=blk->len;
       r=mt_next(blk,start,level);
       if(r) goto end;
    }
    if(i>=0) {
       r=mt_this(blockbuf+blk->sublock+i,start,level);
       goto end;
    }
    r=0;
    switch(i) {
       case -1: {    /* any */
           any:
           for(k=blk->lstart;k<blk->len;k++) {
              pl->tag[k]=pl->ind2;
              r=mt_this(blockbuf+blk->sublock+k,start,level);
              cleartag(pl);
              if(r) break;
           }
           goto end;
       }
       case -2: {    /* any unused */
           unused:
           for(k=blk->lstart;k<blk->len;k++) {
              if(pl->tag[k]>0) continue;
              pl->tag[k]=pl->ind2;
              r=mt_this(blockbuf+blk->sublock+k,start,level);
              cleartag(pl);
              if(r) break;
           }
           goto end;
       }
       case -3: {    /* any unused bigger */
           unused_bigger:
           for(k=blk->len-1;k>=blk->lstart && pl->tag[k]==0;k--);
           for(k++;k<blk->len;k++) {
              pl->tag[k]=pl->ind2;
              r=mt_this(blockbuf+blk->sublock+k,start,level);
              cleartag(pl);
              if(r) break;
           }
           goto end;
       }
       case -4: {    /* any unused smaller; not used */
           unused_smaller:
           for(j=0; j<blk->len && pl->tag[j]==0;j++);
           for(k=blk->lstart;k<j;k++) {
              pl->tag[k]=pl->ind2;
              r=mt_this(blockbuf+blk->sublock+k,start,level);
              cleartag(pl);
              if(r) break;
           }
           goto end;
       }
       case -5: {    /* repeat */
           re=pl->ind2-1;
           if(pl->ind2<2 || pl->string >= start) goto end;
           pl->string=start;
           r=mt_next(blk,start,level);
           if(r) goto end;
           pl->ind2=re;
           i=blk->lists[pl->ind1][pl->ind2 - 1];
           goto ppstart;
       }
       case -6: {
           r=mt_next(blk,start,level);
           if(r) goto end;
           goto any;
       }
       case -7: {
           r=mt_next(blk,start,level);
           if(r) goto end;
           goto unused;
       }
       case -8: {
           r=mt_next(blk,start,level);
           if(r) goto end;
           goto unused_bigger;
       }
       case -9: {
           r=mt_next(blk,start,level);
           if(r) goto end;
           goto unused_smaller;
       }
       case -10: {   /* unused. */
           goto end;
       }
       case -11: {   /* unused. */
           goto end;
       }
       case -12: {   /* insertion */
           if(pl->tag[0]==0) {
              pl->tag[0]=pl->ind2;
              r=mt_this(blockbuf+blk->sublock,start,level);
              cleartag(pl);
              if(r) goto end;
           }
           r=_permpick1(blk,start,level+1);
           goto end;
       }
       case -13: {   /* insertion end */
           if(pl->tag[0]) r=mt_next(blk,start,level+1);
           else r=0;
           goto end;
       }
    }
end:
    if(r==0) pl->ind2--;
    for(i=blk->pool+1; i<nextpool;i++) if(poolbuf[i].dirty) poolbuf[i].dirty--;
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cleartag ( struct poolstruct pl)

Definition at line 61 of file match.c.

{
    int i, len, level;
    listtype *tag;
    len=pl->len; tag=pl->tag; level=pl->ind2;
    if(level==0) {
       memset(tag,0,pl->len*sizeof(listtype));
    }
    else for(i=0; i<len; i++) {
       if(tag[i]>=level) tag[i]=0;
    }
}

Here is the caller graph for this function:

void getnpool ( int  b)

Definition at line 349 of file match.c.

Here is the call graph for this function:

Here is the caller graph for this function:

struct poolstruct* getpool ( struct block blk) [read]

Definition at line 74 of file match.c.

{
    struct poolstruct *pl;
    
    if(nextpool>=MAX_POOLS) error("pool_overflow");
    pl=poolbuf+nextpool;
    pl->lastpool=blk->pool;
    blk->pool=nextpool; nextpool++;
    pl->block=blk-blockbuf;
    pl->string=NULL;
    pl->ind1=pl->ind2=pl->dirty=pl->len=0;
    return pl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int match ( char *  p)

Definition at line 451 of file match.c.

{
    int i;
    outptr=outbuf; *outptr=0; nextpool=nextnpool=1; nexttag=0;
    currnpool=0;
    for(i=0;i<nextblock;i++) blockbuf[i].pool=blockbuf[i].mpool=0;
    return mt_this(blockbuf,find_word_start(p),0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_dic ( struct block blk,
char *  start,
int  level 
)

Definition at line 142 of file match.c.

{
    int i,t;
    struct entry *et;
    char *p;
    
    i=blk->lind1;
    t=search_dic(entry+dic[i].start,dic[i].len,sizeof(entry[0]),start);
    if(t>=0) {
       et=entry+(dic[i].start+t);
       if(itemchr(et->replace,blk->string)==NULL) return 0;
       p=start+et->olen;
       return mt_next(blk,p,level+1);
    }
    switch(dic[i].unknown_type) {
       case unk_leave: {
           if(memcmp(start,blk->string,blk->len)==0 ||
              (start[blk->len]!=0 && !myisspace(start[blk->len])))
             return 0;
           return mt_next(blk,find_word_start(start+blk->len),level+1);          
       }
       case unk_replace: {
           if(strcmp(dic[i].unknown,blk->string)!=0) return 0;
           return mt_next(blk,start,level+1);
       }
       case unk_delete: return 0;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_m ( struct block blk,
char *  start,
int  level 
)

Definition at line 364 of file match.c.

{
    int i,r,pl,b,e,cp;
    char *bkstart;
    
    if(blk->string>=start) return 0;
    bkstart=blk->string; blk->string=start;
    cp=currnpool;
    getnpool(blk->nextblock);
    b=blk->sublock; pl=blockbuf[b].mpool; blockbuf[b].mpool=nextpool+1;
    e=blockbuf[b].mend;
    if(pl>0) for(i=pl-1;i<nextpool;i++) {
       if(poolbuf[i].block>=b && poolbuf[i].block<e) poolbuf[i].dirty++;
    }
    if(debug>=3) fprintf(stderr, "Entering macro %d npool=%d, next=%d.\n",
                      b, currnpool, npool[currnpool].nextblock);
    r = mt_this(blockbuf+b,start,level+1);
    if(pl>0) for(i=pl-1;i<nextpool;i++) {
       if(poolbuf[i].block>=b && poolbuf[i].block<e && poolbuf[i].dirty>0) poolbuf[i].dirty--;
    }
    blockbuf[b].mpool=pl;
    putnpool(); currnpool=cp; blk->string=bkstart;
    if(debug>=3) fprintf(stderr, "macro %d returns %d, npool=%d, next=%d.\n",
                      b, r, nextnpool, npool[nextnpool].nextblock);
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_neg ( struct block blk,
char *  start,
int  level 
)

Definition at line 325 of file match.c.

{
    int r, newpool;
    struct poolstruct *pl;
    
    newpool=0;
    pl=poolbuf+blk->pool;
    if(pl==poolbuf || pl->dirty>0) {
       pl=getpool(blk); newpool=1;
    }
    if(pl->ind2) return 1;
    pl->ind2=1;
    r=mt_this(blockbuf+blk->sublock,start,level+1);
    pl->ind2=0;      if(newpool) putpool(pl);
    if(r==0) return mt_next(blk,start,level+1);
    if(r==1) return 0;
    else return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_next ( struct block blk,
char *  start,
int  level 
)

Definition at line 106 of file match.c.

{
    int r,cp,next;
    next=blk->nextblock;
    cp=currnpool;
    if(next==-2) {
       do {
           next=npool[currnpool].nextblock; currnpool=npool[currnpool].last;
       }
       while (next==-2 && currnpool>0);
       if(next==-2) error("internal_error npool disorder");
       if(debug>=3) fprintf(stderr,"Calling macro %d: next=%d.\n",
                          blk-blockbuf,next);
    }
    if(next<0) {
       if(*start) return 0; else return 1;
    }
    r=mt_this(blockbuf+next,start,level);
    currnpool=cp;
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_nomatch ( struct block blk,
char *  start,
int  level 
)

Definition at line 344 of file match.c.

{
    return 0;
}

Here is the caller graph for this function:

int mt_out ( struct block blk,
char *  start,
int  level 
)

Definition at line 391 of file match.c.

{
    int r, l, newpool;
    char buf[MAX_LINELEN+1];
    struct poolstruct *pl;
    
    newpool=0;
    pl=poolbuf+blk->pool;
    if(pl==poolbuf || pl->dirty>0) {
       pl=getpool(blk); newpool=1;
    }
    if(pl->ind2) {
       pl->string=start;
       return mt_next(blk,start,level+1);
    }
    pl->ind2++;
    r=mt_this(blockbuf+blk->sublock,start,level+1);
    pl->ind2=0;      if(newpool) putpool(pl);
    if(r) {
       l=pl->string - start;
       if(l>=0 && l<MAX_LINELEN) {
           memmove(buf,start,l); buf[l]=0;
           outval(blk->string, buf);
       }
    }
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_permpick ( struct block blk,
char *  start,
int  level 
)

Definition at line 295 of file match.c.

{
    int r, n, newpool;
    struct poolstruct *pl;
    
    newpool=n=0;
    pl=poolbuf+blk->pool;
    if(pl==poolbuf || pl->dirty>0) {
       pl=getpool(blk); newpool=1;
       n=pl->len=blk->len;
       if(nexttag + n >= MAX_BLOCKS) error("tag_overflow");
       pl->tag=tagbuf+nexttag; nexttag+=n;
    }
    if(pl->ind1==0 && pl->ind2==0) {
       for(r=0;pl->ind1<blk->lcnt;pl->ind1++,pl->ind2=0){
           r=_permpick1(blk,start,level);
           if(r) break;
       }
       pl->ind1=pl->ind2=0;
       if(newpool) {
           putpool(pl); nexttag-=n;
       }
       return r;
    }
    if(pl->ind2>=blk->listlen[pl->ind1]) {
       return mt_next(blk,start,level);
    }
    return _permpick1(blk,start,level);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_string ( struct block blk,
char *  start,
int  level 
)

Definition at line 128 of file match.c.

{
    char *p;
    int r;
    if(blk->len>0) {
       if(memcmp(blk->string,start,blk->len)!=0) return 0;
       p=start+blk->len; if(*p && !myisspace(*p)) return 0;
    }
    else p=start;
    r = mt_next(blk,p,level+1);
    if(debug) fprintf(stderr,"Strcmp %d %.20s. <-> %.20s.\n",r, blk->string,start);
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_this ( struct block blk,
char *  start,
int  level 
)

Definition at line 95 of file match.c.

{
    int r;
    if(level > MAX_LEVELS) error("level_overflow %.20s",start);
    start=find_word_start(start);
    if(debug>=2) fprintf(stderr,"lvl=%d. Checking against block %d for %.10s.\n",level,blk-blockbuf,start);
    r = blk->fn(blk,start,level);
    if(debug) fprintf(stderr,"lvl=%d. Tested %d block %d for %.10s.\n",level,r,blk-blockbuf,start);
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_w ( struct block blk,
char *  start,
int  level 
)

Definition at line 419 of file match.c.

{
    char *p1, *p2;
    char buf[MAX_NAMELEN+1];
    int l;
    p1=find_word_start(start); p2=find_word_end(p1); l=p2-p1;
    if(*p2) p2++;
    if(l>=MAX_NAMELEN) return 0;
    memmove(buf,p1,l); buf[l]=0;
    if(wordchr(wbuf,buf)==NULL) return 0;
    return mt_next(blk,p2,level+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mt_wild ( struct block blk,
char *  start,
int  level 
)

Definition at line 432 of file match.c.

{
    char *p;
    int i,l,r;

    l=blk->lstart;
    for(i=0,p=find_word_start(start);i<l;i++,p=find_word_start(find_word_end(p))) {
       if(*p==0) return 0;
    }
    l=blk->len;
    if(l==0) return mt_next(blk,p,level+1);
    for(i=0; i<=l && *p; i++, p=find_word_start(find_word_end(p))) {
       r=mt_next(blk,p,level+1);
       if(r) return r;
    }
    if(i<=l) return mt_next(blk,p,level+1);
    else return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void outval ( char *  tit,
char *  val 
)

Definition at line 29 of file match.c.

{
    char *p, l, r;
    val=find_word_start(val);
    strip_trailing_spaces(val);
    if(*val==0) {
       snprintf(outptr,sizeof(outbuf)-(outptr-outbuf)-1,"%s=_EMPTY_ ",tit);
       goto outend;
    }
    if(*find_word_end(val)==0) {
       snprintf(outptr,sizeof(outbuf)-(outptr-outbuf)-1,"%s=%s ",tit,val);
    }
    else {
       l='('; r=')';
       if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
           l='['; r=']';
           if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
              l='{'; r='}';
              if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
                  l='"'; r='"';
                  if(strchr(val,l)!=NULL || strchr(val,r)!=NULL) {
                     l=r=' ';
                     for(p=val;*p;p++) if(*p==' ') *p='_';
                  }
              }
           }
       }
       snprintf(outptr,sizeof(outbuf)-(outptr-outbuf)-1,"%s=%c%s%c ",tit,l,val,r);
    }
    outend: outptr+=strlen(outptr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void putnpool ( void  )

Definition at line 358 of file match.c.

{
    if(nextnpool<=0) error("npool_underflow");
    nextnpool--;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void putpool ( struct poolstruct pl)

Definition at line 88 of file match.c.

{
    nextpool--;
    if(nextpool!=pl-poolbuf) error("internal_error pool leaking");
    blockbuf[pl->block].pool=pl->lastpool;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int currnpool

Definition at line 27 of file match.c.

int nextnpool

Definition at line 27 of file match.c.