4 * Copyright (c) 1990, 1991, John W. Eaton.
6 * You may distribute under the terms of the GNU General Public
7 * License as specified in the file COPYING that comes with the man
12 * Department of Chemical Engineering
13 * The University of Texas at Austin
16 * $FreeBSD: src/gnu/usr.bin/man/man/man.c,v 1.37.2.10 2003/02/14 15:38:51 ru Exp $
23 #include <sys/param.h>
41 extern char **glob_filename (char *);
42 extern char *manpath (int);
44 char *is_section (char *);
45 char **get_section_list (void);
46 void man_getopt (int, char **);
47 void do_apropos (char *);
48 void do_whatis (char *);
51 char **add_dir_to_mpath_list (char **, char *);
52 char *convert_name (char *, int);
53 char **glob_for_file (char *, char *, char *, char *, int);
54 char **make_name (char *, char *, char *, char *, int);
55 const char *get_expander (char *);
56 int display_cat_file (char *);
57 char *ultimate_source (char *, char *);
58 void add_directive (int *, const char *, char *, char *, int);
59 int parse_roff_directive (const char *, char *, char *, int);
60 char *make_roff_command (char *);
63 void restore_sigs(void);
64 int make_cat_file (char *, char *, char *, int);
65 int format_and_display (char *, char *, char *);
66 int try_section (char *, char *, char *, char *, int);
70 static const char *machine;
72 static char *manpathlist[MAXDIRS];
73 static char *shortsec;
75 static char *colon_sep_section_list;
76 static char **section_list;
77 static char *roff_directive;
81 static int print_where;
83 static char *locale, *locale_codeset;
84 static const char *locale_nroff, *locale_opts;
85 static char locale_terr[3], locale_lang[3];
86 static char *man_locale;
87 static int use_man_locale;
88 static int use_original;
93 static struct ltable ltable[] = {
95 {"ISO8859-1", "latin1"},
96 {"ISO8859-15", "latin1"},
100 static int troff = 0;
104 static char args[] = "M:P:S:adfhkm:op:tw?";
112 main (int argc, char **argv)
118 prognam = mkprogname (argv[0]);
122 (void) setlocale(LC_ALL, "");
123 man_getopt (argc, argv);
126 gripe_no_name ((char *)NULL);
128 section_list = get_section_list ();
130 if (optind == argc - 1)
132 tmp = is_section (argv[optind]);
145 while (optind < argc)
147 nextarg = argv[optind++];
150 * See if this argument is a valid section name. If not,
151 * is_section returns NULL.
153 tmp = is_section (nextarg);
160 fprintf (stderr, "\nsection: %s\n", shortsec);
166 do_apropos (nextarg);
167 status = (status ? 0 : 1); /* reverts status, see below */
171 status = (status ? 0 : 1); /* reverts status, see below */
175 status = man (nextarg);
178 gripe_not_found (nextarg, longsec);
181 return (status==0); /* status==1 --> exit(0),
182 status==0 --> exit(1) */
188 static char usage_string[1024] = "%s, version %s\n\n";
191 "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\
192 [-m machine] [-p string] name ...\n\n";
194 static char s2[] = " a : find all matching entries\n\
195 d : print gobs of debugging information\n\
196 f : same as whatis(1)\n\
197 h : print this help message\n\
198 k : same as apropos(1)\n";
200 static char s3[] = " o : use original, non-localized manpages\n";
202 static char s4[] = " t : use troff to format pages for printing\n";
204 static char s5[] = " w : print location of man page(s) that would be displayed\n\n\
205 M path : set search path for manual pages to `path'\n\
206 P pager : use program `pager' to display pages\n\
207 S list : colon separated section list\n\
208 m machine : search for alternate architecture man pages\n";
210 static char s6[] = " p string : string tells which preprocessors to run\n\
211 e - [n]eqn(1) p - pic(1) t - tbl(1)\n\
212 g - grap(1) r - refer(1) v - vgrind(1)\n";
214 strcat (usage_string, s1);
215 strcat (usage_string, s2);
216 strcat (usage_string, s3);
218 strcat (usage_string, s4);
220 strcat (usage_string, s5);
222 strcat (usage_string, s6);
224 fprintf (stderr, usage_string, prognam, version, prognam);
229 add_dir_to_mpath_list (char **mp, char *p)
233 status = is_directory (p);
235 if (status < 0 && debug)
237 fprintf (stderr, "Warning: couldn't stat file %s!\n", p);
239 else if (status == 0 && debug)
241 fprintf (stderr, "Warning: %s isn't a directory!\n", p);
243 else if (status == 1)
246 fprintf (stderr, "adding %s to manpathlist\n", p);
254 * Get options from the command line and user environment.
257 man_getopt (int argc, char **argv)
264 while ((c = getopt (argc, argv, args)) != -1)
269 manp = strdup (optarg);
272 pager = strdup (optarg);
273 if (setenv("PAGER", pager, 1) != 0)
274 (void)fprintf(stderr, "setenv PAGER=%s\n", pager);
277 colon_sep_section_list = strdup (optarg);
287 gripe_incompatible ("-f and -t");
289 gripe_incompatible ("-f and -k");
291 gripe_incompatible ("-f and -w");
296 gripe_incompatible ("-k and -t");
298 gripe_incompatible ("-k and -f");
300 gripe_incompatible ("-k and -w");
310 roff_directive = strdup (optarg);
314 gripe_incompatible ("-t and -k");
316 gripe_incompatible ("-t and -f");
318 gripe_incompatible ("-t and -w");
323 gripe_incompatible ("-w and -k");
325 gripe_incompatible ("-w and -f");
327 gripe_incompatible ("-w and -t");
338 /* "" intentionally used to catch error */
339 if ((locale = setlocale(LC_CTYPE, "")) != NULL)
340 locale_codeset = nl_langinfo(CODESET);
341 if (!use_original && locale != NULL && *locale_codeset != '\0' &&
342 strcmp(locale_codeset, "US-ASCII") != 0
344 char *tmp, *short_locale;
345 struct ltable *pltable;
350 if ((short_locale = strdup(locale)) == NULL) {
351 perror ("ctype locale strdup");
354 if ((tmp = strchr(short_locale, '.')) != NULL)
357 if (strlen(short_locale) == 2)
358 strcpy(locale_lang, short_locale);
359 else if ((tmp = strchr(short_locale, '_')) == NULL ||
360 tmp != short_locale + 2 ||
364 perror ("ctype locale format");
367 strncpy(locale_terr, short_locale + 3, 2);
368 locale_terr[2] = '\0';
369 strncpy(locale_lang, short_locale, 2);
370 locale_lang[2] = '\0';
375 if (locale != NULL) {
376 for (pltable = ltable; pltable->lcode != NULL; pltable++) {
377 if (strcmp(pltable->lcode, locale_codeset) == 0) {
378 locale_nroff = pltable->nroff;
382 asprintf(&man_locale, "%s.%s", locale_lang, locale_codeset);
385 if (locale == NULL) {
387 perror ("ctype locale");
390 if (*locale_codeset == '\0') {
392 perror ("ctype codeset");
397 if (pager == NULL || *pager == '\0')
398 if ((pager = getenv ("PAGER")) == NULL || *pager == '\0')
399 pager = strdup (PAGER);
402 fprintf (stderr, "\nusing %s as pager\n", pager);
404 if (machine == NULL && (machine = getenv ("MACHINE")) == NULL)
408 fprintf (stderr, "\nusing %s architecture\n", machine);
412 if ((manp = manpath (0)) == NULL)
417 "\nsearch path for pages determined by manpath is\n%s\n\n",
422 * Expand the manpath into a list for easier handling.
425 for (p = manp; ; p = end+1)
427 if (mp == manpathlist + MAXDIRS - 1) {
428 fprintf (stderr, "Warning: too many directories in manpath, truncated!\n");
431 if ((end = strchr (p, ':')) != NULL)
434 mp = add_dir_to_mpath_list (mp, p);
444 * Check to see if the argument is a valid section number. If the
445 * first character of name is a numeral, or the name matches one of
446 * the sections listed in section_list, we'll assume that it's a section.
447 * The list of sections in config.h simply allows us to specify oddly
448 * named directories like .../man3f. Yuk.
451 is_section (char *name)
454 char *temp, *end, *loc;
458 for (vs = section_list; *vs != NULL; vs++)
459 if ((strcmp (*vs, name) == 0)
460 || (isdigit ((unsigned char)name[0]) && strlen(name) == 1))
461 return (longsec = strdup (name));
464 if (isdigit ((unsigned char)name[0]))
466 while (*plist != NULL)
468 asprintf(&temp, "%s/man%c/*", *plist, name[0]);
472 vs = glob_filename (temp);
473 if (vs == (char **)-1)
478 for ( ; *vs != NULL; vs++)
480 end = strrchr (*vs, '/');
481 if ((loc = strstr (end, name)) != NULL && loc - end > 2
483 && (*(loc+strlen(name)) == '\0' || *(loc+strlen(name)) == '.'))
492 asprintf(&temp, "%c", name[0]);
493 longsec = strdup (name);
502 * Handle the apropos option. Cheat by using another program.
505 do_apropos (char *name)
510 len = strlen (APROPOS) + strlen (name) + 4;
512 if ((command = (char *) malloc(len)) == NULL)
513 gripe_alloc (len, "command");
515 sprintf (command, "%s \"%s\"", APROPOS, name);
517 (void) do_system_command (command);
523 * Handle the whatis option. Cheat by using another program.
526 do_whatis (char *name)
531 len = strlen (WHATIS) + strlen (name) + 4;
533 if ((command = (char *) malloc(len)) == NULL)
534 gripe_alloc (len, "command");
536 sprintf (command, "%s \"%s\"", WHATIS, name);
538 (void) do_system_command (command);
544 * Change a name of the form ...man/man1/name.1 to ...man/cat1/name.1
545 * or a name of the form ...man/cat1/name.1 to ...man/man1/name.1
548 convert_name (char *name, int to_cat)
556 int olen = strlen(name);
557 int cextlen = strlen(COMPRESS_EXT);
558 int len = olen + cextlen;
560 to_name = malloc (len+1);
562 gripe_alloc (len+1, "to_name");
563 strcpy (to_name, name);
565 /* Avoid tacking it on twice */
566 if (olen >= 1 && strcmp(name + olen, COMPRESS_EXT) != 0)
567 strcat (to_name, COMPRESS_EXT);
570 to_name = strdup (name);
572 t1 = strrchr (to_name, '/');
576 t2 = strrchr (to_name, '/');
579 /* Skip architecture part (if present). */
580 if (t2 != NULL && (t1 - t2 < 5 || *(t2 + 1) != 'm' || *(t2 + 3) != 'n'))
584 t2 = strrchr (to_name, '/');
590 gripe_converting_name (name, to_cat);
604 fprintf (stderr, "to_name in convert_name () is: %s\n", to_name);
610 * Try to find the man page corresponding to the given name. The
611 * reason we do this with globbing is because some systems have man
612 * page directories named man3 which contain files with names like
613 * XtPopup.3Xt. Rather than requiring that this program know about
614 * all those possible names, we simply try to match things like
615 * .../man[sect]/name[sect]*. This is *much* easier.
617 * Note that globbing is only done when the section is unspecified.
620 glob_for_file (char *path, char *section, char *_longsec, char *name, int cat)
622 char pathname[FILENAME_MAX];
625 if (_longsec == NULL)
629 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%s*", path, section,
632 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%s*", path, section,
636 fprintf (stderr, "globbing %s\n", pathname);
638 gf = glob_filename (pathname);
640 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
641 && strlen (_longsec) == 1)
644 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%c*", path, section, name, *section);
646 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%c*", path, section, name, *section);
648 gf = glob_filename (pathname);
650 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
651 && strlen (_longsec) == 1)
654 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.0*", path, section, name);
656 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.0*", path, section, name);
658 fprintf (stderr, "globbing %s\n", pathname);
659 gf = glob_filename (pathname);
665 * Return an un-globbed name in the same form as if we were doing
669 make_name (char *path, char *section, char *_longsec, char *name, int cat)
672 static char *names[3];
673 char buf[FILENAME_MAX];
676 snprintf (buf, sizeof(buf), "%s/cat%s/%s.%s", path, section, name, _longsec);
678 snprintf (buf, sizeof(buf), "%s/man%s/%s.%s", path, section, name, _longsec);
680 if (access (buf, R_OK) == 0)
681 names[i++] = strdup (buf);
684 * If we're given a section that looks like `3f', we may want to try
685 * file names like .../man3/foo.3f as well. This seems a bit
686 * kludgey to me, but what the hey...
688 if (section[1] != '\0')
691 snprintf (buf, sizeof(buf), "%s/cat%c/%s.%s", path, section[0], name, section);
693 snprintf (buf, sizeof(buf), "%s/man%c/%s.%s", path, section[0], name, section);
695 if (access (buf, R_OK) == 0)
696 names[i++] = strdup (buf);
705 get_expander (char *file)
707 char *end = file + (strlen (file) - 1);
709 while (end > file && end[-1] != '.')
722 if (*end == 'Z' || !strcmp(end, "gz"))
729 * Simply display the preformatted page.
732 display_cat_file (char *file)
735 char command[FILENAME_MAX];
739 if (access (file, R_OK) == 0)
741 const char *expander = get_expander (file);
743 if (expander != NULL)
744 snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager);
746 snprintf (command, sizeof(command), "%s %s", pager, file);
748 found = do_system_command (command);
754 * Try to find the ultimate source file. If the first line of the
755 * current file is not of the form
759 * the input file name is returned.
762 ultimate_source (char *name, char *path)
764 static char buf[BUFSIZ];
765 static char ult[FILENAME_MAX];
771 strncpy (ult, name, sizeof(ult)-1);
772 ult[sizeof(ult)-1] = '\0';
773 strncpy (buf, name, sizeof(buf)-1);
774 ult[sizeof(buf)-1] = '\0';
778 if ((fp = fopen (ult, "r")) == NULL)
781 end = fgets (buf, BUFSIZ, fp);
784 if (!end || strlen (buf) < 5)
788 if (*beg++ == '.' && *beg++ == 's' && *beg++ == 'o')
790 while ((*beg == ' ' || *beg == '\t') && *beg != '\0')
794 while (*end != ' ' && *end != '\t' && *end != '\n' && *end != '\0')
799 snprintf(ult, sizeof(ult), "%s/%s", path, beg);
800 snprintf(buf, sizeof(buf), "%s", ult);
806 fprintf (stderr, "found ultimate source file %s\n", ult);
812 add_directive (int *first, const char *d, char *file, char *buf, int bufsize)
814 if (strcmp (d, "") != 0)
819 snprintf(buf, bufsize, "%s %s", d, file);
823 strncat (buf, " | ", bufsize-strlen(buf)-1);
824 strncat (buf, d, bufsize-strlen(buf)-1);
830 parse_roff_directive (const char *cp, char *file, char *buf, int bufsize)
835 int preproc_found = 0;
838 if ((exp = get_expander(file)) != NULL)
839 add_directive (&first, exp, file, buf, bufsize);
841 while ((c = *cp++) != '\0')
848 fprintf (stderr, "found eqn(1) directive\n");
852 add_directive (&first, EQN, file, buf, bufsize);
854 char lbuf[FILENAME_MAX];
856 snprintf(lbuf, sizeof(lbuf), "%s -T%s", NEQN,
857 locale_opts == NULL ? "ascii" : locale_opts);
858 add_directive (&first, lbuf, file, buf, bufsize);
866 fprintf (stderr, "found grap(1) directive\n");
869 add_directive (&first, GRAP, file, buf, bufsize);
876 fprintf (stderr, "found pic(1) directive\n");
879 add_directive (&first, PIC, file, buf, bufsize);
886 fprintf (stderr, "found tbl(1) directive\n");
890 add_directive (&first, TBL, file, buf, bufsize);
896 fprintf (stderr, "found vgrind(1) directive\n");
898 add_directive (&first, VGRIND, file, buf, bufsize);
904 fprintf (stderr, "found refer(1) directive\n");
906 add_directive (&first, REFER, file, buf, bufsize);
924 add_directive (&first, TROFF, file, buf, bufsize);
927 char lbuf[FILENAME_MAX];
929 snprintf(lbuf, sizeof(lbuf), "%s -T%s%s%s", NROFF,
930 locale_opts == NULL ? "ascii" : locale_opts,
931 use_man_locale ? " -dlocale=" : "",
932 use_man_locale ? man_locale : "");
933 add_directive (&first, lbuf, file, buf, bufsize);
935 if (use_col && !troff)
936 add_directive (&first, COL, file, buf, bufsize);
945 make_roff_command (char *file)
949 static char buf [BUFSIZ];
953 if (roff_directive != NULL)
956 fprintf (stderr, "parsing directive from command line\n");
958 status = parse_roff_directive (roff_directive, file, buf, sizeof(buf));
964 gripe_roff_command_from_command_line ();
967 if ((fp = gzopen (file, "r")) != NULL)
970 gzgets (fp, line, BUFSIZ);
972 if (*cp++ == '\'' && *cp++ == '\\' && *cp++ == '"' && *cp++ == ' ')
975 fprintf (stderr, "parsing directive from file\n");
977 status = parse_roff_directive (cp, file, buf, sizeof(buf));
983 gripe_roff_command_from_file (file);
989 * Is there really any point in continuing to look for
990 * preprocessor options if we can't even read the man page source?
992 gripe_reading_man_file (file);
996 if ((cp = getenv ("MANROFFSEQ")) != NULL)
999 fprintf (stderr, "parsing directive from environment\n");
1001 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1007 gripe_roff_command_from_env ();
1011 fprintf (stderr, "using default preprocessor sequence\n");
1013 status = parse_roff_directive ("t", file, buf, sizeof(buf));
1016 else /* can't happen */
1020 sig_t ohup, oint, oquit, oterm;
1021 static char temp[FILENAME_MAX];
1024 cleantmp(int signo __unused)
1033 ohup = signal(SIGHUP, cleantmp);
1034 oint = signal(SIGINT, cleantmp);
1035 oquit = signal(SIGQUIT, cleantmp);
1036 oterm = signal(SIGTERM, cleantmp);
1042 signal(SIGHUP, ohup);
1043 signal(SIGINT, oint);
1044 signal(SIGQUIT, oquit);
1045 signal(SIGTERM, oterm);
1049 * Try to format the man page and create a new formatted file. Return
1050 * 1 for success and 0 for failure.
1053 make_cat_file (char *path, char *man_file, char *cat_file, int manid)
1058 char command[FILENAME_MAX];
1060 roff_command = make_roff_command (man_file);
1061 if (roff_command == NULL)
1064 snprintf(temp, sizeof(temp), "%s.tmpXXXXXX", cat_file);
1065 if ((f = mkstemp(temp)) >= 0 && (fp = fdopen(f, "w")) != NULL)
1069 if (fchmod (f, CATMODE) < 0) {
1076 fprintf (stderr, "mode of %s is now %o\n", temp, CATMODE);
1078 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1079 roff_command, COMPRESSOR);
1080 fprintf (stderr, "Formatting page, please wait...");
1084 fprintf (stderr, "\ntrying command: %s\n", command);
1090 if ((pp = popen(command, "r")) == NULL) {
1092 fprintf(stderr, "Failed.\n");
1110 while ((s = getc(pp)) != EOF) {
1114 if (!f || ((s = pclose(pp)) == -1)) {
1116 fprintf(stderr, "Failed.\n");
1126 fprintf(stderr, "Failed.\n");
1127 gripe_system_command(s);
1137 else if (rename(temp, cat_file) == -1) {
1140 "\nHmm! Can't seem to rename %s to %s, check permissions on man dir!\n",
1155 fprintf(stderr, "Failed.\n");
1162 fprintf(stderr, "No output, debug mode.\n");
1166 fprintf(stderr, "Done.\n");
1179 fprintf (stderr, "Couldn't open %s for writing.\n", temp);
1192 * Try to format the man page source and save it, then display it. If
1193 * that's not possible, try to format the man page source and display
1196 * Note that we've already been handed the name of the ultimate source
1197 * file at this point.
1200 format_and_display (char *path, char *man_file, char *cat_file)
1205 char command[FILENAME_MAX];
1209 if (access (man_file, R_OK) != 0)
1214 roff_command = make_roff_command (man_file);
1215 if (roff_command == NULL)
1218 snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command);
1220 found = do_system_command (command);
1224 if (cat_file == NULL)
1225 goto format_and_display;
1227 status = is_newer (man_file, cat_file);
1229 fprintf (stderr, "status from is_newer() = %d\n", status);
1231 if (status == 1 || status == -2)
1234 * Cat file is out of date. Try to format and save it.
1238 printf ("%s\n", man_file);
1246 found = make_cat_file (path, man_file, cat_file, 1);
1252 /* Try again as real user - see note below.
1254 effective group (user) ID == real group (user) ID
1255 except for the call above, I believe the problems
1256 of reading private man pages is avoided. */
1257 found = make_cat_file (path, man_file, cat_file, 0);
1262 * Creating the cat file worked. Now just display it.
1264 (void) display_cat_file (cat_file);
1269 * Couldn't create cat file. Just format it and
1270 * display it through the pager.
1273 roff_command = make_roff_command (man_file);
1274 if (roff_command == NULL)
1277 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1278 roff_command, pager);
1280 found = do_system_command (command);
1284 else if (access (cat_file, R_OK) == 0)
1287 * Formatting not necessary. Cat file is newer than source
1288 * file, or source file is not present but cat file is.
1292 printf ("%s (source: %s)\n", cat_file, man_file);
1297 found = display_cat_file (cat_file);
1305 * See if the preformatted man page or the source exists in the given
1309 try_section (char *path, char *section, char *_longsec, char *name, int glob)
1316 static int arch_search;
1317 char buf[FILENAME_MAX];
1321 snprintf(buf, sizeof(buf), "%s/man%s/%s", path, section, machine);
1322 if (is_directory (buf) == 1)
1324 snprintf(buf, sizeof(buf), "%s/%s", machine, name);
1326 found = try_section (path, section, _longsec, buf, glob);
1328 if (found && !findall) /* only do this architecture... */
1336 fprintf (stderr, "trying section %s with globbing\n", section);
1338 fprintf (stderr, "trying section %s without globbing\n", section);
1341 #ifndef NROFF_MISSING
1343 * Look for man page source files.
1347 names = glob_for_file (path, section, _longsec, name, cat);
1349 names = make_name (path, section, _longsec, name, cat);
1351 if (names == (char **) -1 || *names == NULL)
1353 * No files match. See if there's a preformatted page around that
1356 #endif /* NROFF_MISSING */
1362 names = glob_for_file (path, section, _longsec, name, cat);
1364 names = make_name (path, section, _longsec, name, cat);
1366 if (names != (char **) -1 && *names != NULL)
1368 for (np = names; *np != NULL; np++)
1372 printf ("%s\n", *np);
1377 found += display_cat_file (*np);
1383 #ifndef NROFF_MISSING
1386 for (np = names; *np != NULL; np++)
1388 char *cat_file = NULL;
1391 man_file = ultimate_source (*np, path);
1397 cat_file = convert_name (man_file, to_cat);
1400 fprintf (stderr, "will try to write %s if needed\n", cat_file);
1403 found += format_and_display (path, man_file, cat_file);
1406 #endif /* NROFF_MISSING */
1411 * Search for manual pages.
1413 * If preformatted manual pages are supported, look for the formatted
1414 * file first, then the man page source file. If they both exist and
1415 * the man page source file is newer, or only the source file exists,
1416 * try to reformat it and write the results in the cat directory. If
1417 * it is not possible to write the cat file, simply format and display
1420 * If preformatted pages are not supported, or the troff option is
1421 * being used, only look for the man page source file.
1437 if (strchr(name, '/')) /* Treat name as file name if it's a path */
1442 fprintf(stderr, "Trying as file name\n");
1445 * We need to pass an absolute file name to format_and_display,
1446 * or it will run into problems later.
1448 realpath(name, buf);
1450 if (stat(buf, &st) == 0)
1451 found += format_and_display(dirname(buf), buf, NULL);
1453 else if (shortsec != NULL)
1455 for (mp = manpathlist; *mp != NULL; mp++)
1458 fprintf (stderr, "\nsearching in %s\n", *mp);
1463 if (locale != NULL) {
1464 locale_opts = locale_nroff;
1466 if (*locale_lang != '\0' && *locale_terr != '\0') {
1467 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1468 locale_lang, locale_terr, locale_codeset);
1469 if (is_directory (buf) == 1)
1470 l_found = try_section (buf, shortsec, longsec, name, glob);
1473 if (*locale_lang != '\0') {
1474 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1475 locale_lang, locale_codeset);
1476 if (is_directory (buf) == 1)
1477 l_found = try_section (buf, shortsec, longsec, name, glob);
1480 if (!l_found && strcmp(locale_lang, "en") != 0) {
1481 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1483 if (is_directory (buf) == 1)
1484 l_found = try_section (buf, shortsec, longsec, name, glob);
1491 found += try_section (*mp, shortsec, longsec, name, glob);
1495 if (found && !findall) /* i.e. only do this section... */
1501 for (sp = section_list; *sp != NULL; sp++)
1503 for (mp = manpathlist; *mp != NULL; mp++)
1506 fprintf (stderr, "\nsearching in %s\n", *mp);
1511 if (locale != NULL) {
1512 locale_opts = locale_nroff;
1514 if (*locale_lang != '\0' && *locale_terr != '\0') {
1515 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1516 locale_lang, locale_terr, locale_codeset);
1517 if (is_directory (buf) == 1)
1518 l_found = try_section (buf, *sp, longsec, name, glob);
1521 if (*locale_lang != '\0') {
1522 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1523 locale_lang, locale_codeset);
1524 if (is_directory (buf) == 1)
1525 l_found = try_section (buf, *sp, longsec, name, glob);
1528 if (!l_found && strcmp(locale_lang, "en") != 0) {
1529 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1531 if (is_directory (buf) == 1)
1532 l_found = try_section (buf, *sp, longsec, name, glob);
1539 found += try_section (*mp, *sp, longsec, name, glob);
1543 if (found && !findall) /* i.e. only do this section... */
1552 get_section_list (void)
1557 #define TMP_SECTION_LIST_SIZE 100
1558 static char *tmp_section_list[TMP_SECTION_LIST_SIZE];
1560 if (colon_sep_section_list == NULL)
1562 if ((p = getenv ("MANSECT")) == NULL)
1564 return __DECONST(char **, std_sections);
1568 colon_sep_section_list = strdup (p);
1573 for (p = colon_sep_section_list; i < TMP_SECTION_LIST_SIZE ; p = end+1)
1575 if ((end = strchr (p, ':')) != NULL)
1578 tmp_section_list[i++] = strdup (p);
1584 tmp_section_list [i] = NULL;
1585 return tmp_section_list;