2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_tagset.c,v $
7 * Revision 1.4 1995-11-13 09:27:38 quinn
8 * Fiddling with the variant stuff.
10 * Revision 1.3 1995/11/01 16:34:58 quinn
11 * Making data1 look for tables in data1_tabpath
13 * Revision 1.2 1995/11/01 13:54:49 quinn
16 * Revision 1.1 1995/11/01 11:56:09 quinn
17 * Added Retrieval (data management) functions en masse.
34 * We'll probably want to add some sort of hashed index to these lookup-
35 * functions eventually.
38 data1_datatype data1_maptype(char *t)
46 {"structured", DATA1K_structured},
47 {"string", DATA1K_string},
48 {"numeric", DATA1K_numeric},
50 {"bool", DATA1K_bool},
51 {"generalizedtime", DATA1K_generalizedtime},
52 {"intunit", DATA1K_intunit},
54 {"octetstring", DATA1K_octetstring},
55 {"null", DATA1K_null},
60 for (i = 0; types[i].tname; i++)
61 if (!data1_matchstr(types[i].tname, t))
66 data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value)
70 for (; s; s = s->next)
74 for (r = s->tags; r; r = r->next)
75 if (r->which == DATA1T_numeric && r->value.numeric == value)
77 /* scan included sets */
78 if (s->children && (r = data1_gettagbynum(s->children, type, value)))
84 data1_tag *data1_gettagbyname(data1_tagset *s, char *name)
88 for (; s; s = s->next)
91 for (r = s->tags; r; r = r->next)
95 for (np = r->names; np; np = np->next)
96 if (!data1_matchstr(np->name, name))
99 /* scan included sets */
100 if (s->children && (r = data1_gettagbyname(s->children, name)))
106 data1_tagset *data1_read_tagset(char *file)
108 char line[512], *r, cmd[512], args[512];
109 data1_tagset *res = 0, **childp;
113 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
115 logf(LOG_WARN|LOG_ERRNO, "%s", file);
119 if (!(res = xmalloc(sizeof(*res))))
126 childp = &res->children;
131 while ((r = fgets(line, 512, f)))
133 while (*r && isspace(*r))
143 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
145 if (!strcmp(cmd, "tag"))
148 char names[512], type[512], *nm;
152 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
154 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
159 if (!(rr = *tagp = xmalloc(sizeof(*rr))))
164 rr->which = DATA1T_numeric;
165 rr->value.numeric = value;
167 * how to deal with local numeric tags?
170 if (!(rr->kind = data1_maptype(type)))
172 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
184 if (!(*npp = xmalloc(sizeof(**npp))))
186 if ((e = strchr(nm, '/')))
188 if (!((*npp)->name = xmalloc(strlen(nm)+1)))
190 strcpy((*npp)->name, nm);
198 else if (!strcmp(cmd, "name"))
202 if (!sscanf(args, "%s", name))
204 logf(LOG_WARN, "%s malformed name directive in %s", file);
208 if (!(res->name = xmalloc(strlen(args)+1)))
210 strcpy(res->name, name);
212 else if (!strcmp(cmd, "reference"))
216 if (!sscanf(args, "%s", name))
218 logf(LOG_WARN, "%s malformed reference directive in %s", file);
222 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
224 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
229 else if (!strcmp(cmd, "type"))
231 if (!sscanf(args, "%d", &res->type))
233 logf(LOG_WARN, "%s malformed type directive in %s", file);
238 else if (!strcmp(cmd, "include"))
242 if (!sscanf(args, "%s", name))
244 logf(LOG_WARN, "%s malformed reference directive in %s", file);
248 if (!(*childp = data1_read_tagset(name)))
250 logf(LOG_WARN, "Inclusion failed in %s", file);
254 childp = &(*childp)->next;
258 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);