version 1.222, 2016/07/19 22:40:33 |
version 1.228, 2016/08/22 16:15:26 |
Line 122 static void mlink_add(struct mlink *, const struct st |
|
Line 122 static void mlink_add(struct mlink *, const struct st |
|
static void 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 *); |
|
int mpages_compare(const void *, const void *); |
static void mpages_free(void); |
static void mpages_free(void); |
static void mpages_merge(struct dba *, struct mparse *); |
static void mpages_merge(struct dba *, struct mparse *); |
static void parse_cat(struct mpage *, int); |
static void parse_cat(struct mpage *, int); |
Line 426 mandocdb(int argc, char *argv[]) |
|
Line 427 mandocdb(int argc, char *argv[]) |
|
if (OP_TEST != op && 0 == set_basedir(path_arg, 1)) |
if (OP_TEST != op && 0 == set_basedir(path_arg, 1)) |
goto out; |
goto out; |
|
|
if ((dba = dba_read(MANDOC_DB)) != NULL) { |
dba = nodb ? dba_new(128) : dba_read(MANDOC_DB); |
|
if (dba != NULL) { |
/* |
/* |
* The existing database is usable. Process |
* The existing database is usable. Process |
* all files specified on the command-line. |
* all files specified on the command-line. |
Line 443 mandocdb(int argc, char *argv[]) |
|
Line 445 mandocdb(int argc, char *argv[]) |
|
use_all = 1; |
use_all = 1; |
for (i = 0; i < argc; i++) |
for (i = 0; i < argc; i++) |
filescan(argv[i]); |
filescan(argv[i]); |
if (OP_TEST != op) |
if (nodb == 0) |
dbprune(dba); |
dbprune(dba); |
} else { |
} else { |
/* |
/* Database missing or corrupt. */ |
* Database missing or corrupt. |
say(MANDOC_DB, |
* Recreate from scratch. |
"%s: Automatically recreating from scratch", |
*/ |
strerror(errno)); |
exitcode = (int)MANDOCLEVEL_OK; |
exitcode = (int)MANDOCLEVEL_OK; |
op = OP_DEFAULT; |
op = OP_DEFAULT; |
if (0 == treescan()) |
if (0 == treescan()) |
Line 1084 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
Line 1086 mlink_check(struct mpage *mpage, struct mlink *mlink) |
|
static void |
static void |
mpages_merge(struct dba *dba, struct mparse *mp) |
mpages_merge(struct dba *dba, struct mparse *mp) |
{ |
{ |
char any[] = "any"; |
struct mpage **mplist, *mpage, *mpage_dest; |
struct mpage *mpage, *mpage_dest; |
|
struct mlink *mlink, *mlink_dest; |
struct mlink *mlink, *mlink_dest; |
struct roff_man *man; |
struct roff_man *man; |
char *sodest; |
char *sodest; |
char *cp; |
char *cp; |
int fd; |
int fd; |
unsigned int pslot; |
unsigned int ip, npages, pslot; |
|
|
|
npages = ohash_entries(&mpages); |
|
mplist = mandoc_reallocarray(NULL, npages, sizeof(*mplist)); |
|
ip = 0; |
mpage = ohash_first(&mpages, &pslot); |
mpage = ohash_first(&mpages, &pslot); |
while (mpage != NULL) { |
while (mpage != NULL) { |
mlinks_undupe(mpage); |
mlinks_undupe(mpage); |
if ((mlink = mpage->mlinks) == NULL) { |
if (mpage->mlinks != NULL) |
mpage = ohash_next(&mpages, &pslot); |
mplist[ip++] = mpage; |
continue; |
mpage = ohash_next(&mpages, &pslot); |
} |
} |
|
npages = ip; |
|
qsort(mplist, npages, sizeof(*mplist), mpages_compare); |
|
|
|
for (ip = 0; ip < npages; ip++) { |
|
mpage = mplist[ip]; |
|
mlink = mpage->mlinks; |
name_mask = NAME_MASK; |
name_mask = NAME_MASK; |
mandoc_ohash_init(&names, 4, offsetof(struct str, key)); |
mandoc_ohash_init(&names, 4, offsetof(struct str, key)); |
mandoc_ohash_init(&strings, 6, offsetof(struct str, key)); |
mandoc_ohash_init(&strings, 6, offsetof(struct str, key)); |
Line 1186 mpages_merge(struct dba *dba, struct mparse *mp) |
|
Line 1195 mpages_merge(struct dba *dba, struct mparse *mp) |
|
mpage->arch = mandoc_strdup(mlink->arch); |
mpage->arch = mandoc_strdup(mlink->arch); |
mpage->title = mandoc_strdup(mlink->name); |
mpage->title = mandoc_strdup(mlink->name); |
} |
} |
putkey(mpage, mpage->sec, TYPE_sec); |
|
if (*mpage->arch != '\0') |
|
putkey(mpage, mpage->arch, TYPE_arch); |
|
|
|
for ( ; mlink != NULL; mlink = mlink->next) { |
|
if ('\0' != *mlink->dsec) |
|
putkey(mpage, mlink->dsec, TYPE_sec); |
|
if ('\0' != *mlink->fsec) |
|
putkey(mpage, mlink->fsec, TYPE_sec); |
|
putkey(mpage, '\0' == *mlink->arch ? |
|
any : mlink->arch, TYPE_arch); |
|
putkey(mpage, mlink->name, NAME_FILE); |
|
} |
|
|
|
assert(mpage->desc == NULL); |
assert(mpage->desc == NULL); |
if (man != NULL && man->macroset == MACROSET_MDOC) |
if (man != NULL && man->macroset == MACROSET_MDOC) |
parse_mdoc(mpage, &man->meta, man->first); |
parse_mdoc(mpage, &man->meta, man->first); |
Line 1221 mpages_merge(struct dba *dba, struct mparse *mp) |
|
Line 1217 mpages_merge(struct dba *dba, struct mparse *mp) |
|
nextpage: |
nextpage: |
ohash_delete(&strings); |
ohash_delete(&strings); |
ohash_delete(&names); |
ohash_delete(&names); |
mpage = ohash_next(&mpages, &pslot); |
|
} |
} |
|
free(mplist); |
} |
} |
|
|
|
int |
|
mpages_compare(const void *vp1, const void *vp2) |
|
{ |
|
const struct mpage *mp1, *mp2; |
|
|
|
mp1 = *(const struct mpage **)vp1; |
|
mp2 = *(const struct mpage **)vp2; |
|
return strcmp(mp1->mlinks->file, mp2->mlinks->file); |
|
} |
|
|
static void |
static void |
parse_cat(struct mpage *mpage, int fd) |
parse_cat(struct mpage *mpage, int fd) |
{ |
{ |
Line 1347 parse_cat(struct mpage *mpage, int fd) |
|
Line 1353 parse_cat(struct mpage *mpage, int fd) |
|
static void |
static void |
putkey(const struct mpage *mpage, char *value, uint64_t type) |
putkey(const struct mpage *mpage, char *value, uint64_t type) |
{ |
{ |
char *cp; |
|
|
|
assert(NULL != value); |
|
if (TYPE_arch == type) |
|
for (cp = value; *cp; cp++) |
|
if (isupper((unsigned char)*cp)) |
|
*cp = _tolower((unsigned char)*cp); |
|
putkeys(mpage, value, strlen(value), type); |
putkeys(mpage, value, strlen(value), type); |
} |
} |
|
|
Line 1694 parse_mdoc_Nm(struct mpage *mpage, const struct roff_m |
|
Line 1693 parse_mdoc_Nm(struct mpage *mpage, const struct roff_m |
|
if ( ! (mpage->name_head_done || |
if ( ! (mpage->name_head_done || |
n->child == NULL || n->child->string == NULL || |
n->child == NULL || n->child->string == NULL || |
strcasecmp(n->child->string, meta->title))) { |
strcasecmp(n->child->string, meta->title))) { |
putkey(mpage, n->child->string, ROFFT_HEAD); |
putkey(mpage, n->child->string, NAME_HEAD); |
mpage->name_head_done = 1; |
mpage->name_head_done = 1; |
} |
} |
return 0; |
return 0; |
Line 1954 dbadd_mlink(const struct mlink *mlink) |
|
Line 1953 dbadd_mlink(const struct mlink *mlink) |
|
{ |
{ |
dba_page_alias(mlink->mpage->dba, mlink->name, NAME_FILE); |
dba_page_alias(mlink->mpage->dba, mlink->name, NAME_FILE); |
dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->dsec); |
dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->dsec); |
|
dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->fsec); |
dba_page_add(mlink->mpage->dba, DBP_ARCH, mlink->arch); |
dba_page_add(mlink->mpage->dba, DBP_ARCH, mlink->arch); |
dba_page_add(mlink->mpage->dba, DBP_FILE, mlink->file); |
dba_page_add(mlink->mpage->dba, DBP_FILE, mlink->file); |
} |
} |
Line 2013 dbadd(struct dba *dba, struct mpage *mpage) |
|
Line 2013 dbadd(struct dba *dba, struct mpage *mpage) |
|
cp = mpage->desc; |
cp = mpage->desc; |
i = strlen(cp); |
i = strlen(cp); |
mustfree = render_string(&cp, &i); |
mustfree = render_string(&cp, &i); |
mpage->dba = dba_page_new(dba->pages, mlink->name, |
mpage->dba = dba_page_new(dba->pages, |
mlink->dsec, mlink->arch, cp, mlink->file, mpage->form); |
*mpage->arch == '\0' ? mlink->arch : mpage->arch, |
|
cp, mlink->file, mpage->form); |
if (mustfree) |
if (mustfree) |
free(cp); |
free(cp); |
|
dba_page_add(mpage->dba, DBP_SECT, mpage->sec); |
|
|
while ((mlink = mlink->next) != NULL) |
while (mlink != NULL) { |
dbadd_mlink(mlink); |
dbadd_mlink(mlink); |
|
mlink = mlink->next; |
|
} |
|
|
for (key = ohash_first(&names, &slot); NULL != key; |
for (key = ohash_first(&names, &slot); NULL != key; |
key = ohash_next(&names, &slot)) { |
key = ohash_next(&names, &slot)) { |