version 1.169, 2014/11/19 20:40:51 |
version 1.174, 2014/12/04 20:13:25 |
|
|
char *desc; /* description from file content */ |
char *desc; /* description from file content */ |
struct mlink *mlinks; /* singly linked list */ |
struct mlink *mlinks; /* singly linked list */ |
int form; /* format from file content */ |
int form; /* format from file content */ |
|
int name_head_done; |
}; |
}; |
|
|
struct mlink { |
struct mlink { |
|
|
STMT__MAX |
STMT__MAX |
}; |
}; |
|
|
typedef int (*mdoc_fp)(struct mpage *, const struct mdoc_node *); |
typedef int (*mdoc_fp)(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
|
|
struct mdoc_handler { |
struct mdoc_handler { |
mdoc_fp fp; /* optional handler */ |
mdoc_fp fp; /* optional handler */ |
Line 153 static void mpages_free(void); |
|
Line 155 static void mpages_free(void); |
|
static void mpages_merge(struct mchars *, struct mparse *); |
static void mpages_merge(struct mchars *, struct mparse *); |
static void names_check(void); |
static void names_check(void); |
static void parse_cat(struct mpage *, int); |
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_meta *, |
static void parse_mdoc(struct mpage *, const struct mdoc_node *); |
const struct man_node *); |
static int parse_mdoc_body(struct mpage *, const struct mdoc_node *); |
static void parse_mdoc(struct mpage *, const struct mdoc_meta *, |
static int parse_mdoc_head(struct mpage *, const struct mdoc_node *); |
const struct mdoc_node *); |
static int parse_mdoc_Fd(struct mpage *, const struct mdoc_node *); |
static int parse_mdoc_body(struct mpage *, const struct mdoc_meta *, |
static int parse_mdoc_Fn(struct mpage *, const struct mdoc_node *); |
const struct mdoc_node *); |
static int parse_mdoc_Nd(struct mpage *, const struct mdoc_node *); |
static int parse_mdoc_head(struct mpage *, const struct mdoc_meta *, |
static int parse_mdoc_Nm(struct mpage *, const struct mdoc_node *); |
const struct mdoc_node *); |
static int parse_mdoc_Sh(struct mpage *, const struct mdoc_node *); |
static int parse_mdoc_Fd(struct mpage *, const struct mdoc_meta *, |
static int parse_mdoc_Xr(struct mpage *, const struct mdoc_node *); |
const struct mdoc_node *); |
|
static int parse_mdoc_Fn(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
|
static int parse_mdoc_Fo(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
|
static int parse_mdoc_Nd(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
|
static int parse_mdoc_Nm(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
|
static int parse_mdoc_Sh(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
|
static int parse_mdoc_Xr(struct mpage *, const struct mdoc_meta *, |
|
const struct mdoc_node *); |
static void putkey(const struct mpage *, char *, uint64_t); |
static void putkey(const struct mpage *, char *, uint64_t); |
static void putkeys(const struct mpage *, |
static void putkeys(const struct mpage *, |
const char *, size_t, uint64_t); |
const char *, size_t, uint64_t); |
Line 290 static const struct mdoc_handler mdocs[MDOC_MAX] = { |
|
Line 304 static const struct mdoc_handler mdocs[MDOC_MAX] = { |
|
{ NULL, 0 }, /* Ux */ |
{ NULL, 0 }, /* Ux */ |
{ NULL, 0 }, /* Xc */ |
{ NULL, 0 }, /* Xc */ |
{ NULL, 0 }, /* Xo */ |
{ NULL, 0 }, /* Xo */ |
{ parse_mdoc_head, 0 }, /* Fo */ |
{ parse_mdoc_Fo, 0 }, /* Fo */ |
{ NULL, 0 }, /* Fc */ |
{ NULL, 0 }, /* Fc */ |
{ NULL, 0 }, /* Oo */ |
{ NULL, 0 }, /* Oo */ |
{ NULL, 0 }, /* Oc */ |
{ NULL, 0 }, /* Oc */ |
Line 1084 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1098 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
struct man *man; |
struct man *man; |
char *sodest; |
char *sodest; |
char *cp; |
char *cp; |
pid_t child_pid; |
|
int fd; |
int fd; |
unsigned int pslot; |
unsigned int pslot; |
enum mandoclevel lvl; |
enum mandoclevel lvl; |
Line 1094 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1107 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
str_info.free = hash_free; |
str_info.free = hash_free; |
str_info.key_offset = offsetof(struct str, key); |
str_info.key_offset = offsetof(struct str, key); |
|
|
if (0 == nodb) |
if ( ! nodb) |
SQL_EXEC("BEGIN TRANSACTION"); |
SQL_EXEC("BEGIN TRANSACTION"); |
|
|
mpage = ohash_first(&mpages, &pslot); |
mpage = ohash_first(&mpages, &pslot); |
while (NULL != mpage) { |
while (mpage != NULL) { |
mlinks_undupe(mpage); |
mlinks_undupe(mpage); |
if (NULL == mpage->mlinks) { |
if (mpage->mlinks == NULL) { |
mpage = ohash_next(&mpages, &pslot); |
mpage = ohash_next(&mpages, &pslot); |
continue; |
continue; |
} |
} |
Line 1112 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1125 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
mdoc = NULL; |
mdoc = NULL; |
man = NULL; |
man = NULL; |
sodest = NULL; |
sodest = NULL; |
child_pid = 0; |
|
|
|
mparse_open(mp, &fd, mpage->mlinks->file, &child_pid); |
mparse_open(mp, &fd, mpage->mlinks->file); |
if (fd == -1) { |
if (fd == -1) { |
say(mpage->mlinks->file, "&open"); |
say(mpage->mlinks->file, "&open"); |
goto nextpage; |
goto nextpage; |
Line 1125 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1137 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
* source code, unless it is already known to be |
* source code, unless it is already known to be |
* formatted. Fall back to formatted mode. |
* formatted. Fall back to formatted mode. |
*/ |
*/ |
if (FORM_CAT != mpage->mlinks->dform || |
if (mpage->mlinks->dform != FORM_CAT || |
FORM_CAT != mpage->mlinks->fform) { |
mpage->mlinks->fform != FORM_CAT) { |
lvl = mparse_readfd(mp, fd, mpage->mlinks->file); |
lvl = mparse_readfd(mp, fd, mpage->mlinks->file); |
if (lvl < MANDOCLEVEL_FATAL) |
if (lvl < MANDOCLEVEL_FATAL) |
mparse_result(mp, &mdoc, &man, &sodest); |
mparse_result(mp, &mdoc, &man, &sodest); |
} |
} |
|
|
if (NULL != sodest) { |
if (sodest != NULL) { |
mlink_dest = ohash_find(&mlinks, |
mlink_dest = ohash_find(&mlinks, |
ohash_qlookup(&mlinks, sodest)); |
ohash_qlookup(&mlinks, sodest)); |
if (NULL != mlink_dest) { |
if (mlink_dest == NULL) { |
|
mandoc_asprintf(&cp, "%s.gz", sodest); |
|
mlink_dest = ohash_find(&mlinks, |
|
ohash_qlookup(&mlinks, cp)); |
|
free(cp); |
|
} |
|
if (mlink_dest != NULL) { |
|
|
/* The .so target exists. */ |
/* The .so target exists. */ |
|
|
Line 1156 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1174 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
if (mpage_dest->pageid) |
if (mpage_dest->pageid) |
dbadd_mlink_name(mlink); |
dbadd_mlink_name(mlink); |
|
|
if (NULL == mlink->next) |
if (mlink->next == NULL) |
break; |
break; |
mlink = mlink->next; |
mlink = mlink->next; |
} |
} |
Line 1168 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1186 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
mpage->mlinks = NULL; |
mpage->mlinks = NULL; |
} |
} |
goto nextpage; |
goto nextpage; |
} else if (NULL != mdoc) { |
} else if (mdoc != NULL) { |
mpage->form = FORM_SRC; |
mpage->form = FORM_SRC; |
mpage->sec = mdoc_meta(mdoc)->msec; |
mpage->sec = mdoc_meta(mdoc)->msec; |
mpage->sec = mandoc_strdup( |
mpage->sec = mandoc_strdup( |
NULL == mpage->sec ? "" : mpage->sec); |
mpage->sec == NULL ? "" : mpage->sec); |
mpage->arch = mdoc_meta(mdoc)->arch; |
mpage->arch = mdoc_meta(mdoc)->arch; |
mpage->arch = mandoc_strdup( |
mpage->arch = mandoc_strdup( |
NULL == mpage->arch ? "" : mpage->arch); |
mpage->arch == NULL ? "" : mpage->arch); |
mpage->title = |
mpage->title = |
mandoc_strdup(mdoc_meta(mdoc)->title); |
mandoc_strdup(mdoc_meta(mdoc)->title); |
} else if (NULL != man) { |
} else if (man != NULL) { |
mpage->form = FORM_SRC; |
mpage->form = FORM_SRC; |
mpage->sec = |
mpage->sec = |
mandoc_strdup(man_meta(man)->msec); |
mandoc_strdup(man_meta(man)->msec); |
Line 1195 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1213 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
mpage->title = |
mpage->title = |
mandoc_strdup(mpage->mlinks->name); |
mandoc_strdup(mpage->mlinks->name); |
} |
} |
if (mpage->mlinks->gzip) |
|
mpage->form |= FORM_GZ; |
|
putkey(mpage, mpage->sec, TYPE_sec); |
putkey(mpage, mpage->sec, TYPE_sec); |
if (*mpage->arch != '\0') |
if (*mpage->arch != '\0') |
putkey(mpage, mpage->arch, TYPE_arch); |
putkey(mpage, mpage->arch, TYPE_arch); |
Line 1211 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1227 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
putkey(mpage, mlink->name, NAME_FILE); |
putkey(mpage, mlink->name, NAME_FILE); |
} |
} |
|
|
assert(NULL == mpage->desc); |
assert(mpage->desc == NULL); |
if (NULL != mdoc) { |
if (mdoc != NULL) |
if (NULL != (cp = mdoc_meta(mdoc)->name)) |
parse_mdoc(mpage, mdoc_meta(mdoc), mdoc_node(mdoc)); |
putkey(mpage, cp, NAME_HEAD); |
else if (man != NULL) |
parse_mdoc(mpage, mdoc_node(mdoc)); |
parse_man(mpage, man_meta(man), man_node(man)); |
} else if (NULL != man) |
|
parse_man(mpage, man_node(man)); |
|
else |
else |
parse_cat(mpage, fd); |
parse_cat(mpage, fd); |
if (NULL == mpage->desc) |
if (mpage->desc == NULL) |
mpage->desc = mandoc_strdup(mpage->mlinks->name); |
mpage->desc = mandoc_strdup(mpage->mlinks->name); |
|
|
if (warnings && !use_all) |
if (warnings && !use_all) |
Line 1231 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
Line 1245 mpages_merge(struct mchars *mc, struct mparse *mp) |
|
dbadd(mpage, mc); |
dbadd(mpage, mc); |
|
|
nextpage: |
nextpage: |
if (child_pid && |
if (mparse_wait(mp) != MANDOCLEVEL_OK) { |
mparse_wait(mp, child_pid) != MANDOCLEVEL_OK) { |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
exitcode = (int)MANDOCLEVEL_SYSERR; |
say(mpage->mlinks->file, "&wait gunzip"); |
say(mpage->mlinks->file, "&wait gunzip"); |
} |
} |
Line 1426 putmdockey(const struct mpage *mpage, |
|
Line 1439 putmdockey(const struct mpage *mpage, |
|
} |
} |
|
|
static void |
static void |
parse_man(struct mpage *mpage, const struct man_node *n) |
parse_man(struct mpage *mpage, const struct man_meta *meta, |
|
const struct man_node *n) |
{ |
{ |
const struct man_node *head, *body; |
const struct man_node *head, *body; |
char *start, *title; |
char *start, *title; |
Line 1492 parse_man(struct mpage *mpage, const struct man_node * |
|
Line 1506 parse_man(struct mpage *mpage, const struct man_node * |
|
break; |
break; |
|
|
putkey(mpage, start, NAME_TITLE); |
putkey(mpage, start, NAME_TITLE); |
|
if ( ! (mpage->name_head_done || |
|
strcasecmp(start, meta->title))) { |
|
putkey(mpage, start, NAME_HEAD); |
|
mpage->name_head_done = 1; |
|
} |
|
|
if (' ' == byte) { |
if (' ' == byte) { |
start += sz + 1; |
start += sz + 1; |
Line 1506 parse_man(struct mpage *mpage, const struct man_node * |
|
Line 1525 parse_man(struct mpage *mpage, const struct man_node * |
|
|
|
if (start == title) { |
if (start == title) { |
putkey(mpage, start, NAME_TITLE); |
putkey(mpage, start, NAME_TITLE); |
|
if ( ! (mpage->name_head_done || |
|
strcasecmp(start, meta->title))) { |
|
putkey(mpage, start, NAME_HEAD); |
|
mpage->name_head_done = 1; |
|
} |
free(title); |
free(title); |
return; |
return; |
} |
} |
Line 1536 parse_man(struct mpage *mpage, const struct man_node * |
|
Line 1560 parse_man(struct mpage *mpage, const struct man_node * |
|
for (n = n->child; n; n = n->next) { |
for (n = n->child; n; n = n->next) { |
if (NULL != mpage->desc) |
if (NULL != mpage->desc) |
break; |
break; |
parse_man(mpage, n); |
parse_man(mpage, meta, n); |
} |
} |
} |
} |
|
|
static void |
static void |
parse_mdoc(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
assert(NULL != n); |
assert(NULL != n); |
Line 1557 parse_mdoc(struct mpage *mpage, const struct mdoc_node |
|
Line 1582 parse_mdoc(struct mpage *mpage, const struct mdoc_node |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MDOC_TAIL: |
case MDOC_TAIL: |
if (NULL != mdocs[n->tok].fp) |
if (NULL != mdocs[n->tok].fp) |
if (0 == (*mdocs[n->tok].fp)(mpage, n)) |
if (0 == (*mdocs[n->tok].fp)(mpage, meta, n)) |
break; |
break; |
if (mdocs[n->tok].mask) |
if (mdocs[n->tok].mask) |
putmdockey(mpage, n->child, |
putmdockey(mpage, n->child, |
Line 1568 parse_mdoc(struct mpage *mpage, const struct mdoc_node |
|
Line 1593 parse_mdoc(struct mpage *mpage, const struct mdoc_node |
|
continue; |
continue; |
} |
} |
if (NULL != n->child) |
if (NULL != n->child) |
parse_mdoc(mpage, n); |
parse_mdoc(mpage, meta, n); |
} |
} |
} |
} |
|
|
static int |
static int |
parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
const char *start, *end; |
const char *start, *end; |
size_t sz; |
size_t sz; |
Line 1616 parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_n |
|
Line 1642 parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_n |
|
} |
} |
|
|
static int |
static int |
parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
char *cp; |
char *cp; |
|
|
Line 1637 parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_n |
|
Line 1664 parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_n |
|
cp++; |
cp++; |
|
|
putkey(mpage, cp, TYPE_Fn); |
putkey(mpage, cp, TYPE_Fn); |
|
if (n->sec == SEC_SYNOPSIS) |
|
putkey(mpage, cp, NAME_SYN); |
|
|
if (n->string < cp) |
if (n->string < cp) |
putkeys(mpage, n->string, cp - n->string, TYPE_Ft); |
putkeys(mpage, n->string, cp - n->string, TYPE_Ft); |
Line 1649 parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_n |
|
Line 1678 parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_n |
|
} |
} |
|
|
static int |
static int |
parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
|
putmdockey(mpage, n->child, TYPE_Fn); |
|
if (n->sec == SEC_SYNOPSIS) |
|
putmdockey(mpage, n->child, NAME_SYN); |
|
return(0); |
|
} |
|
|
|
static int |
|
parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
|
{ |
char *cp; |
char *cp; |
|
|
if (NULL == (n = n->child)) |
if (NULL == (n = n->child)) |
Line 1668 parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_n |
|
Line 1709 parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_n |
|
} |
} |
|
|
static int |
static int |
parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
if (MDOC_BODY == n->type) |
if (MDOC_BODY == n->type) |
Line 1677 parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_n |
|
Line 1719 parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_n |
|
} |
} |
|
|
static int |
static int |
parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
if (SEC_NAME == n->sec) |
if (SEC_NAME == n->sec) |
putmdockey(mpage, n->child, NAME_TITLE); |
putmdockey(mpage, n->child, NAME_TITLE); |
else if (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type) |
else if (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type) { |
putmdockey(mpage, n->child, NAME_SYN); |
if (n->child == NULL) |
|
putkey(mpage, meta->name, NAME_SYN); |
|
else |
|
putmdockey(mpage, n->child, NAME_SYN); |
|
} |
|
if ( ! (mpage->name_head_done || |
|
n->child == NULL || n->child->string == NULL || |
|
strcasecmp(n->child->string, meta->title))) { |
|
putkey(mpage, n->child->string, NAME_HEAD); |
|
mpage->name_head_done = 1; |
|
} |
return(0); |
return(0); |
} |
} |
|
|
static int |
static int |
parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
return(SEC_CUSTOM == n->sec && MDOC_HEAD == n->type); |
return(SEC_CUSTOM == n->sec && MDOC_HEAD == n->type); |
} |
} |
|
|
static int |
static int |
parse_mdoc_head(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_head(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
return(MDOC_HEAD == n->type); |
return(MDOC_HEAD == n->type); |
} |
} |
|
|
static int |
static int |
parse_mdoc_body(struct mpage *mpage, const struct mdoc_node *n) |
parse_mdoc_body(struct mpage *mpage, const struct mdoc_meta *meta, |
|
const struct mdoc_node *n) |
{ |
{ |
|
|
return(MDOC_BODY == n->type); |
return(MDOC_BODY == n->type); |