From fd12cf9b8e16c109f3c0f7aedb0e0efd65209e16 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 18 Sep 1997 08:59:16 +0000 Subject: [PATCH] Extra generic handle for the character mapping routines. --- bfile/bfile.c | 7 +++- bfile/mfile.c | 105 +++++++++++++++++++++++++++++++++-------------------- dfa/dfa.c | 16 +++++--- dfa/dfap.h | 8 +++- dict/lookgrep.c | 12 ++++-- include/dfa.h | 9 +++-- include/dict.h | 13 +++++-- include/mfile.h | 7 +++- include/recctrl.h | 7 +++- index/index.h | 7 +++- index/zrpn.c | 17 +++++---- recctrl/recgrs.c | 17 +++++---- 12 files changed, 146 insertions(+), 79 deletions(-) diff --git a/bfile/bfile.c b/bfile/bfile.c index 06bca15..ee8e707 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: bfile.c,v $ - * Revision 1.23 1997-09-17 12:19:06 adam + * Revision 1.24 1997-09-18 08:59:16 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.23 1997/09/17 12:19:06 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -106,6 +109,8 @@ BFiles bfs_create (const char *spec) void bfs_destroy (BFiles bfs) { + mf_destroy (bfs->commit_area); + mf_destroy (bfs->register_area); xfree (bfs); } diff --git a/bfile/mfile.c b/bfile/mfile.c index 6074cfb..41fc3ca 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: mfile.c,v $ - * Revision 1.24 1997-09-17 12:19:06 adam + * Revision 1.25 1997-09-18 08:59:16 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.24 1997/09/17 12:19:06 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -224,7 +227,7 @@ static int cmp_part_file(const void *p1, const void *p2) */ MFile_area mf_init(const char *name, const char *spec) { - MFile_area ma = xmalloc(sizeof(MFile_area_struct)); + MFile_area ma = xmalloc(sizeof(*ma)); mf_dir *dirp; meta_file *meta_f; part_file *part_f = 0; @@ -232,9 +235,8 @@ MFile_area mf_init(const char *name, const char *spec) struct dirent *dent; int fd, number; char metaname[FILENAME_MAX+1], tmpnam[FILENAME_MAX+1]; - + logf (LOG_DEBUG, "mf_init(%s)", name); - ma = xmalloc(sizeof(MFile_area_struct)); strcpy(ma->name, name); ma->mfiles = 0; ma->dirs = 0; @@ -317,13 +319,37 @@ MFile_area mf_init(const char *name, const char *spec) return ma; } +void mf_destroy(MFile_area ma) +{ + mf_dir *dp; + meta_file *meta_f; + + if (!ma) + return; + dp = ma->dirs; + while (dp) + { + mf_dir *d = dp; + dp = dp->next; + xfree (d); + } + meta_f = ma->mfiles; + while (meta_f) + { + meta_file *m = meta_f; + meta_f = meta_f->next; + xfree (m); + } + xfree (ma); +} + /* * Open a metafile. * If !ma, Use MF_DEFAULT_AREA. */ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) { - struct meta_file *new; + struct meta_file *mnew; int i; char tmp[FILENAME_MAX+1]; mf_dir *dp; @@ -331,62 +357,63 @@ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) logf(LOG_DEBUG, "mf_open(%s bs=%d, %s)", name, block_size, wflag ? "RW" : "RDONLY"); assert (ma); - for (new = ma->mfiles; new; new = new->next) - if (!strcmp(name, new->name)) - if (new->open) + for (mnew = ma->mfiles; mnew; mnew = mnew->next) + if (!strcmp(name, mnew->name)) + if (mnew->open) abort(); else break; - if (!new) + if (!mnew) { - new = xmalloc(sizeof(*new)); - strcpy(new->name, name); + mnew = xmalloc(sizeof(*mnew)); + strcpy(mnew->name, name); /* allocate one, empty file */ - new->no_files = 1; - new->files[0].bytes = new->files[0].blocks = 0; - new->files[0].top = -1; - new->files[0].number = 0; - new->files[0].fd = -1; - new->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size; + mnew->no_files = 1; + mnew->files[0].bytes = mnew->files[0].blocks = 0; + mnew->files[0].top = -1; + mnew->files[0].number = 0; + mnew->files[0].fd = -1; + mnew->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size; for (dp = ma->dirs; dp && dp->max_bytes >= 0 && dp->avail_bytes < - new->min_bytes_creat; dp = dp->next); + mnew->min_bytes_creat; dp = dp->next); if (!dp) { logf (LOG_FATAL, "Insufficient space for new mfile."); return 0; } - new->files[0].dir = dp; - sprintf(tmp, "%s/%s.mf.%d", dp->name, new->name, 0); - new->files[0].path = xstrdup(tmp); - new->ma = ma; + mnew->files[0].dir = dp; + sprintf(tmp, "%s/%s.mf.%d", dp->name, mnew->name, 0); + mnew->files[0].path = xstrdup(tmp); + mnew->ma = ma; } else { - for (i = 0; i < new->no_files; i++) + for (i = 0; i < mnew->no_files; i++) { - if (new->files[i].bytes % block_size) - new->files[i].bytes += block_size - new->files[i].bytes % + if (mnew->files[i].bytes % block_size) + mnew->files[i].bytes += block_size - mnew->files[i].bytes % block_size; - new->files[i].blocks = new->files[i].bytes / block_size; + mnew->files[i].blocks = mnew->files[i].bytes / block_size; } - assert(!new->open); + assert(!mnew->open); } - new->blocksize = block_size; - new->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size; - new->wr=wflag; - new->cur_file = 0; - new->open = 1; + mnew->blocksize = block_size; + mnew->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size; + mnew->wr=wflag; + mnew->cur_file = 0; + mnew->open = 1; - for (i = 0; i < new->no_files; i++) + for (i = 0; i < mnew->no_files; i++) { - new->files[i].blocks = new->files[i].bytes / new->blocksize; - if (i == new->no_files - 1) - new->files[i].top = -1; + mnew->files[i].blocks = mnew->files[i].bytes / mnew->blocksize; + if (i == mnew->no_files - 1) + mnew->files[i].top = -1; else - new->files[i].top = i ? (new->files[i-1].top + new->files[i].blocks) - : (new->files[i].blocks - 1); + mnew->files[i].top = + i ? (mnew->files[i-1].top + mnew->files[i].blocks) + : (mnew->files[i].blocks - 1); } - return new; + return mnew; } /* diff --git a/dfa/dfa.c b/dfa/dfa.c index 945adad..f55b69a 100644 --- a/dfa/dfa.c +++ b/dfa/dfa.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dfa.c,v $ - * Revision 1.16 1997-09-05 15:29:57 adam + * Revision 1.17 1997-09-18 08:59:17 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.16 1997/09/05 15:29:57 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -426,7 +429,7 @@ static int read_charset (void) char mapfrom[2]; const char *mcp = mapfrom; mapfrom[0] = ch0; - mapto = (*parse_info->cmap)(&mcp, 1); + mapto = (*parse_info->cmap)(parse_info->cmap_data, &mcp, 1); assert (mapto); ch0 = mapto[0][0]; } @@ -456,7 +459,7 @@ static int read_charset (void) char mapfrom[2]; const char *mcp = mapfrom; mapfrom[0] = ch1; - mapto = (*parse_info->cmap) (&mcp, 1); + mapto = (*parse_info->cmap) (parse_info->cmap_data, &mcp, 1); assert (mapto); ch1 = mapto[0][0]; } @@ -493,7 +496,7 @@ static int map_l_char (void) if (!parse_info->cmap) return L_CHAR; - mapto = (*parse_info->cmap) (&cp0, len); + mapto = (*parse_info->cmap) (parse_info->cmap_data, &cp0, len); assert (mapto); expr_ptr = (const unsigned char *) cp0; @@ -1107,10 +1110,11 @@ struct DFA *dfa_init (void) return dfa; } -void dfa_set_cmap (struct DFA *dfa, - const char **(*cmap)(const char **from, int len)) +void dfa_set_cmap (struct DFA *dfa, void *vp, + const char **(*cmap)(void *vp, const char **from, int len)) { dfa->parse_info->cmap = cmap; + dfa->parse_info->cmap_data = vp; } int dfa_parse (struct DFA *dfa, const char **pattern) diff --git a/dfa/dfap.h b/dfa/dfap.h index 07051bb..c7798c1 100644 --- a/dfa/dfap.h +++ b/dfa/dfap.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dfap.h,v $ - * Revision 1.5 1997-09-05 15:29:58 adam + * Revision 1.6 1997-09-18 08:59:17 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.5 1997/09/05 15:29:58 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -42,7 +45,8 @@ struct DFA_parse { struct Tblock *end; /* end block of Tnodes */ int *charMap; int charMapSize; - const char **(*cmap)(const char **from, int len); + void *cmap_data; + const char **(*cmap)(void *vp, const char **from, int len); }; typedef struct DFA_stateb_ { diff --git a/dict/lookgrep.c b/dict/lookgrep.c index 13eb8cb..f3d8421 100644 --- a/dict/lookgrep.c +++ b/dict/lookgrep.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: lookgrep.c,v $ - * Revision 1.18 1997-09-05 15:29:58 adam + * Revision 1.19 1997-09-18 08:59:18 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.18 1997/09/05 15:29:58 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -412,7 +415,7 @@ int dict_lookup_grep (Dict dict, const char *pattern, int range, void *client, logf (LOG_DEBUG, "dict_lookup_grep '%s' range=%d", pattern, range); - dfa_set_cmap (dfa, dict->grep_cmap); + dfa_set_cmap (dfa, dict->grep_cmap_data, dict->grep_cmap); i = dfa_parse (dfa, &this_pattern); if (i || *this_pattern) @@ -455,8 +458,9 @@ int dict_lookup_grep (Dict dict, const char *pattern, int range, void *client, return i; } -void dict_grep_cmap (Dict dict, - const char **(*cmap)(const char **from, int len)) +void dict_grep_cmap (Dict dict, void *vp, + const char **(*cmap)(void *vp, const char **from, int len)) { dict->grep_cmap = cmap; + dict->grep_cmap_data = vp; } diff --git a/include/dfa.h b/include/dfa.h index 0d59afa..8a031d3 100644 --- a/include/dfa.h +++ b/include/dfa.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dfa.h,v $ - * Revision 1.7 1997-09-05 15:29:59 adam + * Revision 1.8 1997-09-18 08:59:18 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.7 1997/09/05 15:29:59 adam * Changed prototype for chr_map_input - added const. * Added support for C++, headers uses extern "C" for public definitions. * @@ -70,8 +73,8 @@ struct DFA { }; struct DFA *dfa_init (void); -void dfa_set_cmap (struct DFA *dfa, - const char **(*cmap)(const char **from, int len)); +void dfa_set_cmap (struct DFA *dfa, void *vp, + const char **(*cmap)(void *vp, const char **from, int len)); int dfa_parse (struct DFA *, const char **); void dfa_mkstate (struct DFA *); void dfa_delete (struct DFA **); diff --git a/include/dict.h b/include/dict.h index b631c72..2dca367 100644 --- a/include/dict.h +++ b/include/dict.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dict.h,v $ - * Revision 1.25 1997-09-17 12:19:09 adam + * Revision 1.26 1997-09-18 08:59:18 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.25 1997/09/17 12:19:09 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -140,7 +143,8 @@ typedef struct Dict_file_struct typedef struct Dict_struct { int rw; Dict_BFile dbf; - const char **(*grep_cmap)(const char **from, int len); + const char **(*grep_cmap)(void *vp, const char **from, int len); + void *grep_cmap_data; struct Dict_head head; } *Dict; @@ -174,8 +178,9 @@ int dict_scan (Dict dict, char *str, int (*f)(char *name, const char *info, int pos, void *client)); -void dict_grep_cmap (Dict dict, - const char **(*cmap)(const char **from, int len)); +void dict_grep_cmap (Dict dict, void *vp, + const char **(*cmap)(void *vp, + const char **from, int len)); #define DICT_EOS 0 diff --git a/include/mfile.h b/include/mfile.h index 7959b25..5d01264 100644 --- a/include/mfile.h +++ b/include/mfile.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: mfile.h,v $ - * Revision 1.8 1997-09-17 12:19:10 adam + * Revision 1.9 1997-09-18 08:59:19 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.8 1997/09/17 12:19:10 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -105,7 +108,7 @@ MFile_area mf_init(const char *name, const char *spec); /* * Release an area. */ -int mf_dispose(MFile_area ma); +void mf_destroy(MFile_area ma); /* * Open a metafile. diff --git a/include/recctrl.h b/include/recctrl.h index d89c8ec..93de77b 100644 --- a/include/recctrl.h +++ b/include/recctrl.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recctrl.h,v $ - * Revision 1.20 1997-09-17 12:19:10 adam + * Revision 1.21 1997-09-18 08:59:19 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.20 1997/09/17 12:19:10 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -123,7 +126,7 @@ struct recExtractCtrl { char *subType; void (*init)(RecWord *p); void (*add)(const RecWord *p); - const char **(*map_chrs_input)(const char **from, int len); + const char **(*map_chrs_input)(void *vp, const char **from, int len); int flagShowRecords; data1_handle dh; }; diff --git a/index/index.h b/index/index.h index 2e60e90..2ae3ab2 100644 --- a/index/index.h +++ b/index/index.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.50 1997-09-17 12:19:13 adam + * Revision 1.51 1997-09-18 08:59:19 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.50 1997/09/17 12:19:13 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -300,7 +303,7 @@ int zebraLockNB (int fd, int wr); int zebraUnlock (int fd); void init_charmap(Res res); -const char **map_chrs_input(const char **from, int len); +const char **map_chrs_input(void *vp, const char **from, int len); const char *map_chrs_output(const char **from); extern Res common_resource; diff --git a/index/zrpn.c b/index/zrpn.c index 8a6af0b..cc13551 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.63 1997-09-17 12:19:18 adam + * Revision 1.64 1997-09-18 08:59:20 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.63 1997/09/17 12:19:18 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -359,7 +362,7 @@ static int term_pre (const char **src, const char *ct1, const char *ct2) if (ct2 && strchr (ct2, *s0)) break; s1 = s0; - map = map_chrs_input (&s1, strlen(s1)); + map = map_chrs_input (0, &s1, strlen(s1)); if (**map != *CHR_SPACE) break; s0 = s1; @@ -380,7 +383,7 @@ static int term_100 (const char **src, char *dst, int space_split) while (*s0) { s1 = s0; - map = map_chrs_input (&s0, strlen(s0)); + map = map_chrs_input (0, &s0, strlen(s0)); if (space_split && **map == *CHR_SPACE) break; while (s1 < s0) @@ -415,7 +418,7 @@ static int term_101 (const char **src, char *dst, int space_split) else { s1 = s0; - map = map_chrs_input (&s0, strlen(s0)); + map = map_chrs_input (0, &s0, strlen(s0)); if (space_split && **map == *CHR_SPACE) break; while (s1 < s0) @@ -456,7 +459,7 @@ static int term_103 (const char **src, char *dst, int *errors, int space_split) else { s1 = s0; - map = map_chrs_input (&s0, strlen(s0)); + map = map_chrs_input (0, &s0, strlen(s0)); if (**map == *CHR_SPACE) break; while (s1 < s0) @@ -819,7 +822,7 @@ static void trans_scan_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt, while ((len = (cp_end - cp)) > 0) { - map = map_chrs_input (&cp, len); + map = map_chrs_input (0, &cp, len); if (**map == *CHR_SPACE) space_map = *map; else @@ -1441,7 +1444,7 @@ int rpn_search (ZServerInfo *zi, oident *attrset; oid_value attributeSet; - dict_grep_cmap (zi->dict, map_chrs_input); + dict_grep_cmap (zi->dict, 0, map_chrs_input); zlog_rpn (rpn); zi->errCode = 0; diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index d4cf58c..a7056a3 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recgrs.c,v $ - * Revision 1.9 1997-09-17 12:19:21 adam + * Revision 1.10 1997-09-18 08:59:21 adam + * Extra generic handle for the character mapping routines. + * + * Revision 1.9 1997/09/17 12:19:21 adam * Zebra version corresponds to YAZ version 1.4. * Changed Zebra server so that it doesn't depend on global common_resource. * @@ -179,7 +182,7 @@ static void dumpkeys_word(data1_node *n, struct recExtractCtrl *p, remain = n->u.data.len - (b - n->u.data.data); if (remain > 0) - map = (*p->map_chrs_input)(&b, remain); + map = (*p->map_chrs_input)(0, &b, remain); while (map) { @@ -192,7 +195,7 @@ static void dumpkeys_word(data1_node *n, struct recExtractCtrl *p, { remain = n->u.data.len - (b - n->u.data.data); if (remain > 0) - map = (*p->map_chrs_input)(&b, remain); + map = (*p->map_chrs_input)(0, &b, remain); else map = 0; } @@ -207,7 +210,7 @@ static void dumpkeys_word(data1_node *n, struct recExtractCtrl *p, buf[i++] = *(cp++); remain = n->u.data.len - (b - n->u.data.data); if (remain > 0) - map = (*p->map_chrs_input)(&b, remain); + map = (*p->map_chrs_input)(0, &b, remain); else map = 0; } @@ -235,7 +238,7 @@ static void dumpkeys_phrase(data1_node *n, struct recExtractCtrl *p, remain = n->u.data.len - (b - n->u.data.data); if (remain > 0) - map = (*p->map_chrs_input)(&b, remain); + map = (*p->map_chrs_input)(0, &b, remain); while (remain > 0 && i < GRS_MAX_WORD) { @@ -243,7 +246,7 @@ static void dumpkeys_phrase(data1_node *n, struct recExtractCtrl *p, { remain = n->u.data.len - (b - n->u.data.data); if (remain > 0) - map = (*p->map_chrs_input)(&b, remain); + map = (*p->map_chrs_input)(0, &b, remain); else map = 0; } @@ -262,7 +265,7 @@ static void dumpkeys_phrase(data1_node *n, struct recExtractCtrl *p, buf[i++] = *(cp++); remain = n->u.data.len - (b - n->u.data.data); if (remain > 0) - map = (*p->map_chrs_input)(&b, remain); + map = (*p->map_chrs_input)(0, &b, remain); else map = 0; } -- 1.7.10.4