--- /dev/null
+/*
+ * Copyright (C) 1995-2007, Index Data ApS
+ * All rights reserved.
+ *
+ * $Id: query-charset.c,v 1.1 2007-03-21 19:47:28 adam Exp $
+ */
+
+/** \file query-charset.c
+ \brief converts General Terms in RPN queries
+ */
+
+#include <stdio.h>
+#include <assert.h>
+
+#include <yaz/proto.h>
+#include <yaz/wrbuf.h>
+#include <yaz/odr.h>
+#include <yaz/yaz-iconv.h>
+
+void yaz_query_charset_convert_buf(char *buf_in, int len_in,
+ char **buf_out, int *len_out,
+ ODR o, WRBUF wrbuf, yaz_iconv_t cd)
+{
+ wrbuf_rewind(wrbuf);
+ wrbuf_iconv_write(wrbuf, cd, buf_in, len_in);
+ wrbuf_iconv_reset(wrbuf, cd);
+
+ *len_out = wrbuf_len(wrbuf);
+ if (*len_out == 0)
+ { // we assume conversion failed
+ *buf_out = buf_in;
+ *len_out = len_in;
+ }
+ else
+ {
+ *buf_out = (char*) odr_malloc(o, *len_out);
+ memcpy(*buf_out, wrbuf_buf(wrbuf), *len_out);
+ }
+}
+
+void yaz_query_charset_convert_term(Z_Term *q,
+ ODR o, WRBUF wrbuf, yaz_iconv_t cd)
+{
+ switch(q->which)
+ {
+ case Z_Term_general:
+ yaz_query_charset_convert_buf(
+ (char *) q->u.general->buf, q->u.general->len,
+ (char **) &q->u.general->buf, &q->u.general->len, o, wrbuf, cd);
+ break;
+ }
+}
+
+void yaz_query_charset_convert_operand(Z_Operand *q,
+ ODR o, WRBUF wrbuf, yaz_iconv_t cd)
+{
+ switch(q->which)
+ {
+ case Z_Operand_APT:
+ yaz_query_charset_convert_term(q->u.attributesPlusTerm->term,
+ o, wrbuf, cd);
+ break;
+ case Z_Operand_resultSetId:
+ break;
+ case Z_Operand_resultAttr:
+ break;
+ }
+}
+
+void yaz_query_charset_convert_structure(Z_RPNStructure *q,
+ ODR o, WRBUF wrbuf, yaz_iconv_t cd)
+{
+ switch(q->which)
+ {
+ case Z_RPNStructure_simple:
+ yaz_query_charset_convert_operand(q->u.simple, o, wrbuf, cd);
+ break;
+ case Z_RPNStructure_complex:
+ yaz_query_charset_convert_structure(q->u.complex->s1, o, wrbuf, cd);
+ yaz_query_charset_convert_structure(q->u.complex->s2, o, wrbuf, cd);
+ break;
+ }
+}
+
+void yaz_query_charset_convert_rpnquery(Z_RPNQuery *q,
+ ODR o, yaz_iconv_t cd)
+{
+ WRBUF wrbuf = wrbuf_alloc();
+ yaz_query_charset_convert_structure(q->RPNStructure, o, wrbuf, cd);
+ wrbuf_destroy(wrbuf);
+}
+
+void yaz_query_charset_convert_apt(Z_AttributesPlusTerm *apt,
+ ODR o, yaz_iconv_t cd)
+{
+ WRBUF wrbuf = wrbuf_alloc();
+ yaz_query_charset_convert_term(apt->term, o, wrbuf, cd);
+ wrbuf_destroy(wrbuf);
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+