comparison sidinfo.c @ 120:ecbc8cabd6a2

Initial work on iconv support.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 17 Feb 2016 09:23:20 +0200
parents 24583e5ca0b3
children a2c2c63311de
comparison
equal deleted inserted replaced
119:431aa2c00c45 120:ecbc8cabd6a2
5 */ 5 */
6 #include "th_args.h" 6 #include "th_args.h"
7 #include "th_string.h" 7 #include "th_string.h"
8 #include "th_file.h" 8 #include "th_file.h"
9 #include "sidlib.h" 9 #include "sidlib.h"
10 #include <iconv.h>
10 11
11 12
12 // Some constants 13 // Some constants
14 #define SET_DEF_CHARSET "utf-8"
13 #define SET_SLDB_FILENAME "Songlengths.txt" 15 #define SET_SLDB_FILENAME "Songlengths.txt"
14 16
15 enum 17 enum
16 { 18 {
17 OTYPE_OTHER = 0, 19 OTYPE_OTHER = 0,
85 int optNFiles = 0; 87 int optNFiles = 0;
86 88
87 PSFStack optFormat; 89 PSFStack optFormat;
88 90
89 SIDLibSLDB *sidSLDB = NULL; 91 SIDLibSLDB *sidSLDB = NULL;
92
93 BOOL setUseChConv;
94 iconv_t setChConv;
90 95
91 96
92 // Define option arguments 97 // Define option arguments
93 static const th_optarg_t optList[] = 98 static const th_optarg_t optList[] =
94 { 99 {
566 } 571 }
567 572
568 573
569 int main(int argc, char *argv[]) 574 int main(int argc, char *argv[])
570 { 575 {
576 char *setLang = th_strdup(getenv("LANG"));
577
571 // Initialize 578 // Initialize
572 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL); 579 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL);
573 th_verbosityLevel = 0; 580 th_verbosityLevel = 0;
574 581
575 memset(&optFormat, 0, sizeof(optFormat)); 582 memset(&optFormat, 0, sizeof(optFormat));
583
584 // Initialize iconv, check if we have language/charset
585 if (setLang != NULL)
586 {
587 char *ptr = strchr(setLang, '.');
588 if (ptr != NULL) strcpy(setLang, ptr + 1);
589 }
590
591 setChConv = iconv_open("iso88591", setLang != NULL ? setLang : SET_DEF_CHARSET);
592 setUseChConv = setChConv != (iconv_t) -1;
593 th_free(setLang);
576 594
577 // Parse command line arguments 595 // Parse command line arguments
578 if (!th_args_process(argc, argv, optList, optListN, 596 if (!th_args_process(argc, argv, optList, optListN,
579 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) 597 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS))
580 return -1; 598 return -1;
654 THERR("No filename(s) specified.\n"); 672 THERR("No filename(s) specified.\n");
655 } 673 }
656 674
657 out: 675 out:
658 676
677 if (setUseChConv)
678 iconv_close(setChConv);
679
659 th_free(setHVSCPath); 680 th_free(setHVSCPath);
660 th_free(setSLDBPath); 681 th_free(setSLDBPath);
661 si_sldb_free(sidSLDB); 682 si_sldb_free(sidSLDB);
662 return 0; 683 return 0;
663 } 684 }