[BACK]Return to apropos.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/Attic/apropos.c between version 1.15 and 1.16

version 1.15, 2011/11/20 15:43:14 version 1.16, 2011/11/20 16:29:50
Line 39  struct manpaths {
Line 39  struct manpaths {
   
 static  int      cmp(const void *, const void *);  static  int      cmp(const void *, const void *);
 static  void     list(struct res *, size_t, void *);  static  void     list(struct res *, size_t, void *);
 static  int      manpath_add(struct manpaths *, const char *);  static  void     manpath_add(struct manpaths *, const char *);
 static  int      manpath_parse(struct manpaths *, char *);  static  void     manpath_parse(struct manpaths *, char *);
 static  void     usage(void);  static  void     usage(void);
   
 static  char    *progname;  static  char    *progname;
Line 71  main(int argc, char *argv[])
Line 71  main(int argc, char *argv[])
         while (-1 != (ch = getopt(argc, argv, "m:S:s:")))          while (-1 != (ch = getopt(argc, argv, "m:S:s:")))
                 switch (ch) {                  switch (ch) {
                 case ('m'):                  case ('m'):
                         if ( ! manpath_parse(&paths, optarg))                          manpath_parse(&paths, optarg);
                                 goto out;  
                         break;                          break;
                 case ('S'):                  case ('S'):
                         opts.arch = optarg;                          opts.arch = optarg;
Line 93  main(int argc, char *argv[])
Line 92  main(int argc, char *argv[])
                 goto out;                  goto out;
         }          }
   
         if (0 == paths.sz && ! manpath_add(&paths, "."))          /*
                 goto out;           * Let MANPATH override our default paths.
            */
   
           if (NULL != getenv("MANPATH"))
                   manpath_add(&paths, getenv("MANPATH"));
           else
                   manpath_add(&paths, ".");
   
         if (NULL == (e = exprcomp(argc, argv, &terms))) {          if (NULL == (e = exprcomp(argc, argv, &terms))) {
                 /* FIXME: be more specific about this. */                  fprintf(stderr, "%s: Bad expression\n", progname);
                 fprintf(stderr, "Bad expression\n");  
                 goto out;                  goto out;
         }          }
   
Line 106  main(int argc, char *argv[])
Line 110  main(int argc, char *argv[])
                 (paths.sz, paths.paths,                  (paths.sz, paths.paths,
                  &opts, e, terms, NULL, list);                   &opts, e, terms, NULL, list);
   
         /* FIXME: report an error based on ch. */          if (0 == rc)
                   fprintf(stderr, "%s: Error reading "
                                   "manual database\n", progname);
   
 out:  out:
         for (i = 0; i < paths.sz; i++)          for (i = 0; i < paths.sz; i++)
Line 156  usage(void)
Line 162  usage(void)
 /*  /*
  * Parse a FULL pathname from a colon-separated list of arrays.   * Parse a FULL pathname from a colon-separated list of arrays.
  */   */
 static int  static void
 manpath_parse(struct manpaths *dirs, char *path)  manpath_parse(struct manpaths *dirs, char *path)
 {  {
         char    *dir;          char    *dir;
   
         for (dir = strtok(path, ":"); dir; dir = strtok(NULL, ":"))          for (dir = strtok(path, ":"); dir; dir = strtok(NULL, ":"))
                 if ( ! manpath_add(dirs, dir))                  manpath_add(dirs, dir);
                         return(0);  
   
         return(1);  
 }  }
   
 /*  /*
  * Add a directory to the array.   * Add a directory to the array, ignoring bad directories.
  * Grow the array one-by-one for simplicity's sake.   * Grow the array one-by-one for simplicity's sake.
  * Return 0 if the directory is not a real path.  
  */   */
 static int  static void
 manpath_add(struct manpaths *dirs, const char *dir)  manpath_add(struct manpaths *dirs, const char *dir)
 {  {
         char             buf[PATH_MAX];          char             buf[PATH_MAX];
         char            *cp;          char            *cp;
   
         if (NULL == (cp = realpath(dir, buf))) {          if (NULL == (cp = realpath(dir, buf)))
                 fprintf(stderr, "%s: Invalid path\n", dir);                  return;
                 return(0);  
         }  
   
         dirs->paths = mandoc_realloc          dirs->paths = mandoc_realloc
                 (dirs->paths,                  (dirs->paths,
                  ((size_t)dirs->sz + 1) * sizeof(char *));                   ((size_t)dirs->sz + 1) * sizeof(char *));
   
         dirs->paths[dirs->sz++] = mandoc_strdup(cp);          dirs->paths[dirs->sz++] = mandoc_strdup(cp);
         return(1);  
 }  }

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

CVSweb