From d806242e060d9d92c0430f3aec214a7cb52007b0 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Sat, 9 Jul 2011 04:31:22 +0000 Subject: [PATCH] Forgot to svn add the new locale command. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42395 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/locale/locale.cpp | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/bin/locale/locale.cpp diff --git a/src/bin/locale/locale.cpp b/src/bin/locale/locale.cpp new file mode 100644 index 0000000000..130cfb68b3 --- /dev/null +++ b/src/bin/locale/locale.cpp @@ -0,0 +1,99 @@ +/* + * Copyright 2011, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Ryan Leavengood, leavengood@gmail.com + */ + + +#include +#include +#include +#include + +#include +#include +#include + + +extern const char *__progname; +static const char *kProgramName = __progname; + + +const char* +preferred_language() +{ + BMessage preferredLanguages; + BLocaleRoster::Default()->GetPreferredLanguages(&preferredLanguages); + const char* firstPreferredLanguage; + if (preferredLanguages.FindString("language", &firstPreferredLanguage) + != B_OK) { + // Default to English + firstPreferredLanguage = "en"; + } + + return firstPreferredLanguage; +} + + +void +print_formatting_conventions() +{ + BFormattingConventions conventions; + BLocale::Default()->GetFormattingConventions(&conventions); + printf("%s_%s.UTF-8", conventions.LanguageCode(), conventions.CountryCode()); +} + + +void +usage(int status) +{ + printf("Usage: %s [-lcf]\n" + " -l, --language\tPrint the currently set preferred language\n" + " -c, --ctype\t\tPrint the LC_CTYPE value based on the preferred language\n" + " -f, --format\t\tPrint the formatting convention language\n" + " -h, --help\t\tDisplay this help and exit\n", + kProgramName); + + exit(status); +} + + +int +main(int argc, char **argv) +{ + static struct option const longopts[] = { + {"language", no_argument, 0, 'l'}, + {"ctype", no_argument, 0, 'c'}, + {"format", no_argument, 0, 'f'}, + {"help", no_argument, 0, 'h'}, + {NULL} + }; + + int c; + while ((c = getopt_long(argc, argv, "lcfh", longopts, NULL)) != -1) { + switch (c) { + case 'l': + printf("%s", preferred_language()); + break; + case 'c': + printf("%s.UTF-8", preferred_language()); + break; + case 'f': + print_formatting_conventions(); + break; + case 'h': + usage(0); + break; + case 0: + break; + default: + usage(1); + break; + } + } + + return 0; +} +