diff options
Diffstat (limited to 'usr/src/cmd/man/man.c')
-rw-r--r-- | usr/src/cmd/man/man.c | 110 |
1 files changed, 76 insertions, 34 deletions
diff --git a/usr/src/cmd/man/man.c b/usr/src/cmd/man/man.c index 3935305932..ec8c361190 100644 --- a/usr/src/cmd/man/man.c +++ b/usr/src/cmd/man/man.c @@ -74,6 +74,7 @@ static const struct map_entry { char *old_name; char *new_name; } map[] = { + { "1m", "8" }, { "3b", "3ucb" }, { "3e", "3elf" }, { "3g", "3gen" }, @@ -85,6 +86,16 @@ static const struct map_entry { { "3x", "3curses" }, { "3xc", "3xcurses" }, { "3xn", "3xnet" }, + { "4", "5" }, + { "5", "7" }, + { "7", "4" }, + { "7b", "4b" }, + { "7d", "4d" }, + { "7fs", "4fs" }, + { "7i", "4i" }, + { "7ipp", "4ipp" }, + { "7m", "4m" }, + { "7p", "4p" }, { NULL, NULL } }; @@ -135,18 +146,18 @@ static struct pathmap { dev_t dev; ino_t ino; } bintoman[] = { - { "/sbin", "/usr/share/man,1m", 0, 0 }, - { "/usr/sbin", "/usr/share/man,1m", 0, 0 }, - { "/usr/ucb", "/usr/share/man,1b", 0, 0 }, - { "/usr/bin", "/usr/share/man,1,1m,1s,1t,1c", 0, 0 }, - { "/usr/xpg4/bin", "/usr/share/man,1", 0, 0 }, - { "/usr/xpg6/bin", "/usr/share/man,1", 0, 0 }, - { NULL, NULL, 0, 0 } + { "/sbin", "/usr/share/man,8,1m", 0, 0 }, + { "/usr/sbin", "/usr/share/man,8,1m", 0, 0 }, + { "/usr/ucb", "/usr/share/man,1b", 0, 0 }, + { "/usr/bin", "/usr/share/man,1,8,1m,1s,1t,1c", 0, 0 }, + { "/usr/xpg4/bin", "/usr/share/man,1", 0, 0 }, + { "/usr/xpg6/bin", "/usr/share/man,1", 0, 0 }, + { NULL, NULL, 0, 0 } }; struct man_node { char *path; /* mandir path */ - char **secv; /* submandir suffices */ + char **secv; /* submandir suffixes */ int defsrch; /* hint for man -p */ int frompath; /* hint for man -d */ struct man_node *next; @@ -159,17 +170,16 @@ static int found = 0; static int list = 0; static int makewhatis = 0; static int printmp = 0; -static int sargs = 0; static int psoutput = 0; static int lintout = 0; static int whatis = 0; static int makewhatishere = 0; -static char *mansec; +static char *mansec = NULL; static char *pager = NULL; static char *addlocale(char *); -static struct man_node *build_manpath(char **, int); +static struct man_node *build_manpath(char **, char *, int); static void do_makewhatis(struct man_node *); static char *check_config(char *); static int cmp(const void *, const void *); @@ -182,11 +192,11 @@ static void fullpaths(struct man_node **); static void get_all_sect(struct man_node *); static int getdirs(char *, char ***, int); static void getpath(struct man_node *, char **); -static void getsect(struct man_node *, char **); +static void getsect(struct man_node *, char **, char *); static void init_bintoman(void); static void lower(char *); static void mandir(char **, char *, char *, int); -static int manual(struct man_node *, char *); +static int manual(struct man_node *, char *, char *); static char *map_section(char *, char *); static char *path_to_manpath(char *); static void print_manpath(struct man_node *); @@ -283,7 +293,6 @@ main(int argc, char **argv) break; case 's': mansec = optarg; - sargs++; break; case 'r': lintout++; @@ -334,8 +343,7 @@ main(int argc, char **argv) manpath = DEFMANDIR; } pathv = split(manpath, ':'); - mandirs = build_manpath(pathv, bmp_flags); - freev(pathv); + mandirs = build_manpath(pathv, mansec, bmp_flags); fullpaths(&mandirs); if (makewhatis) { @@ -377,7 +385,7 @@ main(int argc, char **argv) for (i = 0; i < argc; i++) { char *cmd; static struct man_node *mp; - char *pv[2]; + char *pv[2] = {NULL, NULL}; /* * If full path to command specified, customize @@ -389,23 +397,56 @@ main(int argc, char **argv) err(1, "strdup"); pv[1] = NULL; *cmd = '/'; - mp = build_manpath(pv, + mp = build_manpath(pv, mansec, BMP_ISPATH | BMP_FALLBACK_DEFMANDIR); } else { mp = mandirs; } - if (apropos) + if (apropos) { whatapro(mp, argv[i]); - else - ret += manual(mp, argv[i]); + } else { + /* + * If a page is specified with an embedded section, + * such as 'printf.3c' First try to find it literally + * (which has historically worked due to the + * implementation of mandir() and has come to be + * relied upon), if that doesn't work split it at the + * right most '.' to separate a hypothetical name and + * section, and explicitly search under the specified + * section, which will trigger the section name + * compatibility logic. + * + * The error that the page they initially requested + * does not exist will still be produced at this + * point, and indicate (unless clobbered by the pager) + * what has been done. + */ + int lret = 0; + + lret = manual(mp, argv[i], NULL); + if (lret != 0) { + char *sec = NULL; + + if ((sec = strrchr(argv[i], '.')) != NULL) { + char *page = NULL; + *sec++ = '\0'; + if ((page = strdup(argv[i])) == NULL) + err(1, "strdup"); + mp = build_manpath(pathv, sec, 0); + lret = manual(mp, page, sec); + free(page); + } + } + ret += lret; + } if (mp != NULL && mp != mandirs) { free(pv[0]); free_manp(mp); } } - + freev(pathv); return (ret == 0 ? 0 : 1); } @@ -415,7 +456,7 @@ main(int argc, char **argv) * flags. */ static struct man_node * -build_manpath(char **pathv, int flags) +build_manpath(char **pathv, char *sec, int flags) { struct man_node *manpage = NULL; struct man_node *currp = NULL; @@ -458,7 +499,7 @@ build_manpath(char **pathv, int flags) lastp = manpage = currp; getpath(currp, p); - getsect(currp, p); + getsect(currp, p, sec); /* * If there are no new elements in this path, @@ -518,7 +559,7 @@ getpath(struct man_node *manp, char **pv) * directories) into the manp structure. */ static void -getsect(struct man_node *manp, char **pv) +getsect(struct man_node *manp, char **pv, char *explicit_sec) { char *sections; char **sectp; @@ -529,9 +570,10 @@ getsect(struct man_node *manp, char **pv) DPRINTF("-- Adding %s\n", manp->path); manp->secv = NULL; get_all_sect(manp); - } else if (sargs) { - DPRINTF("-- Adding %s: sections=%s\n", manp->path, mansec); - manp->secv = split(mansec, ','); + } else if (explicit_sec != NULL) { + DPRINTF("-- Adding %s: sections=%s\n", manp->path, + explicit_sec); + manp->secv = split(explicit_sec, ','); for (sectp = manp->secv; *sectp; sectp++) lower(*sectp); } else if ((sections = strchr(*pv, ',')) != NULL) { @@ -743,12 +785,12 @@ search_whatis(char *whatpath, char *word) if (regcomp(&preg, pkwd, REG_BASIC | REG_ICASE | REG_NOSUB) != 0) err(1, "regcomp"); - if (sargs) + if (mansec != NULL) ss = split(mansec, ','); while (getline(&line, &linecap, fp) > 0) { if (regexec(&preg, line, 0, NULL, 0) == 0) { - if (sargs) { + if (mansec != NULL) { /* Section-restricted search */ for (i = 0; ss[i] != NULL; i++) { (void) snprintf(s, sizeof (s), "(%s)", @@ -939,7 +981,7 @@ cmp(const void *arg1, const void *arg2) * Find a manpage. */ static int -manual(struct man_node *manp, char *name) +manual(struct man_node *manp, char *name, char *sec) { struct man_node *p; struct man_node *local; @@ -964,7 +1006,7 @@ manual(struct man_node *manp, char *name) if (ndirs != 0) { ldirs[0] = ldir; ldirs[1] = NULL; - local = build_manpath(ldirs, 0); + local = build_manpath(ldirs, mansec, 0); DPRINTF("-- Locale specific subdir: %s\n", ldir); mandir(local->secv, ldir, name, 1); @@ -985,10 +1027,10 @@ manual(struct man_node *manp, char *name) } if (!found) { - if (sargs) { + if (sec != NULL) { (void) fprintf(stderr, gettext( "No manual entry for %s in section(s) %s\n"), - fullname, mansec); + fullname, sec); } else { (void) fprintf(stderr, gettext("No manual entry for %s\n"), fullname); |