-/* $Id: d1_absyn.c,v 1.17 2005-01-04 16:28:34 quinn Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
- Index Data Aps
+/* $Id: d1_absyn.c,v 1.29 2006-09-28 18:38:44 adam Exp $
+ Copyright (C) 1995-2006
+ Index Data ApS
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
data1_xpelement *xpe = abs->xp_elements;
while (xpe) {
yaz_log (YLOG_DEBUG,"Destroy xp element %s",xpe->xpath_expr);
data1_xpelement *xpe = abs->xp_elements;
while (xpe) {
yaz_log (YLOG_DEBUG,"Destroy xp element %s",xpe->xpath_expr);
-data1_absyn *data1_absyn_add (data1_handle dh, const char *name)
+static data1_absyn *data1_read_absyn(data1_handle dh, const char *file,
+ enum DATA1_XPATH_INDEXING en);
+
+static data1_absyn *data1_absyn_add(data1_handle dh, const char *name,
+ enum DATA1_XPATH_INDEXING en)
data1_absyn_cache p = (data1_absyn_cache)nmem_malloc (mem, sizeof(*p));
data1_absyn_cache *pp = data1_absyn_cache_get (dh);
data1_absyn_cache p = (data1_absyn_cache)nmem_malloc (mem, sizeof(*p));
data1_absyn_cache *pp = data1_absyn_cache_get (dh);
- sprintf(fname, "%s.abs", name);
- p->absyn = data1_read_absyn (dh, fname, 0);
- p->name = nmem_strdup (mem, name);
+ sprintf(fname, "%.500s.abs", name);
+ p->absyn = data1_read_absyn(dh, fname, en);
+ p->name = nmem_strdup(mem, name);
-data1_absyn *data1_get_absyn (data1_handle dh, const char *name)
+data1_absyn *data1_get_absyn (data1_handle dh, const char *name,
+ enum DATA1_XPATH_INDEXING en)
-
- strcpy (aname, name);
- sprintf(fname, "%s.att", name);
- attset = data1_read_attset (dh, fname);
- if (!attset)
- {
- char *cp;
- attset = data1_read_attset (dh, name);
- if (attset && (cp = strrchr (aname, '.')))
- *cp = '\0';
- }
+
+ attset = data1_read_attset (dh, name);
nmem_malloc (mem, sizeof(*p));
data1_attset_cache *pp = data1_attset_cache_get (dh);
nmem_malloc (mem, sizeof(*p));
data1_attset_cache *pp = data1_attset_cache_get (dh);
/* we have multiple versions of data1_getelementbyname */
#define DATA1_GETELEMENTBYTAGNAME_VERSION 1
/* we have multiple versions of data1_getelementbyname */
#define DATA1_GETELEMENTBYTAGNAME_VERSION 1
-#if DATA1_GETELEMENTBYTAGNAME_VERSION==0
-/* straight linear search */
-data1_element *data1_getelementbytagname (data1_handle dh, data1_absyn *abs,
- data1_element *parent,
- const char *tagname)
-{
- data1_element *r;
-
- /* It's now possible to have a data1 tree with no abstract syntax */
- if ( !abs )
- return 0;
-
- if (!parent)
- r = abs->main_elements;
- else
- r = parent->children;
-
- for (; r; r = r->next)
- {
- data1_name *n;
-
- for (n = r->tag->names; n; n = n->next)
- if (!data1_matchstr(tagname, n->name))
- return r;
- }
- return 0;
-}
-#endif
-
-#if DATA1_GETELEMENTBYTAGNAME_VERSION==1
-/* using hash search */
- if (*p == '/') { abs=0; p++; }
-
- while (*p) {
- i=0;
- while (*p && !strchr("/",*p)) {
- i++; p++;
- }
- stack[e] = (char *) nmem_malloc (data1_nmem_get (dh), i+1);
+ if (*p == '/')
+ {
+ abs =0;
+ p++;
+ }
+ while (*p)
+ {
+ int is_predicate = 0;
+ char *s;
+ int i, j;
+ for (i = 0; *p && !strchr("/",*p); i++, p++)
+ ;
+ res_size += (i+3); /* we'll add / between later .. */
+ stack[e] = (char *) nmem_malloc(data1_nmem_get(dh), i+1);
+ if (*p)
+ p++;
+ }
+ res_p = res = nmem_malloc(data1_nmem_get(dh), res_size + 10);
+
+ if (stack[e-1][0] == '@') /* path/@attr spec (leaf is attribute) */
+ strcpy(res_p, "/");
+ else
+ 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]);
+ res_p += strlen(stack[e]) + 1;
- if (!abs) { sprintf (p, ".*"); p+=2; }
- sprintf (p, "$"); p++;
- r = nmem_strdup (data1_nmem_get (dh), res);
- yaz_log(YLOG_DEBUG,"Got regexp: %s",r);
- return (r);
+ sprintf (res_p, "$");
+ res_p++;
+ yaz_log(YLOG_DEBUG, "Got regexp: %s", res);
+ 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)
- }
- 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);
if (r == 2 && (source = strchr(structure, ':')))
*source++ = '\0'; /* cut off structure .. */
else
if (r == 2 && (source = strchr(structure, ':')))
*source++ = '\0'; /* cut off structure .. */
else
-data1_absyn *data1_read_absyn (data1_handle dh, const char *file,
- int file_must_exist)
+static data1_absyn *data1_read_absyn(data1_handle dh, const char *file,
+ enum DATA1_XPATH_INDEXING default_xpath)
- 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;
- }
+ f = data1_path_fopen(dh, file, "r");
res = (data1_absyn *) nmem_malloc(data1_nmem_get(dh), sizeof(*res));
res->name = 0;
res->reference = VAL_NONE;
res->tagset = 0;
res->encoding = 0;
res = (data1_absyn *) nmem_malloc(data1_nmem_get(dh), sizeof(*res));
res->name = 0;
res->reference = VAL_NONE;
res->tagset = 0;
res->encoding = 0;
while (f && (argc = read_absyn_line(f, &lineno, line, 512, argv, 50)))
{
char *cmd = *argv;
while (f && (argc = read_absyn_line(f, &lineno, line, 512, argv, 50)))
{
char *cmd = *argv;
- 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))
- i = dfa_parse (dfa, ®exp);
- if (i || *regexp) {
- yaz_log(YLOG_WARN, "%s:%d: Bad xpath to xelm", file, lineno);
- dfa_delete (&dfa);
- continue;
- }
-
+
+#if OPTIMIZE_MELM
+ for (xp_old = res->xp_elements; xp_old; xp_old = xp_old->next)
+ if (!strcmp(xp_old->regexp, regexp))
+ break;
+#endif
+ if (!xp_old)
+ {
+ const char *regexp_ptr = regexp;
+
+ dfa = dfa_init();
+ i = dfa_parse (dfa, ®exp_ptr);
+ if (i || *regexp_ptr) {
+ yaz_log(YLOG_WARN, "%s:%d: Bad xpath to xelm", file, lineno);
+ dfa_delete (&dfa);
+ continue;
+ }
+ }
nmem_malloc(data1_nmem_get(dh), sizeof(*cur_xpelement));
cur_xpelement = cur_xpelement->next;
}
nmem_malloc(data1_nmem_get(dh), sizeof(*cur_xpelement));
cur_xpelement = cur_xpelement->next;
}
cur_xpelement->next = NULL;
cur_xpelement->xpath_expr = nmem_strdup(data1_nmem_get (dh),
xpath_expr);
cur_xpelement->next = NULL;
cur_xpelement->xpath_expr = nmem_strdup(data1_nmem_get (dh),
xpath_expr);
if (parse_termlists (dh, &tp, p, file, lineno,
if (parse_termlists (dh, &tp, p, file, lineno,
- 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))
- 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;
+ 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;