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