Home | History | Annotate | Line # | Download | only in makemandb
apropos-utils.h revision 1.6
      1  1.6  christos /*	$NetBSD: apropos-utils.h,v 1.6 2013/02/10 23:24:18 christos 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 #define SECMAX 9
     40  1.1     joerg 
     41  1.1     joerg /* Flags for opening the database */
     42  1.1     joerg #define MANDB_READONLY SQLITE_OPEN_READONLY
     43  1.1     joerg #define MANDB_WRITE SQLITE_OPEN_READWRITE
     44  1.1     joerg #define MANDB_CREATE SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
     45  1.1     joerg 
     46  1.3       wiz #define APROPOS_SCHEMA_VERSION 20120507
     47  1.1     joerg 
     48  1.1     joerg /*
     49  1.1     joerg  * Used to identify the section of a man(7) page.
     50  1.1     joerg  * This is similar to the enum mdoc_sec defined in mdoc.h from mdocml project.
     51  1.1     joerg  */
     52  1.1     joerg enum man_sec {
     53  1.1     joerg 	MANSEC_NAME = 0,
     54  1.1     joerg 	MANSEC_SYNOPSIS,
     55  1.1     joerg 	MANSEC_LIBRARY,
     56  1.1     joerg 	MANSEC_ERRORS,
     57  1.1     joerg 	MANSEC_FILES,
     58  1.1     joerg 	MANSEC_RETURN_VALUES,
     59  1.1     joerg 	MANSEC_EXIT_STATUS,
     60  1.1     joerg 	MANSEC_DESCRIPTION,
     61  1.1     joerg 	MANSEC_ENVIRONMENT,
     62  1.1     joerg 	MANSEC_DIAGNOSTICS,
     63  1.1     joerg 	MANSEC_EXAMPLES,
     64  1.1     joerg 	MANSEC_STANDARDS,
     65  1.1     joerg 	MANSEC_HISTORY,
     66  1.1     joerg 	MANSEC_BUGS,
     67  1.1     joerg 	MANSEC_AUTHORS,
     68  1.1     joerg 	MANSEC_COPYRIGHT,
     69  1.1     joerg 	MANSEC_NONE
     70  1.1     joerg };
     71  1.1     joerg 
     72  1.1     joerg typedef struct query_args {
     73  1.1     joerg 	const char *search_str;		// user query
     74  1.1     joerg 	int *sec_nums;		// Section in which to do the search
     75  1.1     joerg 	int nrec;			// number of records to fetch
     76  1.1     joerg 	int offset;		//From which position to start processing the records
     77  1.1     joerg 	const char *machine;
     78  1.1     joerg 	int (*callback) (void *, const char *, const char *, const char *,
     79  1.1     joerg 		const char *, size_t);	// The callback function
     80  1.1     joerg 	void *callback_data;	// data to pass to the callback function
     81  1.1     joerg 	char **errmsg;		// buffer for storing the error msg
     82  1.1     joerg } query_args;
     83  1.1     joerg 
     84  1.1     joerg char *lower(char *);
     85  1.1     joerg void concat(char **, const char *);
     86  1.1     joerg void concat2(char **, const char *, size_t);
     87  1.4       wiz sqlite3 *init_db(int, const char *);
     88  1.1     joerg void close_db(sqlite3 *);
     89  1.4       wiz char *get_dbpath(const char *);
     90  1.1     joerg int run_query(sqlite3 *, const char *[3], query_args *);
     91  1.1     joerg int run_query_html(sqlite3 *, query_args *);
     92  1.1     joerg int run_query_pager(sqlite3 *, query_args *);
     93  1.5  christos int run_query_term(sqlite3 *, query_args *);
     94  1.6  christos #endif
     95