diff options
author | ru <ru@FreeBSD.org> | 2008-05-14 17:08:31 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2008-05-14 17:08:31 +0000 |
commit | 0cdbf64f06e0e5edab127c551595a705f461bcad (patch) | |
tree | 795eb925ff2a456640d792dba215732782824497 /gnu | |
parent | cadf21c3959e86ac71359976323c0ee7381cfcfd (diff) | |
download | FreeBSD-src-0cdbf64f06e0e5edab127c551595a705f461bcad.zip FreeBSD-src-0cdbf64f06e0e5edab127c551595a705f461bcad.tar.gz |
Add an ability to run man(1) on local files (the argument should
contain a `/' character); based on the submission in the PR.
PR: bin/120730
MFC after: 1 week
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/man/TODO | 4 | ||||
-rw-r--r-- | gnu/usr.bin/man/lib/util.c | 20 | ||||
-rw-r--r-- | gnu/usr.bin/man/man/man.c | 14 |
3 files changed, 35 insertions, 3 deletions
diff --git a/gnu/usr.bin/man/TODO b/gnu/usr.bin/man/TODO index 19060ad..63dbb22 100644 --- a/gnu/usr.bin/man/TODO +++ b/gnu/usr.bin/man/TODO @@ -1,3 +1,5 @@ +$FreeBSD$ + Things that would be nice but aren't really necessary: 0. Update the documentation. @@ -105,7 +107,7 @@ XX I've been using your man(1) package for a while now and I ran into file names used by Motif. Maybe there's a better way to handle this? -15. Add ability to run man on a local file +XX Add ability to run man on a local file 16. Handle per-tree tmac macros diff --git a/gnu/usr.bin/man/lib/util.c b/gnu/usr.bin/man/lib/util.c index 70d57b5..106e12c 100644 --- a/gnu/usr.bin/man/lib/util.c +++ b/gnu/usr.bin/man/lib/util.c @@ -14,6 +14,8 @@ * Austin, Texas 78712 */ +/* $FreeBSD$ */ + #include <stdio.h> #include <string.h> #include <ctype.h> @@ -120,6 +122,24 @@ is_directory (path) } /* + * Is path a regular file? + */ +int +is_file (path) + char *path; +{ + struct stat sb; + register int status; + + status = stat (path, &sb); + + if (status != 0) + return -1; + + return ((sb.st_mode & S_IFREG) == S_IFREG); +} + +/* * Attempt a system () call. Return 1 for success and 0 for failure * (handy for counting successes :-). */ diff --git a/gnu/usr.bin/man/man/man.c b/gnu/usr.bin/man/man/man.c index 39b452e..721c5e6 100644 --- a/gnu/usr.bin/man/man/man.c +++ b/gnu/usr.bin/man/man/man.c @@ -30,6 +30,7 @@ static const char rcsid[] = #ifdef __FreeBSD__ #include <locale.h> #include <langinfo.h> +#include <libgen.h> #endif #include <stdio.h> #include <string.h> @@ -70,6 +71,7 @@ extern char *sprintf (); extern char **glob_filename (); extern int is_newer (); extern int is_directory (); +extern int is_file (); extern int do_system_command (); char *prognam; @@ -87,6 +89,7 @@ static int apropos; static int whatis; static int findall; static int print_where; +static char *ultimate_source (); #ifdef __FreeBSD__ static char *locale, *locale_opts, *locale_nroff, *locale_codeset; @@ -201,6 +204,11 @@ main (argc, argv) do_whatis (nextarg); status = (status ? 0 : 1); /* reverts status, see below */ } + else if (strchr (nextarg, '/') != NULL && is_file (nextarg) == 1) + { + format_and_display (NULL, ultimate_source(nextarg, dirname(nextarg)), + NULL); + } else { status = man (nextarg); @@ -1409,13 +1417,15 @@ format_and_display (path, man_file, cat_file) if (access (man_file, R_OK) != 0) return 0; - if (troff) + if (troff || path == NULL) { roff_command = make_roff_command (man_file); if (roff_command == NULL) return 0; - else + if (troff) snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command); + else + snprintf (command, sizeof(command), "%s | %s", roff_command, pager); found = do_system_command (command); } |