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 $
17 * $DragonFly: src/gnu/usr.bin/man/man/man.c,v 1.2 2003/06/17 04:25:46 dillon Exp $
24 #include <sys/param.h>
50 extern uid_t getuid ();
57 extern char *malloc ();
58 extern char *getenv ();
62 extern int strncmp ();
66 extern int fprintf ();
67 extern FILE *fopen ();
69 extern char *sprintf ();
72 extern char **glob_filename ();
73 extern int is_newer ();
74 extern int is_directory ();
75 extern int do_system_command ();
81 static char *manpathlist[MAXDIRS];
82 static char *shortsec;
84 static char *colon_sep_section_list;
85 static char **section_list;
86 static char *roff_directive;
90 static int print_where;
93 static char *locale, *locale_opts, *locale_nroff, *locale_codeset;
94 static char locale_terr[3], locale_lang[3];
95 static char *man_locale;
96 static int use_man_locale;
97 static int use_original;
102 static struct ltable ltable[] = {
103 {"KOI8-R", "koi8-r"},
104 {"ISO8859-1", "latin1"},
105 {"ISO8859-15", "latin1"},
110 static int troff = 0;
116 static char args[] = "M:P:S:adfhkm:op:tw?";
118 static char args[] = "M:P:S:adfhkm:p:tw?";
122 static char args[] = "M:P:S:adfhkm:op:w?";
124 static char args[] = "M:P:S:adfhkm:p:w?";
143 extern char *mkprogname ();
145 char **get_section_list ();
151 prognam = mkprogname (argv[0]);
156 (void) setlocale(LC_ALL, "");
158 man_getopt (argc, argv);
161 gripe_no_name ((char *)NULL);
163 section_list = get_section_list ();
165 if (optind == argc - 1)
167 tmp = is_section (argv[optind], manp);
182 while (optind < argc)
184 nextarg = argv[optind++];
187 * See if this argument is a valid section name. If not,
188 * is_section returns NULL.
190 tmp = is_section (nextarg, manp);
197 fprintf (stderr, "\nsection: %s\n", shortsec);
203 do_apropos (nextarg);
204 status = (status ? 0 : 1); /* reverts status, see below */
208 status = (status ? 0 : 1); /* reverts status, see below */
212 status = man (nextarg);
215 gripe_not_found (nextarg, longsec);
218 return (status==0); /* status==1 --> exit(0),
219 status==0 --> exit(1) */
225 static char usage_string[1024] = "%s, version %s\n\n";
230 "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\
231 [-m machine] [-p string] name ...\n\n";
234 "usage: %s [-adfhktw] [section] [-M path] [-P pager] [-S list]\n\
235 [-m machine] [-p string] name ...\n\n";
240 "usage: %s [-adfhkow] [section] [-M path] [-P pager] [-S list]\n\
241 [-m machine] [-p string] name ...\n\n";
244 "usage: %s [-adfhkw] [section] [-M path] [-P pager] [-S list]\n\
245 [-m machine] [-p string] name ...\n\n";
249 static char s2[] = " a : find all matching entries\n\
250 d : print gobs of debugging information\n\
251 f : same as whatis(1)\n\
252 h : print this help message\n\
253 k : same as apropos(1)\n";
256 static char s3[] = " o : use original, non-localized manpages\n";
260 static char s4[] = " t : use troff to format pages for printing\n";
263 static char s5[] = " w : print location of man page(s) that would be displayed\n\n\
264 M path : set search path for manual pages to `path'\n\
265 P pager : use program `pager' to display pages\n\
266 S list : colon separated section list\n\
267 m machine : search for alternate architecture man pages\n";
269 static char s6[] = " p string : string tells which preprocessors to run\n\
270 e - [n]eqn(1) p - pic(1) t - tbl(1)\n\
271 g - grap(1) r - refer(1) v - vgrind(1)\n";
273 strcat (usage_string, s1);
274 strcat (usage_string, s2);
276 strcat (usage_string, s3);
280 strcat (usage_string, s4);
283 strcat (usage_string, s5);
285 strcat (usage_string, s6);
287 fprintf (stderr, usage_string, prognam, version, prognam);
292 add_dir_to_mpath_list (mp, p)
298 status = is_directory (p);
300 if (status < 0 && debug)
302 fprintf (stderr, "Warning: couldn't stat file %s!\n", p);
304 else if (status == 0 && debug)
306 fprintf (stderr, "Warning: %s isn't a directory!\n", p);
308 else if (status == 1)
311 fprintf (stderr, "adding %s to manpathlist\n", p);
319 * Get options from the command line and user environment.
322 man_getopt (argc, argv)
324 register char **argv;
330 extern void downcase ();
331 extern char *manpath ();
333 while ((c = getopt (argc, argv, args)) != EOF)
338 manp = strdup (optarg);
341 pager = strdup (optarg);
342 if (setenv("PAGER", pager, 1) != 0)
343 (void)fprintf(stderr, "setenv PAGER=%s\n", pager);
346 colon_sep_section_list = strdup (optarg);
356 gripe_incompatible ("-f and -t");
358 gripe_incompatible ("-f and -k");
360 gripe_incompatible ("-f and -w");
365 gripe_incompatible ("-k and -t");
367 gripe_incompatible ("-k and -f");
369 gripe_incompatible ("-k and -w");
381 roff_directive = strdup (optarg);
386 gripe_incompatible ("-t and -k");
388 gripe_incompatible ("-t and -f");
390 gripe_incompatible ("-t and -w");
396 gripe_incompatible ("-w and -k");
398 gripe_incompatible ("-w and -f");
400 gripe_incompatible ("-w and -t");
412 /* "" intentionally used to catch error */
413 if ((locale = setlocale(LC_CTYPE, "")) != NULL)
414 locale_codeset = nl_langinfo(CODESET);
415 if (!use_original && locale != NULL && *locale_codeset != '\0' &&
416 strcmp(locale_codeset, "US-ASCII") != 0
418 char *tmp, *short_locale;
419 struct ltable *pltable;
424 if ((short_locale = strdup(locale)) == NULL) {
425 perror ("ctype locale strdup");
428 if ((tmp = strchr(short_locale, '.')) != NULL)
431 if (strlen(short_locale) == 2)
432 strcpy(locale_lang, short_locale);
433 else if ((tmp = strchr(short_locale, '_')) == NULL ||
434 tmp != short_locale + 2 ||
438 perror ("ctype locale format");
441 strncpy(locale_terr, short_locale + 3, 2);
442 locale_terr[2] = '\0';
443 strncpy(locale_lang, short_locale, 2);
444 locale_lang[2] = '\0';
449 if (locale != NULL) {
450 for (pltable = ltable; pltable->lcode != NULL; pltable++) {
451 if (strcmp(pltable->lcode, locale_codeset) == 0) {
452 locale_nroff = pltable->nroff;
456 asprintf(&man_locale, "%s.%s", locale_lang, locale_codeset);
459 if (locale == NULL) {
461 perror ("ctype locale");
464 if (*locale_codeset == '\0') {
466 perror ("ctype codeset");
470 #endif /* __FreeBSD__ */
472 if (pager == NULL || *pager == '\0')
473 if ((pager = getenv ("PAGER")) == NULL || *pager == '\0')
474 pager = strdup (PAGER);
477 fprintf (stderr, "\nusing %s as pager\n", pager);
479 if (machine == NULL && (machine = getenv ("MACHINE")) == NULL)
483 fprintf (stderr, "\nusing %s architecture\n", machine);
487 if ((manp = manpath (0)) == NULL)
492 "\nsearch path for pages determined by manpath is\n%s\n\n",
497 * Expand the manpath into a list for easier handling.
500 for (p = manp; ; p = end+1)
502 if (mp == manpathlist + MAXDIRS - 1) {
503 fprintf (stderr, "Warning: too many directories in manpath, truncated!\n");
506 if ((end = strchr (p, ':')) != NULL)
509 mp = add_dir_to_mpath_list (mp, p);
519 * Check to see if the argument is a valid section number. If the
520 * first character of name is a numeral, or the name matches one of
521 * the sections listed in section_list, we'll assume that it's a section.
522 * The list of sections in config.h simply allows us to specify oddly
523 * named directories like .../man3f. Yuk.
526 is_section (name, path)
531 char *temp, *end, *loc;
535 for (vs = section_list; *vs != NULL; vs++)
536 if ((strcmp (*vs, name) == 0)
537 || (isdigit ((unsigned char)name[0]) && strlen(name) == 1))
538 return (longsec = strdup (name));
541 if (isdigit ((unsigned char)name[0]))
543 while (*plist != NULL)
545 asprintf(&temp, "%s/man%c/*", *plist, name[0]);
549 vs = glob_filename (temp);
555 for ( ; *vs != NULL; vs++)
557 end = strrchr (*vs, '/');
558 if ((loc = strstr (end, name)) != NULL && loc - end > 2
560 && (*(loc+strlen(name)) == '\0' || *(loc+strlen(name)) == '.'))
569 asprintf(&temp, "%c", name[0]);
570 longsec = strdup (name);
579 * Handle the apropos option. Cheat by using another program.
586 register char *command;
588 len = strlen (APROPOS) + strlen (name) + 4;
590 if ((command = (char *) malloc(len)) == NULL)
591 gripe_alloc (len, "command");
593 sprintf (command, "%s \"%s\"", APROPOS, name);
595 (void) do_system_command (command);
601 * Handle the whatis option. Cheat by using another program.
608 register char *command;
610 len = strlen (WHATIS) + strlen (name) + 4;
612 if ((command = (char *) malloc(len)) == NULL)
613 gripe_alloc (len, "command");
615 sprintf (command, "%s \"%s\"", WHATIS, name);
617 (void) do_system_command (command);
623 * Change a name of the form ...man/man1/name.1 to ...man/cat1/name.1
624 * or a name of the form ...man/cat1/name.1 to ...man/man1/name.1
627 convert_name (name, to_cat)
631 register char *to_name;
633 register char *t2 = NULL;
638 int olen = strlen(name);
639 int cextlen = strlen(COMPRESS_EXT);
640 int len = olen + cextlen;
642 to_name = malloc (len+1);
644 gripe_alloc (len+1, "to_name");
645 strcpy (to_name, name);
647 /* Avoid tacking it on twice */
648 if (olen >= 1 && strcmp(name + olen, COMPRESS_EXT) != 0)
649 strcat (to_name, COMPRESS_EXT);
652 to_name = strdup (name);
654 to_name = strdup (name);
657 t1 = strrchr (to_name, '/');
661 t2 = strrchr (to_name, '/');
664 /* Skip architecture part (if present). */
665 if (t2 != NULL && (t1 - t2 < 5 || *(t2 + 1) != 'm' || *(t2 + 3) != 'n'))
669 t2 = strrchr (to_name, '/');
675 gripe_converting_name (name, to_cat);
689 fprintf (stderr, "to_name in convert_name () is: %s\n", to_name);
695 * Try to find the man page corresponding to the given name. The
696 * reason we do this with globbing is because some systems have man
697 * page directories named man3 which contain files with names like
698 * XtPopup.3Xt. Rather than requiring that this program know about
699 * all those possible names, we simply try to match things like
700 * .../man[sect]/name[sect]*. This is *much* easier.
702 * Note that globbing is only done when the section is unspecified.
705 glob_for_file (path, section, longsec, name, cat)
712 char pathname[FILENAME_MAX];
719 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%s*", path, section,
722 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%s*", path, section,
726 fprintf (stderr, "globbing %s\n", pathname);
728 gf = glob_filename (pathname);
730 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
731 && strlen (longsec) == 1)
734 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%c*", path, section, name, *section);
736 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%c*", path, section, name, *section);
738 gf = glob_filename (pathname);
740 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
741 && strlen (longsec) == 1)
744 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.0*", path, section, name);
746 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.0*", path, section, name);
748 fprintf (stderr, "globbing %s\n", pathname);
749 gf = glob_filename (pathname);
755 * Return an un-globbed name in the same form as if we were doing
759 make_name (path, section, longsec, name, cat)
767 static char *names[3];
768 char buf[FILENAME_MAX];
771 snprintf (buf, sizeof(buf), "%s/cat%s/%s.%s", path, section, name, longsec);
773 snprintf (buf, sizeof(buf), "%s/man%s/%s.%s", path, section, name, longsec);
775 if (access (buf, R_OK) == 0)
776 names[i++] = strdup (buf);
779 * If we're given a section that looks like `3f', we may want to try
780 * file names like .../man3/foo.3f as well. This seems a bit
781 * kludgey to me, but what the hey...
783 if (section[1] != '\0')
786 snprintf (buf, sizeof(buf), "%s/cat%c/%s.%s", path, section[0], name, section);
788 snprintf (buf, sizeof(buf), "%s/man%c/%s.%s", path, section[0], name, section);
790 if (access (buf, R_OK) == 0)
791 names[i++] = strdup (buf);
803 char *end = file + (strlen (file) - 1);
805 while (end > file && end[-1] != '.')
818 if (*end == 'Z' || !strcmp(end, "gz"))
825 * Simply display the preformatted page.
828 display_cat_file (file)
832 char command[FILENAME_MAX];
836 if (access (file, R_OK) == 0)
838 char *expander = get_expander (file);
840 if (expander != NULL)
841 snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager);
843 snprintf (command, sizeof(command), "%s %s", pager, file);
845 found = do_system_command (command);
851 * Try to find the ultimate source file. If the first line of the
852 * current file is not of the form
856 * the input file name is returned.
859 ultimate_source (name, path)
863 static char buf[BUFSIZ];
864 static char ult[FILENAME_MAX];
870 strncpy (ult, name, sizeof(ult)-1);
871 ult[sizeof(ult)-1] = '\0';
872 strncpy (buf, name, sizeof(buf)-1);
873 ult[sizeof(buf)-1] = '\0';
877 if ((fp = fopen (ult, "r")) == NULL)
880 end = fgets (buf, BUFSIZ, fp);
883 if (!end || strlen (buf) < 5)
887 if (*beg++ == '.' && *beg++ == 's' && *beg++ == 'o')
889 while ((*beg == ' ' || *beg == '\t') && *beg != '\0')
893 while (*end != ' ' && *end != '\t' && *end != '\n' && *end != '\0')
898 snprintf(ult, sizeof(ult), "%s/%s", path, beg);
899 snprintf(buf, sizeof(buf), "%s", ult);
905 fprintf (stderr, "found ultimate source file %s\n", ult);
911 add_directive (first, d, file, buf, bufsize)
918 if (strcmp (d, "") != 0)
923 snprintf(buf, bufsize, "%s %s", d, file);
927 strncat (buf, " | ", bufsize-strlen(buf)-1);
928 strncat (buf, d, bufsize-strlen(buf)-1);
934 parse_roff_directive (cp, file, buf, bufsize)
943 int preproc_found = 0;
946 if ((exp = get_expander(file)) != NULL)
947 add_directive (&first, exp, file, buf, bufsize);
949 while ((c = *cp++) != '\0')
956 fprintf (stderr, "found eqn(1) directive\n");
960 add_directive (&first, EQN, file, buf, bufsize);
963 char lbuf[FILENAME_MAX];
965 snprintf(lbuf, sizeof(lbuf), "%s -T%s", NEQN,
966 locale_opts == NULL ? "ascii" : locale_opts);
967 add_directive (&first, lbuf, file, buf, bufsize);
969 add_directive (&first, NEQN, file, buf, bufsize);
978 fprintf (stderr, "found grap(1) directive\n");
981 add_directive (&first, GRAP, file, buf, bufsize);
988 fprintf (stderr, "found pic(1) directive\n");
991 add_directive (&first, PIC, file, buf, bufsize);
998 fprintf (stderr, "found tbl(1) directive\n");
1002 add_directive (&first, TBL, file, buf, bufsize);
1008 fprintf (stderr, "found vgrind(1) directive\n");
1010 add_directive (&first, VGRIND, file, buf, bufsize);
1016 fprintf (stderr, "found refer(1) directive\n");
1018 add_directive (&first, REFER, file, buf, bufsize);
1037 add_directive (&first, TROFF, file, buf, bufsize);
1042 char lbuf[FILENAME_MAX];
1044 snprintf(lbuf, sizeof(lbuf), "%s -T%s%s%s", NROFF,
1045 locale_opts == NULL ? "ascii" : locale_opts,
1046 use_man_locale ? " -dlocale=" : "",
1047 use_man_locale ? man_locale : "");
1048 add_directive (&first, lbuf, file, buf, bufsize);
1050 add_directive (&first, NROFF " -Tascii", file, buf, bufsize);
1053 if (use_col && !troff)
1054 add_directive (&first, COL, file, buf, bufsize);
1063 make_roff_command (file)
1072 static char buf [BUFSIZ];
1076 if (roff_directive != NULL)
1079 fprintf (stderr, "parsing directive from command line\n");
1081 status = parse_roff_directive (roff_directive, file, buf, sizeof(buf));
1087 gripe_roff_command_from_command_line (file);
1091 if ((fp = gzopen (file, "r")) != NULL)
1093 if ((fp = fopen (file, "r")) != NULL)
1098 gzgets (fp, line, BUFSIZ);
1101 fgets (line, BUFSIZ, fp);
1104 if (*cp++ == '\'' && *cp++ == '\\' && *cp++ == '"' && *cp++ == ' ')
1107 fprintf (stderr, "parsing directive from file\n");
1109 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1115 gripe_roff_command_from_file (file);
1121 * Is there really any point in continuing to look for
1122 * preprocessor options if we can't even read the man page source?
1124 gripe_reading_man_file (file);
1128 if ((cp = getenv ("MANROFFSEQ")) != NULL)
1131 fprintf (stderr, "parsing directive from environment\n");
1133 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1139 gripe_roff_command_from_env ();
1143 fprintf (stderr, "using default preprocessor sequence\n");
1145 status = parse_roff_directive ("t", file, buf, sizeof(buf));
1148 else /* can't happen */
1152 sig_t ohup, oint, oquit, oterm;
1153 static char temp[FILENAME_MAX];
1164 ohup = signal(SIGHUP, cleantmp);
1165 oint = signal(SIGINT, cleantmp);
1166 oquit = signal(SIGQUIT, cleantmp);
1167 oterm = signal(SIGTERM, cleantmp);
1173 signal(SIGHUP, ohup);
1174 signal(SIGINT, oint);
1175 signal(SIGQUIT, oquit);
1176 signal(SIGTERM, oterm);
1180 * Try to format the man page and create a new formatted file. Return
1181 * 1 for success and 0 for failure.
1184 make_cat_file (path, man_file, cat_file, manid)
1185 register char *path;
1186 register char *man_file;
1187 register char *cat_file;
1192 char command[FILENAME_MAX];
1194 roff_command = make_roff_command (man_file);
1195 if (roff_command == NULL)
1198 snprintf(temp, sizeof(temp), "%s.tmpXXXXXX", cat_file);
1199 if ((f = mkstemp(temp)) >= 0 && (fp = fdopen(f, "w")) != NULL)
1203 if (fchmod (f, CATMODE) < 0) {
1210 fprintf (stderr, "mode of %s is now %o\n", temp, CATMODE);
1213 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1214 roff_command, COMPRESSOR);
1216 snprintf (command, sizeof(command), "(cd %s ; %s)", path,
1219 fprintf (stderr, "Formatting page, please wait...");
1223 fprintf (stderr, "\ntrying command: %s\n", command);
1232 if ((pp = popen(command, "r")) == NULL) {
1234 fprintf(stderr, "Failed.\n");
1256 while ((s = getc(pp)) != EOF) {
1260 if (!f || ((s = pclose(pp)) == -1)) {
1262 fprintf(stderr, "Failed.\n");
1272 fprintf(stderr, "Failed.\n");
1273 gripe_system_command(s);
1283 else if (rename(temp, cat_file) == -1) {
1286 "\nHmm! Can't seem to rename %s to %s, check permissions on man dir!\n",
1301 fprintf(stderr, "Failed.\n");
1308 fprintf(stderr, "No output, debug mode.\n");
1312 fprintf(stderr, "Done.\n");
1325 fprintf (stderr, "Couldn't open %s for writing.\n", temp);
1338 * Try to format the man page source and save it, then display it. If
1339 * that's not possible, try to format the man page source and display
1342 * Note that we've already been handed the name of the ultimate source
1343 * file at this point.
1346 format_and_display (path, man_file, cat_file)
1347 register char *path;
1348 register char *man_file;
1349 register char *cat_file;
1354 char command[FILENAME_MAX];
1358 if (access (man_file, R_OK) != 0)
1363 roff_command = make_roff_command (man_file);
1364 if (roff_command == NULL)
1367 snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command);
1369 found = do_system_command (command);
1373 status = is_newer (man_file, cat_file);
1375 fprintf (stderr, "status from is_newer() = %d\n", status);
1377 if (status == 1 || status == -2)
1380 * Cat file is out of date. Try to format and save it.
1384 printf ("%s\n", man_file);
1393 found = make_cat_file (path, man_file, cat_file, 1);
1395 found = make_cat_file (path, man_file, cat_file, 0);
1403 /* Try again as real user - see note below.
1405 effective group (user) ID == real group (user) ID
1406 except for the call above, I believe the problems
1407 of reading private man pages is avoided. */
1408 found = make_cat_file (path, man_file, cat_file, 0);
1411 #ifdef SECURE_MAN_UID
1415 * Try again as real user. Note that for private
1416 * man pages, we won't even get this far unless the
1417 * effective user can read the real user's man page
1418 * source. Also, if we are trying to find all the
1419 * man pages, this will probably make it impossible
1420 * to make cat files in the system directories if
1421 * the real user's man directories are searched
1422 * first, because there's no way to undo this (is
1423 * there?). Yikes, am I missing something obvious?
1427 found = make_cat_file (path, man_file, cat_file, 0);
1433 * Creating the cat file worked. Now just display it.
1435 (void) display_cat_file (cat_file);
1440 * Couldn't create cat file. Just format it and
1441 * display it through the pager.
1443 roff_command = make_roff_command (man_file);
1444 if (roff_command == NULL)
1447 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1448 roff_command, pager);
1450 found = do_system_command (command);
1454 else if (access (cat_file, R_OK) == 0)
1457 * Formatting not necessary. Cat file is newer than source
1458 * file, or source file is not present but cat file is.
1462 printf ("%s (source: %s)\n", cat_file, man_file);
1467 found = display_cat_file (cat_file);
1475 * See if the preformatted man page or the source exists in the given
1479 try_section (path, section, longsec, name, glob)
1486 register int found = 0;
1487 register int to_cat;
1489 register char **names;
1491 static int arch_search;
1492 char buf[FILENAME_MAX];
1496 snprintf(buf, sizeof(buf), "%s/man%s/%s", path, section, machine);
1497 if (is_directory (buf) == 1)
1499 snprintf(buf, sizeof(buf), "%s/%s", machine, name);
1501 found = try_section (path, section, longsec, buf, glob);
1503 if (found && !findall) /* only do this architecture... */
1511 fprintf (stderr, "trying section %s with globbing\n", section);
1513 fprintf (stderr, "trying section %s without globbing\n", section);
1516 #ifndef NROFF_MISSING
1518 * Look for man page source files.
1522 names = glob_for_file (path, section, longsec, name, cat);
1524 names = make_name (path, section, longsec, name, cat);
1526 if (names == (char **) -1 || *names == NULL)
1528 * No files match. See if there's a preformatted page around that
1531 #endif /* NROFF_MISSING */
1537 names = glob_for_file (path, section, longsec, name, cat);
1539 names = make_name (path, section, longsec, name, cat);
1541 if (names != (char **) -1 && *names != NULL)
1543 for (np = names; *np != NULL; np++)
1547 printf ("%s\n", *np);
1552 found += display_cat_file (*np);
1558 #ifndef NROFF_MISSING
1561 for (np = names; *np != NULL; np++)
1563 register char *cat_file = NULL;
1564 register char *man_file;
1566 man_file = ultimate_source (*np, path);
1572 cat_file = convert_name (man_file, to_cat);
1575 fprintf (stderr, "will try to write %s if needed\n", cat_file);
1578 found += format_and_display (path, man_file, cat_file);
1581 #endif /* NROFF_MISSING */
1586 * Search for manual pages.
1588 * If preformatted manual pages are supported, look for the formatted
1589 * file first, then the man page source file. If they both exist and
1590 * the man page source file is newer, or only the source file exists,
1591 * try to reformat it and write the results in the cat directory. If
1592 * it is not possible to write the cat file, simply format and display
1595 * If preformatted pages are not supported, or the troff option is
1596 * being used, only look for the man page source file.
1609 char buf[FILENAME_MAX];
1615 if (shortsec != NULL)
1617 for (mp = manpathlist; *mp != NULL; mp++)
1620 fprintf (stderr, "\nsearching in %s\n", *mp);
1626 if (locale != NULL) {
1627 locale_opts = locale_nroff;
1629 if (*locale_lang != '\0' && *locale_terr != '\0') {
1630 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1631 locale_lang, locale_terr, locale_codeset);
1632 if (is_directory (buf) == 1)
1633 l_found = try_section (buf, shortsec, longsec, name, glob);
1636 if (*locale_lang != '\0') {
1637 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1638 locale_lang, locale_codeset);
1639 if (is_directory (buf) == 1)
1640 l_found = try_section (buf, shortsec, longsec, name, glob);
1643 if (!l_found && strcmp(locale_lang, "en") != 0) {
1644 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1646 if (is_directory (buf) == 1)
1647 l_found = try_section (buf, shortsec, longsec, name, glob);
1655 found += try_section (*mp, shortsec, longsec, name, glob);
1661 if (found && !findall) /* i.e. only do this section... */
1667 for (sp = section_list; *sp != NULL; sp++)
1669 for (mp = manpathlist; *mp != NULL; mp++)
1672 fprintf (stderr, "\nsearching in %s\n", *mp);
1678 if (locale != NULL) {
1679 locale_opts = locale_nroff;
1681 if (*locale_lang != '\0' && *locale_terr != '\0') {
1682 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1683 locale_lang, locale_terr, locale_codeset);
1684 if (is_directory (buf) == 1)
1685 l_found = try_section (buf, *sp, longsec, name, glob);
1688 if (*locale_lang != '\0') {
1689 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1690 locale_lang, locale_codeset);
1691 if (is_directory (buf) == 1)
1692 l_found = try_section (buf, *sp, longsec, name, glob);
1695 if (!l_found && strcmp(locale_lang, "en") != 0) {
1696 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1698 if (is_directory (buf) == 1)
1699 l_found = try_section (buf, *sp, longsec, name, glob);
1707 found += try_section (*mp, *sp, longsec, name, glob);
1713 if (found && !findall) /* i.e. only do this section... */
1727 #define TMP_SECTION_LIST_SIZE 100
1728 static char *tmp_section_list[TMP_SECTION_LIST_SIZE];
1730 if (colon_sep_section_list == NULL)
1732 if ((p = getenv ("MANSECT")) == NULL)
1734 return std_sections;
1738 colon_sep_section_list = strdup (p);
1743 for (p = colon_sep_section_list; i < TMP_SECTION_LIST_SIZE ; p = end+1)
1745 if ((end = strchr (p, ':')) != NULL)
1748 tmp_section_list[i++] = strdup (p);
1754 tmp_section_list [i] = NULL;
1755 return tmp_section_list;