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

Diff for /mandoc/mandocdb.c between version 1.95 and 1.96

version 1.95, 2014/01/02 22:19:41 version 1.96, 2014/01/02 22:44:10
Line 82  enum form {
Line 82  enum form {
 };  };
   
 struct  str {  struct  str {
         char            *utf8; /* key in UTF-8 form */          char            *rendered; /* key in UTF-8 or ASCII form */
         const struct mpage *mpage; /* if set, the owning parse */          const struct mpage *mpage; /* if set, the owning parse */
         uint64_t         mask; /* bitmask in sequence */          uint64_t         mask; /* bitmask in sequence */
         char             key[]; /* the string itself */          char             key[]; /* may contain escape sequences */
 };  };
   
 struct  inodev {  struct  inodev {
Line 165  static void  putkeys(const struct mpage *,
Line 165  static void  putkeys(const struct mpage *,
                         const char *, size_t, uint64_t);                          const char *, size_t, uint64_t);
 static  void     putmdockey(const struct mpage *,  static  void     putmdockey(const struct mpage *,
                         const struct mdoc_node *, uint64_t);                          const struct mdoc_node *, uint64_t);
   static  void     render_key(struct mchars *, struct str *);
 static  void     say(const char *, const char *, ...);  static  void     say(const char *, const char *, ...);
 static  int      set_basedir(const char *);  static  int      set_basedir(const char *);
 static  int      treescan(void);  static  int      treescan(void);
 static  size_t   utf8(unsigned int, char [7]);  static  size_t   utf8(unsigned int, char [7]);
 static  void     utf8key(struct mchars *, struct str *);  
   
 static  char            *progname;  static  char            *progname;
 static  int              use_all; /* use all found files */  static  int              use_all; /* use all found files */
Line 1662  utf8(unsigned int cp, char out[7])
Line 1662  utf8(unsigned int cp, char out[7])
 }  }
   
 /*  /*
  * Store the UTF-8 version of a key, or alias the pointer if the key has   * Store the rendered version of a key, or alias the pointer
  * no UTF-8 transcription marks in it.   * if the key contains no escape sequences.
  */   */
 static void  static void
 utf8key(struct mchars *mc, struct str *key)  render_key(struct mchars *mc, struct str *key)
 {  {
         size_t           sz, bsz, pos;          size_t           sz, bsz, pos;
         char             utfbuf[7], res[5];          char             utfbuf[7], res[5];
Line 1675  utf8key(struct mchars *mc, struct str *key)
Line 1675  utf8key(struct mchars *mc, struct str *key)
         int              len, u;          int              len, u;
         enum mandoc_esc  esc;          enum mandoc_esc  esc;
   
         assert(NULL == key->utf8);          assert(NULL == key->rendered);
   
         res[0] = '\\';          res[0] = '\\';
         res[1] = '\t';          res[1] = '\t';
Line 1691  utf8key(struct mchars *mc, struct str *key)
Line 1691  utf8key(struct mchars *mc, struct str *key)
          * pointer as ourselvse and get out of here.           * pointer as ourselvse and get out of here.
          */           */
         if (strcspn(val, res) == bsz) {          if (strcspn(val, res) == bsz) {
                 key->utf8 = key->key;                  key->rendered = key->key;
                 return;                  return;
         }          }
   
Line 1770  utf8key(struct mchars *mc, struct str *key)
Line 1770  utf8key(struct mchars *mc, struct str *key)
         }          }
   
         buf[pos] = '\0';          buf[pos] = '\0';
         key->utf8 = buf;          key->rendered = buf;
 }  }
   
 /*  /*
  * Flush the current page's terms (and their bits) into the database.   * Flush the current page's terms (and their bits) into the database.
  * Wrap the entire set of additions in a transaction to make sqlite be a   * Wrap the entire set of additions in a transaction to make sqlite be a
  * little faster.   * little faster.
  * Also, UTF-8-encode the description at the last possible moment.   * Also, handle escape sequences at the last possible moment.
  */   */
 static void  static void
 dbindex(const struct mpage *mpage, struct mchars *mc)  dbindex(const struct mpage *mpage, struct mchars *mc)
Line 1800  dbindex(const struct mpage *mpage, struct mchars *mc)
Line 1800  dbindex(const struct mpage *mpage, struct mchars *mc)
                 key = ohash_find(&strings,                  key = ohash_find(&strings,
                         ohash_qlookup(&strings, mpage->desc));                          ohash_qlookup(&strings, mpage->desc));
                 assert(NULL != key);                  assert(NULL != key);
                 if (NULL == key->utf8)                  if (NULL == key->rendered)
                         utf8key(mc, key);                          render_key(mc, key);
                 desc = key->utf8;                  desc = key->rendered;
         }          }
   
         SQL_EXEC("BEGIN TRANSACTION");          SQL_EXEC("BEGIN TRANSACTION");
Line 1836  dbindex(const struct mpage *mpage, struct mchars *mc)
Line 1836  dbindex(const struct mpage *mpage, struct mchars *mc)
         for (key = ohash_first(&strings, &slot); NULL != key;          for (key = ohash_first(&strings, &slot); NULL != key;
              key = ohash_next(&strings, &slot)) {               key = ohash_next(&strings, &slot)) {
                 assert(key->mpage == mpage);                  assert(key->mpage == mpage);
                 if (NULL == key->utf8)                  if (NULL == key->rendered)
                         utf8key(mc, key);                          render_key(mc, key);
                 i = 1;                  i = 1;
                 SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask);                  SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask);
                 SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->utf8);                  SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->rendered);
                 SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, recno);                  SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, recno);
                 SQL_STEP(stmts[STMT_INSERT_KEY]);                  SQL_STEP(stmts[STMT_INSERT_KEY]);
                 sqlite3_reset(stmts[STMT_INSERT_KEY]);                  sqlite3_reset(stmts[STMT_INSERT_KEY]);
                 if (key->utf8 != key->key)                  if (key->rendered != key->key)
                         free(key->utf8);                          free(key->rendered);
                 free(key);                  free(key);
         }          }
   

Legend:
Removed from v.1.95  
changed lines
  Added in v.1.96

CVSweb