From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout.scc.kit.edu (scc-mailout-webmail.scc.kit.edu [129.13.185.232]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id pADIgbtS015833 for ; Sun, 13 Nov 2011 13:42:38 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-02.scc.kit.edu with esmtp (Exim 4.72 #1) id 1RPf0m-0003ET-HJ; Sun, 13 Nov 2011 19:42:36 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1RPf0m-00022s-HL for tech@mdocml.bsd.lv; Sun, 13 Nov 2011 19:42:36 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1RPf0m-00078W-E4 for tech@mdocml.bsd.lv; Sun, 13 Nov 2011 19:42:36 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1RPf0m-0004Yv-4q for tech@mdocml.bsd.lv; Sun, 13 Nov 2011 19:42:36 +0100 Date: Sun, 13 Nov 2011 19:42:35 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: mandocdb: do not use bogus files Message-ID: <20111113184235.GI3374@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, here is the first step towards usable titles in apropos(1) output. Currently, if you have a page /usr/share/man/man3p/FooBar::cAmEl.3p, you are quite lost, because apropos(1) will tell you FOOBAR::CAMEL(3p) - my fancy Perl module but of course, this will not find the page: man FOOBAR::CAMEL Also, imagine /usr/share/man/foobar/bogus.mdoc contained .Dt fancy 6, then apropos fancy would happily return FANCY - my well hidden manual but of course man(1) will search for it in vain. Thus, only look for files in reasonable places, and save the filename stem (title), suffix (section), and architecture in the struct of, for later use by the indexer. OK? Ingo --- mandocdb.c.orig +++ mandocdb.c @@ -38,6 +38,9 @@ struct of { char *fname; /* heap-allocated */ + char *sec; + char *arch; + char *title; struct of *next; /* NULL for last one */ struct of *first; /* first in list */ }; @@ -85,7 +88,8 @@ static void index_prune(const struct of *, DB *, const char *, DB *, const char *, int, recno_t *, recno_t **, size_t *); static void ofile_argbuild(char *[], int, int, struct of **); -static int ofile_dirbuild(const char *, int, struct of **); +static int ofile_dirbuild(const char *, const char *, + const char *, int, struct of **); static void ofile_free(struct of *); static int pman_node(MAN_ARGS); static void pmdoc_node(MDOC_ARGS); @@ -396,7 +400,7 @@ mandocdb(int argc, char *argv[]) ofile_free(of); of = NULL; - if ( ! ofile_dirbuild(argv[i], verb, &of)) + if ( ! ofile_dirbuild(argv[i], NULL, NULL, verb, &of)) exit((int)MANDOCLEVEL_SYSERR); if (NULL == of) @@ -1180,12 +1184,14 @@ ofile_argbuild(char *argv[], int argc, int verb, struct of **of) * Pass in a pointer to a NULL structure for the first invocation. */ static int -ofile_dirbuild(const char *dir, int verb, struct of **of) +ofile_dirbuild(const char *dir, const char* psec, const char *parch, + int verb, struct of **of) { char buf[MAXPATHLEN]; size_t sz; DIR *d; - const char *fn; + const char *fn, *sec, *arch; + char *suffix; struct of *nof; struct dirent *dp; @@ -1194,12 +1200,27 @@ ofile_dirbuild(const char *dir, int verb, struct of **of) return(0); } + sec = psec; + arch = parch; + while (NULL != (dp = readdir(d))) { fn = dp->d_name; if (DT_DIR == dp->d_type) { - if (0 == strcmp(".", fn)) - continue; - if (0 == strcmp("..", fn)) + + /* + * Don't bother parsing directories + * that man(1) won't find. + */ + + if (NULL == psec) { + if(strncmp("man", fn, 3)) + continue; + sec = fn + 3; + arch = NULL; + } else if (NULL == parch && + NULL == strchr(fn, '.')) + arch = fn; + else continue; buf[0] = '\0'; @@ -1207,21 +1228,27 @@ ofile_dirbuild(const char *dir, int verb, struct of **of) strlcat(buf, "/", MAXPATHLEN); sz = strlcat(buf, fn, MAXPATHLEN); - if (sz < MAXPATHLEN) { - if ( ! ofile_dirbuild(buf, verb, of)) - return(0); - continue; - } else if (sz < MAXPATHLEN) - continue; + if (MAXPATHLEN <= sz) { + fprintf(stderr, "%s: Path too long\n", dir); + return(0); + } + + if (verb > 2) + printf("%s: Scanning\n", buf); - fprintf(stderr, "%s: Path too long\n", dir); - return(0); + if ( ! ofile_dirbuild(buf, sec, arch, verb, of)) + return(0); } - if (DT_REG != dp->d_type) + if (NULL == sec || DT_REG != dp->d_type) continue; - if (0 == strcmp(MANDOC_DB, fn) || - 0 == strcmp(MANDOC_IDX, fn)) + /* + * Don't bother parsing files that man(1) won't find. + */ + + if (NULL == (suffix = strrchr(fn, '.'))) + continue; + if (strcmp(suffix + 1, sec)) continue; buf[0] = '\0'; @@ -1235,6 +1262,11 @@ ofile_dirbuild(const char *dir, int verb, struct of **of) nof = mandoc_calloc(1, sizeof(struct of)); nof->fname = mandoc_strdup(buf); + nof->sec = mandoc_strdup(sec); + if (NULL != arch) + nof->arch = mandoc_strdup(arch); + *suffix = '\0'; + nof->title = mandoc_strdup(fn); if (verb > 2) printf("%s: Scheduling\n", buf); -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv