summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
Commit message (Collapse)AuthorAgeFilesLines
* Support homebrew-style linking on Mac OS X.Ingo Schwarze2015-01-211-1/+9
| | | | Idea found together with Alexis Hildebrandt <surryhill at gmail dot com>.
* Fatal errors no longer exist.Ingo Schwarze2015-01-151-8/+5
| | | | | | If a file can be opened, mandoc will produce some output; at worst, the output may be almost empty. Simplifies error handling and frees a message type for future use.
* Fix a potential NULL pointer access in an error message after waitpid()Ingo Schwarze2015-01-031-22/+15
| | | | | failure; found using detailed information provided by Ulrich Spoerlein <uqs at FreeBSD> about FreeBSD Coverity CID 1261304.
* Explicitly set the *data member of struct ohash_info to NULL.Ingo Schwarze2015-01-021-1/+3
| | | | | | | It is never dereferenced, but it gets copied around, which worries static analysis tools and might also confuse human auditors. FreeBSD Coverity CID 1261298, 1261299, 1261300, reported by Pedro Giffuni and Ulrich Spörlein <pfg@ and uqs@ at FreeBSD>.
* When a file is given on the command line, actually exists, and its nameIngo Schwarze2014-12-301-0/+1
| | | | | | | relative to the respective manual tree is longer than PATH_MAX, do not leak the memory allocated to hold the name. Not sure that can actually happen, but better safe than sorry. FreeBSD Coverity Scan CID 1261303, reported by Pedro Giffuni <pfg@>.
* Integrate the makewhatis binary into the mandoc binaryIngo Schwarze2014-12-091-1/+1
| | | | | just like we do it on OpenBSD. Smaller and neater. While here, let ./configure set INSTALL_TARGETS.
* Improve parsing of function names.Ingo Schwarze2014-12-051-24/+27
| | | | This gets rid of the last bogus entries in base and Xenocara.
* Do not misinterpret function arguments as function names;Ingo Schwarze2014-12-051-0/+3
| | | | improves semantic analysis of more than 300 manuals.
* Render text before, not after accumulating flag bits, such that flagsIngo Schwarze2014-12-051-116/+107
| | | | | for different representations of the same string end up in the same database entry. Improves name classification for 500 manuals.
* When finding a .so link after the page was already processed,Ingo Schwarze2014-12-041-3/+16
| | | | | do not clobber the existing names flags; instead, OR the additional flags into them.
* correctly store .Dt and .TH information in the names tableIngo Schwarze2014-12-041-10/+27
|
* in the SYNOPSIS, add .Fo and first .Fn arguments to the names tableIngo Schwarze2014-12-041-1/+16
|
* In the SYNOPSIS, if .Nm occurs without argument, give the first .NmIngo Schwarze2014-12-041-24/+47
| | | | that occurred in the document a NAME_SYN entry in the names table.
* Make makewhatis(8) understand .so links to .gz pages.Ingo Schwarze2014-11-271-14/+18
| | | | | | | | 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.
* Simplify the mparse_open()/mparse_wait() interface.Ingo Schwarze2014-11-261-5/+2
| | | | | Don't bother the user with the PID of the child process, store it inside the opaque mparse handle.
* Three fixes with respect to the names table:Ingo Schwarze2014-11-191-3/+13
| | | | | | 1. Do not mask out NAME_FIRST before its first use. 2. Avoid duplicate NAME_FILE entries. 3. Correctly mask NAME_FILE for .so links.
* Make the character table available to libroff so it can check theIngo Schwarze2014-10-281-3/+3
| | | | | | | | validity of character escape names and warn about unknown ones. This requires mchars_spec2cp() to report unknown names again. Fortunately, that doesn't require changing the calling code because according to groff, invalid character escapes should not produce output anyway, and now that we warn about them, that's fine.
* Fix a regression in term.c rev. 1.229 reported by bentley@:Ingo Schwarze2014-10-271-1/+1
| | | | | | | | | | In UTF-8 output, do not print anything if mchars_spec2cp() returns 0. In particular, this repairs handling of zero-width spaces (\&). While here, let mchars_spec2cp() return 0xFFFD instead of -1 if the character is not found, simplifying the using code. In HTML output, do not print obfuscated ASCII characters and do not test for one-char escapes, mchars_spec2cp() already does that.
* add missing entry for .ll to the dispatch table;Ingo Schwarze2014-10-121-0/+1
| | | | patch from Martin <Natano at natano dot net>, thanks
* If a manpath directory (for example, a _whatdb entry from man.conf(5)Ingo Schwarze2014-09-091-11/+15
| | | | | | | | | | | | | or an entry in the MANPATH environment variable) does not exist, silently skip it. This brings makewhatis(8) back closer to the behaviour of espie@'s version and ought to shut up the weekly(8) whining observed by henning@ on machines not having xbase installed. Also, don't error out after the first unusable manpath entry, still try the others. Of course, still complain about non-existent directories specified on the command line and about any directories failing for other reasons than ENOENT.
* Do not report a page as arch=any merely because .Dt lacks the third argument.Ingo Schwarze2014-09-071-2/+2
| | | | | Pages found outside arch-specific dirs still get arch=any, of course. Issue reported by justinhenryhaynes at gmail dot com on misc@, thanks!
* fix debugging outputIngo Schwarze2014-09-071-1/+1
|
* Add *.gz support to apropos(1) -a, man(1), and even mandoc(1).Ingo Schwarze2014-09-031-54/+15
| | | | Implemented by moving the zip code from makewhatis(8) to the parser lib.
* If a manual page is installed gzip(1)ed, let makewhatis(8) takeIngo Schwarze2014-09-031-11/+8
| | | | | | | 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.
* When makewhatis(8) finds an .so link after the manual being pointed toIngo Schwarze2014-09-011-0/+7
| | | | | | | | has already been processed, add the file names to the names table, too, not just to the mlinks table. This fixes a bug where apropos(1) and the new man(1) wouldn't find some of the Xenocara manuals via some of their .so links. After rebuilding, run "makewhatis /usr/X11R6/man" or just wait for weekly(8).
* do not leak a file descriptor on fdopen(3) failure; from doug@Ingo Schwarze2014-08-231-0/+2
|
* 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.
* Provide a fallback version of fts(3) for systems lacking it.Ingo Schwarze2014-08-111-0/+4
| | | | | | I chose the OpenBSD version because it apparently contains various bugfixes that never made it into libnbcompat. To reduce size and complexity, i stripped out the features we don't need.
* Get rid of HAVE_CONFIG_H, it is always defined; idea from libnbcompat.Ingo Schwarze2014-08-101-2/+1
| | | | | | 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.
* Bring the handling of defective prologues even closer to groff,Ingo Schwarze2014-08-061-2/+3
| | | | | | | | | | | | in particular relaxing the distinction between prologue and body and further improving messages. * The last .Dd wins and the last .Os wins, even in the body. * The last .Dt before the first body macro wins. * Missing title in .Dt defaults to UNTITLED. Warn about it. * Missing section in .Dt does not default to 1. But warn about it. * Do not warn multiple times about the same mdoc(7) prologue macro. * Warn about missing .Os. * Incomplete .TH defaults to empty strings. Warn about it.
* Absurdly, the return value of sqlite3_column_text()Ingo Schwarze2014-08-051-4/+4
| | | | | | is "const unsigned char *", which causes warnings with GCC on Linux. Explicitly cast to "const char *" to avoid this. Issue noticed by kristaps@.
* Prefix messages about bad command line options and argumentsIngo Schwarze2014-06-211-4/+7
| | | | | with "mandoc: " or "makewhatis: ", respectively, similar to what we already do for other messages.
* Merge from OpenBSD - Marc Espie improved the ohash interface:Ingo Schwarze2014-06-201-9/+9
| | | | | | * 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
* More tweaking of set_basedir().Ingo Schwarze2014-06-201-23/+39
| | | | | | | | | | | | 1) Do not error out when getcwd(3) fails, only fail when inaccessibility of the cwd prevents processing of relative paths given on the command line. 2) Do not uselessly call set_basedir() twice in a row. While fts_read(3) in treescan() does cause the cwd to jump around, fts_close(3) is always called at the end, putting us back where we came from. The -d/-u fallback code already relied on this. 3) Fix the man-root-dir indicator in say().
* Some simple set_basedir() cleanup; more to come.Ingo Schwarze2014-06-191-16/+20
| | | | | | | | | | | | | | 1) Refrain from calling set_basedir() in the -t case, and do not attempt to strip anything from the file names in that case. Testing individual files cannot reasonably have any notion of a base dir. 2) Remove the possibility of passing NULL to set_basedir(). It was dangerous because it was not idempotent, and it served no purpose except closing a file descriptor right before exit(), which is pointless. Besides, the file descriptor is likely to be removed completely, soon. 3) Make sure that /foobar isn't treated as a subdirectory of /foo; this fixes a bug reported by espie@.
* Merge OpenBSD rev. 1.108 by sthen@; original commit message:Ingo Schwarze2014-06-181-1/+2
| | | | | | Don't display "unable to open mandoc.db" error messages (SQLITE_CANTOPEN) in the code which opens mandocdb's sqlite database when updating/deleting individual files (as used and only really useful for pkg_add/pkg_delete).
* Render roff escape sequences contained in manual page descriptionsIngo Schwarze2014-05-071-1/+10
| | | | | before putting them into the mpages table. Issue found by bentley@ in OpenBSD::Getopt(3p).
* Fix two memory leaks in makewhatis -n:Ingo Schwarze2014-05-071-1/+13
| | | | | 1. As found by nigel@, names_check() requires database access. 2. Do not leak names and strings in -n mode.
* Improve error handling in dbopen(). If PRAGMA SQL statements fail,Ingo Schwarze2014-04-271-6/+21
| | | | | | | | | | | | | report the error, close the database, and return failure from dbopen(), such that the main program can recover and rebuild the database. As noticed by stsp@, this can happen when database files are accessible, but corrupt or in the wrong format, which will now automatically be repaired. Besides, use a safer idiom after sqlite3_open*() failure that also handles out-of-memory situations correctly, and do not forget to close the database after CREATE TABLE failure.
* Reduce the verbosity of makewhatis -t:Ingo Schwarze2014-04-251-0/+2
| | | | | | | | In the past, it always showed the title lines of the files processed. Now, it only shows them when called with -D. That is better because pkg_create calls makewhatis -t. It is also more consistent with -D behaviour in non- -t modes. Issue reported by ajacoutot@; ok espie@ ajacoutot@ jasper@.
* 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).
* Audit strlcpy(3)/strlcat(3) usage:Ingo Schwarze2014-04-231-22/+22
| | | | | | * Add missing truncation checks to three calls. * In four cases where we know that the distination buffer is large enough, cast the return vailue to (void).
* improve SQL style: avoid "SELECT *", be explicit in what columns we want;Ingo Schwarze2014-04-231-1/+2
| | | | suggested by espie@.
* KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze2014-04-201-65/+66
| | | | | remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
* Two minor tweaks regarding the fallback from -u/-d to default mode:Ingo Schwarze2014-04-191-6/+8
| | | | | | | (1) Use all files found on the command line, but do *not* use all stray files found during fallback tree recursion. (2) If the fallback works, call that success, i.e. exit(0). As pointed out by naddy@, the latter is required for ports' happiness.
* Properly handle symlinks (hardlinks and .so only files were already ok):Ingo Schwarze2014-04-191-16/+75
| | | | | | | | Use the file name of the symlink but the inode number of the file pointed to, such that we get multiple mlinks records but not multiple mpages records. Also make sure they do not point outside the tree we are processing. Issue found by kili@ in desktop-file-edit(1), thanks!
* In update mode, when opening the database fails, probably because it isIngo Schwarze2014-04-181-7/+17
| | | | | | | | missing or corrupt, just rebuild it from scratch. This also helps when installing the very first port on a freshly installed machine and is similar to what espie@'s classical makewhatis(8) did. Issue reported by naddy@ via kili@.
* Rename the mpages.id column to mpages.pageid. There is no good reasonIngo Schwarze2014-04-161-11/+11
| | | | to call this kid by a different name here than in all other tables.
* Give the mlinks and keys tables a pageid index,Ingo Schwarze2014-04-161-1/+3
| | | | | | | | | | | | | | | | as suggested by jeremy@ and espie@. The mlinks index speeds up basic apropos(1) searches by around 30% because it speeds up the final SELECT FROM mlinks query by about 95%. For large result sets, the overall speedup gets even larger, in the extreme case of "apropos Nd~." bymore than 90%. The keys index finally makes the apropos(1) -O option usable: It no longer incurs relevant extra cost, while in the past it was embarrassingly slow. This comes at a cost: Total database build times grow by about 5%, and each index adds about 10% database size with -Q. I consider that acceptable in view of the huge apropos(1) performance gains. The -Q database for /usr/share/man still remains below 1 MB.
* Unify description handling across all document types (mdoc, man, cat).Ingo Schwarze2014-04-131-8/+3
| | | | | | | | Assert that the description is unset right before calling the parse_* handler, and assign a default if it's still unset right afterwards. Remove all stray asserts and default assignments found elsewhere. This fixes SQL_STEP failures for man(7) pages lacking descriptions.