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.13 1999-10-21 12:06:29 adam
8 * Retrieval module no longer uses ctype.h - functions.
10 * Revision 1.12 1999/08/27 09:40:32 adam
11 * Renamed logf function to yaz_log. Removed VC++ project files.
13 * Revision 1.11 1998/10/14 13:31:56 adam
14 * Bug fix. Bug introduced by previous commit.
16 * Revision 1.10 1998/10/13 16:09:48 adam
17 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
18 * Added support for multiple attribute set references and tagset references
19 * from an abstract syntax file.
20 * Fixed many bad logs-calls in routines that read the various
21 * specifications regarding data1 (*.abs,*.att,...) and made the messages
22 * consistent whenever possible.
23 * Added extra 'lineno' argument to function readconf_line.
25 * Revision 1.9 1998/05/18 13:07:03 adam
26 * Changed the way attribute sets are handled by the retriaval module.
27 * Extended Explain conversion / schema.
28 * Modified server and client to work with ASN.1 compiled protocol handlers.
30 * Revision 1.8 1998/02/11 11:53:35 adam
31 * Changed code so that it compiles as C++.
33 * Revision 1.7 1997/09/17 12:10:34 adam
36 * Revision 1.6 1997/09/05 09:50:56 adam
37 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
39 * Revision 1.5 1996/05/09 07:27:43 quinn
40 * Multiple local attributes values supported.
42 * Revision 1.4 1996/02/21 15:23:36 quinn
43 * Reversed fclose and return;
45 * Revision 1.3 1995/12/13 17:14:26 quinn
46 * *** empty log message ***
48 * Revision 1.2 1995/11/01 16:34:55 quinn
49 * Making data1 look for tables in data1_tabpath
51 * Revision 1.1 1995/11/01 11:56:07 quinn
52 * Added Retrieval (data management) functions en masse.
62 #include <d1_attset.h>
65 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name)
68 data1_attset_child *c;
71 for (r = s->atts; r; r = r->next)
72 if (!data1_matchstr(r->name, name))
74 for (c = s->children; c; c = c->next)
77 /* scan included sets */
78 if ((r = data1_getattbyname (dh, c->child, name)))
84 data1_attset *data1_empty_attset(data1_handle dh)
86 NMEM mem = data1_nmem_get (dh);
87 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
90 res->reference = VAL_NONE;
97 data1_attset *data1_read_attset(data1_handle dh, const char *file)
99 data1_attset *res = 0;
100 data1_attset_child **childp;
103 NMEM mem = data1_nmem_get (dh);
106 char *argv[50], line[512];
108 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
110 res = data1_empty_attset (dh);
112 childp = &res->children;
115 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
118 if (!strcmp(cmd, "att"))
123 data1_local_attribute *locals;
127 yaz_log(LOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
130 num = atoi (argv[1]);
133 if (argc == 3) /* no local attributes given */
135 locals = (data1_local_attribute *)
136 nmem_malloc(mem, sizeof(*locals));
140 else /* parse the string "local{,local}" */
143 data1_local_attribute **ap = &locals;
146 *ap = (data1_local_attribute *)
147 nmem_malloc(mem, sizeof(**ap));
148 (*ap)->local = atoi(p);
152 while ((p = strchr(p, ',')) && *(++p));
154 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
156 t->name = nmem_strdup(mem, name);
162 else if (!strcmp(cmd, "name"))
166 yaz_log(LOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
170 else if (!strcmp(cmd, "reference"))
176 yaz_log(LOG_WARN, "%s:%d: Bad # of args to reference",
181 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
183 yaz_log(LOG_WARN, "%s:%d: Unknown reference oid '%s'",
189 else if (!strcmp(cmd, "ordinal"))
191 yaz_log (LOG_WARN, "%s:%d: Directive ordinal ignored",
194 else if (!strcmp(cmd, "include"))
197 data1_attset *attset;
201 yaz_log(LOG_WARN, "%s:%d: Bad # of args to include",
207 if (!(attset = data1_get_attset (dh, name)))
209 yaz_log(LOG_WARN, "%s:%d: Include of attset %s failed",
214 *childp = (data1_attset_child *)
215 nmem_malloc (mem, sizeof(**childp));
216 (*childp)->child = attset;
218 childp = &(*childp)->next;
222 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",