summaryrefslogtreecommitdiff
path: root/contrib/ltree
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2003-08-04 00:43:34 +0000
committerBruce Momjian <bruce@momjian.us>2003-08-04 00:43:34 +0000
commit089003fb462fcce46c02bf47322b429f73c33c50 (patch)
tree77d78bc3a149df06f5603f60200a6ab363336624 /contrib/ltree
parent63354a0228a1dbc4a0d5ddc8ecdd8326349d2100 (diff)
downloadpostgresql-089003fb462fcce46c02bf47322b429f73c33c50.tar.gz
pgindent run.
Diffstat (limited to 'contrib/ltree')
-rw-r--r--contrib/ltree/_ltree_op.c54
-rw-r--r--contrib/ltree/lquery_op.c52
-rw-r--r--contrib/ltree/ltree_io.c24
-rw-r--r--contrib/ltree/ltree_op.c119
4 files changed, 133 insertions, 116 deletions
diff --git a/contrib/ltree/_ltree_op.c b/contrib/ltree/_ltree_op.c
index f55434d387..3890769ce1 100644
--- a/contrib/ltree/_ltree_op.c
+++ b/contrib/ltree/_ltree_op.c
@@ -45,8 +45,8 @@ array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree ** found)
if (ARR_NDIM(la) != 1)
ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("array must be one-dimensional")));
+ (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
+ errmsg("array must be one-dimensional")));
if (found)
*found = NULL;
@@ -133,38 +133,40 @@ _ltq_rregex(PG_FUNCTION_ARGS)
Datum
_lt_q_regex(PG_FUNCTION_ARGS)
{
- ArrayType *_tree = PG_GETARG_ARRAYTYPE_P(0);
- ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
- lquery *query = (lquery *) ARR_DATA_PTR(_query);
- bool res = false;
- int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
-
- if (ARR_NDIM(_query) != 1)
- ereport(ERROR,
+ ArrayType *_tree = PG_GETARG_ARRAYTYPE_P(0);
+ ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
+ lquery *query = (lquery *) ARR_DATA_PTR(_query);
+ bool res = false;
+ int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
+
+ if (ARR_NDIM(_query) != 1)
+ ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
- while (num > 0) {
- if ( array_iterator(_tree, ltq_regex, (void*)query, NULL) ) {
- res = true;
- break;
- }
- num--;
- query = (lquery*)NEXTVAL(query);
- }
-
- PG_FREE_IF_COPY(_tree, 0);
- PG_FREE_IF_COPY(_query, 1);
- PG_RETURN_BOOL(res);
+ while (num > 0)
+ {
+ if (array_iterator(_tree, ltq_regex, (void *) query, NULL))
+ {
+ res = true;
+ break;
+ }
+ num--;
+ query = (lquery *) NEXTVAL(query);
+ }
+
+ PG_FREE_IF_COPY(_tree, 0);
+ PG_FREE_IF_COPY(_query, 1);
+ PG_RETURN_BOOL(res);
}
Datum
_lt_q_rregex(PG_FUNCTION_ARGS)
{
- PG_RETURN_DATUM(DirectFunctionCall2(_lt_q_regex,
- PG_GETARG_DATUM(1),
- PG_GETARG_DATUM(0)
- ));
+ PG_RETURN_DATUM(DirectFunctionCall2(_lt_q_regex,
+ PG_GETARG_DATUM(1),
+ PG_GETARG_DATUM(0)
+ ));
}
diff --git a/contrib/ltree/lquery_op.c b/contrib/ltree/lquery_op.c
index 72fd968d59..2328fcd238 100644
--- a/contrib/ltree/lquery_op.c
+++ b/contrib/ltree/lquery_op.c
@@ -45,7 +45,7 @@ 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)
+ 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;
@@ -123,10 +123,15 @@ printFieldNot(FieldNot *fn ) {
}
*/
-static struct {
- bool muse;
- uint32 high_pos;
-} SomeStack = {false,0,};
+static struct
+{
+ bool muse;
+ uint32 high_pos;
+} SomeStack =
+
+{
+ false, 0,
+};
static bool
checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_numlevel, FieldNot * ptr)
@@ -140,7 +145,8 @@ checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_
lquery_level *prevq = NULL;
ltree_level *prevt = NULL;
- if ( SomeStack.muse ) {
+ if (SomeStack.muse)
+ {
high_pos = SomeStack.high_pos;
qlen--;
prevq = curq;
@@ -200,13 +206,15 @@ checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_
curt = LEVEL_NEXT(curt);
tlen--;
cur_tpos++;
- if ( isok && prevq && prevq->numvar==0 && tlen>0 && cur_tpos <= high_pos ) {
- FieldNot tmpptr;
- if ( ptr )
- memcpy(&tmpptr,ptr,sizeof(FieldNot));
- SomeStack.high_pos = high_pos-cur_tpos;
+ if (isok && prevq && prevq->numvar == 0 && tlen > 0 && cur_tpos <= high_pos)
+ {
+ FieldNot tmpptr;
+
+ if (ptr)
+ memcpy(&tmpptr, ptr, sizeof(FieldNot));
+ SomeStack.high_pos = high_pos - cur_tpos;
SomeStack.muse = true;
- if ( checkCond(prevq, qlen+1, curt, tlen, (ptr) ? &tmpptr : NULL) )
+ if (checkCond(prevq, qlen + 1, curt, tlen, (ptr) ? &tmpptr : NULL))
return true;
}
if (!isok && ptr)
@@ -311,19 +319,21 @@ Datum
lt_q_regex(PG_FUNCTION_ARGS)
{
ltree *tree = PG_GETARG_LTREE(0);
- ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
- lquery *query = (lquery *) ARR_DATA_PTR(_query);
- bool res = false;
- int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
+ ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
+ lquery *query = (lquery *) ARR_DATA_PTR(_query);
+ bool res = false;
+ int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
- if (ARR_NDIM(_query) != 1)
- ereport(ERROR,
+ if (ARR_NDIM(_query) != 1)
+ ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional")));
- while (num > 0) {
+ while (num > 0)
+ {
if (DatumGetBool(DirectFunctionCall2(ltq_regex,
- PointerGetDatum(tree), PointerGetDatum(query)))) {
+ PointerGetDatum(tree), PointerGetDatum(query))))
+ {
res = true;
break;
@@ -345,5 +355,3 @@ lt_q_rregex(PG_FUNCTION_ARGS)
PG_GETARG_DATUM(0)
));
}
-
-
diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c
index 24116b0242..62c033cc5d 100644
--- a/contrib/ltree/ltree_io.c
+++ b/contrib/ltree/ltree_io.c
@@ -22,7 +22,7 @@ Datum lquery_out(PG_FUNCTION_ARGS);
#define UNCHAR ereport(ERROR, \
(errcode(ERRCODE_SYNTAX_ERROR), \
- errmsg("syntax error at position %d near \"%c\"", \
+ errmsg("syntax error at position %d near \"%c\"", \
(int)(ptr-buf), *ptr)));
@@ -81,8 +81,8 @@ ltree_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
- "be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ "be < 256, in position %d",
+ lptr->len, (int) (lptr->start - buf))));
totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
lptr++;
@@ -105,8 +105,8 @@ ltree_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
- "be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ "be < 256, in position %d",
+ lptr->len, (int) (lptr->start - buf))));
totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
lptr++;
@@ -283,8 +283,8 @@ lquery_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
- "be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ "be < 256, in position %d",
+ lptr->len, (int) (lptr->start - buf))));
state = LQPRS_WAITVAR;
}
@@ -299,8 +299,8 @@ lquery_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
- "be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ "be < 256, in position %d",
+ lptr->len, (int) (lptr->start - buf))));
state = LQPRS_WAITLEVEL;
curqlevel = NEXTLEV(curqlevel);
@@ -412,8 +412,8 @@ lquery_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NAME_TOO_LONG),
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
- "be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ "be < 256, in position %d",
+ lptr->len, (int) (lptr->start - buf))));
}
else if (state == LQPRS_WAITOPEN)
curqlevel->high = 0xffff;
@@ -442,7 +442,7 @@ lquery_in(PG_FUNCTION_ARGS)
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error"),
errdetail("Low limit(%d) is greater than upper(%d).",
- curqlevel->low, curqlevel->high)));
+ curqlevel->low, curqlevel->high)));
curqlevel = NEXTLEV(curqlevel);
}
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c
index 1b3c80b726..4dcb558fe4 100644
--- a/contrib/ltree/ltree_op.c
+++ b/contrib/ltree/ltree_op.c
@@ -83,49 +83,49 @@ Datum
ltree_cmp(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_INT32(res);
+ PG_RETURN_INT32(res);
}
Datum
ltree_lt(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_BOOL((res < 0) ? true : false);
+ PG_RETURN_BOOL((res < 0) ? true : false);
}
Datum
ltree_le(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_BOOL((res <= 0) ? true : false);
+ PG_RETURN_BOOL((res <= 0) ? true : false);
}
Datum
ltree_eq(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_BOOL((res == 0) ? true : false);
+ PG_RETURN_BOOL((res == 0) ? true : false);
}
Datum
ltree_ge(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_BOOL((res >= 0) ? true : false);
+ PG_RETURN_BOOL((res >= 0) ? true : false);
}
Datum
ltree_gt(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_BOOL((res > 0) ? true : false);
+ PG_RETURN_BOOL((res > 0) ? true : false);
}
Datum
ltree_ne(PG_FUNCTION_ARGS)
{
RUNCMP
- PG_RETURN_BOOL((res != 0) ? true : false);
+ PG_RETURN_BOOL((res != 0) ? true : false);
}
Datum
@@ -331,46 +331,55 @@ ltree_index(PG_FUNCTION_ARGS)
{
ltree *a = PG_GETARG_LTREE(0);
ltree *b = PG_GETARG_LTREE(1);
- int start=(fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
- int i,j;
- ltree_level *startptr, *aptr, *bptr;
- bool found=false;
-
- if ( start < 0 ) {
- if ( -start >= a->numlevel )
- start=0;
- else
- start = (int)(a->numlevel)+start;
+ int start = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
+ int i,
+ j;
+ ltree_level *startptr,
+ *aptr,
+ *bptr;
+ bool found = false;
+
+ if (start < 0)
+ {
+ if (-start >= a->numlevel)
+ start = 0;
+ else
+ start = (int) (a->numlevel) + start;
}
- if ( a->numlevel - start < b->numlevel || a->numlevel==0 || b->numlevel==0 ) {
+ if (a->numlevel - start < b->numlevel || a->numlevel == 0 || b->numlevel == 0)
+ {
PG_FREE_IF_COPY(a, 0);
PG_FREE_IF_COPY(b, 1);
PG_RETURN_INT32(-1);
}
- startptr=LTREE_FIRST(a);
- for(i=0; i<=a->numlevel-b->numlevel; i++) {
- if ( i>=start ) {
- aptr=startptr;
- bptr=LTREE_FIRST(b);
- for(j=0;j<b->numlevel;j++) {
- if ( !(aptr->len==bptr->len && strncmp(aptr->name,bptr->name, aptr->len)==0) )
- break;
- aptr=LEVEL_NEXT(aptr);
- bptr=LEVEL_NEXT(bptr);
+ startptr = LTREE_FIRST(a);
+ for (i = 0; i <= a->numlevel - b->numlevel; i++)
+ {
+ if (i >= start)
+ {
+ aptr = startptr;
+ bptr = LTREE_FIRST(b);
+ for (j = 0; j < b->numlevel; j++)
+ {
+ if (!(aptr->len == bptr->len && strncmp(aptr->name, bptr->name, aptr->len) == 0))
+ break;
+ aptr = LEVEL_NEXT(aptr);
+ bptr = LEVEL_NEXT(bptr);
}
-
- if ( j==b->numlevel ) {
- found=true;
+
+ if (j == b->numlevel)
+ {
+ found = true;
break;
}
}
- startptr=LEVEL_NEXT(startptr);
+ startptr = LEVEL_NEXT(startptr);
}
-
- if ( !found )
- i=-1;
+
+ if (!found)
+ i = -1;
PG_FREE_IF_COPY(a, 0);
PG_FREE_IF_COPY(b, 1);
@@ -496,18 +505,18 @@ Datum
text2ltree(PG_FUNCTION_ARGS)
{
text *in = PG_GETARG_TEXT_P(0);
- char *s = (char *) palloc(VARSIZE(in) - VARHDRSZ + 1);
- ltree *out;
+ char *s = (char *) palloc(VARSIZE(in) - VARHDRSZ + 1);
+ ltree *out;
memcpy(s, VARDATA(in), VARSIZE(in) - VARHDRSZ);
s[VARSIZE(in) - VARHDRSZ] = '\0';
out = (ltree *) DatumGetPointer(DirectFunctionCall1(
- ltree_in,
- PointerGetDatum(s)
- ));
+ ltree_in,
+ PointerGetDatum(s)
+ ));
pfree(s);
- PG_FREE_IF_COPY(in,0);
+ PG_FREE_IF_COPY(in, 0);
PG_RETURN_POINTER(out);
}
@@ -516,16 +525,18 @@ Datum
ltree2text(PG_FUNCTION_ARGS)
{
ltree *in = PG_GETARG_LTREE(0);
- char *ptr;
- int i;
+ char *ptr;
+ int i;
ltree_level *curlevel;
- text *out;
-
- out=(text*)palloc(in->len+VARHDRSZ);
- ptr = VARDATA(out);
+ text *out;
+
+ out = (text *) palloc(in->len + VARHDRSZ);
+ ptr = VARDATA(out);
curlevel = LTREE_FIRST(in);
- for (i = 0; i < in->numlevel; i++) {
- if (i != 0) {
+ for (i = 0; i < in->numlevel; i++)
+ {
+ if (i != 0)
+ {
*ptr = '.';
ptr++;
}
@@ -533,13 +544,9 @@ ltree2text(PG_FUNCTION_ARGS)
ptr += curlevel->len;
curlevel = LEVEL_NEXT(curlevel);
}
-
- VARATT_SIZEP(out) = VARHDRSZ + (ptr-VARDATA(out));
+
+ VARATT_SIZEP(out) = VARHDRSZ + (ptr - VARDATA(out));
PG_FREE_IF_COPY(in, 0);
-
+
PG_RETURN_POINTER(out);
}
-
-
-
-