apropos-utils.h revision 1.11.6.1 1 /* $NetBSD: apropos-utils.h,v 1.11.6.1 2017/05/02 03:19:23 pgoyette Exp $ */
2 /*-
3 * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay (at) 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
40 /* Flags for opening the database */
41 typedef enum mandb_access_mode {
42 MANDB_READONLY = SQLITE_OPEN_READONLY,
43 MANDB_WRITE = SQLITE_OPEN_READWRITE,
44 MANDB_CREATE = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
45 } mandb_access_mode;
46
47
48 #define APROPOS_SCHEMA_VERSION 20120507
49
50 /*
51 * Used to identify the section of a man(7) page.
52 * This is similar to the enum mdoc_sec defined in mdoc.h from mdocml project.
53 */
54 enum man_sec {
55 MANSEC_NAME = 0,
56 MANSEC_SYNOPSIS,
57 MANSEC_LIBRARY,
58 MANSEC_ERRORS,
59 MANSEC_FILES,
60 MANSEC_RETURN_VALUES,
61 MANSEC_EXIT_STATUS,
62 MANSEC_DESCRIPTION,
63 MANSEC_ENVIRONMENT,
64 MANSEC_DIAGNOSTICS,
65 MANSEC_EXAMPLES,
66 MANSEC_STANDARDS,
67 MANSEC_HISTORY,
68 MANSEC_BUGS,
69 MANSEC_AUTHORS,
70 MANSEC_COPYRIGHT,
71 MANSEC_NONE
72 };
73
74 typedef struct query_args {
75 const char *search_str; // user query
76 char **sections; // Sections in which to do the search
77 int nrec; // number of records to fetch
78 int offset; //From which position to start processing the records
79 int legacy;
80 const char *machine;
81 int (*callback) (void *, const char *, const char *, const char *,
82 const char *, size_t); // The callback function
83 void *callback_data; // data to pass to the callback function
84 char **errmsg; // buffer for storing the error msg
85 } query_args;
86
87 typedef enum query_format {
88 APROPOS_NONE,
89 APROPOS_PAGER,
90 APROPOS_TERM,
91 APROPOS_HTML
92 } query_format;
93
94 char *lower(char *);
95 void concat(char **, const char *);
96 void concat2(char **, const char *, size_t);
97 sqlite3 *init_db(mandb_access_mode, const char *);
98 void close_db(sqlite3 *);
99 char *get_dbpath(const char *);
100 int run_query(sqlite3 *, query_format, query_args *);
101 #endif
102