2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_attset.c,v $
7 * Revision 1.6 1997-09-05 09:50:56 adam
8 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
10 * Revision 1.5 1996/05/09 07:27:43 quinn
11 * Multiple local attributes values supported.
13 * Revision 1.4 1996/02/21 15:23:36 quinn
14 * Reversed fclose and return;
16 * Revision 1.3 1995/12/13 17:14:26 quinn
17 * *** empty log message ***
19 * Revision 1.2 1995/11/01 16:34:55 quinn
20 * Making data1 look for tables in data1_tabpath
22 * Revision 1.1 1995/11/01 11:56:07 quinn
23 * Added Retrieval (data management) functions en masse.
35 #include <d1_attset.h>
39 data1_att *data1_getattbyname(data1_attset *s, char *name)
43 for (; s; s = s->next)
46 for (r = s->atts; r; r = r->next)
47 if (!data1_matchstr(r->name, name))
49 /* scan included sets */
50 if (s->children && (r = data1_getattbyname(s->children, name)))
56 data1_attset *data1_read_attset(char *file)
58 char line[512], *r, cmd[512], args[512];
59 data1_attset *res = 0, **childp;
63 if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r")))
65 logf(LOG_WARN|LOG_ERRNO, "%s", file);
69 if (!(res = xmalloc(sizeof(*res))))
72 res->reference = VAL_NONE;
75 res->children = res->next = 0;
76 childp = &res->children;
81 while ((r = fgets(line, 512, f)))
83 while (*r && isspace(*r))
93 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
95 if (!strcmp(cmd, "att"))
98 char name[512], localstr[512];
100 data1_local_attribute *locals;
102 if ((rr = sscanf(args, "%511d %s %511s", &num, name, localstr)) < 2)
104 logf(LOG_WARN, "Not enough arguments to att in '%s' in %s",
109 if (rr < 3) /* no local attributes given */
111 locals = xmalloc(sizeof(*locals));
115 else /* parse the string "local{,local}" */
118 data1_local_attribute **ap = &locals;
121 *ap = xmalloc(sizeof(**ap));
122 (*ap)->local = atoi(p);
126 while ((p = strchr(p, ',')) && *(++p));
128 if (!(t = *attp = xmalloc(sizeof(*t))))
131 if (!(t->name = xmalloc(strlen(name)+1)))
133 strcpy(t->name, name);
139 else if (!strcmp(cmd, "name"))
143 if (!sscanf(args, "%s", name))
145 logf(LOG_WARN, "%s malformed name directive in %s", file);
149 if (!(res->name = xmalloc(strlen(args)+1)))
151 strcpy(res->name, name);
153 else if (!strcmp(cmd, "reference"))
157 if (!sscanf(args, "%s", name))
159 logf(LOG_WARN, "%s malformed reference directive in %s", file);
163 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
165 logf(LOG_WARN, "Unknown attset name '%s' in %s", name, file);
170 else if (!strcmp(cmd, "ordinal"))
172 if (!sscanf(args, "%d", &res->ordinal))
174 logf(LOG_WARN, "%s malformed ordinal directive in %s", file);
179 else if (!strcmp(cmd, "include"))
183 if (!sscanf(args, "%s", name))
185 logf(LOG_WARN, "%s malformed reference directive in %s", file);
189 if (!(*childp = data1_read_attset(name)))
191 logf(LOG_WARN, "Inclusion failed in %s", file);
195 childp = &(*childp)->next;
199 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);