xref: /illumos-gate/usr/src/cmd/mandoc/mansearch.h (revision 94ddd0900a8838f62bba15e270649a42f4ef9f81)
1 /*	$Id: mansearch.h,v 1.28 2017/04/17 20:05:08 schwarze Exp $ */
2 /*
3  * Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2013, 2014, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
5  *
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.
9  *
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.
17  */
18 
19 #define	MANDOC_DB	 "mandoc.db"
20 #define	MANDOCDB_MAGIC	 0x3a7d0cdb
21 #define	MANDOCDB_VERSION 1
22 
23 #define	MACRO_MAX	 36
24 #define	KEY_arch	 0
25 #define	KEY_sec		 1
26 #define	KEY_Nm		 38
27 #define	KEY_Nd		 39
28 #define	KEY_MAX		 40
29 
30 #define	TYPE_arch	 0x0000000000000001ULL
31 #define	TYPE_sec	 0x0000000000000002ULL
32 #define	TYPE_Xr		 0x0000000000000004ULL
33 #define	TYPE_Ar		 0x0000000000000008ULL
34 #define	TYPE_Fa		 0x0000000000000010ULL
35 #define	TYPE_Fl		 0x0000000000000020ULL
36 #define	TYPE_Dv		 0x0000000000000040ULL
37 #define	TYPE_Fn		 0x0000000000000080ULL
38 #define	TYPE_Ic		 0x0000000000000100ULL
39 #define	TYPE_Pa		 0x0000000000000200ULL
40 #define	TYPE_Cm		 0x0000000000000400ULL
41 #define	TYPE_Li		 0x0000000000000800ULL
42 #define	TYPE_Em		 0x0000000000001000ULL
43 #define	TYPE_Cd		 0x0000000000002000ULL
44 #define	TYPE_Va		 0x0000000000004000ULL
45 #define	TYPE_Ft		 0x0000000000008000ULL
46 #define	TYPE_Tn		 0x0000000000010000ULL
47 #define	TYPE_Er		 0x0000000000020000ULL
48 #define	TYPE_Ev		 0x0000000000040000ULL
49 #define	TYPE_Sy		 0x0000000000080000ULL
50 #define	TYPE_Sh		 0x0000000000100000ULL
51 #define	TYPE_In		 0x0000000000200000ULL
52 #define	TYPE_Ss		 0x0000000000400000ULL
53 #define	TYPE_Ox		 0x0000000000800000ULL
54 #define	TYPE_An		 0x0000000001000000ULL
55 #define	TYPE_Mt		 0x0000000002000000ULL
56 #define	TYPE_St		 0x0000000004000000ULL
57 #define	TYPE_Bx		 0x0000000008000000ULL
58 #define	TYPE_At		 0x0000000010000000ULL
59 #define	TYPE_Nx		 0x0000000020000000ULL
60 #define	TYPE_Fx		 0x0000000040000000ULL
61 #define	TYPE_Lk		 0x0000000080000000ULL
62 #define	TYPE_Ms		 0x0000000100000000ULL
63 #define	TYPE_Bsx	 0x0000000200000000ULL
64 #define	TYPE_Dx		 0x0000000400000000ULL
65 #define	TYPE_Rs		 0x0000000800000000ULL
66 #define	TYPE_Vt		 0x0000001000000000ULL
67 #define	TYPE_Lb		 0x0000002000000000ULL
68 #define	TYPE_Nm		 0x0000004000000000ULL
69 #define	TYPE_Nd		 0x0000008000000000ULL
70 
71 #define	NAME_SYN	 0x0000004000000001ULL
72 #define	NAME_FIRST	 0x0000004000000004ULL
73 #define	NAME_TITLE	 0x0000004000000006ULL
74 #define	NAME_HEAD	 0x0000004000000008ULL
75 #define	NAME_FILE	 0x0000004000000010ULL
76 #define	NAME_MASK	 0x000000000000001fULL
77 
78 enum	form {
79 	FORM_SRC = 1,	/* Format is mdoc(7) or man(7). */
80 	FORM_CAT,	/* Manual page is preformatted. */
81 	FORM_NONE	/* Format is unknown. */
82 };
83 
84 enum	argmode {
85 	ARG_FILE = 0,
86 	ARG_NAME,
87 	ARG_WORD,
88 	ARG_EXPR
89 };
90 
91 struct	manpage {
92 	char		*file; /* to be prefixed by manpath */
93 	char		*names; /* a list of names with sections */
94 	char		*output; /* user-defined additional output */
95 	size_t		 ipath; /* number of the manpath */
96 	uint64_t	 bits; /* name type mask */
97 	int		 sec; /* section number, 10 means invalid */
98 	enum form	 form;
99 };
100 
101 struct	mansearch {
102 	const char	*arch; /* architecture/NULL */
103 	const char	*sec; /* mansection/NULL */
104 	const char	*outkey; /* show content of this macro */
105 	enum argmode	 argmode; /* interpretation of arguments */
106 	int		 firstmatch; /* first matching database only */
107 };
108 
109 
110 struct	manpaths;
111 
112 int	mansearch(const struct mansearch *cfg, /* options */
113 		const struct manpaths *paths, /* manpaths */
114 		int argc, /* size of argv */
115 		char *argv[],  /* search terms */
116 		struct manpage **res, /* results */
117 		size_t *ressz); /* results returned */
118 void	mansearch_free(struct manpage *, size_t);
119