2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_varset.c,v $
7 * Revision 1.10 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.9 1999/08/27 09:40:32 adam
11 * Renamed logf function to yaz_log. Removed VC++ project files.
13 * Revision 1.8 1998/10/13 16:09:54 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.7 1998/02/11 11:53:35 adam
23 * Changed code so that it compiles as C++.
25 * Revision 1.6 1997/09/17 12:10:39 adam
28 * Revision 1.5 1997/09/05 09:50:58 adam
29 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
31 * Revision 1.4 1997/05/14 06:54:04 adam
34 * Revision 1.3 1995/11/01 16:34:58 quinn
35 * Making data1 look for tables in data1_tabpath
37 * Revision 1.2 1995/11/01 13:54:50 quinn
40 * Revision 1.1 1995/11/01 11:56:09 quinn
41 * Added Retrieval (data management) functions en masse.
51 #include <yaz/data1.h>
53 data1_vartype *data1_getvartypebyct (data1_handle dh, data1_varset *set,
54 char *zclass, char *type)
59 for (c = set->classes; c; c = c->next)
60 if (!data1_matchstr(c->name, zclass))
62 for (t = c->types; t; t = t->next)
63 if (!data1_matchstr(t->name, type))
65 yaz_log(LOG_WARN, "Unknown variant type %s in class %s",
69 yaz_log(LOG_WARN, "Unknown variant class %s", zclass);
73 data1_varset *data1_read_varset (data1_handle dh, const char *file)
75 NMEM mem = data1_nmem_get (dh);
76 data1_varset *res = (data1_varset *)nmem_malloc(mem, sizeof(*res));
77 data1_varclass **classp = &res->classes, *zclass = 0;
78 data1_vartype **typep = 0;
82 char *argv[50],line[512];
85 res->reference = VAL_NONE;
88 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
90 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
93 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
94 if (!strcmp(argv[0], "class"))
100 yaz_log(LOG_WARN, "%s:%d: Bad # or args to class",
104 *classp = r = zclass = (data1_varclass *)
105 nmem_malloc(mem, sizeof(*r));
107 r->zclass = atoi(argv[1]);
108 r->name = nmem_strdup(mem, argv[2]);
114 else if (!strcmp(argv[0], "type"))
120 yaz_log(LOG_WARN, "%s:%d: Directive class must precede type",
126 yaz_log(LOG_WARN, "%s:%d: Bad # or args to type",
130 *typep = r = (data1_vartype *)nmem_malloc(mem, sizeof(*r));
131 r->name = nmem_strdup(mem, argv[2]);
133 r->type = atoi(argv[1]);
134 if (!(r->datatype = data1_maptype (dh, argv[3])))
136 yaz_log(LOG_WARN, "%s:%d: Unknown datatype '%s'",
137 file, lineno, argv[3]);
144 else if (!strcmp(argv[0], "name"))
148 yaz_log(LOG_WARN, "%s:%d: Bad # args for name",
152 res->name = nmem_strdup(mem, argv[1]);
154 else if (!strcmp(argv[0], "reference"))
158 yaz_log(LOG_WARN, "%s:%d: Bad # args for reference",
162 if ((res->reference = oid_getvalbyname(argv[1])) == VAL_NONE)
164 yaz_log(LOG_WARN, "%s:%d: Unknown reference '%s'",
165 file, lineno, argv[1]);
170 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",
171 file, lineno, argv[0]);