1*c9bcef03Schristos.\" Id: mansearch.3,v 1.5 2017/03/30 22:22:05 schwarze Exp 2fec65c98Schristos.\" 3fec65c98Schristos.\" Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> 4fec65c98Schristos.\" 5fec65c98Schristos.\" Permission to use, copy, modify, and distribute this software for any 6fec65c98Schristos.\" purpose with or without fee is hereby granted, provided that the above 7fec65c98Schristos.\" copyright notice and this permission notice appear in all copies. 8fec65c98Schristos.\" 9fec65c98Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10fec65c98Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11fec65c98Schristos.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12fec65c98Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13fec65c98Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14fec65c98Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15fec65c98Schristos.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16fec65c98Schristos.\" 17*c9bcef03Schristos.Dd March 30, 2017 18fec65c98Schristos.Dt MANSEARCH 3 19fec65c98Schristos.Os 20fec65c98Schristos.Sh NAME 21*c9bcef03Schristos.Nm mansearch 22fec65c98Schristos.Nd search manual page databases 23fec65c98Schristos.Sh SYNOPSIS 24fec65c98Schristos.In stdint.h 259ff1f2acSchristos.In manconf.h 26fec65c98Schristos.In mansearch.h 27fec65c98Schristos.Ft int 28fec65c98Schristos.Fo mansearch 29fec65c98Schristos.Fa "const struct mansearch *search" 30fec65c98Schristos.Fa "const struct manpaths *paths" 31fec65c98Schristos.Fa "int argc" 32fec65c98Schristos.Fa "char *argv[]" 33fec65c98Schristos.Fa "struct manpage **res" 34fec65c98Schristos.Fa "size_t *sz" 35fec65c98Schristos.Fc 36fec65c98Schristos.Sh DESCRIPTION 37fec65c98SchristosThe 38fec65c98Schristos.Fn mansearch 39fec65c98Schristosfunction returns information about manuals matching a search query from a 40fec65c98Schristos.Xr mandoc.db 5 41*c9bcef03Schristosdatabase. 42fec65c98Schristos.Pp 43fec65c98SchristosThe query arguments are as follows: 44fec65c98Schristos.Bl -tag -width Ds 45fec65c98Schristos.It Fa "const struct mansearch *search" 46fec65c98SchristosSearch options, defined in 47fec65c98Schristos.In mansearch.h . 48fec65c98Schristos.It Fa "const struct manpaths *paths" 49fec65c98SchristosDirectories to be searched, defined in 509ff1f2acSchristos.In manconf.h . 51fec65c98Schristos.It Fa "int argc" , "char *argv[]" 52fec65c98SchristosSearch criteria, usually taken from the command line. 53fec65c98Schristos.El 54fec65c98Schristos.Pp 55fec65c98SchristosThe output arguments are as follows: 56fec65c98Schristos.Bl -tag -width Ds 57fec65c98Schristos.It Fa "struct manpage **res" 58fec65c98SchristosReturns a pointer to an array of result structures defined in 59fec65c98Schristos.In mansearch.h . 60fec65c98SchristosThe user is expected to call 61fec65c98Schristos.Xr free 3 62fec65c98Schristoson the 63fec65c98Schristos.Va file , 64fec65c98Schristos.Va names , 65fec65c98Schristosand 66fec65c98Schristos.Va output 67fec65c98Schristosfields of all structures, as well as the 68fec65c98Schristos.Fa res 69fec65c98Schristosarray itself. 70fec65c98Schristos.It Fa "size_t *sz" 71fec65c98SchristosReturns the number of result structures contained in 72fec65c98Schristos.Fa res . 73fec65c98Schristos.El 74fec65c98Schristos.Sh IMPLEMENTATION NOTES 75fec65c98SchristosFor each manual page tree, the search is done in two steps. 76fec65c98SchristosIn the first step, a list of pages matching the search criteria is built. 77fec65c98SchristosIn the second step, the requested information about these pages is 78fec65c98Schristosretrieved from the database and assembled into the 79fec65c98Schristos.Fa res 80fec65c98Schristosarray. 81fec65c98Schristos.Pp 82fec65c98SchristosAll function mentioned here are defined in the file 83fec65c98Schristos.Pa mansearch.c . 84fec65c98Schristos.Ss Finding matches 85fec65c98SchristosCommand line parsing is done by the function 86fec65c98Schristos.Fn exprcomp 87fec65c98Schristosbuilding a singly linked list of 88fec65c98Schristos.Vt expr 89fec65c98Schristosstructures, using the helper functions 90*c9bcef03Schristos.Fn expr_and 91fec65c98Schristosand 92*c9bcef03Schristos.Fn exprterm . 93fec65c98Schristos.Ss Assembling the results 94fec65c98SchristosThe names, sections, and architectures of the manuals found 95fec65c98Schristosare assembled into the 96fec65c98Schristos.Va names 97fec65c98Schristosfield of the result structure by the function 98*c9bcef03Schristos.Fn buildnames . 99fec65c98Schristos.Sh FILES 100fec65c98Schristos.Bl -tag -width mandoc.db -compact 101fec65c98Schristos.It Pa mandoc.db 102fec65c98SchristosThe manual page database. 103fec65c98Schristos.El 104fec65c98Schristos.Sh SEE ALSO 105fec65c98Schristos.Xr apropos 1 , 106fec65c98Schristos.Xr mandoc.db 5 , 107fec65c98Schristos.Xr makewhatis 8 108fec65c98Schristos.Sh HISTORY 109fec65c98SchristosThe 110fec65c98Schristos.Fn mansearch 111fec65c98Schristossubsystem first appeared in 112fec65c98Schristos.Ox 5.6 . 113fec65c98Schristos.Sh AUTHORS 114fec65c98Schristos.An -nosplit 115fec65c98SchristosA module to search manual page databases was first written by 116fec65c98Schristos.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv 117fec65c98Schristosin 2011, at first using the Berkeley DB; 118*c9bcef03Schristoshe rewrote it for SQLite3 in 2012, and 119*c9bcef03Schristos.An Ingo Schwarze Aq Mt schwarze@openbsd.org 120*c9bcef03Schristosremoved the dependency on SQLite3 in 2016. 121