2 * Copyright (c) 1995-1998, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_attset.c,v $
7 * Revision 1.9 1998-05-18 13:07:03 adam
8 * Changed the way attribute sets are handled by the retriaval module.
9 * Extended Explain conversion / schema.
10 * Modified server and client to work with ASN.1 compiled protocol handlers.
12 * Revision 1.8 1998/02/11 11:53:35 adam
13 * Changed code so that it compiles as C++.
15 * Revision 1.7 1997/09/17 12:10:34 adam
18 * Revision 1.6 1997/09/05 09:50:56 adam
19 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
21 * Revision 1.5 1996/05/09 07:27:43 quinn
22 * Multiple local attributes values supported.
24 * Revision 1.4 1996/02/21 15:23:36 quinn
25 * Reversed fclose and return;
27 * Revision 1.3 1995/12/13 17:14:26 quinn
28 * *** empty log message ***
30 * Revision 1.2 1995/11/01 16:34:55 quinn
31 * Making data1 look for tables in data1_tabpath
33 * Revision 1.1 1995/11/01 11:56:07 quinn
34 * Added Retrieval (data management) functions en masse.
45 #include <d1_attset.h>
49 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name)
52 data1_attset_child *c;
55 for (r = s->atts; r; r = r->next)
56 if (!data1_matchstr(r->name, name))
58 for (c = s->children; c; c = c->next)
61 /* scan included sets */
62 if ((r = data1_getattbyname (dh, c->child, name)))
68 data1_attset *data1_read_attset(data1_handle dh, const char *file)
70 char line[512], *r, cmd[512], args[512];
71 data1_attset *res = 0;
72 data1_attset_child **childp;
75 NMEM mem = data1_nmem_get (dh);
77 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
79 res = (data1_attset *)nmem_malloc(mem, sizeof(*res));
81 res->reference = VAL_NONE;
84 childp = &res->children;
89 while ((r = fgets(line, 512, f)))
91 while (*r && isspace(*r))
101 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
103 if (!strcmp(cmd, "att"))
106 char name[512], localstr[512];
108 data1_local_attribute *locals;
110 if ((rr = sscanf(args, "%511d %s %511s", &num, name, localstr)) < 2)
112 logf(LOG_WARN, "Not enough arguments to att in '%s' in %s",
117 if (rr < 3) /* no local attributes given */
119 locals = (data1_local_attribute *)nmem_malloc(mem, sizeof(*locals));
123 else /* parse the string "local{,local}" */
126 data1_local_attribute **ap = &locals;
129 *ap = (data1_local_attribute *)nmem_malloc(mem, sizeof(**ap));
130 (*ap)->local = atoi(p);
134 while ((p = strchr(p, ',')) && *(++p));
136 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
138 t->name = nmem_strdup(mem, name);
144 else if (!strcmp(cmd, "name"))
148 if (!sscanf(args, "%s", name))
150 logf(LOG_WARN, "%s malformed name directive in %s", file);
155 else if (!strcmp(cmd, "reference"))
159 if (!sscanf(args, "%s", name))
161 logf(LOG_WARN, "%s malformed reference directive in %s", file);
165 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
167 logf(LOG_WARN, "Unknown attset name '%s' in %s", name, file);
172 else if (!strcmp(cmd, "ordinal"))
175 if (!sscanf(args, "%d", &dummy))
177 logf(LOG_WARN, "%s malformed ordinal directive in %s", file);
182 else if (!strcmp(cmd, "include"))
186 if (!sscanf(args, "%s", name))
188 logf(LOG_WARN, "%s malformed reference directive in %s", file);
192 *childp = (data1_attset_child *)
193 nmem_malloc (mem, sizeof(**childp));
194 if (!((*childp)->child = data1_get_attset (dh, name)))
196 logf(LOG_WARN, "Inclusion failed in %s", file);
201 childp = &(*childp)->next;
205 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);