Commit b2096a55 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Clean up directory to compile and run on my Linux box at least.

Note that there is some trouble with inconsistant input/output formats.
parent 71b4790b
ifndef PGDIR # Makefile
PGDIR= ../.. # For the bit/varbit data types
PGDIR=/data/build/postgresql-7.0beta3
endif
SRCDIR= $(PGDIR)/src SRCDIR= ../../src
include $(SRCDIR)/Makefile.global include $(SRCDIR)/Makefile.global
INSTALLDIR= $(LIBDIR)
MODDIR= $(INSTALLDIR)/modules
SQLDIR= $(INSTALLDIR)/sql
TARGETS= varbit.sql varbit$(DLSUFFIX) TARGETS= varbit.sql varbit$(DLSUFFIX)
# vartest # vartest
SOURCE= varbit.c varbit_glue.c SOURCE= varbit.c varbit_glue.c
...@@ -15,27 +17,24 @@ CFLAGS += -g ...@@ -15,27 +17,24 @@ CFLAGS += -g
all: $(TARGETS) all: $(TARGETS)
varbit$(DLSUFFIX): $(OBJ)
$(CC) $(CFLAGS) -shared -o varbit$(DLSUFFIX) $(SOURCE) $(CLIBS)
vartest: varbit.o vartest.o vartest: varbit.o vartest.o
$(CC) -o $@ varbit.o vartest.o $(CC) -o $@ varbit.o vartest.o
install: install:
$(MAKE) all $(MAKE) all
cp -p varbit$(DLSUFFIX) $(LIBDIR)/contrib -test -d $(INSTALLDIR) || $(INSTALL) -d $(INSTALLDIR)
chmod 555 $(LIBDIR)/contrib/varbit$(DLSUFFIX) -test -d ${MODDIR} || $(INSTALL) -d ${MODDIR}
-test -d ${SQLDIR} || $(INSTALL) -d ${SQLDIR}
$(INSTALL) -m 555 $(filter %$(DLSUFFIX), $(TARGETS)) $(MODDIR)
$(INSTALL) -m 664 $(filter %.sql, $(TARGETS)) $(SQLDIR)
%.sql: %.source %.sql: %.source
echo $(SRCDIR)
if [ -z "$$USER" ]; then USER=$$LOGNAME; fi; \ if [ -z "$$USER" ]; then USER=$$LOGNAME; fi; \
if [ -z "$$USER" ]; then USER=`whoami`; fi; \ if [ -z "$$USER" ]; then USER=`whoami`; fi; \
if [ -z "$$USER" ]; then echo 'Cannot deduce $$USER.'; exit 1; fi; \ if [ -z "$$USER" ]; then echo 'Cannot deduce $$USER.'; exit 1; fi; \
rm -f $@; \ rm -f $@; \
C=`pwd`; \ C=`pwd`; \
O=$C; \ O=${MODDIR}; \
if [ -d ${LIBDIR}/contrib ]; then O=${LIBDIR}/contrib; else \
echo "contrib directory does not exist."; fi; \
sed -e "s:_CWD_:$$C:g" \ sed -e "s:_CWD_:$$C:g" \
-e "s:_OBJWD_:$$O:g" \ -e "s:_OBJWD_:$$O:g" \
-e "s:_DLSUFFIX_:$(DLSUFFIX):g" \ -e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
......
#ifndef POSTGRES_H
#define POSTGRES_H
#include <stdio.h>
typedef char bool;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
/*#define NULL ((void *) 0)*/
#define Min(x, y) ((x) < (y) ? (x) : (y))
#define Max(x, y) ((x) > (y) ? (x) : (y))
#define PointerIsValid(pointer) (bool)((void*)(pointer) != NULL)
typedef unsigned int Oid;
typedef int16 int2;
typedef int32 int4;
typedef float float4;
typedef double float8;
typedef unsigned char uint8; /* == 8 bits */
typedef unsigned short uint16; /* == 16 bits */
typedef unsigned int uint32; /* == 32 bits */
typedef uint8 bits8; /* >= 8 bits */
typedef uint16 bits16; /* >= 16 bits */
typedef uint32 bits32; /* >= 32 bits */
typedef int4 aclitem;
#define InvalidOid 0
#define OidIsValid(objectId) ((bool) (objectId != InvalidOid))
/* unfortunately, both regproc and RegProcedure are used */
typedef Oid regproc;
typedef Oid RegProcedure;
typedef char *((*func_ptr) ());
#define RegProcedureIsValid(p) OidIsValid(p)
/* ----------------------------------------------------------------
* Section 2: variable length and array types
* ----------------------------------------------------------------
*/
/* ----------------
* struct varlena
* ----------------
*/
struct varlena
{
int32 vl_len;
char vl_dat[1];
};
#define VARSIZE(PTR) (((struct varlena *)(PTR))->vl_len)
#define VARDATA(PTR) (((struct varlena *)(PTR))->vl_dat)
#define VARHDRSZ sizeof(int32)
typedef struct varlena bytea;
typedef struct varlena text;
typedef int2 int28[8];
typedef Oid oid8[8];
#define ERROR stderr
#define elog fprintf
#define MaxAttrSize 10000
#define palloc malloc
#endif
create table bit_example (a bits, b bits); create table bit_example (a bit, b bit);
copy bit_example from stdin; copy bit_example from stdin;
X0F X10 X0F X10
X1F X11 X1F X11
......
#include "c.h" #include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <float.h> /* faked on sunos4 */
#include <math.h>
#include "postgres.h" #include "postgres.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#ifndef MAXINT
#define MAXINT INT_MAX
#endif
#else
#ifdef HAVE_VALUES_H
#include <values.h>
#endif
#endif
#include "fmgr.h"
#include "utils/timestamp.h"
#include "utils/builtins.h"
#define HEXDIG(z) (z)<10 ? ((z)+'0') : ((z)-10+'A') #define HEXDIG(z) (z)<10 ? ((z)+'0') : ((z)-10+'A')
......
LOAD '_OBJWD_/varbit.so'; LOAD '_OBJWD_/varbit.so';
CREATE FUNCTION varbit_in(opaque) CREATE FUNCTION varbitin(opaque)
RETURNS bit RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'c'; LANGUAGE 'c';
CREATE FUNCTION varbit_out(opaque) CREATE FUNCTION zpbitout(opaque)
RETURNS opaque RETURNS opaque
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'c'; LANGUAGE 'c';
CREATE TYPE bits ( CREATE TYPE bit (
internallength = -1, internallength = -1,
input = varbit_in, input = varbitin,
output = varbit_out output = zpbitout
); );
CREATE FUNCTION bitcat(bits,bits) RETURNS bits CREATE FUNCTION bitcat(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR || ( CREATE OPERATOR || (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitcat procedure = bitcat
); );
CREATE FUNCTION bitsubstr(bits,integer,integer) RETURNS bits CREATE FUNCTION bitsubstr(bit,integer,integer) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE FUNCTION biteq(bits,bits) RETURNS bool CREATE FUNCTION biteq(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR = ( CREATE OPERATOR = (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = biteq, procedure = biteq,
negator = <>, negator = <>,
commutator = = commutator = =
); );
CREATE FUNCTION bitne(bits,bits) RETURNS bool CREATE FUNCTION bitne(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR <> ( CREATE OPERATOR <> (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitne, procedure = bitne,
negator = =, negator = =,
commutator = <> commutator = <>
); );
CREATE FUNCTION bitlt(bits,bits) RETURNS bool CREATE FUNCTION bitlt(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR < ( CREATE OPERATOR < (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitlt procedure = bitlt
); );
CREATE FUNCTION bitle(bits,bits) RETURNS bool CREATE FUNCTION bitle(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR <= ( CREATE OPERATOR <= (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitle procedure = bitle
); );
CREATE FUNCTION bitgt(bits,bits) RETURNS bool CREATE FUNCTION bitgt(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR > ( CREATE OPERATOR > (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitgt, procedure = bitgt,
negator = <=, negator = <=,
commutator = < commutator = <
); );
CREATE FUNCTION bitge(bits,bits) RETURNS bool CREATE FUNCTION bitge(bit,bit) RETURNS bool
as '_OBJWD_/varbit.so' as '_OBJWD_/varbit.so'
language 'C'; language 'C';
CREATE OPERATOR >= ( CREATE OPERATOR >= (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitge, procedure = bitge,
negator = <, negator = <,
commutator = <= commutator = <=
); );
CREATE FUNCTION bitcmp(bits,bits) RETURNS int4 CREATE FUNCTION bitcmp(bit,bit) RETURNS integer
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR <=> ( CREATE OPERATOR <=> (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitcmp procedure = bitcmp
); );
CREATE FUNCTION bitor(bits,bits) RETURNS bits CREATE FUNCTION bitor(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR | ( CREATE OPERATOR | (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitor, procedure = bitor,
commutator = | commutator = |
); );
CREATE FUNCTION bitand(bits,bits) RETURNS bits CREATE FUNCTION bitand(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR & ( CREATE OPERATOR & (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitand, procedure = bitand,
commutator = & commutator = &
); );
CREATE FUNCTION bitxor(bits,bits) RETURNS bits CREATE FUNCTION bitxor(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR ^ ( CREATE OPERATOR ^ (
leftarg = bits, leftarg = bit,
rightarg = bits, rightarg = bit,
procedure = bitxor procedure = bitxor
); );
CREATE FUNCTION bitnot(bits) RETURNS bits CREATE FUNCTION bitnot(bit) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR ~ ( CREATE OPERATOR ~ (
rightarg = bits, rightarg = bit,
procedure = bitnot procedure = bitnot
); );
CREATE FUNCTION bitshiftleft(bits,int4) RETURNS bits CREATE FUNCTION bitshiftleft(bit,integer) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR << ( CREATE OPERATOR << (
leftarg = bits, leftarg = bit,
rightarg = int4, rightarg = integer,
procedure = bitshiftleft procedure = bitshiftleft
); );
CREATE FUNCTION bitshiftright(bits,int4) RETURNS bits CREATE FUNCTION bitshiftright(bit,integer) RETURNS bit
AS '_OBJWD_/varbit.so' AS '_OBJWD_/varbit.so'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE OPERATOR >> ( CREATE OPERATOR >> (
leftarg = bits, leftarg = bit,
rightarg = int4, rightarg = integer,
procedure = bitshiftright procedure = bitshiftright
); );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment