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.15 2002-04-04 20:49:46 adam
8 * New functions yaz_is_abspath, yaz_path_fopen_base
10 * Revision 1.14 1999/11/30 13:47:12 adam
11 * Improved installation. Moved header files to include/yaz.
13 * Revision 1.13 1999/10/21 12:06:29 adam
14 * Retrieval module no longer uses ctype.h - functions.
16 * Revision 1.12 1999/08/27 09:40:32 adam
17 * Renamed logf function to yaz_log. Removed VC++ project files.
19 * Revision 1.11 1998/10/14 13:31:56 adam
20 * Bug fix. Bug introduced by previous commit.
22 * Revision 1.10 1998/10/13 16:09:48 adam
23 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
24 * Added support for multiple attribute set references and tagset references
25 * from an abstract syntax file.
26 * Fixed many bad logs-calls in routines that read the various
27 * specifications regarding data1 (*.abs,*.att,...) and made the messages
28 * consistent whenever possible.
29 * Added extra 'lineno' argument to function readconf_line.
31 * Revision 1.9 1998/05/18 13:07:03 adam
32 * Changed the way attribute sets are handled by the retriaval module.
33 * Extended Explain conversion / schema.
34 * Modified server and client to work with ASN.1 compiled protocol handlers.
36 * Revision 1.8 1998/02/11 11:53:35 adam
37 * Changed code so that it compiles as C++.
39 * Revision 1.7 1997/09/17 12:10:34 adam
42 * Revision 1.6 1997/09/05 09:50:56 adam
43 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
45 * Revision 1.5 1996/05/09 07:27:43 quinn
46 * Multiple local attributes values supported.
48 * Revision 1.4 1996/02/21 15:23:36 quinn
49 * Reversed fclose and return;
51 * Revision 1.3 1995/12/13 17:14:26 quinn
52 * *** empty log message ***
54 * Revision 1.2 1995/11/01 16:34:55 quinn
55 * Making data1 look for tables in data1_tabpath
57 * Revision 1.1 1995/11/01 11:56:07 quinn
58 * Added Retrieval (data management) functions en masse.
68 #include <yaz/d1_attset.h>
69 #include <yaz/data1.h>
71 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name)
74 data1_attset_child *c;
77 for (r = s->atts; r; r = r->next)
78 if (!data1_matchstr(r->name, name))
80 for (c = s->children; c; c = c->next)
83 /* scan included sets */
84 if ((r = data1_getattbyname (dh, c->child, name)))
90 data1_attset *data1_empty_attset(data1_handle dh)
92 NMEM mem = data1_nmem_get (dh);
93 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
96 res->reference = VAL_NONE;
103 data1_attset *data1_read_attset(data1_handle dh, const char *file)
105 data1_attset *res = 0;
106 data1_attset_child **childp;
109 NMEM mem = data1_nmem_get (dh);
112 char *argv[50], line[512];
114 if (!(f = data1_path_fopen(dh, file, "r")))
116 res = data1_empty_attset (dh);
118 childp = &res->children;
121 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
124 if (!strcmp(cmd, "att"))
129 data1_local_attribute *locals;
133 yaz_log(LOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
136 num = atoi (argv[1]);
139 if (argc == 3) /* no local attributes given */
141 locals = (data1_local_attribute *)
142 nmem_malloc(mem, sizeof(*locals));
146 else /* parse the string "local{,local}" */
149 data1_local_attribute **ap = &locals;
152 *ap = (data1_local_attribute *)
153 nmem_malloc(mem, sizeof(**ap));
154 (*ap)->local = atoi(p);
158 while ((p = strchr(p, ',')) && *(++p));
160 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
162 t->name = nmem_strdup(mem, name);
168 else if (!strcmp(cmd, "name"))
172 yaz_log(LOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
176 else if (!strcmp(cmd, "reference"))
182 yaz_log(LOG_WARN, "%s:%d: Bad # of args to reference",
187 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
189 yaz_log(LOG_WARN, "%s:%d: Unknown reference oid '%s'",
195 else if (!strcmp(cmd, "ordinal"))
197 yaz_log (LOG_WARN, "%s:%d: Directive ordinal ignored",
200 else if (!strcmp(cmd, "include"))
203 data1_attset *attset;
207 yaz_log(LOG_WARN, "%s:%d: Bad # of args to include",
213 if (!(attset = data1_get_attset (dh, name)))
215 yaz_log(LOG_WARN, "%s:%d: Include of attset %s failed",
220 *childp = (data1_attset_child *)
221 nmem_malloc (mem, sizeof(**childp));
222 (*childp)->child = attset;
224 childp = &(*childp)->next;
228 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",