From 42b9e1d0ec4a98637b142d127765f28ecd86b64b Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 26 Jul 2004 12:20:06 +0000 Subject: [PATCH] Simplify XML attribute node creation (xattr). Add data1 utilities data1_insert_preprocess, data1_insert_preprocess_n. --- data1/d1_read.c | 75 ++++++++++++++++++++++++++++++------------------------- include/data1.h | 15 +++++++++-- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/data1/d1_read.c b/data1/d1_read.c index 4fb3ecb..c1e8860 100644 --- a/data1/d1_read.c +++ b/data1/d1_read.c @@ -1,4 +1,4 @@ -/* $Id: d1_read.c,v 1.6 2004-05-25 10:21:25 adam Exp $ +/* $Id: d1_read.c,v 1.7 2004-07-26 12:20:07 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -213,6 +213,24 @@ void data1_set_root(data1_handle dh, data1_node *res, res->u.root.absyn = absyn; } +void data1_add_attrs(data1_handle dh, NMEM nmem, const char **attr, + data1_xattr **p) +{ + while (*p) + p = &(*p)->next; + + while (attr && *attr) + { + *p = (data1_xattr*) nmem_malloc (nmem, sizeof(**p)); + (*p)->name = nmem_strdup (nmem, *attr++); + (*p)->value = nmem_strdup (nmem, *attr++); + (*p)->what = DATA1I_text; + + p = &(*p)->next; + } + *p = 0; +} + data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem, const char *target, const char **attr, data1_node *at) @@ -225,22 +243,31 @@ data1_node *data1_mk_preprocess_n (data1_handle dh, NMEM nmem, const char *target, size_t len, const char **attr, data1_node *at) { - data1_xattr **p; data1_node *res = data1_mk_node2 (dh, nmem, DATA1N_preprocess, at); res->u.preprocess.target = data1_insert_string_n (dh, res, nmem, target, len); - p = &res->u.preprocess.attributes; - while (attr && *attr) - { - *p = (data1_xattr*) nmem_malloc (nmem, sizeof(**p)); - (*p)->name = nmem_strdup (nmem, *attr++); - (*p)->value = nmem_strdup (nmem, *attr++); - (*p)->what = DATA1I_text; + data1_add_attrs(dh, nmem, attr, &res->u.preprocess.attributes); + return res; +} - p = &(*p)->next; - } - *p = 0; +data1_node *data1_insert_preprocess (data1_handle dh, NMEM nmem, + const char *target, + const char **attr, data1_node *at) +{ + return data1_insert_preprocess_n (dh, nmem, target, strlen(target), + attr, at); +} + +data1_node *data1_insert_preprocess_n (data1_handle dh, NMEM nmem, + const char *target, size_t len, + const char **attr, data1_node *at) +{ + data1_node *res = data1_insert_node (dh, nmem, DATA1N_preprocess, at); + res->u.preprocess.target = data1_insert_string_n (dh, res, nmem, + target, len); + + data1_add_attrs(dh, nmem, attr, &res->u.preprocess.attributes); return res; } @@ -250,7 +277,6 @@ data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem, { data1_node *partag = get_parent_tag(dh, at); data1_node *res = data1_mk_node2 (dh, nmem, DATA1N_tag, at); - data1_xattr **p; data1_element *e = 0; res->u.tag.tag = data1_insert_string_n (dh, res, nmem, tag, len); @@ -268,16 +294,7 @@ data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem, e, res->u.tag.tag); } res->u.tag.element = e; - p = &res->u.tag.attributes; - while (attr && *attr) - { - *p = (data1_xattr*) nmem_malloc (nmem, sizeof(**p)); - (*p)->name = nmem_strdup (nmem, *attr++); - (*p)->value = nmem_strdup (nmem, *attr++); - (*p)->what = DATA1I_text; - p = &(*p)->next; - } - *p = 0; + data1_add_attrs(dh, nmem, attr, &res->u.tag.attributes); return res; } @@ -290,17 +307,7 @@ void data1_tag_add_attr (data1_handle dh, NMEM nmem, return; p = &res->u.tag.attributes; - while (*p) - p = &(*p)->next; - - while (attr && *attr) - { - *p = (data1_xattr*) nmem_malloc (nmem, sizeof(**p)); - (*p)->name = nmem_strdup (nmem, *attr++); - (*p)->value = nmem_strdup (nmem, *attr++); - (*p)->what = DATA1I_text; - p = &(*p)->next; - } + data1_add_attrs(dh, nmem, attr, p); *p = 0; } diff --git a/include/data1.h b/include/data1.h index bcc9c7e..276bdd5 100644 --- a/include/data1.h +++ b/include/data1.h @@ -1,5 +1,5 @@ -/* $Id: data1.h,v 1.8 2003-06-23 15:36:11 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: data1.h,v 1.9 2004-07-26 12:20:06 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -407,6 +407,17 @@ YAZ_EXPORT data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem, const char **attr, data1_node *at); +YAZ_EXPORT data1_node *data1_insert_preprocess_n (data1_handle dh, NMEM nmem, + const char *target, + size_t len, + const char **attr, + data1_node *at); + +YAZ_EXPORT data1_node *data1_insert_preprocess (data1_handle dh, NMEM nmem, + const char *target, + const char **attr, + data1_node *at); + YAZ_EXPORT data1_node *data1_mk_root (data1_handle dh, NMEM nmem, const char *name); YAZ_EXPORT void data1_set_root(data1_handle dh, data1_node *res, -- 1.7.10.4