summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/roff.c
AgeCommit message (Collapse)Author
2018-08-01After rewriting the parse buffer from scratch, we also have to resetIngo Schwarze
the parse point to the beginning of the new buffer or we risk out of bounds accesses. Bug found by Leah Neukirchen <leah at vuxu dot org> with valgrind on Void Linux.
2018-04-11preserve comments before .Dd when converting mdoc(7) to man(7)Ingo Schwarze
with mandoc -Tman; suggested by Thomas Klausner <wiz at NetBSD>
2018-04-10Two new low-level roff(7) features:Ingo Schwarze
* .nr optional third argument (auto-increment step size) * \n+ and \n- numerical register auto-increment and -decrement bentley@ reported on Dec 9, 2013 that lang/sbcl(1) uses these.
2018-04-09When accessing an undefined number register, define it to be zero, likeIngo Schwarze
the previous commit for strings and macros, only technically simpler. Desired behaviour also mentioned by Werner Lemberg in 2011. This diff adds functionality but is -21 +19 LOC. :-)
2018-04-09Using an undefined string or macro will cause it to be defined as empty.Ingo Schwarze
Observed by Werner Lemberg on Nov 14, 2011 and rotting on my TODO list ever since.
2017-07-14The .Dd and .TH macros must interrupt .ce, too;Ingo Schwarze
fixing tree corruption and assertion failure found by jsg@ with afl(1)
2017-07-14Explicitly initialize a variable where the compiler is (understandably)Ingo Schwarze
unable to figure out that it is never used uninitialized. While here, tweak the content of the variable to make its usage easier to understand. No functional change.
2017-07-13eqn(7) .EQ has to break man(7) next-line scope, or tree corruptionIngo Schwarze
and use after free many ensue; again found by jsg@ with afl(1)
2017-07-08Simplify by creating struct roff_node syntax tree nodes for tbl(7)Ingo Schwarze
right from roff_parseln() rather than delegating to read.c, similar to what i just did for eqn(7). The interface function roff_span() becomes obsolete and is deleted, the former interface function roff_addtbl() becomes static, the interface functions tbl_read() and tbl_cdata() become void, and minus twelve linus of code. No functional change.
2017-07-08fix an assertion failure triggered by .ce in next-line scope;Ingo Schwarze
found by jsg@ with afl(1)
2017-07-081. Eliminate struct eqn, instead use the existing membersIngo Schwarze
of struct roff_node which is allocated for each equation anyway. 2. Do not keep a list of equation parsers, one parser is enough. Minus fifty lines of code, no functional change.
2017-07-04Fix handling of \} on roff request lines.Ingo Schwarze
Cures bogus error messages in pages generated with pod2man(1).
2017-06-25Add support for the MT and ME mailto macros, used for example in wg(8).Anthony J. Bentley
feedback and ok schwarze@
2017-06-24Split -Wstyle into -Wstyle and the even lower -Wbase, and addIngo Schwarze
-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@.
2017-06-18Implement appending to standard man(7) and mdoc(7) macros with .am.Ingo Schwarze
With roff_getstrn(), provide finer control which definitions can be used for what: * All definitions can be used for .if d tests and .am appending. * User-defined for \* expansion, .dei expansion, and macro calling. * Predefined for \* expansion. * Standard macros, original or renamed, for macro calling. Several related improvements while here: * Do not return string table entries that have explicitly been removed. * Do not create a rentab entry when trying to rename a non-existent macro. * Clear an existing rentab entry when the external interface roff_setstr() is called with its name. * Avoid trailing blanks in macro lines generated from renamed and from aliased macros. * Delete the duplicate __m*_reserved[] tables, just use roff_name[].
2017-06-17style message about duplicate RCS ids; inspired by mdoclintIngo Schwarze
2017-06-17style message about missing RCS ids; inspired by mdoclintIngo Schwarze
2017-06-14Naive implementation of the roff(7) .po (page offset) request.Ingo Schwarze
This clearly works when .po is called on the top level, but might not be sophisticated enough if people call .po inside indentation-changing contexts, but i haven't seen that in manual pages (yet :).
2017-06-14simple implementation of the roff(7) .als (macro alias) request,Ingo Schwarze
sufficient for pages using po4a(1)
2017-06-14implement the roff(7) d (macro or string defined) conditionalIngo Schwarze
2017-06-14implement roff(7) .rj (right justify) requestIngo Schwarze
2017-06-13Explicitly ignore .br, .ce, and .sp inside tbl(7) text blocks.Ingo Schwarze
With the current code structure, they would appear at the wrong place in the syntax tree, so it is better to not insert them into the tree at all and issue an UNSUPP message instead.
2017-06-08Properly reinitialize roffce_node between parses,Ingo Schwarze
or this may crash with use-after-free in makewhatis(8); reported by jmc@, thanks!
2017-06-07Implement the roff(7) .rn (rename macro or string) request.Ingo Schwarze
Renaming a user-defined macro is very simple: just copy the definition to the new name and delete the old name. Renaming high-level macros is a bit tricky: use a dedicated key-value-table, with non-standard names as keys and standard names as values. When a macro is found that is not user-defined, look it up in the "renamed" table and translate it back to the standard name before passing it on to the high-level parsers.
2017-06-06Minimal implementation of the roff(7) .ce request (center a numberIngo Schwarze
of input lines without filling). Contrary to groff, high-level macros abort .ce mode for now.
2017-06-04Implement the roff(7) .mc (right margin character) request.Ingo Schwarze
The Tcl/Tk manual pages use this extensively. Delete the TERM_MAXMARGIN hack, it breaks .mc inside .nf; instead, implement a proper TERMP_BRNEVER flag.
2017-06-04Pure preprocessor implementation of the roff(7) .ec and .eo requestsIngo Schwarze
(escape character control), touching nothing after the preprocessing stage and keeping even the state variable local to the preprocessor. Since the escape character is also used for line continuation, this requires pulling the implementation of line continuation from the input reader to the preprocessor, which also considerably shortens the code required for that. When the escape character is changed, simply let the preprocessor replace bare by escaped backslashes and instances of the non-standard escape character with bare backslashes - that's all we need. Oh, and if anybody dares to use these requests in OpenBSD manuals, sending a medium-sized pack of axe-murderes after them might be a worthwhile part of the punishment, but probably insuffient on its own.
2017-05-08Line-breaking roff(7) requests also break man(7) next-line scope.Ingo Schwarze
Considering that real roff implements next-line scope using input line traps, that isn't all that surprising. Issue found in the games/xbattle port.
2017-05-08Basic implementation of the roff(7) .ti (temporary indent) request.Ingo Schwarze
Needed by about four dozen ports (thanks to naddy@ for the research).
2017-05-07Basic implementation of the roff(7) .ta (define tab stops) request.Ingo Schwarze
This is the first feature made possible by the parser reorganization. Improves the formatting of the SYNOPSIS in many Xenocara GL manuals. Also important for ports, as reported by many, including naddy@.
2017-05-05Move .sp to the roff modules. Enough infrastructure is in placeIngo Schwarze
now that this actually saves code: -70 LOC.
2017-05-05move .ll to the roff modulesIngo Schwarze
2017-05-05Move handling of the roff(7) .ft request from the man(7)Ingo Schwarze
modules to the new roff(7) modules. As a side effect, mdoc(7) now handles .ft, too. Of course, do not use that.
2017-05-04Parser reorg:Ingo Schwarze
Generate the first node on the roff level: .br Fix some column numbers in diagnostic messages while here.
2017-04-29Parser unification: use nice ohashes for all three request and macro tables;Ingo Schwarze
no functional change, minus two source files, minus 200 lines of code.
2017-04-24Continue parser unification:Ingo Schwarze
* 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[].
2017-03-09Fix blunder in previous: we must keep the line parse bufferIngo Schwarze
consistent even when aborting the parsing of the line. That buffer is not our own, but owned and reused by mparse_buf_r(), read.c. Returning without cleanup leaked memory and caused write overruns of the old, typically much smaller buffer in mparse_buf_r(). Promptly noticed by tb@ with afl(1), using MALLOC_OPTIONS=C.
2017-03-08prevent infinite recursion while expanding the argumentsIngo Schwarze
of a user-defined macro; issue found by tb@ with afl(1)
2017-03-03remove a few redundant conditions that jsg@ found with cppcheckIngo Schwarze
2017-03-03Fix previous: do not access the byte before the string if the stringIngo Schwarze
is empty; found by jsg@ with afl(1).
2017-02-17Fix a read buffer overrun that copied random data from memory intoIngo Schwarze
text nodes when a string passed to deroff() ended in a backslash and the byte after the terminating NUL was non-NUL, found by tb@ with afl(1). Invalid bytes so copied with the high bit set could later sometimes trigger another out of bounds read access to static memory in roff_strdup(), so add an assertion there to abort safely in case of similar data corruption.
2017-01-12Skipping all escape sequences at the beginning of strings in deroff()Ingo Schwarze
was too aggressive. There are strings that legitimately begin with an escape sequence. Only skip leading escape sequences representing whitespace. Bug reported by martijn@.
2017-01-10For the .Ux/.Ox family of macros, do text production at the validationIngo Schwarze
stage rather than in each and every individual formatter, using the new NODE_NOSRC flag. More rigorous and also ten lines less code.
2017-01-10simplify; NODE_ENDED does no harm in man(7)Ingo Schwarze
2017-01-10unify names of AST node flags; no change of cpp outputIngo Schwarze
2016-01-08Delete the redundant "nchild" member of struct roff_node, replacingIngo Schwarze
most uses by one, a few by two pointer checks, and only one by a tiny loop - not only making data smaller, but code shorter as well. This gets rid of an implicit invariant that confused both static analysis tools and human auditors. No functional change.
2015-10-22move man(7) validation into the dedicated validation phase, tooIngo Schwarze
2015-10-21Move all mdoc(7) node validation done before child parsingIngo Schwarze
to the new separate validation pass, except for a tiny bit needed by the parser which goes to the new mdoc_state() module; cleaner, simpler, and surprisingly also shorter by 15 lines.
2015-10-20In order to become able to generate syntax tree nodes on the roff(7)Ingo Schwarze
level, validation must be separated from parsing and rewinding. This first big step moves calling of the mdoc(7) post_*() functions out of the parser loop into their own mdoc_validate() pass, while using a new mdoc_state() module to make syntax tree state handling available to both the parser loop and the validation pass.
2015-10-15Delete two preprocessor constants that are no longer used.Ingo Schwarze
Patch from Michael Reed <m dot reed at mykolab dot com>.