aboutsummaryrefslogtreecommitdiff
path: root/gnu/usr.bin/man
diff options
context:
space:
mode:
authorAlexey Zelkin <phantom@FreeBSD.org>2002-03-12 19:12:35 +0000
committerAlexey Zelkin <phantom@FreeBSD.org>2002-03-12 19:12:35 +0000
commitdcd7e37740f5a89d975b2c178201b05ddfc2e7cc (patch)
treecabf9691478dd212a8cf225bb5f0f277a9773798 /gnu/usr.bin/man
parentec605b95862acf19e312029d590c67ff4a368d7e (diff)
Notes
Diffstat (limited to 'gnu/usr.bin/man')
-rw-r--r--gnu/usr.bin/man/man/man.c121
1 files changed, 77 insertions, 44 deletions
diff --git a/gnu/usr.bin/man/man/man.c b/gnu/usr.bin/man/man/man.c
index 7fd4f89a0d7f..e7987e09d6d6 100644
--- a/gnu/usr.bin/man/man/man.c
+++ b/gnu/usr.bin/man/man/man.c
@@ -25,6 +25,7 @@
#include <errno.h>
#ifdef __FreeBSD__
#include <locale.h>
+#include <langinfo.h>
#endif
#include <stdio.h>
#include <string.h>
@@ -87,8 +88,8 @@ static int findall;
static int print_where;
#ifdef __FreeBSD__
-/* short_locale without country suffix */
-static char *locale, *short_locale, *locale_opts, *locale_nroff;
+static char *locale, *locale_opts, *locale_nroff, *locale_codeset;
+static char locale_terr[3], locale_lang[3];
static int use_original;
struct ltable {
char *lcode;
@@ -97,9 +98,7 @@ struct ltable {
static struct ltable ltable[] = {
{"KOI8-R", "koi8-r"},
{"ISO8859-1", "latin1"},
- {"ISO_8859-1", "latin1"},
{"ISO8859-15", "latin1"},
- {"ISO_8859-15", "latin1"},
{NULL}
};
#endif
@@ -403,44 +402,64 @@ man_getopt (argc, argv)
}
#ifdef __FreeBSD__
- if (!use_original && (locale = setlocale(LC_CTYPE, NULL)) != NULL) {
- char *tmp;
+ /* "" intentionally used to catch error */
+ if ((locale = setlocale(LC_CTYPE, "")) != NULL)
+ locale_codeset = nl_langinfo(CODESET);
+ if (!use_original && locale != NULL && *locale_codeset != '\0' &&
+ strcmp(locale_codeset, "US-ASCII") != 0
+ ) {
+ char *tmp, *short_locale;
struct ltable *pltable;
- if ((tmp = strchr(locale, '_')) == NULL
- || tmp != locale + 2
- || strlen(tmp + 1) < 4
- || tmp[3] != '.') {
- if (debug) {
- if (strcmp(locale, "C") != 0 &&
- strcmp(locale, "POSIX") != 0 &&
- strcmp(locale, "ASCII") != 0 &&
- strcmp(locale, "US-ASCII") != 0) {
- errno = EINVAL;
- perror ("ctype locale env");
- }
- }
+ *locale_lang = '\0';
+ *locale_terr = '\0';
+
+ if ((short_locale = strdup(locale)) == NULL) {
+ perror ("ctype locale strdup");
+ exit (1);
+ }
+ if ((tmp = strchr(short_locale, '.')) != NULL)
+ *tmp = '\0';
+
+ if (strlen(short_locale) == 2)
+ strcpy(locale_lang, short_locale);
+ else if ((tmp = strchr(short_locale, '_')) == NULL ||
+ tmp != short_locale + 2 ||
+ strlen(tmp + 1) != 2
+ ) {
+ errno = EINVAL;
+ perror ("ctype locale format");
locale = NULL;
} else {
- if ((short_locale = strdup(locale)) == NULL) {
- perror ("ctype locale strdup");
- exit (1);
- }
- tmp = short_locale + 3;
- tmp[0] = short_locale[0];
- tmp[1] = short_locale[1];
- short_locale = tmp;
+ strncpy(locale_terr, short_locale + 3, 2);
+ locale_terr[2] = '\0';
+ strncpy(locale_lang, short_locale, 2);
+ locale_lang[2] = '\0';
+ }
- tmp = short_locale + 3;
+ free(short_locale);
+
+ if (locale != NULL) {
for (pltable = ltable; pltable->lcode != NULL; pltable++) {
- if (strcmp(pltable->lcode, tmp) == 0) {
+ if (strcmp(pltable->lcode, locale_codeset) == 0) {
locale_nroff = pltable->nroff;
break;
}
}
}
+ } else {
+ if (locale == NULL) {
+ errno = EINVAL;
+ perror ("ctype locale");
+ } else {
+ locale = NULL;
+ if (*locale_codeset == '\0') {
+ errno = EINVAL;
+ perror ("ctype codeset");
+ }
+ }
}
-#endif
+#endif /* __FreeBSD__ */
if (pager == NULL || *pager == '\0')
if ((pager = getenv ("PAGER")) == NULL)
@@ -1547,15 +1566,22 @@ man (name)
l_found = 0;
if (locale != NULL) {
locale_opts = locale_nroff;
- snprintf(buf, sizeof(buf), "%s/%s", *mp, locale);
- if (is_directory (buf) == 1)
- l_found = try_section (buf, section, name, glob);
- if (!l_found) {
- snprintf(buf, sizeof(buf), "%s/%s", *mp, short_locale);
+ if (*locale_lang != '\0' && *locale_terr != '\0') {
+ snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
+ locale_lang, locale_terr, locale_codeset);
if (is_directory (buf) == 1)
l_found = try_section (buf, section, name, glob);
- if (!l_found && (*short_locale != 'e' || *(short_locale + 1) != 'n')) {
- snprintf(buf, sizeof(buf), "%s/en.%s", *mp, short_locale + 3);
+ }
+ if (!l_found) {
+ if (*locale_lang != '\0') {
+ snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
+ locale_lang, locale_codeset);
+ if (is_directory (buf) == 1)
+ l_found = try_section (buf, section, name, glob);
+ }
+ if (!l_found && strcmp(locale_lang, "en") != 0) {
+ snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
+ locale_codeset);
if (is_directory (buf) == 1)
l_found = try_section (buf, section, name, glob);
}
@@ -1589,15 +1615,22 @@ man (name)
l_found = 0;
if (locale != NULL) {
locale_opts = locale_nroff;
- snprintf(buf, sizeof(buf), "%s/%s", *mp, locale);
- if (is_directory (buf) == 1)
- l_found = try_section (buf, *sp, name, glob);
- if (!l_found) {
- snprintf(buf, sizeof(buf), "%s/%s", *mp, short_locale);
+ if (*locale_lang != '\0' && *locale_terr != '\0') {
+ snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
+ locale_lang, locale_terr, locale_codeset);
if (is_directory (buf) == 1)
l_found = try_section (buf, *sp, name, glob);
- if (!l_found && (*short_locale != 'e' || *(short_locale + 1) != 'n')) {
- snprintf(buf, sizeof(buf), "%s/en.%s", *mp, short_locale + 3);
+ }
+ if (!l_found) {
+ if (*locale_lang != '\0') {
+ snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
+ locale_lang, locale_codeset);
+ if (is_directory (buf) == 1)
+ l_found = try_section (buf, *sp, name, glob);
+ }
+ if (!l_found && strcmp(locale_lang, "en") != 0) {
+ snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
+ locale_codeset);
if (is_directory (buf) == 1)
l_found = try_section (buf, *sp, name, glob);
}