* Makefile.in (CYGWIN_BINS): Add getlocale.

* getlocale.c: New file.
	* utils.sgml (getlocale): New section describing new getlocale tool.
This commit is contained in:
Corinna Vinschen 2010-01-22 22:31:50 +00:00
parent 326fb376dd
commit be822de2a1
4 changed files with 185 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2010-01-22 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (CYGWIN_BINS): Add getlocale.
* getlocale.c: New file.
* utils.sgml (getlocale): New section describing new getlocale tool.
2010-01-16 Corinna Vinschen <corinna@vinschen.de>
* cygpath.cc (get_mixed_name): Drop function. Replace with call to

View File

@ -1,6 +1,6 @@
# Makefile for Cygwin utilities
# Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005, 2006, 2007, 2008, 2009 Red Hat, Inc.
# 2005, 2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
# This file is part of Cygwin.
@ -52,7 +52,7 @@ MINGW_CXX := ${srcdir}/mingw ${CXX} -I${updir}
# List all binaries to be linked in Cygwin mode. Each binary on this list
# must have a corresponding .o of the same name.
CYGWIN_BINS := ${addsuffix .exe,cygpath getfacl ldd kill mkgroup \
CYGWIN_BINS := ${addsuffix .exe,cygpath getfacl getlocale ldd kill mkgroup \
mkpasswd mount passwd ps regtool setfacl setmetamode ssp umount}
# List all binaries to be linked in MinGW mode. Each binary on this list

129
winsup/utils/getlocale.c Normal file
View File

@ -0,0 +1,129 @@
/*
* Copyright (c) 2010, Corinna Vinschen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#define WINVER 0x0601
#include <windows.h>
extern char *__progname;
void usage (FILE *, int) __attribute__ ((noreturn));
void
usage (FILE * stream, int status)
{
fprintf (stream,
"Usage: %s [-asuh]\n"
"Print Windows locale(s)\n"
"\n"
"Options:\n"
"\n"
" -a, --all List all available locales\n"
" -s, --system Print system default locale\n"
" (default is current user default locale)\n"
" -u, --utf Attach \".UTF-8\" to the result\n"
" -h, --help this text\n",
__progname);
exit (status);
}
struct option longopts[] = {
{"all", no_argument, NULL, 'a'},
{"system", no_argument, NULL, 's'},
{"utf", no_argument, NULL, 'u'},
{"help", no_argument, NULL, 'h'},
{0, no_argument, NULL, 0}
};
const char *opts = "ahsu";
int
getlocale (LCID lcid, char *name)
{
char iso639[10];
char iso3166[10];
iso3166[0] = '\0';
if (!GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, 10))
return 0;
GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, 10);
sprintf (name, "%s%s%s", iso639, lcid > 0x3ff ? "_" : "",
lcid > 0x3ff ? iso3166 : "");
return 1;
}
int main (int argc, char **argv)
{
int opt;
LCID lcid = LOCALE_USER_DEFAULT;
int all = 0;
const char *utf = "";
char name[32];
while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (opt)
{
case 'a':
all = 1;
break;
case 's':
lcid = LOCALE_SYSTEM_DEFAULT;
break;
case 'u':
utf = ".UTF-8";
break;
case 'h':
usage (stdout, 0);
break;
default:
usage (stderr, 1);
break;
}
if (all)
{
unsigned lang, sublang;
for (lang = 1; lang <= 0x3ff; ++lang)
for (sublang = 1; sublang <= 0x3f; ++sublang)
{
lcid = (sublang << 10) | lang;
if (getlocale (lcid, name))
{
char lang[256];
char country[256];
char loc[32];
GetLocaleInfo (lcid, LOCALE_SENGLANGUAGE, lang, 256);
GetLocaleInfo (lcid, LOCALE_SENGCOUNTRY, country, 256);
stpcpy (stpcpy (loc, name), utf);
printf ("%-16s %s (%s)\n", loc, lang, country);
}
}
return 0;
}
if (getlocale (lcid, name))
printf ("%s%s\n", name, utf);
return 0;
}

View File

@ -501,6 +501,54 @@ The format for ACL output is as follows:
</para>
</sect2>
<sect2 id="getlocale"><title>getlocale</title>
<screen>
Usage: getlocale [-asuh]
Print Windows locale(s)
Options:
-a, --all List all available locales
-s, --system Print system default locale
(default is current user default locale)
-u, --utf Attach ".UTF-8" to the result
-h, --help this text
</screen>
<para><command>getlocale</command> without parameters just prints the
current user's Windows default locale to stdout. The <literal>-s</literal>
option prints the systems default locale instead. With the
<literal>-u</literal> option <command>getlocale</command> appends a ".UTF-8".
This can be used in scripts to set the Cygwin locale, for instance:
</para>
<screen>
bash$ export LANG=$(getlocale -u)
bash$ echo $LANG
en_US.UTF-8
</screen>
<para>The <literal>-a</literal> option is helpful to learn which locales
are supported by your Windows machine. It prints the locales and their
actual meaning, like this:</para>
<screen>
bash$ getlocale -a
ar_SA Arabic (Saudi Arabia)
ar_IQ Arabic (Iraq)
zh_TW Chinese (Traditional) (Taiwan)
zh_CN Chinese (Simplified) (People's Republic of China)
zh_HK Chinese (Traditional) (Hong Kong S.A.R.)
da_DK Danish (Denmark)
en_US English (United States)
en_GB English (United Kingdom)
en_AU English (Australia)
...
</screen>
</sect2>
<sect2 id="kill"><title>kill</title>
<screen>