Cast to unsigned char for ctype is.. compare
[idzebra-moved-to-github.git] / recctrl / recgrs.c
index 41b873c..0f11bd6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: recgrs.c,v 1.93 2004-11-19 10:27:12 heikki Exp $
+/* $Id: recgrs.c,v 1.96 2004-12-21 22:02:28 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <dlfcn.h>
 #endif
 
-#include <yaz/ylog.h>
+#include <yaz/log.h>
 #include <yaz/oid.h>
 
 #include <d1_absyn.h>
@@ -900,7 +900,8 @@ int zebra_grs_extract(void *clientData, struct recExtractCtrl *p,
 /*
  * Return: -1: Nothing done. 0: Ok. >0: Bib-1 diagnostic.
  */
-static int process_comp(data1_handle dh, data1_node *n, Z_RecordComposition *c)
+static int process_comp(data1_handle dh, data1_node *n, Z_RecordComposition *c,
+                       char **addinfo, ODR o)
 {
     data1_esetname *eset;
     Z_Espec1 *espec = 0;
@@ -915,6 +916,7 @@ static int process_comp(data1_handle dh, data1_node *n, Z_RecordComposition *c)
                                         c->u.simple->u.generic)))
        {
            yaz_log(YLOG_LOG, "Unknown esetname '%s'", c->u.simple->u.generic);
+           *addinfo = odr_strdup(o, c->u.simple->u.generic);
            return 25; /* invalid esetname */
        }
        yaz_log(YLOG_DEBUG, "Esetname '%s' in simple compspec",
@@ -934,8 +936,9 @@ static int process_comp(data1_handle dh, data1_node *n, Z_RecordComposition *c)
                          data1_getesetbyname(dh, n->u.root.absyn,
                                              p->u.elementSetName)))
                    {
-                       yaz_log(YLOG_LOG, "Unknown esetname '%s'",
+                       yaz_log(YLOG_DEBUG, "Unknown esetname '%s'",
                             p->u.elementSetName);
+                       *addinfo = odr_strdup(o, p->u.elementSetName);
                        return 25; /* invalid esetname */
                    }
                    yaz_log(YLOG_DEBUG, "Esetname '%s' in complex compspec",
@@ -1056,9 +1059,6 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
     }
     data1_concat_text(p->dh, mem, node);
 
-    /* ensure our data1 tree is UTF-8 */
-    data1_iconv (p->dh, mem, node, "UTF-8", data1_get_encoding(p->dh, node));
-
 #if 0
     data1_pr_tree (p->dh, node, stdout);
 #endif
@@ -1105,7 +1105,6 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
 #if 0
     data1_pr_tree (p->dh, node, stdout);
 #endif
-#if YAZ_VERSIONL >= 0x010903L
     if (p->comp && p->comp->which == Z_RecordComp_complex &&
        p->comp->u.complex->generic &&
         p->comp->u.complex->generic->which == Z_Schema_oid &&
@@ -1115,16 +1114,6 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
        if (oe)
            requested_schema = oe->value;
     }
-#else
-    if (p->comp && p->comp->which == Z_RecordComp_complex &&
-       p->comp->u.complex->generic && p->comp->u.complex->generic->schema)
-    {
-       oident *oe = oid_getentbyoid (p->comp->u.complex->generic->schema);
-       if (oe)
-           requested_schema = oe->value;
-    }
-#endif
-
     /* If schema has been specified, map if possible, then check that
      * we got the right one 
      */
@@ -1213,7 +1202,8 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
     }
 
     yaz_log(YLOG_DEBUG, "grs_retrieve: element spec");
-    if (p->comp && (res = process_comp(p->dh, node, p->comp)) > 0)
+    if (p->comp && (res = process_comp(p->dh, node, p->comp, &p->addinfo,
+                                      p->odr)) > 0)
     {
        p->diagnostic = res;
        if (onode)
@@ -1233,13 +1223,13 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
                                p->input_format : VAL_SUTRS))
     {
     case VAL_TEXT_XML:
-
 #if 0
         data1_pr_tree (p->dh, node, stdout);
 #endif
-
-        if (p->encoding)
-            data1_iconv (p->dh, mem, node, p->encoding, "UTF-8");
+       /* default output encoding for XML is UTF-8 */
+       data1_iconv (p->dh, mem, node,
+                    p->encoding ? p->encoding : "UTF-8",
+                    data1_get_encoding(p->dh, node));
 
        if (!(p->rec_buf = data1_nodetoidsgml(p->dh, node, selected,
                                              &p->rec_len)))
@@ -1252,6 +1242,7 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
        }
        break;
     case VAL_GRS1:
+       data1_iconv (p->dh, mem, node, "UTF-8", data1_get_encoding(p->dh, node));
        dummy = 0;
        if (!(p->rec_buf = data1_nodetogr(p->dh, node, selected,
                                          p->odr, &dummy)))
@@ -1260,6 +1251,9 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
            p->rec_len = (size_t) (-1);
        break;
     case VAL_EXPLAIN:
+       /* ensure our data1 tree is UTF-8 */
+       data1_iconv (p->dh, mem, node, "UTF-8", data1_get_encoding(p->dh, node));
+       
        if (!(p->rec_buf = data1_nodetoexplain(p->dh, node, selected,
                                               p->odr)))
            p->diagnostic = 238;
@@ -1267,6 +1261,8 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
            p->rec_len = (size_t) (-1);
        break;
     case VAL_SUMMARY:
+       /* ensure our data1 tree is UTF-8 */
+       data1_iconv (p->dh, mem, node, "UTF-8", data1_get_encoding(p->dh, node));
        if (!(p->rec_buf = data1_nodetosummary(p->dh, node, selected,
                                               p->odr)))
            p->diagnostic = 238;
@@ -1274,8 +1270,9 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
            p->rec_len = (size_t) (-1);
        break;
     case VAL_SUTRS:
-        if (p->encoding)
-            data1_iconv (p->dh, mem, node, p->encoding, "UTF-8");
+       if (p->encoding)
+            data1_iconv (p->dh, mem, node, p->encoding,
+                        data1_get_encoding(p->dh, node));
        if (!(p->rec_buf = data1_nodetobuf(p->dh, node, selected,
                                           &p->rec_len)))
            p->diagnostic = 238;
@@ -1287,6 +1284,9 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
        }
        break;
     case VAL_SOIF:
+       if (p->encoding)
+            data1_iconv (p->dh, mem, node, p->encoding,
+                        data1_get_encoding(p->dh, node));
        if (!(p->rec_buf = data1_nodetosoif(p->dh, node, selected,
                                            &p->rec_len)))
            p->diagnostic = 238;
@@ -1312,8 +1312,9 @@ int zebra_grs_retrieve(void *clientData, struct recRetrieveCtrl *p,
            p->diagnostic = 238;
            break;
        }
-        if (p->encoding)
-            data1_iconv (p->dh, mem, node, p->encoding, "UTF-8");
+       if (p->encoding)
+            data1_iconv (p->dh, mem, node, p->encoding,
+                        data1_get_encoding(p->dh, node));
        if (!(p->rec_buf = data1_nodetomarc(p->dh, marctab, node,
                                        selected, &p->rec_len)))
            p->diagnostic = 238;