version 1.98, 2014/01/05 03:06:43 |
version 1.103, 2014/01/06 03:02:46 |
|
|
struct mlink *next; /* singly linked list */ |
struct mlink *next; /* singly linked list */ |
}; |
}; |
|
|
struct title { |
|
char *title; /* name(sec/arch) given inside the file */ |
|
char *file; /* file name in case of mismatch */ |
|
}; |
|
|
|
enum stmt { |
enum stmt { |
STMT_DELETE_PAGE = 0, /* delete mpage */ |
STMT_DELETE_PAGE = 0, /* delete mpage */ |
STMT_INSERT_PAGE, /* insert mpage */ |
STMT_INSERT_PAGE, /* insert mpage */ |
Line 147 static int mlink_check(struct mpage *, struct mlink * |
|
Line 142 static int mlink_check(struct mpage *, struct mlink * |
|
static void mlink_free(struct mlink *); |
static void mlink_free(struct mlink *); |
static void mlinks_undupe(struct mpage *); |
static void mlinks_undupe(struct mpage *); |
static void mpages_free(void); |
static void mpages_free(void); |
static void mpages_merge(struct mchars *, struct mparse *, int); |
static void mpages_merge(struct mchars *, struct mparse *); |
static void parse_cat(struct mpage *); |
static void parse_cat(struct mpage *); |
static void parse_man(struct mpage *, const struct man_node *); |
static void parse_man(struct mpage *, const struct man_node *); |
static void parse_mdoc(struct mpage *, const struct mdoc_node *); |
static void parse_mdoc(struct mpage *, const struct mdoc_node *); |
Line 172 static int treescan(void); |
|
Line 167 static int treescan(void); |
|
static size_t utf8(unsigned int, char [7]); |
static size_t utf8(unsigned int, char [7]); |
|
|
static char *progname; |
static char *progname; |
static int use_all; /* use all found files */ |
|
static int nodb; /* no database changes */ |
static int nodb; /* no database changes */ |
|
static int quick; /* abort the parse early */ |
|
static int use_all; /* use all found files */ |
static int verb; /* print what we're doing */ |
static int verb; /* print what we're doing */ |
static int warnings; /* warn about crap */ |
static int warnings; /* warn about crap */ |
static int write_utf8; /* write UTF-8 output; else ASCII */ |
static int write_utf8; /* write UTF-8 output; else ASCII */ |
Line 352 main(int argc, char *argv[]) |
|
Line 348 main(int argc, char *argv[]) |
|
path_arg = NULL; |
path_arg = NULL; |
op = OP_DEFAULT; |
op = OP_DEFAULT; |
|
|
while (-1 != (ch = getopt(argc, argv, "aC:d:nT:tu:vW"))) |
while (-1 != (ch = getopt(argc, argv, "aC:d:nQT:tu:vW"))) |
switch (ch) { |
switch (ch) { |
case ('a'): |
case ('a'): |
use_all = 1; |
use_all = 1; |
Line 370 main(int argc, char *argv[]) |
|
Line 366 main(int argc, char *argv[]) |
|
case ('n'): |
case ('n'): |
nodb = 1; |
nodb = 1; |
break; |
break; |
|
case ('Q'): |
|
quick = 1; |
|
break; |
case ('T'): |
case ('T'): |
if (strcmp(optarg, "utf8")) { |
if (strcmp(optarg, "utf8")) { |
fprintf(stderr, "-T%s: Unsupported " |
fprintf(stderr, "-T%s: Unsupported " |
Line 409 main(int argc, char *argv[]) |
|
Line 408 main(int argc, char *argv[]) |
|
|
|
exitcode = (int)MANDOCLEVEL_OK; |
exitcode = (int)MANDOCLEVEL_OK; |
mp = mparse_alloc(MPARSE_AUTO, |
mp = mparse_alloc(MPARSE_AUTO, |
MANDOCLEVEL_FATAL, NULL, NULL, NULL); |
MANDOCLEVEL_FATAL, NULL, NULL, quick); |
mc = mchars_alloc(); |
mc = mchars_alloc(); |
|
|
ohash_init(&mpages, 6, &mpages_info); |
ohash_init(&mpages, 6, &mpages_info); |
Line 435 main(int argc, char *argv[]) |
|
Line 434 main(int argc, char *argv[]) |
|
if (OP_TEST != op) |
if (OP_TEST != op) |
dbprune(); |
dbprune(); |
if (OP_DELETE != op) |
if (OP_DELETE != op) |
mpages_merge(mc, mp, 0); |
mpages_merge(mc, mp); |
dbclose(1); |
dbclose(1); |
} else { |
} else { |
/* |
/* |
Line 479 main(int argc, char *argv[]) |
|
Line 478 main(int argc, char *argv[]) |
|
if (0 == dbopen(0)) |
if (0 == dbopen(0)) |
goto out; |
goto out; |
|
|
mpages_merge(mc, mp, warnings && !use_all); |
mpages_merge(mc, mp); |
dbclose(0); |
dbclose(0); |
|
|
if (j + 1 < dirs.sz) { |
if (j + 1 < dirs.sz) { |
|
|
ohash_delete(&mlinks); |
ohash_delete(&mlinks); |
return(exitcode); |
return(exitcode); |
usage: |
usage: |
fprintf(stderr, "usage: %s [-anvW] [-C file] [-Tutf8]\n" |
fprintf(stderr, "usage: %s [-anQvW] [-C file] [-Tutf8]\n" |
" %s [-anvW] [-Tutf8] dir ...\n" |
" %s [-anQvW] [-Tutf8] dir ...\n" |
" %s [-nvW] [-Tutf8] -d dir [file ...]\n" |
" %s [-nQvW] [-Tutf8] -d dir [file ...]\n" |
" %s [-nvW] -u dir [file ...]\n" |
" %s [-nvW] -u dir [file ...]\n" |
" %s -t file ...\n", |
" %s [-Q] -t file ...\n", |
progname, progname, progname, |
progname, progname, progname, |
progname, progname); |
progname, progname); |
|
|
Line 945 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
Line 944 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
* and filename to determine whether the file is parsable or not. |
* and filename to determine whether the file is parsable or not. |
*/ |
*/ |
static void |
static void |
mpages_merge(struct mchars *mc, struct mparse *mp, int check_reachable) |
mpages_merge(struct mchars *mc, struct mparse *mp) |
{ |
{ |
struct ohash title_table; |
struct ohash_info str_info; |
struct ohash_info title_info, str_info; |
|
struct mpage *mpage; |
struct mpage *mpage; |
struct mlink *mlink; |
struct mlink *mlink; |
struct mdoc *mdoc; |
struct mdoc *mdoc; |
struct man *man; |
struct man *man; |
struct title *title_entry; |
|
char *title_str; |
|
const char *cp; |
const char *cp; |
int match; |
int match; |
unsigned int pslot, tslot; |
unsigned int pslot; |
enum mandoclevel lvl; |
enum mandoclevel lvl; |
|
|
str_info.alloc = hash_alloc; |
str_info.alloc = hash_alloc; |
Line 965 mpages_merge(struct mchars *mc, struct mparse *mp, int |
|
Line 961 mpages_merge(struct mchars *mc, struct mparse *mp, int |
|
str_info.hfree = hash_free; |
str_info.hfree = hash_free; |
str_info.key_offset = offsetof(struct str, key); |
str_info.key_offset = offsetof(struct str, key); |
|
|
if (check_reachable) { |
|
title_info.alloc = hash_alloc; |
|
title_info.halloc = hash_halloc; |
|
title_info.hfree = hash_free; |
|
title_info.key_offset = offsetof(struct title, title); |
|
ohash_init(&title_table, 6, &title_info); |
|
} |
|
|
|
mpage = ohash_first(&mpages, &pslot); |
mpage = ohash_first(&mpages, &pslot); |
while (NULL != mpage) { |
while (NULL != mpage) { |
mlinks_undupe(mpage); |
mlinks_undupe(mpage); |
Line 1059 mpages_merge(struct mchars *mc, struct mparse *mp, int |
|
Line 1047 mpages_merge(struct mchars *mc, struct mparse *mp, int |
|
else |
else |
parse_cat(mpage); |
parse_cat(mpage); |
|
|
/* |
|
* Build a title string for the file. If it matches |
|
* the location of the file, remember the title as |
|
* found; else, remember it as missing. |
|
*/ |
|
|
|
if (check_reachable) { |
|
if (-1 == asprintf(&title_str, "%s(%s%s%s)", |
|
mpage->title, mpage->sec, |
|
'\0' == *mpage->arch ? "" : "/", |
|
mpage->arch)) { |
|
perror(NULL); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
|
tslot = ohash_qlookup(&title_table, title_str); |
|
title_entry = ohash_find(&title_table, tslot); |
|
if (NULL == title_entry) { |
|
title_entry = mandoc_malloc( |
|
sizeof(struct title)); |
|
title_entry->title = title_str; |
|
title_entry->file = mandoc_strdup( |
|
match ? "" : mpage->mlinks->file); |
|
ohash_insert(&title_table, tslot, |
|
title_entry); |
|
} else { |
|
if (match) |
|
*title_entry->file = '\0'; |
|
free(title_str); |
|
} |
|
} |
|
|
|
dbindex(mpage, mc); |
dbindex(mpage, mc); |
ohash_delete(&strings); |
ohash_delete(&strings); |
mpage = ohash_next(&mpages, &pslot); |
mpage = ohash_next(&mpages, &pslot); |
} |
} |
|
|
if (check_reachable) { |
|
title_entry = ohash_first(&title_table, &tslot); |
|
while (NULL != title_entry) { |
|
if ('\0' != *title_entry->file) |
|
say(title_entry->file, |
|
"Probably unreachable, title is %s", |
|
title_entry->title); |
|
free(title_entry->title); |
|
free(title_entry->file); |
|
free(title_entry); |
|
title_entry = ohash_next(&title_table, &tslot); |
|
} |
|
ohash_delete(&title_table); |
|
} |
|
} |
} |
|
|
static void |
static void |
Line 1794 dbindex(const struct mpage *mpage, struct mchars *mc) |
|
Line 1736 dbindex(const struct mpage *mpage, struct mchars *mc) |
|
{ |
{ |
struct mlink *mlink; |
struct mlink *mlink; |
struct str *key; |
struct str *key; |
const char *desc; |
|
int64_t recno; |
int64_t recno; |
size_t i; |
size_t i; |
unsigned int slot; |
unsigned int slot; |
Line 1805 dbindex(const struct mpage *mpage, struct mchars *mc) |
|
Line 1746 dbindex(const struct mpage *mpage, struct mchars *mc) |
|
if (nodb) |
if (nodb) |
return; |
return; |
|
|
desc = ""; |
|
if (NULL != mpage->desc && '\0' != *mpage->desc) { |
|
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"); |
SQL_EXEC("BEGIN TRANSACTION"); |
|
|
i = 1; |
i = 1; |
/* |
|
* XXX The following three lines are obsolete |
|
* and only kept for backward compatibility |
|
* until apropos(1) and friends have caught up. |
|
*/ |
|
SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->mlinks->file); |
|
SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->mlinks->dsec); |
|
SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->mlinks->arch); |
|
SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, desc); |
|
SQL_BIND_INT(stmts[STMT_INSERT_PAGE], i, FORM_SRC == mpage->form); |
SQL_BIND_INT(stmts[STMT_INSERT_PAGE], i, FORM_SRC == mpage->form); |
SQL_STEP(stmts[STMT_INSERT_PAGE]); |
SQL_STEP(stmts[STMT_INSERT_PAGE]); |
recno = sqlite3_last_insert_rowid(db); |
recno = sqlite3_last_insert_rowid(db); |
Line 1962 dbopen(int real) |
|
Line 1884 dbopen(int real) |
|
return(0); |
return(0); |
} |
} |
|
|
/* |
|
* XXX The first three columns in table mpages are obsolete |
|
* and only kept for backward compatibility |
|
* until apropos(1) and friends have caught up. |
|
*/ |
|
sql = "CREATE TABLE \"mpages\" (\n" |
sql = "CREATE TABLE \"mpages\" (\n" |
" \"file\" TEXT NOT NULL,\n" |
|
" \"sec\" TEXT NOT NULL,\n" |
|
" \"arch\" TEXT NOT NULL,\n" |
|
" \"desc\" TEXT NOT NULL,\n" |
|
" \"form\" INTEGER NOT NULL,\n" |
" \"form\" INTEGER NOT NULL,\n" |
" \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n" |
" \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n" |
");\n" |
");\n" |
Line 2007 prepare_statements: |
|
Line 1920 prepare_statements: |
|
sql = "DELETE FROM mpages where file=?"; |
sql = "DELETE FROM mpages where file=?"; |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE_PAGE], NULL); |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE_PAGE], NULL); |
sql = "INSERT INTO mpages " |
sql = "INSERT INTO mpages " |
"(file,sec,arch,desc,form) VALUES (?,?,?,?,?)"; |
"(form) VALUES (?)"; |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_PAGE], NULL); |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_PAGE], NULL); |
sql = "INSERT INTO mlinks " |
sql = "INSERT INTO mlinks " |
"(file,sec,arch,name,pageid) VALUES (?,?,?,?,?)"; |
"(file,sec,arch,name,pageid) VALUES (?,?,?,?,?)"; |