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

Diff for /mandoc/mandocdb.c between version 1.49.2.2 and 1.49.2.6

version 1.49.2.2, 2013/09/17 22:48:53 version 1.49.2.6, 2013/10/01 00:52:58
Line 34 
Line 34 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 #if defined(__linux__)  #if defined(__linux__) || defined(__sun)
 # include <endian.h>  # include <endian.h>
 # include <db_185.h>  # include <db_185.h>
 #elif defined(__APPLE__)  #elif defined(__APPLE__)
Line 44 
Line 44 
 # include <db.h>  # include <db.h>
 #endif  #endif
   
   #if defined(__sun)
   #include <sys/stat.h>
   #endif
   
 #include "man.h"  #include "man.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "mandoc.h"  #include "mandoc.h"
Line 299  main(int argc, char *argv[])
Line 303  main(int argc, char *argv[])
         int              ch, i, flags;          int              ch, i, flags;
         DB              *hash; /* temporary keyword hashtable */          DB              *hash; /* temporary keyword hashtable */
         BTREEINFO        info; /* btree configuration */          BTREEINFO        info; /* btree configuration */
         size_t           sz1, sz2;          size_t           sz1, sz2, ipath;
         struct buf       buf, /* keyword buffer */          struct buf       buf, /* keyword buffer */
                          dbuf; /* description buffer */                           dbuf; /* description buffer */
         struct of       *of; /* list of files for processing */          struct of       *of; /* list of files for processing */
Line 482  main(int argc, char *argv[])
Line 486  main(int argc, char *argv[])
         } else          } else
                 manpath_parse(&dirs, dir, NULL, NULL);                  manpath_parse(&dirs, dir, NULL, NULL);
   
         for (i = 0; i < dirs.sz; i++) {          for (ipath = 0; ipath < dirs.sz; ipath++) {
   
                 /*                  /*
                  * Go to the root of the respective manual tree.                   * Go to the root of the respective manual tree.
Line 490  main(int argc, char *argv[])
Line 494  main(int argc, char *argv[])
                  * They are indexed relative to the root.                   * They are indexed relative to the root.
                  */                   */
   
                 if (-1 == chdir(dirs.paths[i])) {                  if (-1 == chdir(dirs.paths[ipath])) {
                         perror(dirs.paths[i]);                          perror(dirs.paths[ipath]);
                         exit((int)MANDOCLEVEL_SYSERR);                          exit((int)MANDOCLEVEL_SYSERR);
                 }                  }
   
                 strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX);                  /* Create a new database in two temporary files. */
                 strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX);  
   
                 flags = O_CREAT | O_TRUNC | O_RDWR;                  flags = O_CREAT | O_EXCL | O_RDWR;
                 mdb.db = dbopen(mdb.dbn, flags, 0644, DB_BTREE, &info);                  while (NULL == mdb.db) {
                 mdb.idx = dbopen(mdb.idxn, flags, 0644, DB_RECNO, NULL);                          strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX);
                           strlcat(mdb.dbn, ".XXXXXXXXXX", PATH_MAX);
                 if (NULL == mdb.db) {                          if (NULL == mktemp(mdb.dbn)) {
                         perror(mdb.dbn);                                  perror(mdb.dbn);
                         exit((int)MANDOCLEVEL_SYSERR);                                  exit((int)MANDOCLEVEL_SYSERR);
                 } else if (NULL == mdb.idx) {                          }
                         perror(mdb.idxn);                          mdb.db = dbopen(mdb.dbn, flags, 0644,
                         exit((int)MANDOCLEVEL_SYSERR);                                          DB_BTREE, &info);
                           if (NULL == mdb.db && EEXIST != errno) {
                                   perror(mdb.dbn);
                                   exit((int)MANDOCLEVEL_SYSERR);
                           }
                 }                  }
                   while (NULL == mdb.idx) {
                           strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX);
                           strlcat(mdb.idxn, ".XXXXXXXXXX", PATH_MAX);
                           if (NULL == mktemp(mdb.idxn)) {
                                   perror(mdb.idxn);
                                   unlink(mdb.dbn);
                                   exit((int)MANDOCLEVEL_SYSERR);
                           }
                           mdb.idx = dbopen(mdb.idxn, flags, 0644,
                                           DB_RECNO, NULL);
                           if (NULL == mdb.idx && EEXIST != errno) {
                                   perror(mdb.idxn);
                                   unlink(mdb.dbn);
                                   exit((int)MANDOCLEVEL_SYSERR);
                           }
                   }
   
                 /*                  /*
                  * Search for manuals and fill the new database.                   * Search for manuals and fill the new database.
Line 527  main(int argc, char *argv[])
Line 550  main(int argc, char *argv[])
                 (*mdb.idx->close)(mdb.idx);                  (*mdb.idx->close)(mdb.idx);
                 mdb.db = NULL;                  mdb.db = NULL;
                 mdb.idx = NULL;                  mdb.idx = NULL;
   
                   /*
                    * Replace the old database with the new one.
                    * This is not perfectly atomic,
                    * but i cannot think of a better way.
                    */
   
                   if (-1 == rename(mdb.dbn, MANDOC_DB)) {
                           perror(MANDOC_DB);
                           unlink(mdb.dbn);
                           unlink(mdb.idxn);
                           exit((int)MANDOCLEVEL_SYSERR);
                   }
                   if (-1 == rename(mdb.idxn, MANDOC_IDX)) {
                           perror(MANDOC_IDX);
                           unlink(MANDOC_DB);
                           unlink(MANDOC_IDX);
                           unlink(mdb.idxn);
                           exit((int)MANDOCLEVEL_SYSERR);
                   }
         }          }
   
 out:  out:
Line 1708  ofile_argbuild(int argc, char *argv[], struct of **of,
Line 1751  ofile_argbuild(int argc, char *argv[], struct of **of,
  * Recursively build up a list of files to parse.   * Recursively build up a list of files to parse.
  * We use this instead of ftw() and so on because I don't want global   * We use this instead of ftw() and so on because I don't want global
  * variables hanging around.   * variables hanging around.
  * This ignores the mandocdb.db and mandocdb.index files, but assumes that   * This ignores the mandoc.db and mandoc.index files, but assumes that
  * everything else is a manual.   * everything else is a manual.
  * Pass in a pointer to a NULL structure for the first invocation.   * Pass in a pointer to a NULL structure for the first invocation.
  */   */
Line 1717  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1760  ofile_dirbuild(const char *dir, const char* psec, cons
                 int p_src_form, struct of **of)                  int p_src_form, struct of **of)
 {  {
         char             buf[PATH_MAX];          char             buf[PATH_MAX];
   #if defined(__sun)
           struct stat      sb;
   #endif
         size_t           sz;          size_t           sz;
         DIR             *d;          DIR             *d;
         const char      *fn, *sec, *arch;          const char      *fn, *sec, *arch;
Line 1739  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1785  ofile_dirbuild(const char *dir, const char* psec, cons
   
                 src_form = p_src_form;                  src_form = p_src_form;
   
   #if defined(__sun)
                   stat(dp->d_name, &sb);
                   if (S_IFDIR & sb.st_mode) {
   #else
                 if (DT_DIR == dp->d_type) {                  if (DT_DIR == dp->d_type) {
   #endif
                         sec = psec;                          sec = psec;
                         arch = parch;                          arch = parch;
   
Line 1796  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1847  ofile_dirbuild(const char *dir, const char* psec, cons
                         continue;                          continue;
                 }                  }
   
   #if defined(__sun)
                   if (0 == S_IFREG & sb.st_mode) {
   #else
                 if (DT_REG != dp->d_type) {                  if (DT_REG != dp->d_type) {
   #endif
                         if (warnings)                          if (warnings)
                                 fprintf(stderr,                                  fprintf(stderr,
                                     "%s/%s: not a regular file\n",                                      "%s/%s: not a regular file\n",

Legend:
Removed from v.1.49.2.2  
changed lines
  Added in v.1.49.2.6

CVSweb