]>
git.cameronkatri.com Git - mandoc.git/blob - apropos.c
1 /* $Id: apropos.c,v 1.24 2011/12/12 02:00:49 schwarze 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
;
51 progname
= strrchr(argv
[0], '/');
57 whatis
= 0 == strncmp(progname
, "whatis", 6);
59 memset(&paths
, 0, sizeof(struct manpaths
));
60 memset(&opts
, 0, sizeof(struct opts
));
62 auxpaths
= defpaths
= NULL
;
66 while (-1 != (ch
= getopt(argc
, argv
, "C:M:m:S:s:")))
96 manpath_parse(&paths
, conf_file
, defpaths
, auxpaths
);
98 e
= whatis
? termcomp(argc
, argv
, &terms
) :
99 exprcomp(argc
, argv
, &terms
);
102 fprintf(stderr
, "%s: Bad expression\n", progname
);
107 (paths
.sz
, paths
.paths
,
108 &opts
, e
, terms
, NULL
, list
);
111 fprintf(stderr
, "%s: Error reading "
112 "manual database\n", progname
);
115 manpath_free(&paths
);
118 return(rc
? EXIT_SUCCESS
: EXIT_FAILURE
);
123 list(struct res
*res
, size_t sz
, void *arg
)
127 qsort(res
, sz
, sizeof(struct res
), cmp
);
129 for (i
= 0; i
< (int)sz
; i
++)
130 printf("%s(%s%s%s) - %s\n", res
[i
].title
,
132 *res
[i
].arch
? "/" : "",
133 *res
[i
].arch
? res
[i
].arch
: "",
138 cmp(const void *p1
, const void *p2
)
141 return(strcasecmp(((const struct res
*)p1
)->title
,
142 ((const struct res
*)p2
)->title
));
149 fprintf(stderr
, "usage: %s "