Annotation of mandoc/apropos.c, Revision 1.31
1.31 ! kristaps 1: /* $Id: mandocdb.c,v 1.46 2012/03/23 06:52:17 kristaps Exp $ */
1.1 kristaps 2: /*
1.31 ! kristaps 3: * Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
1.13 kristaps 17: #ifdef HAVE_CONFIG_H
18: #include "config.h"
19: #endif
1.27 kristaps 20: #include <sys/param.h>
1.13 kristaps 21:
1.1 kristaps 22: #include <assert.h>
23: #include <getopt.h>
24: #include <stdio.h>
25: #include <stdlib.h>
26: #include <string.h>
1.29 kristaps 27: #include <unistd.h>
1.1 kristaps 28:
1.18 kristaps 29: #include "manpath.h"
1.31 ! kristaps 30: #include "mansearch.h"
1.1 kristaps 31:
32: int
33: main(int argc, char *argv[])
34: {
1.31 ! kristaps 35: int ch;
! 36: size_t i, sz;
! 37: struct manpage *res;
! 38: char *conf_file, *defpaths, *auxpaths,
! 39: *arch, *sec;
1.15 kristaps 40: struct manpaths paths;
1.31 ! kristaps 41: char *progname;
! 42: extern char *optarg;
1.1 kristaps 43: extern int optind;
44:
45: progname = strrchr(argv[0], '/');
46: if (progname == NULL)
47: progname = argv[0];
48: else
49: ++progname;
50:
1.31 ! kristaps 51: auxpaths = defpaths = conf_file = arch = sec = NULL;
1.15 kristaps 52: memset(&paths, 0, sizeof(struct manpaths));
53:
1.24 schwarze 54: while (-1 != (ch = getopt(argc, argv, "C:M:m:S:s:")))
1.1 kristaps 55: switch (ch) {
1.24 schwarze 56: case ('C'):
57: conf_file = optarg;
58: break;
1.17 kristaps 59: case ('M'):
60: defpaths = optarg;
61: break;
1.15 kristaps 62: case ('m'):
1.17 kristaps 63: auxpaths = optarg;
1.15 kristaps 64: break;
1.9 kristaps 65: case ('S'):
1.31 ! kristaps 66: arch = optarg;
1.1 kristaps 67: break;
1.9 kristaps 68: case ('s'):
1.31 ! kristaps 69: sec = optarg;
1.1 kristaps 70: break;
71: default:
1.31 ! kristaps 72: goto usage;
1.1 kristaps 73: }
74:
75: argc -= optind;
76: argv += optind;
77:
1.31 ! kristaps 78: if (0 == argc)
! 79: goto usage;
1.15 kristaps 80:
1.24 schwarze 81: manpath_parse(&paths, conf_file, defpaths, auxpaths);
1.31 ! kristaps 82: ch = mansearch(&paths, arch, sec, argc, argv, &res, &sz);
1.18 kristaps 83: manpath_free(&paths);
1.28 kristaps 84:
1.31 ! kristaps 85: if (0 == ch)
! 86: goto usage;
1.28 kristaps 87:
1.31 ! kristaps 88: for (i = 0; i < sz; i++) {
! 89: printf("%s - %s\n", res[i].file, res[i].desc);
! 90: free(res[i].desc);
1.28 kristaps 91: }
92:
1.31 ! kristaps 93: free(res);
! 94: return(sz ? EXIT_SUCCESS : EXIT_FAILURE);
! 95: usage:
! 96: fprintf(stderr, "usage: %s [-C conf] "
! 97: "[-M paths] "
! 98: "[-m paths] "
! 99: "[-S arch] "
! 100: "[-s section] "
! 101: "expr ...\n",
! 102: progname);
1.28 kristaps 103: return(EXIT_FAILURE);
1.1 kristaps 104: }
CVSweb