home *** CD-ROM | disk | FTP | other *** search
- case $CONFIG in
- '')
- if test ! -f config.sh; then
- ln ../config.sh . || \
- ln ../../config.sh . || \
- ln ../../../config.sh . || \
- (echo "Can't find config.sh."; exit 1)
- echo "Using config.sh from above..."
- fi
- . ./config.sh
- ;;
- esac
- : This forces SH files to create target in same directory as SH file.
- : This is so that make depend always knows where to find SH derivatives.
- case "$0" in
- */*) cd `expr X$0 : 'X\(.*\)/'` ;;
- esac
- echo "Extracting kef.h (with variable substitutions)"
- cat >kef.h <<!GROK!THIS!
- #ifndef _KEF_H_
- #define _KEF_H_
- /*
- * Headerfile for KEF.
- *
- * sccsid = @(#) kef.h (v2.12 4/17/90)
- */
-
- /*
- * On most machines the following definitions are ok:
- * char * malloc(), * realloc();
- * void free ();
- * Only on SUN OS 3.5 (so far) there is a difference :
- * int free ();
- * This will result in some warnings, so we set here FREE_TYPE to
- * the appropriate type.
- */
- #define FREE_TYPE $d_intfree /* */
-
- typedef unsigned char byte;
-
- /*
- * "Pointers" are indices into arrays. Their type is "kef_index",
- * two bytes unsigned.
- */
- typedef unsigned short kef_index;
-
- /*
- * Values are stored as 2 byte unsigned, called "kef_value".
- */
- typedef unsigned short kef_value;
-
- /*
- * KEF_NIL specifies the "no pointer" (NULL) value for type kef_index.
- * (Let's play it save and use 2^16-2)
- */
-
- # define KEF_NIL ((kef_value)65534)
-
- /*
- * Free nodes are fitted with a high tag value prior to "cleaning up".
- * This limits the number of nodes to 65532. Oh well.
- */
- # define HIGH_TAG ((kef_value)65533)
-
- /*
- * kef_node: holds information for one character.
- * next : sequential link to next node
- * sub : points at possible successor characters
- * what : character associated with the node.
- * value : value associated with this node; use macro HAS_VALUE to
- * test whether there is a value in this node.
- * flags : takes several flags:
- * value : 0/1 is value present at node
- * clean : 0/1 are the subsequent nodes connected,i.e.
- * are they stored in adjacent array elements
- * num : how many successors do we have?
- * tag : used to store temporary values before "cleaning up"
- * and to link nodes when traversing the tree
- */
- struct kef_node {
- kef_index sub;
- kef_index next;
- short value;
- short num;
- kef_index tag;
- char what;
- byte flags;
- };
-
- # define VALUE_FLAG 0x01
- # define CLEAN_FLAG 0x02
- # define FREE_FLAG 0x04
-
- # define HAS_VALUE(n) ((n).flags & VALUE_FLAG)
- # define SET_VALUE(n) ((n).flags |= VALUE_FLAG)
- # define CLEAR_VALUE(n) ((n).flags &= ~VALUE_FLAG)
-
- # define IS_CLEAN(n) ((n).flags & CLEAN_FLAG)
- # define SET_CLEAN(n) ((n).flags |= CLEAN_FLAG)
- # define CLEAR_CLEAN(n) ((n).flags &= ~CLEAN_FLAG)
-
- # define IS_FREE(n) ((n).flags & FREE_FLAG)
- # define SET_FREE(n) ((n).flags |= FREE_FLAG)
- # define CLEAR_FREE(n) ((n).flags &= ~FREE_FLAG)
-
-
- struct kef_db {
- short num_nodes; /* number of nodes in array node */
- short used_nodes; /* number of used nodes */
- short high_nodes; /* number of used+free nodes */
-
- kef_index root; /* first node */
- kef_index free_list; /* index into node : start of free list */
-
- short longest; /* length of longest string */
-
- byte must_clean; /* should clean flag be recomputed ? */
- byte was_allocated; /* was array node allocated ? */
-
- struct kef_node * node;
-
- char * (* malloc)(); /* internally used malloc */
- char * (* realloc)(); /* internally used realloc */
- FREE_TYPE (* free)(); /* internally used free */
- };
-
- /*
- * This is the main kef structure.
- * The buffer looks like this:
- * Guaranteed:
- *
- * <---------- size_buf ------------->
- * |---------------------------------|
- * ^ ^ ^ ^
- * buf from to one character at end is reserved
- *
- * After call to fillbuf, from routine get:
- *
- * <---------- size_buf ------------->
- * |---------------------------------|
- * ^ ^ ^ ^ ^
- * buf from cur to one character at end is reserved
- * Newly read characters are from "cur" to "to" exclusive. Old character,
- * aka. lookahead are from "from" to "cur" exclusive.
- */
-
- struct kef {
- int fd; /* filedescriptor for this struct */
- short size_buf; /* size of buffer which can be used by read */
-
- char is_delay;
- char is_timeout;
- int timeout;
- int delay;
-
- byte * buf;
- byte * buf_end; /* one after last possible character in buf */
-
- byte * from; /* start of not discarded characters */
- byte * to; /* one after end of available characters */
- byte * cur; /* start of new characters after fillbuf */
-
- struct kef_db * db; /* pointer to kdb structure */
-
- char * (* malloc)(); /* internally used malloc */
- char * (* realloc)(); /* internally used realloc */
- FREE_TYPE (* free)(); /* internally used free */
-
- char use_db; /* should we use database ? */
- char filler; /* just to pad it on 2 bytes boundaries */
- };
-
- /*
- * Routine kef_get returns either a character or a value from a string
- * or one of the following constants except KEF_CHAR. KEF_CHAR is
- * returned by functions called by kef_get, like kef_see or kef_wait.
- */
- # define KEF_CHAR 0
- # define KEF_NO_CHAR -1
- # define KEF_INTERRUPTED -2
- # define KEF_EOF -3
- # define KEF_SOME_ERROR -4
-
- /*
- * A kef_db structure can be written to file, even as only a part of a file.
- * Structure of file:
- * - 4 byte magic number
- * - 2 byte swap info for 2 byte quantities
- * - 2 byte number of nodes
- * - 2 byte number of bytes in first part of kdb structure.
- * This is equal to "offsetof(kdb->node)" and should be the same
- * on all machines that have sizeof(short)=2
- * - 2 byte sizeof(struct kef_node); just to be sure.
- * - kef_db structure part
- * - if number of bytes in kef_db part was not a multiple of 4, there are
- * several padding characters
- * - nodes
- * The first part is gathered into a header, to minimize read/writes
- */
- # define KEF_MAGIC0 0x81
- # define KEF_MAGIC1 ('K' | 0x80)
- # define KEF_MAGIC2 ('E' | 0x80)
- # define KEF_MAGIC3 'F'
-
- struct kef_fheader {
- byte magic[4];
- short swap;
- short num_nodes;
- short size_kdb;
- short size_node;
- };
-
- /*
- * Error messages for KEF and KEF_DB.
- * Codes:
- * 0 : ok
- * -1 thru -9 : return codes from routines, but no error
- * less or equal -10 : error code
- */
- # define KEF_E_OK 0
-
- # define KEF_E_SOME_ERROR -10
- # define KEF_E_NODES_USEDUP -11
- # define KEF_E_STRING_TWICE -12
- # define KEF_E_WRITE_ERROR -13
- # define KEF_E_READ_ERROR -14
- # define KEF_E_NOT_FOUND -15
- # define KEF_E_EMPTY_STRING -16
- # define KEF_E_WRONG_MAGIC -17
- # define KEF_E_TOO_MANY_NODES -18
- # define KEF_E_SIZE_KDB -19
- # define KEF_E_SIZE_NODE -20
- # define KEF_E_NO_MALLOC -21
- # define KEF_E_NO_REALLOC -22
- # define KEF_E_NO_FREE -23
- # define KEF_E_ALLOC_FAILED -24
- # define KEF_E_CHECK -25
- # define KEF_E_INV_PAR -26
- # define KEF_E_INV_INX -27
- # define KEF_E_TAG_LOOP -28
- #endif /* _KEF_H_ */
- !GROK!THIS!
-