[Gnucash-changes] r12198 - gnucash/trunk - Use glib's g_iconv functions instead of the system's iconv(3)

Christian Stimming cstim at cvs.gnucash.org
Thu Dec 29 16:25:02 EST 2005


Author: cstim
Date: 2005-12-29 16:25:00 -0500 (Thu, 29 Dec 2005)
New Revision: 12198
Trac: http://svn.gnucash.org/trac/changeset/12198

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/import-export/hbci/dialog-hbcitrans.c
   gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.c
   gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.h
   gnucash/trunk/src/import-export/hbci/hbci-interaction.c
   gnucash/trunk/src/import-export/hbci/hbci-interactionP.h
Log:
Use glib's g_iconv functions instead of the system's iconv(3)
functions to improve portability.



Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2005-12-29 05:21:02 UTC (rev 12197)
+++ gnucash/trunk/ChangeLog	2005-12-29 21:25:00 UTC (rev 12198)
@@ -1,3 +1,9 @@
+2005-12-29  Christian Stimming  <stimming at tuhh.de>
+
+	* src/import-export/hbci/gnc-hbci-utils.h, gnc-hbci-utils.c: Use
+	glib's g_iconv functions instead of the system's iconv(3)
+	functions to improve portability.
+
 2005-12-28  David Hampton  <hampton at employees.org>
 
 	* src/glib-compat.h:

Modified: gnucash/trunk/src/import-export/hbci/dialog-hbcitrans.c
===================================================================
--- gnucash/trunk/src/import-export/hbci/dialog-hbcitrans.c	2005-12-29 05:21:02 UTC (rev 12197)
+++ gnucash/trunk/src/import-export/hbci/dialog-hbcitrans.c	2005-12-29 21:25:00 UTC (rev 12198)
@@ -581,9 +581,9 @@
      to be fixed for the gnome2 version; the source encoding is then
      probably utf-8 as well. iconv is also used in
      gnc_AB_BANKING_interactors() in hbci-interaction.c. */
-  iconv_t gnc_iconv_handler =
-    iconv_open(gnc_hbci_AQBANKING_encoding(), gnc_hbci_book_encoding());
-  g_assert(gnc_iconv_handler != (iconv_t)(-1));
+  GIConv gnc_iconv_handler =
+    g_iconv_open(gnc_hbci_AQBANKING_encoding(), gnc_hbci_book_encoding());
+  g_assert(gnc_iconv_handler != (GIConv)(-1));
 	
   /* OpenHBCI newer than 0.9.8: use account's bankCode values
    * instead of the bank's ones since this is what some banks
@@ -649,7 +649,7 @@
     AB_Transaction_SetTextKey (trans, 51);
   }
 
-  iconv_close(gnc_iconv_handler);
+  g_iconv_close(gnc_iconv_handler);
   return trans;
 }
 

Modified: gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.c
===================================================================
--- gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.c	2005-12-29 05:21:02 UTC (rev 12197)
+++ gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.c	2005-12-29 21:25:00 UTC (rev 12198)
@@ -498,7 +498,7 @@
 
 struct cb_struct {
   gchar **result;
-  iconv_t gnc_iconv_handler;
+  GIConv gnc_iconv_handler;
 };
 
 /* Needed for the gnc_hbci_descr_tognc and gnc_hbci_memo_tognc. */
@@ -540,8 +540,8 @@
   struct cb_struct cb_object;
 
   cb_object.gnc_iconv_handler = 
-    iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
-  g_assert(cb_object.gnc_iconv_handler != (iconv_t)(-1));
+    g_iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
+  g_assert(cb_object.gnc_iconv_handler != (GIConv)(-1));
 
   /* Get othername */
   cb_object.result = &othername;
@@ -564,7 +564,7 @@
        g_strdup (h_descr) : 
        g_strdup (_("Unspecified")));
 
-  iconv_close(cb_object.gnc_iconv_handler);
+  g_iconv_close(cb_object.gnc_iconv_handler);
   free (h_descr);
   free (othername);
   return g_descr;
@@ -579,8 +579,8 @@
   struct cb_struct cb_object;
 
   cb_object.gnc_iconv_handler = 
-    iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
-  g_assert(cb_object.gnc_iconv_handler != (iconv_t)(-1));
+    g_iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
+  g_assert(cb_object.gnc_iconv_handler != (GIConv)(-1));
 
   cb_object.result = &h_descr;
   if (h_purpose)
@@ -590,7 +590,7 @@
 
   g_descr = g_strdup (h_descr ? h_descr : "");
 
-  iconv_close(cb_object.gnc_iconv_handler);
+  g_iconv_close(cb_object.gnc_iconv_handler);
   free (h_descr);
   return g_descr;
 }
@@ -898,19 +898,26 @@
   return g_strdup(tmp);
 }
 
+/* Note: In the gnome2-branch we don't need the iconv(3) conversion
+   and gnc_call_iconv() anymore since the gnc_book has an UTF-8
+   encoding and the AqBanking library also expects all strings in
+   UTF-8. Nevertheless we keep all these functions for now, just in
+   case they might be needed later.
+*/
+
 /* Returns a newly allocated gchar, converted according to the given
    handler */
-gchar *gnc_call_iconv(iconv_t handler, const char* input)
+gchar *gnc_call_iconv(GIConv handler, const gchar* input)
 {
-  char *inbuffer = (char*)input;
-  char *outbuffer, *outbufferstart;
-  size_t inbytes, outbytes;
+  gchar *inbuffer = (gchar*)input;
+  gchar *outbuffer, *outbufferstart;
+  gsize inbytes, outbytes;
 
   inbytes = strlen(inbuffer);
   outbytes = inbytes + 2;
   outbufferstart = g_strndup(inbuffer, outbytes);
   outbuffer = outbufferstart;
-  iconv(handler, &inbuffer, &inbytes, &outbuffer, &outbytes);
+  g_iconv(handler, &inbuffer, &inbytes, &outbuffer, &outbytes);
   if (outbytes > 0) 
     *outbuffer = '\0';
   return outbufferstart;

Modified: gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.h
===================================================================
--- gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.h	2005-12-29 05:21:02 UTC (rev 12197)
+++ gnucash/trunk/src/import-export/hbci/gnc-hbci-utils.h	2005-12-29 21:25:00 UTC (rev 12198)
@@ -153,7 +153,7 @@
 
 /** Returns a newly allocated gchar, converted according to the given
    handler */
-gchar *gnc_call_iconv(iconv_t handler, const char* input);
+gchar *gnc_call_iconv(GIConv handler, const gchar* input);
 
 /** Returns the encoding of the current book in the format as required
     by iconv_open(3). */

Modified: gnucash/trunk/src/import-export/hbci/hbci-interaction.c
===================================================================
--- gnucash/trunk/src/import-export/hbci/hbci-interaction.c	2005-12-29 05:21:02 UTC (rev 12197)
+++ gnucash/trunk/src/import-export/hbci/hbci-interaction.c	2005-12-29 21:25:00 UTC (rev 12198)
@@ -60,8 +60,8 @@
      then probably utf-8 as well. iconv is also used in
      gnc_hbci_descr_tognc() in gnc-hbci-utils.c. */
   data->gnc_iconv_handler = 
-    iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
-  g_assert(data->gnc_iconv_handler != (iconv_t)(-1));
+    g_iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
+  g_assert(data->gnc_iconv_handler != (GIConv)(-1));
   data->keepAlive = TRUE;
   data->cache_pin = 
     gnc_gconf_get_bool(GCONF_SECTION, KEY_REMEMBER_PIN, NULL);
@@ -90,7 +90,7 @@
   data->dialog = NULL;
 
   g_hash_table_destroy(data->showbox_hash);
-  iconv_close(data->gnc_iconv_handler);
+  g_iconv_close(data->gnc_iconv_handler);
 
   g_free (data);
 }

Modified: gnucash/trunk/src/import-export/hbci/hbci-interactionP.h
===================================================================
--- gnucash/trunk/src/import-export/hbci/hbci-interactionP.h	2005-12-29 05:21:02 UTC (rev 12197)
+++ gnucash/trunk/src/import-export/hbci/hbci-interactionP.h	2005-12-29 21:25:00 UTC (rev 12198)
@@ -60,7 +60,7 @@
   const char *format_pin_min_char;
 
   /* The iconv handler for utf8 -> latin1 conversion */
-  iconv_t gnc_iconv_handler;
+  GIConv gnc_iconv_handler;
 
   /* Flags to keep track on whether an HBCI action is running or
      not. */



More information about the gnucash-changes mailing list