From 02ac0a77d27046442a63371dbf37ee5c0c452dee Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 22 Sep 1994 10:43:34 +0000 Subject: [PATCH] Two versions of depend. Type 1 is the tail-type compatible with all make programs. Type 2 is the GNU make with include facility. Type 2 is default. depend rule chooses current rule. --- bfile/Makefile | 12 ++++- dict/Makefile | 18 +++++-- dict/dicttest.c | 31 +++++++++-- dict/lookupec.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 10 deletions(-) create mode 100644 dict/lookupec.c diff --git a/bfile/Makefile b/bfile/Makefile index 3fa5f2f..5c80307 100644 --- a/bfile/Makefile +++ b/bfile/Makefile @@ -23,9 +23,19 @@ $(LIB): $(PO) clean: rm -f *.[oa] $(TPROG) core mon.out gmon.out errlist -dep depend: +depend: depend2 + +depend1: mv Makefile Makefile.tmp sed '/^#Depend/q' Makefile $(CPP) $(INCLUDE) -M *.c >>Makefile + -rm Makefile.tmp + +depend2: + $(CPP) $(INCLUDE) -M *.c >.depend + +ifeq (.depend,$(wildcard .depend)) +include .depend +endif #Depend --- DOT NOT DELETE THIS LINE diff --git a/dict/Makefile b/dict/Makefile index f75d118..d94ad4b 100644 --- a/dict/Makefile +++ b/dict/Makefile @@ -1,16 +1,16 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.9 1994-09-20 09:02:56 adam Exp $ +# $Id: Makefile,v 1.10 1994-09-22 10:43:43 adam Exp $ SHELL=/bin/sh INCLUDE=-I../include TPROG1=dicttest TPROG2=dictext -CFLAGS=-O -Wall -g -pedantic +CFLAGS=-g -Wall -pedantic DEFS=$(INCLUDE) LIB=../lib/dict.a -PO = dopen.o dclose.o drdwr.o open.o close.o insert.o lookup.o +PO = dopen.o dclose.o drdwr.o open.o close.o insert.o lookup.o lookupec.o CPP=cc -E all: $(LIB) @@ -33,9 +33,19 @@ $(LIB): $(PO) clean: rm -f *.[oa] $(TPROG1) $(TPROG2) core mon.out gmon.out errlist -dep depend: +depend: depend2 + +depend1: mv Makefile Makefile.tmp sed '/^#Depend/q' Makefile $(CPP) $(INCLUDE) -M *.c >>Makefile + -rm Makefile.tmp + +depend2: + $(CPP) $(INCLUDE) -M *.c >.depend + +ifeq (.depend,$(wildcard .depend)) +include .depend +endif #Depend --- DOT NOT DELETE THIS LINE diff --git a/dict/dicttest.c b/dict/dicttest.c index 36cebc1..8d8f861 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -4,7 +4,12 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dicttest.c,v $ - * Revision 1.7 1994-09-19 16:34:26 adam + * Revision 1.8 1994-09-22 10:43:44 adam + * Two versions of depend. Type 1 is the tail-type compatible with + * all make programs. Type 2 is the GNU make with include facility. + * Type 2 is default. depend rule chooses current rule. + * + * Revision 1.7 1994/09/19 16:34:26 adam * Depend rule change. Minor changes in dicttest.c * * Revision 1.6 1994/09/16 15:39:12 adam @@ -39,11 +44,18 @@ char *prog; Dict dict; +static int lookup_handle (Dict_char *name) +{ + printf ("%s\n", name); + return 0; +} + int main (int argc, char **argv) { const char *name = NULL; const char *inputfile = NULL; const char *base = NULL; + int range = -1; int rw = 0; int infosize = 4; int cache = 10; @@ -57,12 +69,13 @@ int main (int argc, char **argv) prog = argv[0]; if (argc < 2) { - fprintf (stderr, "usage:\n" - " %s [-u] [-s n] [-v n] [-i f] [-w] [-c n] base file\n", + fprintf (stderr, "usage:\n " + " %s [-r n] [-u] [-s n] [-v n] [-i f] [-w] [-c n]" + " base file\n", prog); exit (1); } - while ((ret = options ("us:v:i:wc:", argv, argc, &arg)) != -2) + while ((ret = options ("r:us:v:i:wc:", argv, argc, &arg)) != -2) { if (ret == 0) { @@ -76,6 +89,10 @@ int main (int argc, char **argv) exit (1); } } + else if (ret == 'r') + { + range = atoi (arg); + } else if (ret == 'u') { unique = 1; @@ -169,7 +186,7 @@ int main (int argc, char **argv) break; } } - else + else if(range < 0) { char *cp; @@ -179,6 +196,10 @@ int main (int argc, char **argv) else no_of_misses++; } + else + { + dict_lookup_ec (dict, ipf_ptr, range, lookup_handle); + } ++no_of_iterations; ipf_ptr += (i-1); } diff --git a/dict/lookupec.c b/dict/lookupec.c new file mode 100644 index 0000000..56e5384 --- /dev/null +++ b/dict/lookupec.c @@ -0,0 +1,154 @@ +/* + * Copyright (C) 1994, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: lookupec.c,v $ + * Revision 1.1 1994-09-22 10:43:44 adam + * Two versions of depend. Type 1 is the tail-type compatible with + * all make programs. Type 2 is the GNU make with include facility. + * Type 2 is default. depend rule chooses current rule. + * + */ + +#include +#include +#include +#include + +#include + +typedef unsigned MatchWord; + +typedef struct { + MatchWord *s; + int m; +} MatchInfo; + +#define SH(x) (((x)<<1)+1) + +int dict_look_ec (Dict dict, MatchInfo *mi, MatchWord *ri_base, int pos, + int (*userfunc)(Dict_char *), int range) +{ + Dict_ptr ptr = 1; + int mid, lo, hi; + void *p; + short *indxp; + char *info; + MatchWord match_mask = 1<<(mi->m-1); + + dict_bf_readp (dict->dbf, ptr, &p); + mid = lo = 0; + hi = DICT_nodir(p)-1; + indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + while (lo <= hi) + { + mid = lo; + if (indxp[-mid] > 0) + { + /* string (Dict_char *) DICT_EOS terminated */ + /* unsigned char length of information */ + /* char * information */ + MatchWord *ri = ri_base, sc; + int i, j; + info = (char*)p + indxp[-mid]; + for (j=0; ; j++) + { + Dict_char ch; + + memcpy (&ch, info+j*sizeof(Dict_char), sizeof(Dict_char)); + if (j && (ri[-1] & match_mask)) + { + if (ch == DICT_EOS) + (*userfunc)(info); + break; + } + if (j > mi->m+range-pos) + break; + if (ch == DICT_EOS) + break; + sc = mi->s[ch & 255]; + ri[1+range] = SH(ri[0]) & sc; + for (i=1; i<=range; i++) + ri[i+1+range] = (SH(ri[i])&sc) | SH(ri[i-1]) + | SH(ri[i+range]) | ri[i-1]; + ri += 1+range; + } + } +#if 0 + else + { + Dict_char dc; + Dict_ptr subptr; + + /* Dict_ptr subptr */ + /* Dict_char sub char */ + /* unsigned char length of information */ + /* char * information */ + info = (char*)p - indxp[-mid]; + memcpy (&dc, info+sizeof(Dict_ptr), sizeof(Dict_char)); + cmp = dc- *str; + if (!cmp) + { + memcpy (&subptr, info, sizeof(Dict_ptr)); + if (*++str == DICT_EOS) + return info+sizeof(Dict_ptr)+sizeof(Dict_char); + else + { + if (subptr == 0) + return NULL; + ptr = subptr; + dict_bf_readp (dict->dbf, ptr, &p); + mid = lo = 0; + hi = DICT_nodir(p)-1; + indxp = (short*) ((char*) p+DICT_PAGESIZE-sizeof(short)); + continue; + } + } + + } +#endif + lo++; + } + return 0; +} + +static MatchInfo *prepare_match (Dict_char *pattern) +{ + int i; + MatchWord *s; + MatchInfo *mi; + + mi = xmalloc (sizeof(*mi)); + mi->m = dict_strlen (pattern); + mi->s = s = xmalloc (sizeof(*s)*256); /* 256 !!! */ + for (i=0; i<256; i++) + s[i] = 0; + for (i=0; pattern[i]; i++) + s[pattern[i]&255] += 1<head.last == 1) + return 0; + + mi = prepare_match (pattern); + ri = xmalloc ((dict_strlen(pattern)+range+2)*(range+1)*sizeof(*ri)); + for (i=0; i<=range; i++) + ri[i] = (2<