From: greim@sbsvax.cs.uni-sb.de (Michael Greim)
Newsgroups: alt.sources
Subject: KEF - a library to store and identify function key presses, Part 02/06
Message-ID: <4364@sbsvax.cs.uni-sb.de>
Date: 15 May 90 15:12:27 GMT


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 5)."
# Contents:  MANIFEST Makefile README cfg cfg/BSD43 cfg/SINIX
#   cfg/SUN3-5 cfg/ULTRIX demos demos/demo11.c kdb-high
#   kdb-high/Makefile.SH kdb-high/add.c kdb-high/create_db.c
#   kdb-high/mcreate_db.c kdb-high/misc.c kdb-high/mread.c
#   kdb-high/read.c kdb-low kdb-low/_init_db.c kdb-low/_locate.c
#   kdb-low/_locate2.c kdb-low/_read.c kdb-low/advance.c
#   kdb-low/check.c kdb-low/error.c kdb-low/match.c kdb-low/walk.c
#   kdb-low/write.c kef kef/Makefile.SH kef/_init.c kef/create.c
#   kef/dump.c kef/mcreate.c kef/set.c local.h patchlevel.h
# Wrapped by greim@usb370 on Tue May 15 09:37:54 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(2085 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X COPYING                    2	
X Configure                  5	
X MANIFEST                   1	This shipping list
X Makefile                   1	
X PORTING                    3	
X README                     1	
X cfg                        1	
X cfg/BSD43                  1	
X cfg/SINIX                  1	
X cfg/SUN3-5                 1	
X cfg/ULTRIX                 1	
X config.h.SH                3	Produces config.h.
X demos                      1	
X demos/Makefile.SH          2	
X demos/demo11.c             1	
X demos/demo13.c             3	
X demos/demo15.c             3	
X demos/set_io.c             2	
X kdb-high                   1	
X kdb-high/Makefile.SH       1	
X kdb-high/add.c             1	
X kdb-high/cleanup.c         2	
X kdb-high/create_db.c       1	
X kdb-high/kdb-high.man      3	
X kdb-high/mcreate_db.c      1	
X kdb-high/misc.c            1	
X kdb-high/mread.c           1	
X kdb-high/read.c            1	
X kdb-high/str.c             2	
X kdb-low                    1	
X kdb-low/Makefile.SH        2	
X kdb-low/_add.c             3	
X kdb-low/_cleanup.c         2	
X kdb-low/_dump.c            2	
X kdb-low/_init_db.c         1	
X kdb-low/_locate.c          1	
X kdb-low/_locate2.c         1	
X kdb-low/_read.c            1	
X kdb-low/_rtools.c          2	
X kdb-low/_str.c             2	
X kdb-low/advance.c          1	
X kdb-low/check.c            1	
X kdb-low/error.c            1	
X kdb-low/kdb-low.man        4	
X kdb-low/match.c            1	
X kdb-low/remove.c           2	
X kdb-low/walk.c             1	
X kdb-low/write.c            1	
X kef                        1	
X kef.h.SH                   3	
X kef/Makefile.SH            1	
X kef/_init.c                1	
X kef/create.c               1	
X kef/dump.c                 1	
X kef/fill.c                 2	
X kef/get.c                  3	
X kef/kef.man                4	
X kef/look_wait.c            2	
X kef/mcreate.c              1	
X kef/set.c                  1	
X local.h                    1	
X patchlevel.h               1	
X setup.h                    2	
END_OF_FILE
if test 2085 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(102 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# Global Makefile for KEF
X#
Xall:
X	cd kdb-low; make
X	cd kdb-high; make
X	cd kef; make
X	cd demos; make
END_OF_FILE
if test 102 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(4665 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X( To get best results when reading these files, use an option in your favourite
X  editor to expand a TAB to 4 SPACEs. E.g. in vi it is "set tabstop=4"
X)
X
X
X1.) What do you have here?
X
X	This is the README file for 'KEF'.
X	'KEF' is a library to help a program recognize function key hits from a
X	keyboard.
X	It can be used by all program that read characters immediately
X	when a key is hit.
X	KEF uses a simple database to identify sequences of characters
X	in the input and returns a user-selectable value for such a
X	sequence to the calling routines.
X
X	You can easily see that KEF is not for people who only want to
X	write applications running under X with direct input from mouse
X	and keyboard. These people can use the translation mechanisms of
X	X to map event sequences to actions and be quite happy.
X
X	But for all of us that have to deal with function keys, KEF
X	can be quite useful.
X
X
X2.) Version
X
X	Current version is 1.0 alpha.
X
X	This version is not yet complete.
X	Missing :
X	- In the manuals (and probably some
X		other places there are references to part of the KEF library called
X		"kef-id". This part of the library is not part of the current release.
X	- For documentation there are only the manual pages. An article is
X		planned.
X	- There are only a few demo programs.
X
X
X3.) Files
X
X	You should have a lot of files in several directories. See MANIFEST
X	for a list of the files.
X
X	The directories are:
X	kdb-low		: low level database routines
X	kdb-high	: high level database routines
X	kef			: low + high level routines to read from keyboard
X	demos		: some demonstration programs (not complete yet)
X	cfg			: some "config.sh" prototypes
X	
X	Some important files:
X	COPYING		: the terms of redistribution, usage, etc.
X	README		: you are reading it.
X	PORTING		: what to do when porting to a new machine.
X	kef.h		: global header file for KEF.
X
X
X4.) How does KEF work?
X
X	A function key is a key on the keyboard, whose pressing causes several
X	characters to be transmitted. For example the arrow keys typically send
X	a 2 or 3 character sequence. On my keyboard, "up arrow" sends "\E[A" where
X	"\E" stands for the ASCII character ESC (hex 1b).
X	
X	The KEF routines use a simple database to store strings and their
X	associated values and to retrieve values.
X	A program can enter a character sequence and an associated value
X	into the KEF database. When the sequence is seen in the input, the
X	KEF routines return the associated value.
X	In order to identify sequences that are prefixes of other sequences it
X	is possible to specify in milliseconds how long a KEF routine should
X	wait for one more character.
X	
X	It is possible to use KEF in programs that do not include the routines
X	malloc/realloc or free or that use routines named differently but
X	performing equally.
X
X	KEF uses ultimately the routine "read" to get characters.
X	As the implentation of "read" may vary widely, the range of
X	possible operations has been kept relatively small. KEF uses
X	only operations that should be implementable on almost any
X	architecture and operating system that allows single character input.
X	Possible operations:
X	- try to read one or more characters
X		- block until a character is available
X		- wait at most for a certain time
X		- don't wait, don't block
X	- is a character available? Don't block.
X	All of these operations are interruptible. If they are interrupted,
X	they tell the calling routine about it.
X	To implement these operations one may have to use a couple of system
X	calls together, e.g. on 4.3BSD I use "select" to wait for characters
X	and "read" to actually fetch them.
X
X	See the programs in directory "demos" for some sample runs.
X
X
X5.) What about bugs?
X
X	If you find bugs, tell me. If you fixed them or if you made an
X	extension which really is one, drop me a note.
X
X6.) Feedback
X
X	If you like these routines or if you think something can be
X	added or improved write me a letter.
X
X7.) Status
X
X	Read COPYING.
X
X8.) Author
X
X           ___---~~~-_
X  ___---~~~     ___   ~-_
X|~     ___---~~~  |~-_--~|
X|~-_~~~-_ ___---~~~-_|__-'
X|  |~-_  ~-_         ~
X|  |   ~-_  ~-_           ___---~-_
X|  |  -_  ~-_  ~-___---~~~ ___---~|
X|  |  | ~-_  ~-_  ___---~~~       |
X|  |  |  | ~-_  |~      ___---~|  |
X|  |  |  |    ~-|_---~~~     | |  |       Michael T. Greim
X|  |  |  |          _--~-_   | |  |
X|  -_ |  |          |~-_  ~-_| |  |       e-mail : greim@cs.uni-sb.de
X ~-_ ~-_~~-_        |_  ~-_  | |  |                uunet!unido!sbsvax!greim
X    ~-_ ~-_ ~-_       ~-___~-_ | _|       @-mail : Sudstr.22 D-6602 Dudweiler
X       ~-_ ~-_ ~-_---~~~___---~~~ |                West Germany
X          ~-_ ~-__---~~~   ___---~~
X             ~-_| ___---~~~       
X                ~~  
END_OF_FILE
if test 4665 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test ! -d 'cfg' ; then
    echo shar: Creating directory \"'cfg'\"
    mkdir 'cfg'
fi
if test -f 'cfg/BSD43' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cfg/BSD43'\"
else
echo shar: Extracting \"'cfg/BSD43'\" \(982 characters\)
sed "s/^X//" >'cfg/BSD43' <<'END_OF_FILE'
X#!/bin/sh
X# config.sh
X# This file was produced by running the Configure script.
X
Xd_eunice='undef'
Xeunicefix=':'
Xloclist='
Xexpr
Xsed
Xecho
Xcat
Xrm
Xtr
Xgrep
X'
Xexpr='/bin/expr'
Xsed='/bin/sed'
Xecho='/bin/echo'
Xcat='/bin/cat'
Xrm='/bin/rm'
Xmv=''
Xcp=''
Xtail=''
Xtr='/usr/bin/tr'
Xmkdir=''
Xsort=''
Xuniq=''
Xgrep='/usr/ucb/grep'
Xtrylist='
Xtest
XMcc
Xcpp
X'
Xtest='/bin/test'
Xinews=''
Xegrep=''
Xmore=''
Xpg=''
XMcc='Mcc'
Xvi=''
Xmailx=''
Xmail=''
Xcpp='/lib/cpp'
Xperl=''
Xcontains='grep'
Xd_bcopy='define'
Xd_charsprf='define'
Xd_index='undef'
Xd_memcpy='define'
Xlibc='/lib/libc.a'
Xmansrc='/usr/man/mann'
Xmanext='n'
Xmodels='none'
Xsplit=''
Xsmall=''
Xmedium=''
Xlarge=''
Xhuge=''
Xccflags=''
Xldflags=''
Xcc='cc'
Xn='-n'
Xc=''
Xpackage='KEF'
Xspitshell='cat'
Xshsharp='true'
Xsharpbang='#!'
Xstartsh='#!/bin/sh'
Xdefine='define'
Xcppstdin='/lib/cpp'
Xcppminus=''
Xd_intfree='int'
Xd_reread='define'
Xd_termio='undef'
Xsystermio='undef'
Xlook4char='USE_SELECT'
Xuse_select=''
Xuse_rdchk=''
Xuse_fionread=''
Xwait4char='USE_SELECT'
XCONFIG=true
END_OF_FILE
if test 982 -ne `wc -c <'cfg/BSD43'`; then
    echo shar: \"'cfg/BSD43'\" unpacked with wrong size!
fi
# end of 'cfg/BSD43'
fi
if test -f 'cfg/SINIX' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cfg/SINIX'\"
else
echo shar: Extracting \"'cfg/SINIX'\" \(988 characters\)
sed "s/^X//" >'cfg/SINIX' <<'END_OF_FILE'
X: use /bin/sh
X# config.sh
X# This file was produced by running the Configure script.
X
Xd_eunice='undef'
Xeunicefix=':'
Xloclist='
Xexpr
Xsed
Xecho
Xcat
Xrm
Xtr
Xgrep
X'
Xexpr='/bin/expr'
Xsed='/bin/sed'
Xecho='/bin/echo'
Xcat='/bin/cat'
Xrm='/bin/rm'
Xmv=''
Xcp=''
Xtail=''
Xtr='/bin/tr'
Xmkdir=''
Xsort=''
Xuniq=''
Xgrep='/bin/grep'
Xtrylist='
Xtest
XMcc
Xcpp
X'
Xtest='/bin/test'
Xinews=''
Xegrep=''
Xmore=''
Xpg=''
XMcc='Mcc'
Xvi=''
Xmailx=''
Xmail=''
Xcpp='/lib/cpp'
Xperl=''
Xcontains='grep'
Xd_bcopy='define'
Xd_charsprf='define'
Xd_index='undef'
Xd_memcpy='undef'
Xlibc='/lib/libc.a'
Xmansrc='/usr/man/man1'
Xmanext='1'
Xmodels='none'
Xsplit=''
Xsmall=''
Xmedium=''
Xlarge=''
Xhuge=''
Xccflags=''
Xldflags=''
Xcc='cc'
Xn='-n'
Xc=''
Xpackage='KEF'
Xspitshell='cat'
Xshsharp='true'
Xsharpbang=': use '
Xstartsh=': use /bin/sh'
Xdefine='define'
Xcppstdin='/usr/SB/cpp'
Xcppminus=''
Xd_intfree='void'
Xd_reread='undef'
Xd_termio='define'
Xsystermio='define'
Xlook4char='USE_RDCHK'
Xuse_select=''
Xuse_rdchk=''
Xuse_fionread=''
Xwait4char='USE_RDCHK'
XCONFIG=true
END_OF_FILE
if test 988 -ne `wc -c <'cfg/SINIX'`; then
    echo shar: \"'cfg/SINIX'\" unpacked with wrong size!
fi
# end of 'cfg/SINIX'
fi
if test -f 'cfg/SUN3-5' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cfg/SUN3-5'\"
else
echo shar: Extracting \"'cfg/SUN3-5'\" \(973 characters\)
sed "s/^X//" >'cfg/SUN3-5' <<'END_OF_FILE'
X#!/bin/sh
X# config.sh
X# This file was produced by running the Configure script.
X
Xd_eunice='undef'
Xeunicefix=':'
Xloclist='
Xexpr
Xsed
Xecho
Xcat
Xrm
Xtr
Xgrep
X'
Xexpr='/bin/expr'
Xsed='/bin/sed'
Xecho='/bin/echo'
Xcat='/bin/cat'
Xrm='/bin/rm'
Xmv=''
Xcp=''
Xtail=''
Xtr='/usr/bin/tr'
Xmkdir=''
Xsort=''
Xuniq=''
Xgrep='/bin/grep'
Xtrylist='
Xtest
XMcc
Xcpp
X'
Xtest='test'
Xinews=''
Xegrep=''
Xmore=''
Xpg=''
XMcc='Mcc'
Xvi=''
Xmailx=''
Xmail=''
Xcpp='/lib/cpp'
Xperl=''
Xcontains='grep'
Xd_bcopy='define'
Xd_charsprf='define'
Xd_index='undef'
Xd_memcpy='define'
Xlibc='/lib/libc.a'
Xmansrc='/usr/man/manl'
Xmanext='l'
Xmodels='none'
Xsplit=''
Xsmall=''
Xmedium=''
Xlarge=''
Xhuge=''
Xccflags=''
Xldflags=''
Xcc='cc'
Xn='-n'
Xc=''
Xpackage='KEF'
Xspitshell='cat'
Xshsharp='true'
Xsharpbang='#!'
Xstartsh='#!/bin/sh'
Xdefine='define'
Xcppstdin='/lib/cpp'
Xcppminus=''
Xd_intfree='int'
Xd_reread='define'
Xd_termio='undef'
Xsystermio='undef'
Xlook4char='USE_SELECT'
Xuse_select=''
Xuse_rdchk=''
Xuse_fionread=''
Xwait4char='USE_SELECT'
XCONFIG=true
END_OF_FILE
if test 973 -ne `wc -c <'cfg/SUN3-5'`; then
    echo shar: \"'cfg/SUN3-5'\" unpacked with wrong size!
fi
# end of 'cfg/SUN3-5'
fi
if test -f 'cfg/ULTRIX' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cfg/ULTRIX'\"
else
echo shar: Extracting \"'cfg/ULTRIX'\" \(982 characters\)
sed "s/^X//" >'cfg/ULTRIX' <<'END_OF_FILE'
X#!/bin/sh
X# config.sh
X# This file was produced by running the Configure script.
X
Xd_eunice='undef'
Xeunicefix=':'
Xloclist='
Xexpr
Xsed
Xecho
Xcat
Xrm
Xtr
Xgrep
X'
Xexpr='/bin/expr'
Xsed='/bin/sed'
Xecho='/bin/echo'
Xcat='/bin/cat'
Xrm='/bin/rm'
Xmv=''
Xcp=''
Xtail=''
Xtr='/usr/bin/tr'
Xmkdir=''
Xsort=''
Xuniq=''
Xgrep='/usr/ucb/grep'
Xtrylist='
Xtest
XMcc
Xcpp
X'
Xtest='/bin/test'
Xinews=''
Xegrep=''
Xmore=''
Xpg=''
XMcc='Mcc'
Xvi=''
Xmailx=''
Xmail=''
Xcpp='/lib/cpp'
Xperl=''
Xcontains='grep'
Xd_bcopy='define'
Xd_charsprf='define'
Xd_index='undef'
Xd_memcpy='define'
Xlibc='/lib/libc.a'
Xmansrc='/usr/man/mann'
Xmanext='n'
Xmodels='none'
Xsplit=''
Xsmall=''
Xmedium=''
Xlarge=''
Xhuge=''
Xccflags=''
Xldflags=''
Xcc='cc'
Xn='-n'
Xc=''
Xpackage='KEF'
Xspitshell='cat'
Xshsharp='true'
Xsharpbang='#!'
Xstartsh='#!/bin/sh'
Xdefine='define'
Xcppstdin='/lib/cpp'
Xcppminus=''
Xd_intfree='int'
Xd_reread='define'
Xd_termio='undef'
Xsystermio='undef'
Xlook4char='USE_SELECT'
Xuse_select=''
Xuse_rdchk=''
Xuse_fionread=''
Xwait4char='USE_SELECT'
XCONFIG=true
END_OF_FILE
if test 982 -ne `wc -c <'cfg/ULTRIX'`; then
    echo shar: \"'cfg/ULTRIX'\" unpacked with wrong size!
fi
# end of 'cfg/ULTRIX'
fi
if test ! -d 'demos' ; then
    echo shar: Creating directory \"'demos'\"
    mkdir 'demos'
fi
if test -f 'demos/demo11.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'demos/demo11.c'\"
else
echo shar: Extracting \"'demos/demo11.c'\" \(1956 characters\)
sed "s/^X//" >'demos/demo11.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  demo11.c  (v1.2 5/15/90)";
X
X/*
X * Is it possible to switch driver to a mode where a character
X * becomes immediately available to a program and it is not echoed ?
X */
X
X# include <stdio.h>
X# include <sys/types.h>
X# include <sys/timeb.h>
X# include <signal.h>
X
XFILE * prot;
X
Xint tty_is_set = 0;
X
Xstruct timeb t0, t1;
X
Xfinish (n)
X	int n;
X{
X	if (tty_is_set)
X		tty_reset();
X	exit (n);
X}
X
Xmain (argc, argv)
X	int argc;
X	char ** argv;
X{
X	int n;
X	char c, c2;
X	int ind;
X
X	if ((prot = fopen ("prot", "w")) == NULL) {
X		fprintf (stderr, "cannot open prot.\n");
X		finish (2);
X	}
X
X	printf ("\nWelcome to demo program 11\n\n");
X	printf ("I will now try to switch driver into a mode where\n");
X	printf ("characters are not echoed and become immediately available\n");
X	printf ("to me.\n\n");
X	fflush (stdout);
X
X	signal (SIGINT, finish);
X
X	tty_save ();
X	tty_is_set = 1;
X	tty_cbreak(1);
X	tty_echo(0);
X	tty_set();
X
X	printf ("Done. Please press any of the character keys\n");
X	printf ("e.g. 'a' or '5'. Wait several seconds then press RETURN.\n");
X
X	ind = 0;
X
X	c = fgetc (stdin);
X	ftime (&t0);
X	c = fgetc (stdin);
X	ftime (&t1);
X	/*
X	 * Compute time difference.
X	 */
X	n = (t1.time - t0.time) * 1000 + t1.millitm - t0.millitm;
X	if (n < 1000) {
X		printf ("It does not seem to work correctly (or you cheated)\n");
X		printf ("The two characters were available within %1d milliseconds\n",n);
X		ind = 1;
X	}
X	for (;;) {
X		printf ("\nWas the character echoed (y/n) ?\n");
X		c = fgetc (stdin);
X		if  (c == 'n' || c == 'N' || c == 'y' || c == 'Y')
X			break;
X		printf ("\nPlease type 'y' or 'n'.\n");
X		printf ("I ignore anything until the next RETURN.\n");
X		while ((c2 = fgetc (stdin)) != '\n')
X			;
X	}
X
X	if (c == 'y' || c == 'Y') {
X		printf ("Switching off echoing did not work either\n");
X		ind += 2;
X	}
X
X	if (ind == 0) {
X		printf ("\nHooray !! It seems to work correctly.\n");
X		printf ("Now you may try the next demo programs.\n");
X	}
X
X	finish (ind);
X}
END_OF_FILE
if test 1956 -ne `wc -c <'demos/demo11.c'`; then
    echo shar: \"'demos/demo11.c'\" unpacked with wrong size!
fi
# end of 'demos/demo11.c'
fi
if test ! -d 'kdb-high' ; then
    echo shar: Creating directory \"'kdb-high'\"
    mkdir 'kdb-high'
fi
if test -f 'kdb-high/Makefile.SH' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/Makefile.SH'\"
else
echo shar: Extracting \"'kdb-high/Makefile.SH'\" \(2234 characters\)
sed "s/^X//" >'kdb-high/Makefile.SH' <<'END_OF_FILE'
Xrmconfig='no'
Xcase $CONFIG in
X'')
X	if test ! -f config.sh; then
X		ln ../config.sh . || \
X			ln ../../config.sh . || \
X			ln ../../../config.sh . || \
X			(echo "Can't find config.sh."; exit 1)
X		rmconfig='yes'
X	fi
X	. config.sh
X	;;
Xesac
X: This forces SH files to create target in same directory as SH file.
X: This is so that make depend always knows where to find SH derivatives.
Xcase "$0" in
X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
Xesac
Xecho "Extracting kdb-high/Makefile (with variable substitutions)"
X: Some headers, do no variable substitution
X$spitshell >Makefile <<'!NO!SUBS!'
X#
X# Makefile fuer KEF kdb-high
X#
X# sccsid = @(#)  Makefile  (v2.3 5/2/90)
X#
X
X#
X# Some general stuff
X#
XSHELL	=	/bin/sh
XSCCSPATH=
X!NO!SUBS!
X: This section of the file will have variable substitutions done on it.
X: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
X: Protect any dollar signs and backticks that you do not want interpreted
X: by putting a backslash in front.  You may delete these comments.
X$spitshell >>Makefile <<!GROK!THIS!
X
X#
X# The values of the following variables come from config.sh which has
X# been generated by running the Configure script.
X#
XCC=$cc
XSTDCFLAGS=$ccflags
XLDFLAGS=$ldflags
X!GROK!THIS!
X
X: In the following dollars and backticks do not need the extra backslash.
X$spitshell >>Makefile <<'!NO!SUBS!'
X
X# Debug flags go into DEB. Delete the object and recompile.
X# Debug info is written to "FILE * prot"
X# Define them as "-DDEBUG_ADD".
X#
X#     flag          |  file
X#   ----------------+------------------
X#   DEBUG_ADD       |  add.c
X#   DEBUG_CLEANUP   |  cleanup.c
X#   DEBUG_INIT      |  create_db.c mcreate_db.c
X#   DEBUG_MISC      |  misc.c
X#   DEBUG_IO        |  read.c mread.c
X#   DEBUG_STR       |  str.c
XDEB		=
X
X#
X# INCL should be pointing at the directory kef.h etc. are in.
X#
XINCL	=	-I..
X
X#
X# Compile flags
X#
XCFLAGS	=	${DEB} ${INCL}
X
X#
X# Object files
X#
XOBJS	=	add.o cleanup.o create_db.o mcreate_db.o mread.o read.o str.o \
X			misc.o
X
XKEF_LIB	=	../libkef.a
X
X#
X# Dependencies
X# ============
X#
X
Xall: ${KEF_LIB}
X
X${KEF_LIB}: ${OBJS}
X	ar rv ${KEF_LIB} $?
X	ranlib ${KEF_LIB}
X
X${OBJS}: ../kef.h
X!NO!SUBS!
Xchmod 755 Makefile
X$eunicefix Makefile
Xif test "$rmconfig" = "yes" ; then
X	rm -f config.sh
Xfi
END_OF_FILE
if test 2234 -ne `wc -c <'kdb-high/Makefile.SH'`; then
    echo shar: \"'kdb-high/Makefile.SH'\" unpacked with wrong size!
fi
# end of 'kdb-high/Makefile.SH'
fi
if test -f 'kdb-high/add.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/add.c'\"
else
echo shar: Extracting \"'kdb-high/add.c'\" \(1340 characters\)
sed "s/^X//" >'kdb-high/add.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  add.c  (v1.8 4/26/90)";
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_ADD
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X# ifdef L_DEBUG
Xextern char * kef_error ();
X# endif
X
X	int
Xkef_add (kdb, s, val)
X	struct kef_db * kdb;
X	char * s;
X	kef_value val;
X/*
X * If there are no more free nodes in nodes array, it is extended
X * using my_realloc. This works only if the array has been allocated
X * previously by malloc.
X */
X{
X	DI("kef_add ::")
X	register int i, count, redo;
X	struct kef_node * tmp;
X
X	/*
X	 * As long as we try and get an error we extend the structure
X	 * and retry.
X	 */
X	for (count = 1, redo = 1; count < 10 && redo == 1; count++) {
X		DEB3("%s try to add '%s' for the %1d. time\n", s, count);
X		FLUSH;
X		i = kef__add (kdb, s, val);
X# ifdef L_DEBUG
X		if (i < 0)
X			fprintf (prot, "kef_add ERROR : %s\n", kef_error (i));
X# endif
X
X		if (i != KEF_E_NODES_USEDUP)
X			return i;
X		/*
X		 * Extend the nodes array
X		 */
X		if (kdb->realloc == NULL)
X			return KEF_E_NO_REALLOC;
X		tmp = (struct kef_node *) (* kdb->realloc) ((char *)kdb->node,
X			(unsigned int)(kdb->num_nodes + 32 * count) *
X			sizeof (struct kef_node));
X		if (tmp == NULL)
X			return KEF_E_ALLOC_FAILED;
X		kdb->num_nodes += 32*count;
X		kdb->node = tmp;
X	}
X	return count < 10 ? KEF_E_OK : i;
X}
END_OF_FILE
if test 1340 -ne `wc -c <'kdb-high/add.c'`; then
    echo shar: \"'kdb-high/add.c'\" unpacked with wrong size!
fi
# end of 'kdb-high/add.c'
fi
if test -f 'kdb-high/create_db.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/create_db.c'\"
else
echo shar: Extracting \"'kdb-high/create_db.c'\" \(641 characters\)
sed "s/^X//" >'kdb-high/create_db.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  create_db.c  (v1.10 4/17/90)";
X
X/*
X * Frontend for kef_mcreate_db.
X * If a user calls kef_create_db s/he gets malloc/realloc/free. If s/he desires
X * otherwise s/he should call kef_mcreate_db directly.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_INIT
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
Xextern char * malloc ();
Xextern char * realloc ();
Xextern FREE_TYPE free ();
X
Xextern int kef_mcreate_db ();
X
X	int
Xkef_create_db (pkdb, num_nodes)
X	struct kef_db ** pkdb;
X	int num_nodes;
X{
X	return kef_mcreate_db (pkdb, num_nodes, malloc, realloc, free);
X}
END_OF_FILE
if test 641 -ne `wc -c <'kdb-high/create_db.c'`; then
    echo shar: \"'kdb-high/create_db.c'\" unpacked with wrong size!
fi
# end of 'kdb-high/create_db.c'
fi
if test -f 'kdb-high/mcreate_db.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/mcreate_db.c'\"
else
echo shar: Extracting \"'kdb-high/mcreate_db.c'\" \(1183 characters\)
sed "s/^X//" >'kdb-high/mcreate_db.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  mcreate_db.c  (v1.6 4/17/90)";
X
X/*
X * Create (allocate) and initialize a kef_db structure.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_INIT
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X# define DEF_NUM_NODES	128
X
Xextern int kef__init_db ();
X
X	int
Xkef_mcreate_db (pkdb, num_nodes, my_malloc, my_realloc, my_free)
X	struct kef_db ** pkdb;
X	int num_nodes;
X	char * (* my_malloc) ();
X	char * (* my_realloc) ();
X	FREE_TYPE (* my_free) ();
X{
X	register int i;
X	struct kef_node * nd;
X
X	if (my_malloc == NULL)
X		return KEF_E_NO_MALLOC;
X	/*
X	 * Allocate a kef_db structure. A structure consists of 2 parts:
X	 * a header, the node array. These are allocated in turn.
X	 */
X	*pkdb = (struct kef_db *) (* my_malloc) (sizeof (struct kef_db));
X	if (num_nodes <= 0)
X		num_nodes = DEF_NUM_NODES;
X	nd  = (struct kef_node *) (* my_malloc) (sizeof (struct kef_node) * num_nodes);
X	if (*pkdb == NULL || nd == NULL)
X		return KEF_E_ALLOC_FAILED;
X
X	/*
X	 * Set the entries in it to default values.
X	 */
X	i = kef__init_db (*pkdb, nd, num_nodes, my_malloc, my_realloc, my_free);
X
X	(*pkdb)->was_allocated = 1;
X
X	return i;
X}
END_OF_FILE
if test 1183 -ne `wc -c <'kdb-high/mcreate_db.c'`; then
    echo shar: \"'kdb-high/mcreate_db.c'\" unpacked with wrong size!
fi
# end of 'kdb-high/mcreate_db.c'
fi
if test -f 'kdb-high/misc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/misc.c'\"
else
echo shar: Extracting \"'kdb-high/misc.c'\" \(624 characters\)
sed "s/^X//" >'kdb-high/misc.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  misc.c  (v1.1 4/17/90)";
X
X/*
X * Miscalleneous routines to make things work on different OS.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_MISC
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X#include "setup.h"
X
X#ifndef FASTCOPY
X/*
X * The variable FASTCOPY is neither defined as "bcopy" nor "memcpy".
X * Use this routine here.
X */
X
X	void
XFASTCOPY(s,t,l)
X	register char * s;
X	register char * t;
X	register int l;
X/*
X * Copy l bytes starting at s to t.
X * Returns no error indication.
X */
X{
X	while (l--)
X		*t++ = *s++;
X}
X#endif	/* FASTCOPY */
END_OF_FILE
if test 624 -ne `wc -c <'kdb-high/misc.c'`; then
    echo shar: \"'kdb-high/misc.c'\" unpacked with wrong size!
fi
# end of 'kdb-high/misc.c'
fi
if test -f 'kdb-high/mread.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/mread.c'\"
else
echo shar: Extracting \"'kdb-high/mread.c'\" \(1554 characters\)
sed "s/^X//" >'kdb-high/mread.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  mread.c  (v1.7 3/21/90)";
X
X/*
X * Read a structure from a file.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_IO
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef_mread (fd, pkdb, my_malloc, my_realloc, my_free)
X	register int fd;
X	struct kef_db ** pkdb;
X	char * (* my_malloc)();
X	char * (* my_realloc)();
X	FREE_TYPE (* my_free)();
X/*
X * Create a structure and read into it from a file.
X */
X{
X	DI("kef_mread ::")
X	register int n;
X	struct kef_fheader kfh;
X	struct kef_node * nd;
X
X	if ((long)my_malloc == 0L)
X		return KEF_E_NO_MALLOC;
X	if ((long)my_free == 0L)
X		return KEF_E_NO_FREE;
X
X	n = kef_read_header (fd, &kfh);
X	if (n != KEF_E_OK)
X		return n;
X
X	DEB1("%s got header from file\n");
X
X	/*
X	 * Allocate kef_db structure and nodes array.
X	 */
X	*pkdb = (struct kef_db *) (* my_malloc) (sizeof (struct kef_db));
X	if (*pkdb == NULL)
X		return KEF_E_ALLOC_FAILED;
X
X	n = sizeof (struct kef_node) * kfh.num_nodes;
X	nd = (struct kef_node *) (* my_malloc) (n);
X	if (nd == NULL)
X		return KEF_E_ALLOC_FAILED;
X	/*
X	 * Read stuff.
X	 */
X	n = kef_read_file (fd, *pkdb, kfh.size_kdb, nd, kfh.num_nodes,
X		kfh.swap != 0x0201);
X	if (n != KEF_E_OK) {
X		(void) (* my_free) ((*pkdb)->node);
X		(void) (* my_free) ((*pkdb));
X	} else {
X		/*
X		 * Set kdb for the current configuration.
X		 */
X		(*pkdb)->node = nd;
X		(*pkdb)->num_nodes = kfh.num_nodes;
X		(*pkdb)->was_allocated = 1;
X		(*pkdb)->malloc = my_malloc;
X		(*pkdb)->realloc = my_realloc;
X		(*pkdb)->free = my_free;
X	}
X	return n;
X}
END_OF_FILE
if test 1554 -ne `wc -c <'kdb-high/mread.c'`; then
    echo shar: \"'kdb-high/mread.c'\" unpacked with wrong size!
fi
# end of 'kdb-high/mread.c'
fi
if test -f 'kdb-high/read.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-high/read.c'\"
else
echo shar: Extracting \"'kdb-high/read.c'\" \(553 characters\)
sed "s/^X//" >'kdb-high/read.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  read.c  (v1.8 3/16/90)";
X
X/*
X * Read a structure from a file.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_IO
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
Xextern int kef_mread ();
X
Xextern char * malloc ();
Xextern char * realloc ();
Xextern FREE_TYPE free();
X
X	int
Xkef_read (fd, pkdb)
X	register int fd;
X	struct kef_db ** pkdb;
X/*
X * Frontend before kef_mread. Causes malloc/realloc/free to be included.
X */
X{
X	
X	return kef_mread (fd, pkdb, malloc, realloc, free);
X}
END_OF_FILE
if test 553 -ne `wc -c <'kdb-high/read.c'`; then
    echo shar: \"'kdb-high/read.c'\" unpacked with wrong size!
fi
# end of 'kdb-high/read.c'
fi
if test ! -d 'kdb-low' ; then
    echo shar: Creating directory \"'kdb-low'\"
    mkdir 'kdb-low'
fi
if test -f 'kdb-low/_init_db.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/_init_db.c'\"
else
echo shar: Extracting \"'kdb-low/_init_db.c'\" \(1122 characters\)
sed "s/^X//" >'kdb-low/_init_db.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  _init_db.c  (v2.8 3/27/90)";
X
X/*
X * Initialize a kef_db structure.
X */
X
X# include <stdio.h>
X# include <sys/types.h>
X# include <sys/times.h>
X# include "kef.h"
X
X	int
Xkef__init_db (kdb, nd, num_nodes, my_malloc, my_realloc, my_free)
X	struct kef_db * kdb;
X	struct kef_node * nd;
X	int num_nodes;
X	char * (* my_malloc) ();
X	char * (* my_realloc) ();
X	FREE_TYPE (* my_free) ();
X/*
X * kdb and nd have been allocated. Set the initial values
X * in kdb accordingly.
X * The topmost node is allocated here.
X *
X * Returns: possible errors : none.
X */
X{
X	kdb->node = nd;
X	kdb->num_nodes  = num_nodes;
X	kdb->used_nodes = 1;
X	kdb->high_nodes = 1;
X
X	kdb->root = 0;
X	kdb->free_list = KEF_NIL;
X
X	kdb->longest = 0;
X	kdb->must_clean = 0;
X	kdb->was_allocated = 0;
X
X	kdb->malloc = my_malloc;
X	kdb->realloc = my_realloc;
X	kdb->free = my_free;
X	/*
X	 * Initialize topmost node.
X	 */
X	kdb->node[0].sub = KEF_NIL;
X	kdb->node[0].next = KEF_NIL;
X	kdb->node[0].value = 0;
X	kdb->node[0].num = 0;
X	kdb->node[0].tag = KEF_NIL;
X	kdb->node[0].what = '\0';
X	kdb->node[0].flags = 0;		/* all flags set to NO */
X
X	return KEF_E_OK;
X}
END_OF_FILE
if test 1122 -ne `wc -c <'kdb-low/_init_db.c'`; then
    echo shar: \"'kdb-low/_init_db.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/_init_db.c'
fi
if test -f 'kdb-low/_locate.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/_locate.c'\"
else
echo shar: Extracting \"'kdb-low/_locate.c'\" \(2023 characters\)
sed "s/^X//" >'kdb-low/_locate.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  _locate.c  (v1.7 3/13/90)";
X
X/*
X */
X
X# include <stdio.h>
X# include "kef.h"
X# include <ctype.h>
X
X#ifdef DEBUG_LOCATE
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef__locate_node (nd, c, here, inx)
X	struct kef_node * nd;
X	char c;
X	kef_index here;
X	kef_value * inx;
X/*
X * Locate a character in a list of character attached below here.
X * If the character is not found, returns 0 and in inx the index AFTER which
X * a new element should be inserted. If insertion place is at start of list it
X * returns KEF_NIL.
X * If the character is found, returns something != 0 and in inx the index
X * at which it was found.
X */
X{
X	DI("kef__locate_node")
X	register kef_index cur, low, high;
X
X	low = nd[here].sub;
X	*inx = KEF_NIL;
X
X	if (low == KEF_NIL)
X		return 0;
X	
X	DEB5 ("%s for '%c' below node %1d num = %1d is_clean = %1d\n", c, here,
X		nd[here].num, IS_CLEAN(nd[here]));
X# ifdef L_DEBUG
X	if (nd[here].num < 3 || !IS_CLEAN(nd[here])) {
X# else
X	if (nd[here].num < 8 || !IS_CLEAN(nd[here])) {
X# endif
X		DEB1("%s using sequential search\n");
X		/*
X		 * Sequential search.
X		 *
X		 * Use high as temporary variable to store index of node before
X		 * cur
X		 */
X		high = KEF_NIL;
X		for (cur = low; cur != KEF_NIL && nd [cur].what < c; cur = nd[cur].next) {
X			DEB4 ("%s '%c' is smaller than '%c' at node %1d\n", c, nd[cur].what,
X				cur);
X			high = cur;
X		}
X		*inx = high;
X		DEB3 ("%s %sfound inx = %1d\n",
X			(cur != KEF_NIL && nd[cur].what == c) ? " " : "not ", *inx);
X		return cur != KEF_NIL && nd[cur].what == c;
X	}
X	DEB1("%s using binary search\n");
X	/*
X	 * Binary search.
X	 */
X	high = low + nd[here].num;
X
X	while (low < high) {
X		cur = (high + low) >> 1;
X		if (c < nd [cur].what)
X			high = cur;
X		else if (c > nd [cur].what)
X			low = cur + 1;
X		else {
X			if (cur > nd[here].sub)
X				*inx = cur - 1;
X			DEB2 ("%s found inx = %1d\n", *inx);
X			return 1;
X		}
X	}
X	if (nd[here].sub < high)
X		*inx = high;
X	DEB2 ("%s not found inx = %1d\n", *inx);
X	return 0;
X}
END_OF_FILE
if test 2023 -ne `wc -c <'kdb-low/_locate.c'`; then
    echo shar: \"'kdb-low/_locate.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/_locate.c'
fi
if test -f 'kdb-low/_locate2.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/_locate2.c'\"
else
echo shar: Extracting \"'kdb-low/_locate2.c'\" \(2089 characters\)
sed "s/^X//" >'kdb-low/_locate2.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  _locate2.c  (v1.4 3/21/90)";
X
X/*
X */
X
X# include <stdio.h>
X# include "kef.h"
X# include <ctype.h>
X
X#ifdef DEBUG_LOCATE
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef__flocate_node (nd, c, here, inx)
X	struct kef_node * nd;
X	char c;
X	kef_index here;
X	kef_value * inx;
X/*
X * Locate a character in a list of character attached below here.
X * If the character is found, returns something != 0 (might be 1)
X * and in inx the index at which it was found. If the character is not
X * found, returns 0 and in inx the index after which something might
X * be inserted. If index is KEF_NIL then at end of list.
X *
X * Similar to kef__locate_node, only return really the index at which
X * character is found. Faster than kef__locate_node.
X */
X{
X	DI("kef__flocate_node")
X	register kef_index cur, low, high;
X
X	*inx = KEF_NIL;
X	if ((low = nd[here].sub) == KEF_NIL)
X		return 0;
X	
X	DEB5 ("%s for '%c' below node %1d num = %1d is_clean = %1d\n", c, here,
X		nd[here].num, IS_CLEAN(nd[here]));
X# ifdef L_DEBUG
X	if (nd[here].num < 3 || !IS_CLEAN(nd[here])) {
X# else
X	if (nd[here].num < 8 || !IS_CLEAN(nd[here])) {
X# endif
X		DEB1("%s using sequential search\n");
X		/*
X		 * Sequential search.
X		 */
X		for (cur = low; cur != KEF_NIL && nd [cur].what < c; cur = nd[cur].next)
X			DEB4 ("%s '%c' is smaller than '%c' at node %1d\n", c, nd[cur].what,
X				cur);
X		*inx = cur;
X		DEB3 ("%s %sfound inx = %1d\n",
X			(cur != KEF_NIL && nd[cur].what == c) ? " " : "not ", *inx);
X		return cur != KEF_NIL && nd[cur].what == c;
X	}
X	DEB1("%s using binary search\n");
X	/*
X	 * Binary search.
X	 */
X	high = low + nd[here].num;
X
X	while (low < high) {
X		cur = (high + low) >> 1;
X		if (c < nd [cur].what)
X			high = cur;
X		else if (c > nd [cur].what)
X			low = cur + 1;
X		else {
X			*inx = cur;
X			DEB2 ("%s found inx = %1d\n", *inx);
X			return 1;
X		}
X	}
X	/*
X	 * Would return *inx = low here, but we only use this routine
X	 * in a context where we only need the value of *inx when we found
X	 * the character node.
X	 */
X	DEB1 ("%s not found\n");
X	return 0;
X}
END_OF_FILE
if test 2089 -ne `wc -c <'kdb-low/_locate2.c'`; then
    echo shar: \"'kdb-low/_locate2.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/_locate2.c'
fi
if test -f 'kdb-low/_read.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/_read.c'\"
else
echo shar: Extracting \"'kdb-low/_read.c'\" \(1596 characters\)
sed "s/^X//" >'kdb-low/_read.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  _read.c  (v1.7 3/27/90)";
X
X/*
X * Read a kdb structure from file.
X *
X * File structure:
X * - header
X * - kdb structure padded to fit yield 4 byte alignment. This is because
X *   some compiler may choose to extend the structure to 4 byte limits.
X *   If a compiler chooses to rearrange the fields, we are licked, though.
X * - nodes (must be 2 byte aligned)
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_IO
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef__read(fd, kdb, nd, num_nd, my_malloc, my_realloc, my_free)
X	int fd;
X	struct kef_db * kdb;
X	struct kef_node * nd;
X	int num_nd;
X	char * (* my_malloc)();
X	char * (* my_realloc)();
X	FREE_TYPE (* my_free)();
X/*
X * Read a kdb structure from file fd.
X * The nodes are placed in the array nd, the array is then
X * attached at kdb.
X *
X * Values in kdb are overwritten.
X */
X{
X	DI("kef__read ::")
X	int i;
X	struct kef_fheader kfh;
X
X	DEB1("%s called \n");
X
X	i = kef_read_header (fd, &kfh);
X	if (i != KEF_E_OK)
X		return i;
X
X	DEB1("%s got header from file\n");
X
X	/*
X	 * We have only a certain amount of space at our disposal. Check whether
X	 * the stuff on file fits.
X	 */
X	if (kfh.num_nodes > num_nd)
X		return KEF_E_TOO_MANY_NODES;
X
X	i = kef_read_file (fd, kdb, kfh.size_kdb, nd, kfh.num_nodes,
X		kfh.swap != 0x0201);
X	if (i != KEF_E_OK)
X		return i;
X	/*
X	 * Set kdb for the current configuration.
X	 */
X	kdb->node = nd;
X	kdb->num_nodes = num_nd;
X	kdb->malloc = my_malloc;
X	kdb->realloc = my_realloc;
X	kdb->free = my_free;
X
X	DEB1("%s done.\n");
X
X	return KEF_E_OK;
X}
END_OF_FILE
if test 1596 -ne `wc -c <'kdb-low/_read.c'`; then
    echo shar: \"'kdb-low/_read.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/_read.c'
fi
if test -f 'kdb-low/advance.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/advance.c'\"
else
echo shar: Extracting \"'kdb-low/advance.c'\" \(837 characters\)
sed "s/^X//" >'kdb-low/advance.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  advance.c  (v2.2 3/21/90)";
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_WALK
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
Xkef_advance (kdb, c, pos)
X	struct kef_db * kdb;
X	char c;
X	kef_index * pos;
X/*
X * Look in list below cell *pos for character c.
X * found :
X *		return 1 and set *pos to index at which character was found
X * not found:
X *		return 0 and don't change value at *pos
X */
X{
X	DI("kef_advance ::")
X	int i;
X	kef_index found;
X
X	if (*pos == KEF_NIL)
X		*pos = kdb->root;
X
X	/*
X	 * Use flocate because we are only interested in the position
X	 * at which character is.
X	 */
X	i = kef__flocate_node (kdb->node, c, *pos, &found);
X	if (i != 0)
X		*pos = found;
X
X	DEB3("%s return value == %1d, pos = %1d\n", i, *pos);
X	FLUSH;
X	return i == 0 ? 0 : 1;
X}
END_OF_FILE
if test 837 -ne `wc -c <'kdb-low/advance.c'`; then
    echo shar: \"'kdb-low/advance.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/advance.c'
fi
if test -f 'kdb-low/check.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/check.c'\"
else
echo shar: Extracting \"'kdb-low/check.c'\" \(1874 characters\)
sed "s/^X//" >'kdb-low/check.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  check.c  (v1.7 3/15/90)";
X/*
X * Check various conditions on kef-db structures.
X * Routines here:
X *
X * kef_check (f, kdb)
X */
X
X# include <stdio.h>
X# include "kef.h"
X
Xextern int kef__is_clean ();
X
X	static int
Xcheck1 (f, kdb)
X	FILE * f;
X	struct kef_db * kdb;
X/*
X * Check for each node with follow nodes, whether they are really
X * sorted and unique.
X */
X{
X	static char * I = "check1 ::";
X	register int i, j;
X	int num;
X	unsigned char b;
X
X	num = 0;
X	for (i = 0; i < kdb->high_nodes; i++) {
X		if (IS_FREE(kdb->node[i]) || kdb->node[i].sub == KEF_NIL)
X			continue;
X		j = kdb->node[i].sub;
X		b = kdb->node[j].what;
X		while ((j = kdb->node[j].next) != KEF_NIL) {
X			if (b >= kdb->node[j].what) {
X				fprintf (f, "%s list below node %1d not sorted at node %1d\n",
X					I, i, j);
X				num ++;
X				break;
X			}
X			b = kdb->node[j].what;
X		}
X	}
X	if (num == 0)
X		return KEF_E_OK;
X	else
X		return KEF_E_CHECK;
X}
X	static int
Xcheck2 (f, kdb)
X	FILE * f;
X	struct kef_db * kdb;
X/*
X * Check the CLEAN flag for all elements.
X */
X{
X	static char * I = "check2 ::";
X	register int i, j;
X	int num = 0;
X
X	for (i = 0; i < kdb->high_nodes; i++) {
X		if (IS_FREE(kdb->node[i]) || kdb->node[i].sub == KEF_NIL)
X			continue;
X		j = kef__is_clean (kdb, i);
X
X		if (IS_CLEAN(kdb->node[i])) {
X			if (j == 0) {
X				fprintf (f, "%s ERROR CLEAN flag set, but array not clean at %1d\n",
X					I, i);
X				num ++;
X			}
X		} else {
X			if (j == 1) {
X				fprintf (f, "%s WARNING CLEAN flag not set, but should be at %1d\n",
X					I, i);
X				num ++;
X			}
X		}
X	}
X	if (num == 0)
X		return KEF_E_OK;
X	else
X		return KEF_E_CHECK;
X}
X
Xkef_check_db (f, kdb)
X	FILE * f;
X	struct kef_db * kdb;
X/*
X * Return KEF_E_OK if everything was ok, else KEF_E_CHECK.
X * Messages are printed on file f.
X */
X{
X	int i, j;
X
X	i = KEF_E_OK;
X	i = check1 (f, kdb);
X	j = check2 (f, kdb);
X	if (i == KEF_E_OK)
X		i = j;
X
X	return i;
X}
END_OF_FILE
if test 1874 -ne `wc -c <'kdb-low/check.c'`; then
    echo shar: \"'kdb-low/check.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/check.c'
fi
if test -f 'kdb-low/error.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/error.c'\"
else
echo shar: Extracting \"'kdb-low/error.c'\" \(1391 characters\)
sed "s/^X//" >'kdb-low/error.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  error.c  (v1.7 4/17/90)";
X
X# include "kef.h"
X
X# define A(lab,str)	case lab: s = str; break
X
X#ifdef CHARSPRINTF
Xextern char * sprintf ();
X#else
Xextern int sprintf();
X#endif /* ! CHARSPRINTF */
X
X	char *
Xkef_error (ret)
X	int ret;
X{
X	char * s;
X	char buf [80];
X	switch (ret) {
X		A(KEF_E_SOME_ERROR,		"Some error");
X		A(KEF_E_NODES_USEDUP,	"No more space in database.");
X		A(KEF_E_STRING_TWICE,	"String is already in the kef database.");
X		A(KEF_E_WRITE_ERROR,	"Write error.");
X		A(KEF_E_READ_ERROR,		"Read error.");
X		A(KEF_E_NOT_FOUND,		"String not found.");
X		A(KEF_E_EMPTY_STRING,	"String is empty.");
X		A(KEF_E_WRONG_MAGIC,	"Magic number not found on file.");
X		A(KEF_E_TOO_MANY_NODES,	"Too many nodes.");
X		A(KEF_E_SIZE_KDB,		"Size of kdb.");
X		A(KEF_E_SIZE_NODE,		"Size of node array.");
X		A(KEF_E_NO_MALLOC,		"I don't know a malloc like routine to call.");
X		A(KEF_E_NO_REALLOC,		"I don't know a realloc like routine to call.");
X		A(KEF_E_NO_FREE,		"I don't know a free like routine to call.");
X		A(KEF_E_ALLOC_FAILED,	"Allocation failed.");
X		A(KEF_E_CHECK,			"Checking found error.");
X		A(KEF_E_INV_PAR,		"buf != NULL but buf_size <= 0.");
X		A(KEF_E_INV_INX,		"Invalid index encountered.");
X		A(KEF_E_TAG_LOOP,		"Loop while travelling along tags.");
X		
X		default:
X			(void) sprintf (buf, "** kef error %1d **", ret);
X			s = buf;
X			break;
X	}
X	return (s);
X}
END_OF_FILE
if test 1391 -ne `wc -c <'kdb-low/error.c'`; then
    echo shar: \"'kdb-low/error.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/error.c'
fi
if test -f 'kdb-low/match.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/match.c'\"
else
echo shar: Extracting \"'kdb-low/match.c'\" \(1645 characters\)
sed "s/^X//" >'kdb-low/match.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  match.c  (v1.5 3/13/90)";
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_MATCH
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef_match (kdb, str, val)
X	struct kef_db * kdb;
X	char * str;
X	kef_value * val;
X/*
X * Does string str match a string in kef database kdb?
X * returns : 0 : no, 1 : yes + val contains value
X *
X * Bugs: Does not work with strings containing '\0'. But then what
X * does ?
X */
X{
X	DI("kef__match ::")
X	register int i, j;
X	kef_index pos, new_pos;
X
X	DEB2("%s called for '%s'\n", str);
X	FLUSH;
X	if (str [0] == '\0')
X		return 0;		/* A special case */
X
X	/*
X	 * Is the first character in the set of
X	 * start characters ?
X	 */
X	j = kef__locate_node (kdb->node, str[0],
X			(kef_index) (kdb->root), &pos);
X	DEB3("%s locate of first character returned %1d; pos = %1d\n", j, pos);
X	if (j == 0)
X		return 0;
X	if (pos == KEF_NIL)
X		pos = kdb->node[kdb->root].sub;
X	else
X		pos = kdb->node[pos].next;
X
X	for (i = 1; str [i] != '\0'; i++) {
X		DEB3("%s locate node for '%c' below %1d\n", str[i], pos);
X		FLUSH;
X		j = kef__locate_node (kdb->node, str[i], pos, &new_pos);
X		DEB3("%s search returned %1d, pos = %1d\n", j, new_pos);
X		FLUSH;
X		if (j == 0)
X			break;
X		if (new_pos == KEF_NIL)
X			pos = kdb->node[pos].sub;
X		else
X			pos = kdb->node[new_pos].next;
X	}
X	DEB3("%s last char %s NUL; pos = %1d\n",
X		str[i] == '\0' ? "==" : "!=", pos);
X	DEB3("%s match of '%s' results %d\n",
X		str, str[i] == '\0' && HAS_VALUE(kdb->node[pos]));
X
X	if (str[i] == '\0' && HAS_VALUE(kdb->node[pos])) {
X			*val = kdb->node[pos].value;
X			return 1;
X	}
X	*val = 0;
X	return 0;
X}
END_OF_FILE
if test 1645 -ne `wc -c <'kdb-low/match.c'`; then
    echo shar: \"'kdb-low/match.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/match.c'
fi
if test -f 'kdb-low/walk.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/walk.c'\"
else
echo shar: Extracting \"'kdb-low/walk.c'\" \(2206 characters\)
sed "s/^X//" >'kdb-low/walk.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  walk.c  (v1.2 3/21/90)";
X
X/*
X * Do a depth first walk on tree.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_WALK
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef_walk (kdb, inx)
X	struct kef_db * kdb;
X	kef_index * inx;
X/*
X * Walk depth-first through tree of character cells.
X * It must be possible to build string from this information so
X * this routine sets fields "tag" which are unused execpt in cleanup
X * to point at father node. String can be built backwards by running
X * up chain of "tag" links. The "tag" stuff also serves as a stack
X * so we don't have to hold a stack to retrace our steps on the tree.
X * Returns normal KEF error codes.
X * If "*inx == KEF_NIL" on start, we start at the top of the tree.
X * At end : the end of the tree is reached, when "*inx == KEF_NIL"
X */
X{
X	DI("kef_walk ::")
X	register kef_index at, up;
X	register struct kef_node * nd;
X
X	DEB2("%s started at node %1d\n", *inx);
X	nd = kdb->node;
X	if (*inx == KEF_NIL) {
X		at = kdb->root;
X		nd[at].tag = KEF_NIL;		/* put an end for retracing */
X	} else
X		at = *inx;
X	DEB2("%s current node = %1d\n", at);
X
X	/*
X	 * Continue walk through tree.
X	 * First try to go down.
X	 */
X	if (nd[at].sub != KEF_NIL) {
X		/*
X		 * Can go down.
X		 */
X		up = at;
X		at = nd[at].sub;
X		nd[at].tag = up;		/* set pointer to parent node */
X		DEB2("%s stepped down to %1d\n", at);
X	} else {
X		while (at != kdb->root && nd[at].next == KEF_NIL) {
X			at = nd[at].tag;
X			DEB2 ("%s retracing to %1d\n", at);
X		}
X		if (at != kdb->root) {
X			DEB2 ("%s go right to %1d\n", at);
X			up = nd[at].tag;
X			at = nd[at].next;
X			nd[at].tag = up;		/* set pointer to parent node */
X		} else
X			at = KEF_NIL;
X	}
X	*inx = at;
X	DEB2("%s return node index %1d\n", at);
X	return KEF_E_OK;
X}
X
X	int
Xkef_get_value (kdb, pos, val)
X	struct kef_db * kdb;
X	kef_index pos;
X	kef_value * val;
X/*
X * Returns 1 if value, 0 else.
X * Sets val to value.
X */
X{
X	DI("kef_get_value ::")
X
X	if (HAS_VALUE(kdb->node[pos])) {
X		DEB3("%s value at node %1d : %1d\n", pos, kdb->node[pos].value);
X		*val = kdb->node[pos].value;
X		return 1;
X	} else {
X		DEB2("%s no value at node %1d\n", pos);
X		return 0;
X	}
X}
END_OF_FILE
if test 2206 -ne `wc -c <'kdb-low/walk.c'`; then
    echo shar: \"'kdb-low/walk.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/walk.c'
fi
if test -f 'kdb-low/write.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kdb-low/write.c'\"
else
echo shar: Extracting \"'kdb-low/write.c'\" \(2054 characters\)
sed "s/^X//" >'kdb-low/write.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  write.c  (v1.6 3/15/90)";
X
X/*
X * Write a kdb structure to file.
X *
X * File structure:
X * - header
X * - kdb structure padded to fit yield 4 byte alignment. This is because
X *   If a compiler chooses to rearrange the fields, we are licked, though.
X * - nodes (must be 2 byte aligned)
X *
X * Conversion (swap) is done on read.
X * Don't use fwrite/fread : they may introduce malloc calls by including
X * _flsbuf (the routine used by stdin to fill its buffers).
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_IO
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef_write(fd, kdb)
X	int fd;
X	struct kef_db * kdb;
X/*
X * Write a kdb structure to file fd.
X *
X * Format on file:
X * - num_nodes
X * - kdb structure
X * - nodes
X */
X{
X	DI("kef_write ::")
X	int n;
X	struct kef_fheader kfh;
X
X	DEB1("%s called \n");
X
X	kfh.magic[0] = KEF_MAGIC0;
X	kfh.magic[1] = KEF_MAGIC1;
X	kfh.magic[2] = KEF_MAGIC2;
X	kfh.magic[3] = KEF_MAGIC3;
X	/*
X	 * Set swap to value 0x0201. On little endian machines this
X	 * will be written to a file as 0102, on big endian machines it
X	 * will be 0201.
X	 */
X	kfh.swap = 0x0201;
X	kfh.num_nodes = kdb->high_nodes;
X	kfh.size_kdb = (int)(&(kdb->node)) - (int)(kdb);
X	kfh.size_node = sizeof (struct kef_node);
X
X# ifdef L_DEBUG
X	dump_fheader (prot, &kfh);
X# endif
X
X	if (write (fd, &kfh, sizeof(kfh)) != sizeof(kfh))
X		return KEF_E_WRITE_ERROR;
X	DEB2("%s wrote header with %1d characters\n", sizeof(kfh));
X
X	/*
X	 * Write kef_db.
X	 */
X	n = kfh.size_kdb;
X	if (write (fd, kdb, n) != n)
X		return KEF_E_WRITE_ERROR;
X	DEB2("%s wrote kef_db struct with %1d characters\n", n);
X
X	if (n & 0x03) {
X		/*
X		 * Pad the kef_db structure.
X		 */
X		n = 4 - (n & 0x03);
X		if (write (fd, kdb, n) != n)
X			return KEF_E_WRITE_ERROR;
X		DEB2("%s wrote padding %1d characters\n", n);
X	}
X
X	n = kfh.num_nodes * sizeof (struct kef_node);
X	if (write (fd, kdb->node, n) != n)
X		return KEF_E_WRITE_ERROR;
X	DEB2("%s wrote node total of %1d characters\n", n);
X
X	DEB1("%s done.\n");
X
X	return KEF_E_OK;
X}
END_OF_FILE
if test 2054 -ne `wc -c <'kdb-low/write.c'`; then
    echo shar: \"'kdb-low/write.c'\" unpacked with wrong size!
fi
# end of 'kdb-low/write.c'
fi
if test ! -d 'kef' ; then
    echo shar: Creating directory \"'kef'\"
    mkdir 'kef'
fi
if test -f 'kef/Makefile.SH' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kef/Makefile.SH'\"
else
echo shar: Extracting \"'kef/Makefile.SH'\" \(2210 characters\)
sed "s/^X//" >'kef/Makefile.SH' <<'END_OF_FILE'
Xrmconfig='no'
Xcase $CONFIG in
X'')
X	if test ! -f config.sh; then
X		ln ../config.sh . || \
X			ln ../../config.sh . || \
X			ln ../../../config.sh . || \
X			(echo "Can't find config.sh."; exit 1)
X		rmconfig='yes'
X	fi
X	. config.sh
X	;;
Xesac
X: This forces SH files to create target in same directory as SH file.
X: This is so that make depend always knows where to find SH derivatives.
Xcase "$0" in
X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
Xesac
Xecho "Extracting kef/Makefile (with variable substitutions)"
X: Some headers, do no variable substitution
X$spitshell >Makefile <<'!NO!SUBS!'
X#
X# Makefile for KEF
X#
X# sccsid = @(#)  Makefile  (v2.2 5/2/90)
X#
X
X#
X# Some general stuff
X#
XSHELL	=	/bin/sh
XSCCSPATH=
X!NO!SUBS!
X: This section of the file will have variable substitutions done on it.
X: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
X: Protect any dollar signs and backticks that you do not want interpreted
X: by putting a backslash in front.  You may delete these comments.
X$spitshell >>Makefile <<!GROK!THIS!
X#
X# The values of the following variables come from config.sh which has
X# been generated by running the Configure script.
XCC=$cc
XSTDCFLAGS=$ccflags
XLDFLAGS=$ldflags
X!GROK!THIS!
X
X: In the following dollars and backticks do not need the extra backslash.
X$spitshell >>Makefile <<'!NO!SUBS!'
X
X# Debug flags go into DEB. Delete the object and recompile.
X# Debug info is written to "FILE * prot"
X#
X#     flag          |	file
X#   ----------------+------------------
X#	DEBUG_INIT		|	create.c, mcreate.c, _init.c
X#	DEBUG_GET		|	get.c, look_wait.c
X#	DEBUG_FILL		|	fill.c
XDEB		=
X
X#
X# INCL should be pointing at the directory kef.h etc. are in.
X#
XINCL	=	-I..
X
X#
X# Compile flags
X#
XCFLAGS	=	${STDCFLAGS} ${DEB} ${INCL}
X
X#
X# Object files
X#
XOBJS	=	_init.o create.o fill.o get.o set.o mcreate.o look_wait.o
XDOBJS	=	dump.o
X
XKEF_LIB	=	../libkef.a
XKEF_DLIB=	../libDkef.a
X
X
X#
X# Dependencies
X# ============
X#
X
Xall:	${KEF_LIB} ${KEF_DLIB}
X
X${KEF_LIB}: ${OBJS}
X	ar rv ${KEF_LIB} $?
X	ranlib ${KEF_LIB}
X
X${KEF_DLIB}: ${DOBJS}
X	ar rv ${KEF_DLIB} $?
X	ranlib ${KEF_DLIB}
X
X${OBJS}: ../kef.h
X${DOBJS}: ../kef.h
X!NO!SUBS!
Xchmod 755 Makefile
X$eunicefix Makefile
Xif test "$rmconfig" = "yes" ; then
X	rm -f config.sh
Xfi
END_OF_FILE
if test 2210 -ne `wc -c <'kef/Makefile.SH'`; then
    echo shar: \"'kef/Makefile.SH'\" unpacked with wrong size!
fi
# end of 'kef/Makefile.SH'
fi
if test -f 'kef/_init.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kef/_init.c'\"
else
echo shar: Extracting \"'kef/_init.c'\" \(1144 characters\)
sed "s/^X//" >'kef/_init.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  _init.c  (v1.1 3/27/90)";
X
X/*
X * Initialize a kef structure, without using malloc/realloc/free.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_INIT
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef__init (k, buf, buf_size, kdb, fd, my_malloc, my_realloc, my_free)
X	struct kef * k;
X	byte * buf;
X	int buf_size;
X	struct kef_db * kdb;
X	int fd;
X	char * (* my_malloc) ();
X	char * (* my_realloc)();
X	FREE_TYPE (* my_free) ();
X/*
X * Initialize an object of type kef with appendages.
X */
X{
X	DI("kef__init ::")
X
X	DEB6("%s called with k=%1d, buf=%1d, buf_size=%1d, kdb=%1d, fd=%1d\n",
X		(long)k, buf, buf_size, (long)kdb, fd);
X
X	if (k == NULL || buf == NULL || buf_size <= 0)
X		return KEF_E_INV_PAR;
X
X	/*
X	 * Initialize the stuff in the new structure.
X	 */
X	k->fd = fd;
X
X	k->is_delay = 1;
X	k->delay = 0;
X	k->is_timeout = 1;
X	k->timeout = 500;
X
X	k->buf = buf;
X	k->size_buf = buf_size;
X
X	k->buf_end = NULL;
X	k->from = k->to = k->cur = k->buf;
X
X	k->db = kdb;
X	k->malloc = my_malloc;
X	k->realloc = my_realloc;
X	k->free = my_free;
X
X	k->use_db = 1;
X
X	return KEF_E_OK;
X}
END_OF_FILE
if test 1144 -ne `wc -c <'kef/_init.c'`; then
    echo shar: \"'kef/_init.c'\" unpacked with wrong size!
fi
# end of 'kef/_init.c'
fi
if test -f 'kef/create.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kef/create.c'\"
else
echo shar: Extracting \"'kef/create.c'\" \(552 characters\)
sed "s/^X//" >'kef/create.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  create.c  (v2.6 4/17/90)";
X
X/*
X * Initialize a kef structure.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X/*
X * Frontend for kef_mcreate; OS' standard malloc/realloc/free are included
X */
X
Xextern char * malloc ();
Xextern char * realloc ();
Xextern FREE_TYPE free ();
X
X	int
Xkef_create (pk, buf, buf_size, kdb, fd)
X	struct kef ** pk;
X	byte * buf;
X	int buf_size;
X	struct kef_db * kdb;
X	int fd;
X/*
X * Create an object of type kef with appendages.
X */
X{
X	return kef_mcreate(pk, buf, buf_size, kdb, fd, malloc, realloc, free);
X}
END_OF_FILE
if test 552 -ne `wc -c <'kef/create.c'`; then
    echo shar: \"'kef/create.c'\" unpacked with wrong size!
fi
# end of 'kef/create.c'
fi
if test -f 'kef/dump.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kef/dump.c'\"
else
echo shar: Extracting \"'kef/dump.c'\" \(1489 characters\)
sed "s/^X//" >'kef/dump.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  dump.c  (v5.1 8/31/89)";
X/*
X * Dump various parts of the structures
X */
X
X# include <stdio.h>
X# include "kef.h"
X# include <ctype.h>
X
Xextern struct kef ** kef_table;
Xextern int kef_size_db_table;
X
Xextern char * malloc ();
Xextern char * realloc ();
Xextern FREE_TYPE free ();
X
Xdump_kef (f, k)
X	FILE * f;
X	struct kef * k;
X{
X	fprintf (f, "Dump of kef structure at %1d\n", k);
X
X	fprintf (f, "fd           = %3d (filedescriptor)\n", k->fd);
X	fprintf (f, "delay        = %3s %4d\n",k->is_delay?"ON ":"OFF",k->delay);
X	fprintf (f, "timeout      = %3s %4d\n",k->is_timeout?"ON ":"OFF",k->timeout);
X	fprintf (f, "use_db       = %3s\n", k->use_db ? "yes" : "no ");
X	fprintf (f, "buffer at    = %1d\n", k->buf);
X	fprintf (f, "from at      = %1d offset %1d\n", k->from,
X		(int)((char *)k->from - (char *)k->buf));
X	fprintf (f, "cur at       = %1d offset %1d\n", k->cur,
X		(int)((char *)k->cur - (char *)k->buf));
X	fprintf (f, "to at        = %1d offset %1d\n", k->to,
X		(int)((char *)k->to - (char *)k->buf));
X	fprintf (f, "buf_end   at = %1d\n", k->buf_end);
X	fprintf (f, "kef_db at    = %d\n", k->db);
X	fprintf (f, "malloc       = %s\n", k->malloc == NULL ? "NULL":
X		(k->malloc == malloc ? "malloc" : "some routine"));
X	fprintf (f, "realloc      = %s\n", k->realloc == NULL ? "NULL":
X		(k->realloc == realloc ? "realloc" : "some routine"));
X	fprintf (f, "free         = %s\n", k->free == NULL ? "NULL":
X		(k->free == free ? "free" : "some routine"));
X	return KEF_E_OK;
X}
END_OF_FILE
if test 1489 -ne `wc -c <'kef/dump.c'`; then
    echo shar: \"'kef/dump.c'\" unpacked with wrong size!
fi
# end of 'kef/dump.c'
fi
if test -f 'kef/mcreate.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kef/mcreate.c'\"
else
echo shar: Extracting \"'kef/mcreate.c'\" \(1339 characters\)
sed "s/^X//" >'kef/mcreate.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  mcreate.c  (v2.10 4/17/90)";
X
X/*
X * Create a kef structure and call _init to initialize it.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_CREATE
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef_mcreate (pk, buf, buf_size, kdb, fd, my_malloc, my_realloc, my_free)
X	struct kef ** pk;
X	byte * buf;
X	int buf_size;
X	struct kef_db * kdb;
X	int fd;
X	char * (* my_malloc) ();
X	char * (* my_realloc)();
X	FREE_TYPE (* my_free) ();
X/*
X * Create an object of type kef with appendages.
X */
X{
X	DI("kef_create ::")
X	register struct kef * k;
X	byte * mybuf;
X
X	DEB6("%s called with pk=%1d, buf=%1d, buf_size=%1d, kdb=%1d, fd=%1d\n",
X		(int)pk, buf, buf_size, (int)kdb, fd);
X	if (my_malloc == NULL)
X		return KEF_E_NO_MALLOC;
X	/*
X	 * Allocate a new kef structure.
X	 */
X	k = (struct kef *) (* my_malloc) (sizeof (struct kef));
X	if (k == NULL)
X		return KEF_E_ALLOC_FAILED;
X
X	if (buf == NULL) {
X		/*
X		 * Allocate buffer.
X		 */
X		if (buf_size == 0)
X			buf_size = 512;
X		mybuf = (byte *) (* my_malloc) (buf_size);
X		if (mybuf == NULL)
X			return KEF_E_ALLOC_FAILED;
X	} else {
X		if (buf_size <= 0)
X			return KEF_E_INV_PAR;
X		/*
X		 * Use the parameter.
X		 */
X		mybuf = buf;
X	}
X
X	*pk = k;
X
X	return
X		kef__init (k, mybuf, buf_size, kdb, fd, my_malloc, my_realloc, my_free);
X}
END_OF_FILE
if test 1339 -ne `wc -c <'kef/mcreate.c'`; then
    echo shar: \"'kef/mcreate.c'\" unpacked with wrong size!
fi
# end of 'kef/mcreate.c'
fi
if test -f 'kef/set.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kef/set.c'\"
else
echo shar: Extracting \"'kef/set.c'\" \(1541 characters\)
sed "s/^X//" >'kef/set.c' <<'END_OF_FILE'
Xstatic char * sccsid = "@(#)  set.c  (v2.4 4/26/90)";
X/*
X * Set timeout and delay.
X */
X
X# include <stdio.h>
X# include "kef.h"
X
X#ifdef DEBUG_SET
X#	define L_DEBUG
X#else
X#	ifdef L_DEBUG
X#		undef L_DEBUG
X#	endif
X#endif
X# include "local.h"
X
X	int
Xkef_set_timeout (k, msec, ind)
X	struct kef * k;
X	int ind;
X	int msec;
X/*
X * Set timeout.
X * 
X * ind = 0 : set "no timeout"
X *       1 : set timeout to value in msec
X */
X{
X	switch (ind) {
X		case 0:
X			k->is_timeout = 0;
X			break;
X		case 1:
X			k->is_timeout = 1;
X			k->timeout = msec;
X			break;
X		default:
X			return KEF_E_INV_PAR;
X	}
X	return KEF_E_OK;
X}
X
X	int
Xkef_set_delay (k, msec, ind)
X	struct kef * k;
X	int ind;
X	int msec;
X/*
X * Set delay (= timeout when waiting for first character).
X * 
X * ind = 0 : set "no delay"
X *       1 : set delay to value in msec
X */
X{
X	switch (ind) {
X		case 0:
X			k->is_delay = 0;
X			break;
X		case 1:
X			k->is_delay = 1;
X			k->delay = msec;
X			break;
X		default:
X			return KEF_E_INV_PAR;
X	}
X	return KEF_E_OK;
X}
X
X	int
Xkef_get_timeout (k, msec)
X	struct kef * k;
X	int * msec;
X/*
X * Get timeout.
X * 
X * ind = 0 : set "no timeout"
X *       1 : set timeout to value in msec
X * returns:
X *		value 0 : no timeout, 1 : timeout active
X */
X{
X	*msec = k->timeout;
X	return k->is_timeout;
X}
X
X	int
Xkef_get_delay (k, msec)
X	struct kef * k;
X	int * msec;
X/*
X * Get delay (= timeout when waiting for first character).
X * 
X * ind = 0 : set "no delay"
X *       1 : set delay to value in msec
X * returns:
X *		value 0 : no delay, 1 : delay active
X */
X{
X	*msec = k->delay;
X	return k->is_delay;
X}
END_OF_FILE
if test 1541 -ne `wc -c <'kef/set.c'`; then
    echo shar: \"'kef/set.c'\" unpacked with wrong size!
fi
# end of 'kef/set.c'
fi
if test -f 'local.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'local.h'\"
else
echo shar: Extracting \"'local.h'\" \(1296 characters\)
sed "s/^X//" >'local.h' <<'END_OF_FILE'
X/*
X * sccsid = @(#)  local.h  (v2.1 3/9/90)
X *
X * Local definitions for debugging.
X *
X * This file is included in several source files.
X * The caller must have either set or unset L_DEBUG
X * The macros with DEB end with no ";". The ";" is supplied in the
X * routines. This will result in some spurious stuff but the compiler
X * should ignore empty statements.
X * Unfortunately DI must include the ";". Don't supply one when calling.
X * This is because DI is the first declaration in a routine, and there
X * is no such thing as an empty declaration. If DI is undefined on BSD systems
X * one could do something like "int;", but this is confusing, so I drop it.
X */
X
X#ifdef L_DEBUG
Xextern FILE * prot;
X#	define DEB1(p1)					fprintf(prot,p1,I)
X#	define DEB2(p1,p2)				fprintf (prot,p1,I,p2)
X#	define DEB3(p1,p2,p3)			fprintf (prot,p1,I,p2,p3)
X#	define DEB4(p1,p2,p3,p4)		fprintf (prot,p1,I,p2,p3,p4)
X#	define DEB5(p1,p2,p3,p4,p5)		fprintf (prot,p1,I,p2,p3,p4,p5)
X#	define DEB6(p1,p2,p3,p4,p5,p6)	fprintf (prot,p1,I,p2,p3,p4,p5,p6)
X#	define FLUSH					fflush (prot)
X#	define DI(s)					static char * I = s;
X#else
X#	define DEB1(p1)
X#	define DEB2(p1,p2)
X#	define DEB3(p1,p2,p3)
X#	define DEB4(p1,p2,p3,p4)
X#	define DEB5(p1,p2,p3,p4,p5)
X#	define DEB6(p1,p2,p3,p4,p5,p6)
X#	define FLUSH
X#	define DI(s)
X#endif
END_OF_FILE
if test 1296 -ne `wc -c <'local.h'`; then
    echo shar: \"'local.h'\" unpacked with wrong size!
fi
# end of 'local.h'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL	0
END_OF_FILE
if test 21 -ne `wc -c <'patchlevel.h'`; then
    echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
fi
echo shar: End of archive 1 \(of 5\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 5 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
 .-. .-.  .-.  Michael Greim
(   X   )( __) e-mail : greim@cs.uni-sb.de
 \ / \ /  \ /  or     : ...!uunet!unido!sbsvax!greim
  ~   ~    ~
