This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CYGWIN=codepage? Or LC_CTYPE=foo?


On Apr  8 15:52, Corinna Vinschen wrote:
> On Apr  7 07:15, Kazuhiro Fujieda wrote:
> > >>> On Sun, 06 Apr 2008 21:26:18 +0200
> > >>> Corinna Vinschen said:
> > > I don't know if gsw-FR is correct though.  That's apparently an ISO639-2
> > > code.  But it looks like there is no ISO639 code covering that.  What
> > > would POSIX do?
> > 
> > de_FR would be used instead of it.
> 
> I made a testrun and found the following LCIDs/locales which have a
> three letter language code, [...]

On further reading I found RFC4646, which defines that the shortest
ISO 639 code available should be used.  Looks like there's no problem
at all...

I attached my first cut of an application which prints the LANG info
to stdout.  Note especially the undocumented `--testloop' option ;)


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat
#include <stdio.h>
#include <windows.h>
#include <getopt.h>

#define VERSION  "1.0"

extern char *__progname;

void version () __attribute__ ((noreturn));
void usage (FILE *, int) __attribute__ ((noreturn));

void
version ()
{
  printf ("%s (Cygwin) %s\n", __progname, VERSION);
  exit (0);
}

void
usage (FILE * stream, int status)
{
  fprintf (stream, "\n\
Usage: %s [-suU] [-l LCID]\n\
\n\
Return POSIX LANG identifier corresponding to a locale, default is the\n\
system default locale\n\
Possible options are:\n\
\n\
  -s, --system      return LANG for the system's default locale\n\
  -u, --user        return LANG for the current user's default locale\n\
  -l, --lcid LCID   return LANG for the LCID given as argument\n\
  -U, --UTF-8       always attach .UTF-8 to LANG\n\
  -h, --help        this text\n\
  -V, --version     print the version of %s and exit\n",
	   __progname, __progname);
  exit (status);
}

struct option longopts[] = {
  {"system", no_argument, NULL, 's'},
  {"user", no_argument, NULL, 'u'},
  {"lcid", required_argument, NULL, 'l'},
  {"UTF-8", no_argument, NULL, 'U'},
  {"help", no_argument, NULL, 'h'},
  {"version", no_argument, NULL, 'V'},
  {"testloop", no_argument, NULL, 'T'},
  {0, no_argument, NULL, 0}
};
char *opts = "sul:UhV";

int
getlocale (LCID lcid, bool utf, bool test)
{
  UINT codepage;
  char iso639[10];
  char iso3166[10];

  if (!GetLocaleInfo (lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
		      (char *) &codepage, sizeof codepage)
      || !GetLocaleInfo (lcid, LOCALE_SISO639LANGNAME, iso639, 10)
      || !GetLocaleInfo (lcid, LOCALE_SISO3166CTRYNAME, iso3166, 10))
    {
      if (!test)
        fprintf (stderr, "%s: Non existant locale\n", __progname);
      return 2;
    }
  if (utf)
    codepage = 0;
  if (test)
    {
      char cty[256];
      char lang[256];
      GetLocaleInfo (lcid, LOCALE_SENGCOUNTRY, cty, 256);
      GetLocaleInfo (lcid, LOCALE_SENGLANGUAGE, lang, 256);
      printf ("0x%04x=\"%s_%s\", %s (%s)\n", (unsigned) lcid, iso639, iso3166,
	      lang, cty);
    }
  else
    printf ("LANG=\"%s_%s%s\"\n", iso639, iso3166, codepage ? "" : ".UTF-8");
  return 0;
}

int main (int argc, char **argv)
{
  int opt;
  LCID lcid = LOCALE_SYSTEM_DEFAULT;
  bool utf = false;
  bool test = false;

  while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
    switch (opt)
      {
      case 's':
	lcid = LOCALE_SYSTEM_DEFAULT;
	break;
      case 'u':
	lcid = LOCALE_USER_DEFAULT;
	break;
      case 'l':
	lcid = strtoul (optarg, NULL, 0);
	break;
      case 'U':
	utf = true;
	break;
      case 'h':
	usage (stdout, 0);
	break;
      case 'V':
	version ();
	break;
      case 'T':
        test = true;
	break;
      default:
	usage (stderr, 1);
	break;
      }
  if (test)
    {
      for (unsigned lang = 1; lang <= 0x3ff; ++lang)
	for (unsigned sublang = 1; sublang <= 0x3f; ++sublang)
	  getlocale ((sublang << 10) | lang, false, true);
      return 0;
    }
  return getlocale (lcid, utf, false);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]