From 307eff3ce68d5f78a4b5f36425b61dd45c228b25 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 7 Jun 1999 18:36:00 +0000 Subject: [PATCH] Add ability to read/write localized manpages --- gnu/usr.bin/man/Makefile.inc | 3 +- gnu/usr.bin/man/man/man.c | 154 ++++++++++++++++++++++++++++++++++- gnu/usr.bin/man/man/man.man | 10 ++- 3 files changed, 164 insertions(+), 3 deletions(-) diff --git a/gnu/usr.bin/man/Makefile.inc b/gnu/usr.bin/man/Makefile.inc index 715932527d0a..25ba7bb72fc9 100644 --- a/gnu/usr.bin/man/Makefile.inc +++ b/gnu/usr.bin/man/Makefile.inc @@ -7,7 +7,8 @@ bindir= ${BINDIR} pager= more -s manpath_config_file= /etc/manpath.config troff= /usr/bin/groff -man -nroff= /usr/bin/groff -Wall -mtty-char -Tascii -man +# -Tascii or localized encoding added automatically +nroff= /usr/bin/groff -Wall -mtty-char -man apropos= /usr/bin/apropos whatis= /usr/bin/whatis neqn= /usr/bin/eqn -Tascii diff --git a/gnu/usr.bin/man/man/man.c b/gnu/usr.bin/man/man/man.c index 6d2aacd10f7b..d38047745d5c 100644 --- a/gnu/usr.bin/man/man/man.c +++ b/gnu/usr.bin/man/man/man.c @@ -85,23 +85,54 @@ static int alt_system; static char *alt_system_name; #endif +#ifdef __FreeBSD__ +/* short_locale without country suffix */ +static char *locale, *short_locale, *locale_opts, *locale_nroff; +static int use_original; +struct ltable { + char *lcode; + char *nroff; +}; +static struct ltable ltable[] = { + {"KOI8-R", " -Tkoi8-r"}, + {"ISO_8859-1", " -Tlatin1"}, + {NULL, NULL} +}; +#endif + static int troff = 0; int debug; #ifdef HAS_TROFF #ifdef ALT_SYSTEMS +#ifdef __FreeBSD__ +static char args[] = "M:P:S:adfhkm:op:tw?"; +#else static char args[] = "M:P:S:adfhkm:p:tw?"; +#endif +#else +#ifdef __FreeBSD__ +static char args[] = "M:P:S:adfhkop:tw?"; #else static char args[] = "M:P:S:adfhkp:tw?"; #endif +#endif #else #ifdef ALT_SYSTEMS +#ifdef __FreeBSD__ +static char args[] = "M:P:S:adfhkm:op:w?"; +#else static char args[] = "M:P:S:adfhkm:p:w?"; +#endif +#else +#ifdef __FreeBSD__ +static char args[] = "M:P:S:adfhkop:w?"; #else static char args[] = "M:P:S:adfhkp:w?"; #endif #endif +#endif #ifdef SETREUID uid_t ruid; @@ -203,23 +234,47 @@ usage () #ifdef HAS_TROFF #ifdef ALT_SYSTEMS +#ifdef __FreeBSD__ + static char s1[] = + "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\ + [-m system] [-p string] name ...\n\n"; +#else static char s1[] = "usage: %s [-adfhktw] [section] [-M path] [-P pager] [-S list]\n\ [-m system] [-p string] name ...\n\n"; +#endif +#else +#ifdef __FreeBSD__ + static char s1[] = + "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\ + [-p string] name ...\n\n"; #else static char s1[] = "usage: %s [-adfhktw] [section] [-M path] [-P pager] [-S list]\n\ [-p string] name ...\n\n"; #endif +#endif #else #ifdef ALT_SYSTEMS +#ifdef __FreeBSD__ static char s1[] = - "usage: %s [-adfhkw] [section] [-M path] [-P pager] [-S list]\n\ + "usage: %s [-adfhkow] [section] [-M path] [-P pager] [-S list]\n\ [-m system] [-p string] name ...\n\n"; #else static char s1[] = "usage: %s [-adfhkw] [section] [-M path] [-P pager] [-S list]\n\ + [-m system] [-p string] name ...\n\n"; +#endif +#else +#ifdef __FreeBSD__ + static char s1[] = + "usage: %s [-adfhkow] [section] [-M path] [-P pager] [-S list]\n\ [-p string] name ...\n\n"; +#else + static char s1[] = + "usage: %s [-adfhkw] [section] [-M path] [-P pager] [-S list]\n\ + [-p string] name ...\n\n"; +#endif #endif #endif @@ -229,6 +284,10 @@ static char s2[] = " a : find all matching entries\n\ h : print this help message\n\ k : same as apropos(1)\n"; +#ifdef __FreeBSD__ + static char s21[] = " o : use original, non-localized manpages\n"; +#endif + #ifdef HAS_TROFF static char s3[] = " t : use troff to format pages for printing\n"; #endif @@ -248,6 +307,9 @@ static char s2[] = " a : find all matching entries\n\ strcat (usage_string, s1); strcat (usage_string, s2); +#ifdef __FreeBSD__ + strcat (usage_string, s21); +#endif #ifdef HAS_TROFF strcat (usage_string, s3); @@ -352,6 +414,9 @@ man_getopt (argc, argv) alt_system_name = strdup (optarg); break; #endif + case 'o': + use_original++; + break; case 'p': roff_directive = strdup (optarg); break; @@ -401,6 +466,36 @@ man_getopt (argc, argv) manp); } +#ifdef __FreeBSD__ + if (!use_original && (locale = setlocale(LC_CTYPE, NULL)) != NULL) { + char *tmp; + struct ltable *pltable; + + if ((short_locale = strdup(locale)) == NULL) { + perror ("ctype locale strdup"); + exit (1); + } + if ((tmp = strchr(short_locale, '_')) == NULL + || tmp != short_locale + 2 + || strlen(tmp + 1) < 4 + || tmp[3] != '.') { + errno = EINVAL; + perror ("bad ctype locale env"); + exit (1); + } + tmp[1] = short_locale[0]; + tmp[2] = short_locale[1]; + short_locale = tmp + 1; + tmp = short_locale + 3; + for (pltable = ltable; pltable->lcode != NULL; pltable++) { + if (strcmp(pltable->lcode, tmp) == 0) { + locale_nroff = pltable->nroff; + break; + } + } + } +#endif + #ifdef ALT_SYSTEMS if (alt_system_name == NULL || *alt_system_name == '\0') if ((alt_system_name = getenv ("SYSTEM")) != NULL) @@ -907,6 +1002,12 @@ parse_roff_directive (cp, file, buf, bufsize) { strncat (buf, " | ", bufsize-strlen(buf)-1); strncat (buf, NROFF, bufsize-strlen(buf)-1); +#ifdef __FreeBSD__ + if (locale_opts != NULL) + strncat (buf, locale_opts, bufsize-strlen(buf)-1); + else +#endif + strncat (buf, " -Tascii", bufsize-strlen(buf)-1); } if (tbl_found && !troff && strcmp (COL, "") != 0) { @@ -1018,6 +1119,13 @@ make_roff_command (file) strncpy (buf, NROFF, sizeof(buf)); } +#ifdef __FreeBSD__ + if (locale_opts != NULL) + strncat (buf, locale_opts, sizeof(buf)-strlen(buf)-1); + else +#endif + strncat (buf, " -Tascii", sizeof(buf)-strlen(buf)-1); + if (strcmp (COL, "") != 0) { strncat (buf, " | ", sizeof(buf)-strlen(buf)-1); @@ -1463,6 +1571,10 @@ man (name) register int glob; register char **mp; register char **sp; +#ifdef __FreeBSD__ + int l_found; + char buf[FILENAME_MAX]; +#endif found = 0; @@ -1476,7 +1588,27 @@ man (name) glob = 1; +#ifdef __FreeBSD__ + l_found = 0; + if (locale != NULL) { + locale_opts = locale_nroff; + snprintf(buf, sizeof(buf), "%s/%s", *mp, locale); + if (is_directory (buf)) + l_found = try_section (buf, section, name, glob); + if (!l_found) { + snprintf(buf, sizeof(buf), "%s/%s", *mp, short_locale); + if (is_directory (buf)) + l_found = try_section (buf, section, name, glob); + } + locale_opts = NULL; + } + if (!l_found) { +#endif found += try_section (*mp, section, name, glob); +#ifdef __FreeBSD__ + } else + found += l_found; +#endif if (found && !findall) /* i.e. only do this section... */ return found; @@ -1493,7 +1625,27 @@ man (name) glob = 1; +#ifdef __FreeBSD__ + l_found = 0; + if (locale != NULL) { + locale_opts = locale_nroff; + snprintf(buf, sizeof(buf), "%s/%s", *mp, locale); + if (is_directory (buf)) + l_found = try_section (buf, *sp, name, glob); + if (!l_found) { + snprintf(buf, sizeof(buf), "%s/%s", *mp, short_locale); + if (is_directory (buf)) + l_found = try_section (buf, *sp, name, glob); + } + locale_opts = NULL; + } + if (!l_found) { +#endif found += try_section (*mp, *sp, name, glob); +#ifdef __FreeBSD__ + } else + found += l_found; +#endif if (found && !findall) /* i.e. only do this section... */ return found; diff --git a/gnu/usr.bin/man/man/man.man b/gnu/usr.bin/man/man/man.man index b597929ecdb8..b3b49a99936d 100644 --- a/gnu/usr.bin/man/man/man.man +++ b/gnu/usr.bin/man/man/man.man @@ -19,7 +19,7 @@ .Nd format and display the on-line manual pages .Sh SYNOPSIS .Nm man -.Op Fl adfhktw +.Op Fl adfhkotw .Op Fl m Ar system .Op Fl p Ar string .Op Fl M Ar path @@ -83,6 +83,14 @@ Equivalent to .It Fl m Ar system Specify an alternate set of man pages to search based on the system name given. +.It Fl o +Use original, non-localized manpages. By default, man searches +for localized subdirectories of each manpath component, subdirectory +name is determined by the +.Ev LANG +or +.Ev LC_CTYPE +environment variables. .It Fl p Ar string Specify the sequence of preprocessors to run before nroff or troff. Not all installations will have a full set of preprocessors.