Index: man/man/Makefile diff -u man/man/Makefile:1.1.1.1 man/man/Makefile:1.3 --- man/man/Makefile:1.1.1.1 Tue Jul 17 10:34:22 2001 +++ man/man/Makefile Mon Dec 17 18:44:27 2001 @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1.1.1 2001/07/17 01:34:22 mori Exp $ +# $Id: Makefile,v 1.3 2001/12/17 09:44:27 mori Exp $ # # Japanized by # Copyright (c) KUMANO, Tadashi , 1996-2001, @@ -7,14 +7,14 @@ # (version 1.1i 2001/01/15) PROG= jman -SRCS= man.c manpath.c glob.c +SRCS= man.c manpath.c glob.c locale.c MAN1= jman.1 EMAN1= jman.1.eng.gz BINOWN= man BINMODE=4555 INSTALLFLAGS+= -fschg -CFLAGS+= -I${LIBDESTDIR} +CFLAGS+= -g -I${LIBDESTDIR} DPADD= ${LIBMAN} LDADD= ${LIBMAN} .if exists(/usr/lib/libxpg4.a) @@ -55,6 +55,8 @@ .else afterinstall: .endif + +man.o locale.o: locale.h .include "../Makefile.inc" Index: man/man/README.jman-ex diff -u /dev/null man/man/README.jman-ex:1.2 --- /dev/null Tue Jan 15 21:37:53 2002 +++ man/man/README.jman-ex Thu Jul 26 15:25:56 2001 @@ -0,0 +1,39 @@ +$B%G%U%)%k%H$G$O(B en $B$H(B ja $B$,%5%]!<%H$5$l$F$$$k!#(B + +$B4D6-JQ?t(B + +JMAN_SEARCH + $B%^%K%e%"%k$r8!:w$9$k8@8l$N%j%9%H$r(B '%', ':' $B$G6h@Z$C$FNs5s$9$k!#(B + $B%0%k!<%W$N6h@Z$j$O(B '%'$B!"%a%s%P!<$N6h@Z$j$O(B ':' $B$G$"$k!#(B + '%' $B$G6h@Z$i$l$?%0%k!<%W$4$H$K(B manpath $B$O;O$a$+$i8!:w$5$l$k!#(B + ':' $B$G6h@Z$i$l$?%a%s%P!<$O(B manpath $B$N3FMWAG$4$H$K8!:w$5$l$k!#(B + $BNc$($P(B JMAN_SEARCH $B$,(B "ja:en%fr:ru" $B$N>l9g!"(Bmanpath $B$N(B + $B3FMWAG$4$H$K!VF|K\8l!W!V1Q8l!W$N%^%K%e%"%k$,$3$N=g$G8!:w$5$l$k!#(B + $B$9$Y$F$N(B manpath $B$N8!:w$,=*N;$7$F$b$J$*%^%K%e%"%k$,8+$D$+$i$J$$>l9g$K(B + $B!V%U%i%s%98l!W!V%m%7%"8l!W$N%^%K%e%"%k$N8!:w$,9T$J$o$l$k!#(B + + $B$3$N;EMM$O0[$J$k%;%/%7%g%s$N%^%K%e%"%k$,ItJ,E*$KB8:_$9$k>l9g$N(B + $BF0:n$K1F6A$rM?$($k!#1Q8lHG$N(B man.1, man.7 $B$HF|K\8lHG$N(B man.7 $B$,(B + $B%$%s%9%H!<%k$5$l$?%7%9%F%`$G$O(B ja%en $B$N>l9g$OF|K\8lHG$N(B man.7 $B$,!"(B + ja:en $B$N>l9g$O1Q8lHG$N(B man.1 $B$,I=<($5$l$k!#(B + +JMAN__PATH + $B%^%K%e%"%k$, $B$O(B JMAN_SEARCH $B$G;XDj$7$?%a%s%P!$rBgJ8;z$K$7$?$b$N(B + $B$G$"$k!#%G%j%_%?$O(B ':'$B!#(BJMAN_SEARCH $B$GF|K\8l$N%^%K%e%"%k$r(B + $B8!:w=g=x$r(B ja $B$G;XDj$7$?$J$i$3$N4D6-JQ?t$O(B JMAN_JA_PATH $B$H$J$k!#(B + $BF|K\8l$N%^%K%e%"%k$N%5%V%G%#%l%/%H%j$r(B ja, ja_JP.EUC, ja_JP.eucJP + $B$N=g$G8!:w$9$k;~$O(B JMAN_JA_PATH=ja:ja_JP.EUC:ja_JP.eucJP $B$H(B + $B;XDj$9$k!#(B + +JMAN__ + $B%^%K%e%"%k$r@07A$9$k$H$-$K;HMQ$9$k%3%^%s%I$r%*%W%7%g%s$D$-$G;XDj$9$k!#(B + $B$K$O(B TROFF, NROFF, EQN, NEQN, GRAP, PIC, TBL, VGRIND, + REFER, COL, PAGER $B$,$"$k!#(B + +JMAN__TEMPLATE + $B$r;XDj$9$k;~$N%F%s%W%l!<%H$H$J$k8@8l4D6-L>$r;XDj$9$k!#(B + JMAN_RU_TEMPLATE=ja $B$H$9$k$HL@<(E*$K;XDj$7$J$+$C$?(B directive $B$K$O(B + ja $B4D6-$N(B directive $B$,%3%T!<$5$l$k!#(B + + $Id: README.jman-ex,v 1.2 2001/07/26 06:25:56 mori Exp $ Index: man/man/jman.man diff -u man/man/jman.man:1.1.1.1 man/man/jman.man:1.5 --- man/man/jman.man:1.1.1.1 Tue Jul 17 10:34:22 2001 +++ man/man/jman.man Tue Jan 15 21:37:32 2002 @@ -59,12 +59,6 @@ .Bl -tag -width Fl .It Fl M Ar path 別のマニュアルページを検索するパスを指定します。 -通常、jman は -.Nm jmanpath -を使い、検索するパスを決めます。 -このオプションは環境変数 -.Ev MANPATH -よりも優先されます。 .It Fl P Ar pager 使用するページャを指定します。 通常、jman は、 @@ -98,11 +92,8 @@ .Ev SYSTEM よりも優先されます。 .It Fl o -環境変数 -.Ev LC_CTYPE -または -.Ev LANG -設定にかかわらず、オリジナルのマニュアルページ以外の探索・表示を抑制します。 +環境変数の設定にかかわらず、 +オリジナルのマニュアルページ以外の探索・表示を抑制します。 .It Fl p Ar string nroff や troff を行う前に実行するプリプロセッサの順序を指定します。 全てのプリプロセッサがインストールされているとはかぎりません。 @@ -125,17 +116,18 @@ .It Ev MANPATH .Ev MANPATH がセットされていれば、その値はマニュアルページを検索するパスとして使われます。 -.It Ev LC_CTYPE -.It Ev LANG +.It Ev LC_ALL, LC_CTYPE オリジナルのマニュアルページに優先して検索するマニュアルページの言語を -決定します。 -日本語マニュアルページを検索・表示するためには +変更します。有効なロケール名で指定する必要があります。 +.Ev LC_ALL +は .Ev LC_CTYPE -または -.Ev LANG -が -.Ev ja_JP.EUC -にセットされている必要があります。 +よりも優先されます。 +.It Ev LANG +オリジナルのマニュアルページに優先して検索するマニュアルページの言語を +変更します。有効なロケール名で指定する必要があります。 +.Ev LC_ALL , LC_CTYPE +が設定されていない場合に有効です。 .It Ev MACHINE 特定のアーキテクチャ向けのマニュアルページを提供するために、 .Nm jman @@ -158,6 +150,7 @@ セットされていなければ、 .Nm %pager% が使われます。 +.El .El .Sh 使用例 .Pp Index: man/man/locale.c diff -u /dev/null man/man/locale.c:1.12 --- /dev/null Tue Jan 15 21:37:53 2002 +++ man/man/locale.c Tue Jan 15 21:19:48 2002 @@ -0,0 +1,374 @@ +/* $Id: locale.c,v 1.12 2002/01/15 12:19:48 mori Exp $ */ + +#include +#include +#include +#include +#include "gripes.h" +#include "locale.h" + +#define ENV_PREFIX "JMAN" +#define MAX_SUPPORT_LANG 255 +#define MAX_SUPPORT_LANG_DIRS 255 + +int debug; +int insecure = 0; +int force_original_man = 0; +char *search_lang_path_default = "ja%en"; + +typedef struct { + char *name; + char **path; + char **directive; +} man_lang_env_t; + +static man_lang_env_t **current_locale_list_root, *current_locale_set; + +static char *locale_alias[][2] = { + { "C", "en" }, + { "POSIX", "en" }, + { "ASCII", "en" }, + { "US-ASCII", "en" }, + { "japanese", "ja" }, + NULL +}; + +static char *search_path_en[] = { "", NULL }; +static char *search_path_ja[] = { "ja", "ja_JP.EUC", "ja_JP.eucJP", NULL }; + +static char *directive_en[] = { + "/usr/bin/groff -S -man", + "/usr/bin/groff -S -Wall -mtty-char -man -Tascii", + "/usr/bin/eqn", + "/usr/bin/neqn", + "", /* grap */ + "/usr/bin/pic", + "/usr/bin/tbl", + "/usr/bin/vgrind", + "/usr/bin/refer", + "/usr/bin/col", + "more -s", + NULL +}; +static char *directive_ja[] = { + "/usr/local/bin/groff -man -dlang=ja_JP.eucJP", + "/usr/local/bin/groff -S -Wall -mtty-char -man -Tnippon -dlang=ja_JP.eucJP", + "/usr/local/bin/geqn", + "/usr/local/bin/gneqn", + "", /* grap */ + "/usr/local/bin/gpic", + "/usr/local/bin/gtbl", + "/usr/bin/vgrind", + "/usr/bin/refer", + "", /* col */ + "jless -sEX", + NULL +}; +static char *directive_list[] = { + "TROFF", "NROFF", "EQN", "NEQN", "GRAP", "PIC", "TBL", "VGRIND", + "REFER", "COL", "PAGER", NULL +}; + +static man_lang_env_t lang_env_hint[] = { + { "en", search_path_en, directive_en }, + { "ja", search_path_ja, directive_ja }, + NULL +}; + +static man_lang_env_t *lang_env_list[MAX_SUPPORT_LANG] = { NULL }; + +static char *locale_info(char *locale_string) +{ + int len; + char *name, *(*p)[2]; + static char locale_short_name[3]; + + if (locale_string == NULL || locale_string[0] == '\0') { + name = "en"; + goto found; + } + for (p = locale_alias; (*p)[0] != NULL; p++) { + if (strcmp(locale_string, (*p)[0]) == 0) { + name = (*p)[1]; + goto found; + } + } + switch (len = strlen(locale_string)) { + case 2: + name = locale_string; + goto found; + case 5: + if (locale_string[2] == '_') { + name = locale_string; + goto found; + } + break; + default: + if (len > 5 && locale_string[2] == '_' && locale_string[5] == '.') { + name = locale_string; + goto found; + } + } + bad_name: + fprintf(stderr, "bad locale name: %s.\n", locale_string); + return NULL; + + found: + locale_short_name[0] = name[0]; + locale_short_name[1] = name[1]; + locale_short_name[2] = '\0'; + return locale_short_name; +} + +static void convert_path(char **list, char *path, char *delimiter, int max) +{ + int i, j; + + for (i = 0; i < max - 1; i++) { + if (debug) + fprintf(stderr, " path = %s", path); + retry: + if ((list[i] = strsep(&path, delimiter)) == NULL) + break; + for (j = 0; j < i; j++) + if (strcmp(list[j], list[i]) == 0) + goto retry; + if (debug) { + fprintf(stderr, "\titem = \"%s\"\trest = \"%s\"\n", list[i], path); + } + } + list[max - 1] = NULL; + if (debug) + fprintf(stderr, "\n"); + return; +} + +static man_lang_env_t *get_lang_env(char *lang) +{ + man_lang_env_t **p; + + if (lang == NULL) + return NULL; + for (p = lang_env_list; *p; p++) + if (strcmp((*p)->name, lang) == 0) + return *p; + return NULL; +} + +static man_lang_env_t *new_lang_env(char *lang) +{ + man_lang_env_t *p, **q, *template_lang_env, *lang_env; + char buf[BUFSIZ]; + char lang_upper[BUFSIZ], *s, *t; + char *path; + char **d_name, **d_dst, **d_src; + int exist = 0; + char *template_lang; + char **pp, **qq; + + for (s = lang, t = lang_upper; *s; s++, t++) + *t = toupper(*s); + *t = '\0'; + + if (debug) + fprintf(stderr, "create new lang env set \"%s\".\n", lang); + + if ((p = get_lang_env(lang)) != NULL) + return p; + + for (q = lang_env_list; *q; q++) + ; + if ((p = *q = (man_lang_env_t *)malloc(sizeof(man_lang_env_t))) == NULL) + gripe_alloc(sizeof(man_lang_env_t), "lang_env"); + p->name = lang; + if ((p->path = + (char **)malloc(sizeof(char *) * MAX_SUPPORT_LANG_DIRS + 1)) == NULL) { + p->path[0] = NULL; + gripe_alloc(sizeof(char *) * MAX_SUPPORT_LANG_DIRS + 1, "lang_env"); + } + if ((p->directive = + (char **)malloc(sizeof(char *) * N_DIRECTIVE + 1)) == NULL) + gripe_alloc(sizeof(char *) * N_DIRECTIVE + 1, "lang_env"); + *(q + 1) = NULL; + + template_lang_env = NULL; + snprintf(buf, sizeof(buf), ENV_PREFIX "_%s_TEMPLATE", lang_upper); + if ((template_lang = getenv(buf)) != NULL) { + if ((template_lang_env = get_lang_env(template_lang)) == NULL) { + for (lang_env = lang_env_hint; lang_env->name != NULL; lang_env++) { + if (strcmp(lang_env->name, template_lang) == 0) + break; + } + template_lang_env = lang_env; + } + } + if (template_lang_env == NULL || template_lang_env->name == NULL) { + for (lang_env = lang_env_hint; lang_env->name != NULL; lang_env++) { + if (strcmp(lang_env->name, lang) == 0) + break; + } + if (lang_env->name != NULL) + template_lang_env = lang_env; + else + template_lang_env = lang_env_hint; + } + if (debug) + fprintf(stderr, "template lang: %s\n", template_lang_env->name); + + snprintf(buf, sizeof(buf), ENV_PREFIX "_%s_PATH", lang_upper); + if ((s = getenv(buf)) != NULL) { + if (debug) + fprintf(stderr, "found path list in env: \"%s\"\n", s); + if ((path = (char *)malloc(sizeof(char) * strlen(s) + 1)) == NULL) + gripe_alloc(sizeof(char) * strlen(s) + 1, "lang_path"); + strcpy(path, s); + convert_path(p->path, path, ":", MAX_SUPPORT_LANG_DIRS); + } else { + if (strcmp(template_lang_env->name, lang) == 0) { + for (pp = p->path, qq = template_lang_env->path; *qq; pp++, qq++) { + *pp = *qq; + } + *pp = NULL; + } + } + if (p->path[0] == NULL) { + if (debug) + fprintf(stderr, "not found path list, use default: \"%s\"\n", lang); + p->path[0] = lang; + p->path[1] = NULL; + } + + for (pp = p->directive, qq = template_lang_env->directive; *qq; pp++, qq++) { + *pp = *qq; + } + *pp = NULL; + for (pp = p->directive, d_name = directive_list; *d_name; d_name++, pp++) { + snprintf(buf, sizeof(buf), ENV_PREFIX "_%s_%s", lang_upper, *d_name); + if ((s = getenv(buf)) != NULL) { + *pp = s; + insecure = 1; + } + } + + return p; +} + + +man_lang_env_t ***make_search_list() +{ + man_lang_env_t **p, ***q, ***root; + char **s, **t, *e; + char *list_1[MAX_SUPPORT_LANG], *list_2[MAX_SUPPORT_LANG_DIRS]; + int i; + char *list[MAX_SUPPORT_LANG + 1]; + static char search_lang_path[BUFSIZ]; + + if (force_original_man) { + strcmp(search_lang_path, "en"); + } else if ((e = getenv(ENV_PREFIX "_SEARCH")) != NULL && *e != '\0') { + strncpy(search_lang_path, e, BUFSIZ - 1); + search_lang_path[BUFSIZ - 1] = '\0'; + } else { + e = setlocale(LC_CTYPE, NULL); + if (e != NULL && *e != '\0') { + if ((e = locale_info(e)) == NULL) { + strcpy(search_lang_path, "en"); + } else if (strcmp(e, "en") == 0) { + strcpy(search_lang_path, e); + } else { + snprintf(search_lang_path, 6, "%s%%en", e); + } + } else { + strncpy(search_lang_path, search_lang_path_default, BUFSIZ - 1); + search_lang_path[BUFSIZ - 1] = '\0'; + } + } + + convert_path(list_1, search_lang_path, "%", MAX_SUPPORT_LANG); + for (i = 0; list_1[i]; i++); /* count length of list_1*/ + if ((root = + (man_lang_env_t ***)malloc(sizeof(man_lang_env_t ***) * i + 1)) == NULL) + gripe_alloc(sizeof(man_lang_env_t ***) * i + 1, "lang_search_list"); + + q = root; + for (s = list_1; *s; s++) { + convert_path(list_2, *s, ":", MAX_SUPPORT_LANG_DIRS); + for (i = 0; list_2[i]; i++); + if ((p = *q = + (man_lang_env_t **)malloc(sizeof(man_lang_env_t **) * i + 1)) == NULL) + gripe_alloc(sizeof(man_lang_env_t **), "lang_search_list"); + for (t = list_2; *t; t++) { + *p = new_lang_env(*t); + if (*p) + p++; + } + *p = NULL; + q++; + } + *q = NULL; + + if (debug) { + for (p = lang_env_list; *p; p++) { + fprintf(stderr, "\nlanguage environment \"%s\" (%0x)\n", + (*p)->name, *p); + + fprintf(stderr, " search directory list: "); + for (s = (*p)->path; *s; s++) + fprintf(stderr, " \"%s\",", *s); + fprintf(stderr, " (null)\n"); + + for (i = 0; i < N_DIRECTIVE; i++) + fprintf(stderr, " %-8s: \"%s\"\n", directive_list[i], + (*p)->directive[i]); + } + } + + return root; +} + +char *directive(int n) +{ + return (current_locale_set->directive[n]); +} + +int try_section_ml(char *path, char *section, char *name, + int glob, int findall) +{ + man_lang_env_t **p; + char **d, buf[BUFSIZ]; + int found = 0; + + for (p = current_locale_list_root; *p; p++) { + current_locale_set = *p; /* current_locale_set is global */ + for (d = current_locale_set->path; *d; d++) { + if (debug) + fprintf(stderr, "trying subdir \"%s\"\n", *d); + if (**d != '\0') + snprintf(buf, sizeof(buf), "%s/%s", path, *d); + else + snprintf(buf, sizeof(buf), "%s", path); + found += try_section(buf, section, name, glob); + if (found && !findall) + return found; + } + } + return found; +} + +int man_ml(char *name, int findall) +{ + static man_lang_env_t ***root = NULL; + man_lang_env_t ***p; + int found = 0; + + if (root == NULL) + root = make_search_list(); + + for (p = root; *p; p++) { + current_locale_list_root = *p; /* current_locale_list_root is global */ + found += man(name); + if (found && !findall) + return found; + } + return found; +} Index: man/man/locale.h diff -u /dev/null man/man/locale.h:1.2 --- /dev/null Tue Jan 15 21:37:53 2002 +++ man/man/locale.h Mon Dec 17 14:05:36 2001 @@ -0,0 +1,25 @@ +/* $Id: locale.h,v 1.2 2001/12/17 05:05:36 mori Exp $ */ + +#define N_DIRECTIVE 11 +#define N_TROFF 0 +#define N_NROFF 1 +#define N_EQN 2 +#define N_NEQN 3 +#define N_GRAP 4 +#define N_PIC 5 +#define N_TBL 6 +#define N_VGRIND 7 +#define N_REFER 8 +#define N_COL 9 +#define N_PAGER 10 + +extern int insecure; +extern int force_original_man; +extern int debug; +extern char *search_lang_path; + +char *directive(int); +int try_section_ml(char *, char *, char *, int, int); +int try_section(char *, char *, char *, int); +int man_ml(char *, int); +int man(char *); Index: man/man/man.c diff -u man/man/man.c:1.1.1.1 man/man/man.c:1.8 --- man/man/man.c:1.1.1.1 Tue Jul 17 10:34:21 2001 +++ man/man/man.c Tue Jan 15 21:19:48 2002 @@ -37,6 +37,7 @@ #include "config.h" #include "gripes.h" #include "version.h" +#include "locale.h" #ifdef POSIX #include @@ -87,9 +88,6 @@ static int whatis; static int findall; static int print_where; -#ifdef LOCALE -static int force_original; -#endif #ifdef ALT_SYSTEMS static int alt_system; @@ -99,17 +97,19 @@ static int troff = 0; int debug; +int insecure; +int ignore_cat_file; #ifdef HAS_TROFF #ifdef ALT_SYSTEMS #ifdef LOCALE -static char args[] = "M:P:S:adfhkm:op:tw?"; +static char args[] = "M:P:S:adfhikm:op:tw?"; #else static char args[] = "M:P:S:adfhkm:p:tw?"; #endif #else #ifdef LOCALE -static char args[] = "M:P:S:adfhkop:tw?"; +static char args[] = "M:P:S:adfhikop:tw?"; #else static char args[] = "M:P:S:adfhkp:tw?"; #endif @@ -117,13 +117,13 @@ #else #ifdef ALT_SYSTEMS #ifdef LOCALE -static char args[] = "M:P:S:adfhkm:op:w?"; +static char args[] = "M:P:S:adfhikm:op:w?"; #else static char args[] = "M:P:S:adfhkm:p:w?"; #endif #else #ifdef LOCALE -static char args[] = "M:P:S:adfhkop:w?"; +static char args[] = "M:P:S:adfhikop:w?"; #else static char args[] = "M:P:S:adfhkp:w?"; #endif @@ -222,7 +222,7 @@ } else { - status = man (nextarg); + status = man_ml (nextarg, findall); if (status == 0) gripe_not_found (nextarg, section); @@ -334,46 +334,20 @@ } char ** -#ifdef LOCALE -add_dir_to_mpath_list (mp, pp, locale) -#else add_dir_to_mpath_list (mp, p) -#endif char **mp; -#ifdef LOCALE - char *pp; - int locale; -#else char *p; -#endif { int status; -#ifdef LOCALE - char *p; - char *tmp_locale; - int num_expand = 1; - - if (locale && (tmp_locale = strdup(current_locale)) != NULL) - { - if (tmp_locale[2] == '_') - num_expand++; - if (tmp_locale[5] == '.') - num_expand++; - } + char q[MAXPATHLEN+1]; - while (num_expand > 0) { - if (locale) - { - static char buf[FILENAME_MAX]; - - snprintf(buf, (size_t)(FILENAME_MAX - 1), "%s/%s", pp, tmp_locale); - p = buf; - } - else - { - p = pp; - } -#endif + if (p && *p != '/') { + insecure++; + getcwd(q, sizeof(q) - 1); + strcat(q, "/"); + strncat(q, p, sizeof(q) - strlen(q) - 1); + p = q; + } status = is_directory (p); @@ -392,21 +366,6 @@ *mp++ = strdup (p); } -#ifdef LOCALE - num_expand--; - if (locale) - { - if (num_expand > 1) - { - tmp_locale[5] = '\0'; - } - else if (num_expand > 0) - { - tmp_locale[2] = '\0'; - } - } - } -#endif return mp; } @@ -422,9 +381,6 @@ register char *p; register char *end; register char **mp; -#ifdef LOCALE - register int locale; -#endif extern void downcase (); extern char *manpath (); @@ -458,6 +414,11 @@ gripe_incompatible ("-f and -w"); whatis++; break; +#ifdef LOCALE + case 'i': + ignore_cat_file++; + break; +#endif case 'k': if (troff) gripe_incompatible ("-k and -t"); @@ -475,7 +436,7 @@ #endif #ifdef LOCALE case 'o': - force_original++; + force_original_man++; break; #endif case 'p': @@ -510,11 +471,13 @@ } if (pager == NULL || *pager == '\0') - if ((pager = getenv ("PAGER")) == NULL) - pager = strdup (PAGER); + pager = getenv ("PAGER"); if (debug) - fprintf (stderr, "\nusing %s as pager\n", pager); + if (pager) + fprintf (stderr, "\nusing %s as pager\n", pager); + else + fprintf (stderr, "\nusing default pager\n"); if ((machine = getenv ("MACHINE")) == NULL) machine = MACHINE; @@ -546,12 +509,6 @@ * Expand the manpath into a list for easier handling. */ mp = manpathlist; -#ifdef LOCALE - for (locale = 1; locale >= 0; locale--) - { - if (locale && (force_original || !current_locale || *current_locale == '\0')) - continue; -#endif for (p = manp; ; p = end+1) { if (mp == manpathlist + MAXDIRS - 1) { @@ -572,35 +529,20 @@ snprintf(buf, sizeof(buf), "%s/%s", p, alt_system_name); -# ifdef LOCALE - mp = add_dir_to_mpath_list (mp, buf, locale); -# else mp = add_dir_to_mpath_list (mp, buf); -# endif } else { -# ifdef LOCALE - mp = add_dir_to_mpath_list (mp, p, locale); -# else mp = add_dir_to_mpath_list (mp, p); -# endif } #else -# ifdef LOCALE - mp = add_dir_to_mpath_list (mp, p, locale); -# else mp = add_dir_to_mpath_list (mp, p); -# endif #endif if (end == NULL) break; *end = ':'; } -#ifdef LOCALE - } -#endif *mp = NULL; } @@ -879,9 +821,11 @@ char *expander = get_expander (file); if (expander != NULL) - snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager); + snprintf (command, sizeof(command), "%s %s | %s", expander, file, + pager ? pager : directive(N_PAGER)); else - snprintf (command, sizeof(command), "%s %s", pager, file); + snprintf (command, sizeof(command), "%s %s", + pager ? pager : directive(N_PAGER), file); found = do_system_command (command); } @@ -992,9 +936,9 @@ fprintf (stderr, "found eqn(1) directive\n"); if (troff) - add_directive (&first, EQN, file, buf, bufsize); + add_directive (&first, directive(N_EQN), file, buf, bufsize); else - add_directive (&first, NEQN, file, buf, bufsize); + add_directive (&first, directive(N_NEQN), file, buf, bufsize); break; @@ -1003,7 +947,7 @@ if (debug) fprintf (stderr, "found grap(1) directive\n"); - add_directive (&first, GRAP, file, buf, bufsize); + add_directive (&first, directive(N_GRAP), file, buf, bufsize); break; @@ -1012,7 +956,7 @@ if (debug) fprintf (stderr, "found pic(1) directive\n"); - add_directive (&first, PIC, file, buf, bufsize); + add_directive (&first, directive(N_PIC), file, buf, bufsize); break; @@ -1022,7 +966,7 @@ fprintf (stderr, "found tbl(1) directive\n"); tbl_found++; - add_directive (&first, TBL, file, buf, bufsize); + add_directive (&first, directive(N_TBL), file, buf, bufsize); break; case 'v': @@ -1030,7 +974,7 @@ if (debug) fprintf (stderr, "found vgrind(1) directive\n"); - add_directive (&first, VGRIND, file, buf, bufsize); + add_directive (&first, directive(N_VGRIND), file, buf, bufsize); break; case 'r': @@ -1038,7 +982,7 @@ if (debug) fprintf (stderr, "found refer(1) directive\n"); - add_directive (&first, REFER, file, buf, bufsize); + add_directive (&first, directive(N_REFER), file, buf, bufsize); break; case ' ': @@ -1062,18 +1006,18 @@ if (troff) { strncat (buf, " | ", bufsize-strlen(buf)-1); - strncat (buf, TROFF, bufsize-strlen(buf)-1); + strncat (buf, directive(N_TROFF), bufsize-strlen(buf)-1); } else #endif { strncat (buf, " | ", bufsize-strlen(buf)-1); - strncat (buf, NROFF, bufsize-strlen(buf)-1); + strncat (buf, directive(N_NROFF), bufsize-strlen(buf)-1); } - if (tbl_found && !troff && strcmp (COL, "") != 0) + if (tbl_found && !troff && strcmp (directive(N_COL), "") != 0) { strncat (buf, " | ", bufsize-strlen(buf)-1); - strncat (buf, COL, bufsize-strlen(buf)-1); + strncat (buf, directive(N_COL), bufsize-strlen(buf)-1); } return 0; @@ -1155,35 +1099,35 @@ #ifdef HAS_TROFF if (troff) { - if (strcmp (TBL, "") != 0) + if (strcmp (directive(N_TBL), "") != 0) { - strncat(buf, TBL, sizeof(buf)-strlen(buf)-1); + strncat(buf, directive(N_TBL), sizeof(buf)-strlen(buf)-1); strncat(buf, " | ", sizeof(buf)-strlen(buf)-1); - strncat(buf, TROFF, sizeof(buf)-strlen(buf)-1); + strncat(buf, directive(N_TROFF), sizeof(buf)-strlen(buf)-1); } else { - strncat(buf, TROFF, sizeof(buf)-strlen(buf)-1); + strncat(buf, directive(N_TROFF), sizeof(buf)-strlen(buf)-1); } } else #endif { - if (strcmp (TBL, "") != 0) + if (strcmp (directive(N_TBL), "") != 0) { - strncat(buf, TBL, sizeof(buf)-strlen(buf)-1); + strncat(buf, directive(N_TBL), sizeof(buf)-strlen(buf)-1); strncat(buf, " | ", sizeof(buf)-strlen(buf)-1); - strncat(buf, NROFF, sizeof(buf)-strlen(buf)-1); + strncat(buf, directive(N_NROFF), sizeof(buf)-strlen(buf)-1); } else { - strncpy (buf, NROFF, sizeof(buf)); + strncpy (buf, directive(N_NROFF), sizeof(buf)); } - if (strcmp (COL, "") != 0) + if (strcmp (directive(N_COL), "") != 0) { strncat (buf, " | ", sizeof(buf)-strlen(buf)-1); - strncat (buf, COL, sizeof(buf)-strlen(buf)-1); + strncat (buf, directive(N_COL), sizeof(buf)-strlen(buf)-1); } } return buf; @@ -1414,7 +1358,7 @@ if (debug) fprintf (stderr, "status from is_newer() = %d\n", status); - if (status == 1 || status == -2) + if (status == 1 || status == -2 || ignore_cat_file) { /* * Cat file is out of date. Try to format and save it. @@ -1424,9 +1368,10 @@ printf ("%s\n", man_file); found++; } - else + else if (!insecure) { - + if (debug) + fprintf(stderr, "secure mode\n"); #ifdef SETREUID setreuid(-1, euid); setregid(-1, egid); @@ -1485,11 +1430,23 @@ return 0; else snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path, - roff_command, pager); + roff_command, pager ? pager : directive(N_PAGER)); found = do_system_command (command); } } + else + { + if (debug) + fprintf (stderr, "insecure mode\n"); + roff_command = make_roff_command (man_file); + if (roff_command == NULL) + return 0; + else + snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path, + roff_command, pager ? pager : directive(N_PAGER)); + found = do_system_command (command); + } } else if (access (cat_file, R_OK) == 0) { @@ -1643,6 +1600,7 @@ register int glob; register char **mp; register char **sp; + char buf[BUFSIZ], **path; found = 0; @@ -1656,9 +1614,9 @@ glob = 1; - found += try_section (*mp, section, name, glob); + found += try_section_ml (*mp, section, name, glob, findall); - if (found && !findall) /* i.e. only do this section... */ + if (found && !findall) /* i.e. only do this section... */ return found; } } @@ -1673,7 +1631,7 @@ glob = 1; - found += try_section (*mp, *sp, name, glob); + found += try_section_ml (*mp, *sp, name, glob, findall); if (found && !findall) /* i.e. only do this section... */ return found;