diff options
Diffstat (limited to 'src/backend/utils/adt')
39 files changed, 1859 insertions, 1607 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 5a3b99f64a4..10e2f13bc32 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.57 2001/01/24 19:43:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.58 2001/03/22 03:59:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -262,7 +262,7 @@ aclitemin(PG_FUNCTION_ARGS) Datum aclitemout(PG_FUNCTION_ARGS) { - AclItem *aip = PG_GETARG_ACLITEM_P(0); + AclItem *aip = PG_GETARG_ACLITEM_P(0); char *p; char *out; HeapTuple htup; @@ -281,7 +281,7 @@ aclitemout(PG_FUNCTION_ARGS) if (HeapTupleIsValid(htup)) { strncat(p, - NameStr(((Form_pg_shadow) GETSTRUCT(htup))->usename), + NameStr(((Form_pg_shadow) GETSTRUCT(htup))->usename), NAMEDATALEN); ReleaseSysCache(htup); } @@ -291,7 +291,7 @@ aclitemout(PG_FUNCTION_ARGS) char *tmp; tmp = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum((int32) aip->ai_id))); + Int32GetDatum((int32) aip->ai_id))); strcat(p, tmp); pfree(tmp); } @@ -307,7 +307,7 @@ aclitemout(PG_FUNCTION_ARGS) char *tmp; tmp = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum((int32) aip->ai_id))); + Int32GetDatum((int32) aip->ai_id))); strcat(p, tmp); pfree(tmp); } @@ -473,9 +473,9 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg) } /* - * if the adjusted entry has no permissions, delete it from the - * list. For example, this helps in removing entries for users who no - * longer exist. EXCEPTION: never remove the world entry. + * if the adjusted entry has no permissions, delete it from the list. + * For example, this helps in removing entries for users who no longer + * exist. EXCEPTION: never remove the world entry. */ if (new_aip[dst].ai_mode == 0 && dst > 0) { @@ -502,7 +502,7 @@ Datum aclinsert(PG_FUNCTION_ARGS) { Acl *old_acl = PG_GETARG_ACL_P(0); - AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); + AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); PG_RETURN_ACL_P(aclinsert3(old_acl, mod_aip, ACL_MODECHG_EQL)); } @@ -511,7 +511,7 @@ Datum aclremove(PG_FUNCTION_ARGS) { Acl *old_acl = PG_GETARG_ACL_P(0); - AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); + AclItem *mod_aip = PG_GETARG_ACLITEM_P(1); Acl *new_acl; AclItem *old_aip, *new_aip; @@ -575,7 +575,7 @@ Datum aclcontains(PG_FUNCTION_ARGS) { Acl *acl = PG_GETARG_ACL_P(0); - AclItem *aip = PG_GETARG_ACLITEM_P(1); + AclItem *aip = PG_GETARG_ACLITEM_P(1); AclItem *aidat; int i, num; @@ -599,7 +599,7 @@ aclcontains(PG_FUNCTION_ARGS) void ExecuteChangeACLStmt(ChangeACLStmt *stmt) { - AclItem aclitem; + AclItem aclitem; unsigned modechg; List *i; diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index d76fe6d64fe..84c674071c1 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.69 2001/01/24 19:43:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.70 2001/03/22 03:59:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,29 +60,29 @@ static int ArrayCount(char *str, int *dim, int typdelim); static Datum *ReadArrayStr(char *arrayStr, int nitems, int ndim, int *dim, - FmgrInfo *inputproc, Oid typelem, int32 typmod, - char typdelim, int typlen, bool typbyval, - char typalign, int *nbytes); + FmgrInfo *inputproc, Oid typelem, int32 typmod, + char typdelim, int typlen, bool typbyval, + char typalign, int *nbytes); static void CopyArrayEls(char *p, Datum *values, int nitems, - bool typbyval, int typlen, char typalign, - bool freedata); + bool typbyval, int typlen, char typalign, + bool freedata); static void system_cache_lookup(Oid element_type, bool input, int *typlen, - bool *typbyval, char *typdelim, Oid *typelem, - Oid *proc, char *typalign); + bool *typbyval, char *typdelim, Oid *typelem, + Oid *proc, char *typalign); static Datum ArrayCast(char *value, bool byval, int len); static int ArrayCastAndSet(Datum src, bool typbyval, int typlen, char *dest); static int array_nelems_size(char *ptr, int eltsize, int nitems); static char *array_seek(char *ptr, int eltsize, int nitems); static int array_copy(char *destptr, int eltsize, int nitems, char *srcptr); -static int array_slice_size(int ndim, int *dim, int *lb, char *arraydataptr, - int eltsize, int *st, int *endp); +static int array_slice_size(int ndim, int *dim, int *lb, char *arraydataptr, + int eltsize, int *st, int *endp); static void array_extract_slice(int ndim, int *dim, int *lb, - char *arraydataptr, int eltsize, - int *st, int *endp, char *destPtr); + char *arraydataptr, int eltsize, + int *st, int *endp, char *destPtr); static void array_insert_slice(int ndim, int *dim, int *lb, - char *origPtr, int origdatasize, - char *destPtr, int eltsize, - int *st, int *endp, char *srcPtr); + char *origPtr, int origdatasize, + char *destPtr, int eltsize, + int *st, int *endp, char *srcPtr); /*--------------------------------------------------------------------- @@ -96,9 +96,11 @@ static void array_insert_slice(int ndim, int *dim, int *lb, Datum array_in(PG_FUNCTION_ARGS) { - char *string = PG_GETARG_CSTRING(0); /* external form */ - Oid element_type = PG_GETARG_OID(1); /* type of an array element */ - int32 typmod = PG_GETARG_INT32(2); /* typmod for array elements */ + char *string = PG_GETARG_CSTRING(0); /* external form */ + Oid element_type = PG_GETARG_OID(1); /* type of an array + * element */ + int32 typmod = PG_GETARG_INT32(2); /* typmod for array + * elements */ int typlen; bool typbyval; char typdelim; @@ -132,8 +134,8 @@ array_in(PG_FUNCTION_ARGS) * Otherwise, we require the input to be in curly-brace style, and we * prescan the input to determine dimensions. * - * Dimension info takes the form of one or more [n] or [m:n] items. - * The outer loop iterates once per dimension item. + * Dimension info takes the form of one or more [n] or [m:n] items. The + * outer loop iterates once per dimension item. */ p = string_save; ndim = 0; @@ -450,6 +452,7 @@ ReadArrayStr(char *arrayStr, ObjectIdGetDatum(typelem), Int32GetDatum(typmod)); p = ++q; + /* * if not at the end of the array skip white space */ @@ -460,6 +463,7 @@ ReadArrayStr(char *arrayStr, q++; } } + /* * Initialize any unset items and compute total data space needed */ @@ -511,7 +515,7 @@ ReadArrayStr(char *arrayStr, * referenced by Datums after copying them. * * If the input data is of varlena type, the caller must have ensured that - * the values are not toasted. (Doing it here doesn't work since the + * the values are not toasted. (Doing it here doesn't work since the * caller has already allocated space for the array...) *---------- */ @@ -601,7 +605,7 @@ array_out(PG_FUNCTION_ARGS) itemvalue = fetch_att(p, typbyval, typlen); values[i] = DatumGetCString(FunctionCall3(&outputproc, itemvalue, - ObjectIdGetDatum(typelem), + ObjectIdGetDatum(typelem), Int32GetDatum(-1))); if (typlen > 0) p += typlen; @@ -706,6 +710,7 @@ array_dims(PG_FUNCTION_ARGS) PG_RETURN_NULL(); nbytes = ARR_NDIM(v) * 33 + 1; + /* * 33 since we assume 15 digits per number + ':' +'[]' * @@ -759,6 +764,7 @@ array_ref(ArrayType *array, if (arraylen > 0) { + /* * fixed-length arrays -- these are assumed to be 1-d, 0-based */ @@ -809,7 +815,7 @@ array_ref(ArrayType *array, * lowerIndx[] and upperIndx[]. These are generally just temporaries. *----------------------------------------------------------------------------- */ -ArrayType * +ArrayType * array_get_slice(ArrayType *array, int nSubscripts, int *upperIndx, @@ -835,6 +841,7 @@ array_get_slice(ArrayType *array, if (arraylen > 0) { + /* * fixed-length arrays -- currently, cannot slice these because * parser labels output as being of the fixed-length array type! @@ -866,8 +873,9 @@ array_get_slice(ArrayType *array, /* * Check provided subscripts. A slice exceeding the current array - * limits is silently truncated to the array limits. If we end up with - * an empty slice, return NULL (should it be an empty array instead?) + * limits is silently truncated to the array limits. If we end up + * with an empty slice, return NULL (should it be an empty array + * instead?) */ if (ndim != nSubscripts || ndim <= 0 || ndim > MAXDIM) RETURN_NULL(ArrayType *); @@ -918,7 +926,7 @@ array_get_slice(ArrayType *array, * with NULL, which will probably not make him happy. *----------------------------------------------------------------------------- */ -ArrayType * +ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, @@ -950,9 +958,10 @@ array_set(ArrayType *array, if (arraylen > 0) { + /* - * fixed-length arrays -- these are assumed to be 1-d, 0-based. - * We cannot extend them, either. + * fixed-length arrays -- these are assumed to be 1-d, 0-based. We + * cannot extend them, either. */ if (nSubscripts != 1) elog(ERROR, "Invalid array subscripts"); @@ -994,9 +1003,7 @@ array_set(ArrayType *array, extendbefore = true; } else - { elog(ERROR, "Invalid array subscripts"); - } } if (indx[i] >= (dim[i] + lb[i])) { @@ -1006,9 +1013,7 @@ array_set(ArrayType *array, extendafter = true; } else - { elog(ERROR, "Invalid array subscripts"); - } } } @@ -1085,7 +1090,7 @@ array_set(ArrayType *array, * with NULL, which will probably not make him happy. *---------------------------------------------------------------------------- */ -ArrayType * +ArrayType * array_set_slice(ArrayType *array, int nSubscripts, int *upperIndx, @@ -1118,6 +1123,7 @@ array_set_slice(ArrayType *array, if (arraylen > 0) { + /* * fixed-length arrays -- not got round to doing this... */ @@ -1141,8 +1147,8 @@ array_set_slice(ArrayType *array, /* * Check provided subscripts. A slice exceeding the current array * limits throws an error, *except* in the 1-D case where we will - * extend the array as long as no hole is created. - * An empty slice is an error, too. + * extend the array as long as no hole is created. An empty slice is + * an error, too. */ for (i = 0; i < ndim; i++) { @@ -1156,26 +1162,20 @@ array_set_slice(ArrayType *array, lb[i] = lowerIndx[i]; } else - { elog(ERROR, "Invalid array subscripts"); - } } if (upperIndx[i] >= (dim[i] + lb[i])) { if (ndim == 1 && lowerIndx[i] <= (dim[i] + lb[i])) - { dim[i] = upperIndx[i] - lb[i] + 1; - } else - { elog(ERROR, "Invalid array subscripts"); - } } } /* - * Make sure source array has enough entries. Note we ignore the shape - * of the source array and just read entries serially. + * Make sure source array has enough entries. Note we ignore the + * shape of the source array and just read entries serially. */ mda_get_range(ndim, span, lowerIndx, upperIndx); nsrcitems = ArrayGetNItems(ndim, span); @@ -1192,24 +1192,27 @@ array_set_slice(ArrayType *array, olddatasize = ARR_SIZE(array) - overheadlen; if (ndim > 1) { + /* - * here we do not need to cope with extension of the array; - * it would be a lot more complicated if we had to do so... + * here we do not need to cope with extension of the array; it + * would be a lot more complicated if we had to do so... */ olditemsize = array_slice_size(ndim, dim, lb, ARR_DATA_PTR(array), elmlen, lowerIndx, upperIndx); - lenbefore = lenafter = 0; /* keep compiler quiet */ + lenbefore = lenafter = 0; /* keep compiler quiet */ } else { + /* - * here we must allow for possibility of slice larger than orig array + * here we must allow for possibility of slice larger than orig + * array */ - int oldlb = ARR_LBOUND(array)[0]; - int oldub = oldlb + ARR_DIMS(array)[0] - 1; - int slicelb = MAX(oldlb, lowerIndx[0]); - int sliceub = MIN(oldub, upperIndx[0]); - char *oldarraydata = ARR_DATA_PTR(array); + int oldlb = ARR_LBOUND(array)[0]; + int oldub = oldlb + ARR_DIMS(array)[0] - 1; + int slicelb = MAX(oldlb, lowerIndx[0]); + int sliceub = MIN(oldub, upperIndx[0]); + char *oldarraydata = ARR_DATA_PTR(array); lenbefore = array_nelems_size(oldarraydata, elmlen, @@ -1234,9 +1237,10 @@ array_set_slice(ArrayType *array, if (ndim > 1) { + /* - * here we do not need to cope with extension of the array; - * it would be a lot more complicated if we had to do so... + * here we do not need to cope with extension of the array; it + * would be a lot more complicated if we had to do so... */ array_insert_slice(ndim, dim, lb, ARR_DATA_PTR(array), olddatasize, ARR_DATA_PTR(newarray), elmlen, @@ -1261,7 +1265,7 @@ array_set_slice(ArrayType *array, /* * array_map() * - * Map an array through an arbitrary function. Return a new array with + * Map an array through an arbitrary function. Return a new array with * same dimensions and each source element transformed by fn(). Each * source element is passed as the first argument to fn(); additional * arguments to be passed to fn() can be specified by the caller. @@ -1269,15 +1273,15 @@ array_set_slice(ArrayType *array, * * Parameters are: * * fcinfo: a function-call data structure pre-constructed by the caller - * to be ready to call the desired function, with everything except the - * first argument position filled in. In particular, flinfo identifies - * the function fn(), and if nargs > 1 then argument positions after the - * first must be preset to the additional values to be passed. The - * first argument position initially holds the input array value. + * to be ready to call the desired function, with everything except the + * first argument position filled in. In particular, flinfo identifies + * the function fn(), and if nargs > 1 then argument positions after the + * first must be preset to the additional values to be passed. The + * first argument position initially holds the input array value. * * inpType: OID of element type of input array. This must be the same as, - * or binary-compatible with, the first argument type of fn(). - * * retType: OID of element type of output array. This must be the same as, - * or binary-compatible with, the result type of fn(). + * or binary-compatible with, the first argument type of fn(). + * * retType: OID of element type of output array. This must be the same as, + * or binary-compatible with, the result type of fn(). * * NB: caller must assure that input array is not NULL. Currently, * any additional parameters passed to fn() may not be specified as NULL @@ -1344,9 +1348,9 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) /* * Apply the given function to source elt and extra args. * - * We assume the extra args are non-NULL, so need not check - * whether fn() is strict. Would need to do more work here - * to support arrays containing nulls, too. + * We assume the extra args are non-NULL, so need not check whether + * fn() is strict. Would need to do more work here to support + * arrays containing nulls, too. */ fcinfo->arg[0] = elt; fcinfo->argnull[0] = false; @@ -1374,7 +1378,10 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) result->ndim = ndim; memcpy(ARR_DIMS(result), ARR_DIMS(v), 2 * ndim * sizeof(int)); - /* Note: do not risk trying to pfree the results of the called function */ + /* + * Note: do not risk trying to pfree the results of the called + * function + */ CopyArrayEls(ARR_DATA_PTR(result), values, nitems, typbyval, typlen, typalign, false); pfree(values); @@ -1383,7 +1390,7 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) } /*---------- - * construct_array --- simple method for constructing an array object + * construct_array --- simple method for constructing an array object * * elems: array of Datum items to become the array contents * nelems: number of items @@ -1394,7 +1401,7 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType) * NULL element values are not supported. *---------- */ -ArrayType * +ArrayType * construct_array(Datum *elems, int nelems, bool elmbyval, int elmlen, char elmalign) { diff --git a/src/backend/utils/adt/ascii.c b/src/backend/utils/adt/ascii.c index ddc365f2004..bdcd24e44e0 100644 --- a/src/backend/utils/adt/ascii.c +++ b/src/backend/utils/adt/ascii.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- * ascii.c * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.6 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.7 2001/03/22 03:59:49 momjian Exp $ * * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group * @@ -33,21 +33,21 @@ multibyte_error(void) elog(ERROR, "Multi-byte support is not enabled"); } -Datum +Datum to_ascii_encname(PG_FUNCTION_ARGS) { multibyte_error(); return 0; /* keep compiler quiet */ } -Datum +Datum to_ascii_enc(PG_FUNCTION_ARGS) { multibyte_error(); return 0; /* keep compiler quiet */ } -Datum +Datum to_ascii_default(PG_FUNCTION_ARGS) { multibyte_error(); @@ -55,29 +55,29 @@ to_ascii_default(PG_FUNCTION_ARGS) } -#else /* with MULTIBYTE */ +#else /* with MULTIBYTE */ static text *encode_to_ascii(text *data, int enc); /* ---------- - * to_ascii + * to_ascii * ---------- */ char * pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int enc) { - unsigned char *x = NULL; - unsigned char *ascii = NULL ; - int range = 0; - - /* - * relevant start for an encoding - */ - #define RANGE_128 128 - #define RANGE_160 160 - - + unsigned char *x = NULL; + unsigned char *ascii = NULL; + int range = 0; + + /* + * relevant start for an encoding + */ +#define RANGE_128 128 +#define RANGE_160 160 + + if (enc == LATIN1) { /* ---------- @@ -107,24 +107,24 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int } else { - elog(ERROR, "pg_to_ascii(): unsupported encoding from %s", - pg_encoding_to_char(enc)); + elog(ERROR, "pg_to_ascii(): unsupported encoding from %s", + pg_encoding_to_char(enc)); } - + /* ---------- * Encode * ---------- */ for (x = src; x <= src_end; x++) { - if (*x < 128) + if (*x < 128) *desc++ = *x; else if (*x < range) - *desc++ = ' '; /* bogus 128 to 'range' */ + *desc++ = ' '; /* bogus 128 to 'range' */ else - *desc++ = ascii[*x - range]; - } - + *desc++ = ascii[*x - range]; + } + return desc; } @@ -136,11 +136,11 @@ static text * encode_to_ascii(text *data, int enc) { pg_to_ascii( - (unsigned char *) VARDATA(data), /* src */ - VARDATA(data) + VARSIZE(data), /* src end */ - (unsigned char *) VARDATA(data), /* desc */ - enc); /* encoding */ - + (unsigned char *) VARDATA(data), /* src */ + VARDATA(data) + VARSIZE(data), /* src end */ + (unsigned char *) VARDATA(data), /* desc */ + enc); /* encoding */ + return data; } @@ -152,30 +152,30 @@ Datum to_ascii_encname(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P - ( - encode_to_ascii - ( - PG_GETARG_TEXT_P_COPY(0), - pg_char_to_encoding( NameStr(*PG_GETARG_NAME(1)) ) - ) - ); + ( + encode_to_ascii + ( + PG_GETARG_TEXT_P_COPY(0), + pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1))) + ) + ); } /* ---------- * convert to ASCII - enc is set as int4 * ---------- */ -Datum +Datum to_ascii_enc(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P - ( - encode_to_ascii - ( - PG_GETARG_TEXT_P_COPY(0), - PG_GETARG_INT32(1) - ) - ); + ( + encode_to_ascii + ( + PG_GETARG_TEXT_P_COPY(0), + PG_GETARG_INT32(1) + ) + ); } /* ---------- @@ -185,14 +185,14 @@ to_ascii_enc(PG_FUNCTION_ARGS) Datum to_ascii_default(PG_FUNCTION_ARGS) { - PG_RETURN_TEXT_P - ( - encode_to_ascii - ( - PG_GETARG_TEXT_P_COPY(0), - GetDatabaseEncoding() - ) + PG_RETURN_TEXT_P + ( + encode_to_ascii + ( + PG_GETARG_TEXT_P_COPY(0), + GetDatabaseEncoding() + ) ); } -#endif /* MULTIBYTE */ +#endif /* MULTIBYTE */ diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c index 4f702b24595..dba0fe61492 100644 --- a/src/backend/utils/adt/bool.c +++ b/src/backend/utils/adt/bool.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.24 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.25 2001/03/22 03:59:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,8 +36,8 @@ boolin(PG_FUNCTION_ARGS) switch (*b) { - case 't': - case 'T': + case 't': + case 'T': if (strncasecmp(b, "true", strlen(b)) == 0) PG_RETURN_BOOL(true); break; @@ -187,7 +187,7 @@ isfalse(PG_FUNCTION_ARGS) b = PG_GETARG_BOOL(0); - PG_RETURN_BOOL(! b); + PG_RETURN_BOOL(!b); } Datum @@ -200,7 +200,7 @@ isnottrue(PG_FUNCTION_ARGS) b = PG_GETARG_BOOL(0); - PG_RETURN_BOOL(! b); + PG_RETURN_BOOL(!b); } Datum diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index 7a3a5c11be9..dbcf881bf6c 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -9,7 +9,7 @@ * workings can be found in the book "Software Solutions in C" by * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.49 2000/12/03 20:45:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.50 2001/03/22 03:59:49 momjian Exp $ */ #include "postgres.h" @@ -82,20 +82,23 @@ cash_in(PG_FUNCTION_ARGS) ssymbol, psymbol, *nsymbol; + #ifdef USE_LOCALE struct lconv *lconvert = PGLC_localeconv(); + #endif #ifdef USE_LOCALE + /* * frac_digits will be CHAR_MAX in some locales, notably C. However, * just testing for == CHAR_MAX is risky, because of compilers like * gcc that "helpfully" let you alter the platform-standard definition * of whether char is signed or not. If we are so unfortunate as to * get compiled with a nonstandard -fsigned-char or -funsigned-char - * switch, then our idea of CHAR_MAX will not agree with libc's. - * The safest course is not to test for CHAR_MAX at all, but to impose - * a range check for plausible frac_digits values. + * switch, then our idea of CHAR_MAX will not agree with libc's. The + * safest course is not to test for CHAR_MAX at all, but to impose a + * range check for plausible frac_digits values. */ fpoint = lconvert->frac_digits; if (fpoint < 0 || fpoint > 10) @@ -238,8 +241,10 @@ cash_out(PG_FUNCTION_ARGS) dsymbol, *nsymbol; char convention; + #ifdef USE_LOCALE struct lconv *lconvert = PGLC_localeconv(); + #endif #ifdef USE_LOCALE @@ -249,8 +254,8 @@ cash_out(PG_FUNCTION_ARGS) points = 2; /* best guess in this case, I think */ /* - * As with frac_digits, must apply a range check to mon_grouping - * to avoid being fooled by variant CHAR_MAX values. + * As with frac_digits, must apply a range check to mon_grouping to + * avoid being fooled by variant CHAR_MAX values. */ mon_group = *lconvert->mon_grouping; if (mon_group <= 0 || mon_group > 6) @@ -680,7 +685,7 @@ cash_words(PG_FUNCTION_ARGS) buf[0] = '\0'; m0 = value % 100; /* cents */ - m1 = (value / 100) % 1000; /* hundreds */ + m1 = (value / 100) % 1000; /* hundreds */ m2 = (value / 100000) % 1000; /* thousands */ m3 = value / 100000000 % 1000; /* millions */ diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index 35031e81873..5e7d3c92f2e 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.55 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.56 2001/03/22 03:59:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,7 @@ date_in(PG_FUNCTION_ARGS) char lowstr[MAXDATELEN + 1]; if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0) - || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0)) + || (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0)) elog(ERROR, "Bad date external representation '%s'", str); switch (dtype) @@ -244,15 +244,15 @@ date_timestamp(PG_FUNCTION_ARGS) if (utime == -1) elog(ERROR, "Unable to convert date to tm"); - result = utime + ((date2j(1970,1,1)-date2j(2000,1,1))*86400.0); + result = utime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400.0); #else - result = dateVal*86400.0+CTimeZone; + result = dateVal * 86400.0 + CTimeZone; #endif } else { /* Outside of range for timezone support, so assume UTC */ - result = dateVal*86400.0; + result = dateVal * 86400.0; } PG_RETURN_TIMESTAMP(result); @@ -277,13 +277,9 @@ timestamp_date(PG_FUNCTION_ARGS) elog(ERROR, "Unable to convert timestamp to date"); if (TIMESTAMP_IS_EPOCH(timestamp)) - { timestamp2tm(SetTimestamp(timestamp), NULL, tm, &fsec, NULL); - } else if (TIMESTAMP_IS_CURRENT(timestamp)) - { timestamp2tm(SetTimestamp(timestamp), &tz, tm, &fsec, &tzn); - } else { if (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) != 0) @@ -538,8 +534,10 @@ time_smaller(PG_FUNCTION_ARGS) Datum overlaps_time(PG_FUNCTION_ARGS) { - /* The arguments are TimeADT, but we leave them as generic Datums - * to avoid dereferencing nulls (TimeADT is pass-by-reference!) + + /* + * The arguments are TimeADT, but we leave them as generic Datums to + * avoid dereferencing nulls (TimeADT is pass-by-reference!) */ Datum ts1 = PG_GETARG_DATUM(0); Datum te1 = PG_GETARG_DATUM(1); @@ -556,9 +554,9 @@ overlaps_time(PG_FUNCTION_ARGS) (DatumGetTimeADT(t1) < DatumGetTimeADT(t2)) /* - * If both endpoints of interval 1 are null, the result is null (unknown). - * If just one endpoint is null, take ts1 as the non-null one. - * Otherwise, take ts1 as the lesser endpoint. + * If both endpoints of interval 1 are null, the result is null + * (unknown). If just one endpoint is null, take ts1 as the non-null + * one. Otherwise, take ts1 as the lesser endpoint. */ if (ts1IsNull) { @@ -572,7 +570,7 @@ overlaps_time(PG_FUNCTION_ARGS) { if (TIMEADT_GT(ts1, te1)) { - Datum tt = ts1; + Datum tt = ts1; ts1 = te1; te1 = tt; @@ -592,7 +590,7 @@ overlaps_time(PG_FUNCTION_ARGS) { if (TIMEADT_GT(ts2, te2)) { - Datum tt = ts2; + Datum tt = ts2; ts2 = te2; te2 = tt; @@ -605,7 +603,9 @@ overlaps_time(PG_FUNCTION_ARGS) */ if (TIMEADT_GT(ts1, ts2)) { - /* This case is ts1 < te2 OR te1 < te2, which may look redundant + + /* + * This case is ts1 < te2 OR te1 < te2, which may look redundant * but in the presence of nulls it's not quite completely so. */ if (te2IsNull) @@ -614,7 +614,9 @@ overlaps_time(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); - /* If te1 is not null then we had ts1 <= te1 above, and we just + + /* + * If te1 is not null then we had ts1 <= te1 above, and we just * found ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); @@ -628,15 +630,20 @@ overlaps_time(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); - /* If te2 is not null then we had ts2 <= te2 above, and we just + + /* + * If te2 is not null then we had ts2 <= te2 above, and we just * found ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { - /* For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a - * rather silly way of saying "true if both are nonnull, else null". + + /* + * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a + * rather silly way of saying "true if both are nonnull, else + * null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); @@ -690,7 +697,7 @@ datetime_timestamp(PG_FUNCTION_ARGS) Timestamp result; result = DatumGetTimestamp(DirectFunctionCall1(date_timestamp, - DateADTGetDatum(date))); + DateADTGetDatum(date))); result += time; PG_RETURN_TIMESTAMP(result); @@ -895,62 +902,62 @@ timetz_out(PG_FUNCTION_ARGS) Datum timetz_eq(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) == (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) == (time2->time + time2->zone))); } Datum timetz_ne(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) != (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) != (time2->time + time2->zone))); } Datum timetz_lt(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) < (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) < (time2->time + time2->zone))); } Datum timetz_le(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) <= (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) <= (time2->time + time2->zone))); } Datum timetz_gt(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) > (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) > (time2->time + time2->zone))); } Datum timetz_ge(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); - PG_RETURN_BOOL(((time1->time+time1->zone) >= (time2->time+time2->zone))); + PG_RETURN_BOOL(((time1->time + time1->zone) >= (time2->time + time2->zone))); } Datum timetz_cmp(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); if (DatumGetBool(DirectFunctionCall2(timetz_lt, TimeTzADTPGetDatum(time1), @@ -969,7 +976,7 @@ timetz_cmp(PG_FUNCTION_ARGS) Datum timetz_hash(PG_FUNCTION_ARGS) { - TimeTzADT *key = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *key = PG_GETARG_TIMETZADT_P(0); /* * Specify hash length as sizeof(double) + sizeof(int4), not as @@ -982,8 +989,8 @@ timetz_hash(PG_FUNCTION_ARGS) Datum timetz_larger(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); if (DatumGetBool(DirectFunctionCall2(timetz_gt, TimeTzADTPGetDatum(time1), @@ -995,8 +1002,8 @@ timetz_larger(PG_FUNCTION_ARGS) Datum timetz_smaller(PG_FUNCTION_ARGS) { - TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); - TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); + TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); + TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); if (DatumGetBool(DirectFunctionCall2(timetz_lt, TimeTzADTPGetDatum(time1), @@ -1058,7 +1065,9 @@ timetz_mi_interval(PG_FUNCTION_ARGS) Datum overlaps_timetz(PG_FUNCTION_ARGS) { - /* The arguments are TimeTzADT *, but we leave them as generic Datums + + /* + * The arguments are TimeTzADT *, but we leave them as generic Datums * for convenience of notation --- and to avoid dereferencing nulls. */ Datum ts1 = PG_GETARG_DATUM(0); @@ -1076,9 +1085,9 @@ overlaps_timetz(PG_FUNCTION_ARGS) DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2)) /* - * If both endpoints of interval 1 are null, the result is null (unknown). - * If just one endpoint is null, take ts1 as the non-null one. - * Otherwise, take ts1 as the lesser endpoint. + * If both endpoints of interval 1 are null, the result is null + * (unknown). If just one endpoint is null, take ts1 as the non-null + * one. Otherwise, take ts1 as the lesser endpoint. */ if (ts1IsNull) { @@ -1092,7 +1101,7 @@ overlaps_timetz(PG_FUNCTION_ARGS) { if (TIMETZ_GT(ts1, te1)) { - Datum tt = ts1; + Datum tt = ts1; ts1 = te1; te1 = tt; @@ -1112,7 +1121,7 @@ overlaps_timetz(PG_FUNCTION_ARGS) { if (TIMETZ_GT(ts2, te2)) { - Datum tt = ts2; + Datum tt = ts2; ts2 = te2; te2 = tt; @@ -1125,7 +1134,9 @@ overlaps_timetz(PG_FUNCTION_ARGS) */ if (TIMETZ_GT(ts1, ts2)) { - /* This case is ts1 < te2 OR te1 < te2, which may look redundant + + /* + * This case is ts1 < te2 OR te1 < te2, which may look redundant * but in the presence of nulls it's not quite completely so. */ if (te2IsNull) @@ -1134,7 +1145,9 @@ overlaps_timetz(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); - /* If te1 is not null then we had ts1 <= te1 above, and we just + + /* + * If te1 is not null then we had ts1 <= te1 above, and we just * found ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); @@ -1148,15 +1161,20 @@ overlaps_timetz(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); - /* If te2 is not null then we had ts2 <= te2 above, and we just + + /* + * If te2 is not null then we had ts2 <= te2 above, and we just * found ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { - /* For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a - * rather silly way of saying "true if both are nonnull, else null". + + /* + * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a + * rather silly way of saying "true if both are nonnull, else + * null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); @@ -1219,7 +1237,7 @@ datetimetz_timestamp(PG_FUNCTION_ARGS) TimeTzADT *time = PG_GETARG_TIMETZADT_P(1); Timestamp result; - result = date*86400.0 + time->time + time->zone; + result = date * 86400.0 + time->time + time->zone; PG_RETURN_TIMESTAMP(result); } diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 8e9299643ff..8691fa49b91 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.61 2001/03/14 20:12:10 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.62 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,16 +25,16 @@ #include "utils/datetime.h" static int DecodeNumber(int flen, char *field, - int fmask, int *tmask, - struct tm * tm, double *fsec, int *is2digits); + int fmask, int *tmask, + struct tm * tm, double *fsec, int *is2digits); static int DecodeNumberField(int len, char *str, - int fmask, int *tmask, - struct tm * tm, double *fsec, int *is2digits); + int fmask, int *tmask, + struct tm * tm, double *fsec, int *is2digits); static int DecodeTime(char *str, int fmask, int *tmask, - struct tm * tm, double *fsec); + struct tm * tm, double *fsec); static int DecodeTimezone(char *str, int *tzp); static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel); -static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); +static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); #define USE_DATE_CACHE 1 #define ROUND_ALL 0 @@ -271,10 +271,13 @@ static datetkn deltatktbl[] = { {"m", UNITS, DTK_MINUTE}, /* "minute" relative time units */ {"microsecon", UNITS, DTK_MICROSEC}, /* "microsecond" relative * time units */ - {"mil", UNITS, DTK_MILLENNIUM}, /* "millennium" relative time units */ - {"mils", UNITS, DTK_MILLENNIUM}, /* "millennia" relative time units */ - {"millennia", UNITS, DTK_MILLENNIUM}, /* "millennia" relative time units */ - {DMILLENNIUM, UNITS, DTK_MILLENNIUM}, /* "millennium" relative time units */ + {"mil", UNITS, DTK_MILLENNIUM}, /* "millennium" relative time + * units */ + {"mils", UNITS, DTK_MILLENNIUM}, /* "millennia" relative time units */ + {"millennia", UNITS, DTK_MILLENNIUM}, /* "millennia" relative + * time units */ + {DMILLENNIUM, UNITS, DTK_MILLENNIUM}, /* "millennium" relative + * time units */ {"millisecon", UNITS, DTK_MILLISEC}, /* relative time units */ {"min", UNITS, DTK_MINUTE}, /* "minute" relative time units */ {"mins", UNITS, DTK_MINUTE},/* "minutes" relative time units */ @@ -876,14 +879,14 @@ DecodeDateTime(char **field, int *ftype, int nf, tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is * Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif /* HAVE_INT_TIMEZONE */ +#endif /* HAVE_INT_TIMEZONE */ -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ *tzp = CTimeZone; #endif } @@ -1121,13 +1124,13 @@ DecodeTimeOnly(char **field, int *ftype, int nf, mktime(tmp); tm->tm_isdst = tmp->tm_isdst; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) *tzp = -(tmp->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) *tzp = ((tmp->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ *tzp = CTimeZone; #endif } @@ -1492,7 +1495,7 @@ DecodeNumberField(int len, char *str, int fmask, return -1; return 0; -} /* DecodeNumberField() */ +} /* DecodeNumberField() */ /* DecodeTimezone() @@ -1674,20 +1677,26 @@ DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, do break; case DTK_TZ: + /* * Timezone is a token with a leading sign character and * otherwise the same as a non-signed time field */ Assert((*field[i] == '-') || (*field[i] == '+')); - /* A single signed number ends up here, but will be rejected by DecodeTime(). - * So, work this out to drop through to DTK_NUMBER, which *can* tolerate this. + + /* + * A single signed number ends up here, but will be + * rejected by DecodeTime(). So, work this out to drop + * through to DTK_NUMBER, which *can* tolerate this. */ - cp = field[i]+1; + cp = field[i] + 1; while ((*cp != '\0') && (*cp != ':') && (*cp != '.')) cp++; if ((*cp == ':') - && (DecodeTime((field[i]+1), fmask, &tmask, tm, fsec) == 0)) { - if (*field[i] == '-') { + && (DecodeTime((field[i] + 1), fmask, &tmask, tm, fsec) == 0)) + { + if (*field[i] == '-') + { /* flip the sign on all fields */ tm->tm_hour = -tm->tm_hour; tm->tm_min = -tm->tm_min; @@ -1695,18 +1704,33 @@ DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, do *fsec = -(*fsec); } - /* Set the next type to be a day, if units are not specified. - * This handles the case of '1 +02:03' since we are reading right to left. + /* + * Set the next type to be a day, if units are not + * specified. This handles the case of '1 +02:03' + * since we are reading right to left. */ type = DTK_DAY; tmask = DTK_M(TZ); break; - } else if (type == IGNORE) { - if (*cp == '.') { - /* Got a decimal point? Then assume some sort of seconds specification */ + } + else if (type == IGNORE) + { + if (*cp == '.') + { + + /* + * Got a decimal point? Then assume some sort of + * seconds specification + */ type = DTK_SECOND; - } else if (*cp == '\0') { - /* Only a signed integer? Then must assume a timezone-like usage */ + } + else if (*cp == '\0') + { + + /* + * Only a signed integer? Then must assume a + * timezone-like usage + */ type = DTK_HOUR; } } @@ -1921,7 +1945,7 @@ DecodeUnits(int field, char *lowtoken, int *val) * Binary search -- from Knuth (6.2.1) Algorithm B. Special case like this * is WAY faster than the generic bsearch(). */ -static datetkn * +static datetkn * datebsearch(char *key, datetkn *base, unsigned int nel) { datetkn *last = base + nel - 1, @@ -2166,7 +2190,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha if ((*tzn != NULL) && (tm->tm_isdst >= 0)) { strcpy((str + 27), " "); - StrNCpy((str + 28), *tzn, MAXTZLEN+1); + StrNCpy((str + 28), *tzn, MAXTZLEN + 1); } } else @@ -2175,7 +2199,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha if ((*tzn != NULL) && (tm->tm_isdst >= 0)) { strcpy((str + 24), " "); - StrNCpy((str + 25), *tzn, MAXTZLEN+1); + StrNCpy((str + 25), *tzn, MAXTZLEN + 1); } } @@ -2207,10 +2231,11 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) int is_nonzero = FALSE; char *cp = str; - /* The sign of year and month are guaranteed to match, - * since they are stored internally as "month". - * But we'll need to check for is_before and is_nonzero - * when determining the signs of hour/minute/seconds fields. + /* + * The sign of year and month are guaranteed to match, since they are + * stored internally as "month". But we'll need to check for is_before + * and is_nonzero when determining the signs of hour/minute/seconds + * fields. */ switch (style) { @@ -2247,8 +2272,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if ((!is_nonzero) || (tm->tm_hour != 0) || (tm->tm_min != 0) || (tm->tm_sec != 0) || (fsec != 0)) { - int minus = ((tm->tm_hour < 0) || (tm->tm_min < 0) - || (tm->tm_sec < 0) || (fsec < 0)); + int minus = ((tm->tm_hour < 0) || (tm->tm_min < 0) + || (tm->tm_sec < 0) || (fsec < 0)); sprintf(cp, "%s%s%02d:%02d", (is_nonzero ? " " : ""), (minus ? "-" : (is_before ? "+" : "")), @@ -2283,7 +2308,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_year != 0) { - int year = tm->tm_year; + int year = tm->tm_year; + if (tm->tm_year < 0) year = -year; @@ -2296,55 +2322,59 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_mon != 0) { - int mon = tm->tm_mon; + int mon = tm->tm_mon; + if (is_before || ((!is_nonzero) && (tm->tm_mon < 0))) mon = -mon; sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), mon, ((mon != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_mon < 0); is_nonzero = TRUE; } if (tm->tm_mday != 0) { - int day = tm->tm_mday; + int day = tm->tm_mday; + if (is_before || ((!is_nonzero) && (tm->tm_mday < 0))) day = -day; sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), day, ((day != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_mday < 0); is_nonzero = TRUE; } if (tm->tm_hour != 0) { - int hour = tm->tm_hour; + int hour = tm->tm_hour; + if (is_before || ((!is_nonzero) && (tm->tm_hour < 0))) hour = -hour; sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), hour, ((hour != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_hour < 0); is_nonzero = TRUE; } if (tm->tm_min != 0) { - int min = tm->tm_min; + int min = tm->tm_min; + if (is_before || ((!is_nonzero) && (tm->tm_min < 0))) min = -min; sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), min, ((min != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_min < 0); is_nonzero = TRUE; } @@ -2352,7 +2382,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) /* fractional seconds? */ if (fsec != 0) { - double sec; + double sec; + fsec += tm->tm_sec; sec = fsec; if (is_before || ((!is_nonzero) && (fsec < 0))) @@ -2360,7 +2391,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), sec); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (fsec < 0); is_nonzero = TRUE; @@ -2368,14 +2399,15 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) } else if (tm->tm_sec != 0) { - int sec = tm->tm_sec; + int sec = tm->tm_sec; + if (is_before || ((!is_nonzero) && (tm->tm_sec < 0))) sec = -sec; sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), sec, ((sec != 1) ? "s" : "")); cp += strlen(cp); - if (! is_nonzero) + if (!is_nonzero) is_before = (tm->tm_sec < 0); is_nonzero = TRUE; } @@ -2383,7 +2415,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) } /* identically zero? then put in a unitless zero... */ - if (! is_nonzero) + if (!is_nonzero) { strcat(cp, "0"); cp += strlen(cp); diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c index 9a1bffb81e4..d0766d15d70 100644 --- a/src/backend/utils/adt/datum.c +++ b/src/backend/utils/adt/datum.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.19 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.20 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -153,10 +153,11 @@ datumFree(Datum value, bool typByVal, int typLen) bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen) { - bool res; + bool res; if (typByVal) { + /* * just compare the two datums. NOTE: just comparing "len" bytes * will not do the work, because we do not know how these bytes diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index b02117d3a78..7a83ee6577e 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.69 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.70 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -56,7 +56,7 @@ #include <limits.h> /* for finite() on Solaris */ #ifdef HAVE_IEEEFP_H -# include <ieeefp.h> +#include <ieeefp.h> #endif #include "fmgr.h" @@ -69,6 +69,7 @@ #ifndef atof extern double atof(const char *p); + #endif #ifndef HAVE_CBRT @@ -78,8 +79,9 @@ static double cbrt(double x); #else #if !defined(nextstep) extern double cbrt(double x); + #endif -#endif /* HAVE_CBRT */ +#endif /* HAVE_CBRT */ #ifndef HAVE_RINT #define rint my_rint @@ -87,9 +89,10 @@ static double rint(double x); #else extern double rint(double x); -#endif /* HAVE_RINT */ -#endif /* NeXT check */ +#endif /* HAVE_RINT */ + +#endif /* NeXT check */ static void CheckFloat4Val(double val); @@ -1345,7 +1348,7 @@ setseed(PG_FUNCTION_ARGS) * float8_accum - accumulate for AVG(), STDDEV(), etc * float4_accum - same, but input data is float4 * float8_avg - produce final result for float AVG() - * float8_variance - produce final result for float VARIANCE() + * float8_variance - produce final result for float VARIANCE() * float8_stddev - produce final result for float STDDEV() * * The transition datatype for all these aggregates is a 3-element array @@ -1360,10 +1363,11 @@ setseed(PG_FUNCTION_ARGS) static float8 * check_float8_array(ArrayType *transarray, const char *caller) { + /* - * We expect the input to be a 3-element float array; verify that. - * We don't need to use deconstruct_array() since the array data - * is just going to look like a C array of 3 float8 values. + * We expect the input to be a 3-element float array; verify that. We + * don't need to use deconstruct_array() since the array data is just + * going to look like a C array of 3 float8 values. */ if (ARR_SIZE(transarray) != (ARR_OVERHEAD(1) + 3 * sizeof(float8)) || ARR_NDIM(transarray) != 1 || @@ -1398,7 +1402,7 @@ float8_accum(PG_FUNCTION_ARGS) transdatums[2] = Float8GetDatumFast(sumX2); result = construct_array(transdatums, 3, - false /* float8 byval */, sizeof(float8), 'd'); + false /* float8 byval */ , sizeof(float8), 'd'); PG_RETURN_ARRAYTYPE_P(result); } @@ -1433,7 +1437,7 @@ float4_accum(PG_FUNCTION_ARGS) transdatums[2] = Float8GetDatumFast(sumX2); result = construct_array(transdatums, 3, - false /* float8 byval */, sizeof(float8), 'd'); + false /* float8 byval */ , sizeof(float8), 'd'); PG_RETURN_ARRAYTYPE_P(result); } diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index 4cdaaee765f..b4990245500 100644 --- a/src/backend/utils/adt/format_type.c +++ b/src/backend/utils/adt/format_type.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.9 2001/02/05 17:35:04 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.10 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,10 +31,10 @@ static char *format_type_internal(Oid type_oid, int32 typemod); static char * -psnprintf(size_t len, const char * fmt, ...) +psnprintf(size_t len, const char *fmt,...) { - va_list ap; - char * buf; + va_list ap; + char *buf; buf = palloc(len); @@ -136,7 +136,9 @@ format_type_internal(Oid type_oid, int32 typemod) break; case CHAROID: - /* This char type is the single-byte version. You have to + + /* + * This char type is the single-byte version. You have to * double-quote it to get at it in the parser. */ buf = pstrdup("\"char\""); @@ -252,7 +254,7 @@ type_maximum_size(Oid type_oid, int32 typemod) /* precision (ie, max # of digits) is in upper bits of typmod */ if (typemod > VARHDRSZ) { - int precision = ((typemod - VARHDRSZ) >> 16) & 0xffff; + int precision = ((typemod - VARHDRSZ) >> 16) & 0xffff; /* Numeric stores 2 decimal digits/byte, plus header */ return (precision + 1) / 2 + NUMERIC_HDRSZ; @@ -262,7 +264,7 @@ type_maximum_size(Oid type_oid, int32 typemod) case VARBITOID: case ZPBITOID: /* typemod is the (max) number of bits */ - return (typemod + (BITS_PER_BYTE-1)) / BITS_PER_BYTE + return (typemod + (BITS_PER_BYTE - 1)) / BITS_PER_BYTE + 2 * sizeof(int32); } @@ -300,10 +302,10 @@ oidvectortypes(PG_FUNCTION_ARGS) result = palloc(total); result[0] = '\0'; left = total - 1; - + for (num = 0; num < numargs; num++) { - char * typename = format_type_internal(oidArray[num], -1); + char *typename = format_type_internal(oidArray[num], -1); if (left < strlen(typename) + 2) { diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index bef39d2da53..bebe8240144 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- * formatting.c * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.33 2001/02/27 08:13:28 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.34 2001/03/22 03:59:50 momjian Exp $ * * * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group @@ -47,14 +47,14 @@ * TODO (7.2): * - replace some global values by struct that handle it * - check last used entry in the cache_search - * - better number building (formatting) + * - better number building (formatting) * - add support for abstime * - add support for roman number to standard number conversion * - add support for number spelling * - add support for string to string formatting (we must be better - * than Oracle :-), - * to_char('Hello', 'X X X X X') -> 'H e l l o' - * + * than Oracle :-), + * to_char('Hello', 'X X X X X') -> 'H e l l o' + * * ----------------------------------------------------------------------- */ @@ -116,8 +116,8 @@ * External (defined in PgSQL dt.c (timestamp utils)) * ---------- */ -extern char *months[], /* month abbreviation */ - *days[]; /* full days */ +extern char *months[], /* month abbreviation */ + *days[]; /* full days */ /* ---------- * Format parser structs @@ -125,28 +125,28 @@ extern char *months[], /* month abbreviation */ */ typedef struct { - char *name; /* suffix string */ - int len, /* suffix length */ - id, /* used in node->suffix */ - type; /* prefix / postfix */ + char *name; /* suffix string */ + int len, /* suffix length */ + id, /* used in node->suffix */ + type; /* prefix / postfix */ } KeySuffix; typedef struct { - char *name; /* keyword */ - /* action for keyword */ - int len, /* keyword length */ - (*action) (), - id; /* keyword id */ - bool isitdigit; /* is expected output/input digit */ + char *name; /* keyword */ + /* action for keyword */ + int len, /* keyword length */ + (*action) (), + id; /* keyword id */ + bool isitdigit; /* is expected output/input digit */ } KeyWord; typedef struct { - int type; /* node type */ - KeyWord *key; /* if node type is KEYWORD */ - int character, /* if node type is CHAR */ - suffix; /* keyword suffix */ + int type; /* node type */ + KeyWord *key; /* if node type is KEYWORD */ + int character, /* if node type is CHAR */ + suffix; /* keyword suffix */ } FormatNode; #define NODE_TYPE_END 1 @@ -249,7 +249,7 @@ static char *numth[] = {"st", "nd", "rd", "th", NULL}; * Flags for DCH version * ---------- */ -static int DCH_global_flag = 0; +static int DCH_global_flag = 0; #define DCH_F_FX 0x01 @@ -262,15 +262,15 @@ static int DCH_global_flag = 0; */ typedef struct { - int pre, /* (count) numbers before decimal */ - post, /* (count) numbers after decimal */ - lsign, /* want locales sign */ - flag, /* number parametrs */ - pre_lsign_num, /* tmp value for lsign */ - multi, /* multiplier for 'V' */ - zero_start, /* position of first zero */ - zero_end, /* position of last zero */ - need_locale; /* needs it locale */ + int pre, /* (count) numbers before decimal */ + post, /* (count) numbers after decimal */ + lsign, /* want locales sign */ + flag, /* number parametrs */ + pre_lsign_num, /* tmp value for lsign */ + multi, /* multiplier for 'V' */ + zero_start, /* position of first zero */ + zero_end, /* position of last zero */ + need_locale; /* needs it locale */ } NUMDesc; /* ---------- @@ -280,14 +280,14 @@ typedef struct #define NUM_F_DECIMAL 0x01 #define NUM_F_LDECIMAL 0x02 #define NUM_F_ZERO 0x04 -#define NUM_F_BLANK 0x08 +#define NUM_F_BLANK 0x08 #define NUM_F_FILLMODE 0x10 -#define NUM_F_LSIGN 0x20 +#define NUM_F_LSIGN 0x20 #define NUM_F_BRACKET 0x40 -#define NUM_F_MINUS 0x80 +#define NUM_F_MINUS 0x80 #define NUM_F_PLUS 0x100 -#define NUM_F_ROMAN 0x200 -#define NUM_F_MULTI 0x400 +#define NUM_F_ROMAN 0x200 +#define NUM_F_MULTI 0x400 #define NUM_LSIGN_PRE -1 #define NUM_LSIGN_POST 1 @@ -299,20 +299,20 @@ typedef struct */ #define IS_DECIMAL(_f) ((_f)->flag & NUM_F_DECIMAL) #define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL) -#define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO) +#define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO) #define IS_BLANK(_f) ((_f)->flag & NUM_F_BLANK) #define IS_FILLMODE(_f) ((_f)->flag & NUM_F_FILLMODE) #define IS_BRACKET(_f) ((_f)->flag & NUM_F_BRACKET) #define IS_MINUS(_f) ((_f)->flag & NUM_F_MINUS) #define IS_LSIGN(_f) ((_f)->flag & NUM_F_LSIGN) -#define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS) +#define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS) #define IS_ROMAN(_f) ((_f)->flag & NUM_F_ROMAN) #define IS_MULTI(_f) ((_f)->flag & NUM_F_MULTI) /* ---------- * Format picture cache * (cache size: - * Number part = NUM_CACHE_SIZE * NUM_CACHE_FIELDS + * Number part = NUM_CACHE_SIZE * NUM_CACHE_FIELDS * Date-time part = DCH_CACHE_SIZE * DCH_CACHE_FIELDS * ) * ---------- @@ -326,25 +326,25 @@ typedef struct { FormatNode format[DCH_CACHE_SIZE + 1]; char str[DCH_CACHE_SIZE + 1]; - int age; + int age; } DCHCacheEntry; typedef struct { FormatNode format[NUM_CACHE_SIZE + 1]; char str[NUM_CACHE_SIZE + 1]; - int age; + int age; NUMDesc Num; } NUMCacheEntry; /* global cache for --- date/time part */ -static DCHCacheEntry DCHCache[DCH_CACHE_FIELDS + 1]; +static DCHCacheEntry DCHCache[DCH_CACHE_FIELDS + 1]; static int n_DCHCache = 0; /* number of entries */ static int DCHCounter = 0; /* global cache for --- number part */ -static NUMCacheEntry NUMCache[NUM_CACHE_FIELDS + 1]; +static NUMCacheEntry NUMCache[NUM_CACHE_FIELDS + 1]; static NUMCacheEntry *last_NUMCacheEntry; static int n_NUMCache = 0; /* number of entries */ @@ -356,18 +356,38 @@ static int NUMCounter = 0; * For char->date/time conversion * ---------- */ -typedef struct { - int hh, am, pm, mi, ss, ssss, d, dd, ddd, mm, yyyy, yyy, yy, y, - bc, iw, ww, w, cc, q, j; +typedef struct +{ + int hh, + am, + pm, + mi, + ss, + ssss, + d, + dd, + ddd, + mm, + yyyy, + yyy, + yy, + y, + bc, + iw, + ww, + w, + cc, + q, + j; } TmFromChar; -#define ZERO_tmfc( _X ) \ +#define ZERO_tmfc( _X ) \ do { \ (_X)->hh= (_X)->am= (_X)->pm= (_X)->mi= (_X)->ss= (_X)->ssss= \ (_X)->d= (_X)->dd= (_X)->ddd= (_X)->mm= (_X)->yyyy= (_X)->yyy= \ (_X)->yy= (_X)->y= (_X)->bc= (_X)->iw= (_X)->ww= (_X)->w= \ (_X)->cc= (_X)->q= (_X)->j= 0; \ - } while(0) + } while(0) #ifdef DEBUG_TO_FROM_CHAR @@ -396,8 +416,10 @@ typedef struct { * Private global-modul definitions * ---------- */ -static struct tm _tm, *tm = &_tm; -static TmFromChar _tmfc, *tmfc = &_tmfc; +static struct tm _tm, + *tm = &_tm; +static TmFromChar _tmfc, + *tmfc = &_tmfc; static char *tzn; /* ---------- @@ -620,7 +642,7 @@ static KeyWord DCH_keywords[] = { {"AM", 2, dch_time, DCH_AM, FALSE}, {"B.C.", 4, dch_date, DCH_B_C, FALSE}, /* B */ {"BC", 2, dch_date, DCH_BC, FALSE}, - {"CC", 2, dch_date, DCH_CC, TRUE}, /* C */ + {"CC", 2, dch_date, DCH_CC, TRUE}, /* C */ {"DAY", 3, dch_date, DCH_DAY, FALSE}, /* D */ {"DDD", 3, dch_date, DCH_DDD, TRUE}, {"DD", 2, dch_date, DCH_DD, TRUE}, @@ -632,8 +654,8 @@ static KeyWord DCH_keywords[] = { {"HH24", 4, dch_time, DCH_HH24, TRUE}, /* H */ {"HH12", 4, dch_time, DCH_HH12, TRUE}, {"HH", 2, dch_time, DCH_HH, TRUE}, - {"IW", 2, dch_date, DCH_IW, TRUE}, /* I */ - {"J", 1, dch_date, DCH_J, TRUE}, /* J */ + {"IW", 2, dch_date, DCH_IW, TRUE}, /* I */ + {"J", 1, dch_date, DCH_J, TRUE}, /* J */ {"MI", 2, dch_time, DCH_MI, TRUE}, {"MM", 2, dch_date, DCH_MM, TRUE}, {"MONTH", 5, dch_date, DCH_MONTH, FALSE}, @@ -642,12 +664,12 @@ static KeyWord DCH_keywords[] = { {"Mon", 3, dch_date, DCH_Mon, FALSE}, {"P.M.", 4, dch_time, DCH_P_M, FALSE}, /* P */ {"PM", 2, dch_time, DCH_PM, FALSE}, - {"Q", 1, dch_date, DCH_Q, TRUE}, /* Q */ - {"RM", 2, dch_date, DCH_RM, FALSE}, /* R */ - {"SSSS", 4, dch_time, DCH_SSSS, TRUE}, /* S */ + {"Q", 1, dch_date, DCH_Q, TRUE}, /* Q */ + {"RM", 2, dch_date, DCH_RM, FALSE}, /* R */ + {"SSSS", 4, dch_time, DCH_SSSS, TRUE}, /* S */ {"SS", 2, dch_time, DCH_SS, TRUE}, - {"TZ", 2, dch_time, DCH_TZ, FALSE}, /* T */ - {"WW", 2, dch_date, DCH_WW, TRUE}, /* W */ + {"TZ", 2, dch_time, DCH_TZ, FALSE}, /* T */ + {"WW", 2, dch_date, DCH_WW, TRUE}, /* W */ {"W", 1, dch_date, DCH_W, TRUE}, {"Y,YYY", 5, dch_date, DCH_Y_YYY, TRUE}, /* Y */ {"YYYY", 4, dch_date, DCH_YYYY, TRUE}, @@ -660,7 +682,7 @@ static KeyWord DCH_keywords[] = { {"am", 2, dch_time, DCH_am, FALSE}, {"b.c.", 4, dch_date, DCH_b_c, FALSE}, /* b */ {"bc", 2, dch_date, DCH_bc, FALSE}, - {"cc", 2, dch_date, DCH_CC, TRUE}, /* c */ + {"cc", 2, dch_date, DCH_CC, TRUE}, /* c */ {"day", 3, dch_date, DCH_day, FALSE}, /* d */ {"ddd", 3, dch_date, DCH_DDD, TRUE}, {"dd", 2, dch_date, DCH_DD, TRUE}, @@ -670,20 +692,20 @@ static KeyWord DCH_keywords[] = { {"hh24", 4, dch_time, DCH_HH24, TRUE}, /* h */ {"hh12", 4, dch_time, DCH_HH12, TRUE}, {"hh", 2, dch_time, DCH_HH, TRUE}, - {"iw", 2, dch_date, DCH_IW, TRUE}, /* i */ - {"j", 1, dch_time, DCH_J, TRUE}, /* j */ - {"mi", 2, dch_time, DCH_MI, TRUE}, /* m */ + {"iw", 2, dch_date, DCH_IW, TRUE}, /* i */ + {"j", 1, dch_time, DCH_J, TRUE}, /* j */ + {"mi", 2, dch_time, DCH_MI, TRUE}, /* m */ {"mm", 2, dch_date, DCH_MM, TRUE}, {"month", 5, dch_date, DCH_month, FALSE}, {"mon", 3, dch_date, DCH_mon, FALSE}, {"p.m.", 4, dch_time, DCH_p_m, FALSE}, /* p */ {"pm", 2, dch_time, DCH_pm, FALSE}, - {"q", 1, dch_date, DCH_Q, TRUE}, /* q */ - {"rm", 2, dch_date, DCH_rm, FALSE}, /* r */ - {"ssss", 4, dch_time, DCH_SSSS, TRUE}, /* s */ + {"q", 1, dch_date, DCH_Q, TRUE}, /* q */ + {"rm", 2, dch_date, DCH_rm, FALSE}, /* r */ + {"ssss", 4, dch_time, DCH_SSSS, TRUE}, /* s */ {"ss", 2, dch_time, DCH_SS, TRUE}, - {"tz", 2, dch_time, DCH_tz, FALSE}, /* t */ - {"ww", 2, dch_date, DCH_WW, TRUE}, /* w */ + {"tz", 2, dch_time, DCH_tz, FALSE}, /* t */ + {"ww", 2, dch_date, DCH_WW, TRUE}, /* w */ {"w", 1, dch_date, DCH_W, TRUE}, {"y,yyy", 5, dch_date, DCH_Y_YYY, TRUE}, /* y */ {"yyyy", 4, dch_date, DCH_YYYY, TRUE}, @@ -794,32 +816,33 @@ static int NUM_index[KeyWord_INDEX_SIZE] = { */ typedef struct NUMProc { - int type; /* FROM_CHAR (TO_NUMBER) or TO_CHAR */ - - NUMDesc *Num; /* number description */ - - int sign, /* '-' or '+' */ - sign_wrote, /* was sign write */ - sign_pos, /* pre number sign position */ - num_count, /* number of write digits */ - num_in, /* is inside number */ - num_curr, /* current position in number */ - num_pre, /* space before first number */ - - read_dec, /* to_number - was read dec. point */ - read_post; /* to_number - number of dec. digit */ - - char *number, /* string with number */ - *number_p, /* pointer to current number pozition */ - *inout, /* in / out buffer */ - *inout_p, /* pointer to current inout pozition */ - *last_relevant, /* last relevant number after decimal point */ - - *L_negative_sign,/* Locale */ - *L_positive_sign, - *decimal, - *L_thousands_sep, - *L_currency_symbol; + int type; /* FROM_CHAR (TO_NUMBER) or TO_CHAR */ + + NUMDesc *Num; /* number description */ + + int sign, /* '-' or '+' */ + sign_wrote, /* was sign write */ + sign_pos, /* pre number sign position */ + num_count, /* number of write digits */ + num_in, /* is inside number */ + num_curr, /* current position in number */ + num_pre, /* space before first number */ + + read_dec, /* to_number - was read dec. point */ + read_post; /* to_number - number of dec. digit */ + + char *number, /* string with number */ + *number_p, /* pointer to current number pozition */ + *inout, /* in / out buffer */ + *inout_p, /* pointer to current inout pozition */ + *last_relevant, /* last relevant number after decimal + * point */ + + *L_negative_sign,/* Locale */ + *L_positive_sign, + *decimal, + *L_thousands_sep, + *L_currency_symbol; } NUMProc; @@ -1093,11 +1116,11 @@ static void parse_format(FormatNode *node, char *str, KeyWord *kw, KeySuffix *suf, int *index, int ver, NUMDesc *Num) { - KeySuffix *s; - FormatNode *n; - int node_set = 0, - suffix, - last = 0; + KeySuffix *s; + FormatNode *n; + int node_set = 0, + suffix, + last = 0; #ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "to_char/number(): run parser."); @@ -1245,7 +1268,7 @@ DCH_processor(FormatNode *node, char *inout, int flag) { if (n->type == NODE_TYPE_ACTION) { - int len; + int len; /* ---------- * Call node action function @@ -1274,7 +1297,7 @@ DCH_processor(FormatNode *node, char *inout, int flag) * Skip blank space in FROM_CHAR's input * ---------- */ - if (isspace((unsigned char) n->character) && IS_FX == 0) + if (isspace((unsigned char) n->character) && IS_FX == 0) { while (*s != '\0' && isspace((unsigned char) *(s + 1))) ++s; @@ -1341,18 +1364,19 @@ dump_node(FormatNode *node, int max) static char * get_th(char *num, int type) { - int len = strlen(num), - last, seclast; + int len = strlen(num), + last, + seclast; last = *(num + (len - 1)); if (!isdigit((unsigned char) last)) elog(ERROR, "get_th: '%s' is not number.", num); /* - * All "teens" (<x>1[0-9]) get 'TH/th', - * while <x>[02-9][123] still get 'ST/st', 'ND/nd', 'RD/rd', respectively + * All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get + * 'ST/st', 'ND/nd', 'RD/rd', respectively */ - if ((len > 1) && ((seclast = num[len-2]) == '1')) + if ((len > 1) && ((seclast = num[len - 2]) == '1')) last = 0; switch (last) @@ -1442,11 +1466,11 @@ str_tolower(char *buff) static int seq_search(char *name, char **array, int type, int max, int *len) { - char *p, - *n, - **a; - int last, - i; + char *p, + *n, + **a; + int last, + i; *len = 0; @@ -1522,9 +1546,9 @@ seq_search(char *name, char **array, int type, int max, int *len) static void dump_index(KeyWord *k, int *index) { - int i, - count = 0, - free_i = 0; + int i, + count = 0, + free_i = 0; elog(DEBUG_elog_output, "TO-FROM_CHAR: Dump KeyWord Index:"); @@ -1563,9 +1587,9 @@ dch_global(int arg, char *inout, int suf, int flag, FormatNode *node) { switch (arg) { - case DCH_FX: - DCH_global_flag |= DCH_F_FX; - break; + case DCH_FX: + DCH_global_flag |= DCH_F_FX; + break; } return -1; } @@ -1579,29 +1603,29 @@ is_next_separator(FormatNode *n) { if (n->type == NODE_TYPE_END) return FALSE; - + if (n->type == NODE_TYPE_ACTION && S_THth(n->suffix)) return TRUE; - - /* - * Next node + + /* + * Next node */ - n++; - + n++; + if (n->type == NODE_TYPE_END) return FALSE; - + if (n->type == NODE_TYPE_ACTION) { if (n->key->isitdigit) return FALSE; - - return TRUE; - } + + return TRUE; + } else if (isdigit((unsigned char) n->character)) return FALSE; - - return TRUE; /* some non-digit input (separator) */ + + return TRUE; /* some non-digit input (separator) */ } #define AMPM_ERROR elog(ERROR, "to_timestamp(): bad AM/PM string") @@ -1619,12 +1643,12 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) switch (arg) { - case DCH_A_M: + case DCH_A_M: case DCH_P_M: if (flag == TO_CHAR) { - strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? P_M_STR : A_M_STR)); + strcpy(inout, ((tm->tm_hour > 11 + && tm->tm_hour < 24) ? P_M_STR : A_M_STR)); return 3; } else if (flag == FROM_CHAR) @@ -1632,9 +1656,9 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) if (strncmp(inout, P_M_STR, 4) == 0) tmfc->pm = TRUE; else if (strncmp(inout, A_M_STR, 4) == 0) - tmfc->am = TRUE; + tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 3; } break; @@ -1642,8 +1666,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_PM: if (flag == TO_CHAR) { - strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? PM_STR : AM_STR)); + strcpy(inout, ((tm->tm_hour > 11 + && tm->tm_hour < 24) ? PM_STR : AM_STR)); return 1; } else if (flag == FROM_CHAR) @@ -1653,7 +1677,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) else if (strncmp(inout, AM_STR, 2) == 0) tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 1; } break; @@ -1661,8 +1685,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_p_m: if (flag == TO_CHAR) { - strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? p_m_STR : a_m_STR)); + strcpy(inout, ((tm->tm_hour > 11 + && tm->tm_hour < 24) ? p_m_STR : a_m_STR)); return 3; } else if (flag == FROM_CHAR) @@ -1672,7 +1696,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) else if (strncmp(inout, a_m_STR, 4) == 0) tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 3; } break; @@ -1681,7 +1705,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) if (flag == TO_CHAR) { strcpy(inout, ((tm->tm_hour > 11 - && tm->tm_hour < 24) ? pm_STR : am_STR)); + && tm->tm_hour < 24) ? pm_STR : am_STR)); return 1; } else if (flag == FROM_CHAR) @@ -1691,7 +1715,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) else if (strncmp(inout, am_STR, 2) == 0) tmfc->am = TRUE; else - AMPM_ERROR; + AMPM_ERROR; return 1; } break; @@ -1812,12 +1836,12 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) str_numth(p_inout, inout, S_TH_TYPE(suf)); return strlen(p_inout) - 1; } - else if (flag == FROM_CHAR) + else if (flag == FROM_CHAR) { if (is_next_separator(node)) sscanf(inout, "%d", &tmfc->ssss); else - sscanf(inout, "%05d", &tmfc->ssss); + sscanf(inout, "%05d", &tmfc->ssss); return int4len((int4) tmfc->ssss) - 1 + SKIP_THth(suf); } break; @@ -1825,24 +1849,22 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_TZ: if (flag == TO_CHAR && tzn) { - int siz = strlen(tzn); - + int siz = strlen(tzn); + if (arg == DCH_TZ) strcpy(inout, tzn); - else + else { - char *p = palloc(siz); - + char *p = palloc(siz); + strcpy(p, tzn); strcpy(inout, str_tolower(p)); pfree(p); } return siz - 1; - } - else if (flag == FROM_CHAR) - { + } + else if (flag == FROM_CHAR) elog(ERROR, "to_timestamp(): TZ/tz not supported."); - } } return -1; } @@ -1864,10 +1886,10 @@ do { \ static int dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) { - char buff[DCH_CACHE_SIZE], - *p_inout; - int i, - len; + char buff[DCH_CACHE_SIZE], + *p_inout; + int i, + len; p_inout = inout; @@ -1881,7 +1903,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) { if (arg == DCH_MONTH || arg == DCH_Month || arg == DCH_month) { - tmfc->mm = seq_search(inout, months_full, ONE_UPPER, FULL_SIZ, &len) +1; + tmfc->mm = seq_search(inout, months_full, ONE_UPPER, FULL_SIZ, &len) + 1; CHECK_SEQ_SEARCH(len, "MONTH/Month/month"); if (S_FM(suf)) return len - 1; @@ -1891,7 +1913,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) } else if (arg == DCH_MON || arg == DCH_Mon || arg == DCH_mon) { - tmfc->mm = seq_search(inout, months, ONE_UPPER, MAX_MON_LEN, &len) +1; + tmfc->mm = seq_search(inout, months, ONE_UPPER, MAX_MON_LEN, &len) + 1; CHECK_SEQ_SEARCH(len, "MON/Mon/mon"); return 2; } @@ -1983,14 +2005,14 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return strlen(p_inout) - 1; else return 8; - + case DCH_Month: sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); if (S_FM(suf)) return strlen(p_inout) - 1; else return 8; - + case DCH_month: sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); *inout = tolower((unsigned char) *inout); @@ -1998,12 +2020,12 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return strlen(p_inout) - 1; else return 8; - + case DCH_MON: strcpy(inout, months[tm->tm_mon - 1]); inout = str_toupper(inout); return 2; - + case DCH_Mon: strcpy(inout, months[tm->tm_mon - 1]); return 2; @@ -2149,7 +2171,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) if (flag == TO_CHAR) { sprintf(inout, "%0*d", S_FM(suf) ? 0 : 2, - (tm->tm_yday-1) / 7 + 1); + (tm->tm_yday - 1) / 7 + 1); if (S_THth(suf)) str_numth(p_inout, inout, S_TH_TYPE(suf)); if (S_FM(suf) || S_THth(suf)) @@ -2158,7 +2180,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return 1; } - else if (flag == FROM_CHAR) + else if (flag == FROM_CHAR) { if (S_FM(suf)) { @@ -2176,7 +2198,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) if (flag == TO_CHAR) { sprintf(inout, "%0*d", S_FM(suf) ? 0 : 2, - date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday)); + date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday)); if (S_THth(suf)) str_numth(p_inout, inout, S_TH_TYPE(suf)); if (S_FM(suf) || S_THth(suf)) @@ -2185,7 +2207,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return 1; } - else if (flag == FROM_CHAR) + else if (flag == FROM_CHAR) { if (S_FM(suf)) { @@ -2198,7 +2220,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) return 1 + SKIP_THth(suf); } } - break; + break; case DCH_Q: if (flag == TO_CHAR) { @@ -2233,7 +2255,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) else if (flag == FROM_CHAR) { sscanf(inout, "%d", &tmfc->cc); - return int4len((int4) tmfc->cc) + SKIP_THth(suf) -1; + return int4len((int4) tmfc->cc) + SKIP_THth(suf) - 1; } break; case DCH_Y_YYY: @@ -2277,7 +2299,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) sscanf(inout, "%d", &tmfc->yyyy); else sscanf(inout, "%04d", &tmfc->yyyy); - + if (!S_FM(suf) && tmfc->yyyy <= 9999 && tmfc->yyyy >= -9999) len = 4; else @@ -2391,7 +2413,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) case DCH_W: if (flag == TO_CHAR) { - sprintf(inout, "%d", (tm->tm_mday-1) / 7 + 1); + sprintf(inout, "%d", (tm->tm_mday - 1) / 7 + 1); if (S_THth(suf)) { str_numth(p_inout, inout, S_TH_TYPE(suf)); @@ -2416,7 +2438,7 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node) else if (flag == FROM_CHAR) { sscanf(inout, "%d", &tmfc->j); - return int4len((int4) tmfc->j) + SKIP_THth(suf) -1; + return int4len((int4) tmfc->j) + SKIP_THth(suf) - 1; } break; } @@ -2522,24 +2544,24 @@ Datum timestamp_to_char(PG_FUNCTION_ARGS) { Timestamp dt = PG_GETARG_TIMESTAMP(0); - text *fmt = PG_GETARG_TEXT_P(1); - text *result, - *result_tmp; - - FormatNode *format; - char *str; + text *fmt = PG_GETARG_TEXT_P(1); + text *result, + *result_tmp; + + FormatNode *format; + char *str; double fsec; - int len = 0, - tz, - flag = 0, - x = 0; + int len = 0, + tz, + flag = 0, + x = 0; len = VARSIZE(fmt) - VARHDRSZ; if (len <= 0 || TIMESTAMP_NOT_FINITE(dt)) PG_RETURN_NULL(); - ZERO_tm(tm); + ZERO_tm(tm); tzn = NULL; if (TIMESTAMP_IS_EPOCH(dt)) @@ -2613,7 +2635,7 @@ timestamp_to_char(PG_FUNCTION_ARGS) * ---------- */ parse_format(ent->format, str, DCH_keywords, - DCH_suff, DCH_index, DCH_TYPE, NULL); + DCH_suff, DCH_index, DCH_TYPE, NULL); (ent->format + len)->type = NODE_TYPE_END; /* Paranoa? */ @@ -2642,7 +2664,7 @@ timestamp_to_char(PG_FUNCTION_ARGS) pfree(result); PG_RETURN_NULL(); } - + result_tmp = result; result = (text *) palloc(len + 1 + VARHDRSZ); @@ -2664,13 +2686,13 @@ timestamp_to_char(PG_FUNCTION_ARGS) Datum to_timestamp(PG_FUNCTION_ARGS) { - text *date_txt = PG_GETARG_TEXT_P(0); - text *fmt = PG_GETARG_TEXT_P(1); - FormatNode *format; - int flag = 0; + text *date_txt = PG_GETARG_TEXT_P(0); + text *fmt = PG_GETARG_TEXT_P(1); + FormatNode *format; + int flag = 0; Timestamp result; - char *str; - char *date_str; + char *str; + char *date_str; int len, date_len, fsec = 0, @@ -2766,16 +2788,16 @@ to_timestamp(PG_FUNCTION_ARGS) } /* -------------------------------------------------------------- - * Convert values that user define for FROM_CHAR (to_date/to_timestamp) + * Convert values that user define for FROM_CHAR (to_date/to_timestamp) * to standard 'tm' * ---------- - */ + */ #ifdef DEBUG_TO_FROM_CHAR NOTICE_TMFC; -#endif - if (tmfc->ssss) +#endif + if (tmfc->ssss) { - int x = tmfc->ssss; + int x = tmfc->ssss; tm->tm_hour = x / 3600; x %= 3600; @@ -2785,128 +2807,148 @@ to_timestamp(PG_FUNCTION_ARGS) } if (tmfc->cc) - tm->tm_year = (tmfc->cc-1) * 100; + tm->tm_year = (tmfc->cc - 1) * 100; - if (tmfc->ww) + if (tmfc->ww) tmfc->ddd = (tmfc->ww - 1) * 7 + 1; - if (tmfc->w) + if (tmfc->w) tmfc->dd = (tmfc->w - 1) * 7 + 1; - if (tmfc->ss) tm->tm_sec = tmfc->ss; - if (tmfc->mi) tm->tm_min = tmfc->mi; - if (tmfc->hh) tm->tm_hour = tmfc->hh; - - if (tmfc->pm || tmfc->am) - { - if (tm->tm_hour < 1 || tm->tm_hour > 12) - elog(ERROR, "to_timestamp(): AM/PM hour must be between 1 and 12"); - + if (tmfc->ss) + tm->tm_sec = tmfc->ss; + if (tmfc->mi) + tm->tm_min = tmfc->mi; + if (tmfc->hh) + tm->tm_hour = tmfc->hh; + + if (tmfc->pm || tmfc->am) + { + if (tm->tm_hour < 1 || tm->tm_hour > 12) + elog(ERROR, "to_timestamp(): AM/PM hour must be between 1 and 12"); + if (tmfc->pm && tm->tm_hour < 12) tm->tm_hour += 12; - + else if (tmfc->am && tm->tm_hour == 12) - tm->tm_hour = 0; - } + tm->tm_hour = 0; + } - switch (tmfc->q) + switch (tmfc->q) { - case 1: tm->tm_mday = 1; tm->tm_mon = 1; break; - case 2: tm->tm_mday = 1; tm->tm_mon = 4; break; - case 3: tm->tm_mday = 1; tm->tm_mon = 7; break; - case 4: tm->tm_mday = 1; tm->tm_mon = 10; break; + case 1: + tm->tm_mday = 1; + tm->tm_mon = 1; + break; + case 2: + tm->tm_mday = 1; + tm->tm_mon = 4; + break; + case 3: + tm->tm_mday = 1; + tm->tm_mon = 7; + break; + case 4: + tm->tm_mday = 1; + tm->tm_mon = 10; + break; } - - if (tmfc->yyyy) + + if (tmfc->yyyy) tm->tm_year = tmfc->yyyy; else if (tmfc->y) { + /* - * 1-digit year: - * always +2000 + * 1-digit year: always +2000 */ - tm->tm_year = tmfc->y + 2000; - } + tm->tm_year = tmfc->y + 2000; + } else if (tmfc->yy) { + /* - * 2-digit year: - * '00' ... '69' = 2000 ... 2069 - * '70' ... '99' = 1970 ... 1999 - */ + * 2-digit year: '00' ... '69' = 2000 ... 2069 '70' ... '99' = + * 1970 ... 1999 + */ tm->tm_year = tmfc->yy; - + if (tm->tm_year < 70) tm->tm_year += 2000; - else + else tm->tm_year += 1900; } else if (tmfc->yyy) { + /* - * 3-digit year: - * '100' ... '999' = 1100 ... 1999 - * '000' ... '099' = 2000 ... 2099 + * 3-digit year: '100' ... '999' = 1100 ... 1999 '000' ... '099' = + * 2000 ... 2099 */ tm->tm_year = tmfc->yyy; - + if (tm->tm_year >= 100) tm->tm_year += 1000; - else + else tm->tm_year += 2000; } - + if (tmfc->bc) { if (tm->tm_year > 0) tm->tm_year = -(tm->tm_year - 1); else elog(ERROR, "Inconsistant use of year %04d and 'BC'", tm->tm_year); - } - + } + if (tmfc->j) j2date(tmfc->j, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); - + if (tmfc->iw) isoweek2date(tmfc->iw, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); - - if (tmfc->d) tm->tm_wday = tmfc->d; - if (tmfc->dd) tm->tm_mday = tmfc->dd; - if (tmfc->ddd) tm->tm_yday = tmfc->ddd; - if (tmfc->mm) tm->tm_mon = tmfc->mm; + + if (tmfc->d) + tm->tm_wday = tmfc->d; + if (tmfc->dd) + tm->tm_mday = tmfc->dd; + if (tmfc->ddd) + tm->tm_yday = tmfc->ddd; + if (tmfc->mm) + tm->tm_mon = tmfc->mm; /* * we not ignore DDD */ - if (tmfc->ddd && (tm->tm_mon <=1 || tm->tm_mday <=1)) + if (tmfc->ddd && (tm->tm_mon <= 1 || tm->tm_mday <= 1)) { /* count mday and mon from yday */ - int *y, i; - - int ysum[2][13] = { - { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 0 }, - { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0 }}; - - if (!tm->tm_year) - elog(ERROR, "to_timestamp() cat't convert yday without year information"); - - y = ysum[ isleap(tm->tm_year) ]; - - for (i=0; i <= 11; i++) - { - if (tm->tm_yday < y[i]) + int *y, + i; + + int ysum[2][13] = { + {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 0}, + {31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 0}}; + + if (!tm->tm_year) + elog(ERROR, "to_timestamp() cat't convert yday without year information"); + + y = ysum[isleap(tm->tm_year)]; + + for (i = 0; i <= 11; i++) + { + if (tm->tm_yday < y[i]) break; - } - if (tm->tm_mon <=1) - tm->tm_mon = i+1; - - if (tm->tm_mday <=1) - tm->tm_mday = i == 0 ? tm->tm_yday : - tm->tm_yday - y[i-1]; + } + if (tm->tm_mon <= 1) + tm->tm_mon = i + 1; + + if (tm->tm_mday <= 1) + tm->tm_mday = i == 0 ? tm->tm_yday : + tm->tm_yday - y[i - 1]; } - + /* -------------------------------------------------------------- */ #ifdef DEBUG_TO_FROM_CHAR @@ -2920,21 +2962,21 @@ to_timestamp(PG_FUNCTION_ARGS) tm->tm_year -= 1900; tm->tm_mon -= 1; -# ifdef DEBUG_TO_FROM_CHAR +#ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "TO-FROM_CHAR: Call mktime()"); NOTICE_TM; -# endif +#endif mktime(tm); tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ tz = CTimeZone; #endif } @@ -2960,8 +3002,10 @@ to_timestamp(PG_FUNCTION_ARGS) Datum to_date(PG_FUNCTION_ARGS) { - /* Quick hack: since our inputs are just like to_timestamp, - * hand over the whole input info struct... + + /* + * Quick hack: since our inputs are just like to_timestamp, hand over + * the whole input info struct... */ return DirectFunctionCall1(timestamp_date, to_timestamp(fcinfo)); } @@ -2985,7 +3029,7 @@ do { \ (_n)->lsign = 0; \ (_n)->pre = 0; \ (_n)->post = 0; \ - (_n)->pre_lsign_num = 0; \ + (_n)->pre_lsign_num = 0; \ (_n)->need_locale = 0; \ (_n)->multi = 0; \ (_n)->zero_start = 0; \ @@ -3021,10 +3065,11 @@ NUM_cache_getnew(char *str) for (ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++) { - /* entry removed via NUM_cache_remove() - * can be used here + + /* + * entry removed via NUM_cache_remove() can be used here */ - if (*ent->str == '\0') + if (*ent->str == '\0') { old = ent; break; @@ -3063,7 +3108,7 @@ NUM_cache_getnew(char *str) static NUMCacheEntry * NUM_cache_search(char *str) { - int i = 0; + int i = 0; NUMCacheEntry *ent; /* counter overload check - paranoa? */ @@ -3196,12 +3241,12 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, int *flag) static char * int_to_roman(int number) { - int len = 0, - num = 0, - set = 0; - char *p = NULL, - *result, - numstr[5]; + int len = 0, + num = 0, + set = 0; + char *p = NULL, + *result, + numstr[5]; result = (char *) palloc(16); *result = '\0'; @@ -3336,7 +3381,7 @@ static char * get_last_relevant_decnum(char *num) { char *result, - *p = strchr(num, '.'); + *p = strchr(num, '.'); #ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "CALL: get_last_relevant_decnum()"); @@ -3483,7 +3528,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen) } else { - int x = strlen(Np->decimal); + int x = strlen(Np->decimal); #ifdef DEBUG_TO_FROM_CHAR elog(DEBUG_elog_output, "Try read locale point (%c).", *Np->inout_p); @@ -3716,8 +3761,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, int plen, int sign, int type) { FormatNode *n; - NUMProc _Np, - *Np = &_Np; + NUMProc _Np, + *Np = &_Np; Np->Num = Num; Np->type = type; @@ -3802,9 +3847,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, { if (IS_DECIMAL(Np->Num)) Np->last_relevant = get_last_relevant_decnum( - Np->number + - ((Np->Num->zero_end - Np->num_pre > 0) ? - Np->Num->zero_end - Np->num_pre : 0)); + Np->number + + ((Np->Num->zero_end - Np->num_pre > 0) ? + Np->Num->zero_end - Np->num_pre : 0)); } if (!Np->sign_wrote && Np->num_pre == 0) @@ -4168,7 +4213,7 @@ do { \ if (flag) \ pfree(format); \ \ - /* ---------- \ + /* ---------- \ * for result is allocated max memory, which current format-picture\ * needs, now it must be re-allocate to result real size \ * ---------- \ @@ -4194,16 +4239,16 @@ do { \ Datum numeric_to_number(PG_FUNCTION_ARGS) { - text *value = PG_GETARG_TEXT_P(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; - Datum result; + text *value = PG_GETARG_TEXT_P(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; + Datum result; FormatNode *format; - char *numstr; - int flag = 0; - int len = 0; - int scale, - precision; + char *numstr; + int flag = 0; + int len = 0; + int scale, + precision; len = VARSIZE(fmt) - VARHDRSZ; @@ -4224,9 +4269,9 @@ numeric_to_number(PG_FUNCTION_ARGS) pfree(format); result = DirectFunctionCall3(numeric_in, - CStringGetDatum(numstr), - ObjectIdGetDatum(InvalidOid), - Int32GetDatum(((precision << 16) | scale) + VARHDRSZ)); + CStringGetDatum(numstr), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(((precision << 16) | scale) + VARHDRSZ)); pfree(numstr); return result; } @@ -4238,20 +4283,20 @@ numeric_to_number(PG_FUNCTION_ARGS) Datum numeric_to_char(PG_FUNCTION_ARGS) { - Numeric value = PG_GETARG_NUMERIC(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + Numeric value = PG_GETARG_NUMERIC(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum, - *p; - Numeric x; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum, + *p; + Numeric x; NUM_TOCHAR_prepare; @@ -4262,11 +4307,11 @@ numeric_to_char(PG_FUNCTION_ARGS) if (IS_ROMAN(&Num)) { x = DatumGetNumeric(DirectFunctionCall2(numeric_round, - NumericGetDatum(value), - Int32GetDatum(0))); + NumericGetDatum(value), + Int32GetDatum(0))); numstr = orgnum = int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4, - NumericGetDatum(x)))); + NumericGetDatum(x)))); pfree(x); } else @@ -4276,16 +4321,16 @@ numeric_to_char(PG_FUNCTION_ARGS) if (IS_MULTI(&Num)) { Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric, - Int32GetDatum(10))); + Int32GetDatum(10))); Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric, - Int32GetDatum(Num.multi))); + Int32GetDatum(Num.multi))); x = DatumGetNumeric(DirectFunctionCall2(numeric_power, NumericGetDatum(a), NumericGetDatum(b))); val = DatumGetNumeric(DirectFunctionCall2(numeric_mul, - NumericGetDatum(value), - NumericGetDatum(x))); + NumericGetDatum(value), + NumericGetDatum(x))); pfree(x); pfree(a); pfree(b); @@ -4293,10 +4338,10 @@ numeric_to_char(PG_FUNCTION_ARGS) } x = DatumGetNumeric(DirectFunctionCall2(numeric_round, - NumericGetDatum(val), - Int32GetDatum(Num.post))); + NumericGetDatum(val), + Int32GetDatum(Num.post))); orgnum = DatumGetCString(DirectFunctionCall1(numeric_out, - NumericGetDatum(x))); + NumericGetDatum(x))); pfree(x); if (*orgnum == '-') @@ -4339,18 +4384,18 @@ numeric_to_char(PG_FUNCTION_ARGS) Datum int4_to_char(PG_FUNCTION_ARGS) { - int32 value = PG_GETARG_INT32(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + int32 value = PG_GETARG_INT32(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum; NUM_TOCHAR_prepare; @@ -4359,21 +4404,19 @@ int4_to_char(PG_FUNCTION_ARGS) * ---------- */ if (IS_ROMAN(&Num)) - { numstr = orgnum = int_to_roman(value); - } else { if (IS_MULTI(&Num)) { orgnum = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum(value * ((int32) pow((double) 10, (double) Num.multi))))); + Int32GetDatum(value * ((int32) pow((double) 10, (double) Num.multi))))); Num.pre += Num.multi; } else { orgnum = DatumGetCString(DirectFunctionCall1(int4out, - Int32GetDatum(value))); + Int32GetDatum(value))); } len = strlen(orgnum); @@ -4387,7 +4430,7 @@ int4_to_char(PG_FUNCTION_ARGS) if (Num.post) { - int i; + int i; numstr = (char *) palloc(len + Num.post + 2); strcpy(numstr, orgnum + (*orgnum == '-' ? 1 : 0)); @@ -4423,18 +4466,18 @@ int4_to_char(PG_FUNCTION_ARGS) Datum int8_to_char(PG_FUNCTION_ARGS) { - int64 value = PG_GETARG_INT64(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + int64 value = PG_GETARG_INT64(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum; NUM_TOCHAR_prepare; @@ -4446,7 +4489,7 @@ int8_to_char(PG_FUNCTION_ARGS) { /* Currently don't support int8 conversion to roman... */ numstr = orgnum = int_to_roman(DatumGetInt32( - DirectFunctionCall1(int84, Int64GetDatum(value)))); + DirectFunctionCall1(int84, Int64GetDatum(value)))); } else { @@ -4455,14 +4498,14 @@ int8_to_char(PG_FUNCTION_ARGS) double multi = pow((double) 10, (double) Num.multi); value = DatumGetInt64(DirectFunctionCall2(int8mul, - Int64GetDatum(value), - DirectFunctionCall1(dtoi8, - Float8GetDatum(multi)))); + Int64GetDatum(value), + DirectFunctionCall1(dtoi8, + Float8GetDatum(multi)))); Num.pre += Num.multi; } orgnum = DatumGetCString(DirectFunctionCall1(int8out, - Int64GetDatum(value))); + Int64GetDatum(value))); len = strlen(orgnum); if (*orgnum == '-') @@ -4475,7 +4518,7 @@ int8_to_char(PG_FUNCTION_ARGS) if (Num.post) { - int i; + int i; numstr = (char *) palloc(len + Num.post + 2); strcpy(numstr, orgnum + (*orgnum == '-' ? 1 : 0)); @@ -4511,19 +4554,19 @@ int8_to_char(PG_FUNCTION_ARGS) Datum float4_to_char(PG_FUNCTION_ARGS) { - float4 value = PG_GETARG_FLOAT4(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + float4 value = PG_GETARG_FLOAT4(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum, - *p; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum, + *p; NUM_TOCHAR_prepare; @@ -4538,7 +4581,7 @@ float4_to_char(PG_FUNCTION_ARGS) if (IS_MULTI(&Num)) { - float multi = pow((double) 10, (double) Num.multi); + float multi = pow((double) 10, (double) Num.multi); val = value * multi; Num.pre += Num.multi; @@ -4591,19 +4634,19 @@ float4_to_char(PG_FUNCTION_ARGS) Datum float8_to_char(PG_FUNCTION_ARGS) { - float8 value = PG_GETARG_FLOAT8(0); - text *fmt = PG_GETARG_TEXT_P(1); - NUMDesc Num; + float8 value = PG_GETARG_FLOAT8(0); + text *fmt = PG_GETARG_TEXT_P(1); + NUMDesc Num; FormatNode *format; - text *result, - *result_tmp; - int flag = 0; - int len = 0, - plen = 0, - sign = 0; - char *numstr, - *orgnum, - *p; + text *result, + *result_tmp; + int flag = 0; + int len = 0, + plen = 0, + sign = 0; + char *numstr, + *orgnum, + *p; NUM_TOCHAR_prepare; @@ -4618,7 +4661,7 @@ float8_to_char(PG_FUNCTION_ARGS) if (IS_MULTI(&Num)) { - double multi = pow((double) 10, (double) Num.multi); + double multi = pow((double) 10, (double) Num.multi); val = value * multi; Num.pre += Num.multi; diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index ef3e28fc61d..aac191b3778 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.57 2001/01/24 19:43:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.58 2001/03/22 03:59:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -484,11 +484,11 @@ box_ov(BOX *box1, BOX *box2) FPle(box1->low.x, box2->high.x)) || (FPge(box2->high.x, box1->high.x) && FPle(box2->low.x, box1->high.x))) - && - ((FPge(box1->high.y, box2->high.y) && - FPle(box1->low.y, box2->high.y)) || - (FPge(box2->high.y, box1->high.y) && - FPle(box2->low.y, box1->high.y))); + && + ((FPge(box1->high.y, box2->high.y) && + FPle(box1->low.y, box2->high.y)) || + (FPge(box2->high.y, box1->high.y) && + FPle(box2->low.y, box1->high.y))); } /* box_overleft - is the right edge of box1 to the left of @@ -811,8 +811,10 @@ line_in(PG_FUNCTION_ARGS) { #ifdef ENABLE_LINE_TYPE char *str = PG_GETARG_CSTRING(0); + #endif LINE *line; + #ifdef ENABLE_LINE_TYPE LSEG lseg; int isopen; @@ -838,8 +840,10 @@ line_out(PG_FUNCTION_ARGS) { #ifdef ENABLE_LINE_TYPE LINE *line = PG_GETARG_LINE_P(0); + #endif char *result; + #ifdef ENABLE_LINE_TYPE LSEG lseg; @@ -996,9 +1000,9 @@ line_intersect(PG_FUNCTION_ARGS) LINE *l1 = PG_GETARG_LINE_P(0); LINE *l2 = PG_GETARG_LINE_P(1); - PG_RETURN_BOOL(! DatumGetBool(DirectFunctionCall2(line_parallel, - LinePGetDatum(l1), - LinePGetDatum(l2)))); + PG_RETURN_BOOL(!DatumGetBool(DirectFunctionCall2(line_parallel, + LinePGetDatum(l1), + LinePGetDatum(l2)))); } Datum @@ -1089,9 +1093,9 @@ line_distance(PG_FUNCTION_ARGS) float8 result; Point *tmp; - if (! DatumGetBool(DirectFunctionCall2(line_parallel, - LinePGetDatum(l1), - LinePGetDatum(l2)))) + if (!DatumGetBool(DirectFunctionCall2(line_parallel, + LinePGetDatum(l1), + LinePGetDatum(l2)))) PG_RETURN_FLOAT8(0.0); if (FPzero(l1->B)) /* vertical? */ PG_RETURN_FLOAT8(fabs(l1->C - l2->C)); @@ -1131,9 +1135,10 @@ line_interpt_internal(LINE *l1, LINE *l2) y; /* - * NOTE: if the lines are identical then we will find they are parallel - * and report "no intersection". This is a little weird, but since - * there's no *unique* intersection, maybe it's appropriate behavior. + * NOTE: if the lines are identical then we will find they are + * parallel and report "no intersection". This is a little weird, but + * since there's no *unique* intersection, maybe it's appropriate + * behavior. */ if (DatumGetBool(DirectFunctionCall2(line_parallel, LinePGetDatum(l1), @@ -1226,7 +1231,7 @@ path_in(PG_FUNCTION_ARGS) depth++; } - size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * npts; + size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts; path = (PATH *) palloc(size); path->size = size; @@ -1321,7 +1326,7 @@ path_isopen(PG_FUNCTION_ARGS) { PATH *path = PG_GETARG_PATH_P(0); - PG_RETURN_BOOL(! path->closed); + PG_RETURN_BOOL(!path->closed); } Datum @@ -1434,7 +1439,7 @@ path_distance(PG_FUNCTION_ARGS) tmp = DatumGetFloat8(DirectFunctionCall2(lseg_distance, LsegPGetDatum(&seg1), - LsegPGetDatum(&seg2))); + LsegPGetDatum(&seg2))); if (!have_min || tmp < min) { min = tmp; @@ -1443,7 +1448,7 @@ path_distance(PG_FUNCTION_ARGS) } } - if (! have_min) + if (!have_min) PG_RETURN_NULL(); PG_RETURN_FLOAT8(min); @@ -1992,9 +1997,10 @@ lseg_interpt(PG_FUNCTION_ARGS) result = line_interpt_internal(&tmp1, &tmp2); if (!PointerIsValid(result)) PG_RETURN_NULL(); + /* - * If the line intersection point isn't within l1 (or equivalently l2), - * there is no valid segment intersection point at all. + * If the line intersection point isn't within l1 (or equivalently + * l2), there is no valid segment intersection point at all. */ if (!on_ps_internal(result, l1) || !on_ps_internal(result, l2)) @@ -2002,10 +2008,11 @@ lseg_interpt(PG_FUNCTION_ARGS) pfree(result); PG_RETURN_NULL(); } + /* * If there is an intersection, then check explicitly for matching - * endpoints since there may be rounding effects with annoying - * lsb residue. - tgl 1997-07-09 + * endpoints since there may be rounding effects with annoying lsb + * residue. - tgl 1997-07-09 */ if ((FPeq(l1->p[0].x, l2->p[0].x) && FPeq(l1->p[0].y, l2->p[0].y)) || (FPeq(l1->p[0].x, l2->p[1].x) && FPeq(l1->p[0].y, l2->p[1].y))) @@ -2014,7 +2021,7 @@ lseg_interpt(PG_FUNCTION_ARGS) result->y = l1->p[0].y; } else if ((FPeq(l1->p[1].x, l2->p[0].x) && FPeq(l1->p[1].y, l2->p[0].y)) || - (FPeq(l1->p[1].x, l2->p[1].x) && FPeq(l1->p[1].y, l2->p[1].y))) + (FPeq(l1->p[1].x, l2->p[1].x) && FPeq(l1->p[1].y, l2->p[1].y))) { result->x = l1->p[1].x; result->y = l1->p[1].y; @@ -2048,7 +2055,7 @@ static double dist_pl_internal(Point *pt, LINE *line) { return (line->A * pt->x + line->B * pt->y + line->C) / - HYPOT(line->A, line->B); + HYPOT(line->A, line->B); } Datum @@ -2080,9 +2087,7 @@ dist_ps_internal(Point *pt, LSEG *lseg) m = (double) DBL_MAX; } else - { m = ((lseg->p[0].y - lseg->p[1].y) / (lseg->p[1].x - lseg->p[0].x)); - } ln = line_construct_pm(pt, m); #ifdef GEODEBUG @@ -2188,9 +2193,7 @@ dist_sl(PG_FUNCTION_ARGS) d2; if (has_interpt_sl(lseg, line)) - { result = 0.0; - } else { result = dist_pl_internal(&lseg->p[0], line); @@ -2230,6 +2233,7 @@ dist_lb(PG_FUNCTION_ARGS) #ifdef NOT_USED LINE *line = PG_GETARG_LINE_P(0); BOX *box = PG_GETARG_BOX_P(1); + #endif /* think about this one for a while */ @@ -2243,7 +2247,7 @@ Datum dist_cpoly(PG_FUNCTION_ARGS) { CIRCLE *circle = PG_GETARG_CIRCLE_P(0); - POLYGON *poly = PG_GETARG_POLYGON_P(1); + POLYGON *poly = PG_GETARG_POLYGON_P(1); float8 result; float8 d; int i; @@ -2430,7 +2434,7 @@ close_ps(PG_FUNCTION_ARGS) xh = lseg->p[0].x < lseg->p[1].x; yh = lseg->p[0].y < lseg->p[1].y; - if (FPeq(lseg->p[0].x, lseg->p[1].x)) /* vertical? */ + if (FPeq(lseg->p[0].x, lseg->p[1].x)) /* vertical? */ { #ifdef GEODEBUG printf("close_ps- segment is vertical\n"); @@ -2450,7 +2454,7 @@ close_ps(PG_FUNCTION_ARGS) result->y = pt->y; PG_RETURN_POINT_P(result); } - else if (FPeq(lseg->p[0].y, lseg->p[1].y)) /* horizontal? */ + else if (FPeq(lseg->p[0].y, lseg->p[1].y)) /* horizontal? */ { #ifdef GEODEBUG printf("close_ps- segment is horizontal\n"); @@ -2484,7 +2488,7 @@ close_ps(PG_FUNCTION_ARGS) * lower end pt */ #ifdef GEODEBUG printf("close_ps below: tmp A %f B %f C %f m %f\n", - tmp->A,tmp->B,tmp->C, tmp->m); + tmp->A, tmp->B, tmp->C, tmp->m); #endif PG_RETURN_POINT_P(result); } @@ -2496,7 +2500,7 @@ close_ps(PG_FUNCTION_ARGS) * higher end pt */ #ifdef GEODEBUG printf("close_ps above: tmp A %f B %f C %f m %f\n", - tmp->A,tmp->B,tmp->C, tmp->m); + tmp->A, tmp->B, tmp->C, tmp->m); #endif PG_RETURN_POINT_P(result); } @@ -2508,7 +2512,7 @@ close_ps(PG_FUNCTION_ARGS) tmp = line_construct_pm(pt, invm); #ifdef GEODEBUG printf("close_ps- tmp A %f B %f C %f m %f\n", - tmp->A,tmp->B,tmp->C, tmp->m); + tmp->A, tmp->B, tmp->C, tmp->m); #endif result = interpt_sl(lseg, tmp); Assert(result != NULL); @@ -2545,12 +2549,12 @@ close_lseg(PG_FUNCTION_ARGS) if ((d = dist_ps_internal(&l2->p[0], l1)) < dist) { result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&l2->p[0]), + PointPGetDatum(&l2->p[0]), LsegPGetDatum(l1))); memcpy(&point, result, sizeof(Point)); pfree(result); result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&point), + PointPGetDatum(&point), LsegPGetDatum(l2))); } @@ -2560,12 +2564,12 @@ close_lseg(PG_FUNCTION_ARGS) pfree(result); result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&l2->p[1]), + PointPGetDatum(&l2->p[1]), LsegPGetDatum(l1))); memcpy(&point, result, sizeof(Point)); pfree(result); result = DatumGetPointP(DirectFunctionCall2(close_ps, - PointPGetDatum(&point), + PointPGetDatum(&point), LsegPGetDatum(l2))); } @@ -2752,6 +2756,7 @@ close_lb(PG_FUNCTION_ARGS) #ifdef NOT_USED LINE *line = PG_GETARG_LINE_P(0); BOX *box = PG_GETARG_BOX_P(1); + #endif /* think about this one for a while */ @@ -2858,11 +2863,11 @@ on_sl(PG_FUNCTION_ARGS) LINE *line = PG_GETARG_LINE_P(1); PG_RETURN_BOOL(DatumGetBool(DirectFunctionCall2(on_pl, - PointPGetDatum(&lseg->p[0]), - LinePGetDatum(line))) && + PointPGetDatum(&lseg->p[0]), + LinePGetDatum(line))) && DatumGetBool(DirectFunctionCall2(on_pl, - PointPGetDatum(&lseg->p[1]), - LinePGetDatum(line)))); + PointPGetDatum(&lseg->p[1]), + LinePGetDatum(line)))); } Datum @@ -2872,11 +2877,11 @@ on_sb(PG_FUNCTION_ARGS) BOX *box = PG_GETARG_BOX_P(1); PG_RETURN_BOOL(DatumGetBool(DirectFunctionCall2(on_pb, - PointPGetDatum(&lseg->p[0]), - BoxPGetDatum(box))) && + PointPGetDatum(&lseg->p[0]), + BoxPGetDatum(box))) && DatumGetBool(DirectFunctionCall2(on_pb, - PointPGetDatum(&lseg->p[1]), - BoxPGetDatum(box)))); + PointPGetDatum(&lseg->p[1]), + BoxPGetDatum(box)))); } /*--------------------------------------------------------------------- @@ -3058,7 +3063,7 @@ poly_in(PG_FUNCTION_ARGS) if ((npts = pair_count(str, ',')) <= 0) elog(ERROR, "Bad polygon external representation '%s'", str); - size = offsetof(POLYGON, p[0]) + sizeof(poly->p[0]) * npts; + size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts; poly = (POLYGON *) palloc(size); MemSet((char *) poly, 0, size); /* zero any holes */ @@ -3081,7 +3086,7 @@ poly_in(PG_FUNCTION_ARGS) Datum poly_out(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); PG_RETURN_CSTRING(path_encode(TRUE, poly->npts, poly->p)); } @@ -3095,13 +3100,16 @@ poly_out(PG_FUNCTION_ARGS) Datum poly_left(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.high.x < polyb->boundbox.low.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3116,13 +3124,16 @@ poly_left(PG_FUNCTION_ARGS) Datum poly_overleft(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.low.x <= polyb->boundbox.high.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3137,13 +3148,16 @@ poly_overleft(PG_FUNCTION_ARGS) Datum poly_right(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.low.x > polyb->boundbox.high.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3158,13 +3172,16 @@ poly_right(PG_FUNCTION_ARGS) Datum poly_overright(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = polya->boundbox.high.x > polyb->boundbox.low.x; - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3181,8 +3198,8 @@ poly_overright(PG_FUNCTION_ARGS) Datum poly_same(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; if (polya->npts != polyb->npts) @@ -3190,7 +3207,10 @@ poly_same(PG_FUNCTION_ARGS) else result = plist_same(polya->npts, polya->p, polyb->p); - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3206,13 +3226,16 @@ poly_same(PG_FUNCTION_ARGS) Datum poly_overlap(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; result = box_ov(&polya->boundbox, &polyb->boundbox); - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3226,8 +3249,8 @@ poly_overlap(PG_FUNCTION_ARGS) Datum poly_contain(PG_FUNCTION_ARGS) { - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); bool result; int i; @@ -3275,7 +3298,10 @@ poly_contain(PG_FUNCTION_ARGS) result = false; } - /* Avoid leaking memory for toasted inputs ... needed for rtree indexes */ + /* + * Avoid leaking memory for toasted inputs ... needed for rtree + * indexes + */ PG_FREE_IF_COPY(polya, 0); PG_FREE_IF_COPY(polyb, 1); @@ -3310,7 +3336,7 @@ poly_contained(PG_FUNCTION_ARGS) Datum poly_contain_pt(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); Point *p = PG_GETARG_POINT_P(1); PG_RETURN_BOOL(point_inside(p, poly->npts, poly->p) != 0); @@ -3320,7 +3346,7 @@ Datum pt_contained_poly(PG_FUNCTION_ARGS) { Point *p = PG_GETARG_POINT_P(0); - POLYGON *poly = PG_GETARG_POLYGON_P(1); + POLYGON *poly = PG_GETARG_POLYGON_P(1); PG_RETURN_BOOL(point_inside(p, poly->npts, poly->p) != 0); } @@ -3330,8 +3356,9 @@ Datum poly_distance(PG_FUNCTION_ARGS) { #ifdef NOT_USED - POLYGON *polya = PG_GETARG_POLYGON_P(0); - POLYGON *polyb = PG_GETARG_POLYGON_P(1); + POLYGON *polya = PG_GETARG_POLYGON_P(0); + POLYGON *polyb = PG_GETARG_POLYGON_P(1); + #endif elog(ERROR, "poly_distance not implemented"); @@ -3531,7 +3558,7 @@ path_add(PG_FUNCTION_ARGS) if (p1->closed || p2->closed) PG_RETURN_NULL(); - size = offsetof(PATH, p[0]) + sizeof(p1->p[0]) * (p1->npts + p2->npts); + size = offsetof(PATH, p[0]) +sizeof(p1->p[0]) * (p1->npts + p2->npts); result = (PATH *) palloc(size); result->size = size; @@ -3601,7 +3628,7 @@ path_mul_pt(PG_FUNCTION_ARGS) for (i = 0; i < path->npts; i++) { p = DatumGetPointP(DirectFunctionCall2(point_mul, - PointPGetDatum(&path->p[i]), + PointPGetDatum(&path->p[i]), PointPGetDatum(point))); path->p[i].x = p->x; path->p[i].y = p->y; @@ -3622,7 +3649,7 @@ path_div_pt(PG_FUNCTION_ARGS) for (i = 0; i < path->npts; i++) { p = DatumGetPointP(DirectFunctionCall2(point_div, - PointPGetDatum(&path->p[i]), + PointPGetDatum(&path->p[i]), PointPGetDatum(point))); path->p[i].x = p->x; path->p[i].y = p->y; @@ -3638,6 +3665,7 @@ path_center(PG_FUNCTION_ARGS) { #ifdef NOT_USED PATH *path = PG_GETARG_PATH_P(0); + #endif elog(ERROR, "path_center not implemented"); @@ -3657,7 +3685,7 @@ path_poly(PG_FUNCTION_ARGS) if (!path->closed) elog(ERROR, "Open path cannot be converted to polygon"); - size = offsetof(POLYGON, p[0]) + sizeof(poly->p[0]) * path->npts; + size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * path->npts; poly = (POLYGON *) palloc(size); poly->size = size; @@ -3684,7 +3712,7 @@ path_poly(PG_FUNCTION_ARGS) Datum poly_npoints(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); PG_RETURN_INT32(poly->npts); } @@ -3693,7 +3721,7 @@ poly_npoints(PG_FUNCTION_ARGS) Datum poly_center(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); Datum result; CIRCLE *circle; @@ -3710,7 +3738,7 @@ poly_center(PG_FUNCTION_ARGS) Datum poly_box(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); BOX *box; if (poly->npts < 1) @@ -3733,7 +3761,7 @@ box_poly(PG_FUNCTION_ARGS) int size; /* map four corners of the box to a polygon */ - size = offsetof(POLYGON, p[0]) + sizeof(poly->p[0]) * 4; + size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * 4; poly = (POLYGON *) palloc(size); poly->size = size; @@ -3758,12 +3786,12 @@ box_poly(PG_FUNCTION_ARGS) Datum poly_path(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); PATH *path; int size; int i; - size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * poly->npts; + size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * poly->npts; path = (PATH *) palloc(size); path->size = size; @@ -4133,7 +4161,7 @@ circle_mul_pt(PG_FUNCTION_ARGS) result = circle_copy(circle); p = DatumGetPointP(DirectFunctionCall2(point_mul, - PointPGetDatum(&circle->center), + PointPGetDatum(&circle->center), PointPGetDatum(point))); result->center.x = p->x; result->center.y = p->y; @@ -4154,7 +4182,7 @@ circle_div_pt(PG_FUNCTION_ARGS) result = circle_copy(circle); p = DatumGetPointP(DirectFunctionCall2(point_div, - PointPGetDatum(&circle->center), + PointPGetDatum(&circle->center), PointPGetDatum(point))); result->center.x = p->x; result->center.y = p->y; @@ -4381,7 +4409,7 @@ circle_poly(PG_FUNCTION_ARGS) Datum poly_circle(PG_FUNCTION_ARGS) { - POLYGON *poly = PG_GETARG_POLYGON_P(0); + POLYGON *poly = PG_GETARG_POLYGON_P(0); CIRCLE *circle; int i; diff --git a/src/backend/utils/adt/inet_net_ntop.c b/src/backend/utils/adt/inet_net_ntop.c index ecc83cab814..73329300956 100644 --- a/src/backend/utils/adt/inet_net_ntop.c +++ b/src/backend/utils/adt/inet_net_ntop.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.9 2000/11/10 20:13:25 tgl Exp $"; +static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.10 2001/03/22 03:59:51 momjian Exp $"; #endif @@ -56,7 +56,7 @@ inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { - case AF_INET: + case AF_INET: return (inet_cidr_ntop_ipv4(src, bits, dst, size)); default: errno = EAFNOSUPPORT; @@ -157,7 +157,7 @@ inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { - case AF_INET: + case AF_INET: return (inet_net_ntop_ipv4(src, bits, dst, size)); default: errno = EAFNOSUPPORT; diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index 189cd384162..00c99805c9e 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.45 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.46 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,7 +63,7 @@ Datum int2out(PG_FUNCTION_ARGS) { int16 arg1 = PG_GETARG_INT16(0); - char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */ + char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */ pg_itoa(arg1, result); PG_RETURN_CSTRING(result); @@ -180,7 +180,8 @@ Datum int44out(PG_FUNCTION_ARGS) { int32 *an_array = (int32 *) PG_GETARG_POINTER(0); - char *result = (char *) palloc(16 * 4); /* Allow 14 digits + sign */ + char *result = (char *) palloc(16 * 4); /* Allow 14 digits + + * sign */ int i; char *walk; @@ -219,7 +220,7 @@ Datum int4out(PG_FUNCTION_ARGS) { int32 arg1 = PG_GETARG_INT32(0); - char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */ + char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */ pg_ltoa(arg1, result); PG_RETURN_CSTRING(result); @@ -257,7 +258,7 @@ Datum int2_text(PG_FUNCTION_ARGS) { int16 arg1 = PG_GETARG_INT16(0); - text *result = (text *) palloc(7+VARHDRSZ); /* sign,5 digits, '\0' */ + text *result = (text *) palloc(7 + VARHDRSZ); /* sign,5 digits, '\0' */ pg_itoa(arg1, VARDATA(result)); VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ; @@ -288,7 +289,7 @@ Datum int4_text(PG_FUNCTION_ARGS) { int32 arg1 = PG_GETARG_INT32(0); - text *result = (text *) palloc(12+VARHDRSZ); /* sign,10 digits,'\0' */ + text *result = (text *) palloc(12 + VARHDRSZ); /* sign,10 digits,'\0' */ pg_ltoa(arg1, VARDATA(result)); VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ; @@ -960,4 +961,3 @@ int2shr(PG_FUNCTION_ARGS) PG_RETURN_INT16(arg1 >> arg2); } - diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index a7df878c65b..3f286069b7d 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.28 2001/01/26 22:50:26 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.29 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -67,15 +67,15 @@ int8in(PG_FUNCTION_ARGS) * Do our own scan, rather than relying on sscanf which might be * broken for long long. */ - while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */ + while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */ ptr++; if (*ptr == '-') /* handle sign */ sign = -1, ptr++; else if (*ptr == '+') ptr++; - if (!isdigit((unsigned char) *ptr)) /* require at least one digit */ + if (!isdigit((unsigned char) *ptr)) /* require at least one digit */ elog(ERROR, "Bad int8 external representation \"%s\"", str); - while (*ptr && isdigit((unsigned char) *ptr)) /* process digits */ + while (*ptr && isdigit((unsigned char) *ptr)) /* process digits */ { int64 newtmp = tmp * 10 + (*ptr++ - '0'); @@ -409,7 +409,7 @@ int8um(PG_FUNCTION_ARGS) { int64 val = PG_GETARG_INT64(0); - PG_RETURN_INT64(- val); + PG_RETURN_INT64(-val); } Datum @@ -702,10 +702,11 @@ dtoi8(PG_FUNCTION_ARGS) /* Round val to nearest integer (but it's still in float form) */ val = rint(val); + /* - * Does it fit in an int64? Avoid assuming that we have handy constants - * defined for the range boundaries, instead test for overflow by - * reverse-conversion. + * Does it fit in an int64? Avoid assuming that we have handy + * constants defined for the range boundaries, instead test for + * overflow by reverse-conversion. */ result = (int64) val; diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c index 7bac7793fba..f27bc067d6a 100644 --- a/src/backend/utils/adt/like.c +++ b/src/backend/utils/adt/like.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.44 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.45 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,10 +30,10 @@ #define LIKE_ABORT (-1) -static int MatchText(unsigned char * t, int tlen, - unsigned char * p, int plen); -static int MatchTextIC(unsigned char * t, int tlen, - unsigned char * p, int plen); +static int MatchText(unsigned char *t, int tlen, + unsigned char *p, int plen); +static int MatchTextIC(unsigned char *t, int tlen, + unsigned char *p, int plen); #ifdef MULTIBYTE @@ -42,19 +42,20 @@ static int MatchTextIC(unsigned char * t, int tlen, * as wide characters. If they match, returns 1 otherwise returns 0. *-------------------- */ -static int wchareq(unsigned char *p1, unsigned char *p2) +static int +wchareq(unsigned char *p1, unsigned char *p2) { - int l; + int l; l = pg_mblen(p1); - if (pg_mblen(p2) != l) { - return(0); - } - while (l--) { + if (pg_mblen(p2) != l) + return (0); + while (l--) + { if (*p1++ != *p2++) - return(0); + return (0); } - return(1); + return (1); } /*-------------------- @@ -65,32 +66,38 @@ static int wchareq(unsigned char *p1, unsigned char *p2) */ #define CHARMAX 0x80 -static int iwchareq(unsigned char *p1, unsigned char *p2) +static int +iwchareq(unsigned char *p1, unsigned char *p2) { - int c1[2], c2[2]; - int l; + int c1[2], + c2[2]; + int l; - /* short cut. if *p1 and *p2 is lower than CHARMAX, then - we could assume they are ASCII */ + /* + * short cut. if *p1 and *p2 is lower than CHARMAX, then we could + * assume they are ASCII + */ if (*p1 < CHARMAX && *p2 < CHARMAX) - return(tolower(*p1) == tolower(*p2)); + return (tolower(*p1) == tolower(*p2)); - /* if one of them is an ASCII while the other is not, then - they must be different characters - */ + /* + * if one of them is an ASCII while the other is not, then they must + * be different characters + */ else if (*p1 < CHARMAX || *p2 < CHARMAX) - return(0); + return (0); - /* ok, p1 and p2 are both > CHARMAX, then they must be multi-byte - characters - */ + /* + * ok, p1 and p2 are both > CHARMAX, then they must be multi-byte + * characters + */ l = pg_mblen(p1); - (void)pg_mb2wchar_with_len(p1, (pg_wchar *)c1, l); + (void) pg_mb2wchar_with_len(p1, (pg_wchar *) c1, l); c1[0] = tolower(c1[0]); l = pg_mblen(p2); - (void)pg_mb2wchar_with_len(p2, (pg_wchar *)c2, l); + (void) pg_mb2wchar_with_len(p2, (pg_wchar *) c2, l); c2[0] = tolower(c2[0]); - return(c1[0] == c2[0]); + return (c1[0] == c2[0]); } #endif @@ -124,13 +131,15 @@ namelike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) == LIKE_TRUE); @@ -143,13 +152,15 @@ namenlike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) != LIKE_TRUE); @@ -162,13 +173,15 @@ textlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) == LIKE_TRUE); @@ -181,13 +194,15 @@ textnlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchText(s, slen, p, plen) != LIKE_TRUE); @@ -204,13 +219,15 @@ nameiclike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE); @@ -223,13 +240,15 @@ nameicnlike(PG_FUNCTION_ARGS) Name str = PG_GETARG_NAME(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = NameStr(*str); slen = strlen(s); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE); @@ -242,13 +261,15 @@ texticlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) == LIKE_TRUE); @@ -261,13 +282,15 @@ texticnlike(PG_FUNCTION_ARGS) text *str = PG_GETARG_TEXT_P(0); text *pat = PG_GETARG_TEXT_P(1); bool result; - unsigned char *s, *p; - int slen, plen; + unsigned char *s, + *p; + int slen, + plen; s = VARDATA(str); - slen = (VARSIZE(str)-VARHDRSZ); + slen = (VARSIZE(str) - VARHDRSZ); p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); result = (MatchTextIC(s, slen, p, plen) != LIKE_TRUE); @@ -284,14 +307,17 @@ like_escape(PG_FUNCTION_ARGS) text *pat = PG_GETARG_TEXT_P(0); text *esc = PG_GETARG_TEXT_P(1); text *result; - unsigned char *p, *e, *r; - int plen, elen; + unsigned char *p, + *e, + *r; + int plen, + elen; bool afterescape; p = VARDATA(pat); - plen = (VARSIZE(pat)-VARHDRSZ); + plen = (VARSIZE(pat) - VARHDRSZ); e = VARDATA(esc); - elen = (VARSIZE(esc)-VARHDRSZ); + elen = (VARSIZE(esc) - VARHDRSZ); /* * Worst-case pattern growth is 2x --- unlikely, but it's hardly worth @@ -302,6 +328,7 @@ like_escape(PG_FUNCTION_ARGS) if (elen == 0) { + /* * No escape character is wanted. Double any backslashes in the * pattern to make them act like ordinary characters. @@ -315,6 +342,7 @@ like_escape(PG_FUNCTION_ARGS) } else { + /* * The specified escape must be only a single character. */ @@ -322,6 +350,7 @@ like_escape(PG_FUNCTION_ARGS) if (elen != 0) elog(ERROR, "ESCAPE string must be empty or one character"); e = VARDATA(esc); + /* * If specified escape is '\', just copy the pattern as-is. */ @@ -330,15 +359,16 @@ like_escape(PG_FUNCTION_ARGS) memcpy(result, pat, VARSIZE(pat)); PG_RETURN_TEXT_P(result); } + /* - * Otherwise, convert occurrences of the specified escape character - * to '\', and double occurrences of '\' --- unless they immediately - * follow an escape character! + * Otherwise, convert occurrences of the specified escape + * character to '\', and double occurrences of '\' --- unless they + * immediately follow an escape character! */ afterescape = false; while (plen > 0) { - if (CHAREQ(p,e) && !afterescape) + if (CHAREQ(p, e) && !afterescape) { *r++ = '\\'; NextChar(p, plen); @@ -347,7 +377,7 @@ like_escape(PG_FUNCTION_ARGS) else if (*p == '\\') { *r++ = '\\'; - if (! afterescape) + if (!afterescape) *r++ = '\\'; NextChar(p, plen); afterescape = false; @@ -413,7 +443,7 @@ like_escape(PG_FUNCTION_ARGS) */ static int -MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) +MatchText(unsigned char *t, int tlen, unsigned char *p, int plen) { /* Fast path for match-everything pattern */ if ((plen == 1) && (*p == '%')) @@ -425,7 +455,7 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) { /* Next pattern char must match literally, whatever it is */ NextChar(p, plen); - if ((plen <= 0) || !CHAREQ(t,p)) + if ((plen <= 0) || !CHAREQ(t, p)) return LIKE_FALSE; } else if (*p == '%') @@ -439,22 +469,22 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_TRUE; /* - * Otherwise, scan for a text position at which we can - * match the rest of the pattern. + * Otherwise, scan for a text position at which we can match + * the rest of the pattern. */ while (tlen > 0) { + /* - * Optimization to prevent most recursion: don't - * recurse unless first pattern char might match this - * text char. + * Optimization to prevent most recursion: don't recurse + * unless first pattern char might match this text char. */ - if (CHAREQ(t,p) || (*p == '\\') || (*p == '_')) + if (CHAREQ(t, p) || (*p == '\\') || (*p == '_')) { - int matched = MatchText(t, tlen, p, plen); + int matched = MatchText(t, tlen, p, plen); if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -466,9 +496,11 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) */ return LIKE_ABORT; } - else if ((*p != '_') && !CHAREQ(t,p)) + else if ((*p != '_') && !CHAREQ(t, p)) { - /* Not the single-character wildcard and no explicit match? + + /* + * Not the single-character wildcard and no explicit match? * Then time to quit... */ return LIKE_FALSE; @@ -482,7 +514,8 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_FALSE; /* end of pattern, but not of text */ /* End of input string. Do we have matching pattern remaining? */ - while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */ + while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of + * pattern */ NextChar(p, plen); if (plen <= 0) return LIKE_TRUE; @@ -492,13 +525,13 @@ MatchText(unsigned char * t, int tlen, unsigned char * p, int plen) * start matching this pattern. */ return LIKE_ABORT; -} /* MatchText() */ +} /* MatchText() */ /* * Same as above, but ignore case */ static int -MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) +MatchTextIC(unsigned char *t, int tlen, unsigned char *p, int plen) { /* Fast path for match-everything pattern */ if ((plen == 1) && (*p == '%')) @@ -510,7 +543,7 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) { /* Next pattern char must match literally, whatever it is */ NextChar(p, plen); - if ((plen <= 0) || !ICHAREQ(t,p)) + if ((plen <= 0) || !ICHAREQ(t, p)) return LIKE_FALSE; } else if (*p == '%') @@ -524,22 +557,22 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_TRUE; /* - * Otherwise, scan for a text position at which we can - * match the rest of the pattern. + * Otherwise, scan for a text position at which we can match + * the rest of the pattern. */ while (tlen > 0) { + /* - * Optimization to prevent most recursion: don't - * recurse unless first pattern char might match this - * text char. + * Optimization to prevent most recursion: don't recurse + * unless first pattern char might match this text char. */ - if (ICHAREQ(t,p) || (*p == '\\') || (*p == '_')) + if (ICHAREQ(t, p) || (*p == '\\') || (*p == '_')) { - int matched = MatchTextIC(t, tlen, p, plen); + int matched = MatchTextIC(t, tlen, p, plen); if (matched != LIKE_FALSE) - return matched; /* TRUE or ABORT */ + return matched; /* TRUE or ABORT */ } NextChar(t, tlen); @@ -551,9 +584,11 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) */ return LIKE_ABORT; } - else if ((*p != '_') && !ICHAREQ(t,p)) + else if ((*p != '_') && !ICHAREQ(t, p)) { - /* Not the single-character wildcard and no explicit match? + + /* + * Not the single-character wildcard and no explicit match? * Then time to quit... */ return LIKE_FALSE; @@ -567,7 +602,8 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) return LIKE_FALSE; /* end of pattern, but not of text */ /* End of input string. Do we have matching pattern remaining? */ - while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of pattern */ + while ((plen > 0) && (*p == '%')) /* allow multiple %'s at end of + * pattern */ NextChar(p, plen); if (plen <= 0) return LIKE_TRUE; @@ -577,4 +613,4 @@ MatchTextIC(unsigned char * t, int tlen, unsigned char * p, int plen) * start matching this pattern. */ return LIKE_ABORT; -} /* MatchTextIC() */ +} /* MatchTextIC() */ diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c index 17754588e97..0724abec5b2 100644 --- a/src/backend/utils/adt/mac.c +++ b/src/backend/utils/adt/mac.c @@ -1,7 +1,7 @@ /* * PostgreSQL type definitions for MAC addresses. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.19 2000/12/08 23:57:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.20 2001/03/22 03:59:51 momjian Exp $ */ #include "postgres.h" @@ -82,7 +82,7 @@ macaddr_in(PG_FUNCTION_ARGS) Datum macaddr_out(PG_FUNCTION_ARGS) { - macaddr *addr = PG_GETARG_MACADDR_P(0); + macaddr *addr = PG_GETARG_MACADDR_P(0); char *result; result = (char *) palloc(32); @@ -139,16 +139,16 @@ text_macaddr(PG_FUNCTION_ARGS) char str[18]; int len; - len = (VARSIZE(addr)-VARHDRSZ); + len = (VARSIZE(addr) - VARHDRSZ); if (len >= 18) elog(ERROR, "Text is too long to convert to MAC address"); memmove(str, VARDATA(addr), len); - *(str+len) = '\0'; + *(str + len) = '\0'; - result = DirectFunctionCall1(macaddr_in, CStringGetDatum(str)); + result = DirectFunctionCall1(macaddr_in, CStringGetDatum(str)); - return(result); + return (result); } /* @@ -173,8 +173,8 @@ macaddr_cmp_internal(macaddr *a1, macaddr *a2) Datum macaddr_cmp(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_INT32(macaddr_cmp_internal(a1, a2)); } @@ -186,8 +186,8 @@ macaddr_cmp(PG_FUNCTION_ARGS) Datum macaddr_lt(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) < 0); } @@ -195,8 +195,8 @@ macaddr_lt(PG_FUNCTION_ARGS) Datum macaddr_le(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) <= 0); } @@ -204,8 +204,8 @@ macaddr_le(PG_FUNCTION_ARGS) Datum macaddr_eq(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) == 0); } @@ -213,8 +213,8 @@ macaddr_eq(PG_FUNCTION_ARGS) Datum macaddr_ge(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) >= 0); } @@ -222,8 +222,8 @@ macaddr_ge(PG_FUNCTION_ARGS) Datum macaddr_gt(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) > 0); } @@ -231,8 +231,8 @@ macaddr_gt(PG_FUNCTION_ARGS) Datum macaddr_ne(PG_FUNCTION_ARGS) { - macaddr *a1 = PG_GETARG_MACADDR_P(0); - macaddr *a2 = PG_GETARG_MACADDR_P(1); + macaddr *a1 = PG_GETARG_MACADDR_P(0); + macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) != 0); } @@ -243,7 +243,7 @@ macaddr_ne(PG_FUNCTION_ARGS) Datum hashmacaddr(PG_FUNCTION_ARGS) { - macaddr *key = PG_GETARG_MACADDR_P(0); + macaddr *key = PG_GETARG_MACADDR_P(0); return hash_any((char *) key, sizeof(macaddr)); } @@ -255,8 +255,8 @@ hashmacaddr(PG_FUNCTION_ARGS) Datum macaddr_trunc(PG_FUNCTION_ARGS) { - macaddr *result; - macaddr *addr = PG_GETARG_MACADDR_P(0); + macaddr *result; + macaddr *addr = PG_GETARG_MACADDR_P(0); result = (macaddr *) palloc(sizeof(macaddr)); diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index d3a82eaf8a1..af08bda8789 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.21 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.22 2001/03/22 03:59:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,7 +53,7 @@ nonnullvalue(PG_FUNCTION_ARGS) * select * from TEMP where oidrand(TEMP.oid, 10) * will return about 1/10 of the tuples in TEMP * - * NOTE: the OID input is not used at all. It is there just because of + * NOTE: the OID input is not used at all. It is there just because of * an old optimizer bug: a qual expression containing no variables was * mistakenly assumed to be a constant. Pretending to access the row's OID * prevented the optimizer from treating the oidrand() result as constant. @@ -66,6 +66,7 @@ oidrand(PG_FUNCTION_ARGS) { #ifdef NOT_USED Oid o = PG_GETARG_OID(0); + #endif int32 X = PG_GETARG_INT32(1); bool result; diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index 99dc95d4663..972ca7a67fa 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.82 2001/02/21 22:03:00 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.83 2001/03/22 03:59:52 momjian Exp $ * * NOTES * @@ -162,7 +162,8 @@ GetCurrentAbsoluteTime(void) CDayLight = tm->tm_isdst; CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); strcpy(CTZName, tzname[tm->tm_isdst]); -#else /* neither HAVE_TM_ZONE nor HAVE_INT_TIMEZONE */ +#else /* neither HAVE_TM_ZONE nor + * HAVE_INT_TIMEZONE */ CTimeZone = tb.timezone * 60; CDayLight = (tb.dstflag != 0); @@ -192,7 +193,8 @@ GetCurrentTime(struct tm * tm) void abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) { - time_t time = (time_t) _time; + time_t time = (time_t) _time; + #if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE) struct tm *tx; @@ -207,14 +209,14 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) if (tzp != NULL) { tx = localtime((time_t *) &time); -# ifdef NO_MKTIME_BEFORE_1970 +#ifdef NO_MKTIME_BEFORE_1970 if (tx->tm_year < 70 && tx->tm_isdst == 1) { time -= 3600; tx = localtime((time_t *) &time); tx->tm_isdst = 0; } -# endif +#endif } else { @@ -229,7 +231,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) tm->tm_sec = tx->tm_sec; tm->tm_isdst = tx->tm_isdst; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tm->tm_gmtoff = tx->tm_gmtoff; tm->tm_zone = tx->tm_zone; @@ -243,11 +245,11 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) * Copy no more than MAXTZLEN bytes of timezone to tzn, in case it * contains an error message, which doesn't fit in the buffer */ - StrNCpy(tzn, tm->tm_zone, MAXTZLEN+1); + StrNCpy(tzn, tm->tm_zone, MAXTZLEN + 1); if (strlen(tm->tm_zone) > MAXTZLEN) elog(NOTICE, "Invalid timezone \'%s\'", tm->tm_zone); } -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) if (tzp != NULL) *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); @@ -258,12 +260,12 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char *tzn) * Copy no more than MAXTZLEN bytes of timezone to tzn, in case it * contains an error message, which doesn't fit in the buffer */ - StrNCpy(tzn, tzname[tm->tm_isdst], MAXTZLEN+1); + StrNCpy(tzn, tzname[tm->tm_isdst], MAXTZLEN + 1); if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN) elog(NOTICE, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]); } -# endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#endif +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ if (tzp != NULL) *tzp = tb.timezone * 60; @@ -470,7 +472,7 @@ AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2) Datum abstime_finite(PG_FUNCTION_ARGS) { - AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); PG_RETURN_BOOL((abstime != INVALID_ABSTIME) && (abstime != NOSTART_ABSTIME) && @@ -489,8 +491,8 @@ abstime_finite(PG_FUNCTION_ARGS) Datum abstimeeq(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -505,8 +507,8 @@ abstimeeq(PG_FUNCTION_ARGS) Datum abstimene(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -521,8 +523,8 @@ abstimene(PG_FUNCTION_ARGS) Datum abstimelt(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -537,8 +539,8 @@ abstimelt(PG_FUNCTION_ARGS) Datum abstimegt(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -553,8 +555,8 @@ abstimegt(PG_FUNCTION_ARGS) Datum abstimele(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -569,8 +571,8 @@ abstimele(PG_FUNCTION_ARGS) Datum abstimege(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) PG_RETURN_BOOL(false); @@ -596,17 +598,11 @@ timestamp_abstime(PG_FUNCTION_ARGS) *tm = &tt; if (TIMESTAMP_IS_INVALID(timestamp)) - { result = INVALID_ABSTIME; - } else if (TIMESTAMP_IS_NOBEGIN(timestamp)) - { result = NOSTART_ABSTIME; - } else if (TIMESTAMP_IS_NOEND(timestamp)) - { result = NOEND_ABSTIME; - } else { if (TIMESTAMP_IS_RELATIVE(timestamp)) @@ -615,13 +611,9 @@ timestamp_abstime(PG_FUNCTION_ARGS) result = tm2abstime(tm, 0); } else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) == 0) - { result = tm2abstime(tm, 0); - } else - { result = INVALID_ABSTIME; - } } PG_RETURN_ABSOLUTETIME(result); @@ -633,7 +625,7 @@ timestamp_abstime(PG_FUNCTION_ARGS) Datum abstime_timestamp(PG_FUNCTION_ARGS) { - AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); + AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); Timestamp result; switch (abstime) @@ -677,7 +669,7 @@ abstime_timestamp(PG_FUNCTION_ARGS) Datum reltimein(PG_FUNCTION_ARGS) { - char *str = PG_GETARG_CSTRING(0); + char *str = PG_GETARG_CSTRING(0); RelativeTime result; struct tm tt, *tm = &tt; @@ -724,9 +716,7 @@ reltimeout(PG_FUNCTION_ARGS) char buf[MAXDATELEN + 1]; if (time == INVALID_RELTIME) - { strcpy(buf, INVALID_RELTIME_STR); - } else { reltime2tm(time, tm); @@ -840,12 +830,12 @@ tintervalout(PG_FUNCTION_ARGS) else { p = DatumGetCString(DirectFunctionCall1(nabstimeout, - AbsoluteTimeGetDatum(interval->data[0]))); + AbsoluteTimeGetDatum(interval->data[0]))); strcat(i_str, p); pfree(p); strcat(i_str, "\" \""); p = DatumGetCString(DirectFunctionCall1(nabstimeout, - AbsoluteTimeGetDatum(interval->data[1]))); + AbsoluteTimeGetDatum(interval->data[1]))); strcat(i_str, p); pfree(p); } @@ -868,9 +858,7 @@ interval_reltime(PG_FUNCTION_ARGS) double span; if (INTERVAL_IS_INVALID(*interval)) - { time = INVALID_RELTIME; - } else { if (interval->month == 0) @@ -965,8 +953,8 @@ mktinterval(PG_FUNCTION_ARGS) Datum timepl(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == CURRENT_ABSTIME) t1 = GetCurrentTransactionStartTime(); @@ -987,8 +975,8 @@ timepl(PG_FUNCTION_ARGS) Datum timemi(PG_FUNCTION_ARGS) { - AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == CURRENT_ABSTIME) t1 = GetCurrentTransactionStartTime(); @@ -1030,17 +1018,17 @@ abstimemi(AbsoluteTime t1, AbsoluteTime t2) Datum intinterval(PG_FUNCTION_ARGS) { - AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0); - TimeInterval interval = PG_GETARG_TIMEINTERVAL(1); + AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0); + TimeInterval interval = PG_GETARG_TIMEINTERVAL(1); if (interval->status == T_INTERVAL_VALID && t != INVALID_ABSTIME) { if (DatumGetBool(DirectFunctionCall2(abstimege, - AbsoluteTimeGetDatum(t), - AbsoluteTimeGetDatum(interval->data[0]))) && + AbsoluteTimeGetDatum(t), + AbsoluteTimeGetDatum(interval->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimele, - AbsoluteTimeGetDatum(t), - AbsoluteTimeGetDatum(interval->data[1])))) + AbsoluteTimeGetDatum(t), + AbsoluteTimeGetDatum(interval->data[1])))) PG_RETURN_BOOL(true); } PG_RETURN_BOOL(false); @@ -1086,8 +1074,8 @@ timenow(PG_FUNCTION_ARGS) Datum reltimeeq(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1097,8 +1085,8 @@ reltimeeq(PG_FUNCTION_ARGS) Datum reltimene(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1108,8 +1096,8 @@ reltimene(PG_FUNCTION_ARGS) Datum reltimelt(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1119,8 +1107,8 @@ reltimelt(PG_FUNCTION_ARGS) Datum reltimegt(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1130,8 +1118,8 @@ reltimegt(PG_FUNCTION_ARGS) Datum reltimele(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1141,8 +1129,8 @@ reltimele(PG_FUNCTION_ARGS) Datum reltimege(PG_FUNCTION_ARGS) { - RelativeTime t1 = PG_GETARG_RELATIVETIME(0); - RelativeTime t2 = PG_GETARG_RELATIVETIME(1); + RelativeTime t1 = PG_GETARG_RELATIVETIME(0); + RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (t1 == INVALID_RELTIME || t2 == INVALID_RELTIME) PG_RETURN_BOOL(false); @@ -1157,18 +1145,18 @@ reltimege(PG_FUNCTION_ARGS) Datum tintervalsame(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimeeq, - AbsoluteTimeGetDatum(i1->data[0]), - AbsoluteTimeGetDatum(i2->data[0]))) && + AbsoluteTimeGetDatum(i1->data[0]), + AbsoluteTimeGetDatum(i2->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimeeq, - AbsoluteTimeGetDatum(i1->data[1]), - AbsoluteTimeGetDatum(i2->data[1])))) + AbsoluteTimeGetDatum(i1->data[1]), + AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(true); PG_RETURN_BOOL(false); } @@ -1181,8 +1169,8 @@ tintervalsame(PG_FUNCTION_ARGS) Datum tintervaleq(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1215,8 +1203,8 @@ tintervaleq(PG_FUNCTION_ARGS) Datum tintervalne(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1249,8 +1237,8 @@ tintervalne(PG_FUNCTION_ARGS) Datum tintervallt(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1283,8 +1271,8 @@ tintervallt(PG_FUNCTION_ARGS) Datum tintervalle(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1317,8 +1305,8 @@ tintervalle(PG_FUNCTION_ARGS) Datum tintervalgt(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1351,8 +1339,8 @@ tintervalgt(PG_FUNCTION_ARGS) Datum tintervalge(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); AbsoluteTime t10, t11, t20, @@ -1407,7 +1395,7 @@ tintervalleneq(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt == t); } @@ -1421,7 +1409,7 @@ tintervallenne(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt != t); } @@ -1435,7 +1423,7 @@ tintervallenlt(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt < t); } @@ -1449,7 +1437,7 @@ tintervallengt(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt > t); } @@ -1463,7 +1451,7 @@ tintervallenle(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt <= t); } @@ -1477,7 +1465,7 @@ tintervallenge(PG_FUNCTION_ARGS) if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, - TimeIntervalGetDatum(i))); + TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt >= t); } @@ -1487,17 +1475,17 @@ tintervallenge(PG_FUNCTION_ARGS) Datum tintervalct(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimele, - AbsoluteTimeGetDatum(i1->data[0]), - AbsoluteTimeGetDatum(i2->data[0]))) && + AbsoluteTimeGetDatum(i1->data[0]), + AbsoluteTimeGetDatum(i2->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimege, - AbsoluteTimeGetDatum(i1->data[1]), - AbsoluteTimeGetDatum(i2->data[1])))) + AbsoluteTimeGetDatum(i1->data[1]), + AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(true); PG_RETURN_BOOL(false); } @@ -1508,17 +1496,17 @@ tintervalct(PG_FUNCTION_ARGS) Datum tintervalov(PG_FUNCTION_ARGS) { - TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); - TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); + TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimelt, - AbsoluteTimeGetDatum(i1->data[1]), - AbsoluteTimeGetDatum(i2->data[0]))) || + AbsoluteTimeGetDatum(i1->data[1]), + AbsoluteTimeGetDatum(i2->data[0]))) || DatumGetBool(DirectFunctionCall2(abstimegt, - AbsoluteTimeGetDatum(i1->data[0]), - AbsoluteTimeGetDatum(i2->data[1])))) + AbsoluteTimeGetDatum(i1->data[0]), + AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(false); PG_RETURN_BOOL(true); } @@ -1529,7 +1517,7 @@ tintervalov(PG_FUNCTION_ARGS) Datum tintervalstart(PG_FUNCTION_ARGS) { - TimeInterval i = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i = PG_GETARG_TIMEINTERVAL(0); if (i->status == T_INTERVAL_INVAL) PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); @@ -1542,7 +1530,7 @@ tintervalstart(PG_FUNCTION_ARGS) Datum tintervalend(PG_FUNCTION_ARGS) { - TimeInterval i = PG_GETARG_TIMEINTERVAL(0); + TimeInterval i = PG_GETARG_TIMEINTERVAL(0); if (i->status == T_INTERVAL_INVAL) PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); @@ -1835,7 +1823,7 @@ istinterval(char *i_string, } /* get the first date */ *i_start = DatumGetAbsoluteTime(DirectFunctionCall1(nabstimein, - CStringGetDatum(p))); + CStringGetDatum(p))); /* rechange NULL at the end of the first date to a "'" */ *p1 = '"'; p = ++p1; @@ -1863,7 +1851,7 @@ istinterval(char *i_string, } /* get the second date */ *i_end = DatumGetAbsoluteTime(DirectFunctionCall1(nabstimein, - CStringGetDatum(p))); + CStringGetDatum(p))); /* rechange NULL at the end of the first date to a ''' */ *p1 = '"'; p = ++p1; diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 97e0825adf8..56bc534c230 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -3,7 +3,7 @@ * is for IP V4 CIDR notation, but prepared for V6: just * add the necessary bits where the comments indicate. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.28 2000/12/22 18:00:20 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.29 2001/03/22 03:59:52 momjian Exp $ * * Jon Postel RIP 16 Oct 1998 */ @@ -21,7 +21,7 @@ static int32 network_cmp_internal(inet *a1, inet *a2); -static int v4bitncmp(unsigned long a1, unsigned long a2, int bits); +static int v4bitncmp(unsigned long a1, unsigned long a2, int bits); static bool v4addressOK(unsigned long a1, int bits); /* @@ -66,12 +66,12 @@ network_in(char *src, int type) } /* - * Error check: CIDR values must not have any bits set beyond the masklen. - * XXX this code is not IPV6 ready. + * Error check: CIDR values must not have any bits set beyond the + * masklen. XXX this code is not IPV6 ready. */ if (type) { - if (! v4addressOK(ip_v4addr(dst), bits)) + if (!v4addressOK(ip_v4addr(dst), bits)) elog(ERROR, "invalid CIDR value '%s': has bits set to right of mask", src); } @@ -116,7 +116,9 @@ inet_out(PG_FUNCTION_ARGS) if (ip_family(src) == AF_INET) { /* It's an IP V4 address: */ - /* Use inet style for both inet and cidr, since we don't want + + /* + * Use inet style for both inet and cidr, since we don't want * abbreviated CIDR style here. */ dst = inet_net_ntop(AF_INET, &ip_v4addr(src), ip_bits(src), @@ -162,7 +164,7 @@ network_cmp_internal(inet *a1, inet *a2) { if (ip_family(a1) == AF_INET && ip_family(a2) == AF_INET) { - int order; + int order; order = v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), Min(ip_bits(a1), ip_bits(a2))); @@ -260,7 +262,7 @@ network_sub(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) > ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); } else { @@ -280,7 +282,7 @@ network_subeq(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) >= ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a2)) == 0); } else { @@ -300,7 +302,7 @@ network_sup(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) < ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); } else { @@ -320,7 +322,7 @@ network_supeq(PG_FUNCTION_ARGS) if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { PG_RETURN_BOOL(ip_bits(a1) <= ip_bits(a2) - && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); + && v4bitncmp(ip_v4addr(a1), ip_v4addr(a2), ip_bits(a1)) == 0); } else { @@ -456,8 +458,9 @@ network_broadcast(PG_FUNCTION_ARGS) /* It's an IP V4 address: */ unsigned long mask = 0xffffffff; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (ip_bits(ip) < 32) mask >>= ip_bits(ip); @@ -495,8 +498,9 @@ network_network(PG_FUNCTION_ARGS) /* It's an IP V4 address: */ unsigned long mask = 0xffffffff; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (ip_bits(ip) > 0) mask <<= (32 - ip_bits(ip)); @@ -534,8 +538,9 @@ network_netmask(PG_FUNCTION_ARGS) /* It's an IP V4 address: */ unsigned long mask = 0xffffffff; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (ip_bits(ip) > 0) mask <<= (32 - ip_bits(ip)); @@ -568,8 +573,9 @@ v4bitncmp(unsigned long a1, unsigned long a2, int bits) { unsigned long mask; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (bits > 0) mask = (0xFFFFFFFFL << (32 - bits)) & 0xFFFFFFFFL; @@ -592,8 +598,9 @@ v4addressOK(unsigned long a1, int bits) { unsigned long mask; - /* Shifting by 32 or more bits does not yield portable results, - * so don't try it. + /* + * Shifting by 32 or more bits does not yield portable results, so + * don't try it. */ if (bits > 0) mask = (0xFFFFFFFFL << (32 - bits)) & 0xFFFFFFFFL; diff --git a/src/backend/utils/adt/not_in.c b/src/backend/utils/adt/not_in.c index 450cfb2484a..ac596b1f123 100644 --- a/src/backend/utils/adt/not_in.c +++ b/src/backend/utils/adt/not_in.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.25 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.26 2001/03/22 03:59:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ int4notin(PG_FUNCTION_ARGS) /* make a null-terminated copy of text */ strlength = VARSIZE(relation_and_attr) - VARHDRSZ; if (strlength >= sizeof(my_copy)) - strlength = sizeof(my_copy)-1; + strlength = sizeof(my_copy) - 1; memcpy(my_copy, VARDATA(relation_and_attr), strlength); my_copy[strlength] = '\0'; @@ -110,8 +110,10 @@ Datum oidnotin(PG_FUNCTION_ARGS) { Oid the_oid = PG_GETARG_OID(0); + #ifdef NOT_USED text *relation_and_attr = PG_GETARG_TEXT_P(1); + #endif if (the_oid == InvalidOid) diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index d18d3003a08..4a16741bb91 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -5,7 +5,7 @@ * * 1998 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.37 2001/03/14 16:50:37 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.38 2001/03/22 03:59:52 momjian Exp $ * * ---------- */ @@ -192,8 +192,10 @@ Datum numeric_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 typmod = PG_GETARG_INT32(2); NumericVar value; @@ -1865,8 +1867,8 @@ do_numeric_accum(ArrayType *transarray, Numeric newval) NumericGetDatum(newval)); sumX2 = DirectFunctionCall2(numeric_add, sumX2, DirectFunctionCall2(numeric_mul, - NumericGetDatum(newval), - NumericGetDatum(newval))); + NumericGetDatum(newval), + NumericGetDatum(newval))); transdatums[0] = N; transdatums[1] = sumX; @@ -2011,8 +2013,8 @@ numeric_variance(PG_FUNCTION_ARGS) mul_var(&vsumX, &vsumX, &vsumX); /* now vsumX contains sumX * sumX */ mul_var(&vN, &vsumX2, &vsumX2); /* now vsumX2 contains N * sumX2 */ sub_var(&vsumX2, &vsumX, &vsumX2); /* N * sumX2 - sumX * sumX */ - mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ - div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ + mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ + div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ res = make_result(&vsumX); @@ -2078,9 +2080,9 @@ numeric_stddev(PG_FUNCTION_ARGS) mul_var(&vsumX, &vsumX, &vsumX); /* now vsumX contains sumX * sumX */ mul_var(&vN, &vsumX2, &vsumX2); /* now vsumX2 contains N * sumX2 */ sub_var(&vsumX2, &vsumX, &vsumX2); /* N * sumX2 - sumX * sumX */ - mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ - div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ - sqrt_var(&vsumX, &vsumX); /* stddev */ + mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */ + div_var(&vsumX2, &vNminus1, &vsumX); /* variance */ + sqrt_var(&vsumX, &vsumX); /* stddev */ res = make_result(&vsumX); @@ -2096,9 +2098,9 @@ numeric_stddev(PG_FUNCTION_ARGS) /* * SUM transition functions for integer datatypes. * - * We use a Numeric accumulator to avoid overflow. Because SQL92 defines + * We use a Numeric accumulator to avoid overflow. Because SQL92 defines * the SUM() of no values to be NULL, not zero, the initial condition of - * the transition data value needs to be NULL. This means we can't rely + * the transition data value needs to be NULL. This means we can't rely * on ExecAgg to automatically insert the first non-null data value into * the transition data: it doesn't know how to do the type conversion. * The upshot is that these routines have to be marked non-strict and @@ -3563,7 +3565,7 @@ exp_var(NumericVar *arg, NumericVar *result) set_var_from_var(&const_one, &ifac); set_var_from_var(&const_one, &ni); - for (i = 2; ; i++) + for (i = 2;; i++) { add_var(&ni, &const_one, &ni); mul_var(&xpow, &x, &xpow); @@ -3647,7 +3649,7 @@ ln_var(NumericVar *arg, NumericVar *result) set_var_from_var(&const_one, &ni); - for (i = 2; ; i++) + for (i = 2;; i++) { add_var(&ni, &const_two, &ni); mul_var(&xx, &x, &xx); @@ -3820,6 +3822,7 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) i1, i2; int carry = 0; + /* copy these values into local vars for speed in inner loop */ int var1ndigits = var1->ndigits; int var2ndigits = var2->ndigits; @@ -3906,6 +3909,7 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) i1, i2; int borrow = 0; + /* copy these values into local vars for speed in inner loop */ int var1ndigits = var1->ndigits; int var2ndigits = var2->ndigits; diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c index 11e779d45d6..92af2ab56cf 100644 --- a/src/backend/utils/adt/numutils.c +++ b/src/backend/utils/adt/numutils.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.44 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.45 2001/03/22 03:59:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,11 +63,11 @@ pg_atoi(char *s, int size, int c) l = (long) 0; else l = strtol(s, &badp, 10); + /* - * strtol() normally only sets ERANGE. On some systems it also - * may set EINVAL, which simply means it couldn't parse the - * input string. This is handled by the second "if" consistent - * across platforms. + * strtol() normally only sets ERANGE. On some systems it also may + * set EINVAL, which simply means it couldn't parse the input string. + * This is handled by the second "if" consistent across platforms. */ if (errno && errno != EINVAL) elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c index 0cb4ea1a0a2..91dbf6c54eb 100644 --- a/src/backend/utils/adt/oid.c +++ b/src/backend/utils/adt/oid.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.44 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.45 2001/03/22 03:59:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,11 +36,11 @@ oidin_subr(const char *funcname, const char *s, char **endloc) cvt = strtoul(s, &endptr, 10); /* - * strtoul() normally only sets ERANGE. On some systems it also - * may set EINVAL, which simply means it couldn't parse the - * input string. This is handled by the second "if" consistent - * across platforms. Note that for historical reasons we accept - * an empty string as meaning 0. + * strtoul() normally only sets ERANGE. On some systems it also may + * set EINVAL, which simply means it couldn't parse the input string. + * This is handled by the second "if" consistent across platforms. + * Note that for historical reasons we accept an empty string as + * meaning 0. */ if (errno && errno != EINVAL) elog(ERROR, "%s: error reading \"%s\": %m", @@ -67,21 +67,20 @@ oidin_subr(const char *funcname, const char *s, char **endloc) result = (Oid) cvt; /* - * Cope with possibility that unsigned long is wider than Oid, - * in which case strtoul will not raise an error for some values - * that are out of the range of Oid. + * Cope with possibility that unsigned long is wider than Oid, in + * which case strtoul will not raise an error for some values that are + * out of the range of Oid. * - * For backwards compatibility, we want to accept inputs that - * are given with a minus sign, so allow the input value if it - * matches after either signed or unsigned extension to long. + * For backwards compatibility, we want to accept inputs that are given + * with a minus sign, so allow the input value if it matches after + * either signed or unsigned extension to long. * - * To ensure consistent results on 32-bit and 64-bit platforms, - * make sure the error message is the same as if strtoul() had - * returned ERANGE. + * To ensure consistent results on 32-bit and 64-bit platforms, make sure + * the error message is the same as if strtoul() had returned ERANGE. */ #if OID_MAX != ULONG_MAX if (cvt != (unsigned long) result && - cvt != (unsigned long) ((int) result)) + cvt != (unsigned long) ((int) result)) elog(ERROR, "%s: error reading \"%s\": %s", funcname, s, strerror(ERANGE)); #endif @@ -235,8 +234,8 @@ oidgt(PG_FUNCTION_ARGS) Datum oidvectoreq(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(Oid)) == 0); } @@ -244,8 +243,8 @@ oidvectoreq(PG_FUNCTION_ARGS) Datum oidvectorne(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(Oid)) != 0); } @@ -253,8 +252,8 @@ oidvectorne(PG_FUNCTION_ARGS) Datum oidvectorlt(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) @@ -266,8 +265,8 @@ oidvectorlt(PG_FUNCTION_ARGS) Datum oidvectorle(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) @@ -279,8 +278,8 @@ oidvectorle(PG_FUNCTION_ARGS) Datum oidvectorge(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) @@ -292,8 +291,8 @@ oidvectorge(PG_FUNCTION_ARGS) Datum oidvectorgt(PG_FUNCTION_ARGS) { - Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); - Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); + Oid *arg1 = (Oid *) PG_GETARG_POINTER(0); + Oid *arg2 = (Oid *) PG_GETARG_POINTER(1); int i; for (i = 0; i < INDEX_MAX_KEYS; i++) diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index 5a83c56687f..b91230b1f0a 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -1,7 +1,7 @@ /* * Edmund Mergl <E.Mergl@bawue.de> * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.30 2000/12/07 23:22:56 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.31 2001/03/22 03:59:52 momjian Exp $ * */ @@ -596,8 +596,8 @@ ascii(PG_FUNCTION_ARGS) Datum chr(PG_FUNCTION_ARGS) { - int32 cvalue = PG_GETARG_INT32(0); - text *result; + int32 cvalue = PG_GETARG_INT32(0); + text *result; result = (text *) palloc(VARHDRSZ + 1); VARATT_SIZEP(result) = VARHDRSZ + 1; @@ -616,20 +616,20 @@ chr(PG_FUNCTION_ARGS) * * Purpose: * - * Repeat string by val. + * Repeat string by val. * ********************************************************************/ Datum repeat(PG_FUNCTION_ARGS) { - text *string = PG_GETARG_TEXT_P(0); - int32 count = PG_GETARG_INT32(1); - text *result; - int slen, - tlen; - int i; - char *cp; + text *string = PG_GETARG_TEXT_P(0); + int32 count = PG_GETARG_INT32(1); + text *result; + int slen, + tlen; + int i; + char *cp; if (count < 0) count = 0; diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 6d30a53edcb..faa81cd09af 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -4,7 +4,7 @@ * The PostgreSQL locale utils. * * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.8 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.9 2001/03/22 03:59:52 momjian Exp $ * * Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group * @@ -68,7 +68,7 @@ PGLC_debug_lc(PG_LocaleCategories * lc) lc->lc_collate, lc->lc_monetary #ifdef LC_MESSAGES - , lc->lc_messages + ,lc->lc_messages #endif ); } @@ -116,7 +116,7 @@ PGLC_setlocale(PG_LocaleCategories * lc) /*------ * Return the POSIX lconv struct (contains number/money formatting information) - * with locale information for all categories. Note that returned lconv + * with locale information for all categories. Note that returned lconv * does not depend on currently active category settings, but on external * environment variables for locale. * diff --git a/src/backend/utils/adt/pg_lzcompress.c b/src/backend/utils/adt/pg_lzcompress.c index fc93031b521..f548775ad2f 100644 --- a/src/backend/utils/adt/pg_lzcompress.c +++ b/src/backend/utils/adt/pg_lzcompress.c @@ -1,7 +1,7 @@ /* ---------- * pg_lzcompress.c - * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.9 2000/10/03 03:11:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.10 2001/03/22 03:59:52 momjian Exp $ * * This is an implementation of LZ compression for PostgreSQL. * It uses a simple history table and generates 2-3 byte tags @@ -120,7 +120,7 @@ * 8 times the size of the input!). * * The compressor creates a table for 8192 lists of positions. - * For each input position (except the last 3), a hash key is + * For each input position (except the last 3), a hash key is * built from the 4 next input bytes and the posiiton remembered * in the appropriate list. Thus, the table points to linked * lists of likely to be at least in the first 4 characters @@ -152,7 +152,7 @@ * * - a match >= good_match is found * - there are no more history entries to look at - * - the next history entry is already too far back + * - the next history entry is already too far back * to be coded into a tag. * * Finally the match algorithm checks that at least a match @@ -286,18 +286,18 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE]; #define pglz_hist_add(_hs,_he,_hn,_s,_e) { \ int __hindex = pglz_hist_idx((_s),(_e)); \ if ((_he)[(_hn)].prev == NULL) { \ - (_hs)[__hindex] = (_he)[(_hn)].next; \ + (_hs)[__hindex] = (_he)[(_hn)].next; \ } else { \ - (_he)[(_hn)].prev->next = (_he)[(_hn)].next; \ + (_he)[(_hn)].prev->next = (_he)[(_hn)].next; \ } \ if ((_he)[(_hn)].next != NULL) { \ - (_he)[(_hn)].next->prev = (_he)[(_hn)].prev; \ + (_he)[(_hn)].next->prev = (_he)[(_hn)].prev; \ } \ (_he)[(_hn)].next = (_hs)[__hindex]; \ (_he)[(_hn)].prev = NULL; \ (_he)[(_hn)].pos = (_s); \ if ((_hs)[__hindex] != NULL) { \ - (_hs)[__hindex]->prev = &((_he)[(_hn)]); \ + (_hs)[__hindex]->prev = &((_he)[(_hn)]); \ } \ (_hs)[__hindex] = &((_he)[(_hn)]); \ if (++(_hn) >= PGLZ_HISTORY_SIZE) { \ @@ -476,7 +476,7 @@ pglz_find_match(PGLZ_HistEntry **hstart, char *input, char *end, int pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strategy) { - int hist_next = 0; + int hist_next = 0; unsigned char *bp = ((unsigned char *) dest) + sizeof(PGLZ_Header); unsigned char *bstart = bp; diff --git a/src/backend/utils/adt/quote.c b/src/backend/utils/adt/quote.c index 02aaac74134..10999150a21 100644 --- a/src/backend/utils/adt/quote.c +++ b/src/backend/utils/adt/quote.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/quote.c,v 1.3 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/quote.c,v 1.4 2001/03/22 03:59:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -35,12 +35,10 @@ quote_ident(PG_FUNCTION_ARGS) text *result; if (quote_ident_required(t)) - { - result = do_quote_ident(t); - } + result = do_quote_ident(t); else { - result = (text *)palloc(VARSIZE(t)); + result = (text *) palloc(VARSIZE(t)); memcpy(result, t, VARSIZE(t)); } @@ -79,23 +77,26 @@ quote_literal(PG_FUNCTION_ARGS) static bool quote_ident_required(text *iptr) { - char *cp; - char *ep; + char *cp; + char *ep; cp = VARDATA(iptr); - ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; + ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; if (cp >= ep) return true; - if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) + if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) return true; - while((++cp) < ep) + while ((++cp) < ep) { - if (*cp >= 'a' && *cp <= 'z') continue; - if (*cp >= '0' && *cp <= '9') continue; - if (*cp == '_') continue; + if (*cp >= 'a' && *cp <= 'z') + continue; + if (*cp >= '0' && *cp <= '9') + continue; + if (*cp == '_') + continue; return true; } @@ -107,29 +108,29 @@ quote_ident_required(text *iptr) static text * do_quote_ident(text *iptr) { - text *result; - char *cp1; - char *cp2; - int len; + text *result; + char *cp1; + char *cp2; + int len; - len = VARSIZE(iptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(iptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(iptr); cp2 = VARDATA(result); *cp2++ = '"'; - while(len-- > 0) + while (len-- > 0) { - if (*cp1 == '"') + if (*cp1 == '"') *cp2++ = '"'; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; } *cp2++ = '"'; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } @@ -138,29 +139,29 @@ do_quote_ident(text *iptr) static text * do_quote_literal(text *lptr) { - text *result; - char *cp1; - char *cp2; - int len; + text *result; + char *cp1; + char *cp2; + int len; - len = VARSIZE(lptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(lptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(lptr); cp2 = VARDATA(result); *cp2++ = '\''; - while(len-- > 0) + while (len-- > 0) { - if (*cp1 == '\'') + if (*cp1 == '\'') *cp2++ = '\''; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; } *cp2++ = '\''; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } @@ -171,28 +172,31 @@ do_quote_literal(text *lptr) static bool quote_ident_required(text *iptr) { - char *cp; - char *ep; + char *cp; + char *ep; cp = VARDATA(iptr); - ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; + ep = VARDATA(iptr) + VARSIZE(iptr) - VARHDRSZ; if (cp >= ep) return true; - if(pg_mblen(cp) != 1) + if (pg_mblen(cp) != 1) return true; - if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) + if (!(*cp == '_' || (*cp >= 'a' && *cp <= 'z'))) return true; - while((++cp) < ep) + while ((++cp) < ep) { if (pg_mblen(cp) != 1) return true; - if (*cp >= 'a' && *cp <= 'z') continue; - if (*cp >= '0' && *cp <= '9') continue; - if (*cp == '_') continue; + if (*cp >= 'a' && *cp <= 'z') + continue; + if (*cp >= '0' && *cp <= '9') + continue; + if (*cp == '_') + continue; return true; } @@ -204,41 +208,41 @@ quote_ident_required(text *iptr) static text * do_quote_ident(text *iptr) { - text *result; - char *cp1; - char *cp2; - int len; - int wl; + text *result; + char *cp1; + char *cp2; + int len; + int wl; - len = VARSIZE(iptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(iptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(iptr); cp2 = VARDATA(result); *cp2++ = '"'; - while(len > 0) + while (len > 0) { if ((wl = pg_mblen(cp1)) != 1) { len -= wl; - while(wl-- > 0) + while (wl-- > 0) *cp2++ = *cp1++; continue; } - if (*cp1 == '"') + if (*cp1 == '"') *cp2++ = '"'; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; len--; } *cp2++ = '"'; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } @@ -247,45 +251,43 @@ do_quote_ident(text *iptr) static text * do_quote_literal(text *lptr) { - text *result; - char *cp1; - char *cp2; - int len; - int wl; + text *result; + char *cp1; + char *cp2; + int len; + int wl; - len = VARSIZE(lptr) - VARHDRSZ; - result = (text *)palloc(len * 2 + VARHDRSZ + 2); + len = VARSIZE(lptr) - VARHDRSZ; + result = (text *) palloc(len * 2 + VARHDRSZ + 2); cp1 = VARDATA(lptr); cp2 = VARDATA(result); *cp2++ = '\''; - while(len > 0) + while (len > 0) { if ((wl = pg_mblen(cp1)) != 1) { len -= wl; - while(wl-- > 0) + while (wl-- > 0) *cp2++ = *cp1++; continue; } - if (*cp1 == '\'') + if (*cp1 == '\'') *cp2++ = '\''; - if (*cp1 == '\\') + if (*cp1 == '\\') *cp2++ = '\\'; - *cp2++ = *cp1++; + *cp2++ = *cp1++; len--; } *cp2++ = '\''; - VARATT_SIZEP(result) = cp2 - ((char *)result); + VARATT_SIZEP(result) = cp2 - ((char *) result); return result; } #endif - - diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index b55cb3b42e7..146ae742636 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.35 2001/03/19 22:27:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.36 2001/03/22 03:59:53 momjian Exp $ * * Alistair Crooks added the code for the regex caching * agc - cached the regular expressions used - there's a good chance @@ -121,6 +121,7 @@ RE_compile_and_execute(text *text_re, char *text, int cflags) regcomp_result = pg95_regcomp(&rev[oldest].cre_re, re, cflags); if (regcomp_result == 0) { + /* * use malloc/free for the cre_s field because the storage has to * persist across transactions @@ -197,10 +198,10 @@ nameregexne(PG_FUNCTION_ARGS) Name n = PG_GETARG_NAME(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(NameStr(*n), - p, - strlen(NameStr(*n)), - REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(NameStr(*n), + p, + strlen(NameStr(*n)), + REG_EXTENDED)); } Datum @@ -221,15 +222,15 @@ textregexne(PG_FUNCTION_ARGS) text *s = PG_GETARG_TEXT_P(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(VARDATA(s), - p, - VARSIZE(s) - VARHDRSZ, - REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(VARDATA(s), + p, + VARSIZE(s) - VARHDRSZ, + REG_EXTENDED)); } /* - * routines that use the regexp stuff, but ignore the case. + * routines that use the regexp stuff, but ignore the case. * for this, we use the REG_ICASE flag to pg95_regcomp */ @@ -252,10 +253,10 @@ texticregexne(PG_FUNCTION_ARGS) text *s = PG_GETARG_TEXT_P(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(VARDATA(s), - p, - VARSIZE(s) - VARHDRSZ, - REG_ICASE | REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(VARDATA(s), + p, + VARSIZE(s) - VARHDRSZ, + REG_ICASE | REG_EXTENDED)); } Datum @@ -276,8 +277,8 @@ nameicregexne(PG_FUNCTION_ARGS) Name n = PG_GETARG_NAME(0); text *p = PG_GETARG_TEXT_P(1); - PG_RETURN_BOOL(! fixedlen_regexeq(NameStr(*n), - p, - strlen(NameStr(*n)), - REG_ICASE | REG_EXTENDED)); + PG_RETURN_BOOL(!fixedlen_regexeq(NameStr(*n), + p, + strlen(NameStr(*n)), + REG_ICASE | REG_EXTENDED)); } diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 6a772ee1b71..1f3abde5f11 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.60 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.61 2001/03/22 03:59:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -58,7 +58,7 @@ regprocin(PG_FUNCTION_ARGS) result = (RegProcedure) GetSysCacheOid(PROCOID, DirectFunctionCall1(oidin, - CStringGetDatum(pro_name_or_oid)), + CStringGetDatum(pro_name_or_oid)), 0, 0, 0); if (!RegProcedureIsValid(result)) elog(ERROR, "No procedure with oid %s", pro_name_or_oid); diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 94d9b7313a1..db7f67ec601 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -9,7 +9,7 @@ * the backend does. This works because the hashtable structures * themselves are allocated by dynahash.c in its permanent DynaHashCxt, * and the parse/plan node trees they point to are copied into - * TopMemoryContext using SPI_saveplan(). This is pretty ugly, since there + * TopMemoryContext using SPI_saveplan(). This is pretty ugly, since there * is no way to free a no-longer-needed plan tree, but then again we don't * yet have any bookkeeping that would allow us to detect that a plan isn't * needed anymore. Improve it someday. @@ -18,7 +18,7 @@ * Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group * Copyright 1999 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.21 2001/02/15 21:57:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.22 2001/03/22 03:59:53 momjian Exp $ * * ---------- */ @@ -535,7 +535,7 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) char del_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; - Oid save_uid; + Oid save_uid; save_uid = GetUserId(); @@ -750,7 +750,7 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) char upd_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; - Oid save_uid; + Oid save_uid; save_uid = GetUserId(); @@ -1611,7 +1611,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) char upd_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; - Oid save_uid; + Oid save_uid; save_uid = GetUserId(); diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 2dd460a442b..c6db1c5b30f 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.73 2001/02/21 18:53:47 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.74 2001/03/22 03:59:53 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -82,7 +82,7 @@ typedef struct List *rtable; /* List of RangeTblEntry nodes */ List *namespace; /* List of joinlist items (RangeTblRef and * JoinExpr nodes) */ -} deparse_namespace; +} deparse_namespace; /* ---------- @@ -118,15 +118,15 @@ static void get_delete_query_def(Query *query, deparse_context *context); static void get_utility_query_def(Query *query, deparse_context *context); static void get_basic_select_query(Query *query, deparse_context *context); static void get_setop_query(Node *setOp, Query *query, - deparse_context *context, bool toplevel); + deparse_context *context, bool toplevel); static bool simple_distinct(List *distinctClause, List *targetList); static void get_names_for_var(Var *var, deparse_context *context, - char **refname, char **attname); + char **refname, char **attname); static bool get_alias_for_case(CaseExpr *caseexpr, deparse_context *context, - char **refname, char **attname); + char **refname, char **attname); static bool find_alias_in_namespace(Node *nsnode, Node *expr, - List *rangetable, int levelsup, - char **refname, char **attname); + List *rangetable, int levelsup, + char **refname, char **attname); static bool phony_equal(Node *expr1, Node *expr2, int levelsup); static void get_rule_expr(Node *node, deparse_context *context); static void get_func_expr(Expr *expr, deparse_context *context); @@ -135,7 +135,7 @@ static void get_const_expr(Const *constval, deparse_context *context); static void get_sublink_expr(Node *node, deparse_context *context); static void get_from_clause(Query *query, deparse_context *context); static void get_from_clause_item(Node *jtnode, Query *query, - deparse_context *context); + deparse_context *context); static bool tleIsArrayAssign(TargetEntry *tle); static char *quote_identifier(char *ident); static char *get_relation_name(Oid relid); @@ -478,7 +478,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS) * ---------- */ appendStringInfo(&keybuf, "%s", - quote_identifier(get_relid_attribute_name(idxrec->indrelid, + quote_identifier(get_relid_attribute_name(idxrec->indrelid, idxrec->indkey[keyno]))); /* ---------- @@ -767,8 +767,8 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc) quote_identifier(get_relation_name(ev_class))); if (ev_attr > 0) appendStringInfo(buf, ".%s", - quote_identifier(get_relid_attribute_name(ev_class, - ev_attr))); + quote_identifier(get_relid_attribute_name(ev_class, + ev_attr))); /* If the rule has an event qualification, add it */ if (ev_qual == NULL) @@ -1043,9 +1043,7 @@ get_basic_select_query(Query *query, deparse_context *context) if (query->distinctClause != NIL) { if (simple_distinct(query->distinctClause, query->targetList)) - { appendStringInfo(buf, " DISTINCT"); - } else { appendStringInfo(buf, " DISTINCT ON ("); @@ -1146,7 +1144,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, { RangeTblRef *rtr = (RangeTblRef *) setOp; RangeTblEntry *rte = rt_fetch(rtr->rtindex, query->rtable); - Query *subquery = rte->subquery; + Query *subquery = rte->subquery; Assert(subquery != NULL); get_query_def(subquery, buf, context->namespaces); @@ -1155,10 +1153,11 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, { SetOperationStmt *op = (SetOperationStmt *) setOp; - /* Must suppress parens at top level of a setop tree because - * of grammar limitations... + /* + * Must suppress parens at top level of a setop tree because of + * grammar limitations... */ - if (! toplevel) + if (!toplevel) appendStringInfo(buf, "("); get_setop_query(op->larg, query, context, false); switch (op->op) @@ -1179,7 +1178,7 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context, if (op->all) appendStringInfo(buf, "ALL "); get_setop_query(op->rarg, query, context, false); - if (! toplevel) + if (!toplevel) appendStringInfo(buf, ")"); } else @@ -1201,7 +1200,7 @@ simple_distinct(List *distinctClause, List *targetList) { TargetEntry *tle = (TargetEntry *) lfirst(targetList); - if (! tle->resdom->resjunk) + if (!tle->resdom->resjunk) { if (distinctClause == NIL) return false; @@ -1288,9 +1287,7 @@ get_insert_query_def(Query *query, deparse_context *context) appendStringInfoChar(buf, ')'); } else - { get_query_def(select_rte->subquery, buf, NIL); - } } @@ -1326,12 +1323,13 @@ get_update_query_def(Query *query, deparse_context *context) appendStringInfo(buf, sep); sep = ", "; + /* - * If the update expression is an array assignment, we mustn't - * put out "attname =" here; it will come out of the display - * of the ArrayRef node instead. + * If the update expression is an array assignment, we mustn't put + * out "attname =" here; it will come out of the display of the + * ArrayRef node instead. */ - if (! tleIsArrayAssign(tle)) + if (!tleIsArrayAssign(tle)) appendStringInfo(buf, "%s = ", quote_identifier(tle->resdom->resname)); get_tle_expr(tle, context); @@ -1389,6 +1387,7 @@ get_utility_query_def(Query *query, deparse_context *context) if (query->utilityStmt && IsA(query->utilityStmt, NotifyStmt)) { NotifyStmt *stmt = (NotifyStmt *) query->utilityStmt; + appendStringInfo(buf, "NOTIFY %s", quote_identifier(stmt->relname)); } else @@ -1428,8 +1427,8 @@ get_names_for_var(Var *var, deparse_context *context, /* * Otherwise, fall back on the rangetable entry. This should happen - * only for uses of special RTEs like *NEW* and *OLD*, which won't - * get placed in our namespace. + * only for uses of special RTEs like *NEW* and *OLD*, which won't get + * placed in our namespace. */ rte = rt_fetch(var->varno, dpns->rtable); *refname = rte->eref->relname; @@ -1448,9 +1447,9 @@ get_alias_for_case(CaseExpr *caseexpr, deparse_context *context, int sup; /* - * This could be done more efficiently if we first groveled through the - * CASE to find varlevelsup values, but it's probably not worth the - * trouble. All this code will go away someday anyway ... + * This could be done more efficiently if we first groveled through + * the CASE to find varlevelsup values, but it's probably not worth + * the trouble. All this code will go away someday anyway ... */ sup = 0; @@ -1525,6 +1524,7 @@ find_alias_in_namespace(Node *nsnode, Node *expr, } nlist = lnext(nlist); } + /* * Tables within an aliased join are invisible from outside * the join, according to the scope rules of SQL92 (the join @@ -1579,8 +1579,8 @@ phony_equal(Node *expr1, Node *expr2, int levelsup) return false; if (IsA(expr1, Var)) { - Var *a = (Var *) expr1; - Var *b = (Var *) expr2; + Var *a = (Var *) expr1; + Var *b = (Var *) expr2; if (a->varno != b->varno) return false; @@ -1600,8 +1600,8 @@ phony_equal(Node *expr1, Node *expr2, int levelsup) } if (IsA(expr1, CaseExpr)) { - CaseExpr *a = (CaseExpr *) expr1; - CaseExpr *b = (CaseExpr *) expr2; + CaseExpr *a = (CaseExpr *) expr1; + CaseExpr *b = (CaseExpr *) expr2; if (a->casetype != b->casetype) return false; @@ -1615,8 +1615,8 @@ phony_equal(Node *expr1, Node *expr2, int levelsup) } if (IsA(expr1, CaseWhen)) { - CaseWhen *a = (CaseWhen *) expr1; - CaseWhen *b = (CaseWhen *) expr2; + CaseWhen *a = (CaseWhen *) expr1; + CaseWhen *b = (CaseWhen *) expr2; if (!phony_equal(a->expr, b->expr, levelsup)) return false; @@ -1840,9 +1840,10 @@ get_rule_expr(Node *node, deparse_context *context) /* * If we are doing UPDATE array[n] = expr, we need to - * suppress any prefix on the array name. Currently, - * that is the only context in which we will see a non-null - * refassgnexpr --- but someday a smarter test may be needed. + * suppress any prefix on the array name. Currently, that + * is the only context in which we will see a non-null + * refassgnexpr --- but someday a smarter test may be + * needed. */ if (aref->refassgnexpr) context->varprefix = false; @@ -1880,7 +1881,7 @@ get_rule_expr(Node *node, deparse_context *context) /* we do NOT parenthesize the arg expression, for now */ get_rule_expr(fselect->arg, context); typetup = SearchSysCache(TYPEOID, - ObjectIdGetDatum(exprType(fselect->arg)), + ObjectIdGetDatum(exprType(fselect->arg)), 0, 0, 0); if (!HeapTupleIsValid(typetup)) elog(ERROR, "cache lookup of type %u failed", @@ -2163,9 +2164,9 @@ get_const_expr(Const *constval, deparse_context *context) } extval = DatumGetCString(OidFunctionCall3(typeStruct->typoutput, - constval->constvalue, - ObjectIdGetDatum(typeStruct->typelem), - Int32GetDatum(-1))); + constval->constvalue, + ObjectIdGetDatum(typeStruct->typelem), + Int32GetDatum(-1))); switch (constval->consttype) { @@ -2317,16 +2318,16 @@ get_from_clause(Query *query, deparse_context *context) /* * We use the query's jointree as a guide to what to print. However, - * we must ignore auto-added RTEs that are marked not inFromCl. - * (These can only appear at the top level of the jointree, so it's - * sufficient to check here.) - * Also ignore the rule pseudo-RTEs for NEW and OLD. + * we must ignore auto-added RTEs that are marked not inFromCl. (These + * can only appear at the top level of the jointree, so it's + * sufficient to check here.) Also ignore the rule pseudo-RTEs for NEW + * and OLD. */ sep = " FROM "; foreach(l, query->jointree->fromlist) { - Node *jtnode = (Node *) lfirst(l); + Node *jtnode = (Node *) lfirst(l); if (IsA(jtnode, RangeTblRef)) { @@ -2396,7 +2397,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (col != rte->alias->attrs) appendStringInfo(buf, ", "); appendStringInfo(buf, "%s", - quote_identifier(strVal(lfirst(col)))); + quote_identifier(strVal(lfirst(col)))); } appendStringInfoChar(buf, ')'); } @@ -2435,7 +2436,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) (int) j->jointype); } get_from_clause_item(j->rarg, query, context); - if (! j->isNatural) + if (!j->isNatural) { if (j->using) { @@ -2447,7 +2448,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (col != j->using) appendStringInfo(buf, ", "); appendStringInfo(buf, "%s", - quote_identifier(strVal(lfirst(col)))); + quote_identifier(strVal(lfirst(col)))); } appendStringInfoChar(buf, ')'); } @@ -2475,7 +2476,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (col != j->alias->attrs) appendStringInfo(buf, ", "); appendStringInfo(buf, "%s", - quote_identifier(strVal(lfirst(col)))); + quote_identifier(strVal(lfirst(col)))); } appendStringInfoChar(buf, ')'); } @@ -2503,6 +2504,7 @@ tleIsArrayAssign(TargetEntry *tle) aref = (ArrayRef *) tle->expr; if (aref->refassgnexpr == NULL) return false; + /* * Currently, it should only be possible to see non-null refassgnexpr * if we are indeed looking at an "UPDATE array[n] = expr" situation. @@ -2563,8 +2565,8 @@ quote_identifier(char *ident) * but the parser doesn't provide any easy way to test for whether * an identifier is safe or not... so be safe not sorry. * - * Note: ScanKeywordLookup() does case-insensitive comparison, - * but that's fine, since we already know we have all-lower-case. + * Note: ScanKeywordLookup() does case-insensitive comparison, but + * that's fine, since we already know we have all-lower-case. */ if (ScanKeywordLookup(ident) != NULL) safe = false; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 72be0f04722..b7af8b9ca5e 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.85 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.86 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -61,18 +61,18 @@ #define NOT_MOST_COMMON_RATIO 0.1 static bool convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, - Datum lobound, Datum hibound, Oid boundstypid, - double *scaledlobound, double *scaledhibound); + Datum lobound, Datum hibound, Oid boundstypid, + double *scaledlobound, double *scaledhibound); static double convert_numeric_to_scalar(Datum value, Oid typid); static void convert_string_to_scalar(unsigned char *value, - double *scaledvalue, - unsigned char *lobound, - double *scaledlobound, - unsigned char *hibound, - double *scaledhibound); + double *scaledvalue, + unsigned char *lobound, + double *scaledlobound, + unsigned char *hibound, + double *scaledhibound); static double convert_one_string_to_scalar(unsigned char *value, - int rangelo, int rangehi); -static unsigned char * convert_string_datum(Datum value, Oid typid); + int rangelo, int rangehi); +static unsigned char *convert_string_datum(Datum value, Oid typid); static double convert_timevalue_to_scalar(Datum value, Oid typid); static void getattproperties(Oid relid, AttrNumber attnum, Oid *typid, @@ -87,9 +87,9 @@ static bool getattstatistics(Oid relid, AttrNumber attnum, Datum *loval, Datum *hival); static Selectivity prefix_selectivity(char *prefix, - Oid relid, - AttrNumber attno, - Oid datatype); + Oid relid, + AttrNumber attno, + Oid datatype); static Selectivity pattern_selectivity(char *patt, Pattern_Type ptype); static bool string_lessthan(const char *str1, const char *str2, Oid datatype); @@ -102,7 +102,7 @@ static Datum string_to_datum(const char *str, Oid datatype); * * Note: this routine is also used to estimate selectivity for some * operators that are not "=" but have comparable selectivity behavior, - * such as "~=" (geometric approximate-match). Even for "=", we must + * such as "~=" (geometric approximate-match). Even for "=", we must * keep in mind that the left and right datatypes may differ, so the type * of the given constant "value" may be different from the type of the * attribute. @@ -165,7 +165,7 @@ eqsel(PG_FUNCTION_ARGS) else mostcommon = DatumGetBool(OidFunctionCall2(eqproc, value, - commonval)); + commonval)); if (mostcommon) { @@ -264,15 +264,15 @@ neqsel(PG_FUNCTION_ARGS) float8 result; /* - * We want 1 - eqsel() where the equality operator is the one associated - * with this != operator, that is, its negator. + * We want 1 - eqsel() where the equality operator is the one + * associated with this != operator, that is, its negator. */ eqopid = get_negator(opid); if (eqopid) { result = DatumGetFloat8(DirectFunctionCall5(eqsel, - ObjectIdGetDatum(eqopid), - ObjectIdGetDatum(relid), + ObjectIdGetDatum(eqopid), + ObjectIdGetDatum(relid), Int16GetDatum(attno), value, Int32GetDatum(flag))); @@ -432,16 +432,16 @@ scalargtsel(PG_FUNCTION_ARGS) /* * Compute selectivity of "<", then invert --- but only if we were - * able to produce a non-default estimate. Note that we get the - * negator which strictly speaking means we are looking at "<=" - * for ">" or "<" for ">=". We assume this won't matter. + * able to produce a non-default estimate. Note that we get the + * negator which strictly speaking means we are looking at "<=" for + * ">" or "<" for ">=". We assume this won't matter. */ ltopid = get_negator(opid); if (ltopid) { result = DatumGetFloat8(DirectFunctionCall5(scalarltsel, - ObjectIdGetDatum(ltopid), - ObjectIdGetDatum(relid), + ObjectIdGetDatum(ltopid), + ObjectIdGetDatum(relid), Int16GetDatum(attno), value, Int32GetDatum(flag))); @@ -506,23 +506,28 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) if (pstatus == Pattern_Prefix_Exact) { - /* Pattern specifies an exact match, so pretend operator is '=' */ - Oid eqopr = find_operator("=", ltype); - Datum eqcon; + + /* + * Pattern specifies an exact match, so pretend operator is + * '=' + */ + Oid eqopr = find_operator("=", ltype); + Datum eqcon; if (eqopr == InvalidOid) elog(ERROR, "patternsel: no = operator for type %u", ltype); eqcon = string_to_datum(prefix, ltype); result = DatumGetFloat8(DirectFunctionCall5(eqsel, - ObjectIdGetDatum(eqopr), - ObjectIdGetDatum(relid), - Int16GetDatum(attno), - eqcon, - Int32GetDatum(SEL_CONSTANT|SEL_RIGHT))); + ObjectIdGetDatum(eqopr), + ObjectIdGetDatum(relid), + Int16GetDatum(attno), + eqcon, + Int32GetDatum(SEL_CONSTANT | SEL_RIGHT))); pfree(DatumGetPointer(eqcon)); } else { + /* * Not exact-match pattern. We estimate selectivity of the * fixed prefix and remainder of pattern separately, then @@ -648,6 +653,7 @@ eqjoinsel(PG_FUNCTION_ARGS) { #ifdef NOT_USED /* see neqjoinsel() before removing me! */ Oid opid = PG_GETARG_OID(0); + #endif Oid relid1 = PG_GETARG_OID(1); AttrNumber attno1 = PG_GETARG_INT16(2); @@ -701,8 +707,8 @@ neqjoinsel(PG_FUNCTION_ARGS) /* * XXX we skip looking up the negator operator here because we know - * eqjoinsel() won't look at it anyway. If eqjoinsel() ever does look, - * this routine will need to look more like neqsel() does. + * eqjoinsel() won't look at it anyway. If eqjoinsel() ever does + * look, this routine will need to look more like neqsel() does. */ result = DatumGetFloat8(eqjoinsel(fcinfo)); result = 1.0 - result; @@ -845,48 +851,48 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue, switch (valuetypid) { - /* - * Built-in numeric types - */ - case BOOLOID: - case INT2OID: - case INT4OID: - case INT8OID: - case FLOAT4OID: - case FLOAT8OID: - case NUMERICOID: - case OIDOID: - case REGPROCOID: + /* + * Built-in numeric types + */ + case BOOLOID: + case INT2OID: + case INT4OID: + case INT8OID: + case FLOAT4OID: + case FLOAT8OID: + case NUMERICOID: + case OIDOID: + case REGPROCOID: *scaledvalue = convert_numeric_to_scalar(value, valuetypid); *scaledlobound = convert_numeric_to_scalar(lobound, boundstypid); *scaledhibound = convert_numeric_to_scalar(hibound, boundstypid); return true; - /* - * Built-in string types - */ + /* + * Built-in string types + */ case CHAROID: case BPCHAROID: case VARCHAROID: case TEXTOID: case NAMEOID: - { - unsigned char *valstr = convert_string_datum(value, valuetypid); - unsigned char *lostr = convert_string_datum(lobound, boundstypid); - unsigned char *histr = convert_string_datum(hibound, boundstypid); - - convert_string_to_scalar(valstr, scaledvalue, - lostr, scaledlobound, - histr, scaledhibound); - pfree(valstr); - pfree(lostr); - pfree(histr); - return true; - } + { + unsigned char *valstr = convert_string_datum(value, valuetypid); + unsigned char *lostr = convert_string_datum(lobound, boundstypid); + unsigned char *histr = convert_string_datum(hibound, boundstypid); + + convert_string_to_scalar(valstr, scaledvalue, + lostr, scaledlobound, + histr, scaledhibound); + pfree(valstr); + pfree(lostr); + pfree(histr); + return true; + } - /* - * Built-in time types - */ + /* + * Built-in time types + */ case TIMESTAMPOID: case ABSTIMEOID: case DATEOID: @@ -911,7 +917,7 @@ convert_numeric_to_scalar(Datum value, Oid typid) { switch (typid) { - case BOOLOID: + case BOOLOID: return (double) DatumGetBool(value); case INT2OID: return (double) DatumGetInt16(value); @@ -931,7 +937,9 @@ convert_numeric_to_scalar(Datum value, Oid typid) /* we can treat OIDs as integers... */ return (double) DatumGetObjectId(value); } - /* Can't get here unless someone tries to use scalarltsel/scalargtsel + + /* + * Can't get here unless someone tries to use scalarltsel/scalargtsel * on an operator with one numeric and one non-numeric operand. */ elog(ERROR, "convert_numeric_to_scalar: unsupported type %u", typid); @@ -1007,7 +1015,9 @@ convert_string_to_scalar(unsigned char *value, if (rangehi < '9') rangehi = '9'; } - /* If range includes less than 10 chars, assume we have not got enough + + /* + * If range includes less than 10 chars, assume we have not got enough * data, and make it include regular ASCII set. */ if (rangehi - rangelo < 9) @@ -1045,7 +1055,10 @@ convert_one_string_to_scalar(unsigned char *value, int rangelo, int rangehi) if (slen <= 0) return 0.0; /* empty string has scalar value 0 */ - /* Since base is at least 10, need not consider more than about 20 chars */ + /* + * Since base is at least 10, need not consider more than about 20 + * chars + */ if (slen > 20) slen = 20; @@ -1055,12 +1068,12 @@ convert_one_string_to_scalar(unsigned char *value, int rangelo, int rangehi) denom = base; while (slen-- > 0) { - int ch = *value++; + int ch = *value++; if (ch < rangelo) - ch = rangelo-1; + ch = rangelo - 1; else if (ch > rangehi) - ch = rangehi+1; + ch = rangehi + 1; num += ((double) (ch - rangelo)) / denom; denom *= base; } @@ -1078,10 +1091,12 @@ static unsigned char * convert_string_datum(Datum value, Oid typid) { char *val; + #ifdef USE_LOCALE char *xfrmstr; size_t xfrmsize; size_t xfrmlen; + #endif switch (typid) @@ -1094,25 +1109,27 @@ convert_string_datum(Datum value, Oid typid) case BPCHAROID: case VARCHAROID: case TEXTOID: - { - char *str = (char *) VARDATA(DatumGetPointer(value)); - int strlength = VARSIZE(DatumGetPointer(value)) - VARHDRSZ; + { + char *str = (char *) VARDATA(DatumGetPointer(value)); + int strlength = VARSIZE(DatumGetPointer(value)) - VARHDRSZ; - val = (char *) palloc(strlength+1); - memcpy(val, str, strlength); - val[strlength] = '\0'; - break; - } + val = (char *) palloc(strlength + 1); + memcpy(val, str, strlength); + val[strlength] = '\0'; + break; + } case NAMEOID: - { - NameData *nm = (NameData *) DatumGetPointer(value); + { + NameData *nm = (NameData *) DatumGetPointer(value); - val = pstrdup(NameStr(*nm)); - break; - } + val = pstrdup(NameStr(*nm)); + break; + } default: - /* Can't get here unless someone tries to use scalarltsel - * on an operator with one string and one non-string operand. + + /* + * Can't get here unless someone tries to use scalarltsel on + * an operator with one string and one non-string operand. */ elog(ERROR, "convert_string_datum: unsupported type %u", typid); return NULL; @@ -1120,7 +1137,7 @@ convert_string_datum(Datum value, Oid typid) #ifdef USE_LOCALE /* Guess that transformed string is not much bigger than original */ - xfrmsize = strlen(val) + 32; /* arbitrary pad value here... */ + xfrmsize = strlen(val) + 32;/* arbitrary pad value here... */ xfrmstr = (char *) palloc(xfrmsize); xfrmlen = strxfrm(xfrmstr, val, xfrmsize); if (xfrmlen >= xfrmsize) @@ -1145,7 +1162,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid) { switch (typid) { - case TIMESTAMPOID: + case TIMESTAMPOID: return DatumGetTimestamp(value); case ABSTIMEOID: return DatumGetTimestamp(DirectFunctionCall1(abstime_timestamp, @@ -1154,31 +1171,33 @@ convert_timevalue_to_scalar(Datum value, Oid typid) return DatumGetTimestamp(DirectFunctionCall1(date_timestamp, value)); case INTERVALOID: - { - Interval *interval = DatumGetIntervalP(value); + { + Interval *interval = DatumGetIntervalP(value); - /* - * Convert the month part of Interval to days using - * assumed average month length of 365.25/12.0 days. Not - * too accurate, but plenty good enough for our purposes. - */ - return interval->time + - interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0); - } + /* + * Convert the month part of Interval to days using + * assumed average month length of 365.25/12.0 days. Not + * too accurate, but plenty good enough for our purposes. + */ + return interval->time + + interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0); + } case RELTIMEOID: return DatumGetRelativeTime(value); case TINTERVALOID: - { - TimeInterval interval = DatumGetTimeInterval(value); + { + TimeInterval interval = DatumGetTimeInterval(value); - if (interval->status != 0) - return interval->data[1] - interval->data[0]; - return 0; /* for lack of a better idea */ - } + if (interval->status != 0) + return interval->data[1] - interval->data[0]; + return 0; /* for lack of a better idea */ + } case TIMEOID: return DatumGetTimeADT(value); } - /* Can't get here unless someone tries to use scalarltsel/scalargtsel + + /* + * Can't get here unless someone tries to use scalarltsel/scalargtsel * on an operator with one timevalue and one non-timevalue operand. */ elog(ERROR, "convert_timevalue_to_scalar: unsupported type %u", typid); @@ -1305,7 +1324,7 @@ getattstatistics(Oid relid, else { char *strval = DatumGetCString(DirectFunctionCall1(textout, - val)); + val)); *commonval = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1329,7 +1348,7 @@ getattstatistics(Oid relid, else { char *strval = DatumGetCString(DirectFunctionCall1(textout, - val)); + val)); *loval = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1353,7 +1372,7 @@ getattstatistics(Oid relid, else { char *strval = DatumGetCString(DirectFunctionCall1(textout, - val)); + val)); *hival = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1417,12 +1436,14 @@ like_fixed_prefix(char *patt, bool case_insensitive, if (patt[pos] == '\0') break; } + /* * XXX I suspect isalpha() is not an adequately locale-sensitive * test for characters that can vary under case folding? */ if (case_insensitive && isalpha((unsigned char) patt[pos])) break; + /* * NOTE: this code used to think that %% meant a literal %, but * textlike() itself does not think that, and the SQL92 spec @@ -1436,7 +1457,8 @@ like_fixed_prefix(char *patt, bool case_insensitive, /* in LIKE, an empty pattern is an exact match! */ if (patt[pos] == '\0') - return Pattern_Prefix_Exact; /* reached end of pattern, so exact */ + return Pattern_Prefix_Exact; /* reached end of pattern, so + * exact */ if (match_pos > 0) return Pattern_Prefix_Partial; @@ -1463,7 +1485,8 @@ regex_fixed_prefix(char *patt, bool case_insensitive, return Pattern_Prefix_None; } - /* If unquoted | is present at paren level 0 in pattern, then there + /* + * If unquoted | is present at paren level 0 in pattern, then there * are multiple alternatives for the start of the string. */ paren_depth = 0; @@ -1495,10 +1518,12 @@ regex_fixed_prefix(char *patt, bool case_insensitive, /* note start at pos 1 to skip leading ^ */ for (pos = 1; patt[pos]; pos++) { + /* - * Check for characters that indicate multiple possible matches here. - * XXX I suspect isalpha() is not an adequately locale-sensitive - * test for characters that can vary under case folding? + * Check for characters that indicate multiple possible matches + * here. XXX I suspect isalpha() is not an adequately + * locale-sensitive test for characters that can vary under case + * folding? */ if (patt[pos] == '.' || patt[pos] == '(' || @@ -1506,9 +1531,11 @@ regex_fixed_prefix(char *patt, bool case_insensitive, patt[pos] == '$' || (case_insensitive && isalpha((unsigned char) patt[pos]))) break; + /* * Check for quantifiers. Except for +, this means the preceding - * character is optional, so we must remove it from the prefix too! + * character is optional, so we must remove it from the prefix + * too! */ if (patt[pos] == '*' || patt[pos] == '?' || @@ -1573,7 +1600,7 @@ pattern_fixed_prefix(char *patt, Pattern_Type ptype, break; default: elog(ERROR, "pattern_fixed_prefix: bogus ptype"); - result = Pattern_Prefix_None; /* keep compiler quiet */ + result = Pattern_Prefix_None; /* keep compiler quiet */ break; } return result; @@ -1596,7 +1623,7 @@ prefix_selectivity(char *prefix, AttrNumber attno, Oid datatype) { - Selectivity prefixsel; + Selectivity prefixsel; Oid cmpopr; Datum prefixcon; char *greaterstr; @@ -1608,21 +1635,21 @@ prefix_selectivity(char *prefix, prefixcon = string_to_datum(prefix, datatype); /* Assume scalargtsel is appropriate for all supported types */ prefixsel = DatumGetFloat8(DirectFunctionCall5(scalargtsel, - ObjectIdGetDatum(cmpopr), - ObjectIdGetDatum(relid), - Int16GetDatum(attno), - prefixcon, - Int32GetDatum(SEL_CONSTANT|SEL_RIGHT))); + ObjectIdGetDatum(cmpopr), + ObjectIdGetDatum(relid), + Int16GetDatum(attno), + prefixcon, + Int32GetDatum(SEL_CONSTANT | SEL_RIGHT))); pfree(DatumGetPointer(prefixcon)); /* - * If we can create a string larger than the prefix, - * say "x < greaterstr". + * If we can create a string larger than the prefix, say "x < + * greaterstr". */ greaterstr = make_greater_string(prefix, datatype); if (greaterstr) { - Selectivity topsel; + Selectivity topsel; cmpopr = find_operator("<", datatype); if (cmpopr == InvalidOid) @@ -1631,28 +1658,28 @@ prefix_selectivity(char *prefix, prefixcon = string_to_datum(greaterstr, datatype); /* Assume scalarltsel is appropriate for all supported types */ topsel = DatumGetFloat8(DirectFunctionCall5(scalarltsel, - ObjectIdGetDatum(cmpopr), - ObjectIdGetDatum(relid), - Int16GetDatum(attno), - prefixcon, - Int32GetDatum(SEL_CONSTANT|SEL_RIGHT))); + ObjectIdGetDatum(cmpopr), + ObjectIdGetDatum(relid), + Int16GetDatum(attno), + prefixcon, + Int32GetDatum(SEL_CONSTANT | SEL_RIGHT))); pfree(DatumGetPointer(prefixcon)); pfree(greaterstr); /* - * Merge the two selectivities in the same way as for - * a range query (see clauselist_selectivity()). + * Merge the two selectivities in the same way as for a range + * query (see clauselist_selectivity()). */ prefixsel = topsel + prefixsel - 1.0; /* - * A zero or slightly negative prefixsel should be converted into a - * small positive value; we probably are dealing with a very + * A zero or slightly negative prefixsel should be converted into + * a small positive value; we probably are dealing with a very * tight range and got a bogus result due to roundoff errors. * However, if prefixsel is very negative, then we probably have * default selectivity estimates on one or both sides of the - * range. In that case, insert a not-so-wildly-optimistic - * default estimate. + * range. In that case, insert a not-so-wildly-optimistic default + * estimate. */ if (prefixsel <= 0.0) { @@ -1660,8 +1687,8 @@ prefix_selectivity(char *prefix, { /* - * No data available --- use a default estimate that - * is small, but not real small. + * No data available --- use a default estimate that is + * small, but not real small. */ prefixsel = 0.01; } @@ -1691,15 +1718,16 @@ prefix_selectivity(char *prefix, #define FIXED_CHAR_SEL 0.04 /* about 1/25 */ #define CHAR_RANGE_SEL 0.25 -#define ANY_CHAR_SEL 0.9 /* not 1, since it won't match end-of-string */ +#define ANY_CHAR_SEL 0.9 /* not 1, since it won't match + * end-of-string */ #define FULL_WILDCARD_SEL 5.0 #define PARTIAL_WILDCARD_SEL 2.0 static Selectivity like_selectivity(char *patt, bool case_insensitive) { - Selectivity sel = 1.0; - int pos; + Selectivity sel = 1.0; + int pos; /* Skip any leading %; it's already factored into initial sel */ pos = (*patt == '%') ? 1 : 0; @@ -1730,17 +1758,17 @@ like_selectivity(char *patt, bool case_insensitive) static Selectivity regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) { - Selectivity sel = 1.0; - int paren_depth = 0; - int paren_pos = 0; /* dummy init to keep compiler quiet */ - int pos; + Selectivity sel = 1.0; + int paren_depth = 0; + int paren_pos = 0; /* dummy init to keep compiler quiet */ + int pos; for (pos = 0; pos < pattlen; pos++) { if (patt[pos] == '(') { if (paren_depth == 0) - paren_pos = pos; /* remember start of parenthesized item */ + paren_pos = pos;/* remember start of parenthesized item */ paren_depth++; } else if (patt[pos] == ')' && paren_depth > 0) @@ -1753,9 +1781,10 @@ regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) } else if (patt[pos] == '|' && paren_depth == 0) { + /* - * If unquoted | is present at paren level 0 in pattern, - * we have multiple alternatives; sum their probabilities. + * If unquoted | is present at paren level 0 in pattern, we + * have multiple alternatives; sum their probabilities. */ sel += regex_selectivity_sub(patt + (pos + 1), pattlen - (pos + 1), @@ -1764,19 +1793,20 @@ regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) } else if (patt[pos] == '[') { - bool negclass = false; + bool negclass = false; if (patt[++pos] == '^') { negclass = true; pos++; } - if (patt[pos] == ']') /* ']' at start of class is not special */ + if (patt[pos] == ']') /* ']' at start of class is not + * special */ pos++; while (pos < pattlen && patt[pos] != ']') pos++; if (paren_depth == 0) - sel *= (negclass ? (1.0-CHAR_RANGE_SEL) : CHAR_RANGE_SEL); + sel *= (negclass ? (1.0 - CHAR_RANGE_SEL) : CHAR_RANGE_SEL); } else if (patt[pos] == '.') { @@ -1822,15 +1852,15 @@ regex_selectivity_sub(char *patt, int pattlen, bool case_insensitive) static Selectivity regex_selectivity(char *patt, bool case_insensitive) { - Selectivity sel; - int pattlen = strlen(patt); + Selectivity sel; + int pattlen = strlen(patt); /* If patt doesn't end with $, consider it to have a trailing wildcard */ - if (pattlen > 0 && patt[pattlen-1] == '$' && - (pattlen == 1 || patt[pattlen-2] != '\\')) + if (pattlen > 0 && patt[pattlen - 1] == '$' && + (pattlen == 1 || patt[pattlen - 2] != '\\')) { /* has trailing $ */ - sel = regex_selectivity_sub(patt, pattlen-1, case_insensitive); + sel = regex_selectivity_sub(patt, pattlen - 1, case_insensitive); } else { @@ -1893,6 +1923,7 @@ locale_is_like_safe(void) localeptr = setlocale(LC_COLLATE, NULL); if (!localeptr) elog(STOP, "Invalid LC_COLLATE setting"); + /* * Currently we accept only "C" and "POSIX" (do any systems still * return "POSIX"?). Which other locales allow safe optimization? @@ -1904,9 +1935,9 @@ locale_is_like_safe(void) else result = false; return (bool) result; -#else /* not USE_LOCALE */ - return true; /* We must be in C locale, which is OK */ -#endif /* USE_LOCALE */ +#else /* not USE_LOCALE */ + return true; /* We must be in C locale, which is OK */ +#endif /* USE_LOCALE */ } /* @@ -2039,6 +2070,7 @@ find_operator(const char *opname, Oid datatype) static Datum string_to_datum(const char *str, Oid datatype) { + /* * We cheat a little by assuming that textin() will do for bpchar and * varchar constants too... diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c index 11c5579fc20..c48526a7ba1 100644 --- a/src/backend/utils/adt/sets.c +++ b/src/backend/utils/adt/sets.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.36 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.37 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -62,8 +62,8 @@ SetDefine(char *querystr, char *typename) false, /* canCache (assume unsafe) */ false, /* isStrict (irrelevant, no args) */ 100, /* byte_pct */ - 0, /* perbyte_cpu */ - 0, /* percall_cpu */ + 0, /* perbyte_cpu */ + 0, /* percall_cpu */ 100, /* outin_ratio */ NIL, /* argList */ whereToSendOutput); @@ -165,8 +165,8 @@ seteval(PG_FUNCTION_ARGS) } /* - * Evaluate the function. NOTE: we need no econtext because there - * are no arguments to evaluate. + * Evaluate the function. NOTE: we need no econtext because there are + * no arguments to evaluate. */ /* ExecMakeFunctionResult assumes these are initialized at call: */ @@ -175,14 +175,14 @@ seteval(PG_FUNCTION_ARGS) result = ExecMakeFunctionResult(fcache, NIL, - NULL, /* no econtext, see above */ + NULL, /* no econtext, see above */ &isNull, &isDone); /* - * If we're done with the results of this set function, get rid of - * its func cache so that we will start from the top next time. - * (Can you say "memory leak"? This feature is a crock anyway...) + * If we're done with the results of this set function, get rid of its + * func cache so that we will start from the top next time. (Can you + * say "memory leak"? This feature is a crock anyway...) */ if (isDone != ExprMultipleResult) { @@ -197,7 +197,7 @@ seteval(PG_FUNCTION_ARGS) if (isDone != ExprSingleResult) { - ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo; + ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo; if (rsi && IsA(rsi, ReturnSetInfo)) rsi->isDone = isDone; diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c index 18bad89c48b..7e3b4bfc257 100644 --- a/src/backend/utils/adt/tid.c +++ b/src/backend/utils/adt/tid.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.23 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.24 2001/03/22 03:59:54 momjian Exp $ * * NOTES * input routine largely stolen from boxin(). @@ -21,8 +21,8 @@ #include "access/heapam.h" #include "utils/builtins.h" -#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X)) -#define ItemPointerGetDatum(X) PointerGetDatum(X) +#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X)) +#define ItemPointerGetDatum(X) PointerGetDatum(X) #define PG_GETARG_ITEMPOINTER(n) DatumGetItemPointer(PG_GETARG_DATUM(n)) #define PG_RETURN_ITEMPOINTER(x) return ItemPointerGetDatum(x) @@ -70,7 +70,7 @@ tidin(PG_FUNCTION_ARGS) Datum tidout(PG_FUNCTION_ARGS) { - ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0); + ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0); BlockId blockId; BlockNumber blockNumber; OffsetNumber offsetNumber; @@ -97,8 +97,8 @@ tidout(PG_FUNCTION_ARGS) Datum tideq(PG_FUNCTION_ARGS) { - ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); - ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); + ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); + ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); PG_RETURN_BOOL(BlockIdGetBlockNumber(&(arg1->ip_blkid)) == BlockIdGetBlockNumber(&(arg2->ip_blkid)) && @@ -109,13 +109,14 @@ tideq(PG_FUNCTION_ARGS) Datum tidne(PG_FUNCTION_ARGS) { - ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); - ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); + ItemPointer arg1 = PG_GETARG_ITEMPOINTER(0); + ItemPointer arg2 = PG_GETARG_ITEMPOINTER(1); PG_RETURN_BOOL(BlockIdGetBlockNumber(&(arg1->ip_blkid)) != BlockIdGetBlockNumber(&(arg2->ip_blkid)) || arg1->ip_posid != arg2->ip_posid); } + #endif /* @@ -126,11 +127,11 @@ tidne(PG_FUNCTION_ARGS) Datum currtid_byreloid(PG_FUNCTION_ARGS) { - Oid reloid = PG_GETARG_OID(0); - ItemPointer tid = PG_GETARG_ITEMPOINTER(1); - ItemPointer result, - ret; - Relation rel; + Oid reloid = PG_GETARG_OID(0); + ItemPointer tid = PG_GETARG_ITEMPOINTER(1); + ItemPointer result, + ret; + Relation rel; result = (ItemPointer) palloc(sizeof(ItemPointerData)); ItemPointerSetInvalid(result); @@ -150,12 +151,12 @@ currtid_byreloid(PG_FUNCTION_ARGS) Datum currtid_byrelname(PG_FUNCTION_ARGS) { - text *relname = PG_GETARG_TEXT_P(0); - ItemPointer tid = PG_GETARG_ITEMPOINTER(1); - ItemPointer result, - ret; - char *str; - Relation rel; + text *relname = PG_GETARG_TEXT_P(0); + ItemPointer tid = PG_GETARG_ITEMPOINTER(1); + ItemPointer result, + ret; + char *str; + Relation rel; str = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(relname))); diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index a01a790124f..7a2e6ea8bb0 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.45 2001/02/13 14:32:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.46 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -92,7 +92,7 @@ timestamp_in(PG_FUNCTION_ARGS) default: elog(ERROR, "Internal coding error, can't input timestamp '%s'", str); - TIMESTAMP_INVALID(result); /* keep compiler quiet */ + TIMESTAMP_INVALID(result); /* keep compiler quiet */ } PG_RETURN_TIMESTAMP(result); @@ -315,14 +315,14 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn) #if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE) tx = localtime(&utime); -# ifdef NO_MKTIME_BEFORE_1970 +#ifdef NO_MKTIME_BEFORE_1970 if (tx->tm_year < 70 && tx->tm_isdst == 1) { utime -= 3600; tx = localtime(&utime); tx->tm_isdst = 0; } -# endif +#endif tm->tm_year = tx->tm_year + 1900; tm->tm_mon = tx->tm_mon + 1; tm->tm_mday = tx->tm_mday; @@ -341,20 +341,20 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn) #endif tm->tm_isdst = tx->tm_isdst; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tm->tm_gmtoff = tx->tm_gmtoff; tm->tm_zone = tx->tm_zone; *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ if (tzn != NULL) *tzn = (char *) tm->tm_zone; -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) *tzp = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); if (tzn != NULL) *tzn = tzname[(tm->tm_isdst > 0)]; -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ *tzp = CTimeZone; /* V7 conventions; don't know timezone? */ if (tzn != NULL) *tzn = CTZName; @@ -482,7 +482,7 @@ timestamp_finite(PG_FUNCTION_ARGS) { Timestamp timestamp = PG_GETARG_TIMESTAMP(0); - PG_RETURN_BOOL(! TIMESTAMP_NOT_FINITE(timestamp)); + PG_RETURN_BOOL(!TIMESTAMP_NOT_FINITE(timestamp)); } Datum @@ -490,7 +490,7 @@ interval_finite(PG_FUNCTION_ARGS) { Interval *interval = PG_GETARG_INTERVAL_P(0); - PG_RETURN_BOOL(! INTERVAL_NOT_FINITE(*interval)); + PG_RETURN_BOOL(!INTERVAL_NOT_FINITE(*interval)); } @@ -656,13 +656,9 @@ timestamp_cmp(PG_FUNCTION_ARGS) Timestamp dt2 = PG_GETARG_TIMESTAMP(1); if (TIMESTAMP_IS_INVALID(dt1)) - { PG_RETURN_INT32(TIMESTAMP_IS_INVALID(dt2) ? 0 : 1); - } else if (TIMESTAMP_IS_INVALID(dt2)) - { PG_RETURN_INT32(-1); - } else { if (TIMESTAMP_IS_RELATIVE(dt1)) @@ -839,7 +835,9 @@ interval_hash(PG_FUNCTION_ARGS) Datum overlaps_timestamp(PG_FUNCTION_ARGS) { - /* The arguments are Timestamps, but we leave them as generic Datums + + /* + * The arguments are Timestamps, but we leave them as generic Datums * to avoid unnecessary conversions between value and reference forms * --- not to mention possible dereferences of null pointers. */ @@ -858,9 +856,9 @@ overlaps_timestamp(PG_FUNCTION_ARGS) DatumGetBool(DirectFunctionCall2(timestamp_lt,t1,t2)) /* - * If both endpoints of interval 1 are null, the result is null (unknown). - * If just one endpoint is null, take ts1 as the non-null one. - * Otherwise, take ts1 as the lesser endpoint. + * If both endpoints of interval 1 are null, the result is null + * (unknown). If just one endpoint is null, take ts1 as the non-null + * one. Otherwise, take ts1 as the lesser endpoint. */ if (ts1IsNull) { @@ -874,7 +872,7 @@ overlaps_timestamp(PG_FUNCTION_ARGS) { if (TIMESTAMP_GT(ts1, te1)) { - Datum tt = ts1; + Datum tt = ts1; ts1 = te1; te1 = tt; @@ -894,7 +892,7 @@ overlaps_timestamp(PG_FUNCTION_ARGS) { if (TIMESTAMP_GT(ts2, te2)) { - Datum tt = ts2; + Datum tt = ts2; ts2 = te2; te2 = tt; @@ -907,7 +905,9 @@ overlaps_timestamp(PG_FUNCTION_ARGS) */ if (TIMESTAMP_GT(ts1, ts2)) { - /* This case is ts1 < te2 OR te1 < te2, which may look redundant + + /* + * This case is ts1 < te2 OR te1 < te2, which may look redundant * but in the presence of nulls it's not quite completely so. */ if (te2IsNull) @@ -916,7 +916,9 @@ overlaps_timestamp(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); - /* If te1 is not null then we had ts1 <= te1 above, and we just + + /* + * If te1 is not null then we had ts1 <= te1 above, and we just * found ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); @@ -930,15 +932,20 @@ overlaps_timestamp(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); - /* If te2 is not null then we had ts2 <= te2 above, and we just + + /* + * If te2 is not null then we had ts2 <= te2 above, and we just * found ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { - /* For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a - * rather silly way of saying "true if both are nonnull, else null". + + /* + * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a + * rather silly way of saying "true if both are nonnull, else + * null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); @@ -1086,13 +1093,14 @@ timestamp_pl_span(PG_FUNCTION_ARGS) tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) - tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#if defined(HAVE_TM_ZONE) + tz = -(tm->tm_gmtoff); /* tm_gmtoff is + * Sun/DEC-ism */ +#elif defined(HAVE_INT_TIMEZONE) tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ tz = CTimeZone; #endif } @@ -1129,8 +1137,8 @@ timestamp_mi_span(PG_FUNCTION_ARGS) Interval *span = PG_GETARG_INTERVAL_P(1); Interval tspan; - tspan.month = - span->month; - tspan.time = - span->time; + tspan.month = -span->month; + tspan.time = -span->time; return DirectFunctionCall2(timestamp_pl_span, TimestampGetDatum(timestamp), @@ -1351,18 +1359,19 @@ interval_accum(PG_FUNCTION_ARGS) &transdatums, &ndatums); if (ndatums != 2) elog(ERROR, "interval_accum: expected 2-element interval array"); + /* * XXX memcpy, instead of just extracting a pointer, to work around * buggy array code: it won't ensure proper alignment of Interval - * objects on machines where double requires 8-byte alignment. - * That should be fixed, but in the meantime... + * objects on machines where double requires 8-byte alignment. That + * should be fixed, but in the meantime... */ memcpy(&sumX, DatumGetIntervalP(transdatums[0]), sizeof(Interval)); memcpy(&N, DatumGetIntervalP(transdatums[1]), sizeof(Interval)); newsum = DatumGetIntervalP(DirectFunctionCall2(interval_pl, - IntervalPGetDatum(&sumX), - IntervalPGetDatum(newval))); + IntervalPGetDatum(&sumX), + IntervalPGetDatum(newval))); N.time += 1; transdatums[0] = IntervalPGetDatum(newsum); @@ -1389,11 +1398,12 @@ interval_avg(PG_FUNCTION_ARGS) &transdatums, &ndatums); if (ndatums != 2) elog(ERROR, "interval_avg: expected 2-element interval array"); + /* * XXX memcpy, instead of just extracting a pointer, to work around * buggy array code: it won't ensure proper alignment of Interval - * objects on machines where double requires 8-byte alignment. - * That should be fixed, but in the meantime... + * objects on machines where double requires 8-byte alignment. That + * should be fixed, but in the meantime... */ memcpy(&sumX, DatumGetIntervalP(transdatums[0]), sizeof(Interval)); memcpy(&N, DatumGetIntervalP(transdatums[1]), sizeof(Interval)); @@ -1439,9 +1449,7 @@ timestamp_age(PG_FUNCTION_ARGS) if (TIMESTAMP_IS_INVALID(dt1) || TIMESTAMP_IS_INVALID(dt2)) - { TIMESTAMP_INVALID(result->time); - } else if ((timestamp2tm(dt1, NULL, tm1, &fsec1, NULL) == 0) && (timestamp2tm(dt2, NULL, tm2, &fsec2, NULL) == 0)) { @@ -1597,7 +1605,7 @@ interval_text(PG_FUNCTION_ARGS) int len; str = DatumGetCString(DirectFunctionCall1(interval_out, - IntervalPGetDatum(interval))); + IntervalPGetDatum(interval))); len = (strlen(str) + VARHDRSZ); @@ -1662,7 +1670,7 @@ timestamp_trunc(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1672,9 +1680,7 @@ timestamp_trunc(PG_FUNCTION_ARGS) type = DecodeUnits(0, lowunits, &val); if (TIMESTAMP_NOT_FINITE(timestamp)) - { PG_RETURN_NULL(); - } else { dt = (TIMESTAMP_IS_RELATIVE(timestamp) ? SetTimestamp(timestamp) : timestamp); @@ -1729,13 +1735,13 @@ timestamp_trunc(PG_FUNCTION_ARGS) tm->tm_year += 1900; tm->tm_mon += 1; -# if defined(HAVE_TM_ZONE) +#if defined(HAVE_TM_ZONE) tz = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ -# elif defined(HAVE_INT_TIMEZONE) +#elif defined(HAVE_INT_TIMEZONE) tz = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL); -# endif +#endif -#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ +#else /* not (HAVE_TM_ZONE || HAVE_INT_TIMEZONE) */ tz = CTimeZone; #endif } @@ -1789,7 +1795,7 @@ interval_trunc(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1872,7 +1878,7 @@ interval_trunc(PG_FUNCTION_ARGS) { elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); PG_RETURN_NULL(); } @@ -1885,75 +1891,80 @@ interval_trunc(PG_FUNCTION_ARGS) * karel 2000/08/07 */ void -isoweek2date( int woy, int *year, int *mon, int *mday) +isoweek2date(int woy, int *year, int *mon, int *mday) { - int day0, day4, dayn; - + int day0, + day4, + dayn; + if (!*year) elog(ERROR, "isoweek2date(): can't convert without year information"); /* fourth day of current year */ day4 = date2j(*year, 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); dayn = ((woy - 1) * 7) + (day4 - day0); - + j2date(dayn, year, mon, mday); } /* date2isoweek() - * + * * Returns ISO week number of year. */ int -date2isoweek(int year, int mon, int mday) +date2isoweek(int year, int mon, int mday) { - float8 result; - int day0, day4, dayn; - - /* current day */ + float8 result; + int day0, + day4, + dayn; + + /* current day */ dayn = date2j(year, mon, mday); - + /* fourth day of current year */ day4 = date2j(year, 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); - - /* We need the first week containing a Thursday, - * otherwise this day falls into the previous year - * for purposes of counting weeks + + /* + * We need the first week containing a Thursday, otherwise this day + * falls into the previous year for purposes of counting weeks */ if (dayn < (day4 - day0)) { day4 = date2j((year - 1), 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); } - + result = (((dayn - (day4 - day0)) / 7) + 1); - - /* Sometimes the last few days in a year will fall into - * the first week of the next year, so check for this. + + /* + * Sometimes the last few days in a year will fall into the first week + * of the next year, so check for this. */ if (result >= 53) { day4 = date2j((year + 1), 1, 4); - + /* day0 == offset to first day of week (Monday) */ day0 = (j2day(day4 - 1) % 7); - + if (dayn >= (day4 - day0)) result = (((dayn - (day4 - day0)) / 7) + 1); } return (int) result; -} - - +} + + /* timestamp_part() * Extract specified field from timestamp. */ @@ -1980,7 +1991,7 @@ timestamp_part(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1992,9 +2003,7 @@ timestamp_part(PG_FUNCTION_ARGS) type = DecodeSpecial(0, lowunits, &val); if (TIMESTAMP_NOT_FINITE(timestamp)) - { PG_RETURN_NULL(); - } else { dt = (TIMESTAMP_IS_RELATIVE(timestamp) ? SetTimestamp(timestamp) : timestamp); @@ -2096,7 +2105,7 @@ timestamp_part(PG_FUNCTION_ARGS) elog(ERROR, "Unable to encode timestamp"); result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - - date2j(tm->tm_year, 1, 1) + 1); + - date2j(tm->tm_year, 1, 1) + 1); break; default: @@ -2138,7 +2147,7 @@ interval_part(PG_FUNCTION_ARGS) if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -2213,7 +2222,7 @@ interval_part(PG_FUNCTION_ARGS) default: elog(ERROR, "Interval units '%s' not yet supported", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); result = 0; } @@ -2237,7 +2246,7 @@ interval_part(PG_FUNCTION_ARGS) { elog(ERROR, "Interval units '%s' not recognized", DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(units)))); + PointerGetDatum(units)))); result = 0; } @@ -2283,9 +2292,7 @@ timestamp_zone(PG_FUNCTION_ARGS) type = DecodeSpecial(0, lowzone, &val); if (TIMESTAMP_NOT_FINITE(timestamp)) - { PG_RETURN_NULL(); - } else if ((type == TZ) || (type == DTZ)) { tm->tm_isdst = ((type == DTZ) ? 1 : 0); @@ -2320,7 +2327,7 @@ timestamp_zone(PG_FUNCTION_ARGS) } PG_RETURN_TEXT_P(result); -} /* timestamp_zone() */ +} /* timestamp_zone() */ /* timestamp_izone() * Encode timestamp type with specified time interval as time zone. @@ -2364,4 +2371,4 @@ timestamp_izone(PG_FUNCTION_ARGS) memmove(VARDATA(result), buf, (len - VARHDRSZ)); PG_RETURN_TEXT_P(result); -} /* timestamp_izone() */ +} /* timestamp_izone() */ diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c index adbdf4f8ca7..775382568bb 100644 --- a/src/backend/utils/adt/varbit.c +++ b/src/backend/utils/adt/varbit.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.15 2001/01/24 19:43:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.16 2001/03/22 03:59:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -51,8 +51,10 @@ Datum zpbit_in(PG_FUNCTION_ARGS) { char *input_string = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); VarBit *result; /* The resulting bit string */ @@ -79,9 +81,10 @@ zpbit_in(PG_FUNCTION_ARGS) } else { + /* - * Otherwise it's binary. This allows things like cast('1001' - * as bit) to work transparently. + * Otherwise it's binary. This allows things like cast('1001' as + * bit) to work transparently. */ bit_not_hex = true; sp = input_string; @@ -214,8 +217,8 @@ zpbit_out(PG_FUNCTION_ARGS) } /* - * Go back one step if we printed a hex number that was not part - * of the bitstring anymore + * Go back one step if we printed a hex number that was not part of + * the bitstring anymore */ if (i > len) r--; @@ -263,12 +266,13 @@ _zpbit(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since zpbit() is a built-in function, we should only need to - * look it up once per run. + * Since zpbit() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo zpbit_finfo; + static FmgrInfo zpbit_finfo; if (zpbit_finfo.fn_oid == InvalidOid) fmgr_info(F_ZPBIT, &zpbit_finfo); @@ -293,8 +297,10 @@ Datum varbit_in(PG_FUNCTION_ARGS) { char *input_string = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); VarBit *result; /* The resulting bit string */ @@ -490,12 +496,13 @@ _varbit(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since varbit() is a built-in function, we should only need to - * look it up once per run. + * Since varbit() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo varbit_finfo; + static FmgrInfo varbit_finfo; if (varbit_finfo.fn_oid == InvalidOid) fmgr_info(F_VARBIT, &varbit_finfo); @@ -765,7 +772,7 @@ bitsubstr(PG_FUNCTION_ARGS) bitlen = VARBITLEN(arg); /* If we do not have an upper bound, set bitlen */ - if (l==-1) + if (l == -1) l = bitlen; e = s + l; s1 = Max(s, 1); @@ -780,6 +787,7 @@ bitsubstr(PG_FUNCTION_ARGS) } else { + /* * OK, we've got a true substring starting at position s1-1 and * ending at position e1-1 @@ -823,7 +831,7 @@ bitsubstr(PG_FUNCTION_ARGS) PG_RETURN_VARBIT_P(result); } -/* bitlength, bitoctetlength +/* bitlength, bitoctetlength * Return the length of a bit string */ Datum @@ -986,7 +994,7 @@ bitnot(PG_FUNCTION_ARGS) p = VARBITS(arg); r = VARBITS(result); for (; p < VARBITEND(arg); p++) - *r++ = ~ *p; + *r++ = ~*p; /* Pad the result */ mask = BITMASK << VARBITPAD(result); @@ -1076,8 +1084,8 @@ bitshiftright(PG_FUNCTION_ARGS) /* Negative shift is a shift to the left */ if (shft < 0) PG_RETURN_DATUM(DirectFunctionCall2(bitshiftleft, - VarBitPGetDatum(arg), - Int32GetDatum(-shft))); + VarBitPGetDatum(arg), + Int32GetDatum(-shft))); result = (VarBit *) palloc(VARSIZE(arg)); VARATT_SIZEP(result) = VARSIZE(arg); @@ -1121,7 +1129,7 @@ bitshiftright(PG_FUNCTION_ARGS) } /* This is not defined in any standard. We retain the natural ordering of - * bits here, as it just seems more intuitive. + * bits here, as it just seems more intuitive. */ Datum bitfromint4(PG_FUNCTION_ARGS) @@ -1130,19 +1138,21 @@ bitfromint4(PG_FUNCTION_ARGS) VarBit *result; bits8 *r; int len; - + /* allocate enough space for the bits in an int4 */ - len = VARBITTOTALLEN(sizeof(int4)*BITS_PER_BYTE); + len = VARBITTOTALLEN(sizeof(int4) * BITS_PER_BYTE); result = (VarBit *) palloc(len); VARATT_SIZEP(result) = len; - VARBITLEN(result) = sizeof(int4)*BITS_PER_BYTE; - /* masks and shifts here are just too painful and we know that an int4 has - * got 4 bytes + VARBITLEN(result) = sizeof(int4) * BITS_PER_BYTE; + + /* + * masks and shifts here are just too painful and we know that an int4 + * has got 4 bytes */ r = VARBITS(result); - r[0] = (bits8) ((a >> (3*BITS_PER_BYTE)) & BITMASK); - r[1] = (bits8) ((a >> (2*BITS_PER_BYTE)) & BITMASK); - r[2] = (bits8) ((a >> (1*BITS_PER_BYTE)) & BITMASK); + r[0] = (bits8) ((a >> (3 * BITS_PER_BYTE)) & BITMASK); + r[1] = (bits8) ((a >> (2 * BITS_PER_BYTE)) & BITMASK); + r[2] = (bits8) ((a >> (1 * BITS_PER_BYTE)) & BITMASK); r[3] = (bits8) (a & BITMASK); PG_RETURN_VARBIT_P(result); @@ -1156,7 +1166,7 @@ bittoint4(PG_FUNCTION_ARGS) bits8 *r; /* Check that the bit string is not too long */ - if (VARBITLEN(arg) > sizeof(int4)*BITS_PER_BYTE) + if (VARBITLEN(arg) > sizeof(int4) * BITS_PER_BYTE) elog(ERROR, "Bit string is too large to fit in an int4"); result = 0; for (r = VARBITS(arg); r < VARBITEND(arg); r++) @@ -1179,18 +1189,18 @@ bittoint4(PG_FUNCTION_ARGS) Datum bitposition(PG_FUNCTION_ARGS) { - VarBit *substr = PG_GETARG_VARBIT_P(1); - VarBit *arg = PG_GETARG_VARBIT_P(0); - int substr_length, + VarBit *substr = PG_GETARG_VARBIT_P(1); + VarBit *arg = PG_GETARG_VARBIT_P(0); + int substr_length, arg_length, i, is; - bits8 *s, /* pointer into substring */ - *p; /* pointer into arg */ - bits8 cmp, /* shifted substring byte to compare */ - mask1, /* mask for substring byte shifted right */ - mask2, /* mask for substring byte shifted left */ - end_mask, /* pad mask for last substring byte */ + bits8 *s, /* pointer into substring */ + *p; /* pointer into arg */ + bits8 cmp, /* shifted substring byte to compare */ + mask1, /* mask for substring byte shifted right */ + mask2, /* mask for substring byte shifted left */ + end_mask, /* pad mask for last substring byte */ arg_mask; /* pad mask for last argument byte */ bool is_match; @@ -1200,8 +1210,8 @@ bitposition(PG_FUNCTION_ARGS) /* Argument has 0 length or substring longer than argument, return 0 */ if (arg_length == 0 || substr_length > arg_length) - PG_RETURN_INT32(0); - + PG_RETURN_INT32(0); + /* 0-length means return 1 */ if (substr_length == 0) PG_RETURN_INT32(1); @@ -1209,23 +1219,26 @@ bitposition(PG_FUNCTION_ARGS) /* Initialise the padding masks */ end_mask = BITMASK << VARBITPAD(substr); arg_mask = BITMASK << VARBITPAD(arg); - for (i = 0; i < VARBITBYTES(arg) - VARBITBYTES(substr) + 1; i++) + for (i = 0; i < VARBITBYTES(arg) - VARBITBYTES(substr) + 1; i++) { - for (is = 0; is < BITS_PER_BYTE; is++) { + for (is = 0; is < BITS_PER_BYTE; is++) + { is_match = true; p = VARBITS(arg) + i; mask1 = BITMASK >> is; mask2 = ~mask1; - for (s = VARBITS(substr); - is_match && s < VARBITEND(substr); s++) + for (s = VARBITS(substr); + is_match && s < VARBITEND(substr); s++) { cmp = *s >> is; - if (s == VARBITEND(substr) - 1) + if (s == VARBITEND(substr) - 1) { mask1 &= end_mask >> is; - if (p == VARBITEND(arg) - 1) { + if (p == VARBITEND(arg) - 1) + { /* Check that there is enough of arg left */ - if (mask1 & ~arg_mask) { + if (mask1 & ~arg_mask) + { is_match = false; break; } @@ -1237,21 +1250,24 @@ bitposition(PG_FUNCTION_ARGS) break; /* Move on to the next byte */ p++; - if (p == VARBITEND(arg)) { + if (p == VARBITEND(arg)) + { mask2 = end_mask << (BITS_PER_BYTE - is); is_match = mask2 == 0; #if 0 - elog(NOTICE,"S. %d %d em=%2x sm=%2x r=%d", - i,is,end_mask,mask2,is_match); + elog(NOTICE, "S. %d %d em=%2x sm=%2x r=%d", + i, is, end_mask, mask2, is_match); #endif break; } cmp = *s << (BITS_PER_BYTE - is); - if (s == VARBITEND(substr) - 1) + if (s == VARBITEND(substr) - 1) { mask2 &= end_mask << (BITS_PER_BYTE - is); - if (p == VARBITEND(arg) - 1) { - if (mask2 & ~arg_mask) { + if (p == VARBITEND(arg) - 1) + { + if (mask2 & ~arg_mask) + { is_match = false; break; } @@ -1262,7 +1278,7 @@ bitposition(PG_FUNCTION_ARGS) } /* Have we found a match */ if (is_match) - PG_RETURN_INT32(i*BITS_PER_BYTE + is + 1); + PG_RETURN_INT32(i * BITS_PER_BYTE + is + 1); } } PG_RETURN_INT32(0); diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index acec5f0cf24..37eeee4206c 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.74 2001/02/10 02:31:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.75 2001/03/22 03:59:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -64,8 +64,10 @@ Datum bpcharin(PG_FUNCTION_ARGS) { char *s = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); BpChar *result; @@ -82,9 +84,9 @@ bpcharin(PG_FUNCTION_ARGS) else #ifdef MULTIBYTE { + /* - * truncate multi-byte string preserving multi-byte - * boundary + * truncate multi-byte string preserving multi-byte boundary */ len = pg_mbcliplen(s, atttypmod - VARHDRSZ, atttypmod - VARHDRSZ); } @@ -169,6 +171,7 @@ bpchar(PG_FUNCTION_ARGS) r = VARDATA(result); #ifdef MULTIBYTE + /* * truncate multi-byte string in a way not to break multi-byte * boundary @@ -214,18 +217,19 @@ _bpchar(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since bpchar() is a built-in function, we should only need to - * look it up once per run. + * Since bpchar() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo bpchar_finfo; + static FmgrInfo bpchar_finfo; if (bpchar_finfo.fn_oid == InvalidOid) fmgr_info(F_BPCHAR, &bpchar_finfo); MemSet(&locfcinfo, 0, sizeof(locfcinfo)); - locfcinfo.flinfo = &bpchar_finfo; + locfcinfo.flinfo = &bpchar_finfo; locfcinfo.nargs = 2; /* We assume we are "strict" and need not worry about null inputs */ locfcinfo.arg[0] = PointerGetDatum(v); @@ -280,7 +284,7 @@ bpchar_name(PG_FUNCTION_ARGS) /* Truncate to max length for a Name */ if (len >= NAMEDATALEN) - len = NAMEDATALEN-1; + len = NAMEDATALEN - 1; /* Remove trailing blanks */ while (len > 0) @@ -335,17 +339,19 @@ Datum varcharin(PG_FUNCTION_ARGS) { char *s = PG_GETARG_CSTRING(0); + #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); + #endif int32 atttypmod = PG_GETARG_INT32(2); - VarChar *result; + VarChar *result; int len; len = strlen(s) + VARHDRSZ; if (atttypmod >= (int32) VARHDRSZ && len > atttypmod) #ifdef MULTIBYTE - len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ; + len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ; #else len = atttypmod; /* clip the string at max length */ #endif @@ -364,7 +370,7 @@ varcharin(PG_FUNCTION_ARGS) Datum varcharout(PG_FUNCTION_ARGS) { - VarChar *s = PG_GETARG_VARCHAR_P(0); + VarChar *s = PG_GETARG_VARCHAR_P(0); char *result; int len; @@ -388,9 +394,9 @@ varcharout(PG_FUNCTION_ARGS) Datum varchar(PG_FUNCTION_ARGS) { - VarChar *s = PG_GETARG_VARCHAR_P(0); + VarChar *s = PG_GETARG_VARCHAR_P(0); int32 slen = PG_GETARG_INT32(1); - VarChar *result; + VarChar *result; int len; len = VARSIZE(s); @@ -402,8 +408,7 @@ varchar(PG_FUNCTION_ARGS) #ifdef MULTIBYTE /* - * truncate multi-byte string preserving multi-byte - * boundary + * truncate multi-byte string preserving multi-byte boundary */ len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ); slen = len + VARHDRSZ; @@ -427,18 +432,19 @@ _varchar(PG_FUNCTION_ARGS) { ArrayType *v = (ArrayType *) PG_GETARG_VARLENA_P(0); int32 len = PG_GETARG_INT32(1); - FunctionCallInfoData locfcinfo; + FunctionCallInfoData locfcinfo; + /* - * Since varchar() is a built-in function, we should only need to - * look it up once per run. + * Since varchar() is a built-in function, we should only need to look + * it up once per run. */ - static FmgrInfo varchar_finfo; + static FmgrInfo varchar_finfo; if (varchar_finfo.fn_oid == InvalidOid) fmgr_info(F_VARCHAR, &varchar_finfo); MemSet(&locfcinfo, 0, sizeof(locfcinfo)); - locfcinfo.flinfo = &varchar_finfo; + locfcinfo.flinfo = &varchar_finfo; locfcinfo.nargs = 2; /* We assume we are "strict" and need not worry about null inputs */ locfcinfo.arg[0] = PointerGetDatum(v); @@ -468,6 +474,7 @@ Datum bpcharlen(PG_FUNCTION_ARGS) { BpChar *arg = PG_GETARG_BPCHAR_P(0); + #ifdef MULTIBYTE unsigned char *s; int len, @@ -656,7 +663,7 @@ bpcharcmp(PG_FUNCTION_ARGS) /* * bpchar needs a specialized hash function because we want to ignore - * trailing blanks in comparisons. (varchar can use plain hashvarlena.) + * trailing blanks in comparisons. (varchar can use plain hashvarlena.) */ Datum hashbpchar(PG_FUNCTION_ARGS) @@ -685,7 +692,8 @@ hashbpchar(PG_FUNCTION_ARGS) Datum varcharlen(PG_FUNCTION_ARGS) { - VarChar *arg = PG_GETARG_VARCHAR_P(0); + VarChar *arg = PG_GETARG_VARCHAR_P(0); + #ifdef MULTIBYTE unsigned char *s; int len, @@ -711,7 +719,7 @@ varcharlen(PG_FUNCTION_ARGS) Datum varcharoctetlen(PG_FUNCTION_ARGS) { - VarChar *arg = PG_GETARG_VARCHAR_P(0); + VarChar *arg = PG_GETARG_VARCHAR_P(0); PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ); } @@ -728,8 +736,8 @@ varcharoctetlen(PG_FUNCTION_ARGS) Datum varchareq(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; bool result; @@ -751,8 +759,8 @@ varchareq(PG_FUNCTION_ARGS) Datum varcharne(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; bool result; @@ -774,8 +782,8 @@ varcharne(PG_FUNCTION_ARGS) Datum varcharlt(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -794,8 +802,8 @@ varcharlt(PG_FUNCTION_ARGS) Datum varcharle(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -814,8 +822,8 @@ varcharle(PG_FUNCTION_ARGS) Datum varchargt(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -834,8 +842,8 @@ varchargt(PG_FUNCTION_ARGS) Datum varcharge(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; @@ -854,8 +862,8 @@ varcharge(PG_FUNCTION_ARGS) Datum varcharcmp(PG_FUNCTION_ARGS) { - VarChar *arg1 = PG_GETARG_VARCHAR_P(0); - VarChar *arg2 = PG_GETARG_VARCHAR_P(1); + VarChar *arg1 = PG_GETARG_VARCHAR_P(0); + VarChar *arg2 = PG_GETARG_VARCHAR_P(1); int len1, len2; int cmp; diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index ba1ed5350ed..efa6ab65527 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.68 2001/02/10 02:31:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.69 2001/03/22 03:59:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -202,6 +202,7 @@ Datum textlen(PG_FUNCTION_ARGS) { text *t = PG_GETARG_TEXT_P(0); + #ifdef MULTIBYTE unsigned char *s; int len, @@ -236,10 +237,10 @@ textlen(PG_FUNCTION_ARGS) Datum textoctetlen(PG_FUNCTION_ARGS) { - struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0); + struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0); if (!VARATT_IS_EXTERNAL(t)) - PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ); + PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ); PG_RETURN_INT32(t->va_content.va_external.va_extsize); } @@ -320,9 +321,11 @@ text_substr(PG_FUNCTION_ARGS) int32 n = PG_GETARG_INT32(2); text *ret; int len; + #ifdef MULTIBYTE int i; char *p; + #endif len = VARSIZE(string) - VARHDRSZ; @@ -392,9 +395,11 @@ textpos(PG_FUNCTION_ARGS) len2; pg_wchar *p1, *p2; + #ifdef MULTIBYTE pg_wchar *ps1, *ps2; + #endif if (VARSIZE(t2) <= VARHDRSZ) @@ -843,7 +848,7 @@ text_name(PG_FUNCTION_ARGS) /* Truncate oversize input */ if (len >= NAMEDATALEN) - len = NAMEDATALEN-1; + len = NAMEDATALEN - 1; #ifdef STRINGDEBUG printf("text- convert string length %d (%d) ->%d\n", |