From: Adam Dickmeiss Date: Tue, 30 Oct 2007 19:17:15 +0000 (+0000) Subject: Introduced zebra_map_t in zebra_maps API. X-Git-Tag: ZEBRA.2.0.20~89 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=6f7dfe3c3f09f7104c1ae7616c9d207edeab308d Introduced zebra_map_t in zebra_maps API. --- diff --git a/include/zebramap.h b/include/zebramap.h index 8704b7a..678ff94 100644 --- a/include/zebramap.h +++ b/include/zebramap.h @@ -1,4 +1,4 @@ -/* $Id: zebramap.h,v 1.24 2007-10-29 22:22:06 adam Exp $ +/* $Id: zebramap.h,v 1.25 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -28,62 +28,69 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA YAZ_BEGIN_CDECL -typedef struct zebra_maps *ZebraMaps; +typedef struct zebra_maps_s *zebra_maps_t; +typedef struct zebra_map *zebra_map_t; YAZ_EXPORT -ZebraMaps zebra_maps_open(Res res, const char *base_path, +zebra_maps_t zebra_maps_open(Res res, const char *base_path, const char *profile_path); YAZ_EXPORT -ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname); +ZEBRA_RES zebra_maps_read_file(zebra_maps_t zms, const char *fname); YAZ_EXPORT -void zebra_maps_close(ZebraMaps zm); +void zebra_maps_close(zebra_maps_t zm); YAZ_EXPORT -const char **zebra_maps_input(ZebraMaps zms, unsigned reg_id, +const char **zebra_maps_input(zebra_map_t zm, const char **from, int len, int first); YAZ_EXPORT -const char **zebra_maps_search(ZebraMaps zms, unsigned reg_id, +const char **zebra_maps_search(zebra_map_t zm, const char **from, int len, int *q_map_match); YAZ_EXPORT -const char *zebra_maps_output(ZebraMaps, unsigned reg_id, const char **from); +const char *zebra_maps_output(zebra_map_t zm, const char **from); YAZ_EXPORT -int zebra_maps_attr(ZebraMaps zms, Z_AttributesPlusTerm *zapt, +int zebra_maps_attr(zebra_maps_t zms, Z_AttributesPlusTerm *zapt, const char **reg_id, char **search_type, char *rank_type, int *complete_flag, int *sort_flag); YAZ_EXPORT -int zebra_maps_sort(ZebraMaps zms, Z_SortAttributes *sortAttributes, +int zebra_maps_sort(zebra_maps_t zms, Z_SortAttributes *sortAttributes, int *numerical); YAZ_EXPORT -int zebra_maps_is_complete(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_complete(zebra_map_t zm); YAZ_EXPORT -int zebra_maps_is_sort(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_sort(zebra_map_t zm); YAZ_EXPORT -int zebra_maps_is_index(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_index(zebra_map_t zm); YAZ_EXPORT -int zebra_maps_is_staticrank(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_staticrank(zebra_map_t zm); YAZ_EXPORT -int zebra_maps_is_alwaysmatches(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_alwaysmatches(zebra_map_t zm); YAZ_EXPORT -int zebra_maps_is_positioned(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_positioned(zebra_map_t zm); YAZ_EXPORT -int zebra_maps_is_first_in_field(ZebraMaps zms, unsigned reg_id); +int zebra_maps_is_first_in_field(zebra_map_t zm); YAZ_EXPORT -WRBUF zebra_replace(ZebraMaps zms, unsigned reg_id, const char *ex_list, +WRBUF zebra_replace(zebra_map_t zm, const char *ex_list, const char *input_str, int input_len); +YAZ_EXPORT +zebra_map_t zebra_map_get(zebra_maps_t zms, unsigned reg_id); + +YAZ_EXPORT +zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, unsigned reg_id); + YAZ_END_CDECL #endif diff --git a/index/extract.c b/index/extract.c index f0ea3ab..66eaff1 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.265 2007-10-29 16:57:52 adam Exp $ +/* $Id: extract.c,v 1.266 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -103,7 +103,8 @@ static void init_extractCtrl(ZebraHandle zh, struct recExtractCtrl *ctrl) int i; for (i = 0; i<256; i++) { - if (zebra_maps_is_positioned(zh->reg->zebra_maps, i)) + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, i); + if (zebra_maps_is_positioned(zm)) ctrl->seqno[i] = 1; else ctrl->seqno[i] = 0; @@ -135,10 +136,10 @@ struct snip_rec_info { }; -static void snippet_add_complete_field(RecWord *p, int ord) +static void snippet_add_complete_field(RecWord *p, int ord, + zebra_map_t zm) { struct snip_rec_info *h = p->extractCtrl->handle; - ZebraHandle zh = h->zh; const char *b = p->term_buf; char buf[IT_MAX_WORD+1]; @@ -148,7 +149,7 @@ static void snippet_add_complete_field(RecWord *p, int ord) const char *last = 0; if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 1); + map = zebra_maps_input(zm, &b, remain, 1); while (remain > 0 && i < IT_MAX_WORD) { @@ -162,8 +163,7 @@ static void snippet_add_complete_field(RecWord *p, int ord) { int first = i ? 0 : 1; /* first position */ - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, - &b, remain, first); + map = zebra_maps_input(zm, &b, remain, first); } else map = 0; @@ -192,8 +192,7 @@ static void snippet_add_complete_field(RecWord *p, int ord) remain = p->term_len - (b - p->term_buf); if (remain > 0) { - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, - remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); } else map = 0; @@ -206,10 +205,9 @@ static void snippet_add_complete_field(RecWord *p, int ord) start, last - start); } -static void snippet_add_incomplete_field(RecWord *p, int ord) +static void snippet_add_incomplete_field(RecWord *p, int ord, zebra_map_t zm) { struct snip_rec_info *h = p->extractCtrl->handle; - ZebraHandle zh = h->zh; const char *b = p->term_buf; int remain = p->term_len; int first = 1; @@ -218,7 +216,7 @@ static void snippet_add_incomplete_field(RecWord *p, int ord) const char *last = b; if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); while (map) { @@ -231,8 +229,7 @@ static void snippet_add_incomplete_field(RecWord *p, int ord) remain = p->term_len - (b - p->term_buf); last = b; if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, - remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); else map = 0; } @@ -256,7 +253,7 @@ static void snippet_add_incomplete_field(RecWord *p, int ord) remain = p->term_len - (b - p->term_buf); last = b; if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); else map = 0; } @@ -266,7 +263,7 @@ static void snippet_add_incomplete_field(RecWord *p, int ord) if (first) { first = 0; - if (zebra_maps_is_first_in_field(zh->reg->zebra_maps, *p->index_type)) + if (zebra_maps_is_first_in_field(zm)) { /* first in field marker */ p->seqno++; @@ -285,17 +282,18 @@ static void snippet_token_add(RecWord *p) { struct snip_rec_info *h = p->extractCtrl->handle; ZebraHandle zh = h->zh; + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *p->index_type); - if (zebra_maps_is_index(zh->reg->zebra_maps, *p->index_type)) + if (zm && zebra_maps_is_index(zm)) { ZebraExplainInfo zei = zh->reg->zei; int ch = zebraExplain_lookup_attr_str( zei, zinfo_index_category_index, p->index_type, p->index_name); - if(zebra_maps_is_complete (h->zh->reg->zebra_maps, *p->index_type)) - snippet_add_complete_field(p, ch); + if (zebra_maps_is_complete(zm)) + snippet_add_complete_field(p, ch, zm); else - snippet_add_incomplete_field(p, ch); + snippet_add_incomplete_field(p, ch, zm); } } @@ -1608,19 +1606,19 @@ static void extract_add_staticrank_string(RecWord *p, ctrl->staticrank = atozint(valz); } -static void extract_add_string(RecWord *p, const char *string, int length) +static void extract_add_string(RecWord *p, zebra_map_t zm, + const char *string, int length) { - ZebraHandle zh = p->extractCtrl->handle; assert(length > 0); if (!p->index_name) return; - if (zebra_maps_is_index(zh->reg->zebra_maps, *p->index_type)) + if (zebra_maps_is_index(zm)) { extract_add_index_string(p, zinfo_index_category_index, string, length); - if (zebra_maps_is_alwaysmatches(zh->reg->zebra_maps, *p->index_type)) + if (zebra_maps_is_alwaysmatches(zm)) { RecWord word; memcpy(&word, p, sizeof(word)); @@ -1630,26 +1628,25 @@ static void extract_add_string(RecWord *p, const char *string, int length) &word, zinfo_index_category_alwaysmatches, "", 0); } } - else if (zebra_maps_is_sort(zh->reg->zebra_maps, *p->index_type)) + else if (zebra_maps_is_sort(zm)) { extract_add_sort_string(p, string, length); } - else if (zebra_maps_is_staticrank(zh->reg->zebra_maps, *p->index_type)) + else if (zebra_maps_is_staticrank(zm)) { extract_add_staticrank_string(p, string, length); } } -static void extract_add_incomplete_field(RecWord *p) +static void extract_add_incomplete_field(RecWord *p, zebra_map_t zm) { - ZebraHandle zh = p->extractCtrl->handle; const char *b = p->term_buf; int remain = p->term_len; int first = 1; const char **map = 0; if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); while (map) { @@ -1661,8 +1658,7 @@ static void extract_add_incomplete_field(RecWord *p) { remain = p->term_len - (b - p->term_buf); if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, - remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); else map = 0; } @@ -1677,7 +1673,7 @@ static void extract_add_incomplete_field(RecWord *p) buf[i++] = *(cp++); remain = p->term_len - (b - p->term_buf); if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); else map = 0; } @@ -1687,28 +1683,27 @@ static void extract_add_incomplete_field(RecWord *p) if (first) { first = 0; - if (zebra_maps_is_first_in_field(zh->reg->zebra_maps, *p->index_type)) + if (zebra_maps_is_first_in_field(zm)) { /* first in field marker */ - extract_add_string(p, FIRST_IN_FIELD_STR, FIRST_IN_FIELD_LEN); + extract_add_string(p, zm, FIRST_IN_FIELD_STR, FIRST_IN_FIELD_LEN); p->seqno++; } } - extract_add_string(p, buf, i); + extract_add_string(p, zm, buf, i); p->seqno++; } } -static void extract_add_complete_field(RecWord *p) +static void extract_add_complete_field(RecWord *p, zebra_map_t zm) { - ZebraHandle zh = p->extractCtrl->handle; const char *b = p->term_buf; char buf[IT_MAX_WORD+1]; const char **map = 0; int i = 0, remain = p->term_len; if (remain > 0) - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 1); + map = zebra_maps_input(zm, &b, remain, 1); while (remain > 0 && i < IT_MAX_WORD) { @@ -1719,7 +1714,7 @@ static void extract_add_complete_field(RecWord *p) if (remain > 0) { int first = i ? 0 : 1; /* first position */ - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, first); + map = zebra_maps_input(zm, &b, remain, first); } else map = 0; @@ -1747,8 +1742,7 @@ static void extract_add_complete_field(RecWord *p) remain = p->term_len - (b - p->term_buf); if (remain > 0) { - map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, - remain, 0); + map = zebra_maps_input(zm, &b, remain, 0); } else map = 0; @@ -1756,7 +1750,7 @@ static void extract_add_complete_field(RecWord *p) } if (!i) return; - extract_add_string(p, buf, i); + extract_add_string(p, zm, buf, i); } static void extract_token_add2_index(ZebraHandle zh, zebra_index_type_t type, @@ -1827,6 +1821,7 @@ static void extract_token_add2(RecWord *p) static void extract_token_add(RecWord *p) { ZebraHandle zh = p->extractCtrl->handle; + zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, *p->index_type); WRBUF wrbuf; if (log_level_details) @@ -1836,16 +1831,15 @@ static void extract_token_add(RecWord *p) p->index_type, p->index_name, p->seqno, p->term_len, p->term_buf); } - if ((wrbuf = zebra_replace(zh->reg->zebra_maps, *p->index_type, 0, - p->term_buf, p->term_len))) + if ((wrbuf = zebra_replace(zm, 0, p->term_buf, p->term_len))) { p->term_buf = wrbuf_buf(wrbuf); p->term_len = wrbuf_len(wrbuf); } - if (zebra_maps_is_complete(zh->reg->zebra_maps, *p->index_type)) - extract_add_complete_field(p); + if (zebra_maps_is_complete(zm)) + extract_add_complete_field(p, zm); else - extract_add_incomplete_field(p); + extract_add_incomplete_field(p, zm); } static void extract_set_store_data_cb(struct recExtractCtrl *p, diff --git a/index/index.h b/index/index.h index 7a5152c..a03ee21 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.202 2007-10-29 16:57:52 adam Exp $ +/* $Id: index.h,v 1.203 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -145,7 +145,7 @@ struct zebra_register { char *server_path_prefix; data1_handle dh; zebra_index_types_t index_types; - ZebraMaps zebra_maps; + zebra_maps_t zebra_maps; ZebraRankClass rank_classes; RecTypes recTypes; int seqno; @@ -410,11 +410,11 @@ ZEBRA_RES zebra_remove_file_match(ZebraHandle zh); struct rpn_char_map_info { - ZebraMaps zm; + zebra_map_t zm; int reg_type; }; -void rpn_char_map_prepare(struct zebra_register *reg, int reg_type, +void rpn_char_map_prepare(struct zebra_register *reg, zebra_map_t zm, struct rpn_char_map_info *map_info); ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt, diff --git a/index/rpnscan.c b/index/rpnscan.c index 839d88e..1327f5f 100644 --- a/index/rpnscan.c +++ b/index/rpnscan.c @@ -1,4 +1,4 @@ -/* $Id: rpnscan.c,v 1.15 2007-10-29 16:57:53 adam Exp $ +/* $Id: rpnscan.c,v 1.16 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -45,7 +45,7 @@ int log_scan = YLOG_LOG; /* convert APT SCAN term to internal cmap */ static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, - char *termz, const char *index_type) + char *termz, zebra_map_t zm) { char termz0[IT_MAX_WORD]; @@ -63,8 +63,7 @@ static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, while ((len = (cp_end - cp)) > 0) { - map = zebra_maps_input(zh->reg->zebra_maps, *index_type, - &cp, len, 0); + map = zebra_maps_input(zm, &cp, len, 0); if (**map == *CHR_SPACE) space_map = *map; else @@ -284,6 +283,7 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, { struct scan2_info_entry *ar = nmem_malloc(nmem, sizeof(*ar) * ord_no); struct rpn_char_map_info rcmi; + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type); int i, dif; int after_pos; int pos = 0; @@ -299,7 +299,7 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, *num_entries = 0; return ZEBRA_OK; } - rpn_char_map_prepare(zh->reg, *index_type, &rcmi); + rpn_char_map_prepare(zh->reg, zm, &rcmi); for (i = 0; i < ord_no; i++) ar[i].term = wrbuf_alloc(); @@ -313,7 +313,7 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, termz[prefix_len] = 0; strcpy(ar[i].prefix, termz); - if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) == + if (trans_scan_term(zh, zapt, termz+prefix_len, zm) == ZEBRA_FAIL) { for (i = 0; i < ord_no; i++) @@ -383,7 +383,7 @@ static ZEBRA_RES rpn_scan_ver2(ZebraHandle zh, ODR stream, NMEM nmem, termz[prefix_len] = 0; strcpy(ar[i].prefix, termz); - if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) == + if (trans_scan_term(zh, zapt, termz+prefix_len, zm) == ZEBRA_FAIL) return ZEBRA_FAIL; wrbuf_rewind(ar[i].term); diff --git a/index/rpnsearch.c b/index/rpnsearch.c index 5f7a84e..ca44a81 100644 --- a/index/rpnsearch.c +++ b/index/rpnsearch.c @@ -1,4 +1,4 @@ -/* $Id: rpnsearch.c,v 1.17 2007-10-29 20:07:04 adam Exp $ +/* $Id: rpnsearch.c,v 1.18 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -45,7 +45,7 @@ static int log_level_rpn = 0; static const char **rpn_char_map_handler(void *vp, const char **from, int len) { struct rpn_char_map_info *p = (struct rpn_char_map_info *) vp; - const char **out = zebra_maps_input(p->zm, p->reg_type, from, len, 0); + const char **out = zebra_maps_input(p->zm, from, len, 0); #if 0 if (out && *out) { @@ -61,11 +61,10 @@ static const char **rpn_char_map_handler(void *vp, const char **from, int len) return out; } -void rpn_char_map_prepare(struct zebra_register *reg, int reg_type, +void rpn_char_map_prepare(struct zebra_register *reg, zebra_map_t zm, struct rpn_char_map_info *map_info) { - map_info->zm = reg->zebra_maps; - map_info->reg_type = reg_type; + map_info->zm = zm; dict_grep_cmap(reg->dict, map_info, rpn_char_map_handler); } @@ -154,7 +153,7 @@ static int grep_handle(char *name, const char *info, void *p) return add_isam_p(name, info, (struct grep_info *) p); } -static int term_pre(ZebraMaps zebra_maps, int reg_type, const char **src, +static int term_pre(zebra_map_t zm, const char **src, const char *ct1, const char *ct2, int first) { const char *s1, *s0 = *src; @@ -168,7 +167,7 @@ static int term_pre(ZebraMaps zebra_maps, int reg_type, const char **src, if (ct2 && strchr(ct2, *s0)) break; s1 = s0; - map = zebra_maps_input(zebra_maps, reg_type, &s1, strlen(s1), first); + map = zebra_maps_input(zm, &s1, strlen(s1), first); if (**map != *CHR_SPACE) break; s0 = s1; @@ -234,7 +233,7 @@ static void add_non_space(const char *start, const char *end, } /* term_100: handle term, where trunc = none(no operators at all) */ -static int term_100(ZebraMaps zebra_maps, const char *index_type, +static int term_100(zebra_map_t zm, const char **src, WRBUF term_dict, int space_split, char *dst_term) { @@ -246,15 +245,14 @@ static int term_100(ZebraMaps zebra_maps, const char *index_type, const char *space_start = 0; const char *space_end = 0; - if (!term_pre(zebra_maps, *index_type, src, NULL, NULL, !space_split)) + if (!term_pre(zm, src, NULL, NULL, !space_split)) return 0; s0 = *src; while (*s0) { const char *s1 = s0; int q_map_match = 0; - map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0), - &q_map_match); + map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match); if (space_split) { if (**map == *CHR_SPACE) @@ -294,7 +292,7 @@ static int term_100(ZebraMaps zebra_maps, const char *index_type, } /* term_101: handle term, where trunc = Process # */ -static int term_101(ZebraMaps zebra_maps, const char *index_type, +static int term_101(zebra_map_t zm, const char **src, WRBUF term_dict, int space_split, char *dst_term) { @@ -303,7 +301,7 @@ static int term_101(ZebraMaps zebra_maps, const char *index_type, int i = 0; int j = 0; - if (!term_pre(zebra_maps, *index_type, src, "#", "#", !space_split)) + if (!term_pre(zm, src, "#", "#", !space_split)) return 0; s0 = *src; while (*s0) @@ -318,8 +316,7 @@ static int term_101(ZebraMaps zebra_maps, const char *index_type, { const char *s1 = s0; int q_map_match = 0; - map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0), - &q_map_match); + map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match); if (space_split && **map == *CHR_SPACE) break; @@ -334,8 +331,7 @@ static int term_101(ZebraMaps zebra_maps, const char *index_type, } /* term_103: handle term, where trunc = re-2 (regular expressions) */ -static int term_103(ZebraMaps zebra_maps, const char *index_type, - const char **src, +static int term_103(zebra_map_t zm, const char **src, WRBUF term_dict, int *errors, int space_split, char *dst_term) { @@ -344,7 +340,7 @@ static int term_103(ZebraMaps zebra_maps, const char *index_type, const char *s0; const char **map; - if (!term_pre(zebra_maps, *index_type, src, "^\\()[].*+?|", "(", !space_split)) + if (!term_pre(zm, src, "^\\()[].*+?|", "(", !space_split)) return 0; s0 = *src; if (errors && *s0 == '+' && s0[1] && s0[2] == '+' && s0[3] && @@ -368,8 +364,7 @@ static int term_103(ZebraMaps zebra_maps, const char *index_type, { const char *s1 = s0; int q_map_match = 0; - map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0), - &q_map_match); + map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match); if (space_split && **map == *CHR_SPACE) break; @@ -385,26 +380,23 @@ static int term_103(ZebraMaps zebra_maps, const char *index_type, } /* term_103: handle term, where trunc = re-1 (regular expressions) */ -static int term_102(ZebraMaps zebra_maps, const char *index_type, - const char **src, +static int term_102(zebra_map_t zm, const char **src, WRBUF term_dict, int space_split, char *dst_term) { - return term_103(zebra_maps, index_type, src, term_dict, NULL, space_split, - dst_term); + return term_103(zm, src, term_dict, NULL, space_split, dst_term); } /* term_104: handle term, process # and ! */ -static int term_104(ZebraMaps zebra_maps, const char *index_type, - const char **src, WRBUF term_dict, int space_split, - char *dst_term) +static int term_104(zebra_map_t zm, const char **src, + WRBUF term_dict, int space_split, char *dst_term) { const char *s0; const char **map; int i = 0; int j = 0; - if (!term_pre(zebra_maps, *index_type, src, "?*#", "?*#", !space_split)) + if (!term_pre(zm, src, "?*#", "?*#", !space_split)) return 0; s0 = *src; while (*s0) @@ -449,8 +441,7 @@ static int term_104(ZebraMaps zebra_maps, const char *index_type, { const char *s1 = s0; int q_map_match = 0; - map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0), - &q_map_match); + map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match); if (space_split && **map == *CHR_SPACE) break; @@ -465,8 +456,8 @@ static int term_104(ZebraMaps zebra_maps, const char *index_type, } /* term_105/106: handle term, where trunc = Process * and ! and right trunc */ -static int term_105(ZebraMaps zebra_maps, const char *index_type, - const char **src, WRBUF term_dict, int space_split, +static int term_105(zebra_map_t zm, const char **src, + WRBUF term_dict, int space_split, char *dst_term, int right_truncate) { const char *s0; @@ -474,7 +465,7 @@ static int term_105(ZebraMaps zebra_maps, const char *index_type, int i = 0; int j = 0; - if (!term_pre(zebra_maps, *index_type, src, "*!", "*!", !space_split)) + if (!term_pre(zm, src, "*!", "*!", !space_split)) return 0; s0 = *src; while (*s0) @@ -495,8 +486,7 @@ static int term_105(ZebraMaps zebra_maps, const char *index_type, { const char *s1 = s0; int q_map_match = 0; - map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0), - &q_map_match); + map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match); if (space_split && **map == *CHR_SPACE) break; @@ -652,7 +642,7 @@ void string_rel_add_char(WRBUF term_p, WRBUF wsrc, int *indx) static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char **term_sub, WRBUF term_dict, const Odr_oid *attributeSet, - const char *index_type, int space_split, char *term_dst, + zebra_map_t zm, int space_split, char *term_dst, int *error_code) { AttrType relation; @@ -668,9 +658,7 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, switch (relation_value) { case 1: - if (!term_100(zh->reg->zebra_maps, index_type, - term_sub, term_component, - space_split, term_dst)) + if (!term_100(zm, term_sub, term_component, space_split, term_dst)) { wrbuf_destroy(term_component); return 0; @@ -704,9 +692,7 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_putc(term_dict, ')'); break; case 2: - if (!term_100(zh->reg->zebra_maps, index_type, - term_sub, term_component, - space_split, term_dst)) + if (!term_100(zm, term_sub, term_component, space_split, term_dst)) { wrbuf_destroy(term_component); return 0; @@ -741,8 +727,7 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_putc(term_dict, ')'); break; case 5: - if (!term_100(zh->reg->zebra_maps, index_type, - term_sub, term_component, space_split, term_dst)) + if (!term_100(zm, term_sub, term_component, space_split, term_dst)) { wrbuf_destroy(term_component); return 0; @@ -775,8 +760,7 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_putc(term_dict, ')'); break; case 4: - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, - term_component, space_split, term_dst)) + if (!term_100(zm, term_sub, term_component, space_split, term_dst)) { wrbuf_destroy(term_component); return 0; @@ -817,8 +801,7 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (!**term_sub) return 1; yaz_log(log_level_rpn, "Relation ="); - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, - term_component, space_split, term_dst)) + if (!term_100(zm, term_sub, term_component, space_split, term_dst)) { wrbuf_destroy(term_component); return 0; @@ -965,10 +948,11 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, int relation_error; char ord_buf[32]; int ord_len, i; + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type); *ol = ord_list_create(stream); - rpn_char_map_prepare(zh->reg, *index_type, &rcmi); + rpn_char_map_prepare(zh->reg, zm, &rcmi); attr_init_APT(&truncation, zapt, 5); truncation_value = attr_find(&truncation, NULL); yaz_log(log_level_rpn, "truncation value %d", truncation_value); @@ -1004,7 +988,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, case 100: /* do not truncate */ if (!string_relation(zh, zapt, &termp, term_dict, attributeSet, - index_type, space_split, term_dst, + zm, space_split, term_dst, &relation_error)) { if (relation_error) @@ -1018,8 +1002,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 1: /* right truncation */ wrbuf_putc(term_dict, '('); - if (!term_100(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst)) + if (!term_100(zm, &termp, term_dict, space_split, term_dst)) { *term_sub = 0; return ZEBRA_OK; @@ -1028,8 +1011,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 2: /* keft truncation */ wrbuf_puts(term_dict, "(.*"); - if (!term_100(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst)) + if (!term_100(zm, &termp, term_dict, space_split, term_dst)) { *term_sub = 0; return ZEBRA_OK; @@ -1038,8 +1020,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 3: /* left&right truncation */ wrbuf_puts(term_dict, "(.*"); - if (!term_100(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst)) + if (!term_100(zm, &termp, term_dict, space_split, term_dst)) { *term_sub = 0; return ZEBRA_OK; @@ -1048,8 +1029,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 101: /* process # in term */ wrbuf_putc(term_dict, '('); - if (!term_101(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst)) + if (!term_101(zm, &termp, term_dict, space_split, term_dst)) { *term_sub = 0; return ZEBRA_OK; @@ -1058,8 +1038,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 102: /* Regexp-1 */ wrbuf_putc(term_dict, '('); - if (!term_102(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst)) + if (!term_102(zm, &termp, term_dict, space_split, term_dst)) { *term_sub = 0; return ZEBRA_OK; @@ -1069,8 +1048,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, case 103: /* Regexp-2 */ regex_range = 1; wrbuf_putc(term_dict, '('); - if (!term_103(zh->reg->zebra_maps, index_type, - &termp, term_dict, ®ex_range, + if (!term_103(zm, &termp, term_dict, ®ex_range, space_split, term_dst)) { *term_sub = 0; @@ -1080,8 +1058,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 104: /* process # and ! in term */ wrbuf_putc(term_dict, '('); - if (!term_104(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst)) + if (!term_104(zm, &termp, term_dict, space_split, term_dst)) { *term_sub = 0; return ZEBRA_OK; @@ -1090,8 +1067,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 105: /* process * and ! in term */ wrbuf_putc(term_dict, '('); - if (!term_105(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst, 1)) + if (!term_105(zm, &termp, term_dict, space_split, term_dst, 1)) { *term_sub = 0; return ZEBRA_OK; @@ -1100,8 +1076,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 106: /* process * and ! in term */ wrbuf_putc(term_dict, '('); - if (!term_105(zh->reg->zebra_maps, index_type, - &termp, term_dict, space_split, term_dst, 0)) + if (!term_105(zm, &termp, term_dict, space_split, term_dst, 0)) { *term_sub = 0; return ZEBRA_OK; @@ -1300,6 +1275,7 @@ static ZEBRA_RES rpn_search_APT_position(ZebraHandle zh, int ord_len; char *val; ISAM_P isam_p; + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type); attr_init_APT(&position, zapt, 3); position_value = attr_find(&position, NULL); @@ -1317,7 +1293,8 @@ static ZEBRA_RES rpn_search_APT_position(ZebraHandle zh, return ZEBRA_FAIL; } - if (!zebra_maps_is_first_in_field(zh->reg->zebra_maps, *index_type)) + + if (!zebra_maps_is_first_in_field(zm)) { zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_POSITION_ATTRIBUTE, position_value); @@ -1550,7 +1527,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, const Odr_oid *attributeSet, struct grep_info *grep_info, int *max_pos, - const char *index_type, + zebra_map_t zm, char *term_dst, int *error_code) { @@ -1570,8 +1547,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, { case 1: yaz_log(log_level_rpn, "Relation <"); - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1, - term_dst)) + if (!term_100(zm, term_sub, term_num, 1, term_dst)) { wrbuf_destroy(term_num); return 0; @@ -1581,8 +1557,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 2: yaz_log(log_level_rpn, "Relation <="); - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1, - term_dst)) + if (!term_100(zm, term_sub, term_num, 1, term_dst)) { wrbuf_destroy(term_num); return 0; @@ -1592,8 +1567,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 4: yaz_log(log_level_rpn, "Relation >="); - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1, - term_dst)) + if (!term_100(zm, term_sub, term_num, 1, term_dst)) { wrbuf_destroy(term_num); return 0; @@ -1603,8 +1577,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; case 5: yaz_log(log_level_rpn, "Relation >"); - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1, - term_dst)) + if (!term_100(zm, term_sub, term_num, 1, term_dst)) { wrbuf_destroy(term_num); return 0; @@ -1615,8 +1588,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, case -1: case 3: yaz_log(log_level_rpn, "Relation ="); - if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1, - term_dst)) + if (!term_100(zm, term_sub, term_num, 1, term_dst)) { wrbuf_destroy(term_num); return 0; @@ -1662,10 +1634,11 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, int relation_error = 0; int ord, ord_len, i; char ord_buf[32]; + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type); *ol = ord_list_create(stream); - rpn_char_map_prepare(zh->reg, *index_type, &rcmi); + rpn_char_map_prepare(zh->reg, zm, &rcmi); termp = *term_sub; @@ -1690,7 +1663,7 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_putc(term_dict, ')'); if (!numeric_relation(zh, zapt, &termp, term_dict, - attributeSet, grep_info, &max_pos, index_type, + attributeSet, grep_info, &max_pos, zm, term_dst, &relation_error)) { if (relation_error) diff --git a/index/untrans.c b/index/untrans.c index 0e9adf1..d51c25c 100644 --- a/index/untrans.c +++ b/index/untrans.c @@ -1,4 +1,4 @@ -/* $Id: untrans.c,v 1.3 2007-03-20 22:07:35 adam Exp $ +/* $Id: untrans.c,v 1.4 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -31,11 +31,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA void zebra_term_untrans(ZebraHandle zh, int reg_type, char *dst, const char *src) { + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, reg_type); int len = 0; while (*src) { - const char *cp = zebra_maps_output(zh->reg->zebra_maps, - reg_type, &src); + const char *cp = zebra_maps_output(zm, &src); if (!cp) { if (len < IT_MAX_WORD-1) diff --git a/index/zebraapi.c b/index/zebraapi.c index f648db9..ed3786c 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.260 2007-10-29 09:25:41 adam Exp $ +/* $Id: zebraapi.c,v 1.261 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -1556,6 +1556,7 @@ int zebra_string_norm(ZebraHandle zh, unsigned reg_id, char *output_str, int output_len) { WRBUF wrbuf; + zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, reg_id); ASSERTZH; assert(input_str); assert(output_str); @@ -1563,8 +1564,7 @@ int zebra_string_norm(ZebraHandle zh, unsigned reg_id, if (!zh->reg->zebra_maps) return -1; - wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "", - input_str, input_len); + wrbuf = zebra_replace(zm, "", input_str, input_len); if (!wrbuf) return -2; if (wrbuf_len(wrbuf) >= output_len) diff --git a/util/zebramap.c b/util/zebramap.c index 170ccc0..b96e9f0 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -1,4 +1,4 @@ -/* $Id: zebramap.c,v 1.59 2007-10-29 16:57:54 adam Exp $ +/* $Id: zebramap.c,v 1.60 2007-10-30 19:17:15 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -53,22 +53,24 @@ struct zebra_map { } u; chrmaptab maptab; const char *maptab_name; + zebra_maps_t zebra_maps; struct zebra_map *next; }; -struct zebra_maps { +struct zebra_maps_s { char *tabpath; char *tabroot; NMEM nmem; - struct zebra_map *map_list; char temp_map_str[2]; const char *temp_map_ptr[2]; struct zebra_map **lookup_array; WRBUF wrbuf_1; int no_maps; + zebra_map_t map_list; + zebra_map_t *last_map; }; -void zebra_maps_close(ZebraMaps zms) +void zebra_maps_close(zebra_maps_t zms) { struct zebra_map *zm = zms->map_list; while (zm) @@ -82,7 +84,31 @@ void zebra_maps_close(ZebraMaps zms) xfree(zms); } -ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname) +zebra_map_t zebra_add_map(zebra_maps_t zms, const char *index_type, + int map_type) +{ + zebra_map_t zm = (zebra_map_t) nmem_malloc(zms->nmem, sizeof(*zm)); + + zm->zebra_maps = zms; + zm->reg_id = index_type[0]; + zm->maptab_name = 0; + zm->maptab = 0; + zm->type = map_type; + zm->completeness = 0; + zm->positioned = 0; + zm->alwaysmatches = 0; + zm->first_in_field = 0; + + zm->next = 0; + *zms->last_map = zm; + zms->last_map = &zm->next; + + zms->no_maps++; + + return zm; +} + +ZEBRA_RES zebra_maps_read_file(zebra_maps_t zms, const char *fname) { FILE *f; char line[512]; @@ -90,7 +116,7 @@ ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname) int argc; int lineno = 0; int failures = 0; - struct zebra_map **zm = 0, *zp; + zebra_map_t zm = 0; if (!(f = yaz_fopen(zms->tabpath, fname, "r", zms->tabroot))) { @@ -115,55 +141,18 @@ ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname) } if (!yaz_matchstr(argv[0], "index")) { - if (!zm) - zm = &zms->map_list; - else - zm = &(*zm)->next; - *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm)); - (*zm)->reg_id = argv[1][0]; - (*zm)->maptab_name = NULL; - (*zm)->maptab = NULL; - (*zm)->type = ZEBRA_MAP_TYPE_INDEX; - (*zm)->completeness = 0; - (*zm)->positioned = 1; - (*zm)->alwaysmatches = 0; - (*zm)->first_in_field = 0; - zms->no_maps++; + zm = zebra_add_map(zms, argv[1], ZEBRA_MAP_TYPE_INDEX); + zm->positioned = 1; } else if (!yaz_matchstr(argv[0], "sort")) { - if (!zm) - zm = &zms->map_list; - else - zm = &(*zm)->next; - *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm)); - (*zm)->reg_id = argv[1][0]; - (*zm)->maptab_name = NULL; - (*zm)->type = ZEBRA_MAP_TYPE_SORT; - (*zm)->u.sort.entry_size = 80; - (*zm)->maptab = NULL; - (*zm)->completeness = 0; - (*zm)->positioned = 0; - (*zm)->alwaysmatches = 0; - (*zm)->first_in_field = 0; - zms->no_maps++; + zm = zebra_add_map(zms, argv[1], ZEBRA_MAP_TYPE_SORT); + zm->u.sort.entry_size = 80; } else if (!yaz_matchstr(argv[0], "staticrank")) { - if (!zm) - zm = &zms->map_list; - else - zm = &(*zm)->next; - *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm)); - (*zm)->reg_id = argv[1][0]; - (*zm)->maptab_name = NULL; - (*zm)->type = ZEBRA_MAP_TYPE_STATICRANK; - (*zm)->maptab = NULL; - (*zm)->completeness = 1; - (*zm)->positioned = 0; - (*zm)->alwaysmatches = 0; - (*zm)->first_in_field = 0; - zms->no_maps++; + zm = zebra_add_map(zms, argv[1], ZEBRA_MAP_TYPE_STATICRANK); + zm->completeness = 1; } else if (!zm) { @@ -173,28 +162,28 @@ ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname) } else if (!yaz_matchstr(argv[0], "charmap") && argc == 2) { - if ((*zm)->type != ZEBRA_MAP_TYPE_STATICRANK) - (*zm)->maptab_name = nmem_strdup(zms->nmem, argv[1]); + if (zm->type != ZEBRA_MAP_TYPE_STATICRANK) + zm->maptab_name = nmem_strdup(zms->nmem, argv[1]); else { yaz_log(YLOG_WARN|YLOG_FATAL, "%s:%d: charmap for " "staticrank is invalid", fname, lineno); - yaz_log(YLOG_LOG, "Type is %d", (*zm)->type); + yaz_log(YLOG_LOG, "Type is %d", zm->type); failures++; } } else if (!yaz_matchstr(argv[0], "completeness") && argc == 2) { - (*zm)->completeness = atoi(argv[1]); + zm->completeness = atoi(argv[1]); } else if (!yaz_matchstr(argv[0], "position") && argc == 2) { - (*zm)->positioned = atoi(argv[1]); + zm->positioned = atoi(argv[1]); } else if (!yaz_matchstr(argv[0], "alwaysmatches") && argc == 2) { - if ((*zm)->type != ZEBRA_MAP_TYPE_STATICRANK) - (*zm)->alwaysmatches = atoi(argv[1]); + if (zm->type != ZEBRA_MAP_TYPE_STATICRANK) + zm->alwaysmatches = atoi(argv[1]); else { yaz_log(YLOG_WARN|YLOG_FATAL, "%s:%d: alwaysmatches for " @@ -204,12 +193,12 @@ ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname) } else if (!yaz_matchstr(argv[0], "firstinfield") && argc == 2) { - (*zm)->first_in_field = atoi(argv[1]); + zm->first_in_field = atoi(argv[1]); } else if (!yaz_matchstr(argv[0], "entrysize") && argc == 2) { - if ((*zm)->type == ZEBRA_MAP_TYPE_SORT) - (*zm)->u.sort.entry_size = atoi(argv[1]); + if (zm->type == ZEBRA_MAP_TYPE_SORT) + zm->u.sort.entry_size = atoi(argv[1]); } else { @@ -218,22 +207,20 @@ ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname) failures++; } } - if (zm) - (*zm)->next = NULL; yaz_fclose(f); - for (zp = zms->map_list; zp; zp = zp->next) - zms->lookup_array[zp->reg_id] = zp; + for (zm = zms->map_list; zm; zm = zm->next) + zms->lookup_array[zm->reg_id] = zm; if (failures) return ZEBRA_FAIL; return ZEBRA_OK; } -ZebraMaps zebra_maps_open(Res res, const char *base_path, +zebra_maps_t zebra_maps_open(Res res, const char *base_path, const char *profile_path) { - ZebraMaps zms = (ZebraMaps) xmalloc(sizeof(*zms)); + zebra_maps_t zms = (zebra_maps_t) xmalloc(sizeof(*zms)); int i; zms->nmem = nmem_create(); @@ -242,7 +229,8 @@ ZebraMaps zebra_maps_open(Res res, const char *base_path, zms->tabroot = 0; if (base_path) zms->tabroot = nmem_strdup(zms->nmem, base_path); - zms->map_list = NULL; + zms->map_list = 0; + zms->last_map = &zms->map_list; zms->temp_map_str[0] = '\0'; zms->temp_map_str[1] = '\0'; @@ -250,7 +238,7 @@ ZebraMaps zebra_maps_open(Res res, const char *base_path, zms->temp_map_ptr[0] = zms->temp_map_str; zms->temp_map_ptr[1] = NULL; - zms->lookup_array = (struct zebra_map**) + zms->lookup_array = (zebra_map_t *) nmem_malloc(zms->nmem, sizeof(*zms->lookup_array)*256); zms->wrbuf_1 = wrbuf_alloc(); @@ -259,40 +247,51 @@ ZebraMaps zebra_maps_open(Res res, const char *base_path, return zms; } -struct zebra_map *zebra_map_get(ZebraMaps zms, unsigned reg_id) +zebra_map_t zebra_map_get(zebra_maps_t zms, unsigned reg_id) { assert(reg_id >= 0 && reg_id <= 255); return zms->lookup_array[reg_id]; } -chrmaptab zebra_charmap_get(ZebraMaps zms, unsigned reg_id) +zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, unsigned reg_id) { struct zebra_map *zm = zebra_map_get(zms, reg_id); if (!zm) { - zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(*zm)); + char name[2]; + name[0] = reg_id; + name[1] = '\0'; + + zm = zebra_add_map(zms, name, ZEBRA_MAP_TYPE_INDEX); - /* no reason to warn if no maps are installed at ALL */ - if (zms->no_maps) + /* no reason to warn if no maps are installed at ALL + Note that zebra_add_maps increments no_maps .. + */ + if (zms->no_maps > 1) yaz_log(YLOG_WARN, "Unknown register type: %c", reg_id); + else + zms->no_maps = 0; - zm->reg_id = reg_id; zm->maptab_name = nmem_strdup(zms->nmem, "@"); - zm->maptab = NULL; - zm->type = ZEBRA_MAP_TYPE_INDEX; zm->completeness = 0; + zm->positioned = 1; zm->next = zms->map_list; zms->map_list = zm->next; zms->lookup_array[zm->reg_id & 255] = zm; } + return zm; +} + +chrmaptab zebra_charmap_get(zebra_map_t zm) +{ if (!zm->maptab) { if (!zm->maptab_name || !yaz_matchstr(zm->maptab_name, "@")) return NULL; - if (!(zm->maptab = chrmaptab_create(zms->tabpath, + if (!(zm->maptab = chrmaptab_create(zm->zebra_maps->tabpath, zm->maptab_name, - zms->tabroot))) + zm->zebra_maps->tabroot))) yaz_log(YLOG_WARN, "Failed to read character table %s", zm->maptab_name); else @@ -301,28 +300,26 @@ chrmaptab zebra_charmap_get(ZebraMaps zms, unsigned reg_id) return zm->maptab; } -const char **zebra_maps_input(ZebraMaps zms, unsigned reg_id, +const char **zebra_maps_input(zebra_map_t zm, const char **from, int len, int first) { - chrmaptab maptab; - - maptab = zebra_charmap_get(zms, reg_id); + chrmaptab maptab = zebra_charmap_get(zm); if (maptab) return chr_map_input(maptab, from, len, first); - zms->temp_map_str[0] = **from; + zm->zebra_maps->temp_map_str[0] = **from; (*from)++; - return zms->temp_map_ptr; + return zm->zebra_maps->temp_map_ptr; } -const char **zebra_maps_search(ZebraMaps zms, unsigned reg_id, +const char **zebra_maps_search(zebra_map_t zm, const char **from, int len, int *q_map_match) { chrmaptab maptab; *q_map_match = 0; - maptab = zebra_charmap_get(zms, reg_id); + maptab = zebra_charmap_get(zm); if (maptab) { const char **map; @@ -336,16 +333,16 @@ const char **zebra_maps_search(ZebraMaps zms, unsigned reg_id, if (map) return map; } - zms->temp_map_str[0] = **from; + zm->zebra_maps->temp_map_str[0] = **from; (*from)++; - return zms->temp_map_ptr; + return zm->zebra_maps->temp_map_ptr; } -const char *zebra_maps_output(ZebraMaps zms, unsigned reg_id, +const char *zebra_maps_output(zebra_map_t zm, const char **from) { - chrmaptab maptab = zebra_charmap_get(zms, reg_id); + chrmaptab maptab = zebra_charmap_get(zm); if (!maptab) return 0; return chr_map_output(maptab, from, 1); @@ -354,63 +351,56 @@ const char *zebra_maps_output(ZebraMaps zms, unsigned reg_id, /* ------------------------------------ */ -int zebra_maps_is_complete(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_complete(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->completeness; return 0; } -int zebra_maps_is_positioned(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_positioned(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->positioned; return 0; } -int zebra_maps_is_index(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_index(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->type == ZEBRA_MAP_TYPE_INDEX; return 0; } -int zebra_maps_is_staticrank(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_staticrank(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->type == ZEBRA_MAP_TYPE_STATICRANK; return 0; } -int zebra_maps_is_sort(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_sort(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->type == ZEBRA_MAP_TYPE_SORT; return 0; } -int zebra_maps_is_alwaysmatches(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_alwaysmatches(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->alwaysmatches; return 0; } -int zebra_maps_is_first_in_field(ZebraMaps zms, unsigned reg_id) +int zebra_maps_is_first_in_field(zebra_map_t zm) { - struct zebra_map *zm = zebra_map_get(zms, reg_id); if (zm) return zm->first_in_field; return 0; } -int zebra_maps_sort(ZebraMaps zms, Z_SortAttributes *sortAttributes, +int zebra_maps_sort(zebra_maps_t zms, Z_SortAttributes *sortAttributes, int *numerical) { AttrType use; @@ -426,7 +416,7 @@ int zebra_maps_sort(ZebraMaps zms, Z_SortAttributes *sortAttributes, return attr_find(&use, NULL); } -int zebra_maps_attr(ZebraMaps zms, Z_AttributesPlusTerm *zapt, +int zebra_maps_attr(zebra_maps_t zms, Z_AttributesPlusTerm *zapt, const char **index_type, char **search_type, char *rank_type, int *complete_flag, int *sort_flag) { @@ -530,12 +520,12 @@ int zebra_maps_attr(ZebraMaps zms, Z_AttributesPlusTerm *zapt, return 0; } -WRBUF zebra_replace(ZebraMaps zms, unsigned reg_id, const char *ex_list, +WRBUF zebra_replace(zebra_map_t zm, const char *ex_list, const char *input_str, int input_len) { - wrbuf_rewind(zms->wrbuf_1); - wrbuf_write(zms->wrbuf_1, input_str, input_len); - return zms->wrbuf_1; + wrbuf_rewind(zm->zebra_maps->wrbuf_1); + wrbuf_write(zm->zebra_maps->wrbuf_1, input_str, input_len); + return zm->zebra_maps->wrbuf_1; } /*