version 1.122, 2014/03/23 12:44:56 |
version 1.133, 2014/04/10 02:46:21 |
|
|
char *fsec; /* section from file name suffix */ |
char *fsec; /* section from file name suffix */ |
struct mlink *next; /* singly linked list */ |
struct mlink *next; /* singly linked list */ |
struct mpage *mpage; /* parent */ |
struct mpage *mpage; /* parent */ |
|
int gzip; /* filename has a .gz suffix */ |
}; |
}; |
|
|
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 */ |
STMT_INSERT_LINK, /* insert mlink */ |
STMT_INSERT_LINK, /* insert mlink */ |
|
STMT_INSERT_NAME, /* insert name */ |
STMT_INSERT_KEY, /* insert parsed key */ |
STMT_INSERT_KEY, /* insert parsed key */ |
STMT__MAX |
STMT__MAX |
}; |
}; |
Line 146 static void *hash_alloc(size_t, void *); |
|
Line 148 static void *hash_alloc(size_t, void *); |
|
static void hash_free(void *, size_t, void *); |
static void hash_free(void *, size_t, void *); |
static void *hash_halloc(size_t, void *); |
static void *hash_halloc(size_t, void *); |
static void mlink_add(struct mlink *, const struct stat *); |
static void mlink_add(struct mlink *, const struct stat *); |
static int mlink_check(struct mpage *, struct mlink *); |
static void 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 *); |
static void mpages_merge(struct mchars *, struct mparse *); |
static void parse_cat(struct mpage *); |
static void names_check(void); |
|
static void parse_cat(struct mpage *, int); |
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 *); |
static int parse_mdoc_body(struct mpage *, const struct mdoc_node *); |
static int parse_mdoc_body(struct mpage *, const struct mdoc_node *); |
Line 178 static char *progname; |
|
Line 181 static char *progname; |
|
static int nodb; /* no database changes */ |
static int nodb; /* no database changes */ |
static int mparse_options; /* abort the parse early */ |
static int mparse_options; /* abort the parse early */ |
static int use_all; /* use all found files */ |
static int use_all; /* use all found files */ |
static int verb; /* print what we're doing */ |
static int debug; /* 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 */ |
static int exitcode; /* to be returned by main */ |
static int exitcode; /* to be returned by main */ |
Line 186 static enum op op; /* operational mode */ |
|
Line 189 static enum op op; /* operational mode */ |
|
static char basedir[PATH_MAX]; /* current base directory */ |
static char basedir[PATH_MAX]; /* current base directory */ |
static struct ohash mpages; /* table of distinct manual pages */ |
static struct ohash mpages; /* table of distinct manual pages */ |
static struct ohash mlinks; /* table of directory entries */ |
static struct ohash mlinks; /* table of directory entries */ |
|
static struct ohash names; /* table of all names */ |
static struct ohash strings; /* table of all strings */ |
static struct ohash strings; /* table of all strings */ |
static sqlite3 *db = NULL; /* current database */ |
static sqlite3 *db = NULL; /* current database */ |
static sqlite3_stmt *stmts[STMT__MAX]; /* current statements */ |
static sqlite3_stmt *stmts[STMT__MAX]; /* current statements */ |
|
static uint64_t name_mask; |
|
|
static const struct mdoc_handler mdocs[MDOC_MAX] = { |
static const struct mdoc_handler mdocs[MDOC_MAX] = { |
{ NULL, 0 }, /* Ap */ |
{ NULL, 0 }, /* Ap */ |
Line 222 static const struct mdoc_handler mdocs[MDOC_MAX] = { |
|
Line 227 static const struct mdoc_handler mdocs[MDOC_MAX] = { |
|
{ NULL, TYPE_Ic }, /* Ic */ |
{ NULL, TYPE_Ic }, /* Ic */ |
{ NULL, TYPE_In }, /* In */ |
{ NULL, TYPE_In }, /* In */ |
{ NULL, TYPE_Li }, /* Li */ |
{ NULL, TYPE_Li }, /* Li */ |
{ parse_mdoc_Nd, TYPE_Nd }, /* Nd */ |
{ parse_mdoc_Nd, 0 }, /* Nd */ |
{ parse_mdoc_Nm, TYPE_Nm }, /* Nm */ |
{ parse_mdoc_Nm, 0 }, /* Nm */ |
{ NULL, 0 }, /* Op */ |
{ NULL, 0 }, /* Op */ |
{ NULL, 0 }, /* Ot */ |
{ NULL, 0 }, /* Ot */ |
{ NULL, TYPE_Pa }, /* Pa */ |
{ NULL, TYPE_Pa }, /* Pa */ |
Line 356 main(int argc, char *argv[]) |
|
Line 361 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:nQT:tu:vW"))) |
while (-1 != (ch = getopt(argc, argv, "aC:Dd:npQT:tu:v"))) |
switch (ch) { |
switch (ch) { |
case ('a'): |
case ('a'): |
use_all = 1; |
use_all = 1; |
Line 366 main(int argc, char *argv[]) |
|
Line 371 main(int argc, char *argv[]) |
|
path_arg = optarg; |
path_arg = optarg; |
op = OP_CONFFILE; |
op = OP_CONFFILE; |
break; |
break; |
|
case ('D'): |
|
debug++; |
|
break; |
case ('d'): |
case ('d'): |
CHECKOP(op, ch); |
CHECKOP(op, ch); |
path_arg = optarg; |
path_arg = optarg; |
Line 374 main(int argc, char *argv[]) |
|
Line 382 main(int argc, char *argv[]) |
|
case ('n'): |
case ('n'): |
nodb = 1; |
nodb = 1; |
break; |
break; |
|
case ('p'): |
|
warnings = 1; |
|
break; |
case ('Q'): |
case ('Q'): |
mparse_options |= MPARSE_QUICK; |
mparse_options |= MPARSE_QUICK; |
break; |
break; |
Line 397 main(int argc, char *argv[]) |
|
Line 408 main(int argc, char *argv[]) |
|
op = OP_DELETE; |
op = OP_DELETE; |
break; |
break; |
case ('v'): |
case ('v'): |
verb++; |
/* Compatibility with espie@'s makewhatis. */ |
break; |
break; |
case ('W'): |
|
warnings = 1; |
|
break; |
|
default: |
default: |
goto usage; |
goto usage; |
} |
} |
Line 458 main(int argc, char *argv[]) |
|
Line 466 main(int argc, char *argv[]) |
|
} else |
} else |
manpath_parse(&dirs, path_arg, NULL, NULL); |
manpath_parse(&dirs, path_arg, NULL, NULL); |
|
|
|
if (0 == dirs.sz) { |
|
exitcode = (int)MANDOCLEVEL_BADARG; |
|
say("", "Empty manpath"); |
|
} |
|
|
/* |
/* |
* First scan the tree rooted at a base directory, then |
* First scan the tree rooted at a base directory, then |
* build a new database and finally move it into place. |
* build a new database and finally move it into place. |
Line 486 main(int argc, char *argv[]) |
|
Line 499 main(int argc, char *argv[]) |
|
goto out; |
goto out; |
|
|
mpages_merge(mc, mp); |
mpages_merge(mc, mp); |
|
if (warnings && |
|
! (MPARSE_QUICK & mparse_options)) |
|
names_check(); |
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 [-anQvW] [-C file] [-Tutf8]\n" |
fprintf(stderr, "usage: %s [-aDnpQ] [-C file] [-Tutf8]\n" |
" %s [-anQvW] [-Tutf8] dir ...\n" |
" %s [-aDnpQ] [-Tutf8] dir ...\n" |
" %s [-nQvW] [-Tutf8] -d dir [file ...]\n" |
" %s [-DnpQ] [-Tutf8] -d dir [file ...]\n" |
" %s [-nvW] -u dir [file ...]\n" |
" %s [-Dnp] -u dir [file ...]\n" |
" %s [-Q] -t file ...\n", |
" %s [-Q] -t file ...\n", |
progname, progname, progname, |
progname, progname, progname, |
progname, progname); |
progname, progname); |
|
|
FTS *f; |
FTS *f; |
FTSENT *ff; |
FTSENT *ff; |
struct mlink *mlink; |
struct mlink *mlink; |
int dform; |
int dform, gzip; |
char *dsec, *arch, *fsec, *cp; |
char *dsec, *arch, *fsec, *cp; |
const char *path; |
const char *path; |
const char *argv[2]; |
const char *argv[2]; |
|
|
f = fts_open((char * const *)argv, FTS_LOGICAL, NULL); |
f = fts_open((char * const *)argv, FTS_LOGICAL, NULL); |
if (NULL == f) { |
if (NULL == f) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("", NULL); |
say("", "&fts_open"); |
return(0); |
return(0); |
} |
} |
|
|
|
|
if (warnings) |
if (warnings) |
say(path, "Extraneous file"); |
say(path, "Extraneous file"); |
continue; |
continue; |
} else if (NULL == (fsec = |
} |
strrchr(ff->fts_name, '.'))) { |
gzip = 0; |
|
fsec = NULL; |
|
while (NULL == fsec) { |
|
fsec = strrchr(ff->fts_name, '.'); |
|
if (NULL == fsec || strcmp(fsec+1, "gz")) |
|
break; |
|
gzip = 1; |
|
*fsec = '\0'; |
|
fsec = NULL; |
|
} |
|
if (NULL == fsec) { |
if ( ! use_all) { |
if ( ! use_all) { |
if (warnings) |
if (warnings) |
say(path, |
say(path, |
|
|
if (warnings) |
if (warnings) |
say(path, "Skip html"); |
say(path, "Skip html"); |
continue; |
continue; |
} else if (0 == strcmp(fsec, "gz")) { |
|
if (warnings) |
|
say(path, "Skip gz"); |
|
continue; |
|
} else if (0 == strcmp(fsec, "ps")) { |
} else if (0 == strcmp(fsec, "ps")) { |
if (warnings) |
if (warnings) |
say(path, "Skip ps"); |
say(path, "Skip ps"); |
|
|
mlink->arch = arch; |
mlink->arch = arch; |
mlink->name = ff->fts_name; |
mlink->name = ff->fts_name; |
mlink->fsec = fsec; |
mlink->fsec = fsec; |
|
mlink->gzip = gzip; |
mlink_add(mlink, ff->fts_statp); |
mlink_add(mlink, ff->fts_statp); |
continue; |
continue; |
} else if (FTS_D != ff->fts_info && |
} else if (FTS_D != ff->fts_info && |
Line 705 filescan(const char *file) |
|
Line 728 filescan(const char *file) |
|
|
|
if (NULL == realpath(file, buf)) { |
if (NULL == realpath(file, buf)) { |
exitcode = (int)MANDOCLEVEL_BADARG; |
exitcode = (int)MANDOCLEVEL_BADARG; |
say(file, NULL); |
say(file, "&realpath"); |
return; |
return; |
} |
} |
|
|
Line 721 filescan(const char *file) |
|
Line 744 filescan(const char *file) |
|
|
|
if (-1 == stat(buf, &st)) { |
if (-1 == stat(buf, &st)) { |
exitcode = (int)MANDOCLEVEL_BADARG; |
exitcode = (int)MANDOCLEVEL_BADARG; |
say(file, NULL); |
say(file, "&stat"); |
return; |
return; |
} else if ( ! (S_IFREG & st.st_mode)) { |
} else if ( ! (S_IFREG & st.st_mode)) { |
exitcode = (int)MANDOCLEVEL_BADARG; |
exitcode = (int)MANDOCLEVEL_BADARG; |
|
|
} |
} |
} |
} |
|
|
static int |
static void |
mlink_check(struct mpage *mpage, struct mlink *mlink) |
mlink_check(struct mpage *mpage, struct mlink *mlink) |
{ |
{ |
int match; |
struct str *str; |
|
unsigned int slot; |
|
|
match = 1; |
|
|
|
/* |
/* |
* Check whether the manual section given in a file |
* Check whether the manual section given in a file |
* agrees with the directory where the file is located. |
* agrees with the directory where the file is located. |
Line 921 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
Line 943 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
*/ |
*/ |
|
|
if (FORM_SRC == mpage->form && |
if (FORM_SRC == mpage->form && |
strcasecmp(mpage->sec, mlink->dsec)) { |
strcasecmp(mpage->sec, mlink->dsec)) |
match = 0; |
|
say(mlink->file, "Section \"%s\" manual in %s directory", |
say(mlink->file, "Section \"%s\" manual in %s directory", |
mpage->sec, mlink->dsec); |
mpage->sec, mlink->dsec); |
} |
|
|
|
/* |
/* |
* Manual page directories exist for each kernel |
* Manual page directories exist for each kernel |
Line 940 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
Line 960 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
* on amd64, i386, sparc, and sparc64. |
* on amd64, i386, sparc, and sparc64. |
*/ |
*/ |
|
|
if (strcasecmp(mpage->arch, mlink->arch)) { |
if (strcasecmp(mpage->arch, mlink->arch)) |
match = 0; |
|
say(mlink->file, "Architecture \"%s\" manual in " |
say(mlink->file, "Architecture \"%s\" manual in " |
"\"%s\" directory", mpage->arch, mlink->arch); |
"\"%s\" directory", mpage->arch, mlink->arch); |
} |
|
|
|
if (strcasecmp(mpage->title, mlink->name)) |
/* |
match = 0; |
* XXX |
|
* parse_cat() doesn't set NAME_TITLE yet. |
|
*/ |
|
|
return(match); |
if (FORM_CAT == mpage->form) |
|
return; |
|
|
|
/* |
|
* Check whether this mlink |
|
* appears as a name in the NAME section. |
|
*/ |
|
|
|
slot = ohash_qlookup(&names, mlink->name); |
|
str = ohash_find(&names, slot); |
|
assert(NULL != str); |
|
if ( ! (NAME_TITLE & str->mask)) |
|
say(mlink->file, "Name missing in NAME section"); |
} |
} |
|
|
/* |
/* |
Line 964 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 996 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
{ |
{ |
char any[] = "any"; |
char any[] = "any"; |
struct ohash_info str_info; |
struct ohash_info str_info; |
|
int fd[2]; |
struct mpage *mpage, *mpage_dest; |
struct mpage *mpage, *mpage_dest; |
struct mlink *mlink, *mlink_dest; |
struct mlink *mlink, *mlink_dest; |
struct mdoc *mdoc; |
struct mdoc *mdoc; |
struct man *man; |
struct man *man; |
char *sodest; |
char *sodest; |
char *cp; |
char *cp; |
int match; |
pid_t child_pid; |
|
int status; |
unsigned int pslot; |
unsigned int pslot; |
enum mandoclevel lvl; |
enum mandoclevel lvl; |
|
|
Line 990 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1024 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
continue; |
continue; |
} |
} |
|
|
|
name_mask = NAME_MASK; |
|
ohash_init(&names, 4, &str_info); |
ohash_init(&strings, 6, &str_info); |
ohash_init(&strings, 6, &str_info); |
mparse_reset(mp); |
mparse_reset(mp); |
mdoc = NULL; |
mdoc = NULL; |
man = NULL; |
man = NULL; |
|
sodest = NULL; |
|
child_pid = 0; |
|
fd[0] = -1; |
|
fd[1] = -1; |
|
|
|
if (mpage->mlinks->gzip) { |
|
if (-1 == pipe(fd)) { |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
|
say(mpage->mlinks->file, "&pipe gunzip"); |
|
goto nextpage; |
|
} |
|
switch (child_pid = fork()) { |
|
case (-1): |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
|
say(mpage->mlinks->file, "&fork gunzip"); |
|
child_pid = 0; |
|
close(fd[1]); |
|
close(fd[0]); |
|
goto nextpage; |
|
case (0): |
|
close(fd[0]); |
|
if (-1 == dup2(fd[1], STDOUT_FILENO)) { |
|
say(mpage->mlinks->file, |
|
"&dup gunzip"); |
|
exit(1); |
|
} |
|
execlp("gunzip", "gunzip", "-c", |
|
mpage->mlinks->file, NULL); |
|
say(mpage->mlinks->file, "&exec gunzip"); |
|
exit(1); |
|
default: |
|
close(fd[1]); |
|
break; |
|
} |
|
} |
|
|
/* |
/* |
* Try interpreting the file as mdoc(7) or man(7) |
* Try interpreting the file as mdoc(7) or man(7) |
* source code, unless it is already known to be |
* source code, unless it is already known to be |
Line 1002 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1073 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
*/ |
*/ |
if (FORM_CAT != mpage->mlinks->dform || |
if (FORM_CAT != mpage->mlinks->dform || |
FORM_CAT != mpage->mlinks->fform) { |
FORM_CAT != mpage->mlinks->fform) { |
lvl = mparse_readfd(mp, -1, mpage->mlinks->file); |
lvl = mparse_readfd(mp, fd[0], mpage->mlinks->file); |
if (lvl < MANDOCLEVEL_FATAL) |
if (lvl < MANDOCLEVEL_FATAL) |
mparse_result(mp, &mdoc, &man, &sodest); |
mparse_result(mp, &mdoc, &man, &sodest); |
} |
} |
Line 1042 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1113 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
mlink_dest->next = mpage->mlinks; |
mlink_dest->next = mpage->mlinks; |
mpage->mlinks = NULL; |
mpage->mlinks = NULL; |
} |
} |
ohash_delete(&strings); |
goto nextpage; |
mpage = ohash_next(&mpages, &pslot); |
|
continue; |
|
} else if (NULL != mdoc) { |
} else if (NULL != mdoc) { |
mpage->form = FORM_SRC; |
mpage->form = FORM_SRC; |
mpage->sec = |
mpage->sec = |
Line 1082 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1151 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
putkey(mpage, mlink->fsec, TYPE_sec); |
putkey(mpage, mlink->fsec, TYPE_sec); |
putkey(mpage, '\0' == *mlink->arch ? |
putkey(mpage, '\0' == *mlink->arch ? |
any : mlink->arch, TYPE_arch); |
any : mlink->arch, TYPE_arch); |
putkey(mpage, mlink->name, TYPE_Nm); |
putkey(mpage, mlink->name, NAME_FILE); |
} |
} |
|
|
if (warnings && !use_all) { |
|
match = 0; |
|
for (mlink = mpage->mlinks; mlink; |
|
mlink = mlink->next) |
|
if (mlink_check(mpage, mlink)) |
|
match = 1; |
|
} else |
|
match = 1; |
|
|
|
if (NULL != mdoc) { |
if (NULL != mdoc) { |
if (NULL != (cp = mdoc_meta(mdoc)->name)) |
if (NULL != (cp = mdoc_meta(mdoc)->name)) |
putkey(mpage, cp, TYPE_Nm); |
putkey(mpage, cp, NAME_HEAD); |
assert(NULL == mpage->desc); |
assert(NULL == mpage->desc); |
parse_mdoc(mpage, mdoc_node(mdoc)); |
parse_mdoc(mpage, mdoc_node(mdoc)); |
putkey(mpage, NULL != mpage->desc ? |
if (NULL == mpage->desc) |
mpage->desc : mpage->mlinks->name, TYPE_Nd); |
mpage->desc = mandoc_strdup( |
|
mpage->mlinks->name); |
} else if (NULL != man) |
} else if (NULL != man) |
parse_man(mpage, man_node(man)); |
parse_man(mpage, man_node(man)); |
else |
else |
parse_cat(mpage); |
parse_cat(mpage, fd[0]); |
|
|
|
if (warnings && !use_all) |
|
for (mlink = mpage->mlinks; mlink; |
|
mlink = mlink->next) |
|
mlink_check(mpage, mlink); |
|
|
dbadd(mpage, mc); |
dbadd(mpage, mc); |
|
|
|
nextpage: |
|
if (child_pid) { |
|
if (-1 == waitpid(child_pid, &status, 0)) { |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
|
say(mpage->mlinks->file, "&wait gunzip"); |
|
} else if (WIFSIGNALED(status)) { |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
|
say(mpage->mlinks->file, |
|
"gunzip died from signal %d", |
|
WTERMSIG(status)); |
|
} else if (WEXITSTATUS(status)) { |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
|
say(mpage->mlinks->file, |
|
"gunzip failed with code %d", |
|
WEXITSTATUS(status)); |
|
} |
|
} |
ohash_delete(&strings); |
ohash_delete(&strings); |
|
ohash_delete(&names); |
mpage = ohash_next(&mpages, &pslot); |
mpage = ohash_next(&mpages, &pslot); |
} |
} |
|
|
Line 1116 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1201 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
} |
} |
|
|
static void |
static void |
parse_cat(struct mpage *mpage) |
names_check(void) |
{ |
{ |
|
sqlite3_stmt *stmt; |
|
const char *name, *sec, *arch, *key; |
|
size_t i; |
|
int irc; |
|
|
|
sqlite3_prepare_v2(db, |
|
"SELECT name, sec, arch, key FROM (" |
|
"SELECT name AS key, pageid FROM names " |
|
"WHERE bits & ? AND NOT EXISTS (" |
|
"SELECT pageid FROM mlinks " |
|
"WHERE mlinks.pageid == names.pageid " |
|
"AND mlinks.name == names.name" |
|
")" |
|
") JOIN (" |
|
"SELECT * FROM mlinks GROUP BY pageid" |
|
") USING (pageid);", |
|
-1, &stmt, NULL); |
|
|
|
i = 1; |
|
SQL_BIND_INT64(stmt, i, NAME_TITLE); |
|
|
|
while (SQLITE_ROW == (irc = sqlite3_step(stmt))) { |
|
name = sqlite3_column_text(stmt, 0); |
|
sec = sqlite3_column_text(stmt, 1); |
|
arch = sqlite3_column_text(stmt, 2); |
|
key = sqlite3_column_text(stmt, 3); |
|
say("", "%s(%s%s%s) lacks mlink \"%s\"", name, sec, |
|
'\0' == *arch ? "" : "/", |
|
'\0' == *arch ? "" : arch, key); |
|
} |
|
sqlite3_finalize(stmt); |
|
} |
|
|
|
static void |
|
parse_cat(struct mpage *mpage, int fd) |
|
{ |
FILE *stream; |
FILE *stream; |
char *line, *p, *title; |
char *line, *p, *title; |
size_t len, plen, titlesz; |
size_t len, plen, titlesz; |
|
|
if (NULL == (stream = fopen(mpage->mlinks->file, "r"))) { |
stream = (-1 == fd) ? |
|
fopen(mpage->mlinks->file, "r") : |
|
fdopen(fd, "r"); |
|
if (NULL == stream) { |
if (warnings) |
if (warnings) |
say(mpage->mlinks->file, NULL); |
say(mpage->mlinks->file, "&fopen"); |
return; |
return; |
} |
} |
|
|
Line 1181 parse_cat(struct mpage *mpage) |
|
Line 1305 parse_cat(struct mpage *mpage) |
|
"Cannot find NAME section"); |
"Cannot find NAME section"); |
assert(NULL == mpage->desc); |
assert(NULL == mpage->desc); |
mpage->desc = mandoc_strdup(mpage->mlinks->name); |
mpage->desc = mandoc_strdup(mpage->mlinks->name); |
putkey(mpage, mpage->mlinks->name, TYPE_Nd); |
|
fclose(stream); |
fclose(stream); |
free(title); |
free(title); |
return; |
return; |
Line 1222 parse_cat(struct mpage *mpage) |
|
Line 1345 parse_cat(struct mpage *mpage) |
|
|
|
assert(NULL == mpage->desc); |
assert(NULL == mpage->desc); |
mpage->desc = mandoc_strdup(p); |
mpage->desc = mandoc_strdup(p); |
putkey(mpage, mpage->desc, TYPE_Nd); |
|
fclose(stream); |
fclose(stream); |
free(title); |
free(title); |
} |
} |
Line 1325 parse_man(struct mpage *mpage, const struct man_node * |
|
Line 1447 parse_man(struct mpage *mpage, const struct man_node * |
|
('\\' == start[0] && '-' == start[1])) |
('\\' == start[0] && '-' == start[1])) |
break; |
break; |
|
|
putkey(mpage, start, TYPE_Nm); |
putkey(mpage, start, NAME_TITLE); |
|
|
if (' ' == byte) { |
if (' ' == byte) { |
start += sz + 1; |
start += sz + 1; |
Line 1339 parse_man(struct mpage *mpage, const struct man_node * |
|
Line 1461 parse_man(struct mpage *mpage, const struct man_node * |
|
} |
} |
|
|
if (start == title) { |
if (start == title) { |
putkey(mpage, start, TYPE_Nm); |
putkey(mpage, start, NAME_TITLE); |
free(title); |
free(title); |
return; |
return; |
} |
} |
Line 1363 parse_man(struct mpage *mpage, const struct man_node * |
|
Line 1485 parse_man(struct mpage *mpage, const struct man_node * |
|
|
|
assert(NULL == mpage->desc); |
assert(NULL == mpage->desc); |
mpage->desc = mandoc_strdup(start); |
mpage->desc = mandoc_strdup(start); |
putkey(mpage, mpage->desc, TYPE_Nd); |
|
free(title); |
free(title); |
return; |
return; |
} |
} |
|
|
parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_node *n) |
{ |
{ |
|
|
return(SEC_NAME == n->sec || |
if (SEC_NAME == n->sec) |
(SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type)); |
putmdockey(mpage, n->child, NAME_TITLE); |
|
else if (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type) |
|
putmdockey(mpage, n->child, NAME_SYN); |
|
return(0); |
} |
} |
|
|
static int |
static int |
|
|
putkeys(const struct mpage *mpage, |
putkeys(const struct mpage *mpage, |
const char *cp, size_t sz, uint64_t v) |
const char *cp, size_t sz, uint64_t v) |
{ |
{ |
|
struct ohash *htab; |
struct str *s; |
struct str *s; |
const char *end; |
const char *end; |
uint64_t mask; |
|
unsigned int slot; |
unsigned int slot; |
int i; |
int i; |
|
|
if (0 == sz) |
if (0 == sz) |
return; |
return; |
|
|
if (verb > 1) { |
if (TYPE_Nm & v) { |
for (i = 0, mask = 1; |
htab = &names; |
i < mansearch_keymax; |
v &= name_mask; |
i++, mask <<= 1) |
name_mask &= ~NAME_FIRST; |
if (mask & v) |
if (debug > 1) |
break; |
say(mpage->mlinks->file, |
say(mpage->mlinks->file, "Adding key %s=%*s", |
"Adding name %*s", sz, cp); |
mansearch_keynames[i], sz, cp); |
} else { |
|
htab = &strings; |
|
if (debug > 1) |
|
for (i = 0; i < mansearch_keymax; i++) |
|
if (1 << i & v) |
|
say(mpage->mlinks->file, |
|
"Adding key %s=%*s", |
|
mansearch_keynames[i], sz, cp); |
} |
} |
|
|
end = cp + sz; |
end = cp + sz; |
slot = ohash_qlookupi(&strings, cp, &end); |
slot = ohash_qlookupi(htab, cp, &end); |
s = ohash_find(&strings, slot); |
s = ohash_find(htab, slot); |
|
|
if (NULL != s && mpage == s->mpage) { |
if (NULL != s && mpage == s->mpage) { |
s->mask |= v; |
s->mask |= v; |
Line 1579 putkeys(const struct mpage *mpage, |
|
Line 1710 putkeys(const struct mpage *mpage, |
|
} else if (NULL == s) { |
} else if (NULL == s) { |
s = mandoc_calloc(sizeof(struct str) + sz + 1, 1); |
s = mandoc_calloc(sizeof(struct str) + sz + 1, 1); |
memcpy(s->key, cp, sz); |
memcpy(s->key, cp, sz); |
ohash_insert(&strings, slot, s); |
ohash_insert(htab, slot, s); |
} |
} |
s->mpage = mpage; |
s->mpage = mpage; |
s->mask = v; |
s->mask = v; |
Line 1786 dbadd(struct mpage *mpage, struct mchars *mc) |
|
Line 1917 dbadd(struct mpage *mpage, struct mchars *mc) |
|
size_t i; |
size_t i; |
unsigned int slot; |
unsigned int slot; |
|
|
if (verb) |
mlink = mpage->mlinks; |
say(mpage->mlinks->file, "Adding to database"); |
|
|
|
if (nodb) |
if (nodb) { |
|
while (NULL != mlink) { |
|
fputs(mlink->name, stdout); |
|
if (NULL == mlink->next || |
|
strcmp(mlink->dsec, mlink->next->dsec) || |
|
strcmp(mlink->fsec, mlink->next->fsec) || |
|
strcmp(mlink->arch, mlink->next->arch)) { |
|
putchar('('); |
|
if ('\0' == *mlink->dsec) |
|
fputs(mlink->fsec, stdout); |
|
else |
|
fputs(mlink->dsec, stdout); |
|
if ('\0' != *mlink->arch) |
|
printf("/%s", mlink->arch); |
|
putchar(')'); |
|
} |
|
mlink = mlink->next; |
|
if (NULL != mlink) |
|
fputs(", ", stdout); |
|
} |
|
printf(" - %s\n", mpage->desc); |
return; |
return; |
|
} |
|
|
|
if (debug) |
|
say(mlink->file, "Adding to database"); |
|
|
i = 1; |
i = 1; |
|
SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, mpage->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]); |
mpage->recno = sqlite3_last_insert_rowid(db); |
mpage->recno = sqlite3_last_insert_rowid(db); |
sqlite3_reset(stmts[STMT_INSERT_PAGE]); |
sqlite3_reset(stmts[STMT_INSERT_PAGE]); |
|
|
for (mlink = mpage->mlinks; mlink; mlink = mlink->next) |
while (NULL != mlink) { |
dbadd_mlink(mlink); |
dbadd_mlink(mlink); |
|
mlink = mlink->next; |
|
} |
|
|
|
for (key = ohash_first(&names, &slot); NULL != key; |
|
key = ohash_next(&names, &slot)) { |
|
assert(key->mpage == mpage); |
|
if (NULL == key->rendered) |
|
render_key(mc, key); |
|
i = 1; |
|
SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, key->mask); |
|
SQL_BIND_TEXT(stmts[STMT_INSERT_NAME], i, key->rendered); |
|
SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, mpage->recno); |
|
SQL_STEP(stmts[STMT_INSERT_NAME]); |
|
sqlite3_reset(stmts[STMT_INSERT_NAME]); |
|
if (key->rendered != key->key) |
|
free(key->rendered); |
|
free(key); |
|
} |
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); |
|
|
for (mpage = ohash_first(&mpages, &slot); NULL != mpage; |
for (mpage = ohash_first(&mpages, &slot); NULL != mpage; |
mpage = ohash_next(&mpages, &slot)) { |
mpage = ohash_next(&mpages, &slot)) { |
mlink = mpage->mlinks; |
mlink = mpage->mlinks; |
if (verb) |
if (debug) |
say(mlink->file, "Deleting from database"); |
say(mlink->file, "Deleting from database"); |
if (nodb) |
if (nodb) |
continue; |
continue; |
Line 1881 dbclose(int real) |
|
Line 2053 dbclose(int real) |
|
if ('\0' == *tempfilename) { |
if ('\0' == *tempfilename) { |
if (-1 == rename(MANDOC_DB "~", MANDOC_DB)) { |
if (-1 == rename(MANDOC_DB "~", MANDOC_DB)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(MANDOC_DB, "%s", strerror(errno)); |
say(MANDOC_DB, "&rename"); |
} |
} |
return; |
return; |
} |
} |
Line 1889 dbclose(int real) |
|
Line 2061 dbclose(int real) |
|
switch (child = fork()) { |
switch (child = fork()) { |
case (-1): |
case (-1): |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("fork cmp", "%s", strerror(errno)); |
say("", "&fork cmp"); |
return; |
return; |
case (0): |
case (0): |
execlp("cmp", "cmp", "-s", |
execlp("cmp", "cmp", "-s", |
tempfilename, MANDOC_DB, NULL); |
tempfilename, MANDOC_DB, NULL); |
say("exec cmp", "%s", strerror(errno)); |
say("", "&exec cmp"); |
exit(0); |
exit(0); |
default: |
default: |
break; |
break; |
} |
} |
if (-1 == waitpid(child, &status, 0)) { |
if (-1 == waitpid(child, &status, 0)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("wait cmp", "%s", strerror(errno)); |
say("", "&wait cmp"); |
} else if (WIFSIGNALED(status)) { |
} else if (WIFSIGNALED(status)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("cmp", "Died from a signal"); |
say("", "cmp died from signal %d", WTERMSIG(status)); |
} else if (WEXITSTATUS(status)) { |
} else if (WEXITSTATUS(status)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(MANDOC_DB, |
say(MANDOC_DB, |
Line 1915 dbclose(int real) |
|
Line 2087 dbclose(int real) |
|
switch (child = fork()) { |
switch (child = fork()) { |
case (-1): |
case (-1): |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("fork rm", "%s", strerror(errno)); |
say("", "&fork rm"); |
return; |
return; |
case (0): |
case (0): |
execlp("rm", "rm", "-rf", tempfilename, NULL); |
execlp("rm", "rm", "-rf", tempfilename, NULL); |
say("exec rm", "%s", strerror(errno)); |
say("", "&exec rm"); |
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
default: |
default: |
break; |
break; |
} |
} |
if (-1 == waitpid(child, &status, 0)) { |
if (-1 == waitpid(child, &status, 0)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("wait rm", "%s", strerror(errno)); |
say("", "&wait rm"); |
} else if (WIFSIGNALED(status) || WEXITSTATUS(status)) { |
} else if (WIFSIGNALED(status) || WEXITSTATUS(status)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(tempfilename, |
say("", "%s: Cannot remove temporary directory", |
"Cannot remove temporary directory"); |
tempfilename); |
} |
} |
} |
} |
|
|
Line 1979 dbopen(int real) |
|
Line 2151 dbopen(int real) |
|
if (strlcpy(tempfilename, "/tmp/mandocdb.XXXXXX", |
if (strlcpy(tempfilename, "/tmp/mandocdb.XXXXXX", |
sizeof(tempfilename)) >= sizeof(tempfilename)) { |
sizeof(tempfilename)) >= sizeof(tempfilename)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say("/tmp/mandocdb.XXXXXX", "Filename too long"); |
say("", "/tmp/mandocdb.XXXXXX: Filename too long"); |
return(0); |
return(0); |
} |
} |
if (NULL == mkdtemp(tempfilename)) { |
if (NULL == mkdtemp(tempfilename)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(tempfilename, "%s", strerror(errno)); |
say("", "&%s", tempfilename); |
return(0); |
return(0); |
} |
} |
if (strlcat(tempfilename, "/" MANDOC_DB, |
if (strlcat(tempfilename, "/" MANDOC_DB, |
sizeof(tempfilename)) >= sizeof(tempfilename)) { |
sizeof(tempfilename)) >= sizeof(tempfilename)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(tempfilename, "Filename too long"); |
say("", "%s/" MANDOC_DB ": Filename too long", |
|
tempfilename); |
return(0); |
return(0); |
} |
} |
rc = sqlite3_open_v2(tempfilename, &db, ofl, NULL); |
rc = sqlite3_open_v2(tempfilename, &db, ofl, NULL); |
if (SQLITE_OK != rc) { |
if (SQLITE_OK != rc) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(tempfilename, "%s", sqlite3_errmsg(db)); |
say("", "%s: %s", tempfilename, sqlite3_errmsg(db)); |
return(0); |
return(0); |
} |
} |
|
|
create_tables: |
create_tables: |
sql = "CREATE TABLE \"mpages\" (\n" |
sql = "CREATE TABLE \"mpages\" (\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" |
|
|
"ON DELETE CASCADE\n" |
"ON DELETE CASCADE\n" |
");\n" |
");\n" |
"\n" |
"\n" |
|
"CREATE TABLE \"names\" (\n" |
|
" \"bits\" INTEGER NOT NULL,\n" |
|
" \"name\" TEXT NOT NULL,\n" |
|
" \"pageid\" INTEGER NOT NULL REFERENCES mpages(id) " |
|
"ON DELETE CASCADE\n" |
|
");\n" |
|
"\n" |
"CREATE TABLE \"keys\" (\n" |
"CREATE TABLE \"keys\" (\n" |
" \"bits\" INTEGER NOT NULL,\n" |
" \"bits\" INTEGER NOT NULL,\n" |
" \"key\" TEXT NOT NULL,\n" |
" \"key\" TEXT NOT NULL,\n" |
Line 2034 prepare_statements: |
|
Line 2215 prepare_statements: |
|
"sec=? AND arch=? AND name=?)"; |
"sec=? AND arch=? AND name=?)"; |
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 " |
"(form) VALUES (?)"; |
"(desc,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 " |
"(sec,arch,name,pageid) VALUES (?,?,?,?)"; |
"(sec,arch,name,pageid) VALUES (?,?,?,?)"; |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_LINK], NULL); |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_LINK], NULL); |
|
sql = "INSERT INTO names " |
|
"(bits,name,pageid) VALUES (?,?,?)"; |
|
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_NAME], NULL); |
sql = "INSERT INTO keys " |
sql = "INSERT INTO keys " |
"(bits,key,pageid) VALUES (?,?,?)"; |
"(bits,key,pageid) VALUES (?,?,?)"; |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_KEY], NULL); |
sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_KEY], NULL); |
Line 2093 set_basedir(const char *targetdir) |
|
Line 2277 set_basedir(const char *targetdir) |
|
if (NULL == getcwd(startdir, PATH_MAX)) { |
if (NULL == getcwd(startdir, PATH_MAX)) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
if (NULL != targetdir) |
if (NULL != targetdir) |
say(".", NULL); |
say("", "&getcwd"); |
return(0); |
return(0); |
} |
} |
if (-1 == (fd = open(startdir, O_RDONLY, 0))) { |
if (-1 == (fd = open(startdir, O_RDONLY, 0))) { |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(startdir, NULL); |
say("", "&open %s", startdir); |
return(0); |
return(0); |
} |
} |
if (NULL == targetdir) |
if (NULL == targetdir) |
Line 2110 set_basedir(const char *targetdir) |
|
Line 2294 set_basedir(const char *targetdir) |
|
close(fd); |
close(fd); |
basedir[0] = '\0'; |
basedir[0] = '\0'; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(startdir, NULL); |
say("", "&chdir %s", startdir); |
return(0); |
return(0); |
} |
} |
if (NULL == targetdir) { |
if (NULL == targetdir) { |
Line 2121 set_basedir(const char *targetdir) |
|
Line 2305 set_basedir(const char *targetdir) |
|
if (NULL == realpath(targetdir, basedir)) { |
if (NULL == realpath(targetdir, basedir)) { |
basedir[0] = '\0'; |
basedir[0] = '\0'; |
exitcode = (int)MANDOCLEVEL_BADARG; |
exitcode = (int)MANDOCLEVEL_BADARG; |
say(targetdir, NULL); |
say("", "&%s: realpath", targetdir); |
return(0); |
return(0); |
} else if (-1 == chdir(basedir)) { |
} else if (-1 == chdir(basedir)) { |
exitcode = (int)MANDOCLEVEL_BADARG; |
exitcode = (int)MANDOCLEVEL_BADARG; |
say("", NULL); |
say("", "&chdir"); |
return(0); |
return(0); |
} |
} |
return(1); |
return(1); |
|
|
say(const char *file, const char *format, ...) |
say(const char *file, const char *format, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
|
int use_errno; |
|
|
if ('\0' != *basedir) |
if ('\0' != *basedir) |
fprintf(stderr, "%s", basedir); |
fprintf(stderr, "%s", basedir); |
Line 2142 say(const char *file, const char *format, ...) |
|
Line 2327 say(const char *file, const char *format, ...) |
|
fputs("//", stderr); |
fputs("//", stderr); |
if ('\0' != *file) |
if ('\0' != *file) |
fprintf(stderr, "%s", file); |
fprintf(stderr, "%s", file); |
fputs(": ", stderr); |
|
|
|
if (NULL == format) { |
use_errno = 1; |
perror(NULL); |
if (NULL != format) { |
return; |
switch (*format) { |
|
case ('&'): |
|
format++; |
|
break; |
|
case ('\0'): |
|
format = NULL; |
|
break; |
|
default: |
|
use_errno = 0; |
|
break; |
|
} |
} |
} |
|
if (NULL != format) { |
va_start(ap, format); |
if ('\0' != *basedir || '\0' != *file) |
vfprintf(stderr, format, ap); |
fputs(": ", stderr); |
va_end(ap); |
va_start(ap, format); |
|
vfprintf(stderr, format, ap); |
fputc('\n', stderr); |
va_end(ap); |
|
} |
|
if (use_errno) { |
|
if ('\0' != *basedir || '\0' != *file || NULL != format) |
|
fputs(": ", stderr); |
|
perror(NULL); |
|
} else |
|
fputc('\n', stderr); |
} |
} |