home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
125.img
/
PRO-C4.ZIP
/
BENCH1.ZIP
/
BENCH
/
PROTREE.H
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-28
|
15KB
|
378 lines
/***( io8.h )****************************************************************
* Pro-TREE Prototypes and Definitions *
*****************************************************************************
* *
* Pro-TREE v1.10 - Copyright (c) 1988, 1990 Vestronix Inc. *
* *
* Features: *
* - Dynamic leveling *
* - Free list for data file and each key in the index file *
* - Single-user or Multi-user with appropriate index file locking *
* - Single record locking on the data file *
* *
* Original : NIG 24-Feb-88, GEO 23-Mar-88, VVA Dec-88 (indexing functs) *
* Changed : JZ Apr-89 *
* Changed : BRC 4-Dec-89 (dynamic levels, free space reuse) *
* *
****************************************************************************/
#include <stdio.h>
#include <iodef.h>
#include <proc.io>
#include <bench.h>
#include <iosup.h>
#include <procerr.h>
#include <fileio.h>
/*#include <memchk.h>*/
/****************************************************************************
* Machine Specific Definitions -- SHOULD BE SET FOR EACH NEW MACHINE/OS *
*---------------------------------------------------------------------------*
* Use PROTEST to determine the correct settings for the following *
****************************************************************************/
#define NO_MULTI_USER /* record locking is enabled if defined */
#define SWAP_WORD8 /* pairs of bytes are swapped */
#define SWAP_WORD16 /* pairs of 2-byte words are swapped */
#define NO_SWAP_WORD32 /* pairs of 4-byte long words are swapped */
#define WORD8 char /* type for a one byte integer */
#define WORD16 short /* type for a two byte integer */
#define WORD32 long /* type for a four byte integer */
#define FLOAT32 float /* type for a four byte integer */
#define FLOAT64 double /* type for a four byte integer */
#define NO_LOCKDEBUG
/****************************************************************************
* Global Definitions and Macros *
*---------------------------------------------------------------------------*
* Changes to the following setting should be made WITH EXTREME CAUTION as *
* these settings greatly affect the portability and function of Pro-TREE *
****************************************************************************/
/* B-Tree configuration settings */
#define MAXELTS 50 /* number of elements pre node */
#define MAXKEYS 30 /* number of keys per file */
#define MAXSEGS 5 /* number of segments per key */
#define DUPSEG MAXSEGS /* duplicate segment's home */
/* File and locking settings */
#define MAXLOCKS 0 /* NOTE: range is 0..10 */
#define MAXLOCKTRYS 0 /* number of trys at locking a file */
#define FLUSH_LEVEL 50 /* <=1:write-through, >1:"dangerous" */
/****************************************************************************
* Pro-TREE internal codes *
*---------------------------------------------------------------------------*
* WARNING: ANY CHANGES HERE WILL CAUSE Pro-TREE TO MALFUNCTION *
****************************************************************************/
#define CURRENT_VERSION "110"
#define FIELD_NAME_LEN 10
#define READ_LOCK 1
#define WRITE_LOCK -1
#define FILE_LOCK -2
#define PTNOPTR -1L /* error indicating no record offset */
#ifndef IODATSEEK
extern char *io_tran();
#define IODATSEEK IOERROR
#define IOIDXSEEK IOERROR
#define IODATWRITE IOERROR
#define IOIDXWRITE IOERROR
#define IODATREAD IOERROR
#define IOIDXREAD IOERROR
#define IOOLDVER IOBADOPEN
#define IONEWVER IOBADOPEN
#define IODATOPEN IOBADOPEN
#define IOIDXOPEN IOBADOPEN
#define IOFLDDEF IOBADOPEN
#define IOKEYDEF IOBADOPEN
#define IOFLDPERM IOERROR
#define IOIDXPERM IOBADOPEN
#define IODATPERM IOBADOPEN
#define IOFILLOCK IOBADOPEN
#define IONOSERVER IOERROR
#define IOCONFIG IOBADOPEN
#define IOFTABLE IOBADOPEN
#define IOILOCKED IOLOCKED
#define IOINOLOCK IONOLOCK
#endif
/****************************************************************************
* Compiler Specific Setting -- Should not need any tweaking *
****************************************************************************/
#ifdef MSDOS
#define ttyname(x) "<DOS>"
#endif
#ifdef LATTICE
# include <fcntl.h>
# define OPN_FILE(fname) open(fname,O_RAW|O_RDWR)
# define CRT_FILE(fname) open(fname,O_RAW|O_RDWR|O_CREAT,S_IREAD|S_IWRITE)
# define LOCK_BLK(fd,pos,len) lockf(fd,F_LOCK,len)
# define LOCK_TST(fd,pos,len) lockf(fd,F_TLOCK,len)
# define LOCK_REL(fd,pos,len) lockf(fd,F_ULOCK,len)
#endif
#ifdef __TURBOC__
# include <ctype.h>
# include <fcntl.h>
# include <sys/stat.h>
# define OPN_FILE(fname) open(fname,O_BINARY|O_RDWR)
# define CRT_FILE(fname) open(fname,O_BINARY|O_RDWR|O_CREAT,S_IREAD|S_IWRITE)
# define LOCK_BLK(fd,pos,len) lock(fd,pos,(long)len)
# define LOCK_TST(fd,pos,len) lock(fd,pos,(long)len)
# define LOCK_REL(fd,pos,len) unlock(fd,pos,(long)len)
#endif
#ifdef MSC /* This has been defined in bench.h */
# include <fcntl.h>
# include <sys\locking.h>
# include <sys\stat.h>
# include <sys\types.h>
# define OPN_FILE(fname) open(fname,O_BINARY|O_RDWR)
# define CRT_FILE(fname) open(fname,O_BINARY|O_RDWR|O_CREAT,S_IREAD|S_IWRITE)
# define LOCK_BLK(fd,pos,len) locking(fd,LK_LOCK,len)
# define LOCK_TST(fd,pos,len) locking(fd,LK_NBLCK,len)
# define LOCK_REL(fd,pos,len) locking(fd,LK_UNLCK,len)
#endif
#ifdef __WATCOMC__
# include <fcntl.h>
# include <io.h>
# include <sys\types.h>
# include <sys\stat.h>
# include <stdlib.h>
# define OPN_FILE(fname) open(fname,O_BINARY|O_RDWR|,S_IREAD|S_IWRITE)
# define CRT_FILE(fname) open(fname,O_BINARY|O_RDWR|O_CREAT,S_IREAD|S_IWRITE)
# define LOCK_BLK(fd,pos,len) (0)
# define LOCK_TST(fd,pos,len) (0)
# define LOCK_REL(fd,pos,len) (0)
#endif
#ifdef __ZTC__
# include <io.h>
# include <dos.h>
# include <sys\stat.h>
# include <stdlib.h>
# define OPN_FILE(fname) open(fname,O_RDWR)
# define CRT_FILE(fname) creat(fname,S_IREAD|S_IWRITE)
# define LOCK_BLK(fd,pos,len) (0)
# define LOCK_TST(fd,pos,len) (0)
# define LOCK_REL(fd,pos,len) (0)
# define tell(fh) lseek(fh,0L,1)
# define access(name,mode) close(open(name,mode))
#endif
#ifdef QNX
# include <ctype.h>
# include <errno.h>
# include <file_io.h>
# define OPN_FILE(fname) sopen(fname,O_BINARY|O_RDWR|O_CACHE,SH_DENYNO)
# define CRT_FILE(fname) sopen(fname,O_BINARY|O_RDWR|O_CACHE|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE)
# define LOCK_BLK(fd,pos,len) lockf(fd,F_LOCK,len)
# define LOCK_TST(fd,pos,len) lockf(fd,F_TLOCK,len)
# define LOCK_REL(fd,pos,len) lockf(fd,F_ULOCK,len)
#endif
#ifdef UNIX
extern int lockf();
extern long tell();
# include <ctype.h>
# include <errno.h>
# ifdef RT
# include <macros.h>
# else
# include <malloc.h>
# endif
# include <memory.h>
# include <string.h>
# define OPN_FILE(fname) open(fname,O_RDWR)
# define CRT_FILE(fname) open(fname,O_RDWR|O_CREAT,0664)
# define LOCK_BLK(fd,pos,len) lockf(fd,F_LOCK,len)
# define LOCK_TST(fd,pos,len) lockf(fd,F_TLOCK,len)
# define LOCK_REL(fd,pos,len) lockf(fd,F_ULOCK,len)
#endif
/***************************************************************************
* Structure Tag Definitions *
***************************************************************************/
typedef struct b_elmnt
{
WORD32 offset; /* data rec for leaves, child node for others */
WORD8 *keyval; /* all key types referenced by pointer */
} BELT;
/* structures for B-tree index information held in memory */
typedef struct b_node
{
WORD16 level; /* levels above leaf level */
WORD16 num_used; /* number of elements filled in */
BELT *elt; /* element array */
} BNODE;
/* segment information */
typedef struct segdesc
{
WORD16 s_recstart; /* offset of segment in record */
WORD16 s_keystart; /* offset of segment in key */
WORD16 s_leng; /* length of segment */
WORD16 s_vtyp; /* data type of segment */
} SINFO;
/* Definition for All Keys within a file */
typedef struct keydesc
{
WORD16 k_leng; /* Length of Key in Record */
WORD16 k_type; /* Key type, ie Unique or Duplicate */
WORD16 k_segs; /* Number of segments contained in key */
WORD16 k_levs; /* Number of nodal levels in the tree */
WORD16 exact; /* scoping flag for this key */
WORD32 didxptr; /* offset of didxlst in file */
WORD8 *keyval; /* current key value or NULL */
WORD16 *c_elt; /* Active element for each node level */
WORD16 *changes; /* Number of Changes Made to Node Buffers */
WORD32 *nodeoffset; /* Offset of Each Node in Index File */
BNODE *nodebuff; /* Node Buffer for Each Level */
SINFO sd[MAXSEGS + 1]; /* segment information */
} KINFO;
/* Definition for Each Open File */
typedef struct PT_fd_def
{
WORD16 fd_idx; /* index file handle from open() */
WORD16 rec_len; /* data record length */
WORD16 maxelts; /* number of elements per node */
WORD16 ilocked; /* index file locking flag */
WORD32 ddatptr; /* offset of ddellst in file */
WORD32 doffset; /* current offset into data file */
WORD8 version[4]; /* file version number */
WORD8 *fname; /* data file name */
WORD8 *iname; /* index file name */
KINFO *keyinfo; /* key information */
} AFDDEF;
typedef struct fd_def FDDEF;
/****************************************************************************
* Internal Function Declarations *
****************************************************************************/
#ifdef ANSI
extern char *PT_fmtkey(struct keydesc *,char *);
extern int PT_add_elt(int, int, long, char *);
extern int PT_add_key(int, char *);
extern int PT_add_node(int, int, long, char *);
extern int PT_chk_open(int, char *);
extern int PT_del_elt(int, int);
extern int PT_del_key(int, char *);
extern int PT_del_node(int, int);
extern int PT_find_key(int, char *);
extern int PT_find_match(int, char *, struct b_node *, int *);
extern int PT_flush_cache(int);
extern int PT_flush_node(int, int);
extern int PT_get_rec(int, char *);
extern int PT_idxlock(int, int);
extern int PT_idxunlock(int, int);
extern int PT_keycmp(int, char *, char *, int);
extern int PT_keyrecycle(int, long);
extern int PT_new_dup(int, char *);
extern int PT_readdata(int, char *);
extern int PT_readhdr(int);
extern int PT_readidx(int, int, int);
extern int PT_readnum(int, char *, int);
extern int PT_recrecycle(int, long);
extern int PT_resize(int, struct keydesc *, int);
extern int PT_writedata(int, char *);
extern int PT_writehdr(int);
extern int PT_writeidx(int, int);
extern int PT_writenum(int, char *, int);
extern long PT_first_key(int);
extern long PT_gteq_key(int, char *, int);
extern long PT_keyreuse(int);
extern long PT_last_key(int);
extern long PT_next_key(int);
extern long PT_prev_key(int);
extern long PT_recreuse(int);
extern void PT_cpyelt(struct b_elmnt *, struct b_elmnt *, int);
extern void PT_cpynode(int, struct b_node *, struct b_node *);
extern void PT_freenodes(int, struct keydesc *);
extern void PT_get_key(int, char *, char *);
extern void PT_makenodes(int, struct keydesc *, int);
extern void PT_shownode(int);
extern void PT_swapper(char *, int);
extern void PT_zeroelt(int, struct b_elmnt *);
extern void PT_zeronode(int, struct b_node *);
#else
extern char *PT_fmtkey();
extern int PT_add_elt();
extern int PT_add_key();
extern int PT_add_node();
extern int PT_chk_open();
extern int PT_del_elt();
extern int PT_del_key();
extern int PT_del_node();
extern int PT_find_key();
extern int PT_find_match();
extern int PT_flush_cache();
extern int PT_flush_node();
extern int PT_get_rec();
extern int PT_idxlock();
extern int PT_idxunlock();
extern int PT_keycmp();
extern int PT_keyrecycle();
extern int PT_new_dup();
extern int PT_readdata();
extern int PT_readhdr();
extern int PT_readidx();
extern int PT_readnum();
extern int PT_recrecycle();
extern int PT_resize();
extern int PT_writedata();
extern int PT_writehdr();
extern int PT_writeidx();
extern int PT_writenum();
extern long PT_first_key();
extern long PT_gteq_key();
extern long PT_keyreuse();
extern long PT_last_key();
extern long PT_next_key();
extern long PT_prev_key();
extern long PT_recreuse();
extern void PT_cpyelt();
extern void PT_cpynode();
extern void PT_freenodes();
extern void PT_get_key();
extern void PT_makenodes();
extern void PT_shownode();
extern void PT_swapper();
extern void PT_zeroelt();
extern void PT_zeronode();
#endif
/****************************************************************************
* External Function Declarations *
****************************************************************************/
#ifdef ANSI
extern char *io_tran(int);
#else
extern char *io_tran();
#endif
/****************************************************************************
* Pro-TREE Internal Variable Declatations *
****************************************************************************/
extern WORD16 PT_filecnt; /* file system initialization file */
extern WORD8 *PT_Recbuf; /* alloc'd once to prevent thrashing */
extern WORD16 PT_Reclen; /* length of Recbuf */
extern WORD8 *PT_Nodebuf; /* alloc'd once to prevent thrashing */
extern WORD16 PT_Nodelen; /* length of Nodebuf */
extern AFDDEF *PT_fd; /* file descriptor structure */
extern long lseek();