X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=data1%2Fd1_absyn.c;h=2879df402370a5bda9800eaa10bbfc9861c065a5;hb=f4a6bacdb4ec6a7ba64635b1d568a60aa1648426;hp=dfe048473b5b5e3cba9518b65b2c526bc01c596f;hpb=9be04e6cf1e848fcc4f065a7407e489684aaaf61;p=idzebra-moved-to-github.git diff --git a/data1/d1_absyn.c b/data1/d1_absyn.c index dfe0484..2879df4 100644 --- a/data1/d1_absyn.c +++ b/data1/d1_absyn.c @@ -1,5 +1,5 @@ -/* $Id: d1_absyn.c,v 1.22 2006-02-06 23:22:28 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: d1_absyn.c,v 1.26 2006-06-08 10:33:19 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -28,6 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include #include #include @@ -165,7 +166,7 @@ data1_absyn *data1_absyn_search (data1_handle dh, const char *name) return p->absyn; p = p->next; } - return NULL; + return 0; } /* *ostrich* We need to destroy DFAs, in xp_element (xelm) definitions @@ -240,7 +241,7 @@ data1_attset *data1_attset_search_name (data1_handle dh, const char *name) return p->attset; p = p->next; } - return NULL; + return 0; } data1_attset *data1_attset_search_id (data1_handle dh, int id) @@ -253,7 +254,7 @@ data1_attset *data1_attset_search_id (data1_handle dh, int id) return p->attset; p = p->next; } - return NULL; + return 0; } data1_attset *data1_attset_add (data1_handle dh, const char *name) @@ -443,7 +444,6 @@ static const char * mk_xpath_regexp (data1_handle dh, const char *expr) { const char *p = expr; int abs = 1; - int i; int e = 0; char *stack[32]; char *res_p, *res = 0; @@ -491,9 +491,9 @@ static const char * mk_xpath_regexp (data1_handle dh, const char *expr) res_p = res = nmem_malloc(data1_nmem_get(dh), res_size + 10); if (stack[e-1][0] == '@') /* path/@attr spec (leaf is attribute) */ - sprintf(res_p, "/"); + strcpy(res_p, "/"); else - sprintf(res_p, "[^@]*/"); /* path .. (index all cdata below it) */ + strcpy(res_p, "[^@]*/"); /* path .. (index all cdata below it) */ res_p = res_p + strlen(res_p); while (--e >= 0) { sprintf(res_p, "%s/", stack[e]); @@ -510,17 +510,11 @@ static const char * mk_xpath_regexp (data1_handle dh, const char *expr) return res; } -/* *ostrich* - - added arg xpelement... when called from xelm context, it's 1, saying - that ! means xpath, not element name as attribute name... - - pop, 2002-12-13 - */ -static int parse_termlists (data1_handle dh, data1_termlist ***tpp, - char *cp, const char *file, int lineno, - const char *element_name, data1_absyn *res, - int xpelement) +static int parse_termlists(data1_handle dh, data1_termlist ***tpp, + char *cp, const char *file, int lineno, + const char *element_name, data1_absyn *res, + int xpelement, + data1_attset *attset) { data1_termlist **tp = *tpp; while(1) @@ -571,27 +565,24 @@ static int parse_termlists (data1_handle dh, data1_termlist ***tpp, nmem_malloc(data1_nmem_get(dh), sizeof(**tp)); (*tp)->next = 0; -#if NATTR - (*tp)->index_name = nmem_strdup(data1_nmem_get(dh), element_name); - if (*attname == '!' && xpelement) - (*tp)->index_name = 0; -#else - if (!xpelement) { - if (*attname == '!') + if (*attname == '!') + { + if (!xpelement && element_name) strcpy(attname, element_name); - } - if (!((*tp)->att = data1_getattbyname(dh, res->attset, attname))) - { - if ((!xpelement) || (*attname != '!')) { - yaz_log(YLOG_WARN, - "%s:%d: Couldn't find att '%s' in attset", - file, lineno, attname); - return -1; - } else { - (*tp)->att = 0; + else if (xpelement) + strcpy(attname, ZEBRA_XPATH_CDATA); + } + if (attset) + { + if (!data1_getattbyname(dh, attset, attname)) + { + yaz_log(YLOG_WARN, "Index '%s' not found in attset(s)", + attname); } - } -#endif + } + + (*tp)->index_name = nmem_strdup(data1_nmem_get(dh), attname); + assert (*(*tp)->index_name != '!'); if (r == 2 && (source = strchr(structure, ':'))) *source++ = '\0'; /* cut off structure .. */ else @@ -705,6 +696,8 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, { data1_sub_elements *cur_elements = NULL; data1_xpelement *cur_xpelement = NULL; + data1_attset *attset_list = data1_empty_attset(dh); + data1_attset_child **attset_childp = &attset_list->children; data1_absyn *res = 0; FILE *f; @@ -713,7 +706,6 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, data1_maptab **maptabp; data1_marctab **marcp; data1_termlist *all = 0; - data1_attset_child **attset_childp; data1_tagset **tagset_childp; struct data1_systag **systagsp; int level = 0; @@ -723,7 +715,6 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, if (!(f = data1_path_fopen(dh, file, "r"))) { - yaz_log(YLOG_WARN|YLOG_ERRNO, "Couldn't open %s", file); if (file_must_exist) return 0; } @@ -738,9 +729,6 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, systagsp = &res->systags; tagset_childp = &res->tagset; - res->attset = data1_empty_attset (dh); - attset_childp = &res->attset->children; - res->varset = 0; res->esetnames = 0; esetpp = &res->esetnames; @@ -751,7 +739,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, res->sub_elements = NULL; res->main_elements = NULL; res->xp_elements = NULL; - + while (f && (argc = read_absyn_line(f, &lineno, line, 512, argv, 50))) { char *cmd = *argv; @@ -860,9 +848,8 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, p = termlists; if (*p != '-') { - assert (res->attset); - - if (parse_termlists (dh, &tp, p, file, lineno, name, res, 0)) + if (parse_termlists (dh, &tp, p, file, lineno, name, res, 0, + attset_list)) { fclose (f); return 0; @@ -950,10 +937,8 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, p = termlists; if (*p != '-') { - assert (res->attset); - if (parse_termlists (dh, &tp, p, file, lineno, - xpath_expr, res, 1)) + xpath_expr, res, 1, attset_list)) { fclose (f); return 0; @@ -1016,7 +1001,8 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, file, lineno); continue; } - if (parse_termlists (dh, &tp, argv[1], file, lineno, 0, res, 0)) + if (parse_termlists (dh, &tp, argv[1], file, lineno, 0, res, 0, + attset_list)) { fclose (f); return 0; @@ -1052,31 +1038,27 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, } else if (!strcmp(cmd, "attset")) { -#if NATTR - yaz_log(YLOG_WARN, "%s:%d: attset obsolete", file, lineno); -#else - char *name; - data1_attset *attset; - - if (argc != 2) - { - yaz_log(YLOG_WARN, "%s:%d: Bad # of args to attset", - file, lineno); - continue; - } - name = argv[1]; - if (!(attset = data1_get_attset (dh, name))) - { - yaz_log(YLOG_WARN, "%s:%d: Couldn't find attset %s", - file, lineno, name); - continue; - } - *attset_childp = (data1_attset_child *) - nmem_malloc (data1_nmem_get(dh), sizeof(**attset_childp)); - (*attset_childp)->child = attset; - (*attset_childp)->next = 0; - attset_childp = &(*attset_childp)->next; -#endif + char *name; + data1_attset *attset; + + if (argc != 2) + { + yaz_log(YLOG_WARN, "%s:%d: Bad # of args to attset", + file, lineno); + continue; + } + name = argv[1]; + if (!(attset = data1_get_attset (dh, name))) + { + yaz_log(YLOG_WARN, "%s:%d: Couldn't find attset %s", + file, lineno, name); + continue; + } + *attset_childp = (data1_attset_child *) + nmem_malloc (data1_nmem_get(dh), sizeof(**attset_childp)); + (*attset_childp)->child = attset; + (*attset_childp)->next = 0; + attset_childp = &(*attset_childp)->next; } else if (!strcmp(cmd, "tagset")) { @@ -1225,6 +1207,13 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file, fix_element_ref (dh, res, cur_elements->elements); } *systagsp = 0; - yaz_log(YLOG_DEBUG, "%s: data1_read_absyn end", file); return res; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +