diff options
| author | Bruce Momjian <bruce@momjian.us> | 2005-11-22 18:17:34 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2005-11-22 18:17:34 +0000 |
| commit | 436a2956d80db29ac1dff640b631620d856b4f70 (patch) | |
| tree | db2252048385dd23a7d7a196e8685cb0a5816f7a /contrib/tsearch2 | |
| parent | e196eedd8a95380fb392c00b9e7ea88a0e46053e (diff) | |
| download | postgresql-436a2956d80db29ac1dff640b631620d856b4f70.tar.gz | |
Re-run pgindent, fixing a problem where comment lines after a blank
comment line where output as too long, and update typedefs for /lib
directory. Also fix case where identifiers were used as variable names
in the backend, but as typedefs in ecpg (favor the backend for
indenting).
Backpatch to 8.1.X.
Diffstat (limited to 'contrib/tsearch2')
| -rw-r--r-- | contrib/tsearch2/query.c | 30 | ||||
| -rw-r--r-- | contrib/tsearch2/query.h | 2 | ||||
| -rw-r--r-- | contrib/tsearch2/query_gist.c | 296 | ||||
| -rw-r--r-- | contrib/tsearch2/query_rewrite.c | 613 | ||||
| -rw-r--r-- | contrib/tsearch2/query_support.c | 157 | ||||
| -rw-r--r-- | contrib/tsearch2/query_util.c | 344 | ||||
| -rw-r--r-- | contrib/tsearch2/query_util.h | 56 | ||||
| -rw-r--r-- | contrib/tsearch2/rank.c | 155 | ||||
| -rw-r--r-- | contrib/tsearch2/snowball/api.h | 2 | ||||
| -rw-r--r-- | contrib/tsearch2/snowball/english_stem.c | 158 | ||||
| -rw-r--r-- | contrib/tsearch2/snowball/english_stem.h | 6 | ||||
| -rw-r--r-- | contrib/tsearch2/snowball/russian_stem.c | 116 | ||||
| -rw-r--r-- | contrib/tsearch2/snowball/russian_stem.h | 6 | ||||
| -rw-r--r-- | contrib/tsearch2/ts_locale.c | 56 | ||||
| -rw-r--r-- | contrib/tsearch2/ts_locale.h | 16 | ||||
| -rw-r--r-- | contrib/tsearch2/wordparser/parser.c | 1187 | ||||
| -rw-r--r-- | contrib/tsearch2/wordparser/parser.h | 105 | ||||
| -rw-r--r-- | contrib/tsearch2/wparser_def.c | 13 |
18 files changed, 1796 insertions, 1522 deletions
diff --git a/contrib/tsearch2/query.c b/contrib/tsearch2/query.c index e312cf6af7..de6d96ed52 100644 --- a/contrib/tsearch2/query.c +++ b/contrib/tsearch2/query.c @@ -178,7 +178,7 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2 state->state = WAITOPERATOR; return VAL; } - else if ( state->state == WAITFIRSTOPERAND ) + else if (state->state == WAITFIRSTOPERAND) return END; else ereport(ERROR, @@ -206,13 +206,13 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2 return ERR; break; case WAITSINGLEOPERAND: - if ( *(state->buf) == '\0' ) + if (*(state->buf) == '\0') return END; *strval = state->buf; - *lenval = strlen( state->buf ); - state->buf += strlen( state->buf ); + *lenval = strlen(state->buf); + state->buf += strlen(state->buf); state->count++; - return VAL; + return VAL; default: return ERR; break; @@ -600,7 +600,7 @@ findoprnd(ITEM * ptr, int4 *pos) * input */ static QUERYTYPE * -queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain) + queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain) { QPRS_STATE state; int4 i; @@ -637,12 +637,13 @@ queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int c /* parse query & make polish notation (postfix, but in reverse order) */ makepol(&state, pushval); pfree(state.valstate.word); - if (!state.num) { + if (!state.num) + { elog(NOTICE, "Query doesn't contain lexem(s)"); - query = (QUERYTYPE*)palloc( HDRSIZEQT ); + query = (QUERYTYPE *) palloc(HDRSIZEQT); query->len = HDRSIZEQT; query->size = 0; - return query; + return query; } /* make finish struct */ @@ -928,9 +929,9 @@ to_tsquery(PG_FUNCTION_ARGS) str = text2char(in); PG_FREE_IF_COPY(in, 1); - query = queryin(str, pushval_morph, PG_GETARG_INT32(0),false); - - if ( query->size == 0 ) + query = queryin(str, pushval_morph, PG_GETARG_INT32(0), false); + + if (query->size == 0) PG_RETURN_POINTER(query); res = clean_fakeval_v2(GETQUERY(query), &len); @@ -984,8 +985,8 @@ plainto_tsquery(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(in, 1); query = queryin(str, pushval_morph, PG_GETARG_INT32(0), true); - - if ( query->size == 0 ) + + if (query->size == 0) PG_RETURN_POINTER(query); res = clean_fakeval_v2(GETQUERY(query), &len); @@ -1023,4 +1024,3 @@ plainto_tsquery_current(PG_FUNCTION_ARGS) Int32GetDatum(get_currcfg()), PG_GETARG_DATUM(0))); } - diff --git a/contrib/tsearch2/query.h b/contrib/tsearch2/query.h index 3a84afc9c0..9eff69cc71 100644 --- a/contrib/tsearch2/query.h +++ b/contrib/tsearch2/query.h @@ -17,7 +17,7 @@ typedef struct ITEM int4 val; /* user-friendly value, must correlate with WordEntry */ uint32 - istrue:1, /* use for ranking in Cover */ + istrue:1, /* use for ranking in Cover */ length:11, distance:20; } ITEM; diff --git a/contrib/tsearch2/query_gist.c b/contrib/tsearch2/query_gist.c index c14ece0112..d87a5d8d01 100644 --- a/contrib/tsearch2/query_gist.c +++ b/contrib/tsearch2/query_gist.c @@ -7,180 +7,201 @@ #include "query.h" typedef uint64 TPQTGist; -#define SIGLEN (sizeof(TPQTGist)*BITS_PER_BYTE) + +#define SIGLEN (sizeof(TPQTGist)*BITS_PER_BYTE) #define GETENTRY(vec,pos) ((TPQTGist *) DatumGetPointer((vec)->vector[(pos)].key)) PG_FUNCTION_INFO_V1(tsq_mcontains); -Datum tsq_mcontains(PG_FUNCTION_ARGS); +Datum tsq_mcontains(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(tsq_mcontained); -Datum tsq_mcontained(PG_FUNCTION_ARGS); +Datum tsq_mcontained(PG_FUNCTION_ARGS); static TPQTGist -makesign(QUERYTYPE* a) { - int i; - ITEM *ptr = GETQUERY(a); +makesign(QUERYTYPE * a) +{ + int i; + ITEM *ptr = GETQUERY(a); TPQTGist sign = 0; - for (i = 0; i < a->size; i++) { - if ( ptr->type == VAL ) + for (i = 0; i < a->size; i++) + { + if (ptr->type == VAL) sign |= 1 << (ptr->val % SIGLEN); ptr++; } - + return sign; } Datum -tsq_mcontains(PG_FUNCTION_ARGS) { +tsq_mcontains(PG_FUNCTION_ARGS) +{ QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); QUERYTYPE *ex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); - TPQTGist sq, se; - int i,j; - ITEM *iq, *ie; - - if ( query->size < ex->size ) { + TPQTGist sq, + se; + int i, + j; + ITEM *iq, + *ie; + + if (query->size < ex->size) + { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); - PG_RETURN_BOOL( false ); + PG_RETURN_BOOL(false); } sq = makesign(query); se = makesign(ex); - if ( (sq&se)!=se ) { + if ((sq & se) != se) + { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); - PG_RETURN_BOOL( false ); - } + PG_RETURN_BOOL(false); + } ie = GETQUERY(ex); - for(i=0;i<ex->size;i++) { + for (i = 0; i < ex->size; i++) + { iq = GETQUERY(query); - if ( ie[i].type != VAL ) + if (ie[i].type != VAL) continue; - for(j=0;j<query->size;j++) - if ( iq[j].type == VAL && ie[i].val == iq[j].val ) { - j = query->size+1; + for (j = 0; j < query->size; j++) + if (iq[j].type == VAL && ie[i].val == iq[j].val) + { + j = query->size + 1; break; } - if ( j == query->size ) { + if (j == query->size) + { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); - PG_RETURN_BOOL( false ); + PG_RETURN_BOOL(false); } - } + } PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); - PG_RETURN_BOOL( true ); + PG_RETURN_BOOL(true); } Datum -tsq_mcontained(PG_FUNCTION_ARGS) { +tsq_mcontained(PG_FUNCTION_ARGS) +{ PG_RETURN_DATUM( - DirectFunctionCall2( - tsq_mcontains, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) + DirectFunctionCall2( + tsq_mcontains, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + ) ); } PG_FUNCTION_INFO_V1(gtsq_in); -Datum gtsq_in(PG_FUNCTION_ARGS); +Datum gtsq_in(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_out); -Datum gtsq_out(PG_FUNCTION_ARGS); +Datum gtsq_out(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_compress); -Datum gtsq_compress(PG_FUNCTION_ARGS); +Datum gtsq_compress(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_decompress); -Datum gtsq_decompress(PG_FUNCTION_ARGS); +Datum gtsq_decompress(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_consistent); -Datum gtsq_consistent(PG_FUNCTION_ARGS); +Datum gtsq_consistent(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_union); -Datum gtsq_union(PG_FUNCTION_ARGS); +Datum gtsq_union(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_same); -Datum gtsq_same(PG_FUNCTION_ARGS); +Datum gtsq_same(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_penalty); -Datum gtsq_penalty(PG_FUNCTION_ARGS); +Datum gtsq_penalty(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(gtsq_picksplit); -Datum gtsq_picksplit(PG_FUNCTION_ARGS); +Datum gtsq_picksplit(PG_FUNCTION_ARGS); Datum -gtsq_in(PG_FUNCTION_ARGS) { - elog(ERROR, "Not implemented"); - PG_RETURN_DATUM(0); +gtsq_in(PG_FUNCTION_ARGS) +{ + elog(ERROR, "Not implemented"); + PG_RETURN_DATUM(0); } Datum -gtsq_out(PG_FUNCTION_ARGS) { - elog(ERROR, "Not implemented"); - PG_RETURN_DATUM(0); +gtsq_out(PG_FUNCTION_ARGS) +{ + elog(ERROR, "Not implemented"); + PG_RETURN_DATUM(0); } Datum -gtsq_compress(PG_FUNCTION_ARGS) { +gtsq_compress(PG_FUNCTION_ARGS) +{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = entry; - if (entry->leafkey) { - TPQTGist *sign = (TPQTGist*)palloc( sizeof(TPQTGist) ); + if (entry->leafkey) + { + TPQTGist *sign = (TPQTGist *) palloc(sizeof(TPQTGist)); + retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); - *sign = makesign( (QUERYTYPE*)DatumGetPointer(PG_DETOAST_DATUM(entry->key)) ); + *sign = makesign((QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(entry->key))); gistentryinit(*retval, PointerGetDatum(sign), - entry->rel, entry->page, - entry->offset, sizeof(TPQTGist), FALSE); + entry->rel, entry->page, + entry->offset, sizeof(TPQTGist), FALSE); } PG_RETURN_POINTER(retval); } Datum -gtsq_decompress(PG_FUNCTION_ARGS) { +gtsq_decompress(PG_FUNCTION_ARGS) +{ PG_RETURN_DATUM(PG_GETARG_DATUM(0)); } Datum -gtsq_consistent(PG_FUNCTION_ARGS) { +gtsq_consistent(PG_FUNCTION_ARGS) +{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); - TPQTGist *key = (TPQTGist*) DatumGetPointer(entry->key); + TPQTGist *key = (TPQTGist *) DatumGetPointer(entry->key); QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); - StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); + StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); TPQTGist sq = makesign(query); - if ( GIST_LEAF(entry) ) - PG_RETURN_BOOL( ( (*key) & sq ) == ((strategy==1) ? sq : *key) ); - else - PG_RETURN_BOOL( (*key) & sq ); + if (GIST_LEAF(entry)) + PG_RETURN_BOOL(((*key) & sq) == ((strategy == 1) ? sq : *key)); + else + PG_RETURN_BOOL((*key) & sq); } Datum -gtsq_union(PG_FUNCTION_ARGS) { +gtsq_union(PG_FUNCTION_ARGS) +{ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); - TPQTGist *sign = (TPQTGist*)palloc( sizeof(TPQTGist) ); - int i; - int *size = (int *) PG_GETARG_POINTER(1); + TPQTGist *sign = (TPQTGist *) palloc(sizeof(TPQTGist)); + int i; + int *size = (int *) PG_GETARG_POINTER(1); - memset( sign, 0, sizeof(TPQTGist) ); + memset(sign, 0, sizeof(TPQTGist)); - for (i = 0; i < entryvec->n;i++) + for (i = 0; i < entryvec->n; i++) *sign |= *GETENTRY(entryvec, i); *size = sizeof(TPQTGist); @@ -189,35 +210,40 @@ gtsq_union(PG_FUNCTION_ARGS) { } Datum -gtsq_same(PG_FUNCTION_ARGS) { - TPQTGist *a = (TPQTGist *) PG_GETARG_POINTER(0); - TPQTGist *b = (TPQTGist *) PG_GETARG_POINTER(1); +gtsq_same(PG_FUNCTION_ARGS) +{ + TPQTGist *a = (TPQTGist *) PG_GETARG_POINTER(0); + TPQTGist *b = (TPQTGist *) PG_GETARG_POINTER(1); - PG_RETURN_POINTER( *a == *b ); + PG_RETURN_POINTER(*a == *b); } static int -sizebitvec(TPQTGist sign) { - int size=0,i; +sizebitvec(TPQTGist sign) +{ + int size = 0, + i; - for(i=0;i<SIGLEN;i++) - size += 0x01 & (sign>>i); + for (i = 0; i < SIGLEN; i++) + size += 0x01 & (sign >> i); return size; } static int -hemdist(TPQTGist a, TPQTGist b) { - TPQTGist res = a ^ b; +hemdist(TPQTGist a, TPQTGist b) +{ + TPQTGist res = a ^ b; return sizebitvec(res); } Datum -gtsq_penalty(PG_FUNCTION_ARGS) { - TPQTGist *origval = (TPQTGist*) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); - TPQTGist *newval = (TPQTGist*) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); - float *penalty = (float *) PG_GETARG_POINTER(2); +gtsq_penalty(PG_FUNCTION_ARGS) +{ + TPQTGist *origval = (TPQTGist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); + TPQTGist *newval = (TPQTGist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); + float *penalty = (float *) PG_GETARG_POINTER(2); *penalty = hemdist(*origval, *newval); @@ -225,36 +251,45 @@ gtsq_penalty(PG_FUNCTION_ARGS) { } -typedef struct { - OffsetNumber pos; - int4 cost; +typedef struct +{ + OffsetNumber pos; + int4 cost; } SPLITCOST; static int -comparecost(const void *a, const void *b) { - if (((SPLITCOST *) a)->cost == ((SPLITCOST *) b)->cost) - return 0; - else - return (((SPLITCOST *) a)->cost > ((SPLITCOST *) b)->cost) ? 1 : -1; +comparecost(const void *a, const void *b) +{ + if (((SPLITCOST *) a)->cost == ((SPLITCOST *) b)->cost) + return 0; + else + return (((SPLITCOST *) a)->cost > ((SPLITCOST *) b)->cost) ? 1 : -1; } #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) ) Datum -gtsq_picksplit(PG_FUNCTION_ARGS) { +gtsq_picksplit(PG_FUNCTION_ARGS) +{ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); OffsetNumber maxoff = entryvec->n - 2; - OffsetNumber k,j; - - TPQTGist *datum_l, *datum_r; - int4 size_alpha, size_beta; - int4 size_waste, waste = -1; - int4 nbytes; - OffsetNumber seed_1 = 0, seed_2 = 0; - OffsetNumber *left, *right; - - SPLITCOST *costvector; + OffsetNumber k, + j; + + TPQTGist *datum_l, + *datum_r; + int4 size_alpha, + size_beta; + int4 size_waste, + waste = -1; + int4 nbytes; + OffsetNumber seed_1 = 0, + seed_2 = 0; + OffsetNumber *left, + *right; + + SPLITCOST *costvector; nbytes = (maxoff + 2) * sizeof(OffsetNumber); left = v->spl_left = (OffsetNumber *) palloc(nbytes); @@ -262,9 +297,11 @@ gtsq_picksplit(PG_FUNCTION_ARGS) { v->spl_nleft = v->spl_nright = 0; for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) - for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) { - size_waste = hemdist( *GETENTRY(entryvec,j), *GETENTRY(entryvec,k) ); - if (size_waste > waste) { + for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) + { + size_waste = hemdist(*GETENTRY(entryvec, j), *GETENTRY(entryvec, k)); + if (size_waste > waste) + { waste = size_waste; seed_1 = k; seed_2 = j; @@ -272,47 +309,56 @@ gtsq_picksplit(PG_FUNCTION_ARGS) { } - if (seed_1 == 0 || seed_2 == 0) { + if (seed_1 == 0 || seed_2 == 0) + { seed_1 = 1; seed_2 = 2; } - datum_l = (TPQTGist*)palloc( sizeof(TPQTGist) ); - *datum_l=*GETENTRY(entryvec,seed_1); - datum_r = (TPQTGist*)palloc( sizeof(TPQTGist) ); - *datum_r=*GETENTRY(entryvec,seed_2); - - + datum_l = (TPQTGist *) palloc(sizeof(TPQTGist)); + *datum_l = *GETENTRY(entryvec, seed_1); + datum_r = (TPQTGist *) palloc(sizeof(TPQTGist)); + *datum_r = *GETENTRY(entryvec, seed_2); + + maxoff = OffsetNumberNext(maxoff); costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff); - for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) { + for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) + { costvector[j - 1].pos = j; - size_alpha = hemdist( *GETENTRY(entryvec,seed_1), *GETENTRY(entryvec,j) ); - size_beta = hemdist( *GETENTRY(entryvec,seed_2), *GETENTRY(entryvec,j) ); + size_alpha = hemdist(*GETENTRY(entryvec, seed_1), *GETENTRY(entryvec, j)); + size_beta = hemdist(*GETENTRY(entryvec, seed_2), *GETENTRY(entryvec, j)); costvector[j - 1].cost = abs(size_alpha - size_beta); } qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost); - for (k = 0; k < maxoff; k++) { + for (k = 0; k < maxoff; k++) + { j = costvector[k].pos; - if ( j == seed_1 ) { + if (j == seed_1) + { *left++ = j; v->spl_nleft++; continue; - } else if ( j == seed_2 ) { + } + else if (j == seed_2) + { *right++ = j; v->spl_nright++; continue; } - size_alpha = hemdist( *datum_l, *GETENTRY(entryvec,j) ); - size_beta = hemdist( *datum_r, *GETENTRY(entryvec,j) ); + size_alpha = hemdist(*datum_l, *GETENTRY(entryvec, j)); + size_beta = hemdist(*datum_r, *GETENTRY(entryvec, j)); - if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.05)) { - *datum_l |= *GETENTRY(entryvec,j); + if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.05)) + { + *datum_l |= *GETENTRY(entryvec, j); *left++ = j; v->spl_nleft++; - } else { - *datum_r |= *GETENTRY(entryvec,j); + } + else + { + *datum_r |= *GETENTRY(entryvec, j); *right++ = j; v->spl_nright++; } @@ -324,5 +370,3 @@ gtsq_picksplit(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(v); } - - diff --git a/contrib/tsearch2/query_rewrite.c b/contrib/tsearch2/query_rewrite.c index e3d40cc44d..f1faaf8778 100644 --- a/contrib/tsearch2/query_rewrite.c +++ b/contrib/tsearch2/query_rewrite.c @@ -6,135 +6,167 @@ MemoryContext AggregateContext = NULL; static int -addone(int * counters, int last, int total) { +addone(int *counters, int last, int total) +{ counters[last]++; - if ( counters[last]>=total ) { - if (last==0) + if (counters[last] >= total) + { + if (last == 0) return 0; - if ( addone( counters, last-1, total-1 ) == 0 ) + if (addone(counters, last - 1, total - 1) == 0) return 0; - counters[last] = counters[last-1]+1; + counters[last] = counters[last - 1] + 1; } return 1; } -static QTNode * -findeq(QTNode *node, QTNode *ex, MemoryType memtype, QTNode *subs, bool *isfind) { - - if ( (node->sign & ex->sign) != ex->sign || node->valnode->type != ex->valnode->type || node->valnode->val != ex->valnode->val ) +static QTNode * +findeq(QTNode * node, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind) +{ + + if ((node->sign & ex->sign) != ex->sign || node->valnode->type != ex->valnode->type || node->valnode->val != ex->valnode->val) return node; - if ( node->flags & QTN_NOCHANGE ) - return node; + if (node->flags & QTN_NOCHANGE) + return node; - if ( node->valnode->type==OPR ) { - if ( node->nchild == ex->nchild ) { - if ( QTNEq( node, ex ) ) { - QTNFree( node ); - if ( subs ) { - node = QTNCopy( subs, memtype ); + if (node->valnode->type == OPR) + { + if (node->nchild == ex->nchild) + { + if (QTNEq(node, ex)) + { + QTNFree(node); + if (subs) + { + node = QTNCopy(subs, memtype); node->flags |= QTN_NOCHANGE; - } else - node = NULL; + } + else + node = NULL; *isfind = true; } - } else if ( node->nchild > ex->nchild ) { - int *counters = (int*)palloc( sizeof(int) * node->nchild ); - int i; - QTNode *tnode = (QTNode*)MEMALLOC( memtype, sizeof(QTNode) ); + } + else if (node->nchild > ex->nchild) + { + int *counters = (int *) palloc(sizeof(int) * node->nchild); + int i; + QTNode *tnode = (QTNode *) MEMALLOC(memtype, sizeof(QTNode)); memset(tnode, 0, sizeof(QTNode)); - tnode->child = (QTNode**)MEMALLOC( memtype, sizeof(QTNode*) * ex->nchild ); + tnode->child = (QTNode **) MEMALLOC(memtype, sizeof(QTNode *) * ex->nchild); tnode->nchild = ex->nchild; - tnode->valnode = (ITEM*)MEMALLOC( memtype, sizeof(ITEM) ); + tnode->valnode = (ITEM *) MEMALLOC(memtype, sizeof(ITEM)); *(tnode->valnode) = *(ex->valnode); - for(i=0;i<ex->nchild;i++) - counters[i]=i; + for (i = 0; i < ex->nchild; i++) + counters[i] = i; - do { - tnode->sign=0; - for(i=0;i<ex->nchild;i++) { - tnode->child[i] = node->child[ counters[i] ]; + do + { + tnode->sign = 0; + for (i = 0; i < ex->nchild; i++) + { + tnode->child[i] = node->child[counters[i]]; tnode->sign |= tnode->child[i]->sign; } - if ( QTNEq( tnode, ex ) ) { - int j=0; + if (QTNEq(tnode, ex)) + { + int j = 0; - MEMFREE( memtype, tnode->valnode ); - MEMFREE( memtype, tnode->child ); - MEMFREE( memtype, tnode ); - if ( subs ) { - tnode = QTNCopy( subs, memtype ); + MEMFREE(memtype, tnode->valnode); + MEMFREE(memtype, tnode->child); + MEMFREE(memtype, tnode); + if (subs) + { + tnode = QTNCopy(subs, memtype); tnode->flags = QTN_NOCHANGE | QTN_NEEDFREE; - } else + } + else tnode = NULL; - node->child[ counters[0] ] = tnode; + node->child[counters[0]] = tnode; - for(i=1;i<ex->nchild;i++) - node->child[ counters[i] ] = NULL; - for(i=0;i<node->nchild;i++) { - if ( node->child[i] ) { + for (i = 1; i < ex->nchild; i++) + node->child[counters[i]] = NULL; + for (i = 0; i < node->nchild; i++) + { + if (node->child[i]) + { node->child[j] = node->child[i]; j++; } } - node->nchild = j; + node->nchild = j; *isfind = true; break; } - } while (addone(counters,ex->nchild-1,node->nchild)); - if ( tnode && (tnode->flags & QTN_NOCHANGE) == 0 ) { - MEMFREE( memtype, tnode->valnode ); - MEMFREE( memtype, tnode->child ); - MEMFREE( memtype, tnode ); - } else - QTNSort( node ); - pfree( counters ); + } while (addone(counters, ex->nchild - 1, node->nchild)); + if (tnode && (tnode->flags & QTN_NOCHANGE) == 0) + { + MEMFREE(memtype, tnode->valnode); + MEMFREE(memtype, tnode->child); + MEMFREE(memtype, tnode); + } + else + QTNSort(node); + pfree(counters); } - } else if ( QTNEq( node, ex ) ) { - QTNFree( node ); - if ( subs ) { - node = QTNCopy( subs, memtype ); + } + else if (QTNEq(node, ex)) + { + QTNFree(node); + if (subs) + { + node = QTNCopy(subs, memtype); node->flags |= QTN_NOCHANGE; - } else { + } + else + { node = NULL; } *isfind = true; } return node; -} +} static QTNode * -dofindsubquery( QTNode *root, QTNode *ex, MemoryType memtype, QTNode *subs, bool *isfind ) { - root = findeq( root, ex, memtype, subs, isfind ); +dofindsubquery(QTNode * root, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind) +{ + root = findeq(root, ex, memtype, subs, isfind); + + if (root && (root->flags & QTN_NOCHANGE) == 0 && root->valnode->type == OPR) + { + int i; - if ( root && (root->flags & QTN_NOCHANGE) == 0 && root->valnode->type==OPR) { - int i; - for(i=0;i<root->nchild;i++) - root->child[i] = dofindsubquery( root->child[i], ex, memtype, subs, isfind ); + for (i = 0; i < root->nchild; i++) + root->child[i] = dofindsubquery(root->child[i], ex, memtype, subs, isfind); } return root; } static QTNode * -dropvoidsubtree( QTNode *root ) { +dropvoidsubtree(QTNode * root) +{ - if ( !root ) + if (!root) return NULL; - if ( root->valnode->type==OPR ) { - int i,j=0; + if (root->valnode->type == OPR) + { + int i, + j = 0; - for(i=0;i<root->nchild;i++) { - if ( root->child[i] ) { + for (i = 0; i < root->nchild; i++) + { + if (root->child[i]) + { root->child[j] = root->child[i]; j++; } @@ -142,88 +174,100 @@ dropvoidsubtree( QTNode *root ) { root->nchild = j; - if ( root->valnode->val == (int4)'!' && root->nchild==0 ) { + if (root->valnode->val == (int4) '!' && root->nchild == 0) + { QTNFree(root); - root=NULL; - } else if ( root->nchild==1 ) { - QTNode *nroot = root->child[0]; + root = NULL; + } + else if (root->nchild == 1) + { + QTNode *nroot = root->child[0]; + pfree(root); - root = nroot; - } + root = nroot; + } } return root; } static QTNode * -findsubquery( QTNode *root, QTNode *ex, MemoryType memtype, QTNode *subs, bool *isfind ) { - bool DidFind = false; - root = dofindsubquery( root, ex, memtype, subs, &DidFind ); +findsubquery(QTNode * root, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind) +{ + bool DidFind = false; + + root = dofindsubquery(root, ex, memtype, subs, &DidFind); - if ( !subs && DidFind ) - root = dropvoidsubtree( root ); + if (!subs && DidFind) + root = dropvoidsubtree(root); - if ( isfind ) + if (isfind) *isfind = DidFind; return root; } -static Oid tsqOid = InvalidOid; +static Oid tsqOid = InvalidOid; static void get_tsq_Oid(void) { - int ret; - bool isnull; - - if ((ret = SPI_exec("select oid from pg_type where typname='tsquery'", 1)) < 0) - /* internal error */ - elog(ERROR, "SPI_exec to get tsquery oid returns %d", ret); - - if (SPI_processed < 0) - /* internal error */ - elog(ERROR, "There is no tsvector type"); - tsqOid = DatumGetObjectId(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull)); - if (tsqOid == InvalidOid) - /* internal error */ - elog(ERROR, "tsquery type has InvalidOid"); + int ret; + bool isnull; + + if ((ret = SPI_exec("select oid from pg_type where typname='tsquery'", 1)) < 0) + /* internal error */ + elog(ERROR, "SPI_exec to get tsquery oid returns %d", ret); + + if (SPI_processed < 0) + /* internal error */ + elog(ERROR, "There is no tsvector type"); + tsqOid = DatumGetObjectId(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull)); + if (tsqOid == InvalidOid) + /* internal error */ + elog(ERROR, "tsquery type has InvalidOid"); } PG_FUNCTION_INFO_V1(tsquery_rewrite); PG_FUNCTION_INFO_V1(rewrite_accum); -Datum rewrite_accum(PG_FUNCTION_ARGS); - -Datum -rewrite_accum(PG_FUNCTION_ARGS) { - QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0); - ArrayType *qa = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); - QUERYTYPE *q; - QTNode *qex, *subs = NULL, *acctree; - bool isfind = false; - Datum *elemsp; - int nelemsp; +Datum rewrite_accum(PG_FUNCTION_ARGS); + +Datum +rewrite_accum(PG_FUNCTION_ARGS) +{ + QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0); + ArrayType *qa = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + QUERYTYPE *q; + QTNode *qex, + *subs = NULL, + *acctree; + bool isfind = false; + Datum *elemsp; + int nelemsp; AggregateContext = ((AggState *) fcinfo->context)->aggcontext; - - if (acc == NULL || PG_ARGISNULL(0)) { - acc = (QUERYTYPE*)MEMALLOC( AggMemory, sizeof(QUERYTYPE) ); + + if (acc == NULL || PG_ARGISNULL(0)) + { + acc = (QUERYTYPE *) MEMALLOC(AggMemory, sizeof(QUERYTYPE)); acc->len = HDRSIZEQT; acc->size = 0; } - if ( qa == NULL || PG_ARGISNULL(1) ) { - PG_FREE_IF_COPY( qa, 1 ); - PG_RETURN_POINTER( acc ); + if (qa == NULL || PG_ARGISNULL(1)) + { + PG_FREE_IF_COPY(qa, 1); + PG_RETURN_POINTER(acc); } - if ( ARR_NDIM(qa) != 1 ) + if (ARR_NDIM(qa) != 1) elog(ERROR, "array must be one-dimensional, not %d dimension", ARR_NDIM(qa)); - if ( ArrayGetNItems( ARR_NDIM(qa), ARR_DIMS(qa)) != 3 ) + if (ArrayGetNItems(ARR_NDIM(qa), ARR_DIMS(qa)) != 3) elog(ERROR, "array should have only three elements"); - if (tsqOid == InvalidOid) { + if (tsqOid == InvalidOid) + { SPI_connect(); get_tsq_Oid(); SPI_finish(); @@ -232,108 +276,122 @@ rewrite_accum(PG_FUNCTION_ARGS) { if (ARR_ELEMTYPE(qa) != tsqOid) elog(ERROR, "array should contain tsquery type"); - deconstruct_array(qa, tsqOid, -1, false, 'i', &elemsp, NULL, &nelemsp); + deconstruct_array(qa, tsqOid, -1, false, 'i', &elemsp, NULL, &nelemsp); - q = (QUERYTYPE*)DatumGetPointer( elemsp[0] ); - if ( q->size == 0 ) { - pfree( elemsp ); - PG_RETURN_POINTER( acc ); + q = (QUERYTYPE *) DatumGetPointer(elemsp[0]); + if (q->size == 0) + { + pfree(elemsp); + PG_RETURN_POINTER(acc); } - - if ( !acc->size ) { - if ( acc->len > HDRSIZEQT ) { - pfree( elemsp ); - PG_RETURN_POINTER( acc ); - } else - acctree = QT2QTN( GETQUERY(q), GETOPERAND(q) ); - } else - acctree = QT2QTN( GETQUERY(acc), GETOPERAND(acc) ); - - QTNTernary( acctree ); - QTNSort( acctree ); - - q = (QUERYTYPE*)DatumGetPointer( elemsp[1] ); - if ( q->size == 0 ) { - pfree( elemsp ); - PG_RETURN_POINTER( acc ); + + if (!acc->size) + { + if (acc->len > HDRSIZEQT) + { + pfree(elemsp); + PG_RETURN_POINTER(acc); + } + else + acctree = QT2QTN(GETQUERY(q), GETOPERAND(q)); } - qex = QT2QTN( GETQUERY(q), GETOPERAND(q) ); - QTNTernary( qex ); - QTNSort( qex ); - - q = (QUERYTYPE*)DatumGetPointer( elemsp[2] ); - if ( q->size ) - subs = QT2QTN( GETQUERY(q), GETOPERAND(q) ); + else + acctree = QT2QTN(GETQUERY(acc), GETOPERAND(acc)); - acctree = findsubquery( acctree, qex, PlainMemory, subs, &isfind ); + QTNTernary(acctree); + QTNSort(acctree); + + q = (QUERYTYPE *) DatumGetPointer(elemsp[1]); + if (q->size == 0) + { + pfree(elemsp); + PG_RETURN_POINTER(acc); + } + qex = QT2QTN(GETQUERY(q), GETOPERAND(q)); + QTNTernary(qex); + QTNSort(qex); - if ( isfind || !acc->size ) { + q = (QUERYTYPE *) DatumGetPointer(elemsp[2]); + if (q->size) + subs = QT2QTN(GETQUERY(q), GETOPERAND(q)); + + acctree = findsubquery(acctree, qex, PlainMemory, subs, &isfind); + + if (isfind || !acc->size) + { /* pfree( acc ); do not pfree(p), because nodeAgg.c will */ - if ( acctree ) { - QTNBinary( acctree ); - acc = QTN2QT( acctree, AggMemory ); - } else { - acc = (QUERYTYPE*)MEMALLOC( AggMemory, HDRSIZEQT*2 ); + if (acctree) + { + QTNBinary(acctree); + acc = QTN2QT(acctree, AggMemory); + } + else + { + acc = (QUERYTYPE *) MEMALLOC(AggMemory, HDRSIZEQT * 2); acc->len = HDRSIZEQT * 2; acc->size = 0; } } - pfree( elemsp ); - QTNFree( qex ); - QTNFree( subs ); - QTNFree( acctree ); + pfree(elemsp); + QTNFree(qex); + QTNFree(subs); + QTNFree(acctree); - PG_RETURN_POINTER( acc ); + PG_RETURN_POINTER(acc); } PG_FUNCTION_INFO_V1(rewrite_finish); -Datum rewrite_finish(PG_FUNCTION_ARGS); - -Datum -rewrite_finish(PG_FUNCTION_ARGS) { - QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0); - QUERYTYPE *rewrited; - - if (acc == NULL || PG_ARGISNULL(0) || acc->size == 0 ) { - acc = (QUERYTYPE*)palloc(sizeof(QUERYTYPE)); +Datum rewrite_finish(PG_FUNCTION_ARGS); + +Datum +rewrite_finish(PG_FUNCTION_ARGS) +{ + QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0); + QUERYTYPE *rewrited; + + if (acc == NULL || PG_ARGISNULL(0) || acc->size == 0) + { + acc = (QUERYTYPE *) palloc(sizeof(QUERYTYPE)); acc->len = HDRSIZEQT; acc->size = 0; } - rewrited = (QUERYTYPE*) palloc( acc->len ); - memcpy( rewrited, acc, acc->len ); - pfree( acc ); + rewrited = (QUERYTYPE *) palloc(acc->len); + memcpy(rewrited, acc, acc->len); + pfree(acc); - PG_RETURN_POINTER(rewrited); + PG_RETURN_POINTER(rewrited); } -Datum tsquery_rewrite(PG_FUNCTION_ARGS); +Datum tsquery_rewrite(PG_FUNCTION_ARGS); Datum -tsquery_rewrite(PG_FUNCTION_ARGS) { +tsquery_rewrite(PG_FUNCTION_ARGS) +{ QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_P(1); QUERYTYPE *rewrited = query; - QTNode *tree; - char *buf; - void *plan; - Portal portal; - bool isnull; - int i; - - if ( query->size == 0 ) { + QTNode *tree; + char *buf; + void *plan; + Portal portal; + bool isnull; + int i; + + if (query->size == 0) + { PG_FREE_IF_COPY(in, 1); - PG_RETURN_POINTER( rewrited ); + PG_RETURN_POINTER(rewrited); } - tree = QT2QTN( GETQUERY(query), GETOPERAND(query) ); - QTNTernary( tree ); - QTNSort( tree ); + tree = QT2QTN(GETQUERY(query), GETOPERAND(query)); + QTNTernary(tree); + QTNSort(tree); - buf = (char*)palloc( VARSIZE(in) ); + buf = (char *) palloc(VARSIZE(in)); memcpy(buf, VARDATA(in), VARSIZE(in) - VARHDRSZ); - buf[ VARSIZE(in) - VARHDRSZ ] = '\0'; + buf[VARSIZE(in) - VARHDRSZ] = '\0'; SPI_connect(); @@ -345,132 +403,147 @@ tsquery_rewrite(PG_FUNCTION_ARGS) { if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, false)) == NULL) elog(ERROR, "SPI_cursor_open('%s') returns NULL", buf); - + SPI_cursor_fetch(portal, true, 100); if (SPI_tuptable->tupdesc->natts != 2) elog(ERROR, "number of fields doesn't equal to 2"); - if (SPI_gettypeid(SPI_tuptable->tupdesc, 1) != tsqOid ) + if (SPI_gettypeid(SPI_tuptable->tupdesc, 1) != tsqOid) elog(ERROR, "column #1 isn't of tsquery type"); - if (SPI_gettypeid(SPI_tuptable->tupdesc, 2) != tsqOid ) + if (SPI_gettypeid(SPI_tuptable->tupdesc, 2) != tsqOid) elog(ERROR, "column #2 isn't of tsquery type"); - while (SPI_processed > 0 && tree ) { - for (i = 0; i < SPI_processed && tree; i++) { - Datum qdata = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 1, &isnull); - Datum sdata; + while (SPI_processed > 0 && tree) + { + for (i = 0; i < SPI_processed && tree; i++) + { + Datum qdata = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 1, &isnull); + Datum sdata; - if ( isnull ) continue; + if (isnull) + continue; sdata = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 2, &isnull); - if (!isnull) { - QUERYTYPE *qtex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(qdata)); - QUERYTYPE *qtsubs = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(sdata)); - QTNode *qex, *qsubs = NULL; - - if (qtex->size == 0) { - if ( qtex != (QUERYTYPE *) DatumGetPointer(qdata) ) - pfree( qtex ); - if ( qtsubs != (QUERYTYPE *) DatumGetPointer(sdata) ) - pfree( qtsubs ); + if (!isnull) + { + QUERYTYPE *qtex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(qdata)); + QUERYTYPE *qtsubs = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(sdata)); + QTNode *qex, + *qsubs = NULL; + + if (qtex->size == 0) + { + if (qtex != (QUERYTYPE *) DatumGetPointer(qdata)) + pfree(qtex); + if (qtsubs != (QUERYTYPE *) DatumGetPointer(sdata)) + pfree(qtsubs); continue; } - qex = QT2QTN( GETQUERY(qtex), GETOPERAND(qtex) ); + qex = QT2QTN(GETQUERY(qtex), GETOPERAND(qtex)); - QTNTernary( qex ); - QTNSort( qex ); + QTNTernary(qex); + QTNSort(qex); - if ( qtsubs->size ) - qsubs = QT2QTN( GETQUERY(qtsubs), GETOPERAND(qtsubs) ); + if (qtsubs->size) + qsubs = QT2QTN(GETQUERY(qtsubs), GETOPERAND(qtsubs)); - tree = findsubquery( tree, qex, SPIMemory, qsubs, NULL ); - - QTNFree( qex ); - if ( qtex != (QUERYTYPE *) DatumGetPointer(qdata) ) - pfree( qtex ); - QTNFree( qsubs ); - if ( qtsubs != (QUERYTYPE *) DatumGetPointer(sdata) ) - pfree( qtsubs ); + tree = findsubquery(tree, qex, SPIMemory, qsubs, NULL); + + QTNFree(qex); + if (qtex != (QUERYTYPE *) DatumGetPointer(qdata)) + pfree(qtex); + QTNFree(qsubs); + if (qtsubs != (QUERYTYPE *) DatumGetPointer(sdata)) + pfree(qtsubs); } } SPI_freetuptable(SPI_tuptable); SPI_cursor_fetch(portal, true, 100); } - + SPI_freetuptable(SPI_tuptable); SPI_cursor_close(portal); SPI_freeplan(plan); - SPI_finish(); + SPI_finish(); - if ( tree ) { - QTNBinary( tree ); - rewrited = QTN2QT( tree, PlainMemory ); - QTNFree( tree ); + if (tree) + { + QTNBinary(tree); + rewrited = QTN2QT(tree, PlainMemory); + QTNFree(tree); PG_FREE_IF_COPY(query, 0); - } else { + } + else + { rewrited->len = HDRSIZEQT; rewrited->size = 0; } pfree(buf); PG_FREE_IF_COPY(in, 1); - PG_RETURN_POINTER( rewrited ); + PG_RETURN_POINTER(rewrited); } PG_FUNCTION_INFO_V1(tsquery_rewrite_query); -Datum tsquery_rewrite_query(PG_FUNCTION_ARGS); +Datum tsquery_rewrite_query(PG_FUNCTION_ARGS); Datum -tsquery_rewrite_query(PG_FUNCTION_ARGS) { - QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - QUERYTYPE *ex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); - QUERYTYPE *subst = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(2))); - QUERYTYPE *rewrited = query; - QTNode *tree, *qex, *subs = NULL; - - if ( query->size == 0 || ex->size == 0 ) { - PG_FREE_IF_COPY(ex, 1); - PG_FREE_IF_COPY(subst, 2); - PG_RETURN_POINTER( rewrited ); - } - - tree = QT2QTN( GETQUERY(query), GETOPERAND(query) ); - QTNTernary( tree ); - QTNSort( tree ); - - qex = QT2QTN( GETQUERY(ex), GETOPERAND(ex) ); - QTNTernary( qex ); - QTNSort( qex ); - - if ( subst->size ) - subs = QT2QTN( GETQUERY(subst), GETOPERAND(subst) ); - - tree = findsubquery( tree, qex, PlainMemory, subs, NULL ); - QTNFree( qex ); - QTNFree( subs ); - - if ( !tree ) { +tsquery_rewrite_query(PG_FUNCTION_ARGS) +{ + QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + QUERYTYPE *ex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); + QUERYTYPE *subst = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(2))); + QUERYTYPE *rewrited = query; + QTNode *tree, + *qex, + *subs = NULL; + + if (query->size == 0 || ex->size == 0) + { + PG_FREE_IF_COPY(ex, 1); + PG_FREE_IF_COPY(subst, 2); + PG_RETURN_POINTER(rewrited); + } + + tree = QT2QTN(GETQUERY(query), GETOPERAND(query)); + QTNTernary(tree); + QTNSort(tree); + + qex = QT2QTN(GETQUERY(ex), GETOPERAND(ex)); + QTNTernary(qex); + QTNSort(qex); + + if (subst->size) + subs = QT2QTN(GETQUERY(subst), GETOPERAND(subst)); + + tree = findsubquery(tree, qex, PlainMemory, subs, NULL); + QTNFree(qex); + QTNFree(subs); + + if (!tree) + { rewrited->len = HDRSIZEQT; rewrited->size = 0; - PG_FREE_IF_COPY(ex, 1); - PG_FREE_IF_COPY(subst, 2); - PG_RETURN_POINTER( rewrited ); - } else { - QTNBinary( tree ); - rewrited = QTN2QT( tree, PlainMemory ); - QTNFree( tree ); + PG_FREE_IF_COPY(ex, 1); + PG_FREE_IF_COPY(subst, 2); + PG_RETURN_POINTER(rewrited); + } + else + { + QTNBinary(tree); + rewrited = QTN2QT(tree, PlainMemory); + QTNFree(tree); } - PG_FREE_IF_COPY(query, 0); - PG_FREE_IF_COPY(ex, 1); - PG_FREE_IF_COPY(subst, 2); - PG_RETURN_POINTER( rewrited ); + PG_FREE_IF_COPY(query, 0); + PG_FREE_IF_COPY(ex, 1); + PG_FREE_IF_COPY(subst, 2); + PG_RETURN_POINTER(rewrited); } - diff --git a/contrib/tsearch2/query_support.c b/contrib/tsearch2/query_support.c index edc2d48fcf..dfdd714073 100644 --- a/contrib/tsearch2/query_support.c +++ b/contrib/tsearch2/query_support.c @@ -4,168 +4,188 @@ #include "query_util.h" PG_FUNCTION_INFO_V1(tsquery_numnode); -Datum tsquery_numnode(PG_FUNCTION_ARGS); +Datum tsquery_numnode(PG_FUNCTION_ARGS); Datum -tsquery_numnode(PG_FUNCTION_ARGS) { +tsquery_numnode(PG_FUNCTION_ARGS) +{ QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - int nnode = query->size; - PG_FREE_IF_COPY(query,0); + int nnode = query->size; + + PG_FREE_IF_COPY(query, 0); PG_RETURN_INT32(nnode); } -static QTNode* -join_tsqueries(QUERYTYPE *a, QUERYTYPE *b) { - QTNode *res=(QTNode*)palloc0( sizeof(QTNode) ); +static QTNode * +join_tsqueries(QUERYTYPE * a, QUERYTYPE * b) +{ + QTNode *res = (QTNode *) palloc0(sizeof(QTNode)); res->flags |= QTN_NEEDFREE; - res->valnode = (ITEM*)palloc0( sizeof(ITEM) ); + res->valnode = (ITEM *) palloc0(sizeof(ITEM)); res->valnode->type = OPR; - res->child = (QTNode**)palloc0( sizeof(QTNode*)*2 ); - res->child[0] = QT2QTN( GETQUERY(b), GETOPERAND(b) ); - res->child[1] = QT2QTN( GETQUERY(a), GETOPERAND(a) ); + res->child = (QTNode **) palloc0(sizeof(QTNode *) * 2); + res->child[0] = QT2QTN(GETQUERY(b), GETOPERAND(b)); + res->child[1] = QT2QTN(GETQUERY(a), GETOPERAND(a)); res->nchild = 2; return res; } PG_FUNCTION_INFO_V1(tsquery_and); -Datum tsquery_and(PG_FUNCTION_ARGS); +Datum tsquery_and(PG_FUNCTION_ARGS); Datum -tsquery_and(PG_FUNCTION_ARGS) { +tsquery_and(PG_FUNCTION_ARGS) +{ QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); - QTNode *res; + QTNode *res; QUERYTYPE *query; - if ( a->size == 0 ) { - PG_FREE_IF_COPY(a,1); + if (a->size == 0) + { + PG_FREE_IF_COPY(a, 1); PG_RETURN_POINTER(b); - } else if ( b->size == 0 ) { - PG_FREE_IF_COPY(b,1); + } + else if (b->size == 0) + { + PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(a); - } + } res = join_tsqueries(a, b); res->valnode->val = '&'; - query = QTN2QT( res, PlainMemory ); + query = QTN2QT(res, PlainMemory); QTNFree(res); - PG_FREE_IF_COPY(a,0); - PG_FREE_IF_COPY(b,1); + PG_FREE_IF_COPY(a, 0); + PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(query); } PG_FUNCTION_INFO_V1(tsquery_or); -Datum tsquery_or(PG_FUNCTION_ARGS); +Datum tsquery_or(PG_FUNCTION_ARGS); Datum -tsquery_or(PG_FUNCTION_ARGS) { +tsquery_or(PG_FUNCTION_ARGS) +{ QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); - QTNode *res; + QTNode *res; QUERYTYPE *query; - if ( a->size == 0 ) { - PG_FREE_IF_COPY(a,1); + if (a->size == 0) + { + PG_FREE_IF_COPY(a, 1); PG_RETURN_POINTER(b); - } else if ( b->size == 0 ) { - PG_FREE_IF_COPY(b,1); + } + else if (b->size == 0) + { + PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(a); - } + } res = join_tsqueries(a, b); res->valnode->val = '|'; - query = QTN2QT( res, PlainMemory ); + query = QTN2QT(res, PlainMemory); QTNFree(res); - PG_FREE_IF_COPY(a,0); - PG_FREE_IF_COPY(b,1); + PG_FREE_IF_COPY(a, 0); + PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(query); } PG_FUNCTION_INFO_V1(tsquery_not); -Datum tsquery_not(PG_FUNCTION_ARGS); +Datum tsquery_not(PG_FUNCTION_ARGS); Datum -tsquery_not(PG_FUNCTION_ARGS) { +tsquery_not(PG_FUNCTION_ARGS) +{ QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - QTNode *res; + QTNode *res; QUERYTYPE *query; - if ( a->size == 0 ) + if (a->size == 0) PG_RETURN_POINTER(a); - res=(QTNode*)palloc0( sizeof(QTNode) ); + res = (QTNode *) palloc0(sizeof(QTNode)); res->flags |= QTN_NEEDFREE; - res->valnode = (ITEM*)palloc0( sizeof(ITEM) ); + res->valnode = (ITEM *) palloc0(sizeof(ITEM)); res->valnode->type = OPR; res->valnode->val = '!'; - res->child = (QTNode**)palloc0( sizeof(QTNode*) ); - res->child[0] = QT2QTN( GETQUERY(a), GETOPERAND(a) ); + res->child = (QTNode **) palloc0(sizeof(QTNode *)); + res->child[0] = QT2QTN(GETQUERY(a), GETOPERAND(a)); res->nchild = 1; - query = QTN2QT( res, PlainMemory ); + query = QTN2QT(res, PlainMemory); QTNFree(res); - PG_FREE_IF_COPY(a,0); + PG_FREE_IF_COPY(a, 0); PG_RETURN_POINTER(query); } static int -CompareTSQ( QUERYTYPE *a, QUERYTYPE *b ) { - if ( a->size != b->size ) { - return ( a->size < b->size ) ? -1 : 1; - } else if ( a->len != b->len ) { - return ( a->len < b->len ) ? -1 : 1; - } else { - QTNode *an = QT2QTN( GETQUERY(a), GETOPERAND(a) ); - QTNode *bn = QT2QTN( GETQUERY(b), GETOPERAND(b) ); - int res = QTNodeCompare(an, bn); +CompareTSQ(QUERYTYPE * a, QUERYTYPE * b) +{ + if (a->size != b->size) + { + return (a->size < b->size) ? -1 : 1; + } + else if (a->len != b->len) + { + return (a->len < b->len) ? -1 : 1; + } + else + { + QTNode *an = QT2QTN(GETQUERY(a), GETOPERAND(a)); + QTNode *bn = QT2QTN(GETQUERY(b), GETOPERAND(b)); + int res = QTNodeCompare(an, bn); QTNFree(an); QTNFree(bn); - return res; + return res; } return 0; } -PG_FUNCTION_INFO_V1(tsquery_cmp); \ -Datum tsquery_cmp(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(tsquery_cmp); +\ +Datum tsquery_cmp(PG_FUNCTION_ARGS); Datum -tsquery_cmp(PG_FUNCTION_ARGS) { +tsquery_cmp(PG_FUNCTION_ARGS) +{ QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); - int res = CompareTSQ(a,b); + int res = CompareTSQ(a, b); - PG_FREE_IF_COPY(a,0); - PG_FREE_IF_COPY(b,1); + PG_FREE_IF_COPY(a, 0); + PG_FREE_IF_COPY(b, 1); PG_RETURN_INT32(res); } -#define CMPFUNC( NAME, ACTION ) \ +#define CMPFUNC( NAME, ACTION ) \ PG_FUNCTION_INFO_V1(NAME); \ Datum NAME(PG_FUNCTION_ARGS); \ \ Datum \ -NAME(PG_FUNCTION_ARGS) { \ +NAME(PG_FUNCTION_ARGS) { \ QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); \ QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); \ int res = CompareTSQ(a,b); \ @@ -176,12 +196,9 @@ NAME(PG_FUNCTION_ARGS) { \ PG_RETURN_BOOL( ACTION ); \ } -CMPFUNC( tsquery_lt, res <0 ); -CMPFUNC( tsquery_le, res<=0 ); -CMPFUNC( tsquery_eq, res==0 ); -CMPFUNC( tsquery_ge, res>=0 ); -CMPFUNC( tsquery_gt, res >0 ); -CMPFUNC( tsquery_ne, res!=0 ); - - - +CMPFUNC(tsquery_lt, res < 0); +CMPFUNC(tsquery_le, res <= 0); +CMPFUNC(tsquery_eq, res == 0); +CMPFUNC(tsquery_ge, res >= 0); +CMPFUNC(tsquery_gt, res > 0); +CMPFUNC(tsquery_ne, res != 0); diff --git a/contrib/tsearch2/query_util.c b/contrib/tsearch2/query_util.c index f509d9b642..efa74fe053 100644 --- a/contrib/tsearch2/query_util.c +++ b/contrib/tsearch2/query_util.c @@ -2,153 +2,180 @@ #include "executor/spi.h" #include "query_util.h" -QTNode* -QT2QTN( ITEM *in, char *operand ) { - QTNode *node = (QTNode*)palloc0( sizeof(QTNode) ); +QTNode * +QT2QTN(ITEM * in, char *operand) +{ + QTNode *node = (QTNode *) palloc0(sizeof(QTNode)); node->valnode = in; - - if (in->type == OPR) { - node->child = (QTNode**)palloc0( sizeof(QTNode*) * 2 ); - node->child[0] = QT2QTN( in + 1, operand ); + + if (in->type == OPR) + { + node->child = (QTNode **) palloc0(sizeof(QTNode *) * 2); + node->child[0] = QT2QTN(in + 1, operand); node->sign = node->child[0]->sign; if (in->val == (int4) '!') node->nchild = 1; - else { + else + { node->nchild = 2; - node->child[1] = QT2QTN( in + in->left, operand ); + node->child[1] = QT2QTN(in + in->left, operand); node->sign |= node->child[1]->sign; } - } else if ( operand ) { + } + else if (operand) + { node->word = operand + in->distance; - node->sign = 1 << ( in->val % 32 ); + node->sign = 1 << (in->val % 32); } - - return node; + + return node; } -void -QTNFree( QTNode* in ) { - if ( !in ) +void +QTNFree(QTNode * in) +{ + if (!in) return; - if ( in->valnode->type == VAL && in->word && (in->flags & QTN_WORDFREE) !=0 ) - pfree( in->word ); + if (in->valnode->type == VAL && in->word && (in->flags & QTN_WORDFREE) != 0) + pfree(in->word); - if ( in->child ) { - if ( in->valnode ) { - if ( in->valnode->type == OPR && in->nchild > 0 ) { - int i; - for (i=0;i<in->nchild;i++) - QTNFree( in->child[i] ); + if (in->child) + { + if (in->valnode) + { + if (in->valnode->type == OPR && in->nchild > 0) + { + int i; + + for (i = 0; i < in->nchild; i++) + QTNFree(in->child[i]); } - if ( in->flags & QTN_NEEDFREE ) - pfree( in->valnode ); + if (in->flags & QTN_NEEDFREE) + pfree(in->valnode); } - pfree( in->child ); + pfree(in->child); } - pfree( in ); + pfree(in); } int -QTNodeCompare( QTNode *an, QTNode *bn ) { - if ( an->valnode->type != bn->valnode->type ) - return ( an->valnode->type > bn->valnode->type ) ? -1 : 1; - else if ( an->valnode->val != bn->valnode->val ) - return ( an->valnode->val > bn->valnode->val ) ? -1 : 1; - else if ( an->valnode->type == VAL ) { - if ( an->valnode->length == bn->valnode->length ) - return strncmp( an->word, bn->word, an->valnode->length ); - else - return ( an->valnode->length > bn->valnode->length ) ? -1 : 1; - } else if ( an->nchild != bn->nchild ) { - return ( an->nchild > bn->nchild ) ? -1 : 1; - } else { - int i,res; - - for( i=0; i<an->nchild; i++ ) - if ( (res=QTNodeCompare(an->child[i], bn->child[i]))!=0 ) +QTNodeCompare(QTNode * an, QTNode * bn) +{ + if (an->valnode->type != bn->valnode->type) + return (an->valnode->type > bn->valnode->type) ? -1 : 1; + else if (an->valnode->val != bn->valnode->val) + return (an->valnode->val > bn->valnode->val) ? -1 : 1; + else if (an->valnode->type == VAL) + { + if (an->valnode->length == bn->valnode->length) + return strncmp(an->word, bn->word, an->valnode->length); + else + return (an->valnode->length > bn->valnode->length) ? -1 : 1; + } + else if (an->nchild != bn->nchild) + { + return (an->nchild > bn->nchild) ? -1 : 1; + } + else + { + int i, + res; + + for (i = 0; i < an->nchild; i++) + if ((res = QTNodeCompare(an->child[i], bn->child[i])) != 0) return res; - } - + } + return 0; } static int -cmpQTN( const void *a, const void *b ) { - return QTNodeCompare( *(QTNode**)a, *(QTNode**)b ); +cmpQTN(const void *a, const void *b) +{ + return QTNodeCompare(*(QTNode **) a, *(QTNode **) b); } - -void -QTNSort( QTNode* in ) { - int i; - if ( in->valnode->type != OPR ) +void +QTNSort(QTNode * in) +{ + int i; + + if (in->valnode->type != OPR) return; - - for (i=0;i<in->nchild;i++) - QTNSort( in->child[i] ); - if ( in->nchild > 1 ) - qsort((void *) in->child, in->nchild, sizeof(QTNode*), cmpQTN); + + for (i = 0; i < in->nchild; i++) + QTNSort(in->child[i]); + if (in->nchild > 1) + qsort((void *) in->child, in->nchild, sizeof(QTNode *), cmpQTN); } -bool -QTNEq( QTNode* a, QTNode* b ) { - uint32 sign = a->sign & b->sign; - if ( !(sign == a->sign && sign == b->sign) ) +bool +QTNEq(QTNode * a, QTNode * b) +{ + uint32 sign = a->sign & b->sign; + + if (!(sign == a->sign && sign == b->sign)) return 0; - return ( QTNodeCompare(a,b) == 0 ) ? true : false; + return (QTNodeCompare(a, b) == 0) ? true : false; } -void -QTNTernary( QTNode* in ) { - int i; +void +QTNTernary(QTNode * in) +{ + int i; - if ( in->valnode->type != OPR ) + if (in->valnode->type != OPR) return; - for (i=0;i<in->nchild;i++) - QTNTernary( in->child[i] ); + for (i = 0; i < in->nchild; i++) + QTNTernary(in->child[i]); + + for (i = 0; i < in->nchild; i++) + { + if (in->valnode->type == in->child[i]->valnode->type && in->valnode->val == in->child[i]->valnode->val) + { + QTNode *cc = in->child[i]; + int oldnchild = in->nchild; - for (i=0;i<in->nchild;i++) { - if ( in->valnode->type == in->child[i]->valnode->type && in->valnode->val == in->child[i]->valnode->val ) { - QTNode* cc = in->child[i]; - int oldnchild = in->nchild; + in->nchild += cc->nchild - 1; + in->child = (QTNode **) repalloc(in->child, in->nchild * sizeof(QTNode *)); - in->nchild += cc->nchild-1; - in->child = (QTNode**)repalloc( in->child, in->nchild * sizeof(QTNode*) ); - - if ( i+1 != oldnchild ) - memmove( in->child + i + cc->nchild, in->child + i + 1, - (oldnchild-i-1)*sizeof(QTNode*) ); + if (i + 1 != oldnchild) + memmove(in->child + i + cc->nchild, in->child + i + 1, + (oldnchild - i - 1) * sizeof(QTNode *)); - memcpy( in->child + i, cc->child, cc->nchild * sizeof(QTNode*) ); - i += cc->nchild-1; + memcpy(in->child + i, cc->child, cc->nchild * sizeof(QTNode *)); + i += cc->nchild - 1; pfree(cc); - } + } } } -void -QTNBinary( QTNode* in ) { - int i; +void +QTNBinary(QTNode * in) +{ + int i; - if ( in->valnode->type != OPR ) + if (in->valnode->type != OPR) return; - for (i=0;i<in->nchild;i++) - QTNBinary( in->child[i] ); + for (i = 0; i < in->nchild; i++) + QTNBinary(in->child[i]); + + if (in->nchild <= 2) + return; - if ( in->nchild <= 2 ) - return; + while (in->nchild > 2) + { + QTNode *nn = (QTNode *) palloc0(sizeof(QTNode)); - while( in->nchild > 2 ) { - QTNode *nn = (QTNode*)palloc0( sizeof(QTNode) ); - nn->valnode = (ITEM*)palloc0( sizeof(ITEM) ); - nn->child = (QTNode**)palloc0( sizeof(QTNode*) * 2 ); + nn->valnode = (ITEM *) palloc0(sizeof(ITEM)); + nn->child = (QTNode **) palloc0(sizeof(QTNode *) * 2); nn->nchild = 2; nn->flags = QTN_NEEDFREE; @@ -161,97 +188,114 @@ QTNBinary( QTNode* in ) { nn->valnode->val = in->valnode->val; in->child[0] = nn; - in->child[1] = in->child[ in->nchild-1 ]; + in->child[1] = in->child[in->nchild - 1]; in->nchild--; - } + } } static void -cntsize(QTNode *in, int4 *sumlen, int4 *nnode) { +cntsize(QTNode * in, int4 *sumlen, int4 *nnode) +{ *nnode += 1; - if ( in->valnode->type == OPR ) { - int i; - for (i=0;i<in->nchild;i++) + if (in->valnode->type == OPR) + { + int i; + + for (i = 0; i < in->nchild; i++) cntsize(in->child[i], sumlen, nnode); - } else { - *sumlen += in->valnode->length+1; + } + else + { + *sumlen += in->valnode->length + 1; } } -typedef struct { - ITEM *curitem; - char *operand; - char *curoperand; -} QTN2QTState; +typedef struct +{ + ITEM *curitem; + char *operand; + char *curoperand; +} QTN2QTState; static void -fillQT( QTN2QTState *state, QTNode *in ) { +fillQT(QTN2QTState * state, QTNode * in) +{ *(state->curitem) = *(in->valnode); - - if ( in->valnode->type == VAL ) { - memcpy( state->curoperand, in->word, in->valnode->length ); + + if (in->valnode->type == VAL) + { + memcpy(state->curoperand, in->word, in->valnode->length); state->curitem->distance = state->curoperand - state->operand; - state->curoperand[ in->valnode->length ] = '\0'; - state->curoperand += in->valnode->length + 1; + state->curoperand[in->valnode->length] = '\0'; + state->curoperand += in->valnode->length + 1; state->curitem++; - } else { - ITEM *curitem = state->curitem; + } + else + { + ITEM *curitem = state->curitem; - Assert( in->nchild<=2 ); + Assert(in->nchild <= 2); state->curitem++; - fillQT( state, in->child[0] ); + fillQT(state, in->child[0]); - if ( in->nchild==2 ) { + if (in->nchild == 2) + { curitem->left = state->curitem - curitem; - fillQT( state, in->child[1] ); - } + fillQT(state, in->child[1]); + } } -} +} -QUERYTYPE* -QTN2QT( QTNode* in, MemoryType memtype ) { - QUERYTYPE *out; - int len; - int sumlen=0, nnode=0; - QTN2QTState state; +QUERYTYPE * +QTN2QT(QTNode * in, MemoryType memtype) +{ + QUERYTYPE *out; + int len; + int sumlen = 0, + nnode = 0; + QTN2QTState state; cntsize(in, &sumlen, &nnode); - len = COMPUTESIZE( nnode, sumlen ); + len = COMPUTESIZE(nnode, sumlen); - out = (QUERYTYPE*)MEMALLOC(memtype, len); - out->len = len; - out->size = nnode; + out = (QUERYTYPE *) MEMALLOC(memtype, len); + out->len = len; + out->size = nnode; - state.curitem = GETQUERY( out ); - state.operand = state.curoperand = GETOPERAND( out ); + state.curitem = GETQUERY(out); + state.operand = state.curoperand = GETOPERAND(out); - fillQT( &state, in ); - return out; + fillQT(&state, in); + return out; } QTNode * -QTNCopy( QTNode* in, MemoryType memtype ) { - QTNode *out = (QTNode*)MEMALLOC( memtype, sizeof(QTNode) ); +QTNCopy(QTNode * in, MemoryType memtype) +{ + QTNode *out = (QTNode *) MEMALLOC(memtype, sizeof(QTNode)); *out = *in; - out->valnode = (ITEM*)MEMALLOC( memtype, sizeof(ITEM) ); + out->valnode = (ITEM *) MEMALLOC(memtype, sizeof(ITEM)); *(out->valnode) = *(in->valnode); out->flags |= QTN_NEEDFREE; - - if ( in->valnode->type == VAL ) { - out->word = MEMALLOC( memtype, in->valnode->length + 1 ); - memcpy( out->word, in->word, in->valnode->length ); - out->word[ in->valnode->length ] = '\0'; + + if (in->valnode->type == VAL) + { + out->word = MEMALLOC(memtype, in->valnode->length + 1); + memcpy(out->word, in->word, in->valnode->length); + out->word[in->valnode->length] = '\0'; out->flags |= QTN_WORDFREE; - } else { - int i; + } + else + { + int i; - out->child = (QTNode**)MEMALLOC( memtype, sizeof(QTNode*) * in->nchild ); + out->child = (QTNode **) MEMALLOC(memtype, sizeof(QTNode *) * in->nchild); - for(i=0;i<in->nchild;i++) - out->child[i] = QTNCopy( in->child[i], memtype ); - } + for (i = 0; i < in->nchild; i++) + out->child[i] = QTNCopy(in->child[i], memtype); + } return out; } diff --git a/contrib/tsearch2/query_util.h b/contrib/tsearch2/query_util.h index cf3900925a..484c7f383c 100644 --- a/contrib/tsearch2/query_util.h +++ b/contrib/tsearch2/query_util.h @@ -6,39 +6,41 @@ #include "query.h" -typedef struct QTNode { - ITEM *valnode; - uint32 flags; - int4 nchild; - char *word; - uint32 sign; - struct QTNode **child; -} QTNode; - -#define QTN_NEEDFREE 0x01 -#define QTN_NOCHANGE 0x02 -#define QTN_WORDFREE 0x04 - -typedef enum { +typedef struct QTNode +{ + ITEM *valnode; + uint32 flags; + int4 nchild; + char *word; + uint32 sign; + struct QTNode **child; +} QTNode; + +#define QTN_NEEDFREE 0x01 +#define QTN_NOCHANGE 0x02 +#define QTN_WORDFREE 0x04 + +typedef enum +{ PlainMemory, SPIMemory, AggMemory -} MemoryType; +} MemoryType; -QTNode* QT2QTN( ITEM *in, char *operand ); -QUERYTYPE* QTN2QT( QTNode* in, MemoryType memtype ); -void QTNFree( QTNode* in ); -void QTNSort( QTNode* in ); -void QTNTernary( QTNode* in ); -void QTNBinary( QTNode* in ); -int QTNodeCompare( QTNode *an, QTNode *bn ); -QTNode* QTNCopy( QTNode* in, MemoryType memtype); -bool QTNEq( QTNode* a, QTNode* b ); +QTNode *QT2QTN(ITEM * in, char *operand); +QUERYTYPE *QTN2QT(QTNode * in, MemoryType memtype); +void QTNFree(QTNode * in); +void QTNSort(QTNode * in); +void QTNTernary(QTNode * in); +void QTNBinary(QTNode * in); +int QTNodeCompare(QTNode * an, QTNode * bn); +QTNode *QTNCopy(QTNode * in, MemoryType memtype); +bool QTNEq(QTNode * a, QTNode * b); -extern MemoryContext AggregateContext; +extern MemoryContext AggregateContext; -#define MEMALLOC(us, s) ( ((us)==SPIMemory) ? SPI_palloc(s) : ( ( (us)==PlainMemory ) ? palloc(s) : MemoryContextAlloc(AggregateContext, (s)) ) ) -#define MEMFREE(us, p) ( ((us)==SPIMemory) ? SPI_pfree(p) : pfree(p) ) +#define MEMALLOC(us, s) ( ((us)==SPIMemory) ? SPI_palloc(s) : ( ( (us)==PlainMemory ) ? palloc(s) : MemoryContextAlloc(AggregateContext, (s)) ) ) +#define MEMFREE(us, p) ( ((us)==SPIMemory) ? SPI_pfree(p) : pfree(p) ) #endif diff --git a/contrib/tsearch2/rank.c b/contrib/tsearch2/rank.c index d5cb777401..a8c30bf329 100644 --- a/contrib/tsearch2/rank.c +++ b/contrib/tsearch2/rank.c @@ -266,8 +266,10 @@ calc_rank_or(float *w, tsvector * t, QUERYTYPE * q) for (i = 0; i < size; i++) { - float resj,wjm; - int4 jm; + float resj, + wjm; + int4 jm; + entry = find_wordentry(t, q, item[i]); if (!entry) continue; @@ -283,28 +285,29 @@ calc_rank_or(float *w, tsvector * t, QUERYTYPE * q) post = POSNULL + 1; } - resj = 0.0; - wjm = -1.0; - jm = 0; - for (j = 0; j < dimt; j++) - { - resj = resj + wpos(post[j])/((j+1)*(j+1)); - if ( wpos(post[j]) > wjm ) { - wjm = wpos(post[j]); - jm = j; - } - } -/* - limit (sum(i/i^2),i->inf) = pi^2/6 - resj = sum(wi/i^2),i=1,noccurence, - wi - should be sorted desc, - don't sort for now, just choose maximum weight. This should be corrected + resj = 0.0; + wjm = -1.0; + jm = 0; + for (j = 0; j < dimt; j++) + { + resj = resj + wpos(post[j]) / ((j + 1) * (j + 1)); + if (wpos(post[j]) > wjm) + { + wjm = wpos(post[j]); + jm = j; + } + } +/* + limit (sum(i/i^2),i->inf) = pi^2/6 + resj = sum(wi/i^2),i=1,noccurence, + wi - should be sorted desc, + don't sort for now, just choose maximum weight. This should be corrected Oleg Bartunov */ - res = res + ( wjm + resj - wjm/((jm+1)*(jm+1)))/1.64493406685; + res = res + (wjm + resj - wjm / ((jm + 1) * (jm + 1))) / 1.64493406685; } - if ( size > 0 ) - res = res /size; + if (size > 0) + res = res / size; pfree(item); return res; } @@ -414,7 +417,7 @@ rank_def(PG_FUNCTION_ARGS) typedef struct { - ITEM **item; + ITEM **item; int16 nitem; bool needfree; int32 pos; @@ -429,53 +432,59 @@ compareDocR(const void *a, const void *b) } static bool -checkcondition_ITEM(void *checkval, ITEM * val) { - return (bool)(val->istrue); +checkcondition_ITEM(void *checkval, ITEM * val) +{ + return (bool) (val->istrue); } static void -reset_istrue_flag(QUERYTYPE *query) { - ITEM *item = GETQUERY(query); - int i; +reset_istrue_flag(QUERYTYPE * query) +{ + ITEM *item = GETQUERY(query); + int i; /* reset istrue flag */ - for(i = 0; i < query->size; i++) { - if ( item->type == VAL ) + for (i = 0; i < query->size; i++) + { + if (item->type == VAL) item->istrue = 0; item++; } } - + static bool Cover(DocRepresentation * doc, int len, QUERYTYPE * query, int *pos, int *p, int *q) { DocRepresentation *ptr; int lastpos = *pos; - int i; - bool found=false; + int i; + bool found = false; reset_istrue_flag(query); - + *p = 0x7fffffff; *q = 0; ptr = doc + *pos; /* find upper bound of cover from current position, move up */ - while (ptr - doc < len) { - for(i=0;i<ptr->nitem;i++) + while (ptr - doc < len) + { + for (i = 0; i < ptr->nitem; i++) ptr->item[i]->istrue = 1; - if ( TS_execute(GETQUERY(query), NULL, false, checkcondition_ITEM) ) { - if (ptr->pos > *q) { + if (TS_execute(GETQUERY(query), NULL, false, checkcondition_ITEM)) + { + if (ptr->pos > *q) + { *q = ptr->pos; lastpos = ptr - doc; found = true; - } + } break; } ptr++; } - if (!found) + if (!found) return false; reset_istrue_flag(query); @@ -483,25 +492,31 @@ Cover(DocRepresentation * doc, int len, QUERYTYPE * query, int *pos, int *p, int ptr = doc + lastpos; /* find lower bound of cover from founded upper bound, move down */ - while (ptr >= doc ) { - for(i=0;i<ptr->nitem;i++) + while (ptr >= doc) + { + for (i = 0; i < ptr->nitem; i++) ptr->item[i]->istrue = 1; - if ( TS_execute(GETQUERY(query), NULL, true, checkcondition_ITEM) ) { - if (ptr->pos < *p) + if (TS_execute(GETQUERY(query), NULL, true, checkcondition_ITEM)) + { + if (ptr->pos < *p) *p = ptr->pos; break; } ptr--; } - if ( *p <= *q ) { - /* set position for next try to next lexeme after begining of founded cover */ - *pos= (ptr-doc) + 1; + if (*p <= *q) + { + /* + * set position for next try to next lexeme after begining of founded + * cover + */ + *pos = (ptr - doc) + 1; return true; } (*pos)++; - return Cover( doc, len, query, pos, p, q ); + return Cover(doc, len, query, pos, p, q); } static DocRepresentation * @@ -550,26 +565,32 @@ get_docrep(tsvector * txt, QUERYTYPE * query, int *doclen) for (j = 0; j < dimt; j++) { - if ( j == 0 ) { - ITEM *kptr, *iptr = item+i; - int k; - + if (j == 0) + { + ITEM *kptr, + *iptr = item + i; + int k; + doc[cur].needfree = false; doc[cur].nitem = 0; - doc[cur].item = (ITEM**)palloc( sizeof(ITEM*) * query->size ); + doc[cur].item = (ITEM **) palloc(sizeof(ITEM *) * query->size); - for(k=0; k < query->size; k++) { - kptr = item+k; - if ( k==i || ( item[k].type == VAL && compareITEM( &kptr, &iptr ) == 0 ) ) { - doc[cur].item[ doc[cur].nitem ] = item+k; + for (k = 0; k < query->size; k++) + { + kptr = item + k; + if (k == i || (item[k].type == VAL && compareITEM(&kptr, &iptr) == 0)) + { + doc[cur].item[doc[cur].nitem] = item + k; doc[cur].nitem++; kptr->istrue = 1; } - } - } else { + } + } + else + { doc[cur].needfree = false; - doc[cur].nitem = doc[cur-1].nitem; - doc[cur].item = doc[cur-1].item; + doc[cur].nitem = doc[cur - 1].nitem; + doc[cur].item = doc[cur - 1].item; } doc[cur].pos = WEP_GETPOS(post[j]); cur++; @@ -604,7 +625,7 @@ rank_cd(PG_FUNCTION_ARGS) len, cur, i, - doclen=0; + doclen = 0; doc = get_docrep(txt, query, &doclen); if (!doc) @@ -640,9 +661,9 @@ rank_cd(PG_FUNCTION_ARGS) elog(ERROR, "unrecognized normalization method: %d", method); } - for(i=0;i<doclen;i++) - if ( doc[i].needfree ) - pfree( doc[i].item ); + for (i = 0; i < doclen; i++) + if (doc[i].needfree) + pfree(doc[i].item); pfree(doc); PG_FREE_IF_COPY(txt, 1); PG_FREE_IF_COPY(query, 2); @@ -784,9 +805,9 @@ get_covers(PG_FUNCTION_ARGS) VARATT_SIZEP(out) = cptr - ((char *) out); pfree(dw); - for(i=0;i<rlen;i++) - if ( doc[i].needfree ) - pfree( doc[i].item ); + for (i = 0; i < rlen; i++) + if (doc[i].needfree) + pfree(doc[i].item); pfree(doc); PG_FREE_IF_COPY(txt, 0); diff --git a/contrib/tsearch2/snowball/api.h b/contrib/tsearch2/snowball/api.h index fb0a69469c..a66935efcc 100644 --- a/contrib/tsearch2/snowball/api.h +++ b/contrib/tsearch2/snowball/api.h @@ -23,7 +23,7 @@ struct SN_env int S_size; int I_size; int B_size; - symbol **S; + symbol **S; int *I; symbol *B; }; diff --git a/contrib/tsearch2/snowball/english_stem.c b/contrib/tsearch2/snowball/english_stem.c index de4f99114f..ccb3d12988 100644 --- a/contrib/tsearch2/snowball/english_stem.c +++ b/contrib/tsearch2/snowball/english_stem.c @@ -28,8 +28,8 @@ static symbol s_0_1[5] = {'g', 'e', 'n', 'e', 'r'}; static struct among a_0[2] = { - /* 0 */ {6, s_0_0, -1, -1, 0}, - /* 1 */ {5, s_0_1, -1, -1, 0} + /* 0 */ {6, s_0_0, -1, -1, 0}, + /* 1 */ {5, s_0_1, -1, -1, 0} }; static symbol s_1_0[1] = {'\''}; @@ -38,9 +38,9 @@ static symbol s_1_2[2] = {'\'', 's'}; static struct among a_1[3] = { - /* 0 */ {1, s_1_0, -1, 1, 0}, - /* 1 */ {3, s_1_1, 0, 1, 0}, - /* 2 */ {2, s_1_2, -1, 1, 0} + /* 0 */ {1, s_1_0, -1, 1, 0}, + /* 1 */ {3, s_1_1, 0, 1, 0}, + /* 2 */ {2, s_1_2, -1, 1, 0} }; static symbol s_2_0[3] = {'i', 'e', 'd'}; @@ -52,12 +52,12 @@ static symbol s_2_5[2] = {'u', 's'}; static struct among a_2[6] = { - /* 0 */ {3, s_2_0, -1, 2, 0}, - /* 1 */ {1, s_2_1, -1, 3, 0}, - /* 2 */ {3, s_2_2, 1, 2, 0}, - /* 3 */ {4, s_2_3, 1, 1, 0}, - /* 4 */ {2, s_2_4, 1, -1, 0}, - /* 5 */ {2, s_2_5, 1, -1, 0} + /* 0 */ {3, s_2_0, -1, 2, 0}, + /* 1 */ {1, s_2_1, -1, 3, 0}, + /* 2 */ {3, s_2_2, 1, 2, 0}, + /* 3 */ {4, s_2_3, 1, 1, 0}, + /* 4 */ {2, s_2_4, 1, -1, 0}, + /* 5 */ {2, s_2_5, 1, -1, 0} }; static symbol s_3_1[2] = {'b', 'b'}; @@ -75,16 +75,16 @@ static symbol s_3_12[2] = {'i', 'z'}; static struct among a_3[13] = { - /* 0 */ {0, 0, -1, 3, 0}, - /* 1 */ {2, s_3_1, 0, 2, 0}, - /* 2 */ {2, s_3_2, 0, 2, 0}, - /* 3 */ {2, s_3_3, 0, 2, 0}, - /* 4 */ {2, s_3_4, 0, 2, 0}, - /* 5 */ {2, s_3_5, 0, 1, 0}, - /* 6 */ {2, s_3_6, 0, 2, 0}, - /* 7 */ {2, s_3_7, 0, 2, 0}, - /* 8 */ {2, s_3_8, 0, 2, 0}, - /* 9 */ {2, s_3_9, 0, 2, 0}, + /* 0 */ {0, 0, -1, 3, 0}, + /* 1 */ {2, s_3_1, 0, 2, 0}, + /* 2 */ {2, s_3_2, 0, 2, 0}, + /* 3 */ {2, s_3_3, 0, 2, 0}, + /* 4 */ {2, s_3_4, 0, 2, 0}, + /* 5 */ {2, s_3_5, 0, 1, 0}, + /* 6 */ {2, s_3_6, 0, 2, 0}, + /* 7 */ {2, s_3_7, 0, 2, 0}, + /* 8 */ {2, s_3_8, 0, 2, 0}, + /* 9 */ {2, s_3_9, 0, 2, 0}, /* 10 */ {2, s_3_10, 0, 1, 0}, /* 11 */ {2, s_3_11, 0, 2, 0}, /* 12 */ {2, s_3_12, 0, 1, 0} @@ -99,12 +99,12 @@ static symbol s_4_5[5] = {'i', 'n', 'g', 'l', 'y'}; static struct among a_4[6] = { - /* 0 */ {2, s_4_0, -1, 2, 0}, - /* 1 */ {3, s_4_1, 0, 1, 0}, - /* 2 */ {3, s_4_2, -1, 2, 0}, - /* 3 */ {4, s_4_3, -1, 2, 0}, - /* 4 */ {5, s_4_4, 3, 1, 0}, - /* 5 */ {5, s_4_5, -1, 2, 0} + /* 0 */ {2, s_4_0, -1, 2, 0}, + /* 1 */ {3, s_4_1, 0, 1, 0}, + /* 2 */ {3, s_4_2, -1, 2, 0}, + /* 3 */ {4, s_4_3, -1, 2, 0}, + /* 4 */ {5, s_4_4, 3, 1, 0}, + /* 5 */ {5, s_4_5, -1, 2, 0} }; static symbol s_5_0[4] = {'a', 'n', 'c', 'i'}; @@ -134,16 +134,16 @@ static symbol s_5_23[7] = {'o', 'u', 's', 'n', 'e', 's', 's'}; static struct among a_5[24] = { - /* 0 */ {4, s_5_0, -1, 3, 0}, - /* 1 */ {4, s_5_1, -1, 2, 0}, - /* 2 */ {3, s_5_2, -1, 13, 0}, - /* 3 */ {2, s_5_3, -1, 16, 0}, - /* 4 */ {3, s_5_4, 3, 12, 0}, - /* 5 */ {4, s_5_5, 4, 4, 0}, - /* 6 */ {4, s_5_6, 3, 8, 0}, - /* 7 */ {5, s_5_7, 3, 14, 0}, - /* 8 */ {6, s_5_8, 3, 15, 0}, - /* 9 */ {5, s_5_9, 3, 10, 0}, + /* 0 */ {4, s_5_0, -1, 3, 0}, + /* 1 */ {4, s_5_1, -1, 2, 0}, + /* 2 */ {3, s_5_2, -1, 13, 0}, + /* 3 */ {2, s_5_3, -1, 16, 0}, + /* 4 */ {3, s_5_4, 3, 12, 0}, + /* 5 */ {4, s_5_5, 4, 4, 0}, + /* 6 */ {4, s_5_6, 3, 8, 0}, + /* 7 */ {5, s_5_7, 3, 14, 0}, + /* 8 */ {6, s_5_8, 3, 15, 0}, + /* 9 */ {5, s_5_9, 3, 10, 0}, /* 10 */ {5, s_5_10, 3, 5, 0}, /* 11 */ {5, s_5_11, -1, 8, 0}, /* 12 */ {6, s_5_12, -1, 12, 0}, @@ -172,15 +172,15 @@ static symbol s_6_8[4] = {'n', 'e', 's', 's'}; static struct among a_6[9] = { - /* 0 */ {5, s_6_0, -1, 4, 0}, - /* 1 */ {5, s_6_1, -1, 6, 0}, - /* 2 */ {5, s_6_2, -1, 3, 0}, - /* 3 */ {5, s_6_3, -1, 4, 0}, - /* 4 */ {4, s_6_4, -1, 4, 0}, - /* 5 */ {6, s_6_5, -1, 1, 0}, - /* 6 */ {7, s_6_6, 5, 2, 0}, - /* 7 */ {3, s_6_7, -1, 5, 0}, - /* 8 */ {4, s_6_8, -1, 5, 0} + /* 0 */ {5, s_6_0, -1, 4, 0}, + /* 1 */ {5, s_6_1, -1, 6, 0}, + /* 2 */ {5, s_6_2, -1, 3, 0}, + /* 3 */ {5, s_6_3, -1, 4, 0}, + /* 4 */ {4, s_6_4, -1, 4, 0}, + /* 5 */ {6, s_6_5, -1, 1, 0}, + /* 6 */ {7, s_6_6, 5, 2, 0}, + /* 7 */ {3, s_6_7, -1, 5, 0}, + /* 8 */ {4, s_6_8, -1, 5, 0} }; static symbol s_7_0[2] = {'i', 'c'}; @@ -204,16 +204,16 @@ static symbol s_7_17[5] = {'e', 'm', 'e', 'n', 't'}; static struct among a_7[18] = { - /* 0 */ {2, s_7_0, -1, 1, 0}, - /* 1 */ {4, s_7_1, -1, 1, 0}, - /* 2 */ {4, s_7_2, -1, 1, 0}, - /* 3 */ {4, s_7_3, -1, 1, 0}, - /* 4 */ {4, s_7_4, -1, 1, 0}, - /* 5 */ {3, s_7_5, -1, 1, 0}, - /* 6 */ {3, s_7_6, -1, 1, 0}, - /* 7 */ {3, s_7_7, -1, 1, 0}, - /* 8 */ {3, s_7_8, -1, 1, 0}, - /* 9 */ {2, s_7_9, -1, 1, 0}, + /* 0 */ {2, s_7_0, -1, 1, 0}, + /* 1 */ {4, s_7_1, -1, 1, 0}, + /* 2 */ {4, s_7_2, -1, 1, 0}, + /* 3 */ {4, s_7_3, -1, 1, 0}, + /* 4 */ {4, s_7_4, -1, 1, 0}, + /* 5 */ {3, s_7_5, -1, 1, 0}, + /* 6 */ {3, s_7_6, -1, 1, 0}, + /* 7 */ {3, s_7_7, -1, 1, 0}, + /* 8 */ {3, s_7_8, -1, 1, 0}, + /* 9 */ {2, s_7_9, -1, 1, 0}, /* 10 */ {3, s_7_10, -1, 1, 0}, /* 11 */ {3, s_7_11, -1, 2, 0}, /* 12 */ {2, s_7_12, -1, 1, 0}, @@ -229,8 +229,8 @@ static symbol s_8_1[1] = {'l'}; static struct among a_8[2] = { - /* 0 */ {1, s_8_0, -1, 1, 0}, - /* 1 */ {1, s_8_1, -1, 2, 0} + /* 0 */ {1, s_8_0, -1, 1, 0}, + /* 1 */ {1, s_8_1, -1, 2, 0} }; static symbol s_9_0[7] = {'s', 'u', 'c', 'c', 'e', 'e', 'd'}; @@ -244,14 +244,14 @@ static symbol s_9_7[6] = {'o', 'u', 't', 'i', 'n', 'g'}; static struct among a_9[8] = { - /* 0 */ {7, s_9_0, -1, -1, 0}, - /* 1 */ {7, s_9_1, -1, -1, 0}, - /* 2 */ {6, s_9_2, -1, -1, 0}, - /* 3 */ {7, s_9_3, -1, -1, 0}, - /* 4 */ {6, s_9_4, -1, -1, 0}, - /* 5 */ {7, s_9_5, -1, -1, 0}, - /* 6 */ {7, s_9_6, -1, -1, 0}, - /* 7 */ {6, s_9_7, -1, -1, 0} + /* 0 */ {7, s_9_0, -1, -1, 0}, + /* 1 */ {7, s_9_1, -1, -1, 0}, + /* 2 */ {6, s_9_2, -1, -1, 0}, + /* 3 */ {7, s_9_3, -1, -1, 0}, + /* 4 */ {6, s_9_4, -1, -1, 0}, + /* 5 */ {7, s_9_5, -1, -1, 0}, + /* 6 */ {7, s_9_6, -1, -1, 0}, + /* 7 */ {6, s_9_7, -1, -1, 0} }; static symbol s_10_0[5] = {'a', 'n', 'd', 'e', 's'}; @@ -275,16 +275,16 @@ static symbol s_10_17[4] = {'u', 'g', 'l', 'y'}; static struct among a_10[18] = { - /* 0 */ {5, s_10_0, -1, -1, 0}, - /* 1 */ {5, s_10_1, -1, -1, 0}, - /* 2 */ {4, s_10_2, -1, -1, 0}, - /* 3 */ {6, s_10_3, -1, -1, 0}, - /* 4 */ {5, s_10_4, -1, 3, 0}, - /* 5 */ {5, s_10_5, -1, 9, 0}, - /* 6 */ {6, s_10_6, -1, 7, 0}, - /* 7 */ {4, s_10_7, -1, -1, 0}, - /* 8 */ {4, s_10_8, -1, 6, 0}, - /* 9 */ {5, s_10_9, -1, 4, 0}, + /* 0 */ {5, s_10_0, -1, -1, 0}, + /* 1 */ {5, s_10_1, -1, -1, 0}, + /* 2 */ {4, s_10_2, -1, -1, 0}, + /* 3 */ {6, s_10_3, -1, -1, 0}, + /* 4 */ {5, s_10_4, -1, 3, 0}, + /* 5 */ {5, s_10_5, -1, 9, 0}, + /* 6 */ {6, s_10_6, -1, 7, 0}, + /* 7 */ {4, s_10_7, -1, -1, 0}, + /* 8 */ {4, s_10_8, -1, 6, 0}, + /* 9 */ {5, s_10_9, -1, 4, 0}, /* 10 */ {4, s_10_10, -1, -1, 0}, /* 11 */ {4, s_10_11, -1, 10, 0}, /* 12 */ {6, s_10_12, -1, 11, 0}, @@ -1609,12 +1609,14 @@ lab0: return 1; } -extern struct SN_env *english_ISO_8859_1_create_env(void) +extern struct SN_env * +english_ISO_8859_1_create_env(void) { return SN_create_env(0, 2, 1); } -extern void english_ISO_8859_1_close_env(struct SN_env * z) +extern void +english_ISO_8859_1_close_env(struct SN_env * z) { SN_close_env(z); } diff --git a/contrib/tsearch2/snowball/english_stem.h b/contrib/tsearch2/snowball/english_stem.h index 8a3c3816d6..c889c7bfa9 100644 --- a/contrib/tsearch2/snowball/english_stem.h +++ b/contrib/tsearch2/snowball/english_stem.h @@ -6,10 +6,10 @@ extern "C" { #endif - extern struct SN_env *english_ISO_8859_1_create_env(void); - extern void english_ISO_8859_1_close_env(struct SN_env * z); +extern struct SN_env *english_ISO_8859_1_create_env(void); +extern void english_ISO_8859_1_close_env(struct SN_env * z); - extern int english_ISO_8859_1_stem(struct SN_env * z); +extern int english_ISO_8859_1_stem(struct SN_env * z); #ifdef __cplusplus } diff --git a/contrib/tsearch2/snowball/russian_stem.c b/contrib/tsearch2/snowball/russian_stem.c index 213e88f7b9..a9558b3ab5 100644 --- a/contrib/tsearch2/snowball/russian_stem.c +++ b/contrib/tsearch2/snowball/russian_stem.c @@ -30,15 +30,15 @@ static symbol s_0_8[6] = {0xD9, 0xD7, 0xDB, 0xC9, 0xD3, 0xD8}; static struct among a_0[9] = { - /* 0 */ {3, s_0_0, -1, 1, 0}, - /* 1 */ {4, s_0_1, 0, 2, 0}, - /* 2 */ {4, s_0_2, 0, 2, 0}, - /* 3 */ {1, s_0_3, -1, 1, 0}, - /* 4 */ {2, s_0_4, 3, 2, 0}, - /* 5 */ {2, s_0_5, 3, 2, 0}, - /* 6 */ {5, s_0_6, -1, 1, 0}, - /* 7 */ {6, s_0_7, 6, 2, 0}, - /* 8 */ {6, s_0_8, 6, 2, 0} + /* 0 */ {3, s_0_0, -1, 1, 0}, + /* 1 */ {4, s_0_1, 0, 2, 0}, + /* 2 */ {4, s_0_2, 0, 2, 0}, + /* 3 */ {1, s_0_3, -1, 1, 0}, + /* 4 */ {2, s_0_4, 3, 2, 0}, + /* 5 */ {2, s_0_5, 3, 2, 0}, + /* 6 */ {5, s_0_6, -1, 1, 0}, + /* 7 */ {6, s_0_7, 6, 2, 0}, + /* 8 */ {6, s_0_8, 6, 2, 0} }; static symbol s_1_0[2] = {0xC0, 0xC0}; @@ -70,16 +70,16 @@ static symbol s_1_25[3] = {0xCF, 0xCD, 0xD5}; static struct among a_1[26] = { - /* 0 */ {2, s_1_0, -1, 1, 0}, - /* 1 */ {2, s_1_1, -1, 1, 0}, - /* 2 */ {2, s_1_2, -1, 1, 0}, - /* 3 */ {2, s_1_3, -1, 1, 0}, - /* 4 */ {2, s_1_4, -1, 1, 0}, - /* 5 */ {2, s_1_5, -1, 1, 0}, - /* 6 */ {2, s_1_6, -1, 1, 0}, - /* 7 */ {2, s_1_7, -1, 1, 0}, - /* 8 */ {2, s_1_8, -1, 1, 0}, - /* 9 */ {2, s_1_9, -1, 1, 0}, + /* 0 */ {2, s_1_0, -1, 1, 0}, + /* 1 */ {2, s_1_1, -1, 1, 0}, + /* 2 */ {2, s_1_2, -1, 1, 0}, + /* 3 */ {2, s_1_3, -1, 1, 0}, + /* 4 */ {2, s_1_4, -1, 1, 0}, + /* 5 */ {2, s_1_5, -1, 1, 0}, + /* 6 */ {2, s_1_6, -1, 1, 0}, + /* 7 */ {2, s_1_7, -1, 1, 0}, + /* 8 */ {2, s_1_8, -1, 1, 0}, + /* 9 */ {2, s_1_9, -1, 1, 0}, /* 10 */ {3, s_1_10, -1, 1, 0}, /* 11 */ {3, s_1_11, -1, 1, 0}, /* 12 */ {2, s_1_12, -1, 1, 0}, @@ -109,14 +109,14 @@ static symbol s_2_7[3] = {0xD5, 0xC0, 0xDD}; static struct among a_2[8] = { - /* 0 */ {2, s_2_0, -1, 1, 0}, - /* 1 */ {2, s_2_1, -1, 1, 0}, - /* 2 */ {2, s_2_2, -1, 1, 0}, - /* 3 */ {3, s_2_3, 2, 2, 0}, - /* 4 */ {3, s_2_4, 2, 2, 0}, - /* 5 */ {1, s_2_5, -1, 1, 0}, - /* 6 */ {2, s_2_6, 5, 1, 0}, - /* 7 */ {3, s_2_7, 6, 2, 0} + /* 0 */ {2, s_2_0, -1, 1, 0}, + /* 1 */ {2, s_2_1, -1, 1, 0}, + /* 2 */ {2, s_2_2, -1, 1, 0}, + /* 3 */ {3, s_2_3, 2, 2, 0}, + /* 4 */ {3, s_2_4, 2, 2, 0}, + /* 5 */ {1, s_2_5, -1, 1, 0}, + /* 6 */ {2, s_2_6, 5, 1, 0}, + /* 7 */ {3, s_2_7, 6, 2, 0} }; static symbol s_3_0[2] = {0xD3, 0xD1}; @@ -124,8 +124,8 @@ static symbol s_3_1[2] = {0xD3, 0xD8}; static struct among a_3[2] = { - /* 0 */ {2, s_3_0, -1, 1, 0}, - /* 1 */ {2, s_3_1, -1, 1, 0} + /* 0 */ {2, s_3_0, -1, 1, 0}, + /* 1 */ {2, s_3_1, -1, 1, 0} }; static symbol s_4_0[1] = {0xC0}; @@ -177,16 +177,16 @@ static symbol s_4_45[3] = {0xC5, 0xCE, 0xD9}; static struct among a_4[46] = { - /* 0 */ {1, s_4_0, -1, 2, 0}, - /* 1 */ {2, s_4_1, 0, 2, 0}, - /* 2 */ {2, s_4_2, -1, 1, 0}, - /* 3 */ {3, s_4_3, 2, 2, 0}, - /* 4 */ {3, s_4_4, 2, 2, 0}, - /* 5 */ {2, s_4_5, -1, 1, 0}, - /* 6 */ {3, s_4_6, 5, 2, 0}, - /* 7 */ {3, s_4_7, -1, 1, 0}, - /* 8 */ {3, s_4_8, -1, 2, 0}, - /* 9 */ {3, s_4_9, -1, 1, 0}, + /* 0 */ {1, s_4_0, -1, 2, 0}, + /* 1 */ {2, s_4_1, 0, 2, 0}, + /* 2 */ {2, s_4_2, -1, 1, 0}, + /* 3 */ {3, s_4_3, 2, 2, 0}, + /* 4 */ {3, s_4_4, 2, 2, 0}, + /* 5 */ {2, s_4_5, -1, 1, 0}, + /* 6 */ {3, s_4_6, 5, 2, 0}, + /* 7 */ {3, s_4_7, -1, 1, 0}, + /* 8 */ {3, s_4_8, -1, 2, 0}, + /* 9 */ {3, s_4_9, -1, 1, 0}, /* 10 */ {4, s_4_10, 9, 2, 0}, /* 11 */ {4, s_4_11, 9, 2, 0}, /* 12 */ {2, s_4_12, -1, 1, 0}, @@ -264,16 +264,16 @@ static symbol s_5_35[1] = {0xD9}; static struct among a_5[36] = { - /* 0 */ {1, s_5_0, -1, 1, 0}, - /* 1 */ {2, s_5_1, 0, 1, 0}, - /* 2 */ {2, s_5_2, 0, 1, 0}, - /* 3 */ {1, s_5_3, -1, 1, 0}, - /* 4 */ {1, s_5_4, -1, 1, 0}, - /* 5 */ {2, s_5_5, 4, 1, 0}, - /* 6 */ {2, s_5_6, 4, 1, 0}, - /* 7 */ {2, s_5_7, -1, 1, 0}, - /* 8 */ {2, s_5_8, -1, 1, 0}, - /* 9 */ {3, s_5_9, 8, 1, 0}, + /* 0 */ {1, s_5_0, -1, 1, 0}, + /* 1 */ {2, s_5_1, 0, 1, 0}, + /* 2 */ {2, s_5_2, 0, 1, 0}, + /* 3 */ {1, s_5_3, -1, 1, 0}, + /* 4 */ {1, s_5_4, -1, 1, 0}, + /* 5 */ {2, s_5_5, 4, 1, 0}, + /* 6 */ {2, s_5_6, 4, 1, 0}, + /* 7 */ {2, s_5_7, -1, 1, 0}, + /* 8 */ {2, s_5_8, -1, 1, 0}, + /* 9 */ {3, s_5_9, 8, 1, 0}, /* 10 */ {1, s_5_10, -1, 1, 0}, /* 11 */ {2, s_5_11, 10, 1, 0}, /* 12 */ {2, s_5_12, 10, 1, 0}, @@ -307,8 +307,8 @@ static symbol s_6_1[4] = {0xCF, 0xD3, 0xD4, 0xD8}; static struct among a_6[2] = { - /* 0 */ {3, s_6_0, -1, 1, 0}, - /* 1 */ {4, s_6_1, -1, 1, 0} + /* 0 */ {3, s_6_0, -1, 1, 0}, + /* 1 */ {4, s_6_1, -1, 1, 0} }; static symbol s_7_0[4] = {0xC5, 0xCA, 0xDB, 0xC5}; @@ -318,10 +318,10 @@ static symbol s_7_3[3] = {0xC5, 0xCA, 0xDB}; static struct among a_7[4] = { - /* 0 */ {4, s_7_0, -1, 1, 0}, - /* 1 */ {1, s_7_1, -1, 2, 0}, - /* 2 */ {1, s_7_2, -1, 3, 0}, - /* 3 */ {3, s_7_3, -1, 1, 0} + /* 0 */ {4, s_7_0, -1, 1, 0}, + /* 1 */ {1, s_7_1, -1, 2, 0}, + /* 2 */ {1, s_7_2, -1, 3, 0}, + /* 3 */ {3, s_7_3, -1, 1, 0} }; static unsigned char g_v[] = {35, 130, 34, 18}; @@ -915,12 +915,14 @@ lab0: return 1; } -extern struct SN_env *russian_KOI8_R_create_env(void) +extern struct SN_env * +russian_KOI8_R_create_env(void) { return SN_create_env(0, 2, 0); } -extern void russian_KOI8_R_close_env(struct SN_env * z) +extern void +russian_KOI8_R_close_env(struct SN_env * z) { SN_close_env(z); } diff --git a/contrib/tsearch2/snowball/russian_stem.h b/contrib/tsearch2/snowball/russian_stem.h index 84941b037f..217c20abdd 100644 --- a/contrib/tsearch2/snowball/russian_stem.h +++ b/contrib/tsearch2/snowball/russian_stem.h @@ -6,10 +6,10 @@ extern "C" { #endif - extern struct SN_env *russian_KOI8_R_create_env(void); - extern void russian_KOI8_R_close_env(struct SN_env * z); +extern struct SN_env *russian_KOI8_R_create_env(void); +extern void russian_KOI8_R_close_env(struct SN_env * z); - extern int russian_KOI8_R_stem(struct SN_env * z); +extern int russian_KOI8_R_stem(struct SN_env * z); #ifdef __cplusplus } diff --git a/contrib/tsearch2/ts_locale.c b/contrib/tsearch2/ts_locale.c index 8bb453276b..5dc67abc8d 100644 --- a/contrib/tsearch2/ts_locale.c +++ b/contrib/tsearch2/ts_locale.c @@ -8,58 +8,64 @@ #if defined(TS_USE_WIDE) && defined(WIN32) size_t -wchar2char( char *to, const wchar_t *from, size_t len ) { - if (GetDatabaseEncoding() == PG_UTF8) { - int r, nbytes; - - if (len==0) +wchar2char(char *to, const wchar_t *from, size_t len) +{ + if (GetDatabaseEncoding() == PG_UTF8) + { + int r, + nbytes; + + if (len == 0) return 0; /* in any case, *to should be allocated with enough space */ nbytes = WideCharToMultiByte(CP_UTF8, 0, from, len, NULL, 0, NULL, NULL); - if ( nbytes==0 ) + if (nbytes == 0) ereport(ERROR, - (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), - errmsg("UTF-16 to UTF-8 translation failed: %lu", - GetLastError()))); + (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), + errmsg("UTF-16 to UTF-8 translation failed: %lu", + GetLastError()))); r = WideCharToMultiByte(CP_UTF8, 0, from, len, to, nbytes, - NULL, NULL); + NULL, NULL); - if ( r==0 ) + if (r == 0) ereport(ERROR, - (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), - errmsg("UTF-16 to UTF-8 translation failed: %lu", - GetLastError()))); + (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), + errmsg("UTF-16 to UTF-8 translation failed: %lu", + GetLastError()))); return r; } return wcstombs(to, from, len); } -size_t -char2wchar( wchar_t *to, const char *from, size_t len ) { - if (GetDatabaseEncoding() == PG_UTF8) { - int r; +size_t +char2wchar(wchar_t *to, const char *from, size_t len) +{ + if (GetDatabaseEncoding() == PG_UTF8) + { + int r; - if (len==0) + if (len == 0) return 0; r = MultiByteToWideChar(CP_UTF8, 0, from, len, to, len); - if (!r) { + if (!r) + { pg_verifymbstr(from, len, false); ereport(ERROR, - (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), - errmsg("invalid multibyte character for locale"), - errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding."))); + (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE), + errmsg("invalid multibyte character for locale"), + errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding."))); } - Assert( r <= len ); + Assert(r <= len); return r; } - + return mbstowcs(to, from, len); } diff --git a/contrib/tsearch2/ts_locale.h b/contrib/tsearch2/ts_locale.h index 4935e70c6a..905eb94af0 100644 --- a/contrib/tsearch2/ts_locale.h +++ b/contrib/tsearch2/ts_locale.h @@ -22,17 +22,15 @@ #ifdef WIN32 -size_t wchar2char( char *to, const wchar_t *from, size_t len ); -size_t char2wchar( wchar_t *to, const char *from, size_t len ); - -#else /* WIN32 */ +size_t wchar2char(char *to, const wchar_t *from, size_t len); +size_t char2wchar(wchar_t *to, const char *from, size_t len); +#else /* WIN32 */ /* correct mbstowcs */ #define char2wchar mbstowcs #define wchar2char wcstombs +#endif /* WIN32 */ +#endif /* defined(HAVE_WCSTOMBS) && + * defined(HAVE_TOWLOWER) */ -#endif /* WIN32 */ - -#endif /* defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER) */ - -#endif /* __TSLOCALE_H__ */ +#endif /* __TSLOCALE_H__ */ diff --git a/contrib/tsearch2/wordparser/parser.c b/contrib/tsearch2/wordparser/parser.c index 565c3c1741..282acf6e36 100644 --- a/contrib/tsearch2/wordparser/parser.c +++ b/contrib/tsearch2/wordparser/parser.c @@ -9,11 +9,12 @@ #include "ts_locale.h" -static TParserPosition* -newTParserPosition(TParserPosition *prev) { - TParserPosition *res = (TParserPosition*)palloc(sizeof(TParserPosition)); +static TParserPosition * +newTParserPosition(TParserPosition * prev) +{ + TParserPosition *res = (TParserPosition *) palloc(sizeof(TParserPosition)); - if ( prev ) + if (prev) memcpy(res, prev, sizeof(TParserPosition)); else memset(res, 0, sizeof(TParserPosition)); @@ -25,29 +26,33 @@ newTParserPosition(TParserPosition *prev) { return res; } -TParser* -TParserInit( char *str, int len ) { - TParser *prs = (TParser*)palloc0( sizeof(TParser) ); +TParser * +TParserInit(char *str, int len) +{ + TParser *prs = (TParser *) palloc0(sizeof(TParser)); prs->charmaxlen = pg_database_encoding_max_length(); - prs->str = str; + prs->str = str; prs->lenstr = len; #ifdef TS_USE_WIDE - /* - * Use wide char code only when max encoding length > 1 and ctype != C. - * Some operating systems fail with multi-byte encodings and a C locale. - * Also, for a C locale there is no need to process as multibyte. - * From backend/utils/adt/oracle_compat.c Teodor - */ - - if ( prs->charmaxlen > 1 && !lc_ctype_is_c() ) { - prs->usewide=true; - prs->wstr = (wchar_t*)palloc( sizeof(wchar_t) * prs->lenstr ); - prs->lenwstr = char2wchar( prs->wstr, prs->str, prs->lenstr ); - } else + + /* + * Use wide char code only when max encoding length > 1 and ctype != C. + * Some operating systems fail with multi-byte encodings and a C locale. + * Also, for a C locale there is no need to process as multibyte. From + * backend/utils/adt/oracle_compat.c Teodor + */ + + if (prs->charmaxlen > 1 && !lc_ctype_is_c()) + { + prs->usewide = true; + prs->wstr = (wchar_t *) palloc(sizeof(wchar_t) * prs->lenstr); + prs->lenwstr = char2wchar(prs->wstr, prs->str, prs->lenstr); + } + else #endif - prs->usewide=false; + prs->usewide = false; prs->state = newTParserPosition(NULL); prs->state->state = TPS_Base; @@ -56,16 +61,19 @@ TParserInit( char *str, int len ) { } void -TParserClose( TParser* prs ) { - while( prs->state ) { +TParserClose(TParser * prs) +{ + while (prs->state) + { TParserPosition *ptr = prs->state->prev; - pfree( prs->state ); + + pfree(prs->state); prs->state = ptr; } - if ( prs->wstr ) - pfree( prs->wstr ); - pfree( prs ); + if (prs->wstr) + pfree(prs->wstr); + pfree(prs); } /* @@ -73,15 +81,15 @@ TParserClose( TParser* prs ) { * working with any possible encodings and locales */ -#ifdef TS_USE_WIDE +#ifdef TS_USE_WIDE -#define p_iswhat(type) \ +#define p_iswhat(type) \ static int \ p_is##type(TParser *prs) { \ Assert( prs->state ); \ - return ( ( prs->usewide ) ? isw##type( (wint_t)*( prs->wstr + prs->state->poschar ) ) : \ + return ( ( prs->usewide ) ? isw##type( (wint_t)*( prs->wstr + prs->state->poschar ) ) : \ is##type( (unsigned char)*( prs->str + prs->state->posbyte ) ) ); \ -} \ +} \ \ static int \ p_isnot##type(TParser *prs) { \ @@ -93,19 +101,19 @@ p_isnot##type(TParser *prs) { \ /* p_iseq should be used only for ascii symbols */ static int -p_iseq(TParser *prs, char c) { - Assert( prs->state ); - return ( ( prs->state->charlen==1 && *( prs->str + prs->state->posbyte ) == c ) ) ? 1 : 0; +p_iseq(TParser * prs, char c) +{ + Assert(prs->state); + return ((prs->state->charlen == 1 && *(prs->str + prs->state->posbyte) == c)) ? 1 : 0; } +#else /* TS_USE_WIDE */ -#else /* TS_USE_WIDE */ - -#define p_iswhat(type) \ +#define p_iswhat(type) \ static int \ p_is##type(TParser *prs) { \ Assert( prs->state ); \ return is##type( (unsigned char)*( prs->str + prs->state->posbyte ) ); \ -} \ +} \ \ static int \ p_isnot##type(TParser *prs) { \ @@ -114,12 +122,12 @@ p_isnot##type(TParser *prs) { \ static int -p_iseq(TParser *prs, char c) { - Assert( prs->state ); - return ( *( prs->str + prs->state->posbyte ) == c ) ? 1 : 0; +p_iseq(TParser * prs, char c) +{ + Assert(prs->state); + return (*(prs->str + prs->state->posbyte) == c) ? 1 : 0; } - -#endif /* TS_USE_WIDE */ +#endif /* TS_USE_WIDE */ p_iswhat(alnum) p_iswhat(alpha) @@ -132,90 +140,114 @@ p_iswhat(upper) p_iswhat(xdigit) static int -p_isEOF(TParser *prs) { - Assert( prs->state ); - return (prs->state->posbyte == prs->lenstr || prs->state->charlen==0) ? 1 : 0; +p_isEOF(TParser * prs) +{ + Assert(prs->state); + return (prs->state->posbyte == prs->lenstr || prs->state->charlen == 0) ? 1 : 0; } static int -p_iseqC(TParser *prs) { - return p_iseq(prs, prs->c); +p_iseqC(TParser * prs) +{ + return p_iseq(prs, prs->c); } static int -p_isneC(TParser *prs) { +p_isneC(TParser * prs) +{ return !p_iseq(prs, prs->c); } static int -p_isascii(TParser *prs) { - return ( prs->state->charlen==1 && isascii( (unsigned char) *( prs->str + prs->state->posbyte ) ) ) ? 1 : 0; +p_isascii(TParser * prs) +{ + return (prs->state->charlen == 1 && isascii((unsigned char) *(prs->str + prs->state->posbyte))) ? 1 : 0; } static int -p_islatin(TParser *prs) { - return ( p_isalpha(prs) && p_isascii(prs) ) ? 1 : 0; +p_islatin(TParser * prs) +{ + return (p_isalpha(prs) && p_isascii(prs)) ? 1 : 0; } static int -p_isnonlatin(TParser *prs) { - return ( p_isalpha(prs) && !p_isascii(prs) ) ? 1 : 0; +p_isnonlatin(TParser * prs) +{ + return (p_isalpha(prs) && !p_isascii(prs)) ? 1 : 0; } -void _make_compiler_happy(void); +void _make_compiler_happy(void); void -_make_compiler_happy(void) { - p_isalnum(NULL); p_isnotalnum(NULL); - p_isalpha(NULL); p_isnotalpha(NULL); - p_isdigit(NULL); p_isnotdigit(NULL); - p_islower(NULL); p_isnotlower(NULL); - p_isprint(NULL); p_isnotprint(NULL); - p_ispunct(NULL); p_isnotpunct(NULL); - p_isspace(NULL); p_isnotspace(NULL); - p_isupper(NULL); p_isnotupper(NULL); - p_isxdigit(NULL); p_isnotxdigit(NULL); - p_isEOF(NULL); - p_iseqC(NULL); p_isneC(NULL); +_make_compiler_happy(void) +{ + p_isalnum(NULL); + p_isnotalnum(NULL); + p_isalpha(NULL); + p_isnotalpha(NULL); + p_isdigit(NULL); + p_isnotdigit(NULL); + p_islower(NULL); + p_isnotlower(NULL); + p_isprint(NULL); + p_isnotprint(NULL); + p_ispunct(NULL); + p_isnotpunct(NULL); + p_isspace(NULL); + p_isnotspace(NULL); + p_isupper(NULL); + p_isnotupper(NULL); + p_isxdigit(NULL); + p_isnotxdigit(NULL); + p_isEOF(NULL); + p_iseqC(NULL); + p_isneC(NULL); } static void -SpecialTags(TParser *prs) { - switch( prs->state->lencharlexeme ) { - case 8: /* </script */ - if ( pg_strncasecmp( prs->lexeme, "</script", 8 ) == 0 ) +SpecialTags(TParser * prs) +{ + switch (prs->state->lencharlexeme) + { + case 8: /* </script */ + if (pg_strncasecmp(prs->lexeme, "</script", 8) == 0) prs->ignore = false; break; - case 7: /* <script || </style */ - if ( pg_strncasecmp( prs->lexeme, "</style", 7 ) == 0 ) + case 7: /* <script || </style */ + if (pg_strncasecmp(prs->lexeme, "</style", 7) == 0) prs->ignore = false; - else if ( pg_strncasecmp( prs->lexeme, "<script", 7 ) == 0 ) + else if (pg_strncasecmp(prs->lexeme, "<script", 7) == 0) prs->ignore = true; break; - case 6: /* <style */ - if ( pg_strncasecmp( prs->lexeme, "<style", 6 ) == 0 ) + case 6: /* <style */ + if (pg_strncasecmp(prs->lexeme, "<style", 6) == 0) prs->ignore = true; break; - default: break; + default: + break; } } static void -SpecialFURL(TParser *prs) { +SpecialFURL(TParser * prs) +{ prs->wanthost = true; prs->state->posbyte -= prs->state->lenbytelexeme; prs->state->poschar -= prs->state->lencharlexeme; } static void -SpecialHyphen(TParser *prs) { +SpecialHyphen(TParser * prs) +{ prs->state->posbyte -= prs->state->lenbytelexeme; prs->state->poschar -= prs->state->lencharlexeme; } static int -p_isstophost(TParser *prs) { - if ( prs->wanthost ) { +p_isstophost(TParser * prs) +{ + if (prs->wanthost) + { prs->wanthost = false; return 1; } @@ -223,21 +255,24 @@ p_isstophost(TParser *prs) { } static int -p_isignore(TParser *prs) { +p_isignore(TParser * prs) +{ return (prs->ignore) ? 1 : 0; } static int -p_ishost(TParser *prs) { - TParser *tmpprs = TParserInit( prs->str+prs->state->posbyte, prs->lenstr - prs->state->posbyte ); - int res = 0; +p_ishost(TParser * prs) +{ + TParser *tmpprs = TParserInit(prs->str + prs->state->posbyte, prs->lenstr - prs->state->posbyte); + int res = 0; - if ( TParserGet(tmpprs) && tmpprs->type == HOST ) { + if (TParserGet(tmpprs) && tmpprs->type == HOST) + { prs->state->posbyte += tmpprs->lenbytelexeme; prs->state->poschar += tmpprs->lencharlexeme; prs->state->lenbytelexeme += tmpprs->lenbytelexeme; prs->state->lencharlexeme += tmpprs->lencharlexeme; - prs->state->charlen = tmpprs->state->charlen; + prs->state->charlen = tmpprs->state->charlen; res = 1; } TParserClose(tmpprs); @@ -246,19 +281,21 @@ p_ishost(TParser *prs) { } static int -p_isURI(TParser *prs) { - TParser *tmpprs = TParserInit( prs->str+prs->state->posbyte, prs->lenstr - prs->state->posbyte ); - int res = 0; +p_isURI(TParser * prs) +{ + TParser *tmpprs = TParserInit(prs->str + prs->state->posbyte, prs->lenstr - prs->state->posbyte); + int res = 0; - tmpprs->state = newTParserPosition( tmpprs->state ); + tmpprs->state = newTParserPosition(tmpprs->state); tmpprs->state->state = TPS_InFileFirst; - if ( TParserGet(tmpprs) && (tmpprs->type == URI || tmpprs->type == FILEPATH) ) { + if (TParserGet(tmpprs) && (tmpprs->type == URI || tmpprs->type == FILEPATH)) + { prs->state->posbyte += tmpprs->lenbytelexeme; prs->state->poschar += tmpprs->lencharlexeme; prs->state->lenbytelexeme += tmpprs->lenbytelexeme; prs->state->lencharlexeme += tmpprs->lencharlexeme; - prs->state->charlen = tmpprs->state->charlen; + prs->state->charlen = tmpprs->state->charlen; res = 1; } TParserClose(tmpprs); @@ -280,715 +317,736 @@ p_isURI(TParser *prs) { #define A_CLRALL 0x0040 static TParserStateActionItem actionTPS_Base[] = { - {p_isEOF, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '<', A_PUSH, TPS_InTagFirst, 0, NULL}, - {p_isignore, 0, A_NEXT, TPS_InSpace, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InLatWord, 0, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InCyrWord, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InUnsignedInt, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InSignedIntFirst, 0, NULL}, - {p_iseqC, '+', A_PUSH, TPS_InSignedIntFirst, 0, NULL}, - {p_iseqC, '&', A_PUSH, TPS_InHTMLEntityFirst, 0, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, - {NULL, 0, A_NEXT, TPS_InSpace, 0, NULL} -}; + {p_isEOF, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '<', A_PUSH, TPS_InTagFirst, 0, NULL}, + {p_isignore, 0, A_NEXT, TPS_InSpace, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InLatWord, 0, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InCyrWord, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InUnsignedInt, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InSignedIntFirst, 0, NULL}, + {p_iseqC, '+', A_PUSH, TPS_InSignedIntFirst, 0, NULL}, + {p_iseqC, '&', A_PUSH, TPS_InHTMLEntityFirst, 0, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, + {NULL, 0, A_NEXT, TPS_InSpace, 0, NULL} +}; static TParserStateActionItem actionTPS_InUWord[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, UWORD, NULL}, - {p_isalnum, 0, A_NEXT, TPS_InUWord, 0, NULL}, - {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, UWORD, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, UWORD, NULL}, + {p_isalnum, 0, A_NEXT, TPS_InUWord, 0, NULL}, + {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, UWORD, NULL} }; static TParserStateActionItem actionTPS_InLatWord[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, LATWORD, NULL}, - {p_islatin, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InFileFirst, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenLatWordFirst,0, NULL}, - {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, - {p_iseqC, ':', A_PUSH, TPS_InProtocolFirst, 0, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, - {p_isdigit, 0, A_PUSH, TPS_InHost, 0, NULL}, - {p_isalnum, 0, A_NEXT, TPS_InUWord, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, LATWORD, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, LATWORD, NULL}, + {p_islatin, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InFileFirst, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenLatWordFirst, 0, NULL}, + {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, + {p_iseqC, ':', A_PUSH, TPS_InProtocolFirst, 0, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, + {p_isdigit, 0, A_PUSH, TPS_InHost, 0, NULL}, + {p_isalnum, 0, A_NEXT, TPS_InUWord, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, LATWORD, NULL} }; static TParserStateActionItem actionTPS_InCyrWord[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, CYRWORD, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_isalnum, 0, A_NEXT, TPS_InUWord, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenCyrWordFirst,0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, CYRWORD, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, CYRWORD, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_isalnum, 0, A_NEXT, TPS_InUWord, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenCyrWordFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, CYRWORD, NULL} }; - + static TParserStateActionItem actionTPS_InUnsignedInt[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, UNSIGNEDINT, NULL}, - {p_isdigit, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InUDecimalFirst, 0, NULL}, - {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {p_islatin, 0, A_PUSH, TPS_InHost, 0, NULL}, - {p_isalpha, 0, A_NEXT, TPS_InUWord, 0, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, UNSIGNEDINT, NULL} -}; - + {p_isEOF, 0, A_BINGO, TPS_Base, UNSIGNEDINT, NULL}, + {p_isdigit, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InUDecimalFirst, 0, NULL}, + {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {p_islatin, 0, A_PUSH, TPS_InHost, 0, NULL}, + {p_isalpha, 0, A_NEXT, TPS_InUWord, 0, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, UNSIGNEDINT, NULL} +}; + static TParserStateActionItem actionTPS_InSignedIntFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT|A_CLEAR, TPS_InSignedInt, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT | A_CLEAR, TPS_InSignedInt, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; - + static TParserStateActionItem actionTPS_InSignedInt[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, SIGNEDINT, NULL}, - {p_isdigit, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InDecimalFirst, 0, NULL}, - {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, SIGNEDINT, NULL} -}; - + {p_isEOF, 0, A_BINGO, TPS_Base, SIGNEDINT, NULL}, + {p_isdigit, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InDecimalFirst, 0, NULL}, + {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, SIGNEDINT, NULL} +}; + static TParserStateActionItem actionTPS_InSpace[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, SPACE, NULL}, - {p_iseqC, '<', A_BINGO, TPS_Base, SPACE, NULL}, - {p_isignore, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_BINGO, TPS_Base, SPACE, NULL}, - {p_iseqC, '+', A_BINGO, TPS_Base, SPACE, NULL}, - {p_iseqC, '&', A_BINGO, TPS_Base, SPACE, NULL}, - {p_iseqC, '/', A_BINGO, TPS_Base, SPACE, NULL}, - {p_isnotalnum, 0, A_NEXT, TPS_InSpace, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, SPACE, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, SPACE, NULL}, + {p_iseqC, '<', A_BINGO, TPS_Base, SPACE, NULL}, + {p_isignore, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_BINGO, TPS_Base, SPACE, NULL}, + {p_iseqC, '+', A_BINGO, TPS_Base, SPACE, NULL}, + {p_iseqC, '&', A_BINGO, TPS_Base, SPACE, NULL}, + {p_iseqC, '/', A_BINGO, TPS_Base, SPACE, NULL}, + {p_isnotalnum, 0, A_NEXT, TPS_InSpace, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, SPACE, NULL} }; static TParserStateActionItem actionTPS_InUDecimalFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InUDecimal, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InUDecimal, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InUDecimal[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, DECIMAL, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InUDecimal, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InVersionFirst, 0, NULL}, - {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, DECIMAL, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, DECIMAL, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InUDecimal, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InVersionFirst, 0, NULL}, + {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, DECIMAL, NULL} }; static TParserStateActionItem actionTPS_InDecimalFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InDecimal, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InDecimal, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InDecimal[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, DECIMAL, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InDecimal, 0, NULL}, - {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, DECIMAL, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, DECIMAL, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InDecimal, 0, NULL}, + {p_iseqC, 'e', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {p_iseqC, 'E', A_PUSH, TPS_InMantissaFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, DECIMAL, NULL} }; static TParserStateActionItem actionTPS_InVersionFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InVersion, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InVersion, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InVersion[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, VERSIONNUMBER, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InVersion, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InVersionFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, VERSIONNUMBER, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, VERSIONNUMBER, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InVersion, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InVersionFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, VERSIONNUMBER, NULL} }; static TParserStateActionItem actionTPS_InMantissaFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InMantissa, 0, NULL}, - {p_iseqC, '+', A_NEXT, TPS_InMantissaSign, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_InMantissaSign, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InMantissa, 0, NULL}, + {p_iseqC, '+', A_NEXT, TPS_InMantissaSign, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_InMantissaSign, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InMantissaSign[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InMantissa, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InMantissa, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InMantissa[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, SCIENTIFIC, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InMantissa, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, SCIENTIFIC, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, SCIENTIFIC, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InMantissa, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, SCIENTIFIC, NULL} }; static TParserStateActionItem actionTPS_InHTMLEntityFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '#', A_NEXT, TPS_InHTMLEntityNumFirst,0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHTMLEntity, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '#', A_NEXT, TPS_InHTMLEntityNumFirst, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHTMLEntity, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHTMLEntity[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHTMLEntity, 0, NULL}, - {p_iseqC, ';', A_NEXT, TPS_InHTMLEntityEnd, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHTMLEntity, 0, NULL}, + {p_iseqC, ';', A_NEXT, TPS_InHTMLEntityEnd, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHTMLEntityNumFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHTMLEntityNum, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHTMLEntityNum, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHTMLEntityNum[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHTMLEntityNum, 0, NULL}, - {p_iseqC, ';', A_NEXT, TPS_InHTMLEntityEnd, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHTMLEntityNum, 0, NULL}, + {p_iseqC, ';', A_NEXT, TPS_InHTMLEntityEnd, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHTMLEntityEnd[] = { - {NULL, 0, A_BINGO|A_CLEAR,TPS_Base, HTMLENTITY, NULL} + {NULL, 0, A_BINGO | A_CLEAR, TPS_Base, HTMLENTITY, NULL} }; static TParserStateActionItem actionTPS_InTagFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InTagCloseFirst, 0, NULL}, - {p_iseqC, '!', A_PUSH, TPS_InCommentFirst, 0, NULL}, - {p_islatin, 0, A_PUSH, TPS_InTag, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InTagCloseFirst, 0, NULL}, + {p_iseqC, '!', A_PUSH, TPS_InCommentFirst, 0, NULL}, + {p_islatin, 0, A_PUSH, TPS_InTag, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InTagCloseFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InTag, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InTag, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InTag[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '>', A_NEXT, TPS_InTagEnd, 0, SpecialTags}, - {p_iseqC, '\'', A_NEXT, TPS_InTagEscapeK, 0, NULL}, - {p_iseqC, '"', A_NEXT, TPS_InTagEscapeKK, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '=', A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '#', A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '%', A_NEXT, TPS_Null, 0, NULL}, - {p_isspace, 0, A_NEXT, TPS_Null, 0, SpecialTags}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '>', A_NEXT, TPS_InTagEnd, 0, SpecialTags}, + {p_iseqC, '\'', A_NEXT, TPS_InTagEscapeK, 0, NULL}, + {p_iseqC, '"', A_NEXT, TPS_InTagEscapeKK, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '=', A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '#', A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '%', A_NEXT, TPS_Null, 0, NULL}, + {p_isspace, 0, A_NEXT, TPS_Null, 0, SpecialTags}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InTagEscapeK[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '\\', A_PUSH, TPS_InTagBackSleshed, 0, NULL}, - {p_iseqC, '\'', A_NEXT, TPS_InTag, 0, NULL}, - {NULL, 0, A_NEXT, TPS_InTagEscapeK, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '\\', A_PUSH, TPS_InTagBackSleshed, 0, NULL}, + {p_iseqC, '\'', A_NEXT, TPS_InTag, 0, NULL}, + {NULL, 0, A_NEXT, TPS_InTagEscapeK, 0, NULL} }; static TParserStateActionItem actionTPS_InTagEscapeKK[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '\\', A_PUSH, TPS_InTagBackSleshed, 0, NULL}, - {p_iseqC, '"', A_NEXT, TPS_InTag, 0, NULL}, - {NULL, 0, A_NEXT, TPS_InTagEscapeKK, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '\\', A_PUSH, TPS_InTagBackSleshed, 0, NULL}, + {p_iseqC, '"', A_NEXT, TPS_InTag, 0, NULL}, + {NULL, 0, A_NEXT, TPS_InTagEscapeKK, 0, NULL} }; static TParserStateActionItem actionTPS_InTagBackSleshed[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {NULL, 0, A_MERGE, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {NULL, 0, A_MERGE, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InTagEnd[] = { - {NULL, 0, A_BINGO|A_CLRALL,TPS_Base, TAG, NULL} + {NULL, 0, A_BINGO | A_CLRALL, TPS_Base, TAG, NULL} }; static TParserStateActionItem actionTPS_InCommentFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_InCommentLast, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_InCommentLast, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InCommentLast[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_InComment, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_InComment, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InComment[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_InCloseCommentFirst,0, NULL}, - {NULL, 0, A_NEXT, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_InCloseCommentFirst, 0, NULL}, + {NULL, 0, A_NEXT, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InCloseCommentFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_InCloseCommentLast, 0, NULL}, - {NULL, 0, A_NEXT, TPS_InComment, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_InCloseCommentLast, 0, NULL}, + {NULL, 0, A_NEXT, TPS_InComment, 0, NULL} }; static TParserStateActionItem actionTPS_InCloseCommentLast[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_Null, 0, NULL}, - {p_iseqC, '>', A_NEXT, TPS_InCommentEnd, 0, NULL}, - {NULL, 0, A_NEXT, TPS_InComment, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_Null, 0, NULL}, + {p_iseqC, '>', A_NEXT, TPS_InCommentEnd, 0, NULL}, + {NULL, 0, A_NEXT, TPS_InComment, 0, NULL} }; static TParserStateActionItem actionTPS_InCommentEnd[] = { - {NULL, 0, A_BINGO|A_CLRALL,TPS_Base, TAG, NULL} + {NULL, 0, A_BINGO | A_CLRALL, TPS_Base, TAG, NULL} }; static TParserStateActionItem actionTPS_InHostFirstDomen[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHostDomenSecond, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHost, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHostDomenSecond, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHost, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHostDomenSecond[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHostDomen, 0, NULL}, - {p_isdigit, 0, A_PUSH, TPS_InHost, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, - {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHostDomen, 0, NULL}, + {p_isdigit, 0, A_PUSH, TPS_InHost, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, + {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHostDomen[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_Base, HOST, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHostDomen, 0, NULL}, - {p_isdigit, 0, A_PUSH, TPS_InHost, 0, NULL}, - {p_iseqC, ':', A_PUSH, TPS_InPortFirst, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, - {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, - {p_isdigit, 0, A_POP, TPS_Null, 0, NULL}, - {p_isstophost, 0, A_BINGO|A_CLRALL,TPS_InURIStart, HOST, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFURL, 0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_Base, HOST, NULL} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_Base, HOST, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHostDomen, 0, NULL}, + {p_isdigit, 0, A_PUSH, TPS_InHost, 0, NULL}, + {p_iseqC, ':', A_PUSH, TPS_InPortFirst, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, + {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, + {p_isdigit, 0, A_POP, TPS_Null, 0, NULL}, + {p_isstophost, 0, A_BINGO | A_CLRALL, TPS_InURIStart, HOST, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFURL, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_Base, HOST, NULL} }; static TParserStateActionItem actionTPS_InPortFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InPort, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InPort, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InPort[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_Base, HOST, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InPort, 0, NULL}, - {p_isstophost, 0, A_BINGO|A_CLRALL,TPS_InURIStart, HOST, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFURL, 0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_Base, HOST, NULL} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_Base, HOST, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InPort, 0, NULL}, + {p_isstophost, 0, A_BINGO | A_CLRALL, TPS_InURIStart, HOST, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFURL, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_Base, HOST, NULL} }; static TParserStateActionItem actionTPS_InHostFirstAN[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHost, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHost, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHost, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHost, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHost[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHost, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHost, 0, NULL}, - {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHost, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHost, 0, NULL}, + {p_iseqC, '@', A_PUSH, TPS_InEmail, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHostFirstDomen, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHostFirstAN, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InEmail[] = { - {p_ishost, 0, A_BINGO|A_CLRALL, TPS_Base, EMAIL, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_ishost, 0, A_BINGO | A_CLRALL, TPS_Base, EMAIL, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InFileFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_CLEAR, TPS_InFile, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InFile, 0, NULL}, - {p_iseqC, '.', A_CLEAR, TPS_InFile, 0, NULL}, - {p_iseqC, '_', A_CLEAR, TPS_InFile, 0, NULL}, - {p_iseqC, '?', A_PUSH, TPS_InURIFirst, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_CLEAR, TPS_InFile, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InFile, 0, NULL}, + {p_iseqC, '.', A_CLEAR, TPS_InFile, 0, NULL}, + {p_iseqC, '_', A_CLEAR, TPS_InFile, 0, NULL}, + {p_iseqC, '?', A_PUSH, TPS_InURIFirst, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InFile[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, FILEPATH, NULL}, - {p_islatin, 0, A_NEXT, TPS_InFile, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InFile, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InFileNext, 0, NULL}, - {p_iseqC, '_', A_NEXT, TPS_InFile, 0, NULL}, - {p_iseqC, '-', A_NEXT, TPS_InFile, 0, NULL}, - {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, - {p_iseqC, '?', A_PUSH, TPS_InURIFirst, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, FILEPATH, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, FILEPATH, NULL}, + {p_islatin, 0, A_NEXT, TPS_InFile, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InFile, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InFileNext, 0, NULL}, + {p_iseqC, '_', A_NEXT, TPS_InFile, 0, NULL}, + {p_iseqC, '-', A_NEXT, TPS_InFile, 0, NULL}, + {p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL}, + {p_iseqC, '?', A_PUSH, TPS_InURIFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, FILEPATH, NULL} }; static TParserStateActionItem actionTPS_InFileNext[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_CLEAR, TPS_InFile, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InFile, 0, NULL}, - {p_iseqC, '_', A_CLEAR, TPS_InFile, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_CLEAR, TPS_InFile, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InFile, 0, NULL}, + {p_iseqC, '_', A_CLEAR, TPS_InFile, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InURIFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '"', A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '\'', A_POP, TPS_Null, 0, NULL}, - {p_isnotspace, 0, A_CLEAR, TPS_InURI, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL}, + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '"', A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '\'', A_POP, TPS_Null, 0, NULL}, + {p_isnotspace, 0, A_CLEAR, TPS_InURI, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL}, }; - + static TParserStateActionItem actionTPS_InURIStart[] = { - {NULL, 0, A_NEXT, TPS_InURI, 0, NULL} + {NULL, 0, A_NEXT, TPS_InURI, 0, NULL} }; static TParserStateActionItem actionTPS_InURI[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, URI, NULL}, - {p_iseqC, '"', A_BINGO, TPS_Base, URI, NULL}, - {p_iseqC, '\'', A_BINGO, TPS_Base, URI, NULL}, - {p_isnotspace, 0, A_NEXT, TPS_InURI, 0, NULL}, - {NULL, 0, A_BINGO, TPS_Base, URI, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, URI, NULL}, + {p_iseqC, '"', A_BINGO, TPS_Base, URI, NULL}, + {p_iseqC, '\'', A_BINGO, TPS_Base, URI, NULL}, + {p_isnotspace, 0, A_NEXT, TPS_InURI, 0, NULL}, + {NULL, 0, A_BINGO, TPS_Base, URI, NULL} }; static TParserStateActionItem actionTPS_InFURL[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isURI, 0, A_BINGO|A_CLRALL,TPS_Base, FURL, SpecialFURL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isURI, 0, A_BINGO | A_CLRALL, TPS_Base, FURL, SpecialFURL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; - + static TParserStateActionItem actionTPS_InProtocolFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '/', A_NEXT, TPS_InProtocolSecond, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '/', A_NEXT, TPS_InProtocolSecond, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; - + static TParserStateActionItem actionTPS_InProtocolSecond[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_iseqC, '/', A_NEXT, TPS_InProtocolEnd, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_iseqC, '/', A_NEXT, TPS_InProtocolEnd, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; - + static TParserStateActionItem actionTPS_InProtocolEnd[] = { - {NULL, 0, A_BINGO|A_CLRALL,TPS_Base, PROTOCOL, NULL} + {NULL, 0, A_BINGO | A_CLRALL, TPS_Base, PROTOCOL, NULL} }; - + static TParserStateActionItem actionTPS_InHyphenLatWordFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHyphenLatWord, 0, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHyphenLatWord, 0, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHyphenLatWord[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, LATHYPHENWORD, SpecialHyphen}, - {p_islatin, 0, A_NEXT, TPS_InHyphenLatWord, 0, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenLatWordFirst,0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, LATHYPHENWORD, SpecialHyphen} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, LATHYPHENWORD, SpecialHyphen}, + {p_islatin, 0, A_NEXT, TPS_InHyphenLatWord, 0, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenLatWordFirst, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, LATHYPHENWORD, SpecialHyphen} }; static TParserStateActionItem actionTPS_InHyphenCyrWordFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWord, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWord, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHyphenCyrWord[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, CYRHYPHENWORD, SpecialHyphen}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWord, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenCyrWordFirst,0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, CYRHYPHENWORD, SpecialHyphen} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, CYRHYPHENWORD, SpecialHyphen}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWord, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenCyrWordFirst, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, CYRHYPHENWORD, SpecialHyphen} }; static TParserStateActionItem actionTPS_InHyphenUWordFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, - {p_isalnum, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, + {p_isalnum, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHyphenUWord[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, HYPHENWORD, SpecialHyphen}, - {p_isalnum, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst,0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, HYPHENWORD, SpecialHyphen} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, HYPHENWORD, SpecialHyphen}, + {p_isalnum, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, HYPHENWORD, SpecialHyphen} }; static TParserStateActionItem actionTPS_InHyphenValueFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenValueExact, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenValueExact, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHyphenValue[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, HYPHENWORD, SpecialHyphen}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHyphenValueFirst, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst,0, NULL}, - {p_isalpha, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, HYPHENWORD, SpecialHyphen} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, HYPHENWORD, SpecialHyphen}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenValue, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHyphenValueFirst, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst, 0, NULL}, + {p_isalpha, 0, A_NEXT, TPS_InHyphenUWord, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, HYPHENWORD, SpecialHyphen} }; static TParserStateActionItem actionTPS_InHyphenValueExact[] = { - {p_isEOF, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, HYPHENWORD, SpecialHyphen}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenValueExact, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHyphenValueFirst, 0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst, 0, NULL}, - {NULL, 0, A_BINGO|A_CLRALL,TPS_InParseHyphen, HYPHENWORD, SpecialHyphen} + {p_isEOF, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, HYPHENWORD, SpecialHyphen}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenValueExact, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHyphenValueFirst, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InHyphenUWordFirst, 0, NULL}, + {NULL, 0, A_BINGO | A_CLRALL, TPS_InParseHyphen, HYPHENWORD, SpecialHyphen} }; static TParserStateActionItem actionTPS_InParseHyphen[] = { - {p_isEOF, 0, A_RERUN, TPS_Base, 0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHyphenLatWordPart,0, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWordPart,0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUnsignedInt,0, NULL}, - {p_iseqC, '-', A_PUSH, TPS_InParseHyphenHyphen,0, NULL}, - {NULL, 0, A_RERUN, TPS_Base, 0, NULL} + {p_isEOF, 0, A_RERUN, TPS_Base, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHyphenLatWordPart, 0, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWordPart, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUnsignedInt, 0, NULL}, + {p_iseqC, '-', A_PUSH, TPS_InParseHyphenHyphen, 0, NULL}, + {NULL, 0, A_RERUN, TPS_Base, 0, NULL} }; static TParserStateActionItem actionTPS_InParseHyphenHyphen[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isalnum, 0, A_BINGO|A_CLEAR,TPS_InParseHyphen, SPACE, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isalnum, 0, A_BINGO | A_CLEAR, TPS_InParseHyphen, SPACE, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHyphenCyrWordPart[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, CYRPARTHYPHENWORD,NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWordPart,0, NULL}, - {p_islatin, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, - {NULL, 0, A_BINGO, TPS_InParseHyphen, CYRPARTHYPHENWORD,NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, CYRPARTHYPHENWORD, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenCyrWordPart, 0, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, + {NULL, 0, A_BINGO, TPS_InParseHyphen, CYRPARTHYPHENWORD, NULL} }; static TParserStateActionItem actionTPS_InHyphenLatWordPart[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, LATPARTHYPHENWORD,NULL}, - {p_islatin, 0, A_NEXT, TPS_InHyphenLatWordPart,0, NULL}, - {p_isnonlatin, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, - {NULL, 0, A_BINGO, TPS_InParseHyphen, LATPARTHYPHENWORD,NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, LATPARTHYPHENWORD, NULL}, + {p_islatin, 0, A_NEXT, TPS_InHyphenLatWordPart, 0, NULL}, + {p_isnonlatin, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, + {NULL, 0, A_BINGO, TPS_InParseHyphen, LATPARTHYPHENWORD, NULL} }; static TParserStateActionItem actionTPS_InHyphenUWordPart[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, PARTHYPHENWORD, NULL}, - {p_isalnum, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, - {NULL, 0, A_BINGO, TPS_InParseHyphen, PARTHYPHENWORD, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, PARTHYPHENWORD, NULL}, + {p_isalnum, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, + {NULL, 0, A_BINGO, TPS_InParseHyphen, PARTHYPHENWORD, NULL} }; static TParserStateActionItem actionTPS_InHyphenUnsignedInt[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, UNSIGNEDINT, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHyphenUnsignedInt,0, NULL}, - {p_isalpha, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHDecimalPartFirst,0, NULL}, - {NULL, 0, A_BINGO, TPS_InParseHyphen, UNSIGNEDINT, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, UNSIGNEDINT, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHyphenUnsignedInt, 0, NULL}, + {p_isalpha, 0, A_NEXT, TPS_InHyphenUWordPart, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHDecimalPartFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_InParseHyphen, UNSIGNEDINT, NULL} }; static TParserStateActionItem actionTPS_InHDecimalPartFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InHDecimalPart, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InHDecimalPart, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHDecimalPart[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, DECIMAL, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHDecimalPart, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHVersionPartFirst,0, NULL}, - {NULL, 0, A_BINGO, TPS_InParseHyphen, DECIMAL, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, DECIMAL, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHDecimalPart, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHVersionPartFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_InParseHyphen, DECIMAL, NULL} }; static TParserStateActionItem actionTPS_InHVersionPartFirst[] = { - {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, - {p_isdigit, 0, A_CLEAR, TPS_InHVersionPart, 0, NULL}, - {NULL, 0, A_POP, TPS_Null, 0, NULL} + {p_isEOF, 0, A_POP, TPS_Null, 0, NULL}, + {p_isdigit, 0, A_CLEAR, TPS_InHVersionPart, 0, NULL}, + {NULL, 0, A_POP, TPS_Null, 0, NULL} }; static TParserStateActionItem actionTPS_InHVersionPart[] = { - {p_isEOF, 0, A_BINGO, TPS_Base, VERSIONNUMBER, NULL}, - {p_isdigit, 0, A_NEXT, TPS_InHVersionPart, 0, NULL}, - {p_iseqC, '.', A_PUSH, TPS_InHVersionPartFirst,0, NULL}, - {NULL, 0, A_BINGO, TPS_InParseHyphen, VERSIONNUMBER, NULL} + {p_isEOF, 0, A_BINGO, TPS_Base, VERSIONNUMBER, NULL}, + {p_isdigit, 0, A_NEXT, TPS_InHVersionPart, 0, NULL}, + {p_iseqC, '.', A_PUSH, TPS_InHVersionPartFirst, 0, NULL}, + {NULL, 0, A_BINGO, TPS_InParseHyphen, VERSIONNUMBER, NULL} }; -/* +/* * order should be the same as in typedef enum {} TParserState!! */ static const TParserStateAction Actions[] = { - { TPS_Base, actionTPS_Base }, - { TPS_InUWord, actionTPS_InUWord }, - { TPS_InLatWord, actionTPS_InLatWord }, - { TPS_InCyrWord, actionTPS_InCyrWord }, - { TPS_InUnsignedInt, actionTPS_InUnsignedInt }, - { TPS_InSignedIntFirst, actionTPS_InSignedIntFirst }, - { TPS_InSignedInt, actionTPS_InSignedInt }, - { TPS_InSpace, actionTPS_InSpace }, - { TPS_InUDecimalFirst, actionTPS_InUDecimalFirst }, - { TPS_InUDecimal, actionTPS_InUDecimal }, - { TPS_InDecimalFirst, actionTPS_InDecimalFirst }, - { TPS_InDecimal, actionTPS_InDecimal }, - { TPS_InVersionFirst, actionTPS_InVersionFirst }, - { TPS_InVersion, actionTPS_InVersion }, - { TPS_InMantissaFirst, actionTPS_InMantissaFirst }, - { TPS_InMantissaSign, actionTPS_InMantissaSign }, - { TPS_InMantissa, actionTPS_InMantissa }, - { TPS_InHTMLEntityFirst, actionTPS_InHTMLEntityFirst }, - { TPS_InHTMLEntity, actionTPS_InHTMLEntity }, - { TPS_InHTMLEntityNumFirst, actionTPS_InHTMLEntityNumFirst }, - { TPS_InHTMLEntityNum, actionTPS_InHTMLEntityNum }, - { TPS_InHTMLEntityEnd, actionTPS_InHTMLEntityEnd }, - { TPS_InTagFirst, actionTPS_InTagFirst }, - { TPS_InTagCloseFirst, actionTPS_InTagCloseFirst }, - { TPS_InTag, actionTPS_InTag }, - { TPS_InTagEscapeK, actionTPS_InTagEscapeK }, - { TPS_InTagEscapeKK, actionTPS_InTagEscapeKK }, - { TPS_InTagBackSleshed, actionTPS_InTagBackSleshed }, - { TPS_InTagEnd, actionTPS_InTagEnd }, - { TPS_InCommentFirst, actionTPS_InCommentFirst }, - { TPS_InCommentLast, actionTPS_InCommentLast }, - { TPS_InComment, actionTPS_InComment }, - { TPS_InCloseCommentFirst, actionTPS_InCloseCommentFirst }, - { TPS_InCloseCommentLast, actionTPS_InCloseCommentLast }, - { TPS_InCommentEnd, actionTPS_InCommentEnd }, - { TPS_InHostFirstDomen, actionTPS_InHostFirstDomen }, - { TPS_InHostDomenSecond, actionTPS_InHostDomenSecond }, - { TPS_InHostDomen, actionTPS_InHostDomen }, - { TPS_InPortFirst, actionTPS_InPortFirst }, - { TPS_InPort, actionTPS_InPort }, - { TPS_InHostFirstAN, actionTPS_InHostFirstAN }, - { TPS_InHost, actionTPS_InHost }, - { TPS_InEmail, actionTPS_InEmail }, - { TPS_InFileFirst, actionTPS_InFileFirst }, - { TPS_InFile, actionTPS_InFile }, - { TPS_InFileNext, actionTPS_InFileNext }, - { TPS_InURIFirst, actionTPS_InURIFirst }, - { TPS_InURIStart, actionTPS_InURIStart }, - { TPS_InURI, actionTPS_InURI }, - { TPS_InFURL, actionTPS_InFURL }, - { TPS_InProtocolFirst, actionTPS_InProtocolFirst }, - { TPS_InProtocolSecond, actionTPS_InProtocolSecond }, - { TPS_InProtocolEnd, actionTPS_InProtocolEnd }, - { TPS_InHyphenLatWordFirst, actionTPS_InHyphenLatWordFirst }, - { TPS_InHyphenLatWord, actionTPS_InHyphenLatWord }, - { TPS_InHyphenCyrWordFirst, actionTPS_InHyphenCyrWordFirst }, - { TPS_InHyphenCyrWord, actionTPS_InHyphenCyrWord }, - { TPS_InHyphenUWordFirst, actionTPS_InHyphenUWordFirst }, - { TPS_InHyphenUWord, actionTPS_InHyphenUWord }, - { TPS_InHyphenValueFirst, actionTPS_InHyphenValueFirst }, - { TPS_InHyphenValue, actionTPS_InHyphenValue }, - { TPS_InHyphenValueExact, actionTPS_InHyphenValueExact }, - { TPS_InParseHyphen, actionTPS_InParseHyphen }, - { TPS_InParseHyphenHyphen, actionTPS_InParseHyphenHyphen }, - { TPS_InHyphenCyrWordPart, actionTPS_InHyphenCyrWordPart }, - { TPS_InHyphenLatWordPart, actionTPS_InHyphenLatWordPart }, - { TPS_InHyphenUWordPart, actionTPS_InHyphenUWordPart }, - { TPS_InHyphenUnsignedInt, actionTPS_InHyphenUnsignedInt }, - { TPS_InHDecimalPartFirst, actionTPS_InHDecimalPartFirst }, - { TPS_InHDecimalPart, actionTPS_InHDecimalPart }, - { TPS_InHVersionPartFirst, actionTPS_InHVersionPartFirst }, - { TPS_InHVersionPart, actionTPS_InHVersionPart }, - { TPS_Null, NULL } + {TPS_Base, actionTPS_Base}, + {TPS_InUWord, actionTPS_InUWord}, + {TPS_InLatWord, actionTPS_InLatWord}, + {TPS_InCyrWord, actionTPS_InCyrWord}, + {TPS_InUnsignedInt, actionTPS_InUnsignedInt}, + {TPS_InSignedIntFirst, actionTPS_InSignedIntFirst}, + {TPS_InSignedInt, actionTPS_InSignedInt}, + {TPS_InSpace, actionTPS_InSpace}, + {TPS_InUDecimalFirst, actionTPS_InUDecimalFirst}, + {TPS_InUDecimal, actionTPS_InUDecimal}, + {TPS_InDecimalFirst, actionTPS_InDecimalFirst}, + {TPS_InDecimal, actionTPS_InDecimal}, + {TPS_InVersionFirst, actionTPS_InVersionFirst}, + {TPS_InVersion, actionTPS_InVersion}, + {TPS_InMantissaFirst, actionTPS_InMantissaFirst}, + {TPS_InMantissaSign, actionTPS_InMantissaSign}, + {TPS_InMantissa, actionTPS_InMantissa}, + {TPS_InHTMLEntityFirst, actionTPS_InHTMLEntityFirst}, + {TPS_InHTMLEntity, actionTPS_InHTMLEntity}, + {TPS_InHTMLEntityNumFirst, actionTPS_InHTMLEntityNumFirst}, + {TPS_InHTMLEntityNum, actionTPS_InHTMLEntityNum}, + {TPS_InHTMLEntityEnd, actionTPS_InHTMLEntityEnd}, + {TPS_InTagFirst, actionTPS_InTagFirst}, + {TPS_InTagCloseFirst, actionTPS_InTagCloseFirst}, + {TPS_InTag, actionTPS_InTag}, + {TPS_InTagEscapeK, actionTPS_InTagEscapeK}, + {TPS_InTagEscapeKK, actionTPS_InTagEscapeKK}, + {TPS_InTagBackSleshed, actionTPS_InTagBackSleshed}, + {TPS_InTagEnd, actionTPS_InTagEnd}, + {TPS_InCommentFirst, actionTPS_InCommentFirst}, + {TPS_InCommentLast, actionTPS_InCommentLast}, + {TPS_InComment, actionTPS_InComment}, + {TPS_InCloseCommentFirst, actionTPS_InCloseCommentFirst}, + {TPS_InCloseCommentLast, actionTPS_InCloseCommentLast}, + {TPS_InCommentEnd, actionTPS_InCommentEnd}, + {TPS_InHostFirstDomen, actionTPS_InHostFirstDomen}, + {TPS_InHostDomenSecond, actionTPS_InHostDomenSecond}, + {TPS_InHostDomen, actionTPS_InHostDomen}, + {TPS_InPortFirst, actionTPS_InPortFirst}, + {TPS_InPort, actionTPS_InPort}, + {TPS_InHostFirstAN, actionTPS_InHostFirstAN}, + {TPS_InHost, actionTPS_InHost}, + {TPS_InEmail, actionTPS_InEmail}, + {TPS_InFileFirst, actionTPS_InFileFirst}, + {TPS_InFile, actionTPS_InFile}, + {TPS_InFileNext, actionTPS_InFileNext}, + {TPS_InURIFirst, actionTPS_InURIFirst}, + {TPS_InURIStart, actionTPS_InURIStart}, + {TPS_InURI, actionTPS_InURI}, + {TPS_InFURL, actionTPS_InFURL}, + {TPS_InProtocolFirst, actionTPS_InProtocolFirst}, + {TPS_InProtocolSecond, actionTPS_InProtocolSecond}, + {TPS_InProtocolEnd, actionTPS_InProtocolEnd}, + {TPS_InHyphenLatWordFirst, actionTPS_InHyphenLatWordFirst}, + {TPS_InHyphenLatWord, actionTPS_InHyphenLatWord}, + {TPS_InHyphenCyrWordFirst, actionTPS_InHyphenCyrWordFirst}, + {TPS_InHyphenCyrWord, actionTPS_InHyphenCyrWord}, + {TPS_InHyphenUWordFirst, actionTPS_InHyphenUWordFirst}, + {TPS_InHyphenUWord, actionTPS_InHyphenUWord}, + {TPS_InHyphenValueFirst, actionTPS_InHyphenValueFirst}, + {TPS_InHyphenValue, actionTPS_InHyphenValue}, + {TPS_InHyphenValueExact, actionTPS_InHyphenValueExact}, + {TPS_InParseHyphen, actionTPS_InParseHyphen}, + {TPS_InParseHyphenHyphen, actionTPS_InParseHyphenHyphen}, + {TPS_InHyphenCyrWordPart, actionTPS_InHyphenCyrWordPart}, + {TPS_InHyphenLatWordPart, actionTPS_InHyphenLatWordPart}, + {TPS_InHyphenUWordPart, actionTPS_InHyphenUWordPart}, + {TPS_InHyphenUnsignedInt, actionTPS_InHyphenUnsignedInt}, + {TPS_InHDecimalPartFirst, actionTPS_InHDecimalPartFirst}, + {TPS_InHDecimalPart, actionTPS_InHDecimalPart}, + {TPS_InHVersionPartFirst, actionTPS_InHVersionPartFirst}, + {TPS_InHVersionPart, actionTPS_InHVersionPart}, + {TPS_Null, NULL} }; bool -TParserGet( TParser *prs ) { - TParserStateActionItem *item=NULL; +TParserGet(TParser * prs) +{ + TParserStateActionItem *item = NULL; - if ( prs->state->posbyte >= prs->lenstr ) + if (prs->state->posbyte >= prs->lenstr) return false; - Assert( prs->state ); - prs->lexeme = prs->str + prs->state->posbyte; + Assert(prs->state); + prs->lexeme = prs->str + prs->state->posbyte; prs->state->pushedAtAction = NULL; /* look at string */ - while (prs->state->posbyte <= prs->lenstr) { - if ( prs->state->posbyte == prs->lenstr ) + while (prs->state->posbyte <= prs->lenstr) + { + if (prs->state->posbyte == prs->lenstr) prs->state->charlen = 0; else - prs->state->charlen = ( prs->charmaxlen == 1 ) ? prs->charmaxlen : - pg_mblen( prs->str + prs->state->posbyte ); + prs->state->charlen = (prs->charmaxlen == 1) ? prs->charmaxlen : + pg_mblen(prs->str + prs->state->posbyte); - Assert( prs->state->posbyte + prs->state->charlen <= prs->lenstr ); - Assert( prs->state->state >=TPS_Base && prs->state->state < TPS_Null ); - Assert( Actions[ prs->state->state ].state == prs->state->state ); + Assert(prs->state->posbyte + prs->state->charlen <= prs->lenstr); + Assert(prs->state->state >= TPS_Base && prs->state->state < TPS_Null); + Assert(Actions[prs->state->state].state == prs->state->state); - item = Actions[ prs->state->state ].action; - Assert(item!=NULL); + item = Actions[prs->state->state].action; + Assert(item != NULL); - if ( item < prs->state->pushedAtAction ) - item = prs->state->pushedAtAction; + if (item < prs->state->pushedAtAction) + item = prs->state->pushedAtAction; /* find action by character class */ - while( item->isclass ) { + while (item->isclass) + { prs->c = item->c; - if ( item->isclass(prs)!=0 ) { - if ( item > prs->state->pushedAtAction ) /* remember: after pushing we were by false way */ + if (item->isclass(prs) != 0) + { + if (item > prs->state->pushedAtAction) /* remember: after + * pushing we were by + * false way */ break; - } + } item++; } prs->state->pushedAtAction = NULL; /* call special handler if exists */ - if ( item->special ) + if (item->special) item->special(prs); /* BINGO, lexeme is found */ - if ( item->flags & A_BINGO ) { - Assert( item->type>0 ); + if (item->flags & A_BINGO) + { + Assert(item->type > 0); prs->lenbytelexeme = prs->state->lenbytelexeme; prs->lencharlexeme = prs->state->lencharlexeme; prs->state->lenbytelexeme = prs->state->lencharlexeme = 0; prs->type = item->type; - } + } - /* do various actions by flags */ - if ( item->flags & A_POP ) { /* pop stored state in stack */ + /* do various actions by flags */ + if (item->flags & A_POP) + { /* pop stored state in stack */ TParserPosition *ptr = prs->state->prev; - pfree( prs->state ); + + pfree(prs->state); prs->state = ptr; - Assert( prs->state ); - } else if ( item->flags & A_PUSH ) { /* push (store) state in stack */ - prs->state->pushedAtAction = item; /* remember where we push */ - prs->state = newTParserPosition( prs->state ); - } else if ( item->flags & A_CLEAR ) { /* clear previous pushed state */ + Assert(prs->state); + } + else if (item->flags & A_PUSH) + { /* push (store) state in stack */ + prs->state->pushedAtAction = item; /* remember where we push */ + prs->state = newTParserPosition(prs->state); + } + else if (item->flags & A_CLEAR) + { /* clear previous pushed state */ TParserPosition *ptr; - Assert( prs->state->prev ); + + Assert(prs->state->prev); ptr = prs->state->prev->prev; - pfree( prs->state->prev ); + pfree(prs->state->prev); prs->state->prev = ptr; - } else if ( item->flags & A_CLRALL ) { /* clear all previous pushed state */ + } + else if (item->flags & A_CLRALL) + { /* clear all previous pushed state */ TParserPosition *ptr; - while( prs->state->prev ) { + + while (prs->state->prev) + { ptr = prs->state->prev->prev; - pfree( prs->state->prev ); + pfree(prs->state->prev); prs->state->prev = ptr; } - } else if ( item->flags & A_MERGE ) { /* merge posinfo with current and pushed state */ + } + else if (item->flags & A_MERGE) + { /* merge posinfo with current and pushed state */ TParserPosition *ptr = prs->state; - Assert( prs->state->prev ); + + Assert(prs->state->prev); prs->state = prs->state->prev; prs->state->posbyte = ptr->posbyte; @@ -996,31 +1054,30 @@ TParserGet( TParser *prs ) { prs->state->charlen = ptr->charlen; prs->state->lenbytelexeme = ptr->lenbytelexeme; prs->state->lencharlexeme = ptr->lencharlexeme; - pfree(ptr); + pfree(ptr); } /* set new state if pointed */ - if ( item->tostate != TPS_Null ) + if (item->tostate != TPS_Null) prs->state->state = item->tostate; - /* check for go away */ - if ( (item->flags & A_BINGO) || (prs->state->posbyte >= prs->lenstr && (item->flags & A_RERUN)==0 ) ) + /* check for go away */ + if ((item->flags & A_BINGO) || (prs->state->posbyte >= prs->lenstr && (item->flags & A_RERUN) == 0)) break; /* go to begining of loop if we should rerun or we just restore state */ - if ( item->flags & ( A_RERUN | A_POP ) ) + if (item->flags & (A_RERUN | A_POP)) continue; - - /* move forward */ - if ( prs->state->charlen ) { + + /* move forward */ + if (prs->state->charlen) + { prs->state->posbyte += prs->state->charlen; prs->state->lenbytelexeme += prs->state->charlen; - prs->state->poschar ++; - prs->state->lencharlexeme ++; + prs->state->poschar++; + prs->state->lencharlexeme++; } - } + } return (item && (item->flags & A_BINGO)) ? true : false; } - - diff --git a/contrib/tsearch2/wordparser/parser.h b/contrib/tsearch2/wordparser/parser.h index ee5b3b7ab5..83468d657f 100644 --- a/contrib/tsearch2/wordparser/parser.h +++ b/contrib/tsearch2/wordparser/parser.h @@ -5,7 +5,8 @@ #include <limits.h> #include "ts_locale.h" -typedef enum { +typedef enum +{ TPS_Base = 0, TPS_InUWord, TPS_InLatWord, @@ -78,70 +79,76 @@ typedef enum { TPS_InHDecimalPart, TPS_InHVersionPartFirst, TPS_InHVersionPart, - TPS_Null /* last state (fake value) */ -} TParserState; + TPS_Null /* last state (fake value) */ +} TParserState; /* forward declaration */ struct TParser; -typedef int (*TParserCharTest)(struct TParser*); /* any p_is* functions except p_iseq */ -typedef void (*TParserSpecial)(struct TParser*); /* special handler for special cases... */ - -typedef struct { - TParserCharTest isclass; - char c; - uint16 flags; - TParserState tostate; - int type; - TParserSpecial special; -} TParserStateActionItem; - -typedef struct { - TParserState state; - TParserStateActionItem *action; -} TParserStateAction; - -typedef struct TParserPosition { - int posbyte; /* position of parser in bytes */ - int poschar; /* osition of parser in characters */ - int charlen; /* length of current char */ - int lenbytelexeme; - int lencharlexeme; - TParserState state; - struct TParserPosition *prev; - int flags; - TParserStateActionItem *pushedAtAction; -} TParserPosition; - -typedef struct TParser { +typedef int (*TParserCharTest) (struct TParser *); /* any p_is* functions + * except p_iseq */ +typedef void (*TParserSpecial) (struct TParser *); /* special handler for + * special cases... */ + +typedef struct +{ + TParserCharTest isclass; + char c; + uint16 flags; + TParserState tostate; + int type; + TParserSpecial special; +} TParserStateActionItem; + +typedef struct +{ + TParserState state; + TParserStateActionItem *action; +} TParserStateAction; + +typedef struct TParserPosition +{ + int posbyte; /* position of parser in bytes */ + int poschar; /* osition of parser in characters */ + int charlen; /* length of current char */ + int lenbytelexeme; + int lencharlexeme; + TParserState state; + struct TParserPosition *prev; + int flags; + TParserStateActionItem *pushedAtAction; +} TParserPosition; + +typedef struct TParser +{ /* string and position information */ - char *str; /* multibyte string */ - int lenstr; /* length of mbstring */ - wchar_t *wstr; /* wide character string */ - int lenwstr; /* length of wsting */ + char *str; /* multibyte string */ + int lenstr; /* length of mbstring */ + wchar_t *wstr; /* wide character string */ + int lenwstr; /* length of wsting */ /* State of parse */ - int charmaxlen; + int charmaxlen; bool usewide; - TParserPosition *state; + TParserPosition *state; bool ignore; bool wanthost; /* silly char */ - char c; + char c; /* out */ - char *lexeme; - int lenbytelexeme; - int lencharlexeme; - int type; - -} TParser; + char *lexeme; + int lenbytelexeme; + int lencharlexeme; + int type; + +} TParser; -TParser* TParserInit( char *, int ); -bool TParserGet( TParser* ); -void TParserClose( TParser* ); +TParser *TParserInit(char *, int); +bool TParserGet(TParser *); +void TParserClose(TParser *); #endif diff --git a/contrib/tsearch2/wparser_def.c b/contrib/tsearch2/wparser_def.c index 897ff2795e..b20909ce5b 100644 --- a/contrib/tsearch2/wparser_def.c +++ b/contrib/tsearch2/wparser_def.c @@ -39,7 +39,7 @@ Datum prsd_start(PG_FUNCTION_ARGS); Datum prsd_start(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER(TParserInit( (char *) PG_GETARG_POINTER(0), PG_GETARG_INT32(1))); + PG_RETURN_POINTER(TParserInit((char *) PG_GETARG_POINTER(0), PG_GETARG_INT32(1))); } PG_FUNCTION_INFO_V1(prsd_getlexeme); @@ -47,14 +47,14 @@ Datum prsd_getlexeme(PG_FUNCTION_ARGS); Datum prsd_getlexeme(PG_FUNCTION_ARGS) { - TParser *p=(TParser*)PG_GETARG_POINTER(0); + TParser *p = (TParser *) PG_GETARG_POINTER(0); char **t = (char **) PG_GETARG_POINTER(1); int *tlen = (int *) PG_GETARG_POINTER(2); - if ( !TParserGet(p) ) + if (!TParserGet(p)) PG_RETURN_INT32(0); - *t = p->lexeme; + *t = p->lexeme; *tlen = p->lenbytelexeme; PG_RETURN_INT32(p->type); @@ -65,8 +65,9 @@ Datum prsd_end(PG_FUNCTION_ARGS); Datum prsd_end(PG_FUNCTION_ARGS) { - TParser *p=(TParser*)PG_GETARG_POINTER(0); - TParserClose(p); + TParser *p = (TParser *) PG_GETARG_POINTER(0); + + TParserClose(p); PG_RETURN_VOID(); } |
