From c947e6c0e24066c93aeb2891a10968bcc253cf75 Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 8 Oct 2012 05:31:07 +0300 Subject: [PATCH] argdox for stdockConvert; locale detection --- src/main.cpp | 17 +++++++++++++++-- tools/stdockConvert/main.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dac07cf..222db7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,9 +21,22 @@ /////////////////////////////////////////////////////////////////////////////// +static void fixTextCodec () { + QTextCodec *kc; + const char *ll = getenv("LANG"); + // + if (!ll || !ll[0]) ll = getenv("LC_CTYPE"); + if (ll && ll[0] && (strcasestr(ll, "utf-8") || strcasestr(ll, "utf8"))) return; + kc = QTextCodec::codecForName("koi8-r"); + if (!kc) return; + QTextCodec::setCodecForCStrings(kc); + QTextCodec::setCodecForLocale(kc); +} + + +/////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv[]) { - QTextCodec::setCodecForCStrings(QTextCodec::codecForName("koi8-r")); - QTextCodec::setCodecForLocale(QTextCodec::codecForName("koi8-r")); + fixTextCodec(); QApplication app(argc, argv); diff --git a/tools/stdockConvert/main.cpp b/tools/stdockConvert/main.cpp index 1ee9acc..4403dfc 100644 --- a/tools/stdockConvert/main.cpp +++ b/tools/stdockConvert/main.cpp @@ -41,24 +41,42 @@ static XCursorTheme *loadTheme (const QString &fname) { } +static void fixTextCodec () { + QTextCodec *kc; + const char *ll = getenv("LANG"); + // + if (!ll || !ll[0]) ll = getenv("LC_CTYPE"); + if (ll && ll[0] && (strcasestr(ll, "utf-8") || strcasestr(ll, "utf8"))) return; + kc = QTextCodec::codecForName("koi8-r"); + if (!kc) return; + QTextCodec::setCodecForCStrings(kc); + QTextCodec::setCodecForLocale(kc); +} + + /////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv[]) { - QTextCodec::setCodecForCStrings(QTextCodec::codecForName("koi8-r")); - QTextCodec::setCodecForLocale(QTextCodec::codecForName("koi8-r")); + fixTextCodec(); QApplication app(argc, argv); bool doPack = false, doRemove = false; int argNo = 1; + while (argNo < argc) { if (!strcmp(argv[argNo], "-p")) doPack = true; else if (!strcmp(argv[argNo], "-P")) doPack = doRemove = true; else break; - argNo++; + ++argNo; } if (argNo >= argc) { - fprintf(stderr, "usage: %s [-p] [-P] file [file...]\n", argv[0]); + fprintf(stderr, + "usage: %s [-p] [-P] file [file...]\n" + " -p: pack converted theme\n" + " -P: pack converted theme and remove source\n" + "", + argv[0]); return 1; } -- 2.11.4.GIT