diff -urN --exclude=CVS jp-man-1.1k/man/Makefile jp-man-1.1k.new/man/Makefile --- jp-man-1.1k/man/Makefile Mon Jul 22 18:58:01 2002 +++ jp-man-1.1k.new/man/Makefile Tue Jul 23 18:07:16 2002 @@ -9,7 +9,7 @@ MAN_LIBZ=YES 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 @@ -25,6 +25,8 @@ .if ${OSVERSION} < 400020 LDADD+= -L/usr/lib -lxpg4 .endif + +man.o locale.o: locale.h DPADD+= ${MAN1} ${EMAN1} diff -urN --exclude=CVS jp-man-1.1k/man/README.jman-ex jp-man-1.1k.new/man/README.jman-ex --- jp-man-1.1k/man/README.jman-ex Thu Jan 1 09:00:00 1970 +++ jp-man-1.1k.new/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 $ diff -urN --exclude=CVS jp-man-1.1k/man/jman.man jp-man-1.1k.new/man/jman.man --- jp-man-1.1k/man/jman.man Mon Jul 22 20:34:17 2002 +++ jp-man-1.1k.new/man/jman.man Tue Jul 23 18:07:45 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 は、 @@ -105,11 +99,8 @@ .Ev MACHINE に優先します。 .It Fl o -環境変数 -.Ev LC_CTYPE -または -.Ev LANG -設定にかかわらず、オリジナルのマニュアルページ以外の探索・表示を抑制します。 +環境変数の設定にかかわらず、 +オリジナルのマニュアルページ以外の探索・表示を抑制します。 .It Fl p Ar string nroff や troff を行う前に実行するプリプロセッサの順序を指定します。 全てのプリプロセッサがインストールされているとはかぎりません。 @@ -132,17 +123,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 が指定されていれば、機種依存マニュアル検索時のアーキテクチャ名として、現在の機種種別の代わりにその値が用いられます。 .It Ev MANROFFSEQ @@ -158,6 +150,7 @@ セットされていなければ、 .Nm %pager% が使われます。 +.El .El .Sh 使用例 .Pp diff -urN --exclude=CVS jp-man-1.1k/man/locale.c jp-man-1.1k.new/man/locale.c --- jp-man-1.1k/man/locale.c Thu Jan 1 09:00:00 1970 +++ jp-man-1.1k.new/man/locale.c Tue Jul 23 18:09:45 2002 @@ -0,0 +1,374 @@ +/* $Id: locale.c,v 1.13 2002/07/23 09:09:45 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 *longsec, 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, longsec, 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; +} diff -urN --exclude=CVS jp-man-1.1k/man/locale.h jp-man-1.1k.new/man/locale.h --- jp-man-1.1k/man/locale.h Thu Jan 1 09:00:00 1970 +++ jp-man-1.1k.new/man/locale.h Tue Jul 23 18:08:50 2002 @@ -0,0 +1,25 @@ +/* $Id: locale.h,v 1.3 2002/07/23 09:08:50 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 *, char *, int, int); +int try_section(char *, char *, char *, char *, int); +int man_ml(char *, int); +int man(char *); diff -urN --exclude=CVS jp-man-1.1k/man/man.c jp-man-1.1k.new/man/man.c --- jp-man-1.1k/man/man.c Mon Jul 22 19:49:25 2002 +++ jp-man-1.1k.new/man/man.c Tue Jul 23 18:58:01 2002 @@ -40,6 +40,7 @@ #include "config.h" #include "gripes.h" #include "version.h" +#include "locale.h" #ifdef POSIX #include @@ -86,25 +87,24 @@ static int whatis; static int findall; static int print_where; -#ifdef LOCALE -static int force_original; -#endif static int troff = 0; int debug; +int insecure; +int ignore_cat_file; #ifdef HAS_TROFF #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:adfhkm:op:w?"; +static char args[] = "M:P:S:adfhikm:op:w?"; #else -static char args[] = "M:P:S:adfhkm:p:w?"; +static char args[] = "M:P:S:adfhikm:p:w?"; #endif #endif @@ -196,7 +196,7 @@ } else { - status = man (nextarg); + status = man_ml (nextarg, findall); if (status == 0) gripe_not_found (nextarg, longsec); @@ -277,46 +277,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); @@ -335,21 +309,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; } @@ -365,9 +324,6 @@ register char *p; register char *end; register char **mp; -#ifdef LOCALE - register int locale; -#endif extern void downcase (); extern char *manpath (); @@ -401,6 +357,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"); @@ -415,7 +376,7 @@ break; #ifdef LOCALE case 'o': - force_original++; + force_original_man++; break; #endif case 'p': @@ -450,11 +411,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 == NULL && (machine = getenv ("MACHINE")) == NULL) machine = MACHINE; @@ -477,12 +440,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) { @@ -492,19 +449,12 @@ if ((end = strchr (p, ':')) != NULL) *end = '\0'; -# ifdef LOCALE - mp = add_dir_to_mpath_list (mp, p, locale); -# else mp = add_dir_to_mpath_list (mp, p); -# endif if (end == NULL) break; *end = ':'; } -#ifdef LOCALE - } -#endif *mp = NULL; } @@ -577,16 +527,31 @@ { register int len; register char *command; + register char *name_escaped, *src, *dst; - len = strlen (APROPOS) + strlen (name) + 4; + if ((name_escaped = (char *) malloc(strlen(name) * 2 + 1)) == NULL) + gripe_alloc (len, "name_escaped"); + src = name; + dst = name_escaped; + while (*src) { + if (isalnum(*src)) { + *dst++ = *src++; + } else { + *dst++ = '\\'; + *dst++ = *src++; + } + } + len = strlen (APROPOS) + strlen (name_escaped) + 2; + if ((command = (char *) malloc(len)) == NULL) gripe_alloc (len, "command"); - sprintf (command, "%s \"%s\"", APROPOS, name); + sprintf (command, "%s %s", APROPOS, name_escaped); (void) do_system_command (command); + free (name_escaped); free (command); } @@ -830,9 +795,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); } @@ -943,9 +910,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; @@ -954,7 +921,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; @@ -963,7 +930,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; @@ -973,7 +940,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': @@ -981,7 +948,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': @@ -989,7 +956,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 ' ': @@ -1013,18 +980,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; @@ -1106,35 +1073,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; @@ -1359,7 +1326,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. @@ -1369,9 +1336,10 @@ printf ("%s\n", man_file); found++; } - else + else if (!insecure) { - + if (debug) + fprintf(stderr, "secure mode\n"); #ifdef SETUID seteuid(euid); found = make_cat_file (path, man_file, cat_file, 1); @@ -1407,11 +1375,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) { @@ -1460,7 +1440,7 @@ { snprintf(buf, sizeof(buf), "%s/%s", machine, name); arch_search++; - found = try_section (path, section, longsec, buf, glob); + found = try_section_ml (path, section, longsec, buf, glob, findall); arch_search--; if (found && !findall) /* only do this architecture... */ return found; @@ -1566,6 +1546,7 @@ register int glob; register char **mp; register char **sp; + char buf[BUFSIZ], **path; found = 0; @@ -1579,7 +1560,7 @@ glob = 1; - found += try_section (*mp, shortsec, longsec, name, glob); + found += try_section_ml (*mp, shortsec, longsec, name, glob, findall); if (found && !findall) /* i.e. only do this section... */ return found; @@ -1596,7 +1577,7 @@ glob = 1; - found += try_section (*mp, *sp, longsec, name, glob); + found += try_section_ml (*mp, *sp, longsec, name, glob, findall); if (found && !findall) /* i.e. only do this section... */ return found;