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.1 1995-11-01 11:56:09 quinn
8 * Added Retrieval (data management) functions en masse.
24 * We'll probably want to add some sort of hashed index to these lookup-
25 * functions eventually.
28 data1_datatype data1_maptype(char *t)
36 {"structured", DATA1K_structured},
37 {"string", DATA1K_string},
38 {"numeric", DATA1K_numeric},
40 {"bool", DATA1K_bool},
41 {"generalizedtime", DATA1K_generalizedtime},
42 {"intunit", DATA1K_intunit},
44 {"octetstring", DATA1K_octetstring},
49 for (i = 0; types[i].tname; i++)
50 if (!data1_matchstr(types[i].tname, t))
55 data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value)
59 for (; s; s = s->next)
63 for (r = s->tags; r; r = r->next)
64 if (r->which == DATA1T_numeric && r->value.numeric == value)
66 /* scan included sets */
67 if (s->children && (r = data1_gettagbynum(s->children, type, value)))
73 data1_tag *data1_gettagbyname(data1_tagset *s, char *name)
77 for (; s; s = s->next)
80 for (r = s->tags; r; r = r->next)
84 for (np = r->names; np; np = np->next)
85 if (!data1_matchstr(np->name, name))
88 /* scan included sets */
89 if (s->children && (r = data1_gettagbyname(s->children, name)))
95 data1_tagset *data1_read_tagset(char *file)
97 char line[512], *r, cmd[512], args[512];
98 data1_tagset *res = 0, **childp;
102 if (!(f = fopen(file, "r")))
104 logf(LOG_WARN|LOG_ERRNO, "%s", file);
108 if (!(res = xmalloc(sizeof(*res))))
115 childp = &res->children;
120 while ((r = fgets(line, 512, f)))
122 while (*r && isspace(*r))
132 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
134 if (!strcmp(cmd, "tag"))
137 char names[512], type[512], *nm;
141 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
143 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
148 if (!(rr = *tagp = xmalloc(sizeof(*rr))))
153 rr->which = DATA1T_numeric;
154 rr->value.numeric = value;
156 * how to deal with local numeric tags?
159 if (!(rr->kind = data1_maptype(type)))
161 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
173 if (!(*npp = xmalloc(sizeof(**npp))))
175 if ((e = strchr(nm, '/')))
177 if (!((*npp)->name = xmalloc(strlen(nm)+1)))
179 strcpy((*npp)->name, nm);
187 else if (!strcmp(cmd, "name"))
191 if (!sscanf(args, "%s", name))
193 logf(LOG_WARN, "%s malformed name directive in %s", file);
197 if (!(res->name = xmalloc(strlen(args)+1)))
199 strcpy(res->name, name);
201 else if (!strcmp(cmd, "reference"))
205 if (!sscanf(args, "%s", name))
207 logf(LOG_WARN, "%s malformed reference directive in %s", file);
211 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
213 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
218 else if (!strcmp(cmd, "type"))
220 if (!sscanf(args, "%d", &res->type))
222 logf(LOG_WARN, "%s malformed type directive in %s", file);
227 else if (!strcmp(cmd, "include"))
231 if (!sscanf(args, "%s", name))
233 logf(LOG_WARN, "%s malformed reference directive in %s", file);
237 if (!(*childp = data1_read_tagset(name)))
239 logf(LOG_WARN, "Inclusion failed in %s", file);
243 childp = &(*childp)->next;
247 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);