2000-10-27 15:54:35 +00:00
|
|
|
/* locale_alias - Test program to create a file of locale to language name
|
|
|
|
aliases
|
|
|
|
|
2005-07-01 21:00:04 +00:00
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
|
2000-10-27 15:54:35 +00:00
|
|
|
Written: Adam Fedor <fedor@gnu.org>
|
|
|
|
Date: Oct 2000
|
|
|
|
|
|
|
|
AFAIK: This only works on machines that support setlocale.
|
|
|
|
The files created may require hand editing.
|
2008-06-08 10:38:33 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep Project
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either
|
|
|
|
version 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this program; see the file COPYINGv3.
|
|
|
|
If not, write to the Free Software Foundation,
|
2024-11-07 13:37:59 +00:00
|
|
|
31 Milk Street #960789 Boston, MA 02196 USA.
|
2008-06-08 10:38:33 +00:00
|
|
|
|
2000-10-27 15:54:35 +00:00
|
|
|
*/
|
|
|
|
|
2010-02-25 08:36:34 +00:00
|
|
|
#import "common.h"
|
|
|
|
|
2000-10-27 15:54:35 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <locale.h>
|
2010-02-19 14:21:02 +00:00
|
|
|
|
2010-02-14 14:34:25 +00:00
|
|
|
#import "Foundation/NSAutoreleasePool.h"
|
|
|
|
#import "Foundation/NSDictionary.h"
|
|
|
|
#import "GNUstepBase/GSLocale.h"
|
2000-10-27 15:54:35 +00:00
|
|
|
|
|
|
|
#define MAXSTRING 100
|
|
|
|
|
|
|
|
static int debug=1;
|
|
|
|
|
|
|
|
NSMutableDictionary *dict;
|
|
|
|
|
|
|
|
int
|
|
|
|
loc_read_file(const char *dir, const char *file)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char name[1000], *s;
|
|
|
|
char buf[1000];
|
|
|
|
char locale[MAXSTRING], language[MAXSTRING], country[MAXSTRING];
|
|
|
|
|
|
|
|
if (strcmp(file, "POSIX") == 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-07 15:34:06 +00:00
|
|
|
snprintf(name, sizeof(name), "%s/%s", dir, file);
|
2000-10-27 15:54:35 +00:00
|
|
|
fp = fopen(name, "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
language[0] = '\0';
|
|
|
|
country[0] = '\0';
|
2012-07-09 10:47:48 +00:00
|
|
|
while (NULL != fgets(buf, MAXSTRING, fp))
|
2000-10-27 15:54:35 +00:00
|
|
|
{
|
|
|
|
if (strstr(buf, "anguage") != NULL)
|
|
|
|
{
|
|
|
|
sscanf(&buf[2], "%s", language);
|
|
|
|
}
|
|
|
|
if ((s = strstr(buf, "ocale for")) != NULL)
|
|
|
|
{
|
2011-03-07 11:34:17 +00:00
|
|
|
strncpy(country, s + 10, sizeof(country) - 1);
|
|
|
|
country[sizeof(country) - 1] = '\0';
|
2000-10-27 15:54:35 +00:00
|
|
|
s = strchr(country, '\n');
|
|
|
|
if (s)
|
|
|
|
*s = '\0';
|
|
|
|
}
|
|
|
|
if (strlen(language) > 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:34:17 +00:00
|
|
|
strncpy(locale, file, sizeof(locale) - 1);
|
|
|
|
locale[sizeof(locale) - 1] = '\0';
|
2000-10-27 15:54:35 +00:00
|
|
|
if (strlen(country) > 0 && strcmp(country, language) != 0)
|
|
|
|
{
|
2011-03-07 11:34:17 +00:00
|
|
|
strncat(country, language, sizeof(country) - 1 - strlen(country));
|
2006-10-09 14:00:01 +00:00
|
|
|
[dict setObject: [NSString stringWithUTF8String: country]
|
|
|
|
forKey: [NSString stringWithUTF8String: locale]];
|
2000-10-27 15:54:35 +00:00
|
|
|
}
|
|
|
|
locale[2] = '\0';
|
2006-10-09 14:00:01 +00:00
|
|
|
[dict setObject: [NSString stringWithUTF8String: language]
|
|
|
|
forKey: [NSString stringWithUTF8String: locale]];
|
2000-10-27 15:54:35 +00:00
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go through all the files in the directory */
|
|
|
|
int
|
|
|
|
loc_get_files(const char *dir)
|
|
|
|
{
|
|
|
|
struct dirent *dp;
|
|
|
|
DIR *dirp;
|
|
|
|
|
|
|
|
dirp = opendir(dir);
|
|
|
|
while ((dp = readdir(dirp)) != NULL)
|
|
|
|
{
|
|
|
|
if (isalpha((dp->d_name)[0]))
|
|
|
|
{
|
|
|
|
if (debug)
|
|
|
|
printf(" checking %s ...\n", dp->d_name);
|
|
|
|
loc_read_file(dir, dp->d_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
NSString *lang;
|
|
|
|
char *l;
|
|
|
|
CREATE_AUTORELEASE_POOL(pool);
|
|
|
|
|
|
|
|
l = setlocale(LC_ALL, "");
|
|
|
|
printf("Locale is %s\n", l);
|
|
|
|
|
|
|
|
/* Create Locale.aliases */
|
|
|
|
dict = [NSMutableDictionary dictionary];
|
|
|
|
loc_get_files("/usr/share/i18n/locales");
|
|
|
|
[dict writeToFile: @"Locale.aliases" atomically: NO];
|
|
|
|
|
|
|
|
/* Write out a skeleton file from the current locale */
|
|
|
|
dict = GSDomainFromDefaultLocale();
|
2012-07-09 10:47:48 +00:00
|
|
|
lang = GSLanguageFromLocale(GSSetLocale(0,NULL));
|
2000-10-27 15:54:35 +00:00
|
|
|
if (lang == nil)
|
|
|
|
lang = @"Locale";
|
|
|
|
if (dict)
|
|
|
|
[dict writeToFile: lang atomically: NO];
|
|
|
|
|
|
|
|
DESTROY(pool);
|
|
|
|
return 0;
|
|
|
|
}
|