=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.46 retrieving revision 1.49.2.1 diff -u -p -r1.46 -r1.49.2.1 --- mandoc/mandocdb.c 2012/03/23 06:52:17 1.46 +++ mandoc/mandocdb.c 2013/09/17 21:32:07 1.49.2.1 @@ -1,7 +1,7 @@ -/* $Id: mandocdb.c,v 1.46 2012/03/23 06:52:17 kristaps Exp $ */ +/* $Id: mandocdb.c,v 1.49.2.1 2013/09/17 21:32:07 schwarze Exp $ */ /* - * Copyright (c) 2011 Kristaps Dzonsons - * Copyright (c) 2011 Ingo Schwarze + * Copyright (c) 2011, 2012 Kristaps Dzonsons + * Copyright (c) 2011, 2012 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,7 +19,6 @@ #include "config.h" #endif -#include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -68,8 +68,8 @@ /* Access to the mandoc database on disk. */ struct mdb { - char idxn[MAXPATHLEN]; /* index db filename */ - char dbn[MAXPATHLEN]; /* keyword db filename */ + char idxn[PATH_MAX]; /* index db filename */ + char dbn[PATH_MAX]; /* keyword db filename */ DB *idx; /* index recno database */ DB *db; /* keyword btree database */ }; @@ -137,12 +137,12 @@ static void index_merge(const struct of *, struct m const char *); static void index_prune(const struct of *, struct mdb *, struct recs *, const char *); -static void ofile_argbuild(int, char *[], +static void ofile_argbuild(int, char *[], struct of **, const char *); static void ofile_dirbuild(const char *, const char *, const char *, int, struct of **, char *); static void ofile_free(struct of *); -static void pformatted(DB *, struct buf *, struct buf *, +static void pformatted(DB *, struct buf *, struct buf *, const struct of *, const char *); static int pman_node(MAN_ARGS); static void pmdoc_node(MDOC_ARGS); @@ -305,7 +305,7 @@ main(int argc, char *argv[]) enum op op; /* current operation */ const char *dir; int ch, i, flags; - char dirbuf[MAXPATHLEN]; + char dirbuf[PATH_MAX]; DB *hash; /* temporary keyword hashtable */ BTREEINFO info; /* btree configuration */ size_t sz1, sz2; @@ -396,7 +396,7 @@ main(int argc, char *argv[]) info.lorder = 4321; info.flags = R_DUP; - mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); + mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL); memset(&buf, 0, sizeof(struct buf)); memset(&dbuf, 0, sizeof(struct buf)); @@ -410,21 +410,21 @@ main(int argc, char *argv[]) ofile_argbuild(argc, argv, &of, "."); if (NULL == of) goto out; - index_merge(of, mp, &dbuf, &buf, + index_merge(of, mp, &dbuf, &buf, hash, &mdb, &recs, "."); goto out; } if (OP_UPDATE == op || OP_DELETE == op) { - strlcat(mdb.dbn, dir, MAXPATHLEN); - strlcat(mdb.dbn, "/", MAXPATHLEN); - sz1 = strlcat(mdb.dbn, MANDOC_DB, MAXPATHLEN); + strlcat(mdb.dbn, dir, PATH_MAX); + strlcat(mdb.dbn, "/", PATH_MAX); + sz1 = strlcat(mdb.dbn, MANDOC_DB, PATH_MAX); - strlcat(mdb.idxn, dir, MAXPATHLEN); - strlcat(mdb.idxn, "/", MAXPATHLEN); - sz2 = strlcat(mdb.idxn, MANDOC_IDX, MAXPATHLEN); + strlcat(mdb.idxn, dir, PATH_MAX); + strlcat(mdb.idxn, "/", PATH_MAX); + sz2 = strlcat(mdb.idxn, MANDOC_IDX, PATH_MAX); - if (sz1 >= MAXPATHLEN || sz2 >= MAXPATHLEN) { + if (sz1 >= PATH_MAX || sz2 >= PATH_MAX) { fprintf(stderr, "%s: path too long\n", dir); exit((int)MANDOCLEVEL_BADARG); } @@ -492,8 +492,8 @@ main(int argc, char *argv[]) exit((int)MANDOCLEVEL_SYSERR); } - strlcpy(mdb.dbn, MANDOC_DB, MAXPATHLEN); - strlcpy(mdb.idxn, MANDOC_IDX, MAXPATHLEN); + strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX); + strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX); flags = O_CREAT | O_TRUNC | O_RDWR; mdb.db = dbopen(mdb.dbn, flags, 0644, DB_BTREE, &info); @@ -511,7 +511,7 @@ main(int argc, char *argv[]) * Search for manuals and fill the new database. */ - strlcpy(dirbuf, dirs.paths[i], MAXPATHLEN); + strlcpy(dirbuf, dirs.paths[i], PATH_MAX); ofile_dirbuild(".", "", "", 0, &of, dirbuf); if (NULL != of) { @@ -651,7 +651,7 @@ index_merge(const struct of *of, struct mparse *mp, assert(march); if (strcasecmp(march, of->arch)) WARNING(fn, basedir, "Architecture \"%s\" " - "manual in \"%s\" directory", + "manual in \"%s\" directory", march, of->arch); /* @@ -822,7 +822,7 @@ index_merge(const struct of *of, struct mparse *mp, while (0 == (*files->seq)(files, &key, &val, seq)) { seq = R_NEXT; if (val.size) - WARNING((char *)val.data, basedir, + WARNING((char *)val.data, basedir, "Probably unreachable, title " "is %s", (char *)key.data); } @@ -837,7 +837,7 @@ index_merge(const struct of *of, struct mparse *mp, * in `idx' (zeroing its value size). */ static void -index_prune(const struct of *ofile, struct mdb *mdb, +index_prune(const struct of *ofile, struct mdb *mdb, struct recs *recs, const char *basedir) { const struct of *of; @@ -913,7 +913,7 @@ index_prune(const struct of *ofile, struct mdb *mdb, } if (verb) - printf("%s: Deleting from index: %s\n", + printf("%s: Deleting from index: %s\n", basedir, fn); val.size = 0; @@ -1598,7 +1598,7 @@ static void ofile_argbuild(int argc, char *argv[], struct of **of, const char *basedir) { - char buf[MAXPATHLEN]; + char buf[PATH_MAX]; const char *sec, *arch, *title; char *p; int i, src_form; @@ -1689,7 +1689,7 @@ static void ofile_dirbuild(const char *dir, const char* psec, const char *parch, int p_src_form, struct of **of, char *basedir) { - char buf[MAXPATHLEN]; + char buf[PATH_MAX]; size_t sz; DIR *d; const char *fn, *sec, *arch; @@ -1749,18 +1749,18 @@ ofile_dirbuild(const char *dir, const char* psec, cons } buf[0] = '\0'; - strlcat(buf, dir, MAXPATHLEN); - strlcat(buf, "/", MAXPATHLEN); - strlcat(basedir, "/", MAXPATHLEN); - strlcat(basedir, fn, MAXPATHLEN); - sz = strlcat(buf, fn, MAXPATHLEN); + strlcat(buf, dir, PATH_MAX); + strlcat(buf, "/", PATH_MAX); + strlcat(basedir, "/", PATH_MAX); + strlcat(basedir, fn, PATH_MAX); + sz = strlcat(buf, fn, PATH_MAX); - if (MAXPATHLEN <= sz) { + if (PATH_MAX <= sz) { WARNING(fn, basedir, "Path too long"); continue; } - ofile_dirbuild(buf, sec, arch, + ofile_dirbuild(buf, sec, arch, src_form, of, basedir); p = strrchr(basedir, '/'); @@ -1814,7 +1814,7 @@ ofile_dirbuild(const char *dir, const char* psec, cons if (0 == use_all && MANDOC_FORM & src_form && '\0' != *psec) { buf[0] = '\0'; - strlcat(buf, dir, MAXPATHLEN); + strlcat(buf, dir, PATH_MAX); p = strrchr(buf, '/'); if ('\0' != *parch && NULL != p) for (p--; p > buf; p--) @@ -1826,17 +1826,17 @@ ofile_dirbuild(const char *dir, const char* psec, cons p++; if (0 == strncmp("cat", p, 3)) memcpy(p, "man", 3); - strlcat(buf, "/", MAXPATHLEN); - sz = strlcat(buf, fn, MAXPATHLEN); - if (sz >= MAXPATHLEN) { + strlcat(buf, "/", PATH_MAX); + sz = strlcat(buf, fn, PATH_MAX); + if (sz >= PATH_MAX) { WARNING(fn, basedir, "Path too long"); continue; } q = strrchr(buf, '.'); if (NULL != q && p < q++) { *q = '\0'; - sz = strlcat(buf, psec, MAXPATHLEN); - if (sz >= MAXPATHLEN) { + sz = strlcat(buf, psec, PATH_MAX); + if (sz >= PATH_MAX) { WARNING(fn, basedir, "Path too long"); continue; } @@ -1848,11 +1848,11 @@ ofile_dirbuild(const char *dir, const char* psec, cons buf[0] = '\0'; assert('.' == dir[0]); if ('/' == dir[1]) { - strlcat(buf, dir + 2, MAXPATHLEN); - strlcat(buf, "/", MAXPATHLEN); + strlcat(buf, dir + 2, PATH_MAX); + strlcat(buf, "/", PATH_MAX); } - sz = strlcat(buf, fn, MAXPATHLEN); - if (sz >= MAXPATHLEN) { + sz = strlcat(buf, fn, PATH_MAX); + if (sz >= PATH_MAX) { WARNING(fn, basedir, "Path too long"); continue; }