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
18 static const char rcsid[] =
26 #include <sys/param.h>
27 #include <sys/utsname.h>
55 extern char *malloc ();
56 extern char *getenv ();
60 extern int strncmp ();
64 extern int fprintf ();
65 extern FILE *fopen ();
67 extern char *sprintf ();
70 extern char **glob_filename ();
71 extern int is_newer ();
72 extern int is_directory ();
73 extern int do_system_command ();
77 static char *machine_arch;
80 static char *manpathlist[MAXDIRS];
81 static char *shortsec;
83 static char *colon_sep_section_list;
84 static char **section_list;
85 static char *roff_directive;
89 static int print_where;
92 static char *locale, *locale_opts, *locale_nroff, *locale_codeset;
93 static char locale_terr[3], locale_lang[3];
94 static char *man_locale;
95 static int use_man_locale;
96 static int use_original;
101 static struct ltable ltable[] = {
102 {"KOI8-R", "koi8-r"},
103 {"ISO8859-1", "latin1"},
104 {"ISO8859-15", "latin1"},
109 static int troff = 0;
115 static char args[] = "M:P:S:adfhkm:op:tw?";
117 static char args[] = "M:P:S:adfhkm:p:tw?";
121 static char args[] = "M:P:S:adfhkm:op:w?";
123 static char args[] = "M:P:S:adfhkm:p:w?";
140 extern char *mkprogname ();
142 char **get_section_list ();
148 prognam = mkprogname (argv[0]);
153 (void) setlocale(LC_ALL, "");
155 man_getopt (argc, argv);
158 gripe_no_name ((char *)NULL);
160 section_list = get_section_list ();
162 if (optind == argc - 1)
164 tmp = is_section (argv[optind], manp);
176 while (optind < argc)
178 nextarg = argv[optind++];
181 * See if this argument is a valid section name. If not,
182 * is_section returns NULL.
184 tmp = is_section (nextarg, manp);
191 fprintf (stderr, "\nsection: %s\n", shortsec);
197 do_apropos (nextarg);
198 status = (status ? 0 : 1); /* reverts status, see below */
202 status = (status ? 0 : 1); /* reverts status, see below */
206 status = man (nextarg);
209 gripe_not_found (nextarg, longsec);
212 return (status==0); /* status==1 --> exit(0),
213 status==0 --> exit(1) */
219 static char usage_string[1024] = "%s, version %s\n\n";
224 "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\
225 [-m machine] [-p string] name ...\n\n";
228 "usage: %s [-adfhktw] [section] [-M path] [-P pager] [-S list]\n\
229 [-m machine] [-p string] name ...\n\n";
234 "usage: %s [-adfhkow] [section] [-M path] [-P pager] [-S list]\n\
235 [-m machine] [-p string] name ...\n\n";
238 "usage: %s [-adfhkw] [section] [-M path] [-P pager] [-S list]\n\
239 [-m machine] [-p string] name ...\n\n";
243 static char s2[] = " a : find all matching entries\n\
244 d : print gobs of debugging information\n\
245 f : same as whatis(1)\n\
246 h : print this help message\n\
247 k : same as apropos(1)\n";
250 static char s3[] = " o : use original, non-localized manpages\n";
254 static char s4[] = " t : use troff to format pages for printing\n";
257 static char s5[] = " w : print location of man page(s) that would be displayed\n\n\
258 M path : set search path for manual pages to `path'\n\
259 P pager : use program `pager' to display pages\n\
260 S list : colon separated section list\n\
261 m machine : search for alternate architecture man pages\n";
263 static char s6[] = " p string : string tells which preprocessors to run\n\
264 e - [n]eqn(1) p - pic(1) t - tbl(1)\n\
265 g - grap(1) r - refer(1) v - vgrind(1)\n";
267 strcat (usage_string, s1);
268 strcat (usage_string, s2);
270 strcat (usage_string, s3);
274 strcat (usage_string, s4);
277 strcat (usage_string, s5);
279 strcat (usage_string, s6);
281 fprintf (stderr, usage_string, prognam, version, prognam);
286 add_dir_to_mpath_list (mp, p)
292 status = is_directory (p);
294 if (status < 0 && debug)
296 fprintf (stderr, "Warning: couldn't stat file %s!\n", p);
298 else if (status == 0 && debug)
300 fprintf (stderr, "Warning: %s isn't a directory!\n", p);
302 else if (status == 1)
305 fprintf (stderr, "adding %s to manpathlist\n", p);
313 * Get options from the command line and user environment.
316 man_getopt (argc, argv)
318 register char **argv;
324 extern void downcase ();
325 extern char *manpath ();
327 while ((c = getopt (argc, argv, args)) != EOF)
332 manp = strdup (optarg);
335 pager = strdup (optarg);
336 if (setenv("PAGER", pager, 1) != 0)
337 (void)fprintf(stderr, "setenv PAGER=%s\n", pager);
340 colon_sep_section_list = strdup (optarg);
350 gripe_incompatible ("-f and -t");
352 gripe_incompatible ("-f and -k");
354 gripe_incompatible ("-f and -w");
359 gripe_incompatible ("-k and -t");
361 gripe_incompatible ("-k and -f");
363 gripe_incompatible ("-k and -w");
367 machine_arch = optarg;
368 if ((machine = strchr(optarg, ':')) != NULL)
379 roff_directive = strdup (optarg);
384 gripe_incompatible ("-t and -k");
386 gripe_incompatible ("-t and -f");
388 gripe_incompatible ("-t and -w");
394 gripe_incompatible ("-w and -k");
396 gripe_incompatible ("-w and -f");
398 gripe_incompatible ("-w and -t");
410 /* "" intentionally used to catch error */
411 if ((locale = setlocale(LC_CTYPE, "")) != NULL)
412 locale_codeset = nl_langinfo(CODESET);
413 if (!use_original && locale != NULL && *locale_codeset != '\0' &&
414 strcmp(locale_codeset, "US-ASCII") != 0
416 char *tmp, *short_locale;
417 struct ltable *pltable;
422 if ((short_locale = strdup(locale)) == NULL) {
423 perror ("ctype locale strdup");
426 if ((tmp = strchr(short_locale, '.')) != NULL)
429 if (strlen(short_locale) == 2)
430 strcpy(locale_lang, short_locale);
431 else if ((tmp = strchr(short_locale, '_')) == NULL ||
432 tmp != short_locale + 2 ||
436 perror ("ctype locale format");
439 strncpy(locale_terr, short_locale + 3, 2);
440 locale_terr[2] = '\0';
441 strncpy(locale_lang, short_locale, 2);
442 locale_lang[2] = '\0';
447 if (locale != NULL) {
448 for (pltable = ltable; pltable->lcode != NULL; pltable++) {
449 if (strcmp(pltable->lcode, locale_codeset) == 0) {
450 locale_nroff = pltable->nroff;
454 asprintf(&man_locale, "%s.%s", locale_lang, locale_codeset);
457 if (locale == NULL) {
459 perror ("ctype locale");
462 if (*locale_codeset == '\0') {
464 perror ("ctype codeset");
468 #endif /* __FreeBSD__ */
470 if (pager == NULL || *pager == '\0')
471 if ((pager = getenv ("PAGER")) == NULL || *pager == '\0')
472 pager = strdup (PAGER);
475 fprintf (stderr, "\nusing %s as pager\n", pager);
477 if (machine_arch == NULL && (machine_arch = getenv ("MACHINE_ARCH")) == NULL)
478 machine_arch = MACHINE_ARCH;
480 if (machine == NULL && (machine = getenv ("MACHINE")) == NULL)
482 static struct utsname utsname;
484 if (uname(&utsname) == -1)
489 machine = utsname.machine;
493 fprintf (stderr, "\nusing %s:%s architecture\n", machine_arch, machine);
497 if ((manp = manpath (0)) == NULL)
502 "\nsearch path for pages determined by manpath is\n%s\n\n",
507 * Expand the manpath into a list for easier handling.
510 for (p = manp; ; p = end+1)
512 if (mp == manpathlist + MAXDIRS - 1) {
513 fprintf (stderr, "Warning: too many directories in manpath, truncated!\n");
516 if ((end = strchr (p, ':')) != NULL)
519 mp = add_dir_to_mpath_list (mp, p);
529 * Check to see if the argument is a valid section number. If the
530 * first character of name is a numeral, or the name matches one of
531 * the sections listed in section_list, we'll assume that it's a section.
532 * The list of sections in config.h simply allows us to specify oddly
533 * named directories like .../man3f. Yuk.
536 is_section (name, path)
541 char *temp, *end, *loc;
545 for (vs = section_list; *vs != NULL; vs++)
546 if ((strcmp (*vs, name) == 0)
547 || (isdigit ((unsigned char)name[0]) && strlen(name) == 1))
548 return (longsec = strdup(name));
551 if (isdigit ((unsigned char)name[0]))
553 while (*plist != NULL)
555 asprintf (&temp, "%s/man%c/*", *plist, name[0]);
559 vs = glob_filename (temp);
560 if (vs == (char **) -1)
565 for ( ; *vs != NULL; vs++)
567 end = strrchr (*vs, '/');
568 if ((loc = strstr (end, name)) != NULL && loc - end > 2
570 && (*(loc+strlen(name)) == '\0' || *(loc+strlen(name)) == '.'))
579 asprintf (&temp, "%c", name[0]);
580 longsec = strdup (name);
589 * Handle the apropos option. Cheat by using another program.
596 register char *command;
598 len = strlen (APROPOS) + strlen (name) + 4;
600 if ((command = (char *) malloc(len)) == NULL)
601 gripe_alloc (len, "command");
603 sprintf (command, "%s \"%s\"", APROPOS, name);
605 (void) do_system_command (command);
611 * Handle the whatis option. Cheat by using another program.
618 register char *command;
620 len = strlen (WHATIS) + strlen (name) + 4;
622 if ((command = (char *) malloc(len)) == NULL)
623 gripe_alloc (len, "command");
625 sprintf (command, "%s \"%s\"", WHATIS, name);
627 (void) do_system_command (command);
633 * Change a name of the form ...man/man1/name.1 to ...man/cat1/name.1
634 * or a name of the form ...man/cat1/name.1 to ...man/man1/name.1
637 convert_name (name, to_cat)
641 register char *to_name;
643 register char *t2 = NULL;
648 int olen = strlen(name);
649 int cextlen = strlen(COMPRESS_EXT);
650 int len = olen + cextlen;
652 to_name = malloc (len+1);
654 gripe_alloc (len+1, "to_name");
655 strcpy (to_name, name);
657 /* Avoid tacking it on twice */
658 if (olen >= 1 && strcmp(name + olen, COMPRESS_EXT) != 0)
659 strcat (to_name, COMPRESS_EXT);
662 to_name = strdup (name);
664 to_name = strdup (name);
667 t1 = strrchr (to_name, '/');
671 t2 = strrchr (to_name, '/');
674 /* Skip architecture part (if present). */
675 if (t2 != NULL && (t1 - t2 < 5 || *(t2 + 1) != 'm' || *(t2 + 3) != 'n'))
679 t2 = strrchr (to_name, '/');
685 gripe_converting_name (name, to_cat);
699 fprintf (stderr, "to_name in convert_name () is: %s\n", to_name);
705 * Try to find the man page corresponding to the given name. The
706 * reason we do this with globbing is because some systems have man
707 * page directories named man3 which contain files with names like
708 * XtPopup.3Xt. Rather than requiring that this program know about
709 * all those possible names, we simply try to match things like
710 * .../man[sect]/name[sect]*. This is *much* easier.
712 * Note that globbing is only done when the section is unspecified.
715 glob_for_file (path, section, longsec, name, cat)
722 char pathname[FILENAME_MAX];
729 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%s*", path, section,
732 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%s*", path, section,
736 fprintf (stderr, "globbing %s\n", pathname);
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.%c*", path, section, name, *section);
746 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%c*", path, section, name, *section);
748 gf = glob_filename (pathname);
750 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
751 && strlen (longsec) == 1)
754 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.0*", path, section, name);
756 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.0*", path, section, name);
758 fprintf (stderr, "globbing %s\n", pathname);
759 gf = glob_filename (pathname);
765 * Return an un-globbed name in the same form as if we were doing
769 make_name (path, section, longsec, name, cat)
777 static char *names[3];
778 char buf[FILENAME_MAX];
781 snprintf (buf, sizeof(buf), "%s/cat%s/%s.%s", path, section, name, longsec);
783 snprintf (buf, sizeof(buf), "%s/man%s/%s.%s", path, section, name, longsec);
785 if (access (buf, R_OK) == 0)
786 names[i++] = strdup (buf);
789 * If we're given a section that looks like `3f', we may want to try
790 * file names like .../man3/foo.3f as well. This seems a bit
791 * kludgey to me, but what the hey...
793 if (section[1] != '\0')
796 snprintf (buf, sizeof(buf), "%s/cat%c/%s.%s", path, section[0], name, section);
798 snprintf (buf, sizeof(buf), "%s/man%c/%s.%s", path, section[0], name, section);
800 if (access (buf, R_OK) == 0)
801 names[i++] = strdup (buf);
813 char *end = file + (strlen (file) - 1);
815 while (end > file && end[-1] != '.')
828 if (*end == 'Z' || !strcmp(end, "gz"))
835 * Simply display the preformatted page.
838 display_cat_file (file)
842 char command[FILENAME_MAX];
846 if (access (file, R_OK) == 0)
848 char *expander = get_expander (file);
850 if (expander != NULL)
851 snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager);
853 snprintf (command, sizeof(command), "%s %s", pager, file);
855 found = do_system_command (command);
861 * Try to find the ultimate source file. If the first line of the
862 * current file is not of the form
866 * the input file name is returned.
869 ultimate_source (name, path)
873 static char buf[BUFSIZ];
874 static char ult[FILENAME_MAX];
880 strncpy (ult, name, sizeof(ult)-1);
881 ult[sizeof(ult)-1] = '\0';
882 strncpy (buf, name, sizeof(buf)-1);
883 ult[sizeof(buf)-1] = '\0';
887 if ((fp = fopen (ult, "r")) == NULL)
890 end = fgets (buf, BUFSIZ, fp);
893 if (!end || strlen (buf) < 5)
897 if (*beg++ == '.' && *beg++ == 's' && *beg++ == 'o')
899 while ((*beg == ' ' || *beg == '\t') && *beg != '\0')
903 while (*end != ' ' && *end != '\t' && *end != '\n' && *end != '\0')
908 snprintf(ult, sizeof(ult), "%s/%s", path, beg);
909 snprintf(buf, sizeof(buf), "%s", ult);
915 fprintf (stderr, "found ultimate source file %s\n", ult);
921 add_directive (first, d, file, buf, bufsize)
928 if (strcmp (d, "") != 0)
933 snprintf(buf, bufsize, "%s %s", d, file);
937 strncat (buf, " | ", bufsize-strlen(buf)-1);
938 strncat (buf, d, bufsize-strlen(buf)-1);
944 parse_roff_directive (cp, file, buf, bufsize)
953 int preproc_found = 0;
956 if ((exp = get_expander(file)) != NULL)
957 add_directive (&first, exp, file, buf, bufsize);
959 while ((c = *cp++) != '\0')
966 fprintf (stderr, "found eqn(1) directive\n");
970 add_directive (&first, EQN, file, buf, bufsize);
973 char lbuf[FILENAME_MAX];
975 snprintf(lbuf, sizeof(lbuf), "%s -T%s", NEQN,
976 locale_opts == NULL ? "ascii" : locale_opts);
977 add_directive (&first, lbuf, file, buf, bufsize);
979 add_directive (&first, NEQN, file, buf, bufsize);
988 fprintf (stderr, "found grap(1) directive\n");
991 add_directive (&first, GRAP, file, buf, bufsize);
998 fprintf (stderr, "found pic(1) directive\n");
1001 add_directive (&first, PIC, file, buf, bufsize);
1008 fprintf (stderr, "found tbl(1) directive\n");
1012 add_directive (&first, TBL, file, buf, bufsize);
1018 fprintf (stderr, "found vgrind(1) directive\n");
1020 add_directive (&first, VGRIND, file, buf, bufsize);
1026 fprintf (stderr, "found refer(1) directive\n");
1028 add_directive (&first, REFER, file, buf, bufsize);
1047 add_directive (&first, TROFF, file, buf, bufsize);
1052 char lbuf[FILENAME_MAX];
1054 snprintf(lbuf, sizeof(lbuf), "%s -T%s%s%s", NROFF,
1055 locale_opts == NULL ? "ascii" : locale_opts,
1056 use_man_locale ? " -dlocale=" : "",
1057 use_man_locale ? man_locale : "");
1058 add_directive (&first, lbuf, file, buf, bufsize);
1060 add_directive (&first, NROFF " -Tascii", file, buf, bufsize);
1063 if (use_col && !troff)
1064 add_directive (&first, COL, file, buf, bufsize);
1073 make_roff_command (file)
1082 static char buf [BUFSIZ];
1086 if (roff_directive != NULL)
1089 fprintf (stderr, "parsing directive from command line\n");
1091 status = parse_roff_directive (roff_directive, file, buf, sizeof(buf));
1097 gripe_roff_command_from_command_line (file);
1101 if ((fp = gzopen (file, "r")) != NULL)
1103 if ((fp = fopen (file, "r")) != NULL)
1108 gzgets (fp, line, BUFSIZ);
1111 fgets (line, BUFSIZ, fp);
1114 if (*cp++ == '\'' && *cp++ == '\\' && *cp++ == '"' && *cp++ == ' ')
1117 fprintf (stderr, "parsing directive from file\n");
1119 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1125 gripe_roff_command_from_file (file);
1131 * Is there really any point in continuing to look for
1132 * preprocessor options if we can't even read the man page source?
1134 gripe_reading_man_file (file);
1138 if ((cp = getenv ("MANROFFSEQ")) != NULL)
1141 fprintf (stderr, "parsing directive from environment\n");
1143 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1149 gripe_roff_command_from_env ();
1153 fprintf (stderr, "using default preprocessor sequence\n");
1155 status = parse_roff_directive ("t", file, buf, sizeof(buf));
1158 else /* can't happen */
1162 sig_t ohup, oint, oquit, oterm;
1163 static char temp[FILENAME_MAX];
1174 ohup = signal(SIGHUP, cleantmp);
1175 oint = signal(SIGINT, cleantmp);
1176 oquit = signal(SIGQUIT, cleantmp);
1177 oterm = signal(SIGTERM, cleantmp);
1183 signal(SIGHUP, ohup);
1184 signal(SIGINT, oint);
1185 signal(SIGQUIT, oquit);
1186 signal(SIGTERM, oterm);
1190 * Try to format the man page and create a new formatted file. Return
1191 * 1 for success and 0 for failure.
1194 make_cat_file (path, man_file, cat_file, manid)
1195 register char *path;
1196 register char *man_file;
1197 register char *cat_file;
1201 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1207 char command[FILENAME_MAX];
1209 roff_command = make_roff_command (man_file);
1210 if (roff_command == NULL)
1213 snprintf(temp, sizeof(temp), "%s.tmpXXXXXX", cat_file);
1214 if ((f = mkstemp(temp)) >= 0 &&
1215 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1216 (fp = gzdopen(f, "w")) != NULL)
1218 (fp = fdopen(f, "w")) != NULL)
1223 if (fchmod (f, CATMODE) < 0) {
1230 fprintf (stderr, "mode of %s is now %o\n", temp, CATMODE);
1232 snprintf (command, sizeof(command), "(cd %s ; %s)", path,
1235 fprintf (stderr, "Formatting page, please wait...");
1239 fprintf (stderr, "\ntrying command: %s\n", command);
1246 if ((pp = popen(command, "r")) == NULL) {
1248 fprintf(stderr, "Failed.\n");
1257 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1270 while ((s = getc(pp)) != EOF) {
1271 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1279 if (!f || ((s = pclose(pp)) == -1)) {
1281 fprintf(stderr, "Failed.\n");
1287 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1296 fprintf(stderr, "Failed.\n");
1297 gripe_system_command(s);
1300 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1311 else if (rename(temp, cat_file) == -1) {
1314 "\nHmm! Can't seem to rename %s to %s, check permissions on man dir!\n",
1320 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1329 #if defined(HAVE_LIBZ) && defined(DO_COMPRESS)
1337 fprintf(stderr, "Failed.\n");
1344 fprintf(stderr, "No output, debug mode.\n");
1348 fprintf(stderr, "Done.\n");
1361 fprintf (stderr, "Couldn't open %s for writing.\n", temp);
1374 * Try to format the man page source and save it, then display it. If
1375 * that's not possible, try to format the man page source and display
1378 * Note that we've already been handed the name of the ultimate source
1379 * file at this point.
1382 format_and_display (path, man_file, cat_file)
1383 register char *path;
1384 register char *man_file;
1385 register char *cat_file;
1390 char command[FILENAME_MAX];
1394 if (access (man_file, R_OK) != 0)
1399 roff_command = make_roff_command (man_file);
1400 if (roff_command == NULL)
1403 snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command);
1405 found = do_system_command (command);
1409 status = is_newer (man_file, cat_file);
1411 fprintf (stderr, "status from is_newer() = %d\n", status);
1413 if (status == 1 || status == -2)
1416 * Cat file is out of date. Try to format and save it.
1420 printf ("%s\n", man_file);
1428 found = make_cat_file (path, man_file, cat_file, 1);
1433 /* Try again as real user - see note below.
1435 effective group (user) ID == real group (user) ID
1436 except for the call above, I believe the problems
1437 of reading private man pages is avoided. */
1438 found = make_cat_file (path, man_file, cat_file, 0);
1441 found = make_cat_file (path, man_file, cat_file, 0);
1446 * Creating the cat file worked. Now just display it.
1448 (void) display_cat_file (cat_file);
1453 * Couldn't create cat file. Just format it and
1454 * display it through the pager.
1456 roff_command = make_roff_command (man_file);
1457 if (roff_command == NULL)
1460 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1461 roff_command, pager);
1463 found = do_system_command (command);
1467 else if (access (cat_file, R_OK) == 0)
1470 * Formatting not necessary. Cat file is newer than source
1471 * file, or source file is not present but cat file is.
1475 printf ("%s (source: %s)\n", cat_file, man_file);
1480 found = display_cat_file (cat_file);
1488 * See if the preformatted man page or the source exists in the given
1492 try_section (path, section, longsec, name, glob)
1499 register int found = 0;
1500 register int to_cat;
1502 register char **names;
1504 static int arch_search;
1505 char buf[FILENAME_MAX];
1509 snprintf(buf, sizeof(buf), "%s/man%s/%s", path, section, machine);
1510 if (is_directory (buf) == 1)
1512 snprintf(buf, sizeof(buf), "%s/%s", machine, name);
1514 found = try_section (path, section, longsec, buf, glob);
1516 if (found && !findall) /* only do this architecture... */
1519 if (strcmp(machine_arch, machine) != 0)
1521 snprintf(buf, sizeof(buf), "%s/man%s/%s", path, section, machine_arch);
1522 if (is_directory (buf) == 1)
1524 snprintf(buf, sizeof(buf), "%s/%s", machine_arch, name);
1526 found = try_section (path, section, longsec, buf, glob);
1528 if (found && !findall) /* only do this architecture... */
1537 fprintf (stderr, "trying section %s with globbing\n", section);
1539 fprintf (stderr, "trying section %s without globbing\n", section);
1542 #ifndef NROFF_MISSING
1544 * Look for man page source files.
1548 names = glob_for_file (path, section, longsec, name, cat);
1550 names = make_name (path, section, longsec, name, cat);
1552 if (names == (char **) -1 || *names == NULL)
1554 * No files match. See if there's a preformatted page around that
1557 #endif /* NROFF_MISSING */
1563 names = glob_for_file (path, section, longsec, name, cat);
1565 names = make_name (path, section, longsec, name, cat);
1567 if (names != (char **) -1 && *names != NULL)
1569 for (np = names; *np != NULL; np++)
1573 printf ("%s\n", *np);
1578 found += display_cat_file (*np);
1584 #ifndef NROFF_MISSING
1587 for (np = names; *np != NULL; np++)
1589 register char *cat_file = NULL;
1590 register char *man_file;
1592 man_file = ultimate_source (*np, path);
1598 cat_file = convert_name (man_file, to_cat);
1601 fprintf (stderr, "will try to write %s if needed\n", cat_file);
1604 found += format_and_display (path, man_file, cat_file);
1607 #endif /* NROFF_MISSING */
1612 * Search for manual pages.
1614 * If preformatted manual pages are supported, look for the formatted
1615 * file first, then the man page source file. If they both exist and
1616 * the man page source file is newer, or only the source file exists,
1617 * try to reformat it and write the results in the cat directory. If
1618 * it is not possible to write the cat file, simply format and display
1621 * If preformatted pages are not supported, or the troff option is
1622 * being used, only look for the man page source file.
1635 char buf[FILENAME_MAX];
1641 if (shortsec != NULL)
1643 for (mp = manpathlist; *mp != NULL; mp++)
1646 fprintf (stderr, "\nsearching in %s\n", *mp);
1652 if (locale != NULL) {
1653 locale_opts = locale_nroff;
1655 if (*locale_lang != '\0' && *locale_terr != '\0') {
1656 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1657 locale_lang, locale_terr, locale_codeset);
1658 if (is_directory (buf) == 1)
1659 l_found = try_section (buf, shortsec, longsec, name, glob);
1662 if (*locale_lang != '\0') {
1663 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1664 locale_lang, locale_codeset);
1665 if (is_directory (buf) == 1)
1666 l_found = try_section (buf, shortsec, longsec, name, glob);
1669 if (!l_found && strcmp(locale_lang, "en") != 0) {
1670 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1672 if (is_directory (buf) == 1)
1673 l_found = try_section (buf, shortsec, longsec, name, glob);
1681 found += try_section (*mp, shortsec, longsec, name, glob);
1687 if (found && !findall) /* i.e. only do this section... */
1693 for (sp = section_list; *sp != NULL; sp++)
1695 for (mp = manpathlist; *mp != NULL; mp++)
1698 fprintf (stderr, "\nsearching in %s\n", *mp);
1704 if (locale != NULL) {
1705 locale_opts = locale_nroff;
1707 if (*locale_lang != '\0' && *locale_terr != '\0') {
1708 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1709 locale_lang, locale_terr, locale_codeset);
1710 if (is_directory (buf) == 1)
1711 l_found = try_section (buf, *sp, longsec, name, glob);
1714 if (*locale_lang != '\0') {
1715 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1716 locale_lang, locale_codeset);
1717 if (is_directory (buf) == 1)
1718 l_found = try_section (buf, *sp, longsec, name, glob);
1721 if (!l_found && strcmp(locale_lang, "en") != 0) {
1722 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1724 if (is_directory (buf) == 1)
1725 l_found = try_section (buf, *sp, longsec, name, glob);
1733 found += try_section (*mp, *sp, longsec, name, glob);
1739 if (found && !findall) /* i.e. only do this section... */
1753 #define TMP_SECTION_LIST_SIZE 100
1754 static char *tmp_section_list[TMP_SECTION_LIST_SIZE];
1756 if (colon_sep_section_list == NULL)
1758 if ((p = getenv ("MANSECT")) == NULL)
1760 return std_sections;
1764 colon_sep_section_list = strdup (p);
1769 for (p = colon_sep_section_list; i < TMP_SECTION_LIST_SIZE ; p = end+1)
1771 if ((end = strchr (p, ':')) != NULL)
1774 tmp_section_list[i++] = strdup (p);
1780 tmp_section_list [i] = NULL;
1781 return tmp_section_list;