X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=retrieval%2Fd1_absyn.c;h=3f2f3a0a1d4a3f3f32e31f206703a29a14ad443b;hb=bf4149c63ad2e11429e302a89f472de52b4d7ce8;hp=132213294d03acf5cf63bb42866ff647381bbea7;hpb=2004bbd9b3bbce5eb8ecc49520255b3d0bf578b9;p=yaz-moved-to-github.git diff --git a/retrieval/d1_absyn.c b/retrieval/d1_absyn.c index 1322132..3f2f3a0 100644 --- a/retrieval/d1_absyn.c +++ b/retrieval/d1_absyn.c @@ -4,7 +4,32 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_absyn.c,v $ - * Revision 1.2 1995-11-01 13:54:44 quinn + * Revision 1.10 1997-05-14 06:54:01 adam + * C++ support. + * + * Revision 1.9 1997/02/19 14:46:15 adam + * The "all" specifier only affects elements that are indexed (and not + * all elements). + * + * Revision 1.8 1997/01/02 10:47:59 quinn + * Added optional, physical ANY + * + * Revision 1.7 1996/06/10 08:56:01 quinn + * Work on Summary. + * + * Revision 1.6 1996/05/31 13:52:21 quinn + * Fixed uninitialized variable for local tags in abstract syntax. + * + * Revision 1.5 1996/05/09 07:27:43 quinn + * Multiple local attributes values supported. + * + * Revision 1.4 1996/05/01 12:45:28 quinn + * Support use of local tag names in abs file. + * + * Revision 1.3 1995/11/01 16:34:55 quinn + * Making data1 look for tables in data1_tabpath + * + * Revision 1.2 1995/11/01 13:54:44 quinn * Minor adjustments * * Revision 1.1 1995/11/01 11:56:06 quinn @@ -22,6 +47,7 @@ #include #include #include +#include #include @@ -103,13 +129,14 @@ data1_absyn *data1_read_absyn(char *file) char line[512], *r, cmd[512], args[512]; data1_absyn *res = 0; FILE *f; - data1_element **ppl[D1_MAX_NESTING]; + data1_element **ppl[D1_MAX_NESTING], *cur[D1_MAX_NESTING]; data1_esetname **esetpp; data1_maptab **maptabp; data1_marctab **marcp; + data1_termlist *all = 0; int level = 0; - if (!(f = fopen(file, "r"))) + if (!(f = yaz_path_fopen(data1_tabpath, file, "r"))) { logf(LOG_WARN|LOG_ERRNO, "%s", file); return 0; @@ -129,6 +156,7 @@ data1_absyn *data1_read_absyn(char *file) marcp = &res->marc; res->elements = 0; ppl[0] = &res->elements; + cur[0] = 0; esetpp = &res->esetnames; for (;;) @@ -149,12 +177,13 @@ data1_absyn *data1_read_absyn(char *file) *args = '\0'; if (!strcmp(cmd, "elm")) { - data1_element *new; + data1_element *new_element; int i; - char path[512], name[512], att[512], *p; + char path[512], name[512], termlists[512], *p; int type, value; + data1_termlist **tp; - if (sscanf(args, "%s %s %s", path, name, att) < 3) + if (sscanf(args, "%511s %511s %511s", path, name, termlists) < 3) { logf(LOG_WARN, "Bad # of args to elm in %s: '%s'", file, args); @@ -173,40 +202,62 @@ data1_absyn *data1_read_absyn(char *file) } if (i > level + 1) { - logf(LOG_WARN, "Bad level inc in %s in '%'", file, args); + logf(LOG_WARN, "Bad level inc in %s in '%s'", file, args); fclose(f); return 0; } level = i; - if (!(new = *ppl[level] = xmalloc(sizeof(*new)))) + if (!(new_element = cur[level] = *ppl[level] = xmalloc(sizeof(*new_element)))) abort; - new ->next = new->children = 0; - ppl[level] = &new->next; - ppl[level+1] = &new->children; + new_element->next = new_element->children = 0; + new_element->tag = 0; + new_element->termlists = 0; + new_element->parent = level ? cur[level - 1] : 0; + tp = &new_element->termlists; + ppl[level] = &new_element->next; + ppl[level+1] = &new_element->children; - if (sscanf(p, "(%d,%d)", &type, &value) < 2) + /* well-defined tag */ + if (sscanf(p, "(%d,%d)", &type, &value) == 2) { - logf(LOG_WARN, "Malformed element '%s' in %s", p, file); - fclose(f); - return 0; + if (!res->tagset) + { + logf(LOG_WARN, "No tagset loaded in %s", file); + fclose(f); + return 0; + } + if (!(new_element->tag = data1_gettagbynum(res->tagset, type, value))) + { + logf(LOG_WARN, "Couldn't find tag %s in tagset in %s", + p, file); + fclose(f); + return 0; + } } - if (!res->tagset) + /* private tag */ + else if (*p) { - logf(LOG_WARN, "No tagset loaded in %s", file); - fclose(f); - return 0; + data1_tag *nt = new_element->tag = xmalloc(sizeof(*new_element->tag)); + nt->which = DATA1T_string; + nt->value.string = xstrdup(p); + nt->names = xmalloc(sizeof(*new_element->tag->names)); + nt->names->name = nt->value.string; + nt->names->next = 0; + nt->kind = DATA1K_string; + nt->next = 0; + nt->tagset = 0; } - if (!(new->tag = data1_gettagbynum(res->tagset, type, value))) + else { - logf(LOG_WARN, "Couldn't find tag %s in tagset in %s", - p, file); + logf(LOG_WARN, "Bad element is %s", file); fclose(f); return 0; } - if (*att == '!') - strcpy(att, name); - if (*att == '-') - new->att = 0; + + /* parse termList definitions */ + p = termlists; + if (*p == '-') + new_element->termlists = 0; else { if (!res->attset) @@ -215,16 +266,98 @@ data1_absyn *data1_read_absyn(char *file) fclose(f); return 0; } - if (!(new->att = data1_getattbyname(res->attset, att))) + do + { + char attname[512], structure[512]; + int r; + + if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname, + structure))) + { + logf(LOG_WARN, "Syntax error in termlistspec in %s", + file); + fclose(f); + return 0; + } + if (*attname == '!') + strcpy(attname, name); + *tp = xmalloc(sizeof(**tp)); + if (!((*tp)->att = data1_getattbyname(res->attset, + attname))) + { + logf(LOG_WARN, "Couldn't find att '%s' in attset", + attname); + fclose(f); + return 0; + } + if (r < 2) /* is the structure qualified? */ + (*tp)->structure = DATA1S_word; + else if (!data1_matchstr(structure, "w")) + (*tp)->structure = DATA1S_word; + else if (!data1_matchstr(structure, "p")) + (*tp)->structure = DATA1S_phrase; + + (*tp)->next = 0; + tp = &(*tp)->next; + } + while ((p = strchr(p, ',')) && *(++p)); + *tp = all; /* append any ALL entries to the list */ + } + + new_element->name = xstrdup(name); + } + else if (!strcmp(cmd, "all")) + { + char *p; + data1_termlist **tp = &all; + + if (all) + { + logf(LOG_WARN, "Too many ALL declarations in %s - ignored", + file); + continue; + } + + p = args; + if (!res->attset) + { + logf(LOG_WARN, "No attset loaded in %s", file); + fclose(f); + return 0; + } + do + { + char attname[512], structure[512]; + int r; + + if (!(r = sscanf(p, "%511[^:,]:%511[^,]", attname, + structure))) + { + logf(LOG_WARN, "Syntax error in termlistspec in %s", + file); + fclose(f); + return 0; + } + *tp = xmalloc(sizeof(**tp)); + if (!((*tp)->att = data1_getattbyname(res->attset, + attname))) { - logf(LOG_WARN, "Couldn't find att '%s' in attset", att); + logf(LOG_WARN, "Couldn't find att '%s' in attset", + attname); fclose(f); return 0; } + if (r < 2) /* is the structure qualified? */ + (*tp)->structure = DATA1S_word; + else if (!data1_matchstr(structure, "w")) + (*tp)->structure = DATA1S_word; + else if (!data1_matchstr(structure, "p")) + (*tp)->structure = DATA1S_phrase; + + (*tp)->next = 0; + tp = &(*tp)->next; } - if (!(new->name = xmalloc(strlen(name)+1))) - abort(); - strcpy(new->name, name); + while ((p = strchr(p, ',')) && *(++p)); } else if (!strcmp(cmd, "name")) {