=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.33 retrieving revision 1.35 diff -u -p -r1.33 -r1.35 --- mandoc/mandocdb.c 2011/12/10 22:01:06 1.33 +++ mandoc/mandocdb.c 2011/12/16 08:04:34 1.35 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.33 2011/12/10 22:01:06 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.35 2011/12/16 08:04:34 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -110,7 +109,7 @@ static void index_prune(const struct of *, DB *, recno_t *, recno_t **, size_t *, size_t *); static void ofile_argbuild(int, char *[], struct of **); -static int ofile_dirbuild(const char *, const char *, +static void ofile_dirbuild(const char *, const char *, const char *, int, struct of **); static void ofile_free(struct of *); static void pformatted(DB *, struct buf *, struct buf *, @@ -273,6 +272,7 @@ main(int argc, char *argv[]) struct manpaths dirs; enum op op; /* current operation */ const char *dir; + char *conf_file; char *cp; char pbuf[PATH_MAX], ibuf[MAXPATHLEN], /* index fname */ @@ -312,12 +312,16 @@ main(int argc, char *argv[]) maxrec = 0; op = OP_NEW; dir = NULL; + conf_file = NULL; - while (-1 != (ch = getopt(argc, argv, "ad:u:v"))) + while (-1 != (ch = getopt(argc, argv, "aC:d:u:v"))) switch (ch) { case ('a'): use_all = 1; break; + case ('C'): + conf_file = optarg; + break; case ('d'): dir = optarg; op = OP_UPDATE; @@ -379,12 +383,8 @@ main(int argc, char *argv[]) exit((int)MANDOCLEVEL_SYSERR); } - if (verb > 2) { - printf("%s: Opened\n", fbuf); - printf("%s: Opened\n", ibuf); - } - ofile_argbuild(argc, argv, &of); + if (NULL == of) goto out; @@ -394,13 +394,16 @@ main(int argc, char *argv[]) &maxrec, &recs, &recsz, &reccur); /* - * Go to the root of the respective manual tree - * such that .so links work. In case of failure, - * just prod on, even though .so links won't work. + * Go to the root of the respective manual tree. + * This must work or no manuals may be found (they're + * indexed relative to the root). */ if (OP_UPDATE == op) { - chdir(dir); + if (-1 == chdir(dir)) { + perror(dir); + exit((int)MANDOCLEVEL_SYSERR); + } index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, idx, ibuf, maxrec, recs, reccur); @@ -426,7 +429,7 @@ main(int argc, char *argv[]) dirs.paths[i] = mandoc_strdup(cp); } } else - manpath_parse(&dirs, NULL, NULL); + manpath_parse(&dirs, conf_file, NULL, NULL); for (i = 0; i < dirs.sz; i++) { ibuf[0] = fbuf[0] = '\0'; @@ -461,30 +464,32 @@ main(int argc, char *argv[]) exit((int)MANDOCLEVEL_SYSERR); } - if (verb > 2) { - printf("%s: Truncated\n", fbuf); - printf("%s: Truncated\n", ibuf); - } - ofile_free(of); of = NULL; - if ( ! ofile_dirbuild(dirs.paths[i], NULL, NULL, - 0, &of)) + if (-1 == chdir(dirs.paths[i])) { + perror(dirs.paths[i]); exit((int)MANDOCLEVEL_SYSERR); + } + ofile_dirbuild(".", NULL, NULL, 0, &of); + if (NULL == of) continue; of = of->first; /* - * Go to the root of the respective manual tree - * such that .so links work. In case of failure, - * just prod on, even though .so links won't work. + * Go to the root of the respective manual tree. + * This must work or no manuals may be found (they're + * indexed relative to the root). */ - chdir(dirs.paths[i]); + if (-1 == chdir(dirs.paths[i])) { + perror(dirs.paths[i]); + exit((int)MANDOCLEVEL_SYSERR); + } + index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, idx, ibuf, maxrec, recs, reccur); } @@ -1429,8 +1434,6 @@ ofile_argbuild(int argc, char *argv[], struct of **of) * Add the structure to the list. */ - if (verb > 2) - printf("%s: Scheduling\n", argv[i]); if (NULL == *of) { *of = nof; (*of)->first = nof; @@ -1450,12 +1453,11 @@ ofile_argbuild(int argc, char *argv[], struct of **of) * everything else is a manual. * Pass in a pointer to a NULL structure for the first invocation. */ -static int +static void ofile_dirbuild(const char *dir, const char* psec, const char *parch, int p_src_form, struct of **of) { char buf[MAXPATHLEN]; - struct stat sb; size_t sz; DIR *d; const char *fn, *sec, *arch; @@ -1466,7 +1468,7 @@ ofile_dirbuild(const char *dir, const char* psec, cons if (NULL == (d = opendir(dir))) { perror(dir); - return(0); + exit((int)MANDOCLEVEL_SYSERR); } while (NULL != (dp = readdir(d))) { @@ -1511,20 +1513,16 @@ ofile_dirbuild(const char *dir, const char* psec, cons if (MAXPATHLEN <= sz) { fprintf(stderr, "%s: Path too long\n", dir); - return(0); + exit((int)MANDOCLEVEL_SYSERR); } - if (verb > 2) - printf("%s: Scanning\n", buf); - - if ( ! ofile_dirbuild(buf, sec, arch, - src_form, of)) - return(0); + ofile_dirbuild(buf, sec, arch, src_form, of); } + if (DT_REG != dp->d_type || - (NULL == psec && !use_all) || - !strcmp(MANDOC_DB, fn) || - !strcmp(MANDOC_IDX, fn)) + (NULL == psec && !use_all) || + ! strcmp(MANDOC_DB, fn) || + ! strcmp(MANDOC_IDX, fn)) continue; /* @@ -1588,13 +1586,15 @@ ofile_dirbuild(const char *dir, const char* psec, cons "%s: Path too long\n", buf); continue; } - if (0 == stat(buf, &sb)) + if (0 == access(buf, R_OK)) continue; } } + assert('.' == dir[0]); + assert('/' == dir[1]); buf[0] = '\0'; - strlcat(buf, dir, MAXPATHLEN); + strlcat(buf, dir + 2, MAXPATHLEN); strlcat(buf, "/", MAXPATHLEN); sz = strlcat(buf, fn, MAXPATHLEN); if (sz >= MAXPATHLEN) { @@ -1623,8 +1623,6 @@ ofile_dirbuild(const char *dir, const char* psec, cons * Add the structure to the list. */ - if (verb > 2) - printf("%s: Scheduling\n", buf); if (NULL == *of) { *of = nof; (*of)->first = nof; @@ -1636,7 +1634,6 @@ ofile_dirbuild(const char *dir, const char* psec, cons } closedir(d); - return(1); } static void @@ -1660,7 +1657,8 @@ usage(void) { fprintf(stderr, "usage: %s [-v] " - "[-d dir [files...] |" - " -u dir [files...] |" - " dir...]\n", progname); + "[-C file] |" + " dir ... |" + " -d dir [file ...] |" + " -u dir [file ...]\n", progname); }