diff --git a/contrib/bit/Makefile b/contrib/bit/Makefile index 9603cba27f8..96e751d0c18 100644 --- a/contrib/bit/Makefile +++ b/contrib/bit/Makefile @@ -1,10 +1,46 @@ -CFLAGS = -g +ifndef PGDIR +PGDIR= ../.. +PGDIR=/data/build/postgresql-7.0beta3 +endif -varbit: vartest.o varbit.o - $(CC) $(CFLAGS) -o $@ $^ +SRCDIR= $(PGDIR)/src -varbit.o: varbit.c varbit.h -vartest.o: vartest.c varbit.h +include $(SRCDIR)/Makefile.global + +TARGETS= varbit.sql varbit$(DLSUFFIX) +# vartest +SOURCE= varbit.c varbit_glue.c +OBJ= $(SOURCE:.c=.o) +CFLAGS += -g + +all: $(TARGETS) + +varbit$(DLSUFFIX): $(OBJ) + $(CC) $(CFLAGS) -shared -o varbit$(DLSUFFIX) $(SOURCE) $(CLIBS) + +vartest: varbit.o vartest.o + $(CC) -o $@ varbit.o vartest.o + +install: + $(MAKE) all + cp -p varbit$(DLSUFFIX) $(LIBDIR)/contrib + chmod 555 $(LIBDIR)/contrib/varbit$(DLSUFFIX) + +%.sql: %.source + echo $(SRCDIR) + if [ -z "$$USER" ]; then USER=$$LOGNAME; fi; \ + if [ -z "$$USER" ]; then USER=`whoami`; fi; \ + if [ -z "$$USER" ]; then echo 'Cannot deduce $$USER.'; exit 1; fi; \ + rm -f $@; \ + C=`pwd`; \ + O=$C; \ + if [ -d ${LIBDIR}/contrib ]; then O=${LIBDIR}/contrib; else \ + echo "contrib directory does not exist."; fi; \ + sed -e "s:_CWD_:$$C:g" \ + -e "s:_OBJWD_:$$O:g" \ + -e "s:_DLSUFFIX_:$(DLSUFFIX):g" \ + -e "s/_USER_/$$USER/g" < $< > $@ + +clean: + rm -f $(TARGETS) varbit.o -clean: - rm -f *.o varbit diff --git a/contrib/bit/README b/contrib/bit/README index b2ddb904b30..18a1fe1820b 100644 --- a/contrib/bit/README +++ b/contrib/bit/README @@ -7,9 +7,6 @@ make this code as independent as possible of the byte length, but it is quite possible that there may be problems on machines that don't have 8 bits/byte (are there still any around?). -In the input routines I have assumed that the parser eats the quotes -in B'...' or X'...'. - The SQL standard only defines comparison, SUBSTR and concatenation operators, and these have been implemented. In addition all logical operators have been implemented, i.e. ~,|,&,^,<< and >>. This is diff --git a/contrib/bit/varbit.c b/contrib/bit/varbit.c index 257f9766fd6..2a677ec6040 100644 --- a/contrib/bit/varbit.c +++ b/contrib/bit/varbit.c @@ -4,18 +4,14 @@ * Functions for the built-in type bit() and varying bit(). * * IDENTIFICATION - * $Header: /cvsroot/pgsql/contrib/bit/Attic/varbit.c,v 1.1 1999/11/29 22:34:36 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/bit/Attic/varbit.c,v 1.2 2000/04/03 20:56:40 momjian Exp $ * *------------------------------------------------------------------------- */ -#include "postgres.h" #include "varbit.h" -/* #include "access/htup.h" -#include "catalog/pg_type.h" -#include "utils/builtins.h" -*/ - +/*#include "catalog/pg_type.h" */ +/*#include "utils/builtins.h" */ /* @@ -43,22 +39,22 @@ * (XXX dummy is here because we pass typelem as the second argument * for array_in. copied this, no idea what it means??) */ -char * +bits8 * zpbitin(char *s, int dummy, int32 atttypmod) { - char *result, - *sp; /* pointer into the character string */ + 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 = hex string 1=bit string */ - int i, bc, ipad; - bits8 x, y; + int bit_not_hex = 0; /* 0 = hex string 1=bit string */ + int bc, ipad; + bits8 x = 0; if (s == NULL) - return NULL; + return (bits8 *) NULL; /* Check that the first character is a b or an x */ if (s[0]=='b' || s[0]=='B') @@ -82,7 +78,8 @@ zpbitin(char *s, int dummy, int32 atttypmod) if (atttypmod == -1) atttypmod = bitlen; else - if (bitlen>atttypmod && bit_not_hex || bitlen>atttypmod+3 && !bit_not_hex) + 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); @@ -90,10 +87,10 @@ zpbitin(char *s, int dummy, int32 atttypmod) len = VARBITDATALEN(atttypmod); if (len > MaxAttrSize) - elog(ERROR, "zpbitin: length of bit() must be less than %d", + elog(ERROR, "zpbitin: length of bit() must be less than %ld", (MaxAttrSize-VARHDRSZ-VARBITHDRSZ)*BITSPERBYTE); - result = (char *) palloc(len); + 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; @@ -103,7 +100,7 @@ zpbitin(char *s, int dummy, int32 atttypmod) significant byte first. s points to the byte before the beginning of the bitstring */ sp = s+1; - r = (bits8 *) VARBITS(result); + r = VARBITS(result); if (bit_not_hex) { /* Parse the bit representation of the string */ @@ -166,10 +163,10 @@ zpbitin(char *s, int dummy, int32 atttypmod) * for long strings */ char * -zpbitout(char *s) +zpbitout(bits8 *s) { char *result, *r; - VarBit sp; + bits8 *sp; int i, len, bitlen; if (s == NULL) @@ -183,7 +180,7 @@ zpbitout(char *s) bitlen = VARBITLEN(s); len = bitlen/4 + (bitlen%4>0 ? 1 : 0); result = (char *) palloc(len + 4); - sp = (bits8 *) VARBITS(s); + sp = VARBITS(s); r = result; *r++ = 'X'; *r++ = '\''; @@ -206,10 +203,10 @@ zpbitout(char *s) * Prints the string a bits */ char * -zpbitsout(char *s) +zpbitsout(bits8 *s) { char *result, *r; - VarBit sp; + bits8 *sp; bits8 x; int i, k, len; @@ -223,7 +220,7 @@ zpbitsout(char *s) { len = VARBITLEN(s); result = (char *) palloc(len + 4); - sp = (bits8 *) VARBITS(s); + sp = VARBITS(s); r = result; *r++ = 'B'; *r++ = '\''; @@ -252,22 +249,22 @@ zpbitsout(char *s) * varbitin - * converts a string to the internal representation of a bitstring. */ -char * +bits8 * varbitin(char *s, int dummy, int32 atttypmod) { - char *result, - *sp; /* pointer into the character string */ + 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; - int i, bc, ipad; - bits8 x, y; + int bit_not_hex = 0; + int bc, ipad; + bits8 x = 0; if (s == NULL) - return NULL; + return (bits8 *) NULL; /* Check that the first character is a b or an x */ if (s[0]=='b' || s[0]=='B') @@ -289,7 +286,8 @@ varbitin(char *s, int dummy, int32 atttypmod) 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) + 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); @@ -297,10 +295,10 @@ varbitin(char *s, int dummy, int32 atttypmod) len = VARBITDATALEN(bitlen); if (len > MaxAttrSize) - elog(ERROR, "varbitin: length of bit() must be less than %d", + elog(ERROR, "varbitin: length of bit() must be less than %ld", (MaxAttrSize-VARHDRSZ-VARBITHDRSZ)*BITSPERBYTE); - result = (char *) palloc(len); + 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; @@ -310,7 +308,7 @@ varbitin(char *s, int dummy, int32 atttypmod) significant byte first. s points to the byte before the beginning of the bitstring */ sp = s + 1; - r = (VarBit) VARBITS(result); + r = VARBITS(result); if (bit_not_hex) { /* Parse the bit representation of the string */ @@ -383,11 +381,10 @@ varbitin(char *s, int dummy, int32 atttypmod) */ bool -biteq (char *arg1, char *arg2) +biteq (bits8 *arg1, bits8 *arg2) { int bitlen1, bitlen2; - bits8 *p1, *p2; if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) return (bool) 0; @@ -402,11 +399,10 @@ biteq (char *arg1, char *arg2) } bool -bitne (char *arg1, char *arg2) +bitne (bits8 *arg1, bits8 *arg2) { int bitlen1, bitlen2; - bits8 *p1, *p2; if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) return (bool) 0; @@ -429,11 +425,10 @@ bitne (char *arg1, char *arg2) * Anything is equal to undefined. */ int -bitcmp (char *arg1, char *arg2) +bitcmp (bits8 *arg1, bits8 *arg2) { int bitlen1, bytelen1, bitlen2, bytelen2; - bits8 *p1, *p2; int cmp; if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) @@ -452,25 +447,25 @@ bitcmp (char *arg1, char *arg2) } bool -bitlt (char *arg1, char *arg2) +bitlt (bits8 *arg1, bits8 *arg2) { return (bool) (bitcmp(arg1,arg2) == -1); } bool -bitle (char *arg1, char *arg2) +bitle (bits8 *arg1, bits8 *arg2) { return (bool) (bitcmp(arg1,arg2) <= 0); } bool -bitge (char *arg1, char *arg2) +bitge (bits8 *arg1, bits8 *arg2) { return (bool) (bitcmp(arg1,arg2) >= 0); } bool -bitgt (char *arg1, char *arg2) +bitgt (bits8 *arg1, bits8 *arg2) { return (bool) (bitcmp(arg1,arg2) == 1); } @@ -478,11 +473,11 @@ bitgt (char *arg1, char *arg2) /* bitcat * Concatenation of bit strings */ -char * -bitcat (char *arg1, char *arg2) +bits8 * +bitcat (bits8 *arg1, bits8 *arg2) { int bitlen1, bitlen2, bytelen, bit1pad, bit2shift; - char *result; + bits8 *result; bits8 *pr, *pa; if (!PointerIsValid(arg1) || !PointerIsValid(arg2)) @@ -493,7 +488,7 @@ bitcat (char *arg1, char *arg2) bytelen = VARBITDATALEN(bitlen1+bitlen2); - result = (char *) palloc(bytelen*sizeof(bits8)); + result = (bits8 *) palloc(bytelen*sizeof(bits8)); VARSIZE(result) = bytelen; VARBITLEN(result) = bitlen1+bitlen2; printf("%d %d %d \n",VARBITBYTES(arg1),VARBITLEN(arg1),VARBITPAD(arg1)); @@ -510,10 +505,10 @@ bitcat (char *arg1, char *arg2) { /* We need to shift all the results to fit */ bit2shift = BITSPERBYTE - bit1pad; - pa = (VarBit) VARBITS(arg2); - pr = (VarBit) VARBITS(result)+VARBITBYTES(arg1)-1; + pa = VARBITS(arg2); + pr = VARBITS(result)+VARBITBYTES(arg1)-1; for ( ; pa < VARBITEND(arg2); pa++) { - *pr = *pr | ((*pa >> bit2shift) & BITMASK); + *pr |= ((*pa >> bit2shift) & BITMASK); pr++; if (pr < VARBITEND(result)) *pr = (*pa << bit1pad) & BITMASK; @@ -528,17 +523,17 @@ bitcat (char *arg1, char *arg2) * Note, s is 1-based. * SQL draft 6.10 9) */ -char * -bitsubstr (char *arg, int32 s, int32 l) +bits8 * +bitsubstr (bits8 *arg, int32 s, int32 l) { int bitlen, rbitlen, len, - ipad, + ipad = 0, ishift, i; int e, s1, e1; - char * result; + bits8 * result; bits8 mask, *r, *ps; if (!PointerIsValid(arg)) @@ -552,7 +547,7 @@ bitsubstr (char *arg, int32 s, int32 l) { /* Need to return a null string */ len = VARBITDATALEN(0); - result = (char *) palloc(len); + result = (bits8 *) palloc(len); VARBITLEN(result) = 0; VARSIZE(result) = len; } @@ -562,22 +557,22 @@ bitsubstr (char *arg, int32 s, int32 l) ending at position e1-1 */ rbitlen = e1-s1; len = VARBITDATALEN(rbitlen); - result = (char *) palloc(len); + 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 */ - len -= VARHDRSZ + VARBITHDRSZ; 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 = (VarBit) VARBITS(result); - ps = (VarBit) VARBITS(arg) + (s1-1)/BITSPERBYTE; + r = VARBITS(result); + ps = VARBITS(arg) + (s1-1)/BITSPERBYTE; for (i=0; i=b as "a>=b",a>b as "a>b",a<=>b as "a<=>b" from bit_example; +select a,a<<4 as "a<<4",b,b>>2 as "b>>2" from bit_example; +select a,b,a||b as "a||b", bitsubstr(a,4,4) as "sub(a,4,4)", + bitsubstr(b,2,4) as "sub(b,2,4)", + bitsubstr(b,5,5) as "sub(b,5,5)" + from bit_example; + +drop table bit_example; diff --git a/contrib/bit/varbit.drop.sql b/contrib/bit/varbit.drop.sql new file mode 100644 index 00000000000..54b831ea2dc --- /dev/null +++ b/contrib/bit/varbit.drop.sql @@ -0,0 +1,36 @@ +DROP FUNCTION biteq(bits,bits); +DROP OPERATOR = (bits,bits); +DROP FUNCTION bitne(bits,bits); +DROP OPERATOR <> (bits,bits); +DROP FUNCTION bitlt(bits,bits); +DROP OPERATOR < (bits,bits); +DROP FUNCTION bitle(bits,bits); +DROP OPERATOR <= (bits,bits); +DROP FUNCTION bitgt(bits,bits); +DROP OPERATOR > (bits,bits); +DROP FUNCTION bitge(bits,bits); +DROP OPERATOR >= (bits,bits); +DROP FUNCTION bitcmp(bits,bits); +DROP OPERATOR <=> (bits,bits); + +DROP FUNCTION bitor(bits,bits); +DROP OPERATOR | (bits,bits); +DROP FUNCTION bitand(bits,bits); +DROP OPERATOR & (bits,bits); +DROP FUNCTION bitxor(bits,bits); +DROP OPERATOR ^ (bits,bits); +DROP FUNCTION bitnot(bits); +DROP OPERATOR ~ (none,bits); + +DROP FUNCTION bitshiftleft(bits,int4); +DROP OPERATOR << (bits,int4); +DROP FUNCTION bitshiftright(bits,int4); +DROP OPERATOR >> (bits,int4); + +DROP FUNCTION bitsubstr(bits,integer,integer); +DROP OPERATOR || (bits,bits); +DROP FUNCTION bitcat(bits,bits); + +DROP FUNCTION varbit_in(opaque); +DROP FUNCTION varbit_out(opaque); +DROP TYPE bits; diff --git a/contrib/bit/varbit.h b/contrib/bit/varbit.h index af55f486ea3..44007ad10a9 100644 --- a/contrib/bit/varbit.h +++ b/contrib/bit/varbit.h @@ -1,17 +1,21 @@ +#include "c.h" #include "postgres.h" -typedef bits8 *VarBit; -typedef uint32 BitIndex; - #define HEXDIG(z) (z)<10 ? ((z)+'0') : ((z)-10+'A') +/* Modeled on struct varlena from postgres.h, bu data type is bits8 */ +struct varbita +{ + int32 vl_len; + bits8 vl_dat[1]; +}; #define BITSPERBYTE 8 #define VARBITHDRSZ sizeof(int32) /* Number of bits in this bit string */ -#define VARBITLEN(PTR) (((struct varlena *)VARDATA(PTR))->vl_len) +#define VARBITLEN(PTR) (((struct varbita *)VARDATA(PTR))->vl_len) /* Pointer tp the first byte containing bit string data */ -#define VARBITS(PTR) (((struct varlena *)VARDATA(PTR))->vl_dat) +#define VARBITS(PTR) (((struct varbita *)VARDATA(PTR))->vl_dat) /* Number of bytes in the data section of a bit string */ #define VARBITBYTES(PTR) (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ) /* Padding of the bit string at the end */ @@ -27,22 +31,22 @@ typedef uint32 BitIndex; #define BITHIGH 0x80 -char * zpbitin(char *s, int dummy, int32 atttypmod); -char * zpbitout(char *s); -char * zpbitsout(char *s); -char * varbitin(char *s, int dummy, int32 atttypmod); -bool biteq (char *arg1, char *arg2); -bool bitne (char *arg1, char *arg2); -bool bitge (char *arg1, char *arg2); -bool bitgt (char *arg1, char *arg2); -bool bitle (char *arg1, char *arg2); -bool bitlt (char *arg1, char *arg2); -int bitcmp (char *arg1, char *arg2); -char * bitand (char * arg1, char * arg2); -char * bitor (char * arg1, char * arg2); -char * bitxor (char * arg1, char * arg2); -char * bitnot (char * arg); -char * bitshiftright (char * arg, int shft); -char * bitshiftleft (char * arg, int shft); -char * bitcat (char *arg1, char *arg2); -char * bitsubstr (char *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.source b/contrib/bit/varbit.source new file mode 100644 index 00000000000..8b9dc29aab5 --- /dev/null +++ b/contrib/bit/varbit.source @@ -0,0 +1,171 @@ +LOAD '_OBJWD_/varbit.so'; + +CREATE FUNCTION varbit_in(opaque) + RETURNS bit + AS '_OBJWD_/varbit.so' + LANGUAGE 'c'; + +CREATE FUNCTION varbit_out(opaque) + RETURNS opaque + AS '_OBJWD_/varbit.so' + LANGUAGE 'c'; + +CREATE TYPE bits ( + internallength = -1, + input = varbit_in, + output = varbit_out +); + +CREATE FUNCTION bitcat(bits,bits) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR || ( + leftarg = bits, + rightarg = bits, + procedure = bitcat +); + +CREATE FUNCTION bitsubstr(bits,integer,integer) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE FUNCTION biteq(bits,bits) RETURNS bool + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR = ( + leftarg = bits, + rightarg = bits, + procedure = biteq, + negator = <>, + commutator = = +); + +CREATE FUNCTION bitne(bits,bits) RETURNS bool + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR <> ( + leftarg = bits, + rightarg = bits, + procedure = bitne, + negator = =, + commutator = <> +); + +CREATE FUNCTION bitlt(bits,bits) RETURNS bool + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR < ( + leftarg = bits, + rightarg = bits, + procedure = bitlt +); + +CREATE FUNCTION bitle(bits,bits) RETURNS bool + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR <= ( + leftarg = bits, + rightarg = bits, + procedure = bitle +); + +CREATE FUNCTION bitgt(bits,bits) RETURNS bool + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR > ( + leftarg = bits, + rightarg = bits, + procedure = bitgt, + negator = <=, + commutator = < +); + +CREATE FUNCTION bitge(bits,bits) RETURNS bool + as '_OBJWD_/varbit.so' + language 'C'; + +CREATE OPERATOR >= ( + leftarg = bits, + rightarg = bits, + procedure = bitge, + negator = <, + commutator = <= +); + +CREATE FUNCTION bitcmp(bits,bits) RETURNS int4 + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR <=> ( + leftarg = bits, + rightarg = bits, + procedure = bitcmp +); + +CREATE FUNCTION bitor(bits,bits) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR | ( + leftarg = bits, + rightarg = bits, + procedure = bitor, + commutator = | +); + +CREATE FUNCTION bitand(bits,bits) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR & ( + leftarg = bits, + rightarg = bits, + procedure = bitand, + commutator = & +); + + +CREATE FUNCTION bitxor(bits,bits) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR ^ ( + leftarg = bits, + rightarg = bits, + procedure = bitxor +); + +CREATE FUNCTION bitnot(bits) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR ~ ( + rightarg = bits, + procedure = bitnot +); + +CREATE FUNCTION bitshiftleft(bits,int4) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR << ( + leftarg = bits, + rightarg = int4, + procedure = bitshiftleft +); + +CREATE FUNCTION bitshiftright(bits,int4) RETURNS bits + AS '_OBJWD_/varbit.so' + LANGUAGE 'C'; + +CREATE OPERATOR >> ( + leftarg = bits, + rightarg = int4, + procedure = bitshiftright +); diff --git a/contrib/bit/varbit_glue.c b/contrib/bit/varbit_glue.c new file mode 100644 index 00000000000..29b7debd03c --- /dev/null +++ b/contrib/bit/varbit_glue.c @@ -0,0 +1,22 @@ +/* Glue file to use varbit before it is properly integrated with postgres */ + +#include "varbit.h" + +bits8 * varbit_in (char * s); +char * varbit_out (bits8 *s); + +bits8 * +varbit_in (char * s) { + return varbitin (s, 0, -1); +} + +/*char * +varbit_out (bits8 *s) { + return zpbitout(s); +} +*/ + +char * +varbit_out (bits8 *s) { + return zpbitsout(s); +} diff --git a/contrib/bit/vartest.c b/contrib/bit/vartest.c index 732141e8df4..f07f5c5b833 100644 --- a/contrib/bit/vartest.c +++ b/contrib/bit/vartest.c @@ -2,6 +2,8 @@ #include "varbit.h" #include +void print_details (unsigned char *s); + const int numb = 8; /* const char *b[] = { "B0010", "B11011011", "B0001", "X3F12", "X27", "B", @@ -23,13 +25,13 @@ void print_details (unsigned char *s) printf("\n"); } -void +int main () { int i, j; char *s[numb]; - for (i=0; i %s\n",zpbitsout(s[3]),9,8, zpbitsout(bitsubstr(s[3],9,8))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),1,9, + 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, + 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, + 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, + 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 %s\n",zpbitsout(s[3]),9,8, zpbitsout(bitsubstr(s[3],9,8))); - printf("%s (%d,%d) => %s\n",zpbitsout(s[3]),1,9, + 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, + 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, + 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("%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