]>
git.cameronkatri.com Git - mandoc.git/blob - apropos.c
1 /* $Id: apropos.c,v 1.23 2011/12/07 16:08:55 kristaps Exp $ */
3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 #include "apropos_db.h"
32 static int cmp(const void *, const void *);
33 static void list(struct res
*, size_t, void *);
34 static void usage(void);
36 static char *progname
;
39 main(int argc
, char *argv
[])
42 struct manpaths paths
;
46 char *defpaths
, *auxpaths
;
50 progname
= strrchr(argv
[0], '/');
56 whatis
= 0 == strncmp(progname
, "whatis", 6);
58 memset(&paths
, 0, sizeof(struct manpaths
));
59 memset(&opts
, 0, sizeof(struct opts
));
61 auxpaths
= defpaths
= NULL
;
64 while (-1 != (ch
= getopt(argc
, argv
, "M:m:S:s:")))
91 manpath_parse(&paths
, defpaths
, auxpaths
);
93 e
= whatis
? termcomp(argc
, argv
, &terms
) :
94 exprcomp(argc
, argv
, &terms
);
97 fprintf(stderr
, "%s: Bad expression\n", progname
);
102 (paths
.sz
, paths
.paths
,
103 &opts
, e
, terms
, NULL
, list
);
106 fprintf(stderr
, "%s: Error reading "
107 "manual database\n", progname
);
110 manpath_free(&paths
);
113 return(rc
? EXIT_SUCCESS
: EXIT_FAILURE
);
118 list(struct res
*res
, size_t sz
, void *arg
)
122 qsort(res
, sz
, sizeof(struct res
), cmp
);
124 for (i
= 0; i
< (int)sz
; i
++)
125 printf("%s(%s%s%s) - %s\n", res
[i
].title
,
127 *res
[i
].arch
? "/" : "",
128 *res
[i
].arch
? res
[i
].arch
: "",
133 cmp(const void *p1
, const void *p2
)
136 return(strcasecmp(((const struct res
*)p1
)->title
,
137 ((const struct res
*)p2
)->title
));
144 fprintf(stderr
, "usage: %s "