version 1.16, 2011/11/27 23:27:31 |
version 1.18, 2011/12/01 21:05:49 |
|
|
#include <stdint.h> |
#include <stdint.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <unistd.h> |
|
|
#ifdef __linux__ |
#ifdef __linux__ |
# include <db_185.h> |
# include <db_185.h> |
Line 383 main(int argc, char *argv[]) |
|
Line 384 main(int argc, char *argv[]) |
|
index_prune(of, db, fbuf, idx, ibuf, |
index_prune(of, db, fbuf, idx, ibuf, |
&maxrec, &recs, &recsz); |
&maxrec, &recs, &recsz); |
|
|
if (OP_UPDATE == op) |
/* |
|
* Go to the root of the respective manual tree |
|
* such that .so links work. In case of failure, |
|
* just prod on, even though .so links won't work. |
|
*/ |
|
|
|
if (OP_UPDATE == op) { |
|
chdir(dir); |
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); |
|
} |
|
|
goto out; |
goto out; |
} |
} |
Line 455 main(int argc, char *argv[]) |
|
Line 464 main(int argc, char *argv[]) |
|
|
|
of = of->first; |
of = of->first; |
|
|
|
/* |
|
* Go to the root of the respective manual tree |
|
* such that .so links work. In case of failure, |
|
* just prod on, even though .so links won't work. |
|
*/ |
|
|
|
chdir(dirs.paths[i]); |
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 619 index_merge(const struct of *of, struct mparse *mp, |
|
Line 635 index_merge(const struct of *of, struct mparse *mp, |
|
val.size = sizeof(struct db_val); |
val.size = sizeof(struct db_val); |
val.data = &vbuf; |
val.data = &vbuf; |
|
|
if (verb > 1) |
|
printf("%s: Added keyword: %s\n", |
|
fn, (char *)key.data); |
|
dbt_put(db, dbf, &key, &val); |
dbt_put(db, dbf, &key, &val); |
} |
} |
if (ch < 0) { |
if (ch < 0) { |
Line 645 index_merge(const struct of *of, struct mparse *mp, |
|
Line 658 index_merge(const struct of *of, struct mparse *mp, |
|
|
|
if (verb) |
if (verb) |
printf("%s: Added index\n", fn); |
printf("%s: Added index\n", fn); |
|
|
dbt_put(idx, idxf, &key, &val); |
dbt_put(idx, idxf, &key, &val); |
} |
} |
} |
} |
Line 661 index_prune(const struct of *ofile, DB *db, const char |
|
Line 675 index_prune(const struct of *ofile, DB *db, const char |
|
recno_t *maxrec, recno_t **recs, size_t *recsz) |
recno_t *maxrec, recno_t **recs, size_t *recsz) |
{ |
{ |
const struct of *of; |
const struct of *of; |
const char *fn; |
const char *fn, *cp; |
struct db_val *vbuf; |
struct db_val *vbuf; |
unsigned seq, sseq; |
unsigned seq, sseq; |
DBT key, val; |
DBT key, val; |
Line 673 index_prune(const struct of *ofile, DB *db, const char |
|
Line 687 index_prune(const struct of *ofile, DB *db, const char |
|
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; |
*maxrec = *(recno_t *)key.data; |
if (0 == val.size) { |
cp = val.data; |
if (reccur >= *recsz) { |
|
*recsz += MANDOC_SLOP; |
|
*recs = mandoc_realloc(*recs, |
|
*recsz * sizeof(recno_t)); |
|
} |
|
(*recs)[(int)reccur] = *maxrec; |
|
reccur++; |
|
continue; |
|
} |
|
|
|
fn = (char *)val.data; |
/* Deleted records are zero-sized. Skip them. */ |
|
|
|
if (0 == val.size) |
|
goto cont; |
|
|
|
/* |
|
* Make sure we're sane. |
|
* Read past our mdoc/man/cat type to the next string, |
|
* then make sure it's bounded by a NUL. |
|
* Failing any of these, we go into our error handler. |
|
*/ |
|
|
|
if (NULL == (fn = memchr(cp, '\0', val.size))) |
|
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. |
|
* XXX: build this into a tree. Too slow. |
|
*/ |
|
|
for (of = ofile; of; of = of->next) |
for (of = ofile; of; of = of->next) |
if (0 == strcmp(fn, of->fname)) |
if (0 == strcmp(fn, of->fname)) |
break; |
break; |
Line 692 index_prune(const struct of *ofile, DB *db, const char |
|
Line 720 index_prune(const struct of *ofile, DB *db, const char |
|
if (NULL == of) |
if (NULL == of) |
continue; |
continue; |
|
|
|
/* |
|
* Search through the keyword database, throwing out all |
|
* references to our file. |
|
*/ |
|
|
sseq = R_FIRST; |
sseq = R_FIRST; |
while (0 == (ch = (*db->seq)(db, &key, &val, sseq))) { |
while (0 == (ch = (*db->seq)(db, &key, &val, sseq))) { |
sseq = R_NEXT; |
sseq = R_NEXT; |
assert(sizeof(struct db_val) == val.size); |
if (sizeof(struct db_val) != val.size) |
|
break; |
|
|
vbuf = val.data; |
vbuf = val.data; |
if (*maxrec != vbuf->rec) |
if (*maxrec != vbuf->rec) |
continue; |
continue; |
if (verb) |
|
printf("%s: Deleted keyword: %s\n", |
if ((ch = (*db->del)(db, &key, R_CURSOR)) < 0) |
fn, (char *)key.data); |
|
ch = (*db->del)(db, &key, R_CURSOR); |
|
if (ch < 0) |
|
break; |
break; |
} |
} |
|
|
if (ch < 0) { |
if (ch < 0) { |
perror(dbf); |
perror(dbf); |
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
|
} else if (1 != ch) { |
|
fprintf(stderr, "%s: Corrupt database\n", dbf); |
|
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
if (verb) |
if (verb) |
Line 716 index_prune(const struct of *ofile, DB *db, const char |
|
Line 752 index_prune(const struct of *ofile, DB *db, const char |
|
|
|
val.size = 0; |
val.size = 0; |
ch = (*idx->put)(idx, &key, &val, R_CURSOR); |
ch = (*idx->put)(idx, &key, &val, R_CURSOR); |
if (ch < 0) { |
|
perror(idxf); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
|
|
|
|
if (ch < 0) |
|
break; |
|
cont: |
if (reccur >= *recsz) { |
if (reccur >= *recsz) { |
*recsz += MANDOC_SLOP; |
*recsz += MANDOC_SLOP; |
*recs = mandoc_realloc |
*recs = mandoc_realloc |
Line 730 index_prune(const struct of *ofile, DB *db, const char |
|
Line 765 index_prune(const struct of *ofile, DB *db, const char |
|
(*recs)[(int)reccur] = *maxrec; |
(*recs)[(int)reccur] = *maxrec; |
reccur++; |
reccur++; |
} |
} |
|
|
|
if (ch < 0) { |
|
perror(idxf); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} else if (1 != ch) { |
|
fprintf(stderr, "%s: Corrupt index\n", idxf); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
|
|
(*maxrec)++; |
(*maxrec)++; |
} |
} |
|
|