aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mansearch.c
Commit message (Collapse)AuthorAgeFilesLines
* Only sort the result array if it contains more than one element,Ingo Schwarze2022-01-131-2/+2
| | | | | | | | | | | | | | | | | | | making the mansearch() function easier to read for human auditors. No functional change on OpenBSD. As observed by Mark Millard <marklmi at yahoo dot com>, neither the latest version of POSIX 2008 nor C11 defines what qsort(3) should do for base == NULL && nmemb == 0. My impression is it is indeed undefined behaviour because the standards say that base shall point to an array, NULL does not point to an array, and while there is special wording saying that compar() shall not be called if nmemb == 0, i fail to see any similar wording stating that base shall not be accessed if nmemb == 0. Consequently, this patch is also likely to improve standard conformance and portability. Minor issue found by Stefan Esser <se at FreeBSD> with UBSAN. He sent a patch to bugs@, but my patch differs in a minor way.
* delete trailing whitespace and space-tab sequences; no code change;Ingo Schwarze2019-07-011-2/+2
| | | | | patch from Michal Nowak <mnowak at startmail dot com> who found these with git pbchk in the illumos tree
* In man(1) mode, i.e. when asking for a single manual page by name,Ingo Schwarze2019-04-301-3/+7
| | | | | | | | | | | | prefer file name matches over .Dt/.TH matches over first NAME matches over later NAME matches, but do not change the ordering for apropos(1) nor for man -a. This reverts main.c rev. 1.310 and mansearch.h rev. 1.29 and includes a partial revert of mansearch.c rev. 1.79. Regression reported by Lorenzo Beretta <loreb at github> as part of https://github.com/void-linux/void-packages/issues/9868 .
* Cleanup, no functional change:Ingo Schwarze2018-12-131-2/+1
| | | | | | | | | | Split the top level parser interface out of the utility header mandoc.h, into a new header mandoc_parse.h, for use in the main program and in the main parser only. Move enum mandoc_os into roff.h because struct roff_man is the place where it is stored. This allows removal of mandoc.h from seven files in low-level parsers and in formatters.
* In apropos(1) output, stop sorting .Nm search results by nameIngo Schwarze2018-11-221-7/+3
| | | | | | | | | | priorities (bits). The obscure feature wasn't documented and merely confused people - for example Edward Tomasz Napierala <trasz at FreeBSD>, see https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227408. Smaller patch provided by Yuri Pankov <yuripv at FreeBSD>, but i'm also retiring the now unused "bits" member from struct manpage. Simplification is good.
* Improve POSIX compliance by making case-insensitive extendedIngo Schwarze2018-11-191-4/+5
| | | | | | | | | | | | | | | | | regular expressions the default in man(1) -k searches, also matching what the man-db package used by many Linux distributions does. Originally requested by Wolfram Schneider <wosch at FreeBSD> via Yuri Pankov <yuripv at FreeBSD>. Feedback and OK cheloha@, and no objections when shown on tech@. Thanks to cheloha@ for pointing out that POSIX requires this behaviour and for the suggestion to explicitly say that *extended* regular expressions are used here. While here, unify spelling of case-[in]sensitive, fix a typo, update the EXAMPLES, and add a STANDARDS section.
* When finding a bogus database entry,Ingo Schwarze2017-08-221-1/+11
| | | | | print a meaningful warning and skip the entry. Issue reported by espie@.
* No longer use names that only occur in the SYNOPSIS section as namesIngo Schwarze2017-08-021-18/+49
| | | | | | | | | | | | | | | | | | | | | | | | | for man(1) lookup. For OpenBSD base and Xenocara, that functionality was never intended to be required, and i just fixed the last handful of offenders using it - not counting the horribly ill-designed interfaces engine(3) and lh_new(3) which are impossible to properly document in the first place. Of course, apropos(1) and whatis(1) continue to use SYNOPSIS .Nm, .Fn, and .Fo macros, so "man -k ENGINE_get_load_privkey_function" still works. This change also gets rid of a few bogus warnings "cross reference to self" which actually are *not* to self, like in yp(8). This former functionality was intended to help third-party software in the ports tree and on non-OpenBSD systems containing manual pages with incomplete or corrupt NAME sections. But it turned out it did more harm than good, and caused more confusion than relief, specifically for third party manuals and for maintainers of mandoc-portable on other operating systems. So kill it. Problems reported, among others, by Yuri Pankov (illumos). OK jmc@
* Prefer arch-dependent over arch-independent pages if the name priority,Ingo Schwarze2017-07-191-3/+19
| | | | | | | | the section number, and all names match. Changes little on installed systems except the ordering of apropos(1) results, because we install base and Xenocara manuals in different trees, but fixes lookup of pages like apm(4) vs. apm(4/amd64) in man.cgi(8). Issue discovered by martian67 on freenode and reported via tj@.
* Basic reporting of .Xrs to manual pages that don't existIngo Schwarze2017-07-011-3/+9
| | | | | | | | | | | | in the base system, inspired by mdoclint(1). We are able to do this because (1) the -mdoc parser, the -Tlint validator, and the man(1) manual page lookup code are all in the same program and (2) the mandoc.db(5) database format allows fast lookup. Feedback from, previous versions tested by, and OK jmc@. A few features will be added to this in the tree, step by step.
* Do not warn if a database file does not existIngo Schwarze2017-05-171-1/+2
| | | | | because that is simply equivalent to an empty database. Suggested by ajacoutot@
* The apropos(1) manual still documents the unary -i operator forIngo Schwarze2017-04-181-1/+6
| | | | | | regular expression search terms, but it appears that somewhere along the way, the implementation got lost, so restore it. Bug found while investigating other reports from Gonzalo Tornaria.
* Fix previous: i forgot explicit NUL termination;Ingo Schwarze2017-04-181-0/+2
| | | | noticed by Gonzalo <Tornaria at cmat dot edu dot uy>, thanks!
* Restore -kO Nd, -kO Nm, -kO sec, and -kO arch to working order.Ingo Schwarze2017-04-171-24/+52
| | | | | | | They got broken in the SQLite removal. As opposed to the rest of -kO, they are no longer very useful, but they are certainly not supposed to fail assertions. Issue reported by Gonzalo Tornaria <tornaria at cmat dot edu dot uy>.
* A missing initialization could randomly cause regular expressionIngo Schwarze2017-03-031-0/+1
| | | | | searches to be case-insensitive that ought to be case sensitive. Found by jsg@ with scan-build.
* Really protect <err.h> as already promised in the previous commit message.Ingo Schwarze2016-08-051-0/+2
|
* Linux compatibility: Work around the lack of EFTYPE and protect <err.h>.Ingo Schwarze2016-07-201-1/+2
|
* Remove the dependency on SQLite without loss of functionality.Ingo Schwarze2016-07-191-575/+471
| | | | | Stop supporting systems that don't have mmap(3). Drop the obsolete names_check() now that we deleted MLINKS.
* getopt(3) is declared in <unistd.h>, and <getopt.h> is not needed;Ingo Schwarze2016-07-091-2/+1
| | | | from Joerg Sonnenberger via Thomas Klausner, NetBSD.
* Prefer warn(3) over perror(3) at the few places where it was used.Ingo Schwarze2016-01-081-6/+6
| | | | | It is useful to see the program name, and we have err.h compat in place anyway. Suggested by Christos Zoulas (NetBSD).
* No point in trying to go on when elementary database operationsIngo Schwarze2015-11-261-7/+10
| | | | | | like preparing queries or binding variables fail; that won't yield useful results anyway but may generate huge pointless error messages. Issue reported by deraadt@.
* Without HAVE_ERR, don't try to include <err.h>, it probably isn't there.Ingo Schwarze2015-11-071-1/+3
| | | | | In that case, the required prototypes are in "config.h". Patch from Peter Bray <pdb_ml at yahoo dot com dot au>.
* In ./configure, select a RE syntax for word boundaries supported by libc;Ingo Schwarze2015-11-061-1/+8
| | | | issue reported by Svyatoslav Mishyn, Peter Bray, and Daniel Levai.
* Reduce the amount of code by moving the three copies of the ohashIngo Schwarze2015-10-131-38/+3
| | | | | callback functions into one common place, preparing for the use of ohash for some additional purposes. No functional change.
* Finally use __progname, err(3) and warn(3).Ingo Schwarze2015-10-111-18/+17
| | | | | | | | | | That's more readable and less error-prone than fumbling around with argv[0], fprintf(3), strerror(3), perror(3), and exit(3). It's a bad idea to boycott good interfaces merely because standards committees ignore them. Instead, let's provide compatibility modules for archaic systems (like commercial Solaris) that still don't have them. The compat module has an UCB Copyright (c) 1993...
* modernize style: "return" is not a functionIngo Schwarze2015-10-061-24/+24
|
* Let man(1) and apropos(1) work even when the current directoryIngo Schwarze2015-04-011-36/+34
| | | | | | | is unusable: Only change back to the current directory when the directory was changed before and the next path is relative. This is now more similar to what makewhatis(8) does. Issue reported by espie@.
* Parse the new man.conf(5) "output" directive.Ingo Schwarze2015-03-271-4/+4
| | | | The next step will be to actually use the parsed data.
* When interpreting the -O argument as a macro name fails,Ingo Schwarze2015-03-111-3/+4
| | | | | fall back to showing Nd rather than not showing anything. Issue reported by jmc@.
* When man(1) and apropos(1) look for a file man1/foo.1 but it's unavailable,Ingo Schwarze2015-02-271-4/+29
| | | | | | | fall back to glob(man1/foo.*), which is more like what old man(1) did. Do this both for file names from the database and for fs_lookup(). This is relevant because some ports install files like man1/xset.1x. Regression reported by patrick keshishian <pkeshish at gmail dot com>.
* Make the man(1) and apropos(1) options -s and -S much less expensive:Ingo Schwarze2015-01-201-49/+23
| | | | | | | | | | | | | | Do not append an SQL clause looking into the large "keys" table. Instead, filter the result of the SQL query in buildnames() where equivalent data from the much smaller "mlinks" table is already available for free. This is relevant because man(1) uses the equivalent of "-S ${MACHINE}" by default since main.c rev. 1.216, to make sure that manuals for the current architecture are shown. With many ports installed, this patch can speed up man(1) by a factor of more than a hundred. Slowness reported by Theo Buehler <theo at math dot ethz dot ch>, thanks!
* When opening mandoc.db fails, tell the user in which directory.Ingo Schwarze2014-12-061-2/+4
| | | | Improving an unhelpful error message reported by millert@.
* Make makewhatis(8) understand .so links to .gz pages.Ingo Schwarze2014-11-271-13/+8
| | | | | | | | Drop the FORM_GZ annotation in the mpages table; it is conceptually wrong because it ought to be in the mlinks table: An uncompressed .so link file can point to a compressed manual page file and vice versa. Besides, it is no longer needed because mparse_open() handles it all. Sprinkle some KNF while here.
* In man(1) mode, prefer file name matches over .Dt name matches overIngo Schwarze2014-11-181-7/+12
| | | | | | first .Nm entries over other NAME .Nm entries over SYNOPSIS .Nm entries. For example, this makes sure "man ypbind" does not return yp(8). Re-run "makewhatis" to profit from this change.
* In man(1) mode without -a, stop searching after the first manual treeIngo Schwarze2014-11-111-1/+9
| | | | | that contained at least one match in order to not prefer mdoc(1) from ports over mdoc(7). As a bonus, this results in a speedup.
* If a manual page is installed gzip(1)ed, let makewhatis(8) takeIngo Schwarze2014-09-031-5/+10
| | | | | | | note in mandoc.db(5), such that man(1) -w and apropos(1) -w can report the correct filename. This is a prerequisite for letting apropos -a and man support gzip'ed manuals in the future, which doesn't work yet.
* In man(1) mode, change to the right directory before starting the parser,Ingo Schwarze2014-09-011-1/+2
| | | | | | | just like traditional man(1) does, such that .so links have a chance to work. After this point, we don't need the current directory for anything else before exit, so we don't need to worry about getting back and we can safely ignore failure.
* Bugfix: make whatis(1) case-insensitive again.Ingo Schwarze2014-08-211-1/+2
| | | | | The traditional whatis(1) was case-insensitve and it's still documented that way, but that apparently got broken with or after the switch.
* Fully integrate apropos(1) into mandoc(1).Ingo Schwarze2014-08-171-28/+29
| | | | | | | | | Switch the argmode on the progname, including man(1). Provide -f and -k options to switch the argmode. Store the argmode inside struct search, generalizing the flags. Derive the deftype from the argmode when needed instead of storing it. Store the outkey inside struct search instead of passing it alone. While here, get rid of the trailing blanks in Makefile.depend.
* Improve build system and autodetection.Ingo Schwarze2014-08-161-2/+2
| | | | | | | | | * Make ./configure standalone, that's what people expect. * Let people write a ./configure.local from scratch, not edit existing files. * Autodetect wchar, sqlite3, and manpath and act accordingly. * Autodetect the need for -L/usr/local/lib and -lutil. * Get rid of config.h.p{re,ost}, let ./configure only write what's needed. * Let ./configure write a Makefile.local snippet, that's quite flexible.
* Get rid of HAVE_CONFIG_H, it is always defined; idea from libnbcompat.Ingo Schwarze2014-08-101-3/+3
| | | | | | Include <sys/types.h> where needed, it does not belong in config.h. Remove <stdio.h> from config.h; if it is missing somewhere, it should be added, but i cannot find a *.c file where it is missing.
* mmap(2) requires MAP_PRIVATE ^ MAP_SHARED for flags;Ingo Schwarze2014-08-091-2/+3
| | | | found by kristaps@ on Mac OS X
* Absurdly, the return value of sqlite3_column_text()Ingo Schwarze2014-08-051-6/+6
| | | | | | is "const unsigned char *", which causes warnings with GCC on Linux. Explicitly cast to "const char *" to avoid this. Issue noticed by kristaps@.
* If an old SQLite version doesn't provide SQLITE_DETERMINISTIC,Ingo Schwarze2014-08-051-1/+4
| | | | | simply ignore it, as using it is merely an optimization. Issue noticed by kristaps@.
* Sort result pages first by section number, then by name.Ingo Schwarze2014-07-241-1/+21
| | | | | | | | By moving the sort from cgi.c to mansearch.c, we get two advantages: Easier access to the data needed for sorting, in particular the section number, and the apropos(1) command line utility profits as well. Feature requested by deraadt@.
* Fix whatis(1) to correctly match words instead of any substrings.Ingo Schwarze2014-07-121-23/+51
| | | | | While here, also provide an internal mode (MANSEARCH_MAN) to match complete names, to be used by man.cgi(8).
* Merge from OpenBSD - Marc Espie improved the ohash interface:Ingo Schwarze2014-06-201-10/+8
| | | | | | * rename the halloc callback to calloc, provide overflow protection * rename the hfree callback to free, drop the useless size argument * prevent integer overflows in ohash_resize
* Audit malloc(3)/calloc(3)/realloc(3) usage.Ingo Schwarze2014-04-231-4/+4
| | | | | | | * Change eight reallocs to reallocarray to be safe from overflows. * Change one malloc to reallocarray to be safe from overflows. * Change one calloc to reallocarray, no zeroing needed. * Change the order of arguments of three callocs (aesthetical).
* improve SQL style: avoid "SELECT *", be explicit in what columns we want;Ingo Schwarze2014-04-231-5/+7
| | | | suggested by espie@.
* KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze2014-04-201-13/+13
| | | | | remove trailing whitespace and blanks before tabs, improve some indenting; no functional change