# HG changeset patch # User Matti Hamalainen # Date 1455693800 -7200 # Node ID ecbc8cabd6a2e7e18e9f6519631f1908a1003049 # Parent 431aa2c00c45c0e5687650a939dbfd3cca267d04 Initial work on iconv support. diff -r 431aa2c00c45 -r ecbc8cabd6a2 sidinfo.c --- 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 // 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);