From d365c986409e6495710508c25a3de7527bccbd68 Mon Sep 17 00:00:00 2001 From: ru Date: Wed, 22 Dec 2004 15:24:48 +0000 Subject: - Fixed handling of manpage subdirectories: catman /usr/share/man/man8 cd /usr/share/man; catman man8 - Don't print false warnings about invalid cat pages which are machine-specific cat page subdirectories (visible with -v). - Fixed one memory leak. --- usr.bin/catman/catman.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/usr.bin/catman/catman.c b/usr.bin/catman/catman.c index 3d4bf8e..3298c41 100644 --- a/usr.bin/catman/catman.c +++ b/usr.bin/catman/catman.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -272,22 +273,6 @@ get_cat_section(char *section) } /* - * Converts .../man/manXXX to .../man. - */ -static char * -get_mandir(char *section) -{ - char *slash; - char *mandir; - - slash = strrchr(section, '/'); - mandir = (char *) malloc(slash - section + 1); - strncpy(mandir, section, slash - section); - mandir[slash - section] = '\0'; - return mandir; -} - -/* * Tests to see if the given directory has already been visited. */ static int @@ -578,7 +563,11 @@ scan_section(char *mandir, char *section, char *cat_section) if (cmp == 0) continue; /* we have an unexpected page */ + snprintf(cat_path, sizeof cat_path, "%s/%s", cat_section, + page_name); if (!is_manpage_name(page_name)) { + if (test_path(cat_path, NULL) & TEST_DIR) + continue; junk_reason = "invalid cat page name"; } else if (!is_gzipped(page_name) && e + 1 < nexpected && strncmp(page_name, expected[e + 1], strlen(page_name)) == 0 && @@ -586,8 +575,6 @@ scan_section(char *mandir, char *section, char *cat_section) junk_reason = "cat page unused due to existing " GZ_EXT; } else junk_reason = "cat page without man page"; - snprintf(cat_path, sizeof cat_path, "%s/%s", cat_section, - page_name); junk(mandir, cat_path, junk_reason); } free(entries); @@ -612,6 +599,7 @@ process_section(char *mandir, char *section) cat_section = get_cat_section(section); if (make_writable_dir(mandir, cat_section)) scan_section(mandir, section, cat_section); + free(cat_section); } static int @@ -671,6 +659,7 @@ process_argument(const char *arg) { char *dir; char *mandir; + char *section; char *parg; parg = strdup(arg); @@ -694,8 +683,11 @@ process_argument(const char *arg) } break; case MAN_SECTION_DIR: { - mandir = get_mandir(dir); - process_mandir(mandir, dir); + mandir = strdup(dirname(dir)); + section = strdup(basename(dir)); + process_mandir(mandir, section); + free(mandir); + free(section); break; } default: -- cgit v1.1