1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Remove dashes in comments that don't need them, rewrap with pgindent.

This commit is contained in:
Bruce Momjian
2001-03-22 06:16:21 +00:00
parent 9e1552607a
commit 0686d49da0
100 changed files with 4522 additions and 6023 deletions

View File

@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* ascii.c
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.7 2001/03/22 03:59:49 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ascii.c,v 1.8 2001/03/22 06:16:17 momjian Exp $
*
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
*
@@ -80,27 +80,27 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
if (enc == LATIN1)
{
/* ----------
/*
* ISO-8859-1 <range: 160 -- 255>
* ----------
*/
ascii = " cL Y \"Ca -R 'u ., ?AAAAAAACEEEEIIII NOOOOOxOUUUUYTBaaaaaaaceeeeiiii nooooo/ouuuuyty";
range = RANGE_160;
}
else if (enc == LATIN2)
{
/* ----------
/*
* ISO-8859-2 <range: 160 -- 255>
* ----------
*/
ascii = " A L LS \"SSTZ-ZZ a,l'ls ,sstz\"zzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt.";
range = RANGE_160;
}
else if (enc == WIN1250)
{
/* ----------
/*
* Window CP1250 <range: 128 -- 255>
* ----------
*/
ascii = " ' \" %S<STZZ `'\"\".-- s>stzz L A \"CS -RZ ,l'u .,as L\"lzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTBraaaalccceeeeiiddnnoooo/ruuuuyt ";
range = RANGE_128;
@@ -111,9 +111,8 @@ pg_to_ascii(unsigned char *src, unsigned char *src_end, unsigned char *desc, int
pg_encoding_to_char(enc));
}
/* ----------
/*
* Encode
* ----------
*/
for (x = src; x <= src_end; x++)
{

View File

@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* formatting.c
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.34 2001/03/22 03:59:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.35 2001/03/22 06:16:17 momjian Exp $
*
*
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
@@ -1132,9 +1132,8 @@ parse_format(FormatNode *node, char *str, KeyWord *kw,
{
suffix = 0;
/* ----------
/*
* Prefix
* ----------
*/
if (ver == DCH_TYPE && (s = suff_search(str, suf, SUFFTYPE_PREFIX)) != NULL)
{
@@ -1143,9 +1142,8 @@ parse_format(FormatNode *node, char *str, KeyWord *kw,
str += s->len;
}
/* ----------
/*
* Keyword
* ----------
*/
if (*str && (n->key = index_seq_search(str, kw, index)) != NULL)
{
@@ -1156,16 +1154,14 @@ parse_format(FormatNode *node, char *str, KeyWord *kw,
if (n->key->len)
str += n->key->len;
/* ----------
/*
* NUM version: Prepare global NUMDesc struct
* ----------
*/
if (ver == NUM_TYPE)
NUMDesc_prepare(Num, n);
/* ----------
/*
* Postfix
* ----------
*/
if (ver == DCH_TYPE && *str && (s = suff_search(str, suf, SUFFTYPE_POSTFIX)) != NULL)
{
@@ -1178,9 +1174,8 @@ parse_format(FormatNode *node, char *str, KeyWord *kw,
else if (*str)
{
/* ----------
/*
* Special characters '\' and '"'
* ----------
*/
if (*str == '"' && last != '\\')
{
@@ -1258,9 +1253,8 @@ DCH_processor(FormatNode *node, char *inout, int flag)
char *s;
/* ----------
/*
* Zeroing global flags
* ----------
*/
DCH_global_flag = 0;
@@ -1270,9 +1264,8 @@ DCH_processor(FormatNode *node, char *inout, int flag)
{
int len;
/* ----------
/*
* Call node action function
* ----------
*/
len = n->key->action(n->key->id, s, n->suffix, flag, n);
if (len > 0)
@@ -1284,18 +1277,17 @@ DCH_processor(FormatNode *node, char *inout, int flag)
else
{
/* ----------
/*
* Remove to output char from input in TO_CHAR
* ----------
*/
if (flag == TO_CHAR)
*s = n->character;
else
{
/* ----------
/*
* Skip blank space in FROM_CHAR's input
* ----------
*/
if (isspace((unsigned char) n->character) && IS_FX == 0)
{
@@ -1893,11 +1885,10 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node)
p_inout = inout;
/* ----------
/*
* In the FROM-char is not difference between "January" or "JANUARY"
* or "january", all is before search convert to "first-upper".
* This convention is used for MONTH, MON, DAY, DY
* ----------
* or "january", all is before search convert to "first-upper". This
* convention is used for MONTH, MON, DAY, DY
*/
if (flag == FROM_CHAR)
{
@@ -2459,9 +2450,8 @@ DCH_cache_getnew(char *str)
ent->age = (++DCHCounter);
}
/* ----------
/*
* Cache is full - needs remove any older entry
* ----------
*/
if (n_DCHCache > DCH_CACHE_FIELDS)
{
@@ -2583,24 +2573,21 @@ timestamp_to_char(PG_FUNCTION_ARGS)
tm->tm_wday = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1) % 7;
tm->tm_yday = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(tm->tm_year, 1, 1) + 1;
/* ----------
/*
* Convert fmt to C string
* ----------
*/
str = (char *) palloc(len + 1);
memcpy(str, VARDATA(fmt), len);
*(str + len) = '\0';
/* ----------
/*
* Allocate result
* ----------
*/
result = (text *) palloc((len * DCH_MAX_ITEM_SIZ) + 1 + VARHDRSZ);
/* ----------
/*
* Allocate new memory if format picture is bigger than static cache
* and not use cache (call parser always) - flag=1 show this variant
* ----------
*/
if (len > DCH_CACHE_SIZE)
{
@@ -2616,9 +2603,8 @@ timestamp_to_char(PG_FUNCTION_ARGS)
else
{
/* ----------
/*
* Use cache buffers
* ----------
*/
DCHCacheEntry *ent;
@@ -2629,10 +2615,9 @@ timestamp_to_char(PG_FUNCTION_ARGS)
ent = DCH_cache_getnew(str);
/* ----------
/*
* Not in the cache, must run parser and save a new
* format-picture to the cache.
* ----------
*/
parse_format(ent->format, str, DCH_keywords,
DCH_suff, DCH_index, DCH_TYPE, NULL);
@@ -2654,10 +2639,9 @@ timestamp_to_char(PG_FUNCTION_ARGS)
pfree(str);
/* ----------
/*
* for result is allocated max memory, which current format-picture
* needs, now it must be re-allocate to result real size
* ----------
*/
if (!(len = strlen(VARDATA(result))))
{
@@ -2706,18 +2690,17 @@ to_timestamp(PG_FUNCTION_ARGS)
if (len)
{
/* ----------
/*
* Convert fmt to C string
* ----------
*/
str = (char *) palloc(len + 1);
memcpy(str, VARDATA(fmt), len);
*(str + len) = '\0';
/* ----------
* Allocate new memory if format picture is bigger than static cache
* and not use cache (call parser always) - flag=1 show this variant
* ----------
/*
* Allocate new memory if format picture is bigger than static
* cache and not use cache (call parser always) - flag=1 show this
* variant
*/
if (len > DCH_CACHE_SIZE)
{
@@ -2732,9 +2715,8 @@ to_timestamp(PG_FUNCTION_ARGS)
else
{
/* ----------
/*
* Use cache buffers
* ----------
*/
DCHCacheEntry *ent;
@@ -2745,11 +2727,10 @@ to_timestamp(PG_FUNCTION_ARGS)
ent = DCH_cache_getnew(str);
/* ----------
/*
* Not in the cache, must run parser and save a new
* format-picture to the cache.
* ----------
*/
*/
parse_format(ent->format, str, DCH_keywords,
DCH_suff, DCH_index, DCH_TYPE, NULL);
@@ -2762,17 +2743,15 @@ to_timestamp(PG_FUNCTION_ARGS)
format = ent->format;
}
/* ----------
/*
* Call action for each node in FormatNode tree
* ----------
*/
#ifdef DEBUG_TO_FROM_CHAR
/* dump_node(format, len); */
#endif
/* ----------
/*
* Convert date to C string
* ----------
*/
date_len = VARSIZE(date_txt) - VARHDRSZ;
date_str = (char *) palloc(date_len + 1);
@@ -2787,10 +2766,9 @@ to_timestamp(PG_FUNCTION_ARGS)
pfree(format);
}
/* --------------------------------------------------------------
* Convert values that user define for FROM_CHAR (to_date/to_timestamp)
* to standard 'tm'
* ----------
/*
* Convert values that user define for FROM_CHAR
* (to_date/to_timestamp) to standard 'tm'
*/
#ifdef DEBUG_TO_FROM_CHAR
NOTICE_TMFC;
@@ -3050,9 +3028,8 @@ NUM_cache_getnew(char *str)
ent->age = (++NUMCounter);
}
/* ----------
/*
* Cache is full - needs remove any older entry
* ----------
*/
if (n_NUMCache > NUM_CACHE_FIELDS)
{
@@ -3156,18 +3133,16 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, int *flag)
FormatNode *format = NULL;
char *str;
/* ----------
/*
* Convert VARDATA() to string
* ----------
*/
str = (char *) palloc(len + 1);
memcpy(str, pars_str, len);
*(str + len) = '\0';
/* ----------
/*
* Allocate new memory if format picture is bigger than static cache
* and not use cache (call parser always) - flag=1 show this variant
* ----------
*/
if (len > NUM_CACHE_SIZE)
{
@@ -3186,9 +3161,8 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, int *flag)
else
{
/* ----------
/*
* Use cache buffers
* ----------
*/
NUMCacheEntry *ent;
@@ -3199,11 +3173,10 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, int *flag)
ent = NUM_cache_getnew(str);
/* ----------
/*
* Not in the cache, must run parser and save a new
* format-picture to the cache.
* ----------
*/
*/
parse_format(ent->format, str, NUM_keywords,
NULL, NUM_index, NUM_TYPE, &ent->Num);
@@ -3213,9 +3186,8 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, int *flag)
format = ent->format;
/* ----------
/*
* Copy cache to used struct
* ----------
*/
Num->flag = ent->Num.flag;
Num->lsign = ent->Num.lsign;
@@ -3302,15 +3274,13 @@ NUM_prepare_locale(NUMProc *Np)
struct lconv *lconv;
/* ----------
/*
* Get locales
* ----------
*/
lconv = PGLC_localeconv();
/* ----------
/*
* Positive / Negative number sign
* ----------
*/
if (lconv->negative_sign && *lconv->negative_sign)
Np->L_negative_sign = lconv->negative_sign;
@@ -3322,27 +3292,24 @@ NUM_prepare_locale(NUMProc *Np)
else
Np->L_positive_sign = "+";
/* ----------
/*
* Number thousands separator
* ----------
*/
if (lconv->thousands_sep && *lconv->thousands_sep)
Np->L_thousands_sep = lconv->thousands_sep;
else
Np->L_thousands_sep = ",";
/* ----------
/*
* Number decimal point
* ----------
*/
if (lconv->decimal_point && *lconv->decimal_point)
Np->decimal = lconv->decimal_point;
else
Np->decimal = ".";
/* ----------
/*
* Currency symbol
* ----------
*/
if (lconv->currency_symbol && *lconv->currency_symbol)
Np->L_currency_symbol = lconv->currency_symbol;
@@ -3357,9 +3324,9 @@ NUM_prepare_locale(NUMProc *Np)
{
#endif
/* ----------
/*
* Default values
* ----------
*/
Np->L_negative_sign = "-";
Np->L_positive_sign = "+";
@@ -3423,9 +3390,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
if (OVERLOAD_TEST)
return;
/* ----------
/*
* read sign
* ----------
*/
if (*Np->number == ' ' && (id == NUM_0 || id == NUM_9 || NUM_S))
{
@@ -3433,9 +3399,9 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
#ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read sign (%c).", *Np->inout_p);
#endif
/* ----------
/*
* locale sign
* ----------
*/
if (IS_LSIGN(Np->Num))
{
@@ -3464,9 +3430,9 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
#ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read sipmle sign (%c).", *Np->inout_p);
#endif
/* ----------
/*
* simple + - < >
* ----------
*/
if (*Np->inout_p == '-' || (IS_BRACKET(Np->Num) &&
*Np->inout_p == '<'))
@@ -3487,9 +3453,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
if (OVERLOAD_TEST)
return;
/* ----------
/*
* read digit
* ----------
*/
if (isdigit((unsigned char) *Np->inout_p))
{
@@ -3507,9 +3472,8 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
elog(DEBUG_elog_output, "Read digit (%c).", *Np->inout_p);
#endif
/* ----------
/*
* read decimal point
* ----------
*/
}
else if (IS_DECIMAL(Np->Num))
@@ -3572,9 +3536,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
#endif
Np->num_in = FALSE;
/* ----------
/*
* Write sign
* ----------
*/
if (Np->num_curr == Np->sign_pos && Np->sign_wrote == FALSE)
{
@@ -3585,9 +3548,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
if (IS_LSIGN(Np->Num))
{
/* ----------
/*
* Write locale SIGN
* ----------
*/
if (Np->sign == '-')
strcpy(Np->inout_p, Np->L_negative_sign);
@@ -3620,9 +3582,9 @@ NUM_numpart_to_char(NUMProc *Np, int id)
(Np->num_curr == Np->num_count + (Np->num_pre ? 1 : 0)
+ (IS_DECIMAL(Np->Num) ? 1 : 0)))
{
/* ----------
/*
* Write close BRACKET
* ----------
*/
#ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Writing bracket to position %d", Np->num_curr);
@@ -3631,9 +3593,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
++Np->inout_p;
}
/* ----------
/*
* digits / FM / Zero / Dec. point
* ----------
*/
if (id == NUM_9 || id == NUM_0 || id == NUM_D || id == NUM_DEC ||
(id == NUM_S && Np->num_curr < Np->num_pre))
@@ -3643,9 +3604,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
(Np->Num->zero_start > Np->num_curr || !IS_ZERO(Np->Num)))
{
/* ----------
/*
* Write blank space
* ----------
*/
if (!IS_FILLMODE(Np->Num))
{
@@ -3662,9 +3622,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
Np->Num->zero_start <= Np->num_curr)
{
/* ----------
/*
* Write ZERO
* ----------
*/
#ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Writing zero to position %d", Np->num_curr);
@@ -3677,10 +3636,9 @@ NUM_numpart_to_char(NUMProc *Np, int id)
else
{
/* ----------
* Write Decinal point
* ----------
*/
/*
* Write Decinal point
*/
if (*Np->number_p == '.')
{
@@ -3708,9 +3666,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
else
{
/* ----------
/*
* Write Digits
* ----------
*/
if (Np->last_relevant && Np->number_p > Np->last_relevant &&
id != NUM_0)
@@ -3775,9 +3732,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
if (Np->Num->zero_start)
--Np->Num->zero_start;
/* ----------
/*
* Roman correction
* ----------
*/
if (IS_ROMAN(Np->Num))
{
@@ -3797,9 +3753,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
Np->Num->flag |= NUM_F_ROMAN;
}
/* ----------
/*
* Sign
* ----------
*/
if (type == FROM_CHAR)
{
@@ -3833,9 +3788,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
Np->sign_wrote = TRUE; /* needn't sign */
}
/* ----------
/*
* Count
* ----------
*/
Np->num_count = Np->Num->post + Np->Num->pre - 1;
@@ -3858,9 +3812,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
if (!Np->sign_wrote)
{
/* ----------
/*
* Set SING position
* ----------
*/
if (Np->Num->lsign == NUM_LSIGN_POST)
{
@@ -3875,9 +3828,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
else
Np->sign_pos = Np->num_pre && !IS_FILLMODE(Np->Num) ? Np->num_pre : 0;
/* ----------
/*
* terrible Ora format
* ----------
*/
if (!IS_ZERO(Np->Num) && *Np->number == '0' &&
!IS_FILLMODE(Np->Num) && Np->Num->post != 0)
@@ -3924,15 +3876,13 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
);
#endif
/* ----------
/*
* Locale
* ----------
*/
NUM_prepare_locale(Np);
/* ----------
/*
* Processor direct cycle
* ----------
*/
if (Np->type == FROM_CHAR)
Np->number_p = Np->number + 1; /* first char is space for sign */
@@ -3944,24 +3894,22 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
if (Np->type == FROM_CHAR)
{
/* ----------
/*
* Check non-string inout end
* ----------
*/
if (Np->inout_p >= Np->inout + plen)
break;
}
/* ----------
/*
* Format pictures actions
* ----------
*/
if (n->type == NODE_TYPE_ACTION)
{
/* ----------
/*
* Create/reading digit/zero/blank/sing
* ----------
*/
switch (n->key->id)
{
@@ -4145,9 +4093,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
}
else
{
/* ----------
/*
* Remove to output char from input in TO_CHAR
* ----------
*/
if (Np->type == TO_CHAR)
*Np->inout_p = n->character;
@@ -4169,9 +4117,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
else
*Np->number_p = '\0';
/* ----------
/*
* Correction - precision of dec. number
* ----------
*/
Np->Num->post = Np->read_post;
@@ -4213,10 +4160,9 @@ do { \
if (flag) \
pfree(format); \
\
/* ---------- \
/*
* for result is allocated max memory, which current format-picture\
* needs, now it must be re-allocate to result real size \
* ---------- \
*/ \
if (!(len = strlen(VARDATA(result)))) \
{ \
@@ -4300,9 +4246,8 @@ numeric_to_char(PG_FUNCTION_ARGS)
NUM_TOCHAR_prepare;
/* ----------
/*
* On DateType depend part (numeric)
* ----------
*/
if (IS_ROMAN(&Num))
{
@@ -4399,9 +4344,8 @@ int4_to_char(PG_FUNCTION_ARGS)
NUM_TOCHAR_prepare;
/* ----------
/*
* On DateType depend part (int32)
* ----------
*/
if (IS_ROMAN(&Num))
numstr = orgnum = int_to_roman(value);
@@ -4481,9 +4425,8 @@ int8_to_char(PG_FUNCTION_ARGS)
NUM_TOCHAR_prepare;
/* ----------
/*
* On DateType depend part (int32)
* ----------
*/
if (IS_ROMAN(&Num))
{

View File

@@ -5,7 +5,7 @@
*
* 1998 Jan Wieck
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.38 2001/03/22 03:59:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.39 2001/03/22 06:16:17 momjian Exp $
*
* ----------
*/
@@ -201,17 +201,15 @@ numeric_in(PG_FUNCTION_ARGS)
NumericVar value;
Numeric res;
/* ----------
/*
* Check for NaN
* ----------
*/
if (strcmp(str, "NaN") == 0)
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Use set_var_from_str() to parse the input string
* and return it in the packed DB storage format
* ----------
/*
* Use set_var_from_str() to parse the input string and return it in
* the packed DB storage format
*/
init_var(&value);
set_var_from_str(str, &value);
@@ -238,21 +236,19 @@ numeric_out(PG_FUNCTION_ARGS)
NumericVar x;
char *str;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_CSTRING(pstrdup("NaN"));
/* ----------
/*
* Get the number in the variable format.
*
* Even if we didn't need to change format, we'd still need to copy
* the value to have a modifiable copy for rounding. set_var_from_num()
* Even if we didn't need to change format, we'd still need to copy the
* value to have a modifiable copy for rounding. set_var_from_num()
* also guarantees there is extra digit space in case we produce a
* carry out from rounding.
* ----------
*/
init_var(&x);
set_var_from_num(num, &x);
@@ -285,17 +281,15 @@ numeric(PG_FUNCTION_ARGS)
int maxweight;
NumericVar var;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* If the value isn't a valid type modifier, simply return a
* copy of the input value
* ----------
/*
* If the value isn't a valid type modifier, simply return a copy of
* the input value
*/
if (typmod < (int32) (VARHDRSZ))
{
@@ -304,20 +298,18 @@ numeric(PG_FUNCTION_ARGS)
PG_RETURN_NUMERIC(new);
}
/* ----------
/*
* Get the precision and scale out of the typmod value
* ----------
*/
tmp_typmod = typmod - VARHDRSZ;
precision = (tmp_typmod >> 16) & 0xffff;
scale = tmp_typmod & 0xffff;
maxweight = precision - scale;
/* ----------
* If the number is in bounds and due to the present result scale
* no rounding could be necessary, just make a copy of the input
* and modify its scale fields.
* ----------
/*
* If the number is in bounds and due to the present result scale no
* rounding could be necessary, just make a copy of the input and
* modify its scale fields.
*/
if (num->n_weight < maxweight && scale >= num->n_rscale)
{
@@ -329,10 +321,9 @@ numeric(PG_FUNCTION_ARGS)
PG_RETURN_NUMERIC(new);
}
/* ----------
* We really need to fiddle with things - unpack the number into
* a variable and let apply_typmod() do it.
* ----------
/*
* We really need to fiddle with things - unpack the number into a
* variable and let apply_typmod() do it.
*/
init_var(&var);
@@ -359,16 +350,14 @@ numeric_abs(PG_FUNCTION_ARGS)
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Do it the easy way directly on the packed format
* ----------
*/
res = (Numeric) palloc(num->varlen);
memcpy(res, num, num->varlen);
@@ -385,25 +374,22 @@ numeric_uminus(PG_FUNCTION_ARGS)
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Do it the easy way directly on the packed format
* ----------
*/
res = (Numeric) palloc(num->varlen);
memcpy(res, num, num->varlen);
/* ----------
* The packed format is known to be totally zero digit trimmed
* always. So we can identify a ZERO by the fact that there
* are no digits at all. Do nothing to a zero.
* ----------
/*
* The packed format is known to be totally zero digit trimmed always.
* So we can identify a ZERO by the fact that there are no digits at
* all. Do nothing to a zero.
*/
if (num->varlen != NUMERIC_HDRSZ)
{
@@ -425,29 +411,27 @@ numeric_sign(PG_FUNCTION_ARGS)
Numeric res;
NumericVar result;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
init_var(&result);
/* ----------
* The packed format is known to be totally zero digit trimmed
* always. So we can identify a ZERO by the fact that there
* are no digits at all.
* ----------
/*
* The packed format is known to be totally zero digit trimmed always.
* So we can identify a ZERO by the fact that there are no digits at
* all.
*/
if (num->varlen == NUMERIC_HDRSZ)
set_var_from_var(&const_zero, &result);
else
{
/* ----------
* And if there are some, we return a copy of ONE
* with the sign of our argument
* ----------
/*
* And if there are some, we return a copy of ONE with the sign of
* our argument
*/
set_var_from_var(&const_one, &result);
result.sign = NUMERIC_SIGN(num);
@@ -477,23 +461,21 @@ numeric_round(PG_FUNCTION_ARGS)
NumericVar arg;
int i;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Limit the scale value to avoid possible overflow in calculations below.
* ----------
/*
* Limit the scale value to avoid possible overflow in calculations
* below.
*/
scale = MIN(NUMERIC_MAX_RESULT_SCALE,
MAX(-NUMERIC_MAX_RESULT_SCALE, scale));
/* ----------
/*
* Unpack the argument and round it at the proper digit position
* ----------
*/
init_var(&arg);
set_var_from_num(num, &arg);
@@ -533,17 +515,15 @@ numeric_round(PG_FUNCTION_ARGS)
}
}
/* ----------
/*
* Set result's scale to something reasonable.
* ----------
*/
scale = MIN(NUMERIC_MAX_DISPLAY_SCALE, MAX(0, scale));
arg.rscale = scale;
arg.dscale = scale;
/* ----------
/*
* Return the rounded result
* ----------
*/
res = make_result(&arg);
@@ -568,40 +548,36 @@ numeric_trunc(PG_FUNCTION_ARGS)
Numeric res;
NumericVar arg;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Limit the scale value to avoid possible overflow in calculations below.
* ----------
/*
* Limit the scale value to avoid possible overflow in calculations
* below.
*/
scale = MIN(NUMERIC_MAX_RESULT_SCALE,
MAX(-NUMERIC_MAX_RESULT_SCALE, scale));
/* ----------
/*
* Unpack the argument and truncate it at the proper digit position
* ----------
*/
init_var(&arg);
set_var_from_num(num, &arg);
arg.ndigits = MIN(arg.ndigits, MAX(0, arg.weight + scale + 1));
/* ----------
/*
* Set result's scale to something reasonable.
* ----------
*/
scale = MIN(NUMERIC_MAX_DISPLAY_SCALE, MAX(0, scale));
arg.rscale = scale;
arg.dscale = scale;
/* ----------
/*
* Return the truncated result
* ----------
*/
res = make_result(&arg);
@@ -931,18 +907,16 @@ numeric_add(PG_FUNCTION_ARGS)
NumericVar result;
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Unpack the values, let add_var() compute the result
* and return it. The internals of add_var() will automatically
* set the correct result and display scales in the result.
* ----------
/*
* Unpack the values, let add_var() compute the result and return it.
* The internals of add_var() will automatically set the correct
* result and display scales in the result.
*/
init_var(&arg1);
init_var(&arg2);
@@ -978,17 +952,15 @@ numeric_sub(PG_FUNCTION_ARGS)
NumericVar result;
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Unpack the two arguments, let sub_var() compute the
* result and return it.
* ----------
/*
* Unpack the two arguments, let sub_var() compute the result and
* return it.
*/
init_var(&arg1);
init_var(&arg2);
@@ -1024,22 +996,19 @@ numeric_mul(PG_FUNCTION_ARGS)
NumericVar result;
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Unpack the arguments, let mul_var() compute the result
* and return it. Unlike add_var() and sub_var(), mul_var()
* will round the result to the scale stored in global_rscale.
* In the case of numeric_mul(), which is invoked for the *
* operator on numerics, we set it to the exact representation
* for the product (rscale = sum(rscale of arg1, rscale of arg2)
* and the same for the dscale).
* ----------
/*
* Unpack the arguments, let mul_var() compute the result and return
* it. Unlike add_var() and sub_var(), mul_var() will round the result
* to the scale stored in global_rscale. In the case of numeric_mul(),
* which is invoked for the * operator on numerics, we set it to the
* exact representation for the product (rscale = sum(rscale of arg1,
* rscale of arg2) and the same for the dscale).
*/
init_var(&arg1);
init_var(&arg2);
@@ -1081,16 +1050,14 @@ numeric_div(PG_FUNCTION_ARGS)
Numeric res;
int res_dscale;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Unpack the arguments
* ----------
*/
init_var(&arg1);
init_var(&arg2);
@@ -1122,9 +1089,8 @@ numeric_div(PG_FUNCTION_ARGS)
global_rscale = MAX(global_rscale, res_dscale + 4);
global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE);
/* ----------
/*
* Do the divide, set the display scale and return the result
* ----------
*/
div_var(&arg1, &arg2, &result);
@@ -1192,16 +1158,14 @@ numeric_inc(PG_FUNCTION_ARGS)
NumericVar arg;
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Compute the result and return it
* ----------
*/
init_var(&arg);
@@ -1231,16 +1195,14 @@ numeric_smaller(PG_FUNCTION_ARGS)
NumericVar arg2;
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Unpack the values, and decide which is the smaller one
* ----------
*/
init_var(&arg1);
init_var(&arg2);
@@ -1275,16 +1237,14 @@ numeric_larger(PG_FUNCTION_ARGS)
NumericVar arg2;
Numeric res;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Unpack the values, and decide which is the larger one
* ----------
*/
init_var(&arg1);
init_var(&arg2);
@@ -1327,17 +1287,15 @@ numeric_sqrt(PG_FUNCTION_ARGS)
NumericVar result;
int res_dscale;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
* Unpack the argument, determine the scales like for divide,
* let sqrt_var() do the calculation and return the result.
* ----------
/*
* Unpack the argument, determine the scales like for divide, let
* sqrt_var() do the calculation and return the result.
*/
init_var(&arg);
init_var(&result);
@@ -1378,16 +1336,14 @@ numeric_exp(PG_FUNCTION_ARGS)
NumericVar result;
int res_dscale;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Same procedure like for sqrt().
* ----------
*/
init_var(&arg);
init_var(&result);
@@ -1427,16 +1383,14 @@ numeric_ln(PG_FUNCTION_ARGS)
NumericVar result;
int res_dscale;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Same procedure like for sqrt()
* ----------
*/
init_var(&arg);
init_var(&result);
@@ -1478,16 +1432,14 @@ numeric_log(PG_FUNCTION_ARGS)
NumericVar result;
int res_dscale;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Initialize things and calculate scales
* ----------
*/
init_var(&arg1);
init_var(&arg2);
@@ -1501,9 +1453,8 @@ numeric_log(PG_FUNCTION_ARGS)
global_rscale = MAX(global_rscale, res_dscale + 4);
global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE);
/* ----------
/*
* Call log_var() to compute and return the result
* ----------
*/
log_var(&arg1, &arg2, &result);
@@ -1536,16 +1487,14 @@ numeric_power(PG_FUNCTION_ARGS)
NumericVar result;
int res_dscale;
/* ----------
/*
* Handle NaN
* ----------
*/
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
PG_RETURN_NUMERIC(make_result(&const_nan));
/* ----------
/*
* Initialize things and calculate scales
* ----------
*/
init_var(&arg1);
init_var(&arg2);
@@ -1559,9 +1508,8 @@ numeric_power(PG_FUNCTION_ARGS)
global_rscale = MAX(global_rscale, res_dscale + 4);
global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE);
/* ----------
/*
* Call log_var() to compute and return the result
* ----------
*/
power_var(&arg1, &arg2, &result);
@@ -1619,9 +1567,8 @@ numeric_int4(PG_FUNCTION_ARGS)
if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int4");
/* ----------
/*
* Get the number in the variable format so we can round to integer.
* ----------
*/
init_var(&x);
set_var_from_num(num, &x);
@@ -1670,9 +1617,8 @@ numeric_int8(PG_FUNCTION_ARGS)
if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int8");
/* ----------
/*
* Get the number in the variable format so we can round to integer.
* ----------
*/
init_var(&x);
set_var_from_num(num, &x);
@@ -1721,9 +1667,8 @@ numeric_int2(PG_FUNCTION_ARGS)
if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int2");
/* ----------
/*
* Get the number in the variable format so we can round to integer.
* ----------
*/
init_var(&x);
set_var_from_num(num, &x);
@@ -2512,10 +2457,8 @@ get_str_from_var(NumericVar *var, int dscale)
int i;
int d;
/* ----------
* Check if we must round up before printing the value and
* do so.
* ----------
/*
* Check if we must round up before printing the value and do so.
*/
i = dscale + var->weight + 1;
if (i >= 0 && var->ndigits > i)
@@ -2543,23 +2486,20 @@ get_str_from_var(NumericVar *var, int dscale)
else
var->ndigits = MAX(0, MIN(i, var->ndigits));
/* ----------
/*
* Allocate space for the result
* ----------
*/
str = palloc(MAX(0, dscale) + MAX(0, var->weight) + 4);
cp = str;
/* ----------
/*
* Output a dash for negative values
* ----------
*/
if (var->sign == NUMERIC_NEG)
*cp++ = '-';
/* ----------
/*
* Output all digits before the decimal point
* ----------
*/
i = MAX(var->weight, 0);
d = 0;
@@ -2573,10 +2513,9 @@ get_str_from_var(NumericVar *var, int dscale)
i--;
}
/* ----------
* If requested, output a decimal point and all the digits
* that follow it.
* ----------
/*
* If requested, output a decimal point and all the digits that follow
* it.
*/
if (dscale > 0)
{
@@ -2591,9 +2530,8 @@ get_str_from_var(NumericVar *var, int dscale)
}
}
/* ----------
/*
* terminate the string and return it
* ----------
*/
*cp = '\0';
return str;
@@ -2725,14 +2663,12 @@ apply_typmod(NumericVar *var, int32 typmod)
else
var->ndigits = MAX(0, MIN(i, var->ndigits));
/* ----------
* Check for overflow - note we can't do this before rounding,
* because rounding could raise the weight. Also note that the
* var's weight could be inflated by leading zeroes, which will
* be stripped before storage but perhaps might not have been yet.
* In any case, we must recognize a true zero, whose weight doesn't
* mean anything.
* ----------
/*
* Check for overflow - note we can't do this before rounding, because
* rounding could raise the weight. Also note that the var's weight
* could be inflated by leading zeroes, which will be stripped before
* storage but perhaps might not have been yet. In any case, we must
* recognize a true zero, whose weight doesn't mean anything.
*/
if (var->weight >= maxweight)
{
@@ -2805,28 +2741,27 @@ cmp_var(NumericVar *var1, NumericVar *var2)
static void
add_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
{
/* ----------
/*
* Decide on the signs of the two variables what to do
* ----------
*/
if (var1->sign == NUMERIC_POS)
{
if (var2->sign == NUMERIC_POS)
{
/* ----------
* Both are positive
* result = +(ABS(var1) + ABS(var2))
* ----------
/*
* Both are positive result = +(ABS(var1) + ABS(var2))
*/
add_abs(var1, var2, result);
result->sign = NUMERIC_POS;
}
else
{
/* ----------
* var1 is positive, var2 is negative
* Must compare absolute values
* ----------
/*
* var1 is positive, var2 is negative Must compare absolute
* values
*/
switch (cmp_abs(var1, var2))
{
@@ -2930,9 +2865,9 @@ add_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
static void
sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
{
/* ----------
/*
* Decide on the signs of the two variables what to do
* ----------
*/
if (var1->sign == NUMERIC_POS)
{
@@ -3157,17 +3092,15 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
int first_nextdigit;
int stat = 0;
/* ----------
/*
* First of all division by zero check
* ----------
*/
ndigits_tmp = var2->ndigits + 1;
if (ndigits_tmp == 1)
elog(ERROR, "division by zero on numeric");
/* ----------
/*
* Determine the result sign, weight and number of digits to calculate
* ----------
*/
if (var1->sign == var2->sign)
res_sign = NUMERIC_POS;
@@ -3178,9 +3111,8 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
if (res_ndigits <= 0)
res_ndigits = 1;
/* ----------
/*
* Now result zero check
* ----------
*/
if (var1->ndigits == 0)
{
@@ -3189,17 +3121,15 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
return;
}
/* ----------
/*
* Initialize local variables
* ----------
*/
init_var(&dividend);
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;
@@ -3209,9 +3139,8 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
divisor[1].digits[0] = 0;
memcpy(&(divisor[1].digits[1]), var2->digits, ndigits_tmp - 1);
/* ----------
/*
* Make a copy of the dividend
* ----------
*/
dividend.ndigits = var1->ndigits;
dividend.weight = 0;
@@ -3221,9 +3150,8 @@ div_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
dividend.digits = dividend.buf;
memcpy(dividend.digits, var1->digits, var1->ndigits);
/* ----------
/*
* Setup the result
* ----------
*/
digitbuf_free(result->buf);
result->buf = digitbuf_alloc(res_ndigits + 2);
@@ -3356,7 +3284,7 @@ mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result)
init_var(&tmp);
/* ----------
/* ---------
* We do this using the equation
* mod(x,y) = x - trunc(x/y)*y
* We fiddle a bit with global_rscale to control result precision.
@@ -3470,9 +3398,8 @@ sqrt_var(NumericVar *arg, NumericVar *result)
set_var_from_var(arg, &tmp_arg);
set_var_from_var(result, &last_val);
/* ----------
/*
* Initialize the result to the first guess
* ----------
*/
digitbuf_free(result->buf);
result->buf = digitbuf_alloc(1);

View File

@@ -1,7 +1,7 @@
/* ----------
* pg_lzcompress.c -
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.10 2001/03/22 03:59:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.11 2001/03/22 06:16:17 momjian Exp $
*
* This is an implementation of LZ compression for PostgreSQL.
* It uses a simple history table and generates 2-3 byte tags
@@ -383,36 +383,33 @@ pglz_find_match(PGLZ_HistEntry **hstart, char *input, char *end,
char *ip;
char *hp;
/* ----------
* Traverse the linked history list until a good enough
* match is found.
* ----------
/*
* Traverse the linked history list until a good enough match is
* found.
*/
hent = hstart[pglz_hist_idx(input, end)];
while (hent && len < good_match)
{
/* ----------
/*
* Be happy with lesser good matches the more entries we visited.
* ----------
*/
good_match -= (good_match * good_drop) / 100;
/* ----------
/*
* Stop if the offset does not fit into our tag anymore.
* ----------
*/
thisoff = (ip = input) - (hp = hent->pos);
if (thisoff >= 0x0fff)
break;
/* ----------
/*
* Determine length of match. A better match must be larger than
* the best so far. And if we already have a match of 16 or more
* bytes, it's worth the call overhead to use memcmp() to check
* if this match is equal for the same size. After that we must
* bytes, it's worth the call overhead to use memcmp() to check if
* this match is equal for the same size. After that we must
* fallback to character by character comparision to know the
* exact position where the diff occured.
* ----------
*/
if (len >= 16)
{
@@ -434,9 +431,8 @@ pglz_find_match(PGLZ_HistEntry **hstart, char *input, char *end,
hp++;
}
/* ----------
/*
* Remember this match as the best (if it is)
* ----------
*/
if (thislen > len)
{
@@ -444,17 +440,15 @@ pglz_find_match(PGLZ_HistEntry **hstart, char *input, char *end,
off = thisoff;
}
/* ----------
/*
* Advance to the next history entry
* ----------
*/
hent = hent->next;
}
/* ----------
* Return match information only if it results at least in one
* byte reduction.
* ----------
/*
* Return match information only if it results at least in one byte
* reduction.
*/
if (len > 2)
{
@@ -495,23 +489,20 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
int32 result_max;
int32 need_rate;
/* ----------
/*
* Our fallback strategy is the default.
* ----------
*/
if (strategy == NULL)
strategy = PGLZ_strategy_default;
/* ----------
/*
* Save the original source size in the header.
* ----------
*/
dest->rawsize = slen;
/* ----------
/*
* If the strategy forbids compression (at all or if source chunk too
* small), copy input to output without compression.
* ----------
*/
if (strategy->match_size_good == 0)
{
@@ -527,9 +518,8 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
}
}
/* ----------
/*
* Limit the match size to the maximum implementation allowed value
* ----------
*/
if ((good_match = strategy->match_size_good) > PGLZ_MAX_MATCH)
good_match = PGLZ_MAX_MATCH;
@@ -541,22 +531,19 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
if (good_drop > 100)
good_drop = 100;
/* ----------
/*
* Initialize the history tables. For inputs smaller than
* PGLZ_HISTORY_SIZE, we already have a big enough history
* table on the stack frame.
* ----------
* PGLZ_HISTORY_SIZE, we already have a big enough history table on
* the stack frame.
*/
memset((void *) hist_start, 0, sizeof(hist_start));
memset((void *) hist_entries, 0, sizeof(hist_entries));
/* ----------
* Compute the maximum result size allowed by the strategy.
* If the input size exceeds force_input_size, the max result size
* is the input size itself.
* Otherwise, it is the input size minus the minimum wanted
* compression rate.
* ----------
/*
* Compute the maximum result size allowed by the strategy. If the
* input size exceeds force_input_size, the max result size is the
* input size itself. Otherwise, it is the input size minus the
* minimum wanted compression rate.
*/
if (slen >= strategy->force_input_size)
result_max = slen;
@@ -570,16 +557,15 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
result_max = slen - ((slen * need_rate) / 100);
}
/* ----------
/*
* Compress the source directly into the output buffer.
* ----------
*/
while (dp < dend)
{
/* ----------
* If we already exceeded the maximum result size, set no compression
* flag and stop this. But don't check too often.
* ----------
/*
* If we already exceeded the maximum result size, set no
* compression flag and stop this. But don't check too often.
*/
if (bp - bstart >= result_max)
{
@@ -587,17 +573,16 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
break;
}
/* ----------
/*
* Try to find a match in the history
* ----------
*/
if (pglz_find_match(hist_start, dp, dend, &match_len,
&match_off, good_match, good_drop))
{
/* ----------
* Create the tag and add history entries for
* all matched characters.
* ----------
/*
* Create the tag and add history entries for all matched
* characters.
*/
pglz_out_tag(ctrlp, ctrlb, ctrl, bp, match_len, match_off);
while (match_len--)
@@ -609,9 +594,9 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
}
else
{
/* ----------
/*
* No match found. Copy one literal byte.
* ----------
*/
pglz_out_literal(ctrlp, ctrlb, ctrl, bp, *dp);
pglz_hist_add(hist_start, hist_entries, hist_next, dp, dend);
@@ -620,11 +605,10 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
}
}
/* ----------
* If we are still in compressing mode, write out the last
* control byte and determine if the compression gained the
* rate requested by the strategy.
* ----------
/*
* If we are still in compressing mode, write out the last control
* byte and determine if the compression gained the rate requested by
* the strategy.
*/
if (do_compress)
{
@@ -635,12 +619,10 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
do_compress = 0;
}
/* ----------
* Done - if we successfully compressed and matched the
* strategy's constraints, return the compressed result.
* Otherwise copy the original source over it and return
* the original length.
* ----------
/*
* Done - if we successfully compressed and matched the strategy's
* constraints, return the compressed result. Otherwise copy the
* original source over it and return the original length.
*/
if (do_compress)
{
@@ -685,22 +667,22 @@ pglz_decompress(PGLZ_Header *source, char *dest)
while (dp < dend)
{
/* ----------
/*
* Read one control byte and process the next 8 items.
* ----------
*/
ctrl = *dp++;
for (ctrlc = 0; ctrlc < 8 && dp < dend; ctrlc++)
{
if (ctrl & 1)
{
/* ----------
* Otherwise it contains the match length minus 3
* and the upper 4 bits of the offset. The next following
* byte contains the lower 8 bits of the offset. If
* the length is coded as 18, another extension tag byte
* tells how much longer the match really was (0-255).
* ----------
/*
* Otherwise it contains the match length minus 3 and the
* upper 4 bits of the offset. The next following byte
* contains the lower 8 bits of the offset. If the length
* is coded as 18, another extension tag byte tells how
* much longer the match really was (0-255).
*/
len = (dp[0] & 0x0f) + 3;
off = ((dp[0] & 0xf0) << 4) | dp[1];
@@ -708,12 +690,11 @@ pglz_decompress(PGLZ_Header *source, char *dest)
if (len == 18)
len += *dp++;
/* ----------
* Now we copy the bytes specified by the tag from
* OUTPUT to OUTPUT. It is dangerous and platform
* dependant to use memcpy() here, because the copied
* areas could overlap extremely!
* ----------
/*
* Now we copy the bytes specified by the tag from OUTPUT
* to OUTPUT. It is dangerous and platform dependant to
* use memcpy() here, because the copied areas could
* overlap extremely!
*/
while (len--)
{
@@ -723,25 +704,23 @@ pglz_decompress(PGLZ_Header *source, char *dest)
}
else
{
/* ----------
* An unset control bit means LITERAL BYTE. So we
* just copy one from INPUT to OUTPUT.
* ----------
/*
* An unset control bit means LITERAL BYTE. So we just
* copy one from INPUT to OUTPUT.
*/
*bp++ = *dp++;
}
/* ----------
/*
* Advance the control bit
* ----------
*/
ctrl >>= 1;
}
}
/* ----------
/*
* That's it.
* ----------
*/
return (char *) bp - dest;
}
@@ -761,11 +740,10 @@ pglz_get_next_decomp_char_from_lzdata(PGLZ_DecompState *dstate)
if (dstate->tocopy > 0)
{
/* ----------
* Copy one byte from output to output until we did it
* for the length specified by the last tag. Return that
* byte.
* ----------
/*
* Copy one byte from output to output until we did it for the
* length specified by the last tag. Return that byte.
*/
dstate->tocopy--;
return (*(dstate->cp_out++) = *(dstate->cp_copy++));
@@ -773,25 +751,24 @@ pglz_get_next_decomp_char_from_lzdata(PGLZ_DecompState *dstate)
if (dstate->ctrl_count == 0)
{
/* ----------
* Get the next control byte if we need to, but check
* for EOF before.
* ----------
/*
* Get the next control byte if we need to, but check for EOF
* before.
*/
if (dstate->cp_in == dstate->cp_end)
return EOF;
/* ----------
* This decompression method saves time only, if we stop near
* the beginning of the data (maybe because we're called by a
/*
* This decompression method saves time only, if we stop near the
* beginning of the data (maybe because we're called by a
* comparision function and a difference occurs early). Otherwise,
* all the checks, needed here, cause too much overhead.
*
* Thus we decompress the entire rest at once into the temporary
* buffer and change the decomp state to return the prepared
* data from the buffer by the more simple calls to
* buffer and change the decomp state to return the prepared data
* from the buffer by the more simple calls to
* pglz_get_next_decomp_char_from_plain().
* ----------
*/
if (dstate->cp_out - dstate->temp_buf >= 256)
{
@@ -838,32 +815,29 @@ pglz_get_next_decomp_char_from_lzdata(PGLZ_DecompState *dstate)
return (int) (*(dstate->cp_in++));
}
/* ----------
/*
* Not yet, get next control byte into decomp state.
* ----------
*/
dstate->ctrl = (unsigned char) (*(dstate->cp_in++));
dstate->ctrl_count = 8;
}
/* ----------
/*
* Check for EOF in tag/literal byte data.
* ----------
*/
if (dstate->cp_in == dstate->cp_end)
return EOF;
/* ----------
/*
* Handle next control bit.
* ----------
*/
dstate->ctrl_count--;
if (dstate->ctrl & 0x01)
{
/* ----------
* Bit is set, so tag is following. Setup copy information
* and do the copy for the first byte as above.
* ----------
/*
* Bit is set, so tag is following. Setup copy information and do
* the copy for the first byte as above.
*/
int off;
@@ -879,9 +853,9 @@ pglz_get_next_decomp_char_from_lzdata(PGLZ_DecompState *dstate)
}
else
{
/* ----------
/*
* Bit is unset, so literal byte follows.
* ----------
*/
retval = (int) (*(dstate->cp_out++) = *(dstate->cp_in++));
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.74 2001/03/22 03:59:53 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.75 2001/03/22 06:16:18 momjian Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -163,24 +163,21 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
StringInfoData buf;
int len;
/* ----------
/*
* We need the rules name somewhere deep down: rulename is global
* ----------
*/
rulename = pstrdup(NameStr(*rname));
/* ----------
/*
* Connect to SPI manager
* ----------
*/
if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "get_ruledef: cannot connect to SPI manager");
/* ----------
* On the first call prepare the plan to lookup pg_proc.
* We read pg_proc over the SPI manager instead of using
* the syscache to be checked for read access on pg_proc.
* ----------
/*
* On the first call prepare the plan to lookup pg_proc. We read
* pg_proc over the SPI manager instead of using the syscache to be
* checked for read access on pg_proc.
*/
if (plan_getrule == NULL)
{
@@ -194,9 +191,8 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
plan_getrule = SPI_saveplan(plan);
}
/* ----------
/*
* Get the pg_rewrite tuple for this rule
* ----------
*/
args[0] = PointerGetDatum(rulename);
nulls[0] = (rulename == NULL) ? 'n' : ' ';
@@ -217,9 +213,8 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
ruletup = SPI_tuptable->vals[0];
rulettc = SPI_tuptable->tupdesc;
/* ----------
/*
* Get the rules definition and put it into executors memory
* ----------
*/
initStringInfo(&buf);
make_ruledef(&buf, ruletup, rulettc);
@@ -229,16 +224,14 @@ pg_get_ruledef(PG_FUNCTION_ARGS)
memcpy(VARDATA(ruledef), buf.data, buf.len);
pfree(buf.data);
/* ----------
/*
* Disconnect from SPI manager
* ----------
*/
if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_ruledef: SPI_finish() failed");
/* ----------
/*
* Easy - isn't it?
* ----------
*/
PG_RETURN_TEXT_P(ruledef);
}
@@ -263,24 +256,21 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
int len;
char *name;
/* ----------
/*
* We need the view name somewhere deep down
* ----------
*/
rulename = pstrdup(NameStr(*vname));
/* ----------
/*
* Connect to SPI manager
* ----------
*/
if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "get_viewdef: cannot connect to SPI manager");
/* ----------
* On the first call prepare the plan to lookup pg_proc.
* We read pg_proc over the SPI manager instead of using
* the syscache to be checked for read access on pg_proc.
* ----------
/*
* On the first call prepare the plan to lookup pg_proc. We read
* pg_proc over the SPI manager instead of using the syscache to be
* checked for read access on pg_proc.
*/
if (plan_getview == NULL)
{
@@ -294,9 +284,9 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
plan_getview = SPI_saveplan(plan);
}
/* ----------
* Get the pg_rewrite tuple for this rule: rulename is actually viewname here
* ----------
/*
* Get the pg_rewrite tuple for this rule: rulename is actually
* viewname here
*/
name = MakeRetrieveViewRuleName(rulename);
args[0] = PointerGetDatum(name);
@@ -309,9 +299,9 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
appendStringInfo(&buf, "Not a view");
else
{
/* ----------
/*
* Get the rules definition and put it into executors memory
* ----------
*/
ruletup = SPI_tuptable->vals[0];
rulettc = SPI_tuptable->tupdesc;
@@ -324,16 +314,14 @@ pg_get_viewdef(PG_FUNCTION_ARGS)
pfree(buf.data);
pfree(name);
/* ----------
/*
* Disconnect from SPI manager
* ----------
*/
if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_viewdef: SPI_finish() failed");
/* ----------
/*
* Easy - isn't it?
* ----------
*/
PG_RETURN_TEXT_P(ruledef);
}
@@ -366,17 +354,14 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
StringInfoData keybuf;
char *sep;
/* ----------
/*
* Connect to SPI manager
* ----------
*/
if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "get_indexdef: cannot connect to SPI manager");
/* ----------
* On the first call prepare the plans to lookup pg_am
* and pg_opclass.
* ----------
/*
* On the first call prepare the plans to lookup pg_am and pg_opclass.
*/
if (plan_getam == NULL)
{
@@ -396,9 +381,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
plan_getopclass = SPI_saveplan(plan);
}
/* ----------
/*
* Fetch the pg_index tuple by the Oid of the index
* ----------
*/
ht_idx = SearchSysCache(INDEXRELID,
ObjectIdGetDatum(indexrelid),
@@ -407,9 +391,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
elog(ERROR, "syscache lookup for index %u failed", indexrelid);
idxrec = (Form_pg_index) GETSTRUCT(ht_idx);
/* ----------
/*
* Fetch the pg_class tuple of the index relation
* ----------
*/
ht_idxrel = SearchSysCache(RELOID,
ObjectIdGetDatum(idxrec->indexrelid),
@@ -418,9 +401,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
elog(ERROR, "syscache lookup for relid %u failed", idxrec->indexrelid);
idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel);
/* ----------
/*
* Fetch the pg_class tuple of the indexed relation
* ----------
*/
ht_indrel = SearchSysCache(RELOID,
ObjectIdGetDatum(idxrec->indrelid),
@@ -429,9 +411,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
elog(ERROR, "syscache lookup for relid %u failed", idxrec->indrelid);
indrelrec = (Form_pg_class) GETSTRUCT(ht_indrel);
/* ----------
/*
* Get the am name for the index relation
* ----------
*/
spi_args[0] = ObjectIdGetDatum(idxrelrec->relam);
spi_nulls[0] = ' ';
@@ -447,9 +428,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
spi_ttc = SPI_tuptable->tupdesc;
spi_fno = SPI_fnumber(spi_ttc, "amname");
/* ----------
/*
* Start the index definition
* ----------
*/
initStringInfo(&buf);
appendStringInfo(&buf, "CREATE %sINDEX %s ON %s USING %s (",
@@ -459,9 +439,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
quote_identifier(SPI_getvalue(spi_tup, spi_ttc,
spi_fno)));
/* ----------
/*
* Collect the indexed attributes
* ----------
*/
initStringInfo(&keybuf);
sep = "";
@@ -473,17 +452,15 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
appendStringInfo(&keybuf, sep);
sep = ", ";
/* ----------
/*
* Add the indexed field name
* ----------
*/
appendStringInfo(&keybuf, "%s",
quote_identifier(get_relid_attribute_name(idxrec->indrelid,
idxrec->indkey[keyno])));
/* ----------
/*
* If not a functional index, add the operator class name
* ----------
*/
if (idxrec->indproc == InvalidOid)
{
@@ -504,9 +481,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
}
}
/* ----------
/*
* For functional index say 'func (attrs) opclass'
* ----------
*/
if (idxrec->indproc != InvalidOid)
{
@@ -541,21 +517,19 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
ReleaseSysCache(proctup);
}
else
/* ----------
/*
* For the others say 'attr opclass [, ...]'
* ----------
*/
appendStringInfo(&buf, "%s", keybuf.data);
/* ----------
/*
* Finish
* ----------
*/
appendStringInfo(&buf, ")");
/* ----------
/*
* Create the result in upper executor memory, and free objects
* ----------
*/
len = buf.len + VARHDRSZ;
indexdef = SPI_palloc(len);
@@ -568,9 +542,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
ReleaseSysCache(ht_idxrel);
ReleaseSysCache(ht_indrel);
/* ----------
/*
* Disconnect from SPI manager
* ----------
*/
if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_viewdef: SPI_finish() failed");
@@ -592,16 +565,14 @@ pg_get_userbyid(PG_FUNCTION_ARGS)
HeapTuple usertup;
Form_pg_shadow user_rec;
/* ----------
/*
* Allocate space for the result
* ----------
*/
result = (Name) palloc(NAMEDATALEN);
memset(NameStr(*result), 0, NAMEDATALEN);
/* ----------
/*
* Get the pg_shadow entry and print the result
* ----------
*/
usertup = SearchSysCache(SHADOWSYSID,
ObjectIdGetDatum(uid),
@@ -705,9 +676,8 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
int fno;
bool isnull;
/* ----------
/*
* Get the attribute values from the rules tuple
* ----------
*/
fno = SPI_fnumber(rulettc, "ev_type");
ev_type = (char) SPI_getbinval(ruletup, rulettc, fno, &isnull);
@@ -730,9 +700,8 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
actions = (List *) stringToNode(ev_action);
/* ----------
/*
* Build the rules definition text
* ----------
*/
appendStringInfo(buf, "CREATE RULE %s AS ON ",
quote_identifier(rulename));
@@ -852,9 +821,8 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
int fno;
bool isnull;
/* ----------
/*
* Get the attribute values from the rules tuple
* ----------
*/
fno = SPI_fnumber(rulettc, "ev_type");
ev_type = (char) SPI_getbinval(ruletup, rulettc, fno, &isnull);
@@ -961,11 +929,10 @@ get_select_query_def(Query *query, deparse_context *context)
char *sep;
List *l;
/* ----------
* If the Query node has a setOperations tree, then it's the top
* level of a UNION/INTERSECT/EXCEPT query; only the ORDER BY and
* LIMIT fields are interesting in the top query itself.
* ----------
/*
* If the Query node has a setOperations tree, then it's the top level
* of a UNION/INTERSECT/EXCEPT query; only the ORDER BY and LIMIT
* fields are interesting in the top query itself.
*/
if (query->setOperations)
{
@@ -1033,9 +1000,8 @@ get_basic_select_query(Query *query, deparse_context *context)
char *sep;
List *l;
/* ----------
/*
* Build up the query string - first we say SELECT
* ----------
*/
appendStringInfo(buf, "SELECT");
@@ -1230,10 +1196,9 @@ get_insert_query_def(Query *query, deparse_context *context)
char *sep;
List *l;
/* ----------
/*
* If it's an INSERT ... SELECT there will be a single subquery RTE
* for the SELECT.
* ----------
*/
foreach(l, query->rtable)
{
@@ -1245,9 +1210,8 @@ get_insert_query_def(Query *query, deparse_context *context)
select_rte = rte;
}
/* ----------
/*
* Start the query with INSERT INTO relname
* ----------
*/
rte = rt_fetch(query->resultRelation, query->rtable);
appendStringInfo(buf, "INSERT INTO %s",
@@ -1303,9 +1267,8 @@ get_update_query_def(Query *query, deparse_context *context)
RangeTblEntry *rte;
List *l;
/* ----------
/*
* Start the query with UPDATE relname SET
* ----------
*/
rte = rt_fetch(query->resultRelation, query->rtable);
appendStringInfo(buf, "UPDATE %s%s SET ",
@@ -1357,9 +1320,8 @@ get_delete_query_def(Query *query, deparse_context *context)
StringInfo buf = context->buf;
RangeTblEntry *rte;
/* ----------
/*
* Start the query with DELETE FROM relname
* ----------
*/
rte = rt_fetch(query->resultRelation, query->rtable);
appendStringInfo(buf, "DELETE FROM %s%s",
@@ -1681,14 +1643,13 @@ get_rule_expr(Node *node, deparse_context *context)
if (node == NULL)
return;
/* ----------
/*
* Each level of get_rule_expr must emit an indivisible term
* (parenthesized if necessary) to ensure result is reparsed into
* the same expression tree.
* (parenthesized if necessary) to ensure result is reparsed into the
* same expression tree.
*
* There might be some work left here to support additional node types.
* Can we ever see Param nodes here?
* ----------
*/
switch (nodeTag(node))
{
@@ -1722,9 +1683,8 @@ get_rule_expr(Node *node, deparse_context *context)
Expr *expr = (Expr *) node;
List *args = expr->args;
/* ----------
/*
* Expr nodes have to be handled a bit detailed
* ----------
*/
switch (expr->opType)
{