From: Adam Dickmeiss Date: Fri, 10 Jun 2011 12:01:26 +0000 (+0200) Subject: Add cql_to_ccl_buf X-Git-Tag: v4.2.2~3 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=02d2f2409c58ab49ab535758d85d70fae0f651f4;p=yaz-moved-to-github.git Add cql_to_ccl_buf --- 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: