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
This commit is contained in:
Ruslan Ermilov
2008-05-14 17:08:31 +00:00
parent aa6985f4f3
commit 6ccf134528
3 changed files with 35 additions and 3 deletions
+3 -1
View File
@@ -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
+20
View File
@@ -14,6 +14,8 @@
* Austin, Texas 78712
*/
/* $FreeBSD$ */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -119,6 +121,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 :-).
+12 -2
View File
@@ -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);
}