[Easyh10-cvs] easyh10/cui main.c,1.92,1.93
Status: Beta
Brought to you by:
nyaochi
|
From: Nyaochi <ny...@us...> - 2006-10-08 19:18:07
|
Update of /cvsroot/easyh10/easyh10/cui In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv20034/cui Modified Files: main.c Log Message: Automatic detection of the character encoding of the current OS. Index: main.c =================================================================== RCS file: /cvsroot/easyh10/easyh10/cui/main.c,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** main.c 8 Oct 2006 08:36:47 -0000 1.92 --- main.c 8 Oct 2006 19:18:02 -0000 1.93 *************** *** 42,45 **** --- 42,49 ---- #include <easyh10.h> + #ifdef HAVE_LANGINFO_CODESET + #include <langinfo.h> + #endif + #ifdef HAVE_GETOPT_H #include <getopt.h> *************** *** 53,57 **** #ifndef _WIN32 ! #define SYSTEM_ENCODING "UTF-8" #define MUSICTAG_ENCODING "ISO-8859-1" #endif --- 57,61 ---- #ifndef _WIN32 ! #define SYSTEM_ENCODING "ISO-8859-1" #define MUSICTAG_ENCODING "ISO-8859-1" #endif *************** *** 643,646 **** --- 647,653 ---- FILE *fpi = stdin, *fpo = stdout, *fpe = stderr; progress_data_t pd; + #ifndef _WIN32 + int encoding_specified = 0; + #endif/*_WIN32*/ pd.fp = fpe; *************** *** 839,851 **** break; ! #ifndef _WIN32 case 'e': if (set_encoding(optarg) != 0) { ret = 1; goto exit_main; } break; case 'w': if (set_encoding_music(optarg) != 0) { ret = 1; goto exit_main; --- 846,861 ---- break; ! #ifndef _WIN32 case 'e': if (set_encoding(optarg) != 0) { + fprintf(fe, "ERROR: Initialization failed to convert %s <-> UCS-2LE.\n", optarg); ret = 1; goto exit_main; } + encoding_specified = 1; break; case 'w': if (set_encoding_music(optarg) != 0) { + fprintf(fe, "ERROR: Initialization failed to convert %s <-> UCS-2LE.\n", optarg); ret = 1; goto exit_main; *************** *** 875,878 **** --- 885,917 ---- } + #ifndef _WIN32 + /* If no system encoding was specified, try to detect it. */ + if (!encoding_specified) { + const char *encoding = getenv("CHARSET"); + + #ifdef HAVE_LANGINFO_CODESET + if (!encoding) { + encoding = nl_langinfo(CODESET); + } + #endif/*HAVE_LANGINFO_CODESET*/ + + if (encoding) { + /* EasyH10 could detect the character encoding. */ + if (set_encoding(encoding) != 0) { + fprintf(fe, "ERROR: Initialization failed to convert %s <-> UCS-2LE.\n", encoding); + fprintf(fp, " Specify a character encoding manually by using -e option.\n"); + ret = 1; + goto exit_main; + } + } else { + /* EasyH10 could not detect the character encoding. */ + fprintf(fe, "ERROR: Failed to detect the default character encoding of the current OS.\n"); + fprintf(fp, " Specify the character encoding manually by using -e option.\n"); + ret = 1; + goto exit_main; + } + } + #endif/*_WIN32*/ + /* Exit when version mode specified. */ if (mode & MODE_VERSION) { |