Home | History | Annotate | Line # | Download | only in makemandb
apropos-utils.h revision 1.4
      1 /*	$NetBSD: apropos-utils.h,v 1.4 2012/10/06 15:33:59 wiz 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 #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 	const char *machine;
     78 	int (*callback) (void *, const char *, const char *, const char *,
     79 		const char *, size_t);	// The callback function
     80 	void *callback_data;	// data to pass to the callback function
     81 	char **errmsg;		// buffer for storing the error msg
     82 } query_args;
     83 
     84 char *lower(char *);
     85 void concat(char **, const char *);
     86 void concat2(char **, const char *, size_t);
     87 sqlite3 *init_db(int, const char *);
     88 void close_db(sqlite3 *);
     89 char *get_dbpath(const char *);
     90 int run_query(sqlite3 *, const char *[3], query_args *);
     91 int run_query_html(sqlite3 *, query_args *);
     92 int run_query_pager(sqlite3 *, query_args *);
     93 #endif
     94