* Copyright (c) 1987 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
static char sccsid
[] = "@(#)apropos.c 5.2 (Berkeley) %G%";
#define DEF_PATH "/usr/man" /* default man path */
#define MAXLINELEN 500 /* max line handled */
#define NO 0 /* no/false */
#define WHATIS "whatis" /* database name */
#define YES 1 /* yes/true */
register char *beg
, *end
, **C
;
int ch
, foundman
= NO
, *found
, isapropos
,
a_match(), w_match(), (*match
)();
buf
[MAXLINELEN
+ 1], fname
[MAXPATHLEN
+ 1],
*getenv(), *index(), *malloc(), *rindex();
myname
= (beg
= rindex(*argv
, '/')) ? beg
+ 1 : *argv
;
if (!strcmp(myname
, "apropos")) {
while ((ch
= getopt(argc
, argv
, "M:P:")) != EOF
)
case 'P': /* backward contemptible */
if (!(manpath
= getenv("MANPATH")))
if (!(found
= (int *)malloc((u_int
)argc
))) {
fprintf(stderr
, "%s: out of space.\n", myname
);
bzero(found
, argc
* sizeof(int)); /* calloc is silly */
for (C
= argv
; *C
; ++C
) { /* trim full paths */
if (beg
= rindex(*C
, '/'))
for (C
= argv
; *C
; ++C
) /* convert to lower-case */
for (beg
= manpath
; beg
; beg
= end
) { /* through path list */
(void)sprintf(fname
, "%s/%s", beg
, WHATIS
);
(void)sprintf(fname
, "%.*s/%s", end
- beg
, beg
, WHATIS
);
/* for each file found */
if (freopen(fname
, "r", stdin
)) {
while (gets(buf
)) { /* read & convert to lcase */
if ((*match
)(wbuf
, *C
)) {
/* only print line once */
fprintf(stderr
, "%s: no %s file found in %s.\n", myname
, WHATIS
, manpath
);
printf("%s: %s\n", *C
, isapropos
? "nothing appropriate" : "not found");
register char test
, *Cs
, *Cb
;
/* backward contemptible: everything matches empty string */
for (test
= *str
++; *bp
;)
} while (*Cb
++ == *Cs
++);
register char test
, *Cs
, *Cb
;
for (test
= *str
++; *bp
;)
for (Cs
= str
, Cb
= bp
; *Cs
== *Cb
; ++Cs
, ++Cb
);
if (!*Cs
&& (isspace(*Cb
) || *Cb
== '(' || *Cb
== ','))
register char *from
, *to
;
for (; *from
; ++from
, ++to
)
*to
= isupper(*from
) ? tolower(*from
) : *from
;
fprintf(stderr
, "usage: %s [-M path] string ...\n", myname
);