* Copyright (c) 1987 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
static char sccsid
[] = "@(#)man.c 5.17 (Berkeley) %G%";
#define DEF_PAGER "/usr/ucb/more -s"
#define DEF_PATH "/usr/man:/usr/new/man:/usr/local/man"
#define LOCAL_PATH "/usr/local/man"
#define NEW_PATH "/usr/new/man"
static char *command
, /* command buffer */
*defpath
, /* default search path */
*locpath
, /* local search path */
*machine
, /* machine type */
*manpath
, /* current search path */
*newpath
, /* new search path */
*pager
, /* requested pager */
how
; /* how to display */
#define ALL 0x1 /* show all man pages */
#define CAT 0x2 /* copy file to stdout */
#define WHERE 0x4 /* just tell me where */
char *getenv(), *malloc();
while ((ch
= getopt(argc
, argv
, "-M:P:afkw")) != EOF
)
case 'P': /* backward compatibility */
* "man -f" and "man -k" are backward contemptible,
* undocumented ways of calling whatis(1) and apropos(1).
jump(argv
, "-f", "whatis");
jump(argv
, "-k", "apropos");
* Deliberately undocumented; really only useful when
* you're moving man pages around. Not worth adding.
else if (pager
= getenv("PAGER")) {
* if the user uses "more", we make it "more -s"
* watch out for PAGER = "mypager /usr/ucb/more"
for (p
= pager
; *p
&& !isspace(*p
); ++p
);
for (; p
> pager
&& *p
!= '/'; --p
);
/* make sure it's "more", not "morex" */
if (!strncmp(p
, "more", 4) && (!p
[4] || isspace(p
[4]))){
* allocate space to add the "-s"
if (!(pager
= malloc((u_int
)(strlen(opager
)
fputs("man: out of space.\n", stderr
);
(void)sprintf(pager
, "%s %s", opager
, "-s");
if (!(machine
= getenv("MACHINE")))
if (!defpath
&& !(defpath
= getenv("MANPATH")))
/* use system(3) in case someone's pager is "pager arg1 arg2" */
static DIR list1
[] = { /* section one list */
"cat1", "1st", "cat8", "8th", "cat6", "6th",
"cat.old", "old", NULL
, NULL
,
}, list2
[] = { /* rest of the list */
"cat2", "2nd", "cat3", "3rd", "cat4", "4th",
"cat5", "5th", "cat7", "7th", "cat3f", "3rd (F)",
}, list3
[2]; /* single section */
DIR *section
, *getsect();
/* support the "{l,local,n,new}###" syntax */
for (p
= *argv
; isalpha(*p
); ++p
);
if (!strncmp(*argv
, "l", p
- *argv
) ||
!strncmp(*argv
, "local", p
- *argv
)) {
for (p
= *argv
; isalpha(*p
); ++p
);
if (!strncmp(*argv
, "n", p
- *argv
) ||
!strncmp(*argv
, "new", p
- *argv
)) {
* old isn't really a separate section of the manual,
* and its entries are all in a single directory.
for (p
= *argv
; isalpha(*p
); ++p
);
if (!strncmp(*argv
, "o", p
- *argv
) ||
!strncmp(*argv
, "old", p
- *argv
)) {
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8':
if (section
= getsect(*argv
))
res
= manual(section
, *argv
);
res
= manual(list1
, *argv
);
res
+= manual(list2
, *argv
);
fprintf(stderr
, "no entry for %s in the ", *argv
);
fputs("what do you want from the ", stderr
);
fprintf(stderr
, "%s section of the ", section
->msg
);
else if (manpath
== newpath
)
fputs("manual.\n", stderr
);
fputs("manual?\n", stderr
);
* given a directory list and a file name find a file that
* matches; check ${directory}/${dir}/{file name} and
* ${directory}/${dir}/${machine}/${file name}.
register char *beg
, *end
;
char fname
[MAXPATHLEN
+ 1], *index();
for (beg
= manpath
, res
= 0;; beg
= end
+ 1) {
if (end
= index(beg
, ':'))
for (dp
= section
; dp
->name
; ++dp
) {
(void)sprintf(fname
, "%s/%s/%s.0", beg
, dp
->name
, name
);
if (access(fname
, R_OK
)) {
(void)sprintf(fname
, "%s/%s/%s/%s.0", beg
,
dp
->name
, machine
, name
);
printf("man: found in %s.\n", fname
);
if (!(fd
= open(fname
, O_RDONLY
, 0))) {
while ((n
= read(fd
, buf
, sizeof(buf
))) > 0)
if (write(1, buf
, n
) != n
) {
* add a file name to the list for future paging
char *malloc(), *realloc(), *strcpy();
if (!(command
= malloc(buflen
= 1024))) {
fputs("man: out of space.\n", stderr
);
len
= strlen(strcpy(command
, pager
));
if (len
+ flen
+ 2 > buflen
) { /* +2 == space, EOS */
if (!(command
= realloc(command
, buflen
+= 1024))) {
fputs("man: out of space.\n", stderr
);
len
+= flen
+ 1; /* +1 = space */
* return a point to the section structure for a particular suffix
/* sect. 3 requests are for either section 3, or section 3[fF]. */
else if ((*s
== 'f' || *s
== 'F') && !*++s
) {
* strip out flag argument and jump
for (arg
= argv
+ 1; *arg
; ++arg
)
fprintf(stderr
, "%s: Command not found.\n", name
);
fputs("usage: man [-] [-a] [-M path] [section] title ...\n", stderr
);