X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;ds=sidebyside;f=data1%2Fd1_read.c;h=1c50d0607d6bb0e4bebef1ca535a60abcc3a681d;hb=d1e1a6a2a574e8019e700abb9d8a9d03ba41aab5;hp=c3cad0a42aeb3e11f0fbbeeee1780034b40192cc;hpb=6c9fcd3b5d3108702fa1ffc92dab4ab6060f9a19;p=idzebra-moved-to-github.git
diff --git a/data1/d1_read.c b/data1/d1_read.c
index c3cad0a..1c50d06 100644
--- a/data1/d1_read.c
+++ b/data1/d1_read.c
@@ -1,4 +1,4 @@
-/* $Id: d1_read.c,v 1.14 2005-01-15 19:38:18 adam Exp $
+/* $Id: d1_read.c,v 1.20 2006-07-06 11:40:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
@@ -125,7 +125,6 @@ data1_node *data1_append_node (data1_handle dh, NMEM m, int type,
{
data1_node *r = (data1_node *)nmem_malloc(m, sizeof(*r));
r->next = r->child = r->last_child = 0;
- r->destroy = 0;
r->parent = parent;
if (!parent)
@@ -154,7 +153,6 @@ data1_node *data1_insert_node (data1_handle dh, NMEM m, int type,
{
data1_node *r = (data1_node *)nmem_malloc(m, sizeof(*r));
r->next = r->child = r->last_child = 0;
- r->destroy = 0;
if (!parent)
r->root = r;
@@ -172,23 +170,9 @@ data1_node *data1_insert_node (data1_handle dh, NMEM m, int type,
return r;
}
-void data1_free_tree (data1_handle dh, data1_node *t)
-{
- data1_node *p = t->child, *pn;
-
- while (p)
- {
- pn = p->next;
- data1_free_tree (dh, p);
- p = pn;
- }
- if (t->destroy)
- (*t->destroy)(t);
-}
-
data1_node *data1_mk_root (data1_handle dh, NMEM nmem, const char *name)
{
- data1_absyn *absyn = data1_get_absyn (dh, name);
+ data1_absyn *absyn = data1_get_absyn(dh, name, 1);
data1_node *res;
if (!absyn)
{
@@ -205,7 +189,8 @@ data1_node *data1_mk_root (data1_handle dh, NMEM nmem, const char *name)
void data1_set_root(data1_handle dh, data1_node *res,
NMEM nmem, const char *name)
{
- data1_absyn *absyn = data1_get_absyn (dh, name);
+ data1_absyn *absyn = data1_get_absyn(
+ dh, name, DATA1_XPATH_INDEXING_ENABLE);
res->u.root.type = data1_insert_string (dh, res, nmem, name);
res->u.root.absyn = absyn;
@@ -697,8 +682,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
{
data1_xattr *xattr;
- char tag[64];
- char args[256];
+ char tag[256];
int null_tag = 0;
int end_tag = 0;
size_t i = 0;
@@ -709,6 +693,33 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
end_tag = 1;
c = ampr (get_byte, fh, &);
}
+ else if (amp == 0 && c == '?')
+ {
+ int quote_mode = 0;
+ while ((c = ampr(get_byte, fh, &)))
+ {
+ if (amp)
+ continue;
+ if (quote_mode == 0)
+ {
+ if (c == '"')
+ quote_mode = c;
+ else if (c == '\'')
+ quote_mode = c;
+ else if (c == '>')
+ {
+ c = ampr(get_byte, fh, &);
+ break;
+ }
+ }
+ else
+ {
+ if (amp == 0 && c == quote_mode)
+ quote_mode = 0;
+ }
+ }
+ continue;
+ }
else if (amp == 0 && c == '!')
{
int c0, amp0;
@@ -776,7 +787,6 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
}
tag[i] = '\0';
xattr = data1_read_xattr (dh, m, get_byte, fh, wrbuf, &c, &);
- args[0] = '\0';
if (amp == 0 && c == '/')
{ /* or */
null_tag = 1;
@@ -829,17 +839,20 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
}
continue;
}
- else if (!strcmp(tag, "var"))
+ else if (!strcmp(tag, "var")
+ && xattr && xattr->next && xattr->next->next
+ && xattr->value == 0
+ && xattr->next->value == 0
+ && xattr->next->next->value == 0)
{
- char tclass[DATA1_MAX_SYMBOL], type[DATA1_MAX_SYMBOL];
+ /* */
+ const char *tclass = xattr->name;
+ const char *type = xattr->next->name;
+ const char *value = xattr->next->name;
data1_vartype *tp;
- int val_offset;
- if (sscanf(args, "%s %s %n", tclass, type, &val_offset) != 2)
- {
- yaz_log(YLOG_WARN, "Malformed variant triple at '%s'", tag);
- continue;
- }
+ yaz_log(YLOG_LOG, "Variant class=%s type=%s value=%s",
+ tclass, type, value);
if (!(tp =
data1_getvartypebyct(dh,
parent->root->u.root.absyn->varset,
@@ -869,7 +882,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m,
res = data1_mk_node2 (dh, m, DATA1N_variant, parent);
res->u.variant.type = tp;
res->u.variant.value =
- data1_insert_string (dh, res, m, args + val_offset);
+ data1_insert_string (dh, res, m, value);
}
}
else
@@ -1108,12 +1121,15 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
if (yaz_matchstr (tocode, fromcode))
{
WRBUF wrbuf = wrbuf_alloc();
- yaz_iconv_t t = yaz_iconv_open (tocode, fromcode);
+ yaz_iconv_t t = yaz_iconv_open(tocode, fromcode);
if (!t)
+ {
+ wrbuf_free(wrbuf, 1);
return -1;
- data1_iconv_s (dh, m, n, t, wrbuf, tocode);
- yaz_iconv_close (t);
- wrbuf_free (wrbuf, 1);
+ }
+ data1_iconv_s(dh, m, n, t, wrbuf, tocode);
+ yaz_iconv_close(t);
+ wrbuf_free(wrbuf, 1);
}
return 0;
}
@@ -1147,3 +1163,11 @@ void data1_concat_text(data1_handle dh, NMEM m, data1_node *n)
data1_concat_text(dh, m, n->child);
}
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+