Added skeleton for query charset conversion. Bug #977.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 21 Mar 2007 19:47:28 +0000 (19:47 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 21 Mar 2007 19:47:28 +0000 (19:47 +0000)
src/Makefile.am
src/query-charset.c [new file with mode: 0644]
win/makefile

index ab82905..48ed65f 100644 (file)
@@ -1,6 +1,6 @@
 ## This file is part of the YAZ toolkit.
 ## Copyright (C) 1995-2007, Index Data, All rights reserved.
-## $Id: Makefile.am,v 1.54 2007-03-19 13:31:48 adam Exp $
+## $Id: Makefile.am,v 1.55 2007-03-21 19:47:28 adam Exp $
 
 YAZ_VERSION_INFO=3:0:0
 
@@ -80,7 +80,7 @@ libyaz_la_SOURCES=version.c options.c log.c \
   eventl.h service.c service.h session.h test.c timing.c \
   xmlquery.c http.c \
   mime.c mime.h \
-  record_conv.c retrieval.c elementset.c snprintf.c
+  record_conv.c retrieval.c elementset.c snprintf.c query-charset.c
 
 libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO)
 
diff --git a/src/query-charset.c b/src/query-charset.c
new file mode 100644 (file)
index 0000000..2001315
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * 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
+ */
+
index ab48fca..c7c8f33 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright (C) 1995-2007, Index Data ApS
 # All rights reserved.
-# $Id: makefile,v 1.129 2007-02-23 10:15:02 adam Exp $
+# $Id: makefile,v 1.130 2007-03-21 19:47:28 adam Exp $
 #
 # Programmed by
 #  Heikki Levanto & Adam Dickmeiss
@@ -427,6 +427,7 @@ MISC_OBJS= \
    $(OBJDIR)\xcqlutil.obj \
    $(OBJDIR)\elementset.obj \
    $(OBJDIR)\timing.obj \
+   $(OBJDIR)\query-charset.obj \
    $(OBJDIR)\http.obj
 
 Z3950_OBJS= \