1 /* $Id: apropos.c,v 1.39 2014/04/20 16:46:04 schwarze Exp $ */
3 * Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013 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.
21 #include <sys/param.h>
32 #include "mansearch.h"
36 main(int argc, char *argv[])
39 struct mansearch search;
42 struct manpaths paths;
43 char *defpaths, *auxpaths;
50 progname = strrchr(argv[0], '/');
56 whatis = (0 == strncmp(progname, "whatis", 6));
58 memset(&paths, 0, sizeof(struct manpaths));
59 memset(&search, 0, sizeof(struct mansearch));
61 auxpaths = defpaths = NULL;
65 while (-1 != (ch = getopt(argc, argv, "C:M:m:O:S:s:")))
95 search.deftype = whatis ? TYPE_Nm : TYPE_Nm | TYPE_Nd;
96 search.flags = whatis ? MANSEARCH_WHATIS : 0;
98 manpath_parse(&paths, conf_file, defpaths, auxpaths);
100 ch = mansearch(&search, &paths, argc, argv, outkey, &res, &sz);
101 manpath_free(&paths);
106 for (i = 0; i < sz; i++) {
107 printf("%s - %s\n", res[i].names,
108 NULL == res[i].output ? "" : res[i].output);
116 return(sz ? EXIT_SUCCESS : EXIT_FAILURE);
118 fprintf(stderr, "usage: %s [-C file] [-M path] [-m path] "
120 "[-S arch] [-s section]%s ...\n", progname,
121 whatis ? " name" : "\n expression");
122 return(EXIT_FAILURE);