aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/main.c
Commit message (Collapse)AuthorAgeFilesLines
* Cleanup, no functional change:Ingo Schwarze2018-12-301-20/+17
| | | | | | | | | | | | | | 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.
* Move the full responsibility for reporting open(2) errors fromIngo Schwarze2018-12-201-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | mparse_open() to the caller. That is better because only the caller knows its preferred reporting method and format and only the caller has access to all the data that should be included - like the column number in .so processing or the current manpath in makewhatis(8). Moving the mandoc_msg() call out is possible because the caller can call strerror(3) just as easily as mparse_open() can. Move mandoc_msg_setinfilename() closer to the parsing of the file contents, to avoid problems *with* the file (like non-existence, lack of permissions, etc.) getting misreported as problems *in* the file. Fix the column number reported for .so failure: let it point to the beginning of the filename. Taken together, this prevents makewhatis(8) from spewing confusing messages about .so failures to stderr, a bug reported by Raf Czlonka <rczlonka at gmail dot com> on ports@. It also prevents mandoc(1) from issuing *two* messages for every single .so failure.
* Almost mechanical diff to remove the "struct mparse *" argumentIngo Schwarze2018-12-141-6/+5
| | | | | | | | from mandoc_msg(), where it is no longer used. While here, rename mandoc_vmsg() to mandoc_msg() and retire the old version: There is really no point in having another function merely to save "%s" in a few places. Minus 140 lines of code.
* Major cleanup; may imply minor changes in edge cases of error reporting.Ingo Schwarze2018-12-141-74/+38
| | | | | | | | | | | 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-1/+2
| | | | | | | | | | 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-3/+1
| | | | | | | | | | 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.
* In -T locale (the default), -T ascii, and -T utf8 mode, provide a newIngo Schwarze2018-11-221-5/+17
| | | | | | | | | | | | | | | output option -O tag[=term] to move right to the definition of "term" when opening the manual page in a pager, effectively porting the -T html fragment name feature - https://man.openbsd.org/ksh#ulimit - to the terminal. Try: $ man -O tag uvm_sysctl $ man -O tag=ulimit ksh $ man -O tag 3 compress Feature development triggered by a question from kn@. Klemens also tested, provided feedback that resulted in improvements, and provided an OK.
* The upcoming .while request will have to re-execute roff(7) linesIngo Schwarze2018-08-231-8/+2
| | | | | | | parsed earlier, so they will have to be saved for reuse - but the read.c preparser does not know yet whether a line contains a .while request before passing it to the roff parser. To cope with that, save all parsed lines for now. Even shortens the code by 20 lines.
* If somebody asks "man 3 chmod",Ingo Schwarze2018-08-091-3/+9
| | | | | | don't respond with the lie: "No entry for chmod in the manual." Instead, say "No entry for chmod in section 3 of the manual." Came up after a question from kn@; OK kn@.
* Some broken terminal emulators (e.g. sakura) do the equivalentIngo Schwarze2018-05-141-2/+3
| | | | | | of "stty cols 0". Ignore that insanity rather than setting conf.output.width to an invalid value and embarking on infinite loops. Issue reported by Jesper Wallin <jesper at ifconfig dot se>, thanks!
* Compatibility with man-db:Ingo Schwarze2018-04-191-13/+57
| | | | | | | | | In page name mode (= man(1) default mode), also try to interpret names containing slashes as absolute or relative file names. Missing feature reported by Nate Bargmann on <groff at gnu dot org>, and the man-db maintainer Colin Watson <cjwatson at debian dot org> kindly explained to me how this is supposed to work.
* Use TIOCGWINSZ to reduce the default -Owidth during interactive useIngo Schwarze2018-04-131-2/+14
| | | | | | | on terminals narrower than 79 columns and the default -Oindent on terminals narrower than 66 columns. Requested by and feedback from pirofti@; mpi@ and juanfra@ also like the general direction.
* Invalidate the tag_files.tfd after fclose(3)ing the stram associatedIngo Schwarze2018-02-231-2/+2
| | | | | | with it. In main() assert that the tfd was actually invalidated. This avoids closing an invalid fd. From tb@; OK deraadt@ on an earlier version.
* When the stdout stream gets broken, there is no point in readingIngo Schwarze2017-08-211-1/+12
| | | | | | | | | any more input files, and it would be misleading to start a parser, because that would show randomly truncated text. Instead, print an error message and exit the program. Issue found by Leah Neukirchen <leah at vuxu dot org>, who was surprised to see half a manpage when her /tmp/ overflew.
* Cast the return value of chdir(2) to void. We already have a commentIngo Schwarze2017-07-261-2/+2
| | | | | | above explaining to human auditors why no error checking is needed here, so it's only fair to tell the compiler, too. Worried compiler reported by Michael <Stapelberg at debian>.
* For -Tlint, put parser messages on stdout instead of stderr.Ingo Schwarze2017-07-201-7/+10
| | | | | | | | | | | Originally, naddy@ requested this in 2011 (or maybe even earlier). It was discussed with joerg@, kristaps@, naddy@, and espie@ in 2011, and everybody agreed in principle, but it was postponed because kristaps@ wanted to do some cleanup of the message system first. Meanwhile, message infrastructure was improved about a dozen times... This makes long, tedious commands like "mandoc -Tlint *.1 2>&1 | less" unnecessary and allows simple ones like "man -l -Tlint *.1".
* Printing "BASE:" in messages about violations of base system conventionsIngo Schwarze2017-07-041-3/+2
| | | | | is confusing, simply print "STYLE:", which is intuitive and does not sound excessively alarming; suggested by jmc@, OK tedu@ jmc@.
* If a single page references the same non-existent manual more thanIngo Schwarze2017-07-021-2/+6
| | | | | | once, print "(N times)" after the message "referenced manual not found", to lessen the risk that people fix the first instance and miss the others; jmc@ confirmed that this is useful.
* add warning "cross reference to self"; inspired by mdoclintIngo Schwarze2017-07-021-4/+6
|
* When checking cross references with -Tlint, ultimately fall back toIngo Schwarze2017-07-011-3/+12
| | | | | | | | | | | | | | | | | looking in the current working directory. Not a security issue because the files are never open(2)ed, only access(2)ed. Requested by jmc@ and inspired by mdoclint(1). This cannot be perfect because it only works for files having the exact filename ./pagename.sec - mandoc has no way to figure out which files might contain a manual for multiple names, or that files in autohell might be called ./pagename.man.in instead, or which subdirectories might contain additional source files. Also, it may hide messages if you have bogus stuff lying around in the directory where you run mandoc -Tlint. But jmc@ considers it important, and good enough for everyday use. Also avoid leaking the memory for the file name while here.
* When checking the validity of cross references with -Tlint,Ingo Schwarze2017-07-011-7/+13
| | | | | | | | | | | | | fall back from database search to file system search just like man(1) does when looking up manuals. This is not too expensive because on a system having up-to-date mandoc.db(5) files, it only prolongs the time needed to check *invalid* references - and you are not supposed to have many of those, right? And on a system with missing or invalid mandoc.db(5) files, spending a bit of time and warning loudly about the real problem is also better than quickly issuing bogus warnings about cross references that are actually valid.
* Basic reporting of .Xrs to manual pages that don't existIngo Schwarze2017-07-011-1/+34
| | | | | | | | | | | | 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.
* Split -Wstyle into -Wstyle and the even lower -Wbase, and addIngo Schwarze2017-06-241-26/+43
| | | | | | | | | | | | | | | -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@.
* enable -Wstyle by default in -Tlint; OK jmc@Ingo Schwarze2017-06-031-2/+2
|
* Delete the -T xhtml command line option.Ingo Schwarze2017-05-171-3/+1
| | | | | It has been obsolete for more than two years. Use -T html.
* Introduce a new mandoc(1) message level, -W style, below -W warning.Ingo Schwarze2017-05-161-11/+14
| | | | | | | | | | | | | Switch -W all from meaning -W warning to meaning -W style. The meaning of -T lint does *not* change, it still implies -W warning. No messages on the new level yet, but they will come. Usually, i do not lightly make the user interface larger. But this has been planned for years, and EXIT STATUS 1 was reserved for it all the time. The message system is now stable enough to finally implement it. jmc@ regarding the concept: "really good idea"
* Now that global -i is gone, pass -i through to the apropos(1)Ingo Schwarze2017-04-181-3/+7
| | | | | | expression parser, such that "apropos -i 'Nm~dump\>'" finds kdump(1) and WCOREDUMP(2) and you don't need to type the counter-intuitive "apropos -- -i 'Nm~dump\>'".
* Delete the undocumented and unimplemented man(1) -i (interactiveIngo Schwarze2017-04-181-5/+1
| | | | | apropos) option. It will not be implemented. Featurism isn't the plan for the future; simplicity is.
* simplify the SYNOPSIS as well, just like the option lists;Ingo Schwarze2017-03-271-10/+8
| | | | suggested by and OK jmc@
* Silently ignore invalid -m input formats rather than erroring out.Ingo Schwarze2017-03-201-16/+8
| | | | | | As observed by Jan Stary <hans at stare dot cz>, this is useful such that after 'alias man="man -m $HOME/man"', 'man -l foo.1' still works. Simplify and shorten the description of -m, and use .Ic for macros.
* new -mdoc -Tmarkdown output mode; OK millert@ reyk@ tb@;Ingo Schwarze2017-03-031-1/+7
| | | | thanks to reyk@ and to Vsevolod at FreeBSD for suggesting it
* Since SQLite is gone, we no longer need the "flock" pledge.Ingo Schwarze2017-02-221-3/+3
| | | | Patch from semarie@, OK tb@.
* Be consistent in protecting __attribute__ attributes with __;Ingo Schwarze2017-02-171-2/+2
| | | | from Christos Zoulas <christos @ NetBSD>.
* Fix rev. 1.280: -O syntax is different in default apropos(1) outputIngo Schwarze2017-02-161-18/+23
| | | | | mode and in other output modes, so do not error out prematurely. Also sort local variables in main() while here.
* In -Ttree output mode, show the BROKEN node flag andIngo Schwarze2017-02-101-3/+5
| | | | provide a -Onoval output option to show the unvalidated tree.
* warn about invalid output optionsIngo Schwarze2017-01-271-4/+10
| | | | | and error out if they occur on the command line; missing feature found in the TODO file
* Use stdout rather than stdin for controlling the terminalIngo Schwarze2017-01-091-6/+6
| | | | | | | such that "cat foo.mdoc | man -l" works. Issue reported by Christian Neukirchen <chneukirchen at gmail dot com> and also tested by him on Void Linux with both glibc and musl. The patch makes sense to millert@.
* Warnings and errors that occur during mdoc_validate()Ingo Schwarze2017-01-091-2/+3
| | | | | | or during man_validate() have to affect the mandoc(1) EXIT STATUS. Many thanks to <Yuri dot Pankov at gmail dot com> (illumos developer) for reporting this regression.
* We cannot use fputs(3) in passthrough() because the stdout streamIngo Schwarze2016-09-181-5/+15
| | | | | | | | | | | | might be in stdio wide orientation due to prior formatting of an unformatted manual in man -aTutf8 mode. So for now, use fflush(3) followed by unbuffered write(2) instead. Fixes output corruption on glibc discovered on Linux while testing a diff to fix a loosely related bug reported by <jmates at ee dot washington dot edu>. I detest the concept of stdio stream orientation. One day, i will rewrite term_ascii.c to always use narrow streams, even in UTF-8 output mode. But that's too much work for today.
* Make sure an output device is allocated before calling terminal_sepline(),Ingo Schwarze2016-09-181-28/+35
| | | | | | fixing a NULL pointer access that happened when the first of multiple pages shown was preformatted, as in "man -a groff troff". Crash reported by <jmates at ee dot washington dot edu> on bugs@, thanks!
* fix printf("%s", NULL);Ingo Schwarze2016-08-091-2/+3
| | | | found while investigating an unrelated bug report from jsg@
* Remove the dependency on SQLite without loss of functionality.Ingo Schwarze2016-07-191-25/+4
| | | | | Stop supporting systems that don't have mmap(3). Drop the obsolete names_check() now that we deleted MLINKS.
* Use __attribute__((__format__ throughout.Ingo Schwarze2016-07-191-7/+1
| | | | | | | Triggered by a smaller patch from Christos Zoulas. While here, unify style, move several config tests to config.h, and delete the useless MANDOC_CONFIG_H.
* To remove the const qualifier from a pointer to an object - eitherIngo Schwarze2016-07-151-2/+2
| | | | | | | | | because we know it is actually mutable or because we are passing it to a function that doesn't accept a const object but won't actually attempt to modify it - simply casting from (const type *) to (type *) is legal C and clearly expresses the intent. So get rid of the obfuscating UNCONST macro. Basic idea discussed with guenther@.
* Fix previous: the mandocdb() prototype was already there, it justIngo Schwarze2016-07-151-4/+3
| | | | hid among static functions, as noticed by tedu@ (my bad).
* add missing prototypes, no code change;Ingo Schwarze2016-07-151-1/+4
| | | | noticed by Christos Zoulas with -Wmissing-prototypes
* Add support for Mac OS X's sandbox_init(3) sandbox functionality, whichKristaps Dzonsons2016-07-121-1/+9
| | | | | | | is marked as DEPRECATED in OS X after 2011 or so, but has not been removed and has no replacement. ok schwarze@
* On OpenBSD, more(1) is actually less(1) with a small number ofIngo Schwarze2016-07-101-3/+3
| | | | | | | compatibility features - so we can safely use more -T on OpenBSD. But don't do that in the portable version: more -T is unlikely to work elsewhere. Issue reported by Svyatoslav Mishyn <juef at openmailbox dot org>.
* ISO C99 7.19.2.5 doesn't like mixing putchar(3) and putwchar(3) onIngo Schwarze2016-07-081-2/+2
| | | | | | the same stream, and actually, it fails spectacularly on glibc. Portability issue pointed out by Svyatoslav Mishyn <juef at openmailbox dot org> after testing on Void Linux.
* Do not hardcode "makewhatis" in a warning message, use BINM_MAKEWHATIS.Ingo Schwarze2016-05-181-3/+3
| | | | Patch from Peter Bray <pdb_ml at yahoo dot com dot au>.