diff options
| author | Ruslan Ermilov <ru@FreeBSD.org> | 2008-05-22 07:30:32 +0000 |
|---|---|---|
| committer | Ruslan Ermilov <ru@FreeBSD.org> | 2008-05-22 07:30:32 +0000 |
| commit | a622817fb60252ba1ef80df526e771ee9a85ace0 (patch) | |
| tree | c0027a4e3f87974d3b7f57200c71fdc51f16a6b4 /gnu | |
| parent | 24c28db7c4f91abb60b14e2cbb8f2497f94362be (diff) | |
Notes
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 | 16 |
3 files changed, 36 insertions, 4 deletions
diff --git a/gnu/usr.bin/man/TODO b/gnu/usr.bin/man/TODO index 19060adc8201..63dbb227126e 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 70d57b56a3c4..106e12c934c5 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 2cdd22a76b30..d29d2f87be03 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); @@ -825,7 +833,7 @@ get_expander (file) return YCAT; #endif /* YCAT */ #ifdef ZCAT - if (*end == 'Z' || !strcmp(end, "gz")) + if (*end == 'Z' || !strcmp(end, "gz") || !strcmp(end, "bz2")) return ZCAT; #endif /* ZCAT */ return NULL; @@ -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); } |
