changeset 120:ecbc8cabd6a2

Initial work on iconv support.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 17 Feb 2016 09:23:20 +0200
parents 431aa2c00c45
children a2c2c63311de
files sidinfo.c
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Wed Feb 17 09:01:12 2016 +0200
+++ b/sidinfo.c	Wed Feb 17 09:23:20 2016 +0200
@@ -7,9 +7,11 @@
 #include "th_string.h"
 #include "th_file.h"
 #include "sidlib.h"
+#include <iconv.h>
 
 
 // Some constants
+#define SET_DEF_CHARSET "utf-8"
 #define SET_SLDB_FILENAME "Songlengths.txt"
 
 enum
@@ -88,6 +90,9 @@
 
 SIDLibSLDB *sidSLDB = NULL;
 
+BOOL    setUseChConv;
+iconv_t setChConv;
+
 
 // Define option arguments
 static const th_optarg_t optList[] =
@@ -568,12 +573,25 @@
 
 int main(int argc, char *argv[])
 {
+    char *setLang = th_strdup(getenv("LANG"));
+
     // Initialize
     th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL);
     th_verbosityLevel = 0;
 
     memset(&optFormat, 0, sizeof(optFormat));
 
+    // Initialize iconv, check if we have language/charset
+    if (setLang != NULL)
+    {
+        char *ptr = strchr(setLang, '.');
+        if (ptr != NULL) strcpy(setLang, ptr + 1);
+    }
+
+    setChConv = iconv_open("iso88591", setLang != NULL ? setLang : SET_DEF_CHARSET);
+    setUseChConv = setChConv != (iconv_t) -1;
+    th_free(setLang);
+
     // Parse command line arguments
     if (!th_args_process(argc, argv, optList, optListN,
         argHandleOpt, argHandleFile, OPTH_ONLY_OPTS))
@@ -656,6 +674,9 @@
 
 out:
 
+    if (setUseChConv)
+        iconv_close(setChConv);
+
     th_free(setHVSCPath);
     th_free(setSLDBPath);
     si_sldb_free(sidSLDB);