version 1.34, 2011/12/12 02:00:49 |
version 1.37, 2011/12/20 21:41:11 |
|
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <dirent.h> |
#include <dirent.h> |
Line 110 static void index_prune(const struct of *, DB *, |
|
Line 109 static void index_prune(const struct of *, DB *, |
|
recno_t *, recno_t **, size_t *, |
recno_t *, recno_t **, size_t *, |
size_t *); |
size_t *); |
static void ofile_argbuild(int, char *[], struct of **); |
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 **); |
const char *, int, struct of **); |
static void ofile_free(struct of *); |
static void ofile_free(struct of *); |
static void pformatted(DB *, struct buf *, struct buf *, |
static void pformatted(DB *, struct buf *, struct buf *, |
Line 384 main(int argc, char *argv[]) |
|
Line 383 main(int argc, char *argv[]) |
|
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
if (verb > 2) { |
|
printf("%s: Opened\n", fbuf); |
|
printf("%s: Opened\n", ibuf); |
|
} |
|
|
|
ofile_argbuild(argc, argv, &of); |
ofile_argbuild(argc, argv, &of); |
|
|
if (NULL == of) |
if (NULL == of) |
goto out; |
goto out; |
|
|
Line 399 main(int argc, char *argv[]) |
|
Line 394 main(int argc, char *argv[]) |
|
&maxrec, &recs, &recsz, &reccur); |
&maxrec, &recs, &recsz, &reccur); |
|
|
/* |
/* |
* Go to the root of the respective manual tree |
* Go to the root of the respective manual tree. |
* such that .so links work. In case of failure, |
* This must work or no manuals may be found (they're |
* just prod on, even though .so links won't work. |
* indexed relative to the root). |
*/ |
*/ |
|
|
if (OP_UPDATE == op) { |
if (OP_UPDATE == op) { |
chdir(dir); |
if (-1 == chdir(dir)) { |
|
perror(dir); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
index_merge(of, mp, &dbuf, &buf, hash, |
index_merge(of, mp, &dbuf, &buf, hash, |
db, fbuf, idx, ibuf, |
db, fbuf, idx, ibuf, |
maxrec, recs, reccur); |
maxrec, recs, reccur); |
Line 466 main(int argc, char *argv[]) |
|
Line 464 main(int argc, char *argv[]) |
|
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
if (verb > 2) { |
|
printf("%s: Truncated\n", fbuf); |
|
printf("%s: Truncated\n", ibuf); |
|
} |
|
|
|
ofile_free(of); |
ofile_free(of); |
of = NULL; |
of = NULL; |
|
|
if ( ! ofile_dirbuild(dirs.paths[i], NULL, NULL, |
if (-1 == chdir(dirs.paths[i])) { |
0, &of)) |
perror(dirs.paths[i]); |
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
|
|
|
ofile_dirbuild(".", NULL, NULL, 0, &of); |
|
|
if (NULL == of) |
if (NULL == of) |
continue; |
continue; |
|
|
of = of->first; |
of = of->first; |
|
|
/* |
/* |
* Go to the root of the respective manual tree |
* Go to the root of the respective manual tree. |
* such that .so links work. In case of failure, |
* This must work or no manuals may be found (they're |
* just prod on, even though .so links won't work. |
* 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, |
index_merge(of, mp, &dbuf, &buf, hash, db, fbuf, |
idx, ibuf, maxrec, recs, reccur); |
idx, ibuf, maxrec, recs, reccur); |
} |
} |
Line 525 index_merge(const struct of *of, struct mparse *mp, |
|
Line 525 index_merge(const struct of *of, struct mparse *mp, |
|
struct mdoc *mdoc; |
struct mdoc *mdoc; |
struct man *man; |
struct man *man; |
const char *fn, *msec, *mtitle, *arch; |
const char *fn, *msec, *mtitle, *arch; |
|
uint64_t mask; |
size_t sv; |
size_t sv; |
unsigned seq; |
unsigned seq; |
struct db_val vbuf; |
struct db_val vbuf; |
|
char type; |
|
|
for (rec = 0; of; of = of->next) { |
for (rec = 0; of; of = of->next) { |
fn = of->fname; |
fn = of->fname; |
Line 608 index_merge(const struct of *of, struct mparse *mp, |
|
Line 610 index_merge(const struct of *of, struct mparse *mp, |
|
*/ |
*/ |
|
|
dbuf->len = 0; |
dbuf->len = 0; |
buf_append(dbuf, mdoc ? "mdoc" : (man ? "man" : "cat")); |
type = mdoc ? 'd' : (man ? 'a' : 'c'); |
|
buf_appendb(dbuf, &type, 1); |
buf_appendb(dbuf, fn, strlen(fn) + 1); |
buf_appendb(dbuf, fn, strlen(fn) + 1); |
buf_appendb(dbuf, msec, strlen(msec) + 1); |
buf_appendb(dbuf, msec, strlen(msec) + 1); |
buf_appendb(dbuf, mtitle, strlen(mtitle) + 1); |
buf_appendb(dbuf, mtitle, strlen(mtitle) + 1); |
Line 653 index_merge(const struct of *of, struct mparse *mp, |
|
Line 656 index_merge(const struct of *of, struct mparse *mp, |
|
seq = R_FIRST; |
seq = R_FIRST; |
while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) { |
while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) { |
seq = R_NEXT; |
seq = R_NEXT; |
vbuf.mask = htobe64(*(uint64_t *)val.data); |
assert(sizeof(uint64_t) == val.size); |
|
memcpy(&mask, val.data, val.size); |
|
vbuf.mask = htobe64(mask); |
val.size = sizeof(struct db_val); |
val.size = sizeof(struct db_val); |
val.data = &vbuf; |
val.data = &vbuf; |
dbt_put(db, dbf, &key, &val); |
dbt_put(db, dbf, &key, &val); |
Line 696 index_prune(const struct of *ofile, DB *db, const char |
|
Line 701 index_prune(const struct of *ofile, DB *db, const char |
|
recno_t **recs, size_t *recsz, size_t *reccur) |
recno_t **recs, size_t *recsz, size_t *reccur) |
{ |
{ |
const struct of *of; |
const struct of *of; |
const char *fn, *cp; |
const char *fn; |
struct db_val *vbuf; |
struct db_val *vbuf; |
unsigned seq, sseq; |
unsigned seq, sseq; |
DBT key, val; |
DBT key, val; |
Line 706 index_prune(const struct of *ofile, DB *db, const char |
|
Line 711 index_prune(const struct of *ofile, DB *db, const char |
|
seq = R_FIRST; |
seq = R_FIRST; |
while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) { |
while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) { |
seq = R_NEXT; |
seq = R_NEXT; |
*maxrec = *(recno_t *)key.data; |
assert(sizeof(recno_t) == key.size); |
cp = val.data; |
memcpy(maxrec, key.data, key.size); |
|
|
/* Deleted records are zero-sized. Skip them. */ |
/* Deleted records are zero-sized. Skip them. */ |
|
|
Line 721 index_prune(const struct of *ofile, DB *db, const char |
|
Line 726 index_prune(const struct of *ofile, DB *db, const char |
|
* Failing any of these, we go into our error handler. |
* Failing any of these, we go into our error handler. |
*/ |
*/ |
|
|
if (NULL == (fn = memchr(cp, '\0', val.size))) |
fn = (char *)val.data + 1; |
|
if (NULL == memchr(fn, '\0', val.size - 1)) |
break; |
break; |
if (++fn - cp >= (int)val.size) |
|
break; |
|
if (NULL == memchr(fn, '\0', val.size - (fn - cp))) |
|
break; |
|
|
|
/* |
/* |
* Search for the file in those we care about. |
* Search for the file in those we care about. |
Line 1070 pmdoc_Sh(MDOC_ARGS) |
|
Line 1072 pmdoc_Sh(MDOC_ARGS) |
|
static void |
static void |
hash_put(DB *db, const struct buf *buf, uint64_t mask) |
hash_put(DB *db, const struct buf *buf, uint64_t mask) |
{ |
{ |
|
uint64_t oldmask; |
DBT key, val; |
DBT key, val; |
int rc; |
int rc; |
|
|
Line 1082 hash_put(DB *db, const struct buf *buf, uint64_t mask) |
|
Line 1085 hash_put(DB *db, const struct buf *buf, uint64_t mask) |
|
if ((rc = (*db->get)(db, &key, &val, 0)) < 0) { |
if ((rc = (*db->get)(db, &key, &val, 0)) < 0) { |
perror("hash"); |
perror("hash"); |
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} else if (0 == rc) |
} else if (0 == rc) { |
mask |= *(uint64_t *)val.data; |
assert(sizeof(uint64_t) == val.size); |
|
memcpy(&oldmask, val.data, val.size); |
|
mask |= oldmask; |
|
} |
|
|
val.data = &mask; |
val.data = &mask; |
val.size = sizeof(uint64_t); |
val.size = sizeof(uint64_t); |
Line 1434 ofile_argbuild(int argc, char *argv[], struct of **of) |
|
Line 1440 ofile_argbuild(int argc, char *argv[], struct of **of) |
|
* Add the structure to the list. |
* Add the structure to the list. |
*/ |
*/ |
|
|
if (verb > 2) |
|
printf("%s: Scheduling\n", argv[i]); |
|
if (NULL == *of) { |
if (NULL == *of) { |
*of = nof; |
*of = nof; |
(*of)->first = nof; |
(*of)->first = nof; |
Line 1455 ofile_argbuild(int argc, char *argv[], struct of **of) |
|
Line 1459 ofile_argbuild(int argc, char *argv[], struct of **of) |
|
* everything else is a manual. |
* everything else is a manual. |
* Pass in a pointer to a NULL structure for the first invocation. |
* 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, |
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[MAXPATHLEN]; |
struct stat sb; |
|
size_t sz; |
size_t sz; |
DIR *d; |
DIR *d; |
const char *fn, *sec, *arch; |
const char *fn, *sec, *arch; |
Line 1471 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1474 ofile_dirbuild(const char *dir, const char* psec, cons |
|
|
|
if (NULL == (d = opendir(dir))) { |
if (NULL == (d = opendir(dir))) { |
perror(dir); |
perror(dir); |
return(0); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
while (NULL != (dp = readdir(d))) { |
while (NULL != (dp = readdir(d))) { |
Line 1516 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1519 ofile_dirbuild(const char *dir, const char* psec, cons |
|
|
|
if (MAXPATHLEN <= sz) { |
if (MAXPATHLEN <= sz) { |
fprintf(stderr, "%s: Path too long\n", dir); |
fprintf(stderr, "%s: Path too long\n", dir); |
return(0); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
if (verb > 2) |
ofile_dirbuild(buf, sec, arch, src_form, of); |
printf("%s: Scanning\n", buf); |
|
|
|
if ( ! ofile_dirbuild(buf, sec, arch, |
|
src_form, of)) |
|
return(0); |
|
} |
} |
|
|
if (DT_REG != dp->d_type || |
if (DT_REG != dp->d_type || |
(NULL == psec && !use_all) || |
(NULL == psec && !use_all) || |
!strcmp(MANDOC_DB, fn) || |
! strcmp(MANDOC_DB, fn) || |
!strcmp(MANDOC_IDX, fn)) |
! strcmp(MANDOC_IDX, fn)) |
continue; |
continue; |
|
|
/* |
/* |
Line 1593 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1592 ofile_dirbuild(const char *dir, const char* psec, cons |
|
"%s: Path too long\n", buf); |
"%s: Path too long\n", buf); |
continue; |
continue; |
} |
} |
if (0 == stat(buf, &sb)) |
if (0 == access(buf, R_OK)) |
continue; |
continue; |
} |
} |
} |
} |
|
|
|
assert('.' == dir[0]); |
|
assert('/' == dir[1]); |
buf[0] = '\0'; |
buf[0] = '\0'; |
strlcat(buf, dir, MAXPATHLEN); |
strlcat(buf, dir + 2, MAXPATHLEN); |
strlcat(buf, "/", MAXPATHLEN); |
strlcat(buf, "/", MAXPATHLEN); |
sz = strlcat(buf, fn, MAXPATHLEN); |
sz = strlcat(buf, fn, MAXPATHLEN); |
if (sz >= MAXPATHLEN) { |
if (sz >= MAXPATHLEN) { |
Line 1628 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1629 ofile_dirbuild(const char *dir, const char* psec, cons |
|
* Add the structure to the list. |
* Add the structure to the list. |
*/ |
*/ |
|
|
if (verb > 2) |
|
printf("%s: Scheduling\n", buf); |
|
if (NULL == *of) { |
if (NULL == *of) { |
*of = nof; |
*of = nof; |
(*of)->first = nof; |
(*of)->first = nof; |
Line 1641 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1640 ofile_dirbuild(const char *dir, const char* psec, cons |
|
} |
} |
|
|
closedir(d); |
closedir(d); |
return(1); |
|
} |
} |
|
|
static void |
static void |