version 1.49, 2012/05/27 17:48:57 |
version 1.49.2.1, 2013/09/17 21:32:07 |
|
|
#include "config.h" |
#include "config.h" |
#endif |
#endif |
|
|
#include <sys/param.h> |
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
|
|
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <getopt.h> |
#include <getopt.h> |
|
#include <limits.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdint.h> |
#include <stdint.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
/* Access to the mandoc database on disk. */ |
/* Access to the mandoc database on disk. */ |
|
|
struct mdb { |
struct mdb { |
char idxn[MAXPATHLEN]; /* index db filename */ |
char idxn[PATH_MAX]; /* index db filename */ |
char dbn[MAXPATHLEN]; /* keyword db filename */ |
char dbn[PATH_MAX]; /* keyword db filename */ |
DB *idx; /* index recno database */ |
DB *idx; /* index recno database */ |
DB *db; /* keyword btree database */ |
DB *db; /* keyword btree database */ |
}; |
}; |
Line 305 main(int argc, char *argv[]) |
|
Line 305 main(int argc, char *argv[]) |
|
enum op op; /* current operation */ |
enum op op; /* current operation */ |
const char *dir; |
const char *dir; |
int ch, i, flags; |
int ch, i, flags; |
char dirbuf[MAXPATHLEN]; |
char dirbuf[PATH_MAX]; |
DB *hash; /* temporary keyword hashtable */ |
DB *hash; /* temporary keyword hashtable */ |
BTREEINFO info; /* btree configuration */ |
BTREEINFO info; /* btree configuration */ |
size_t sz1, sz2; |
size_t sz1, sz2; |
Line 416 main(int argc, char *argv[]) |
|
Line 416 main(int argc, char *argv[]) |
|
} |
} |
|
|
if (OP_UPDATE == op || OP_DELETE == op) { |
if (OP_UPDATE == op || OP_DELETE == op) { |
strlcat(mdb.dbn, dir, MAXPATHLEN); |
strlcat(mdb.dbn, dir, PATH_MAX); |
strlcat(mdb.dbn, "/", MAXPATHLEN); |
strlcat(mdb.dbn, "/", PATH_MAX); |
sz1 = strlcat(mdb.dbn, MANDOC_DB, MAXPATHLEN); |
sz1 = strlcat(mdb.dbn, MANDOC_DB, PATH_MAX); |
|
|
strlcat(mdb.idxn, dir, MAXPATHLEN); |
strlcat(mdb.idxn, dir, PATH_MAX); |
strlcat(mdb.idxn, "/", MAXPATHLEN); |
strlcat(mdb.idxn, "/", PATH_MAX); |
sz2 = strlcat(mdb.idxn, MANDOC_IDX, MAXPATHLEN); |
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); |
fprintf(stderr, "%s: path too long\n", dir); |
exit((int)MANDOCLEVEL_BADARG); |
exit((int)MANDOCLEVEL_BADARG); |
} |
} |
Line 492 main(int argc, char *argv[]) |
|
Line 492 main(int argc, char *argv[]) |
|
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
strlcpy(mdb.dbn, MANDOC_DB, MAXPATHLEN); |
strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX); |
strlcpy(mdb.idxn, MANDOC_IDX, MAXPATHLEN); |
strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX); |
|
|
flags = O_CREAT | O_TRUNC | O_RDWR; |
flags = O_CREAT | O_TRUNC | O_RDWR; |
mdb.db = dbopen(mdb.dbn, flags, 0644, DB_BTREE, &info); |
mdb.db = dbopen(mdb.dbn, flags, 0644, DB_BTREE, &info); |
Line 511 main(int argc, char *argv[]) |
|
Line 511 main(int argc, char *argv[]) |
|
* Search for manuals and fill the new database. |
* 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); |
ofile_dirbuild(".", "", "", 0, &of, dirbuf); |
|
|
if (NULL != of) { |
if (NULL != of) { |
|
|
ofile_argbuild(int argc, char *argv[], |
ofile_argbuild(int argc, char *argv[], |
struct of **of, const char *basedir) |
struct of **of, const char *basedir) |
{ |
{ |
char buf[MAXPATHLEN]; |
char buf[PATH_MAX]; |
const char *sec, *arch, *title; |
const char *sec, *arch, *title; |
char *p; |
char *p; |
int i, src_form; |
int i, src_form; |
|
|
ofile_dirbuild(const char *dir, const char* psec, const char *parch, |
ofile_dirbuild(const char *dir, const char* psec, const char *parch, |
int p_src_form, struct of **of, char *basedir) |
int p_src_form, struct of **of, char *basedir) |
{ |
{ |
char buf[MAXPATHLEN]; |
char buf[PATH_MAX]; |
size_t sz; |
size_t sz; |
DIR *d; |
DIR *d; |
const char *fn, *sec, *arch; |
const char *fn, *sec, *arch; |
Line 1749 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1749 ofile_dirbuild(const char *dir, const char* psec, cons |
|
} |
} |
|
|
buf[0] = '\0'; |
buf[0] = '\0'; |
strlcat(buf, dir, MAXPATHLEN); |
strlcat(buf, dir, PATH_MAX); |
strlcat(buf, "/", MAXPATHLEN); |
strlcat(buf, "/", PATH_MAX); |
strlcat(basedir, "/", MAXPATHLEN); |
strlcat(basedir, "/", PATH_MAX); |
strlcat(basedir, fn, MAXPATHLEN); |
strlcat(basedir, fn, PATH_MAX); |
sz = strlcat(buf, fn, MAXPATHLEN); |
sz = strlcat(buf, fn, PATH_MAX); |
|
|
if (MAXPATHLEN <= sz) { |
if (PATH_MAX <= sz) { |
WARNING(fn, basedir, "Path too long"); |
WARNING(fn, basedir, "Path too long"); |
continue; |
continue; |
} |
} |
Line 1814 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1814 ofile_dirbuild(const char *dir, const char* psec, cons |
|
if (0 == use_all && MANDOC_FORM & src_form && |
if (0 == use_all && MANDOC_FORM & src_form && |
'\0' != *psec) { |
'\0' != *psec) { |
buf[0] = '\0'; |
buf[0] = '\0'; |
strlcat(buf, dir, MAXPATHLEN); |
strlcat(buf, dir, PATH_MAX); |
p = strrchr(buf, '/'); |
p = strrchr(buf, '/'); |
if ('\0' != *parch && NULL != p) |
if ('\0' != *parch && NULL != p) |
for (p--; p > buf; p--) |
for (p--; p > buf; p--) |
Line 1826 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1826 ofile_dirbuild(const char *dir, const char* psec, cons |
|
p++; |
p++; |
if (0 == strncmp("cat", p, 3)) |
if (0 == strncmp("cat", p, 3)) |
memcpy(p, "man", 3); |
memcpy(p, "man", 3); |
strlcat(buf, "/", MAXPATHLEN); |
strlcat(buf, "/", PATH_MAX); |
sz = strlcat(buf, fn, MAXPATHLEN); |
sz = strlcat(buf, fn, PATH_MAX); |
if (sz >= MAXPATHLEN) { |
if (sz >= PATH_MAX) { |
WARNING(fn, basedir, "Path too long"); |
WARNING(fn, basedir, "Path too long"); |
continue; |
continue; |
} |
} |
q = strrchr(buf, '.'); |
q = strrchr(buf, '.'); |
if (NULL != q && p < q++) { |
if (NULL != q && p < q++) { |
*q = '\0'; |
*q = '\0'; |
sz = strlcat(buf, psec, MAXPATHLEN); |
sz = strlcat(buf, psec, PATH_MAX); |
if (sz >= MAXPATHLEN) { |
if (sz >= PATH_MAX) { |
WARNING(fn, basedir, "Path too long"); |
WARNING(fn, basedir, "Path too long"); |
continue; |
continue; |
} |
} |
Line 1848 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1848 ofile_dirbuild(const char *dir, const char* psec, cons |
|
buf[0] = '\0'; |
buf[0] = '\0'; |
assert('.' == dir[0]); |
assert('.' == dir[0]); |
if ('/' == dir[1]) { |
if ('/' == dir[1]) { |
strlcat(buf, dir + 2, MAXPATHLEN); |
strlcat(buf, dir + 2, PATH_MAX); |
strlcat(buf, "/", MAXPATHLEN); |
strlcat(buf, "/", PATH_MAX); |
} |
} |
sz = strlcat(buf, fn, MAXPATHLEN); |
sz = strlcat(buf, fn, PATH_MAX); |
if (sz >= MAXPATHLEN) { |
if (sz >= PATH_MAX) { |
WARNING(fn, basedir, "Path too long"); |
WARNING(fn, basedir, "Path too long"); |
continue; |
continue; |
} |
} |