X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=retrieval%2Fd1_attset.c;h=b747942e0d4568e5a3150bfe6e3927ff3b966885;hb=7674cd40af86e353235cb1b509f4b4687167cdf2;hp=e179415b780c8efdcad9e484dc2fe44ae4bdb9bc;hpb=01555b079443406950c519ad757b36eb2bc38657;p=yaz-moved-to-github.git diff --git a/retrieval/d1_attset.c b/retrieval/d1_attset.c index e179415..b747942 100644 --- a/retrieval/d1_attset.c +++ b/retrieval/d1_attset.c @@ -1,10 +1,19 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1997, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_attset.c,v $ - * Revision 1.4 1996-02-21 15:23:36 quinn + * Revision 1.7 1997-09-17 12:10:34 adam + * YAZ version 1.4. + * + * Revision 1.6 1997/09/05 09:50:56 adam + * Removed global data1_tabpath - uses data1_get_tabpath() instead. + * + * Revision 1.5 1996/05/09 07:27:43 quinn + * Multiple local attributes values supported. + * + * Revision 1.4 1996/02/21 15:23:36 quinn * Reversed fclose and return; * * Revision 1.3 1995/12/13 17:14:26 quinn @@ -24,13 +33,12 @@ #include #include -#include #include #include #include #include -data1_att *data1_getattbyname(data1_attset *s, char *name) +data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name) { data1_att *r; @@ -41,27 +49,27 @@ data1_att *data1_getattbyname(data1_attset *s, char *name) if (!data1_matchstr(r->name, name)) return r; /* scan included sets */ - if (s->children && (r = data1_getattbyname(s->children, name))) + if (s->children && (r = data1_getattbyname (dh, s->children, name))) return r; } return 0; } -data1_attset *data1_read_attset(char *file) +data1_attset *data1_read_attset(data1_handle dh, char *file) { char line[512], *r, cmd[512], args[512]; data1_attset *res = 0, **childp; data1_att **attp; FILE *f; + NMEM mem = data1_nmem_get (dh); - if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) + if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; } - if (!(res = xmalloc(sizeof(*res)))) - abort(); + res = nmem_malloc(mem, sizeof(*res)); res->name = 0; res->reference = VAL_NONE; res->ordinal = -1; @@ -88,27 +96,42 @@ data1_attset *data1_read_attset(char *file) *args = '\0'; if (!strcmp(cmd, "att")) { - int num, local, rr; - char name[512]; + int num, rr; + char name[512], localstr[512]; data1_att *t; + data1_local_attribute *locals; - if ((rr = sscanf(args, "%d %s %d", &num, name, &local)) < 2) + if ((rr = sscanf(args, "%511d %s %511s", &num, name, localstr)) < 2) { logf(LOG_WARN, "Not enough arguments to att in '%s' in %s", args, file); fclose(f); return 0; } - if (rr < 3) - local = num; - if (!(t = *attp = xmalloc(sizeof(*t)))) - abort(); + if (rr < 3) /* no local attributes given */ + { + locals = nmem_malloc(mem, sizeof(*locals)); + locals->local = num; + locals->next = 0; + } + else /* parse the string "local{,local}" */ + { + char *p = localstr; + data1_local_attribute **ap = &locals; + do + { + *ap = nmem_malloc(mem, sizeof(**ap)); + (*ap)->local = atoi(p); + (*ap)->next = 0; + ap = &(*ap)->next; + } + while ((p = strchr(p, ',')) && *(++p)); + } + t = *attp = nmem_malloc(mem, sizeof(*t)); t->parent = res; - if (!(t->name = xmalloc(strlen(name)+1))) - abort(); - strcpy(t->name, name); + t->name = nmem_strdup(mem, name); t->value = num; - t->local = local; + t->locals = locals; t->next = 0; attp = &t->next; } @@ -122,9 +145,7 @@ data1_attset *data1_read_attset(char *file) fclose(f); return 0; } - if (!(res->name = xmalloc(strlen(args)+1))) - abort(); - strcpy(res->name, name); + res->name = nmem_strdup(mem, args); } else if (!strcmp(cmd, "reference")) { @@ -162,7 +183,7 @@ data1_attset *data1_read_attset(char *file) fclose(f); return 0; } - if (!(*childp = data1_read_attset(name))) + if (!(*childp = data1_read_attset (dh, name))) { logf(LOG_WARN, "Inclusion failed in %s", file); fclose(f);