summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/roff.c
AgeCommit message (Collapse)Author
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>.
2015-10-13Major character table cleanup:Ingo Schwarze
* Use ohash(3) rather than a hand-rolled hash table. * Make the character table static in the chars.c module: There is no need to pass a pointer around, we most certainly never want to use two different character tables concurrently. * No need to keep the characters in a separate file chars.in; that merely encourages downstream porters to mess with them. * Sort the characters to agree with the mandoc_chars(7) manual page. * Specify Unicode codepoints in hex, not decimal (that's the detail that originally triggered this patch). No functional change, minus 100 LOC, and i don't see a performance change.
2015-10-12To make the code more readable, delete 283 /* FALLTHROUGH */ commentsIngo Schwarze
that were right between two adjacent case statement. Keep only those 24 where the first case actually executes some code before falling through to the next case.
2015-10-06modernize style: "return" is not a function; ok cmp(1)Ingo Schwarze
2015-09-26/* NOTREACHED */ after abort() is silly, delete itIngo Schwarze
2015-08-29If we have to reparse the text line because we spring an input line trap,Ingo Schwarze
we must not escape breakable hyphens yet, or mparse_buf_r() in read.c will complain and replace the escaped hyphens with question marks. Bug found in ocserv(8) following a report from Kurt Jaeger <pi at FreeBSD>.
2015-08-29Implement the escape sequence \\$*, expanding to all argumentsIngo Schwarze
of the current user-defined macro. This is another missing feature required for ocserv(8). Problem reported by Kurt Jaeger <pi at FreeBSD>.
2015-08-29Minimal implementation of the read-only number register \n(.$Ingo Schwarze
which returns the number of arguments of the current macro. This is one of the missing features required for ocserv(8). Problem reported by Kurt Jaeger <pi at FreeBSD>.
2015-06-27Ignore blank characters at the beginning of a conditional block,Ingo Schwarze
that is, after "\{". Issue found by Markus <Waldeck at gmx dot de> in bash(1).
2015-05-31Implement the roff(7) `r' (register exists) conditional.Ingo Schwarze
Missing feature found by Markus <Waldeck at gmx dot de> in Debian's bash(1) manual page.
2015-05-01Setting the "last" member of struct roff_node was done at an extremelyIngo Schwarze
weird place. Move it to the obviously correct place. Surprisingly, this didn't cause any misformatting in the test suite or in any base system manuals, but i cannot believe the code was really correct for all conceivable input, and it would be very hard to verify. At the very least, it cannot have worked for man(7).
2015-04-23Unify mdoc_deroff() and man_deroff() into a common function deroff().Ingo Schwarze
No functional change except that for mdoc(7), it now skips leading escape sequences just like it already did for man(7). Escape sequences rarely occur in mdoc(7) code and if they do, skipping them is an improvement in this context. Minus 30 lines of code.
2015-04-19Unify trickier node handling functions.Ingo Schwarze
* man_elem_alloc() -> roff_elem_alloc() * man_block_alloc() -> roff_block_alloc() The functions mdoc_elem_alloc() and mdoc_block_alloc() remain for now because they need to do mdoc(7)-specific argument processing.
2015-04-19Unify some node handling functions that use TOKEN_NONE.Ingo Schwarze
* mdoc_word_alloc(), man_word_alloc() -> roff_word_alloc() * mdoc_word_append(), man_word_append() -> roff_word_append() * mdoc_addspan(), man_addspan() -> roff_addtbl() * mdoc_addeqn(), man_addeqn() -> roff_addeqn() Minus 50 lines of code, no functional change.
2015-04-19Unify node handling functions:Ingo Schwarze
* node_alloc() for mdoc and man_node_alloc() -> roff_node_alloc() * node_append() for mdoc and man_node_append() -> roff_node_append() * mdoc_head_alloc() and man_head_alloc() -> roff_head_alloc() * mdoc_body_alloc() and man_body_alloc() -> roff_body_alloc() * mdoc_node_unlink() and man_node_unlink() -> roff_node_unlink() * mdoc_node_free() and man_node_free() -> roff_node_free() * mdoc_node_delete() and man_node_delete() -> roff_node_delete() Minus 130 lines of code, no functional change.
2015-04-18Unify {mdoc,man}_{alloc,reset,free}() into roff_man_{alloc,reset,free}().Ingo Schwarze
Minus 80 lines of code, no functional change. Written on the train from Koeln to Wolfsburg returning from p2k15.
2015-04-04Don't allow breaking the output line after hyphens following escapeIngo Schwarze
sequences. Improves tic(1), sxpm(1), and a few Perl manuals. Quirk found by naddy@ in milter-greylist(8).
2015-02-21Escape quotes when expanding macro arguments.Ingo Schwarze
This fixes a bug naddy@ found in plan9/rc(1).
2015-02-17Cope with another one of the many kinds of DocBook stupidity:Ingo Schwarze
Instead of just using .br, DocBook sometimes fiddles with the utterly unportable internal register \n[an-break-flag] that is only available in the GNU implementation of man(7) and then arms an input line trap to call the equally unportable internal macro .an-trap that, in the GNU implementation, inspects that variable; all the world is GNU, isn't it? Since naddy@ reports that quite a few ports manuals suffer from this insanity, let's just translate it to the intended .br. Et ceterum censeo DocBookem esse delendam.
2015-02-17Let .it accept numerical expressions, not just numerical constants.Ingo Schwarze
For .it, ignore scaling units in roff_getnum(). Inside parentheses, skip whitespace after a sign in roff_getnum(). Parse and ignore unary plus in roff_getnum(). As a bonus, get rid of the only call to mandoc_strntoi() in roff.c.
2015-02-06replace the last legacy generic message type, "argument count wrong",Ingo Schwarze
by more specific messages, improving diagnostics for .cc .tr .Bl -column
2015-01-30correctly handle table layout lines starting with a dotIngo Schwarze
2015-01-28* Polish tbl(7) error reporting.Ingo Schwarze
* Do not print out macro names in tbl(7) data blocks. * Like with GNU tbl, let empty tables cause a blank line. * Avoid producing empty tables in -Tman.
2015-01-28For now, it can't be helped that mandoc tbl(7) ignores high-level macros,Ingo Schwarze
but stop throwing away their arguments. This fixes information loss in a handful of Xenocara manuals, at the price of a small amount of formatting noise creeping through.
2015-01-24Strangely, ignoring the roff(7) .na request was implemented in the man(7)Ingo Schwarze
parser. Simplify the code by moving it into the roff(7) parser, also making it work for mdoc(7).
2015-01-23While ignoring the .ta (set tab stops) and .ti (temp indent) requestsIngo Schwarze
is sometimes harmless, it often causes seriously ugly output, so flag these requests as unsupported rather than ignoring them. Discussed with naddy@.
2015-01-23Wonders of roff(7): Integer numbers in numerical expressions can carryIngo Schwarze
scaling units, and some manuals (e.g. in devel/grcs) actually use that, so let's support it. Missing feature reported by naddy@.
2015-01-22Slightly improve \w width measurements:Ingo Schwarze
Count special characters with the same width as ASCII characters and treat all other escape sequences as if they had a width of 0. Certainly not perfect, but a bit better. For example, GNU RCS ci(1) needs this; reported by naddy@.
2015-01-21pass empty request lines through to tbl(7); sometimes, they end a layoutIngo Schwarze
2015-01-20Split the -Werror message level into -Werror (broken manual, probablyIngo Schwarze
using mandoc is better than using groff) and -Wunsupp (manual using unsupported low-level roff(7) feature, probably using groff is better than using mandoc). Once this feature is complete, it is intended to help porting, making the decision whether to USE_GROFF easier. As a first step, distinguish four classes of roff(7) requests: 1. Supported (currently 24 requests) 2. Currently ignored because unimportant (120) -> no message 3. Ignored for good because insecure (14) -> -Werror 4. Currently unsupported (68) -> these trigger the new -Wunsupp messages
2015-01-16Parse and ignore .IX (generate index entry) macros because pod2man(1)Ingo Schwarze
emits them, by default without defining them, relying on the roff(7) quirk that undefined macros have no effect. This cures 1996 mandoc ERRORs in src/gnu.
2015-01-14downgrade ".so with absolute path" from FATAL to ERROR;Ingo Schwarze
allows to get rid of ROFF_ERR
2015-01-07Bugfix: When the invocation of a user-defined macro follows a roffIngo Schwarze
conditional request on the same input line, don't skip the first few bytes of its content.
2015-01-01Fix a buffer overrun triggered by a trailing backslash at EOF inIngo Schwarze
an unclosed conditional body. If the memory contained the byte sequence "\}" after the end of the buffer before the next NUL, this could even write beyond the end of the buffer, specifically '&' to the location of the '}'. Found by jsg@ with afl.
2014-12-28improve previous: do the size check up front to avoid leaking memoryIngo Schwarze
2014-12-25Reduce memory and time consumption on certain malformed input filesIngo Schwarze
by limiting the length of expanded input lines during the (usually recursive) expansion of user defined strings. Resource hogging found by jsg@ with afl.
2014-12-18Don't let the modulo operator divide by zero.Ingo Schwarze
Found by jsg@ with afl.
2014-12-16Ignore mdoc(7) and man(7) macros inside tbl(7) code because theyIngo Schwarze
would abort the table in an unclean way, causing assertion failures found by jsg@.
2014-12-16When a string comparison condition contains no mismatching characterIngo Schwarze
but ends without the final delimiter, the parse point was advanced one character too far and the invalid pointer returned to the caller of roff_parseln(). Later use could potentially advance the pointer even further and maybe even write to it. Fixing a buffer overrun found by jsg@ with afl (the most severe so far).
2014-12-16When a numerical condition errors out after consuming at least oneIngo Schwarze
character of input, treat it as false, do not retry it as a string comparison condition. This also fixes a read buffer overrun that happened when the numerical condition advanced to the end of the input line before erroring out, found by jsg@ with afl.
2014-12-15Empty conditions count as false.Ingo Schwarze
When negated, they still count as false. Found when investigating crashes jsg@ found with afl. Not completely fixing the crashes yet.
2014-11-19Support the ".if v" conditional operator (vroff mode, always false)Ingo Schwarze
for groff compatibility because pod2man(1) uses it that way. Weirdly, groff documents it as "for compatibility with other troff versions" but neither Heirloom nor Plan 9 have it. Issue reported by giovanni@ via sthen@.
2014-11-01Use struct buf in libroff, it is very natural thereIngo Schwarze
and reduces the number of arguments of many functions. While here, sprinkle some KNF. No functional change.
2014-10-28Make the character table available to libroff so it can check theIngo Schwarze
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.
2014-10-25With the current architecture, we can't support inline equationsIngo Schwarze
inside tables, sorry. So don't even try to parse tbl(7) blocks for eqn(7) delimiters. Broken table layout found in glPixelMap(3) while investigating a bug report by Theo Buehler <theo at math dot ethz dot ch>.
2014-10-25Report arguments to .EQ as an error, and simplify the code:Ingo Schwarze
* drop trivial wrapper function roff_openeqn() * drop unused first arg of function eqn_alloc() * drop usused member "name" of struct eqn_node