version 1.13, 2011/11/14 10:07:06 |
version 1.14, 2011/11/18 07:02:19 |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
|
|
static int cmp(const void *, const void *); |
static int cmp(const void *, const void *); |
static void list(struct rec *, size_t, void *); |
static void list(struct res *, size_t, void *); |
static void usage(void); |
static void usage(void); |
|
|
static char *progname; |
static char *progname; |
|
|
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
int ch; |
int ch; |
size_t sz; |
size_t terms; |
char *buf; |
|
struct opts opts; |
struct opts opts; |
struct expr *e; |
struct expr *e; |
extern int optind; |
extern int optind; |
Line 72 main(int argc, char *argv[]) |
|
Line 71 main(int argc, char *argv[]) |
|
if (0 == argc) |
if (0 == argc) |
return(EXIT_SUCCESS); |
return(EXIT_SUCCESS); |
|
|
/* |
if (NULL == (e = exprcomp(argc, argv, &terms))) { |
* Collapse expressions into a single string. |
|
* First count up the contained strings, adding a space at the |
|
* end of each (plus nil-terminator). Then merge. |
|
*/ |
|
|
|
for (sz = 0, ch = 0; ch < argc; ch++) |
|
sz += strlen(argv[ch]) + 1; |
|
|
|
buf = mandoc_malloc(++sz); |
|
|
|
for (*buf = '\0', ch = 0; ch < argc; ch++) { |
|
strlcat(buf, argv[ch], sz); |
|
strlcat(buf, " ", sz); |
|
} |
|
|
|
buf[sz - 2] = '\0'; |
|
|
|
if (NULL == (e = exprcomp(buf))) { |
|
fprintf(stderr, "Bad expression\n"); |
fprintf(stderr, "Bad expression\n"); |
free(buf); |
|
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |
|
|
free(buf); |
|
|
|
/* |
/* |
* Configure databases. |
* Configure databases. |
* The keyword database is a btree that allows for duplicate |
* The keyword database is a btree that allows for duplicate |
Line 105 main(int argc, char *argv[]) |
|
Line 83 main(int argc, char *argv[]) |
|
* The index database is a recno. |
* The index database is a recno. |
*/ |
*/ |
|
|
apropos_search(&opts, e, NULL, list); |
ch = apropos_search(&opts, e, terms, NULL, list); |
exprfree(e); |
exprfree(e); |
return(EXIT_SUCCESS); |
if (0 == ch) |
|
fprintf(stderr, "%s: Database error\n", progname); |
|
return(ch ? EXIT_SUCCESS : EXIT_FAILURE); |
} |
} |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
static void |
list(struct rec *res, size_t sz, void *arg) |
list(struct res *res, size_t sz, void *arg) |
{ |
{ |
int i; |
int i; |
|
|
qsort(res, sz, sizeof(struct rec), cmp); |
qsort(res, sz, sizeof(struct res), cmp); |
|
|
for (i = 0; i < (int)sz; i++) |
for (i = 0; i < (int)sz; i++) |
printf("%s(%s%s%s) - %s\n", res[i].title, |
printf("%s(%s%s%s) - %s\n", res[i].title, |
|
|
cmp(const void *p1, const void *p2) |
cmp(const void *p1, const void *p2) |
{ |
{ |
|
|
return(strcmp(((const struct rec *)p1)->title, |
return(strcmp(((const struct res *)p1)->title, |
((const struct rec *)p2)->title)); |
((const struct res *)p2)->title)); |
} |
} |
|
|
static void |
static void |
usage(void) |
usage(void) |
{ |
{ |
|
|
fprintf(stderr, "usage: %s " |
fprintf(stderr, "usage: %s [-S arch] [-s section] " |
"[-I] " |
"expression...\n", progname); |
"[-S arch] " |
|
"[-s section] " |
|
"EXPR\n", |
|
progname); |
|
} |
} |