From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p33AEkXa019928 for ; Sun, 3 Apr 2011 06:14:46 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p33AEkoo026453; Sun, 3 Apr 2011 06:14:46 -0400 (EDT) Date: Sun, 3 Apr 2011 06:14:46 -0400 (EDT) Message-Id: <201104031014.p33AEkoo026453@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Have mandoc-db use config.h for strlcat(). X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Have mandoc-db use config.h for strlcat(). Then create the btree database from a directory, instead of a path. This is because it'll also output an index of files to that same directory. Add documentation to the local variable names, too. Modified Files: -------------- mdocml: Makefile mandoc-db.c Revision Data ------------- Index: mandoc-db.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc-db.c,v retrieving revision 1.1 retrieving revision 1.2 diff -Lmandoc-db.c -Lmandoc-db.c -u -p -r1.1 -r1.2 --- mandoc-db.c +++ mandoc-db.c @@ -14,6 +14,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include @@ -34,7 +38,7 @@ #include "mandoc.h" #define MANDOC_DB "mandoc.db" -#define MANDOC_BUFSZ 10 +#define MANDOC_BUFSZ BUFSIZ enum type { MANDOC_NONE = 0, @@ -201,32 +205,32 @@ static const pmdoc_nf mdocs[MDOC_MAX] int main(int argc, char *argv[]) { - struct mparse *mp; - struct mdoc *mdoc; - struct man *man; - const char *f, *fn; - size_t sz; - char fbuf[MAXPATHLEN]; + struct mparse *mp; /* parse sequence */ + struct mdoc *mdoc; /* resulting mdoc */ + const char *fn, + *dir; /* result dir (default: cwd) */ + char fbuf[MAXPATHLEN], /* btree fname */ + fbbuf[MAXPATHLEN]; /* btree backup fname */ int c; - DB *db; - DBT key, val; - size_t ksz, vsz; - BTREEINFO info; + DB *db; /* open database */ + DBT key, val; /* persistent entries */ + size_t ksz, vsz; /* entry buffer sizes */ + BTREEINFO info; /* btree configuration */ extern int optind; extern char *optarg; - f = MANDOC_DB; - progname = strrchr(argv[0], '/'); if (progname == NULL) progname = argv[0]; else ++progname; - while (-1 != (c = getopt(argc, argv, "f:V"))) + dir = "./"; + + while (-1 != (c = getopt(argc, argv, "d:V"))) switch (c) { - case ('f'): - f = optarg; + case ('d'): + dir = optarg; break; case ('V'): version(); @@ -245,15 +249,20 @@ main(int argc, char *argv[]) * file-name after we've written all of our data. */ - if (0 == (sz = strlen(f)) || sz + 5 >= MAXPATHLEN) { + fbuf[0] = fbuf[MAXPATHLEN - 2] = + fbbuf[0] = fbbuf[MAXPATHLEN - 1] = '\0'; + + strlcat(fbuf, dir, MAXPATHLEN); + strlcat(fbuf, MANDOC_DB, MAXPATHLEN); + strlcat(fbbuf, fbuf, MAXPATHLEN); + strlcat(fbbuf, "~", MAXPATHLEN); + + if ('\0' != fbuf[MAXPATHLEN - 2] || + '\0' != fbbuf[MAXPATHLEN - 2]) { fprintf(stderr, "%s: Bad filename\n", progname); exit((int)MANDOCLEVEL_SYSERR); } - memcpy(fbuf, f, sz); - memcpy(fbuf + (int)sz, ".bak", 4); - fbuf[(int)sz + 4] = '\0'; - /* * Open a BTREE database that allows duplicates. If the * database already exists (it's a backup anyway), then blow it @@ -263,11 +272,11 @@ main(int argc, char *argv[]) memset(&info, 0, sizeof(BTREEINFO)); info.flags = R_DUP; - db = dbopen(fbuf, O_CREAT|O_TRUNC|O_RDWR, + db = dbopen(fbbuf, O_CREAT|O_TRUNC|O_RDWR, 0644, DB_BTREE, &info); if (NULL == db) { - perror(f); + perror(fbbuf); exit((int)MANDOCLEVEL_SYSERR); } @@ -286,13 +295,12 @@ main(int argc, char *argv[]) ksz = vsz = 0; while (NULL != (fn = *argv++)) { - printf("Trying: %s\n", fn); mparse_reset(mp); if (mparse_readfd(mp, -1, fn) >= MANDOCLEVEL_FATAL) continue; - mparse_result(mp, &mdoc, &man); + mparse_result(mp, &mdoc, NULL); if (mdoc) - pmdoc(db, fbuf, &key, &ksz, + pmdoc(db, fbbuf, &key, &ksz, &val, &vsz, fn, mdoc); } @@ -304,8 +312,8 @@ main(int argc, char *argv[]) /* Atomically replace the file with our temporary one. */ - if (-1 == rename(fbuf, f)) - perror(f); + if (-1 == rename(fbbuf, fbuf)) + perror(fbuf); return((int)MANDOCLEVEL_OK); } @@ -630,7 +638,7 @@ usage(void) fprintf(stderr, "usage: %s " "[-V] " - "[-f path] " + "[-d path] " "[file...]\n", progname); } Index: Makefile =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v retrieving revision 1.326 retrieving revision 1.327 diff -LMakefile -LMakefile -u -p -r1.326 -r1.327 --- Makefile +++ Makefile @@ -216,7 +216,7 @@ compat.o compat.ln: config.h MANDOCDB_OBJS = mandoc-db.o MANDOCDB_LNS = mandoc-db.ln -$(MANDOCDB_OBJS) $(MANDOCDB_LNS): mandoc.h mdoc.h man.h +$(MANDOCDB_OBJS) $(MANDOCDB_LNS): mandoc.h mdoc.h man.h config.h INDEX_MANS = mandoc.1.html \ mandoc.1.xhtml \ @@ -316,8 +316,8 @@ mandoc: $(MANDOC_OBJS) libmandoc.a $(CC) -o $@ $(MANDOC_OBJS) libmandoc.a # You'll need -ldb for Linux. -mandoc-db: mandoc-db.o libmandoc.a - $(CC) -o $@ mandoc-db.o libmandoc.a +mandoc-db: $(MANDOCDB_OBJS) libmandoc.a + $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a llib-lmandoc.ln: $(MANDOC_LNS) $(LINT) $(LINTFLAGS) -Cmandoc $(MANDOC_LNS) -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv