1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

pgindent run.

This commit is contained in:
Bruce Momjian
2002-09-04 20:31:48 +00:00
parent c91ceec21d
commit e50f52a074
446 changed files with 14942 additions and 13363 deletions

View File

@ -1,5 +1,5 @@
/*
* op function for ltree and lquery
* op function for ltree and lquery
* Teodor Sigaev <teodor@stack.net>
*/
@ -9,27 +9,29 @@
PG_FUNCTION_INFO_V1(ltq_regex);
PG_FUNCTION_INFO_V1(ltq_rregex);
typedef struct {
lquery_level *q;
int nq;
ltree_level *t;
int nt;
int posq;
int post;
} FieldNot;
typedef struct
{
lquery_level *q;
int nq;
ltree_level *t;
int nt;
int posq;
int post;
} FieldNot;
static char *
getlexem(char *start, char *end, int *len) {
char *ptr;
while( start<end && *start == '_' )
getlexem(char *start, char *end, int *len)
{
char *ptr;
while (start < end && *start == '_')
start++;
ptr = start;
if ( ptr == end )
if (ptr == end)
return NULL;
while( ptr < end && *ptr != '_')
while (ptr < end && *ptr != '_')
ptr++;
*len = ptr - start;
@ -37,31 +39,36 @@ getlexem(char *start, char *end, int *len) {
}
bool
compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,const char *,size_t), bool anyend ) {
char *endt = t->name + t->len;
char *endq = qn + len;
char *tn;
int lent,lenq;
bool isok;
compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
{
char *endt = t->name + t->len;
char *endq = qn + len;
char *tn;
int lent,
lenq;
bool isok;
while( (qn=getlexem(qn,endq,&lenq)) != NULL ) {
tn=t->name;
while ((qn = getlexem(qn, endq, &lenq)) != NULL)
{
tn = t->name;
isok = false;
while( (tn=getlexem(tn,endt,&lent)) != NULL ) {
if (
while ((tn = getlexem(tn, endt, &lent)) != NULL)
{
if (
(
lent == lenq ||
( lent > lenq && anyend )
) &&
(*cmpptr)(qn,tn,lenq) == 0 ) {
isok = true;
lent == lenq ||
(lent > lenq && anyend)
) &&
(*cmpptr) (qn, tn, lenq) == 0)
{
isok = true;
break;
}
tn += lent;
}
if ( !isok )
if (!isok)
return false;
qn += lenq;
}
@ -70,27 +77,32 @@ compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,c
}
static bool
checkLevel( lquery_level *curq, ltree_level *curt ) {
int (*cmpptr)(const char *,const char *,size_t);
checkLevel(lquery_level * curq, ltree_level * curt)
{
int (*cmpptr) (const char *, const char *, size_t);
lquery_variant *curvar = LQL_FIRST(curq);
int i;
for(i=0;i<curq->numvar;i++) {
cmpptr = ( curvar->flag & LVAR_INCASE ) ? strncasecmp : strncmp;
int i;
if ( curvar->flag & LVAR_SUBLEXEM ) {
if ( compare_subnode(curt, curvar->name, curvar->len, cmpptr, (curvar->flag & LVAR_ANYEND) ) )
for (i = 0; i < curq->numvar; i++)
{
cmpptr = (curvar->flag & LVAR_INCASE) ? strncasecmp : strncmp;
if (curvar->flag & LVAR_SUBLEXEM)
{
if (compare_subnode(curt, curvar->name, curvar->len, cmpptr, (curvar->flag & LVAR_ANYEND)))
return true;
} else if (
(
curvar->len == curt->len ||
( curt->len > curvar->len && (curvar->flag & LVAR_ANYEND) )
) &&
(*cmpptr)( curvar->name, curt->name, curvar->len) == 0 ) {
}
else if (
(
curvar->len == curt->len ||
(curt->len > curvar->len && (curvar->flag & LVAR_ANYEND))
) &&
(*cmpptr) (curvar->name, curt->name, curvar->len) == 0)
{
return true;
}
curvar = LVAR_NEXT(curvar);
curvar = LVAR_NEXT(curvar);
}
return false;
}
@ -102,78 +114,97 @@ printFieldNot(FieldNot *fn ) {
elog(NOTICE,"posQ:%d lenQ:%d posT:%d lenT:%d", fn->posq,fn->nq,fn->post,fn->nt);
fn++;
}
}
}
*/
static bool
checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_numlevel, FieldNot *ptr ) {
uint32 low_pos=0,high_pos=0,cur_tpos=0;
int tlen = tree_numlevel, qlen = query_numlevel;
int isok;
lquery_level *prevq=NULL;
ltree_level *prevt=NULL;
checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_numlevel, FieldNot * ptr)
{
uint32 low_pos = 0,
high_pos = 0,
cur_tpos = 0;
int tlen = tree_numlevel,
qlen = query_numlevel;
int isok;
lquery_level *prevq = NULL;
ltree_level *prevt = NULL;
while( tlen >0 && qlen>0 ) {
if ( curq->numvar ) {
while (tlen > 0 && qlen > 0)
{
if (curq->numvar)
{
prevt = curt;
while ( cur_tpos < low_pos ) {
while (cur_tpos < low_pos)
{
curt = LEVEL_NEXT(curt);
tlen--;
cur_tpos++;
if ( tlen==0 )
if (tlen == 0)
return false;
if ( ptr && ptr->q )
if (ptr && ptr->q)
ptr->nt++;
}
if ( ptr && curq->flag & LQL_NOT ) {
if ( !(prevq && prevq->numvar == 0) )
if (ptr && curq->flag & LQL_NOT)
{
if (!(prevq && prevq->numvar == 0))
prevq = curq;
if ( ptr->q == NULL ) {
if (ptr->q == NULL)
{
ptr->t = prevt;
ptr->q = prevq;
ptr->nt=1;
ptr->nq=1 + ( (prevq==curq) ? 0 : 1 );
ptr->posq = query_numlevel - qlen - ( (prevq==curq) ? 0 : 1 );
ptr->nt = 1;
ptr->nq = 1 + ((prevq == curq) ? 0 : 1);
ptr->posq = query_numlevel - qlen - ((prevq == curq) ? 0 : 1);
ptr->post = cur_tpos;
} else {
}
else
{
ptr->nt++;
ptr->nq++;
}
if ( qlen == 1 && ptr->q->numvar==0 )
ptr->nt = tree_numlevel - ptr->post;
if (qlen == 1 && ptr->q->numvar == 0)
ptr->nt = tree_numlevel - ptr->post;
curt = LEVEL_NEXT(curt);
tlen--;
cur_tpos++;
if ( high_pos < cur_tpos )
if (high_pos < cur_tpos)
high_pos++;
} else {
}
else
{
isok = false;
while( cur_tpos <= high_pos && tlen > 0 && !isok) {
while (cur_tpos <= high_pos && tlen > 0 && !isok)
{
isok = checkLevel(curq, curt);
curt = LEVEL_NEXT(curt);
tlen--;
cur_tpos++;
if ( !isok && ptr )
if (!isok && ptr)
ptr->nt++;
}
if ( !isok )
if (!isok)
return false;
if (ptr && ptr->q) {
if ( checkCond(ptr->q,ptr->nq,ptr->t,ptr->nt,NULL) )
if (ptr && ptr->q)
{
if (checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL))
return false;
ptr->q = NULL;
}
low_pos=cur_tpos; high_pos=cur_tpos;
low_pos = cur_tpos;
high_pos = cur_tpos;
}
} else {
}
else
{
low_pos = cur_tpos + curq->low;
high_pos = cur_tpos + curq->high;
if ( ptr && ptr->q ) {
if (ptr && ptr->q)
{
ptr->nq++;
if ( qlen==1 )
if (qlen == 1)
ptr->nt = tree_numlevel - ptr->post;
}
}
@ -181,16 +212,20 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n
prevq = curq;
curq = LQL_NEXT(curq);
qlen--;
}
}
if ( low_pos > tree_numlevel || tree_numlevel > high_pos )
if (low_pos > tree_numlevel || tree_numlevel > high_pos)
return false;
while( qlen>0 ) {
if ( curq->numvar ) {
if ( ! (curq->flag & LQL_NOT) )
while (qlen > 0)
{
if (curq->numvar)
{
if (!(curq->flag & LQL_NOT))
return false;
} else {
}
else
{
low_pos = cur_tpos + curq->low;
high_pos = cur_tpos + curq->high;
}
@ -199,42 +234,47 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n
qlen--;
}
if ( low_pos > tree_numlevel || tree_numlevel > high_pos )
if (low_pos > tree_numlevel || tree_numlevel > high_pos)
return false;
if ( ptr && ptr->q && checkCond(ptr->q,ptr->nq,ptr->t,ptr->nt,NULL) )
if (ptr && ptr->q && checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL))
return false;
return true;
}
Datum
ltq_regex(PG_FUNCTION_ARGS) {
ltree *tree = PG_GETARG_LTREE(0);
lquery *query = PG_GETARG_LQUERY(1);
bool res= false;
ltq_regex(PG_FUNCTION_ARGS)
{
ltree *tree = PG_GETARG_LTREE(0);
lquery *query = PG_GETARG_LQUERY(1);
bool res = false;
if ( query->flag & LQUERY_HASNOT ) {
if (query->flag & LQUERY_HASNOT)
{
FieldNot fn;
fn.q=NULL;
fn.q = NULL;
res = checkCond( LQUERY_FIRST(query), query->numlevel,
LTREE_FIRST(tree), tree->numlevel, &fn );
} else {
res = checkCond( LQUERY_FIRST(query), query->numlevel,
LTREE_FIRST(tree), tree->numlevel, NULL );
res = checkCond(LQUERY_FIRST(query), query->numlevel,
LTREE_FIRST(tree), tree->numlevel, &fn);
}
else
{
res = checkCond(LQUERY_FIRST(query), query->numlevel,
LTREE_FIRST(tree), tree->numlevel, NULL);
}
PG_FREE_IF_COPY(tree,0);
PG_FREE_IF_COPY(query,1);
PG_RETURN_BOOL(res);
PG_FREE_IF_COPY(tree, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(res);
}
Datum
ltq_rregex(PG_FUNCTION_ARGS) {
PG_RETURN_DATUM( DirectFunctionCall2( ltq_regex,
PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0)
) );
Datum
ltq_rregex(PG_FUNCTION_ARGS)
{
PG_RETURN_DATUM(DirectFunctionCall2(ltq_regex,
PG_GETARG_DATUM(1),
PG_GETARG_DATUM(0)
));
}