32 #include <yaz/snprintf.h>
33 #include <yaz/yaz-util.h>
89 r->
u.
tag.no_data_requested = 0;
90 r->
u.
tag.node_selected = 0;
91 r->
u.
tag.make_variantlist = 0;
92 r->
u.
tag.get_bytes = -1;
93 r->
u.
tag.attributes = 0;
103 r->
u.
data.formatted_text = 0;
109 r->
u.
data.formatted_text = 1;
120 yaz_log(YLOG_WARN,
"data_mk_node_type. bad type = %d\n", type);
181 yaz_log(YLOG_WARN,
"Unable to acquire abstract syntax " "for '%s'",
187 res->
u.
root.absyn = absyn;
192 NMEM nmem,
const char *name)
198 res->
u.
root.absyn = absyn;
207 while (attr && *attr)
209 *p = (
data1_xattr*) nmem_malloc(nmem,
sizeof(**p));
210 (*p)->
name = nmem_strdup(nmem, *attr++);
211 (*p)->value = nmem_strdup(nmem, *attr++);
228 const char *target,
size_t len,
248 const char *target,
size_t len,
260 const char *tag,
size_t len,
const char **attr,
276 e = partag->
u.
tag.element;
281 res->
u.
tag.element = e;
296 const char *tag,
const char **attr,
data1_node *at)
311 for (; n; n = n->
next)
313 !yaz_matchstr(n->
u.
tag.tag, tag))
332 const char *buf,
size_t len,
data1_node *parent)
340 const char *buf,
size_t len,
data1_node *parent)
343 res->
u.
data.formatted_text = 1;
354 const char *buf,
size_t len,
369 const char *str,
size_t len)
373 res->
u.
data.len = len;
383 NMEM m,
const char *str,
size_t len)
387 b = (
char *) nmem_malloc(m, len+1);
411 NMEM m,
const char *str)
418 const char *tagname, NMEM m,
432 e = partag->
u.
tag.element;
436 if (local_allowed || e)
443 tagn->
u.
tag.element = e;
450 const char *tagname, NMEM m)
462 const char *tagname, NMEM m)
482 const char *tag,
zint num,
495 const char *tag,
int num,
502 const char *tag, Odr_oid *oid,
506 char str[128], *p = str;
513 for (i = 0; i < 14 && oid[i] >= 0; i++)
517 yaz_snprintf(p, 7,
"%d", oid[i]);
527 const char *tag,
const char *str,
539 const char *tag,
const char *str,
551 static int ampr(
int (*get_byte)(
void *fh),
void *fh,
int *amp)
553 int c = (*get_byte)(fh);
559 int (*get_byte)(
void *fh),
void *fh,
560 WRBUF wrbuf,
int *ch,
int *amp)
569 c =
ampr(get_byte, fh, amp);
570 if (*amp == 0 && (c == 0 || c ==
'>' || c ==
'/'))
572 *pp = p = (
data1_xattr *) nmem_malloc(m,
sizeof(*p));
579 while (c && c !=
'=' && c !=
'>' && c !=
'/' && !
d1_isspace(c))
581 wrbuf_putc(wrbuf, c);
582 c =
ampr(get_byte, fh, amp);
584 p->
name = nmem_strdup(m, wrbuf_cstr(wrbuf));
587 c =
ampr(get_byte, fh, amp);
588 if (*amp == 0 && c ==
'"')
590 c =
ampr(get_byte, fh, amp);
592 while (*amp || (c && c !=
'"'))
594 wrbuf_putc(wrbuf, c);
595 c =
ampr(get_byte, fh, amp);
598 c =
ampr(get_byte, fh, amp);
600 else if (*amp == 0 && c ==
'\'')
602 c =
ampr(get_byte, fh, amp);
604 while (*amp || (c && c !=
'\''))
606 wrbuf_putc(wrbuf, c);
607 c =
ampr(get_byte, fh, amp);
610 c =
ampr(get_byte, fh, amp);
615 while (*amp || (c && c !=
'>' && c !=
'/'))
617 wrbuf_putc(wrbuf, c);
618 c =
ampr(get_byte, fh, amp);
621 p->
value = nmem_strdup(m, wrbuf_cstr(wrbuf));
633 int (*get_byte)(
void *fh),
void *fh, WRBUF wrbuf)
642 c =
ampr(get_byte, fh, &);
645 data1_node *parent = level ? d1_stack[level-1] : 0;
647 if (amp == 0 && c ==
'<')
656 c =
ampr(get_byte, fh, &);
657 if (amp == 0 && c ==
'/')
660 c =
ampr(get_byte, fh, &);
662 else if (amp == 0 && c ==
'?')
665 while ((c =
ampr(get_byte, fh, &)))
677 c =
ampr(get_byte, fh, &);
683 if (amp == 0 && c == quote_mode)
689 else if (amp == 0 && c ==
'!')
695 c0 =
ampr(get_byte, fh, &0);
696 if (amp0 == 0 && c0 ==
'\0')
698 c =
ampr(get_byte, fh, &);
700 if (amp0 == 0 && c0 ==
'-' && amp == 0 && c ==
'-')
705 c =
ampr(get_byte, fh, &);
708 if (amp == 0 && c ==
'-')
710 else if (amp == 0 && c ==
'>' && no_dash >= 2)
716 wrbuf_buf(wrbuf), wrbuf_len(wrbuf)-2,
718 c =
ampr(get_byte, fh, &);
723 wrbuf_putc(wrbuf, c);
724 c =
ampr(get_byte, fh, &);
734 if (amp == 0 && c ==
'>' && blevel == 0)
736 c =
ampr(get_byte, fh, &);
739 if (amp == 0 && c ==
'[')
741 if (amp == 0 && c ==
']' && blevel > 0)
743 c =
ampr(get_byte, fh, &);
748 while (amp || (c && c !=
'>' && c !=
'/' && !
d1_isspace(c)))
750 if (i < (
sizeof(tag)-1))
752 c =
ampr(get_byte, fh, &);
756 if (amp == 0 && c ==
'/')
759 c =
ampr(get_byte, fh, &);
763 yaz_log(YLOG_WARN,
"d1: %d: Malformed tag", line);
767 c =
ampr(get_byte, fh, &);
779 parent = d1_stack[--i];
781 !strcmp(tag, parent->
u.
root.type)) ||
783 !strcmp(tag, parent->
u.
tag.tag)))
791 yaz_log(YLOG_WARN,
"%d: no begin tag for %s",
808 else if (!strcmp(tag,
"var")
815 const char *tclass = xattr->
name;
816 const char *type = xattr->
next->
name;
817 const char *value = xattr->
next->
name;
820 yaz_log(YLOG_LOG,
"Variant class=%s type=%s value=%s",
821 tclass, type, value);
824 parent->
root->u.root.absyn->varset,
843 if (d1_stack[i]->u.
variant.type == tp)
861 res = d1_stack[level] = parent;
867 res->
u.
tag.attributes = xattr;
873 res->
u.
tag.attributes = xattr;
876 d1_stack[level] = res;
877 d1_stack[level+1] = 0;
878 if (level < 250 && !null_tag)
887 c =
ampr(get_byte, fh, &);
892 res->
u.
data.formatted_text = 0;
893 d1_stack[level] = res;
897 while (amp || (c && c !=
'<'))
899 wrbuf_putc(wrbuf, c);
900 c =
ampr(get_byte, fh, &);
902 len = wrbuf_len(wrbuf);
906 res->
u.
data.data = (
char*) nmem_malloc(m, len);
911 memcpy(res->
u.
data.data, wrbuf_buf(wrbuf), len);
913 res->
u.
data.data = 0;
914 res->
u.
data.len = len;
922 const char **p = (
const char **) fh;
930 WRBUF wrbuf = wrbuf_alloc();
934 wrbuf_destroy(wrbuf);
942 int (*rf)(
void *,
char *,
size_t),
void *fh,
951 *buf = (
char *)xmalloc(*size = 4096);
955 if (rd + 2048 >= *size && !(*buf =(
char *)xrealloc(*buf, *size *= 2)))
957 if ((res = (*rf)(fh, *buf + rd, 2048)) <= 0)
974 const char *bp = buf;
980 WRBUF wrbuf,
char *inbuf,
size_t inlen)
983 wrbuf_iconv_write(wrbuf, t, inbuf, inlen);
984 wrbuf_iconv_reset(wrbuf, t);
989 yaz_iconv_t t, WRBUF wrbuf,
const char *tocode)
991 for (; n; n = n->
next)
1001 n->
u.
data.len = wrbuf->pos;
1011 if (n->
u.
tag.attributes)
1014 for (p = n->
u.
tag.attributes; p; p = p->
next)
1020 p->
value = nmem_strdup(m, wrbuf_cstr(wrbuf));
1029 for (; p; p = p->
next)
1030 if (strcmp(p->
name,
"encoding") == 0)
1031 p->
value = nmem_strdup(m, tocode);
1046 for (; xp; xp = xp->
next)
1047 if (strcmp(xp->
name,
"encoding") == 0)
1052 n->
u.
root.absyn && n->
u.
root.absyn->encoding)
1053 return n->
u.
root.absyn->encoding;
1055 return "ISO-8859-1";
1060 const char *fromcode)
1062 if (yaz_matchstr(tocode, fromcode))
1064 WRBUF wrbuf = wrbuf_alloc();
1065 yaz_iconv_t t = yaz_iconv_open(tocode, fromcode);
1068 wrbuf_destroy(wrbuf);
1073 wrbuf_destroy(wrbuf);
1080 for (; n; n = n->
next)
1085 int sz = n->
u.
data.len;
1086 const char *ndata = n->
u.
data.data;
1089 for (off = 0; off < sz; off++)
1098 n->
u.
data.data = nmem_malloc(m, sz);
1100 memcpy(n->
u.
data.data, ndata, sz);
1109 for (; n; n = n->
next)
1119 sz += np->
u.
data.len;
1120 ndata = nmem_malloc(m, sz);
1123 memcpy(ndata+off, np->
u.
data.data, np->
u.
data.len);
1124 off += np->
u.
data.len;
1126 n->
u.
data.data = ndata;
data1_node * data1_mk_tag(data1_handle dh, NMEM nmem, const char *tag, const char **attr, data1_node *at)
int data1_iconv(data1_handle dh, NMEM m, data1_node *n, const char *tocode, const char *fromcode)
data1_node * data1_search_tag(data1_handle dh, data1_node *n, const char *tag)
data1_node * data1_mk_root(data1_handle dh, NMEM nmem, const char *name)
void data1_add_attrs(data1_handle dh, NMEM nmem, const char **attr, data1_xattr **p)
char * data1_insert_string(data1_handle dh, data1_node *res, NMEM m, const char *str)
char * data1_insert_string_n(data1_handle dh, data1_node *res, NMEM m, const char *str, size_t len)
data1_node * data1_mk_node_type(data1_handle dh, NMEM m, int type)
data1_node * data1_insert_preprocess(data1_handle dh, NMEM nmem, const char *target, const char **attr, data1_node *at)
static void data1_init_node(data1_handle dh, data1_node *r, int type)
data1_node * data1_mk_tag_data_text(data1_handle dh, data1_node *at, const char *tag, const char *str, NMEM nmem)
void data1_tag_add_attr(data1_handle dh, NMEM nmem, data1_node *res, const char **attr)
data1_node * data1_mk_comment_n(data1_handle dh, NMEM mem, const char *buf, size_t len, data1_node *parent)
void data1_concat_text(data1_handle dh, NMEM m, data1_node *n)
data1_node * data1_read_sgml(data1_handle dh, NMEM m, const char *buf)
data1_xattr * data1_read_xattr(data1_handle dh, NMEM m, int(*get_byte)(void *fh), void *fh, WRBUF wrbuf, int *ch, int *amp)
data1_node * data1_mk_tag_data_wd(data1_handle dh, data1_node *at, const char *tagname, NMEM m)
data1_node * data1_insert_node(data1_handle dh, NMEM m, int type, data1_node *parent)
data1_node * data1_read_nodex(data1_handle dh, NMEM m, int(*get_byte)(void *fh), void *fh, WRBUF wrbuf)
char * data1_insert_zint(data1_handle dh, data1_node *res, NMEM m, zint num)
data1_node * data1_mk_node(data1_handle dh, NMEM m)
void data1_set_data_string(data1_handle dh, data1_node *res, NMEM m, const char *str)
void data1_set_data_zint(data1_handle dh, data1_node *res, NMEM m, zint num)
static void data1_iconv_s(data1_handle dh, NMEM m, data1_node *n, yaz_iconv_t t, WRBUF wrbuf, const char *tocode)
data1_node * data1_append_node(data1_handle dh, NMEM m, int type, data1_node *parent)
data1_node * data1_read_record(data1_handle dh, int(*rf)(void *, char *, size_t), void *fh, NMEM m)
data1_node * data1_add_taggeddata(data1_handle dh, data1_node *root, data1_node *at, const char *tagname, NMEM m)
data1_node * data1_get_root_tag(data1_handle dh, data1_node *n)
data1_node * data1_insert_preprocess_n(data1_handle dh, NMEM nmem, const char *target, size_t len, const char **attr, data1_node *at)
static data1_node * data1_add_insert_taggeddata(data1_handle dh, data1_node *at, const char *tagname, NMEM m, int local_allowed, int insert_mode)
data1_node * data1_mk_comment(data1_handle dh, NMEM mem, const char *buf, data1_node *parent)
data1_node * data1_mk_tag_n(data1_handle dh, NMEM nmem, const char *tag, size_t len, const char **attr, data1_node *at)
data1_node * data1_mk_tag_data_text_uni(data1_handle dh, data1_node *at, const char *tag, const char *str, NMEM nmem)
data1_node * data1_mk_tag_uni(data1_handle dh, NMEM nmem, const char *tag, data1_node *at)
data1_node * data1_mk_node2(data1_handle dh, NMEM m, int type, data1_node *parent)
data1_node * get_parent_tag(data1_handle dh, data1_node *n)
data1_node * data1_mk_tag_data_zint(data1_handle dh, data1_node *at, const char *tag, zint num, NMEM nmem)
void data1_chop_text(data1_handle dh, NMEM m, data1_node *n)
data1_node * data1_mk_text_n(data1_handle dh, NMEM mem, const char *buf, size_t len, data1_node *parent)
data1_node * data1_mk_tag_data(data1_handle dh, data1_node *at, const char *tagname, NMEM m)
data1_node * data1_mk_text_nf(data1_handle dh, NMEM mem, const char *buf, size_t len, data1_node *parent)
data1_node * data1_mk_preprocess(data1_handle dh, NMEM nmem, const char *target, const char **attr, data1_node *at)
data1_node * data1_insert_taggeddata(data1_handle dh, data1_node *root, data1_node *at, const char *tagname, NMEM m)
data1_node * data1_read_node(data1_handle dh, const char **buf, NMEM m)
void data1_set_data_string_n(data1_handle dh, data1_node *res, NMEM m, const char *str, size_t len)
data1_node * data1_mk_preprocess_n(data1_handle dh, NMEM nmem, const char *target, size_t len, const char **attr, data1_node *at)
data1_node * data1_mk_tag_data_oid(data1_handle dh, data1_node *at, const char *tag, Odr_oid *oid, NMEM nmem)
const char * data1_get_encoding(data1_handle dh, data1_node *n)
data1_node * data1_mk_text(data1_handle dh, NMEM mem, const char *buf, data1_node *parent)
data1_node * data1_mk_tag_data_int(data1_handle dh, data1_node *at, const char *tag, int num, NMEM nmem)
void data1_set_root(data1_handle dh, data1_node *res, NMEM nmem, const char *name)
static int ampr(int(*get_byte)(void *fh), void *fh, int *amp)
static int conv_item(NMEM m, yaz_iconv_t t, WRBUF wrbuf, char *inbuf, size_t inlen)
data1_element * data1_getelementbytagname(data1_handle dh, data1_absyn *abs, data1_element *parent, const char *tagname)
data1_absyn * data1_get_absyn(data1_handle dh, const char *name, enum DATA1_XPATH_INDEXING en)
char ** data1_get_read_buf(data1_handle dp, int **lenp)
#define DATA1N_preprocess
@ DATA1_XPATH_INDEXING_ENABLE
data1_vartype * data1_getvartypebyct(data1_handle dh, data1_varset *set, const char *zclass, const char *type)
int data1_is_xmlmode(data1_handle dh)
char lbuf[DATA1_LOCALDATA]
struct data1_node::@2::@7 preprocess
struct data1_node::@2::@3 root
struct data1_node * parent
struct data1_node * child
struct data1_node * last_child
struct data1_node::@2::@6 variant
struct data1_xattr * next