Mercurial > hg > sidinfo
comparison sidinfo.c @ 135:b4b1aac8761c
Add preprocessor guards around iconv stuff.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 02 Jun 2017 04:27:42 +0300 |
parents | b9a3f93f69d1 |
children | d40c371ce1f9 |
comparison
equal
deleted
inserted
replaced
134:b9a3f93f69d1 | 135:b4b1aac8761c |
---|---|
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 #ifdef HAVE_ICONV | |
10 #include <iconv.h> | 11 #include <iconv.h> |
12 #endif | |
11 | 13 |
12 | 14 |
13 // Some constants | 15 // Some constants |
14 #define SET_DEF_CHARSET "utf-8" | 16 #define SET_DEF_CHARSET "utf-8" |
15 #define SET_SLDB_FILENAME "Songlengths.txt" | 17 #define SET_SLDB_FILENAME "Songlengths.txt" |
94 | 96 |
95 PSFStack optFormat; | 97 PSFStack optFormat; |
96 | 98 |
97 SIDLibSLDB *sidSLDB = NULL; | 99 SIDLibSLDB *sidSLDB = NULL; |
98 | 100 |
101 #ifdef HAVE_ICONV | |
99 BOOL setUseChConv; | 102 BOOL setUseChConv; |
100 iconv_t setChConv; | 103 iconv_t setChConv; |
104 #endif | |
101 | 105 |
102 | 106 |
103 // Define option arguments | 107 // Define option arguments |
104 static const th_optarg optList[] = | 108 static const th_optarg optList[] = |
105 { | 109 { |
607 } | 611 } |
608 | 612 |
609 | 613 |
610 int main(int argc, char *argv[]) | 614 int main(int argc, char *argv[]) |
611 { | 615 { |
612 char *setLang = th_strdup(getenv("LANG")); | |
613 | |
614 // Initialize | 616 // Initialize |
615 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL); | 617 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL); |
616 th_verbosityLevel = 0; | 618 th_verbosityLevel = 0; |
617 | 619 |
618 memset(&optFormat, 0, sizeof(optFormat)); | 620 memset(&optFormat, 0, sizeof(optFormat)); |
619 | 621 |
620 // Initialize iconv, check if we have language/charset | 622 // Initialize iconv, check if we have language/charset |
623 #ifdef HAVE_ICONV | |
624 char *setLang = th_strdup(getenv("LANG")); | |
621 if (setLang != NULL) | 625 if (setLang != NULL) |
622 { | 626 { |
623 char *ptr = strchr(setLang, '.'); | 627 char *ptr = strchr(setLang, '.'); |
624 if (ptr != NULL) strcpy(setLang, ptr + 1); | 628 if (ptr != NULL) strcpy(setLang, ptr + 1); |
625 } | 629 } |
626 | 630 |
627 setChConv = iconv_open(setLang != NULL ? setLang : SET_DEF_CHARSET, "iso88591"); | 631 setChConv = iconv_open(setLang != NULL ? setLang : SET_DEF_CHARSET, "iso88591"); |
628 setUseChConv = setChConv != (iconv_t) -1; | 632 setUseChConv = setChConv != (iconv_t) -1; |
629 th_free(setLang); | 633 th_free(setLang); |
634 #endif | |
630 | 635 |
631 // Parse command line arguments | 636 // Parse command line arguments |
632 if (!th_args_process(argc, argv, optList, optListN, | 637 if (!th_args_process(argc, argv, optList, optListN, |
633 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) | 638 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) |
634 return -1; | 639 return -1; |
710 THERR("No filename(s) specified.\n"); | 715 THERR("No filename(s) specified.\n"); |
711 } | 716 } |
712 | 717 |
713 out: | 718 out: |
714 | 719 |
720 #ifdef HAVE_ICONV | |
715 if (setUseChConv) | 721 if (setUseChConv) |
716 iconv_close(setChConv); | 722 iconv_close(setChConv); |
723 #endif | |
717 | 724 |
718 th_free(setHVSCPath); | 725 th_free(setHVSCPath); |
719 th_free(setSLDBPath); | 726 th_free(setSLDBPath); |
720 si_sldb_free(sidSLDB); | 727 si_sldb_free(sidSLDB); |
721 return 0; | 728 return 0; |