From 02d2f2409c58ab49ab535758d85d70fae0f651f4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 10 Jun 2011 14:01:26 +0200 Subject: [PATCH] Add cql_to_ccl_buf --- include/yaz/cql.h | 9 +++++++++ src/cql2ccl.c | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/yaz/cql.h b/include/yaz/cql.h index 817e04b..148a9e0 100644 --- a/include/yaz/cql.h +++ b/include/yaz/cql.h @@ -260,6 +260,15 @@ int cql_to_ccl(struct cql_node *cn, YAZ_EXPORT void cql_to_ccl_stdio(struct cql_node *cn, FILE *f); +/** \brief converts CQL tree to CCL and writes result to buffer + \param cn CQL node (tree) + \param out buffer + \param max size of buffer (max chars to write) + \returns length of resulting buffer + */ +YAZ_EXPORT +int cql_to_ccl_buf(struct cql_node *cn, char *out, int max); + /** \brief stream handle for file (used by cql_to_xml_stdio) */ YAZ_EXPORT void cql_fputs(const char *buf, void *client_data); diff --git a/src/cql2ccl.c b/src/cql2ccl.c index 5f2011b..90ee5d6 100644 --- a/src/cql2ccl.c +++ b/src/cql2ccl.c @@ -168,7 +168,17 @@ void cql_to_ccl_stdio(struct cql_node *cn, FILE *f) cql_to_ccl(cn, cql_fputs, f); } - +int cql_to_ccl_buf(struct cql_node *cn, char *out, int max) +{ + struct cql_buf_write_info info; + info.off = 0; + info.max = max; + info.buf = out; + cql_to_ccl(cn, cql_buf_write_handler, &info); + if (info.off >= 0) + info.buf[info.off] = '\0'; + return info.off; +} /* * Local variables: -- 1.7.10.4