* locale.cc (usage): Restructure, rephrase, add new options. Drop

arguments, don't exit.
	(print_version): New function.
	(longopts): Add -f, -n, and -V options.  Reorder.
	(opts): Add -f, -n, and -V options.
	(main): Call GetSystemDefaultUILanguage for -s option.  Call
	GetUserDefaultUILanguage for -u option.  Add -f and -n options and
	call GetUserDefaultLCID and GetSystemDefaultLCID respectively.  Return
	0 after calling usage in -h case.  Add -V option and call print_version.
	Don't print full usage in default case, rather just a short help message
	similar to GNU tools.
	* utils.sgml (locale): Align to above changes.  Rephrase description.
This commit is contained in:
Corinna Vinschen 2011-10-10 09:50:43 +00:00
parent f818494c63
commit 9198ac4dc6
3 changed files with 123 additions and 40 deletions

View File

@ -1,3 +1,19 @@
2011-10-10 Andy Koppe <andy.koppe@gmail.com>
Corinna Vinschen <corinna@vinschen.de>
* locale.cc (usage): Restructure, rephrase, add new options. Drop
arguments, don't exit.
(print_version): New function.
(longopts): Add -f, -n, and -V options. Reorder.
(opts): Add -f, -n, and -V options.
(main): Call GetSystemDefaultUILanguage for -s option. Call
GetUserDefaultUILanguage for -u option. Add -f and -n options and
call GetUserDefaultLCID and GetSystemDefaultLCID respectively. Return
0 after calling usage in -h case. Add -V option and call print_version.
Don't print full usage in default case, rather just a short help message
similar to GNU tools.
* utils.sgml (locale): Align to above changes. Rephrase description.
2011-10-10 Corinna Vinschen <corinna@vinschen.de> 2011-10-10 Corinna Vinschen <corinna@vinschen.de>
* cygcheck.cc (check_keys): Use UNICODE Win32 functions. * cygcheck.cc (check_keys): Use UNICODE Win32 functions.

View File

@ -32,6 +32,7 @@
#include <langinfo.h> #include <langinfo.h>
#include <limits.h> #include <limits.h>
#include <sys/cygwin.h> #include <sys/cygwin.h>
#include <cygwin/version.h>
#define WINVER 0x0601 #define WINVER 0x0601
#include <windows.h> #include <windows.h>
@ -40,44 +41,72 @@
extern char *__progname; extern char *__progname;
void usage (FILE *, int) __attribute__ ((noreturn)); void
usage ()
{
printf (
"Usage: %1$s [-amvhV]\n"
" or: %1$s [-ck] NAME\n"
" or: %1$s [-usfnU]\n"
"Get locale-specific information.\n"
"\n"
"System information:\n"
"\n"
" -a, --all-locales List all available supported locales\n"
" -m, --charmaps List all available character maps\n"
" -v, --verbose More verbose output\n"
"\n"
"Modify output format:\n"
"\n"
" -c, --category-name List information about given category NAME\n"
" -k, --keyword-name Print information about given keyword NAME\n"
"\n"
"Default locale information:\n"
"\n"
" -u, --user Print locale of user's default UI language\n"
" -s, --system Print locale of system default UI language\n"
" -f, --format Print locale of user's regional format settings\n"
" (time, numeric & monetary)\n"
" -n, --no-unicode Print system default locale for non-Unicode programs\n"
" -U, --utf Attach \".UTF-8\" to the result\n"
"\n"
"Other options:\n"
"\n"
" -h, --help This text\n"
" -V, --version Print program version and exit\n\n",
__progname);
}
void void
usage (FILE * stream, int status) print_version ()
{ {
fprintf (stream, printf ("%s (cygwin) %d.%d.%d\n"
"Usage: %s [-amsuUvh]\n"
" or: %s [-ck] NAME\n"
"Get locale-specific information.\n" "Get locale-specific information.\n"
"\n" "Copyright 2011 Red Hat, Inc.\n"
"Options:\n" "Compiled on %s\n",
"\n" __progname,
" -a, --all-locales List all available supported locales\n" CYGWIN_VERSION_DLL_MAJOR / 1000,
" -c, --category-name List information about given category NAME\n" CYGWIN_VERSION_DLL_MAJOR % 1000,
" -k, --keyword-name Print information about given keyword NAME\n" CYGWIN_VERSION_DLL_MINOR,
" -m, --charmaps List all available character maps\n" __DATE__);
" -s, --system Print system default locale\n"
" -u, --user Print user's default locale\n"
" -U, --utf Attach \".UTF-8\" to the result\n"
" -v, --verbose More verbose output\n"
" -h, --help This text\n",
__progname, __progname);
exit (status);
} }
struct option longopts[] = { struct option longopts[] = {
{"all-locales", no_argument, NULL, 'a'}, {"all-locales", no_argument, NULL, 'a'},
{"category-name", no_argument, NULL, 'c'}, {"category-name", no_argument, NULL, 'c'},
{"format", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"keyword-name", no_argument, NULL, 'k'}, {"keyword-name", no_argument, NULL, 'k'},
{"charmaps", no_argument, NULL, 'm'}, {"charmaps", no_argument, NULL, 'm'},
{"no-unicode", no_argument, NULL, 'n'},
{"system", no_argument, NULL, 's'}, {"system", no_argument, NULL, 's'},
{"user", no_argument, NULL, 'u'}, {"user", no_argument, NULL, 'u'},
{"utf", no_argument, NULL, 'U'}, {"utf", no_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'},
{0, no_argument, NULL, 0} {0, no_argument, NULL, 0}
}; };
const char *opts = "achkmsuUv"; const char *opts = "acfhkmnsuUvV";
int int
getlocale (LCID lcid, char *name) getlocale (LCID lcid, char *name)
@ -772,10 +801,16 @@ main (int argc, char **argv)
maps = 1; maps = 1;
break; break;
case 's': case 's':
lcid = LOCALE_SYSTEM_DEFAULT; lcid = GetSystemDefaultUILanguage ();
break; break;
case 'u': case 'u':
lcid = LOCALE_USER_DEFAULT; lcid = GetUserDefaultUILanguage ();
break;
case 'f':
lcid = GetUserDefaultLCID ();
break;
case 'n':
lcid = GetSystemDefaultLCID ();
break; break;
case 'U': case 'U':
utf = ".UTF-8"; utf = ".UTF-8";
@ -784,11 +819,16 @@ main (int argc, char **argv)
verbose = 1; verbose = 1;
break; break;
case 'h': case 'h':
usage (stdout, 0); usage ();
break; return 0;
case 'V':
print_version ();
return 0;
default: default:
usage (stderr, 1); fprintf (stderr,
break; "Try `%1$s --help' or `%1$s -h' for more information.\n",
__progname);
return 1;
} }
if (all) if (all)
print_all_locales (verbose); print_all_locales (verbose);

View File

@ -606,37 +606,64 @@ SIGUSR2 31 user defined signal 2
<sect2 id="locale"><title>locale</title> <sect2 id="locale"><title>locale</title>
<screen> <screen>
Usage: locale [-amsuUvh] Usage: locale [-amvhV]
or: locale [-ck] NAME or: locale [-ck] NAME
or: locale [-usfnU]
Get locale-specific information. Get locale-specific information.
Options: System information:
-a, --all-locales List all available supported locales -a, --all-locales List all available supported locales
-m, --charmaps List all available character maps
-v, --verbose More verbose output
Modify output format:
-c, --category-name List information about given category NAME -c, --category-name List information about given category NAME
-k, --keyword-name Print information about given keyword NAME -k, --keyword-name Print information about given keyword NAME
-m, --charmaps List all available character maps
-s, --system Print system default locale Default locale information:
-u, --user Print user's default locale
-U, --utf Attach ".UTF-8" to the result -u, --user Print locale of user's default UI language
-v, --verbose More verbose output -s, --system Print locale of system default UI language
-f, --format Print locale of user's regional format settings
(time, numeric &amp; monetary)
-n, --no-unicode Print system default locale for non-Unicode programs
-U, --utf Attach \".UTF-8\" to the result
Other options:
-h, --help This text -h, --help This text
-V, --version Print program version and exit
</screen> </screen>
<para><command>locale</command> without parameters prints information about <para><command>locale</command> without parameters prints information about
the current locale environment settings.</para> the current locale environment settings.</para>
<para>The <literal>-u</literal>, <literal>-s</literal>, <literal>-f</literal>,
and <literal>-n</literal> options can be used to request the various Windows
locale settings. The purpose is to use this command in scripts to set the
POSIX locale variables.</para>
<para>The <literal>-u</literal> option prints the current user's Windows <para>The <literal>-u</literal> option prints the current user's Windows
default locale to stdout. The <literal>-s</literal> option prints the UI locale to stdout. In Windows Vista and Windows 7 this setting is called
systems default locale instead. With the <literal>-U</literal> option the "Display Language"; there was no corresponding user setting in Windows XP.
<command>locale</command> appends a ".UTF-8". This can be used in scripts The <literal>-s</literal> option prints the systems default instead.
to set the Cygwin locale to the Windows user or system default, for instance: The <literal>-f</literal> option prints the user's setting for time, date,
</para> number and currency. That's equivalent to the setting in the "Formats" or
"Regional Options" tab in the "Region and Language" or "Regional and Language
Options" dialog. With the <literal>-U</literal> option
<command>locale</command> appends a ".UTF-8".</para>
<para>Usage example:</para>
<screen> <screen>
bash$ export LANG=$(locale -uU) bash$ export LANG=$(locale -uU)
bash$ echo $LANG bash$ echo $LANG
en_US.UTF-8 en_US.UTF-8
bash$ export LC_TIME=$(locale -fU)
bash$ echo $LC_TIME
de_DE.UTF-8
</screen> </screen>
<para>The <literal>-a</literal> option is helpful to learn which locales <para>The <literal>-a</literal> option is helpful to learn which locales