* Copyright (c) 1987 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
static char sccsid
[] = "@(#)man.c 5.24 (Berkeley) 7/21/90";
int f_all
, f_cat
, f_how
, f_where
;
char *command
, *machine
, *p_augment
, *p_path
, *pager
, *progname
;
extern char **arorder
, *pathbuf
;
char *section
[2], *check_pager(), *getpath(), **getorder(), *tmp
;
while ((ch
= getopt(argc
, argv
, "-acfhkM:m:P:w")) != EOF
)
case '-': /* deprecated */
case 'P': /* backward compatibility */
* "man -f" and "man -k" are backward compatible, undocumented
* ways of calling whatis(1) and apropos(1).
jump(argv
, "-f", "whatis");
jump(argv
, "-k", "apropos");
else if (pager
= getenv("PAGER"))
pager
= check_pager(pager
);
if (!(machine
= getenv("MACHINE")))
/* see if checking in a specific section */
if (argc
> 1 && getsection(*argv
)) {
section
[1] = (char *)NULL
;
section
[1] = (char *)NULL
;
if (p_path
|| (p_path
= getenv("MANPATH"))) {
char buf
[MAXPATHLEN
], **av
;
tmp
= strtok(p_path
, ":");
(void)sprintf(buf
, "%s/", tmp
);
for (av
= arorder
; *av
; ++av
)
cadd(buf
, strlen(buf
), *av
);
tmp
= strtok((char *)NULL
, ":");
} else if (!(p_path
= getpath(section
)) && !p_augment
) {
"man: no place to search for those manual pages.\n");
res
= manual(p_augment
, *argv
);
res
= manual(p_path
, *argv
);
"man: no entry for %s in the manual.\n", *argv
);
/* use system(3) in case someone's pager is "pager arg1 arg2" */
* given a path, a directory list and a file name, find a file
* that matches; check ${directory}/${dir}/{file name} and
* ${directory}/${dir}/${machine}/${file name}.
char fname
[MAXPATHLEN
+ 1];
for (res
= 0;; path
= end
+ 1) {
if (end
= index(path
, ':')) {
if (end
== path
+ 1) /* foo::bar */
(void)sprintf(fname
, "%s/%s.0", path
, name
);
if (access(fname
, R_OK
)) {
(void)sprintf(fname
, "%s/%s/%s.0", path
, machine
, name
);
(void)printf("man: found in %s.\n", fname
);
* display how information
register int lcnt
, print
;
if (!(fp
= fopen(fname
, "r"))) {
(void)fprintf(stderr
, "man: %s: %s\n", fname
, strerror(errno
));
#define S2 "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS"
#define D2 "D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN"
for (lcnt
= print
= 0; fgets(buf
, sizeof(buf
), fp
);) {
if (!strncmp(buf
, S1
, sizeof(S1
) - 1) ||
!strncmp(buf
, S2
, sizeof(S2
) - 1)) {
} else if (!strncmp(buf
, D1
, sizeof(D1
) - 1) ||
!strncmp(buf
, D2
, sizeof(D2
) - 1))
for (p
= buf
; isspace(*p
); ++p
);
if ((fd
= open(fname
, O_RDONLY
, 0)) < 0) {
(void)fprintf(stderr
, "man: %s: %s\n", fname
, strerror(errno
));
while ((n
= read(fd
, buf
, sizeof(buf
))) > 0)
if (write(1, buf
, n
) != n
) {
"man: write: %s\n", strerror(errno
));
(void)fprintf(stderr
, "man: read: %s\n", strerror(errno
));
* add a file name to the list for future paging
if (!(command
= malloc(buflen
= 1024)))
len
= strlen(strcpy(command
, pager
));
if (len
+ flen
+ 2 > buflen
) { /* +2 == space, EOS */
if (!(command
= realloc(command
, buflen
+= 1024)))
len
+= flen
+ 1; /* +1 = space */
* check the user supplied page information
* if the user uses "more", we make it "more -s"; watch out for
* PAGER = "mypager /usr/ucb/more"
for (p
= name
; *p
&& !isspace(*p
); ++p
);
for (; p
> name
&& *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" */
malloc((u_int
)(strlen(save
) + sizeof("-s") + 1))))
(void)sprintf(name
, "%s %s", save
, "-s");
* strip out flag argument and jump
for (arg
= argv
+ 1; *arg
; ++arg
)
(void)fprintf(stderr
, "%s: Command not found.\n", name
);
* print usage message and die
"usage: man [-ac] [-M path] [-m path] [section] title ...\n");