diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/array/array_iterator.c | 58 | ||||
-rw-r--r-- | contrib/array/array_iterator.h | 13 | ||||
-rw-r--r-- | contrib/bit/varbit.c | 1365 | ||||
-rw-r--r-- | contrib/bit/varbit.h | 46 | ||||
-rw-r--r-- | contrib/bit/varbit_glue.c | 18 | ||||
-rw-r--r-- | contrib/bit/vartest.c | 322 | ||||
-rw-r--r-- | contrib/datetime/datetime_functions.c | 20 | ||||
-rw-r--r-- | contrib/datetime/datetime_functions.h | 6 | ||||
-rw-r--r-- | contrib/miscutil/misc_utils.c | 23 | ||||
-rw-r--r-- | contrib/miscutil/misc_utils.h | 8 | ||||
-rw-r--r-- | contrib/os2client/config.h | 2 | ||||
-rw-r--r-- | contrib/pgbench/pgbench.c | 1363 | ||||
-rw-r--r-- | contrib/string/string_io.c | 15 | ||||
-rw-r--r-- | contrib/string/string_io.h | 23 | ||||
-rw-r--r-- | contrib/userlock/user_locks.c | 6 | ||||
-rw-r--r-- | contrib/userlock/user_locks.h | 6 |
16 files changed, 1730 insertions, 1564 deletions
diff --git a/contrib/array/array_iterator.c b/contrib/array/array_iterator.c index cadda58a8f4..aa8697fb037 100644 --- a/contrib/array/array_iterator.c +++ b/contrib/array/array_iterator.c @@ -144,7 +144,7 @@ array_texteq(ArrayType *array, char *value) { return array_iterator((Oid) 25, /* text */ (Oid) 67, /* texteq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -153,7 +153,7 @@ array_all_texteq(ArrayType *array, char *value) { return array_iterator((Oid) 25, /* text */ (Oid) 67, /* texteq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -162,7 +162,7 @@ array_textregexeq(ArrayType *array, char *value) { return array_iterator((Oid) 25, /* text */ (Oid) 1254, /* textregexeq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -171,7 +171,7 @@ array_all_textregexeq(ArrayType *array, char *value) { return array_iterator((Oid) 25, /* text */ (Oid) 1254, /* textregexeq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -185,7 +185,7 @@ array_varchareq(ArrayType *array, char *value) { return array_iterator((Oid) 1043, /* varchar */ (Oid) 1070, /* varchareq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -194,7 +194,7 @@ array_all_varchareq(ArrayType *array, char *value) { return array_iterator((Oid) 1043, /* varchar */ (Oid) 1070, /* varchareq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -203,7 +203,7 @@ array_varcharregexeq(ArrayType *array, char *value) { return array_iterator((Oid) 1043, /* varchar */ (Oid) 1254, /* textregexeq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -212,7 +212,7 @@ array_all_varcharregexeq(ArrayType *array, char *value) { return array_iterator((Oid) 1043, /* varchar */ (Oid) 1254, /* textregexeq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -226,7 +226,7 @@ array_bpchareq(ArrayType *array, char *value) { return array_iterator((Oid) 1042, /* bpchar */ (Oid) 1048, /* bpchareq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -235,7 +235,7 @@ array_all_bpchareq(ArrayType *array, char *value) { return array_iterator((Oid) 1042, /* bpchar */ (Oid) 1048, /* bpchareq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -244,7 +244,7 @@ array_bpcharregexeq(ArrayType *array, char *value) { return array_iterator((Oid) 1042, /* bpchar */ (Oid) 1254, /* textregexeq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -253,7 +253,7 @@ array_all_bpcharregexeq(ArrayType *array, char *value) { return array_iterator((Oid) 1042, /* bpchar */ (Oid) 1254, /* textregexeq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -266,7 +266,7 @@ array_int4eq(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 65, /* int4eq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -275,7 +275,7 @@ array_all_int4eq(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 65, /* int4eq */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -284,7 +284,7 @@ array_int4ne(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 144, /* int4ne */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -293,7 +293,7 @@ array_all_int4ne(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 144, /* int4ne */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -302,7 +302,7 @@ array_int4gt(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 147, /* int4gt */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -311,7 +311,7 @@ array_all_int4gt(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 147, /* int4gt */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -320,7 +320,7 @@ array_int4ge(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 150, /* int4ge */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -329,7 +329,7 @@ array_all_int4ge(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 150, /* int4ge */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -338,7 +338,7 @@ array_int4lt(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 66, /* int4lt */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -347,7 +347,7 @@ array_all_int4lt(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 66, /* int4lt */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -356,7 +356,7 @@ array_int4le(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 149, /* int4le */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -365,7 +365,7 @@ array_all_int4le(ArrayType *array, int4 value) { return array_iterator((Oid) 23, /* int4 */ (Oid) 149, /* int4le */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -376,7 +376,7 @@ array_oideq(ArrayType *array, Oid value) { return array_iterator((Oid) 26, /* oid */ (Oid) 184, /* oideq */ - 0, /* logical or */ + 0, /* logical or */ array, (Datum) value); } @@ -385,7 +385,7 @@ array_all_oidne(ArrayType *array, Oid value) { return array_iterator((Oid) 26, /* int4 */ (Oid) 185, /* oidne */ - 1, /* logical and */ + 1, /* logical and */ array, (Datum) value); } @@ -393,8 +393,8 @@ array_all_oidne(ArrayType *array, Oid value) /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/array/array_iterator.h b/contrib/array/array_iterator.h index 9a386abd2c7..68da385c9a4 100644 --- a/contrib/array/array_iterator.h +++ b/contrib/array/array_iterator.h @@ -2,7 +2,7 @@ #define ARRAY_ITERATOR_H static int32 array_iterator(Oid elemtype, Oid proc, int and, - ArrayType *array, Datum value); + ArrayType *array, Datum value); int32 array_texteq(ArrayType *array, char *value); int32 array_all_texteq(ArrayType *array, char *value); @@ -32,14 +32,15 @@ int32 array_all_int4lt(ArrayType *array, int4 value); int32 array_int4le(ArrayType *array, int4 value); int32 array_all_int4le(ArrayType *array, int4 value); -int32 array_oideq(ArrayType *array, Oid value); -int32 array_all_oidne(ArrayType *array, Oid value); +int32 array_oideq(ArrayType *array, Oid value); +int32 array_all_oidne(ArrayType *array, Oid value); + #endif /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/bit/varbit.c b/contrib/bit/varbit.c index 2a677ec6040..20caaf9f7cb 100644 --- a/contrib/bit/varbit.c +++ b/contrib/bit/varbit.c @@ -4,7 +4,7 @@ * Functions for the built-in type bit() and varying bit(). * * IDENTIFICATION - * $Header: /cvsroot/pgsql/contrib/bit/Attic/varbit.c,v 1.2 2000/04/03 20:56:40 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/bit/Attic/varbit.c,v 1.3 2000/04/12 17:14:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -14,19 +14,19 @@ /*#include "utils/builtins.h" */ -/* +/* Prefixes: - zp -- zero-padded fixed length bit string - var -- varying bit string + zp -- zero-padded fixed length bit string + var -- varying bit string attypmod -- contains the length of the bit string in bits, or for - varying bits the maximum length. + varying bits the maximum length. The data structure contains the following elements: - header -- length of the whole data structure (incl header) - in bytes. (as with all varying length datatypes) - data section -- private data section for the bits data structures - bitlength -- lenght of the bit string in bits + header -- length of the whole data structure (incl header) + in bytes. (as with all varying length datatypes) + data section -- private data section for the bits data structures + bitlength -- lenght of the bit string in bits bitdata -- least significant byte first string */ @@ -34,214 +34,241 @@ * zpbitin - * converts a string to the internal representation of a bitstring. - * The length is determined by the number of bits required plus - * VARHDRSZ bytes or from atttypmod. - * (XXX dummy is here because we pass typelem as the second argument - * for array_in. copied this, no idea what it means??) + * The length is determined by the number of bits required plus + * VARHDRSZ bytes or from atttypmod. + * (XXX dummy is here because we pass typelem as the second argument + * for array_in. copied this, no idea what it means??) */ bits8 * -zpbitin(char *s, int dummy, int32 atttypmod) +zpbitin(char *s, int dummy, int32 atttypmod) { - bits8 *result; /* the bits string that was read in */ - char *sp; /* pointer into the character string */ - bits8 *r; - int len, /* Length of the whole data structure */ - bitlen, /* Number of bits in the bit string */ - slen; /* Length of the input string */ - int bit_not_hex = 0; /* 0 = hex string 1=bit string */ - int bc, ipad; - bits8 x = 0; - - - if (s == NULL) - return (bits8 *) NULL; - - /* Check that the first character is a b or an x */ - if (s[0]=='b' || s[0]=='B') - bit_not_hex = 1; - else if (s[0]=='x' || s[0]=='X') - bit_not_hex = 0; - else - elog(ERROR, "zpbitin: %s is not a valid bitstring",s); - - slen = strlen(s) - 1; - /* Determine bitlength from input string */ - bitlen = slen; - if (!bit_not_hex) - bitlen *= 4; - - /* Sometimes atttypmod is not supplied. If it is supplied we need to make - sure that the bitstring fits. Note that the number of infered bits can - be larger than the number of actual bits needed, but only if we are - reading a hex string and not by more than 3 bits, as a hex string gives - and accurate length upto 4 bits */ - if (atttypmod == -1) - atttypmod = bitlen; - else - if ((bitlen>atttypmod && bit_not_hex) || - (bitlen>atttypmod+3 && !bit_not_hex)) - elog(ERROR, "zpbitin: bit string of size %d cannot be written into bits(%d)", - bitlen,atttypmod); - - - len = VARBITDATALEN(atttypmod); - - if (len > MaxAttrSize) - elog(ERROR, "zpbitin: length of bit() must be less than %ld", - (MaxAttrSize-VARHDRSZ-VARBITHDRSZ)*BITSPERBYTE); - - result = (bits8 *) palloc(len); - /* set to 0 so that *r is always initialised and strin is zero-padded */ - memset(result, 0, len); - VARSIZE(result) = len; - VARBITLEN(result) = atttypmod; - - /* We need to read the bitstring from the end, as we store it least - significant byte first. s points to the byte before the beginning - of the bitstring */ - sp = s+1; - r = VARBITS(result); - if (bit_not_hex) - { - /* Parse the bit representation of the string */ - /* We know it fits, as bitlen was compared to atttypmod */ - x = BITHIGH; - for (bc = 0; sp != s+slen+1; sp++, bc++) + bits8 *result; /* the bits string that was read in */ + char *sp; /* pointer into the character string */ + bits8 *r; + int len, /* Length of the whole data structure */ + bitlen, /* Number of bits in the bit string */ + slen; /* Length of the input string */ + int bit_not_hex = 0;/* 0 = hex string 1=bit string */ + int bc, + ipad; + bits8 x = 0; + + + if (s == NULL) + return (bits8 *) NULL; + + /* Check that the first character is a b or an x */ + if (s[0] == 'b' || s[0] == 'B') + bit_not_hex = 1; + else if (s[0] == 'x' || s[0] == 'X') + bit_not_hex = 0; + else + elog(ERROR, "zpbitin: %s is not a valid bitstring", s); + + slen = strlen(s) - 1; + /* Determine bitlength from input string */ + bitlen = slen; + if (!bit_not_hex) + bitlen *= 4; + + /* + * Sometimes atttypmod is not supplied. If it is supplied we need to + * make sure that the bitstring fits. Note that the number of infered + * bits can be larger than the number of actual bits needed, but only + * if we are reading a hex string and not by more than 3 bits, as a + * hex string gives and accurate length upto 4 bits + */ + if (atttypmod == -1) + atttypmod = bitlen; + else if ((bitlen > atttypmod && bit_not_hex) || + (bitlen > atttypmod + 3 && !bit_not_hex)) + elog(ERROR, "zpbitin: bit string of size %d cannot be written into bits(%d)", + bitlen, atttypmod); + + + len = VARBITDATALEN(atttypmod); + + if (len > MaxAttrSize) + elog(ERROR, "zpbitin: length of bit() must be less than %ld", + (MaxAttrSize - VARHDRSZ - VARBITHDRSZ) * BITSPERBYTE); + + result = (bits8 *) palloc(len); + /* set to 0 so that *r is always initialised and strin is zero-padded */ + memset(result, 0, len); + VARSIZE(result) = len; + VARBITLEN(result) = atttypmod; + + /* + * We need to read the bitstring from the end, as we store it least + * significant byte first. s points to the byte before the beginning + * of the bitstring + */ + sp = s + 1; + r = VARBITS(result); + if (bit_not_hex) + { + /* Parse the bit representation of the string */ + /* We know it fits, as bitlen was compared to atttypmod */ + x = BITHIGH; + for (bc = 0; sp != s + slen + 1; sp++, bc++) + { + if (*sp == '1') + *r |= x; + if (bc == 7) + { + bc = 0; + x = BITHIGH; + r++; + } + else + x >>= 1; + } + } + else { - if (*sp=='1') - *r |= x; - if (bc==7) { - bc = 0; - x = BITHIGH; - r++; - } else - x >>= 1; + /* Parse the hex representation of the string */ + for (bc = 0; sp != s + slen + 1; sp++) + { + if (*sp >= '0' && *sp <= '9') + x = (bits8) (*sp - '0'); + else if (*sp >= 'A' && *sp <= 'F') + x = (bits8) (*sp - 'A') + 10; + else if (*sp >= 'a' && *sp <= 'f') + x = (bits8) (*sp - 'a') + 10; + else + elog(ERROR, "Cannot parse %c as a hex digit", *sp); + if (bc) + { + bc = 0; + *r++ |= x; + } + else + { + bc++; + *r = x << 4; + } + } } - } - else - { - /* Parse the hex representation of the string */ - for (bc = 0; sp != s+slen+1; sp++) + + if (bitlen > atttypmod) { - if (*sp>='0' && *sp<='9') - x = (bits8) (*sp - '0'); - else if (*sp>='A' && *sp<='F') - x = (bits8) (*sp - 'A') + 10; - else if (*sp>='a' && *sp<='f') - x = (bits8) (*sp - 'a') + 10; - else - elog(ERROR,"Cannot parse %c as a hex digit",*sp); - if (bc) { - bc = 0; - *r++ |= x; - } else { - bc++; - *r = x<<4; - } + /* Check that this fitted */ + r = (bits8 *) (result + len - 1); + ipad = VARBITPAD(result); + + /* + * The bottom ipad bits of the byte pointed to by r need to be + * zero + */ + + /* + * printf("Byte %X shift %X %d\n",*r,(*r << (8-ipad)) & BITMASK, + * (*r << (8-ipad)) & BITMASK > 0); + */ + if (((*r << (BITSPERBYTE - ipad)) & BITMASK) > 0) + elog(ERROR, "zpbitin: bit string too large for bit(%d) data type", + atttypmod); } - } - - if (bitlen > atttypmod) { - /* Check that this fitted */ - r = (bits8 *) (result + len - 1); - ipad = VARBITPAD(result); - /* The bottom ipad bits of the byte pointed to by r need to be zero */ - /* printf("Byte %X shift %X %d\n",*r,(*r << (8-ipad)) & BITMASK, - (*r << (8-ipad)) & BITMASK > 0); - */ - if (((*r << (BITSPERBYTE-ipad)) & BITMASK) > 0) - elog(ERROR, "zpbitin: bit string too large for bit(%d) data type", - atttypmod); - } - - return result; + + return result; } /* zpbitout - - * for the time being we print everything as hex strings, as this is likely - * to be more compact than bit strings, and consequently much more efficient - * for long strings + * for the time being we print everything as hex strings, as this is likely + * to be more compact than bit strings, and consequently much more efficient + * for long strings */ char * zpbitout(bits8 *s) { - char *result, *r; - bits8 *sp; - int i, len, bitlen; - - if (s == NULL) - { - result = (char *) palloc(2); - result[0] = '-'; - result[1] = '\0'; - } - else - { - bitlen = VARBITLEN(s); - len = bitlen/4 + (bitlen%4>0 ? 1 : 0); - result = (char *) palloc(len + 4); - sp = VARBITS(s); - r = result; - *r++ = 'X'; - *r++ = '\''; - /* we cheat by knowing that we store full bytes zero padded */ - for (i=0; i<len; i+=2, sp++) { - *r++ = HEXDIG((*sp)>>4); - *r++ = HEXDIG((*sp) & 0xF); - } - /* Go back one step if we printed a hex number that was not part - of the bitstring anymore */ - if (i==len+1) - r--; - *r++ = '\''; - *r = '\0'; - } - return result; + char *result, + *r; + bits8 *sp; + int i, + len, + bitlen; + + if (s == NULL) + { + result = (char *) palloc(2); + result[0] = '-'; + result[1] = '\0'; + } + else + { + bitlen = VARBITLEN(s); + len = bitlen / 4 + (bitlen % 4 > 0 ? 1 : 0); + result = (char *) palloc(len + 4); + sp = VARBITS(s); + r = result; + *r++ = 'X'; + *r++ = '\''; + /* we cheat by knowing that we store full bytes zero padded */ + for (i = 0; i < len; i += 2, sp++) + { + *r++ = HEXDIG((*sp) >> 4); + *r++ = HEXDIG((*sp) & 0xF); + } + + /* + * Go back one step if we printed a hex number that was not part + * of the bitstring anymore + */ + if (i == len + 1) + r--; + *r++ = '\''; + *r = '\0'; + } + return result; } /* zpbitsout - - * Prints the string a bits + * Prints the string a bits */ char * zpbitsout(bits8 *s) { - char *result, *r; - bits8 *sp; - bits8 x; - int i, k, len; - - if (s == NULL) - { - result = (char *) palloc(2); - result[0] = '-'; - result[1] = '\0'; - } - else - { - len = VARBITLEN(s); - result = (char *) palloc(len + 4); - sp = VARBITS(s); - r = result; - *r++ = 'B'; - *r++ = '\''; - for (i=0; i<len-BITSPERBYTE; i+=BITSPERBYTE, sp++) { - x = *sp; - for (k=0; k<BITSPERBYTE; k++) - { - *r++ = (x & BITHIGH) ? '1' : '0'; - x <<= 1; - } - } - x = *sp; - for (k=i; k<len; k++) + char *result, + *r; + bits8 *sp; + bits8 x; + int i, + k, + len; + + if (s == NULL) { - *r++ = (x & BITHIGH) ? '1' : '0'; - x <<= 1; + result = (char *) palloc(2); + result[0] = '-'; + result[1] = '\0'; } - *r++ = '\''; - *r = '\0'; - } - return result; + else + { + len = VARBITLEN(s); + result = (char *) palloc(len + 4); + sp = VARBITS(s); + r = result; + *r++ = 'B'; + *r++ = '\''; + for (i = 0; i < len - BITSPERBYTE; i += BITSPERBYTE, sp++) + { + x = *sp; + for (k = 0; k < BITSPERBYTE; k++) + { + *r++ = (x & BITHIGH) ? '1' : '0'; + x <<= 1; + } + } + x = *sp; + for (k = i; k < len; k++) + { + *r++ = (x & BITHIGH) ? '1' : '0'; + x <<= 1; + } + *r++ = '\''; + *r = '\0'; + } + return result; } @@ -250,118 +277,133 @@ zpbitsout(bits8 *s) * converts a string to the internal representation of a bitstring. */ bits8 * -varbitin(char *s, int dummy, int32 atttypmod) +varbitin(char *s, int dummy, int32 atttypmod) { - bits8 *result; /* The resulting bit string */ - char *sp; /* pointer into the character string */ - bits8 *r; - int len, /* Length of the whole data structure */ - bitlen, /* Number of bits in the bit string */ - slen; /* Length of the input string */ - int bit_not_hex = 0; - int bc, ipad; - bits8 x = 0; - - - if (s == NULL) - return (bits8 *) NULL; - - /* Check that the first character is a b or an x */ - if (s[0]=='b' || s[0]=='B') - bit_not_hex = 1; - else if (s[0]=='x' || s[0]=='X') - bit_not_hex = 0; - else - elog(ERROR, "zpbitin: %s is not a valid bitstring",s); - - slen = strlen(s) - 1; - /* Determine bitlength from input string */ - bitlen = slen; - if (!bit_not_hex) - bitlen *= 4; - - /* Sometimes atttypmod is not supplied. If it is supplied we need to make - sure that the bitstring fits. Note that the number of infered bits can - be larger than the number of actual bits needed, but only if we are - reading a hex string and not by more than 3 bits, as a hex string gives - and accurate length upto 4 bits */ - if (atttypmod > -1) - if ((bitlen>atttypmod && bit_not_hex) || - (bitlen>atttypmod+3 && !bit_not_hex)) - elog(ERROR, "varbitin: bit string of size %d cannot be written into varying bits(%d)", - bitlen,atttypmod); - - - len = VARBITDATALEN(bitlen); - - if (len > MaxAttrSize) - elog(ERROR, "varbitin: length of bit() must be less than %ld", - (MaxAttrSize-VARHDRSZ-VARBITHDRSZ)*BITSPERBYTE); - - result = (bits8 *) palloc(len); - /* set to 0 so that *r is always initialised and strin is zero-padded */ - memset(result, 0, len); - VARSIZE(result) = len; - VARBITLEN(result) = bitlen; - - /* We need to read the bitstring from the end, as we store it least - significant byte first. s points to the byte before the beginning - of the bitstring */ - sp = s + 1; - r = VARBITS(result); - if (bit_not_hex) - { - /* Parse the bit representation of the string */ - x = BITHIGH; - for (bc = 0; sp != s+slen+1; sp++, bc++) + bits8 *result; /* The resulting bit string */ + char *sp; /* pointer into the character string */ + bits8 *r; + int len, /* Length of the whole data structure */ + bitlen, /* Number of bits in the bit string */ + slen; /* Length of the input string */ + int bit_not_hex = 0; + int bc, + ipad; + bits8 x = 0; + + + if (s == NULL) + return (bits8 *) NULL; + + /* Check that the first character is a b or an x */ + if (s[0] == 'b' || s[0] == 'B') + bit_not_hex = 1; + else if (s[0] == 'x' || s[0] == 'X') + bit_not_hex = 0; + else + elog(ERROR, "zpbitin: %s is not a valid bitstring", s); + + slen = strlen(s) - 1; + /* Determine bitlength from input string */ + bitlen = slen; + if (!bit_not_hex) + bitlen *= 4; + + /* + * Sometimes atttypmod is not supplied. If it is supplied we need to + * make sure that the bitstring fits. Note that the number of infered + * bits can be larger than the number of actual bits needed, but only + * if we are reading a hex string and not by more than 3 bits, as a + * hex string gives and accurate length upto 4 bits + */ + if (atttypmod > -1) + if ((bitlen > atttypmod && bit_not_hex) || + (bitlen > atttypmod + 3 && !bit_not_hex)) + elog(ERROR, "varbitin: bit string of size %d cannot be written into varying bits(%d)", + bitlen, atttypmod); + + + len = VARBITDATALEN(bitlen); + + if (len > MaxAttrSize) + elog(ERROR, "varbitin: length of bit() must be less than %ld", + (MaxAttrSize - VARHDRSZ - VARBITHDRSZ) * BITSPERBYTE); + + result = (bits8 *) palloc(len); + /* set to 0 so that *r is always initialised and strin is zero-padded */ + memset(result, 0, len); + VARSIZE(result) = len; + VARBITLEN(result) = bitlen; + + /* + * We need to read the bitstring from the end, as we store it least + * significant byte first. s points to the byte before the beginning + * of the bitstring + */ + sp = s + 1; + r = VARBITS(result); + if (bit_not_hex) + { + /* Parse the bit representation of the string */ + x = BITHIGH; + for (bc = 0; sp != s + slen + 1; sp++, bc++) + { + if (*sp == '1') + *r |= x; + if (bc == 7) + { + bc = 0; + x = BITHIGH; + r++; + } + else + x >>= 1; + } + } + else { - if (*sp=='1') - *r |= x; - if (bc==7) { - bc = 0; - x = BITHIGH; - r++; - } else - x >>= 1; + for (bc = 0; sp != s + slen + 1; sp++) + { + if (*sp >= '0' && *sp <= '9') + x = (bits8) (*sp - '0'); + else if (*sp >= 'A' && *sp <= 'F') + x = (bits8) (*sp - 'A') + 10; + else if (*sp >= 'a' && *sp <= 'f') + x = (bits8) (*sp - 'a') + 10; + else + elog(ERROR, "Cannot parse %c as a hex digit", *sp); + if (bc) + { + bc = 0; + *r++ |= x; + } + else + { + bc++; + *r = x << 4; + } + } } - } - else - { - for (bc = 0; sp != s+slen+1; sp++) + + if (bitlen > atttypmod) { - if (*sp>='0' && *sp<='9') - x = (bits8) (*sp - '0'); - else if (*sp>='A' && *sp<='F') - x = (bits8) (*sp - 'A') + 10; - else if (*sp>='a' && *sp<='f') - x = (bits8) (*sp - 'a') + 10; - else - elog(ERROR,"Cannot parse %c as a hex digit",*sp); - if (bc) { - bc = 0; - *r++ |= x; - } else { - bc++; - *r = x<<4; - } + /* Check that this fitted */ + r = (bits8 *) (result + len - 1); + ipad = VARBITPAD(result); + + /* + * The bottom ipad bits of the byte pointed to by r need to be + * zero + */ + if (((*r << (BITSPERBYTE - ipad)) & BITMASK) > 0) + elog(ERROR, "varbitin: bit string too large for varying bit(%d) data type", + atttypmod); } - } - - if (bitlen > atttypmod) { - /* Check that this fitted */ - r = (bits8 *) (result + len - 1); - ipad = VARBITPAD(result); - /* The bottom ipad bits of the byte pointed to by r need to be zero */ - if (((*r << (BITSPERBYTE-ipad)) & BITMASK) > 0) - elog(ERROR, "varbitin: bit string too large for varying bit(%d) data type", - atttypmod); - } - - return result; + + return result; } /* - the zpbitout routines are fine for varying bits as well + the zpbitout routines are fine for varying bits as well */ @@ -369,228 +411,244 @@ varbitin(char *s, int dummy, int32 atttypmod) * Comparison operators * * We only need one set of comparison operators for bitstrings, as the lengths - * are stored in the same way for zero-padded and varying bit strings. + * are stored in the same way for zero-padded and varying bit strings. * - * Note that the standard is not unambiguous about the comparison between + * Note that the standard is not unambiguous about the comparison between * zero-padded bit strings and varying bitstrings. If the same value is written - * into a zero padded bitstring as into a varying bitstring, but the zero - * padded bitstring has greater length, it will be bigger. + * into a zero padded bitstring as into a varying bitstring, but the zero + * padded bitstring has greater length, it will be bigger. * * Zeros from the beginning of a bitstring cannot simply be ignored, as they * may be part of a bit string and may be significant. */ bool -biteq (bits8 *arg1, bits8 *arg2) +biteq(bits8 *arg1, bits8 *arg2) { - int bitlen1, - bitlen2; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return (bool) 0; - bitlen1 = VARBITLEN(arg1); - bitlen2 = VARBITLEN(arg2); - if (bitlen1 != bitlen2) - return (bool) 0; - - /* bit strings are always stored in a full number of bytes */ - return memcmp((void *)VARBITS(arg1),(void *)VARBITS(arg2), - VARBITBYTES(arg1)) == 0; + int bitlen1, + bitlen2; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return (bool) 0; + bitlen1 = VARBITLEN(arg1); + bitlen2 = VARBITLEN(arg2); + if (bitlen1 != bitlen2) + return (bool) 0; + + /* bit strings are always stored in a full number of bytes */ + return memcmp((void *) VARBITS(arg1), (void *) VARBITS(arg2), + VARBITBYTES(arg1)) == 0; } bool -bitne (bits8 *arg1, bits8 *arg2) +bitne(bits8 *arg1, bits8 *arg2) { - int bitlen1, - bitlen2; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return (bool) 0; - bitlen1 = VARBITLEN(arg1); - bitlen2 = VARBITLEN(arg2); - if (bitlen1 != bitlen2) - return (bool) 1; - - /* bit strings are always stored in a full number of bytes */ - return memcmp((void *)VARBITS(arg1),(void *)VARBITS(arg2), - VARBITBYTES(arg1)) != 0; + int bitlen1, + bitlen2; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return (bool) 0; + bitlen1 = VARBITLEN(arg1); + bitlen2 = VARBITLEN(arg2); + if (bitlen1 != bitlen2) + return (bool) 1; + + /* bit strings are always stored in a full number of bytes */ + return memcmp((void *) VARBITS(arg1), (void *) VARBITS(arg2), + VARBITBYTES(arg1)) != 0; } /* bitcmp - * + * * Compares two bitstrings and returns -1, 0, 1 depending on whether the first * string is smaller, equal, or bigger than the second. All bits are considered * and additional zero bits may make one string smaller/larger than the other, * even if their zero-padded values would be the same. - * Anything is equal to undefined. + * Anything is equal to undefined. */ -int -bitcmp (bits8 *arg1, bits8 *arg2) +int +bitcmp(bits8 *arg1, bits8 *arg2) { - int bitlen1, bytelen1, - bitlen2, bytelen2; - int cmp; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return (bool) 0; - bytelen1 = VARBITBYTES(arg1); - bytelen2 = VARBITBYTES(arg2); - - cmp = memcmp(VARBITS(arg1),VARBITS(arg2),Min(bytelen1,bytelen2)); - if (cmp==0) { - bitlen1 = VARBITLEN(arg1); - bitlen2 = VARBITLEN(arg2); - if (bitlen1 != bitlen2) - return bitlen1 < bitlen2 ? -1 : 1; - } - return cmp; + int bitlen1, + bytelen1, + bitlen2, + bytelen2; + int cmp; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return (bool) 0; + bytelen1 = VARBITBYTES(arg1); + bytelen2 = VARBITBYTES(arg2); + + cmp = memcmp(VARBITS(arg1), VARBITS(arg2), Min(bytelen1, bytelen2)); + if (cmp == 0) + { + bitlen1 = VARBITLEN(arg1); + bitlen2 = VARBITLEN(arg2); + if (bitlen1 != bitlen2) + return bitlen1 < bitlen2 ? -1 : 1; + } + return cmp; } bool -bitlt (bits8 *arg1, bits8 *arg2) +bitlt(bits8 *arg1, bits8 *arg2) { - return (bool) (bitcmp(arg1,arg2) == -1); + return (bool) (bitcmp(arg1, arg2) == -1); } bool -bitle (bits8 *arg1, bits8 *arg2) +bitle(bits8 *arg1, bits8 *arg2) { - return (bool) (bitcmp(arg1,arg2) <= 0); + return (bool) (bitcmp(arg1, arg2) <= 0); } bool -bitge (bits8 *arg1, bits8 *arg2) +bitge(bits8 *arg1, bits8 *arg2) { - return (bool) (bitcmp(arg1,arg2) >= 0); + return (bool) (bitcmp(arg1, arg2) >= 0); } bool -bitgt (bits8 *arg1, bits8 *arg2) +bitgt(bits8 *arg1, bits8 *arg2) { - return (bool) (bitcmp(arg1,arg2) == 1); + return (bool) (bitcmp(arg1, arg2) == 1); } /* bitcat * Concatenation of bit strings */ bits8 * -bitcat (bits8 *arg1, bits8 *arg2) +bitcat(bits8 *arg1, bits8 *arg2) { - int bitlen1, bitlen2, bytelen, bit1pad, bit2shift; - bits8 *result; - bits8 *pr, *pa; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return NULL; - - bitlen1 = VARBITLEN(arg1); - bitlen2 = VARBITLEN(arg2); - - bytelen = VARBITDATALEN(bitlen1+bitlen2); - - result = (bits8 *) palloc(bytelen*sizeof(bits8)); - VARSIZE(result) = bytelen; - VARBITLEN(result) = bitlen1+bitlen2; - printf("%d %d %d \n",VARBITBYTES(arg1),VARBITLEN(arg1),VARBITPAD(arg1)); - /* Copy the first bitstring in */ - memcpy(VARBITS(result),VARBITS(arg1),VARBITBYTES(arg1)); - /* Copy the second bit string */ - bit1pad = VARBITPAD(arg1); - if (bit1pad==0) - { - memcpy(VARBITS(result)+VARBITBYTES(arg1),VARBITS(arg2), - VARBITBYTES(arg2)); - } - else if (bitlen2>0) - { - /* We need to shift all the results to fit */ - bit2shift = BITSPERBYTE - bit1pad; - pa = VARBITS(arg2); - pr = VARBITS(result)+VARBITBYTES(arg1)-1; - for ( ; pa < VARBITEND(arg2); pa++) { - *pr |= ((*pa >> bit2shift) & BITMASK); - pr++; - if (pr < VARBITEND(result)) - *pr = (*pa << bit1pad) & BITMASK; - } - } - - return result; + int bitlen1, + bitlen2, + bytelen, + bit1pad, + bit2shift; + bits8 *result; + bits8 *pr, + *pa; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return NULL; + + bitlen1 = VARBITLEN(arg1); + bitlen2 = VARBITLEN(arg2); + + bytelen = VARBITDATALEN(bitlen1 + bitlen2); + + result = (bits8 *) palloc(bytelen * sizeof(bits8)); + VARSIZE(result) = bytelen; + VARBITLEN(result) = bitlen1 + bitlen2; + printf("%d %d %d \n", VARBITBYTES(arg1), VARBITLEN(arg1), VARBITPAD(arg1)); + /* Copy the first bitstring in */ + memcpy(VARBITS(result), VARBITS(arg1), VARBITBYTES(arg1)); + /* Copy the second bit string */ + bit1pad = VARBITPAD(arg1); + if (bit1pad == 0) + { + memcpy(VARBITS(result) + VARBITBYTES(arg1), VARBITS(arg2), + VARBITBYTES(arg2)); + } + else if (bitlen2 > 0) + { + /* We need to shift all the results to fit */ + bit2shift = BITSPERBYTE - bit1pad; + pa = VARBITS(arg2); + pr = VARBITS(result) + VARBITBYTES(arg1) - 1; + for (; pa < VARBITEND(arg2); pa++) + { + *pr |= ((*pa >> bit2shift) & BITMASK); + pr++; + if (pr < VARBITEND(result)) + *pr = (*pa << bit1pad) & BITMASK; + } + } + + return result; } /* bitsubstr - * retrieve a substring from the bit string. + * retrieve a substring from the bit string. * Note, s is 1-based. * SQL draft 6.10 9) */ -bits8 * -bitsubstr (bits8 *arg, int32 s, int32 l) +bits8 * +bitsubstr(bits8 *arg, int32 s, int32 l) { - int bitlen, - rbitlen, - len, - ipad = 0, - ishift, - i; - int e, s1, e1; - bits8 * result; - bits8 mask, *r, *ps; - - if (!PointerIsValid(arg)) - return NULL; - - bitlen = VARBITLEN(arg); - e = s+l; - s1 = Max(s,1); - e1 = Min(e,bitlen+1); - if (s1>bitlen || e1<1) - { - /* Need to return a null string */ - len = VARBITDATALEN(0); - result = (bits8 *) palloc(len); - VARBITLEN(result) = 0; - VARSIZE(result) = len; - } - else - { - /* OK, we've got a true substring starting at position s1-1 and - ending at position e1-1 */ - rbitlen = e1-s1; - len = VARBITDATALEN(rbitlen); - result = (bits8 *) palloc(len); - VARBITLEN(result) = rbitlen; - VARSIZE(result) = len; - len -= VARHDRSZ + VARBITHDRSZ; - /* Are we copying from a byte boundary? */ - if ((s1-1)%BITSPERBYTE==0) + int bitlen, + rbitlen, + len, + ipad = 0, + ishift, + i; + int e, + s1, + e1; + bits8 *result; + bits8 mask, + *r, + *ps; + + if (!PointerIsValid(arg)) + return NULL; + + bitlen = VARBITLEN(arg); + e = s + l; + s1 = Max(s, 1); + e1 = Min(e, bitlen + 1); + if (s1 > bitlen || e1 < 1) { - /* Yep, we are copying bytes */ - memcpy(VARBITS(result),VARBITS(arg)+(s1-1)/BITSPERBYTE,len); - } - else - { - /* Figure out how much we need to shift the sequence by */ - ishift = (s1-1)%BITSPERBYTE; - r = VARBITS(result); - ps = VARBITS(arg) + (s1-1)/BITSPERBYTE; - for (i=0; i<len; i++) - { - *r = (*ps <<ishift) & BITMASK; - if ((++ps) < VARBITEND(arg)) - *r |= *ps >>(BITSPERBYTE-ishift); - r++; - } + /* Need to return a null string */ + len = VARBITDATALEN(0); + result = (bits8 *) palloc(len); + VARBITLEN(result) = 0; + VARSIZE(result) = len; } - /* Do we need to pad at the end? */ - ipad = VARBITPAD(result); - if (ipad > 0) + else { - mask = BITMASK << ipad; - *(VARBITS(result) + len - 1) &= mask; + + /* + * OK, we've got a true substring starting at position s1-1 and + * ending at position e1-1 + */ + rbitlen = e1 - s1; + len = VARBITDATALEN(rbitlen); + result = (bits8 *) palloc(len); + VARBITLEN(result) = rbitlen; + VARSIZE(result) = len; + len -= VARHDRSZ + VARBITHDRSZ; + /* Are we copying from a byte boundary? */ + if ((s1 - 1) % BITSPERBYTE == 0) + { + /* Yep, we are copying bytes */ + memcpy(VARBITS(result), VARBITS(arg) + (s1 - 1) / BITSPERBYTE, len); + } + else + { + /* Figure out how much we need to shift the sequence by */ + ishift = (s1 - 1) % BITSPERBYTE; + r = VARBITS(result); + ps = VARBITS(arg) + (s1 - 1) / BITSPERBYTE; + for (i = 0; i < len; i++) + { + *r = (*ps << ishift) & BITMASK; + if ((++ps) < VARBITEND(arg)) + *r |= *ps >> (BITSPERBYTE - ishift); + r++; + } + } + /* Do we need to pad at the end? */ + ipad = VARBITPAD(result); + if (ipad > 0) + { + mask = BITMASK << ipad; + *(VARBITS(result) + len - 1) &= mask; + } } - } - return result; + return result; } /* bitand @@ -598,32 +656,32 @@ bitsubstr (bits8 *arg, int32 s, int32 l) * truncated to the shorter bit string */ bits8 * -bitand (bits8 * arg1, bits8 * arg2) +bitand(bits8 *arg1, bits8 *arg2) { - int len, - i; - bits8 *result; - bits8 *p1, - *p2, - *r; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return (bool) 0; - - len = Min(VARSIZE(arg1),VARSIZE(arg2)); - result = (bits8 *) palloc(len); - VARSIZE(result) = len; - VARBITLEN(result) = Min(VARBITLEN(arg1),VARBITLEN(arg2)); - - p1 = (bits8 *) VARBITS(arg1); - p2 = (bits8 *) VARBITS(arg2); - r = (bits8 *) VARBITS(result); - for (i=0; i<Min(VARBITBYTES(arg1),VARBITBYTES(arg2)); i++) - *r++ = *p1++ & *p2++; - - /* Padding is not needed as & of 0 pad is 0 */ - - return result; + int len, + i; + bits8 *result; + bits8 *p1, + *p2, + *r; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return (bool) 0; + + len = Min(VARSIZE(arg1), VARSIZE(arg2)); + result = (bits8 *) palloc(len); + VARSIZE(result) = len; + VARBITLEN(result) = Min(VARBITLEN(arg1), VARBITLEN(arg2)); + + p1 = (bits8 *) VARBITS(arg1); + p2 = (bits8 *) VARBITS(arg2); + r = (bits8 *) VARBITS(result); + for (i = 0; i < Min(VARBITBYTES(arg1), VARBITBYTES(arg2)); i++) + *r++ = *p1++ & *p2++; + + /* Padding is not needed as & of 0 pad is 0 */ + + return result; } /* bitor @@ -631,35 +689,35 @@ bitand (bits8 * arg1, bits8 * arg2) * truncated to the shorter bit string. */ bits8 * -bitor (bits8 * arg1, bits8 * arg2) +bitor(bits8 *arg1, bits8 *arg2) { - int len, - i; - bits8 *result; - bits8 *p1, - *p2, - *r; - bits8 mask; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return (bool) 0; - - len = Min(VARSIZE(arg1),VARSIZE(arg2)); - result = (bits8 *) palloc(len); - VARSIZE(result) = len; - VARBITLEN(result) = Min(VARBITLEN(arg1),VARBITLEN(arg2)); - - p1 = (bits8 *) VARBITS(arg1); - p2 = (bits8 *) VARBITS(arg2); - r = (bits8 *) VARBITS(result); - for (i=0; i<Min(VARBITBYTES(arg1),VARBITBYTES(arg2)); i++) - *r++ = *p1++ | *p2++; - - /* Pad the result */ - mask = BITMASK << VARBITPAD(result); - *r &= mask; - - return result; + int len, + i; + bits8 *result; + bits8 *p1, + *p2, + *r; + bits8 mask; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return (bool) 0; + + len = Min(VARSIZE(arg1), VARSIZE(arg2)); + result = (bits8 *) palloc(len); + VARSIZE(result) = len; + VARBITLEN(result) = Min(VARBITLEN(arg1), VARBITLEN(arg2)); + + p1 = (bits8 *) VARBITS(arg1); + p2 = (bits8 *) VARBITS(arg2); + r = (bits8 *) VARBITS(result); + for (i = 0; i < Min(VARBITBYTES(arg1), VARBITBYTES(arg2)); i++) + *r++ = *p1++ | *p2++; + + /* Pad the result */ + mask = BITMASK << VARBITPAD(result); + *r &= mask; + + return result; } /* bitxor @@ -667,160 +725,167 @@ bitor (bits8 * arg1, bits8 * arg2) * truncated to the shorter bit string. */ bits8 * -bitxor (bits8 * arg1, bits8 * arg2) +bitxor(bits8 *arg1, bits8 *arg2) { - int len, - i; - bits8 *result; - bits8 *p1, - *p2, - *r; - bits8 mask; - - if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) - return (bool) 0; - - len = Min(VARSIZE(arg1),VARSIZE(arg2)); - result = (bits8 *) palloc(len); - VARSIZE(result) = len; - VARBITLEN(result) = Min(VARBITLEN(arg1),VARBITLEN(arg2)); - - p1 = (bits8 *) VARBITS(arg1); - p2 = (bits8 *) VARBITS(arg2); - r = (bits8 *) VARBITS(result); - for (i=0; i<Min(VARBITBYTES(arg1),VARBITBYTES(arg2)); i++) - { - *r++ = *p1++ ^ *p2++; - } - - /* Pad the result */ - mask = BITMASK << VARBITPAD(result); - *r &= mask; - - return result; + int len, + i; + bits8 *result; + bits8 *p1, + *p2, + *r; + bits8 mask; + + if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) + return (bool) 0; + + len = Min(VARSIZE(arg1), VARSIZE(arg2)); + result = (bits8 *) palloc(len); + VARSIZE(result) = len; + VARBITLEN(result) = Min(VARBITLEN(arg1), VARBITLEN(arg2)); + + p1 = (bits8 *) VARBITS(arg1); + p2 = (bits8 *) VARBITS(arg2); + r = (bits8 *) VARBITS(result); + for (i = 0; i < Min(VARBITBYTES(arg1), VARBITBYTES(arg2)); i++) + *r++ = *p1++ ^ *p2++; + + /* Pad the result */ + mask = BITMASK << VARBITPAD(result); + *r &= mask; + + return result; } /* bitnot * perform a logical NOT on a bit strings. */ bits8 * -bitnot (bits8 * arg) +bitnot(bits8 *arg) { - bits8 *result; - bits8 *p, - *r; - bits8 mask; - - if (!PointerIsValid(arg)) - return (bool) 0; - - result = (bits8 *) palloc(VARSIZE(arg)); - VARSIZE(result) = VARSIZE(arg); - VARBITLEN(result) = VARBITLEN(arg); - - p = (bits8 *) VARBITS(arg); - r = (bits8 *) VARBITS(result); - for ( ; p < VARBITEND(arg); p++, r++) - *r = ~*p; - - /* Pad the result */ - mask = BITMASK << VARBITPAD(result); - *r &= mask; - - return result; + bits8 *result; + bits8 *p, + *r; + bits8 mask; + + if (!PointerIsValid(arg)) + return (bool) 0; + + result = (bits8 *) palloc(VARSIZE(arg)); + VARSIZE(result) = VARSIZE(arg); + VARBITLEN(result) = VARBITLEN(arg); + + p = (bits8 *) VARBITS(arg); + r = (bits8 *) VARBITS(result); + for (; p < VARBITEND(arg); p++, r++) + *r = ~*p; + + /* Pad the result */ + mask = BITMASK << VARBITPAD(result); + *r &= mask; + + return result; } /* bitshiftleft * do a left shift (i.e. to the beginning of the string) of the bit string */ bits8 * -bitshiftleft (bits8 * arg, int shft) +bitshiftleft(bits8 *arg, int shft) { - int byte_shift, ishift, len; - bits8 *result; - bits8 *p, - *r; - - if (!PointerIsValid(arg)) - return (bool) 0; - - /* Negative shift is a shift to the right */ - if (shft < 0) - return bitshiftright(arg, -shft); - - result = (bits8 *) palloc(VARSIZE(arg)); - VARSIZE(result) = VARSIZE(arg); - VARBITLEN(result) = VARBITLEN(arg); - r = (bits8 *) VARBITS(result); - - byte_shift = shft/BITSPERBYTE; - ishift = shft % BITSPERBYTE; - p = ((bits8 *) VARBITS(arg)) + byte_shift; - - if (ishift == 0) { - /* Special case: we can do a memcpy */ - len = VARBITBYTES(arg) - byte_shift; - memcpy(r, p, len); - memset(r+len, 0, byte_shift); - } else { - for ( ; p < VARBITEND(arg); r++) { - *r = *p <<ishift; - if ((++p) < VARBITEND(arg)) - *r |= *p >>(BITSPERBYTE-ishift); - } - for ( ; r < VARBITEND(result) ; r++ ) - *r = (bits8) 0; - } - - return result; + int byte_shift, + ishift, + len; + bits8 *result; + bits8 *p, + *r; + + if (!PointerIsValid(arg)) + return (bool) 0; + + /* Negative shift is a shift to the right */ + if (shft < 0) + return bitshiftright(arg, -shft); + + result = (bits8 *) palloc(VARSIZE(arg)); + VARSIZE(result) = VARSIZE(arg); + VARBITLEN(result) = VARBITLEN(arg); + r = (bits8 *) VARBITS(result); + + byte_shift = shft / BITSPERBYTE; + ishift = shft % BITSPERBYTE; + p = ((bits8 *) VARBITS(arg)) + byte_shift; + + if (ishift == 0) + { + /* Special case: we can do a memcpy */ + len = VARBITBYTES(arg) - byte_shift; + memcpy(r, p, len); + memset(r + len, 0, byte_shift); + } + else + { + for (; p < VARBITEND(arg); r++) + { + *r = *p << ishift; + if ((++p) < VARBITEND(arg)) + *r |= *p >> (BITSPERBYTE - ishift); + } + for (; r < VARBITEND(result); r++) + *r = (bits8) 0; + } + + return result; } /* bitshiftright * do a right shift (i.e. to the beginning of the string) of the bit string */ bits8 * -bitshiftright (bits8 * arg, int shft) +bitshiftright(bits8 *arg, int shft) { - int byte_shift, ishift, len; - bits8 *result; - bits8 *p, - *r; - - if (!PointerIsValid(arg)) - return (bits8 *) 0; - - /* Negative shift is a shift to the left */ - if (shft < 0) - return bitshiftleft(arg, -shft); - - result = (bits8 *) palloc(VARSIZE(arg)); - VARSIZE(result) = VARSIZE(arg); - VARBITLEN(result) = VARBITLEN(arg); - r = (bits8 *) VARBITS(result); - - byte_shift = shft/BITSPERBYTE; - ishift = shft % BITSPERBYTE; - p = (bits8 *) VARBITS(arg); - - /* Set the first part of the result to 0 */ - memset(r, 0, byte_shift); - - if (ishift == 0) - { - /* Special case: we can do a memcpy */ - len = VARBITBYTES(arg) - byte_shift; - memcpy(r+byte_shift, p, len); - } - else - { - r += byte_shift; - *r = 0; /* Initialise first byte */ - for ( ; r < VARBITEND(result); p++) { - *r |= *p >> ishift; - if ((++r) < VARBITEND(result)) - *r = (*p <<(BITSPERBYTE-ishift)) & BITMASK; - } - } - - return result; + int byte_shift, + ishift, + len; + bits8 *result; + bits8 *p, + *r; + + if (!PointerIsValid(arg)) + return (bits8 *) 0; + + /* Negative shift is a shift to the left */ + if (shft < 0) + return bitshiftleft(arg, -shft); + + result = (bits8 *) palloc(VARSIZE(arg)); + VARSIZE(result) = VARSIZE(arg); + VARBITLEN(result) = VARBITLEN(arg); + r = (bits8 *) VARBITS(result); + + byte_shift = shft / BITSPERBYTE; + ishift = shft % BITSPERBYTE; + p = (bits8 *) VARBITS(arg); + + /* Set the first part of the result to 0 */ + memset(r, 0, byte_shift); + + if (ishift == 0) + { + /* Special case: we can do a memcpy */ + len = VARBITBYTES(arg) - byte_shift; + memcpy(r + byte_shift, p, len); + } + else + { + r += byte_shift; + *r = 0; /* Initialise first byte */ + for (; r < VARBITEND(result); p++) + { + *r |= *p >> ishift; + if ((++r) < VARBITEND(result)) + *r = (*p << (BITSPERBYTE - ishift)) & BITMASK; + } + } + + return result; } diff --git a/contrib/bit/varbit.h b/contrib/bit/varbit.h index 0b7e3308c48..ca7202b4c80 100644 --- a/contrib/bit/varbit.h +++ b/contrib/bit/varbit.h @@ -2,7 +2,7 @@ #include <ctype.h> #include <errno.h> -#include <float.h> /* faked on sunos4 */ +#include <float.h> /* faked on sunos4 */ #include <math.h> @@ -10,7 +10,7 @@ #ifdef HAVE_LIMITS_H #include <limits.h> #ifndef MAXINT -#define MAXINT INT_MAX +#define MAXINT INT_MAX #endif #else #ifdef HAVE_VALUES_H @@ -22,7 +22,7 @@ #include "utils/builtins.h" -#define HEXDIG(z) (z)<10 ? ((z)+'0') : ((z)-10+'A') +#define HEXDIG(z) (z)<10 ? ((z)+'0') : ((z)-10+'A') /* Modeled on struct varlena from postgres.h, bu data type is bits8 */ struct varbita @@ -49,25 +49,25 @@ struct varbita #define VARBITEND(PTR) ((bits8 *) (PTR + VARSIZE(PTR))) /* Mask that will cover exactly one byte, i.e. BITSPERBYTE bits */ #define BITMASK 0xFF -#define BITHIGH 0x80 +#define BITHIGH 0x80 -bits8 * zpbitin(char *s, int dummy, int32 atttypmod); -char * zpbitout(bits8 *s); -char * zpbitsout(bits8 *s); -bits8 * varbitin(char *s, int dummy, int32 atttypmod); -bool biteq (bits8 *arg1, bits8 *arg2); -bool bitne (bits8 *arg1, bits8 *arg2); -bool bitge (bits8 *arg1, bits8 *arg2); -bool bitgt (bits8 *arg1, bits8 *arg2); -bool bitle (bits8 *arg1, bits8 *arg2); -bool bitlt (bits8 *arg1, bits8 *arg2); -int bitcmp (bits8 *arg1, bits8 *arg2); -bits8 * bitand (bits8 * arg1, bits8 * arg2); -bits8 * bitor (bits8 * arg1, bits8 * arg2); -bits8 * bitxor (bits8 * arg1, bits8 * arg2); -bits8 * bitnot (bits8 * arg); -bits8 * bitshiftright (bits8 * arg, int shft); -bits8 * bitshiftleft (bits8 * arg, int shft); -bits8 * bitcat (bits8 *arg1, bits8 *arg2); -bits8 * bitsubstr (bits8 *arg, int32 s, int32 l); +bits8 *zpbitin(char *s, int dummy, int32 atttypmod); +char *zpbitout(bits8 *s); +char *zpbitsout(bits8 *s); +bits8 *varbitin(char *s, int dummy, int32 atttypmod); +bool biteq(bits8 *arg1, bits8 *arg2); +bool bitne(bits8 *arg1, bits8 *arg2); +bool bitge(bits8 *arg1, bits8 *arg2); +bool bitgt(bits8 *arg1, bits8 *arg2); +bool bitle(bits8 *arg1, bits8 *arg2); +bool bitlt(bits8 *arg1, bits8 *arg2); +int bitcmp(bits8 *arg1, bits8 *arg2); +bits8 *bitand(bits8 *arg1, bits8 *arg2); +bits8 *bitor(bits8 *arg1, bits8 *arg2); +bits8 *bitxor(bits8 *arg1, bits8 *arg2); +bits8 *bitnot(bits8 *arg); +bits8 *bitshiftright(bits8 *arg, int shft); +bits8 *bitshiftleft(bits8 *arg, int shft); +bits8 *bitcat(bits8 *arg1, bits8 *arg2); +bits8 *bitsubstr(bits8 *arg, int32 s, int32 l); diff --git a/contrib/bit/varbit_glue.c b/contrib/bit/varbit_glue.c index 29b7debd03c..bd79a849a50 100644 --- a/contrib/bit/varbit_glue.c +++ b/contrib/bit/varbit_glue.c @@ -2,21 +2,23 @@ #include "varbit.h" -bits8 * varbit_in (char * s); -char * varbit_out (bits8 *s); +bits8 *varbit_in(char *s); +char *varbit_out(bits8 *s); bits8 * -varbit_in (char * s) { - return varbitin (s, 0, -1); +varbit_in(char *s) +{ + return varbitin(s, 0, -1); } -/*char * +/*char * varbit_out (bits8 *s) { return zpbitout(s); } */ -char * -varbit_out (bits8 *s) { - return zpbitsout(s); +char * +varbit_out(bits8 *s) +{ + return zpbitsout(s); } diff --git a/contrib/bit/vartest.c b/contrib/bit/vartest.c index f07f5c5b833..7725f6bbd30 100644 --- a/contrib/bit/vartest.c +++ b/contrib/bit/vartest.c @@ -2,173 +2,183 @@ #include "varbit.h" #include <stdio.h> -void print_details (unsigned char *s); +void print_details(unsigned char *s); + +const int numb = 8; -const int numb = 8; /* const char *b[] = { "B0010", "B11011011", "B0001", "X3F12", "X27", "B", - "X11", "B100111"}; + "X11", "B100111"}; int atttypmod[] = {-1, -1, -1,-1,-1,-1,-1,-1 }; */ -const char *b[] = { "B0010", "B11011011", "B10001", "X3D12", "X27", "B", - "X11", "B100111"}; -int atttypmod[] = { 7, 9, 6, 18, 11, 6, -1, -1 }; +const char *b[] = {"B0010", "B11011011", "B10001", "X3D12", "X27", "B", +"X11", "B100111"}; +int atttypmod[] = {7, 9, 6, 18, 11, 6, -1, -1}; -void print_details (unsigned char *s) +void +print_details(unsigned char *s) { - int i; - printf ("Length in bytes : %d\n",VARSIZE(s)); - printf ("Length of bitstring: %d\n",VARBITLEN(s)); - for (i=8; i<VARSIZE(s); i++) - printf ("%X%X ",s[i]>>4,s[i]&0xF); - printf("\n"); + int i; + + printf("Length in bytes : %d\n", VARSIZE(s)); + printf("Length of bitstring: %d\n", VARBITLEN(s)); + for (i = 8; i < VARSIZE(s); i++) + printf("%X%X ", s[i] >> 4, s[i] & 0xF); + printf("\n"); } int -main () +main() { - int i, j; - char *s[numb]; - - for (i=0; i<numb; i++) { - printf ("Input: %s\n",b[i]); - s[i] = zpbitin(b[i], 0, atttypmod[i]); - //print_details(s[i]); - printf ("%s = %s\n",zpbitout(s[i]),zpbitsout(s[i])); - } - - printf ("\nCOMPARISONS:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s <=> %s = %d\n",zpbitsout(s[i]),zpbitsout(s[j]), - bitcmp(s[i],s[j])); - - printf ("\nCONCATENATION:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s || %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitcat(s[i],s[j]))); - - printf("\nSUBSTR:\n"); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),1,8, - zpbitsout(bitsubstr(s[3],1,8))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),9,8, - zpbitsout(bitsubstr(s[3],9,8))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),1,9, - zpbitsout(bitsubstr(s[3],1,9))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),3,5, - zpbitsout(bitsubstr(s[3],3,5))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),3,9, - zpbitsout(bitsubstr(s[3],3,9))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),3,17, - zpbitsout(bitsubstr(s[3],3,17))); - printf ("\nLOGICAL AND:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s & %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitand(s[i],s[j]))); - - printf ("\nLOGICAL OR:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s | %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitor(s[i],s[j]))); - - printf ("\nLOGICAL XOR:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s ^ %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitxor(s[i],s[j]))); - - printf ("\nLOGICAL NOT:\n"); - for (i=0; i<numb; i++) - printf("~%s = %s\n",zpbitsout(s[i]),zpbitsout(bitnot(s[i]))); - - - printf ("\nSHIFT LEFT:\n"); - for (i=0; i<numb; i++) { - printf("%s\n",zpbitsout(s[i])); - for (j=0; j<=VARBITLEN(s[i]); j++) - printf("\t%3d\t%s\n",j,zpbitsout(bitshiftleft(s[i],j))); - } - - printf ("\nSHIFT RIGHT:\n"); - for (i=0; i<numb; i++) { - printf("%s\n",zpbitsout(s[i])); - for (j=0; j<=VARBITLEN(s[i]); j++) - printf("\t%3d\t%s\n",j,zpbitsout(bitshiftright(s[i],j))); - } - - printf ("\n\n ********** VARYING **********\n"); - for (i=0; i<numb; i++) { - printf ("Input: %s\n",b[i]); - s[i] = varbitin(b[i], 0, atttypmod[i]); - /*print_details(s);*/ - printf ("%s\n",zpbitout(s[i])); - printf ("%s\n",zpbitsout(s[i])); - } - - printf ("\nCOMPARISONS:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s <=> %s = %d\n",zpbitsout(s[i]),zpbitsout(s[j]), - bitcmp(s[i],s[j])); - - printf ("\nCONCATENATION:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s || %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitcat(s[i],s[j]))); - - printf("\nSUBSTR:\n"); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),1,8, - zpbitsout(bitsubstr(s[3],1,8))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),9,8, - zpbitsout(bitsubstr(s[3],9,8))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),1,9, - zpbitsout(bitsubstr(s[3],1,9))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),3,5, - zpbitsout(bitsubstr(s[3],3,5))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),3,9, - zpbitsout(bitsubstr(s[3],3,9))); - printf("%s (%d,%d) => %s (%s)\n",zpbitsout(s[3]),3,17, - zpbitsout(bitsubstr(s[3],3,17)),zpbitsout(bitsubstr(s[3],3,17))); - printf ("\nLOGICAL AND:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s & %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitand(s[i],s[j]))); - - printf ("\nLOGICAL OR:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s | %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitor(s[i],s[j]))); - - printf ("\nLOGICAL XOR:\n"); - for (i=0; i<numb; i++) - for (j=i+1; j<numb; j++) - printf("%s ^ %s = %s\n",zpbitsout(s[i]),zpbitsout(s[j]), - zpbitsout(bitxor(s[i],s[j]))); - - printf ("\nLOGICAL NOT:\n"); - for (i=0; i<numb; i++) - printf("~%s = %s\n",zpbitsout(s[i]),zpbitsout(bitnot(s[i]))); - - - printf ("\nSHIFT LEFT:\n"); - for (i=0; i<numb; i++) { - printf("%s\n",zpbitsout(s[i])); - for (j=0; j<=VARBITLEN(s[i]); j++) - printf("\t%3d\t%s\n",j,zpbitsout(bitshiftleft(s[i],j))); - } - - printf ("\nSHIFT RIGHT:\n"); - for (i=0; i<numb; i++) { - printf("%s\n",zpbitsout(s[i])); - for (j=0; j<=VARBITLEN(s[i]); j++) - printf("\t%3d\t%s\n",j,zpbitsout(bitshiftright(s[i],j))); - } + int i, + j; + char *s[numb]; + + for (i = 0; i < numb; i++) + { + printf("Input: %s\n", b[i]); + s[i] = zpbitin(b[i], 0, atttypmod[i]); + //print_details(s[i]); + printf("%s = %s\n", zpbitout(s[i]), zpbitsout(s[i])); + } + + printf("\nCOMPARISONS:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s <=> %s = %d\n", zpbitsout(s[i]), zpbitsout(s[j]), + bitcmp(s[i], s[j])); + + printf("\nCONCATENATION:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s || %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitcat(s[i], s[j]))); + + printf("\nSUBSTR:\n"); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 1, 8, + zpbitsout(bitsubstr(s[3], 1, 8))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 9, 8, + zpbitsout(bitsubstr(s[3], 9, 8))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 1, 9, + zpbitsout(bitsubstr(s[3], 1, 9))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 3, 5, + zpbitsout(bitsubstr(s[3], 3, 5))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 3, 9, + zpbitsout(bitsubstr(s[3], 3, 9))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 3, 17, + zpbitsout(bitsubstr(s[3], 3, 17))); + printf("\nLOGICAL AND:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s & %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitand(s[i], s[j]))); + + printf("\nLOGICAL OR:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s | %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitor(s[i], s[j]))); + + printf("\nLOGICAL XOR:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s ^ %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitxor(s[i], s[j]))); + + printf("\nLOGICAL NOT:\n"); + for (i = 0; i < numb; i++) + printf("~%s = %s\n", zpbitsout(s[i]), zpbitsout(bitnot(s[i]))); + + + printf("\nSHIFT LEFT:\n"); + for (i = 0; i < numb; i++) + { + printf("%s\n", zpbitsout(s[i])); + for (j = 0; j <= VARBITLEN(s[i]); j++) + printf("\t%3d\t%s\n", j, zpbitsout(bitshiftleft(s[i], j))); + } + + printf("\nSHIFT RIGHT:\n"); + for (i = 0; i < numb; i++) + { + printf("%s\n", zpbitsout(s[i])); + for (j = 0; j <= VARBITLEN(s[i]); j++) + printf("\t%3d\t%s\n", j, zpbitsout(bitshiftright(s[i], j))); + } + + printf("\n\n ********** VARYING **********\n"); + for (i = 0; i < numb; i++) + { + printf("Input: %s\n", b[i]); + s[i] = varbitin(b[i], 0, atttypmod[i]); + /* print_details(s); */ + printf("%s\n", zpbitout(s[i])); + printf("%s\n", zpbitsout(s[i])); + } + + printf("\nCOMPARISONS:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s <=> %s = %d\n", zpbitsout(s[i]), zpbitsout(s[j]), + bitcmp(s[i], s[j])); + + printf("\nCONCATENATION:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s || %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitcat(s[i], s[j]))); + + printf("\nSUBSTR:\n"); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 1, 8, + zpbitsout(bitsubstr(s[3], 1, 8))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 9, 8, + zpbitsout(bitsubstr(s[3], 9, 8))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 1, 9, + zpbitsout(bitsubstr(s[3], 1, 9))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 3, 5, + zpbitsout(bitsubstr(s[3], 3, 5))); + printf("%s (%d,%d) => %s\n", zpbitsout(s[3]), 3, 9, + zpbitsout(bitsubstr(s[3], 3, 9))); + printf("%s (%d,%d) => %s (%s)\n", zpbitsout(s[3]), 3, 17, + zpbitsout(bitsubstr(s[3], 3, 17)), zpbitsout(bitsubstr(s[3], 3, 17))); + printf("\nLOGICAL AND:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s & %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitand(s[i], s[j]))); + + printf("\nLOGICAL OR:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s | %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitor(s[i], s[j]))); + + printf("\nLOGICAL XOR:\n"); + for (i = 0; i < numb; i++) + for (j = i + 1; j < numb; j++) + printf("%s ^ %s = %s\n", zpbitsout(s[i]), zpbitsout(s[j]), + zpbitsout(bitxor(s[i], s[j]))); + + printf("\nLOGICAL NOT:\n"); + for (i = 0; i < numb; i++) + printf("~%s = %s\n", zpbitsout(s[i]), zpbitsout(bitnot(s[i]))); + + + printf("\nSHIFT LEFT:\n"); + for (i = 0; i < numb; i++) + { + printf("%s\n", zpbitsout(s[i])); + for (j = 0; j <= VARBITLEN(s[i]); j++) + printf("\t%3d\t%s\n", j, zpbitsout(bitshiftleft(s[i], j))); + } + + printf("\nSHIFT RIGHT:\n"); + for (i = 0; i < numb; i++) + { + printf("%s\n", zpbitsout(s[i])); + for (j = 0; j <= VARBITLEN(s[i]); j++) + printf("\t%3d\t%s\n", j, zpbitsout(bitshiftright(s[i], j))); + } } diff --git a/contrib/datetime/datetime_functions.c b/contrib/datetime/datetime_functions.c index c5b8bc25e9d..47991a8646d 100644 --- a/contrib/datetime/datetime_functions.c +++ b/contrib/datetime/datetime_functions.c @@ -36,7 +36,7 @@ * Decode time string 00:00:00 through 24:00:00. */ static int -decode_24h_time(char *str, struct tm *tm, double *fsec) +decode_24h_time(char *str, struct tm * tm, double *fsec) { char *cp; @@ -51,9 +51,7 @@ decode_24h_time(char *str, struct tm *tm, double *fsec) *fsec = 0; } else if (*cp != ':') - { return -1; - } else { str = cp + 1; @@ -72,10 +70,10 @@ decode_24h_time(char *str, struct tm *tm, double *fsec) } /* do a sanity check */ - if ( (tm->tm_hour < 0) || (tm->tm_hour > 24) - || (tm->tm_min < 0) || (tm->tm_min > 59) - || (tm->tm_sec < 0) || (tm->tm_sec > 59) - || (*fsec < 0) ) + if ((tm->tm_hour < 0) || (tm->tm_hour > 24) + || (tm->tm_min < 0) || (tm->tm_min > 59) + || (tm->tm_sec < 0) || (tm->tm_sec > 59) + || (*fsec < 0)) return -1; return 0; @@ -265,7 +263,7 @@ currentdate() int4 date2mjd(DateADT val) { - int result; + int result; result = val + JDATE_2000 - 2400000.5; @@ -276,8 +274,8 @@ date2mjd(DateADT val) /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/datetime/datetime_functions.h b/contrib/datetime/datetime_functions.h index ff2309d16f0..c345f2852b8 100644 --- a/contrib/datetime/datetime_functions.h +++ b/contrib/datetime/datetime_functions.h @@ -20,8 +20,8 @@ DateADT currentdate(void); /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/miscutil/misc_utils.c b/contrib/miscutil/misc_utils.c index 6745b5b8bb9..302118689dc 100644 --- a/contrib/miscutil/misc_utils.c +++ b/contrib/miscutil/misc_utils.c @@ -38,6 +38,7 @@ extern int assertTest(int val); #ifdef ASSERT_CHECKING_TEST extern int assertEnable(int val); + #endif int @@ -84,7 +85,8 @@ active_listeners(text *relname) ScanKeyData key; Datum d; bool isnull; - int len, pid; + int len, + pid; int count = 0; int ourpid = getpid(); char listen_name[NAMEDATALEN]; @@ -92,8 +94,9 @@ active_listeners(text *relname) lRel = heap_openr(ListenerRelationName, AccessShareLock); tdesc = RelationGetDescr(lRel); - if (relname && (VARSIZE(relname) > VARHDRSZ)) { - len = MIN(VARSIZE(relname)-VARHDRSZ, NAMEDATALEN-1); + if (relname && (VARSIZE(relname) > VARHDRSZ)) + { + len = MIN(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1); strncpy(listen_name, VARDATA(relname), len); listen_name[len] = '\0'; ScanKeyEntryInitialize(&key, 0, @@ -101,15 +104,16 @@ active_listeners(text *relname) F_NAMEEQ, PointerGetDatum(listen_name)); sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, &key); - } else { - sRel = heap_beginscan(lRel, 0, SnapshotNow, 0, (ScanKey)NULL); } + else + sRel = heap_beginscan(lRel, 0, SnapshotNow, 0, (ScanKey) NULL); while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0))) { d = heap_getattr(lTuple, Anum_pg_listener_pid, tdesc, &isnull); pid = DatumGetInt32(d); - if ((pid == ourpid) || (kill(pid, SIGTSTP) == 0)) { + if ((pid == ourpid) || (kill(pid, SIGTSTP) == 0)) + { /* elog(NOTICE, "%d ok", pid); */ count++; } @@ -134,6 +138,7 @@ assert_test(int val) { return assertTest(val); } + #endif #endif @@ -141,8 +146,8 @@ assert_test(int val) /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/miscutil/misc_utils.h b/contrib/miscutil/misc_utils.h index 139df3bc775..080f1147a88 100644 --- a/contrib/miscutil/misc_utils.h +++ b/contrib/miscutil/misc_utils.h @@ -10,8 +10,10 @@ int active_listeners(text *relname); #ifdef USE_ASSERT_CHECKING int assert_enable(int val); + #ifdef ASSERT_CHECKING_TEST int assert_test(int val); + #endif #endif @@ -19,8 +21,8 @@ int assert_test(int val); /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/os2client/config.h b/contrib/os2client/config.h index afdcb4484c8..7a98eb60a9c 100644 --- a/contrib/os2client/config.h +++ b/contrib/os2client/config.h @@ -11,7 +11,7 @@ * DEF_PGPORT is the TCP port number on which the Postmaster listens by * default. This can be overriden by command options, environment variables, * and the postconfig hook. (set by build script) - */
+ */
#define DEF_PGPORT "5432"
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index ab5f0907167..c2b027c9ecc 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -1,5 +1,5 @@ /* - * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.2 2000/04/08 18:32:24 tgl Exp $ + * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.3 2000/04/12 17:14:27 momjian Exp $ * * pgbench: a simple TPC-B like benchmark program for PostgreSQL * written by Tatsuo Ishii @@ -50,16 +50,17 @@ /******************************************************************** * some configurable parameters */ -#define MAXCLIENTS 1024 /* max number of clients allowed */ +#define MAXCLIENTS 1024 /* max number of clients allowed */ -int nclients = 1; /* default number of simulated clients */ -int nxacts = 10; /* default number of transactions per clients */ +int nclients = 1; /* default number of simulated clients */ +int nxacts = 10; /* default number of transactions per + * clients */ /* * scaling factor. for example, tps = 10 will make 1000000 tuples of * accounts table. */ -int tps = 1; +int tps = 1; /* * end of configurable parameters @@ -67,671 +68,753 @@ int tps = 1; #define nbranches 1 #define ntellers 10 -#define naccounts 100000 - -int remains; /* number of remained clients */ - -typedef struct { - PGconn *con; /* connection handle to DB */ - int state; /* state No. */ - int cnt; /* xacts count */ - int ecnt; /* error count */ - int listen; /* none 0 indicates that an async query has been sent */ - int aid; /* account id for this transaction */ - int bid; /* branch id for this transaction */ - int tid; /* teller id for this transaction */ - int delta; - int abalance; -} CState; - -static void usage() { - fprintf(stderr,"usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-v][-S][-d][dbname]\n"); - fprintf(stderr,"(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-d][dbname]\n"); +#define naccounts 100000 + +int remains; /* number of remained clients */ + +typedef struct +{ + PGconn *con; /* connection handle to DB */ + int state; /* state No. */ + int cnt; /* xacts count */ + int ecnt; /* error count */ + int listen; /* none 0 indicates that an async query + * has been sent */ + int aid; /* account id for this transaction */ + int bid; /* branch id for this transaction */ + int tid; /* teller id for this transaction */ + int delta; + int abalance; +} CState; + +static void +usage() +{ + fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-v][-S][-d][dbname]\n"); + fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-d][dbname]\n"); } /* random number generator */ -static int getrand(int min, int max) { - return(min+(int)(max*1.0*rand()/(RAND_MAX+1.0))); +static int +getrand(int min, int max) +{ + return (min + (int) (max * 1.0 * rand() / (RAND_MAX + 1.0))); } /* throw away response from backend */ -static void discard_response(CState *state) { - PGresult *res; - do { - res = PQgetResult(state->con); - if (res) - PQclear(res); - } while(res); +static void +discard_response(CState * state) +{ + PGresult *res; + + do + { + res = PQgetResult(state->con); + if (res) + PQclear(res); + } while (res); } -static int check(CState *state, PGresult *res, int n, int good) +static int +check(CState * state, PGresult *res, int n, int good) { - CState *st = &state[n]; - - if (res && PQresultStatus(res) != good) { - fprintf(stderr,"Client %d aborted in state %d: %s",n,st->state,PQerrorMessage(st->con)); - remains--; /* I've aborted */ - PQfinish(st->con); - st->con = NULL; - return(-1); - } - return(0); + CState *st = &state[n]; + + if (res && PQresultStatus(res) != good) + { + fprintf(stderr, "Client %d aborted in state %d: %s", n, st->state, PQerrorMessage(st->con)); + remains--; /* I've aborted */ + PQfinish(st->con); + st->con = NULL; + return (-1); + } + return (0); } /* process a transaction */ -static void doOne(CState *state, int n, int debug) { - char sql[256]; - PGresult *res; - CState *st = &state[n]; - - if (st->listen) { /* are we receiver? */ - if (debug) { - fprintf(stderr,"client %d receiving\n",n); - } - while (PQisBusy(st->con) == TRUE) { - if (!PQconsumeInput(st->con)) { /* there's something wrong */ - fprintf(stderr, "Client %d aborted in state %d. Probably the backend died while processing.\n",n, st->state); - remains--; /* I've aborted */ - PQfinish(st->con); - st->con = NULL; - return; - } - } - - switch (st->state) { - case 0: /* response to "begin" */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_COMMAND_OK)) { - return; - } - PQclear(res); - discard_response(st); - break; - case 1: /* response to "update accounts..." */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_COMMAND_OK)) { - return; - } - PQclear(res); - discard_response(st); - break; - case 2: /* response to "select abalance ..." */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_TUPLES_OK)) { - return; - } - PQclear(res); - discard_response(st); - break; - case 3: /* response to "update tellers ..." */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_COMMAND_OK)) { - return; - } - PQclear(res); - discard_response(st); - break; - case 4: /* response to "update branches ..." */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_COMMAND_OK)) { - return; - } - PQclear(res); - discard_response(st); - break; - case 5: /* response to "insert into history ..." */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_COMMAND_OK)) { - return; - } - PQclear(res); - discard_response(st); - break; - case 6: /* response to "end" */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_COMMAND_OK)) { - return; - } - PQclear(res); - discard_response(st); - - if (++st->cnt >= nxacts) { - remains--; /* I've done */ - PQfinish(st->con); - st->con = NULL; - return; - } - break; - } - - /* increment state counter */ - st->state++; - if (st->state > 6) { - st->state = 0; - } - } - - switch (st->state) { - case 0: /* about to start */ - strcpy(sql,"begin"); - st->aid = getrand(1,naccounts*tps); - st->bid = getrand(1,nbranches*tps); - st->tid = getrand(1,ntellers*tps); - st->delta = getrand(1,1000); - break; - case 1: - sprintf(sql,"update accounts set abalance = abalance + %d where aid = %d\n",st->delta,st->aid); - break; - case 2: - sprintf(sql,"select abalance from accounts where aid = %d",st->aid); - break; - case 3: - sprintf(sql,"update tellers set tbalance = tbalance + %d where tid = %d\n", - st->delta,st->tid); - break; - case 4: - sprintf(sql,"update branches set bbalance = bbalance + %d where bid = %d",st->delta,st->bid); - break; - case 5: - sprintf(sql,"insert into history(tid,bid,aid,delta,time) values(%d,%d,%d,%d,'now')", - st->tid,st->bid,st->aid,st->delta); - break; - case 6: - strcpy(sql,"end"); - break; - } - - if (debug) { - fprintf(stderr,"client %d sending %s\n",n,sql); - } - if (PQsendQuery(st->con, sql) == 0) { - if (debug) { - fprintf(stderr, "PQsendQuery(%s)failed\n",sql); - } - st->ecnt++; - } else { - st->listen++; /* flags that should be listned */ - } +static void +doOne(CState * state, int n, int debug) +{ + char sql[256]; + PGresult *res; + CState *st = &state[n]; + + if (st->listen) + { /* are we receiver? */ + if (debug) + fprintf(stderr, "client %d receiving\n", n); + while (PQisBusy(st->con) == TRUE) + { + if (!PQconsumeInput(st->con)) + { /* there's something wrong */ + fprintf(stderr, "Client %d aborted in state %d. Probably the backend died while processing.\n", n, st->state); + remains--; /* I've aborted */ + PQfinish(st->con); + st->con = NULL; + return; + } + } + + switch (st->state) + { + case 0: /* response to "begin" */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_COMMAND_OK)) + return; + PQclear(res); + discard_response(st); + break; + case 1: /* response to "update accounts..." */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_COMMAND_OK)) + return; + PQclear(res); + discard_response(st); + break; + case 2: /* response to "select abalance ..." */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_TUPLES_OK)) + return; + PQclear(res); + discard_response(st); + break; + case 3: /* response to "update tellers ..." */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_COMMAND_OK)) + return; + PQclear(res); + discard_response(st); + break; + case 4: /* response to "update branches ..." */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_COMMAND_OK)) + return; + PQclear(res); + discard_response(st); + break; + case 5: /* response to "insert into history ..." */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_COMMAND_OK)) + return; + PQclear(res); + discard_response(st); + break; + case 6: /* response to "end" */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_COMMAND_OK)) + return; + PQclear(res); + discard_response(st); + + if (++st->cnt >= nxacts) + { + remains--; /* I've done */ + PQfinish(st->con); + st->con = NULL; + return; + } + break; + } + + /* increment state counter */ + st->state++; + if (st->state > 6) + st->state = 0; + } + + switch (st->state) + { + case 0: /* about to start */ + strcpy(sql, "begin"); + st->aid = getrand(1, naccounts * tps); + st->bid = getrand(1, nbranches * tps); + st->tid = getrand(1, ntellers * tps); + st->delta = getrand(1, 1000); + break; + case 1: + sprintf(sql, "update accounts set abalance = abalance + %d where aid = %d\n", st->delta, st->aid); + break; + case 2: + sprintf(sql, "select abalance from accounts where aid = %d", st->aid); + break; + case 3: + sprintf(sql, "update tellers set tbalance = tbalance + %d where tid = %d\n", + st->delta, st->tid); + break; + case 4: + sprintf(sql, "update branches set bbalance = bbalance + %d where bid = %d", st->delta, st->bid); + break; + case 5: + sprintf(sql, "insert into history(tid,bid,aid,delta,time) values(%d,%d,%d,%d,'now')", + st->tid, st->bid, st->aid, st->delta); + break; + case 6: + strcpy(sql, "end"); + break; + } + + if (debug) + fprintf(stderr, "client %d sending %s\n", n, sql); + if (PQsendQuery(st->con, sql) == 0) + { + if (debug) + fprintf(stderr, "PQsendQuery(%s)failed\n", sql); + st->ecnt++; + } + else + { + st->listen++; /* flags that should be listned */ + } } /* process a select only transaction */ -static void doSelectOnly(CState *state, int n, int debug) { - char sql[256]; - PGresult *res; - CState *st = &state[n]; - - if (st->listen) { /* are we receiver? */ - if (debug) { - fprintf(stderr,"client %d receiving\n",n); - } - while (PQisBusy(st->con) == TRUE) { - if (!PQconsumeInput(st->con)) { /* there's something wrong */ - fprintf(stderr, "Client %d aborted in state %d. Probably the backend died while processing.\n",n, st->state); - remains--; /* I've aborted */ - PQfinish(st->con); - st->con = NULL; - return; - } - } - - switch (st->state) { - case 0: /* response to "select abalance ..." */ - res = PQgetResult(st->con); - if (check(state, res, n, PGRES_TUPLES_OK)) { - return; - } - PQclear(res); - discard_response(st); - - if (++st->cnt >= nxacts) { - remains--; /* I've done */ - PQfinish(st->con); - st->con = NULL; - return; - } - break; - } - - /* increment state counter */ - st->state++; - if (st->state > 0) { - st->state = 0; - } - } - - switch (st->state) { - case 0: - st->aid = getrand(1,naccounts*tps); - sprintf(sql,"select abalance from accounts where aid = %d",st->aid); - break; - } - - if (debug) { - fprintf(stderr,"client %d sending %s\n",n,sql); - } - - if (PQsendQuery(st->con, sql) == 0) { - if (debug) { - fprintf(stderr, "PQsendQuery(%s)failed\n",sql); - } - st->ecnt++; - } else { - st->listen++; /* flags that should be listned */ - } +static void +doSelectOnly(CState * state, int n, int debug) +{ + char sql[256]; + PGresult *res; + CState *st = &state[n]; + + if (st->listen) + { /* are we receiver? */ + if (debug) + fprintf(stderr, "client %d receiving\n", n); + while (PQisBusy(st->con) == TRUE) + { + if (!PQconsumeInput(st->con)) + { /* there's something wrong */ + fprintf(stderr, "Client %d aborted in state %d. Probably the backend died while processing.\n", n, st->state); + remains--; /* I've aborted */ + PQfinish(st->con); + st->con = NULL; + return; + } + } + + switch (st->state) + { + case 0: /* response to "select abalance ..." */ + res = PQgetResult(st->con); + if (check(state, res, n, PGRES_TUPLES_OK)) + return; + PQclear(res); + discard_response(st); + + if (++st->cnt >= nxacts) + { + remains--; /* I've done */ + PQfinish(st->con); + st->con = NULL; + return; + } + break; + } + + /* increment state counter */ + st->state++; + if (st->state > 0) + st->state = 0; + } + + switch (st->state) + { + case 0: + st->aid = getrand(1, naccounts * tps); + sprintf(sql, "select abalance from accounts where aid = %d", st->aid); + break; + } + + if (debug) + fprintf(stderr, "client %d sending %s\n", n, sql); + + if (PQsendQuery(st->con, sql) == 0) + { + if (debug) + fprintf(stderr, "PQsendQuery(%s)failed\n", sql); + st->ecnt++; + } + else + { + st->listen++; /* flags that should be listned */ + } } /* discard connections */ -static void disconnect_all(CState *state) { - int i; - for (i=0;i<nclients;i++) { - if (state[i].con) { - PQfinish(state[i].con); - } - } +static void +disconnect_all(CState * state) +{ + int i; + + for (i = 0; i < nclients; i++) + { + if (state[i].con) + PQfinish(state[i].con); + } } /* create tables and setup data */ -static void init(char *pghost, char *pgport,char *dbName) { - PGconn *con; - PGresult *res; - static char *DDLs[] = { - "drop table branches", - "create table branches(bid int, primary key(bid),bbalance int,filler char(88))", - "drop table tellers", - "create table tellers(tid int, primary key(tid),bid int,tbalance int,filler char(84))", - "drop table accounts", - "create table accounts(aid int,primary key(aid),bid int,abalance int,filler char(84))", - "drop table history", - "create table history(tid int,bid int,aid int,delta int,time timestamp,filler char(22))"}; - char sql[256]; - - int i; - - con = PQsetdb(pghost, pgport, NULL, NULL, dbName); - if (PQstatus(con) == CONNECTION_BAD) { - fprintf(stderr, "Connection to database '%s' on %s failed.\n", dbName,pghost); - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - - for (i=0;i<(sizeof(DDLs)/sizeof(char *));i++) { - res = PQexec(con,DDLs[i]); - if (strncmp(DDLs[i],"drop",4) && PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - } - - res = PQexec(con,"begin"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - - for(i = 0; i < nbranches * tps; i++) { - sprintf(sql,"insert into branches(bid,bbalance) values(%d,0)",i+1); - res = PQexec(con,sql); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - } - - for(i = 0; i < ntellers * tps; i++) { - sprintf(sql,"insert into tellers(tid,bid,tbalance) values (%d,%d,0)" - ,i+1,i/ntellers+1); - res = PQexec(con,sql); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - } - - res = PQexec(con,"copy accounts from stdin"); - if (PQresultStatus(res) != PGRES_COPY_IN) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - - fprintf(stderr,"creating tables...\n"); - for(i = 0; i < naccounts*tps; i++) { - int j = i + 1; - sprintf(sql,"%d\t%d\t%d\t\n",i+1,(i+1)/naccounts,0); - if (PQputline(con,sql)) { - fprintf(stderr,"PQputline failed\n"); - exit(1); - } - if (j % 10000 == 0) { - fprintf(stderr,"%d tuples done.\n",j); - } - } - if (PQputline(con,"\\.\n")) { - fprintf(stderr,"very last PQputline failed\n"); - exit(1); - } - - if (PQendcopy(con)) { - fprintf(stderr,"PQendcopy failed\n"); - exit(1); - } - - res = PQexec(con,"end"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - - /* vacuum */ - fprintf(stderr,"vacuum..."); - res = PQexec(con,"vacuum analyze"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - fprintf(stderr,"done.\n"); - - PQfinish(con); -} +static void +init(char *pghost, char *pgport, char *dbName) +{ + PGconn *con; + PGresult *res; + static char *DDLs[] = { + "drop table branches", + "create table branches(bid int, primary key(bid),bbalance int,filler char(88))", + "drop table tellers", + "create table tellers(tid int, primary key(tid),bid int,tbalance int,filler char(84))", + "drop table accounts", + "create table accounts(aid int,primary key(aid),bid int,abalance int,filler char(84))", + "drop table history", + "create table history(tid int,bid int,aid int,delta int,time timestamp,filler char(22))"}; + char sql[256]; + + int i; + + con = PQsetdb(pghost, pgport, NULL, NULL, dbName); + if (PQstatus(con) == CONNECTION_BAD) + { + fprintf(stderr, "Connection to database '%s' on %s failed.\n", dbName, pghost); + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } -/* print out results */ -static void printResults( - int ttype, CState *state, - struct timeval *tv1,struct timeval *tv2, - struct timeval *tv3) { - double t1,t2; - int i; - int normal_xacts = 0; - - for (i=0;i<nclients;i++) { - normal_xacts += state[i].cnt; - } - - t1 = (tv3->tv_sec - tv1->tv_sec)*1000000.0+(tv3->tv_usec - tv1->tv_usec); - t1 = normal_xacts*1000000.0/t1; - - t2 = (tv3->tv_sec - tv2->tv_sec)*1000000.0+(tv3->tv_usec - tv2->tv_usec); - t2 = normal_xacts*1000000.0/t2; - - printf("transaction type: %s\n",ttype==0?"TPC-B (sort of)":"SELECT only"); - printf("scaling factor: %d\n",tps); - printf("number of clients: %d\n",nclients); - printf("number of transactions per client: %d\n",nxacts); - printf("number of transactions actually processed: %d/%d\n",normal_xacts,nxacts*nclients); - printf("tps = %f(including connections establishing)\n",t1); - printf("tps = %f(excluding connections establishing)\n",t2); -} + for (i = 0; i < (sizeof(DDLs) / sizeof(char *)); i++) + { + res = PQexec(con, DDLs[i]); + if (strncmp(DDLs[i], "drop", 4) && PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + } -int main(int argc, char **argv) { - extern char *optarg; - extern int optind, opterr, optopt; - int c; - char *pghost = ""; - char *pgport = ""; - char *dbName; - int is_init_mode = 0; /* initialize mode? */ - int is_no_vacuum = 0; /* no vacuum at all before testing? */ - int is_full_vacuum = 0; /* do full vacuum before testing? */ - int debug = 0; /* debug flag */ - int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only */ + res = PQexec(con, "begin"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } - static CState state[MAXCLIENTS]; /* clients status */ + for (i = 0; i < nbranches * tps; i++) + { + sprintf(sql, "insert into branches(bid,bbalance) values(%d,0)", i + 1); + res = PQexec(con, sql); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + } - struct timeval tv1; /* start up time */ - struct timeval tv2; /* after establishing all connections to the backend */ - struct timeval tv3; /* end time */ + for (i = 0; i < ntellers * tps; i++) + { + sprintf(sql, "insert into tellers(tid,bid,tbalance) values (%d,%d,0)" + ,i + 1, i / ntellers + 1); + res = PQexec(con, sql); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + } - int i; + res = PQexec(con, "copy accounts from stdin"); + if (PQresultStatus(res) != PGRES_COPY_IN) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + + fprintf(stderr, "creating tables...\n"); + for (i = 0; i < naccounts * tps; i++) + { + int j = i + 1; + + sprintf(sql, "%d\t%d\t%d\t\n", i + 1, (i + 1) / naccounts, 0); + if (PQputline(con, sql)) + { + fprintf(stderr, "PQputline failed\n"); + exit(1); + } + if (j % 10000 == 0) + fprintf(stderr, "%d tuples done.\n", j); + } + if (PQputline(con, "\\.\n")) + { + fprintf(stderr, "very last PQputline failed\n"); + exit(1); + } + + if (PQendcopy(con)) + { + fprintf(stderr, "PQendcopy failed\n"); + exit(1); + } + + res = PQexec(con, "end"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + + /* vacuum */ + fprintf(stderr, "vacuum..."); + res = PQexec(con, "vacuum analyze"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + fprintf(stderr, "done.\n"); + + PQfinish(con); +} - fd_set input_mask; - int nsocks; /* return from select(2) */ - int maxsock; /* max socket number to be waited */ +/* print out results */ +static void +printResults( + int ttype, CState * state, + struct timeval * tv1, struct timeval * tv2, + struct timeval * tv3) +{ + double t1, + t2; + int i; + int normal_xacts = 0; + + for (i = 0; i < nclients; i++) + normal_xacts += state[i].cnt; + + t1 = (tv3->tv_sec - tv1->tv_sec) * 1000000.0 + (tv3->tv_usec - tv1->tv_usec); + t1 = normal_xacts * 1000000.0 / t1; + + t2 = (tv3->tv_sec - tv2->tv_sec) * 1000000.0 + (tv3->tv_usec - tv2->tv_usec); + t2 = normal_xacts * 1000000.0 / t2; + + printf("transaction type: %s\n", ttype == 0 ? "TPC-B (sort of)" : "SELECT only"); + printf("scaling factor: %d\n", tps); + printf("number of clients: %d\n", nclients); + printf("number of transactions per client: %d\n", nxacts); + printf("number of transactions actually processed: %d/%d\n", normal_xacts, nxacts * nclients); + printf("tps = %f(including connections establishing)\n", t1); + printf("tps = %f(excluding connections establishing)\n", t2); +} + +int +main(int argc, char **argv) +{ + extern char *optarg; + extern int optind, + opterr, + optopt; + int c; + char *pghost = ""; + char *pgport = ""; + char *dbName; + int is_init_mode = 0; /* initialize mode? */ + int is_no_vacuum = 0; /* no vacuum at all before + * testing? */ + int is_full_vacuum = 0; /* do full vacuum before testing? */ + int debug = 0; /* debug flag */ + int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT + * only */ + + static CState state[MAXCLIENTS]; /* clients status */ + + struct timeval tv1; /* start up time */ + struct timeval tv2; /* after establishing all connections to + * the backend */ + struct timeval tv3; /* end time */ + + int i; + + fd_set input_mask; + int nsocks; /* return from select(2) */ + int maxsock; /* max socket number to be waited */ #ifndef __CYGWIN32__ - struct rlimit rlim; + struct rlimit rlim; + #endif - PGconn *con; - PGresult *res; - - while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:S")) != EOF) { - switch (c) { - case 'i': - is_init_mode++; - break; - case 'h': - pghost = optarg; - break; - case 'n': - is_no_vacuum++; - break; - case 'v': - is_full_vacuum++; - break; - case 'p': - pgport = optarg; - break; - case 'd': - debug++; - break; - case 'S': - ttype = 1; - break; - case 'c': - nclients = atoi(optarg); - if (nclients <= 0 || nclients > MAXCLIENTS) { - fprintf(stderr,"wrong number of clients: %d\n",nclients); - exit(1); - } + PGconn *con; + PGresult *res; + + while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:S")) != EOF) + { + switch (c) + { + case 'i': + is_init_mode++; + break; + case 'h': + pghost = optarg; + break; + case 'n': + is_no_vacuum++; + break; + case 'v': + is_full_vacuum++; + break; + case 'p': + pgport = optarg; + break; + case 'd': + debug++; + break; + case 'S': + ttype = 1; + break; + case 'c': + nclients = atoi(optarg); + if (nclients <= 0 || nclients > MAXCLIENTS) + { + fprintf(stderr, "wrong number of clients: %d\n", nclients); + exit(1); + } #ifndef __CYGWIN32__ -#ifdef RLIMIT_NOFILE /* most platform uses RLIMIT_NOFILE */ - if (getrlimit(RLIMIT_NOFILE,&rlim) == -1) { -#else /* but BSD doesn't ... */ - if (getrlimit(RLIMIT_OFILE,&rlim) == -1) { -#endif /* HAVE_RLIMIT_NOFILE */ - fprintf(stderr,"getrlimit failed. reason: %s\n",strerror(errno)); - exit(1); - } - if (rlim.rlim_cur <= (nclients+2)) { - fprintf(stderr,"You need at least %d open files resource but you are only allowed to use %ld.\n",nclients+2,rlim.rlim_cur); - fprintf(stderr,"Use limit/ulimt to increase the limit before using pgbench.\n"); - exit(1); - } -#endif /* #ifndef __CYGWIN32__ */ - break; - case 's': - tps = atoi(optarg); - if (tps <= 0) { - fprintf(stderr,"wrong scaling factor: %d\n",tps); - exit(1); - } - break; - case 't': - nxacts = atoi(optarg); - if (nxacts <= 0) { - fprintf(stderr,"wrong number of transactions: %d\n",nxacts); - exit(1); - } - break; - default: - usage(); - exit(1); - break; - } - } - - if (argc > optind) { - dbName = argv[optind]; - } else { - dbName = getenv("USER"); - if (dbName == NULL) { - dbName = ""; - } - } - - if (is_init_mode) { - init(pghost, pgport, dbName); - exit(0); - } - - remains = nclients; - - if (debug) { - printf("pghost: %s pgport: %s nclients: %d nxacts: %d dbName: %s\n", - pghost, pgport, nclients, nxacts, dbName); - } - - /* opening connection... */ - con = PQsetdb(pghost, pgport, NULL, NULL, dbName); - if (PQstatus(con) == CONNECTION_BAD) { - fprintf(stderr, "Connection to database '%s' failed.\n", dbName); - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - - /* get the scaling factor that should be same as count(*) from branches... */ - res = PQexec(con,"select count(*) from branches"); - if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - tps = atoi(PQgetvalue(res, 0, 0)); - if (tps < 0) { - fprintf(stderr,"count(*) from branches invalid (%d)\n",tps); - exit(1); - } - PQclear(res); - - if (!is_no_vacuum) { - fprintf(stderr,"starting vacuum..."); - res = PQexec(con,"vacuum branches"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - - res = PQexec(con,"vacuum tellers"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - - res = PQexec(con,"delete from history"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - res = PQexec(con,"vacuum history"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - - fprintf(stderr,"end.\n"); - - if (is_full_vacuum) { - fprintf(stderr,"starting full vacuum..."); - res = PQexec(con,"vacuum analyze accounts"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s", PQerrorMessage(con)); - exit(1); - } - PQclear(res); - fprintf(stderr,"end.\n"); - } - } - PQfinish(con); - - /* set random seed */ - gettimeofday(&tv1, 0); - srand((uint)tv1.tv_usec); - - /* get start up time */ - gettimeofday(&tv1, 0); - - /* make connections to the database */ - for (i=0;i<nclients;i++) { - state[i].con = PQsetdb(pghost, pgport, NULL, NULL, dbName); - if (PQstatus(state[i].con) == CONNECTION_BAD) { - fprintf(stderr, "Connection to database '%s' failed.\n", dbName); - fprintf(stderr, "%s", PQerrorMessage(state[i].con)); - exit(1); - } - } - - /* time after connections set up */ - gettimeofday(&tv2, 0); - - /* send start up quries in async manner */ - for (i=0;i<nclients;i++) { - if (ttype == 0) { - doOne(state, i, debug); - } else if (ttype == 1) { - doSelectOnly(state, i, debug); - } - } - - for (;;) { - if (remains <= 0) { /* all done ? */ - disconnect_all(state); - /* get end time */ - gettimeofday(&tv3, 0); - printResults(ttype, state, &tv1,&tv2,&tv3); - exit(0); - } - - FD_ZERO(&input_mask); - - maxsock = 0; - for (i=0;i<nclients;i++) { - if (state[i].con) { - int sock = PQsocket(state[i].con); - if (sock < 0) { - fprintf(stderr,"Client %d: PQsock failed\n",i); - disconnect_all(state); - exit(1); - } - FD_SET(sock, &input_mask); - if (maxsock < sock) { - maxsock = sock; - } - } - } - - if ((nsocks = select(maxsock +1, &input_mask, (fd_set *)NULL, - (fd_set *)NULL, (struct timeval *)NULL)) < 0) { - if (errno == EINTR) { - continue; - } - /* must be something wrong */ - disconnect_all(state); - fprintf(stderr,"select failed: %s\n",strerror(errno)); - exit(1); - } else if (nsocks == 0) { /* timeout */ - fprintf(stderr,"select timeout\n"); - for (i=0;i<nclients;i++) { - fprintf(stderr,"client %d:state %d cnt %d ecnt %d listen %d\n", - i,state[i].state,state[i].cnt,state[i].ecnt,state[i].listen); - } - exit(0); - } - - /* ok, backend returns reply */ - for (i=0;i<nclients;i++) { - if (state[i].con && FD_ISSET(PQsocket(state[i].con), &input_mask)) { - if (ttype == 0) { - doOne(state, i, debug); - } else if (ttype == 1) { - doSelectOnly(state, i, debug); - } - } - } - } +#ifdef RLIMIT_NOFILE /* most platform uses RLIMIT_NOFILE */ + if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) + { +#else /* but BSD doesn't ... */ + if (getrlimit(RLIMIT_OFILE, &rlim) == -1) + { +#endif /* HAVE_RLIMIT_NOFILE */ + fprintf(stderr, "getrlimit failed. reason: %s\n", strerror(errno)); + exit(1); + } + if (rlim.rlim_cur <= (nclients + 2)) + { + fprintf(stderr, "You need at least %d open files resource but you are only allowed to use %ld.\n", nclients + 2, rlim.rlim_cur); + fprintf(stderr, "Use limit/ulimt to increase the limit before using pgbench.\n"); + exit(1); + } +#endif /* #ifndef __CYGWIN32__ */ + break; + case 's': + tps = atoi(optarg); + if (tps <= 0) + { + fprintf(stderr, "wrong scaling factor: %d\n", tps); + exit(1); + } + break; + case 't': + nxacts = atoi(optarg); + if (nxacts <= 0) + { + fprintf(stderr, "wrong number of transactions: %d\n", nxacts); + exit(1); + } + break; + default: + usage(); + exit(1); + break; + } + } + + if (argc > optind) + dbName = argv[optind]; + else + { + dbName = getenv("USER"); + if (dbName == NULL) + dbName = ""; + } + + if (is_init_mode) + { + init(pghost, pgport, dbName); + exit(0); + } + + remains = nclients; + + if (debug) + { + printf("pghost: %s pgport: %s nclients: %d nxacts: %d dbName: %s\n", + pghost, pgport, nclients, nxacts, dbName); + } + + /* opening connection... */ + con = PQsetdb(pghost, pgport, NULL, NULL, dbName); + if (PQstatus(con) == CONNECTION_BAD) + { + fprintf(stderr, "Connection to database '%s' failed.\n", dbName); + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + + /* + * get the scaling factor that should be same as count(*) from + * branches... + */ + res = PQexec(con, "select count(*) from branches"); + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + tps = atoi(PQgetvalue(res, 0, 0)); + if (tps < 0) + { + fprintf(stderr, "count(*) from branches invalid (%d)\n", tps); + exit(1); + } + PQclear(res); + + if (!is_no_vacuum) + { + fprintf(stderr, "starting vacuum..."); + res = PQexec(con, "vacuum branches"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + + res = PQexec(con, "vacuum tellers"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + + res = PQexec(con, "delete from history"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + res = PQexec(con, "vacuum history"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + + fprintf(stderr, "end.\n"); + + if (is_full_vacuum) + { + fprintf(stderr, "starting full vacuum..."); + res = PQexec(con, "vacuum analyze accounts"); + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s", PQerrorMessage(con)); + exit(1); + } + PQclear(res); + fprintf(stderr, "end.\n"); + } + } + PQfinish(con); + + /* set random seed */ + gettimeofday(&tv1, 0); + srand((uint) tv1.tv_usec); + + /* get start up time */ + gettimeofday(&tv1, 0); + + /* make connections to the database */ + for (i = 0; i < nclients; i++) + { + state[i].con = PQsetdb(pghost, pgport, NULL, NULL, dbName); + if (PQstatus(state[i].con) == CONNECTION_BAD) + { + fprintf(stderr, "Connection to database '%s' failed.\n", dbName); + fprintf(stderr, "%s", PQerrorMessage(state[i].con)); + exit(1); + } + } + + /* time after connections set up */ + gettimeofday(&tv2, 0); + + /* send start up quries in async manner */ + for (i = 0; i < nclients; i++) + { + if (ttype == 0) + doOne(state, i, debug); + else if (ttype == 1) + doSelectOnly(state, i, debug); + } + + for (;;) + { + if (remains <= 0) + { /* all done ? */ + disconnect_all(state); + /* get end time */ + gettimeofday(&tv3, 0); + printResults(ttype, state, &tv1, &tv2, &tv3); + exit(0); + } + + FD_ZERO(&input_mask); + + maxsock = 0; + for (i = 0; i < nclients; i++) + { + if (state[i].con) + { + int sock = PQsocket(state[i].con); + + if (sock < 0) + { + fprintf(stderr, "Client %d: PQsock failed\n", i); + disconnect_all(state); + exit(1); + } + FD_SET(sock, &input_mask); + if (maxsock < sock) + maxsock = sock; + } + } + + if ((nsocks = select(maxsock + 1, &input_mask, (fd_set *) NULL, + (fd_set *) NULL, (struct timeval *) NULL)) < 0) + { + if (errno == EINTR) + continue; + /* must be something wrong */ + disconnect_all(state); + fprintf(stderr, "select failed: %s\n", strerror(errno)); + exit(1); + } + else if (nsocks == 0) + { /* timeout */ + fprintf(stderr, "select timeout\n"); + for (i = 0; i < nclients; i++) + { + fprintf(stderr, "client %d:state %d cnt %d ecnt %d listen %d\n", + i, state[i].state, state[i].cnt, state[i].ecnt, state[i].listen); + } + exit(0); + } + + /* ok, backend returns reply */ + for (i = 0; i < nclients; i++) + { + if (state[i].con && FD_ISSET(PQsocket(state[i].con), &input_mask)) + { + if (ttype == 0) + doOne(state, i, debug); + else if (ttype == 1) + doSelectOnly(state, i, debug); + } + } + } } diff --git a/contrib/string/string_io.c b/contrib/string/string_io.c index 9407e6a21b3..cb8323d9c9b 100644 --- a/contrib/string/string_io.c +++ b/contrib/string/string_io.c @@ -23,7 +23,7 @@ #define ISO8859 #define MIN(x, y) ((x) < (y) ? (x) : (y)) -#define VALUE(char) ((char) - '0') +#define VALUE(char) ((char) - '0') #define DIGIT(val) ((val) + '0') #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7')) #ifndef ISO8859 @@ -89,9 +89,8 @@ string_output(unsigned char *data, int size) break; case '{': /* Escape beginning of string, to distinguish from arrays */ - if (p == data) { + if (p == data) len++; - } break; default: if (NOTPRINTABLE(*p)) @@ -137,9 +136,8 @@ string_output(unsigned char *data, int size) break; case '{': /* Escape beginning of string, to distinguish from arrays */ - if (p == data) { + if (p == data) *r++ = '\\'; - } *r++ = c; break; default: @@ -361,14 +359,15 @@ c_charin(unsigned char *str) { return (string_input(str, 1, 0, NULL)); } + #endif /* end of file */ /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/string/string_io.h b/contrib/string/string_io.h index e79d7fd28fe..556c33660ce 100644 --- a/contrib/string/string_io.h +++ b/contrib/string/string_io.h @@ -1,24 +1,25 @@ #ifndef STRING_IO_H #define STRING_IO_H -unsigned char* string_output(unsigned char *data, int size); -unsigned char* string_input(unsigned char *str, int size, int hdrsize, - int *rtn_size); -unsigned char* c_charout(int32 c); -unsigned char* c_textout(struct varlena * vlena); -unsigned char* c_varcharout(unsigned char *s); +unsigned char *string_output(unsigned char *data, int size); +unsigned char *string_input(unsigned char *str, int size, int hdrsize, + int *rtn_size); +unsigned char *c_charout(int32 c); +unsigned char *c_textout(struct varlena * vlena); +unsigned char *c_varcharout(unsigned char *s); #if 0 -struct varlena* c_textin(unsigned char *str); -int32* c_charin(unsigned char *str) +struct varlena *c_textin(unsigned char *str); +int32 * +c_charin(unsigned char *str) #endif #endif /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/userlock/user_locks.c b/contrib/userlock/user_locks.c index 1a596d51540..1e37a54cf01 100644 --- a/contrib/userlock/user_locks.c +++ b/contrib/userlock/user_locks.c @@ -96,8 +96,8 @@ user_unlock_all() /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/userlock/user_locks.h b/contrib/userlock/user_locks.h index 3f0449e7e45..82ecb3b9ea0 100644 --- a/contrib/userlock/user_locks.h +++ b/contrib/userlock/user_locks.h @@ -13,8 +13,8 @@ int user_unlock_all(void); /* * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ |