=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.89 retrieving revision 1.94 diff -u -p -r1.89 -r1.94 --- mandoc/mandocdb.c 2013/12/27 20:35:51 1.89 +++ mandoc/mandocdb.c 2014/01/02 20:24:39 1.94 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.89 2013/12/27 20:35:51 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.94 2014/01/02 20:24:39 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013 Ingo Schwarze @@ -143,6 +143,7 @@ static void *hash_alloc(size_t, void *); static void hash_free(void *, size_t, void *); static void *hash_halloc(size_t, void *); static void mlink_add(struct mlink *, const struct stat *); +static int mlink_check(struct mpage *, struct mlink *); static void mlink_free(struct mlink *); static void mlinks_undupe(struct mpage *); static void mpages_free(void); @@ -154,11 +155,9 @@ static int parse_mdoc_body(struct mpage *, const stru static int parse_mdoc_head(struct mpage *, const struct mdoc_node *); static int parse_mdoc_Fd(struct mpage *, const struct mdoc_node *); static int parse_mdoc_Fn(struct mpage *, const struct mdoc_node *); -static int parse_mdoc_In(struct mpage *, const struct mdoc_node *); static int parse_mdoc_Nd(struct mpage *, const struct mdoc_node *); static int parse_mdoc_Nm(struct mpage *, const struct mdoc_node *); static int parse_mdoc_Sh(struct mpage *, const struct mdoc_node *); -static int parse_mdoc_St(struct mpage *, const struct mdoc_node *); static int parse_mdoc_Xr(struct mpage *, const struct mdoc_node *); static void putkey(const struct mpage *, const char *, uint64_t); @@ -216,7 +215,7 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = { { parse_mdoc_Fn, 0 }, /* Fn */ { NULL, TYPE_Ft }, /* Ft */ { NULL, TYPE_Ic }, /* Ic */ - { parse_mdoc_In, TYPE_In }, /* In */ + { NULL, TYPE_In }, /* In */ { NULL, TYPE_Li }, /* Li */ { parse_mdoc_Nd, TYPE_Nd }, /* Nd */ { parse_mdoc_Nm, TYPE_Nm }, /* Nm */ @@ -224,7 +223,7 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = { { NULL, 0 }, /* Ot */ { NULL, TYPE_Pa }, /* Pa */ { NULL, 0 }, /* Rv */ - { parse_mdoc_St, 0 }, /* St */ + { NULL, TYPE_St }, /* St */ { NULL, TYPE_Va }, /* Va */ { parse_mdoc_body, TYPE_Va }, /* Vt */ { parse_mdoc_Xr, 0 }, /* Xr */ @@ -523,8 +522,8 @@ treescan(void) FTSENT *ff; struct mlink *mlink; int dform; - char *fsec; - const char *dsec, *arch, *cp, *path; + char *dsec, *arch, *fsec, *cp; + const char *path; const char *argv[2]; argv[0] = "."; @@ -589,16 +588,14 @@ treescan(void) continue; } else fsec[-1] = '\0'; + mlink = mandoc_calloc(1, sizeof(struct mlink)); strlcpy(mlink->file, path, sizeof(mlink->file)); mlink->dform = dform; - if (NULL != dsec) - mlink->dsec = mandoc_strdup(dsec); - if (NULL != arch) - mlink->arch = mandoc_strdup(arch); - mlink->name = mandoc_strdup(ff->fts_name); - if (NULL != fsec) - mlink->fsec = mandoc_strdup(fsec); + mlink->dsec = dsec; + mlink->arch = arch; + mlink->name = ff->fts_name; + mlink->fsec = fsec; mlink_add(mlink, ff->fts_statp); continue; } else if (FTS_D != ff->fts_info && @@ -618,8 +615,6 @@ treescan(void) * Try to infer this from the name. * If we're not in use_all, enforce it. */ - dsec = NULL; - dform = FORM_NONE; cp = ff->fts_name; if (FTS_DP == ff->fts_info) break; @@ -630,6 +625,9 @@ treescan(void) } else if (0 == strncmp(cp, "cat", 3)) { dform = FORM_CAT; dsec = cp + 3; + } else { + dform = FORM_NONE; + dsec = NULL; } if (NULL != dsec || use_all) @@ -644,9 +642,10 @@ treescan(void) * Possibly our architecture. * If we're descending, keep tabs on it. */ - arch = NULL; if (FTS_DP != ff->fts_info && NULL != dsec) arch = ff->fts_name; + else + arch = NULL; break; default: if (FTS_DP == ff->fts_info || use_all) @@ -720,16 +719,16 @@ filescan(const char *file) *p++ = '\0'; if (0 == strncmp(start, "man", 3)) { mlink->dform = FORM_SRC; - mlink->dsec = mandoc_strdup(start + 3); + mlink->dsec = start + 3; } else if (0 == strncmp(start, "cat", 3)) { mlink->dform = FORM_CAT; - mlink->dsec = mandoc_strdup(start + 3); + mlink->dsec = start + 3; } start = p; if (NULL != mlink->dsec && NULL != (p = strchr(start, '/'))) { *p++ = '\0'; - mlink->arch = mandoc_strdup(start); + mlink->arch = start; start = p; } } @@ -744,7 +743,7 @@ filescan(const char *file) if ('.' == *p) { *p++ = '\0'; - mlink->fsec = mandoc_strdup(p); + mlink->fsec = p; } /* @@ -756,8 +755,6 @@ filescan(const char *file) mlink->name = p + 1; *p = '\0'; } - mlink->name = mandoc_strdup(mlink->name); - mlink_add(mlink, &st); } @@ -770,14 +767,10 @@ mlink_add(struct mlink *mlink, const struct stat *st) assert(NULL != mlink->file); - if (NULL == mlink->dsec) - mlink->dsec = mandoc_strdup(""); - if (NULL == mlink->arch) - mlink->arch = mandoc_strdup(""); - if (NULL == mlink->name) - mlink->name = mandoc_strdup(""); - if (NULL == mlink->fsec) - mlink->fsec = mandoc_strdup(""); + mlink->dsec = mandoc_strdup(mlink->dsec ? mlink->dsec : ""); + mlink->arch = mandoc_strdup(mlink->arch ? mlink->arch : ""); + mlink->name = mandoc_strdup(mlink->name ? mlink->name : ""); + mlink->fsec = mandoc_strdup(mlink->fsec ? mlink->fsec : ""); if ('0' == *mlink->fsec) { free(mlink->fsec); @@ -855,16 +848,16 @@ mlinks_undupe(struct mpage *mpage) char *bufp; mpage->form = FORM_CAT; - for(prev = &mpage->mlinks; *prev; prev = &(*prev)->next) { - mlink = *prev; + prev = &mpage->mlinks; + while (NULL != (mlink = *prev)) { if (FORM_CAT != mlink->dform) { mpage->form = FORM_NONE; - continue; + goto nextlink; } if (strlcpy(buf, mlink->file, PATH_MAX) >= PATH_MAX) { if (warnings) say(mlink->file, "Filename too long"); - continue; + goto nextlink; } bufp = strstr(buf, "cat"); assert(NULL != bufp); @@ -874,17 +867,67 @@ mlinks_undupe(struct mpage *mpage) strlcat(buf, mlink->dsec, PATH_MAX); if (NULL == ohash_find(&mlinks, ohash_qlookup(&mlinks, buf))) - continue; + goto nextlink; if (warnings) say(mlink->file, "Man source exists: %s", buf); if (use_all) - continue; + goto nextlink; *prev = mlink->next; mlink_free(mlink); - mlink = *prev; + continue; +nextlink: + prev = &(*prev)->next; } } +static int +mlink_check(struct mpage *mpage, struct mlink *mlink) +{ + int match; + + match = 1; + + /* + * Check whether the manual section given in a file + * agrees with the directory where the file is located. + * Some manuals have suffixes like (3p) on their + * section number either inside the file or in the + * directory name, some are linked into more than one + * section, like encrypt(1) = makekey(8). + */ + + if (FORM_SRC == mpage->form && + strcasecmp(mpage->sec, mlink->dsec)) { + match = 0; + say(mlink->file, "Section \"%s\" manual in %s directory", + mpage->sec, mlink->dsec); + } + + /* + * Manual page directories exist for each kernel + * architecture as returned by machine(1). + * However, many manuals only depend on the + * application architecture as returned by arch(1). + * For example, some (2/ARM) manuals are shared + * across the "armish" and "zaurus" kernel + * architectures. + * A few manuals are even shared across completely + * different architectures, for example fdformat(1) + * on amd64, i386, sparc, and sparc64. + */ + + if (strcasecmp(mpage->arch, mlink->arch)) { + match = 0; + say(mlink->file, "Architecture \"%s\" manual in " + "\"%s\" directory", mpage->arch, mlink->arch); + } + + if (strcasecmp(mpage->title, mlink->name)) + match = 0; + + return(match); +} + /* * Run through the files in the global vector "mpages" * and add them to the database specified in "basedir". @@ -898,6 +941,7 @@ mpages_merge(struct mchars *mc, struct mparse *mp, int struct ohash title_table; struct ohash_info title_info, str_info; struct mpage *mpage; + struct mlink *mlink; struct mdoc *mdoc; struct man *man; struct title *title_entry; @@ -932,7 +976,6 @@ mpages_merge(struct mchars *mc, struct mparse *mp, int mparse_reset(mp); mdoc = NULL; man = NULL; - match = 1; /* * Try interpreting the file as mdoc(7) or man(7) @@ -973,50 +1016,18 @@ mpages_merge(struct mchars *mc, struct mparse *mp, int mandoc_strdup(mpage->mlinks->name); } - /* - * Check whether the manual section given in a file - * agrees with the directory where the file is located. - * Some manuals have suffixes like (3p) on their - * section number either inside the file or in the - * directory name, some are linked into more than one - * section, like encrypt(1) = makekey(8). Do not skip - * manuals for such reasons. - */ - if (warnings && !use_all && FORM_SRC == mpage->form && - strcasecmp(mpage->sec, mpage->mlinks->dsec)) { - match = 0; - say(mpage->mlinks->file, "Section \"%s\" " - "manual in %s directory", - mpage->sec, mpage->mlinks->dsec); - } + for (mlink = mpage->mlinks; mlink; mlink = mlink->next) + putkey(mpage, mlink->name, TYPE_Nm); - /* - * Manual page directories exist for each kernel - * architecture as returned by machine(1). - * However, many manuals only depend on the - * application architecture as returned by arch(1). - * For example, some (2/ARM) manuals are shared - * across the "armish" and "zaurus" kernel - * architectures. - * A few manuals are even shared across completely - * different architectures, for example fdformat(1) - * on amd64, i386, sparc, and sparc64. - * Thus, warn about architecture mismatches, - * but don't skip manuals for this reason. - */ - if (warnings && !use_all && - strcasecmp(mpage->arch, mpage->mlinks->arch)) { + if (warnings && !use_all) { match = 0; - say(mpage->mlinks->file, "Architecture \"%s\" " - "manual in \"%s\" directory", - mpage->arch, mpage->mlinks->arch); - } - if (warnings && !use_all && - strcasecmp(mpage->title, mpage->mlinks->name)) - match = 0; + for (mlink = mpage->mlinks; mlink; + mlink = mlink->next) + if (mlink_check(mpage, mlink)) + match = 1; + } else + match = 1; - putkey(mpage, mpage->mlinks->name, TYPE_Nm); - if (NULL != mdoc) { if (NULL != (cp = mdoc_meta(mdoc)->name)) putkey(mpage, cp, TYPE_Nm); @@ -1439,21 +1450,10 @@ parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_n if (end > start) putkeys(mpage, start, end - start + 1, TYPE_In); - return(1); + return(0); } static int -parse_mdoc_In(struct mpage *mpage, const struct mdoc_node *n) -{ - - if (NULL != n->child && MDOC_TEXT == n->child->type) - return(0); - - putkey(mpage, n->child->string, TYPE_In); - return(1); -} - -static int parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_node *n) { const char *cp; @@ -1487,17 +1487,6 @@ parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_n } static int -parse_mdoc_St(struct mpage *mpage, const struct mdoc_node *n) -{ - - if (NULL == n->child || MDOC_TEXT != n->child->type) - return(0); - - putkey(mpage, n->child->string, TYPE_St); - return(1); -} - -static int parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_node *n) { char *cp; @@ -1554,12 +1543,8 @@ static int parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_node *n) { - if (SEC_NAME == n->sec) - return(1); - else if (SEC_SYNOPSIS != n->sec || MDOC_HEAD != n->type) - return(0); - - return(1); + return(SEC_NAME == n->sec || + (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type)); } static int @@ -1732,7 +1717,6 @@ utf8key(struct mchars *mc, struct str *key) /* Read past the slash. */ val++; - u = 0; /* * Parse the escape sequence and see if it's a