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.6 2006/09/09 17:34:46 corecode Exp $
24 #include <sys/param.h>
51 extern uid_t getuid ();
58 extern char *malloc ();
59 extern char *getenv ();
63 extern int strncmp ();
67 extern int fprintf ();
68 extern FILE *fopen ();
70 extern char *sprintf ();
73 extern char **glob_filename ();
74 extern int is_newer ();
75 extern int is_directory ();
76 extern int do_system_command ();
82 static char *manpathlist[MAXDIRS];
83 static char *shortsec;
85 static char *colon_sep_section_list;
86 static char **section_list;
87 static char *roff_directive;
91 static int print_where;
94 static char *locale, *locale_opts, *locale_nroff, *locale_codeset;
95 static char locale_terr[3], locale_lang[3];
96 static char *man_locale;
97 static int use_man_locale;
98 static int use_original;
103 static struct ltable ltable[] = {
104 {"KOI8-R", "koi8-r"},
105 {"ISO8859-1", "latin1"},
106 {"ISO8859-15", "latin1"},
111 static int troff = 0;
117 static char args[] = "M:P:S:adfhkm:op:tw?";
119 static char args[] = "M:P:S:adfhkm:p:tw?";
123 static char args[] = "M:P:S:adfhkm:op:w?";
125 static char args[] = "M:P:S:adfhkm:p:w?";
144 extern char *mkprogname ();
146 char **get_section_list ();
152 prognam = mkprogname (argv[0]);
157 (void) setlocale(LC_ALL, "");
159 man_getopt (argc, argv);
162 gripe_no_name ((char *)NULL);
164 section_list = get_section_list ();
166 if (optind == argc - 1)
168 tmp = is_section (argv[optind], manp);
183 while (optind < argc)
185 nextarg = argv[optind++];
188 * See if this argument is a valid section name. If not,
189 * is_section returns NULL.
191 tmp = is_section (nextarg, manp);
198 fprintf (stderr, "\nsection: %s\n", shortsec);
204 do_apropos (nextarg);
205 status = (status ? 0 : 1); /* reverts status, see below */
209 status = (status ? 0 : 1); /* reverts status, see below */
213 status = man (nextarg);
216 gripe_not_found (nextarg, longsec);
219 return (status==0); /* status==1 --> exit(0),
220 status==0 --> exit(1) */
226 static char usage_string[1024] = "%s, version %s\n\n";
231 "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\
232 [-m machine] [-p string] name ...\n\n";
235 "usage: %s [-adfhktw] [section] [-M path] [-P pager] [-S list]\n\
236 [-m machine] [-p string] name ...\n\n";
241 "usage: %s [-adfhkow] [section] [-M path] [-P pager] [-S list]\n\
242 [-m machine] [-p string] name ...\n\n";
245 "usage: %s [-adfhkw] [section] [-M path] [-P pager] [-S list]\n\
246 [-m machine] [-p string] name ...\n\n";
250 static char s2[] = " a : find all matching entries\n\
251 d : print gobs of debugging information\n\
252 f : same as whatis(1)\n\
253 h : print this help message\n\
254 k : same as apropos(1)\n";
257 static char s3[] = " o : use original, non-localized manpages\n";
261 static char s4[] = " t : use troff to format pages for printing\n";
264 static char s5[] = " w : print location of man page(s) that would be displayed\n\n\
265 M path : set search path for manual pages to `path'\n\
266 P pager : use program `pager' to display pages\n\
267 S list : colon separated section list\n\
268 m machine : search for alternate architecture man pages\n";
270 static char s6[] = " p string : string tells which preprocessors to run\n\
271 e - [n]eqn(1) p - pic(1) t - tbl(1)\n\
272 g - grap(1) r - refer(1) v - vgrind(1)\n";
274 strcat (usage_string, s1);
275 strcat (usage_string, s2);
277 strcat (usage_string, s3);
281 strcat (usage_string, s4);
284 strcat (usage_string, s5);
286 strcat (usage_string, s6);
288 fprintf (stderr, usage_string, prognam, version, prognam);
293 add_dir_to_mpath_list (mp, p)
299 status = is_directory (p);
301 if (status < 0 && debug)
303 fprintf (stderr, "Warning: couldn't stat file %s!\n", p);
305 else if (status == 0 && debug)
307 fprintf (stderr, "Warning: %s isn't a directory!\n", p);
309 else if (status == 1)
312 fprintf (stderr, "adding %s to manpathlist\n", p);
320 * Get options from the command line and user environment.
323 man_getopt (argc, argv)
325 register char **argv;
331 extern void downcase ();
332 extern char *manpath ();
334 while ((c = getopt (argc, argv, args)) != EOF)
339 manp = strdup (optarg);
342 pager = strdup (optarg);
343 if (setenv("PAGER", pager, 1) != 0)
344 (void)fprintf(stderr, "setenv PAGER=%s\n", pager);
347 colon_sep_section_list = strdup (optarg);
357 gripe_incompatible ("-f and -t");
359 gripe_incompatible ("-f and -k");
361 gripe_incompatible ("-f and -w");
366 gripe_incompatible ("-k and -t");
368 gripe_incompatible ("-k and -f");
370 gripe_incompatible ("-k and -w");
382 roff_directive = strdup (optarg);
387 gripe_incompatible ("-t and -k");
389 gripe_incompatible ("-t and -f");
391 gripe_incompatible ("-t and -w");
397 gripe_incompatible ("-w and -k");
399 gripe_incompatible ("-w and -f");
401 gripe_incompatible ("-w and -t");
413 /* "" intentionally used to catch error */
414 if ((locale = setlocale(LC_CTYPE, "")) != NULL)
415 locale_codeset = nl_langinfo(CODESET);
416 if (!use_original && locale != NULL && *locale_codeset != '\0' &&
417 strcmp(locale_codeset, "US-ASCII") != 0
419 char *tmp, *short_locale;
420 struct ltable *pltable;
425 if ((short_locale = strdup(locale)) == NULL) {
426 perror ("ctype locale strdup");
429 if ((tmp = strchr(short_locale, '.')) != NULL)
432 if (strlen(short_locale) == 2)
433 strcpy(locale_lang, short_locale);
434 else if ((tmp = strchr(short_locale, '_')) == NULL ||
435 tmp != short_locale + 2 ||
439 perror ("ctype locale format");
442 strncpy(locale_terr, short_locale + 3, 2);
443 locale_terr[2] = '\0';
444 strncpy(locale_lang, short_locale, 2);
445 locale_lang[2] = '\0';
450 if (locale != NULL) {
451 for (pltable = ltable; pltable->lcode != NULL; pltable++) {
452 if (strcmp(pltable->lcode, locale_codeset) == 0) {
453 locale_nroff = pltable->nroff;
457 asprintf(&man_locale, "%s.%s", locale_lang, locale_codeset);
460 if (locale == NULL) {
462 perror ("ctype locale");
465 if (*locale_codeset == '\0') {
467 perror ("ctype codeset");
471 #endif /* __DragonFly__ */
473 if (pager == NULL || *pager == '\0')
474 if ((pager = getenv ("PAGER")) == NULL || *pager == '\0')
475 pager = strdup (PAGER);
478 fprintf (stderr, "\nusing %s as pager\n", pager);
480 if (machine == NULL && (machine = getenv ("MACHINE")) == NULL)
484 fprintf (stderr, "\nusing %s architecture\n", machine);
488 if ((manp = manpath (0)) == NULL)
493 "\nsearch path for pages determined by manpath is\n%s\n\n",
498 * Expand the manpath into a list for easier handling.
501 for (p = manp; ; p = end+1)
503 if (mp == manpathlist + MAXDIRS - 1) {
504 fprintf (stderr, "Warning: too many directories in manpath, truncated!\n");
507 if ((end = strchr (p, ':')) != NULL)
510 mp = add_dir_to_mpath_list (mp, p);
520 * Check to see if the argument is a valid section number. If the
521 * first character of name is a numeral, or the name matches one of
522 * the sections listed in section_list, we'll assume that it's a section.
523 * The list of sections in config.h simply allows us to specify oddly
524 * named directories like .../man3f. Yuk.
527 is_section (name, path)
532 char *temp, *end, *loc;
536 for (vs = section_list; *vs != NULL; vs++)
537 if ((strcmp (*vs, name) == 0)
538 || (isdigit ((unsigned char)name[0]) && strlen(name) == 1))
539 return (longsec = strdup (name));
542 if (isdigit ((unsigned char)name[0]))
544 while (*plist != NULL)
546 asprintf(&temp, "%s/man%c/*", *plist, name[0]);
550 vs = glob_filename (temp);
556 for ( ; *vs != NULL; vs++)
558 end = strrchr (*vs, '/');
559 if ((loc = strstr (end, name)) != NULL && loc - end > 2
561 && (*(loc+strlen(name)) == '\0' || *(loc+strlen(name)) == '.'))
570 asprintf(&temp, "%c", name[0]);
571 longsec = strdup (name);
580 * Handle the apropos option. Cheat by using another program.
587 register char *command;
589 len = strlen (APROPOS) + strlen (name) + 4;
591 if ((command = (char *) malloc(len)) == NULL)
592 gripe_alloc (len, "command");
594 sprintf (command, "%s \"%s\"", APROPOS, name);
596 (void) do_system_command (command);
602 * Handle the whatis option. Cheat by using another program.
609 register char *command;
611 len = strlen (WHATIS) + strlen (name) + 4;
613 if ((command = (char *) malloc(len)) == NULL)
614 gripe_alloc (len, "command");
616 sprintf (command, "%s \"%s\"", WHATIS, name);
618 (void) do_system_command (command);
624 * Change a name of the form ...man/man1/name.1 to ...man/cat1/name.1
625 * or a name of the form ...man/cat1/name.1 to ...man/man1/name.1
628 convert_name (name, to_cat)
632 register char *to_name;
634 register char *t2 = NULL;
639 int olen = strlen(name);
640 int cextlen = strlen(COMPRESS_EXT);
641 int len = olen + cextlen;
643 to_name = malloc (len+1);
645 gripe_alloc (len+1, "to_name");
646 strcpy (to_name, name);
648 /* Avoid tacking it on twice */
649 if (olen >= 1 && strcmp(name + olen, COMPRESS_EXT) != 0)
650 strcat (to_name, COMPRESS_EXT);
653 to_name = strdup (name);
655 to_name = strdup (name);
658 t1 = strrchr (to_name, '/');
662 t2 = strrchr (to_name, '/');
665 /* Skip architecture part (if present). */
666 if (t2 != NULL && (t1 - t2 < 5 || *(t2 + 1) != 'm' || *(t2 + 3) != 'n'))
670 t2 = strrchr (to_name, '/');
676 gripe_converting_name (name, to_cat);
690 fprintf (stderr, "to_name in convert_name () is: %s\n", to_name);
696 * Try to find the man page corresponding to the given name. The
697 * reason we do this with globbing is because some systems have man
698 * page directories named man3 which contain files with names like
699 * XtPopup.3Xt. Rather than requiring that this program know about
700 * all those possible names, we simply try to match things like
701 * .../man[sect]/name[sect]*. This is *much* easier.
703 * Note that globbing is only done when the section is unspecified.
706 glob_for_file (path, section, longsec, name, cat)
713 char pathname[FILENAME_MAX];
720 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%s*", path, section,
723 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%s*", path, section,
727 fprintf (stderr, "globbing %s\n", pathname);
729 gf = glob_filename (pathname);
731 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
732 && strlen (longsec) == 1)
735 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%c*", path, section, name, *section);
737 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%c*", path, section, name, *section);
739 gf = glob_filename (pathname);
741 if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section)
742 && strlen (longsec) == 1)
745 snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.0*", path, section, name);
747 snprintf (pathname, sizeof(pathname), "%s/man%s/%s.0*", path, section, name);
749 fprintf (stderr, "globbing %s\n", pathname);
750 gf = glob_filename (pathname);
756 * Return an un-globbed name in the same form as if we were doing
760 make_name (path, section, longsec, name, cat)
768 static char *names[3];
769 char buf[FILENAME_MAX];
772 snprintf (buf, sizeof(buf), "%s/cat%s/%s.%s", path, section, name, longsec);
774 snprintf (buf, sizeof(buf), "%s/man%s/%s.%s", path, section, name, longsec);
776 if (access (buf, R_OK) == 0)
777 names[i++] = strdup (buf);
780 * If we're given a section that looks like `3f', we may want to try
781 * file names like .../man3/foo.3f as well. This seems a bit
782 * kludgey to me, but what the hey...
784 if (section[1] != '\0')
787 snprintf (buf, sizeof(buf), "%s/cat%c/%s.%s", path, section[0], name, section);
789 snprintf (buf, sizeof(buf), "%s/man%c/%s.%s", path, section[0], name, section);
791 if (access (buf, R_OK) == 0)
792 names[i++] = strdup (buf);
804 char *end = file + (strlen (file) - 1);
806 while (end > file && end[-1] != '.')
819 if (*end == 'Z' || !strcmp(end, "gz"))
826 * Simply display the preformatted page.
829 display_cat_file (file)
833 char command[FILENAME_MAX];
837 if (access (file, R_OK) == 0)
839 char *expander = get_expander (file);
841 if (expander != NULL)
842 snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager);
844 snprintf (command, sizeof(command), "%s %s", pager, file);
846 found = do_system_command (command);
852 * Try to find the ultimate source file. If the first line of the
853 * current file is not of the form
857 * the input file name is returned.
860 ultimate_source (name, path)
864 static char buf[BUFSIZ];
865 static char ult[FILENAME_MAX];
871 strncpy (ult, name, sizeof(ult)-1);
872 ult[sizeof(ult)-1] = '\0';
873 strncpy (buf, name, sizeof(buf)-1);
874 ult[sizeof(buf)-1] = '\0';
878 if ((fp = fopen (ult, "r")) == NULL)
881 end = fgets (buf, BUFSIZ, fp);
884 if (!end || strlen (buf) < 5)
888 if (*beg++ == '.' && *beg++ == 's' && *beg++ == 'o')
890 while ((*beg == ' ' || *beg == '\t') && *beg != '\0')
894 while (*end != ' ' && *end != '\t' && *end != '\n' && *end != '\0')
899 snprintf(ult, sizeof(ult), "%s/%s", path, beg);
900 snprintf(buf, sizeof(buf), "%s", ult);
906 fprintf (stderr, "found ultimate source file %s\n", ult);
912 add_directive (first, d, file, buf, bufsize)
919 if (strcmp (d, "") != 0)
924 snprintf(buf, bufsize, "%s %s", d, file);
928 strncat (buf, " | ", bufsize-strlen(buf)-1);
929 strncat (buf, d, bufsize-strlen(buf)-1);
935 parse_roff_directive (cp, file, buf, bufsize)
944 int preproc_found = 0;
947 if ((exp = get_expander(file)) != NULL)
948 add_directive (&first, exp, file, buf, bufsize);
950 while ((c = *cp++) != '\0')
957 fprintf (stderr, "found eqn(1) directive\n");
961 add_directive (&first, EQN, file, buf, bufsize);
964 char lbuf[FILENAME_MAX];
966 snprintf(lbuf, sizeof(lbuf), "%s -T%s", NEQN,
967 locale_opts == NULL ? "ascii" : locale_opts);
968 add_directive (&first, lbuf, file, buf, bufsize);
970 add_directive (&first, NEQN, file, buf, bufsize);
979 fprintf (stderr, "found grap(1) directive\n");
982 add_directive (&first, GRAP, file, buf, bufsize);
989 fprintf (stderr, "found pic(1) directive\n");
992 add_directive (&first, PIC, file, buf, bufsize);
999 fprintf (stderr, "found tbl(1) directive\n");
1003 add_directive (&first, TBL, file, buf, bufsize);
1009 fprintf (stderr, "found vgrind(1) directive\n");
1011 add_directive (&first, VGRIND, file, buf, bufsize);
1017 fprintf (stderr, "found refer(1) directive\n");
1019 add_directive (&first, REFER, file, buf, bufsize);
1038 add_directive (&first, TROFF, file, buf, bufsize);
1042 #ifdef __DragonFly__
1043 char lbuf[FILENAME_MAX];
1045 snprintf(lbuf, sizeof(lbuf), "%s -T%s%s%s", NROFF,
1046 locale_opts == NULL ? "ascii" : locale_opts,
1047 use_man_locale ? " -dlocale=" : "",
1048 use_man_locale ? man_locale : "");
1049 add_directive (&first, lbuf, file, buf, bufsize);
1051 add_directive (&first, NROFF " -Tascii", file, buf, bufsize);
1054 if (use_col && !troff)
1055 add_directive (&first, COL, file, buf, bufsize);
1064 make_roff_command (file)
1073 static char buf [BUFSIZ];
1077 if (roff_directive != NULL)
1080 fprintf (stderr, "parsing directive from command line\n");
1082 status = parse_roff_directive (roff_directive, file, buf, sizeof(buf));
1088 gripe_roff_command_from_command_line (file);
1092 if ((fp = gzopen (file, "r")) != NULL)
1094 if ((fp = fopen (file, "r")) != NULL)
1099 gzgets (fp, line, BUFSIZ);
1102 fgets (line, BUFSIZ, fp);
1105 if (*cp++ == '\'' && *cp++ == '\\' && *cp++ == '"' && *cp++ == ' ')
1108 fprintf (stderr, "parsing directive from file\n");
1110 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1116 gripe_roff_command_from_file (file);
1122 * Is there really any point in continuing to look for
1123 * preprocessor options if we can't even read the man page source?
1125 gripe_reading_man_file (file);
1129 if ((cp = getenv ("MANROFFSEQ")) != NULL)
1132 fprintf (stderr, "parsing directive from environment\n");
1134 status = parse_roff_directive (cp, file, buf, sizeof(buf));
1140 gripe_roff_command_from_env ();
1144 fprintf (stderr, "using default preprocessor sequence\n");
1146 status = parse_roff_directive ("t", file, buf, sizeof(buf));
1149 else /* can't happen */
1153 sig_t ohup, oint, oquit, oterm;
1154 static char temp[FILENAME_MAX];
1165 ohup = signal(SIGHUP, cleantmp);
1166 oint = signal(SIGINT, cleantmp);
1167 oquit = signal(SIGQUIT, cleantmp);
1168 oterm = signal(SIGTERM, cleantmp);
1174 signal(SIGHUP, ohup);
1175 signal(SIGINT, oint);
1176 signal(SIGQUIT, oquit);
1177 signal(SIGTERM, oterm);
1181 * Try to format the man page and create a new formatted file. Return
1182 * 1 for success and 0 for failure.
1185 make_cat_file (path, man_file, cat_file, manid)
1186 register char *path;
1187 register char *man_file;
1188 register char *cat_file;
1193 char command[FILENAME_MAX];
1195 roff_command = make_roff_command (man_file);
1196 if (roff_command == NULL)
1199 snprintf(temp, sizeof(temp), "%s.tmpXXXXXX", cat_file);
1200 if ((f = mkstemp(temp)) >= 0 && (fp = fdopen(f, "w")) != NULL)
1204 if (fchmod (f, CATMODE) < 0) {
1211 fprintf (stderr, "mode of %s is now %o\n", temp, CATMODE);
1214 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1215 roff_command, COMPRESSOR);
1217 snprintf (command, sizeof(command), "(cd %s ; %s)", path,
1220 fprintf (stderr, "Formatting page, please wait...");
1224 fprintf (stderr, "\ntrying command: %s\n", command);
1233 if ((pp = popen(command, "r")) == NULL) {
1235 fprintf(stderr, "Failed.\n");
1257 while ((s = getc(pp)) != EOF) {
1261 if (!f || ((s = pclose(pp)) == -1)) {
1263 fprintf(stderr, "Failed.\n");
1273 fprintf(stderr, "Failed.\n");
1274 gripe_system_command(s);
1284 else if (rename(temp, cat_file) == -1) {
1287 "\nHmm! Can't seem to rename %s to %s, check permissions on man dir!\n",
1302 fprintf(stderr, "Failed.\n");
1309 fprintf(stderr, "No output, debug mode.\n");
1313 fprintf(stderr, "Done.\n");
1326 fprintf (stderr, "Couldn't open %s for writing.\n", temp);
1339 * Try to format the man page source and save it, then display it. If
1340 * that's not possible, try to format the man page source and display
1343 * Note that we've already been handed the name of the ultimate source
1344 * file at this point.
1347 format_and_display (path, man_file, cat_file)
1348 register char *path;
1349 register char *man_file;
1350 register char *cat_file;
1355 char command[FILENAME_MAX];
1359 if (access (man_file, R_OK) != 0)
1364 roff_command = make_roff_command (man_file);
1365 if (roff_command == NULL)
1368 snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command);
1370 found = do_system_command (command);
1374 if (cat_file == NULL)
1375 goto format_and_display;
1377 status = is_newer (man_file, cat_file);
1379 fprintf (stderr, "status from is_newer() = %d\n", status);
1381 if (status == 1 || status == -2)
1384 * Cat file is out of date. Try to format and save it.
1388 printf ("%s\n", man_file);
1397 found = make_cat_file (path, man_file, cat_file, 1);
1399 found = make_cat_file (path, man_file, cat_file, 0);
1407 /* Try again as real user - see note below.
1409 effective group (user) ID == real group (user) ID
1410 except for the call above, I believe the problems
1411 of reading private man pages is avoided. */
1412 found = make_cat_file (path, man_file, cat_file, 0);
1415 #ifdef SECURE_MAN_UID
1419 * Try again as real user. Note that for private
1420 * man pages, we won't even get this far unless the
1421 * effective user can read the real user's man page
1422 * source. Also, if we are trying to find all the
1423 * man pages, this will probably make it impossible
1424 * to make cat files in the system directories if
1425 * the real user's man directories are searched
1426 * first, because there's no way to undo this (is
1427 * there?). Yikes, am I missing something obvious?
1431 found = make_cat_file (path, man_file, cat_file, 0);
1437 * Creating the cat file worked. Now just display it.
1439 (void) display_cat_file (cat_file);
1444 * Couldn't create cat file. Just format it and
1445 * display it through the pager.
1448 roff_command = make_roff_command (man_file);
1449 if (roff_command == NULL)
1452 snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
1453 roff_command, pager);
1455 found = do_system_command (command);
1459 else if (access (cat_file, R_OK) == 0)
1462 * Formatting not necessary. Cat file is newer than source
1463 * file, or source file is not present but cat file is.
1467 printf ("%s (source: %s)\n", cat_file, man_file);
1472 found = display_cat_file (cat_file);
1480 * See if the preformatted man page or the source exists in the given
1484 try_section (path, section, longsec, name, glob)
1491 register int found = 0;
1492 register int to_cat;
1494 register char **names;
1496 static int arch_search;
1497 char buf[FILENAME_MAX];
1501 snprintf(buf, sizeof(buf), "%s/man%s/%s", path, section, machine);
1502 if (is_directory (buf) == 1)
1504 snprintf(buf, sizeof(buf), "%s/%s", machine, name);
1506 found = try_section (path, section, longsec, buf, glob);
1508 if (found && !findall) /* only do this architecture... */
1516 fprintf (stderr, "trying section %s with globbing\n", section);
1518 fprintf (stderr, "trying section %s without globbing\n", section);
1521 #ifndef NROFF_MISSING
1523 * Look for man page source files.
1527 names = glob_for_file (path, section, longsec, name, cat);
1529 names = make_name (path, section, longsec, name, cat);
1531 if (names == (char **) -1 || *names == NULL)
1533 * No files match. See if there's a preformatted page around that
1536 #endif /* NROFF_MISSING */
1542 names = glob_for_file (path, section, longsec, name, cat);
1544 names = make_name (path, section, longsec, name, cat);
1546 if (names != (char **) -1 && *names != NULL)
1548 for (np = names; *np != NULL; np++)
1552 printf ("%s\n", *np);
1557 found += display_cat_file (*np);
1563 #ifndef NROFF_MISSING
1566 for (np = names; *np != NULL; np++)
1568 register char *cat_file = NULL;
1569 register char *man_file;
1571 man_file = ultimate_source (*np, path);
1577 cat_file = convert_name (man_file, to_cat);
1580 fprintf (stderr, "will try to write %s if needed\n", cat_file);
1583 found += format_and_display (path, man_file, cat_file);
1586 #endif /* NROFF_MISSING */
1591 * Search for manual pages.
1593 * If preformatted manual pages are supported, look for the formatted
1594 * file first, then the man page source file. If they both exist and
1595 * the man page source file is newer, or only the source file exists,
1596 * try to reformat it and write the results in the cat directory. If
1597 * it is not possible to write the cat file, simply format and display
1600 * If preformatted pages are not supported, or the troff option is
1601 * being used, only look for the man page source file.
1612 #ifdef __DragonFly__
1614 char buf[FILENAME_MAX];
1620 if (shortsec != NULL)
1622 for (mp = manpathlist; *mp != NULL; mp++)
1625 fprintf (stderr, "\nsearching in %s\n", *mp);
1629 #ifdef __DragonFly__
1631 if (locale != NULL) {
1632 locale_opts = locale_nroff;
1634 if (*locale_lang != '\0' && *locale_terr != '\0') {
1635 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1636 locale_lang, locale_terr, locale_codeset);
1637 if (is_directory (buf) == 1)
1638 l_found = try_section (buf, shortsec, longsec, name, glob);
1641 if (*locale_lang != '\0') {
1642 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1643 locale_lang, locale_codeset);
1644 if (is_directory (buf) == 1)
1645 l_found = try_section (buf, shortsec, longsec, name, glob);
1648 if (!l_found && strcmp(locale_lang, "en") != 0) {
1649 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1651 if (is_directory (buf) == 1)
1652 l_found = try_section (buf, shortsec, longsec, name, glob);
1660 found += try_section (*mp, shortsec, longsec, name, glob);
1661 #ifdef __DragonFly__
1666 if (found && !findall) /* i.e. only do this section... */
1672 for (sp = section_list; *sp != NULL; sp++)
1674 for (mp = manpathlist; *mp != NULL; mp++)
1677 fprintf (stderr, "\nsearching in %s\n", *mp);
1681 #ifdef __DragonFly__
1683 if (locale != NULL) {
1684 locale_opts = locale_nroff;
1686 if (*locale_lang != '\0' && *locale_terr != '\0') {
1687 snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp,
1688 locale_lang, locale_terr, locale_codeset);
1689 if (is_directory (buf) == 1)
1690 l_found = try_section (buf, *sp, longsec, name, glob);
1693 if (*locale_lang != '\0') {
1694 snprintf(buf, sizeof(buf), "%s/%s.%s", *mp,
1695 locale_lang, locale_codeset);
1696 if (is_directory (buf) == 1)
1697 l_found = try_section (buf, *sp, longsec, name, glob);
1700 if (!l_found && strcmp(locale_lang, "en") != 0) {
1701 snprintf(buf, sizeof(buf), "%s/en.%s", *mp,
1703 if (is_directory (buf) == 1)
1704 l_found = try_section (buf, *sp, longsec, name, glob);
1712 found += try_section (*mp, *sp, longsec, name, glob);
1713 #ifdef __DragonFly__
1718 if (found && !findall) /* i.e. only do this section... */
1724 /* Treat name as file name as a last resort */
1729 fprintf(stderr, "Trying as file name\n");
1731 if (stat(name, &st) == 0) {
1732 found += format_and_display(dirname(name), name, NULL);
1744 #define TMP_SECTION_LIST_SIZE 100
1745 static char *tmp_section_list[TMP_SECTION_LIST_SIZE];
1747 if (colon_sep_section_list == NULL)
1749 if ((p = getenv ("MANSECT")) == NULL)
1751 return std_sections;
1755 colon_sep_section_list = strdup (p);
1760 for (p = colon_sep_section_list; i < TMP_SECTION_LIST_SIZE ; p = end+1)
1762 if ((end = strchr (p, ':')) != NULL)
1765 tmp_section_list[i++] = strdup (p);
1771 tmp_section_list [i] = NULL;
1772 return tmp_section_list;