2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_attset.c,v $
7 * Revision 1.12 1999-08-27 09:40:32 adam
8 * Renamed logf function to yaz_log. Removed VC++ project files.
10 * Revision 1.11 1998/10/14 13:31:56 adam
11 * Bug fix. Bug introduced by previous commit.
13 * Revision 1.10 1998/10/13 16:09:48 adam
14 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
15 * Added support for multiple attribute set references and tagset references
16 * from an abstract syntax file.
17 * Fixed many bad logs-calls in routines that read the various
18 * specifications regarding data1 (*.abs,*.att,...) and made the messages
19 * consistent whenever possible.
20 * Added extra 'lineno' argument to function readconf_line.
22 * Revision 1.9 1998/05/18 13:07:03 adam
23 * Changed the way attribute sets are handled by the retriaval module.
24 * Extended Explain conversion / schema.
25 * Modified server and client to work with ASN.1 compiled protocol handlers.
27 * Revision 1.8 1998/02/11 11:53:35 adam
28 * Changed code so that it compiles as C++.
30 * Revision 1.7 1997/09/17 12:10:34 adam
33 * Revision 1.6 1997/09/05 09:50:56 adam
34 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
36 * Revision 1.5 1996/05/09 07:27:43 quinn
37 * Multiple local attributes values supported.
39 * Revision 1.4 1996/02/21 15:23:36 quinn
40 * Reversed fclose and return;
42 * Revision 1.3 1995/12/13 17:14:26 quinn
43 * *** empty log message ***
45 * Revision 1.2 1995/11/01 16:34:55 quinn
46 * Making data1 look for tables in data1_tabpath
48 * Revision 1.1 1995/11/01 11:56:07 quinn
49 * Added Retrieval (data management) functions en masse.
60 #include <d1_attset.h>
63 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name)
66 data1_attset_child *c;
69 for (r = s->atts; r; r = r->next)
70 if (!data1_matchstr(r->name, name))
72 for (c = s->children; c; c = c->next)
75 /* scan included sets */
76 if ((r = data1_getattbyname (dh, c->child, name)))
82 data1_attset *data1_empty_attset(data1_handle dh)
84 NMEM mem = data1_nmem_get (dh);
85 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
88 res->reference = VAL_NONE;
95 data1_attset *data1_read_attset(data1_handle dh, const char *file)
97 data1_attset *res = 0;
98 data1_attset_child **childp;
101 NMEM mem = data1_nmem_get (dh);
104 char *argv[50], line[512];
106 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
108 res = data1_empty_attset (dh);
110 childp = &res->children;
113 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
116 if (!strcmp(cmd, "att"))
121 data1_local_attribute *locals;
125 yaz_log(LOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
128 num = atoi (argv[1]);
131 if (argc == 3) /* no local attributes given */
133 locals = (data1_local_attribute *)
134 nmem_malloc(mem, sizeof(*locals));
138 else /* parse the string "local{,local}" */
141 data1_local_attribute **ap = &locals;
144 *ap = (data1_local_attribute *)
145 nmem_malloc(mem, sizeof(**ap));
146 (*ap)->local = atoi(p);
150 while ((p = strchr(p, ',')) && *(++p));
152 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
154 t->name = nmem_strdup(mem, name);
160 else if (!strcmp(cmd, "name"))
164 yaz_log(LOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
168 else if (!strcmp(cmd, "reference"))
174 yaz_log(LOG_WARN, "%s:%d: Bad # of args to reference",
179 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
181 yaz_log(LOG_WARN, "%s:%d: Unknown reference oid '%s'",
187 else if (!strcmp(cmd, "ordinal"))
189 yaz_log (LOG_WARN, "%s:%d: Directive ordinal ignored",
192 else if (!strcmp(cmd, "include"))
195 data1_attset *attset;
199 yaz_log(LOG_WARN, "%s:%d: Bad # of args to include",
205 if (!(attset = data1_get_attset (dh, name)))
207 yaz_log(LOG_WARN, "%s:%d: Include of attset %s failed",
212 *childp = (data1_attset_child *)
213 nmem_malloc (mem, sizeof(**childp));
214 (*childp)->child = attset;
216 childp = &(*childp)->next;
220 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",