From b31a8654c5b7a597dd4a351f452ac91e5ef60798 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 2 Feb 1996 13:43:50 +0000 Subject: [PATCH] The public functions simply use char instead of Dict_char to represent search strings. Dict_char is used internally only. --- dict/delete.c | 10 +++++++--- dict/dicttest.c | 8 ++++++-- dict/insert.c | 21 +++++++++++++-------- dict/lookgrep.c | 19 ++++++++++++------- dict/lookup.c | 13 +++++++++---- dict/lookupec.c | 23 ++++++++++++++--------- dict/open.c | 10 +++++++--- dict/scan.c | 33 +++++++++++++++++++-------------- include/dict.h | 25 ++++++++++++++----------- 9 files changed, 101 insertions(+), 61 deletions(-) diff --git a/dict/delete.c b/dict/delete.c index e5be225..cb9d64d 100644 --- a/dict/delete.c +++ b/dict/delete.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: delete.c,v $ - * Revision 1.3 1995-12-07 11:48:55 adam + * Revision 1.4 1996-02-02 13:43:50 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.3 1995/12/07 11:48:55 adam * Insert operation obeys DICT_type = 1 (slack in page). * Function dict_open exists if page size or magic aren't right. * @@ -108,9 +112,9 @@ static int dict_del (Dict dict, const Dict_char *str) return 0; } -int dict_delete (Dict dict, const Dict_char *p) +int dict_delete (Dict dict, const char *p) { if (dict->head.last == 1) return 0; - return dict_del (dict, p); + return dict_del (dict, (const Dict_char*) p); } diff --git a/dict/dicttest.c b/dict/dicttest.c index 5d97bb2..181f14a 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dicttest.c,v $ - * Revision 1.18 1996-02-01 20:39:52 adam + * Revision 1.19 1996-02-02 13:43:50 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.18 1996/02/01 20:39:52 adam * Bug fix: insert didn't work on 8-bit characters due to unsigned char * compares in dict_strcmp (strcmp) and signed Dict_char. Dict_char is * unsigned now. @@ -79,7 +83,7 @@ static Dict dict; static int look_hits; -static int grep_handle (Dict_char *name, const char *info, void *client) +static int grep_handle (char *name, const char *info, void *client) { look_hits++; printf ("%s\n", name); diff --git a/dict/insert.c b/dict/insert.c index 5ec6d4c..b3b6a47 100644 --- a/dict/insert.c +++ b/dict/insert.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: insert.c,v $ - * Revision 1.15 1996-02-01 20:39:59 adam + * Revision 1.16 1996-02-02 13:43:50 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.15 1996/02/01 20:39:59 adam * Bug fix: insert didn't work on 8-bit characters due to unsigned char * compares in dict_strcmp (strcmp) and signed Dict_char. Dict_char is * unsigned now. @@ -159,7 +163,7 @@ static int split_page (Dict dict, Dict_ptr ptr, void *p) /* entry start */ memcpy (&dc, info, sizeof(dc)); assert (dc == best_char); - slen = dict_strlen(info); + slen = dict_strlen((Dict_char*) info); assert (slen > 0); if (slen == 1) @@ -170,7 +174,8 @@ static int split_page (Dict dict, Dict_ptr ptr, void *p) else { info1 = info+(1+slen)*sizeof(Dict_char); /* info start */ - dict_ins (dict, info+sizeof(Dict_char), subptr, *info1, info1+1); + dict_ins (dict, (Dict_char*) (info+sizeof(Dict_char)), + subptr, *info1, info1+1); dict_bf_readp (dict->dbf, ptr, &p); } } @@ -220,7 +225,7 @@ static void clean_page (Dict dict, Dict_ptr ptr, void *p, Dict_char *out, continue; } *--indxp2 = info2 - np; - slen = (dict_strlen(info1)+1)*sizeof(Dict_char); + slen = (dict_strlen((Dict_char*) info1)+1)*sizeof(Dict_char); memcpy (info2, info1, slen); info1 += slen; info2 += slen; @@ -300,7 +305,7 @@ static int dict_ins (Dict dict, const Dict_char *str, cmp = dict_strcmp((Dict_char*) info, str); if (!cmp) { - info += (dict_strlen(info)+1)*sizeof(Dict_char); + info += (dict_strlen((Dict_char*) info)+1)*sizeof(Dict_char); /* consider change of userinfo length... */ if (*info == userlen) { @@ -468,12 +473,12 @@ static int dict_ins (Dict dict, const Dict_char *str, return 1; } -int dict_insert (Dict dict, const Dict_char *str, int userlen, void *userinfo) +int dict_insert (Dict dict, const char *str, int userlen, void *userinfo) { assert (dict->head.last > 0); if (dict->head.last == 1) - return dict_ins (dict, str, 0, userlen, userinfo); + return dict_ins (dict, (const Dict_char *) str, 0, userlen, userinfo); else - return dict_ins (dict, str, 1, userlen, userinfo); + return dict_ins (dict, (const Dict_char *) str, 1, userlen, userinfo); } diff --git a/dict/lookgrep.c b/dict/lookgrep.c index 2336970..2fd3533 100644 --- a/dict/lookgrep.c +++ b/dict/lookgrep.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookgrep.c,v $ - * Revision 1.13 1996-01-08 09:09:30 adam + * Revision 1.14 1996-02-02 13:43:51 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.13 1996/01/08 09:09:30 adam * Function dfa_parse got 'const' string argument. * * Revision 1.12 1995/12/11 09:04:48 adam @@ -257,7 +261,7 @@ static INLINE int move (MatchContext *mc, MatchWord *Rj1, MatchWord *Rj, static int dict_grep (Dict dict, Dict_ptr ptr, MatchContext *mc, MatchWord *Rj, int pos, void *client, - int (*userfunc)(Dict_char *, const char *, void *), + int (*userfunc)(char *, const char *, void *), Dict_char *prefix, struct DFA *dfa, int *max_pos) { @@ -295,8 +299,8 @@ static int dict_grep (Dict dict, Dict_ptr ptr, MatchContext *mc, if (ch == DICT_EOS) { if (was_match) - if ((*userfunc)(prefix, info+(j+1)*sizeof(Dict_char), - client)) + if ((*userfunc)((char*) prefix, + info+(j+1)*sizeof(Dict_char), client)) return 1; break; } @@ -344,7 +348,8 @@ static int dict_grep (Dict dict, Dict_ptr ptr, MatchContext *mc, if (Rj1[mc->range*mc->n + d] & mc->match_mask[d]) { prefix[pos+1] = DICT_EOS; - if ((*userfunc)(prefix, info+sizeof(Dict_ptr)+ + if ((*userfunc)((char*) prefix, + info+sizeof(Dict_ptr)+ sizeof(Dict_char), client)) return 1; break; @@ -367,9 +372,9 @@ static int dict_grep (Dict dict, Dict_ptr ptr, MatchContext *mc, return 0; } -int dict_lookup_grep (Dict dict, Dict_char *pattern, int range, void *client, +int dict_lookup_grep (Dict dict, const char *pattern, int range, void *client, int *max_pos, - int (*userfunc)(Dict_char *name, const char *info, + int (*userfunc)(char *name, const char *info, void *client)) { MatchWord *Rj; diff --git a/dict/lookup.c b/dict/lookup.c index 46a13c4..01f5ac4 100644 --- a/dict/lookup.c +++ b/dict/lookup.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookup.c,v $ - * Revision 1.6 1995-12-11 09:04:50 adam + * Revision 1.7 1996-02-02 13:43:51 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.6 1995/12/11 09:04:50 adam * Bug fix: the lookup/scan/lookgrep didn't handle empty dictionary. * * Revision 1.5 1995/09/04 09:09:15 adam @@ -55,7 +59,8 @@ static char *dict_look (Dict dict, const Dict_char *str) info = (char*)p + indxp[-mid]; cmp = dict_strcmp((Dict_char*) info, str); if (!cmp) - return info+(dict_strlen (info)+1)*sizeof(Dict_char); + return info+(dict_strlen ((Dict_char*) info)+1) + *sizeof(Dict_char); } else { @@ -100,11 +105,11 @@ static char *dict_look (Dict dict, const Dict_char *str) return NULL; } -char *dict_lookup (Dict dict, const Dict_char *p) +char *dict_lookup (Dict dict, const char *p) { if (dict->head.last <= 1) return NULL; - return dict_look (dict, p); + return dict_look (dict, (const Dict_char *) p); } diff --git a/dict/lookupec.c b/dict/lookupec.c index 95ead81..686aa04 100644 --- a/dict/lookupec.c +++ b/dict/lookupec.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookupec.c,v $ - * Revision 1.5 1995-01-24 16:01:03 adam + * Revision 1.6 1996-02-02 13:43:51 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.5 1995/01/24 16:01:03 adam * Added -ansi to CFLAGS. * Use new API of dfa module. * @@ -41,8 +45,8 @@ typedef struct { #define SH(x) (((x)<<1)+1) int dict_look_ec (Dict dict, Dict_ptr ptr, MatchInfo *mi, MatchWord *ri_base, - int pos, int (*userfunc)(Dict_char *), - int range, Dict_char *prefix) + int pos, int (*userfunc)(char *), int range, + Dict_char *prefix) { int lo, hi; void *p; @@ -73,7 +77,7 @@ int dict_look_ec (Dict dict, Dict_ptr ptr, MatchInfo *mi, MatchWord *ri_base, if (ch == DICT_EOS) { if (ri[range] & match_mask) - (*userfunc)(prefix); + (*userfunc)((char*) prefix); break; } if (j+pos >= mi->m+range) @@ -115,7 +119,7 @@ int dict_look_ec (Dict dict, Dict_ptr ptr, MatchInfo *mi, MatchWord *ri_base, (ri[range] & match_mask)) { prefix[pos+1] = DICT_EOS; - (*userfunc)(prefix); + (*userfunc)((char*) prefix); } memcpy (&subptr, info, sizeof(Dict_ptr)); if (subptr) @@ -149,8 +153,8 @@ static MatchInfo *prepare_match (Dict_char *pattern) return mi; } -int dict_lookup_ec (Dict dict, Dict_char *pattern, int range, - int (*userfunc)(Dict_char *name)) +int dict_lookup_ec (Dict dict, char *pattern, int range, + int (*userfunc)(char *name)) { MatchInfo *mi; MatchWord *ri; @@ -160,9 +164,10 @@ int dict_lookup_ec (Dict dict, Dict_char *pattern, int range, if (dict->head.last == 1) return 0; - mi = prepare_match (pattern); + mi = prepare_match ((Dict_char*) pattern); - ri = xmalloc ((dict_strlen(pattern)+range+2)*(range+1)*sizeof(*ri)); + ri = xmalloc ((dict_strlen((Dict_char*) pattern)+range+2) + * (range+1)*sizeof(*ri)); for (i=0; i<=range; i++) ri[i] = (2<head.last <= 1) return 0; - return dict_scan_r (dict, 1, 0, str, before, after, client, f); + return dict_scan_r (dict, 1, 0, (Dict_char *) str, before, after, client, + f); } diff --git a/include/dict.h b/include/dict.h index 2b78d2d..2323ac7 100644 --- a/include/dict.h +++ b/include/dict.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dict.h,v $ - * Revision 1.18 1996-02-01 20:41:06 adam + * Revision 1.19 1996-02-02 13:43:54 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.18 1996/02/01 20:41:06 adam * Bug fix: insert didn't work on 8-bit characters due to unsigned char * compares in dict_strcmp (strcmp) and signed Dict_char. Dict_char is * unsigned now. @@ -127,21 +131,20 @@ int dict_bf_close (Dict_BFile dbf); Dict dict_open (const char *name, int cache, int rw); int dict_close (Dict dict); -int dict_insert (Dict dict, const Dict_char *p, int userlen, - void *userinfo); -int dict_delete (Dict dict, const Dict_char *p); -char *dict_lookup (Dict dict, const Dict_char *p); -int dict_lookup_ec (Dict dict, Dict_char *p, int range, - int (*f)(Dict_char *name)); -int dict_lookup_grep (Dict dict, Dict_char *p, int range, void *client, +int dict_insert (Dict dict, const char *p, int userlen, void *userinfo); +int dict_delete (Dict dict, const char *p); +char *dict_lookup (Dict dict, const char *p); +int dict_lookup_ec (Dict dict, char *p, int range, + int (*f)(char *name)); +int dict_lookup_grep (Dict dict, const char *p, int range, void *client, int *max_pos, - int (*f)(Dict_char *name, const char *info, + int (*f)(char *name, const char *info, void *client)); int dict_strcmp (const Dict_char *s1, const Dict_char *s2); int dict_strlen (const Dict_char *s); -int dict_scan (Dict dict, Dict_char *str, +int dict_scan (Dict dict, char *str, int *before, int *after, void *client, - int (*f)(Dict_char *name, const char *info, int pos, + int (*f)(char *name, const char *info, int pos, void *client)); #define DICT_EOS 0 -- 1.7.10.4