version 1.43, 2013/05/29 23:15:11 |
version 1.44, 2013/06/05 02:02:53 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#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 */ |
}; |
}; |
|
|
exit((int)MANDOCLEVEL_BADARG); |
exit((int)MANDOCLEVEL_BADARG); |
} |
} |
|
|
strlcat(mdb.dbn, pbuf, MAXPATHLEN); |
strlcat(mdb.dbn, pbuf, PATH_MAX); |
sz1 = strlcat(mdb.dbn, MANDOC_DB, MAXPATHLEN); |
sz1 = strlcat(mdb.dbn, MANDOC_DB, PATH_MAX); |
|
|
strlcat(mdb.idxn, pbuf, MAXPATHLEN); |
strlcat(mdb.idxn, pbuf, 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", mdb.idxn); |
fprintf(stderr, "%s: path too long\n", mdb.idxn); |
exit((int)MANDOCLEVEL_BADARG); |
exit((int)MANDOCLEVEL_BADARG); |
} |
} |
|
|
|
|
flags = O_CREAT | O_EXCL | O_RDWR; |
flags = O_CREAT | O_EXCL | O_RDWR; |
while (NULL == mdb.db) { |
while (NULL == mdb.db) { |
strlcpy(mdb.dbn, MANDOC_DB, MAXPATHLEN); |
strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX); |
strlcat(mdb.dbn, ".XXXXXXXXXX", MAXPATHLEN); |
strlcat(mdb.dbn, ".XXXXXXXXXX", PATH_MAX); |
if (NULL == mktemp(mdb.dbn)) { |
if (NULL == mktemp(mdb.dbn)) { |
perror(mdb.dbn); |
perror(mdb.dbn); |
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
|
|
} |
} |
} |
} |
while (NULL == mdb.idx) { |
while (NULL == mdb.idx) { |
strlcpy(mdb.idxn, MANDOC_IDX, MAXPATHLEN); |
strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX); |
strlcat(mdb.idxn, ".XXXXXXXXXX", MAXPATHLEN); |
strlcat(mdb.idxn, ".XXXXXXXXXX", PATH_MAX); |
if (NULL == mktemp(mdb.idxn)) { |
if (NULL == mktemp(mdb.idxn)) { |
perror(mdb.idxn); |
perror(mdb.idxn); |
unlink(mdb.dbn); |
unlink(mdb.dbn); |
|
|
ofile_argbuild(int argc, char *argv[], struct of **of, |
ofile_argbuild(int argc, char *argv[], struct of **of, |
const char *basedir) |
const char *basedir) |
{ |
{ |
char buf[MAXPATHLEN]; |
char buf[PATH_MAX]; |
char pbuf[PATH_MAX]; |
char pbuf[PATH_MAX]; |
const char *sec, *arch, *title; |
const char *sec, *arch, *title; |
char *relpath, *p; |
char *relpath, *p; |
|
|
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) |
int p_src_form, struct of **of) |
{ |
{ |
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; |
|
|
} |
} |
|
|
buf[0] = '\0'; |
buf[0] = '\0'; |
strlcat(buf, dir, MAXPATHLEN); |
strlcat(buf, dir, PATH_MAX); |
strlcat(buf, "/", MAXPATHLEN); |
strlcat(buf, "/", PATH_MAX); |
sz = strlcat(buf, fn, MAXPATHLEN); |
sz = strlcat(buf, fn, PATH_MAX); |
|
|
if (MAXPATHLEN <= sz) { |
if (PATH_MAX <= sz) { |
if (warnings) fprintf(stderr, "%s/%s: " |
if (warnings) fprintf(stderr, "%s/%s: " |
"path too long\n", dir, fn); |
"path too long\n", dir, fn); |
continue; |
continue; |
|
|
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--) |
|
|
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) { |
if (warnings) fprintf(stderr, |
if (warnings) fprintf(stderr, |
"%s/%s: path too long\n", |
"%s/%s: path too long\n", |
dir, fn); |
dir, fn); |
|
|
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) { |
if (warnings) fprintf(stderr, |
if (warnings) fprintf(stderr, |
"%s/%s: path too long\n", |
"%s/%s: path too long\n", |
dir, fn); |
dir, fn); |
|
|
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) { |
if (warnings) fprintf(stderr, |
if (warnings) fprintf(stderr, |
"%s/%s: path too long\n", dir, fn); |
"%s/%s: path too long\n", dir, fn); |
continue; |
continue; |