new copyright notice
[unix-history] / usr / src / usr.bin / whatis / whatis.c
index 89ea48e..7c6527b 100644 (file)
@@ -2,17 +2,7 @@
  * Copyright (c) 1987 Regents of the University of California.
  * All rights reserved.
  *
  * 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
  */
 
 #ifndef lint
@@ -22,20 +12,22 @@ char copyright[] =
 #endif /* not lint */
 
 #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>
 #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 */
 
 #include "../man/pathnames.h"
 
 #define        MAXLINELEN      256                     /* max line handled */
 
-int *found, foundman;
 char *progname;
 
 char *progname;
 
+static int *found, foundman;
+
 main(argc, argv)
        int argc;
        char **argv;
 main(argc, argv)
        int argc;
        char **argv;
@@ -44,7 +36,7 @@ main(argc, argv)
        extern int optind;
        register char *beg, **p;
        int ch;
        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)
 
        progname = "whatis";
        while ((ch = getopt(argc, argv, "M:m:P:")) != EOF)
@@ -66,9 +58,6 @@ main(argc, argv)
        if (argc < 1)
                usage();
 
        if (argc < 1)
                usage();
 
-       if (!p_path && !(p_path = getenv("MANPATH")))
-               p_path = config();
-
        /*NOSTRICT*/
        if (!(found = (int *)malloc((u_int)argc)))
                enomem();
        /*NOSTRICT*/
        if (!(found = (int *)malloc((u_int)argc)))
                enomem();
@@ -79,9 +68,12 @@ main(argc, argv)
                        *p = beg + 1;
 
        if (p_augment)
                        *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);
 
        if (!foundman) {
                fprintf(stderr, "whatis: no %s file found.\n", _PATH_WHATIS);
@@ -92,27 +84,31 @@ main(argc, argv)
                        printf("%s: not found\n", *p);
 }
 
                        printf("%s: not found\n", *p);
 }
 
-whatis(argv, path)
+whatis(argv, path, buildpath)
        char **argv, *path;
        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];
 
        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;
 
                        continue;
 
+               foundman = 1;
+
                /* for each file found */
                /* 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)) {
                        dashtrunc(buf, wbuf);
                        for (p = argv; *p; ++p)
                                if (match(wbuf, *p)) {