* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1987, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)apropos.c 8.6 (Berkeley) %G%";
#include "../man/config.h"
#include "../man/pathnames.h"
static int *found
, foundman
;
void apropos
__P((char **, char *, int));
void lowstr
__P((char *, char *));
int match
__P((char *, char *));
char *conffile
, **p
, *p_augment
, *p_path
;
p_augment
= p_path
= NULL
;
while ((ch
= getopt(argc
, argv
, "C:M:m:P:")) != EOF
)
case 'P': /* backward compatible */
if ((found
= malloc((u_int
)argc
* sizeof(int))) == NULL
)
memset(found
, 0, argc
* sizeof(int));
for (p
= argv
; *p
; ++p
) /* convert to lower-case */
apropos(argv
, p_augment
, 1);
if (p_path
|| (p_path
= getenv("MANPATH")))
apropos(argv
, p_path
, 1);
ep
= (tp
= getlist("_whatdb")) == NULL
?
NULL
: tp
->list
.tqh_first
;
for (; ep
!= NULL
; ep
= ep
->q
.tqe_next
)
errx(1, "no %s file found", _PATH_WHATIS
);
(void)printf("%s: nothing appropriate\n", *p
);
apropos(argv
, path
, buildpath
)
char buf
[LINE_MAX
+ 1], wbuf
[LINE_MAX
+ 1];
for (name
= path
; name
; name
= end
) { /* through name list */
if (end
= strchr(name
, ':'))
char hold
[MAXPATHLEN
+ 1];
(void)sprintf(hold
, "%s/%s", name
, _PATH_WHATIS
);
if (!freopen(name
, "r", stdin
))
/* for each file found */
while (fgets(buf
, sizeof(buf
), stdin
)) {
if (!strchr(buf
, '\n')) {
warnx("%s: line too long", name
);
/* only print line once */
* match anywhere the string appears
/* backward compatible: everything matches empty string */
for (test
= *str
++, len
= strlen(str
); *bp
;)
if (test
== *bp
++ && !strncmp(bp
, str
, len
))
* convert a string to lower case
while ((ch
= *from
++) && ch
!= '\n')
*to
++ = isupper(ch
) ? tolower(ch
) : ch
;
* print usage message and die
"usage: apropos [-C file] [-M path] [-m path] keyword ...\n");