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