[BACK]Return to apropos.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / apropos

Diff for /src/usr.bin/apropos/Attic/apropos.c between version 1.1 and 1.15

version 1.1, 1995/10/18 08:44:52 version 1.15, 2009/10/27 23:59:35
Line 1 
Line 1 
   /*      $OpenBSD$      */
 /*      $NetBSD: apropos.c,v 1.5 1995/09/04 20:46:20 tls Exp $      */  /*      $NetBSD: apropos.c,v 1.5 1995/09/04 20:46:20 tls Exp $      */
   
 /*  /*
Line 12 
Line 13 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 33 
Line 30 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
 #ifndef lint  
 static char copyright[] =  
 "@(#) Copyright (c) 1987, 1993, 1994\n\  
         The Regents of the University of California.  All rights reserved.\n";  
 #endif /* not lint */  
   
 #ifndef lint  
 #if 0  
 static char sccsid[] = "@(#)apropos.c   8.8 (Berkeley) 5/4/95";  
 #else  
 static char rcsid[] = "$NetBSD: apropos.c,v 1.5 1995/09/04 20:46:20 tls Exp $";  
 #endif  
 #endif /* not lint */  
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/queue.h>  #include <sys/queue.h>
   
Line 63 
Line 46 
   
 static int *found, foundman;  static int *found, foundman;
   
 void apropos __P((char **, char *, int));  #define MAXLINELEN      8192            /* max line handled */
 void lowstr __P((char *, char *));  
 int match __P((char *, char *));  
 void usage __P((void));  
   
   void apropos(char **, char *, int, char *, char *);
   void lowstr(char *, char *);
   int match(char *, char *);
   void usage(void);
   
 int  int
 main(argc, argv)  main(int argc, char *argv[])
         int argc;  
         char *argv[];  
 {  {
         ENTRY *ep;          ENTRY *ep;
         TAG *tp;          TAG *tp;
         int ch, rv;          int ch, rv;
         char *conffile, **p, *p_augment, *p_path;          char *conffile, *machine, **p, *p_augment, *p_path, *sflag;
   
         conffile = NULL;          conffile = NULL;
         p_augment = p_path = NULL;          p_augment = p_path = NULL;
         while ((ch = getopt(argc, argv, "C:M:m:P:")) != EOF)          machine = sflag = NULL;
           while ((ch = getopt(argc, argv, "C:M:m:P:S:s:")) != -1)
                 switch (ch) {                  switch (ch) {
                 case 'C':                  case 'C':
                         conffile = optarg;                          conffile = optarg;
Line 92 
Line 76 
                 case 'm':                  case 'm':
                         p_augment = optarg;                          p_augment = optarg;
                         break;                          break;
                   case 'S':
                           machine = optarg;
                           lowstr(machine, machine);
                           break;
                   case 's':
                           sflag = optarg;
                           lowstr(sflag, sflag);
                           break;
                 case '?':                  case '?':
                 default:                  default:
                         usage();                          usage();
Line 102 
Line 94 
         if (argc < 1)          if (argc < 1)
                 usage();                  usage();
   
         if ((found = malloc((u_int)argc * sizeof(int))) == NULL)          if ((found = calloc(argc, sizeof(int))) == NULL)
                 err(1, NULL);                  err(1, NULL);
         memset(found, 0, argc * sizeof(int));  
   
         for (p = argv; *p; ++p)                 /* convert to lower-case */          for (p = argv; *p; ++p)                 /* convert to lower-case */
                 lowstr(*p, *p);                  lowstr(*p, *p);
   
         if (p_augment)          if (p_augment)
                 apropos(argv, p_augment, 1);                  apropos(argv, p_augment, 1, sflag, machine);
         if (p_path || (p_path = getenv("MANPATH")))          if (p_path || (p_path = getenv("MANPATH")))
                 apropos(argv, p_path, 1);                  apropos(argv, p_path, 1, sflag, machine);
         else {          else {
                 config(conffile);                  config(conffile);
                 ep = (tp = getlist("_whatdb")) == NULL ?                  ep = (tp = getlist("_whatdb")) == NULL ?
                     NULL : tp->list.tqh_first;                      NULL : TAILQ_FIRST(&tp->list);
                 for (; ep != NULL; ep = ep->q.tqe_next)                  for (; ep != NULL; ep = TAILQ_NEXT(ep, q))
                         apropos(argv, ep->s, 0);                          apropos(argv, ep->s, 0, sflag, machine);
         }          }
   
         if (!foundman)          if (!foundman)
Line 134 
Line 125 
 }  }
   
 void  void
 apropos(argv, path, buildpath)  apropos(char **argv, char *path, int buildpath, char *sflag, char *machine)
         char **argv, *path;  
         int buildpath;  
 {  {
         char *end, *name, **p;          char *end, *name, **p;
         char buf[LINE_MAX + 1], wbuf[LINE_MAX + 1];          char buf[MAXLINELEN + 1], wbuf[MAXLINELEN + 1];
           char hold[MAXPATHLEN];
           size_t slen = 0, mlen = 0;
   
           if (sflag)
                   slen = strlen(sflag);
           if (machine)
                   mlen = strlen(machine);
   
         for (name = path; name; name = end) {   /* through name list */          for (name = path; name; name = end) {   /* through name list */
                 if (end = strchr(name, ':'))                  if ((end = strchr(name, ':')))
                         *end++ = '\0';                          *end++ = '\0';
   
                 if (buildpath) {                  if (buildpath) {
                         char hold[MAXPATHLEN + 1];                          (void)snprintf(hold, sizeof(hold), "%s/%s", name,
                               _PATH_WHATIS);
                         (void)sprintf(hold, "%s/%s", name, _PATH_WHATIS);  
                         name = hold;                          name = hold;
                 }                  }
   
Line 164 
Line 159 
                                 continue;                                  continue;
                         }                          }
                         lowstr(buf, wbuf);                          lowstr(buf, wbuf);
                           if (sflag || machine) {
                                   char *s = strstr(wbuf, ") - ");
                                   if (!s)
                                           continue;
                                   while (s > wbuf && *s != '/' && *s != '(')
                                           s--;
                                   if (machine && *s == '/' &&
                                       strncmp(s+1, machine, mlen))
                                           continue;
                                   while (s > wbuf && *s != '(')
                                           s--;
                                   if (sflag && *s == '(' &&
                                       strncmp(s+1, sflag, slen))
                                           continue;
                           }
                         for (p = argv; *p; ++p)                          for (p = argv; *p; ++p)
                                 if (match(wbuf, *p)) {                                  if (match(wbuf, *p)) {
                                         (void)printf("%s", buf);                                          (void)printf("%s", buf);
Line 184 
Line 194 
  *      match anywhere the string appears   *      match anywhere the string appears
  */   */
 int  int
 match(bp, str)  match(char *bp, char *str)
         char *bp, *str;  
 {  {
         int len;          int len;
         char test;          char test;
Line 206 
Line 215 
  *      convert a string to lower case   *      convert a string to lower case
  */   */
 void  void
 lowstr(from, to)  lowstr(char *from, char *to)
         char *from, *to;  
 {  {
         char ch;          char ch;
   
Line 221 
Line 229 
  *      print usage message and die   *      print usage message and die
  */   */
 void  void
 usage()  usage(void)
 {  {
   
         (void)fprintf(stderr,          (void)fprintf(stderr,
             "usage: apropos [-C file] [-M path] [-m path] keyword ...\n");              "usage: apropos [-C file] [-M path] [-m path] "
               "[-S subsection] [-s section]\n"
               "       keyword ...\n");
         exit(1);          exit(1);
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.15