diff options
Diffstat (limited to 'src/backend/utils')
61 files changed, 2252 insertions, 2084 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 2ca61704076..b1fc5574981 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.35 1999/05/12 12:47:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.36 1999/05/25 16:11:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,7 +34,7 @@ static char *aclparse(char *s, AclItem *aip, unsigned *modechg); /* * getid * Consumes the first alphanumeric string (identifier) found in string - * 's', ignoring any leading white space. If it finds a double quote + * 's', ignoring any leading white space. If it finds a double quote * it returns the word inside the quotes. * * RETURNS: @@ -48,7 +48,7 @@ getid(char *s, char *n) { unsigned len; char *id; - int in_quotes = 0; + int in_quotes = 0; Assert(s && n); @@ -63,7 +63,7 @@ getid(char *s, char *n) for (id = s, len = 0; isalnum(*s) || *s == '_' || in_quotes; ++len, ++s) { - if (in_quotes && *s == '"') + if (in_quotes && *s == '"') { len--; in_quotes = 0; diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 41f02797a7f..b0e59e3ff08 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.42 1999/05/10 00:45:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.43 1999/05/25 16:11:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -200,7 +200,7 @@ array_in(char *string, /* input array in external form */ /* array not a large object */ dataPtr = (char *) _ReadArrayStr(p, nitems, ndim, dim, &inputproc, typelem, typmod, typdelim, typlen, typbyval, typalign, - &nbytes); + &nbytes); nbytes += ARR_OVERHEAD(ndim); retval = (ArrayType *) palloc(nbytes); MemSet(retval, 0, nbytes); @@ -246,7 +246,7 @@ array_in(char *string, /* input array in external form */ } /*----------------------------------------------------------------------------- - * _ArrayCount + * _ArrayCount * Counts the number of dimensions and the *dim array for an array string. * The syntax for array input is C-like nested curly braces *----------------------------------------------------------------------------- @@ -1284,19 +1284,19 @@ array_assgn(ArrayType *array, * Map an arbitrary function to an array and return a new array with * same dimensions and the source elements transformed by fn(). */ -ArrayType * +ArrayType * array_map(ArrayType *v, Oid type, - char * (*fn)(), + char *(*fn) (), Oid retType, int nargs, ...) { - ArrayType *result; - void *args[4]; - char **values; - char *elt; - int *dim; + ArrayType *result; + void *args[4]; + char **values; + char *elt; + int *dim; int ndim; int nitems; int i; @@ -1308,26 +1308,23 @@ array_map(ArrayType *v, char typdelim; Oid typelem; Oid proc; - char typalign; - char *s; - char *p; + char typalign; + char *s; + char *p; va_list ap; /* Large objects not yet supported */ - if (ARR_IS_LO(v) == true) { + if (ARR_IS_LO(v) == true) elog(ERROR, "array_map: large objects not supported"); - } /* Check nargs */ - if ((nargs < 0) || (nargs > 4)) { + if ((nargs < 0) || (nargs > 4)) elog(ERROR, "array_map: invalid nargs: %d", nargs); - } /* Copy extra args to local variable */ va_start(ap, nargs); - for (i=0; i<nargs; i++) { + for (i = 0; i < nargs; i++) args[i] = (void *) va_arg(ap, char *); - } va_end(ap); /* Lookup source and result types. Unneeded variables are reused. */ @@ -1336,14 +1333,13 @@ array_map(ArrayType *v, system_cache_lookup(retType, false, &typlen, &typbyval, &typdelim, &typelem, &proc, &typalign); - ndim = ARR_NDIM(v); - dim = ARR_DIMS(v); + ndim = ARR_NDIM(v); + dim = ARR_DIMS(v); nitems = getNitems(ndim, dim); /* Check for empty array */ - if (nitems <= 0) { + if (nitems <= 0) return v; - } /* Allocate temporary array for new values */ values = (char **) palloc(nitems * sizeof(char *)); @@ -1351,64 +1347,74 @@ array_map(ArrayType *v, /* Loop over source data */ s = (char *) ARR_DATA_PTR(v); - for (i=0; i<nitems; i++) { + for (i = 0; i < nitems; i++) + { /* Get source element */ - if (inp_typbyval) { - switch (inp_typlen) { - case 1: - elt = (char *) ((int) (*(char *) s)); - break; - case 2: - elt = (char *) ((int) (*(int16 *) s)); - break; - case 3: - case 4: - default: - elt = (char *) (*(int32 *) s); - break; + if (inp_typbyval) + { + switch (inp_typlen) + { + case 1: + elt = (char *) ((int) (*(char *) s)); + break; + case 2: + elt = (char *) ((int) (*(int16 *) s)); + break; + case 3: + case 4: + default: + elt = (char *) (*(int32 *) s); + break; } s += inp_typlen; - } else { + } + else + { elt = s; - if (inp_typlen > 0) { + if (inp_typlen > 0) s += inp_typlen; - } else { + else s += INTALIGN(*(int32 *) s); - } } /* - * Apply the given function to source elt and extra args. - * nargs is the number of extra args taken by fn(). + * Apply the given function to source elt and extra args. nargs is + * the number of extra args taken by fn(). */ - switch (nargs) { - case 0: - p = (char *) (*fn) (elt); - break; - case 1: - p = (char *) (*fn) (elt, args[0]); - break; - case 2: - p = (char *) (*fn) (elt, args[0], args[1]); - break; - case 3: - p = (char *) (*fn) (elt, args[0], args[1], args[2]); - break; - case 4: - default: - p = (char *) (*fn) (elt, args[0], args[1], args[2], args[3]); - break; + switch (nargs) + { + case 0: + p = (char *) (*fn) (elt); + break; + case 1: + p = (char *) (*fn) (elt, args[0]); + break; + case 2: + p = (char *) (*fn) (elt, args[0], args[1]); + break; + case 3: + p = (char *) (*fn) (elt, args[0], args[1], args[2]); + break; + case 4: + default: + p = (char *) (*fn) (elt, args[0], args[1], args[2], args[3]); + break; } /* Update values and total result size */ - if (typbyval) { + if (typbyval) + { values[i] = (char *) p; nbytes += typlen; - } else { - int len; + } + else + { + int len; + len = ((typlen > 0) ? typlen : INTALIGN(*(int32 *) p)); /* Needed because _CopyArrayEls tries to pfree items */ - if (p == elt) { + if (p == elt) + { p = (char *) palloc(len); memcpy(p, elt, len); } diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index a6e9711a463..9f74645d38a 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.27 1998/10/12 04:07:44 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.28 1999/05/25 16:11:52 momjian Exp $ */ #include <stdio.h> @@ -681,8 +681,8 @@ cash_words_out(Cash *value) Cash m1; Cash m2; Cash m3; - text *result; - + text *result; + /* work with positive numbers */ if (*value < 0) { diff --git a/src/backend/utils/adt/char.c b/src/backend/utils/adt/char.c index 2984555af02..4c6e3711065 100644 --- a/src/backend/utils/adt/char.c +++ b/src/backend/utils/adt/char.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.21 1999/02/13 23:19:05 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.22 1999/05/25 16:11:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -163,10 +163,10 @@ text_char(text *arg1) text * char_text(int8 arg1) { - text *result; + text *result; - result = palloc(VARHDRSZ+1); - VARSIZE(result) = VARHDRSZ+1; + result = palloc(VARHDRSZ + 1); + VARSIZE(result) = VARHDRSZ + 1; *(VARDATA(result)) = arg1; return result; diff --git a/src/backend/utils/adt/chunk.c b/src/backend/utils/adt/chunk.c index eb692526f89..a9a49fe940e 100644 --- a/src/backend/utils/adt/chunk.c +++ b/src/backend/utils/adt/chunk.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.19 1999/02/13 23:19:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.20 1999/05/25 16:11:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -115,7 +115,7 @@ _ChunkArray(int fd, } /*-------------------------------------------------------------------------- - * GetChunkSize + * GetChunkSize * given an access pattern and array dimensionality etc, this program * returns the dimensions of the chunk in "d" *----------------------------------------------------------------------- @@ -160,7 +160,7 @@ GetChunkSize(FILE *fd, } /*------------------------------------------------------------------------- - * _FindBestChunk + * _FindBestChunk * This routine does most of the number crunching to compute the * optimal chunk shape. * Called by GetChunkSize @@ -213,7 +213,7 @@ _FindBestChunk(int size, } /*---------------------------------------------------------------------- - * get_next + * get_next * Called by _GetBestChunk to get the next tuple in the lexicographic order *--------------------------------------------------------------------- */ @@ -420,7 +420,7 @@ seek_and_read(int pos, int size, char *buff, int fp, int from) #endif /* LOARRAY */ /*---------------------------------------------------------------------------- - * _ReadChunkArray + * _ReadChunkArray * returns the subarray specified bu the range indices "st" and "endp" * from the chunked array stored in file "fp" *--------------------------------------------------------------------------- @@ -620,7 +620,7 @@ _ReadChunkArray(int *st, } /*------------------------------------------------------------------------ - * _ReadChunkArray1El + * _ReadChunkArray1El * returns one element of the chunked array as specified by the index "st" * the chunked file descriptor is "fp" *------------------------------------------------------------------------- diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index e582ebc2c65..7ad18a067e4 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.31 1999/03/14 16:44:01 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.32 1999/05/25 16:11:56 momjian Exp $ * * NOTES * This code is actually (almost) unused. @@ -988,6 +988,7 @@ isreltime(char *str) return 0; } /* isreltime() */ + #endif #ifdef NOT_USED diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index aad1cec4eb0..84163583ef8 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.32 1999/04/26 04:42:48 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.33 1999/05/25 16:11:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -311,7 +311,7 @@ abstime_date(AbsoluteTime abstime) * and then convert again to try to get the time zones correct. */ static int -date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn) +date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn) { struct tm *tx; time_t utime; @@ -358,7 +358,7 @@ date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn) /* tm_gmtoff is Sun/DEC-ism */ *tzp = -(tm->tm_gmtoff); if (tzn != NULL) - *tzn = (char *)tm->tm_zone; + *tzn = (char *) tm->tm_zone; #elif defined(HAVE_INT_TIMEZONE) #ifdef __CYGWIN__ *tzp = (tm->tm_isdst ? (_timezone - 3600) : _timezone); @@ -393,13 +393,13 @@ date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn) #ifdef DATEDEBUG #if defined(HAVE_TM_ZONE) - printf("date2tm- %d.%02d.%02d %02d:%02d:%02.0f (%d %s) dst=%d\n", - tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, (double) tm->tm_sec, - *tzp, tm->tm_zone, tm->tm_isdst); + printf("date2tm- %d.%02d.%02d %02d:%02d:%02.0f (%d %s) dst=%d\n", + tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, (double) tm->tm_sec, + *tzp, tm->tm_zone, tm->tm_isdst); #elif defined(HAVE_INT_TIMEZONE) - printf("date2tm- %d.%02d.%02d %02d:%02d:%02.0f (%d %s %s) dst=%d\n", - tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, (double) tm->tm_sec, - *tzp, tzname[0], tzname[1], tm->tm_isdst); + printf("date2tm- %d.%02d.%02d %02d:%02d:%02.0f (%d %s %s) dst=%d\n", + tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, (double) tm->tm_sec, + *tzp, tzname[0], tzname[1], tm->tm_isdst); #endif #endif diff --git a/src/backend/utils/adt/dt.c b/src/backend/utils/adt/dt.c index a055a03df80..9fb75cb5687 100644 --- a/src/backend/utils/adt/dt.c +++ b/src/backend/utils/adt/dt.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.70 1999/05/01 17:14:56 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.71 1999/05/25 16:12:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,9 +34,9 @@ static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); 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 DecodeSpecial(int field, char *lowtoken, int *val); static int DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, double *fsec); @@ -55,9 +55,9 @@ static int tm2timespan(struct tm * tm, double fsec, TimeSpan *span); #define USE_DATE_CACHE 1 #define ROUND_ALL 0 -int day_tab[2][13] = { +int day_tab[2][13] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}}; +{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}}; char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -2090,7 +2090,7 @@ static datetkn datetktbl[] = { {"idlw", TZ, NEG(72)}, /* Intl. Date Line, West */ {LATE, RESERV, DTK_LATE}, /* "infinity" reserved for "late time" */ {INVALID, RESERV, DTK_INVALID}, - /* "invalid" reserved for invalid time */ + /* "invalid" reserved for invalid time */ {"ist", TZ, 12}, /* Israel */ {"it", TZ, 21}, /* Iran Time */ {"jan", MONTH, 1}, @@ -2438,7 +2438,7 @@ datetime2tm(DateTime dt, int *tzp, struct tm * tm, double *fsec, char **tzn) *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ if (tzn != NULL) - *tzn = (char *)tm->tm_zone; + *tzn = (char *) tm->tm_zone; #elif defined(HAVE_INT_TIMEZONE) #ifdef __CYGWIN__ *tzp = (tm->tm_isdst ? (_timezone - 3600) : _timezone); @@ -2833,8 +2833,10 @@ DecodeDateTime(char **field, int *ftype, int nf, case DTK_NUMBER: flen = strlen(field[i]); - /* long numeric string and either no date or no time read yet? - * then interpret as a concatenated date or time... */ + /* + * long numeric string and either no date or no time read + * yet? then interpret as a concatenated date or time... + */ if ((flen > 4) && !((fmask & DTK_DATE_M) && (fmask & DTK_TIME_M))) { if (DecodeNumberField(flen, field[i], fmask, &tmask, tm, fsec, &is2digits) != 0) @@ -2926,10 +2928,14 @@ DecodeDateTime(char **field, int *ftype, int nf, #ifdef DATEDEBUG printf("DecodeDateTime- month field %s value is %d\n", field[i], val); #endif - /* already have a (numeric) month? then see if we can substitute... */ - if ((fmask & DTK_M(MONTH)) && (! haveTextMonth) - && (!(fmask & DTK_M(DAY))) - && ((tm->tm_mon >= 1) && (tm->tm_mon <= 31))) + + /* + * already have a (numeric) month? then see if we + * can substitute... + */ + if ((fmask & DTK_M(MONTH)) && (!haveTextMonth) + && (!(fmask & DTK_M(DAY))) + && ((tm->tm_mon >= 1) && (tm->tm_mon <= 31))) { tm->tm_mday = tm->tm_mon; tmask = DTK_M(DAY); @@ -2942,7 +2948,11 @@ DecodeDateTime(char **field, int *ftype, int nf, break; case DTZMOD: - /* daylight savings time modifier (solves "MET DST" syntax) */ + + /* + * daylight savings time modifier (solves "MET + * DST" syntax) + */ tmask |= DTK_M(DTZ); tm->tm_isdst = 1; if (tzp == NULL) @@ -3010,7 +3020,7 @@ DecodeDateTime(char **field, int *ftype, int nf, 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); + elog(ERROR, "Inconsistant use of year %04d and 'BC'", tm->tm_year); } else if (is2digits) { @@ -3039,18 +3049,22 @@ DecodeDateTime(char **field, int *ftype, int nf, if ((fmask & DTK_DATE_M) != DTK_DATE_M) return ((fmask & DTK_TIME_M) == DTK_TIME_M) ? 1 : -1; - /* check for valid day of month, now that we know for sure the month and year... */ + /* + * check for valid day of month, now that we know for sure the + * month and year... + */ if ((tm->tm_mday < 1) || (tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])) return -1; /* timezone not specified? then find local timezone if possible */ if (((fmask & DTK_DATE_M) == DTK_DATE_M) - && (tzp != NULL) && (!(fmask & DTK_M(TZ)))) + && (tzp != NULL) && (!(fmask & DTK_M(TZ)))) { + /* - * daylight savings time modifier but no standard timezone? then - * error + * daylight savings time modifier but no standard timezone? + * then error */ if (fmask & DTK_M(DTZMOD)) return -1; @@ -3066,7 +3080,8 @@ DecodeDateTime(char **field, int *ftype, int nf, tm->tm_mon += 1; #if defined(HAVE_TM_ZONE) - *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */ + *tzp = -(tm->tm_gmtoff); /* tm_gmtoff is + * Sun/DEC-ism */ #elif defined(HAVE_INT_TIMEZONE) #ifdef __CYGWIN__ *tzp = ((tm->tm_isdst > 0) ? (_timezone - 3600) : _timezone); @@ -3077,7 +3092,7 @@ DecodeDateTime(char **field, int *ftype, int nf, #error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined #endif -#else /* !USE_POSIX_TIME */ +#else /* !USE_POSIX_TIME */ *tzp = CTimeZone; #endif } @@ -3214,8 +3229,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf, int *dtype, struct tm * tm, dou tm->tm_hour += 12; if (((tm->tm_hour < 0) || (tm->tm_hour > 23)) - || ((tm->tm_min < 0) || (tm->tm_min > 59)) - || ((tm->tm_sec < 0) || ((tm->tm_sec + *fsec) >= 60))) + || ((tm->tm_min < 0) || (tm->tm_min > 59)) + || ((tm->tm_sec < 0) || ((tm->tm_sec + *fsec) >= 60))) return -1; if ((fmask & DTK_TIME_M) != DTK_TIME_M) @@ -3344,7 +3359,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct tm * tm) 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); + elog(ERROR, "Inconsistant use of year %04d and 'BC'", tm->tm_year); } else if (is2digits) { @@ -3449,11 +3464,12 @@ DecodeNumber(int flen, char *str, int fmask, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); } - /* Enough digits to be unequivocal year? - * Used to test for 4 digits or more, - * but we now test first for a three-digit doy - * so anything bigger than two digits had better be - * an explicit year. - thomas 1999-01-09 + + /* + * Enough digits to be unequivocal year? Used to test for 4 digits or + * more, but we now test first for a three-digit doy so anything + * bigger than two digits had better be an explicit year. - thomas + * 1999-01-09 */ else if (flen > 2) { @@ -3464,7 +3480,7 @@ DecodeNumber(int flen, char *str, int fmask, /* already have a year? then see if we can substitute... */ if ((fmask & DTK_M(YEAR)) && (!(fmask & DTK_M(DAY))) - && ((tm->tm_year >= 1) && (tm->tm_year <= 31))) + && ((tm->tm_year >= 1) && (tm->tm_year <= 31))) { tm->tm_mday = tm->tm_year; *tmask = DTK_M(DAY); @@ -3543,7 +3559,7 @@ DecodeNumber(int flen, char *str, int fmask, */ static int DecodeNumberField(int len, char *str, int fmask, - int *tmask, struct tm * tm, double *fsec, int *is2digits) + int *tmask, struct tm * tm, double *fsec, int *is2digits) { char *cp; diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index 5e4e20d257f..5f2a4f15232 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.41 1999/04/20 00:26:32 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.42 1999/05/25 16:12:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -955,12 +955,12 @@ i2tof(int16 num) text * float8_text(float64 num) { - text *result; - int len; - char *str; + text *result; + int len; + char *str; str = float8out(num); - len = (strlen(str)+VARHDRSZ); + len = (strlen(str) + VARHDRSZ); result = palloc(len); @@ -978,9 +978,9 @@ float8_text(float64 num) float64 text_float8(text *string) { - float64 result; - int len; - char *str; + float64 result; + int len; + char *str; len = (VARSIZE(string) - VARHDRSZ); str = palloc(len + 1); @@ -1000,12 +1000,12 @@ text_float8(text *string) text * float4_text(float32 num) { - text *result; - int len; - char *str; + text *result; + int len; + char *str; str = float4out(num); - len = (strlen(str)+VARHDRSZ); + len = (strlen(str) + VARHDRSZ); result = palloc(len); @@ -1023,9 +1023,9 @@ float4_text(float32 num) float32 text_float4(text *string) { - float32 result; - int len; - char *str; + float32 result; + int len; + char *str; len = (VARSIZE(string) - VARHDRSZ); str = palloc(len + 1); @@ -1154,7 +1154,8 @@ dpow(float64 arg1, float64 arg2) #endif *result = (float64data) pow(tmp1, tmp2); #ifndef finite - if (errno != 0) /* on some machines both EDOM & ERANGE can occur */ + if (errno != 0) /* on some machines both EDOM & ERANGE can + * occur */ #else if (!finite(*result)) #endif diff --git a/src/backend/utils/adt/inet_net_ntop.c b/src/backend/utils/adt/inet_net_ntop.c index 8c185dc83ca..11a0cb9363a 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.5 1999/05/25 05:29:38 momjian Exp $"; +static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.6 1999/05/25 16:12:04 momjian Exp $"; #endif @@ -40,9 +40,9 @@ static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.5 1999/05/25 05:29:38 momj #endif static char *inet_net_ntop_ipv4(const u_char *src, int bits, - char *dst, size_t size); + char *dst, size_t size); static char *inet_cidr_ntop_ipv4(const u_char *src, int bits, - char *dst, size_t size); + char *dst, size_t size); /* * char * @@ -59,7 +59,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; @@ -162,7 +162,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; @@ -186,10 +186,11 @@ inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) static char * inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { - char *odst = dst; - char *t; - size_t len = 4; - int b, tb; + char *odst = dst; + char *t; + size_t len = 4; + int b, + tb; if (bits < 0 || bits > 32) { @@ -218,7 +219,7 @@ inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) *dst++ = '.'; *dst = '\0'; } - size -= (size_t)(dst - t); + size -= (size_t) (dst - t); } /* don't print masklen if 32 bits */ @@ -232,7 +233,7 @@ inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) return (odst); - emsgsize: +emsgsize: errno = EMSGSIZE; return (NULL); } diff --git a/src/backend/utils/adt/inet_net_pton.c b/src/backend/utils/adt/inet_net_pton.c index ae3036c3ca6..bcc9ff681a2 100644 --- a/src/backend/utils/adt/inet_net_pton.c +++ b/src/backend/utils/adt/inet_net_pton.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_pton.c,v 1.7 1999/02/03 21:17:27 momjian Exp $"; +static const char rcsid[] = "$Id: inet_net_pton.c,v 1.8 1999/05/25 16:12:05 momjian Exp $"; #endif @@ -58,8 +58,8 @@ static int inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size); * Paul Vixie (ISC), June 1996 * * Changes: - * I added the inet_cidr_pton function (also from Paul) and changed - * the names to reflect their current use. + * I added the inet_cidr_pton function (also from Paul) and changed + * the names to reflect their current use. * */ int @@ -67,10 +67,10 @@ inet_net_pton(int af, const char *src, void *dst, size_t size) { switch (af) { - case AF_INET: + case AF_INET: return size == -1 ? - inet_net_pton_ipv4(src, dst) : - inet_cidr_pton_ipv4(src, dst, size); + inet_net_pton_ipv4(src, dst) : + inet_cidr_pton_ipv4(src, dst, size); default: errno = EAFNOSUPPORT; return (-1); @@ -108,14 +108,16 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size) ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit(src[1])) { + && isascii(src[1]) && isxdigit(src[1])) + { /* Hexadecimal: Eat nybble string. */ if (size <= 0) goto emsgsize; dirty = 0; tmp = 0; - src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) { + src++; /* skip x or X. */ + while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) + { if (isupper(ch)) ch = tolower(ch); n = strchr(xdigits, ch) - xdigits; @@ -124,14 +126,16 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size) tmp = n; else tmp = (tmp << 4) | n; - if (++dirty == 2) { + if (++dirty == 2) + { if (size-- <= 0) goto emsgsize; *dst++ = (u_char) tmp; dirty = 0; } } - if (dirty) { /* Odd trailing nybble? */ + if (dirty) + { /* Odd trailing nybble? */ if (size-- <= 0) goto emsgsize; *dst++ = (u_char) (tmp << 4); @@ -234,27 +238,30 @@ emsgsize: /* * int * inet_net_pton(af, src, dst, *bits) - * convert network address from presentation to network format. - * accepts inet_pton()'s input for this "af" plus trailing "/CIDR". - * "dst" is assumed large enough for its "af". "bits" is set to the - * /CIDR prefix length, which can have defaults (like /32 for IPv4). + * convert network address from presentation to network format. + * accepts inet_pton()'s input for this "af" plus trailing "/CIDR". + * "dst" is assumed large enough for its "af". "bits" is set to the + * /CIDR prefix length, which can have defaults (like /32 for IPv4). * return: - * -1 if an error occurred (inspect errno; ENOENT means bad format). - * 0 if successful conversion occurred. - * note: - * 192.5.5.1/28 has a nonzero host part, which means it isn't a network - * as called for by inet_cidr_pton() but it can be a host address with - * an included netmask. + * -1 if an error occurred (inspect errno; ENOENT means bad format). + * 0 if successful conversion occurred. + * note: + * 192.5.5.1/28 has a nonzero host part, which means it isn't a network + * as called for by inet_cidr_pton() but it can be a host address with + * an included netmask. * author: - * Paul Vixie (ISC), October 1998 + * Paul Vixie (ISC), October 1998 */ static int inet_net_pton_ipv4(const char *src, u_char *dst) { static const char digits[] = "0123456789"; const u_char *odst = dst; - int n, ch, tmp, bits; - size_t size = 4; + int n, + ch, + tmp, + bits; + size_t size = 4; /* Get the mantissa. */ while (ch = *src++, (isascii(ch) && isdigit(ch))) @@ -283,7 +290,7 @@ inet_net_pton_ipv4(const char *src, u_char *dst) if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ + ch = *src++; /* Skip over the /. */ bits = 0; do { @@ -325,11 +332,11 @@ inet_net_pton_ipv4(const char *src, u_char *dst) return bits; - enoent: +enoent: errno = ENOENT; return (-1); - emsgsize: +emsgsize: errno = EMSGSIZE; return (-1); } diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 11363ba6459..289aed674ba 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -44,21 +44,22 @@ int8in(char *str) if (!PointerIsValid(str)) elog(ERROR, "Bad (null) int8 external representation", NULL); - /* Do our own scan, rather than relying on sscanf which might be + /* + * Do our own scan, rather than relying on sscanf which might be * broken for long long. NOTE: this will not detect int64 overflow... * but sscanf doesn't either... */ - while (*ptr && isspace(*ptr)) /* skip leading spaces */ + while (*ptr && isspace(*ptr)) /* skip leading spaces */ ptr++; - if (*ptr == '-') /* handle sign */ + if (*ptr == '-') /* handle sign */ sign = -1, ptr++; else if (*ptr == '+') ptr++; - if (! isdigit(*ptr)) /* require at least one digit */ + if (!isdigit(*ptr)) /* require at least one digit */ elog(ERROR, "Bad int8 external representation '%s'", str); - while (*ptr && isdigit(*ptr)) /* process digits */ + while (*ptr && isdigit(*ptr)) /* process digits */ tmp = tmp * 10 + (*ptr++ - '0'); - if (*ptr) /* trailing junk? */ + if (*ptr) /* trailing junk? */ elog(ERROR, "Bad int8 external representation '%s'", str); *result = (sign < 0) ? -tmp : tmp; @@ -70,7 +71,7 @@ int8in(char *str) /* int8out() */ char * -int8out(int64 *val) +int8out(int64 * val) { char *result; @@ -99,37 +100,37 @@ int8out(int64 *val) * Is val1 relop val2? */ bool -int8eq(int64 *val1, int64 *val2) +int8eq(int64 * val1, int64 * val2) { return *val1 == *val2; } /* int8eq() */ bool -int8ne(int64 *val1, int64 *val2) +int8ne(int64 * val1, int64 * val2) { return *val1 != *val2; } /* int8ne() */ bool -int8lt(int64 *val1, int64 *val2) +int8lt(int64 * val1, int64 * val2) { return *val1 < *val2; } /* int8lt() */ bool -int8gt(int64 *val1, int64 *val2) +int8gt(int64 * val1, int64 * val2) { return *val1 > *val2; } /* int8gt() */ bool -int8le(int64 *val1, int64 *val2) +int8le(int64 * val1, int64 * val2) { return *val1 <= *val2; } /* int8le() */ bool -int8ge(int64 *val1, int64 *val2) +int8ge(int64 * val1, int64 * val2) { return *val1 >= *val2; } /* int8ge() */ @@ -139,37 +140,37 @@ int8ge(int64 *val1, int64 *val2) * Is 64-bit val1 relop 32-bit val2? */ bool -int84eq(int64 *val1, int32 val2) +int84eq(int64 * val1, int32 val2) { return *val1 == val2; } /* int84eq() */ bool -int84ne(int64 *val1, int32 val2) +int84ne(int64 * val1, int32 val2) { return *val1 != val2; } /* int84ne() */ bool -int84lt(int64 *val1, int32 val2) +int84lt(int64 * val1, int32 val2) { return *val1 < val2; } /* int84lt() */ bool -int84gt(int64 *val1, int32 val2) +int84gt(int64 * val1, int32 val2) { return *val1 > val2; } /* int84gt() */ bool -int84le(int64 *val1, int32 val2) +int84le(int64 * val1, int32 val2) { return *val1 <= val2; } /* int84le() */ bool -int84ge(int64 *val1, int32 val2) +int84ge(int64 * val1, int32 val2) { return *val1 >= val2; } /* int84ge() */ @@ -179,37 +180,37 @@ int84ge(int64 *val1, int32 val2) * Is 32-bit val1 relop 64-bit val2? */ bool -int48eq(int32 val1, int64 *val2) +int48eq(int32 val1, int64 * val2) { return val1 == *val2; } /* int48eq() */ bool -int48ne(int32 val1, int64 *val2) +int48ne(int32 val1, int64 * val2) { return val1 != *val2; } /* int48ne() */ bool -int48lt(int32 val1, int64 *val2) +int48lt(int32 val1, int64 * val2) { return val1 < *val2; } /* int48lt() */ bool -int48gt(int32 val1, int64 *val2) +int48gt(int32 val1, int64 * val2) { return val1 > *val2; } /* int48gt() */ bool -int48le(int32 val1, int64 *val2) +int48le(int32 val1, int64 * val2) { return val1 <= *val2; } /* int48le() */ bool -int48ge(int32 val1, int64 *val2) +int48ge(int32 val1, int64 * val2) { return val1 >= *val2; } /* int48ge() */ @@ -220,7 +221,7 @@ int48ge(int32 val1, int64 *val2) *---------------------------------------------------------*/ int64 * -int8um(int64 *val) +int8um(int64 * val) { int64 temp = 0; int64 *result = palloc(sizeof(int64)); @@ -235,7 +236,7 @@ int8um(int64 *val) int64 * -int8pl(int64 *val1, int64 *val2) +int8pl(int64 * val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -248,7 +249,7 @@ int8pl(int64 *val1, int64 *val2) } /* int8pl() */ int64 * -int8mi(int64 *val1, int64 *val2) +int8mi(int64 * val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -261,7 +262,7 @@ int8mi(int64 *val1, int64 *val2) } /* int8mi() */ int64 * -int8mul(int64 *val1, int64 *val2) +int8mul(int64 * val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -274,7 +275,7 @@ int8mul(int64 *val1, int64 *val2) } /* int8mul() */ int64 * -int8div(int64 *val1, int64 *val2) +int8div(int64 * val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -287,7 +288,7 @@ int8div(int64 *val1, int64 *val2) } /* int8div() */ int64 * -int8larger(int64 *val1, int64 *val2) +int8larger(int64 * val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -300,7 +301,7 @@ int8larger(int64 *val1, int64 *val2) } /* int8larger() */ int64 * -int8smaller(int64 *val1, int64 *val2) +int8smaller(int64 * val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -314,7 +315,7 @@ int8smaller(int64 *val1, int64 *val2) int64 * -int84pl(int64 *val1, int32 val2) +int84pl(int64 * val1, int32 val2) { int64 *result = palloc(sizeof(int64)); @@ -327,7 +328,7 @@ int84pl(int64 *val1, int32 val2) } /* int84pl() */ int64 * -int84mi(int64 *val1, int32 val2) +int84mi(int64 * val1, int32 val2) { int64 *result = palloc(sizeof(int64)); @@ -340,7 +341,7 @@ int84mi(int64 *val1, int32 val2) } /* int84mi() */ int64 * -int84mul(int64 *val1, int32 val2) +int84mul(int64 * val1, int32 val2) { int64 *result = palloc(sizeof(int64)); @@ -353,7 +354,7 @@ int84mul(int64 *val1, int32 val2) } /* int84mul() */ int64 * -int84div(int64 *val1, int32 val2) +int84div(int64 * val1, int32 val2) { int64 *result = palloc(sizeof(int64)); @@ -367,7 +368,7 @@ int84div(int64 *val1, int32 val2) int64 * -int48pl(int32 val1, int64 *val2) +int48pl(int32 val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -380,7 +381,7 @@ int48pl(int32 val1, int64 *val2) } /* int48pl() */ int64 * -int48mi(int32 val1, int64 *val2) +int48mi(int32 val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -393,7 +394,7 @@ int48mi(int32 val1, int64 *val2) } /* int48mi() */ int64 * -int48mul(int32 val1, int64 *val2) +int48mul(int32 val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -406,7 +407,7 @@ int48mul(int32 val1, int64 *val2) } /* int48mul() */ int64 * -int48div(int32 val1, int64 *val2) +int48div(int32 val1, int64 * val2) { int64 *result = palloc(sizeof(int64)); @@ -434,7 +435,7 @@ int48(int32 val) } /* int48() */ int32 -int84(int64 *val) +int84(int64 * val) { int32 result; @@ -442,6 +443,7 @@ int84(int64 *val) elog(ERROR, "Invalid (null) int64, can't convert int8 to int4", NULL); #if NOT_USED + /* * Hmm. This conditional always tests true on my i686/linux box. It's * a gcc compiler bug, or I'm missing something obvious, which is more @@ -449,8 +451,8 @@ int84(int64 *val) */ if ((*val < INT_MIN) || (*val > INT_MAX)) #endif - if ((*val < (-pow(2, 31) + 1)) || (*val > (pow(2, 31) - 1))) - elog(ERROR, "int8 conversion to int4 is out of range", NULL); + if ((*val < (-pow(2, 31) + 1)) || (*val > (pow(2, 31) - 1))) + elog(ERROR, "int8 conversion to int4 is out of range", NULL); result = *val; @@ -471,7 +473,7 @@ int28 (int16 val) } /* int28() */ int16 -int82(int64 *val) +int82(int64 * val) { int16 result; @@ -489,7 +491,7 @@ int82(int64 *val) #endif float64 -i8tod(int64 *val) +i8tod(int64 * val) { float64 result = palloc(sizeof(float64data)); @@ -533,9 +535,9 @@ text_int8(text *str) elog(ERROR, "Bad (null) int8 external representation", NULL); len = (VARSIZE(str) - VARHDRSZ); - s = palloc(len+1); + s = palloc(len + 1); memmove(s, VARDATA(str), len); - *(s+len) = '\0'; + *(s + len) = '\0'; return int8in(s); } /* text_int8() */ @@ -544,7 +546,7 @@ text_int8(text *str) /* int8_text() */ text * -int8_text(int64 *val) +int8_text(int64 * val) { text *result; @@ -564,4 +566,3 @@ int8_text(int64 *val) return result; } /* int8out() */ - diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c index 6057fa2f154..14fc5314d0c 100644 --- a/src/backend/utils/adt/like.c +++ b/src/backend/utils/adt/like.c @@ -23,7 +23,7 @@ #include "utils/builtins.h" /* where the function declarations go */ #include "mb/pg_wchar.h" -static int like(pg_wchar *text, pg_wchar *p); +static int like(pg_wchar * text, pg_wchar * p); /* * interface routines called by the function manager @@ -38,7 +38,7 @@ static int like(pg_wchar *text, pg_wchar *p); charlen - the length of the string */ static bool -fixedlen_like(char *s, struct varlena *p, int charlen) +fixedlen_like(char *s, struct varlena * p, int charlen) { pg_wchar *sterm, *pterm; @@ -83,7 +83,7 @@ fixedlen_like(char *s, struct varlena *p, int charlen) } bool -namelike(NameData *n, struct varlena *p) +namelike(NameData *n, struct varlena * p) { if (!n) return FALSE; @@ -91,13 +91,13 @@ namelike(NameData *n, struct varlena *p) } bool -namenlike(NameData *s, struct varlena *p) +namenlike(NameData *s, struct varlena * p) { return !namelike(s, p); } bool -textlike(struct varlena *s, struct varlena *p) +textlike(struct varlena * s, struct varlena * p) { if (!s) return FALSE; @@ -105,13 +105,13 @@ textlike(struct varlena *s, struct varlena *p) } bool -textnlike(struct varlena *s, struct varlena *p) +textnlike(struct varlena * s, struct varlena * p) { return !textlike(s, p); } -/* $Revision: 1.23 $ +/* $Revision: 1.24 $ ** "like.c" A first attempt at a LIKE operator for Postgres95. ** ** Originally written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. @@ -146,11 +146,11 @@ textnlike(struct varlena *s, struct varlena *p) ** Match text and p, return LIKE_TRUE, LIKE_FALSE, or LIKE_ABORT. */ static int -DoMatch(pg_wchar *text, pg_wchar *p) +DoMatch(pg_wchar * text, pg_wchar * p) { int matched; - for (; *p && *text; text++, p++) + for (; *p && *text; text ++, p++) { switch (*p) { @@ -159,7 +159,7 @@ DoMatch(pg_wchar *text, pg_wchar *p) p++; /* FALLTHROUGH */ default: - if (*text != *p) + if (*text !=*p) return LIKE_FALSE; break; case '_': @@ -177,16 +177,16 @@ DoMatch(pg_wchar *text, pg_wchar *p) { /* Optimization to prevent most recursion */ if ((*text == *p || - *p == '\\' || *p == '%' || *p == '_') && + *p == '\\' || *p == '%' || *p == '_') && (matched = DoMatch(text, p)) != LIKE_FALSE) return matched; - text++; + text ++; } return LIKE_ABORT; } } - if (*text != '\0') + if (*text !='\0') return LIKE_ABORT; else { @@ -203,7 +203,7 @@ DoMatch(pg_wchar *text, pg_wchar *p) ** User-level routine. Returns TRUE or FALSE. */ static int -like(pg_wchar *text, pg_wchar *p) +like(pg_wchar * text, pg_wchar * p) { if (p[0] == '%' && p[1] == '\0') return TRUE; diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c index 957292af8ea..48dd19db94b 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. * - * $Id: mac.c,v 1.7 1999/03/22 05:00:57 momjian Exp $ + * $Id: mac.c,v 1.8 1999/05/25 16:12:08 momjian Exp $ */ #include <stdio.h> @@ -13,119 +13,119 @@ #include <utils/inet.h> manufacturer manufacturers[] = { - {0x00, 0x00, 0x0C, "Cisco"}, - {0x00, 0x00, 0x0E, "Fujitsu"}, - {0x00, 0x00, 0x0F, "NeXT"}, - {0x00, 0x00, 0x10, "Sytek"}, - {0x00, 0x00, 0x1D, "Cabletron"}, - {0x00, 0x00, 0x20, "DIAB"}, - {0x00, 0x00, 0x22, "Visual Technology"}, - {0x00, 0x00, 0x2A, "TRW"}, - {0x00, 0x00, 0x32, "GPT Limited"}, - {0x00, 0x00, 0x5A, "S & Koch"}, - {0x00, 0x00, 0x5E, "IANA"}, - {0x00, 0x00, 0x65, "Network General"}, - {0x00, 0x00, 0x6B, "MIPS"}, - {0x00, 0x00, 0x77, "MIPS"}, - {0x00, 0x00, 0x7A, "Ardent"}, - {0x00, 0x00, 0x89, "Cayman Systems"}, - {0x00, 0x00, 0x93, "Proteon"}, - {0x00, 0x00, 0x9F, "Ameristar Technology"}, - {0x00, 0x00, 0xA2, "Wellfleet"}, - {0x00, 0x00, 0xA3, "Network Application Technology"}, - {0x00, 0x00, 0xA6, "Network General"}, - {0x00, 0x00, 0xA7, "NCD"}, - {0x00, 0x00, 0xA9, "Network Systems"}, - {0x00, 0x00, 0xAA, "Xerox"}, - {0x00, 0x00, 0xB3, "CIMLinc"}, - {0x00, 0x00, 0xB7, "Dove Fastnet"}, - {0x00, 0x00, 0xBC, "Allen-Bradley"}, - {0x00, 0x00, 0xC0, "Western Digital"}, - {0x00, 0x00, 0xC5, "Farallon"}, - {0x00, 0x00, 0xC6, "Hewlett-Packard"}, - {0x00, 0x00, 0xC8, "Altos"}, - {0x00, 0x00, 0xC9, "Emulex"}, - {0x00, 0x00, 0xD7, "Dartmouth College"}, - {0x00, 0x00, 0xD8, "3Com (?)"}, - {0x00, 0x00, 0xDD, "Gould"}, - {0x00, 0x00, 0xDE, "Unigraph"}, - {0x00, 0x00, 0xE2, "Acer Counterpoint"}, - {0x00, 0x00, 0xEF, "Alantec"}, - {0x00, 0x00, 0xFD, "High Level Hardware"}, - {0x00, 0x01, 0x02, "BBN internal usage"}, - {0x00, 0x20, 0xAF, "3Com"}, - {0x00, 0x17, 0x00, "Kabel"}, - {0x00, 0x80, 0x64, "Wyse Technology"}, - {0x00, 0x80, 0x2B, "IMAC (?)"}, - {0x00, 0x80, 0x2D, "Xylogics, Inc."}, - {0x00, 0x80, 0x8C, "Frontier Software Development"}, - {0x00, 0x80, 0xC2, "IEEE 802.1 Committee"}, - {0x00, 0x80, 0xD3, "Shiva"}, - {0x00, 0xAA, 0x00, "Intel"}, - {0x00, 0xDD, 0x00, "Ungermann-Bass"}, - {0x00, 0xDD, 0x01, "Ungermann-Bass"}, - {0x02, 0x07, 0x01, "Racal InterLan"}, - {0x02, 0x04, 0x06, "BBN internal usage"}, - {0x02, 0x60, 0x86, "Satelcom MegaPac"}, - {0x02, 0x60, 0x8C, "3Com"}, - {0x02, 0xCF, 0x1F, "CMC"}, - {0x08, 0x00, 0x02, "3Com"}, - {0x08, 0x00, 0x03, "ACC"}, - {0x08, 0x00, 0x05, "Symbolics"}, - {0x08, 0x00, 0x08, "BBN"}, - {0x08, 0x00, 0x09, "Hewlett-Packard"}, - {0x08, 0x00, 0x0A, "Nestar Systems"}, - {0x08, 0x00, 0x0B, "Unisys"}, - {0x08, 0x00, 0x11, "Tektronix"}, - {0x08, 0x00, 0x14, "Excelan"}, - {0x08, 0x00, 0x17, "NSC"}, - {0x08, 0x00, 0x1A, "Data General"}, - {0x08, 0x00, 0x1B, "Data General"}, - {0x08, 0x00, 0x1E, "Apollo"}, - {0x08, 0x00, 0x20, "Sun"}, - {0x08, 0x00, 0x22, "NBI"}, - {0x08, 0x00, 0x25, "CDC"}, - {0x08, 0x00, 0x26, "Norsk Data"}, - {0x08, 0x00, 0x27, "PCS Computer Systems GmbH"}, - {0x08, 0x00, 0x28, "Texas Instruments"}, - {0x08, 0x00, 0x2B, "DEC"}, - {0x08, 0x00, 0x2E, "Metaphor"}, - {0x08, 0x00, 0x2F, "Prime Computer"}, - {0x08, 0x00, 0x36, "Intergraph"}, - {0x08, 0x00, 0x37, "Fujitsu-Xerox"}, - {0x08, 0x00, 0x38, "Bull"}, - {0x08, 0x00, 0x39, "Spider Systems"}, - {0x08, 0x00, 0x41, "DCA Digital Comm. Assoc."}, - {0x08, 0x00, 0x45, "Xylogics (?)"}, - {0x08, 0x00, 0x46, "Sony"}, - {0x08, 0x00, 0x47, "Sequent"}, - {0x08, 0x00, 0x49, "Univation"}, - {0x08, 0x00, 0x4C, "Encore"}, - {0x08, 0x00, 0x4E, "BICC"}, - {0x08, 0x00, 0x56, "Stanford University"}, - {0x08, 0x00, 0x58, "DECsystem 20 (?)"}, - {0x08, 0x00, 0x5A, "IBM"}, - {0x08, 0x00, 0x67, "Comdesign"}, - {0x08, 0x00, 0x68, "Ridge"}, - {0x08, 0x00, 0x69, "Silicon Graphics"}, - {0x08, 0x00, 0x6E, "Concurrent"}, - {0x08, 0x00, 0x75, "DDE"}, - {0x08, 0x00, 0x7C, "Vitalink"}, - {0x08, 0x00, 0x80, "XIOS"}, - {0x08, 0x00, 0x86, "Imagen/QMS"}, - {0x08, 0x00, 0x87, "Xyplex"}, - {0x08, 0x00, 0x89, "Kinetics"}, - {0x08, 0x00, 0x8B, "Pyramid"}, - {0x08, 0x00, 0x8D, "XyVision"}, - {0x08, 0x00, 0x90, "Retix Inc"}, - {0x48, 0x44, 0x53, "HDS (?)"}, - {0x80, 0x00, 0x10, "AT&T"}, - {0xAA, 0x00, 0x00, "DEC"}, - {0xAA, 0x00, 0x01, "DEC"}, - {0xAA, 0x00, 0x02, "DEC"}, - {0xAA, 0x00, 0x03, "DEC"}, - {0xAA, 0x00, 0x04, "DEC"}, - {0x00, 0x00, 0x00, NULL} + {0x00, 0x00, 0x0C, "Cisco"}, + {0x00, 0x00, 0x0E, "Fujitsu"}, + {0x00, 0x00, 0x0F, "NeXT"}, + {0x00, 0x00, 0x10, "Sytek"}, + {0x00, 0x00, 0x1D, "Cabletron"}, + {0x00, 0x00, 0x20, "DIAB"}, + {0x00, 0x00, 0x22, "Visual Technology"}, + {0x00, 0x00, 0x2A, "TRW"}, + {0x00, 0x00, 0x32, "GPT Limited"}, + {0x00, 0x00, 0x5A, "S & Koch"}, + {0x00, 0x00, 0x5E, "IANA"}, + {0x00, 0x00, 0x65, "Network General"}, + {0x00, 0x00, 0x6B, "MIPS"}, + {0x00, 0x00, 0x77, "MIPS"}, + {0x00, 0x00, 0x7A, "Ardent"}, + {0x00, 0x00, 0x89, "Cayman Systems"}, + {0x00, 0x00, 0x93, "Proteon"}, + {0x00, 0x00, 0x9F, "Ameristar Technology"}, + {0x00, 0x00, 0xA2, "Wellfleet"}, + {0x00, 0x00, 0xA3, "Network Application Technology"}, + {0x00, 0x00, 0xA6, "Network General"}, + {0x00, 0x00, 0xA7, "NCD"}, + {0x00, 0x00, 0xA9, "Network Systems"}, + {0x00, 0x00, 0xAA, "Xerox"}, + {0x00, 0x00, 0xB3, "CIMLinc"}, + {0x00, 0x00, 0xB7, "Dove Fastnet"}, + {0x00, 0x00, 0xBC, "Allen-Bradley"}, + {0x00, 0x00, 0xC0, "Western Digital"}, + {0x00, 0x00, 0xC5, "Farallon"}, + {0x00, 0x00, 0xC6, "Hewlett-Packard"}, + {0x00, 0x00, 0xC8, "Altos"}, + {0x00, 0x00, 0xC9, "Emulex"}, + {0x00, 0x00, 0xD7, "Dartmouth College"}, + {0x00, 0x00, 0xD8, "3Com (?)"}, + {0x00, 0x00, 0xDD, "Gould"}, + {0x00, 0x00, 0xDE, "Unigraph"}, + {0x00, 0x00, 0xE2, "Acer Counterpoint"}, + {0x00, 0x00, 0xEF, "Alantec"}, + {0x00, 0x00, 0xFD, "High Level Hardware"}, + {0x00, 0x01, 0x02, "BBN internal usage"}, + {0x00, 0x20, 0xAF, "3Com"}, + {0x00, 0x17, 0x00, "Kabel"}, + {0x00, 0x80, 0x64, "Wyse Technology"}, + {0x00, 0x80, 0x2B, "IMAC (?)"}, + {0x00, 0x80, 0x2D, "Xylogics, Inc."}, + {0x00, 0x80, 0x8C, "Frontier Software Development"}, + {0x00, 0x80, 0xC2, "IEEE 802.1 Committee"}, + {0x00, 0x80, 0xD3, "Shiva"}, + {0x00, 0xAA, 0x00, "Intel"}, + {0x00, 0xDD, 0x00, "Ungermann-Bass"}, + {0x00, 0xDD, 0x01, "Ungermann-Bass"}, + {0x02, 0x07, 0x01, "Racal InterLan"}, + {0x02, 0x04, 0x06, "BBN internal usage"}, + {0x02, 0x60, 0x86, "Satelcom MegaPac"}, + {0x02, 0x60, 0x8C, "3Com"}, + {0x02, 0xCF, 0x1F, "CMC"}, + {0x08, 0x00, 0x02, "3Com"}, + {0x08, 0x00, 0x03, "ACC"}, + {0x08, 0x00, 0x05, "Symbolics"}, + {0x08, 0x00, 0x08, "BBN"}, + {0x08, 0x00, 0x09, "Hewlett-Packard"}, + {0x08, 0x00, 0x0A, "Nestar Systems"}, + {0x08, 0x00, 0x0B, "Unisys"}, + {0x08, 0x00, 0x11, "Tektronix"}, + {0x08, 0x00, 0x14, "Excelan"}, + {0x08, 0x00, 0x17, "NSC"}, + {0x08, 0x00, 0x1A, "Data General"}, + {0x08, 0x00, 0x1B, "Data General"}, + {0x08, 0x00, 0x1E, "Apollo"}, + {0x08, 0x00, 0x20, "Sun"}, + {0x08, 0x00, 0x22, "NBI"}, + {0x08, 0x00, 0x25, "CDC"}, + {0x08, 0x00, 0x26, "Norsk Data"}, + {0x08, 0x00, 0x27, "PCS Computer Systems GmbH"}, + {0x08, 0x00, 0x28, "Texas Instruments"}, + {0x08, 0x00, 0x2B, "DEC"}, + {0x08, 0x00, 0x2E, "Metaphor"}, + {0x08, 0x00, 0x2F, "Prime Computer"}, + {0x08, 0x00, 0x36, "Intergraph"}, + {0x08, 0x00, 0x37, "Fujitsu-Xerox"}, + {0x08, 0x00, 0x38, "Bull"}, + {0x08, 0x00, 0x39, "Spider Systems"}, + {0x08, 0x00, 0x41, "DCA Digital Comm. Assoc."}, + {0x08, 0x00, 0x45, "Xylogics (?)"}, + {0x08, 0x00, 0x46, "Sony"}, + {0x08, 0x00, 0x47, "Sequent"}, + {0x08, 0x00, 0x49, "Univation"}, + {0x08, 0x00, 0x4C, "Encore"}, + {0x08, 0x00, 0x4E, "BICC"}, + {0x08, 0x00, 0x56, "Stanford University"}, + {0x08, 0x00, 0x58, "DECsystem 20 (?)"}, + {0x08, 0x00, 0x5A, "IBM"}, + {0x08, 0x00, 0x67, "Comdesign"}, + {0x08, 0x00, 0x68, "Ridge"}, + {0x08, 0x00, 0x69, "Silicon Graphics"}, + {0x08, 0x00, 0x6E, "Concurrent"}, + {0x08, 0x00, 0x75, "DDE"}, + {0x08, 0x00, 0x7C, "Vitalink"}, + {0x08, 0x00, 0x80, "XIOS"}, + {0x08, 0x00, 0x86, "Imagen/QMS"}, + {0x08, 0x00, 0x87, "Xyplex"}, + {0x08, 0x00, 0x89, "Kinetics"}, + {0x08, 0x00, 0x8B, "Pyramid"}, + {0x08, 0x00, 0x8D, "XyVision"}, + {0x08, 0x00, 0x90, "Retix Inc"}, + {0x48, 0x44, 0x53, "HDS (?)"}, + {0x80, 0x00, 0x10, "AT&T"}, + {0xAA, 0x00, 0x00, "DEC"}, + {0xAA, 0x00, 0x01, "DEC"}, + {0xAA, 0x00, 0x02, "DEC"}, + {0xAA, 0x00, 0x03, "DEC"}, + {0xAA, 0x00, 0x04, "DEC"}, + {0x00, 0x00, 0x00, NULL} }; /* diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index 11f70819420..dbbc54c3f82 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -4,7 +4,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: nabstime.c,v 1.54 1999/04/26 04:42:49 ishii Exp $ + * $Id: nabstime.c,v 1.55 1999/05/25 16:12:09 momjian Exp $ * */ #include <stdio.h> @@ -64,13 +64,18 @@ GetCurrentAbsoluteTime(void) CDayLight = (tm->tm_isdst > 0); #ifdef NOT_USED + /* * XXX is there a better way to get local timezone string w/o * tzname? - tgl 97/03/18 */ strftime(CTZName, MAXTZLEN, "%Z", tm); #endif - /* XXX FreeBSD man pages indicate that this should work - thomas 1998-12-12 */ + + /* + * XXX FreeBSD man pages indicate that this should work - thomas + * 1998-12-12 + */ strcpy(CTZName, tm->tm_zone); #elif defined(HAVE_INT_TIMEZONE) @@ -79,10 +84,10 @@ GetCurrentAbsoluteTime(void) CDayLight = tm->tm_isdst; CTimeZone = #ifdef __CYGWIN32__ - (tm->tm_isdst ? (_timezone - 3600) : _timezone); + (tm->tm_isdst ? (_timezone - 3600) : _timezone); #else - (tm->tm_isdst ? (timezone - 3600) : timezone); -#endif + (tm->tm_isdst ? (timezone - 3600) : timezone); +#endif strcpy(CTZName, tzname[tm->tm_isdst]); #else #error USE_POSIX_TIME defined but no time zone available @@ -91,8 +96,9 @@ GetCurrentAbsoluteTime(void) CTimeZone = tb.timezone * 60; CDayLight = (tb.dstflag != 0); - /* XXX does this work to get the local timezone string in V7? - * - tgl 97/03/18 + /* + * XXX does this work to get the local timezone string in V7? - + * tgl 97/03/18 */ strftime(CTZName, MAXTZLEN, "%Z", localtime(&now)); #endif @@ -389,6 +395,7 @@ AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2) return time1 > time2; } + #endif /* abstime_finite() diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index d49eb9cb23c..1780df2c427 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.17 1999/02/13 23:19:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.18 1999/05/25 16:12:10 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -161,6 +161,7 @@ namecmp(Name n1, Name n2) { return strncmp(n1->data, n2->data, NAMEDATALEN); } + #endif int diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 12f28ccce76..cd86ec6f3d5 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. * - * $Id: network.c,v 1.8 1999/04/15 02:20:50 thomas Exp $ + * $Id: network.c,v 1.9 1999/05/25 16:12:11 momjian Exp $ * Jon Postel RIP 16 Oct 1998 */ @@ -52,7 +52,7 @@ network_in(char *src, int type) if (!src) return NULL; - + dst = palloc(VARHDRSZ + sizeof(inet_struct)); if (dst == NULL) elog(ERROR, "unable to allocate memory in network_in()"); @@ -60,7 +60,7 @@ network_in(char *src, int type) /* First, try for an IP V4 address: */ ip_family(dst) = AF_INET; bits = inet_net_pton(ip_family(dst), src, &ip_v4addr(dst), - type ? ip_addrsize(dst) : -1); + type ? ip_addrsize(dst) : -1); if ((bits < 0) || (bits > 32)) /* Go for an IPV6 address here, before faulting out: */ elog(ERROR, "could not parse \"%s\"", src); @@ -102,10 +102,10 @@ inet_out(inet *src) /* It's an IP V4 address: */ if (ip_type(src)) dst = inet_cidr_ntop(AF_INET, &ip_v4addr(src), ip_bits(src), - tmp, sizeof(tmp)); + tmp, sizeof(tmp)); else dst = inet_net_ntop(AF_INET, &ip_v4addr(src), ip_bits(src), - tmp, sizeof(tmp)); + tmp, sizeof(tmp)); if (dst == NULL) elog(ERROR, "unable to print address (%s)", strerror(errno)); @@ -222,7 +222,7 @@ network_sub(inet *a1, inet *a2) { if (!PointerIsValid(a1) || !PointerIsValid(a2)) return FALSE; - + if ((ip_family(a1) == AF_INET) && (ip_family(a2) == AF_INET)) { return ((ip_bits(a1) > ip_bits(a2)) @@ -370,7 +370,7 @@ network_broadcast(inet *ip) if (ip_family(ip) == AF_INET) { /* It's an IP V4 address: */ - int addr; + int addr; unsigned long mask = 0xffffffff; if (ip_bits(ip) < 32) @@ -402,7 +402,7 @@ network_network(inet *ip) { text *ret; int len; - char tmp[sizeof("255.255.255.255/32")]; + char tmp[sizeof("255.255.255.255/32")]; if (!PointerIsValid(ip)) return NULL; @@ -410,8 +410,8 @@ network_network(inet *ip) if (ip_family(ip) == AF_INET) { /* It's an IP V4 address: */ - int addr = htonl(ntohl(ip_v4addr(ip)) & (0xffffffff << (32 - ip_bits(ip)))); - + int addr = htonl(ntohl(ip_v4addr(ip)) & (0xffffffff << (32 - ip_bits(ip)))); + if (inet_cidr_ntop(AF_INET, &addr, ip_bits(ip), tmp, sizeof(tmp)) == NULL) elog(ERROR, "unable to print network (%s)", strerror(errno)); diff --git a/src/backend/utils/adt/not_in.c b/src/backend/utils/adt/not_in.c index 62a76c83692..7082b0d007e 100644 --- a/src/backend/utils/adt/not_in.c +++ b/src/backend/utils/adt/not_in.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.15 1999/03/15 03:24:32 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.16 1999/05/25 16:12:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,18 +47,16 @@ int4notin(int32 not_in_arg, char *relation_and_attr) int attrid; char *relation, *attribute; - char my_copy[NAMEDATALEN*2+2]; + char my_copy[NAMEDATALEN * 2 + 2]; Datum value; strncpy(my_copy, relation_and_attr, sizeof(my_copy)); - my_copy[sizeof(my_copy)-1] = '\0'; + my_copy[sizeof(my_copy) - 1] = '\0'; relation = (char *) strtok(my_copy, "."); attribute = (char *) strtok(NULL, "."); if (attribute == NULL) - { elog(ERROR, "int4notin: must provide relationname.attributename"); - } /* Open the relation and get a relation descriptor */ diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index b1a86986ac0..e9e5a28c363 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.13 1999/05/10 18:17:44 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.14 1999/05/25 16:12:14 momjian Exp $ * * ---------- */ @@ -41,10 +41,10 @@ #define NUMERIC_MAX_FREEBUFS 20 #ifndef MIN -# define MIN(a,b) (((a)<(b)) ? (a) : (b)) +#define MIN(a,b) (((a)<(b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (((a)>(b)) ? (a) : (b)) +#define MAX(a,b) (((a)>(b)) ? (a) : (b)) #endif #ifndef NAN @@ -56,52 +56,54 @@ * Local data types * ---------- */ -typedef unsigned char NumericDigit; +typedef unsigned char NumericDigit; -typedef struct NumericDigitBuf { - struct NumericDigitBuf *prev; - struct NumericDigitBuf *next; - int size; -} NumericDigitBuf; +typedef struct NumericDigitBuf +{ + struct NumericDigitBuf *prev; + struct NumericDigitBuf *next; + int size; +} NumericDigitBuf; -typedef struct NumericVar { - int ndigits; - int weight; - int rscale; - int dscale; - int sign; - NumericDigitBuf *buf; - NumericDigit *digits; -} NumericVar; +typedef struct NumericVar +{ + int ndigits; + int weight; + int rscale; + int dscale; + int sign; + NumericDigitBuf *buf; + NumericDigit *digits; +} NumericVar; /* ---------- * Local data * ---------- */ -static NumericDigitBuf *digitbuf_freelist = NULL; -static NumericDigitBuf *digitbuf_usedlist = NULL; -static int digitbuf_nfree = 0; -static int global_rscale = NUMERIC_MIN_RESULT_SCALE; +static NumericDigitBuf *digitbuf_freelist = NULL; +static NumericDigitBuf *digitbuf_usedlist = NULL; +static int digitbuf_nfree = 0; +static int global_rscale = NUMERIC_MIN_RESULT_SCALE; /* ---------- * Some preinitialized variables we need often * ---------- */ -static NumericDigit const_zero_data[1] = {0}; -static NumericVar const_zero = - {0, 0, 0, 0, NUMERIC_POS, NULL, const_zero_data}; +static NumericDigit const_zero_data[1] = {0}; +static NumericVar const_zero = +{0, 0, 0, 0, NUMERIC_POS, NULL, const_zero_data}; -static NumericDigit const_one_data[1] = {1}; -static NumericVar const_one = - {1, 0, 0, 0, NUMERIC_POS, NULL, const_one_data}; +static NumericDigit const_one_data[1] = {1}; +static NumericVar const_one = +{1, 0, 0, 0, NUMERIC_POS, NULL, const_one_data}; -static NumericDigit const_two_data[1] = {2}; -static NumericVar const_two = - {1, 0, 0, 0, NUMERIC_POS, NULL, const_two_data}; +static NumericDigit const_two_data[1] = {2}; +static NumericVar const_two = +{1, 0, 0, 0, NUMERIC_POS, NULL, const_two_data}; -static NumericVar const_nan = - {0, 0, 0, 0, NUMERIC_NAN, NULL, NULL}; +static NumericVar const_nan = +{0, 0, 0, 0, NUMERIC_NAN, NULL, NULL}; @@ -112,44 +114,45 @@ static NumericVar const_nan = #ifdef NUMERIC_DEBUG static void dump_numeric(char *str, Numeric num); -static void dump_var(char *str, NumericVar *var); +static void dump_var(char *str, NumericVar * var); + #else #define dump_numeric(s,n) #define dump_var(s,v) #endif static NumericDigitBuf *digitbuf_alloc(int size); -static void digitbuf_free(NumericDigitBuf *buf); +static void digitbuf_free(NumericDigitBuf * buf); #define init_var(v) memset(v,0,sizeof(NumericVar)) -static void free_var(NumericVar *var); +static void free_var(NumericVar * var); static void free_allvars(void); -static void set_var_from_str(char *str, NumericVar *dest); -static void set_var_from_num(Numeric value, NumericVar *dest); -static void set_var_from_var(NumericVar *value, NumericVar *dest); -static Numeric make_result(NumericVar *var); +static void set_var_from_str(char *str, NumericVar * dest); +static void set_var_from_num(Numeric value, NumericVar * dest); +static void set_var_from_var(NumericVar * value, NumericVar * dest); +static Numeric make_result(NumericVar * var); -static void apply_typmod(NumericVar *var, int32 typmod); +static void apply_typmod(NumericVar * var, int32 typmod); -static int cmp_var(NumericVar *var1, NumericVar *var2); -static void add_var(NumericVar *var1, NumericVar *var2, NumericVar *result); -static void sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result); -static void mul_var(NumericVar *var1, NumericVar *var2, NumericVar *result); -static void div_var(NumericVar *var1, NumericVar *var2, NumericVar *result); -static void mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result); -static void ceil_var(NumericVar *var, NumericVar *result); -static void floor_var(NumericVar *var, NumericVar *result); +static int cmp_var(NumericVar * var1, NumericVar * var2); +static void add_var(NumericVar * var1, NumericVar * var2, NumericVar * result); +static void sub_var(NumericVar * var1, NumericVar * var2, NumericVar * result); +static void mul_var(NumericVar * var1, NumericVar * var2, NumericVar * result); +static void div_var(NumericVar * var1, NumericVar * var2, NumericVar * result); +static void mod_var(NumericVar * var1, NumericVar * var2, NumericVar * result); +static void ceil_var(NumericVar * var, NumericVar * result); +static void floor_var(NumericVar * var, NumericVar * result); -static void sqrt_var(NumericVar *arg, NumericVar *result); -static void exp_var(NumericVar *arg, NumericVar *result); -static void ln_var(NumericVar *arg, NumericVar *result); -static void log_var(NumericVar *base, NumericVar *num, NumericVar *result); -static void power_var(NumericVar *base, NumericVar *exp, NumericVar *result); +static void sqrt_var(NumericVar * arg, NumericVar * result); +static void exp_var(NumericVar * arg, NumericVar * result); +static void ln_var(NumericVar * arg, NumericVar * result); +static void log_var(NumericVar * base, NumericVar * num, NumericVar * result); +static void power_var(NumericVar * base, NumericVar * exp, NumericVar * result); -static int cmp_abs(NumericVar *var1, NumericVar *var2); -static void add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result); -static void sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result); +static int cmp_abs(NumericVar * var1, NumericVar * var2); +static void add_abs(NumericVar * var1, NumericVar * var2, NumericVar * result); +static void sub_abs(NumericVar * var1, NumericVar * var2, NumericVar * result); @@ -216,8 +219,8 @@ numeric_in(char *str, int dummy, int32 typmod) char * numeric_out(Numeric num) { - char *str; - char *cp; + char *str; + char *cp; NumericVar x; int i; int d; @@ -257,7 +260,7 @@ numeric_out(Numeric num) */ str = palloc(x.dscale + MAX(0, x.weight) + 5); cp = str; - + /* ---------- * Output a dash for negative values * ---------- @@ -272,8 +275,8 @@ numeric_out(Numeric num) */ if (x.dscale < x.rscale && (x.dscale + x.weight + 1) < x.ndigits) { - int j; - int carry; + int j; + int carry; j = x.dscale + x.weight + 1; carry = (x.digits[j] > 4) ? 1 : 0; @@ -342,7 +345,7 @@ numeric_out(Numeric num) * * This is a special function called by the Postgres database system * before a value is stored in a tuples attribute. The precision and - * scale of the attribute have to be applied on the value. + * scale of the attribute have to be applied on the value. * ---------- */ Numeric @@ -374,9 +377,9 @@ numeric(Numeric num, int32 typmod) * copy of the input value * ---------- */ - if (typmod < (int32)(VARHDRSZ)) + if (typmod < (int32) (VARHDRSZ)) { - new = (Numeric)palloc(num->varlen); + new = (Numeric) palloc(num->varlen); memcpy(new, num, num->varlen); return new; } @@ -387,7 +390,7 @@ numeric(Numeric num, int32 typmod) */ tmp_typmod = typmod - VARHDRSZ; precision = (tmp_typmod >> 16) & 0xffff; - scale = tmp_typmod & 0xffff; + scale = tmp_typmod & 0xffff; maxweight = precision - scale; /* ---------- @@ -398,11 +401,11 @@ numeric(Numeric num, int32 typmod) */ if (num->n_weight < maxweight && scale >= num->n_rscale) { - new = (Numeric)palloc(num->varlen); + new = (Numeric) palloc(num->varlen); memcpy(new, num, num->varlen); new->n_rscale = scale; - new->n_sign_dscale = NUMERIC_SIGN(new) | - ((uint16)scale & ~NUMERIC_SIGN_MASK); + new->n_sign_dscale = NUMERIC_SIGN(new) | + ((uint16) scale & ~NUMERIC_SIGN_MASK); return new; } @@ -454,7 +457,7 @@ numeric_abs(Numeric num) * Do it the easy way directly on the packed format * ---------- */ - res = (Numeric)palloc(num->varlen); + res = (Numeric) palloc(num->varlen); memcpy(res, num, num->varlen); res->n_sign_dscale = NUMERIC_POS | NUMERIC_DSCALE(num); @@ -492,9 +495,7 @@ numeric_sign(Numeric num) * ---------- */ if (num->varlen == NUMERIC_HDRSZ) - { set_var_from_var(&const_zero, &result); - } else { /* ---------- @@ -523,7 +524,7 @@ Numeric numeric_round(Numeric num, int32 scale) { int32 typmod; - int precision; + int precision; /* ---------- * Handle NULL @@ -547,7 +548,7 @@ numeric_round(Numeric num, int32 scale) { free_allvars(); elog(ERROR, "illegal numeric scale %d - must be between 0 and %d", - scale, NUMERIC_MAX_DISPLAY_SCALE); + scale, NUMERIC_MAX_DISPLAY_SCALE); } /* ---------- @@ -569,8 +570,8 @@ numeric_round(Numeric num, int32 scale) Numeric numeric_trunc(Numeric num, int32 scale) { - Numeric res; - NumericVar arg; + Numeric res; + NumericVar arg; /* ---------- * Handle NULL @@ -594,7 +595,7 @@ numeric_trunc(Numeric num, int32 scale) { free_allvars(); elog(ERROR, "illegal numeric scale %d - must be between 0 and %d", - scale, NUMERIC_MAX_DISPLAY_SCALE); + scale, NUMERIC_MAX_DISPLAY_SCALE); } /* ---------- @@ -609,9 +610,7 @@ numeric_trunc(Numeric num, int32 scale) arg.ndigits = MIN(arg.ndigits, MAX(0, arg.weight + scale + 1)); while (arg.ndigits > 0 && arg.digits[arg.ndigits - 1] == 0) - { arg.ndigits--; - } /* ---------- * Return the truncated result @@ -1085,7 +1084,7 @@ numeric_div(Numeric num1, Numeric num2) * numeric.h): * * DR = MIN(MAX(D1 + D2, MIN_DISPLAY_SCALE)) - * SR = MIN(MAX(MAX(S1 + S2, MIN_RESULT_SCALE), DR + 4), MAX_RESULT_SCALE) + * SR = MIN(MAX(MAX(S1 + S2, MIN_RESULT_SCALE), DR + 4), MAX_RESULT_SCALE) * * By default, any result is computed with a minimum of 34 digits * after the decimal point or at least with 4 digits more than @@ -1094,7 +1093,7 @@ numeric_div(Numeric num1, Numeric num2) */ res_dscale = MAX(arg1.dscale + arg2.dscale, NUMERIC_MIN_DISPLAY_SCALE); res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); - global_rscale = MAX(arg1.rscale + arg2.rscale, + global_rscale = MAX(arg1.rscale + arg2.rscale, NUMERIC_MIN_RESULT_SCALE); global_rscale = MAX(global_rscale, res_dscale + 4); global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE); @@ -1358,10 +1357,10 @@ numeric_larger(Numeric num1, Numeric num2) Numeric numeric_sqrt(Numeric num) { - Numeric res; - NumericVar arg; - NumericVar result; - int res_dscale; + Numeric res; + NumericVar arg; + NumericVar result; + int res_dscale; /* ---------- * Handle NULL @@ -1415,10 +1414,10 @@ numeric_sqrt(Numeric num) Numeric numeric_exp(Numeric num) { - Numeric res; - NumericVar arg; - NumericVar result; - int res_dscale; + Numeric res; + NumericVar arg; + NumericVar result; + int res_dscale; /* ---------- * Handle NULL @@ -1470,10 +1469,10 @@ numeric_exp(Numeric num) Numeric numeric_ln(Numeric num) { - Numeric res; - NumericVar arg; - NumericVar result; - int res_dscale; + Numeric res; + NumericVar arg; + NumericVar result; + int res_dscale; /* ---------- * Handle NULL @@ -1525,11 +1524,11 @@ numeric_ln(Numeric num) Numeric numeric_log(Numeric num1, Numeric num2) { - Numeric res; - NumericVar arg1; - NumericVar arg2; - NumericVar result; - int res_dscale; + Numeric res; + NumericVar arg1; + NumericVar arg2; + NumericVar result; + int res_dscale; /* ---------- * Handle NULL @@ -1588,11 +1587,11 @@ numeric_log(Numeric num1, Numeric num2) Numeric numeric_power(Numeric num1, Numeric num2) { - Numeric res; - NumericVar arg1; - NumericVar arg2; - NumericVar result; - int res_dscale; + Numeric res; + NumericVar arg1; + NumericVar arg2; + NumericVar result; + int res_dscale; /* ---------- * Handle NULL @@ -1653,7 +1652,7 @@ int4_numeric(int32 val) { Numeric res; NumericVar result; - char *tmp; + char *tmp; init_var(&result); @@ -1671,7 +1670,7 @@ int4_numeric(int32 val) int32 numeric_int4(Numeric num) { - char *tmp; + char *tmp; int32 result; if (num == NULL) @@ -1717,7 +1716,7 @@ float8_numeric(float64 val) float64 numeric_float8(Numeric num) { - char *tmp; + char *tmp; float64 result; if (num == NULL) @@ -1725,7 +1724,7 @@ numeric_float8(Numeric num) if (NUMERIC_IS_NAN(num)) { - result = (float64)palloc(sizeof(float64data)); + result = (float64) palloc(sizeof(float64data)); *result = NAN; return result; } @@ -1743,7 +1742,7 @@ float4_numeric(float32 val) { Numeric res; NumericVar result; - char *tmp; + char *tmp; if (val == NULL) return NULL; @@ -1767,7 +1766,7 @@ float4_numeric(float32 val) float32 numeric_float4(Numeric num) { - char *tmp; + char *tmp; float32 result; if (num == NULL) @@ -1775,7 +1774,7 @@ numeric_float4(Numeric num) if (NUMERIC_IS_NAN(num)) { - result = (float32)palloc(sizeof(float32data)); + result = (float32) palloc(sizeof(float32data)); *result = NAN; return result; } @@ -1805,26 +1804,28 @@ numeric_float4(Numeric num) static void dump_numeric(char *str, Numeric num) { - int i; + int i; printf("%s: NUMERIC w=%d r=%d d=%d ", str, num->n_weight, num->n_rscale, - NUMERIC_DSCALE(num)); + NUMERIC_DSCALE(num)); switch (NUMERIC_SIGN(num)) { - case NUMERIC_POS: printf("POS"); - break; - case NUMERIC_NEG: printf("NEG"); - break; - case NUMERIC_NAN: printf("NaN"); - break; - default: printf("SIGN=0x%x", NUMERIC_SIGN(num)); - break; + case NUMERIC_POS: + printf("POS"); + break; + case NUMERIC_NEG: + printf("NEG"); + break; + case NUMERIC_NAN: + printf("NaN"); + break; + default: + printf("SIGN=0x%x", NUMERIC_SIGN(num)); + break; } for (i = 0; i < num->varlen - NUMERIC_HDRSZ; i++) - { printf(" %d %d", (num->n_data[i] >> 4) & 0x0f, num->n_data[i] & 0x0f); - } printf("\n"); } @@ -1834,31 +1835,35 @@ dump_numeric(char *str, Numeric num) * ---------- */ static void -dump_var(char *str, NumericVar *var) +dump_var(char *str, NumericVar * var) { - int i; + int i; printf("%s: VAR w=%d r=%d d=%d ", str, var->weight, var->rscale, - var->dscale); + var->dscale); switch (var->sign) { - case NUMERIC_POS: printf("POS"); - break; - case NUMERIC_NEG: printf("NEG"); - break; - case NUMERIC_NAN: printf("NaN"); - break; - default: printf("SIGN=0x%x", var->sign); - break; + case NUMERIC_POS: + printf("POS"); + break; + case NUMERIC_NEG: + printf("NEG"); + break; + case NUMERIC_NAN: + printf("NaN"); + break; + default: + printf("SIGN=0x%x", var->sign); + break; } for (i = 0; i < var->ndigits; i++) printf(" %d", var->digits[i]); - + printf("\n"); } -#endif /* NUMERIC_DEBUG */ +#endif /* NUMERIC_DEBUG */ /* ---------- @@ -1868,7 +1873,7 @@ dump_var(char *str, NumericVar *var) * information (sign, scales etc.) and a digit buffer for the * value itself. All the variable level functions are written in * a style that makes it possible to give one and the same variable - * as argument and result destination. + * as argument and result destination. * * The two functions below manage unused buffers in a free list * as a try to reduce the number of malloc()/free() calls. @@ -1877,8 +1882,8 @@ dump_var(char *str, NumericVar *var) static NumericDigitBuf * digitbuf_alloc(int size) { - NumericDigitBuf *buf; - int asize; + NumericDigitBuf *buf; + int asize; /* ---------- * Lookup the free list if there is a digit buffer of @@ -1887,7 +1892,8 @@ digitbuf_alloc(int size) */ for (buf = digitbuf_freelist; buf != NULL; buf = buf->next) { - if (buf->size < size) continue; + if (buf->size < size) + continue; /* ---------- * We found a free buffer that is big enough - remove it from @@ -1930,7 +1936,7 @@ digitbuf_alloc(int size) * ---------- */ for (asize = NUMERIC_MIN_BUFSIZE; asize < size; asize *= 2); - buf = (NumericDigitBuf *)malloc(sizeof(NumericDigitBuf) + asize); + buf = (NumericDigitBuf *) malloc(sizeof(NumericDigitBuf) + asize); buf->size = asize; /* ---------- @@ -1956,9 +1962,9 @@ digitbuf_alloc(int size) * ---------- */ static void -digitbuf_free(NumericDigitBuf *buf) +digitbuf_free(NumericDigitBuf * buf) { - NumericDigitBuf *smallest; + NumericDigitBuf *smallest; if (buf == NULL) return; @@ -2042,12 +2048,12 @@ digitbuf_free(NumericDigitBuf *buf) * ---------- */ static void -free_var(NumericVar *var) +free_var(NumericVar * var) { if (var->buf != NULL) { digitbuf_free(var->buf); - var->buf = NULL; + var->buf = NULL; var->digits = NULL; } var->sign = NUMERIC_NAN; @@ -2070,8 +2076,8 @@ free_var(NumericVar *var) static void free_allvars(void) { - NumericDigitBuf *buf; - NumericDigitBuf *next; + NumericDigitBuf *buf; + NumericDigitBuf *next; buf = digitbuf_usedlist; while (buf != NULL) @@ -2090,25 +2096,26 @@ free_allvars(void) * ---------- */ static void -set_var_from_str(char *str, NumericVar *dest) +set_var_from_str(char *str, NumericVar * dest) { - char *cp = str; - bool have_dp = FALSE; - int i = 1; + char *cp = str; + bool have_dp = FALSE; + int i = 1; - while(*cp) + while (*cp) { - if (!isspace(*cp)) break; + if (!isspace(*cp)) + break; cp++; } digitbuf_free(dest->buf); - dest->buf = digitbuf_alloc(strlen(cp) + 2); - dest->digits = (NumericDigit *)(dest->buf) + sizeof(NumericDigitBuf); + dest->buf = digitbuf_alloc(strlen(cp) + 2); + dest->digits = (NumericDigit *) (dest->buf) + sizeof(NumericDigitBuf); dest->digits[0] = 0; - dest->weight = 0; - dest->dscale = 0; + dest->weight = 0; + dest->dscale = 0; switch (*cp) { @@ -2121,24 +2128,29 @@ set_var_from_str(char *str, NumericVar *dest) case '6': case '7': case '8': - case '9': dest->sign = NUMERIC_POS; - break; + case '9': + dest->sign = NUMERIC_POS; + break; - case '+': dest->sign = NUMERIC_POS; - cp++; - break; + case '+': + dest->sign = NUMERIC_POS; + cp++; + break; - case '-': dest->sign = NUMERIC_NEG; - cp++; - break; + case '-': + dest->sign = NUMERIC_NEG; + cp++; + break; - case '.': dest->sign = NUMERIC_POS; - have_dp = TRUE; - cp++; - break; + case '.': + dest->sign = NUMERIC_POS; + have_dp = TRUE; + cp++; + break; - default: free_allvars(); - elog(ERROR, "Bad numeric input format '%s'", str); + default: + free_allvars(); + elog(ERROR, "Bad numeric input format '%s'", str); } if (*cp == '.') @@ -2178,24 +2190,27 @@ set_var_from_str(char *str, NumericVar *dest) case '6': case '7': case '8': - case '9': dest->digits[i++] = *cp++ - '0'; - if (!have_dp) - dest->weight++; - else - dest->dscale++; - break; - - case '.': if (have_dp) - { - free_allvars(); - elog(ERROR, "Bad numeric input format '%s'", str); - } - have_dp = TRUE; - cp++; - break; - - default: free_allvars(); - elog(ERROR, "Bad numeric input format '%s'", str); + case '9': + dest->digits[i++] = *cp++ - '0'; + if (!have_dp) + dest->weight++; + else + dest->dscale++; + break; + + case '.': + if (have_dp) + { + free_allvars(); + elog(ERROR, "Bad numeric input format '%s'", str); + } + have_dp = TRUE; + cp++; + break; + + default: + free_allvars(); + elog(ERROR, "Bad numeric input format '%s'", str); } } dest->ndigits = i; @@ -2223,18 +2238,18 @@ set_var_from_str(char *str, NumericVar *dest) * */ static void -set_var_from_num(Numeric num, NumericVar *dest) +set_var_from_num(Numeric num, NumericVar * dest) { - NumericDigit *digit; - int i; - int n; + NumericDigit *digit; + int i; + int n; n = num->varlen - NUMERIC_HDRSZ; digitbuf_free(dest->buf); dest->buf = digitbuf_alloc(n * 2 + 2); - digit = ((NumericDigit *)(dest->buf)) + sizeof(NumericDigitBuf); + digit = ((NumericDigit *) (dest->buf)) + sizeof(NumericDigitBuf); *digit++ = 0; *digit++ = 0; dest->digits = digit; @@ -2243,7 +2258,7 @@ set_var_from_num(Numeric num, NumericVar *dest) dest->weight = num->n_weight; dest->rscale = num->n_rscale; dest->dscale = NUMERIC_DSCALE(num); - dest->sign = NUMERIC_SIGN(num); + dest->sign = NUMERIC_SIGN(num); for (i = 0; i < n; i++) { @@ -2260,18 +2275,18 @@ set_var_from_num(Numeric num, NumericVar *dest) * ---------- */ static void -set_var_from_var(NumericVar *value, NumericVar *dest) +set_var_from_var(NumericVar * value, NumericVar * dest) { - NumericDigitBuf *newbuf; - NumericDigit *newdigits; + NumericDigitBuf *newbuf; + NumericDigit *newdigits; newbuf = digitbuf_alloc(value->ndigits); - newdigits = ((NumericDigit *)newbuf) + sizeof(NumericDigitBuf); + newdigits = ((NumericDigit *) newbuf) + sizeof(NumericDigitBuf); memcpy(newdigits, value->digits, value->ndigits); digitbuf_free(dest->buf); memcpy(dest, value, sizeof(NumericVar)); - dest->buf = newbuf; + dest->buf = newbuf; dest->digits = newdigits; } @@ -2284,22 +2299,23 @@ set_var_from_var(NumericVar *value, NumericVar *dest) * ---------- */ static Numeric -make_result(NumericVar *var) +make_result(NumericVar * var) { - Numeric result; - NumericDigit *digit = var->digits; - int n; - int weight = var->weight; - int sign = var->sign; - int i, j; + Numeric result; + NumericDigit *digit = var->digits; + int n; + int weight = var->weight; + int sign = var->sign; + int i, + j; if (sign == NUMERIC_NAN) { - result = (Numeric)palloc(NUMERIC_HDRSZ); + result = (Numeric) palloc(NUMERIC_HDRSZ); - result->varlen = NUMERIC_HDRSZ; - result->n_weight = 0; - result->n_rscale = 0; + result->varlen = NUMERIC_HDRSZ; + result->n_weight = 0; + result->n_rscale = 0; result->n_sign_dscale = NUMERIC_NAN; dump_numeric("make_result()", result); @@ -2320,16 +2336,17 @@ make_result(NumericVar *var) if (n == 0) { weight = 0; - sign = NUMERIC_POS; + sign = NUMERIC_POS; } - result = (Numeric)palloc(NUMERIC_HDRSZ + (n + 1) / 2); + result = (Numeric) palloc(NUMERIC_HDRSZ + (n + 1) / 2); result->varlen = NUMERIC_HDRSZ + (n + 1) / 2; result->n_weight = weight; result->n_rscale = var->rscale; - result->n_sign_dscale = sign | ((uint16)(var->dscale) & ~NUMERIC_SIGN_MASK); + result->n_sign_dscale = sign | ((uint16) (var->dscale) & ~NUMERIC_SIGN_MASK); - i = 0; j = 0; + i = 0; + j = 0; while (j < n) { result->n_data[i] = digit[j++] << 4; @@ -2351,33 +2368,33 @@ make_result(NumericVar *var) * ---------- */ static void -apply_typmod(NumericVar *var, int32 typmod) +apply_typmod(NumericVar * var, int32 typmod) { int precision; int scale; int maxweight; int i; - if (typmod < (int32)(VARHDRSZ)) + if (typmod < (int32) (VARHDRSZ)) return; typmod -= VARHDRSZ; precision = (typmod >> 16) & 0xffff; - scale = typmod & 0xffff; + scale = typmod & 0xffff; maxweight = precision - scale; if (var->weight >= maxweight) { free_allvars(); elog(ERROR, "overflow on numeric " - "ABS(value) >= 10^%d for field with precision %d scale %d", - var->weight, precision, scale); + "ABS(value) >= 10^%d for field with precision %d scale %d", + var->weight, precision, scale); } i = scale + var->weight + 1; if (i >= 0 && var->ndigits > i) { - long carry = (var->digits[i] > 4) ? 1 : 0; + long carry = (var->digits[i] > 4) ? 1 : 0; var->ndigits = i; while (carry) @@ -2395,9 +2412,7 @@ apply_typmod(NumericVar *var, int32 typmod) } } else - { var->ndigits = MAX(0, MIN(i, var->ndigits)); - } /* ---------- * Check for overflow again - rounding could have raised the @@ -2408,8 +2423,8 @@ apply_typmod(NumericVar *var, int32 typmod) { free_allvars(); elog(ERROR, "overflow on numeric " - "ABS(value) >= 10^%d for field with precision %d scale %d", - var->weight, precision, scale); + "ABS(value) >= 10^%d for field with precision %d scale %d", + var->weight, precision, scale); } var->rscale = scale; @@ -2424,7 +2439,7 @@ apply_typmod(NumericVar *var, int32 typmod) * ---------- */ static int -cmp_var(NumericVar *var1, NumericVar *var2) +cmp_var(NumericVar * var1, NumericVar * var2) { if (var1->ndigits == 0) { @@ -2463,7 +2478,7 @@ cmp_var(NumericVar *var1, NumericVar *var2) * ---------- */ static void -add_var(NumericVar *var1, NumericVar *var2, NumericVar *result) +add_var(NumericVar * var1, NumericVar * var2, NumericVar * result) { /* ---------- * Decide on the signs of the two variables what to do @@ -2474,7 +2489,7 @@ add_var(NumericVar *var1, NumericVar *var2, NumericVar *result) if (var2->sign == NUMERIC_POS) { /* ---------- - * Both are positive + * Both are positive * result = +(ABS(var1) + ABS(var2)) * ---------- */ @@ -2490,39 +2505,39 @@ add_var(NumericVar *var1, NumericVar *var2, NumericVar *result) */ switch (cmp_abs(var1, var2)) { - case 0: /* ---------- - * ABS(var1) == ABS(var2) - * result = ZERO - * ---------- - */ - digitbuf_free(result->buf); - result->buf = digitbuf_alloc(0); - result->ndigits = 0; - result->digits = ((NumericDigit *)(result->buf)) + - sizeof(NumericDigitBuf); - result->weight = 0; - result->rscale = MAX(var1->rscale, var2->rscale); - result->dscale = MAX(var1->dscale, var2->dscale); - result->sign = NUMERIC_POS; - break; - - case 1: /* ---------- - * ABS(var1) > ABS(var2) - * result = +(ABS(var1) - ABS(var2)) - * ---------- - */ - sub_abs(var1, var2, result); - result->sign = NUMERIC_POS; - break; - - case -1: /* ---------- - * ABS(var1) < ABS(var2) - * result = -(ABS(var2) - ABS(var1)) - * ---------- - */ - sub_abs(var2, var1, result); - result->sign = NUMERIC_NEG; - break; + case 0: /* ---------- + * ABS(var1) == ABS(var2) + * result = ZERO + * ---------- + */ + digitbuf_free(result->buf); + result->buf = digitbuf_alloc(0); + result->ndigits = 0; + result->digits = ((NumericDigit *) (result->buf)) + + sizeof(NumericDigitBuf); + result->weight = 0; + result->rscale = MAX(var1->rscale, var2->rscale); + result->dscale = MAX(var1->dscale, var2->dscale); + result->sign = NUMERIC_POS; + break; + + case 1: /* ---------- + * ABS(var1) > ABS(var2) + * result = +(ABS(var1) - ABS(var2)) + * ---------- + */ + sub_abs(var1, var2, result); + result->sign = NUMERIC_POS; + break; + + case -1: /* ---------- + * ABS(var1) < ABS(var2) + * result = -(ABS(var2) - ABS(var1)) + * ---------- + */ + sub_abs(var2, var1, result); + result->sign = NUMERIC_NEG; + break; } } } @@ -2537,39 +2552,39 @@ add_var(NumericVar *var1, NumericVar *var2, NumericVar *result) */ switch (cmp_abs(var1, var2)) { - case 0: /* ---------- - * ABS(var1) == ABS(var2) - * result = ZERO - * ---------- - */ - digitbuf_free(result->buf); - result->buf = digitbuf_alloc(0); - result->ndigits = 0; - result->digits = ((NumericDigit *)(result->buf)) + - sizeof(NumericDigitBuf); - result->weight = 0; - result->rscale = MAX(var1->rscale, var2->rscale); - result->dscale = MAX(var1->dscale, var2->dscale); - result->sign = NUMERIC_POS; - break; - - case 1: /* ---------- - * ABS(var1) > ABS(var2) - * result = -(ABS(var1) - ABS(var2)) - * ---------- - */ - sub_abs(var1, var2, result); - result->sign = NUMERIC_NEG; - break; - - case -1: /* ---------- - * ABS(var1) < ABS(var2) - * result = +(ABS(var2) - ABS(var1)) - * ---------- - */ - sub_abs(var2, var1, result); - result->sign = NUMERIC_POS; - break; + case 0: /* ---------- + * ABS(var1) == ABS(var2) + * result = ZERO + * ---------- + */ + digitbuf_free(result->buf); + result->buf = digitbuf_alloc(0); + result->ndigits = 0; + result->digits = ((NumericDigit *) (result->buf)) + + sizeof(NumericDigitBuf); + result->weight = 0; + result->rscale = MAX(var1->rscale, var2->rscale); + result->dscale = MAX(var1->dscale, var2->dscale); + result->sign = NUMERIC_POS; + break; + + case 1: /* ---------- + * ABS(var1) > ABS(var2) + * result = -(ABS(var1) - ABS(var2)) + * ---------- + */ + sub_abs(var1, var2, result); + result->sign = NUMERIC_NEG; + break; + + case -1: /* ---------- + * ABS(var1) < ABS(var2) + * result = +(ABS(var2) - ABS(var1)) + * ---------- + */ + sub_abs(var2, var1, result); + result->sign = NUMERIC_POS; + break; } } else @@ -2594,7 +2609,7 @@ add_var(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ static void -sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result) +sub_var(NumericVar * var1, NumericVar * var2, NumericVar * result) { /* ---------- * Decide on the signs of the two variables what to do @@ -2621,39 +2636,39 @@ sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result) */ switch (cmp_abs(var1, var2)) { - case 0: /* ---------- - * ABS(var1) == ABS(var2) - * result = ZERO - * ---------- - */ - digitbuf_free(result->buf); - result->buf = digitbuf_alloc(0); - result->ndigits = 0; - result->digits = ((NumericDigit *)(result->buf)) + - sizeof(NumericDigitBuf); - result->weight = 0; - result->rscale = MAX(var1->rscale, var2->rscale); - result->dscale = MAX(var1->dscale, var2->dscale); - result->sign = NUMERIC_POS; - break; - - case 1: /* ---------- - * ABS(var1) > ABS(var2) - * result = +(ABS(var1) - ABS(var2)) - * ---------- - */ - sub_abs(var1, var2, result); - result->sign = NUMERIC_POS; - break; - - case -1: /* ---------- - * ABS(var1) < ABS(var2) - * result = -(ABS(var2) - ABS(var1)) - * ---------- - */ - sub_abs(var2, var1, result); - result->sign = NUMERIC_NEG; - break; + case 0: /* ---------- + * ABS(var1) == ABS(var2) + * result = ZERO + * ---------- + */ + digitbuf_free(result->buf); + result->buf = digitbuf_alloc(0); + result->ndigits = 0; + result->digits = ((NumericDigit *) (result->buf)) + + sizeof(NumericDigitBuf); + result->weight = 0; + result->rscale = MAX(var1->rscale, var2->rscale); + result->dscale = MAX(var1->dscale, var2->dscale); + result->sign = NUMERIC_POS; + break; + + case 1: /* ---------- + * ABS(var1) > ABS(var2) + * result = +(ABS(var1) - ABS(var2)) + * ---------- + */ + sub_abs(var1, var2, result); + result->sign = NUMERIC_POS; + break; + + case -1: /* ---------- + * ABS(var1) < ABS(var2) + * result = -(ABS(var2) - ABS(var1)) + * ---------- + */ + sub_abs(var2, var1, result); + result->sign = NUMERIC_NEG; + break; } } } @@ -2668,39 +2683,39 @@ sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result) */ switch (cmp_abs(var1, var2)) { - case 0: /* ---------- - * ABS(var1) == ABS(var2) - * result = ZERO - * ---------- - */ - digitbuf_free(result->buf); - result->buf = digitbuf_alloc(0); - result->ndigits = 0; - result->digits = ((NumericDigit *)(result->buf)) + - sizeof(NumericDigitBuf); - result->weight = 0; - result->rscale = MAX(var1->rscale, var2->rscale); - result->dscale = MAX(var1->dscale, var2->dscale); - result->sign = NUMERIC_POS; - break; - - case 1: /* ---------- - * ABS(var1) > ABS(var2) - * result = -(ABS(var1) - ABS(var2)) - * ---------- - */ - sub_abs(var1, var2, result); - result->sign = NUMERIC_NEG; - break; - - case -1: /* ---------- - * ABS(var1) < ABS(var2) - * result = +(ABS(var2) - ABS(var1)) - * ---------- - */ - sub_abs(var2, var1, result); - result->sign = NUMERIC_POS; - break; + case 0: /* ---------- + * ABS(var1) == ABS(var2) + * result = ZERO + * ---------- + */ + digitbuf_free(result->buf); + result->buf = digitbuf_alloc(0); + result->ndigits = 0; + result->digits = ((NumericDigit *) (result->buf)) + + sizeof(NumericDigitBuf); + result->weight = 0; + result->rscale = MAX(var1->rscale, var2->rscale); + result->dscale = MAX(var1->dscale, var2->dscale); + result->sign = NUMERIC_POS; + break; + + case 1: /* ---------- + * ABS(var1) > ABS(var2) + * result = -(ABS(var1) - ABS(var2)) + * ---------- + */ + sub_abs(var1, var2, result); + result->sign = NUMERIC_NEG; + break; + + case -1: /* ---------- + * ABS(var1) < ABS(var2) + * result = +(ABS(var2) - ABS(var1)) + * ---------- + */ + sub_abs(var2, var1, result); + result->sign = NUMERIC_POS; + break; } } else @@ -2725,17 +2740,20 @@ sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ static void -mul_var(NumericVar *var1, NumericVar *var2, NumericVar *result) +mul_var(NumericVar * var1, NumericVar * var2, NumericVar * result) { - NumericDigitBuf *res_buf; - NumericDigit *res_digits; - int res_ndigits; - int res_weight; - int res_sign; - int i, ri, i1, i2; - long sum = 0; - - res_weight = var1->weight + var2->weight + 2; + NumericDigitBuf *res_buf; + NumericDigit *res_digits; + int res_ndigits; + int res_weight; + int res_sign; + int i, + ri, + i1, + i2; + long sum = 0; + + res_weight = var1->weight + var2->weight + 2; res_ndigits = var1->ndigits + var2->ndigits + 1; if (var1->sign == var2->sign) res_sign = NUMERIC_POS; @@ -2743,7 +2761,7 @@ mul_var(NumericVar *var1, NumericVar *var2, NumericVar *result) res_sign = NUMERIC_NEG; res_buf = digitbuf_alloc(res_ndigits); - res_digits = ((NumericDigit *)res_buf) + sizeof(NumericDigitBuf); + res_digits = ((NumericDigit *) res_buf) + sizeof(NumericDigitBuf); memset(res_digits, 0, res_ndigits); ri = res_ndigits; @@ -2782,23 +2800,21 @@ mul_var(NumericVar *var1, NumericVar *var2, NumericVar *result) res_ndigits--; } while (res_ndigits > 0 && res_digits[res_ndigits - 1] == 0) - { res_ndigits--; - } if (res_ndigits == 0) { - res_sign = NUMERIC_POS; + res_sign = NUMERIC_POS; res_weight = 0; } digitbuf_free(result->buf); - result->buf = res_buf; - result->digits = res_digits; + result->buf = res_buf; + result->digits = res_digits; result->ndigits = res_ndigits; - result->weight = res_weight; - result->rscale = global_rscale; - result->sign = res_sign; + result->weight = res_weight; + result->rscale = global_rscale; + result->sign = res_sign; } @@ -2809,24 +2825,24 @@ mul_var(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ static void -div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) -{ - NumericDigit *res_digits; - int res_ndigits; - int res_sign; - int res_weight; - NumericVar dividend; - NumericVar divisor[10]; - int ndigits_tmp; - int weight_tmp; - int rscale_tmp; - int ri; - int i; - long guess; - long first_have; - long first_div; - int first_nextdigit; - int stat = 0; +div_var(NumericVar * var1, NumericVar * var2, NumericVar * result) +{ + NumericDigit *res_digits; + int res_ndigits; + int res_sign; + int res_weight; + NumericVar dividend; + NumericVar divisor[10]; + int ndigits_tmp; + int weight_tmp; + int rscale_tmp; + int ri; + int i; + long guess; + long first_have; + long first_div; + int first_nextdigit; + int stat = 0; /* ---------- * First of all division by zero check @@ -2858,11 +2874,11 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) { digitbuf_free(result->buf); result->buf = digitbuf_alloc(0); - result->digits = ((NumericDigit *)(result->buf)) + sizeof(NumericDigitBuf); + result->digits = ((NumericDigit *) (result->buf)) + sizeof(NumericDigitBuf); result->ndigits = 0; - result->weight = 0; - result->rscale = global_rscale; - result->sign = NUMERIC_POS; + result->weight = 0; + result->rscale = global_rscale; + result->sign = NUMERIC_POS; return; } @@ -2872,21 +2888,19 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) */ init_var(÷nd); for (i = 1; i < 10; i++) - { init_var(&divisor[i]); - } /* ---------- * Make a copy of the divisor which has one leading zero digit * ---------- */ - divisor[1].ndigits = ndigits_tmp; - divisor[1].rscale = var2->ndigits; - divisor[1].sign = NUMERIC_POS; - divisor[1].buf = digitbuf_alloc(ndigits_tmp); - divisor[1].digits = ((NumericDigit *)(divisor[1].buf)) + - sizeof(NumericDigitBuf); + divisor[1].ndigits = ndigits_tmp; + divisor[1].rscale = var2->ndigits; + divisor[1].sign = NUMERIC_POS; + divisor[1].buf = digitbuf_alloc(ndigits_tmp); + divisor[1].digits = ((NumericDigit *) (divisor[1].buf)) + + sizeof(NumericDigitBuf); divisor[1].digits[0] = 0; memcpy(&(divisor[1].digits[1]), var2->digits, ndigits_tmp - 1); @@ -2895,11 +2909,11 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ dividend.ndigits = var1->ndigits; - dividend.weight = 0; - dividend.rscale = var1->ndigits; - dividend.sign = NUMERIC_POS; - dividend.buf = digitbuf_alloc(var1->ndigits); - dividend.digits = ((NumericDigit *)(dividend.buf)) + sizeof(NumericDigitBuf); + dividend.weight = 0; + dividend.rscale = var1->ndigits; + dividend.sign = NUMERIC_POS; + dividend.buf = digitbuf_alloc(var1->ndigits); + dividend.digits = ((NumericDigit *) (dividend.buf)) + sizeof(NumericDigitBuf); memcpy(dividend.digits, var1->digits, var1->ndigits); /* ---------- @@ -2908,18 +2922,18 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) */ digitbuf_free(result->buf); result->buf = digitbuf_alloc(res_ndigits + 2); - res_digits = ((NumericDigit *)(result->buf)) + sizeof(NumericDigitBuf); + res_digits = ((NumericDigit *) (result->buf)) + sizeof(NumericDigitBuf); result->digits = res_digits; result->ndigits = res_ndigits; - result->weight = res_weight; - result->rscale = global_rscale; - result->sign = res_sign; + result->weight = res_weight; + result->rscale = global_rscale; + result->sign = res_sign; res_digits[0] = 0; first_div = divisor[1].digits[1] * 10; if (ndigits_tmp > 2) first_div += divisor[1].digits[2]; - + first_have = 0; first_nextdigit = 0; @@ -2941,13 +2955,13 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) { if (divisor[guess].buf == NULL) { - int i; - long sum = 0; + int i; + long sum = 0; memcpy(&divisor[guess], &divisor[1], sizeof(NumericVar)); divisor[guess].buf = digitbuf_alloc(divisor[guess].ndigits); - divisor[guess].digits = ((NumericDigit *)(divisor[guess].buf) + - sizeof(NumericDigitBuf)); + divisor[guess].digits = ((NumericDigit *) (divisor[guess].buf) + + sizeof(NumericDigitBuf)); for (i = divisor[1].ndigits - 1; i >= 0; i--) { sum += divisor[1].digits[i] * guess; @@ -2960,7 +2974,8 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) divisor[guess].rscale = rscale_tmp; stat = cmp_abs(÷nd, &divisor[guess]); - if (stat >= 0) break; + if (stat >= 0) + break; guess--; } @@ -2990,12 +3005,12 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) result->ndigits = ri + 1; if (ri == res_ndigits + 1) { - long carry = (res_digits[ri] > 4) ? 1 : 0; + long carry = (res_digits[ri] > 4) ? 1 : 0; result->ndigits = ri; res_digits[ri] = 0; - while(carry && ri > 0) + while (carry && ri > 0) { carry += res_digits[--ri]; res_digits[ri] = carry % 10; @@ -3010,9 +3025,7 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) (result->ndigits)--; } while (result->ndigits > 0 && result->digits[result->ndigits - 1] == 0) - { (result->ndigits)--; - } if (result->ndigits == 0) result->sign = NUMERIC_POS; @@ -3033,10 +3046,10 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ static void -mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result) +mod_var(NumericVar * var1, NumericVar * var2, NumericVar * result) { - NumericVar tmp; - int save_global_rscale; + NumericVar tmp; + int save_global_rscale; init_var(&tmp); @@ -3070,9 +3083,9 @@ mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ static void -ceil_var(NumericVar *var, NumericVar *result) +ceil_var(NumericVar * var, NumericVar * result) { - NumericVar tmp; + NumericVar tmp; init_var(&tmp); set_var_from_var(var, &tmp); @@ -3095,9 +3108,9 @@ ceil_var(NumericVar *var, NumericVar *result) * ---------- */ static void -floor_var(NumericVar *var, NumericVar *result) +floor_var(NumericVar * var, NumericVar * result) { - NumericVar tmp; + NumericVar tmp; init_var(&tmp); set_var_from_var(var, &tmp); @@ -3119,14 +3132,14 @@ floor_var(NumericVar *var, NumericVar *result) * ---------- */ static void -sqrt_var(NumericVar *arg, NumericVar *result) +sqrt_var(NumericVar * arg, NumericVar * result) { - NumericVar tmp_arg; - NumericVar tmp_val; - NumericVar last_val; - int res_rscale; - int save_global_rscale; - int stat; + NumericVar tmp_arg; + NumericVar tmp_val; + NumericVar last_val; + int res_rscale; + int save_global_rscale; + int stat; save_global_rscale = global_rscale; global_rscale += 8; @@ -3137,7 +3150,7 @@ sqrt_var(NumericVar *arg, NumericVar *result) { set_var_from_var(&const_zero, result); result->rscale = res_rscale; - result->sign = NUMERIC_POS; + result->sign = NUMERIC_POS; return; } @@ -3160,14 +3173,14 @@ sqrt_var(NumericVar *arg, NumericVar *result) */ digitbuf_free(result->buf); result->buf = digitbuf_alloc(1); - result->digits = ((NumericDigit *)(result->buf)) + sizeof(NumericDigitBuf); + result->digits = ((NumericDigit *) (result->buf)) + sizeof(NumericDigitBuf); result->digits[0] = tmp_arg.digits[0] / 2; if (result->digits[0] == 0) result->digits[0] = 1; result->ndigits = 1; result->weight = tmp_arg.weight / 2; result->rscale = res_rscale; - result->sign = NUMERIC_POS; + result->sign = NUMERIC_POS; for (;;) { @@ -3176,7 +3189,8 @@ sqrt_var(NumericVar *arg, NumericVar *result) add_var(result, &tmp_val, result); div_var(result, &const_two, result); - if (cmp_var(&last_val, result) == 0) break; + if (cmp_var(&last_val, result) == 0) + break; set_var_from_var(result, &last_val); } @@ -3196,18 +3210,18 @@ sqrt_var(NumericVar *arg, NumericVar *result) * ---------- */ static void -exp_var(NumericVar *arg, NumericVar *result) -{ - NumericVar x; - NumericVar xpow; - NumericVar ifac; - NumericVar elem; - NumericVar ni; - int d; - int i; - int ndiv2 = 0; - bool xneg = FALSE; - int save_global_rscale; +exp_var(NumericVar * arg, NumericVar * result) +{ + NumericVar x; + NumericVar xpow; + NumericVar ifac; + NumericVar elem; + NumericVar ni; + int d; + int i; + int ndiv2 = 0; + bool xneg = FALSE; + int save_global_rscale; init_var(&x); init_var(&xpow); @@ -3239,7 +3253,7 @@ exp_var(NumericVar *arg, NumericVar *result) global_rscale = global_rscale / 2 + save_global_rscale + 8; - while(cmp_var(&x, &const_one) > 0) + while (cmp_var(&x, &const_one) > 0) { ndiv2++; global_rscale++; @@ -3290,15 +3304,15 @@ exp_var(NumericVar *arg, NumericVar *result) * ---------- */ static void -ln_var(NumericVar *arg, NumericVar *result) +ln_var(NumericVar * arg, NumericVar * result) { - NumericVar x; - NumericVar xx; - NumericVar ni; - NumericVar elem; - NumericVar fact; - int i; - int save_global_rscale; + NumericVar x; + NumericVar xx; + NumericVar ni; + NumericVar elem; + NumericVar fact; + int i; + int save_global_rscale; if (cmp_var(arg, &const_zero) <= 0) { @@ -3368,7 +3382,7 @@ ln_var(NumericVar *arg, NumericVar *result) * ---------- */ static void -log_var(NumericVar *base, NumericVar *num, NumericVar *result) +log_var(NumericVar * base, NumericVar * num, NumericVar * result) { NumericVar ln_base; NumericVar ln_num; @@ -3379,10 +3393,10 @@ log_var(NumericVar *base, NumericVar *num, NumericVar *result) init_var(&ln_num); ln_var(base, &ln_base); - ln_var(num, &ln_num); + ln_var(num, &ln_num); global_rscale -= 8; - + div_var(&ln_num, &ln_base, result); free_var(&ln_num); @@ -3397,7 +3411,7 @@ log_var(NumericVar *base, NumericVar *num, NumericVar *result) * ---------- */ static void -power_var(NumericVar *base, NumericVar *exp, NumericVar *result) +power_var(NumericVar * base, NumericVar * exp, NumericVar * result) { NumericVar ln_base; NumericVar ln_num; @@ -3415,7 +3429,7 @@ power_var(NumericVar *base, NumericVar *exp, NumericVar *result) global_rscale = save_global_rscale; exp_var(&ln_num, result); - + free_var(&ln_num); free_var(&ln_base); @@ -3441,22 +3455,24 @@ power_var(NumericVar *base, NumericVar *exp, NumericVar *result) * ---------- */ static int -cmp_abs(NumericVar *var1, NumericVar *var2) +cmp_abs(NumericVar * var1, NumericVar * var2) { - int i1 = 0; - int i2 = 0; - int w1 = var1->weight; - int w2 = var2->weight; - int stat; + int i1 = 0; + int i2 = 0; + int w1 = var1->weight; + int w2 = var2->weight; + int stat; while (w1 > w2 && i1 < var1->ndigits) { - if (var1->digits[i1++] != 0) return 1; + if (var1->digits[i1++] != 0) + return 1; w1--; } while (w2 > w1 && i2 < var2->ndigits) { - if (var2->digits[i2++] != 0) return -1; + if (var2->digits[i2++] != 0) + return -1; w2--; } @@ -3497,16 +3513,18 @@ cmp_abs(NumericVar *var1, NumericVar *var2) * ---------- */ static void -add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) +add_abs(NumericVar * var1, NumericVar * var2, NumericVar * result) { - NumericDigitBuf *res_buf; - NumericDigit *res_digits; - int res_ndigits; - int res_weight; - int res_rscale; - int res_dscale; - int i, i1, i2; - int carry = 0; + NumericDigitBuf *res_buf; + NumericDigit *res_digits; + int res_ndigits; + int res_weight; + int res_rscale; + int res_dscale; + int i, + i1, + i2; + int carry = 0; res_weight = MAX(var1->weight, var2->weight) + 1; res_rscale = MAX(var1->rscale, var2->rscale); @@ -3514,7 +3532,7 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) res_ndigits = res_rscale + res_weight + 1; res_buf = digitbuf_alloc(res_ndigits); - res_digits = ((NumericDigit *)res_buf) + sizeof(NumericDigitBuf); + res_digits = ((NumericDigit *) res_buf) + sizeof(NumericDigitBuf); i1 = res_rscale + var1->weight + 1; i2 = res_rscale + var2->weight + 1; @@ -3538,20 +3556,18 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) res_ndigits--; } while (res_ndigits > 0 && res_digits[res_ndigits - 1] == 0) - { res_ndigits--; - } if (res_ndigits == 0) res_weight = 0; digitbuf_free(result->buf); result->ndigits = res_ndigits; - result->buf = res_buf; - result->digits = res_digits; - result->weight = res_weight; - result->rscale = res_rscale; - result->dscale = res_dscale; + result->buf = res_buf; + result->digits = res_digits; + result->weight = res_weight; + result->rscale = res_rscale; + result->dscale = res_dscale; } @@ -3566,16 +3582,18 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) * ---------- */ static void -sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) +sub_abs(NumericVar * var1, NumericVar * var2, NumericVar * result) { - NumericDigitBuf *res_buf; - NumericDigit *res_digits; - int res_ndigits; - int res_weight; - int res_rscale; - int res_dscale; - int i, i1, i2; - int borrow = 0; + NumericDigitBuf *res_buf; + NumericDigit *res_digits; + int res_ndigits; + int res_weight; + int res_rscale; + int res_dscale; + int i, + i1, + i2; + int borrow = 0; res_weight = var1->weight; res_rscale = MAX(var1->rscale, var2->rscale); @@ -3583,7 +3601,7 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) res_ndigits = res_rscale + res_weight + 1; res_buf = digitbuf_alloc(res_ndigits); - res_digits = ((NumericDigit *)res_buf) + sizeof(NumericDigitBuf); + res_digits = ((NumericDigit *) res_buf) + sizeof(NumericDigitBuf); i1 = res_rscale + var1->weight + 1; i2 = res_rscale + var2->weight + 1; @@ -3615,20 +3633,16 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result) res_ndigits--; } while (res_ndigits > 0 && res_digits[res_ndigits - 1] == 0) - { res_ndigits--; - } if (res_ndigits == 0) res_weight = 0; digitbuf_free(result->buf); result->ndigits = res_ndigits; - result->buf = res_buf; - result->digits = res_digits; - result->weight = res_weight; - result->rscale = res_rscale; - result->dscale = res_dscale; + result->buf = res_buf; + result->digits = res_digits; + result->weight = res_weight; + result->rscale = res_rscale; + result->dscale = res_dscale; } - - diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c index 19a0f2d385b..413d0fadd88 100644 --- a/src/backend/utils/adt/numutils.c +++ b/src/backend/utils/adt/numutils.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.29 1999/02/13 23:19:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.30 1999/05/25 16:12:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,17 +55,17 @@ pg_atoi(char *s, int size, int c) Assert(s); - errno = 0; + errno = 0; /* - * Some versions of strtol treat the empty string as an error. This + * Some versions of strtol treat the empty string as an error. This * code will explicitly return 0 for an empty string. */ - if (s == (char *)NULL) + if (s == (char *) NULL) elog(ERROR, "pg_atoi: NULL pointer!"); else if (*s == 0) - l = (long)0; + l = (long) 0; else l = strtol(s, &badp, 10); if (errno) /* strtol must set ERANGE */ diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 2e6276f4e2f..1db8ddcc057 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.36 1999/05/10 00:45:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.37 1999/05/25 16:12:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,9 +41,9 @@ int32 regprocin(char *pro_name_or_oid) { - HeapTuple proctup = NULL; - HeapTupleData tuple; - RegProcedure result = InvalidOid; + HeapTuple proctup = NULL; + HeapTupleData tuple; + RegProcedure result = InvalidOid; if (pro_name_or_oid == NULL) return InvalidOid; @@ -52,6 +52,7 @@ regprocin(char *pro_name_or_oid) if (!IsBootstrapProcessingMode()) { + /* * we need to use the oid because there can be multiple entries * with the same name. We accept int4eq_1323 and 1323. @@ -76,23 +77,23 @@ regprocin(char *pro_name_or_oid) RetrieveIndexResult indexRes; Buffer buffer; int matches = 0; - + ScanKeyEntryInitialize(&skey[0], (bits16) 0x0, (AttrNumber) 1, (RegProcedure) F_NAMEEQ, PointerGetDatum(pro_name_or_oid)); - + hdesc = heap_openr(ProcedureRelationName); idesc = index_openr(ProcedureNameIndex); - + sd = index_beginscan(idesc, false, 1, skey); while ((indexRes = index_getnext(sd, ForwardScanDirection))) { tuple.t_self = indexRes->heap_iptr; heap_fetch(hdesc, SnapshotNow, - &tuple, - &buffer); + &tuple, + &buffer); pfree(indexRes); if (tuple.t_data != NULL) { diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index b953567ad9c..62aab389012 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * out of it's tuple * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.14 1999/05/25 08:49:33 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.15 1999/05/25 16:12:19 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -57,16 +57,17 @@ #include "catalog/pg_opclass.h" #include "fmgr.h" -#define BUFSIZE 8192 +#define BUFSIZE 8192 /* ---------- * Local data types * ---------- */ -typedef struct QryHier { - struct QryHier *parent; - Query *query; -} QryHier; +typedef struct QryHier +{ + struct QryHier *parent; + Query *query; +} QryHier; /* ---------- @@ -90,7 +91,7 @@ static char *query_getopclass = "SELECT * FROM pg_opclass WHERE oid = $1"; */ text *pg_get_ruledef(NameData *rname); text *pg_get_viewdef(NameData *rname); -text *pg_get_indexdef(Oid indexrelid); +text *pg_get_indexdef(Oid indexrelid); NameData *pg_get_userbyid(int4 uid); @@ -100,16 +101,16 @@ NameData *pg_get_userbyid(int4 uid); */ static char *make_ruledef(HeapTuple ruletup, TupleDesc rulettc); static char *make_viewdef(HeapTuple ruletup, TupleDesc rulettc); -static char *get_query_def(Query *query, QryHier *parentqh); -static char *get_select_query_def(Query *query, QryHier *qh); -static char *get_insert_query_def(Query *query, QryHier *qh); -static char *get_update_query_def(Query *query, QryHier *qh); -static char *get_delete_query_def(Query *query, QryHier *qh); -static char *get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix); -static char *get_func_expr(QryHier *qh, int rt_index, Expr *expr, bool varprefix); -static char *get_tle_expr(QryHier *qh, int rt_index, TargetEntry *tle, bool varprefix); +static char *get_query_def(Query *query, QryHier * parentqh); +static char *get_select_query_def(Query *query, QryHier * qh); +static char *get_insert_query_def(Query *query, QryHier * qh); +static char *get_update_query_def(Query *query, QryHier * qh); +static char *get_delete_query_def(Query *query, QryHier * qh); +static char *get_rule_expr(QryHier * qh, int rt_index, Node *node, bool varprefix); +static char *get_func_expr(QryHier * qh, int rt_index, Expr *expr, bool varprefix); +static char *get_tle_expr(QryHier * qh, int rt_index, TargetEntry *tle, bool varprefix); static char *get_const_expr(Const *constval); -static char *get_sublink_expr(QryHier *qh, int rt_index, Node *node, bool varprefix); +static char *get_sublink_expr(QryHier * qh, int rt_index, Node *node, bool varprefix); static char *get_relation_name(Oid relid); static char *get_attribute_name(Oid relid, int2 attnum); static bool check_if_rte_used(int rt_index, Node *node, int sup); @@ -314,27 +315,27 @@ pg_get_viewdef(NameData *rname) * only return the SELECT part of a view * ---------- */ -text * +text * pg_get_indexdef(Oid indexrelid) { - text *indexdef; + text *indexdef; HeapTuple ht_idx; HeapTuple ht_idxrel; HeapTuple ht_indrel; HeapTuple spi_tup; TupleDesc spi_ttc; - int spi_fno; - Form_pg_index idxrec; - Form_pg_class idxrelrec; - Form_pg_class indrelrec; + int spi_fno; + Form_pg_index idxrec; + Form_pg_class idxrelrec; + Form_pg_class indrelrec; Datum spi_args[1]; char spi_nulls[2]; - int spirc; - int len; - int keyno; + int spirc; + int len; + int keyno; char buf[BUFSIZE]; char keybuf[BUFSIZE]; - char *sep; + char *sep; /* ---------- * Connect to SPI manager @@ -371,30 +372,30 @@ pg_get_indexdef(Oid indexrelid) * ---------- */ ht_idx = SearchSysCacheTuple(INDEXRELID, - ObjectIdGetDatum(indexrelid), 0, 0, 0); + ObjectIdGetDatum(indexrelid), 0, 0, 0); if (!HeapTupleIsValid(ht_idx)) elog(ERROR, "syscache lookup for index %u failed", indexrelid); - idxrec = (Form_pg_index)GETSTRUCT(ht_idx); + idxrec = (Form_pg_index) GETSTRUCT(ht_idx); /* ---------- * Fetch the pg_class tuple of the index relation * ---------- */ ht_idxrel = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(idxrec->indexrelid), 0, 0, 0); + ObjectIdGetDatum(idxrec->indexrelid), 0, 0, 0); if (!HeapTupleIsValid(ht_idxrel)) elog(ERROR, "syscache lookup for relid %u failed", idxrec->indexrelid); - idxrelrec = (Form_pg_class)GETSTRUCT(ht_idxrel); + idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel); /* ---------- * Fetch the pg_class tuple of the indexed relation * ---------- */ ht_indrel = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(idxrec->indrelid), 0, 0, 0); + ObjectIdGetDatum(idxrec->indrelid), 0, 0, 0); if (!HeapTupleIsValid(ht_indrel)) elog(ERROR, "syscache lookup for relid %u failed", idxrec->indrelid); - indrelrec = (Form_pg_class)GETSTRUCT(ht_indrel); + indrelrec = (Form_pg_class) GETSTRUCT(ht_indrel); /* ---------- * Get the am name for the index relation @@ -417,11 +418,11 @@ pg_get_indexdef(Oid indexrelid) * ---------- */ sprintf(buf, "CREATE %sINDEX \"%s\" ON \"%s\" USING %s (", - idxrec->indisunique ? "UNIQUE " : "", - nameout(&(idxrelrec->relname)), - nameout(&(indrelrec->relname)), - SPI_getvalue(spi_tup, spi_ttc, spi_fno)); - + idxrec->indisunique ? "UNIQUE " : "", + nameout(&(idxrelrec->relname)), + nameout(&(indrelrec->relname)), + SPI_getvalue(spi_tup, spi_ttc, spi_fno)); + /* ---------- * Collect the indexed attributes * ---------- @@ -445,7 +446,7 @@ pg_get_indexdef(Oid indexrelid) strcat(keybuf, "oid"); else strcat(keybuf, get_attribute_name(idxrec->indrelid, - idxrec->indkey[keyno])); + idxrec->indkey[keyno])); strcat(keybuf, "\""); /* ---------- @@ -478,10 +479,10 @@ pg_get_indexdef(Oid indexrelid) if (idxrec->indproc != InvalidOid) { HeapTuple proctup; - Form_pg_proc procStruct; + Form_pg_proc procStruct; proctup = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(idxrec->indproc), 0, 0, 0); + ObjectIdGetDatum(idxrec->indproc), 0, 0, 0); if (!HeapTupleIsValid(proctup)) elog(ERROR, "cache lookup for proc %u failed", idxrec->indproc); @@ -508,13 +509,11 @@ pg_get_indexdef(Oid indexrelid) strcat(buf, "\""); } else - /* ---------- - * For the others say 'attr opclass [, ...]' - * ---------- - */ - { + /* ---------- + * For the others say 'attr opclass [, ...]' + * ---------- + */ strcat(buf, keybuf); - } /* ---------- * Finish @@ -551,8 +550,8 @@ NameData * pg_get_userbyid(int4 uid) { HeapTuple usertup; - Form_pg_shadow user_rec; - NameData *result; + Form_pg_shadow user_rec; + NameData *result; /* ---------- * Allocate space for the result @@ -566,16 +565,14 @@ pg_get_userbyid(int4 uid) * ---------- */ usertup = SearchSysCacheTuple(USESYSID, - ObjectIdGetDatum(uid), 0, 0, 0); + ObjectIdGetDatum(uid), 0, 0, 0); if (HeapTupleIsValid(usertup)) { - user_rec = (Form_pg_shadow)GETSTRUCT(usertup); + user_rec = (Form_pg_shadow) GETSTRUCT(usertup); StrNCpy(result->data, (&(user_rec->usename))->data, NAMEDATALEN); } else - { - sprintf((char *)result, "unknown (UID=%d)", uid); - } + sprintf((char *) result, "unknown (UID=%d)", uid); return result; } @@ -683,12 +680,12 @@ make_ruledef(HeapTuple ruletup, TupleDesc rulettc) { Node *qual; Query *query; - QryHier qh; + QryHier qh; qual = stringToNode(ev_qual); query = (Query *) lfirst(actions); qh.parent = NULL; - qh.query = query; + qh.query = query; strcat(buf, " WHERE "); strcat(buf, get_rule_expr(&qh, 0, qual, TRUE)); @@ -809,16 +806,16 @@ make_viewdef(HeapTuple ruletup, TupleDesc rulettc) * ---------- */ static char * -get_query_def(Query *query, QryHier *parentqh) +get_query_def(Query *query, QryHier * parentqh) { QryHier qh; qh.parent = parentqh; - qh.query = query; + qh.query = query; switch (query->commandType) { - case CMD_SELECT: + case CMD_SELECT: return get_select_query_def(query, &qh); break; @@ -853,7 +850,7 @@ get_query_def(Query *query, QryHier *parentqh) * ---------- */ static char * -get_select_query_def(Query *query, QryHier *qh) +get_select_query_def(Query *query, QryHier * qh) { char buf[BUFSIZE]; char *sep; @@ -1023,7 +1020,7 @@ get_select_query_def(Query *query, QryHier *qh) * ---------- */ static char * -get_insert_query_def(Query *query, QryHier *qh) +get_insert_query_def(Query *query, QryHier * qh) { char buf[BUFSIZE]; char *sep; @@ -1133,7 +1130,7 @@ get_insert_query_def(Query *query, QryHier *qh) * ---------- */ static char * -get_update_query_def(Query *query, QryHier *qh) +get_update_query_def(Query *query, QryHier * qh) { char buf[BUFSIZE]; char *sep; @@ -1186,7 +1183,7 @@ get_update_query_def(Query *query, QryHier *qh) * ---------- */ static char * -get_delete_query_def(Query *query, QryHier *qh) +get_delete_query_def(Query *query, QryHier * qh) { char buf[BUFSIZE]; RangeTblEntry *rte; @@ -1220,7 +1217,7 @@ get_delete_query_def(Query *query, QryHier *qh) * ---------- */ static char * -get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) +get_rule_expr(QryHier * qh, int rt_index, Node *node, bool varprefix) { char buf[BUFSIZE]; @@ -1254,7 +1251,7 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) strcat(buf, aggref->aggname); strcat(buf, "\"("); strcat(buf, get_rule_expr(qh, rt_index, - (Node *) (aggref->target), varprefix)); + (Node *) (aggref->target), varprefix)); strcat(buf, ")"); return pstrdup(buf); } @@ -1263,15 +1260,15 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) case T_GroupClause: { GroupClause *grp = (GroupClause *) node; - List *l; - TargetEntry *tle = NULL; + List *l; + TargetEntry *tle = NULL; foreach(l, qh->query->targetList) { - if (((TargetEntry *)lfirst(l))->resdom->resgroupref == - grp->tleGroupref) + if (((TargetEntry *) lfirst(l))->resdom->resgroupref == + grp->tleGroupref) { - tle = (TargetEntry *)lfirst(l); + tle = (TargetEntry *) lfirst(l); break; } } @@ -1279,7 +1276,7 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) if (tle == NULL) elog(ERROR, "GROUP BY expression not found in targetlist"); - return get_rule_expr(qh, rt_index, (Node *)tle, varprefix); + return get_rule_expr(qh, rt_index, (Node *) tle, varprefix); } break; @@ -1358,9 +1355,10 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) { Var *var = (Var *) node; RangeTblEntry *rte; - int sup = var->varlevelsup; + int sup = var->varlevelsup; - while(sup-- > 0) qh = qh->parent; + while (sup-- > 0) + qh = qh->parent; rte = (RangeTblEntry *) nth(var->varno - 1, qh->query->rtable); @@ -1396,9 +1394,7 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) break; case T_SubLink: - { return get_sublink_expr(qh, rt_index, node, varprefix); - } break; case T_Const: @@ -1421,7 +1417,7 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) * ---------- */ static char * -get_func_expr(QryHier *qh, int rt_index, Expr *expr, bool varprefix) +get_func_expr(QryHier * qh, int rt_index, Expr *expr, bool varprefix) { char buf[BUFSIZE]; HeapTuple proctup; @@ -1500,7 +1496,7 @@ get_func_expr(QryHier *qh, int rt_index, Expr *expr, bool varprefix) * ---------- */ static char * -get_tle_expr(QryHier *qh, int rt_index, TargetEntry *tle, bool varprefix) +get_tle_expr(QryHier * qh, int rt_index, TargetEntry *tle, bool varprefix) { HeapTuple proctup; Form_pg_proc procStruct; @@ -1609,14 +1605,14 @@ get_const_expr(Const *constval) * ---------- */ static char * -get_sublink_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) +get_sublink_expr(QryHier * qh, int rt_index, Node *node, bool varprefix) { SubLink *sublink = (SubLink *) node; Query *query = (Query *) (sublink->subselect); - Expr *expr; + Expr *expr; List *l; char *sep; - char buf[BUFSIZE]; + char buf[BUFSIZE]; buf[0] = '\0'; @@ -1640,32 +1636,33 @@ get_sublink_expr(QryHier *qh, int rt_index, Node *node, bool varprefix) strcat(buf, " "); } - switch (sublink->subLinkType) { + switch (sublink->subLinkType) + { case EXISTS_SUBLINK: strcat(buf, "EXISTS "); break; case ANY_SUBLINK: - expr = (Expr *)lfirst(sublink->oper); + expr = (Expr *) lfirst(sublink->oper); strcat(buf, get_opname(((Oper *) (expr->oper))->opno)); strcat(buf, " ANY "); break; case ALL_SUBLINK: - expr = (Expr *)lfirst(sublink->oper); + expr = (Expr *) lfirst(sublink->oper); strcat(buf, get_opname(((Oper *) (expr->oper))->opno)); strcat(buf, " ALL "); break; case EXPR_SUBLINK: - expr = (Expr *)lfirst(sublink->oper); + expr = (Expr *) lfirst(sublink->oper); strcat(buf, get_opname(((Oper *) (expr->oper))->opno)); strcat(buf, " "); break; default: elog(ERROR, "unupported sublink type %d", - sublink->subLinkType); + sublink->subLinkType); break; } diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 53310bf1b3e..fc65ddc3f97 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.27 1999/05/10 00:46:00 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.28 1999/05/25 16:12:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -393,6 +393,7 @@ btreesel(Oid operatorObjectId, if (FunctionalSelectivity(nIndexKeys, attributeNumber)) { + /* * Need to call the functions selectivity function here. For now * simply assume it's 1/3 since functions don't currently have @@ -437,6 +438,7 @@ btreenpage(Oid operatorObjectId, if (FunctionalSelectivity(nIndexKeys, attributeNumber)) { + /* * Need to call the functions selectivity function here. For now * simply assume it's 1/3 since functions don't currently have diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 1233955c4fd..cb0982a52d8 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.45 1999/05/19 17:53:11 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.46 1999/05/25 16:12:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -82,7 +82,7 @@ bpcharin(char *s, int dummy, int32 atttypmod) len = atttypmod - VARHDRSZ; if (len > BLCKSZ - 128) - elog(ERROR, "bpcharin: length of char() must be less than %d",BLCKSZ-128); + elog(ERROR, "bpcharin: length of char() must be less than %d", BLCKSZ - 128); result = (char *) palloc(atttypmod); VARSIZE(result) = atttypmod; @@ -152,7 +152,7 @@ bpchar(char *s, int32 len) rlen = len - VARHDRSZ; if (rlen > BLCKSZ - 128) - elog(ERROR, "bpchar: length of char() must be less than %d",BLCKSZ-128); + elog(ERROR, "bpchar: length of char() must be less than %d", BLCKSZ - 128); #ifdef STRINGDEBUG printf("bpchar- convert string length %d (%d) ->%d (%d)\n", @@ -163,13 +163,15 @@ bpchar(char *s, int32 len) VARSIZE(result) = len; r = VARDATA(result); #ifdef MULTIBYTE - /* truncate multi-byte string in a way not to break - multi-byte boundary */ - if (VARSIZE(s) > len) { - slen = pg_mbcliplen(VARDATA(s), VARSIZE(s)-VARHDRSZ, rlen); - } else { + + /* + * truncate multi-byte string in a way not to break multi-byte + * boundary + */ + if (VARSIZE(s) > len) + slen = pg_mbcliplen(VARDATA(s), VARSIZE(s) - VARHDRSZ, rlen); + else slen = VARSIZE(s) - VARHDRSZ; - } #else slen = VARSIZE(s) - VARHDRSZ; #endif @@ -206,7 +208,7 @@ bpchar(char *s, int32 len) * Converts an array of char() type to a specific internal length. * len is the length specified in () plus VARHDRSZ bytes. */ -ArrayType * +ArrayType * _bpchar(ArrayType *v, int32 len) { return array_map(v, BPCHAROID, bpchar, BPCHAROID, 1, len); @@ -331,7 +333,7 @@ varcharin(char *s, int dummy, int32 atttypmod) len = atttypmod; /* clip the string at max length */ if (len > BLCKSZ - 128) - elog(ERROR, "varcharin: length of char() must be less than %d",BLCKSZ-128); + elog(ERROR, "varcharin: length of char() must be less than %d", BLCKSZ - 128); result = (char *) palloc(len); VARSIZE(result) = len; @@ -390,15 +392,18 @@ varchar(char *s, int32 slen) /* only reach here if we need to truncate string... */ #ifdef MULTIBYTE - /* truncate multi-byte string in a way not to break - multi-byte boundary */ + + /* + * truncate multi-byte string in a way not to break multi-byte + * boundary + */ len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ); slen = len + VARHDRSZ; #else len = slen - VARHDRSZ; #endif - if (len > BLCKSZ-128) + if (len > BLCKSZ - 128) elog(ERROR, "varchar: length of varchar() must be less than BLCKSZ-128"); result = (char *) palloc(slen); @@ -412,7 +417,7 @@ varchar(char *s, int32 slen) * Converts an array of varchar() type to the specified size. * len is the length specified in () plus VARHDRSZ bytes. */ -ArrayType * +ArrayType * _varchar(ArrayType *v, int32 len) { return array_map(v, VARCHAROID, varchar, VARCHAROID, 1, len); diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 12095816fa1..b649ef225a3 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.47 1999/02/13 23:19:36 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.48 1999/05/25 16:12:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -314,7 +314,7 @@ textcat(text *t1, text *t2) * - string length * * If the starting position is zero or less, then return from the start of the string - * adjusting the length to be consistant with the "negative start" per SQL92. + * adjusting the length to be consistant with the "negative start" per SQL92. * If the length is less than zero, return the remaining string. * * Note that the arguments operate on octet length, @@ -352,11 +352,14 @@ text_substr(text *string, int32 m, int32 n) m = 1; n = 0; } - /* starting position before the start of the string? - * then offset into the string per SQL92 spec... */ + + /* + * starting position before the start of the string? then offset into + * the string per SQL92 spec... + */ else if (m < 1) { - n += (m-1); + n += (m - 1); m = 1; } @@ -588,10 +591,10 @@ text_ge(text *arg1, text *arg2) text * text_larger(text *arg1, text *arg2) { - text *result; - text *temp; + text *result; + text *temp; - temp = ((text_cmp(arg1, arg2) <= 0)? arg2: arg1); + temp = ((text_cmp(arg1, arg2) <= 0) ? arg2 : arg1); /* Make a copy */ @@ -604,10 +607,10 @@ text_larger(text *arg1, text *arg2) text * text_smaller(text *arg1, text *arg2) { - text *result; - text *temp; + text *result; + text *temp; - temp = ((text_cmp(arg1, arg2) > 0)? arg2: arg1); + temp = ((text_cmp(arg1, arg2) > 0) ? arg2 : arg1); /* Make a copy */ diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index 869df05df7c..80444d0a143 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.40 1999/05/10 00:46:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.41 1999/05/25 16:12:22 momjian Exp $ * * Notes: * XXX This needs to use exception.h to handle recovery when @@ -196,6 +196,7 @@ CatalogCacheInitializeCache(struct catcache * cache, if (cache->cc_key[i] > 0) { + /* * Yoiks. The implementation of the hashing code and the * implementation of int28's are at loggerheads. The right @@ -277,7 +278,7 @@ CatalogCacheSetId(CatCache *cacheInOutP, int id) #endif /* ---------------- - * comphash + * comphash * Compute a hash value, somehow. * * XXX explain algorithm here. diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 40155b36aa1..7cf66e22808 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.22 1999/05/10 00:46:07 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.23 1999/05/25 16:12:23 momjian Exp $ * * Note - this code is real crufty... * @@ -106,7 +106,7 @@ InvalidationEntryAllocate(uint16 size) } /* -------------------------------- - * LocalInvalidRegister + * LocalInvalidRegister * Returns a new local cache invalidation state containing a new entry. * -------------------------------- */ @@ -117,7 +117,7 @@ LocalInvalidRegister(LocalInvalid invalid, Assert(PointerIsValid(entry)); ((InvalidationUserData *) entry)->dataP[-1] = - (InvalidationUserData *) invalid; + (InvalidationUserData *) invalid; return entry; } @@ -504,7 +504,7 @@ InitLocalInvalidateData() /* - * DiscardInvalid + * DiscardInvalid * Causes the invalidated cache state to be discarded. * * Note: @@ -527,7 +527,7 @@ DiscardInvalid() } /* - * RegisterInvalid + * RegisterInvalid * Causes registration of invalidated state with other backends iff true. * * Note: @@ -559,7 +559,7 @@ RegisterInvalid(bool send) } /* - * RelationIdInvalidateHeapTuple + * RelationIdInvalidateHeapTuple * Causes the given tuple in a relation to be invalidated. * * Note: diff --git a/src/backend/utils/cache/rel.c b/src/backend/utils/cache/rel.c index 0603f675520..f37a97b34f6 100644 --- a/src/backend/utils/cache/rel.c +++ b/src/backend/utils/cache/rel.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/rel.c,v 1.4 1999/02/13 23:19:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/rel.c,v 1.5 1999/05/25 16:12:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,7 +29,7 @@ */ /* - * RelationGetIndexStrategy + * RelationGetIndexStrategy * Returns index strategy for a relation. * * Note: @@ -43,7 +43,7 @@ RelationGetIndexStrategy(Relation relation) } /* - * RelationSetIndexSupport + * RelationSetIndexSupport * Sets index strategy and support info for a relation. * * Note: diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 4affb0f6aec..f8c73b7b22c 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.61 1999/05/10 00:46:08 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.62 1999/05/25 16:12:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -396,7 +396,7 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo) switch (buildinfo.infotype) { case INFO_RELID: - return_tuple = ClassOidIndexScan(pg_class_desc,buildinfo.i.info_id); + return_tuple = ClassOidIndexScan(pg_class_desc, buildinfo.i.info_id); break; case INFO_RELNAME: @@ -707,20 +707,20 @@ RelationBuildRuleLock(Relation relation) rule->event = (int) heap_getattr(pg_rewrite_tuple, Anum_pg_rewrite_ev_type, pg_rewrite_tupdesc, - &isnull) - 48; + &isnull) - 48; rule->attrno = (int) heap_getattr(pg_rewrite_tuple, Anum_pg_rewrite_ev_attr, pg_rewrite_tupdesc, - &isnull); + &isnull); rule->isInstead = !!heap_getattr(pg_rewrite_tuple, - Anum_pg_rewrite_is_instead, pg_rewrite_tupdesc, - &isnull); + Anum_pg_rewrite_is_instead, pg_rewrite_tupdesc, + &isnull); ruleaction = heap_getattr(pg_rewrite_tuple, - Anum_pg_rewrite_ev_action, pg_rewrite_tupdesc, - &isnull); + Anum_pg_rewrite_ev_action, pg_rewrite_tupdesc, + &isnull); rule_evqual_string = heap_getattr(pg_rewrite_tuple, - Anum_pg_rewrite_ev_qual, pg_rewrite_tupdesc, - &isnull); + Anum_pg_rewrite_ev_qual, pg_rewrite_tupdesc, + &isnull); ruleaction = PointerGetDatum(textout((struct varlena *) DatumGetPointer(ruleaction))); rule_evqual_string = PointerGetDatum(textout((struct varlena *) DatumGetPointer(rule_evqual_string))); @@ -851,9 +851,7 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo) * ---------------- */ if (OidIsValid(relam)) - { relation->rd_am = (Form_pg_am) AccessMethodObjectIdGetForm(relam); - } /* ---------------- * initialize the tuple descriptor (relation->rd_att). @@ -1331,13 +1329,13 @@ RelationForgetRelation(Oid rid) MemoryContext oldcxt; List *curr; List *prev = NIL; - + oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt); - + foreach(curr, newlyCreatedRelns) { Relation reln = lfirst(curr); - + Assert(reln != NULL && reln->rd_myxactonly); if (RelationGetRelid(reln) == rid) break; @@ -1353,7 +1351,7 @@ RelationForgetRelation(Oid rid) pfree(curr); MemoryContextSwitchTo(oldcxt); } - + RelationFlushRelation(&relation, false); } } @@ -1378,6 +1376,7 @@ RelationIdInvalidateRelationCacheByRelationId(Oid relationId) */ if (PointerIsValid(relation) && !relation->rd_myxactonly) { + /* * The boolean onlyFlushReferenceCountZero in RelationFlushReln() * should be set to true when we are incrementing the command @@ -1484,8 +1483,8 @@ RelationRegisterRelation(Relation relation) /* * we've just created the relation. It is invisible to anyone else - * before the transaction is committed. Setting rd_myxactonly allows us - * to use the local buffer manager for select/insert/etc before the + * before the transaction is committed. Setting rd_myxactonly allows + * us to use the local buffer manager for select/insert/etc before the * end of transaction. (We also need to keep track of relations * created during a transaction and does the necessary clean up at the * end of the transaction.) - ay 3/95 @@ -1634,7 +1633,7 @@ AttrDefaultFetch(Relation relation) Relation adrel; Relation irel; ScanKeyData skey; - HeapTupleData tuple; + HeapTupleData tuple; Form_pg_attrdef adform; IndexScanDesc sd; RetrieveIndexResult indexRes; @@ -1722,7 +1721,7 @@ RelCheckFetch(Relation relation) Relation rcrel; Relation irel; ScanKeyData skey; - HeapTupleData tuple; + HeapTupleData tuple; IndexScanDesc sd; RetrieveIndexResult indexRes; Name rcname; diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index bd583ac0ce6..6eb0ed3527d 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.24 1999/02/13 23:19:45 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.25 1999/05/25 16:12:23 momjian Exp $ * * NOTES * These routines allow the parser/planner/executor to perform @@ -421,11 +421,11 @@ InitCatalogCache() Assert(!PointerIsValid((Pointer) SysCache[cacheId])); SysCache[cacheId] = InitSysCache(cacheinfo[cacheId].name, - cacheinfo[cacheId].indname, - cacheId, - cacheinfo[cacheId].nkeys, - cacheinfo[cacheId].key, - cacheinfo[cacheId].iScanFunc); + cacheinfo[cacheId].indname, + cacheId, + cacheinfo[cacheId].nkeys, + cacheinfo[cacheId].key, + cacheinfo[cacheId].iScanFunc); if (!PointerIsValid((char *) SysCache[cacheId])) { elog(ERROR, @@ -492,11 +492,11 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */ if (!PointerIsValid(SysCache[cacheId])) { SysCache[cacheId] = InitSysCache(cacheinfo[cacheId].name, - cacheinfo[cacheId].indname, - cacheId, - cacheinfo[cacheId].nkeys, - cacheinfo[cacheId].key, - cacheinfo[cacheId].iScanFunc); + cacheinfo[cacheId].indname, + cacheId, + cacheinfo[cacheId].nkeys, + cacheinfo[cacheId].key, + cacheinfo[cacheId].iScanFunc); if (!PointerIsValid(SysCache[cacheId])) elog(ERROR, "InitCatalogCache: Can't init cache %s(%d)", diff --git a/src/backend/utils/cache/temprel.c b/src/backend/utils/cache/temprel.c index 60c949fa434..9e9faaf8ab2 100644 --- a/src/backend/utils/cache/temprel.c +++ b/src/backend/utils/cache/temprel.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.2 1999/02/13 23:19:45 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.3 1999/05/25 16:12:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -47,16 +47,16 @@ static List *temp_rels = NIL; typedef struct TempTable { - char *user_relname; + char *user_relname; HeapTuple pg_class_tuple; -} TempTable; +} TempTable; void create_temp_relation(char *relname, HeapTuple pg_class_tuple) { MemoryContext oldcxt; - TempTable *temp_rel; + TempTable *temp_rel; oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt); @@ -65,7 +65,7 @@ create_temp_relation(char *relname, HeapTuple pg_class_tuple) /* save user-supplied name */ strcpy(temp_rel->user_relname, relname); - + temp_rel->pg_class_tuple = heap_copytuple(pg_class_tuple); temp_rels = lcons(temp_rel, temp_rels); @@ -76,24 +76,25 @@ create_temp_relation(char *relname, HeapTuple pg_class_tuple) void remove_all_temp_relations(void) { - List *l, *next; + List *l, + *next; l = temp_rels; while (l != NIL) { - TempTable *temp_rel = lfirst(l); + TempTable *temp_rel = lfirst(l); Form_pg_class classtuple; - classtuple = (Form_pg_class)GETSTRUCT(temp_rel->pg_class_tuple); + classtuple = (Form_pg_class) GETSTRUCT(temp_rel->pg_class_tuple); - next = lnext(l); /* do this first, l is deallocated */ + next = lnext(l); /* do this first, l is deallocated */ if (classtuple->relkind != RELKIND_INDEX) { - char relname[NAMEDATALEN]; + char relname[NAMEDATALEN]; /* safe from deallocation */ - strcpy(relname, temp_rel->user_relname); + strcpy(relname, temp_rel->user_relname); heap_destroy_with_catalog(relname); } else @@ -109,15 +110,16 @@ remove_temp_relation(Oid relid) { MemoryContext oldcxt; - List *l, *prev; - + List *l, + *prev; + oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt); prev = NIL; l = temp_rels; while (l != NIL) { - TempTable *temp_rel = lfirst(l); + TempTable *temp_rel = lfirst(l); if (temp_rel->pg_class_tuple->t_data->t_oid == relid) { @@ -152,11 +154,11 @@ remove_temp_relation(Oid relid) HeapTuple get_temp_rel_by_name(char *user_relname) { - List *l; + List *l; foreach(l, temp_rels) { - TempTable *temp_rel = lfirst(l); + TempTable *temp_rel = lfirst(l); if (strcmp(temp_rel->user_relname, user_relname) == 0) return temp_rel->pg_class_tuple; diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 588f378b5de..283cb01b1f9 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.44 1999/05/10 00:46:11 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.45 1999/05/25 16:12:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ static int Err_file = -1; static int ElogDebugIndentLevel = 0; /* - * elog + * elog * Old error logging function. */ void @@ -167,7 +167,7 @@ elog(int lev, const char *fmt,...) * front-end program, write to it first. This is important because * there's a bug in the socket code on ultrix. If the front end has * gone away (so the channel to it has been closed at the other end), - * then writing here can cause this backend to exit without warning + * then writing here can cause this backend to exit without warning * that is, write() does an exit(). In this case, our only hope of * finding out what's going on is if Err_file was set to some disk * log. This is a major pain. @@ -190,26 +190,32 @@ elog(int lev, const char *fmt,...) if (IsUnderPostmaster && lev > DEBUG) { /* notices are not errors, handle 'em differently */ - char msgtype; + char msgtype; + if (lev == NOTICE) msgtype = 'N'; else { - /* Abort any COPY OUT in progress when an error is detected. - * This hack is necessary because of poor design of copy protocol. + + /* + * Abort any COPY OUT in progress when an error is detected. + * This hack is necessary because of poor design of copy + * protocol. */ pq_endcopyout(true); msgtype = 'E'; } /* exclude the timestamp from msg sent to frontend */ pq_puttextmessage(msgtype, line + TIMESTAMP_SIZE); + /* * This flush is normally not necessary, since postgres.c will * flush out waiting data when control returns to the main loop. * But it seems best to leave it here, so that the client has some - * clue what happened if the backend dies before getting back to the - * main loop ... error/notice messages should not be a performance- - * critical path anyway, so an extra flush won't hurt much ... + * clue what happened if the backend dies before getting back to + * the main loop ... error/notice messages should not be a + * performance- critical path anyway, so an extra flush won't hurt + * much ... */ pq_flush(); } diff --git a/src/backend/utils/error/exc.c b/src/backend/utils/error/exc.c index aa556a62471..7384847d18e 100644 --- a/src/backend/utils/error/exc.c +++ b/src/backend/utils/error/exc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.24 1999/02/13 23:19:48 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.25 1999/05/25 16:12:26 momjian Exp $ * * NOTE * XXX this code needs improvement--check for state violations and @@ -48,7 +48,7 @@ extern char *ProgramName; */ /* - * EnableExceptionHandling + * EnableExceptionHandling * Enables/disables the exception handling system. * * Note: diff --git a/src/backend/utils/error/excid.c b/src/backend/utils/error/excid.c index bc92609e2b4..70842f3b565 100644 --- a/src/backend/utils/error/excid.c +++ b/src/backend/utils/error/excid.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/excid.c,v 1.5 1999/02/13 23:19:48 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/excid.c,v 1.6 1999/05/25 16:12:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -22,19 +22,19 @@ /* - * FailedAssertion + * FailedAssertion * Indicates an Assert(...) failed. */ Exception FailedAssertion = {"Failed Assertion"}; /* - * BadState + * BadState * Indicates a function call request is inconsistent with module state. */ Exception BadState = {"Bad State for Function Call"}; /* - * BadArg + * BadArg * Indicates a function call argument or arguments is out-of-bounds. */ Exception BadArg = {"Bad Argument to Function Call"}; @@ -44,19 +44,19 @@ Exception BadArg = {"Bad Argument to Function Call"}; *****************************************************************************/ /* - * BadAllocSize + * BadAllocSize * Indicates that an allocation request is of unreasonable size. */ Exception BadAllocSize = {"Too Large Allocation Request"}; /* - * ExhaustedMemory + * ExhaustedMemory * Indicates an dynamic memory allocation failed. */ Exception ExhaustedMemory = {"Memory Allocation Failed"}; /* - * Unimplemented + * Unimplemented * Indicates a function call request requires unimplemented code. */ Exception Unimplemented = {"Unimplemented Functionality"}; diff --git a/src/backend/utils/error/format.c b/src/backend/utils/error/format.c index dcc27cec024..f56e3f05b31 100644 --- a/src/backend/utils/error/format.c +++ b/src/backend/utils/error/format.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/format.c,v 1.10 1999/02/13 23:19:49 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/format.c,v 1.11 1999/05/25 16:12:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,7 @@ char * form(const char *fmt,...) { va_list args; + va_start(args, fmt); vsnprintf(FormBuf, FormMaxSize - 1, fmt, args); va_end(args); diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index 4b625bfc7c5..7d9b79575fd 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.25 1999/05/22 19:49:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.26 1999/05/25 16:12:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -237,14 +237,14 @@ void load_file(char *filename) { DynamicFileList *file_scanner, - *p; + *p; struct stat stat_buf; int done = 0; /* - * We need to do stat() in order to determine whether this is the - * same file as a previously loaded file; it's also handy so as to - * give a good error message if bogus file name given. + * We need to do stat() in order to determine whether this is the same + * file as a previously loaded file; it's also handy so as to give a + * good error message if bogus file name given. */ if (stat(filename, &stat_buf) == -1) elog(ERROR, "LOAD: could not open file '%s': %m", filename); @@ -292,4 +292,5 @@ trigger_dynamic(char *filename, char *funcname) return trigger_fn; } + #endif diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 09f9a161138..d5b24cf3410 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.27 1999/05/10 04:02:05 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.28 1999/05/25 16:12:28 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -81,8 +81,10 @@ fmgr_pl(char *arg0,...) static char * fmgr_untrusted(char *arg0,...) { - /* Currently these are unsupported. Someday we might do something like - * forking a subprocess to execute 'em. + + /* + * Currently these are unsupported. Someday we might do something + * like forking a subprocess to execute 'em. */ elog(ERROR, "Untrusted functions not supported."); return NULL; /* keep compiler happy */ @@ -96,9 +98,11 @@ fmgr_untrusted(char *arg0,...) static char * fmgr_sql(char *arg0,...) { + /* - * XXX It'd be really nice to support SQL functions anywhere that builtins - * are supported. What would we have to do? What pitfalls are there? + * XXX It'd be really nice to support SQL functions anywhere that + * builtins are supported. What would we have to do? What pitfalls + * are there? */ elog(ERROR, "SQL-language function not supported in this context."); return NULL; /* keep compiler happy */ @@ -215,14 +219,18 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo) if ((fcp = fmgr_isbuiltin(procedureId)) != NULL) { - /* Fast path for builtin functions: don't bother consulting pg_proc */ + + /* + * Fast path for builtin functions: don't bother consulting + * pg_proc + */ finfo->fn_addr = fcp->func; finfo->fn_nargs = fcp->nargs; } else { procedureTuple = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(procedureId), + ObjectIdGetDatum(procedureId), 0, 0, 0); if (!HeapTupleIsValid(procedureTuple)) { @@ -240,14 +248,16 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo) switch (language) { case INTERNALlanguageId: + /* - * For an ordinary builtin function, we should never get here - * because the isbuiltin() search above will have succeeded. - * However, if the user has done a CREATE FUNCTION to create - * an alias for a builtin function, we end up here. In that - * case we have to look up the function by name. The name - * of the internal function is stored in prosrc (it doesn't - * have to be the same as the name of the alias!) + * For an ordinary builtin function, we should never get + * here because the isbuiltin() search above will have + * succeeded. However, if the user has done a CREATE + * FUNCTION to create an alias for a builtin function, we + * end up here. In that case we have to look up the + * function by name. The name of the internal function is + * stored in prosrc (it doesn't have to be the same as the + * name of the alias!) */ prosrc = textout(&(procedureStruct->prosrc)); finfo->fn_addr = fmgr_lookupByName(prosrc); diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c index dd601bee742..933533b7549 100644 --- a/src/backend/utils/hash/dynahash.c +++ b/src/backend/utils/hash/dynahash.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.21 1999/03/07 23:03:32 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.22 1999/05/25 16:12:28 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -175,8 +175,10 @@ hash_create(int nelem, HASHCTL *info, int flags) if (flags & HASH_SHARED_MEM) { - /* ctl structure is preallocated for shared memory tables. - * Note that HASH_DIRSIZE had better be set as well. + + /* + * ctl structure is preallocated for shared memory tables. Note + * that HASH_DIRSIZE had better be set as well. */ hashp->hctl = (HHDR *) info->hctl; @@ -296,9 +298,9 @@ init_htab(HTAB *hashp, int nelem) hctl = hashp->hctl; /* - * Divide number of elements by the fill factor to determine a - * desired number of buckets. Allocate space for the next greater - * power of two number of buckets + * Divide number of elements by the fill factor to determine a desired + * number of buckets. Allocate space for the next greater power of + * two number of buckets */ nelem = (nelem - 1) / hctl->ffactor + 1; @@ -308,14 +310,15 @@ init_htab(HTAB *hashp, int nelem) hctl->high_mask = (nbuckets << 1) - 1; /* - * Figure number of directory segments needed, round up to a power of 2 + * Figure number of directory segments needed, round up to a power of + * 2 */ nsegs = (nbuckets - 1) / hctl->ssize + 1; nsegs = 1 << my_log2(nsegs); /* - * Make sure directory is big enough. - * If pre-allocated directory is too small, choke (caller screwed up). + * Make sure directory is big enough. If pre-allocated directory is + * too small, choke (caller screwed up). */ if (nsegs > hctl->dsize) { @@ -371,12 +374,12 @@ init_htab(HTAB *hashp, int nelem) long hash_estimate_size(long num_entries, long keysize, long datasize) { - long size = 0; - long nBuckets, - nSegments, - nDirEntries, - nRecordAllocs, - recordSize; + long size = 0; + long nBuckets, + nSegments, + nDirEntries, + nRecordAllocs, + recordSize; /* estimate number of buckets wanted */ nBuckets = 1L << my_log2((num_entries - 1) / DEF_FFACTOR + 1); @@ -388,7 +391,7 @@ hash_estimate_size(long num_entries, long keysize, long datasize) nDirEntries <<= 1; /* dir_alloc doubles dsize at each call */ /* fixed control info */ - size += MAXALIGN(sizeof(HHDR)); /* but not HTAB, per above */ + size += MAXALIGN(sizeof(HHDR)); /* but not HTAB, per above */ /* directory */ size += MAXALIGN(nDirEntries * sizeof(SEG_OFFSET)); /* segments */ @@ -665,8 +668,10 @@ hash_search(HTAB *hashp, */ if (++hctl->nkeys / (hctl->max_bucket + 1) > hctl->ffactor) { - /* NOTE: failure to expand table is not a fatal error, - * it just means we have to run at higher fill factor than we wanted. + + /* + * NOTE: failure to expand table is not a fatal error, it just + * means we have to run at higher fill factor than we wanted. */ expand_table(hashp); } @@ -778,7 +783,7 @@ expand_table(HTAB *hashp) { /* Allocate new segment if necessary -- could fail if dir full */ if (new_segnum >= hctl->dsize) - if (! dir_realloc(hashp)) + if (!dir_realloc(hashp)) return 0; if (!(hashp->dir[new_segnum] = seg_alloc(hashp))) return 0; @@ -872,7 +877,7 @@ seg_alloc(HTAB *hashp) SEG_OFFSET segOffset; segp = (SEGMENT) hashp->alloc((unsigned long) - sizeof(BUCKET_INDEX) * hashp->hctl->ssize); + sizeof(BUCKET_INDEX) * hashp->hctl->ssize); if (!segp) return 0; @@ -917,8 +922,9 @@ bucket_alloc(HTAB *hashp) lastIndex = hashp->hctl->freeBucketIndex; hashp->hctl->freeBucketIndex = tmpIndex; - /* initialize each bucket to point to the one behind it. - * NOTE: loop sets last bucket incorrectly; we fix below. + /* + * initialize each bucket to point to the one behind it. NOTE: loop + * sets last bucket incorrectly; we fix below. */ for (i = 0; i < BUCKET_ALLOC_INCR; i++) { diff --git a/src/backend/utils/init/enbl.c b/src/backend/utils/init/enbl.c index b772ba0d105..78c5ab10403 100644 --- a/src/backend/utils/init/enbl.c +++ b/src/backend/utils/init/enbl.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.6 1999/02/13 23:19:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.7 1999/05/25 16:12:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -15,7 +15,7 @@ #include "utils/module.h" /* where the declarations go */ /* - * BypassEnable + * BypassEnable * False iff enable/disable processing is required given on and "*countP." * * Note: diff --git a/src/backend/utils/init/findbe.c b/src/backend/utils/init/findbe.c index ada3f65c412..783f8ac1b95 100644 --- a/src/backend/utils/init/findbe.c +++ b/src/backend/utils/init/findbe.c @@ -1,12 +1,12 @@ /*------------------------------------------------------------------------- * - * findbe.c + * findbe.c * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.13 1999/02/13 23:20:00 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.14 1999/05/25 16:12:33 momjian Exp $ * *------------------------------------------------------------------------- */ diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 588cb060fdf..1d4225e5821 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.29 1999/05/22 17:47:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.30 1999/05/25 16:12:34 momjian Exp $ * * NOTES * Globals used all over the place should be declared here and not @@ -46,6 +46,7 @@ struct Port *MyProcPort; long MyCancelKey; char *DataDir = NULL; + /* * The PGDATA directory user says to use, or defaults to via environment * variable. NULL if no option given and no environment variable set diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index ce6c4ca3210..86328bbd56e 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.28 1999/05/22 17:47:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.29 1999/05/25 16:12:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -40,7 +40,7 @@ #include "storage/ipc.h" /* for proc_exit */ /* - * EnableAbortEnvVarName + * EnableAbortEnvVarName * Enables system abort iff set to a non-empty string in environment. */ #define EnableAbortEnvVarName "POSTGRESABORT" @@ -69,7 +69,7 @@ unsigned char RecodeBackTable[128]; */ /* - * ExitPostgres + * ExitPostgres * Exit POSTGRES with a status code. * * Note: @@ -89,7 +89,7 @@ ExitPostgres(ExitStatus status) } /* - * AbortPostgres + * AbortPostgres * Abort POSTGRES dumping core. * * Note: @@ -138,6 +138,7 @@ StatusPostmasterExit(int status) /* someday, do some real cleanup and then call the LISP exit */ proc_exit(status); } + #endif @@ -149,7 +150,7 @@ static ProcessingMode Mode = NoProcessing; #ifdef NOT_USED /* - * IsNoProcessingMode + * IsNoProcessingMode * True iff processing mode is NoProcessing. */ bool @@ -157,10 +158,11 @@ IsNoProcessingMode() { return (bool) (Mode == NoProcessing); } + #endif /* - * IsBootstrapProcessingMode + * IsBootstrapProcessingMode * True iff processing mode is BootstrapProcessing. */ bool @@ -170,7 +172,7 @@ IsBootstrapProcessingMode() } /* - * IsInitProcessingMode + * IsInitProcessingMode * True iff processing mode is InitProcessing. */ bool @@ -180,7 +182,7 @@ IsInitProcessingMode() } /* - * IsNormalProcessingMode + * IsNormalProcessingMode * True iff processing mode is NormalProcessing. */ bool @@ -190,7 +192,7 @@ IsNormalProcessingMode() } /* - * SetProcessingMode + * SetProcessingMode * Sets mode of processing as specified. * * Exceptions: diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index e93480da1db..0c2711483fb 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.39 1999/02/22 19:55:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.40 1999/05/25 16:12:36 momjian Exp $ * * NOTES * InitPostgres() is the function called from PostgresMain @@ -143,7 +143,7 @@ InitMyDatabaseInfo(char *name) /* - * DoChdirAndInitDatabaseNameAndPath + * DoChdirAndInitDatabaseNameAndPath * Set current directory to the database directory for the database * named <name>. * Also set global variables DatabasePath and DatabaseName to those @@ -415,7 +415,7 @@ InitStdio() } /* -------------------------------- - * InitPostgres + * InitPostgres * Initialize POSTGRES. * * Note: diff --git a/src/backend/utils/mb/alt.c b/src/backend/utils/mb/alt.c index 54f69cc594b..3d1439a5a3a 100644 --- a/src/backend/utils/mb/alt.c +++ b/src/backend/utils/mb/alt.c @@ -4,63 +4,69 @@ * * Tatsuo Ishii * - * $Id: alt.c,v 1.1 1999/03/24 07:01:36 ishii Exp $ + * $Id: alt.c,v 1.2 1999/05/25 16:12:38 momjian Exp $ */ #include <stdio.h> main() { - int i; - char koitab[128],alttab[128]; - char buf[4096]; - int koi,alt; + int i; + char koitab[128], + alttab[128]; + char buf[4096]; + int koi, + alt; - for (i=0;i<128;i++) { - koitab[i] = alttab[i] = 0; - } + for (i = 0; i < 128; i++) + koitab[i] = alttab[i] = 0; - while (fgets(buf,sizeof(buf),stdin) != NULL) { - if (*buf == '#') { - continue; - } - sscanf(buf,"%d %d",&koi,&alt); - if (koi < 128 || koi > 255 || alt < 128 || alt > 255) { - fprintf(stderr,"invalid value %d\n",koi); - exit(1); - } - koitab[koi-128] = alt; - alttab[alt-128] = koi; - } + while (fgets(buf, sizeof(buf), stdin) != NULL) + { + if (*buf == '#') + continue; + sscanf(buf, "%d %d", &koi, &alt); + if (koi < 128 || koi > 255 || alt < 128 || alt > 255) + { + fprintf(stderr, "invalid value %d\n", koi); + exit(1); + } + koitab[koi - 128] = alt; + alttab[alt - 128] = koi; + } - i = 0; - printf("static char koi2alt[] = {\n"); - while (i < 128) { - int j = 0; - while (j < 8) { - printf("0x%02x",koitab[i++]); - j++; - if (i >= 128) { - break; - } - printf(", "); - } - printf("\n"); - } - printf("};\n"); + i = 0; + printf("static char koi2alt[] = {\n"); + while (i < 128) + { + int j = 0; - i = 0; - printf("static char alt2koi[] = {\n"); - while (i < 128) { - int j = 0; - while (j < 8) { - printf("0x%02x",alttab[i++]); - j++; - if (i >= 128) { - break; - } - printf(", "); - } - printf("\n"); - } - printf("};\n"); + while (j < 8) + { + printf("0x%02x", koitab[i++]); + j++; + if (i >= 128) + break; + printf(", "); + } + printf("\n"); + } + printf("};\n"); + + i = 0; + printf("static char alt2koi[] = {\n"); + while (i < 128) + { + int j = 0; + + while (j < 8) + { + printf("0x%02x", alttab[i++]); + j++; + if (i >= 128) + break; + printf(", "); + } + printf("\n"); + } + printf("};\n"); } diff --git a/src/backend/utils/mb/big5.c b/src/backend/utils/mb/big5.c index 105854d2479..d35ee71b9ff 100644 --- a/src/backend/utils/mb/big5.c +++ b/src/backend/utils/mb/big5.c @@ -4,344 +4,372 @@ * This program is partially copied from lv(Multilingual file viewer) * and slightly modified. lv is written and copyrighted by NARITA Tomio * (nrt@web.ad.jp). - * + * * 1999/1/15 Tatsuo Ishii * - * $Id: big5.c,v 1.1 1999/02/02 18:51:22 momjian Exp $ + * $Id: big5.c,v 1.2 1999/05/25 16:12:40 momjian Exp $ */ #include "mb/pg_wchar.h" -typedef struct { - unsigned short code, peer; -} codes_t; +typedef struct +{ + unsigned short code, + peer; +} codes_t; /* map Big5 Level 1 to CNS 11643-1992 Plane 1 */ -static codes_t big5Level1ToCnsPlane1[ 25 ] = { /* range */ - { 0xA140, 0x2121 }, - { 0xA1F6, 0x2258 }, - { 0xA1F7, 0x2257 }, - { 0xA1F8, 0x2259 }, - { 0xA2AF, 0x2421 }, - { 0xA3C0, 0x4221 }, - { 0xa3e1, 0x0000 }, - { 0xA440, 0x4421 }, - { 0xACFE, 0x5753 }, - { 0xacff, 0x0000 }, - { 0xAD40, 0x5323 }, - { 0xAFD0, 0x5754 }, - { 0xBBC8, 0x6B51 }, - { 0xBE52, 0x6B50 }, - { 0xBE53, 0x6F5C }, - { 0xC1AB, 0x7536 }, - { 0xC2CB, 0x7535 }, - { 0xC2CC, 0x7737 }, - { 0xC361, 0x782E }, - { 0xC3B9, 0x7865 }, - { 0xC3BA, 0x7864 }, - { 0xC3BB, 0x7866 }, - { 0xC456, 0x782D }, - { 0xC457, 0x7962 }, - { 0xc67f, 0x0000 } +static codes_t big5Level1ToCnsPlane1[25] = { /* range */ + {0xA140, 0x2121}, + {0xA1F6, 0x2258}, + {0xA1F7, 0x2257}, + {0xA1F8, 0x2259}, + {0xA2AF, 0x2421}, + {0xA3C0, 0x4221}, + {0xa3e1, 0x0000}, + {0xA440, 0x4421}, + {0xACFE, 0x5753}, + {0xacff, 0x0000}, + {0xAD40, 0x5323}, + {0xAFD0, 0x5754}, + {0xBBC8, 0x6B51}, + {0xBE52, 0x6B50}, + {0xBE53, 0x6F5C}, + {0xC1AB, 0x7536}, + {0xC2CB, 0x7535}, + {0xC2CC, 0x7737}, + {0xC361, 0x782E}, + {0xC3B9, 0x7865}, + {0xC3BA, 0x7864}, + {0xC3BB, 0x7866}, + {0xC456, 0x782D}, + {0xC457, 0x7962}, + {0xc67f, 0x0000} }; /* map CNS 11643-1992 Plane 1 to Big5 Level 1 */ -static codes_t cnsPlane1ToBig5Level1[ 26 ] = { /* range */ - { 0x2121, 0xA140 }, - { 0x2257, 0xA1F7 }, - { 0x2258, 0xA1F6 }, - { 0x2259, 0xA1F8 }, - { 0x234f, 0x0000 }, - { 0x2421, 0xA2AF }, - { 0x2571, 0x0000 }, - { 0x4221, 0xA3C0 }, - { 0x4242, 0x0000 }, - { 0x4421, 0xA440 }, - { 0x5323, 0xAD40 }, - { 0x5753, 0xACFE }, - { 0x5754, 0xAFD0 }, - { 0x6B50, 0xBE52 }, - { 0x6B51, 0xBBC8 }, - { 0x6F5C, 0xBE53 }, - { 0x7535, 0xC2CB }, - { 0x7536, 0xC1AB }, - { 0x7737, 0xC2CC }, - { 0x782D, 0xC456 }, - { 0x782E, 0xC361 }, - { 0x7864, 0xC3BA }, - { 0x7865, 0xC3B9 }, - { 0x7866, 0xC3BB }, - { 0x7962, 0xC457 }, - { 0x7d4c, 0x0000 } +static codes_t cnsPlane1ToBig5Level1[26] = { /* range */ + {0x2121, 0xA140}, + {0x2257, 0xA1F7}, + {0x2258, 0xA1F6}, + {0x2259, 0xA1F8}, + {0x234f, 0x0000}, + {0x2421, 0xA2AF}, + {0x2571, 0x0000}, + {0x4221, 0xA3C0}, + {0x4242, 0x0000}, + {0x4421, 0xA440}, + {0x5323, 0xAD40}, + {0x5753, 0xACFE}, + {0x5754, 0xAFD0}, + {0x6B50, 0xBE52}, + {0x6B51, 0xBBC8}, + {0x6F5C, 0xBE53}, + {0x7535, 0xC2CB}, + {0x7536, 0xC1AB}, + {0x7737, 0xC2CC}, + {0x782D, 0xC456}, + {0x782E, 0xC361}, + {0x7864, 0xC3BA}, + {0x7865, 0xC3B9}, + {0x7866, 0xC3BB}, + {0x7962, 0xC457}, + {0x7d4c, 0x0000} }; /* map Big5 Level 2 to CNS 11643-1992 Plane 2 */ -static codes_t big5Level2ToCnsPlane2[ 48 ] = { /* range */ - { 0xC940, 0x2121 }, - { 0xc94a, 0x0000 }, - { 0xC94B, 0x212B }, - { 0xC96C, 0x214D }, - { 0xC9BE, 0x214C }, - { 0xC9BF, 0x217D }, - { 0xC9ED, 0x224E }, - { 0xCAF7, 0x224D }, - { 0xCAF8, 0x2439 }, - { 0xD77A, 0x3F6A }, - { 0xD77B, 0x387E }, - { 0xDBA7, 0x3F6B }, - { 0xDDFC, 0x4176 }, - { 0xDDFD, 0x4424 }, - { 0xE8A3, 0x554C }, - { 0xE976, 0x5723 }, - { 0xEB5B, 0x5A29 }, - { 0xEBF1, 0x554B }, - { 0xEBF2, 0x5B3F }, - { 0xECDE, 0x5722 }, - { 0xECDF, 0x5C6A }, - { 0xEDAA, 0x5D75 }, - { 0xEEEB, 0x642F }, - { 0xEEEC, 0x6039 }, - { 0xF056, 0x5D74 }, - { 0xF057, 0x6243 }, - { 0xF0CB, 0x5A28 }, - { 0xF0CC, 0x6337 }, - { 0xF163, 0x6430 }, - { 0xF16B, 0x6761 }, - { 0xF16C, 0x6438 }, - { 0xF268, 0x6934 }, - { 0xF269, 0x6573 }, - { 0xF2C3, 0x664E }, - { 0xF375, 0x6762 }, - { 0xF466, 0x6935 }, - { 0xF4B5, 0x664D }, - { 0xF4B6, 0x6962 }, - { 0xF4FD, 0x6A4C }, - { 0xF663, 0x6A4B }, - { 0xF664, 0x6C52 }, - { 0xF977, 0x7167 }, - { 0xF9C4, 0x7166 }, - { 0xF9C5, 0x7234 }, - { 0xF9C6, 0x7240 }, - { 0xF9C7, 0x7235 }, - { 0xF9D2, 0x7241 }, - { 0xf9d6, 0x0000 } +static codes_t big5Level2ToCnsPlane2[48] = { /* range */ + {0xC940, 0x2121}, + {0xc94a, 0x0000}, + {0xC94B, 0x212B}, + {0xC96C, 0x214D}, + {0xC9BE, 0x214C}, + {0xC9BF, 0x217D}, + {0xC9ED, 0x224E}, + {0xCAF7, 0x224D}, + {0xCAF8, 0x2439}, + {0xD77A, 0x3F6A}, + {0xD77B, 0x387E}, + {0xDBA7, 0x3F6B}, + {0xDDFC, 0x4176}, + {0xDDFD, 0x4424}, + {0xE8A3, 0x554C}, + {0xE976, 0x5723}, + {0xEB5B, 0x5A29}, + {0xEBF1, 0x554B}, + {0xEBF2, 0x5B3F}, + {0xECDE, 0x5722}, + {0xECDF, 0x5C6A}, + {0xEDAA, 0x5D75}, + {0xEEEB, 0x642F}, + {0xEEEC, 0x6039}, + {0xF056, 0x5D74}, + {0xF057, 0x6243}, + {0xF0CB, 0x5A28}, + {0xF0CC, 0x6337}, + {0xF163, 0x6430}, + {0xF16B, 0x6761}, + {0xF16C, 0x6438}, + {0xF268, 0x6934}, + {0xF269, 0x6573}, + {0xF2C3, 0x664E}, + {0xF375, 0x6762}, + {0xF466, 0x6935}, + {0xF4B5, 0x664D}, + {0xF4B6, 0x6962}, + {0xF4FD, 0x6A4C}, + {0xF663, 0x6A4B}, + {0xF664, 0x6C52}, + {0xF977, 0x7167}, + {0xF9C4, 0x7166}, + {0xF9C5, 0x7234}, + {0xF9C6, 0x7240}, + {0xF9C7, 0x7235}, + {0xF9D2, 0x7241}, + {0xf9d6, 0x0000} }; /* map CNS 11643-1992 Plane 2 to Big5 Level 2 */ -static codes_t cnsPlane2ToBig5Level2[ 49 ] = { /* range */ - { 0x2121, 0xC940 }, - { 0x212B, 0xC94B }, - { 0x214C, 0xC9BE }, - { 0x214D, 0xC96C }, - { 0x217D, 0xC9BF }, - { 0x224D, 0xCAF7 }, - { 0x224E, 0xC9ED }, - { 0x2439, 0xCAF8 }, - { 0x387E, 0xD77B }, - { 0x3F6A, 0xD77A }, - { 0x3F6B, 0xDBA7 }, - { 0x4424, 0x0000 }, - { 0x4176, 0xDDFC }, - { 0x4177, 0x0000 }, - { 0x4424, 0xDDFD }, - { 0x554B, 0xEBF1 }, - { 0x554C, 0xE8A3 }, - { 0x5722, 0xECDE }, - { 0x5723, 0xE976 }, - { 0x5A28, 0xF0CB }, - { 0x5A29, 0xEB5B }, - { 0x5B3F, 0xEBF2 }, - { 0x5C6A, 0xECDF }, - { 0x5D74, 0xF056 }, - { 0x5D75, 0xEDAA }, - { 0x6039, 0xEEEC }, - { 0x6243, 0xF057 }, - { 0x6337, 0xF0CC }, - { 0x642F, 0xEEEB }, - { 0x6430, 0xF163 }, - { 0x6438, 0xF16C }, - { 0x6573, 0xF269 }, - { 0x664D, 0xF4B5 }, - { 0x664E, 0xF2C3 }, - { 0x6761, 0xF16B }, - { 0x6762, 0xF375 }, - { 0x6934, 0xF268 }, - { 0x6935, 0xF466 }, - { 0x6962, 0xF4B6 }, - { 0x6A4B, 0xF663 }, - { 0x6A4C, 0xF4FD }, - { 0x6C52, 0xF664 }, - { 0x7166, 0xF9C4 }, - { 0x7167, 0xF977 }, - { 0x7234, 0xF9C5 }, - { 0x7235, 0xF9C7 }, - { 0x7240, 0xF9C6 }, - { 0x7241, 0xF9D2 }, - { 0x7245, 0x0000 } +static codes_t cnsPlane2ToBig5Level2[49] = { /* range */ + {0x2121, 0xC940}, + {0x212B, 0xC94B}, + {0x214C, 0xC9BE}, + {0x214D, 0xC96C}, + {0x217D, 0xC9BF}, + {0x224D, 0xCAF7}, + {0x224E, 0xC9ED}, + {0x2439, 0xCAF8}, + {0x387E, 0xD77B}, + {0x3F6A, 0xD77A}, + {0x3F6B, 0xDBA7}, + {0x4424, 0x0000}, + {0x4176, 0xDDFC}, + {0x4177, 0x0000}, + {0x4424, 0xDDFD}, + {0x554B, 0xEBF1}, + {0x554C, 0xE8A3}, + {0x5722, 0xECDE}, + {0x5723, 0xE976}, + {0x5A28, 0xF0CB}, + {0x5A29, 0xEB5B}, + {0x5B3F, 0xEBF2}, + {0x5C6A, 0xECDF}, + {0x5D74, 0xF056}, + {0x5D75, 0xEDAA}, + {0x6039, 0xEEEC}, + {0x6243, 0xF057}, + {0x6337, 0xF0CC}, + {0x642F, 0xEEEB}, + {0x6430, 0xF163}, + {0x6438, 0xF16C}, + {0x6573, 0xF269}, + {0x664D, 0xF4B5}, + {0x664E, 0xF2C3}, + {0x6761, 0xF16B}, + {0x6762, 0xF375}, + {0x6934, 0xF268}, + {0x6935, 0xF466}, + {0x6962, 0xF4B6}, + {0x6A4B, 0xF663}, + {0x6A4C, 0xF4FD}, + {0x6C52, 0xF664}, + {0x7166, 0xF9C4}, + {0x7167, 0xF977}, + {0x7234, 0xF9C5}, + {0x7235, 0xF9C7}, + {0x7240, 0xF9C6}, + {0x7241, 0xF9D2}, + {0x7245, 0x0000} }; /* Big Five Level 1 Correspondence to CNS 11643-1992 Plane 4 */ static unsigned short b1c4[][2] = { - {0xC879, 0x2123}, - {0xC87B, 0x2124}, - {0xC87D, 0x212A}, - {0xC8A2, 0x2152} + {0xC879, 0x2123}, + {0xC87B, 0x2124}, + {0xC87D, 0x212A}, + {0xC8A2, 0x2152} }; /* Big Five Level 2 Correspondence to CNS 11643-1992 Plane 3 */ static unsigned short b2c3[][2] = { - {0xF9D6, 0x4337}, - {0xF9D7, 0x4F50}, - {0xF9D8, 0x444E}, - {0xF9D9, 0x504A}, - {0xF9DA, 0x2C5D}, - {0xF9DB, 0x3D7E}, - {0xF9DC, 0x4B5C} + {0xF9D6, 0x4337}, + {0xF9D7, 0x4F50}, + {0xF9D8, 0x444E}, + {0xF9D9, 0x504A}, + {0xF9DA, 0x2C5D}, + {0xF9DB, 0x3D7E}, + {0xF9DC, 0x4B5C} }; static unsigned short BinarySearchRange -(codes_t *array, int high, unsigned short code ) + (codes_t * array, int high, unsigned short code) { - int low, mid, distance, tmp; + int low, + mid, + distance, + tmp; - low = 0; - mid = high >> 1; + low = 0; + mid = high >> 1; - for( ; low <= high ; mid = ( low + high ) >> 1 ){ - if( ( array[ mid ].code <= code ) && ( array[ mid + 1 ].code > code ) ){ - if( 0 == array[ mid ].peer ) - return 0; - if( code >= 0xa140U ){ - /* big5 to cns */ - tmp = ( ( code & 0xff00 ) - ( array[ mid ].code & 0xff00 ) ) >> 8; - high = code & 0x00ff; - low = array[ mid ].code & 0x00ff; - /* - * NOTE: big5 high_byte: 0xa1-0xfe, low_byte: 0x40-0x7e, 0xa1-0xfe - * (radicals: 0x00-0x3e, 0x3f-0x9c) - * big5 radix is 0x9d. [region_low, region_high] - * We should remember big5 has two different regions (above). - * There is a bias for the distance between these regions. - * 0xa1 - 0x7e + bias = 1 (Distance between 0xa1 and 0x7e is 1.) - * bias = - 0x22. - */ - distance = tmp * 0x9d + high - low + - ( high >= 0xa1 ? ( low >= 0xa1 ? 0 : - 0x22 ) - : ( low >= 0xa1 ? + 0x22 : 0 ) ); - /* - * NOTE: we have to convert the distance into a code point. - * The code point's low_byte is 0x21 plus mod_0x5e. - * In the first, we extract the mod_0x5e of the starting - * code point, subtracting 0x21, and add distance to it. - * Then we calculate again mod_0x5e of them, and restore - * the final codepoint, adding 0x21. - */ - tmp = ( array[ mid ].peer & 0x00ff ) + distance - 0x21; - tmp = ( array[ mid ].peer & 0xff00 ) + ( ( tmp / 0x5e ) << 8 ) - + 0x21 + tmp % 0x5e; - return tmp; - } else { - /* cns to big5 */ - tmp = ( ( code & 0xff00 ) - ( array[ mid ].code & 0xff00 ) ) >> 8; - /* - * NOTE: ISO charsets ranges between 0x21-0xfe (94charset). - * Its radix is 0x5e. But there is no distance bias like big5. - */ - distance = tmp * 0x5e - + ( (int)( code & 0x00ff ) - (int)( array[ mid ].code & 0x00ff ) ); - /* - * NOTE: Similar to big5 to cns conversion, we extract mod_0x9d and - * restore mod_0x9d into a code point. - */ - low = array[ mid ].peer & 0x00ff; - tmp = low + distance - ( low >= 0xa1 ? 0x62 : 0x40 ); - low = tmp % 0x9d; - tmp = ( array[ mid ].peer & 0xff00 ) + ( ( tmp / 0x9d ) << 8 ) - + ( low > 0x3e ? 0x62 : 0x40 ) + low; - return tmp; - } - } else if( array[ mid ].code > code ){ - high = mid - 1; - } else { - low = mid + 1; - } - } + for (; low <= high; mid = (low + high) >> 1) + { + if ((array[mid].code <= code) && (array[mid + 1].code > code)) + { + if (0 == array[mid].peer) + return 0; + if (code >= 0xa140 U) + { + /* big5 to cns */ + tmp = ((code & 0xff00) - (array[mid].code & 0xff00)) >> 8; + high = code & 0x00ff; + low = array[mid].code & 0x00ff; + + /* + * NOTE: big5 high_byte: 0xa1-0xfe, low_byte: 0x40-0x7e, + * 0xa1-0xfe (radicals: 0x00-0x3e, 0x3f-0x9c) big5 radix + * is 0x9d. [region_low, region_high] + * We should remember big5 has two different regions + * (above). There is a bias for the distance between these + * regions. 0xa1 - 0x7e + bias = 1 (Distance between 0xa1 + * and 0x7e is 1.) bias = - 0x22. + */ + distance = tmp * 0x9d + high - low + + (high >= 0xa1 ? (low >= 0xa1 ? 0 : -0x22) + : (low >= 0xa1 ? +0x22 : 0)); - return 0; + /* + * NOTE: we have to convert the distance into a code + * point. The code point's low_byte is 0x21 plus mod_0x5e. + * In the first, we extract the mod_0x5e of the starting + * code point, subtracting 0x21, and add distance to it. + * Then we calculate again mod_0x5e of them, and restore + * the final codepoint, adding 0x21. + */ + tmp = (array[mid].peer & 0x00ff) + distance - 0x21; + tmp = (array[mid].peer & 0xff00) + ((tmp / 0x5e) << 8) + + 0x21 + tmp % 0x5e; + return tmp; + } + else + { + /* cns to big5 */ + tmp = ((code & 0xff00) - (array[mid].code & 0xff00)) >> 8; + + /* + * NOTE: ISO charsets ranges between 0x21-0xfe + * (94charset). Its radix is 0x5e. But there is no + * distance bias like big5. + */ + distance = tmp * 0x5e + + ((int) (code & 0x00ff) - (int) (array[mid].code & 0x00ff)); + + /* + * NOTE: Similar to big5 to cns conversion, we extract + * mod_0x9d and restore mod_0x9d into a code point. + */ + low = array[mid].peer & 0x00ff; + tmp = low + distance - (low >= 0xa1 ? 0x62 : 0x40); + low = tmp % 0x9d; + tmp = (array[mid].peer & 0xff00) + ((tmp / 0x9d) << 8) + + (low > 0x3e ? 0x62 : 0x40) + low; + return tmp; + } + } + else if (array[mid].code > code) + high = mid - 1; + else + low = mid + 1; + } + + return 0; } -unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc ) +unsigned short +BIG5toCNS(unsigned short big5, unsigned char *lc) { - unsigned short cns = 0; - int i; + unsigned short cns = 0; + int i; - if( big5 < 0xc940U ){ - /* level 1 */ + if (big5 < 0xc940 U) + { + /* level 1 */ - for (i=0;i<sizeof(b1c4)/sizeof(unsigned short);i++) { - if (b1c4[i][0] == big5) { - *lc = LC_CNS11643_4; - return(b1c4[i][1] | 0x8080U); - } - } + for (i = 0; i < sizeof(b1c4) / sizeof(unsigned short); i++) + { + if (b1c4[i][0] == big5) + { + *lc = LC_CNS11643_4; + return (b1c4[i][1] | 0x8080 U); + } + } - if( 0 < (cns = BinarySearchRange( big5Level1ToCnsPlane1, 23, big5 )) ) - *lc = LC_CNS11643_1; - } else if( big5 == 0xc94aU ){ - /* level 2 */ - *lc = LC_CNS11643_1; - cns = 0x4442; - } else { - /* level 2 */ - for (i=0;i<sizeof(b2c3)/sizeof(unsigned short);i++) { - if (b2c3[i][0] == big5) { - *lc = LC_CNS11643_3; - return(b2c3[i][1]); - } - } + if (0 < (cns = BinarySearchRange(big5Level1ToCnsPlane1, 23, big5))) + *lc = LC_CNS11643_1; + } + else if (big5 == 0xc94a U) + { + /* level 2 */ + *lc = LC_CNS11643_1; + cns = 0x4442; + } + else + { + /* level 2 */ + for (i = 0; i < sizeof(b2c3) / sizeof(unsigned short); i++) + { + if (b2c3[i][0] == big5) + { + *lc = LC_CNS11643_3; + return (b2c3[i][1]); + } + } - if( 0 < (cns = BinarySearchRange( big5Level2ToCnsPlane2, 46, big5 )) ) - *lc = LC_CNS11643_2; - } + if (0 < (cns = BinarySearchRange(big5Level2ToCnsPlane2, 46, big5))) + *lc = LC_CNS11643_2; + } - if( 0 == cns ){ /* no mapping Big5 to CNS 11643-1992 */ - *lc = 0; - return (unsigned short)'?'; - } + if (0 == cns) + { /* no mapping Big5 to CNS 11643-1992 */ + *lc = 0; + return (unsigned short) '?'; + } - return cns | 0x8080; + return cns | 0x8080; } -unsigned short CNStoBIG5( unsigned short cns, unsigned char lc ) +unsigned short +CNStoBIG5(unsigned short cns, unsigned char lc) { - int i; - unsigned int big5 = 0; + int i; + unsigned int big5 = 0; - cns &= 0x7f7f; + cns &= 0x7f7f; - switch( lc ){ - case LC_CNS11643_1: - big5 = BinarySearchRange( cnsPlane1ToBig5Level1, 24, cns ); - break; - case LC_CNS11643_2: - big5 = BinarySearchRange( cnsPlane2ToBig5Level2, 47, cns ); - break; - case LC_CNS11643_3: - for (i=0;i<sizeof(b2c3)/sizeof(unsigned short);i++) { - if (b2c3[i][1] == cns) { - return(b2c3[i][0]); - } - } - break; - case LC_CNS11643_4: - for (i=0;i<sizeof(b1c4)/sizeof(unsigned short);i++) { - if (b1c4[i][1] == cns) { - return(b1c4[i][0]); - } - } - default: - break; - } - return big5; + switch (lc) + { + case LC_CNS11643_1: + big5 = BinarySearchRange(cnsPlane1ToBig5Level1, 24, cns); + break; + case LC_CNS11643_2: + big5 = BinarySearchRange(cnsPlane2ToBig5Level2, 47, cns); + break; + case LC_CNS11643_3: + for (i = 0; i < sizeof(b2c3) / sizeof(unsigned short); i++) + { + if (b2c3[i][1] == cns) + return (b2c3[i][0]); + } + break; + case LC_CNS11643_4: + for (i = 0; i < sizeof(b1c4) / sizeof(unsigned short); i++) + { + if (b1c4[i][1] == cns) + return (b1c4[i][0]); + } + default: + break; + } + return big5; } diff --git a/src/backend/utils/mb/common.c b/src/backend/utils/mb/common.c index 6d90c734454..cab36c7b4c6 100644 --- a/src/backend/utils/mb/common.c +++ b/src/backend/utils/mb/common.c @@ -2,7 +2,7 @@ * This file contains some public functions * usable for both the backend and the frontend. * Tatsuo Ishii - * $Id: common.c,v 1.4 1999/05/13 10:28:25 ishii Exp $ */ + * $Id: common.c,v 1.5 1999/05/25 16:12:41 momjian Exp $ */ #include <stdlib.h> @@ -28,9 +28,8 @@ pg_char_to_encoding(const char *s) { pg_encoding_conv_tbl *p = pg_conv_tbl; - if (!s) { + if (!s) return (-1); - } for (; p->encoding >= 0; p++) { diff --git a/src/backend/utils/mb/conv.c b/src/backend/utils/mb/conv.c index ca79706bd5f..002a4845454 100644 --- a/src/backend/utils/mb/conv.c +++ b/src/backend/utils/mb/conv.c @@ -2,7 +2,7 @@ * conversion between client encoding and server internal encoding * (currently mule internal code (mic) is used) * Tatsuo Ishii - * $Id: conv.c,v 1.7 1999/04/25 18:09:54 tgl Exp $ + * $Id: conv.c,v 1.8 1999/05/25 16:12:41 momjian Exp $ */ #include <stdio.h> #include <string.h> @@ -375,43 +375,52 @@ mic2euc_tw(unsigned char *mic, unsigned char *p, int len) static void big52mic(unsigned char *big5, unsigned char *p, int len) { - unsigned short c1; - unsigned short big5buf, cnsBuf; - unsigned char lc; - char bogusBuf[2]; - int i; - - while (len > 0 && (c1 = *big5++)) - { - if (c1 <= 0x007fU) { /* ASCII */ - len--; - *p++ = c1; - } else { - len -= 2; - big5buf = c1 << 8; - c1 = *big5++; - big5buf |= c1; - cnsBuf = BIG5toCNS(big5buf, &lc); - if (lc != 0) { - if (lc == LC_CNS11643_3 || lc == LC_CNS11643_4) { - *p++ = 0x9d; /* LCPRV2 */ - } - *p++ = lc; /* Plane No. */ - *p++ = (cnsBuf >> 8) & 0x00ff; - *p++ = cnsBuf & 0x00ff; - } else { /* cannot convert */ - big5 -= 2; - *p++ = '('; - for (i=0;i<2;i++) { - sprintf(bogusBuf,"%02x",*big5++); - *p++ = bogusBuf[0]; - *p++ = bogusBuf[1]; - } - *p++ = ')'; + unsigned short c1; + unsigned short big5buf, + cnsBuf; + unsigned char lc; + char bogusBuf[2]; + int i; + + while (len > 0 && (c1 = *big5++)) + { + if (c1 <= 0x007f U) + { /* ASCII */ + len--; + *p++ = c1; + } + else + { + len -= 2; + big5buf = c1 << 8; + c1 = *big5++; + big5buf |= c1; + cnsBuf = BIG5toCNS(big5buf, &lc); + if (lc != 0) + { + if (lc == LC_CNS11643_3 || lc == LC_CNS11643_4) + { + *p++ = 0x9d;/* LCPRV2 */ + } + *p++ = lc; /* Plane No. */ + *p++ = (cnsBuf >> 8) & 0x00ff; + *p++ = cnsBuf & 0x00ff; + } + else + { /* cannot convert */ + big5 -= 2; + *p++ = '('; + for (i = 0; i < 2; i++) + { + sprintf(bogusBuf, "%02x", *big5++); + *p++ = bogusBuf[0]; + *p++ = bogusBuf[1]; + } + *p++ = ')'; + } + } } - } - } - *p = '\0'; + *p = '\0'; } /* @@ -420,41 +429,46 @@ big52mic(unsigned char *big5, unsigned char *p, int len) static void mic2big5(unsigned char *mic, unsigned char *p, int len) { - int l; - unsigned short c1; - unsigned short big5buf, cnsBuf; + int l; + unsigned short c1; + unsigned short big5buf, + cnsBuf; - while (len > 0 && (c1 = *mic)) - { - l = pg_mic_mblen(mic++); - len -= l; - - /* 0x9d means LCPRV2 */ - if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2 || c1 == 0x9d) - { - if (c1 == 0x9d) { - c1 = *mic++; /* get plane no. */ - } - cnsBuf = (*mic++)<<8; - cnsBuf |= (*mic++) & 0x00ff; - big5buf = CNStoBIG5(cnsBuf, c1); - if (big5buf == 0) { /* cannot convert to Big5! */ - mic -= l; - printBogusChar(&mic, &p); - } else { - *p++ = (big5buf >> 8) & 0x00ff; - *p++ = big5buf & 0x00ff; - } - } - else if (c1 <= 0x7f) /* ASCII */ + while (len > 0 && (c1 = *mic)) { - *p++ = c1; - } else { /* cannot convert to Big5! */ - mic--; - printBogusChar(&mic, &p); + l = pg_mic_mblen(mic++); + len -= l; + + /* 0x9d means LCPRV2 */ + if (c1 == LC_CNS11643_1 || c1 == LC_CNS11643_2 || c1 == 0x9d) + { + if (c1 == 0x9d) + { + c1 = *mic++; /* get plane no. */ + } + cnsBuf = (*mic++) << 8; + cnsBuf |= (*mic++) & 0x00ff; + big5buf = CNStoBIG5(cnsBuf, c1); + if (big5buf == 0) + { /* cannot convert to Big5! */ + mic -= l; + printBogusChar(&mic, &p); + } + else + { + *p++ = (big5buf >> 8) & 0x00ff; + *p++ = big5buf & 0x00ff; + } + } + else if (c1 <= 0x7f) /* ASCII */ + *p++ = c1; + else + { /* cannot convert to Big5! */ + mic--; + printBogusChar(&mic, &p); + } } - } - *p = '\0'; + *p = '\0'; } /* @@ -543,6 +557,7 @@ mic2latin4(unsigned char *mic, unsigned char *p, int len) { mic2latin(mic, p, len, LC_ISO8859_4); } + #ifdef NOT_USED static void latin52mic(unsigned char *l, unsigned char *p, int len) @@ -554,6 +569,7 @@ mic2latin5(unsigned char *mic, unsigned char *p, int len) { mic2latin(mic, p, len, LC_ISO8859_5); } + #endif /* @@ -590,7 +606,7 @@ mic2ascii(unsigned char *mic, unsigned char *p, int len) *p = '\0'; } -/* +/* * Cyrillic support * currently supported Cyrillic encodings: * @@ -601,18 +617,18 @@ mic2ascii(unsigned char *mic, unsigned char *p, int len) * Alternativny Variant (MS-DOS CP866) */ -/* koi2mic: KOI8-R to Mule internal code */ +/* koi2mic: KOI8-R to Mule internal code */ static void koi2mic(unsigned char *l, unsigned char *p, int len) { - latin2mic(l, p, len, LC_KOI8_R); + latin2mic(l, p, len, LC_KOI8_R); } /* mic2koi: Mule internal code to KOI8-R */ static void mic2koi(unsigned char *mic, unsigned char *p, int len) { - mic2latin(mic, p, len, LC_KOI8_R); + mic2latin(mic, p, len, LC_KOI8_R); } /* @@ -625,30 +641,36 @@ mic2koi(unsigned char *mic, unsigned char *p, int len) */ static void latin2mic_with_table( - unsigned char *l, /* local charset string (source) */ - unsigned char *p, /* pointer to store mule internal code - (destination) */ - int len, /* length of l */ - int lc, /* leading character of p */ - unsigned char *tab /* code conversion table */ - ) -{ - unsigned char c1,c2; - - while (len-- > 0 && (c1 = *l++)) { - if (c1 < 128) { - *p++ = c1; - } else { - c2 = tab[c1 - 128]; - if (c2) { - *p++ = lc; - *p++ = c2; - } else { - *p++ = ' '; /* cannot convert */ - } - } - } - *p = '\0'; + unsigned char *l, /* local charset string (source) */ + unsigned char *p, /* pointer to store mule internal + * code (destination) */ + int len, /* length of l */ + int lc, /* leading character of p */ + unsigned char *tab /* code conversion table */ +) +{ + unsigned char c1, + c2; + + while (len-- > 0 && (c1 = *l++)) + { + if (c1 < 128) + *p++ = c1; + else + { + c2 = tab[c1 - 128]; + if (c2) + { + *p++ = lc; + *p++ = c2; + } + else + { + *p++ = ' '; /* cannot convert */ + } + } + } + *p = '\0'; } /* @@ -656,190 +678,202 @@ latin2mic_with_table( * conversion from the mule internal code to a local charset * with a encoding conversion table. * the table is ordered according to the second byte of the mule - * internal code starting from 128 (0x80). + * internal code starting from 128 (0x80). * each entry in the table * holds the corresponding code point for the local code. */ static void mic2latin_with_table( - unsigned char *mic, /* mule internal code (source) */ - unsigned char *p, /* local code (destination) */ - int len, /* length of p */ - int lc, /* leading character */ - unsigned char *tab /* code conversion table */ - ) -{ - - unsigned char c1,c2; - - while (len-- > 0 && (c1 = *mic++)) { - if (c1 < 128) { - *p++ = c1; - } else if (c1 == lc) { - c1 = *mic++; - len--; - c2 = tab[c1 - 128]; - if (c2) { - *p++ = c2; - } else { - *p++ = ' '; /* cannot convert */ - } - } else { - *p++ = ' '; /* bogus character */ - } - } - *p = '\0'; -} - -/* iso2mic: ISO-8859-5 to Mule internal code */ + unsigned char *mic, /* mule internal code + * (source) */ + unsigned char *p, /* local code (destination) */ + int len, /* length of p */ + int lc, /* leading character */ + unsigned char *tab /* code conversion table */ +) +{ + + unsigned char c1, + c2; + + while (len-- > 0 && (c1 = *mic++)) + { + if (c1 < 128) + *p++ = c1; + else if (c1 == lc) + { + c1 = *mic++; + len--; + c2 = tab[c1 - 128]; + if (c2) + *p++ = c2; + else + { + *p++ = ' '; /* cannot convert */ + } + } + else + { + *p++ = ' '; /* bogus character */ + } + } + *p = '\0'; +} + +/* iso2mic: ISO-8859-5 to Mule internal code */ static void iso2mic(unsigned char *l, unsigned char *p, int len) { - static char iso2koi[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, - 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, - 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, - 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, - 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, - 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, - 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - latin2mic_with_table(l, p, len, LC_KOI8_R, iso2koi); + static char iso2koi[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, + 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, + 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, + 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, + 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, + 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, + 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, + 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + latin2mic_with_table(l, p, len, LC_KOI8_R, iso2koi); } /* mic2iso: Mule internal code to ISO8859-5 */ static void mic2iso(unsigned char *mic, unsigned char *p, int len) { - static char koi2iso[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, - 0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, - 0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, - 0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea, - 0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, - 0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, - 0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, - 0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca - }; - - mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2iso); -} - -/* win2mic: CP1251 to Mule internal code */ + static char koi2iso[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xee, 0xd0, 0xd1, 0xe6, 0xd4, 0xd5, 0xe4, 0xd3, + 0xe5, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, + 0xdf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xd6, 0xd2, + 0xec, 0xeb, 0xd7, 0xe8, 0xed, 0xe9, 0xe7, 0xea, + 0xce, 0xb0, 0xb1, 0xc6, 0xb4, 0xb5, 0xc4, 0xb3, + 0xc5, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, + 0xbf, 0xcf, 0xc0, 0xc1, 0xc2, 0xc3, 0xb6, 0xb2, + 0xcc, 0xcb, 0xb7, 0xc8, 0xcd, 0xc9, 0xc7, 0xca + }; + + mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2iso); +} + +/* win2mic: CP1251 to Mule internal code */ static void win2mic(unsigned char *l, unsigned char *p, int len) { - static char win2koi[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, - 0xb3, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0xb7, - 0x00, 0x00, 0xb6, 0xa6, 0xad, 0x00, 0x00, 0x00, - 0xa3, 0x00, 0xa4, 0x00, 0x00, 0x00, 0x00, 0xa7, - 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, - 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, - 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, - 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, - 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, - 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, - 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1 - }; - latin2mic_with_table(l, p, len, LC_KOI8_R, win2koi); + static char win2koi[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, + 0xb3, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0xb7, + 0x00, 0x00, 0xb6, 0xa6, 0xad, 0x00, 0x00, 0x00, + 0xa3, 0x00, 0xa4, 0x00, 0x00, 0x00, 0x00, 0xa7, + 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, + 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, + 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, + 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, + 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, + 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, + 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, + 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1 + }; + + latin2mic_with_table(l, p, len, LC_KOI8_R, win2koi); } /* mic2win: Mule internal code to CP1251 */ static void mic2win(unsigned char *mic, unsigned char *p, int len) { - static char koi2win[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xb8, 0xba, 0x00, 0xb3, 0xbf, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xa8, 0xaa, 0x00, 0xb2, 0xaf, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x00, 0x00, - 0xfe, 0xe0, 0xe1, 0xf6, 0xe4, 0xe5, 0xf4, 0xe3, - 0xf5, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, - 0xef, 0xff, 0xf0, 0xf1, 0xf2, 0xf3, 0xe6, 0xe2, - 0xfc, 0xfb, 0xe7, 0xf8, 0xfd, 0xf9, 0xf7, 0xfa, - 0xde, 0xc0, 0xc1, 0xd6, 0xc4, 0xc5, 0xd4, 0xc3, - 0xd5, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, - 0xcf, 0xdf, 0xd0, 0xd1, 0xd2, 0xd3, 0xc6, 0xc2, - 0xdc, 0xdb, 0xc7, 0xd8, 0xdd, 0xd9, 0xd7, 0xda - }; - mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2win); -} - -/* alt2mic: CP866 to Mule internal code */ + static char koi2win[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xb8, 0xba, 0x00, 0xb3, 0xbf, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xa8, 0xaa, 0x00, 0xb2, 0xaf, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x00, 0x00, + 0xfe, 0xe0, 0xe1, 0xf6, 0xe4, 0xe5, 0xf4, 0xe3, + 0xf5, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, + 0xef, 0xff, 0xf0, 0xf1, 0xf2, 0xf3, 0xe6, 0xe2, + 0xfc, 0xfb, 0xe7, 0xf8, 0xfd, 0xf9, 0xf7, 0xfa, + 0xde, 0xc0, 0xc1, 0xd6, 0xc4, 0xc5, 0xd4, 0xc3, + 0xd5, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, + 0xcf, 0xdf, 0xd0, 0xd1, 0xd2, 0xd3, 0xc6, 0xc2, + 0xdc, 0xdb, 0xc7, 0xd8, 0xdd, 0xd9, 0xd7, 0xda + }; + + mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2win); +} + +/* alt2mic: CP866 to Mule internal code */ static void alt2mic(unsigned char *l, unsigned char *p, int len) { - static char alt2koi[] = { - 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, - 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, - 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, - 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, - 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, - 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, - 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, - 0xb3, 0xa3, 0xb4, 0xa4, 0xb7, 0xa7, 0x00, 0x00, - 0xb6, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - latin2mic_with_table(l, p, len, LC_KOI8_R, alt2koi); + static char alt2koi[] = { + 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, + 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, + 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, + 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, + 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, + 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, + 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, + 0xb3, 0xa3, 0xb4, 0xa4, 0xb7, 0xa7, 0x00, 0x00, + 0xb6, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + latin2mic_with_table(l, p, len, LC_KOI8_R, alt2koi); } /* mic2alt: Mule internal code to CP866 */ static void mic2alt(unsigned char *mic, unsigned char *p, int len) { - static char koi2alt[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xf1, 0xf3, 0x00, 0xf9, 0xf5, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xf0, 0xf2, 0x00, 0xf8, 0xf4, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, - 0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3, - 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, - 0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2, - 0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea, - 0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83, - 0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, - 0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82, - 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a - }; - mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2alt); + static char koi2alt[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf1, 0xf3, 0x00, 0xf9, 0xf5, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xf2, 0x00, 0xf8, 0xf4, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, + 0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3, + 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, + 0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2, + 0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea, + 0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83, + 0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, + 0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82, + 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a + }; + + mic2latin_with_table(mic, p, len, LC_KOI8_R, koi2alt); } /* @@ -858,8 +892,8 @@ pg_encoding_conv_tbl pg_conv_tbl[] = { {LATIN2, "LATIN2", 0, latin22mic, mic2latin2}, /* ISO 8859 Latin 2 */ {LATIN3, "LATIN3", 0, latin32mic, mic2latin3}, /* ISO 8859 Latin 3 */ {LATIN4, "LATIN4", 0, latin42mic, mic2latin4}, /* ISO 8859 Latin 4 */ - {LATIN5, "LATIN5", 0, iso2mic, mic2iso}, /* ISO 8859 Latin 5 */ - {KOI8, "KOI8", 0, koi2mic, mic2koi}, /* KOI8-R */ + {LATIN5, "LATIN5", 0, iso2mic, mic2iso}, /* ISO 8859 Latin 5 */ + {KOI8, "KOI8", 0, koi2mic, mic2koi}, /* KOI8-R */ {WIN, "WIN", 0, win2mic, mic2win}, /* CP1251 */ {ALT, "ALT", 0, alt2mic, mic2alt}, /* CP866 */ {SJIS, "SJIS", 1, sjis2mic, mic2sjis}, /* SJIS */ diff --git a/src/backend/utils/mb/iso.c b/src/backend/utils/mb/iso.c index 4141578a3b8..a2903895b0c 100644 --- a/src/backend/utils/mb/iso.c +++ b/src/backend/utils/mb/iso.c @@ -4,63 +4,69 @@ * * Tatsuo Ishii * - * $Id: iso.c,v 1.1 1999/03/24 07:01:37 ishii Exp $ + * $Id: iso.c,v 1.2 1999/05/25 16:12:42 momjian Exp $ */ #include <stdio.h> main() { - int i; - char koitab[128],isotab[128]; - char buf[4096]; - int koi,iso; + int i; + char koitab[128], + isotab[128]; + char buf[4096]; + int koi, + iso; - for (i=0;i<128;i++) { - koitab[i] = isotab[i] = 0; - } + for (i = 0; i < 128; i++) + koitab[i] = isotab[i] = 0; - while (fgets(buf,sizeof(buf),stdin) != NULL) { - if (*buf == '#') { - continue; - } - sscanf(buf,"%d %x",&koi,&iso); - if (koi < 128 || koi > 255 || iso < 128 || iso > 255) { - fprintf(stderr,"invalid value %d\n",koi); - exit(1); - } - koitab[koi-128] = iso; - isotab[iso-128] = koi; - } + while (fgets(buf, sizeof(buf), stdin) != NULL) + { + if (*buf == '#') + continue; + sscanf(buf, "%d %x", &koi, &iso); + if (koi < 128 || koi > 255 || iso < 128 || iso > 255) + { + fprintf(stderr, "invalid value %d\n", koi); + exit(1); + } + koitab[koi - 128] = iso; + isotab[iso - 128] = koi; + } - i = 0; - printf("static char koi2iso[] = {\n"); - while (i < 128) { - int j = 0; - while (j < 8) { - printf("0x%02x",koitab[i++]); - j++; - if (i >= 128) { - break; - } - printf(", "); - } - printf("\n"); - } - printf("};\n"); + i = 0; + printf("static char koi2iso[] = {\n"); + while (i < 128) + { + int j = 0; - i = 0; - printf("static char iso2koi[] = {\n"); - while (i < 128) { - int j = 0; - while (j < 8) { - printf("0x%02x",isotab[i++]); - j++; - if (i >= 128) { - break; - } - printf(", "); - } - printf("\n"); - } - printf("};\n"); + while (j < 8) + { + printf("0x%02x", koitab[i++]); + j++; + if (i >= 128) + break; + printf(", "); + } + printf("\n"); + } + printf("};\n"); + + i = 0; + printf("static char iso2koi[] = {\n"); + while (i < 128) + { + int j = 0; + + while (j < 8) + { + printf("0x%02x", isotab[i++]); + j++; + if (i >= 128) + break; + printf(", "); + } + printf("\n"); + } + printf("};\n"); } diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index f354ccc96a2..d5831b14e6a 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -3,14 +3,14 @@ * client encoding and server internal encoding. * (currently mule internal code (mic) is used) * Tatsuo Ishii - * $Id: mbutils.c,v 1.5 1999/02/02 18:51:23 momjian Exp $ */ + * $Id: mbutils.c,v 1.6 1999/05/25 16:12:43 momjian Exp $ */ #include <stdio.h> #include <string.h> #include "mb/pg_wchar.h" -static int client_encoding = -1; +static int client_encoding = -1; static void (*client_to_mic) ();/* something to MIC */ static void (*client_from_mic) (); /* MIC to something */ static void (*server_to_mic) ();/* something to MIC */ @@ -213,16 +213,14 @@ pg_mbcliplen(const unsigned char *mbstr, int len, int limit) int clen = 0; int l; - while (*mbstr && len > 0) + while (*mbstr && len > 0) { l = pg_mblen(mbstr); - if ((clen + l) > limit) { + if ((clen + l) > limit) break; - } clen += l; - if (clen == limit) { + if (clen == limit) break; - } len -= l; mbstr += l; } diff --git a/src/backend/utils/mb/variable.c b/src/backend/utils/mb/variable.c index 0b2ffacd644..2452518e12d 100644 --- a/src/backend/utils/mb/variable.c +++ b/src/backend/utils/mb/variable.c @@ -2,7 +2,7 @@ * This file contains some public functions * related to show/set/reset variable commands. * Tatsuo Ishii - * $Id: variable.c,v 1.3 1999/05/13 10:28:26 ishii Exp $ + * $Id: variable.c,v 1.4 1999/05/25 16:12:44 momjian Exp $ */ #include "mb/pg_wchar.h" @@ -13,12 +13,12 @@ parse_client_encoding(const char *value) int encoding; encoding = pg_valid_client_encoding(value); - if (encoding < 0) { - if (value) { + if (encoding < 0) + { + if (value) elog(ERROR, "Client encoding %s is not supported", value); - } else { + else elog(ERROR, "No client encoding is specified"); - } } else { diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c index 2fc856d1b5d..0d557e30f6f 100644 --- a/src/backend/utils/mb/wchar.c +++ b/src/backend/utils/mb/wchar.c @@ -1,7 +1,7 @@ /* * conversion functions between pg_wchar and multi-byte streams. * Tatsuo Ishii - * $Id: wchar.c,v 1.7 1999/04/25 20:35:51 tgl Exp $ + * $Id: wchar.c,v 1.8 1999/05/25 16:12:45 momjian Exp $ */ #include "mb/pg_wchar.h" @@ -428,33 +428,33 @@ pg_wchar_tbl pg_wchar_table[] = { {pg_euctw2wchar_with_len, pg_euctw_mblen}, /* 4 */ {pg_utf2wchar_with_len, pg_utf_mblen}, /* 5 */ {pg_mule2wchar_with_len, pg_mule_mblen}, /* 6 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 15 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 16 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 17 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 18 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 19 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 20 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 21 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 22 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 23 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 24 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 25 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 26 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 27 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 28 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 29 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 30 */ - {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 31 */ - {0, pg_sjis_mblen}, /* 32 */ - {0, pg_big5_mblen} /* 33 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 7 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 8 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 9 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 10 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 11 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 12 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 13 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 14 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 15 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 16 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 17 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 18 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 19 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 20 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 21 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 22 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 23 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 24 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 25 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 26 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 27 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 28 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 29 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 30 */ + {pg_latin12wchar_with_len, pg_latin1_mblen}, /* 31 */ + {0, pg_sjis_mblen}, /* 32 */ + {0, pg_big5_mblen} /* 33 */ }; /* returns the byte length of a word for mule internal code */ diff --git a/src/backend/utils/mb/win.c b/src/backend/utils/mb/win.c index 272c6a638c1..8db62b49b3c 100644 --- a/src/backend/utils/mb/win.c +++ b/src/backend/utils/mb/win.c @@ -4,63 +4,69 @@ * * Tatsuo Ishii * - * $Id: win.c,v 1.1 1999/03/24 07:01:37 ishii Exp $ + * $Id: win.c,v 1.2 1999/05/25 16:12:45 momjian Exp $ */ #include <stdio.h> main() { - int i; - char koitab[128],wintab[128]; - char buf[4096]; - int koi,win; + int i; + char koitab[128], + wintab[128]; + char buf[4096]; + int koi, + win; - for (i=0;i<128;i++) { - koitab[i] = wintab[i] = 0; - } + for (i = 0; i < 128; i++) + koitab[i] = wintab[i] = 0; - while (fgets(buf,sizeof(buf),stdin) != NULL) { - if (*buf == '#') { - continue; - } - sscanf(buf,"%d %d",&koi,&win); - if (koi < 128 || koi > 255 || win < 128 || win > 255) { - fprintf(stderr,"invalid value %d\n",koi); - exit(1); - } - koitab[koi-128] = win; - wintab[win-128] = koi; - } + while (fgets(buf, sizeof(buf), stdin) != NULL) + { + if (*buf == '#') + continue; + sscanf(buf, "%d %d", &koi, &win); + if (koi < 128 || koi > 255 || win < 128 || win > 255) + { + fprintf(stderr, "invalid value %d\n", koi); + exit(1); + } + koitab[koi - 128] = win; + wintab[win - 128] = koi; + } - i = 0; - printf("static char koi2win[] = {\n"); - while (i < 128) { - int j = 0; - while (j < 8) { - printf("0x%02x",koitab[i++]); - j++; - if (i >= 128) { - break; - } - printf(", "); - } - printf("\n"); - } - printf("};\n"); + i = 0; + printf("static char koi2win[] = {\n"); + while (i < 128) + { + int j = 0; - i = 0; - printf("static char win2koi[] = {\n"); - while (i < 128) { - int j = 0; - while (j < 8) { - printf("0x%02x",wintab[i++]); - j++; - if (i >= 128) { - break; - } - printf(", "); - } - printf("\n"); - } - printf("};\n"); + while (j < 8) + { + printf("0x%02x", koitab[i++]); + j++; + if (i >= 128) + break; + printf(", "); + } + printf("\n"); + } + printf("};\n"); + + i = 0; + printf("static char win2koi[] = {\n"); + while (i < 128) + { + int j = 0; + + while (j < 8) + { + printf("0x%02x", wintab[i++]); + j++; + if (i >= 128) + break; + printf(", "); + } + printf("\n"); + } + printf("};\n"); } diff --git a/src/backend/utils/misc/database.c b/src/backend/utils/misc/database.c index d72ebd347b5..e9ea6193492 100644 --- a/src/backend/utils/misc/database.c +++ b/src/backend/utils/misc/database.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.23 1999/02/13 23:20:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.24 1999/05/25 16:12:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -188,7 +188,7 @@ GetRawDatabaseInfo(char *name, int4 *owner, Oid *db_id, char *path, int *encodin int nbytes; int max, i; - HeapTupleData tup; + HeapTupleData tup; Page pg; PageHeader ph; char *dbfname; diff --git a/src/backend/utils/misc/trace.c b/src/backend/utils/misc/trace.c index 871e1d436a0..3ba1626c03d 100644 --- a/src/backend/utils/misc/trace.c +++ b/src/backend/utils/misc/trace.c @@ -132,10 +132,10 @@ tprintf(int flag, const char *fmt,...) * Print a timestamp and a message to stdout or to syslog. */ int -tprintf1(const char *fmt, ... ) +tprintf1(const char *fmt,...) { va_list ap; - char line[ELOG_MAXLEN+TIMESTAMP_SIZE+1]; + char line[ELOG_MAXLEN + TIMESTAMP_SIZE + 1]; va_start(ap, fmt); #ifdef ELOG_TIMESTAMPS @@ -145,10 +145,11 @@ tprintf1(const char *fmt, ... ) va_end(ap); #ifdef USE_SYSLOG - write_syslog(LOG_INFO, line+TIMESTAMP_SIZE); + write_syslog(LOG_INFO, line + TIMESTAMP_SIZE); #endif - if (UseSyslog <= 1) { + if (UseSyslog <= 1) + { puts(line); fflush(stdout); } @@ -193,7 +194,7 @@ eprintf(const char *fmt,...) void write_syslog(int level, char *line) { - static int openlog_done = 0; + static int openlog_done = 0; if (UseSyslog >= 1) { @@ -348,9 +349,10 @@ read_pg_options(SIGNAL_ARGS) char *s, *p; - if (!DataDir) { - fprintf(stderr, "read_pg_options: DataDir not defined\n"); - return; + if (!DataDir) + { + fprintf(stderr, "read_pg_options: DataDir not defined\n"); + return; } snprintf(buffer, BUF_SIZE - 1, "%s/%s", DataDir, "pg_options"); diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c index 04bdba93292..1060f7b6def 100644 --- a/src/backend/utils/mmgr/aset.c +++ b/src/backend/utils/mmgr/aset.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.15 1999/05/22 23:19:37 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.16 1999/05/25 16:12:51 momjian Exp $ * * NOTE: * This is a new (Feb. 05, 1999) implementation of the allocation set @@ -51,7 +51,7 @@ */ #define ALLOC_MINBITS 4 /* smallest chunk size is 16 bytes */ -#define ALLOC_SMALLCHUNK_LIMIT (1 << (ALLOCSET_NUM_FREELISTS-2+ALLOC_MINBITS)) +#define ALLOC_SMALLCHUNK_LIMIT (1 << (ALLOCSET_NUM_FREELISTS-2+ALLOC_MINBITS)) /* Size of largest chunk that we use a fixed size for */ /*-------------------- @@ -65,8 +65,8 @@ *-------------------- */ -#define ALLOC_MIN_BLOCK_SIZE 8192 -#define ALLOC_MAX_BLOCK_SIZE (8 * 1024 * 1024) +#define ALLOC_MIN_BLOCK_SIZE 8192 +#define ALLOC_MAX_BLOCK_SIZE (8 * 1024 * 1024) #define ALLOC_BLOCKHDRSZ MAXALIGN(sizeof(AllocBlockData)) @@ -91,12 +91,12 @@ static inline int AllocSetFreeIndex(Size size) { - int idx = 0; + int idx = 0; if (size > 0) { size = (size - 1) >> ALLOC_MINBITS; - while (size != 0 && idx < ALLOCSET_NUM_FREELISTS-1) + while (size != 0 && idx < ALLOCSET_NUM_FREELISTS - 1) { idx++; size >>= 1; @@ -105,7 +105,7 @@ AllocSetFreeIndex(Size size) return idx; } - + /* * Public routines @@ -119,7 +119,7 @@ AllocSetFreeIndex(Size size) */ /* - * AllocSetInit + * AllocSetInit * Initializes given allocation set. * * Note: @@ -147,7 +147,7 @@ AllocSetInit(AllocSet set, AllocMode mode, Size limit) /* - * AllocSetReset + * AllocSetReset * Frees memory which is allocated in the given set. * * Exceptions: @@ -156,8 +156,8 @@ AllocSetInit(AllocSet set, AllocMode mode, Size limit) void AllocSetReset(AllocSet set) { - AllocBlock block = set->blocks; - AllocBlock next; + AllocBlock block = set->blocks; + AllocBlock next; AssertArg(AllocSetIsValid(set)); @@ -172,7 +172,7 @@ AllocSetReset(AllocSet set) } /* - * AllocSetContains + * AllocSetContains * True iff allocation set contains given allocation element. * * Exceptions: @@ -189,7 +189,7 @@ AllocSetContains(AllocSet set, AllocPointer pointer) } /* - * AllocSetAlloc + * AllocSetAlloc * Returns pointer to allocated memory of given size; memory is added * to the set. * @@ -200,22 +200,22 @@ AllocSetContains(AllocSet set, AllocPointer pointer) AllocPointer AllocSetAlloc(AllocSet set, Size size) { - AllocBlock block; - AllocChunk chunk; - AllocChunk freeref = NULL; - int fidx; - Size chunk_size; - Size blksize; + AllocBlock block; + AllocChunk chunk; + AllocChunk freeref = NULL; + int fidx; + Size chunk_size; + Size blksize; AssertArg(AllocSetIsValid(set)); /* - * Lookup in the corresponding free list if there is a - * free chunk we could reuse + * Lookup in the corresponding free list if there is a free chunk we + * could reuse * */ fidx = AllocSetFreeIndex(size); - for (chunk = set->freelist[fidx]; chunk; chunk = (AllocChunk)chunk->aset) + for (chunk = set->freelist[fidx]; chunk; chunk = (AllocChunk) chunk->aset) { if (chunk->size >= size) break; @@ -223,18 +223,18 @@ AllocSetAlloc(AllocSet set, Size size) } /* - * If one is found, remove it from the free list, make it again - * a member of the alloc set and return it's data address. + * If one is found, remove it from the free list, make it again a + * member of the alloc set and return it's data address. * */ if (chunk != NULL) { if (freeref == NULL) - set->freelist[fidx] = (AllocChunk)chunk->aset; + set->freelist[fidx] = (AllocChunk) chunk->aset; else freeref->aset = chunk->aset; - chunk->aset = (void *)set; + chunk->aset = (void *) set; return AllocChunkGetPointer(chunk); } @@ -248,8 +248,8 @@ AllocSetAlloc(AllocSet set, Size size) Assert(chunk_size >= size); /* - * If there is enough room in the active allocation block, - * always allocate the chunk there. + * If there is enough room in the active allocation block, always + * allocate the chunk there. */ if ((block = set->blocks) != NULL) @@ -261,8 +261,8 @@ AllocSetAlloc(AllocSet set, Size size) } /* - * Otherwise, if requested size exceeds smallchunk limit, - * allocate an entire separate block for this allocation + * Otherwise, if requested size exceeds smallchunk limit, allocate an + * entire separate block for this allocation * */ if (block == NULL && size > ALLOC_SMALLCHUNK_LIMIT) @@ -272,9 +272,9 @@ AllocSetAlloc(AllocSet set, Size size) if (block == NULL) elog(FATAL, "Memory exhausted in AllocSetAlloc()"); block->aset = set; - block->freeptr = block->endptr = ((char *)block) + blksize; + block->freeptr = block->endptr = ((char *) block) + blksize; - chunk = (AllocChunk) (((char *)block) + ALLOC_BLOCKHDRSZ); + chunk = (AllocChunk) (((char *) block) + ALLOC_BLOCKHDRSZ); chunk->aset = set; chunk->size = chunk_size; @@ -310,8 +310,11 @@ AllocSetAlloc(AllocSet set, Size size) { /* Get size of prior block */ blksize = set->blocks->endptr - ((char *) set->blocks); - /* Special case: if very first allocation was for a large chunk, - * could have a funny-sized top block. Do something reasonable. + + /* + * Special case: if very first allocation was for a large + * chunk, could have a funny-sized top block. Do something + * reasonable. */ if (blksize < ALLOC_MIN_BLOCK_SIZE) blksize = ALLOC_MIN_BLOCK_SIZE; @@ -321,12 +324,13 @@ AllocSetAlloc(AllocSet set, Size size) blksize = ALLOC_MAX_BLOCK_SIZE; /* Try to allocate it */ block = (AllocBlock) malloc(blksize); + /* * We could be asking for pretty big blocks here, so cope if * malloc fails. But give up if there's less than a meg or so * available... */ - while (block == NULL && blksize > 1024*1024) + while (block == NULL && blksize > 1024 * 1024) { blksize >>= 1; block = (AllocBlock) malloc(blksize); @@ -336,8 +340,8 @@ AllocSetAlloc(AllocSet set, Size size) if (block == NULL) elog(FATAL, "Memory exhausted in AllocSetAlloc()"); block->aset = set; - block->freeptr = ((char *)block) + ALLOC_BLOCKHDRSZ; - block->endptr = ((char *)block) + blksize; + block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ; + block->endptr = ((char *) block) + blksize; block->next = set->blocks; set->blocks = block; @@ -346,8 +350,8 @@ AllocSetAlloc(AllocSet set, Size size) /* * OK, do the allocation */ - chunk = (AllocChunk)(block->freeptr); - chunk->aset = (void *)set; + chunk = (AllocChunk) (block->freeptr); + chunk->aset = (void *) set; chunk->size = chunk_size; block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ); Assert(block->freeptr <= block->endptr); @@ -356,7 +360,7 @@ AllocSetAlloc(AllocSet set, Size size) } /* - * AllocSetFree + * AllocSetFree * Frees allocated memory; memory is removed from the set. * * Exceptions: @@ -367,8 +371,8 @@ AllocSetAlloc(AllocSet set, Size size) void AllocSetFree(AllocSet set, AllocPointer pointer) { - int fidx; - AllocChunk chunk; + int fidx; + AllocChunk chunk; /* AssertArg(AllocSetIsValid(set)); */ /* AssertArg(AllocPointerIsValid(pointer)); */ @@ -377,12 +381,12 @@ AllocSetFree(AllocSet set, AllocPointer pointer) chunk = AllocPointerGetChunk(pointer); fidx = AllocSetFreeIndex(chunk->size); - chunk->aset = (void *)set->freelist[fidx]; + chunk->aset = (void *) set->freelist[fidx]; set->freelist[fidx] = chunk; } /* - * AllocSetRealloc + * AllocSetRealloc * Returns new pointer to allocated memory of given size; this memory * is added to the set. Memory associated with given pointer is copied * into the new memory, and the old memory is freed. @@ -404,8 +408,8 @@ AllocSetRealloc(AllocSet set, AllocPointer pointer, Size size) AssertArg(AllocSetContains(set, pointer)); /* - * Chunk sizes are aligned to power of 2 on AllocSetAlloc(). - * Maybe the allocated area already is >= the new size. + * Chunk sizes are aligned to power of 2 on AllocSetAlloc(). Maybe the + * allocated area already is >= the new size. * */ oldsize = AllocPointerGetSize(pointer); @@ -425,7 +429,7 @@ AllocSetRealloc(AllocSet set, AllocPointer pointer, Size size) } /* - * AllocSetDump + * AllocSetDump * Displays allocated set. */ void diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 401ef7c6c0b..98cd5b6f161 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.13 1999/03/22 16:45:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.14 1999/05/25 16:12:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -54,7 +54,7 @@ static OrderedSetData ActiveGlobalMemorySetData; /* uninitialized */ #define PSIZESPACE(LEN) ((LEN) + sizeof (int32)) /* - * AllocSizeIsValid + * AllocSizeIsValid * True iff 0 < size and size <= MaxAllocSize. */ #define AllocSizeIsValid(size) (0 < (size) && (size) <= MaxAllocSize) @@ -64,7 +64,7 @@ static OrderedSetData ActiveGlobalMemorySetData; /* uninitialized */ *****************************************************************************/ /* - * CurrentMemoryContext + * CurrentMemoryContext * Memory context for general global allocations. */ DLLIMPORT MemoryContext CurrentMemoryContext = NULL; @@ -106,14 +106,14 @@ static struct MemoryContextMethodsData GlobalContextMethodsData = { static struct GlobalMemoryData TopGlobalMemoryData = { T_GlobalMemory, /* NodeTag tag */ &GlobalContextMethodsData, /* ContextMethods method */ - { NULL, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }}, - /* free AllocSet */ + {NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}}, + /* free AllocSet */ "TopGlobal", /* char* name */ {0} /* uninitialized OrderedElemData elemD */ }; /* - * TopMemoryContext + * TopMemoryContext * Memory context for general global allocations. * * Note: @@ -131,7 +131,7 @@ MemoryContext TopMemoryContext = (MemoryContext) &TopGlobalMemoryData; */ /* - * EnableMemoryContext + * EnableMemoryContext * Enables/disables memory management and global contexts. * * Note: @@ -207,7 +207,7 @@ EnableMemoryContext(bool on) } /* - * MemoryContextAlloc + * MemoryContextAlloc * Returns pointer to aligned allocated memory in the given context. * * Note: @@ -231,7 +231,7 @@ MemoryContextAlloc(MemoryContext context, Size size) } /* - * MemoryContextFree + * MemoryContextFree * Frees allocated memory referenced by pointer in the given context. * * Note: @@ -252,7 +252,7 @@ MemoryContextFree(MemoryContext context, Pointer pointer) } /* - * MemoryContextRelloc + * MemoryContextRelloc * Returns pointer to aligned allocated memory in the given context. * * Note: @@ -278,7 +278,7 @@ MemoryContextRealloc(MemoryContext context, } /* - * MemoryContextGetName + * MemoryContextGetName * Returns pointer to aligned allocated memory in the given context. * * Note: @@ -301,7 +301,7 @@ MemoryContextGetName(MemoryContext context) #endif /* - * PointerGetAllocSize + * PointerGetAllocSize * Returns size of aligned allocated memory given pointer to it. * * Note: @@ -324,7 +324,7 @@ PointerGetAllocSize(Pointer pointer) #endif /* - * MemoryContextSwitchTo + * MemoryContextSwitchTo * Returns the current context; installs the given context. * * Note: @@ -351,7 +351,7 @@ MemoryContextSwitchTo(MemoryContext context) * External Functions */ /* - * CreateGlobalMemory + * CreateGlobalMemory * Returns new global memory context. * * Note: @@ -385,7 +385,7 @@ CreateGlobalMemory(char *name) /* XXX MemoryContextName */ } /* - * GlobalMemoryDestroy + * GlobalMemoryDestroy * Destroys given global memory context. * * Exceptions: @@ -413,7 +413,7 @@ GlobalMemoryDestroy(GlobalMemory context) *****************************************************************************/ /* - * GlobalMemoryAlloc + * GlobalMemoryAlloc * Returns pointer to aligned space in the global context. * * Exceptions: @@ -426,7 +426,7 @@ GlobalMemoryAlloc(GlobalMemory this, Size size) } /* - * GlobalMemoryFree + * GlobalMemoryFree * Frees allocated memory in the global context. * * Exceptions: @@ -441,7 +441,7 @@ GlobalMemoryFree(GlobalMemory this, } /* - * GlobalMemoryRealloc + * GlobalMemoryRealloc * Returns pointer to aligned space in the global context. * * Note: @@ -461,7 +461,7 @@ GlobalMemoryRealloc(GlobalMemory this, } /* - * GlobalMemoryGetName + * GlobalMemoryGetName * Returns name string for context. * * Exceptions: @@ -474,7 +474,7 @@ GlobalMemoryGetName(GlobalMemory this) } /* - * GlobalMemoryDump + * GlobalMemoryDump * Dumps global memory context for debugging. * * Exceptions: @@ -499,7 +499,7 @@ GlobalMemoryDump(GlobalMemory this) } /* - * DumpGlobalMemories + * DumpGlobalMemories * Dumps all global memory contexts for debugging. * * Exceptions: diff --git a/src/backend/utils/mmgr/oset.c b/src/backend/utils/mmgr/oset.c index 493197e8ea9..8aca4a2ec01 100644 --- a/src/backend/utils/mmgr/oset.c +++ b/src/backend/utils/mmgr/oset.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/oset.c,v 1.11 1999/02/13 23:20:10 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/oset.c,v 1.12 1999/05/25 16:12:54 momjian Exp $ * * NOTE * XXX This is a preliminary implementation which lacks fail-fast @@ -24,7 +24,7 @@ static void OrderedElemPush(OrderedElem elem); static void OrderedElemPushHead(OrderedElem elem); /* - * OrderedElemGetBase + * OrderedElemGetBase * Returns base of enclosing structure. */ static Pointer @@ -37,7 +37,7 @@ OrderedElemGetBase(OrderedElem elem) } /* - * OrderedSetInit + * OrderedSetInit */ void OrderedSetInit(OrderedSet set, Offset offset) @@ -49,7 +49,7 @@ OrderedSetInit(OrderedSet set, Offset offset) } /* - * OrderedSetContains + * OrderedSetContains * True iff ordered set contains given element. */ bool @@ -59,7 +59,7 @@ OrderedSetContains(OrderedSet set, OrderedElem elem) } /* - * OrderedSetGetHead + * OrderedSetGetHead */ Pointer OrderedSetGetHead(OrderedSet set) @@ -73,7 +73,7 @@ OrderedSetGetHead(OrderedSet set) } /* - * OrderedSetGetTail + * OrderedSetGetTail */ #ifdef NOT_USED Pointer @@ -90,7 +90,7 @@ OrderedSetGetTail(OrderedSet set) #endif /* - * OrderedElemGetPredecessor + * OrderedElemGetPredecessor */ Pointer OrderedElemGetPredecessor(OrderedElem elem) @@ -102,7 +102,7 @@ OrderedElemGetPredecessor(OrderedElem elem) } /* - * OrderedElemGetSuccessor + * OrderedElemGetSuccessor */ Pointer OrderedElemGetSuccessor(OrderedElem elem) @@ -114,7 +114,7 @@ OrderedElemGetSuccessor(OrderedElem elem) } /* - * OrderedElemPop + * OrderedElemPop */ void OrderedElemPop(OrderedElem elem) @@ -127,7 +127,7 @@ OrderedElemPop(OrderedElem elem) } /* - * OrderedElemPushInto + * OrderedElemPushInto */ void OrderedElemPushInto(OrderedElem elem, OrderedSet set) @@ -140,7 +140,7 @@ OrderedElemPushInto(OrderedElem elem, OrderedSet set) } /* - * OrderedElemPush + * OrderedElemPush */ static void OrderedElemPush(OrderedElem elem) @@ -149,7 +149,7 @@ OrderedElemPush(OrderedElem elem) } /* - * OrderedElemPushHead + * OrderedElemPushHead */ static void OrderedElemPushHead(OrderedElem elem) diff --git a/src/backend/utils/mmgr/palloc.c b/src/backend/utils/mmgr/palloc.c index 2653401b2a9..bf36908973a 100644 --- a/src/backend/utils/mmgr/palloc.c +++ b/src/backend/utils/mmgr/palloc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/palloc.c,v 1.11 1999/02/13 23:20:11 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/Attic/palloc.c,v 1.12 1999/05/25 16:12:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,7 +36,7 @@ char * pstrdup(char *string) { - char *nstr; + char *nstr; int len; nstr = palloc(len = strlen(string) + 1); @@ -44,4 +44,3 @@ pstrdup(char *string) return nstr; } - diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index 4068b13467a..d4cc93482f8 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.18 1999/02/13 23:20:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.19 1999/05/25 16:12:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -50,7 +50,7 @@ * * Here is an old comment taken from nodes/memnodes.h * - * MemoryContext + * MemoryContext * A logical context in which memory allocations occur. * * The types of memory contexts can be thought of as members of the @@ -517,7 +517,7 @@ DumpPortals() * ---------------------------------------------------------------- */ /* - * EnablePortalManager + * EnablePortalManager * Enables/disables the portal management module. */ void @@ -579,7 +579,7 @@ EnablePortalManager(bool on) } /* - * GetPortalByName + * GetPortalByName * Returns a portal given a portal name; returns blank portal given * NULL; returns invalid portal if portal not found. * @@ -606,7 +606,7 @@ GetPortalByName(char *name) } /* - * BlankPortalAssignName + * BlankPortalAssignName * Returns former blank portal as portal with given name. * * Side effect: @@ -659,7 +659,7 @@ BlankPortalAssignName(char *name) /* XXX PortalName */ } /* - * PortalSetQuery + * PortalSetQuery * Attaches a "query" to portal. * * Exceptions: @@ -686,7 +686,7 @@ PortalSetQuery(Portal portal, } /* - * PortalGetQueryDesc + * PortalGetQueryDesc * Returns query attached to portal. * * Exceptions: @@ -703,7 +703,7 @@ PortalGetQueryDesc(Portal portal) } /* - * PortalGetState + * PortalGetState * Returns state attached to portal. * * Exceptions: @@ -720,7 +720,7 @@ PortalGetState(Portal portal) } /* - * CreatePortal + * CreatePortal * Returns a new portal given a name. * * Note: @@ -784,7 +784,7 @@ CreatePortal(char *name) /* XXX PortalName */ } /* - * PortalDestroy + * PortalDestroy * Destroys portal. * * Exceptions: @@ -813,22 +813,22 @@ PortalDestroy(Portal *portalP) AllocSetReset(&portal->variable.setData); /* XXX log */ /* - * In the case of a transaction abort it is possible that - * we get called while one of the memory contexts of the portal - * we're destroying is the current memory context. - * - * Don't know how to handle that cleanly because it is required - * to be in that context right now. This portal struct remains - * allocated in the PortalMemory context until backend dies. + * In the case of a transaction abort it is possible that we get + * called while one of the memory contexts of the portal we're + * destroying is the current memory context. * - * Not happy with that, but it's better to loose some bytes of - * memory than to have the backend dump core. + * Don't know how to handle that cleanly because it is required to be in + * that context right now. This portal struct remains allocated in the + * PortalMemory context until backend dies. + * + * Not happy with that, but it's better to loose some bytes of memory + * than to have the backend dump core. * * --- Feb. 04, 1999 Jan Wieck */ - if (CurrentMemoryContext == (MemoryContext)PortalGetHeapMemory(portal)) + if (CurrentMemoryContext == (MemoryContext) PortalGetHeapMemory(portal)) return; - if (CurrentMemoryContext == (MemoryContext)PortalGetVariableMemory(portal)) + if (CurrentMemoryContext == (MemoryContext) PortalGetVariableMemory(portal)) return; if (portal != BlankPortal) @@ -836,7 +836,7 @@ PortalDestroy(Portal *portalP) } /* ---------------- - * PortalResetHeapMemory + * PortalResetHeapMemory * Resets portal's heap memory context. * * Someday, Reset, Start, and End can be optimized by keeping a global @@ -873,7 +873,7 @@ PortalResetHeapMemory(Portal portal) } /* - * StartPortalAllocMode + * StartPortalAllocMode * Starts a new block of portal heap allocation using mode and limit; * the current block is disabled until EndPortalAllocMode is called. * @@ -904,7 +904,7 @@ StartPortalAllocMode(AllocMode mode, Size limit) /* allocate and initialize new block */ context->block = MemoryContextAlloc( (MemoryContext) PortalHeapMemoryGetVariableMemory(context), - sizeof(HeapMemoryBlockData)); + sizeof(HeapMemoryBlockData)); /* XXX careful, context->block has never been stacked => bad state */ @@ -912,7 +912,7 @@ StartPortalAllocMode(AllocMode mode, Size limit) } /* - * EndPortalAllocMode + * EndPortalAllocMode * Ends current block of portal heap allocation; previous block is * reenabled. * @@ -944,7 +944,7 @@ EndPortalAllocMode() } /* - * PortalGetVariableMemory + * PortalGetVariableMemory * Returns variable memory context for a given portal. * * Exceptions: @@ -958,7 +958,7 @@ PortalGetVariableMemory(Portal portal) } /* - * PortalGetHeapMemory + * PortalGetHeapMemory * Returns heap memory context for a given portal. * * Exceptions: @@ -972,7 +972,7 @@ PortalGetHeapMemory(Portal portal) } /* - * PortalVariableMemoryGetPortal + * PortalVariableMemoryGetPortal * Returns portal containing given variable memory context. * * Exceptions: @@ -986,7 +986,7 @@ PortalVariableMemoryGetPortal(PortalVariableMemory context) } /* - * PortalHeapMemoryGetPortal + * PortalHeapMemoryGetPortal * Returns portal containing given heap memory context. * * Exceptions: @@ -1000,7 +1000,7 @@ PortalHeapMemoryGetPortal(PortalHeapMemory context) } /* - * PortalVariableMemoryGetHeapMemory + * PortalVariableMemoryGetHeapMemory * Returns heap memory context associated with given variable memory. * * Exceptions: @@ -1019,7 +1019,7 @@ PortalVariableMemoryGetHeapMemory(PortalVariableMemory context) #endif /* - * PortalHeapMemoryGetVariableMemory + * PortalHeapMemoryGetVariableMemory * Returns variable memory context associated with given heap memory. * * Exceptions: diff --git a/src/backend/utils/sort/psort.c b/src/backend/utils/sort/psort.c index d35141ad77b..497dceff07e 100644 --- a/src/backend/utils/sort/psort.c +++ b/src/backend/utils/sort/psort.c @@ -4,7 +4,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: psort.c,v 1.51 1999/05/09 00:53:22 tgl Exp $ + * $Id: psort.c,v 1.52 1999/05/25 16:12:59 momjian Exp $ * * NOTES * Sorts the first relation into the second relation. @@ -55,9 +55,9 @@ #include "utils/rel.h" static bool createfirstrun(Sort *node); -static bool createrun(Sort *node, BufFile *file); -static void destroytape(BufFile *file); -static void dumptuples(BufFile *file, Sort *node); +static bool createrun(Sort *node, BufFile * file); +static void destroytape(BufFile * file); +static void dumptuples(BufFile * file, Sort *node); static BufFile *gettape(void); static void initialrun(Sort *node); static void inittapes(Sort *node); @@ -320,15 +320,11 @@ initialrun(Sort *node) tp->tp_dummy--; PS(node)->TotalDummy--; if (tp->tp_dummy < (tp + 1)->tp_dummy) - { tp++; - } - else + else { if (tp->tp_dummy != 0) - { tp = PS(node)->Tape; - } else { PS(node)->Level++; @@ -337,13 +333,13 @@ initialrun(Sort *node) tp - PS(node)->Tape < PS(node)->TapeRange; tp++) { PS(node)->TotalDummy += (tp->tp_dummy = baseruns - + (tp + 1)->tp_fib - - tp->tp_fib); + + (tp + 1)->tp_fib + - tp->tp_fib); tp->tp_fib = baseruns + (tp + 1)->tp_fib; } - tp = PS(node)->Tape;/* D4 */ - } /* D3 */ + tp = PS(node)->Tape; /* D4 */ + } /* D3 */ } if (extrapasses) { @@ -354,9 +350,7 @@ initialrun(Sort *node) continue; } else - { break; - } } if ((bool) createrun(node, tp->tp_file) == false) extrapasses = 1 + (PS(node)->Tuples != NULL); @@ -479,7 +473,7 @@ createfirstrun(Sort *node) * Tuples contains the tuples for the following run upon exit */ static bool -createrun(Sort *node, BufFile *file) +createrun(Sort *node, BufFile * file) { HeapTuple lasttuple; HeapTuple tup; @@ -554,9 +548,7 @@ createrun(Sort *node, BufFile *file) memtuples[t_last] = tup; } else - { puttuple(&PS(node)->Tuples, tup, 0, &PS(node)->treeContext); - } } if (lasttuple != NULL) { @@ -627,7 +619,7 @@ merge(Sort *node, struct tape * dest) struct tape *lasttp; /* (TAPE[P]) */ struct tape *tp; struct leftist *tuples; - BufFile *destfile; + BufFile *destfile; int times; /* runs left to merge */ int outdummy; /* complete dummy runs */ short fromtape; @@ -644,10 +636,9 @@ merge(Sort *node, struct tape * dest) tp->tp_fib += times; /* Tape[].tp_fib (A[]) is set to proper exit values */ - if (PS(node)->TotalDummy < PS(node)->TapeRange) /* no complete dummy runs */ - { + if (PS(node)->TotalDummy < PS(node)->TapeRange) /* no complete dummy + * runs */ outdummy = 0; - } else { outdummy = PS(node)->TotalDummy; /* a large positive number */ @@ -729,7 +720,7 @@ merge(Sort *node, struct tape * dest) * dumptuples - stores all the tuples in tree into file */ static void -dumptuples(BufFile *file, Sort *node) +dumptuples(BufFile * file, Sort *node) { struct leftist *tp; struct leftist *newp; @@ -812,7 +803,7 @@ psort_grabtuple(Sort *node, bool *should_free) * file */ BufFileSeek(PS(node)->psort_grab_file, - PS(node)->psort_current - sizeof(tlendummy), SEEK_SET); + PS(node)->psort_current - sizeof(tlendummy), SEEK_SET); GETLEN(tuplen, PS(node)->psort_grab_file); if (PS(node)->psort_current < tuplen) elog(ERROR, "psort_grabtuple: too big last tuple len in backward scan"); @@ -845,7 +836,7 @@ psort_grabtuple(Sort *node, bool *should_free) PS(node)->psort_current -= tuplen; /* move to position of end tlen of prev tuple */ BufFileSeek(PS(node)->psort_grab_file, - PS(node)->psort_current - sizeof(tlendummy), SEEK_SET); + PS(node)->psort_current - sizeof(tlendummy), SEEK_SET); GETLEN(tuplen, PS(node)->psort_grab_file); if (PS(node)->psort_current < tuplen + sizeof(tlendummy)) elog(ERROR, "psort_grabtuple: too big tuple len in backward scan"); @@ -1005,7 +996,7 @@ gettape() * destroytape - unlinks the tape */ static void -destroytape(BufFile *file) +destroytape(BufFile * file) { BufFileClose(file); } diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index bdcd1afdba8..104e57b9194 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.28 1999/04/12 16:57:27 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.29 1999/05/25 16:13:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,11 +26,11 @@ extern bool PostgresIsInitialized; -SnapshotData SnapshotDirtyData; -Snapshot SnapshotDirty = &SnapshotDirtyData; +SnapshotData SnapshotDirtyData; +Snapshot SnapshotDirty = &SnapshotDirtyData; -Snapshot QuerySnapshot = NULL; -Snapshot SerializableSnapshot = NULL; +Snapshot QuerySnapshot = NULL; +Snapshot SerializableSnapshot = NULL; /* * XXX Transaction system override hacks start here @@ -59,7 +59,7 @@ setheapoverride(bool on) */ /* - * HeapTupleSatisfiesItself + * HeapTupleSatisfiesItself * True iff heap tuple is valid for "itself." * "{it}self" means valid as of everything that's happened * in the current transaction, _including_ the current command. @@ -91,7 +91,7 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple) if (tuple->t_infomask & HEAP_MOVED_OFF) { - if (TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -99,7 +99,7 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple) } else if (tuple->t_infomask & HEAP_MOVED_IN) { - if (!TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (!TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -130,7 +130,7 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple) { if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) return true; - return false; /* updated by other */ + return false; /* updated by other */ } if (TransactionIdIsCurrentTransactionId(tuple->t_xmax)) @@ -157,7 +157,7 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple) } /* - * HeapTupleSatisfiesNow + * HeapTupleSatisfiesNow * True iff heap tuple is valid "now." * "now" means valid including everything that's happened * in the current transaction _up to, but not including,_ @@ -218,7 +218,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple) if (tuple->t_infomask & HEAP_MOVED_OFF) { - if (TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -226,7 +226,7 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple) } else if (tuple->t_infomask & HEAP_MOVED_IN) { - if (!TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (!TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -300,19 +300,19 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple) int HeapTupleSatisfiesUpdate(HeapTuple tuple) { - HeapTupleHeader th = tuple->t_data; + HeapTupleHeader th = tuple->t_data; if (AMI_OVERRIDE) return HeapTupleMayBeUpdated; if (!(th->t_infomask & HEAP_XMIN_COMMITTED)) { - if (th->t_infomask & HEAP_XMIN_INVALID) /* xid invalid or aborted */ + if (th->t_infomask & HEAP_XMIN_INVALID) /* xid invalid or aborted */ return HeapTupleInvisible; if (th->t_infomask & HEAP_MOVED_OFF) { - if (TransactionIdDidCommit((TransactionId)th->t_cmin)) + if (TransactionIdDidCommit((TransactionId) th->t_cmin)) { th->t_infomask |= HEAP_XMIN_INVALID; return HeapTupleInvisible; @@ -320,7 +320,7 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) } else if (th->t_infomask & HEAP_MOVED_IN) { - if (!TransactionIdDidCommit((TransactionId)th->t_cmin)) + if (!TransactionIdDidCommit((TransactionId) th->t_cmin)) { th->t_infomask |= HEAP_XMIN_INVALID; return HeapTupleInvisible; @@ -329,9 +329,10 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) else if (TransactionIdIsCurrentTransactionId(th->t_xmin)) { if (CommandIdGEScanCommandId(th->t_cmin) && !heapisoverride()) - return HeapTupleInvisible; /* inserted after scan started */ + return HeapTupleInvisible; /* inserted after scan + * started */ - if (th->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */ + if (th->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */ return HeapTupleMayBeUpdated; Assert(TransactionIdIsCurrentTransactionId(th->t_xmax)); @@ -340,14 +341,16 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) return HeapTupleMayBeUpdated; if (CommandIdGEScanCommandId(th->t_cmax)) - return HeapTupleSelfUpdated;/* updated after scan started */ + return HeapTupleSelfUpdated; /* updated after scan + * started */ else - return HeapTupleInvisible; /* updated before scan started */ + return HeapTupleInvisible; /* updated before scan + * started */ } else if (!TransactionIdDidCommit(th->t_xmin)) { if (TransactionIdDidAbort(th->t_xmin)) - th->t_infomask |= HEAP_XMIN_INVALID; /* aborted */ + th->t_infomask |= HEAP_XMIN_INVALID; /* aborted */ return HeapTupleInvisible; } th->t_infomask |= HEAP_XMIN_COMMITTED; @@ -355,14 +358,14 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) /* by here, the inserting transaction has committed */ - if (th->t_infomask & HEAP_XMAX_INVALID) /* xid invalid or aborted */ + if (th->t_infomask & HEAP_XMAX_INVALID) /* xid invalid or aborted */ return HeapTupleMayBeUpdated; if (th->t_infomask & HEAP_XMAX_COMMITTED) { if (th->t_infomask & HEAP_MARKED_FOR_UPDATE) return HeapTupleMayBeUpdated; - return HeapTupleUpdated; /* updated by other */ + return HeapTupleUpdated;/* updated by other */ } if (TransactionIdIsCurrentTransactionId(th->t_xmax)) @@ -370,7 +373,8 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) if (th->t_infomask & HEAP_MARKED_FOR_UPDATE) return HeapTupleMayBeUpdated; if (CommandIdGEScanCommandId(th->t_cmax)) - return HeapTupleSelfUpdated;/* updated after scan started */ + return HeapTupleSelfUpdated; /* updated after scan + * started */ else return HeapTupleInvisible; /* updated before scan started */ } @@ -392,7 +396,7 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) if (th->t_infomask & HEAP_MARKED_FOR_UPDATE) return HeapTupleMayBeUpdated; - return HeapTupleUpdated; /* updated by other */ + return HeapTupleUpdated; /* updated by other */ } bool @@ -411,13 +415,14 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple) if (tuple->t_infomask & HEAP_MOVED_OFF) { + /* * HeapTupleSatisfiesDirty is used by unique btree-s and so * may be used while vacuuming. */ - if (TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_cmin)) + if (TransactionIdIsCurrentTransactionId((TransactionId) tuple->t_cmin)) return false; - if (TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -426,9 +431,9 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple) } else if (tuple->t_infomask & HEAP_MOVED_IN) { - if (!TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_cmin)) + if (!TransactionIdIsCurrentTransactionId((TransactionId) tuple->t_cmin)) { - if (TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (TransactionIdDidCommit((TransactionId) tuple->t_cmin)) tuple->t_infomask |= HEAP_XMIN_COMMITTED; else { @@ -457,7 +462,7 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple) return false; } SnapshotDirty->xmin = tuple->t_xmin; - return true; /* in insertion by other */ + return true; /* in insertion by other */ } else tuple->t_infomask |= HEAP_XMIN_COMMITTED; @@ -473,7 +478,7 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple) if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE) return true; SnapshotDirty->tid = tuple->t_ctid; - return false; /* updated by other */ + return false; /* updated by other */ } if (TransactionIdIsCurrentTransactionId(tuple->t_xmax)) @@ -488,7 +493,7 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple) } /* running xact */ SnapshotDirty->xmax = tuple->t_xmax; - return true; /* in updation by other */ + return true; /* in updation by other */ } /* xmax transaction committed */ @@ -498,7 +503,7 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple) return true; SnapshotDirty->tid = tuple->t_ctid; - return false; /* updated by other */ + return false; /* updated by other */ } bool @@ -514,7 +519,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) if (tuple->t_infomask & HEAP_MOVED_OFF) { - if (TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -522,7 +527,7 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) } else if (tuple->t_infomask & HEAP_MOVED_IN) { - if (!TransactionIdDidCommit((TransactionId)tuple->t_cmin)) + if (!TransactionIdDidCommit((TransactionId) tuple->t_cmin)) { tuple->t_infomask |= HEAP_XMIN_INVALID; return false; @@ -555,17 +560,17 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) tuple->t_infomask |= HEAP_XMIN_COMMITTED; } - /* - * By here, the inserting transaction has committed - - * have to check when... + /* + * By here, the inserting transaction has committed - have to check + * when... */ if (tuple->t_xmin >= snapshot->xmax) return false; if (tuple->t_xmin >= snapshot->xmin) { - uint32 i; - + uint32 i; + for (i = 0; i < snapshot->xcnt; i++) { if (tuple->t_xmin == snapshot->xip[i]) @@ -584,15 +589,15 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) if (TransactionIdIsCurrentTransactionId(tuple->t_xmax)) { if (CommandIdGEScanCommandId(tuple->t_cmax)) - return true; /* deleted after scan started */ + return true; /* deleted after scan started */ else - return false; /* deleted before scan started */ + return false; /* deleted before scan started */ } if (!TransactionIdDidCommit(tuple->t_xmax)) { if (TransactionIdDidAbort(tuple->t_xmax)) - tuple->t_infomask |= HEAP_XMAX_INVALID; /* aborted */ + tuple->t_infomask |= HEAP_XMAX_INVALID; /* aborted */ return true; } @@ -604,8 +609,8 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) return true; if (tuple->t_xmax >= snapshot->xmin) { - uint32 i; - + uint32 i; + for (i = 0; i < snapshot->xcnt; i++) { if (tuple->t_xmax == snapshot->xip[i]) |