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.3 1995-11-01 16:34:58 quinn
8 * Making data1 look for tables in data1_tabpath
10 * Revision 1.2 1995/11/01 13:54:49 quinn
13 * Revision 1.1 1995/11/01 11:56:09 quinn
14 * Added Retrieval (data management) functions en masse.
31 * We'll probably want to add some sort of hashed index to these lookup-
32 * functions eventually.
35 data1_datatype data1_maptype(char *t)
43 {"structured", DATA1K_structured},
44 {"string", DATA1K_string},
45 {"numeric", DATA1K_numeric},
47 {"bool", DATA1K_bool},
48 {"generalizedtime", DATA1K_generalizedtime},
49 {"intunit", DATA1K_intunit},
51 {"octetstring", DATA1K_octetstring},
56 for (i = 0; types[i].tname; i++)
57 if (!data1_matchstr(types[i].tname, t))
62 data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value)
66 for (; s; s = s->next)
70 for (r = s->tags; r; r = r->next)
71 if (r->which == DATA1T_numeric && r->value.numeric == value)
73 /* scan included sets */
74 if (s->children && (r = data1_gettagbynum(s->children, type, value)))
80 data1_tag *data1_gettagbyname(data1_tagset *s, char *name)
84 for (; s; s = s->next)
87 for (r = s->tags; r; r = r->next)
91 for (np = r->names; np; np = np->next)
92 if (!data1_matchstr(np->name, name))
95 /* scan included sets */
96 if (s->children && (r = data1_gettagbyname(s->children, name)))
102 data1_tagset *data1_read_tagset(char *file)
104 char line[512], *r, cmd[512], args[512];
105 data1_tagset *res = 0, **childp;
109 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
111 logf(LOG_WARN|LOG_ERRNO, "%s", file);
115 if (!(res = xmalloc(sizeof(*res))))
122 childp = &res->children;
127 while ((r = fgets(line, 512, f)))
129 while (*r && isspace(*r))
139 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
141 if (!strcmp(cmd, "tag"))
144 char names[512], type[512], *nm;
148 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
150 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
155 if (!(rr = *tagp = xmalloc(sizeof(*rr))))
160 rr->which = DATA1T_numeric;
161 rr->value.numeric = value;
163 * how to deal with local numeric tags?
166 if (!(rr->kind = data1_maptype(type)))
168 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
180 if (!(*npp = xmalloc(sizeof(**npp))))
182 if ((e = strchr(nm, '/')))
184 if (!((*npp)->name = xmalloc(strlen(nm)+1)))
186 strcpy((*npp)->name, nm);
194 else if (!strcmp(cmd, "name"))
198 if (!sscanf(args, "%s", name))
200 logf(LOG_WARN, "%s malformed name directive in %s", file);
204 if (!(res->name = xmalloc(strlen(args)+1)))
206 strcpy(res->name, name);
208 else if (!strcmp(cmd, "reference"))
212 if (!sscanf(args, "%s", name))
214 logf(LOG_WARN, "%s malformed reference directive in %s", file);
218 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
220 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
225 else if (!strcmp(cmd, "type"))
227 if (!sscanf(args, "%d", &res->type))
229 logf(LOG_WARN, "%s malformed type directive in %s", file);
234 else if (!strcmp(cmd, "include"))
238 if (!sscanf(args, "%s", name))
240 logf(LOG_WARN, "%s malformed reference directive in %s", file);
244 if (!(*childp = data1_read_tagset(name)))
246 logf(LOG_WARN, "Inclusion failed in %s", file);
250 childp = &(*childp)->next;
254 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);