From: millert Date: Sat, 1 Apr 2000 05:05:35 +0000 (+0000) Subject: Previously, whatis would treat a word as [A-z0-9_] and terminate X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b0a2bf1b38e5885675ca118fee11500ce65faaea;p=openbsd Previously, whatis would treat a word as [A-z0-9_] and terminate parsing an entry at the end of a word. This kept things like 'whatis B::Bytecode' from working. Now we match both on a word basis as well matching until we hit a space, ',', or '(' character. This allows one to say 'whatis B' and see the whatis line for B(3p) as well as its methods (B::*). --- diff --git a/usr.bin/whatis/whatis.1 b/usr.bin/whatis/whatis.1 index 34cf9376b54..1607a7a7e9a 100644 --- a/usr.bin/whatis/whatis.1 +++ b/usr.bin/whatis/whatis.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: whatis.1,v 1.6 2000/03/14 14:58:26 aaron Exp $ +.\" $OpenBSD: whatis.1,v 1.7 2000/04/01 05:05:35 millert Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -50,9 +50,17 @@ looks up a given command and gives the header line from the manual page. You can then use the .Xr man 1 command to get more information. +.Nm +will match on a case insensitive basis and for multiple word entries +will match on each individual word. .Pp The options are as follows: .Bl -tag -width Fl +.It Fl C Ar file +Specify an alternate configuration file in +.Xr man.conf 5 +format. The default is +.Pa /etc/man.conf . .It Fl M Ar path Override the list of standard directories .Nm @@ -100,7 +108,8 @@ name of the whatis database .Xr apropos 1 , .Xr man 1 , .Xr whereis 1 , -.Xr which 1 +.Xr which 1 , +.Xr man.conf 5 .Sh HISTORY The .Nm diff --git a/usr.bin/whatis/whatis.c b/usr.bin/whatis/whatis.c index d1b83fa715f..32cbb818d1c 100644 --- a/usr.bin/whatis/whatis.c +++ b/usr.bin/whatis/whatis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: whatis.c,v 1.4 1997/11/30 05:30:37 deraadt Exp $ */ +/* $OpenBSD: whatis.c,v 1.5 2000/04/01 05:05:35 millert Exp $ */ /* * Copyright (c) 1987, 1993 @@ -58,6 +58,7 @@ static char sccsid[] = "@(#)whatis.c 8.5 (Berkeley) 11/26/93"; #define MAXLINELEN 8192 /* max line handled */ static int *found, foundman; +extern char *__progname; void dashtrunc __P((char *, char *)); int match __P((char *, char *)); @@ -103,7 +104,7 @@ main(argc, argv) memset(found, 0, argc * sizeof(int)); for (p = argv; *p; ++p) /* trim full paths */ - if (beg = strrchr(*p, '/')) + if ((beg = strrchr(*p, '/'))) *p = beg + 1; if (p_augment) @@ -141,7 +142,7 @@ whatis(argv, path, buildpath) char hold[MAXPATHLEN]; for (name = path; name; name = end) { /* through name list */ - if (end = strchr(name, ':')) + if ((end = strchr(name, ':'))) *end++ = '\0'; if (buildpath) { @@ -175,7 +176,7 @@ whatis(argv, path, buildpath) /* * match -- - * match a full word + * match a full word or a full string */ int match(bp, str) @@ -187,13 +188,26 @@ match(bp, str) if (!*str || !*bp) return(0); for (len = strlen(str);;) { - for (; *bp && !isdigit(*bp) && !isalpha(*bp); ++bp); + /* skip leading crud */ + for (; *bp && !isalnum(*bp); ++bp) + ; if (!*bp) break; - for (start = bp++; - *bp && (*bp == '_' || isdigit(*bp) || isalpha(*bp)); ++bp); - if (bp - start == len && !strncasecmp(start, str, len)) - return(1); + + /* check for word match first */ + for (start = bp++; *bp && (*bp == '_' || isalnum(*bp)); ++bp) + ; + if (bp - start == len) { + if (strncasecmp(start, str, len) == 0) + return(1); + } else if (*bp && *bp != ',') { + /* check for full string match */ + for (bp = start; + *bp && *bp != ',' && *bp != '(' && !isspace(*bp); ++bp) + ; + if (bp - start == len && strncasecmp(start, str, len) == 0) + return(1); + } } return(0); } @@ -221,7 +235,9 @@ dashtrunc(from, to) void usage() { + (void)fprintf(stderr, - "usage: whatis [-C file] [-M path] [-m path] command ...\n"); + "usage: %s [-C file] [-M path] [-m path] command ...\n", + __progname); exit(1); }