X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=data1%2Fd1_read.c;h=1afae5a6f5bd3d76af16f029ba60080eda916b2a;hb=dfecbd92db8f9581ec24f1cd29c48198e1413546;hp=4a96ec30eb4f5a3413397ff3eda4a065d9dd6ab7;hpb=cf22d9136ae778877b227aa9d47dc3856a6d9149;p=idzebra-moved-to-github.git
diff --git a/data1/d1_read.c b/data1/d1_read.c
index 4a96ec3..1afae5a 100644
--- a/data1/d1_read.c
+++ b/data1/d1_read.c
@@ -1,8 +1,5 @@
-/* $Id: d1_read.c,v 1.15 2005-01-17 22:12:34 adam Exp $
- Copyright (C) 1995-2005
- Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+ Copyright (C) 1995-2008 Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@ -15,9 +12,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
-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
+
*/
@@ -125,7 +122,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 +150,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,24 +167,11 @@ 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)
{
yaz_log(YLOG_WARN, "Unable to acquire abstract syntax " "for '%s'",
@@ -205,7 +187,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;
@@ -607,7 +590,6 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m,
for (;;)
{
data1_xattr *p;
- int len;
while (*amp || (c && d1_isspace(c)))
c = ampr (get_byte, fh, amp);
if (*amp == 0 && (c == 0 || c == '>' || c == '/'))
@@ -624,10 +606,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m,
wrbuf_putc (wrbuf, c);
c = ampr (get_byte, fh, amp);
}
- wrbuf_putc (wrbuf, '\0');
- len = wrbuf_len(wrbuf);
- p->name = (char*) nmem_malloc (m, len);
- strcpy (p->name, wrbuf_buf(wrbuf));
+ p->name = nmem_strdup (m, wrbuf_cstr(wrbuf));
if (c == '=')
{
c = ampr (get_byte, fh, amp);
@@ -664,10 +643,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m,
c = ampr (get_byte, fh, amp);
}
}
- wrbuf_putc (wrbuf, '\0');
- len = wrbuf_len(wrbuf);
- p->value = (char*) nmem_malloc (m, len);
- strcpy (p->value, wrbuf_buf(wrbuf));
+ p->value = nmem_strdup(m, wrbuf_cstr(wrbuf));
}
}
*ch = c;
@@ -697,8 +673,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 +684,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 +778,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 +830,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 +873,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
@@ -952,7 +956,7 @@ data1_node *data1_read_node (data1_handle dh, const char **buf, NMEM m)
data1_node *node;
node = data1_read_nodex(dh, m, getc_mem, (void *) (buf), wrbuf);
- wrbuf_free (wrbuf, 1);
+ wrbuf_destroy(wrbuf);
return node;
}
@@ -997,34 +1001,12 @@ data1_node *data1_read_sgml (data1_handle dh, NMEM m, const char *buf)
}
-static int conv_item (NMEM m, yaz_iconv_t t,
- WRBUF wrbuf, char *inbuf, size_t inlen)
+static int conv_item(NMEM m, yaz_iconv_t t,
+ WRBUF wrbuf, char *inbuf, size_t inlen)
{
- wrbuf_rewind (wrbuf);
- if (wrbuf->size < 10)
- wrbuf_grow (wrbuf, 10);
- for (;;)
- {
- char *outbuf = wrbuf->buf + wrbuf->pos;
- size_t outlen = wrbuf->size - wrbuf->pos;
- if (yaz_iconv (t, &inbuf, &inlen, &outbuf, &outlen) ==
- (size_t)(-1) && yaz_iconv_error(t) != YAZ_ICONV_E2BIG)
- {
- /* bad data. stop and skip conversion entirely */
- return -1;
- }
- else if (inlen == 0)
- { /* finished converting */
- wrbuf->pos = wrbuf->size - outlen;
- break;
- }
- else
- {
- /* buffer too small: make sure we expand buffer */
- wrbuf->pos = wrbuf->size - outlen;
- wrbuf_grow(wrbuf, 20);
- }
- }
+ wrbuf_rewind(wrbuf);
+ wrbuf_iconv_write(wrbuf, t, inbuf, inlen);
+ wrbuf_iconv_reset(wrbuf, t);
return 0;
}
@@ -1062,8 +1044,7 @@ static void data1_iconv_s (data1_handle dh, NMEM m, data1_node *n,
conv_item(m, t, wrbuf, p->value, strlen(p->value))
== 0)
{
- wrbuf_puts (wrbuf, "");
- p->value = nmem_strdup (m, wrbuf->buf);
+ p->value = nmem_strdup(m, wrbuf_cstr(wrbuf));
}
}
}
@@ -1102,8 +1083,8 @@ const char *data1_get_encoding (data1_handle dh, data1_node *n)
}
int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
- const char *tocode,
- const char *fromcode)
+ const char *tocode,
+ const char *fromcode)
{
if (yaz_matchstr (tocode, fromcode))
{
@@ -1111,16 +1092,45 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
yaz_iconv_t t = yaz_iconv_open(tocode, fromcode);
if (!t)
{
- wrbuf_free(wrbuf, 1);
+ wrbuf_destroy(wrbuf);
return -1;
}
data1_iconv_s(dh, m, n, t, wrbuf, tocode);
yaz_iconv_close(t);
- wrbuf_free(wrbuf, 1);
+ wrbuf_destroy(wrbuf);
}
return 0;
}
+void data1_chop_text(data1_handle dh, NMEM m, data1_node *n)
+{
+ for (; n; n = n->next)
+ {
+ if (n->which == DATA1N_data)
+ {
+
+ int sz = n->u.data.len;
+ const char *ndata = n->u.data.data;
+ int off = 0;
+
+ for (off = 0; off < sz; off++)
+ if (!d1_isspace(ndata[off]))
+ break;
+ sz = sz - off;
+ ndata += off;
+
+ while (sz && d1_isspace(ndata[sz - 1]))
+ sz--;
+
+ n->u.data.data = nmem_malloc(m, sz);
+ n->u.data.len = sz;
+ memcpy(n->u.data.data, ndata, sz);
+
+ }
+ data1_chop_text(dh, m, n->child);
+ }
+}
+
void data1_concat_text(data1_handle dh, NMEM m, data1_node *n)
{
for (; n; n = n->next)
@@ -1150,3 +1160,12 @@ 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
+ */
+