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

Diff for /mandoc/mandocdb.c between version 1.50 and 1.53

version 1.50, 2012/06/08 10:43:01 version 1.53, 2012/06/09 11:00:13
Line 34 
Line 34 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
   #ifdef HAVE_OHASH
 #include <ohash.h>  #include <ohash.h>
   #else
   #include "compat_ohash.h"
   #endif
 #include <sqlite3.h>  #include <sqlite3.h>
   
 #include "mdoc.h"  #include "mdoc.h"
Line 60 
Line 64 
                 fprintf(stderr, ": %s\n", (_f)); \                  fprintf(stderr, ": %s\n", (_f)); \
         } while (/* CONSTCOND */ 0)          } while (/* CONSTCOND */ 0)
   
   #define SQL_EXEC(_v) \
           if (SQLITE_OK != sqlite3_exec(db, (_v), NULL, NULL, NULL)) \
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db))
   #define SQL_BIND_TEXT(_s, _i, _v) \
           if (SQLITE_OK != sqlite3_bind_text \
                   ((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db))
   #define SQL_BIND_INT(_s, _i, _v) \
           if (SQLITE_OK != sqlite3_bind_int \
                   ((_s), (_i)++, (_v))) \
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db))
   #define SQL_BIND_INT64(_s, _i, _v) \
           if (SQLITE_OK != sqlite3_bind_int64 \
                   ((_s), (_i)++, (_v))) \
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db))
   #define SQL_STEP(_s) \
           if (SQLITE_DONE != sqlite3_step((_s))) \
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db))
   
 enum    op {  enum    op {
         OP_DEFAULT = 0, /* new dbs from dir list or default config */          OP_DEFAULT = 0, /* new dbs from dir list or default config */
         OP_CONFFILE, /* new databases from custom config file */          OP_CONFFILE, /* new databases from custom config file */
Line 79  struct str {
Line 102  struct str {
         const struct of *of; /* if set, the owning parse */          const struct of *of; /* if set, the owning parse */
         struct str      *next; /* next in owning parse sequence */          struct str      *next; /* next in owning parse sequence */
         uint64_t         mask; /* bitmask in sequence */          uint64_t         mask; /* bitmask in sequence */
         char             key[1]; /* the string itself */          char             key[]; /* the string itself */
 };  };
   
 struct  id {  struct  id {
Line 308  main(int argc, char *argv[])
Line 331  main(int argc, char *argv[])
 {  {
         char              cwd[MAXPATHLEN];          char              cwd[MAXPATHLEN];
         int               ch, rc, fd, i;          int               ch, rc, fd, i;
           unsigned int      index;
         size_t            j, sz;          size_t            j, sz;
         const char       *dir;          const char       *dir;
         struct str       *s;          struct str       *s;
Line 479  main(int argc, char *argv[])
Line 503  main(int argc, char *argv[])
                                 goto out;                                  goto out;
                         if (0 == dbopen(dirs.paths[j], 0))                          if (0 == dbopen(dirs.paths[j], 0))
                                 goto out;                                  goto out;
   
                           /*
                            * Since we're opening up a new database, we can
                            * turn off synchronous mode for much better
                            * performance.
                            */
                           SQL_EXEC("PRAGMA synchronous = OFF");
   
                         if (0 == ofmerge(mc, mp, dirs.paths[j]))                          if (0 == ofmerge(mc, mp, dirs.paths[j]))
                                 goto out;                                  goto out;
                         dbclose(dirs.paths[j], 0);                          dbclose(dirs.paths[j], 0);
Line 494  out:
Line 526  out:
         manpath_free(&dirs);          manpath_free(&dirs);
         mchars_free(mc);          mchars_free(mc);
         mparse_free(mp);          mparse_free(mp);
         for (s = ohash_first(&strings, &ch);          for (s = ohash_first(&strings, &index);
                         NULL != s; s = ohash_next(&strings, &ch)) {                          NULL != s; s = ohash_next(&strings, &index)) {
                 if (s->utf8 != s->key)                  if (s->utf8 != s->key)
                         free(s->utf8);                          free(s->utf8);
                 free(s);                  free(s);
Line 1538  straddbuf(const char *cp, size_t sz)
Line 1570  straddbuf(const char *cp, size_t sz)
         if (NULL != (s = hashget(cp, sz)))          if (NULL != (s = hashget(cp, sz)))
                 return(s->key);                  return(s->key);
   
         s = mandoc_calloc(sizeof(struct str) + sz, 1);          s = mandoc_calloc(sizeof(struct str) + sz + 1, 1);
         memcpy(s->key, cp, sz);          memcpy(s->key, cp, sz);
   
         end = cp + sz;          end = cp + sz;
Line 1585  wordaddbuf(const struct of *of, 
Line 1617  wordaddbuf(const struct of *of, 
                 s->mask |= v;                  s->mask |= v;
                 return;                  return;
         } else if (NULL == s) {          } else if (NULL == s) {
                 s = mandoc_calloc(sizeof(struct str) + sz, 1);                  s = mandoc_calloc(sizeof(struct str) + sz + 1, 1);
                 memcpy(s->key, cp, sz);                  memcpy(s->key, cp, sz);
                 end = cp + sz;                  end = cp + sz;
                 index = ohash_qlookupi(&strings, cp, &end);                  index = ohash_qlookupi(&strings, cp, &end);
Line 1768  dbindex(struct mchars *mc, int form, 
Line 1800  dbindex(struct mchars *mc, int form, 
         struct str      *key;          struct str      *key;
         const char      *desc;          const char      *desc;
         int64_t          recno;          int64_t          recno;
           size_t           i;
   
         DEBUG(of->file, base, "Adding to index");          DEBUG(of->file, base, "Adding to index");
   
Line 1783  dbindex(struct mchars *mc, int form, 
Line 1816  dbindex(struct mchars *mc, int form, 
                 desc = key->utf8;                  desc = key->utf8;
         }          }
   
         sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL);          SQL_EXEC("BEGIN TRANSACTION");
   
         sqlite3_bind_text          i = 1;
                 (stmts[STMT_INSERT_DOC], 1,          SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, of->file);
                  of->file, -1, SQLITE_STATIC);          SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, of->sec);
         sqlite3_bind_text          SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, of->arch);
                 (stmts[STMT_INSERT_DOC], 2,          SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, desc);
                  of->sec, -1, SQLITE_STATIC);          SQL_BIND_INT(stmts[STMT_INSERT_DOC], i, form);
         sqlite3_bind_text          SQL_STEP(stmts[STMT_INSERT_DOC]);
                 (stmts[STMT_INSERT_DOC], 3,  
                  of->arch, -1, SQLITE_STATIC);  
         sqlite3_bind_text  
                 (stmts[STMT_INSERT_DOC], 4,  
                  desc, -1, SQLITE_STATIC);  
         sqlite3_bind_int  
                 (stmts[STMT_INSERT_DOC], 5, form);  
         sqlite3_step(stmts[STMT_INSERT_DOC]);  
         recno = sqlite3_last_insert_rowid(db);          recno = sqlite3_last_insert_rowid(db);
         sqlite3_reset(stmts[STMT_INSERT_DOC]);          sqlite3_reset(stmts[STMT_INSERT_DOC]);
   
Line 1807  dbindex(struct mchars *mc, int form, 
Line 1832  dbindex(struct mchars *mc, int form, 
                 assert(key->of == of);                  assert(key->of == of);
                 if (NULL == key->utf8)                  if (NULL == key->utf8)
                         utf8key(mc, key);                          utf8key(mc, key);
                 sqlite3_bind_int64                  i = 1;
                         (stmts[STMT_INSERT_KEY], 1, key->mask);                  SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask);
                 sqlite3_bind_text                  SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->utf8);
                         (stmts[STMT_INSERT_KEY], 2,                  SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, recno);
                          key->utf8, -1, SQLITE_STATIC);                  SQL_STEP(stmts[STMT_INSERT_KEY]);
                 sqlite3_bind_int64  
                         (stmts[STMT_INSERT_KEY], 3, recno);  
                 sqlite3_step(stmts[STMT_INSERT_KEY]);  
                 sqlite3_reset(stmts[STMT_INSERT_KEY]);                  sqlite3_reset(stmts[STMT_INSERT_KEY]);
         }          }
   
         sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL);          SQL_EXEC("END TRANSACTION");
   
 }  }
   
 static void  static void
 dbprune(const char *base)  dbprune(const char *base)
 {  {
         struct of       *of;          struct of       *of;
           size_t           i;
   
         if (nodb)          if (nodb)
                 return;                  return;
   
         for (of = ofs; NULL != of; of = of->next) {          for (of = ofs; NULL != of; of = of->next) {
                 sqlite3_bind_text                  i = 1;
                         (stmts[STMT_DELETE], 1,                  SQL_BIND_TEXT(stmts[STMT_DELETE], i, of->file);
                          of->file, -1, SQLITE_STATIC);                  SQL_STEP(stmts[STMT_DELETE]);
                 sqlite3_step(stmts[STMT_DELETE]);  
                 sqlite3_reset(stmts[STMT_DELETE]);                  sqlite3_reset(stmts[STMT_DELETE]);
                 DEBUG(of->file, base, "Deleted from index");                  DEBUG(of->file, base, "Deleted from index");
         }          }
Line 1901  dbopen(const char *base, int real)
Line 1922  dbopen(const char *base, int real)
         if ( ! real)          if ( ! real)
                 remove(file);                  remove(file);
   
         ofl = SQLITE_OPEN_PRIVATECACHE | SQLITE_OPEN_READWRITE |          ofl = SQLITE_OPEN_READWRITE |
                 (0 == real ? SQLITE_OPEN_EXCLUSIVE : 0);                  (0 == real ? SQLITE_OPEN_EXCLUSIVE : 0);
   
         rc = sqlite3_open_v2(file, &db, ofl, NULL);          rc = sqlite3_open_v2(file, &db, ofl, NULL);

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.53

CVSweb