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.4 1996-02-21 15:23:36 quinn
8 * Reversed fclose and return;
10 * Revision 1.3 1995/12/13 17:14:26 quinn
11 * *** empty log message ***
13 * Revision 1.2 1995/11/01 16:34:55 quinn
14 * Making data1 look for tables in data1_tabpath
16 * Revision 1.1 1995/11/01 11:56:07 quinn
17 * Added Retrieval (data management) functions en masse.
29 #include <d1_attset.h>
33 data1_att *data1_getattbyname(data1_attset *s, char *name)
37 for (; s; s = s->next)
40 for (r = s->atts; r; r = r->next)
41 if (!data1_matchstr(r->name, name))
43 /* scan included sets */
44 if (s->children && (r = data1_getattbyname(s->children, name)))
50 data1_attset *data1_read_attset(char *file)
52 char line[512], *r, cmd[512], args[512];
53 data1_attset *res = 0, **childp;
57 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
59 logf(LOG_WARN|LOG_ERRNO, "%s", file);
63 if (!(res = xmalloc(sizeof(*res))))
66 res->reference = VAL_NONE;
69 res->children = res->next = 0;
70 childp = &res->children;
75 while ((r = fgets(line, 512, f)))
77 while (*r && isspace(*r))
87 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
89 if (!strcmp(cmd, "att"))
95 if ((rr = sscanf(args, "%d %s %d", &num, name, &local)) < 2)
97 logf(LOG_WARN, "Not enough arguments to att in '%s' in %s",
104 if (!(t = *attp = xmalloc(sizeof(*t))))
107 if (!(t->name = xmalloc(strlen(name)+1)))
109 strcpy(t->name, name);
115 else if (!strcmp(cmd, "name"))
119 if (!sscanf(args, "%s", name))
121 logf(LOG_WARN, "%s malformed name directive in %s", file);
125 if (!(res->name = xmalloc(strlen(args)+1)))
127 strcpy(res->name, name);
129 else if (!strcmp(cmd, "reference"))
133 if (!sscanf(args, "%s", name))
135 logf(LOG_WARN, "%s malformed reference directive in %s", file);
139 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
141 logf(LOG_WARN, "Unknown attset name '%s' in %s", name, file);
146 else if (!strcmp(cmd, "ordinal"))
148 if (!sscanf(args, "%d", &res->ordinal))
150 logf(LOG_WARN, "%s malformed ordinal directive in %s", file);
155 else if (!strcmp(cmd, "include"))
159 if (!sscanf(args, "%s", name))
161 logf(LOG_WARN, "%s malformed reference directive in %s", file);
165 if (!(*childp = data1_read_attset(name)))
167 logf(LOG_WARN, "Inclusion failed in %s", file);
171 childp = &(*childp)->next;
175 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);