1 | /*
|
---|
2 | * Copyright (c) 1995-1999, Index Data.
|
---|
3 | * See the file LICENSE for details.
|
---|
4 | * Sebastian Hammer, Adam Dickmeiss
|
---|
5 | *
|
---|
6 | * $Log$
|
---|
7 | * Revision 1.1 2000/08/03 03:11:38 johnmcp
|
---|
8 | * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
|
---|
9 | *
|
---|
10 | * Revision 1.10 1999/11/30 13:47:12 adam
|
---|
11 | * Improved installation. Moved header files to include/yaz.
|
---|
12 | *
|
---|
13 | * Revision 1.9 1999/08/27 09:40:32 adam
|
---|
14 | * Renamed logf function to yaz_log. Removed VC++ project files.
|
---|
15 | *
|
---|
16 | * Revision 1.8 1998/10/13 16:09:54 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.
|
---|
24 | *
|
---|
25 | * Revision 1.7 1998/02/11 11:53:35 adam
|
---|
26 | * Changed code so that it compiles as C++.
|
---|
27 | *
|
---|
28 | * Revision 1.6 1997/09/17 12:10:39 adam
|
---|
29 | * YAZ version 1.4.
|
---|
30 | *
|
---|
31 | * Revision 1.5 1997/09/05 09:50:58 adam
|
---|
32 | * Removed global data1_tabpath - uses data1_get_tabpath() instead.
|
---|
33 | *
|
---|
34 | * Revision 1.4 1997/05/14 06:54:04 adam
|
---|
35 | * C++ support.
|
---|
36 | *
|
---|
37 | * Revision 1.3 1995/11/01 16:34:58 quinn
|
---|
38 | * Making data1 look for tables in data1_tabpath
|
---|
39 | *
|
---|
40 | * Revision 1.2 1995/11/01 13:54:50 quinn
|
---|
41 | * Minor adjustments
|
---|
42 | *
|
---|
43 | * Revision 1.1 1995/11/01 11:56:09 quinn
|
---|
44 | * Added Retrieval (data management) functions en masse.
|
---|
45 | *
|
---|
46 | *
|
---|
47 | */
|
---|
48 |
|
---|
49 | #include <string.h>
|
---|
50 | #include <stdlib.h>
|
---|
51 |
|
---|
52 | #include <yaz/oid.h>
|
---|
53 | #include <yaz/log.h>
|
---|
54 | #include <yaz/data1.h>
|
---|
55 |
|
---|
56 | data1_vartype *data1_getvartypebyct (data1_handle dh, data1_varset *set,
|
---|
57 | char *zclass, char *type)
|
---|
58 | {
|
---|
59 | data1_varclass *c;
|
---|
60 | data1_vartype *t;
|
---|
61 |
|
---|
62 | for (c = set->classes; c; c = c->next)
|
---|
63 | if (!data1_matchstr(c->name, zclass))
|
---|
64 | {
|
---|
65 | for (t = c->types; t; t = t->next)
|
---|
66 | if (!data1_matchstr(t->name, type))
|
---|
67 | return t;
|
---|
68 | yaz_log(LOG_WARN, "Unknown variant type %s in class %s",
|
---|
69 | type, zclass);
|
---|
70 | return 0;
|
---|
71 | }
|
---|
72 | yaz_log(LOG_WARN, "Unknown variant class %s", zclass);
|
---|
73 | return 0;
|
---|
74 | }
|
---|
75 |
|
---|
76 | data1_varset *data1_read_varset (data1_handle dh, const char *file)
|
---|
77 | {
|
---|
78 | NMEM mem = data1_nmem_get (dh);
|
---|
79 | data1_varset *res = (data1_varset *)nmem_malloc(mem, sizeof(*res));
|
---|
80 | data1_varclass **classp = &res->classes, *zclass = 0;
|
---|
81 | data1_vartype **typep = 0;
|
---|
82 | FILE *f;
|
---|
83 | int lineno = 0;
|
---|
84 | int argc;
|
---|
85 | char *argv[50],line[512];
|
---|
86 |
|
---|
87 | res->name = 0;
|
---|
88 | res->reference = VAL_NONE;
|
---|
89 | res->classes = 0;
|
---|
90 |
|
---|
91 | if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
|
---|
92 | {
|
---|
93 | yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
|
---|
94 | return 0;
|
---|
95 | }
|
---|
96 | while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
|
---|
97 | if (!strcmp(argv[0], "class"))
|
---|
98 | {
|
---|
99 | data1_varclass *r;
|
---|
100 |
|
---|
101 | if (argc != 3)
|
---|
102 | {
|
---|
103 | yaz_log(LOG_WARN, "%s:%d: Bad # or args to class",
|
---|
104 | file, lineno);
|
---|
105 | continue;
|
---|
106 | }
|
---|
107 | *classp = r = zclass = (data1_varclass *)
|
---|
108 | nmem_malloc(mem, sizeof(*r));
|
---|
109 | r->set = res;
|
---|
110 | r->zclass = atoi(argv[1]);
|
---|
111 | r->name = nmem_strdup(mem, argv[2]);
|
---|
112 | r->types = 0;
|
---|
113 | typep = &r->types;
|
---|
114 | r->next = 0;
|
---|
115 | classp = &r->next;
|
---|
116 | }
|
---|
117 | else if (!strcmp(argv[0], "type"))
|
---|
118 | {
|
---|
119 | data1_vartype *r;
|
---|
120 |
|
---|
121 | if (!typep)
|
---|
122 | {
|
---|
123 | yaz_log(LOG_WARN, "%s:%d: Directive class must precede type",
|
---|
124 | file, lineno);
|
---|
125 | continue;
|
---|
126 | }
|
---|
127 | if (argc != 4)
|
---|
128 | {
|
---|
129 | yaz_log(LOG_WARN, "%s:%d: Bad # or args to type",
|
---|
130 | file, lineno);
|
---|
131 | continue;
|
---|
132 | }
|
---|
133 | *typep = r = (data1_vartype *)nmem_malloc(mem, sizeof(*r));
|
---|
134 | r->name = nmem_strdup(mem, argv[2]);
|
---|
135 | r->zclass = zclass;
|
---|
136 | r->type = atoi(argv[1]);
|
---|
137 | if (!(r->datatype = data1_maptype (dh, argv[3])))
|
---|
138 | {
|
---|
139 | yaz_log(LOG_WARN, "%s:%d: Unknown datatype '%s'",
|
---|
140 | file, lineno, argv[3]);
|
---|
141 | fclose(f);
|
---|
142 | return 0;
|
---|
143 | }
|
---|
144 | r->next = 0;
|
---|
145 | typep = &r->next;
|
---|
146 | }
|
---|
147 | else if (!strcmp(argv[0], "name"))
|
---|
148 | {
|
---|
149 | if (argc != 2)
|
---|
150 | {
|
---|
151 | yaz_log(LOG_WARN, "%s:%d: Bad # args for name",
|
---|
152 | file, lineno);
|
---|
153 | continue;
|
---|
154 | }
|
---|
155 | res->name = nmem_strdup(mem, argv[1]);
|
---|
156 | }
|
---|
157 | else if (!strcmp(argv[0], "reference"))
|
---|
158 | {
|
---|
159 | if (argc != 2)
|
---|
160 | {
|
---|
161 | yaz_log(LOG_WARN, "%s:%d: Bad # args for reference",
|
---|
162 | file, lineno);
|
---|
163 | continue;
|
---|
164 | }
|
---|
165 | if ((res->reference = oid_getvalbyname(argv[1])) == VAL_NONE)
|
---|
166 | {
|
---|
167 | yaz_log(LOG_WARN, "%s:%d: Unknown reference '%s'",
|
---|
168 | file, lineno, argv[1]);
|
---|
169 | continue;
|
---|
170 | }
|
---|
171 | }
|
---|
172 | else
|
---|
173 | yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",
|
---|
174 | file, lineno, argv[0]);
|
---|
175 |
|
---|
176 | fclose(f);
|
---|
177 | return res;
|
---|
178 | }
|
---|