From: Adam Dickmeiss Date: Thu, 4 May 2006 18:58:54 +0000 (+0000) Subject: Reformat with a little more spacing (no code changes) X-Git-Tag: YAZ.2.1.20~84 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=2af6f28e5d261fa873d96611a10c56fc76681685;p=yaz-moved-to-github.git Reformat with a little more spacing (no code changes) --- diff --git a/src/nfa.c b/src/nfa.c index ef6f3f4..0eee5e8 100644 --- a/src/nfa.c +++ b/src/nfa.c @@ -1,7 +1,12 @@ /* Copyright (C) 2006, Index Data ApS * See the file LICENSE for details. * - * $Id: nfa.c,v 1.4 2006-05-03 13:47:35 heikki Exp $ + * $Id: nfa.c,v 1.5 2006-05-04 18:58:54 adam Exp $ + */ + +/** + * \file nfa.c + * \brief NFA for character set normalizing * * This is a simple NFA-based system for character set normalizing * in yaz and zebra. Unlike standard NFA's, this operates on ranges of @@ -78,15 +83,15 @@ struct yaz_nfa_transition { yaz_nfa *yaz_nfa_init() { NMEM my_nmem = nmem_create(); - yaz_nfa *n=nmem_malloc(my_nmem, sizeof(yaz_nfa)); - n->nmem=my_nmem; - n->nstates=0; - n->laststate=0; - n->firststate=0; - n->nbackrefs=0; - n->curr_backrefs=0; - n->best_backrefs=0; - n->lastmatch= YAZ_NFA_NOMATCH; + yaz_nfa *n = nmem_malloc(my_nmem, sizeof(yaz_nfa)); + n->nmem = my_nmem; + n->nstates = 0; + n->laststate = 0; + n->firststate = 0; + n->nbackrefs = 0; + n->curr_backrefs = 0; + n->best_backrefs = 0; + n->lastmatch = YAZ_NFA_NOMATCH; return n; } @@ -100,28 +105,28 @@ void yaz_nfa_destroy(yaz_nfa *n) { * * * * * */ yaz_nfa_state *yaz_nfa_add_state(yaz_nfa *n) { - yaz_nfa_state *s = nmem_malloc(n->nmem,sizeof(yaz_nfa_state)); + yaz_nfa_state *s = nmem_malloc(n->nmem, sizeof(yaz_nfa_state)); s->num = (n->nstates)++; - s->result=0; - s->lasttrans=0; - s->backref_start=0; - s->backref_end=0; + s->result = 0; + s->lasttrans = 0; + s->backref_start = 0; + s->backref_end = 0; if (n->laststate) { - s->next=n->laststate->next; - n->laststate->next=s; - n->laststate=s; + s->next = n->laststate->next; + n->laststate->next = s; + n->laststate = s; } else { /* first state */ - n->laststate=s; - n->firststate=s; - s->next=s; + n->laststate = s; + n->firststate = s; + s->next = s; } return s; } -int yaz_nfa_set_result(yaz_nfa *n, yaz_nfa_state *s,void *result) { +int yaz_nfa_set_result(yaz_nfa *n, yaz_nfa_state *s, void *result) { if ((s->result)&&result) return 1; - s->result=result; + s->result = result; return 0; } @@ -137,11 +142,11 @@ int yaz_nfa_set_backref_point(yaz_nfa *n, yaz_nfa_state *s, if (is_start) { if (s->backref_start) return 1; - s->backref_start=backref_number; + s->backref_start = backref_number; if (n->nbackrefs<=backref_number) { - n->nbackrefs=backref_number+1; - n->curr_backrefs=0; - n->best_backrefs=0; + n->nbackrefs = backref_number+1; + n->curr_backrefs = 0; + n->best_backrefs = 0; /* clear them just in case we have already matched on */ /* with this nfa, and created a too small backref table */ /* we will reallocate when matching. */ @@ -151,7 +156,7 @@ int yaz_nfa_set_backref_point(yaz_nfa *n, yaz_nfa_state *s, return 1; if (n->nbackrefsbackref_end=backref_number; + s->backref_end = backref_number; } return 0; /* ok */ } @@ -171,25 +176,25 @@ void yaz_nfa_add_transition(yaz_nfa *n, yaz_nfa_state *to_state, yaz_nfa_char range_start, yaz_nfa_char range_end) { - yaz_nfa_transition *t=nmem_malloc(n->nmem,sizeof(yaz_nfa_transition)); - t->range_start=range_start; - t->range_end=range_end; - t->to_state=to_state; + yaz_nfa_transition *t = nmem_malloc(n->nmem, sizeof(yaz_nfa_transition)); + t->range_start = range_start; + t->range_end = range_end; + t->to_state = to_state; if (from_state->lasttrans) { t->next= from_state->lasttrans->next; - from_state->lasttrans->next=t; - from_state->lasttrans=t; + from_state->lasttrans->next = t; + from_state->lasttrans = t; } else { /* first trans */ - from_state->lasttrans=t; - t->next=t; + from_state->lasttrans = t; + t->next = t; } } void yaz_nfa_add_empty_transition( yaz_nfa *n, yaz_nfa_state *from_state, yaz_nfa_state *to_state) { - yaz_nfa_add_transition(n,from_state,to_state, - EMPTY_START,EMPTY_END); + yaz_nfa_add_transition(n, from_state, to_state, + EMPTY_START, EMPTY_END); } /* * * * * * * * @@ -202,11 +207,11 @@ static yaz_nfa_state *find_single_trans( yaz_nfa_state *s, yaz_nfa_char range_start, yaz_nfa_char range_end) { - yaz_nfa_transition *t=s->lasttrans; + yaz_nfa_transition *t = s->lasttrans; if (!t) return 0; do { - t=t->next; + t = t->next; if ( ( t->range_start == range_start ) && ( t->range_end == range_end) ) return t->to_state; } while (t != s->lasttrans ); @@ -220,8 +225,8 @@ yaz_nfa_state *yaz_nfa_add_range(yaz_nfa *n, yaz_nfa_char range_end) { yaz_nfa_state *nextstate; if (!s) /* default to top-level of the nfa */ - s=n->firststate; - nextstate=find_single_trans(s,range_start,range_end); + s = n->firststate; + nextstate = find_single_trans(s, range_start, range_end); if (!nextstate) { nextstate = yaz_nfa_add_state(n); yaz_nfa_add_transition(n, s, nextstate, range_start, range_end); @@ -234,8 +239,8 @@ yaz_nfa_state *yaz_nfa_add_sequence(yaz_nfa *n, yaz_nfa_char *seq ){ yaz_nfa_state *nextstate; if (!s) /* default to top-level of the nfa */ - s=n->firststate; - nextstate=find_single_trans(s,*seq,*seq); + s = n->firststate; + nextstate = find_single_trans(s, *seq, *seq); if (nextstate) { seq++; if (!*seq) /* whole sequence matched */ @@ -244,7 +249,7 @@ yaz_nfa_state *yaz_nfa_add_sequence(yaz_nfa *n, return yaz_nfa_add_sequence(n, nextstate, seq); } else { /* no next state, build the rest */ while (*seq) { - s=yaz_nfa_add_range(n,s, *seq, *seq); + s = yaz_nfa_add_range(n, s, *seq, *seq); seq++; } return s; @@ -276,34 +281,34 @@ static void match_state( yaz_nfa_char *inchar, size_t incharsleft, struct matcher *m ) { - yaz_nfa_transition *t=s->lasttrans; + yaz_nfa_transition *t = s->lasttrans; if (s->backref_start) - m->n->curr_backrefs[s->backref_start].start=inchar; + m->n->curr_backrefs[s->backref_start].start = inchar; if (s->backref_end) - m->n->curr_backrefs[s->backref_end].end=inchar; + m->n->curr_backrefs[s->backref_end].end = inchar; if (t) { if (incharsleft) { do { - t=t->next; + t = t->next; if ( (( t->range_start <= *inchar ) && ( t->range_end >= *inchar )) ){ - m->empties=0; + m->empties = 0; if (t->range_start!=t->range_end){ /* backref 0 is special: the last range operation */ - m->n->curr_backrefs[0].start=inchar; - m->n->curr_backrefs[0].end=inchar; + m->n->curr_backrefs[0].start = inchar; + m->n->curr_backrefs[0].end = inchar; } - match_state(t->to_state, inchar+1,incharsleft-1,m); + match_state(t->to_state, inchar+1, incharsleft-1, m); /* yes, descent to all matching nodes, even if overrun, */ /* since we can find a better one later */ } else if (( t->range_start==EMPTY_START) && (t->range_end==EMPTY_END)) { if ( m->empties++ > LOOP_LIMIT ) m->errorcode= YAZ_NFA_LOOP; else - match_state(t->to_state, inchar,incharsleft,m); + match_state(t->to_state, inchar, incharsleft, m); } } while (t != s->lasttrans ); } else { - m->errorcode=YAZ_NFA_OVERRUN; + m->errorcode = YAZ_NFA_OVERRUN; } } if (s->result) { /* terminal node */ @@ -311,21 +316,21 @@ static void match_state( ((m->longest == inchar)&&(m->bestnodenum)) ){ /* or as long, but with lower node number. Still better */ int i; - m->longest=inchar; - m->bestnode=s->num; - m->result=s->result; + m->longest = inchar; + m->bestnode = s->num; + m->result = s->result; if (m->n->curr_backrefs) - for (i=0; in->nbackrefs;i++) { + for (i = 0; in->nbackrefs; i++) { m->n->best_backrefs[i]=m->n->curr_backrefs[i]; } } } if (s->backref_start) - m->n->curr_backrefs[s->backref_start].start=0; + m->n->curr_backrefs[s->backref_start].start = 0; if (s->backref_end) - m->n->curr_backrefs[s->backref_end].end=0; - m->n->curr_backrefs[0].start=0; - m->n->curr_backrefs[0].end=0; + m->n->curr_backrefs[s->backref_end].end = 0; + m->n->curr_backrefs[0].start = 0; + m->n->curr_backrefs[0].end = 0; } /* match_state */ int yaz_nfa_match(yaz_nfa *n, @@ -336,37 +341,37 @@ int yaz_nfa_match(yaz_nfa *n, int sz; int i; if (!n->firststate) { - n->lastmatch=YAZ_NFA_NOMATCH; + n->lastmatch = YAZ_NFA_NOMATCH; return n->lastmatch; } - m.n=n; + m.n = n; m.longest=*inbuff; - m.bestnode=n->nstates; - m.result=0; - m.errorcode=0; - sz=sizeof( struct yaz_nfa_backref_info) * n->nbackrefs; + m.bestnode = n->nstates; + m.result = 0; + m.errorcode = 0; + sz = sizeof( struct yaz_nfa_backref_info) * n->nbackrefs; if (!n->curr_backrefs) { - n->curr_backrefs=nmem_malloc( n->nmem, sz); - n->best_backrefs=nmem_malloc( n->nmem, sz); + n->curr_backrefs = nmem_malloc( n->nmem, sz); + n->best_backrefs = nmem_malloc( n->nmem, sz); } - for (i=0;inbackrefs;i++) { - n->curr_backrefs[i].start=0; - n->curr_backrefs[i].end=0; - n->best_backrefs[i].start=0; - n->best_backrefs[i].end=0; + for (i = 0; inbackrefs; i++) { + n->curr_backrefs[i].start = 0; + n->curr_backrefs[i].end = 0; + n->best_backrefs[i].start = 0; + n->best_backrefs[i].end = 0; } match_state(n->firststate, *inbuff, incharsleft, &m); if (m.result) { - *result=m.result; - *inbuff=m.longest; + *result = m.result; + *inbuff = m.longest; if (m.errorcode) - n->lastmatch=m.errorcode; + n->lastmatch = m.errorcode; else n->lastmatch= YAZ_NFA_SUCCESS; return n->lastmatch; } - n->lastmatch=YAZ_NFA_NOMATCH; + n->lastmatch = YAZ_NFA_NOMATCH; return n->lastmatch; } @@ -382,8 +387,8 @@ int yaz_nfa_get_backref( yaz_nfa *n, if (n->lastmatch== YAZ_NFA_NOMATCH) return 1; /* accept other errors, they return partial matches*/ - *start=n->best_backrefs[backref_no].start; - *end=n->best_backrefs[backref_no].end; + *start = n->best_backrefs[backref_no].start; + *end = n->best_backrefs[backref_no].end; return 0; } @@ -412,17 +417,17 @@ static void dump_trans(FILE *F, yaz_nfa_transition *t ) { char c1; char c2; char *e; - c1=t->range_start; - c2=t->range_end; - e=""; + c1 = t->range_start; + c2 = t->range_end; + e = ""; if ( (t->range_start <= ' ') || (t->range_start>'z')) - c1='?'; + c1 = '?'; if ( (t->range_end <= ' ') || (t->range_end>'z')) - c2='?'; + c2 = '?'; if ((t->range_start==EMPTY_START) && (t->range_end==EMPTY_END)) { - e="(empty)"; + e = "(empty)"; } - fprintf(F," -> [%d] %s '%c' %x - '%c' %x \n", + fprintf(F, " -> [%d] %s '%c' %x - '%c' %x \n", t->to_state->num, e, c1, t->range_start, c2, t->range_end ); @@ -431,30 +436,30 @@ static void dump_trans(FILE *F, yaz_nfa_transition *t ) { static void dump_state(FILE *F, yaz_nfa_state *s, char *(*strfunc)(void *) ) { yaz_nfa_transition *t; - char *resultstring=""; + char *resultstring = ""; if (s->result) { if (strfunc) { - resultstring=(*strfunc)(s->result); + resultstring = (*strfunc)(s->result); } else - resultstring=s->result; + resultstring = s->result; } - fprintf(F," state [%d] %s %s", - s->num, s->result?"(FINAL)":"",resultstring ); + fprintf(F, " state [%d] %s %s", + s->num, s->result?"(FINAL)":"", resultstring ); if (s->backref_start) { - fprintf(F," start-%d",s->backref_start); + fprintf(F, " start-%d", s->backref_start); } if (s->backref_end) { - fprintf(F," end-%d",s->backref_end); + fprintf(F, " end-%d", s->backref_end); } - fprintf(F,"\n"); - t=s->lasttrans; + fprintf(F, "\n"); + t = s->lasttrans; if (!t) { - fprintf(F," (no transitions)\n"); + fprintf(F, " (no transitions)\n"); } else { do { - t=t->next; - dump_trans(F,t); + t = t->next; + dump_trans(F, t); } while (t != s->lasttrans); } @@ -464,20 +469,19 @@ void yaz_nfa_dump(FILE *F, yaz_nfa *n, char *(*strfunc)(void *) ) { yaz_nfa_state *s; if (!F) /* lazy programmers can just pass 0 for F */ - F=stdout; - fprintf(F,"The NFA has %d states and %d backrefs\n", + F = stdout; + fprintf(F, "The NFA has %d states and %d backrefs\n", n->nstates, n->nbackrefs); - s=n->laststate; + s = n->laststate; if (s) { do { - s=s->next; - dump_state(F,s, strfunc); + s = s->next; + dump_state(F, s, strfunc); } while (s != n->laststate); } } - /* * Local variables: * c-basic-offset: 4 diff --git a/test/nfatest1.c b/test/nfatest1.c index c37fc4f..2b730eb 100644 --- a/test/nfatest1.c +++ b/test/nfatest1.c @@ -1,7 +1,7 @@ /* Copyright (C) 2006, Index Data ApS * See the file LICENSE for details. * - * $Id: nfatest1.c,v 1.2 2006-05-03 13:47:35 heikki Exp $ + * $Id: nfatest1.c,v 1.3 2006-05-04 18:59:13 adam Exp $ * */ @@ -16,29 +16,29 @@ char *printfunc(void *result) { static char buf[200]; - sprintf(buf,"\"%s\"", (char*) result); + sprintf(buf, "\"%s\"", (char*) result); return buf; } void test_match(yaz_nfa *n, yaz_nfa_char *buf, int buflen, int expcode, char *expstr) { - yaz_nfa_char *c=buf; - yaz_nfa_char *cp1,*cp2; - void *resptr=0; - int i,bi; - i=yaz_nfa_match(n,&c,buflen,&resptr); + yaz_nfa_char *c = buf; + yaz_nfa_char *cp1, *cp2; + void *resptr = 0; + int i, bi; + i = yaz_nfa_match(n,&c, buflen,&resptr); #if VERBOSE printf("\n'%s' returned %d. Moved c by %d, and resulted in '%s'\n", expstr, i, (c-buf),(char*)resptr); #endif - YAZ_CHECK_EQ(i,expcode); + YAZ_CHECK_EQ(i, expcode); if (i!=1) - YAZ_CHECK_EQ(strcmp(expstr,(char*)resptr),0); - i=0; - bi=0; + YAZ_CHECK_EQ(strcmp(expstr,(char*)resptr), 0); + i = 0; + bi = 0; while(bi!=2){ - bi=yaz_nfa_get_backref(n,i,&cp1,&cp2); + bi = yaz_nfa_get_backref(n, i,&cp1,&cp2); if (bi==0 && ( cp1 || cp2 ) ) { #if VERBOSE printf(" got backref %d of %d chars (%p to %p): '", @@ -55,125 +55,125 @@ void test_match(yaz_nfa *n, void construction_test() { yaz_nfa* n= yaz_nfa_init(); yaz_nfa_char *cp, *cp1, *cp2; - yaz_nfa_state *s,*s0,*s1,*s2,*s3,*s4,*s5; + yaz_nfa_state *s, *s0, *s1, *s2, *s3, *s4, *s5; int i; - yaz_nfa_char seq1[]={'p','r','e','f','i','x',0}; - yaz_nfa_char seq2[]={'p','r','e','l','i','m',0}; - yaz_nfa_char tst1[]={'c',0}; - yaz_nfa_char tst2[]={'c','k',0}; - yaz_nfa_char tst3[]={'c','x',0}; - yaz_nfa_char tst4[]={'z','k',0}; - yaz_nfa_char tst5[]={'y','k','l','k','k','l','k','d',0}; - yaz_nfa_char tst6[]={'x','z','k','a','b',0}; + yaz_nfa_char seq1[]={'p', 'r', 'e', 'f', 'i', 'x', 0}; + yaz_nfa_char seq2[]={'p', 'r', 'e', 'l', 'i', 'm', 0}; + yaz_nfa_char tst1[]={'c', 0}; + yaz_nfa_char tst2[]={'c', 'k', 0}; + yaz_nfa_char tst3[]={'c', 'x', 0}; + yaz_nfa_char tst4[]={'z', 'k', 0}; + yaz_nfa_char tst5[]={'y', 'k', 'l', 'k', 'k', 'l', 'k', 'd', 0}; + yaz_nfa_char tst6[]={'x', 'z', 'k', 'a', 'b', 0}; void *p; YAZ_CHECK(n); - s=yaz_nfa_get_first(n); + s = yaz_nfa_get_first(n); YAZ_CHECK(!s); - s0=yaz_nfa_add_state(n); + s0 = yaz_nfa_add_state(n); - s=yaz_nfa_get_first(n); + s = yaz_nfa_get_first(n); YAZ_CHECK(s); - s=yaz_nfa_get_next(n,s); + s = yaz_nfa_get_next(n, s); YAZ_CHECK(!s); - s1=yaz_nfa_add_state(n); - i=yaz_nfa_set_result(n,s1,"first"); - YAZ_CHECK_EQ(i,0); + s1 = yaz_nfa_add_state(n); + i = yaz_nfa_set_result(n, s1, "first"); + YAZ_CHECK_EQ(i, 0); - i=yaz_nfa_set_result(n,s1,"DUPLICATE"); - YAZ_CHECK_EQ(i,1); + i = yaz_nfa_set_result(n, s1, "DUPLICATE"); + YAZ_CHECK_EQ(i, 1); - p=yaz_nfa_get_result(n,s1); + p = yaz_nfa_get_result(n, s1); YAZ_CHECK(p); - YAZ_CHECK( strcmp((char*)p,"first")==0 ); + YAZ_CHECK( strcmp((char*)p, "first")==0 ); - i=yaz_nfa_set_result(n,s1,0); - YAZ_CHECK_EQ(i,0); - p=yaz_nfa_get_result(n,s1); + i = yaz_nfa_set_result(n, s1, 0); + YAZ_CHECK_EQ(i, 0); + p = yaz_nfa_get_result(n, s1); YAZ_CHECK(!p); - i=yaz_nfa_set_result(n,s1,"first"); - YAZ_CHECK_EQ(i,0); + i = yaz_nfa_set_result(n, s1, "first"); + YAZ_CHECK_EQ(i, 0); - s2=yaz_nfa_add_state(n); - s3=yaz_nfa_add_state(n); - yaz_nfa_set_result(n,s3,"a-k,x-z"); + s2 = yaz_nfa_add_state(n); + s3 = yaz_nfa_add_state(n); + yaz_nfa_set_result(n, s3, "a-k, x-z"); - s=yaz_nfa_get_first(n); + s = yaz_nfa_get_first(n); YAZ_CHECK(s); - s=yaz_nfa_get_next(n,s); + s = yaz_nfa_get_next(n, s); YAZ_CHECK(s); - yaz_nfa_add_transition(n,s0,s1,'a','k'); - yaz_nfa_add_transition(n,s1,s1,'k','k'); - yaz_nfa_add_transition(n,s0,s2,'p','p'); - yaz_nfa_add_transition(n,s1,s3,'x','z'); + yaz_nfa_add_transition(n, s0, s1, 'a', 'k'); + yaz_nfa_add_transition(n, s1, s1, 'k', 'k'); + yaz_nfa_add_transition(n, s0, s2, 'p', 'p'); + yaz_nfa_add_transition(n, s1, s3, 'x', 'z'); - s=yaz_nfa_add_range(n, 0, 'k','s' ); - yaz_nfa_set_result(n,s,"K-S"); + s = yaz_nfa_add_range(n, 0, 'k', 's' ); + yaz_nfa_set_result(n, s, "K-S"); - s4=yaz_nfa_add_range(n, s2, 'l','r' ); - s5=yaz_nfa_add_range(n, s2, 'l','r' ); + s4 = yaz_nfa_add_range(n, s2, 'l', 'r' ); + s5 = yaz_nfa_add_range(n, s2, 'l', 'r' ); YAZ_CHECK((s4==s5)); - s=yaz_nfa_add_range(n, 0, 'c','c' ); - - s=yaz_nfa_add_range(n, 0, 'z','z' ); - yaz_nfa_add_empty_transition(n,s,s); - yaz_nfa_set_result(n,s,"loop"); - - s=yaz_nfa_add_range(n, 0, 'y','y' ); - yaz_nfa_set_backref_point(n,s,1,1); - s1=yaz_nfa_add_state(n); - yaz_nfa_add_empty_transition(n,s,s1); - s=s1; - yaz_nfa_add_transition(n,s,s,'k','l'); - s=yaz_nfa_add_range(n, s, 'd','d' ); - yaz_nfa_set_result(n,s,"y k+ d"); - yaz_nfa_set_backref_point(n,s,1,0); - - s=yaz_nfa_add_sequence(n, 0, seq1 ); - yaz_nfa_set_result(n,s,"PREFIX"); - s=yaz_nfa_add_sequence(n, 0, seq2 ); - yaz_nfa_set_result(n,s,"PRELIM"); - - s=yaz_nfa_add_range(n, 0, 'x','x' ); - yaz_nfa_set_backref_point(n,s,2,1); - s1=yaz_nfa_add_sequence(n,s,tst4); - yaz_nfa_set_backref_point(n,s1,2,0); - yaz_nfa_set_result(n,s1,"xzk"); + s = yaz_nfa_add_range(n, 0, 'c', 'c' ); + + s = yaz_nfa_add_range(n, 0, 'z', 'z' ); + yaz_nfa_add_empty_transition(n, s, s); + yaz_nfa_set_result(n, s, "loop"); + + s = yaz_nfa_add_range(n, 0, 'y', 'y' ); + yaz_nfa_set_backref_point(n, s, 1, 1); + s1 = yaz_nfa_add_state(n); + yaz_nfa_add_empty_transition(n, s, s1); + s = s1; + yaz_nfa_add_transition(n, s, s, 'k', 'l'); + s = yaz_nfa_add_range(n, s, 'd', 'd' ); + yaz_nfa_set_result(n, s, "y k+ d"); + yaz_nfa_set_backref_point(n, s, 1, 0); + + s = yaz_nfa_add_sequence(n, 0, seq1 ); + yaz_nfa_set_result(n, s, "PREFIX"); + s = yaz_nfa_add_sequence(n, 0, seq2 ); + yaz_nfa_set_result(n, s, "PRELIM"); + + s = yaz_nfa_add_range(n, 0, 'x', 'x' ); + yaz_nfa_set_backref_point(n, s, 2, 1); + s1 = yaz_nfa_add_sequence(n, s, tst4); + yaz_nfa_set_backref_point(n, s1, 2, 0); + yaz_nfa_set_result(n, s1, "xzk"); /* check return codes before doing any matches */ - i=yaz_nfa_get_backref(n, 0, &cp1, &cp2 ); - YAZ_CHECK_EQ(i,1); - i=yaz_nfa_get_backref(n, 3, &cp1, &cp2 ); - YAZ_CHECK_EQ(i,2); - i=yaz_nfa_get_backref(n, 1, &cp1, &cp2 ); - YAZ_CHECK_EQ(i,1); + i = yaz_nfa_get_backref(n, 0, &cp1, &cp2 ); + YAZ_CHECK_EQ(i, 1); + i = yaz_nfa_get_backref(n, 3, &cp1, &cp2 ); + YAZ_CHECK_EQ(i, 2); + i = yaz_nfa_get_backref(n, 1, &cp1, &cp2 ); + YAZ_CHECK_EQ(i, 1); #if VERBOSE - yaz_nfa_dump(0,n, printfunc); + yaz_nfa_dump(0, n, printfunc); #endif - test_match(n,seq2,3,YAZ_NFA_OVERRUN,"K-S"); - test_match(n,seq2,6,YAZ_NFA_SUCCESS,"PRELIM"); - test_match(n,tst1,3,YAZ_NFA_SUCCESS,"first"); - test_match(n,tst2,3,YAZ_NFA_SUCCESS,"first"); - test_match(n,tst3,3,YAZ_NFA_SUCCESS,"a-k,x-z"); - test_match(n,tst4,9,YAZ_NFA_LOOP,"loop"); - test_match(n,tst5,9,YAZ_NFA_SUCCESS,"y k+ d"); - - cp=tst6; - i=yaz_nfa_match(n,&cp,8,&p); - YAZ_CHECK_EQ(i,YAZ_NFA_SUCCESS); - i=yaz_nfa_get_backref(n, 2, &cp1, &cp2 ); - YAZ_CHECK_EQ(i,0); + test_match(n, seq2, 3, YAZ_NFA_OVERRUN, "K-S"); + test_match(n, seq2, 6, YAZ_NFA_SUCCESS, "PRELIM"); + test_match(n, tst1, 3, YAZ_NFA_SUCCESS, "first"); + test_match(n, tst2, 3, YAZ_NFA_SUCCESS, "first"); + test_match(n, tst3, 3, YAZ_NFA_SUCCESS, "a-k, x-z"); + test_match(n, tst4, 9, YAZ_NFA_LOOP, "loop"); + test_match(n, tst5, 9, YAZ_NFA_SUCCESS, "y k+ d"); + + cp = tst6; + i = yaz_nfa_match(n,&cp, 8,&p); + YAZ_CHECK_EQ(i, YAZ_NFA_SUCCESS); + i = yaz_nfa_get_backref(n, 2, &cp1, &cp2 ); + YAZ_CHECK_EQ(i, 0); #if VERBOSE printf("backref from %p to %p is %d long\n", - cp1,cp2, cp2-cp1 ); + cp1, cp2, cp2-cp1 ); #endif yaz_nfa_destroy(n); @@ -188,3 +188,11 @@ int main(int argc, char **argv) YAZ_CHECK_TERM; } + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */