=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mandocdb.c,v retrieving revision 1.52 retrieving revision 1.53 diff -c -r1.52 -r1.53 *** src/usr.bin/mandoc/mandocdb.c 2014/01/02 22:19:38 1.52 --- src/usr.bin/mandoc/mandocdb.c 2014/01/02 22:44:07 1.53 *************** *** 1,4 **** ! /* $Id: mandocdb.c,v 1.52 2014/01/02 22:19:38 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze --- 1,4 ---- ! /* $Id: mandocdb.c,v 1.53 2014/01/02 22:44:07 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze *************** *** 74,83 **** }; struct str { ! char *utf8; /* key in UTF-8 form */ const struct mpage *mpage; /* if set, the owning parse */ uint64_t mask; /* bitmask in sequence */ ! char key[]; /* the string itself */ }; struct inodev { --- 74,83 ---- }; struct str { ! char *rendered; /* key in UTF-8 or ASCII form */ const struct mpage *mpage; /* if set, the owning parse */ uint64_t mask; /* bitmask in sequence */ ! char key[]; /* may contain escape sequences */ }; struct inodev { *************** *** 157,167 **** const char *, size_t, uint64_t); static void putmdockey(const struct mpage *, const struct mdoc_node *, uint64_t); static void say(const char *, const char *, ...); static int set_basedir(const char *); static int treescan(void); static size_t utf8(unsigned int, char [7]); - static void utf8key(struct mchars *, struct str *); static char *progname; static int use_all; /* use all found files */ --- 157,167 ---- const char *, size_t, uint64_t); static void putmdockey(const struct mpage *, const struct mdoc_node *, uint64_t); + static void render_key(struct mchars *, struct str *); static void say(const char *, const char *, ...); static int set_basedir(const char *); static int treescan(void); static size_t utf8(unsigned int, char [7]); static char *progname; static int use_all; /* use all found files */ *************** *** 1654,1664 **** } /* ! * Store the UTF-8 version of a key, or alias the pointer if the key has ! * no UTF-8 transcription marks in it. */ static void ! utf8key(struct mchars *mc, struct str *key) { size_t sz, bsz, pos; char utfbuf[7], res[5]; --- 1654,1664 ---- } /* ! * Store the rendered version of a key, or alias the pointer ! * if the key contains no escape sequences. */ static void ! render_key(struct mchars *mc, struct str *key) { size_t sz, bsz, pos; char utfbuf[7], res[5]; *************** *** 1667,1673 **** int len, u; enum mandoc_esc esc; ! assert(NULL == key->utf8); res[0] = '\\'; res[1] = '\t'; --- 1667,1673 ---- int len, u; enum mandoc_esc esc; ! assert(NULL == key->rendered); res[0] = '\\'; res[1] = '\t'; *************** *** 1683,1689 **** * pointer as ourselvse and get out of here. */ if (strcspn(val, res) == bsz) { ! key->utf8 = key->key; return; } --- 1683,1689 ---- * pointer as ourselvse and get out of here. */ if (strcspn(val, res) == bsz) { ! key->rendered = key->key; return; } *************** *** 1762,1775 **** } buf[pos] = '\0'; ! key->utf8 = buf; } /* * 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 * little faster. ! * Also, UTF-8-encode the description at the last possible moment. */ static void dbindex(const struct mpage *mpage, struct mchars *mc) --- 1762,1775 ---- } buf[pos] = '\0'; ! key->rendered = buf; } /* * 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 * little faster. ! * Also, handle escape sequences at the last possible moment. */ static void dbindex(const struct mpage *mpage, struct mchars *mc) *************** *** 1792,1800 **** key = ohash_find(&strings, ohash_qlookup(&strings, mpage->desc)); assert(NULL != key); ! if (NULL == key->utf8) ! utf8key(mc, key); ! desc = key->utf8; } SQL_EXEC("BEGIN TRANSACTION"); --- 1792,1800 ---- key = ohash_find(&strings, ohash_qlookup(&strings, mpage->desc)); assert(NULL != key); ! if (NULL == key->rendered) ! render_key(mc, key); ! desc = key->rendered; } SQL_EXEC("BEGIN TRANSACTION"); *************** *** 1828,1843 **** for (key = ohash_first(&strings, &slot); NULL != key; key = ohash_next(&strings, &slot)) { assert(key->mpage == mpage); ! if (NULL == key->utf8) ! utf8key(mc, key); i = 1; SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask); ! SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->utf8); SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, recno); SQL_STEP(stmts[STMT_INSERT_KEY]); sqlite3_reset(stmts[STMT_INSERT_KEY]); ! if (key->utf8 != key->key) ! free(key->utf8); free(key); } --- 1828,1843 ---- for (key = ohash_first(&strings, &slot); NULL != key; key = ohash_next(&strings, &slot)) { assert(key->mpage == mpage); ! if (NULL == key->rendered) ! render_key(mc, key); i = 1; SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask); ! SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->rendered); SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, recno); SQL_STEP(stmts[STMT_INSERT_KEY]); sqlite3_reset(stmts[STMT_INSERT_KEY]); ! if (key->rendered != key->key) ! free(key->rendered); free(key); }