2 * Copyright (c) 1995-2002, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: d1_tagset.c,v 1.1 2002-10-22 12:53:33 adam Exp $
17 * We'll probably want to add some sort of hashed index to these lookup-
18 * functions eventually.
21 data1_datatype data1_maptype (data1_handle dh, char *t)
29 {"structured", DATA1K_structured},
30 {"string", DATA1K_string},
31 {"numeric", DATA1K_numeric},
33 {"bool", DATA1K_bool},
34 {"generalizedtime", DATA1K_generalizedtime},
35 {"intunit", DATA1K_intunit},
37 {"octetstring", DATA1K_octetstring},
38 {"null", DATA1K_null},
39 {NULL, (data1_datatype) -1}
43 for (i = 0; types[i].tname; i++)
44 if (!data1_matchstr(types[i].tname, t))
46 return DATA1K_unknown;
49 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
54 for (; s; s = s->next)
58 for (r = s->tags; r; r = r->next)
59 if (r->which == DATA1T_numeric && r->value.numeric == value)
61 /* scan included sets */
63 (r = data1_gettagbynum (dh, s->children, type, value)))
69 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
74 for (; s; s = s->next)
77 for (r = s->tags; r; r = r->next)
81 for (np = r->names; np; np = np->next)
82 if (!data1_matchstr(np->name, name))
85 /* scan included sets */
86 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
92 data1_tagset *data1_empty_tagset (data1_handle dh)
95 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
97 res->reference = VAL_NONE;
105 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
107 NMEM mem = data1_nmem_get (dh);
108 data1_tagset *res = 0;
109 data1_tagset **childp;
114 char *argv[50], line[512];
116 if (!(f = data1_path_fopen(dh, file, "r")))
118 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
121 res = data1_empty_tagset (dh);
123 childp = &res->children;
126 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
129 if (!strcmp(cmd, "tag"))
132 char *names, *type, *nm;
138 yaz_log(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
141 value = atoi(argv[1]);
145 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
148 rr->which = DATA1T_numeric;
149 rr->value.numeric = value;
151 * how to deal with local numeric tags?
154 if (!(rr->kind = data1_maptype(dh, type)))
156 yaz_log(LOG_WARN, "%s:%d: Unknown datatype %s",
169 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
170 if ((e = strchr(nm, '/')))
172 (*npp)->name = nmem_strdup(mem, nm);
180 else if (!strcmp(cmd, "name"))
184 yaz_log(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
187 res->name = nmem_strdup(mem, argv[1]);
189 else if (!strcmp(cmd, "reference"))
195 yaz_log(LOG_WARN, "%s:%d: Bad # args to reference",
200 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
202 yaz_log(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
207 else if (!strcmp(cmd, "type"))
211 yaz_log (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
215 res->type = atoi(argv[1]);
217 else if (!strcmp(cmd, "include"))
224 yaz_log(LOG_WARN, "%s:%d: Bad # args to include",
230 type = atoi(argv[2]);
231 *childp = data1_read_tagset (dh, name, type);
234 yaz_log(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
238 childp = &(*childp)->next;
242 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",