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

Diff for /src/usr.bin/mandoc/mandocdb.c between version 1.9 and 1.10

version 1.9, 2011/11/17 15:38:27 version 1.10, 2011/11/26 16:41:35
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
    * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 24 
Line 25 
 #include <stdint.h>  #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  
 #include <db.h>  #include <db.h>
   
 #include "man.h"  #include "man.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "mandoc.h"  #include "mandoc.h"
 #include "mandocdb.h"  #include "mandocdb.h"
 #include "man_conf.h"  #include "manpath.h"
   
 #define MANDOC_BUFSZ      BUFSIZ  #define MANDOC_BUFSZ      BUFSIZ
 #define MANDOC_SLOP       1024  #define MANDOC_SLOP       1024
Line 244 
Line 244 
 int  int
 mandocdb(int argc, char *argv[])  mandocdb(int argc, char *argv[])
 {  {
         struct man_conf  dirs;  
         struct mparse   *mp; /* parse sequence */          struct mparse   *mp; /* parse sequence */
           struct manpaths  dirs;
         enum op          op; /* current operation */          enum op          op; /* current operation */
         const char      *dir;          const char      *dir;
         char             ibuf[MAXPATHLEN], /* index fname */          char             ibuf[MAXPATHLEN], /* index fname */
Line 274 
Line 274 
         else          else
                 ++progname;                  ++progname;
   
           memset(&dirs, 0, sizeof(struct manpaths));
   
         verb = 0;          verb = 0;
         use_all = 0;          use_all = 0;
         of = NULL;          of = NULL;
Line 310 
Line 312 
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
         memset(&dirs, 0, sizeof(struct man_conf));  
         memset(&info, 0, sizeof(BTREEINFO));          memset(&info, 0, sizeof(BTREEINFO));
         info.flags = R_DUP;          info.flags = R_DUP;
   
Line 367 
Line 368 
                 index_prune(of, db, fbuf, idx, ibuf, verb,                  index_prune(of, db, fbuf, idx, ibuf, verb,
                                 &maxrec, &recs, &recsz);                                  &maxrec, &recs, &recsz);
   
                 if (OP_UPDATE == op) {                  if (OP_UPDATE == op)
                         chdir(dir);                          index_merge(of, mp, &dbuf, &buf, hash,
                         index_merge(of, mp, &dbuf, &buf, hash,  
                                         db, fbuf, idx, ibuf, use_all,                                          db, fbuf, idx, ibuf, use_all,
                                         verb, maxrec, recs, reccur);                                          verb, maxrec, recs, reccur);
                 }  
   
                 goto out;                  goto out;
         }          }
   
         if (0 == argc) {          /*
                 man_conf_parse(&dirs);           * Configure the directories we're going to scan.
                 argc = dirs.argc;           * If we have command-line arguments, use them.
                 argv = dirs.argv;           * If not, we use man(1)'s method (see mandocdb.8).
         }           */
   
         for (i = 0; i < argc; i++) {          if (argc > 0) {
                   dirs.paths = mandoc_malloc(argc * sizeof(char *));
                   dirs.sz = argc;
                   for (i = 0; i < argc; i++)
                           dirs.paths[i] = mandoc_strdup(argv[i]);
           } else
                   manpath_parse(&dirs, NULL, NULL);
   
           for (i = 0; i < dirs.sz; i++) {
                 ibuf[0] = fbuf[0] = '\0';                  ibuf[0] = fbuf[0] = '\0';
   
                 strlcat(fbuf, argv[i], MAXPATHLEN);                  strlcat(fbuf, dirs.paths[i], MAXPATHLEN);
                 strlcat(fbuf, "/", MAXPATHLEN);                  strlcat(fbuf, "/", MAXPATHLEN);
                 sz1 = strlcat(fbuf, MANDOC_DB, MAXPATHLEN);                  sz1 = strlcat(fbuf, MANDOC_DB, MAXPATHLEN);
   
                 strlcat(ibuf, argv[i], MAXPATHLEN);                  strlcat(ibuf, dirs.paths[i], MAXPATHLEN);
                 strlcat(ibuf, "/", MAXPATHLEN);                  strlcat(ibuf, "/", MAXPATHLEN);
                 sz2 = strlcat(ibuf, MANDOC_IDX, MAXPATHLEN);                  sz2 = strlcat(ibuf, MANDOC_IDX, MAXPATHLEN);
   
                 if (sz1 >= MAXPATHLEN || sz2 >= MAXPATHLEN) {                  if (sz1 >= MAXPATHLEN || sz2 >= MAXPATHLEN) {
                         fprintf(stderr, "%s: Path too long\n", argv[i]);                          fprintf(stderr, "%s: Path too long\n",
                                           dirs.paths[i]);
                         exit((int)MANDOCLEVEL_BADARG);                          exit((int)MANDOCLEVEL_BADARG);
                 }                  }
   
Line 423 
Line 431 
                 ofile_free(of);                  ofile_free(of);
                 of = NULL;                  of = NULL;
   
                 if ( ! ofile_dirbuild(argv[i], NULL, NULL,                  if ( ! ofile_dirbuild(dirs.paths[i], NULL, NULL,
                                 use_all, verb, &of))                                  use_all, verb, &of))
                         exit((int)MANDOCLEVEL_SYSERR);                          exit((int)MANDOCLEVEL_SYSERR);
   
                 if (NULL == of)                  if (NULL == of)
Line 432 
Line 440 
   
                 of = of->first;                  of = of->first;
   
                 chdir(argv[i]);                  index_merge(of, mp, &dbuf, &buf, hash, db, fbuf,
                 index_merge(of, mp, &dbuf, &buf, hash, db, fbuf,  
                                 idx, ibuf, use_all, verb,                                  idx, ibuf, use_all, verb,
                                 maxrec, recs, reccur);                                  maxrec, recs, reccur);
         }          }
Line 447 
Line 454 
                 (*hash->close)(hash);                  (*hash->close)(hash);
         if (mp)          if (mp)
                 mparse_free(mp);                  mparse_free(mp);
         if (dirs.argc)  
                 man_conf_free(&dirs);  
   
           manpath_free(&dirs);
         ofile_free(of);          ofile_free(of);
         free(buf.cp);          free(buf.cp);
         free(dbuf.cp);          free(dbuf.cp);
Line 461 
Line 467 
 void  void
 index_merge(const struct of *of, struct mparse *mp,  index_merge(const struct of *of, struct mparse *mp,
                 struct buf *dbuf, struct buf *buf,                  struct buf *dbuf, struct buf *buf,
                 DB *hash, DB *db, const char *dbf,                  DB *hash, DB *db, const char *dbf,
                 DB *idx, const char *idxf, int use_all, int verb,                  DB *idx, const char *idxf, int use_all, int verb,
                 recno_t maxrec, const recno_t *recs, size_t reccur)                  recno_t maxrec, const recno_t *recs, size_t reccur)
 {  {

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10