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
PGDIR= ../..
PGDIR=/data/build/postgresql-7.0beta3
endif
# Makefile
# For the bit/varbit data types
SRCDIR= $(PGDIR)/src
SRCDIR= ../../src
include $(SRCDIR)/Makefile.global
INSTALLDIR= $(LIBDIR)
MODDIR= $(INSTALLDIR)/modules
SQLDIR= $(INSTALLDIR)/sql
TARGETS= varbit.sql varbit$(DLSUFFIX)
# vartest
SOURCE= varbit.c varbit_glue.c
......@@ -15,27 +17,24 @@ 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)
-test -d $(INSTALLDIR) || $(INSTALL) -d $(INSTALLDIR)
-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
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; \
O=${MODDIR}; \
sed -e "s:_CWD_:$$C:g" \
-e "s:_OBJWD_:$$O: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;
X0F X10
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"
#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')
......
LOAD '_OBJWD_/varbit.so';
CREATE FUNCTION varbit_in(opaque)
CREATE FUNCTION varbitin(opaque)
RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'c';
CREATE FUNCTION varbit_out(opaque)
CREATE FUNCTION zpbitout(opaque)
RETURNS opaque
AS '_OBJWD_/varbit.so'
LANGUAGE 'c';
CREATE TYPE bits (
CREATE TYPE bit (
internallength = -1,
input = varbit_in,
output = varbit_out
input = varbitin,
output = zpbitout
);
CREATE FUNCTION bitcat(bits,bits) RETURNS bits
CREATE FUNCTION bitcat(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR || (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitcat
);
CREATE FUNCTION bitsubstr(bits,integer,integer) RETURNS bits
CREATE FUNCTION bitsubstr(bit,integer,integer) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE FUNCTION biteq(bits,bits) RETURNS bool
CREATE FUNCTION biteq(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR = (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = biteq,
negator = <>,
commutator = =
);
CREATE FUNCTION bitne(bits,bits) RETURNS bool
CREATE FUNCTION bitne(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR <> (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitne,
negator = =,
commutator = <>
);
CREATE FUNCTION bitlt(bits,bits) RETURNS bool
CREATE FUNCTION bitlt(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR < (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitlt
);
CREATE FUNCTION bitle(bits,bits) RETURNS bool
CREATE FUNCTION bitle(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR <= (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitle
);
CREATE FUNCTION bitgt(bits,bits) RETURNS bool
CREATE FUNCTION bitgt(bit,bit) RETURNS bool
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR > (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitgt,
negator = <=,
commutator = <
);
CREATE FUNCTION bitge(bits,bits) RETURNS bool
CREATE FUNCTION bitge(bit,bit) RETURNS bool
as '_OBJWD_/varbit.so'
language 'C';
CREATE OPERATOR >= (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitge,
negator = <,
commutator = <=
);
CREATE FUNCTION bitcmp(bits,bits) RETURNS int4
CREATE FUNCTION bitcmp(bit,bit) RETURNS integer
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR <=> (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitcmp
);
CREATE FUNCTION bitor(bits,bits) RETURNS bits
CREATE FUNCTION bitor(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR | (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitor,
commutator = |
);
CREATE FUNCTION bitand(bits,bits) RETURNS bits
CREATE FUNCTION bitand(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR & (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitand,
commutator = &
);
CREATE FUNCTION bitxor(bits,bits) RETURNS bits
CREATE FUNCTION bitxor(bit,bit) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR ^ (
leftarg = bits,
rightarg = bits,
leftarg = bit,
rightarg = bit,
procedure = bitxor
);
CREATE FUNCTION bitnot(bits) RETURNS bits
CREATE FUNCTION bitnot(bit) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR ~ (
rightarg = bits,
rightarg = bit,
procedure = bitnot
);
CREATE FUNCTION bitshiftleft(bits,int4) RETURNS bits
CREATE FUNCTION bitshiftleft(bit,integer) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR << (
leftarg = bits,
rightarg = int4,
leftarg = bit,
rightarg = integer,
procedure = bitshiftleft
);
CREATE FUNCTION bitshiftright(bits,int4) RETURNS bits
CREATE FUNCTION bitshiftright(bit,integer) RETURNS bit
AS '_OBJWD_/varbit.so'
LANGUAGE 'C';
CREATE OPERATOR >> (
leftarg = bits,
rightarg = int4,
leftarg = bit,
rightarg = integer,
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