summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
Commit message (Collapse)AuthorAgeFilesLines
* support for hunting memory leaks;Ingo Schwarze2022-04-141-2/+2
| | | | designed and written last autumn, polished today
* Commit and commit message by deraadt@:Ingo Schwarze2021-11-051-2/+5
| | | | | | | | | | | | | | For open/openat, if the flags parameter does not contain O_CREAT, the 3rd (variadic) mode_t parameter is irrelevant. Many developers in the past have passed mode_t (0, 044, 0644, or such), which might lead future people to copy this broken idiom, and perhaps even believe this parameter has some meaning or implication or application. Delete them all. This comes out of a conversation where tb@ noticed that a strange (but intentional) pledge behaviour is to always knock-out high-bits from mode_t on a number of system calls as a safety factor, and his bewilderment that this appeared to be happening against valid modes (at least visually), but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef. ok millert
* do not crash when a manpath directory contains a symbolic linkIngo Schwarze2021-08-191-0/+2
| | | | | | that points to a directory rather than to a regular file; bug reported by Lukas Epple <sternenseemann at systemli dot org>, and my patch also tested by him on NixOS
* Rename the compile-time configuration variable $HOMEBREWDIR toIngo Schwarze2021-08-071-4/+26
| | | | | | | | | $READ_ALLOWED_PATH, allow it to contain more than one directory, and explain how to use it for NixOS and for GNU Guix Linux. Feature improvement based on observations, input, and earlier patches from Lukas Epple <sternenseemann at systemli dot org>, and final patch also tested by Lukas.
* Remove some stray argument names from function prototypes,Ingo Schwarze2020-04-031-3/+5
| | | | | | for consistency with the dominant style used in mandoc. No functional change. Patch from Martin Vahlensieck <academicsolutions dot ch>.
* Repair more of the issues that i found in filescan() while investigatingIngo Schwarze2020-01-261-35/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the report from <Andreas dot Kahari at abc dot se> on ports@: For a symlink, use the first of the following names that is available: 1. In -t mode, the symlink itself (unchanged). 2. When the (unresolved) symlink already resides inside the manpath, just strip the manpath and use the rest (unchanged). 3. When prefix(es) of the unresolved symlink point to the manpath, strip the longest such prefix and use the rest (new); this fixes situations where the manpath or one of its parent directories is a symlink and at the same time contains symlinks to manual pages. 4. Fall back to the fully resolved symlink, with the manpath stripped (new); this may for example happen when the command line passes symlinks from outside the manpath that point to manual pages inside the manpath, or if manual page trees contain symlinks to symlinks and not all of them are given on the command line. The fallback (4) isn't perfect. You can construct symlink spaghetti in such a way that this algorithm will not enter all manual page names into the database that a human would be able to deduce. But i do not expect such spaghetti to actually occur in practice (not even in ports), and a full fix would require re-implementing realpath(3) in terms of step-by-step readlink(2) calls, repeating the complicated algorithm (3) after each step. While here, also stop using PATH_MAX as the size of a static buffer in filescan(); on some systems, it can be unreasonably large. Instead, allocate path strings dynamically.
* Fix incorrect file type tests.Ingo Schwarze2020-01-261-2/+2
| | | | | | | | | | This bug caused sockets and character special devices to be accepted as manual pages if they appeared inside manpaths, and it caused incorrect file names to be entered into the database when the manpath or one of its parent directories was a symbolic link. This fixes the issues reported by <Andreas dot Kahari at abc dot se> on ports@, but additional issues remain when symbolic links are contained in a manpath that involves another symbolic link.
* Minor cleanup, no functional change:Ingo Schwarze2020-01-251-54/+59
| | | | | | | Do not abuse strstr(3) to check whether one long string starts with another long string. Instead, use strncmp(3) with the proper length. In set_basedir(), also reset *basedir in the error brances for extra safety. While here, invert some more Yoda conditions in the neighbourhood.
* Enter dangling .so links into the database, to avoid harassingIngo Schwarze2019-05-031-6/+11
| | | | | | | | | users of man(1) about running makewhatis(8), which won't help. Seeing the content of the broken .so request might even help users to figure out how to access the manual page they want. Fixing the last issue 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-301-24/+20
| | | | | | | | | | | | | | The struct roff_man used to be a bad mixture of internal parser state and public parsing results. Move the public results to the parsing result struct roff_meta, which is already public. Move the rest of struct roff_man to the parser-internal header roff_int.h. Since the validators need access to the parser state, call them from the top level parser during mparse_result() rather than from the main programs, also reducing code duplication. This keeps parser internal state out of thee main programs (five in mandoc portable) and out of eight formatters.
* Major cleanup; may imply minor changes in edge cases of error reporting.Ingo Schwarze2018-12-141-2/+1
| | | | | | | | | | | Finally, drop support for the run-time configurable mandocmsg() callback. It was over-engineered from the start, never used for anything in a decade, and repeatedly caused maintenance headaches. Consolidate reporting infrastructure into two files, mandoc.h and mandoc_msg.c, mopping up the bits and pieces that were scattered around main.c, read.c, mandoc_parse.h, libmandoc.h, the prototypes of four parsing-related functions, and both parser structs.
* Cleanup, no functional change:Ingo Schwarze2018-12-131-0/+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.
* Remove more pointer arithmetic passing via regions outside the arrayIngo Schwarze2018-08-171-10/+12
| | | | | that is undefined according to the C standard. Robert Elz <kre at munnari dot oz dot au> pointed out i wasn't quite done yet.
* Logically, the following are are type names - just like .Vt,Ingo Schwarze2018-02-231-5/+26
| | | | | | | | | | | | some of them with an optional variable name following: - .Ft - .Fa in the SYNOPSIS - .Fn second and later arguments in the SYNOPSIS So add these to the .Vt macro table in the mandoc.db(5) database. During my LibreSSL work, i'm getting really tired of typing $ man -k Vt,Ft,Fa=some_type_name over and over again; now, this becomes just: $ man -k Vt=some_type_name
* In man(7) and cat pages, cut off excessive one line descriptions.Ingo Schwarze2018-02-071-2/+12
| | | | | An extreme example of how rogue files could mess up apropos(1) output was reported by bentley@: qwtlicense(3) in the x11/qwt port.
* Fix previous: mmap(2) returns MAP_FAILED on failure, not NULL.Ingo Schwarze2017-08-261-5/+5
| | | | Bug pointed out by tedu@.
* Do not fork and exec cmp(1); instead, simply fstat(2), mmap(2), andIngo Schwarze2017-08-261-39/+51
| | | | | | compare the files directly, allowing a much stricter pledge(2), at very little cost: merely 15 additional lines of very simple code. Suggested by George Brown <321 dot george at gmail dot com> on misc@.
* No need to fork and exec rm(1) -rf, we know that we have exactlyIngo Schwarze2017-08-261-20/+3
| | | | | | | | | one file and exactly one directory to remove. While here, increase the size of the buffer such that the file name actually fits. Minus 17 lines of code, no functional change. Opportunity for simplification reported by George Brown <321 dot george at gmail dot com> on misc@.
* When the mparse_alloc() prototype changed in read.c 1.179, updatingIngo Schwarze2017-07-281-1/+1
| | | | | | the enum constant was forgotten in this call. No functional change since the mmsg argument is NULL anyway. Found by florian@ with clang.
* Improve rev. 1.250 further:Ingo Schwarze2017-07-151-1/+1
| | | | | | | | If a database is empty, we already don't write a database file and delete an existing one. If none exists, that only means the database was empty and remains so, which is not an error. So don't nag about it, in particular because that would be a weekly(8) annoyance. Issue reported by jmc@.
* Split -Wstyle into -Wstyle and the even lower -Wbase, and addIngo Schwarze2017-06-241-1/+2
| | | | | | | | | | | | | | | -Wopenbsd and -Wnetbsd to check conventions for the base system of a specific operating system. Mark operating system specific messages with "(OpenBSD)" at the end. Please use just "-Tlint" to check base system manuals (defaulting to -Wall, which is now -Wbase), but prefer "-Tlint -Wstyle" for the manuals of portable software projects you maintain that are not part of OpenBSD base, to avoid bogus recommendations about base system conventions that do not apply. Issue originally reported by semarie@, solution using an idea from tedu@, discussed with jmc@ and jca@.
* Never create empty databases.Ingo Schwarze2017-05-171-0/+22
| | | | | | | | | | When pkg_add(1)ing packages installing manual pages into some directory, the database in that directory automatically gets created or updated, no change so far. This patch causes the database file to be automatically unlinked when pkg_delete(1)ing the last package having manual pages in that directory, to leave less cruft behind. Suggested by ajacoutot@.
* Move .sp to the roff modules. Enough infrastructure is in placeIngo Schwarze2017-05-051-1/+0
| | | | now that this actually saves code: -70 LOC.
* move .ll to the roff modulesIngo Schwarze2017-05-051-1/+0
|
* Parser reorg:Ingo Schwarze2017-05-041-2/+4
| | | | | Generate the first node on the roff level: .br Fix some column numbers in diagnostic messages while here.
* Continue parser unification:Ingo Schwarze2017-04-241-9/+8
| | | | | | | | * Make enum rofft an internal interface as enum roff_tok in "roff.h". * Represent mdoc and man macros in enum roff_tok. * Make TOKEN_NONE a proper enum value and use it throughout. * Put the prologue macros first in the macro tables. * Unify mdoc_macroname[] and man_macroname[] into roff_name[].
* Fix a copy-and-paste error that caused man(7) manuals withoutIngo Schwarze2017-03-031-1/+1
| | | | | a section number in .TH to be misinterpreted as preformatted. Found by jsg@ with cppcheck.
* No need to cast NULL when assigning it to a variable;Ingo Schwarze2017-02-171-1/+1
| | | | from Christos Zoulas <christos at NetBSD>.
* Be consistent in protecting __attribute__ attributes with __;Ingo Schwarze2017-02-171-1/+1
| | | | from Christos Zoulas <christos @ NetBSD>.
* warn about missing one-line description;Ingo Schwarze2017-01-271-3/+8
| | | | missing feature found in the TODO file
* Parse the section number from the content of preformatted pagesIngo Schwarze2017-01-271-13/+30
| | | | and warn if it doesn't match the directory where the file was found.
* If parsing a page reveals that it is neither mdoc(7) nor man(7),Ingo Schwarze2017-01-271-12/+16
| | | | | fall back to treating it as preformatted rather than treating it as man(7) anyway.
* fix base directory detection for makewhatis -tIngo Schwarze2017-01-271-0/+14
|
* Always register names taken from file names in the names ohash.Ingo Schwarze2017-01-271-4/+6
| | | | Bug found by makewhatis -p crashing in mlink_check().
* Do text production for .Bt, .Ex, .Rv, .Ud at the validation stageIngo Schwarze2017-01-111-2/+2
| | | | | | | | | rather than in the formatters. Use NODE_NOSRC flag for .Lb and NODE_NOSRC and NODE_NOPRT for .St. Results in a more rigorous syntax tree and in 135 lines less code. This work was triggered by a question from Abhinav Upadhyay <er dot abhinav dot upadhyay at gmail dot com> (NetBSD) on discuss@.
* Use new NODE_NOSRC and NODE_NOPRT flags for .Bx and .At.Ingo Schwarze2017-01-101-2/+2
| | | | More rigorous AST and 40 lines less code.
* For the .Ux/.Ox family of macros, do text production at the validationIngo Schwarze2017-01-101-130/+135
| | | | | stage rather than in each and every individual formatter, using the new NODE_NOSRC flag. More rigorous and also ten lines less code.
* cast off_t and uint64_t for printf(3)Ingo Schwarze2016-10-221-1/+2
| | | | | | to make sure that widths match on all platforms; from Ed Maste <emaste at freebsd dot org>; OK guenther@
* 0x%llu is a bad idea, make that 0x%llx;Ingo Schwarze2016-10-201-1/+1
| | | | noticed while investigating a report from Ed Maste
* Compat glue for the FreeBSD comparison function prototype for fts_open(3)Ingo Schwarze2016-10-181-0/+8
| | | | | which differs from what most other systems use. While here, improve diagnostic output of ./configure tests.
* Simplify and correct support for reproducible builds, such that databaseIngo Schwarze2016-10-181-35/+25
| | | | | | | | | | entries come in a well-defined order even in the presence of MLINKS. Do this by using the compar() argument of fts_open(3) rather than trying to sort later, which missed some cases. This also shortens the code by a few lines. Diff from Ed Maste <emaste @ FreeBSD>, adapted to our tree and tweaked a bit by me, final version confirmed by Ed.
* When "makewhatis -d" tries to add to a database that doesn't (yet) exist,Ingo Schwarze2016-09-021-3/+3
| | | | | | | silently create it from scratch instead of printing a warning. The annoying warning message was reported by ajacoutot@, and espie@ convincingly argues that a non-existing database can be considered equivalent to an empty one.
* remove "sparc" from a commentIngo Schwarze2016-09-011-1/+1
|
* When trying to edit an existing database with makewhatis(8) -d or -uIngo Schwarze2016-08-221-4/+4
| | | | | | | but reading the database fails, report the full path to the database on standard error, and mention that the database is automatically recreated from scratch. Suggested by espie@.
* When the content of a manual page does not specify a section, theIngo Schwarze2016-08-171-1/+2
| | | | | | | | empty string got added to the list of sections, breaking the database format slightly and causing the page to not be considered part of any section, not even if a section could be deduced from the directory or from the file name. Bug found due to the bogus pcredemo(3) "manual" in the pcre-8.38p0 package.
* fix a typo that prevented names from .Dt from getting priorityIngo Schwarze2016-08-051-1/+1
| | | | over names from .Sh NAME
* Repair makewhatis -t, regression in rev. 1.221 reported by naddy@.Ingo Schwarze2016-08-011-2/+3
|
* Sort pages in the pages table by file names.Ingo Schwarze2016-07-291-7/+26
|
* No need to populate the TYPE_arch and TYPE_sec bits, the informationIngo Schwarze2016-07-291-24/+7
| | | | | | | | | | | | is provided directly to dba_page_add() in dbadd_mlink() and to dba_page_new() in dbadd(). No need for a dedicated loop for NAME_FILE. It's done in dbadd_mlink() anyway. In this context, also record section numbers taken from filenames and from .Dt and .TH macros, architectures taken from .Dt macros, and fix the filtering of duplicate filename entries.
* Now that our man.conf(5) format is mature and extremely simple,Ingo Schwarze2016-07-191-2/+1
| | | | | | | | delete manpath(1) support. With the mandoc-based man(1), manpath(1) is utterly useless. Just set MANPATH_DEFAULT in configure.local for sane operating system defaults, use man.conf(5) for machine- specific modifications, and use ${MANPATH}, -m, and -M for user preferences.