xref: /netbsd-src/usr.sbin/makemandb/apropos-utils.h (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /*	$NetBSD: apropos-utils.h,v 1.9 2013/04/02 17:16:50 christos Exp $	*/
2 /*-
3  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com>
4  * All rights reserved.
5  *
6  * This code was developed as part of Google's Summer of Code 2011 program.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
23  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #ifndef APROPOS_UTILS_H
34 #define APROPOS_UTILS_H
35 
36 #include "sqlite3.h"
37 
38 #define MANCONF "/etc/man.conf"
39 #define SECMAX 9
40 
41 /* Flags for opening the database */
42 #define MANDB_READONLY SQLITE_OPEN_READONLY
43 #define MANDB_WRITE SQLITE_OPEN_READWRITE
44 #define MANDB_CREATE SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
45 
46 #define APROPOS_SCHEMA_VERSION 20120507
47 
48 /*
49  * Used to identify the section of a man(7) page.
50  * This is similar to the enum mdoc_sec defined in mdoc.h from mdocml project.
51  */
52 enum man_sec {
53 	MANSEC_NAME = 0,
54 	MANSEC_SYNOPSIS,
55 	MANSEC_LIBRARY,
56 	MANSEC_ERRORS,
57 	MANSEC_FILES,
58 	MANSEC_RETURN_VALUES,
59 	MANSEC_EXIT_STATUS,
60 	MANSEC_DESCRIPTION,
61 	MANSEC_ENVIRONMENT,
62 	MANSEC_DIAGNOSTICS,
63 	MANSEC_EXAMPLES,
64 	MANSEC_STANDARDS,
65 	MANSEC_HISTORY,
66 	MANSEC_BUGS,
67 	MANSEC_AUTHORS,
68 	MANSEC_COPYRIGHT,
69 	MANSEC_NONE
70 };
71 
72 typedef struct query_args {
73 	const char *search_str;		// user query
74 	int *sec_nums;		// Section in which to do the search
75 	int nrec;			// number of records to fetch
76 	int offset;		//From which position to start processing the records
77 	int legacy;
78 	const char *machine;
79 	int (*callback) (void *, const char *, const char *, const char *,
80 		const char *, size_t);	// The callback function
81 	void *callback_data;	// data to pass to the callback function
82 	char **errmsg;		// buffer for storing the error msg
83 } query_args;
84 
85 typedef enum query_format {
86     APROPOS_NONE,
87     APROPOS_PAGER,
88     APROPOS_TERM,
89     APROPOS_HTML
90 } query_format;
91 
92 char *lower(char *);
93 void concat(char **, const char *);
94 void concat2(char **, const char *, size_t);
95 sqlite3 *init_db(int, const char *);
96 void close_db(sqlite3 *);
97 char *get_dbpath(const char *);
98 int run_query(sqlite3 *, query_format, query_args *);
99 #endif
100