From ffe5c37f0c9f55a685ac3559f1cad44baae399f4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 3 May 2002 13:48:27 +0000 Subject: [PATCH] data1 cleanup --- client/client.c | 6 +- include/yaz/data1.h | 69 ++++++++--- retrieval/d1_espec.c | 10 +- retrieval/d1_map.c | 22 ++-- retrieval/d1_read.c | 333 +++++++++++++++++++++++++++++++++----------------- retrieval/d1_sutrs.c | 30 +---- 6 files changed, 293 insertions(+), 177 deletions(-) diff --git a/client/client.c b/client/client.c index f472260..748c184 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.150 2002-04-15 11:19:32 adam Exp $ + * $Id: client.c,v 1.151 2002-05-03 13:48:27 adam Exp $ */ #include @@ -2645,7 +2645,7 @@ char ** readline_completer(char *text, int start, int end) { #if HAVE_READLINE_READLINE_H if(start == 0) { -#ifdef RL_READLINE_VERSION +#if HAVE_READLINE_RL_COMPLETION_MATCHES char** res=rl_completion_matches(text, command_generator); #else @@ -2676,7 +2676,7 @@ char ** readline_completer(char *text, int start, int end) { if(!cmd[i].complete_filenames) rl_attempted_completion_over = 1; if(cmd[i].rl_completerfunction) { -#ifdef RL_READLINE_VERSION +#ifdef HAVE_READLINE_RL_COMPLETION_MATCHES char** res= rl_completion_matches(text, cmd[i].rl_completerfunction); diff --git a/include/yaz/data1.h b/include/yaz/data1.h index 31490e1..37b7c5f 100644 --- a/include/yaz/data1.h +++ b/include/yaz/data1.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: data1.h,v $ - * Revision 1.7 2002-04-04 20:49:46 adam + * Revision 1.8 2002-05-03 13:48:27 adam + * data1 cleanup + * + * Revision 1.7 2002/04/04 20:49:46 adam * New functions yaz_is_abspath, yaz_path_fopen_base * * Revision 1.6 2000/12/05 12:21:45 adam @@ -532,13 +535,13 @@ YAZ_EXPORT data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s, YAZ_EXPORT void data1_free_tree(data1_handle dh, data1_node *t); YAZ_EXPORT char *data1_nodetobuf(data1_handle dh, data1_node *n, int select, int *len); -YAZ_EXPORT data1_node *data1_insert_taggeddata(data1_handle dh, - data1_node *root, - data1_node *at, - const char *tagname, NMEM m); -YAZ_EXPORT data1_node *data1_add_taggeddata(data1_handle dh, data1_node *root, - data1_node *at, - const char *tagname, NMEM m); +YAZ_EXPORT data1_node *data1_mk_tag_data_wd(data1_handle dh, + data1_node *root, + data1_node *at, + const char *tagname, NMEM m); +YAZ_EXPORT data1_node *data1_mk_tag_data(data1_handle dh, data1_node *root, + data1_node *at, + const char *tagname, NMEM m); YAZ_EXPORT data1_datatype data1_maptype(data1_handle dh, char *t); YAZ_EXPORT data1_varset *data1_read_varset(data1_handle dh, const char *file); YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_handle dh, @@ -552,9 +555,46 @@ YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh, YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh, data1_absyn *absyn, const char *name); -YAZ_EXPORT data1_node *data1_mk_node(data1_handle dh, NMEM m); -YAZ_EXPORT data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type); -YAZ_EXPORT data1_absyn *data1_get_absyn(data1_handle dh, const char *name); +YAZ_EXPORT data1_node *data1_mk_node(data1_handle dh, NMEM m, + int type, data1_node *parent); + +YAZ_EXPORT data1_node *data1_mk_tag (data1_handle dh, NMEM nmem, + const char *tag, data1_node *at); +YAZ_EXPORT data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem, + const char *tag, size_t len, + data1_node *at); + +YAZ_EXPORT data1_node *data1_mk_text_n (data1_handle dh, NMEM mem, + const char *buf, size_t len, + data1_node *parent); +YAZ_EXPORT data1_node *data1_mk_text (data1_handle dh, NMEM mem, + const char *buf, data1_node *parent); + +YAZ_EXPORT data1_node *data1_mk_root (data1_handle dh, NMEM nmem, + const char *name); + +YAZ_EXPORT data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at, + const char *tag, int num, + NMEM nmem); +YAZ_EXPORT data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at, + const char *tag, Odr_oid *oid, + NMEM nmem); +YAZ_EXPORT data1_node *data1_mk_tag_data_text (data1_handle dh, data1_node *at, + const char *tag, + const char *str, + NMEM nmem); +YAZ_EXPORT data1_node *data1_mk_tag_data_text_uni (data1_handle dh, + data1_node *at, + const char *tag, + const char *str, + NMEM nmem); + +YAZ_EXPORT data1_absyn *data1_get_absyn (data1_handle dh, const char *name); + +YAZ_EXPORT data1_node *data1_search_tag (data1_handle dh, data1_node *n, + const char *tag); +YAZ_EXPORT data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem, + const char *tag, data1_node *at); YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name); YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file); YAZ_EXPORT data1_node *data1_map_record(data1_handle dh, data1_node *n, @@ -587,6 +627,8 @@ YAZ_EXPORT NMEM data1_nmem_get (data1_handle dh); YAZ_EXPORT void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out); YAZ_EXPORT char *data1_insert_string (data1_handle dh, data1_node *res, NMEM m, const char *str); +YAZ_EXPORT char *data1_insert_string_n (data1_handle dh, data1_node *res, + NMEM m, const char *str, size_t len); YAZ_EXPORT data1_node *data1_read_sgml (data1_handle dh, NMEM m, const char *buf); YAZ_EXPORT void data1_absyn_trav (data1_handle dh, void *handle, @@ -595,11 +637,6 @@ YAZ_EXPORT void data1_absyn_trav (data1_handle dh, void *handle, YAZ_EXPORT data1_attset *data1_attset_search_id (data1_handle dh, int id); -YAZ_EXPORT data1_node -*data1_add_insert_taggeddata(data1_handle dh, data1_node *root, - data1_node *at, const char *tagname, NMEM m, - int first_flag, int local_allowed); - YAZ_EXPORT char *data1_getNodeValue(data1_node* node, char* pTagPath); YAZ_EXPORT data1_node *data1_LookupNode(data1_node* node, char* pTagPath); YAZ_EXPORT int data1_CountOccurences(data1_node* node, char* pTagPath); diff --git a/retrieval/d1_espec.c b/retrieval/d1_espec.c index a530bd2..0b12c27 100644 --- a/retrieval/d1_espec.c +++ b/retrieval/d1_espec.c @@ -1,9 +1,9 @@ /* - * Copyright (c) 1995-2001, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_espec.c,v 1.21 2002-04-04 20:49:46 adam Exp $ + * $Id: d1_espec.c,v 1.22 2002-05-03 13:48:27 adam Exp $ */ #include @@ -39,7 +39,7 @@ static Z_Variant *read_variant(int argc, char **argv, NMEM nmem, char value[512]; Z_Triple *t; - if (sscanf(argv[i], "(%d,%d,%[^)])", &zclass, &type, value) < 3) + if (sscanf(argv[i], "(%d,%d,%511[^)])", &zclass, &type, value) < 3) { yaz_log(LOG_WARN, "%s:%d: Syntax error in variant component '%s'", file, lineno, argv[i]); @@ -150,8 +150,8 @@ static Z_ETagUnit *read_tagunit(char *buf, NMEM nmem, else u->u.wildThing = read_occurrences(0, nmem, file, lineno); } - else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-zA-Z0-9+]", &type, value, - occ)) >= 2) + else if ((terms = sscanf(buf, "(%d,%511[^)]):%511[a-zA-Z0-9+]", + &type, value, occ)) >= 2) { int numval; Z_SpecificTag *t; diff --git a/retrieval/d1_map.c b/retrieval/d1_map.c index e40b678..cb11a27 100644 --- a/retrieval/d1_map.c +++ b/retrieval/d1_map.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_map.c,v $ - * Revision 1.19 2002-04-04 20:49:46 adam + * Revision 1.20 2002-05-03 13:48:27 adam + * data1 cleanup + * + * Revision 1.19 2002/04/04 20:49:46 adam * New functions yaz_is_abspath, yaz_path_fopen_base * * Revision 1.18 2000/11/29 14:22:47 adam @@ -180,7 +183,7 @@ data1_maptab *data1_read_maptab (data1_handle dh, const char *file) if (ep) ep++; - if ((np = sscanf(path, "(%d,%[^)]):%[^/]", &type, valstr, + if ((np = sscanf(path, "(%d,%511[^)]):%511[^/]", &type, valstr, parm)) < 2) { yaz_log(LOG_WARN, "%s:%d: Syntax error in map " @@ -311,16 +314,8 @@ static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, { if (!cur || mt->new_field || !tagmatch(cur, mt)) { - cur = data1_mk_node_type (dh, mem, DATA1N_tag); + cur = data1_mk_node (dh, mem, DATA1N_tag, pn); cur->u.tag.tag = mt->value.string; - - cur->parent = pn; - cur->root = pn->root; - if (!pn->child) - pn->child = cur; - if (pn->last_child) - pn->last_child->next = cur; - pn->last_child = cur; } if (mt->next) @@ -350,7 +345,7 @@ static int map_children(data1_handle dh, data1_node *n, data1_maptab *map, data1_node *data1_map_record (data1_handle dh, data1_node *n, data1_maptab *map, NMEM m) { - data1_node *res = data1_mk_node(dh, m); + data1_node *res = data1_mk_node(dh, m, DATA1N_root, 0); res->which = DATA1N_root; res->u.root.type = map->target_absyn_name; @@ -359,9 +354,6 @@ data1_node *data1_map_record (data1_handle dh, data1_node *n, yaz_log(LOG_WARN, "%s: Failed to load target absyn '%s'", map->name, map->target_absyn_name); } - res->parent = 0; - res->root = res; - if (map_children(dh, n, map, res, m) < 0) { data1_free_tree(dh, res); diff --git a/retrieval/d1_read.c b/retrieval/d1_read.c index 2bbf6ae..743a65c 100644 --- a/retrieval/d1_read.c +++ b/retrieval/d1_read.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: d1_read.c,v 1.39 2002-04-15 09:06:30 adam Exp $ + * $Id: d1_read.c,v 1.40 2002-05-03 13:48:27 adam Exp $ */ #include @@ -26,21 +26,30 @@ data1_node *get_parent_tag (data1_handle dh, data1_node *n) return 0; } -data1_node *data1_mk_node (data1_handle dh, NMEM m) +data1_node *data1_mk_node (data1_handle dh, NMEM m, int type, + data1_node *parent) { data1_node *r; r = (data1_node *)nmem_malloc(m, sizeof(*r)); - r->next = r->child = r->last_child = r->parent = 0; + r->next = r->child = r->last_child = 0; r->destroy = 0; - return r; -} -data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type) -{ - data1_node *r; - - r = data1_mk_node(dh, m); + if (!parent) + { + r->root = r; + assert (type == DATA1N_root); + } + else + { + r->root = parent->root; + r->parent = parent; + if (!parent->child) + parent->child = parent->last_child = r; + else + parent->last_child->next = r; + parent->last_child = r; + } r->which = type; switch(type) { @@ -64,6 +73,10 @@ data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type) r->u.data.len = 0; r->u.data.what = 0; r->u.data.formatted_text = 0; + break; + case DATA1N_variant: + r->u.variant.type = 0; + r->u.variant.value = 0; break; default: logf (LOG_WARN, "data_mk_node_type. bad type = %d\n", type); @@ -85,71 +98,133 @@ void data1_free_tree (data1_handle dh, data1_node *t) (*t->destroy)(t); } -char *data1_insert_string (data1_handle dh, data1_node *res, - NMEM m, const char *str) +data1_node *data1_mk_root (data1_handle dh, NMEM nmem, const char *name) { - int len = strlen(str); + data1_absyn *absyn = data1_get_absyn (dh, name); + data1_node *res; + if (!absyn) + { + yaz_log(LOG_WARN, "Unable to acquire abstract syntax " "for '%s'", + name); + /* It's now OK for a record not to have an absyn */ + } + res = data1_mk_node (dh, nmem, DATA1N_root, 0); + res->u.root.type = data1_insert_string (dh, res, nmem, name); + res->u.root.absyn = absyn; + return res; +} + +data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem, + const char *tag, size_t len, data1_node *at) +{ + data1_node *partag = get_parent_tag(dh, at); + data1_node *res = data1_mk_node (dh, nmem, DATA1N_tag, at); + data1_element *e = NULL; + + res->u.tag.tag = data1_insert_string_n (dh, res, nmem, tag, len); + + if (partag) + e = partag->u.tag.element; + res->u.tag.element = + data1_getelementbytagname (dh, at->root->u.root.absyn, + e, res->u.tag.tag); + return res; +} +data1_node *data1_mk_tag (data1_handle dh, NMEM nmem, + const char *tag, data1_node *at) +{ + return data1_mk_tag_n (dh, nmem, tag, strlen(tag), at); +} + +data1_node *data1_search_tag (data1_handle dh, data1_node *n, + const char *tag) +{ + for (; n; n = n->next) + if (n->which == DATA1N_tag && n->u.tag.tag && + !yaz_matchstr (tag, n->u.tag.tag)) + { + return n; + } + return 0; +} + +data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem, + const char *tag, data1_node *at) +{ + data1_node *node = data1_search_tag (dh, at->child, tag); + if (!node) + node = data1_mk_tag (dh, nmem, tag, at); + return node; +} + + +data1_node *data1_mk_text_n (data1_handle dh, NMEM mem, + const char *buf, size_t len, data1_node *parent) +{ + data1_node *res = data1_mk_node (dh, mem, DATA1N_data, parent); + res->u.data.what = DATA1I_text; + res->u.data.len = len; + + res->u.data.data = data1_insert_string_n (dh, res, mem, buf, len); + return res; +} + + +data1_node *data1_mk_text (data1_handle dh, NMEM mem, + const char *buf, data1_node *parent) +{ + return data1_mk_text_n (dh, mem, buf, strlen(buf), parent); +} + +char *data1_insert_string_n (data1_handle dh, data1_node *res, + NMEM m, const char *str, size_t len) +{ + char *b; if (len >= DATA1_LOCALDATA) - return nmem_strdup (m, str); + b = nmem_malloc (m, len+1); else - { - strcpy (res->lbuf, str); - return res->lbuf; - } + b = res->lbuf; + memcpy (b, str, len); + b[len] = 0; + return b; +} + +char *data1_insert_string (data1_handle dh, data1_node *res, + NMEM m, const char *str) +{ + return data1_insert_string_n (dh, res, m, str, strlen(str)); } -data1_node *data1_add_insert_taggeddata(data1_handle dh, data1_node *root, - data1_node *at, - const char *tagname, NMEM m, - int first_flag, int local_allowed) +static data1_node *data1_add_insert_taggeddata(data1_handle dh, + data1_node *root, + data1_node *at, + const char *tagname, NMEM m, + int local_allowed) { data1_node *partag = get_parent_tag (dh, at); - data1_node *tagn = data1_mk_node_type (dh, m, DATA1N_tag); data1_element *e = NULL; - data1_node *datn; - - tagn->u.tag.tag = data1_insert_string (dh, tagn, m, tagname); + data1_node *datn = 0; + data1_node *tagn = 0; if (partag) e = partag->u.tag.element; - tagn->u.tag.element = - data1_getelementbytagname (dh, root->u.root.absyn, e, tagname); - if (!local_allowed && !tagn->u.tag.element) - return NULL; - tagn->last_child = tagn->child = datn = data1_mk_node_type (dh, m, DATA1N_data); - tagn->root = root; - datn->parent = tagn; - datn->root = root; - datn->u.data.formatted_text = 0; - tagn->parent = at; - - if (first_flag) - { - tagn->next = at->child; - if (!tagn->next) - at->last_child = tagn; - at->child = tagn; - } - else + e = data1_getelementbytagname (dh, root->u.root.absyn, e, tagname); + if (local_allowed || e) { - if (!at->child) - at->child = tagn; - else - { - assert (at->last_child); - at->last_child->next = tagn; - } - at->last_child = tagn; + tagn = data1_mk_node (dh, m, DATA1N_tag, at); + tagn->u.tag.tag = data1_insert_string (dh, tagn, m, tagname); + tagn->u.tag.element = e; + datn = data1_mk_node (dh, m, DATA1N_data, tagn); } return datn; } -data1_node *data1_add_taggeddata(data1_handle dh, data1_node *root, - data1_node *at, - const char *tagname, NMEM m) +data1_node *data1_mk_tag_data(data1_handle dh, data1_node *root, + data1_node *at, + const char *tagname, NMEM m) { - return data1_add_insert_taggeddata (dh, root, at, tagname, m, 0, 1); + return data1_add_insert_taggeddata (dh, root, at, tagname, m, 1); } @@ -158,13 +233,91 @@ data1_node *data1_add_taggeddata(data1_handle dh, data1_node *root, * which should be root or tag itself). Returns pointer to the data node, * which can then be modified. */ -data1_node *data1_insert_taggeddata(data1_handle dh, data1_node *root, - data1_node *at, - const char *tagname, NMEM m) +data1_node *data1_mk_tag_data_wd(data1_handle dh, data1_node *root, + data1_node *at, + const char *tagname, NMEM m) +{ + return data1_add_insert_taggeddata (dh, root, at, tagname, m, 0); +} + + +data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at, + const char *tag, int num, + NMEM nmem) +{ + data1_node *node_data; + + node_data = data1_mk_tag_data (dh, at->root, at, tag, nmem); + if (!node_data) + return 0; + node_data->u.data.what = DATA1I_num; + node_data->u.data.data = node_data->lbuf; + sprintf (node_data->u.data.data, "%d", num); + node_data->u.data.len = strlen (node_data->u.data.data); + return node_data; +} + +data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at, + const char *tag, Odr_oid *oid, + NMEM nmem) +{ + data1_node *node_data; + char str[128], *p = str; + Odr_oid *ii; + + node_data = data1_mk_tag_data (dh, at->root, at, tag, nmem); + if (!node_data) + return 0; + + for (ii = oid; *ii >= 0; ii++) + { + if (ii != oid) + *p++ = '.'; + sprintf (p, "%d", *ii); + p += strlen (p); + } + node_data->u.data.what = DATA1I_oid; + node_data->u.data.len = strlen (str); + node_data->u.data.data = data1_insert_string (dh, node_data, nmem, str); + return node_data; +} + + +data1_node *data1_mk_tag_data_text (data1_handle dh, data1_node *at, + const char *tag, const char *str, + NMEM nmem) +{ + data1_node *node_data; + + node_data = data1_mk_tag_data (dh, at->root, at, tag, nmem); + if (!node_data) + return 0; + node_data->u.data.what = DATA1I_text; + node_data->u.data.len = strlen (str); + node_data->u.data.data = data1_insert_string (dh, node_data, nmem, str); + return node_data; +} + + +data1_node *data1_mk_tag_data_text_uni (data1_handle dh, data1_node *at, + const char *tag, const char *str, + NMEM nmem) { - return data1_add_insert_taggeddata (dh, root, at, tagname, m, 1, 0); + data1_node *node = data1_search_tag (dh, at->child, tag); + if (!node) + return data1_mk_tag_data_text (dh, at, tag, str, nmem); + else + { + data1_node *node_data = node->child; + node_data->u.data.what = DATA1I_text; + node_data->u.data.len = strlen (str); + node_data->u.data.data = data1_insert_string (dh, node_data, + nmem, str); + return node_data; + } } + #if DATA1_USING_XATTR data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, int (*get_byte)(void *fh), void *fh, @@ -238,7 +391,6 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, data1_node *data1_read_nodex (data1_handle dh, NMEM m, int (*get_byte)(void *fh), void *fh, WRBUF wrbuf) { - data1_absyn *absyn = 0; data1_node *d1_stack[256]; data1_node *res; int c; @@ -348,15 +500,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, } if (level == 0) /* root ? */ { - if (!(absyn = data1_get_absyn (dh, tag))) - { - yaz_log(LOG_WARN, "Unable to acquire abstract syntax " "for '%s'", tag); - /* It's now OK for a record not to have an absyn */ - } - res = data1_mk_node_type (dh, m, DATA1N_root); - res->u.root.type = data1_insert_string (dh, res, m, tag); - res->u.root.absyn = absyn; - res->root = res; + res = data1_mk_root (dh, m, tag); } else if (!strcmp(tag, "var")) { @@ -380,10 +524,7 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, */ if (parent->which != DATA1N_variant) { - res = data1_mk_node (dh, m); - res->which = DATA1N_variant; - res->u.variant.type = 0; - res->u.variant.value = 0; + res = data1_mk_node (dh, m, DATA1N_variant, parent); } else { @@ -398,43 +539,14 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, level = i; break; } - res = data1_mk_node (dh, m); - res->which = DATA1N_variant; + res = data1_mk_node (dh, m, DATA1N_variant, parent); res->u.variant.type = tp; res->u.variant.value = data1_insert_string (dh, res, m, args + val_offset); } } else /* tag.. acquire our element in the abstract syntax */ - { - data1_node *partag = get_parent_tag (dh, parent); - data1_element *elem, *e = 0; - int localtag = 0; - - if (parent->which == DATA1N_variant) - return 0; - if (partag) - if (!(e = partag->u.tag.element)) - localtag = 1; /* our parent is a local tag */ - - elem = data1_getelementbytagname(dh, absyn, e, tag); - res = data1_mk_node_type (dh, m, DATA1N_tag); - res->u.tag.tag = data1_insert_string (dh, res, m, tag); - res->u.tag.element = elem; -#if DATA1_USING_XATTR - res->u.tag.attributes = xattr; -#endif - } - if (parent) - { - parent->last_child = res; - res->root = parent->root; - } - res->parent = parent; - if (d1_stack[level]) - d1_stack[level]->next = res; - else if (parent) - parent->child = res; + res = data1_mk_tag (dh, m, tag, parent); d1_stack[level] = res; d1_stack[level+1] = 0; if (level < 250 && !null_tag) @@ -451,16 +563,9 @@ data1_node *data1_read_nodex (data1_handle dh, NMEM m, c = (*get_byte)(fh); continue; } - res = data1_mk_node_type (dh, m, DATA1N_data); - res->parent = parent; + res = data1_mk_node (dh, m, DATA1N_data, parent); res->u.data.what = DATA1I_text; res->u.data.formatted_text = 0; - res->root = parent->root; - parent->last_child = res; - if (d1_stack[level]) - d1_stack[level]->next = res; - else - parent->child = res; d1_stack[level] = res; wrbuf_rewind(wrbuf); diff --git a/retrieval/d1_sutrs.c b/retrieval/d1_sutrs.c index 7cf3e1f..2117408 100644 --- a/retrieval/d1_sutrs.c +++ b/retrieval/d1_sutrs.c @@ -1,27 +1,9 @@ /* - * Copyright (c) 1995-1997, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: d1_sutrs.c,v $ - * Revision 1.6 1999-11-30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.5 1999/10/21 12:06:29 adam - * Retrieval module no longer uses ctype.h - functions. - * - * Revision 1.4 1997/09/17 12:10:38 adam - * YAZ version 1.4. - * - * Revision 1.3 1995/12/15 16:57:11 quinn - * Added formatted-text. - * - * Revision 1.2 1995/11/01 13:54:49 quinn - * Minor adjustments - * - * Revision 1.1 1995/11/01 11:56:09 quinn - * Added Retrieval (data management) functions en masse. - * + * $Id: d1_sutrs.c,v 1.7 2002-05-03 13:48:27 adam Exp $ * */ @@ -30,12 +12,12 @@ #define NTOBUF_INDENT 2 #define NTOBUF_MARGIN 75 -static int wordlen(char *b) +static int wordlen(char *b, int i) { int l = 0; - while (*b && !d1_isspace(*b)) - l++, b++; + while (i && !d1_isspace(*b)) + l++, b++, i--; return l; } @@ -92,7 +74,7 @@ static int nodetobuf(data1_node *n, int select, WRBUF b, int indent, int col) if (!l) break; /* break if we'll cross margin and word is not too long */ - if (col + (wlen = wordlen(p)) > NTOBUF_MARGIN && wlen < + if (col + (wlen = wordlen(p, l)) > NTOBUF_MARGIN && wlen < NTOBUF_MARGIN - indent * NTOBUF_INDENT) { sprintf(line, "\n%*s", indent * NTOBUF_INDENT, ""); -- 1.7.10.4