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.10 1998-10-13 16:09:48 adam
8 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
9 * Added support for multiple attribute set references and tagset references
10 * from an abstract syntax file.
11 * Fixed many bad logs-calls in routines that read the various
12 * specifications regarding data1 (*.abs,*.att,...) and made the messages
13 * consistent whenever possible.
14 * Added extra 'lineno' argument to function readconf_line.
16 * Revision 1.9 1998/05/18 13:07:03 adam
17 * Changed the way attribute sets are handled by the retriaval module.
18 * Extended Explain conversion / schema.
19 * Modified server and client to work with ASN.1 compiled protocol handlers.
21 * Revision 1.8 1998/02/11 11:53:35 adam
22 * Changed code so that it compiles as C++.
24 * Revision 1.7 1997/09/17 12:10:34 adam
27 * Revision 1.6 1997/09/05 09:50:56 adam
28 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
30 * Revision 1.5 1996/05/09 07:27:43 quinn
31 * Multiple local attributes values supported.
33 * Revision 1.4 1996/02/21 15:23:36 quinn
34 * Reversed fclose and return;
36 * Revision 1.3 1995/12/13 17:14:26 quinn
37 * *** empty log message ***
39 * Revision 1.2 1995/11/01 16:34:55 quinn
40 * Making data1 look for tables in data1_tabpath
42 * Revision 1.1 1995/11/01 11:56:07 quinn
43 * Added Retrieval (data management) functions en masse.
54 #include <d1_attset.h>
57 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name)
60 data1_attset_child *c;
63 for (r = s->atts; r; r = r->next)
64 if (!data1_matchstr(r->name, name))
66 for (c = s->children; c; c = c->next)
69 /* scan included sets */
70 if ((r = data1_getattbyname (dh, c->child, name)))
76 data1_attset *data1_empty_attset(data1_handle dh)
78 NMEM mem = data1_nmem_get (dh);
79 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
82 res->reference = VAL_NONE;
89 data1_attset *data1_read_attset(data1_handle dh, const char *file)
91 data1_attset *res = 0;
92 data1_attset_child **childp;
95 NMEM mem = data1_nmem_get (dh);
98 char *argv[50], line[512];
100 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
102 res = data1_empty_attset (dh);
104 childp = &res->children;
107 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
110 if (!strcmp(cmd, "att"))
115 data1_local_attribute *locals;
119 logf(LOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
122 num = atoi (argv[1]);
125 if (argc == 3) /* no local attributes given */
127 locals = (data1_local_attribute *)
128 nmem_malloc(mem, sizeof(*locals));
132 else /* parse the string "local{,local}" */
135 data1_local_attribute **ap = &locals;
138 *ap = (data1_local_attribute *)
139 nmem_malloc(mem, sizeof(**ap));
140 (*ap)->local = atoi(p);
144 while ((p = strchr(p, ',')) && *(++p));
146 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
148 t->name = nmem_strdup(mem, name);
154 else if (!strcmp(cmd, "name"))
158 logf(LOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
162 else if (!strcmp(cmd, "reference"))
168 logf(LOG_WARN, "%s:%d: Bad # of args to reference",
173 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
175 logf(LOG_WARN, "%s:%d: Unknown reference oid '%s'",
181 else if (!strcmp(cmd, "ordinal"))
183 logf (LOG_WARN, "%s:%d: Directive ordinal ignored",
186 else if (!strcmp(cmd, "include"))
189 data1_attset *attset;
193 logf(LOG_WARN, "%s:%d: Bad # of args to include",
199 if (!(attset = data1_get_attset (dh, name)))
201 logf(LOG_WARN, "%s:%d: Include of attset %s failed",
206 *childp = (data1_attset_child *)
207 nmem_malloc (mem, sizeof(**childp));
208 (*childp)->child = attset;
210 childp = &(*childp)->next;
214 logf(LOG_WARN, "%s:%d: Unknown directive '%s'",