1 /* Id: apropos.c,v 1.36 2013/12/31 03:41:14 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"
35 main(int argc
, char *argv
[])
38 struct mansearch search
;
41 struct manpaths paths
;
42 char *defpaths
, *auxpaths
;
49 progname
= strrchr(argv
[0], '/');
55 whatis
= (0 == strncmp(progname
, "whatis", 6));
57 memset(&paths
, 0, sizeof(struct manpaths
));
58 memset(&search
, 0, sizeof(struct mansearch
));
60 auxpaths
= defpaths
= NULL
;
64 while (-1 != (ch
= getopt(argc
, argv
, "C:M:m:O:S:s:")))
94 search
.deftype
= whatis
? TYPE_Nm
: TYPE_Nm
| TYPE_Nd
;
95 search
.flags
= whatis
? MANSEARCH_WHATIS
: 0;
97 manpath_parse(&paths
, conf_file
, defpaths
, auxpaths
);
98 ch
= mansearch(&search
, &paths
, argc
, argv
, outkey
, &res
, &sz
);
104 for (i
= 0; i
< sz
; i
++) {
105 printf("%s - %s\n", res
[i
].names
,
106 NULL
== outkey
? res
[i
].desc
:
107 NULL
== res
[i
].output
? "" : res
[i
].output
);
115 return(sz
? EXIT_SUCCESS
: EXIT_FAILURE
);
117 fprintf(stderr
, "usage: %s [-C file] [-M path] [-m path] "
119 "[-S arch] [-s section]%s ...\n", progname
,
120 whatis
? " name" : "\n expression");
121 return(EXIT_FAILURE
);