aboutsummaryrefslogtreecommitdiff
path: root/locale
diff options
context:
space:
mode:
Diffstat (limited to 'locale')
-rw-r--r--locale/categories.def6
-rw-r--r--locale/localeinfo.h3
-rw-r--r--locale/programs/charmap.c68
-rw-r--r--locale/programs/locale.c63
4 files changed, 132 insertions, 8 deletions
diff --git a/locale/categories.def b/locale/categories.def
index b04ca20cc2..098d712172 100644
--- a/locale/categories.def
+++ b/locale/categories.def
@@ -84,11 +84,11 @@ DEFINE_CATEGORY
DEFINE_ELEMENT (_NL_CTYPE_NAMES_EL, "ctype-names-el", std, string)
DEFINE_ELEMENT (_NL_CTYPE_HASH_SIZE, "ctype-hash-size", std, word)
DEFINE_ELEMENT (_NL_CTYPE_HASH_LAYERS, "ctype-hash-layers", std, word)
- DEFINE_ELEMENT (_NL_CTYPE_CLASS_NAMES, "ctype-class-names", std, string)
- DEFINE_ELEMENT (_NL_CTYPE_MAP_NAMES, "ctype-map-names", std, string)
+ DEFINE_ELEMENT (_NL_CTYPE_CLASS_NAMES, "ctype-class-names", std, stringlist)
+ DEFINE_ELEMENT (_NL_CTYPE_MAP_NAMES, "ctype-map-names", std, stringlist)
DEFINE_ELEMENT (_NL_CTYPE_WIDTH, "ctype-width", std, bytearray)
DEFINE_ELEMENT (_NL_CTYPE_MB_CUR_MAX, "ctype-mb-cur-max", std, word)
- DEFINE_ELEMENT (_NL_CTYPE_CODESET_NAME, "ctype-codeset-name", std, string)
+ DEFINE_ELEMENT (_NL_CTYPE_CODESET_NAME, "charmap", std, string)
), _nl_postload_ctype, ctype_input, ctype_check, ctype_output)
diff --git a/locale/localeinfo.h b/locale/localeinfo.h
index b062200b3b..79db06d2f5 100644
--- a/locale/localeinfo.h
+++ b/locale/localeinfo.h
@@ -81,7 +81,8 @@ enum value_type
stringarray,
byte,
bytearray,
- word
+ word,
+ stringlist
};
diff --git a/locale/programs/charmap.c b/locale/programs/charmap.c
index 37b6cdef96..359b913c1f 100644
--- a/locale/programs/charmap.c
+++ b/locale/programs/charmap.c
@@ -22,6 +22,7 @@
#endif
#include <ctype.h>
+#include <dirent.h>
#include <errno.h>
#include <libintl.h>
#include <obstack.h>
@@ -78,6 +79,73 @@ charmap_read (const char *filename)
if (result == NULL)
{
+ /* OK, one more try. We also accept the names given to the
+ character sets in the files. Sometimes they differ from the
+ file name. */
+ DIR *dir;
+ struct dirent *dirent;
+
+ dir = opendir (CHARMAP_PATH);
+ if (dir == NULL)
+ {
+ while ((dirent = readdir (dir)) != NULL)
+ if (strcmp (dirent->d_name, ".") != 0
+ && strcmp (dirent->d_name, "..") != 0)
+ {
+ char buf[sizeof (CHARMAP_PATH)
+ + strlen (dirent->d_name) + 1];
+ FILE *fp;
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (dirent->d_type != DT_UNKNOWN && dirent->d_type != DT_REG)
+ continue;
+#endif
+ stpcpy (stpcpy (stpcpy (buf, CHARMAP_PATH), "/"),
+ dirent->d_name);
+
+ fp = fopen (buf, "r");
+ if (fp != NULL)
+ {
+ char *name = NULL;
+
+ while (!feof (fp))
+ {
+ char junk[BUFSIZ];
+
+ if (fscanf (fp, " <code_set_name> %as", &name) == 1)
+ break;
+
+ do
+ fgets (junk, sizeof junk, fp);
+ while (strchr (junk, '\n') == NULL);
+ }
+
+ fclose (fp);
+
+ if (name != NULL)
+ {
+ if (strcmp (name, filename) == 0)
+ {
+ result = parse_charmap (buf);
+
+ free (buf);
+
+ if (result)
+ return result;
+
+ break;
+ }
+
+ free (name);
+ }
+ }
+ }
+
+ closedir (dir);
+ }
+ }
+
+ if (result == NULL)
+ {
pathnfile = CHARMAP_PATH "/" DEFAULT_CHARMAP;
result = parse_charmap (pathnfile);
diff --git a/locale/programs/locale.c b/locale/programs/locale.c
index 7b0aaaa60f..28ad94403f 100644
--- a/locale/programs/locale.c
+++ b/locale/programs/locale.c
@@ -456,7 +456,9 @@ write_charmaps (void)
if (strcmp (dirent->d_name, ".") != 0
&& strcmp (dirent->d_name, "..") != 0)
{
+ char *buf = NULL;
mode_t mode;
+
#ifdef _DIRENT_HAVE_D_TYPE
if (dirent->d_type != DT_UNKNOWN)
mode = DTTOIF (dirent->d_type);
@@ -464,7 +466,8 @@ write_charmaps (void)
#endif
{
struct stat st;
- char buf[sizeof (CHARMAP_PATH) + strlen (dirent->d_name) + 1];
+
+ buf = alloca (sizeof (CHARMAP_PATH) + strlen (dirent->d_name) + 1);
stpcpy (stpcpy (stpcpy (buf, CHARMAP_PATH), "/"), dirent->d_name);
@@ -474,7 +477,44 @@ write_charmaps (void)
}
if (S_ISREG (mode))
- PUT (strdup (dirent->d_name));
+ {
+ FILE *fp;
+
+ PUT (strdup (dirent->d_name));
+
+ /* Read the file and learn about the code set name. */
+ if (buf == NULL)
+ {
+ buf = alloca (sizeof (CHARMAP_PATH)
+ + strlen (dirent->d_name) + 1);
+
+ stpcpy (stpcpy (stpcpy (buf, CHARMAP_PATH), "/"),
+ dirent->d_name);
+ }
+
+ fp = fopen (buf, "r");
+ if (fp != NULL)
+ {
+ char *name = NULL;
+
+ while (!feof (fp))
+ {
+ char junk[BUFSIZ];
+
+ if (fscanf (fp, " <code_set_name> %as", &name) == 1)
+ break;
+
+ do
+ fgets (junk, sizeof junk, fp);
+ while (strchr (junk, '\n') == NULL);
+ }
+
+ fclose (fp);
+
+ if (name != NULL)
+ PUT (name);
+ }
+ }
}
closedir (dir);
@@ -496,8 +536,8 @@ show_locale_vars (void)
{
char *val = getenv (name);
- if (lcall != NULL || val == NULL)
- printf ("%s=\"%s\"\n", name, lcall ? : lang);
+ if ((lcall ?: "")[0] != '\0' || val == NULL)
+ printf ("%s=\"%s\"\n", name, (lcall ?: "")[0] ? lcall : lang);
else
printf ("%s=%s\n", name, val);
}
@@ -553,6 +593,21 @@ show_info (const char *name)
putchar ('"');
}
break;
+ case stringlist:
+ {
+ int first = 1;
+ const char *val = nl_langinfo (item->item_id) ? : "";
+
+ while (*val != '\0')
+ {
+ printf ("%s%s%s%s", first ? "" : ";",
+ show_keyword_name ? "\"" : "", val,
+ show_keyword_name ? "\"" : "");
+ val = strchr (val, '\0') + 1;
+ first = 0;
+ }
+ }
+ break;
case byte:
{
const char *val = nl_langinfo (item->item_id);