2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1997-10-31 12:39:30 adam
10 * Revision 1.1 1997/10/27 14:33:06 adam
11 * Moved towards generic character mapping depending on "structure"
12 * field in abstract syntax file. Fixed a few memory leaks. Fixed
13 * bug with negative integers when doing searches with relational
28 struct zebra_map *next;
34 struct zebra_map *map_list;
37 void zebra_maps_close (ZebraMaps zms)
39 struct zebra_map *zm = zms->map_list;
42 struct zebra_map *zm_next = zm->next;
44 chrmaptab_destroy (zm->maptab);
48 nmem_destroy (zms->nmem);
52 ZebraMaps zebra_maps_open (const char *tabpath)
54 ZebraMaps zms = xmalloc (sizeof(*zms));
56 zms->nmem = nmem_create ();
57 zms->tabpath = nmem_strdup (zms->nmem, tabpath);
62 chrmaptab zebra_map_get (ZebraMaps zms, int reg_type)
67 for (zm = zms->map_list; zm; zm = zm->next)
69 if (reg_type == zm->reg_type)
77 strcat (name, "string");
80 strcat (name, "numeric");
86 strcat (name, "null");
88 strcat (name, ".chr");
90 zm = xmalloc (sizeof(*zm));
91 zm->reg_type = reg_type;
92 zm->next = zms->map_list;
94 if (!(zm->maptab = chrmaptab_create (zms->tabpath, name, 0)))
95 logf(LOG_WARN, "Failed to read character table %s", name);
97 logf(LOG_DEBUG, "Read character table %s", name);
101 const char **zebra_maps_input (ZebraMaps zms, int reg_type,
102 const char **from, int len)
104 static char str[2] = {0,0};
105 static const char *buf[2] = {0,0};
108 maptab = zebra_map_get (zms, reg_type);
110 return chr_map_input(maptab, from, len);
114 str[0] = isupper(**from) ? tolower(**from) : **from;
118 buf[0] = (char*) CHR_SPACE;
123 const char *zebra_maps_output(ZebraMaps zms, int reg_type, const char **from)
126 unsigned char i = (unsigned char) **from;
127 static char buf[2] = {0,0};
129 maptab = zebra_map_get (zms, reg_type);
131 return chr_map_output (maptab, from, 1);
138 /* ------------------------------------ */
144 Z_AttributesPlusTerm *zapt;
147 static int attr_find (AttrType *src, oid_value *attributeSetP)
149 while (src->major < src->zapt->num_attributes)
151 Z_AttributeElement *element;
153 element = src->zapt->attributeList[src->major];
154 if (src->type == *element->attributeType)
156 switch (element->which)
158 case Z_AttributeValue_numeric:
160 if (element->attributeSet && attributeSetP)
164 attrset = oid_getentbyoid (element->attributeSet);
165 *attributeSetP = attrset->value;
167 return *element->value.numeric;
169 case Z_AttributeValue_complex:
170 if (src->minor >= element->value.complex->num_list ||
171 element->value.complex->list[src->minor]->which !=
172 Z_StringOrNumeric_numeric)
175 if (element->attributeSet && attributeSetP)
179 attrset = oid_getentbyoid (element->attributeSet);
180 *attributeSetP = attrset->value;
182 return *element->value.complex->list[src->minor-1]->u.numeric;
192 static void attr_init (AttrType *src, Z_AttributesPlusTerm *zapt,
201 /* ------------------------------------ */
203 int zebra_maps_is_complete (ZebraMaps zms, int reg_type)
210 int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt,
211 int *reg_type, char **search_type, int *complete_flag)
213 AttrType completeness;
216 int completeness_value;
220 attr_init (&structure, zapt, 4);
221 attr_init (&completeness, zapt, 6);
222 attr_init (&relation, zapt, 2);
224 completeness_value = attr_find (&completeness, NULL);
225 structure_value = attr_find (&structure, NULL);
227 if (completeness_value == 2 || completeness_value == 3)
233 *search_type = "phrase";
234 if (relation_value == 102)
235 *search_type = "ranked";
237 switch (structure_value)
243 case 6: /* word list */
244 case 105: /* free-form-text */
245 case 106: /* document-text */
246 case 108: /* string */
252 case 107: /* local-number */
253 *search_type = "local";
255 case 109: /* numeric string */