* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
*
- * 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.
+ * %sccs.include.redist.c%
*/
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)whatis.c 5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)whatis.c 5.6 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <stdlib.h>
#include "../man/pathnames.h"
#define MAXLINELEN 256 /* max line handled */
-int *found, foundman;
char *progname;
+static int *found, foundman;
+
main(argc, argv)
int argc;
char **argv;
extern int optind;
register char *beg, **p;
int ch;
- char *p_augment, *p_path, *config(), *getenv(), *malloc();
+ char *p_augment, *p_path, **getdb();
progname = "whatis";
while ((ch = getopt(argc, argv, "M:m:P:")) != EOF)
if (argc < 1)
usage();
- if (!p_path && !(p_path = getenv("MANPATH")))
- p_path = config();
-
/*NOSTRICT*/
if (!(found = (int *)malloc((u_int)argc)))
enomem();
*p = beg + 1;
if (p_augment)
- whatis(argv, p_augment);
- if (p_path)
- whatis(argv, p_path);
+ whatis(argv, p_augment, 1);
+ if (p_path || (p_path = getenv("MANPATH")))
+ whatis(argv, p_path, 1);
+ else
+ for (p = getdb(); *p; ++p)
+ whatis(argv, *p, 0);
if (!foundman) {
fprintf(stderr, "whatis: no %s file found.\n", _PATH_WHATIS);
printf("%s: not found\n", *p);
}
-whatis(argv, path)
+whatis(argv, path, buildpath)
char **argv, *path;
+ int buildpath;
{
- register char *beg, *end, **p;
- char fname[MAXPATHLEN + 1];
+ register char *end, *name, **p;
char buf[MAXLINELEN + 1], wbuf[MAXLINELEN + 1];
- for (beg = path; beg; beg = end) { /* through path list */
- end = index(beg, ':');
- if (!end)
- (void)sprintf(fname, "%s/%s", beg, _PATH_WHATIS);
- else {
- (void)sprintf(fname, "%.*s/%s", end - beg, beg,
- _PATH_WHATIS);
- ++end;
+ for (name = path; name; name = end) { /* through name list */
+ if (end = index(name, ':'))
+ *end++ = '\0';
+
+ if (buildpath) {
+ char hold[MAXPATHLEN + 1];
+
+ (void)sprintf(hold, "%s/%s", name, _PATH_WHATIS);
+ name = hold;
}
- if (!freopen(fname, "r", stdin))
+
+ if (!freopen(name, "r", stdin))
continue;
+ foundman = 1;
+
/* for each file found */
- for (foundman = 1; fgets(buf, sizeof(buf), stdin);) {
+ while (fgets(buf, sizeof(buf), stdin)) {
dashtrunc(buf, wbuf);
for (p = argv; *p; ++p)
if (match(wbuf, *p)) {