Put local variables footer in all c, h files.
[idzebra-moved-to-github.git] / data1 / d1_expout.c
1 /* $Id: d1_expout.c,v 1.7 2006-05-10 08:13:18 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /*
24  * This module converts data1 tree to Z39.50 Explain records  
25  */
26
27 #include <assert.h>
28 #include <string.h>
29 #include <stdlib.h>
30
31 #include <yaz/log.h>
32 #include <yaz/proto.h>
33 #include <idzebra/data1.h>
34
35 typedef struct {
36     data1_handle dh;
37     ODR o;
38     int select;
39
40     bool_t *false_value;
41     bool_t *true_value;
42 } ExpHandle;
43
44 static int is_numeric_tag (ExpHandle *eh, data1_node *c)
45 {
46     if (!c || c->which != DATA1N_tag)
47         return 0;
48     if (!c->u.tag.element)
49     {
50         yaz_log(YLOG_WARN, "Tag %s is local", c->u.tag.tag);
51         return 0;
52     }
53     if (c->u.tag.element->tag->which != DATA1T_numeric)
54     {
55         yaz_log(YLOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
56         return 0;
57     }
58     if (eh->select && !c->u.tag.node_selected)
59         return 0;
60     return c->u.tag.element->tag->value.numeric;
61 }
62
63 static int is_data_tag (ExpHandle *eh, data1_node *c)
64 {
65     if (!c || c->which != DATA1N_data)
66         return 0;
67     if (eh->select && !c->u.tag.node_selected)
68         return 0;
69     return 1;
70 }
71
72 static int *f_integer(ExpHandle *eh, data1_node *c)
73 {
74     int *r;
75     char intbuf[64];
76
77     c = c->child;
78     if (!is_data_tag (eh, c) || c->u.data.len > 63)
79         return 0;
80     r = (int *)odr_malloc(eh->o, sizeof(*r));
81     sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
82     *r = atoi(intbuf);
83     return r;
84 }
85
86 static char *f_string(ExpHandle *eh, data1_node *c)
87 {
88     char *r;
89
90     c = c->child;
91     if (!is_data_tag (eh, c))
92         return 0;
93     r = (char *)odr_malloc(eh->o, c->u.data.len+1);
94     memcpy(r, c->u.data.data, c->u.data.len);
95     r[c->u.data.len] = '\0';
96     return r;
97 }
98
99 static bool_t *f_bool(ExpHandle *eh, data1_node *c)
100 {
101     bool_t *tf;
102     char intbuf[64];
103
104     c = c->child;
105     if (!is_data_tag (eh, c) || c->u.data.len > 63)
106         return 0;
107     tf = (int *)odr_malloc (eh->o, sizeof(*tf));
108     sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
109     *tf = atoi(intbuf);
110     return tf;
111 }
112
113 static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass)
114 {
115     char oidstr[64];
116     int oid_this[20];
117     oid_value value_for_this;
118
119     c = c->child;
120     if (!is_data_tag (eh, c) || c->u.data.len > 63)
121         return 0;
122     sprintf(oidstr, "%.*s", c->u.data.len, c->u.data.data);
123     value_for_this = oid_getvalbyname(oidstr);
124     if (value_for_this == VAL_NONE)
125     {
126         Odr_oid *oid = odr_getoidbystr(eh->o, oidstr);
127         assert (oid);
128         return oid;
129     }
130     else
131     {
132         struct oident ident;
133
134         ident.oclass = oclass;
135         ident.proto = PROTO_Z3950;
136         ident.value = value_for_this;
137         
138         oid_ent_to_oid (&ident, oid_this);
139     }
140     return odr_oiddup (eh->o, oid_this);
141 }
142
143 static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
144 {
145     /* fix */
146     return 0;
147 }
148
149 static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c)
150 {
151     Z_HumanString *r;
152     Z_HumanStringUnit *u;
153
154     c = c->child;
155     if (!is_data_tag (eh, c))
156         return 0;
157     r = (Z_HumanString *)odr_malloc(eh->o, sizeof(*r));
158     r->num_strings = 1;
159     r->strings = (Z_HumanStringUnit **)odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));
160     r->strings[0] = u = (Z_HumanStringUnit *)odr_malloc(eh->o, sizeof(*u));
161     u->language = 0;
162     u->text = (char *)odr_malloc(eh->o, c->u.data.len+1);
163     memcpy(u->text, c->u.data.data, c->u.data.len);
164     u->text[c->u.data.len] = '\0';
165     return r;
166 }
167
168 static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n)
169 {
170     Z_CommonInfo *res = (Z_CommonInfo *)odr_malloc(eh->o, sizeof(*res));
171     data1_node *c;
172
173     res->dateAdded = 0;
174     res->dateChanged = 0;
175     res->expiry = 0;
176     res->humanStringLanguage = 0;
177     res->otherInfo = 0;
178
179     for (c = n->child; c; c = c->next)
180     {
181         switch (is_numeric_tag (eh, c))
182         {
183             case 601: res->dateAdded = f_string(eh, c); break;
184             case 602: res->dateChanged = f_string(eh, c); break;
185             case 603: res->expiry = f_string(eh, c); break;
186             case 604: res->humanStringLanguage = f_string(eh, c); break;
187         }
188     }
189     return res;
190 }
191
192 Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass)
193 {
194     Odr_oid **res;
195     data1_node *c;
196     int i;
197
198     *num = 0;
199     for (c = n->child ; c; c = c->next)
200         if (is_numeric_tag (eh, c) == 1000)
201             ++(*num);
202     if (!*num)
203         return NULL;
204     res = (int **)odr_malloc (eh->o, sizeof(*res) * (*num));
205     for (c = n->child, i = 0 ; c; c = c->next)
206         if (is_numeric_tag (eh, c) == 1000)
207             res[i++] = f_oid (eh, c, oclass);
208     return res;
209 }
210     
211 char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
212 {
213     char **res;
214     data1_node *c;
215     int i;
216
217     *num = 0;
218     for (c = n->child ; c; c = c->next)
219     {
220         if (is_numeric_tag (eh, c) != 1001)
221             continue;
222         ++(*num);
223     }
224     if (!*num)
225         return NULL;
226     res = (char **)odr_malloc (eh->o, sizeof(*res) * (*num));
227     for (c = n->child, i = 0 ; c; c = c->next)
228     {
229         if (is_numeric_tag (eh, c) != 1001)
230             continue;
231         res[i++] = f_string (eh, c);
232     }
233     return res;
234 }
235
236 Z_ProximitySupport *f_proximitySupport (ExpHandle *eh, data1_node *n)
237 {
238     Z_ProximitySupport *res = (Z_ProximitySupport *)
239         odr_malloc (eh->o, sizeof(*res));
240     res->anySupport = eh->false_value;
241     res->num_unitsSupported = 0;
242     res->unitsSupported = 0;
243     return res;
244 }
245
246 Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n)
247 {
248     Z_RpnCapabilities *res = (Z_RpnCapabilities *)
249         odr_malloc (eh->o, sizeof(*res));
250     data1_node *c;
251
252     res->num_operators = 0;
253     res->operators = NULL;
254     res->resultSetAsOperandSupported = eh->false_value;
255     res->restrictionOperandSupported = eh->false_value;
256     res->proximity = NULL;
257
258     for (c = n->child; c; c = c->next)
259     {
260         int i = 0;
261         switch (is_numeric_tag(eh, c))
262         {
263         case 550:
264             for (n = c->child; n; n = n->next)
265             {
266                 if (is_numeric_tag(eh, n) != 551)
267                     continue;
268                 (res->num_operators)++;
269             }
270             if (res->num_operators)
271                 res->operators = (int **)
272                     odr_malloc (eh->o, res->num_operators
273                                 * sizeof(*res->operators));
274             for (n = c->child; n; n = n->next)
275             {
276                 if (is_numeric_tag(eh, n) != 551)
277                     continue;
278                 res->operators[i++] = f_integer (eh, n);
279             }
280             break;
281         case 552:
282             res->resultSetAsOperandSupported = f_bool (eh, c);
283             break;
284         case 553:
285             res->restrictionOperandSupported = f_bool (eh, c);
286             break;
287         case 554:
288             res->proximity = f_proximitySupport (eh, c);
289             break;
290         }
291     }
292     return res;
293 }
294
295 Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n)
296 {
297     Z_QueryTypeDetails *res = (Z_QueryTypeDetails *)
298         odr_malloc(eh->o, sizeof(*res));
299     data1_node *c;
300
301     res->which = Z_QueryTypeDetails_rpn;
302     res->u.rpn = 0;
303     for (c = n->child; c; c = c->next)
304     {
305         switch (is_numeric_tag(eh, c))
306         {
307         case 519:
308             res->which = Z_QueryTypeDetails_rpn;
309             res->u.rpn = f_rpnCapabilities (eh, c);
310             break;
311         case 520:
312             break;
313         case 521:
314             break;
315         }
316     }
317     return res;
318 }
319
320 static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n)
321 {
322     Z_AccessInfo *res = (Z_AccessInfo *)odr_malloc(eh->o, sizeof(*res));
323     data1_node *c;
324
325     res->num_queryTypesSupported = 0;
326     res->queryTypesSupported = 0;
327     res->num_diagnosticsSets = 0;
328     res->diagnosticsSets = 0;
329     res->num_attributeSetIds = 0;
330     res->attributeSetIds = 0;
331     res->num_schemas = 0;
332     res->schemas = 0;
333     res->num_recordSyntaxes = 0;
334     res->recordSyntaxes = 0;
335     res->num_resourceChallenges = 0;
336     res->resourceChallenges = 0;
337     res->restrictedAccess = 0;
338     res->costInfo = 0;
339     res->num_variantSets = 0;
340     res->variantSets = 0;
341     res->num_elementSetNames = 0;
342     res->elementSetNames = 0;
343     res->num_unitSystems = 0;
344     res->unitSystems = 0;
345
346     for (c = n->child; c; c = c->next)
347     {
348         int i = 0;
349         switch (is_numeric_tag (eh, c))
350         {
351         case 501:
352             for (n = c->child; n; n = n->next)
353             {
354                 if (is_numeric_tag(eh, n) != 518)
355                     continue;
356                 (res->num_queryTypesSupported)++;
357             }
358             if (res->num_queryTypesSupported)
359                 res->queryTypesSupported =
360                     (Z_QueryTypeDetails **)
361                     odr_malloc (eh->o, res->num_queryTypesSupported
362                                 * sizeof(*res->queryTypesSupported));
363             for (n = c->child; n; n = n->next)
364             {
365                 if (is_numeric_tag(eh, n) != 518)
366                     continue;
367                 res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);
368             }
369             break;
370         case 503:
371             res->diagnosticsSets =
372                 f_oid_seq(eh, c, &res->num_diagnosticsSets, CLASS_DIAGSET);
373             break;
374         case 505:
375             res->attributeSetIds =
376                 f_oid_seq(eh, c, &res->num_attributeSetIds, CLASS_ATTSET);
377             break;
378         case 507:
379             res->schemas =
380                 f_oid_seq(eh, c, &res->num_schemas, CLASS_SCHEMA);
381             break;
382         case 509:
383             res->recordSyntaxes =
384                 f_oid_seq (eh, c, &res->num_recordSyntaxes, CLASS_RECSYN);
385             break;
386         case 511:
387             res->resourceChallenges =
388                 f_oid_seq (eh, c, &res->num_resourceChallenges, CLASS_RESFORM);
389             break;
390         case 513: res->restrictedAccess = NULL; break; /* fix */
391         case 514: res->costInfo = NULL; break; /* fix */
392         case 515:
393             res->variantSets =
394                 f_oid_seq (eh, c, &res->num_variantSets, CLASS_VARSET);
395             break;
396         case 516:
397             res->elementSetNames =
398                 f_string_seq (eh, c, &res->num_elementSetNames);
399             break;
400         case 517:
401             res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);
402             break;
403         }
404     }
405     return res;
406 }
407
408 static int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
409 {
410     int *r= (int *)odr_malloc(eh->o, sizeof(*r));
411     int *wp = which;
412     char intbuf[64];
413
414     c = c->child;
415     if (!is_numeric_tag (eh, c))
416         return 0;
417     if (c->u.tag.element->tag->value.numeric == 210)
418         *wp = Z_DatabaseInfo_actualNumber;
419     else if (c->u.tag.element->tag->value.numeric == 211)
420         *wp = Z_DatabaseInfo_approxNumber;
421     else
422         return 0;
423     if (!c->child || c->child->which != DATA1N_data)
424         return 0;
425     sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
426     *r = atoi(intbuf);
427     return r;
428 }
429
430 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
431 {
432     Z_ContactInfo *res = (Z_ContactInfo *)
433         odr_malloc (eh->o, sizeof(*res));
434     data1_node *c;
435     
436     res->name = 0;
437     res->description = 0;
438     res->address = 0;
439     res->email = 0;
440     res->phone = 0;
441     
442     for (c = n->child; c; c = c->next)
443     {
444         switch (is_numeric_tag (eh, c))
445         {
446         case 102: res->name = f_string (eh, c); break;
447         case 113: res->description = f_humstring (eh, c); break;
448         case 127: res->address = f_humstring (eh, c); break;
449         case 128: res->email = f_string (eh, c); break;
450         case 129: res->phone = f_string (eh, c); break;
451         }
452     }
453     return res;
454 }
455
456 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
457 {
458     data1_node *c;
459     Z_DatabaseList *res;
460     int i = 0;
461     
462     for (c = n->child; c; c = c->next)
463     {
464         if (!is_numeric_tag (eh, c) != 102) 
465             continue;
466         ++i;
467     }
468     if (!i)
469         return NULL;
470
471     res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
472     
473     res->num_databases = i;
474     res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
475     i = 0;
476     for (c = n->child; c; c = c->next)
477     {
478         if (!is_numeric_tag (eh, c) != 102)
479             continue;
480         res->databases[i++] = f_string (eh, c);
481     }
482     return res;
483 }
484
485 static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n)
486 {
487     Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
488         odr_malloc (eh->o, sizeof(*res));
489     data1_node *c;
490     
491     res->hostAddress = 0;
492     res->port = 0;
493
494     for (c = n->child; c; c = c->next)
495     {
496         switch (is_numeric_tag (eh, c))
497         {
498         case 121: res->hostAddress = f_string (eh, c); break;
499         case 122: res->port = f_integer (eh, c); break;
500         }
501     }
502     return res;
503 }
504
505 static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh,
506                                                     data1_node *n)
507 {
508     Z_NetworkAddressOther *res = (Z_NetworkAddressOther *)
509         odr_malloc (eh->o, sizeof(*res));
510     data1_node *c;
511
512     res->type = 0;
513     res->address = 0;
514
515     for (c = n->child; c; c = c->next)
516     {
517         switch (is_numeric_tag (eh, c))
518         {
519         case 124: res->type = f_string (eh, c); break;
520         case 121: res->address = f_string (eh, c); break;
521         }
522     }
523     return res;
524 }
525
526 static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n, 
527                                              int *num)
528 {
529     Z_NetworkAddress **res = NULL;
530     data1_node *c;
531     int i = 0;
532     
533     *num = 0;
534     for (c = n->child; c; c = c->next)
535     {
536         switch (is_numeric_tag (eh, c))
537         {
538         case 120:
539         case 123:
540             (*num)++;
541             break;
542         }
543     }
544
545     if (*num)
546         res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
547                                                
548     for (c = n->child; c; c = c->next)
549     {
550         switch (is_numeric_tag (eh, c))
551         {
552         case 120:
553             res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
554             res[i]->which = Z_NetworkAddress_iA;
555             res[i]->u.internetAddress = f_networkAddressIA(eh, c);
556             i++;
557             break;
558         case 123:
559             res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
560             res[i]->which = Z_NetworkAddress_other;
561             res[i]->u.other = f_networkAddressOther(eh, c);
562             i++;
563             break;
564         }
565     }
566     return res;
567 }
568
569 static Z_CategoryInfo *f_categoryInfo(ExpHandle *eh, data1_node *n)
570 {
571     Z_CategoryInfo *res = (Z_CategoryInfo *)odr_malloc(eh->o, sizeof(*res));
572     data1_node *c;
573
574     res->category = 0;
575     res->originalCategory = 0;
576     res->description = 0;
577     res->asn1Module = 0;
578     for (c = n->child; c; c = c->next)
579     {
580         switch (is_numeric_tag (eh, c))
581         {
582         case 102: res->category = f_string(eh, c); break;
583         case 302: res->originalCategory = f_string(eh, c); break;
584         case 113: res->description = f_humstring(eh, c); break;
585         case 303: res->asn1Module = f_string (eh, c); break;
586         }
587     }
588     return res;
589 }
590
591 static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n)
592 {
593     Z_CategoryList *res = (Z_CategoryList *)odr_malloc(eh->o, sizeof(*res));
594     data1_node *c;
595
596     res->commonInfo = 0;
597     res->num_categories = 0;
598     res->categories = NULL;
599
600     for (c = n->child; c; c = c->next)
601     {
602         int i = 0;
603
604         switch (is_numeric_tag (eh, c))
605         {
606         case 600: res->commonInfo = f_commonInfo(eh, c); break;
607         case 300:
608             for (n = c->child; n; n = n->next)
609             {
610                 if (is_numeric_tag(eh, n) != 301)
611                     continue;
612                 (res->num_categories)++;
613             }
614             if (res->num_categories)
615                 res->categories =
616                     (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories 
617                                                    * sizeof(*res->categories));
618             for (n = c->child; n; n = n->next)
619             {
620                 if (is_numeric_tag(eh, n) != 301)
621                     continue;
622                 res->categories[i++] = f_categoryInfo (eh, n);
623             }
624             break;
625         }
626     }
627     assert (res->num_categories && res->categories);
628     return res;
629 }
630
631 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
632 {
633     Z_TargetInfo *res = (Z_TargetInfo *)odr_malloc(eh->o, sizeof(*res));
634     data1_node *c;
635
636     res->commonInfo = 0;
637     res->name = 0;
638     res->recentNews = 0;
639     res->icon = 0;
640     res->namedResultSets = 0;
641     res->multipleDBsearch = 0;
642     res->maxResultSets = 0;
643     res->maxResultSize = 0;
644     res->maxTerms = 0;
645     res->timeoutInterval = 0;
646     res->welcomeMessage = 0;
647     res->contactInfo = 0;
648     res->description = 0;
649     res->num_nicknames = 0;
650     res->nicknames = 0;
651     res->usageRest = 0;
652     res->paymentAddr = 0;
653     res->hours = 0;
654     res->num_dbCombinations = 0;
655     res->dbCombinations = 0;
656     res->num_addresses = 0;
657     res->addresses = 0;
658     res->num_languages = 0;
659     res->languages = NULL;
660     res->commonAccessInfo = 0;
661     
662     for (c = n->child; c; c = c->next)
663     {
664         int i = 0;
665
666         switch (is_numeric_tag (eh, c))
667         {
668         case 600: res->commonInfo = f_commonInfo(eh, c); break;
669         case 102: res->name = f_string(eh, c); break;
670         case 103: res->recentNews = f_humstring(eh, c); break;
671         case 104: res->icon = NULL; break; /* fix */
672         case 105: res->namedResultSets = f_bool(eh, c); break;
673         case 106: res->multipleDBsearch = f_bool(eh, c); break;
674         case 107: res->maxResultSets = f_integer(eh, c); break;
675         case 108: res->maxResultSize = f_integer(eh, c); break;
676         case 109: res->maxTerms = f_integer(eh, c); break;
677         case 110: res->timeoutInterval = f_intunit(eh, c); break;
678         case 111: res->welcomeMessage = f_humstring(eh, c); break;
679         case 112: res->contactInfo = f_contactInfo(eh, c); break;
680         case 113: res->description = f_humstring(eh, c); break;
681         case 114: 
682             res->num_nicknames = 0;
683             for (n = c->child; n; n = n->next)
684             {
685                 if (is_numeric_tag(eh, n) != 102)
686                     continue;
687                 (res->num_nicknames)++;
688             }
689             if (res->num_nicknames)
690                 res->nicknames =
691                     (char **)odr_malloc (eh->o, res->num_nicknames 
692                                 * sizeof(*res->nicknames));
693             for (n = c->child; n; n = n->next)
694             {
695                 if (is_numeric_tag(eh, n) != 102)
696                     continue;
697                 res->nicknames[i++] = f_string (eh, n);
698             }
699             break;
700         case 115: res->usageRest = f_humstring(eh, c); break;
701         case 116: res->paymentAddr = f_humstring(eh, c); break;
702         case 117: res->hours = f_humstring(eh, c); break;
703         case 118:
704             res->num_dbCombinations = 0;
705             for (n = c->child; n; n = n->next)
706             {
707                 if (!is_numeric_tag(eh, n) != 605)
708                     continue;
709                 (res->num_dbCombinations)++;
710             }
711             if (res->num_dbCombinations)
712                 res->dbCombinations =
713                     (Z_DatabaseList **)odr_malloc (eh->o, res->num_dbCombinations
714                                 * sizeof(*res->dbCombinations));
715             for (n = c->child; n; n = n->next)
716             {
717                 if (!is_numeric_tag(eh, n) != 605)
718                     continue;
719                 res->dbCombinations[i++] = f_databaseList (eh, n);
720             }
721             break;
722         case 119: 
723             res->addresses =
724                 f_networkAddresses (eh, c, &res->num_addresses);
725             break;
726         case 125:
727             res->num_languages = 0;
728             for (n = c->child; n; n = n->next)
729             {
730                 if (!is_numeric_tag(eh, n) != 126)
731                     continue;
732                 (res->num_languages)++;
733             }
734             if (res->num_languages)
735                 res->languages = (char **)
736                     odr_malloc (eh->o, res->num_languages *
737                                 sizeof(*res->languages));
738             for (n = c->child; n; n = n->next)
739             {
740                 if (!is_numeric_tag(eh, n) != 126)
741                     continue;
742                 res->languages[i++] = f_string (eh, n);
743             }
744             break;
745         case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
746         }
747     }
748     if (!res->namedResultSets)
749         res->namedResultSets = eh->false_value;
750     if (!res->multipleDBsearch)
751         res->multipleDBsearch = eh->false_value;
752     return res;
753 }
754
755 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
756 {
757     Z_DatabaseInfo *res = (Z_DatabaseInfo *)odr_malloc(eh->o, sizeof(*res));
758     data1_node *c;
759
760     res->commonInfo = 0;
761     res->name = 0;
762     res->explainDatabase = 0;
763     res->num_nicknames = 0;
764     res->nicknames = 0;
765     res->icon = 0;
766     res->userFee = 0;
767     res->available = 0;
768     res->titleString = 0;
769     res->num_keywords = 0;
770     res->keywords = 0;
771     res->description = 0;
772     res->associatedDbs = 0;
773     res->subDbs = 0;
774     res->disclaimers = 0;
775     res->news = 0;
776     res->u.actualNumber = 0;
777     res->defaultOrder = 0;
778     res->avRecordSize = 0;
779     res->maxRecordSize = 0;
780     res->hours = 0;
781     res->bestTime = 0;
782     res->lastUpdate = 0;
783     res->updateInterval = 0;
784     res->coverage = 0;
785     res->proprietary = 0;
786     res->copyrightText = 0;
787     res->copyrightNotice = 0;
788     res->producerContactInfo = 0;
789     res->supplierContactInfo = 0;
790     res->submissionContactInfo = 0;
791     res->accessInfo = 0;
792     
793     for (c = n->child; c; c = c->next)
794     {
795         int i = 0;
796
797         switch (is_numeric_tag (eh, c))
798         {
799         case 600: res->commonInfo = f_commonInfo(eh, c); break;
800         case 102: res->name = f_string(eh, c); break;
801         case 226: res->explainDatabase = odr_nullval(); break;
802         case 114:
803             res->num_nicknames = 0;
804             for (n = c->child; n; n = n->next)
805             {
806                 if (!is_numeric_tag(eh, n) ||
807                     n->u.tag.element->tag->value.numeric != 102)
808                     continue;
809                 (res->num_nicknames)++;
810             }
811             if (res->num_nicknames)
812                 res->nicknames =
813                     (char **)odr_malloc (eh->o, res->num_nicknames 
814                                 * sizeof(*res->nicknames));
815             for (n = c->child; n; n = n->next)
816             {
817                 if (!is_numeric_tag(eh, n) ||
818                     n->u.tag.element->tag->value.numeric != 102)
819                     continue;
820                 res->nicknames[i++] = f_string (eh, n);
821             }
822             break;
823         case 104: res->icon = 0; break;      /* fix */
824         case 201: res->userFee = f_bool(eh, c); break;
825         case 202: res->available = f_bool(eh, c); break;
826         case 203: res->titleString = f_humstring(eh, c); break;
827         case 227:
828             res->num_keywords = 0;
829             for (n = c->child; n; n = n->next)
830             {
831                 if (!is_numeric_tag(eh, n) != 1000)
832                     continue;
833                 (res->num_keywords)++;
834             }
835             if (res->num_keywords)
836                 res->keywords =
837                     (Z_HumanString **)odr_malloc (eh->o, res->num_keywords 
838                                 * sizeof(*res->keywords));
839             for (n = c->child; n; n = n->next)
840             {
841                 if (!is_numeric_tag(eh, n) != 1000)
842                     continue;
843                 res->keywords[i++] = f_humstring (eh, n);
844             }
845             break;
846         case 113: res->description = f_humstring(eh, c); break;
847         case 205:
848             res->associatedDbs = f_databaseList (eh, c);
849             break;
850         case 206:
851             res->subDbs = f_databaseList (eh, c);
852             break;
853         case 207: res->disclaimers = f_humstring(eh, c); break;
854         case 103: res->news = f_humstring(eh, c); break;
855         case 209: res->u.actualNumber =
856                       f_recordCount(eh, c, &res->which); break;
857         case 212: res->defaultOrder = f_humstring(eh, c); break;
858         case 213: res->avRecordSize = f_integer(eh, c); break;
859         case 214: res->maxRecordSize = f_integer(eh, c); break;
860         case 215: res->hours = f_humstring(eh, c); break;
861         case 216: res->bestTime = f_humstring(eh, c); break;
862         case 217: res->lastUpdate = f_string(eh, c); break;
863         case 218: res->updateInterval = f_intunit(eh, c); break;
864         case 219: res->coverage = f_humstring(eh, c); break;
865         case 220: res->proprietary = f_bool(eh, c); break;
866         case 221: res->copyrightText = f_humstring(eh, c); break;
867         case 222: res->copyrightNotice = f_humstring(eh, c); break;
868         case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
869         case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
870         case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
871         case 500: res->accessInfo = f_accessInfo(eh, c); break;
872         }
873     }
874     if (!res->userFee)
875         res->userFee = eh->false_value;
876     if (!res->available)
877         res->available = eh->true_value;
878     return res;
879 }
880
881 Z_StringOrNumeric *f_stringOrNumeric (ExpHandle *eh, data1_node *n)
882 {
883     Z_StringOrNumeric *res = (Z_StringOrNumeric *)
884         odr_malloc (eh->o, sizeof(*res));
885     data1_node *c;
886     for (c = n->child; c; c = c->next)
887     {
888         switch (is_numeric_tag (eh, c))
889         {
890         case 1001:
891             res->which = Z_StringOrNumeric_string;
892             res->u.string = f_string (eh, c);
893             break;
894         case 1002:
895             res->which = Z_StringOrNumeric_numeric;
896             res->u.numeric = f_integer (eh, c);
897             break;
898         }
899     }
900     return res;
901 }
902
903 Z_AttributeDescription *f_attributeDescription (
904     ExpHandle *eh, data1_node *n)
905 {
906     Z_AttributeDescription *res = (Z_AttributeDescription *)
907         odr_malloc(eh->o, sizeof(*res));
908     data1_node *c;
909     int i = 0;
910         
911     res->name = 0;
912     res->description = 0;
913     res->attributeValue = 0;
914     res->num_equivalentAttributes = 0;
915     res->equivalentAttributes = 0;
916
917     for (c = n->child; c; c = c->next)
918     {
919         switch (is_numeric_tag (eh, c))
920         {
921         case 102: res->name = f_string (eh, c); break;
922         case 113: res->description = f_humstring (eh, c); break;
923         case 710: res->attributeValue = f_stringOrNumeric (eh, c); break;
924         case 752: (res->num_equivalentAttributes++); break;
925         }
926     }
927     if (res->num_equivalentAttributes)
928         res->equivalentAttributes = (Z_StringOrNumeric **)
929             odr_malloc (eh->o, sizeof(*res->equivalentAttributes) *
930                         res->num_equivalentAttributes);
931     for (c = n->child; c; c = c->next)
932         if (is_numeric_tag (eh, c) == 752)
933             res->equivalentAttributes[i++] = f_stringOrNumeric (eh, c);
934     return res;
935 }
936
937 Z_AttributeType *f_attributeType (ExpHandle *eh, data1_node *n)
938 {
939     Z_AttributeType *res = (Z_AttributeType *)
940         odr_malloc(eh->o, sizeof(*res));
941     data1_node *c;
942
943     res->name = 0;
944     res->description = 0;
945     res->attributeType = 0;
946     res->num_attributeValues = 0;
947     res->attributeValues = 0;
948
949     for (c = n->child; c; c = c->next)
950     {
951         int i = 0;
952         switch (is_numeric_tag (eh, c))
953         {
954         case 102: res->name = f_string (eh, c); break;
955         case 113: res->description = f_humstring (eh, c); break;
956         case 704: res->attributeType = f_integer (eh, c); break;
957         case 708:
958             for (n = c->child; n; n = n->next)
959             {
960                 if (is_numeric_tag(eh, n) != 709)
961                     continue;
962                 (res->num_attributeValues)++;
963             }
964             if (res->num_attributeValues)
965                 res->attributeValues = (Z_AttributeDescription **)
966                     odr_malloc (eh->o, res->num_attributeValues
967                                 * sizeof(*res->attributeValues));
968             for (n = c->child; n; n = n->next)
969             {
970                 if (is_numeric_tag(eh, n) != 709)
971                     continue;
972                 res->attributeValues[i++] = f_attributeDescription (eh, n);
973             }
974             break;
975         }
976     }
977     return res;
978 }
979
980 Z_AttributeSetInfo *f_attributeSetInfo (ExpHandle *eh, data1_node *n)
981 {
982     Z_AttributeSetInfo *res = (Z_AttributeSetInfo *)
983         odr_malloc(eh->o, sizeof(*res));
984     data1_node *c;
985
986     res->commonInfo = 0;
987     res->attributeSet = 0;
988     res->name = 0;
989     res->num_attributes = 0;
990     res->attributes = 0;
991     res->description = 0;
992     for (c = n->child; c; c = c->next)
993     {
994         int i = 0;
995         switch (is_numeric_tag (eh, c))
996         {
997         case 600: res->commonInfo = f_commonInfo (eh, c); break;
998         case 1000: res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
999         case 102: res->name = f_string (eh, c); break;
1000         case 750:
1001             for (n = c->child; n; n = n->next)
1002             {
1003                 if (is_numeric_tag(eh, n) != 751)
1004                     continue;
1005                 (res->num_attributes)++;
1006             }
1007             if (res->num_attributes)
1008                 res->attributes = (Z_AttributeType **)
1009                     odr_malloc (eh->o, res->num_attributes
1010                                 * sizeof(*res->attributes));
1011             for (n = c->child; n; n = n->next)
1012             {
1013                 if (is_numeric_tag(eh, n) != 751)
1014                     continue;
1015                 res->attributes[i++] = f_attributeType (eh, n);
1016             }
1017             break;
1018         case 113: res->description = f_humstring (eh, c); break;
1019         }
1020     }
1021     return res;
1022 }
1023
1024 Z_OmittedAttributeInterpretation *f_omittedAttributeInterpretation (
1025     ExpHandle *eh, data1_node *n)
1026 {
1027     Z_OmittedAttributeInterpretation *res = (Z_OmittedAttributeInterpretation*)
1028         odr_malloc (eh->o, sizeof(*res));
1029     data1_node *c;
1030
1031     res->defaultValue = 0;
1032     res->defaultDescription = 0;
1033     for (c = n->child; c; c = c->next)
1034     {
1035         switch (is_numeric_tag (eh, c))
1036         {
1037         case 706:
1038             res->defaultValue = f_stringOrNumeric (eh, c);
1039             break;
1040         case 113:
1041             res->defaultDescription = f_humstring(eh, c);
1042             break;
1043         }
1044     }
1045     return res;
1046 }
1047
1048 Z_AttributeValue *f_attributeValue (ExpHandle *eh, data1_node *n)
1049 {
1050     Z_AttributeValue *res = (Z_AttributeValue *)
1051         odr_malloc (eh->o, sizeof(*res));
1052     data1_node *c;
1053
1054     res->value = 0;
1055     res->description = 0;
1056     res->num_subAttributes = 0;
1057     res->subAttributes = 0;
1058     res->num_superAttributes = 0;
1059     res->superAttributes = 0;
1060     res->partialSupport = 0;
1061     for (c = n->child; c; c = c->next)
1062     {
1063         int i = 0;
1064         switch (is_numeric_tag (eh, c))
1065         {
1066         case 710:
1067             res->value = f_stringOrNumeric (eh, c);  break;
1068         case 113:
1069             res->description = f_humstring (eh, c); break;
1070         case 712:
1071             for (n = c->child; n; n = n->next)
1072             {
1073                 if (is_numeric_tag(eh, n) != 713)
1074                     continue;
1075                 (res->num_subAttributes)++;
1076             }
1077             if (res->num_subAttributes)
1078                 res->subAttributes =
1079                     (Z_StringOrNumeric **)
1080                     odr_malloc (eh->o, res->num_subAttributes
1081                                 * sizeof(*res->subAttributes));
1082             for (n = c->child; n; n = n->next)
1083             {
1084                 if (is_numeric_tag(eh, n) != 713)
1085                     continue;
1086                 res->subAttributes[i++] = f_stringOrNumeric (eh, n);
1087             }
1088             break;
1089         case 714:
1090             for (n = c->child; n; n = n->next)
1091             {
1092                 if (is_numeric_tag(eh, n) != 715)
1093                     continue;
1094                 (res->num_superAttributes)++;
1095             }
1096             if (res->num_superAttributes)
1097                 res->superAttributes =
1098                     (Z_StringOrNumeric **)
1099                     odr_malloc (eh->o, res->num_superAttributes
1100                                 * sizeof(*res->superAttributes));
1101             for (n = c->child; n; n = n->next)
1102             {
1103                 if (is_numeric_tag(eh, n) != 715)
1104                     continue;
1105                 res->superAttributes[i++] = f_stringOrNumeric (eh, n);
1106             }
1107             break;
1108         case 711:
1109             res->partialSupport = odr_nullval ();
1110             break;
1111         }
1112     }
1113     return res;
1114 }
1115
1116 Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
1117 {
1118     Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
1119         odr_malloc(eh->o, sizeof(*res));
1120     data1_node *c;
1121     res->attributeType = 0;
1122     res->defaultIfOmitted = 0;
1123     res->num_attributeValues = 0;
1124     res->attributeValues = 0;
1125     for (c = n->child; c; c = c->next)
1126     {
1127         int i = 0;
1128         switch (is_numeric_tag (eh, c))
1129         {
1130         case 704: res->attributeType = f_integer (eh, c); break;
1131         case 705:
1132             res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
1133             break;
1134         case 708:
1135             for (n = c->child; n; n = n->next)
1136             {
1137                 if (is_numeric_tag(eh, n) != 709)
1138                     continue;
1139                 (res->num_attributeValues)++;
1140             }
1141             if (res->num_attributeValues)
1142                 res->attributeValues =
1143                     (Z_AttributeValue **)
1144                     odr_malloc (eh->o, res->num_attributeValues
1145                                 * sizeof(*res->attributeValues));
1146             for (n = c->child; n; n = n->next)
1147             {
1148                 if (is_numeric_tag(eh, n) != 709)
1149                     continue;
1150                 res->attributeValues[i++] = f_attributeValue (eh, n);
1151             }
1152             break;
1153         }
1154     }
1155     return res;
1156 }
1157
1158 Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
1159 {
1160     Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
1161         odr_malloc(eh->o, sizeof(*res));
1162     data1_node *c;
1163     
1164     res->attributeSet = 0;
1165     res->num_attributesByType = 0;
1166     res->attributesByType = 0;
1167     for (c = n->child; c; c = c->next)
1168     {
1169         int i = 0;
1170         switch (is_numeric_tag (eh, c))
1171         {
1172         case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
1173         case 702:
1174             for (n = c->child; n; n = n->next)
1175             {
1176                 if (is_numeric_tag(eh, n) != 703)
1177                     continue;
1178                 (res->num_attributesByType)++;
1179             }
1180             if (res->num_attributesByType)
1181                 res->attributesByType =
1182                     (Z_AttributeTypeDetails **)
1183                     odr_malloc (eh->o, res->num_attributesByType
1184                                 * sizeof(*res->attributesByType));
1185             for (n = c->child; n; n = n->next)
1186             {
1187                 if (is_numeric_tag(eh, n) != 703)
1188                     continue;
1189                 res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
1190             }
1191             break;
1192         }
1193     }
1194     return res;
1195 }
1196
1197 Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
1198 {
1199     Z_AttributeValueList *res = (Z_AttributeValueList *)
1200         odr_malloc (eh->o, sizeof(*res));
1201     data1_node *c;
1202     int i = 0;
1203
1204     res->num_attributes = 0;
1205     res->attributes = 0;
1206     for (c = n->child; c; c = c->next)
1207         if (is_numeric_tag (eh, c) == 710)
1208             (res->num_attributes)++;
1209     if (res->num_attributes)
1210     {
1211         res->attributes = (Z_StringOrNumeric **)
1212             odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
1213     }
1214     for (c = n->child; c; c = c->next)
1215         if (is_numeric_tag(eh, c) == 710)
1216             res->attributes[i++] = f_stringOrNumeric (eh, c);
1217     return res;
1218 }
1219
1220 Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
1221 {
1222     Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
1223         odr_malloc (eh->o, sizeof(*res));
1224     data1_node *c;
1225
1226     res->attributeSet = 0;
1227     res->attributeType = 0;
1228     res->mustBeSupplied = 0;
1229     res->which = Z_AttributeOcc_any_or_none;
1230     res->attributeValues.any_or_none = odr_nullval ();
1231
1232     for (c = n->child; c; c = c->next)
1233     {
1234         switch (is_numeric_tag (eh, c))
1235         {
1236         case 1000:
1237             res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
1238         case 704:
1239             res->attributeType = f_integer (eh, c); break;
1240         case 720:
1241             res->mustBeSupplied = odr_nullval (); break;
1242         case 721:
1243             res->which = Z_AttributeOcc_any_or_none;
1244             res->attributeValues.any_or_none = odr_nullval ();
1245             break;
1246         case 722:
1247             res->which = Z_AttributeOcc_specific;
1248             res->attributeValues.specific = f_attributeValueList (eh, c);
1249             break;
1250         }
1251     }
1252     return res;
1253 }
1254
1255 Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
1256 {
1257     Z_AttributeCombination *res = (Z_AttributeCombination *)
1258         odr_malloc (eh->o, sizeof(*res));
1259     data1_node *c;
1260     int i = 0;
1261
1262     res->num_occurrences = 0;
1263     res->occurrences = 0;
1264     for (c = n->child; c; c = c->next)
1265         if (is_numeric_tag (eh, c) == 719)
1266             (res->num_occurrences)++;
1267     if (res->num_occurrences)
1268     {
1269         res->occurrences = (Z_AttributeOccurrence **)
1270             odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
1271     }
1272     for (c = n->child; c; c = c->next)
1273         if (is_numeric_tag(eh, c) == 719)
1274             res->occurrences[i++] = f_attributeOccurrence (eh, c);
1275     assert (res->num_occurrences);
1276     return res;
1277 }
1278
1279 Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
1280 {
1281     Z_AttributeCombinations *res = (Z_AttributeCombinations *)
1282         odr_malloc (eh->o, sizeof(*res));
1283     data1_node *c;
1284     res->defaultAttributeSet = 0;
1285     res->num_legalCombinations = 0;
1286     res->legalCombinations = 0;
1287
1288     for (c = n->child; c; c = c->next)
1289     {
1290         int i = 0;
1291         switch (is_numeric_tag (eh, c))
1292         {
1293         case 1000:
1294             res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
1295             break;
1296         case 717:
1297             for (n = c->child; n; n = n->next)
1298             {
1299                 if (is_numeric_tag(eh, n) != 718)
1300                     continue;
1301                 (res->num_legalCombinations)++;
1302             }
1303             if (res->num_legalCombinations)
1304                 res->legalCombinations =
1305                     (Z_AttributeCombination **)
1306                     odr_malloc (eh->o, res->num_legalCombinations
1307                                 * sizeof(*res->legalCombinations));
1308             for (n = c->child; n; n = n->next)
1309             {
1310                 if (is_numeric_tag(eh, n) != 718)
1311                     continue;
1312                 res->legalCombinations[i++] = f_attributeCombination (eh, n);
1313             }
1314             break;
1315         }
1316     }
1317     assert (res->num_legalCombinations);
1318     return res;
1319 }
1320
1321 Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
1322 {
1323     Z_AttributeDetails *res = (Z_AttributeDetails *)
1324         odr_malloc(eh->o, sizeof(*res));
1325     data1_node *c;
1326
1327     res->commonInfo = 0;
1328     res->databaseName = 0;
1329     res->num_attributesBySet = 0;
1330     res->attributesBySet = NULL;
1331     res->attributeCombinations = NULL;
1332
1333     for (c = n->child; c; c = c->next)
1334     {
1335         int i = 0;
1336         switch (is_numeric_tag (eh, c))
1337         {
1338         case 600: res->commonInfo = f_commonInfo(eh, c); break;
1339         case 102: res->databaseName = f_string (eh, c); break;
1340         case 700:
1341             for (n = c->child; n; n = n->next)
1342             {
1343                 if (is_numeric_tag(eh, n) != 701)
1344                     continue;
1345                 (res->num_attributesBySet)++;
1346             }
1347             if (res->num_attributesBySet)
1348                 res->attributesBySet =
1349                     (Z_AttributeSetDetails **)
1350                     odr_malloc (eh->o, res->num_attributesBySet
1351                                 * sizeof(*res->attributesBySet));
1352             for (n = c->child; n; n = n->next)
1353             {
1354                 if (is_numeric_tag(eh, n) != 701)
1355                     continue;
1356                 res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
1357             }
1358             break;
1359         case 716:
1360             res->attributeCombinations = f_attributeCombinations (eh, c);
1361             break;
1362         }
1363     }
1364     return res;
1365 }
1366
1367 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
1368                                       int select, ODR o)
1369 {
1370     ExpHandle eh;
1371     Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
1372
1373     eh.dh = dh;
1374     eh.select = select;
1375     eh.o = o;
1376     eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
1377     *eh.false_value = 0;
1378     eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
1379     *eh.true_value = 1;
1380
1381     assert(n->which == DATA1N_root);
1382     if (strcmp(n->u.root.type, "explain"))
1383     {
1384         yaz_log(YLOG_WARN, "Attempt to convert a non-Explain record");
1385         return 0;
1386     }
1387     for (n = n->child; n; n = n->next)
1388     {
1389         switch (is_numeric_tag (&eh, n))
1390         {
1391         case 1:
1392             res->which = Z_Explain_categoryList;
1393             if (!(res->u.categoryList = f_categoryList(&eh, n)))
1394                 return 0;
1395             return res;     
1396         case 2:
1397             res->which = Z_Explain_targetInfo;
1398             if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
1399                 return 0;
1400             return res;
1401         case 3:
1402             res->which = Z_Explain_databaseInfo;
1403             if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
1404                 return 0;
1405             return res;
1406         case 7:
1407             res->which = Z_Explain_attributeSetInfo;
1408             if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
1409                 return 0;
1410             return res;     
1411         case 10:
1412             res->which = Z_Explain_attributeDetails;
1413             if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
1414                 return 0;
1415             return res;
1416         }
1417     }
1418     yaz_log(YLOG_WARN, "No category in Explain record");
1419     return 0;
1420 }
1421 /*
1422  * Local variables:
1423  * c-basic-offset: 4
1424  * indent-tabs-mode: nil
1425  * End:
1426  * vim: shiftwidth=4 tabstop=8 expandtab
1427  */
1428