2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1997-10-27 14:33:06 adam
8 * Moved towards generic character mapping depending on "structure"
9 * field in abstract syntax file. Fixed a few memory leaks. Fixed
10 * bug with negative integers when doing searches with relational
25 struct zebra_map *next;
31 struct zebra_map *map_list;
34 void zebra_maps_close (ZebraMaps zms)
36 struct zebra_map *zm = zms->map_list;
39 struct zebra_map *zm_next = zm->next;
41 chrmaptab_destroy (zm->maptab);
45 nmem_destroy (zms->nmem);
49 ZebraMaps zebra_maps_open (const char *tabpath)
51 ZebraMaps zms = xmalloc (sizeof(*zms));
53 zms->nmem = nmem_create ();
54 zms->tabpath = nmem_strdup (zms->nmem, tabpath);
59 chrmaptab zebra_map_get (ZebraMaps zms, int reg_type)
64 for (zm = zms->map_list; zm; zm = zm->next)
66 if (reg_type == zm->reg_type)
74 strcat (name, "string");
77 strcat (name, "numeric");
83 strcat (name, "null");
85 strcat (name, ".chr");
87 zm = xmalloc (sizeof(*zm));
88 zm->reg_type = reg_type;
89 zm->next = zms->map_list;
91 if (!(zm->maptab = chrmaptab_create (zms->tabpath, name, 0)))
92 logf(LOG_WARN, "Failed to read character table %s", name);
94 logf(LOG_LOG, "Read table %s", name);
98 const char **zebra_maps_input (ZebraMaps zms, int reg_type,
99 const char **from, int len)
101 static char str[2] = {0,0};
102 static const char *buf[2] = {0,0};
105 maptab = zebra_map_get (zms, reg_type);
107 return chr_map_input(maptab, from, len);
111 str[0] = isupper(**from) ? tolower(**from) : **from;
115 buf[0] = (char*) CHR_SPACE;
120 const char *zebra_maps_output(ZebraMaps zms, int reg_type, const char **from)
123 unsigned char i = (unsigned char) **from;
124 static char buf[2] = {0,0};
126 maptab = zebra_map_get (zms, reg_type);
128 return chr_map_output (maptab, from, 1);
135 /* ------------------------------------ */
141 Z_AttributesPlusTerm *zapt;
144 static int attr_find (AttrType *src, oid_value *attributeSetP)
146 while (src->major < src->zapt->num_attributes)
148 Z_AttributeElement *element;
150 element = src->zapt->attributeList[src->major];
151 if (src->type == *element->attributeType)
153 switch (element->which)
155 case Z_AttributeValue_numeric:
157 if (element->attributeSet && attributeSetP)
161 attrset = oid_getentbyoid (element->attributeSet);
162 *attributeSetP = attrset->value;
164 return *element->value.numeric;
166 case Z_AttributeValue_complex:
167 if (src->minor >= element->value.complex->num_list ||
168 element->value.complex->list[src->minor]->which !=
169 Z_StringOrNumeric_numeric)
172 if (element->attributeSet && attributeSetP)
176 attrset = oid_getentbyoid (element->attributeSet);
177 *attributeSetP = attrset->value;
179 return *element->value.complex->list[src->minor-1]->u.numeric;
189 static void attr_init (AttrType *src, Z_AttributesPlusTerm *zapt,
198 /* ------------------------------------ */
200 int zebra_maps_is_complete (ZebraMaps zms, int reg_type)
207 int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt,
208 int *reg_type, char **search_type, int *complete_flag)
210 AttrType completeness;
213 int completeness_value;
217 attr_init (&structure, zapt, 4);
218 attr_init (&completeness, zapt, 6);
219 attr_init (&relation, zapt, 2);
221 completeness_value = attr_find (&completeness, NULL);
222 structure_value = attr_find (&structure, NULL);
224 if (completeness_value == 2 || completeness_value == 3)
230 *search_type = "phrase";
231 if (relation_value == 102)
232 *search_type = "ranked";
234 switch (structure_value)
240 case 6: /* word list */
241 case 105: /* free-form-text */
242 case 106: /* document-text */
243 case 108: /* string */
249 case 107: /* local-number */
250 *search_type = "local";
252 case 109: /* numeric string */