summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/mdoc_validate.c
AgeCommit message (Collapse)Author
2017-02-06The .Nm macro does not only use the default name when it has noIngo Schwarze
argument, but also when the first argument is a child macro. Arcane issue found in the FreeBSD cxgbetool(8) manual that Baptiste Daroussin <bapt at FreeBSD> sent me long ago for a different reason. While solving this, switch to the new technique of doing text production in the validator, reducing code duplication in the formatters, which also makes -Ttree output clearer.
2017-01-11Do text production for .Bt, .Ex, .Rv, .Ud at the validation stageIngo Schwarze
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@.
2017-01-10Use new NODE_NOSRC and NODE_NOPRT flags for .Bx and .At.Ingo Schwarze
More rigorous AST and 40 lines less code.
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-10unify names of AST node flags; no change of cpp outputIngo Schwarze
2017-01-10Introduce flags NODE_NOSRC and NODE_NOPRT for AST nodes.Ingo Schwarze
Use them to mark generated nodes and nodes that shall not produce output. Let -Ttree output mode display these new flags. Use NODE_NOSRC for .Ar, .Mt, and .Pa default arguments. Use NODE_NOPRT for .Dd, .Dt, and .Os. These will help to make handling of text production macros more rigorous.
2017-01-08Tolerate bare tabs in SYNOPSIS .Cd for now.Ingo Schwarze
It's used in half a dozen pages. Even though i have been thinking about it for years, i still can't suggest anything better. The false positives are annoying.
2017-01-08Stricter validation of the NAME section, in particular:Ingo Schwarze
- require a comma between names - reject all other text nodes - reject all empty Nm below NAME, not only in the leading position - reject Nm after Nd
2016-12-28Make the second, section number argument of .Xr mandatory.Ingo Schwarze
In fact, we have been requiring it for many years. The only reason to not warn when it was missing was excessive traditionalism - it was optional in 4.4BSD.
2016-10-09Delete complicated code dealing with .Bl -tag without -width,Ingo Schwarze
and just let it default to -width 6n, which agrees with the traditional -width Ds that is still in widespread use. I just pushed a patch upstream to GNU roff that does the same for groff_mdoc(7). Before, groff contained code that was even more complicated than mandoc, but both resulted in quite different user-visible output. Now, both agree, and output is nicer for both. Useless complication noticed by Carsten Kunze (Heirloom roff).
2016-08-20If a column list starts with implicit rows (that is, rows without .It)Ingo Schwarze
and roff-level nodes (e.g. tbl or eqn) follow, don't run into an assertion. Instead, wrap the roff-level nodes in their own row. Issue found by tb@ with afl(1).
2016-08-11oops, fix stupid typo in previousIngo Schwarze
2016-08-11If a .Bd display is on the one hand doomed to be deleted becauseIngo Schwarze
it has no type, but is on the other hand breaking another block, delete its end marker as well, or the end marker may remain behind as an orphan, triggering an assertion in the terminal formatter. Problem found by tb@ with afl(1).
2016-08-10Don't deref NULL if the only child of the first .Sh is an emptyIngo Schwarze
in-line macro, and don't printf("%s", NULL) if the first child of the first .Sh is a macro; again found by tb@ with afl(1). (No, you should never use macros in any .Sh at all, please.)
2016-08-10Don't printf("%s", NULL) if .It has a macro as an argumentIngo Schwarze
in a list of a type where items don't takes arguments. Issue found by tb@ with afl(1).
2016-08-10When validating a .Bl list that defaults to -item for want of a type,Ingo Schwarze
don't let a subsequent -width access mdoc_argnames[] out of bounds. Found by tb@ with afl(1).
2016-08-09fix printf("%s", NULL);Ingo Schwarze
found while investigating an unrelated bug report from jsg@
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-30If a .Bd block has no arguments at all, drop the block and only keepIngo Schwarze
its contents. Removing a gratuitious difference to groff output found after a related bug report from krw@.
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-19style cleanup, no functional changeIngo Schwarze
2015-10-12Delete an assignment that is unconditionally overwritten two lines later;Ingo Schwarze
found by Svyatoslav Mishyn <juef at openmailbox dot org> with the clang static analyzer.
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-09-14Remove the warning about children of .Vt blocks because actually,Ingo Schwarze
.Vt type global_variable No = Dv defined_constant ; is the best way to specify in the SYNOPSIS how a global variable is initialized in the rare case where that matters. Issue noticed by jmc@.
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-20Avoid out-of-bounds read access before the beginning of theIngo Schwarze
mdoc_macros[] array. This sometimes prevented proper warnings about text nodes preceding the first section header.
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-19Decouple the token code for "no request or macro" from the individualIngo Schwarze
high-level parsers to allow further unification of functions that only need to recognize this code, but that don't care about different high-level macrosets beyond that.
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-18Replace the structs mdoc and man by a unified struct roff_man.Ingo Schwarze
Almost completely mechanical, no functional change. Written on the train from Exeter to London returning from p2k15.
2015-04-02Second step towards parser unification:Ingo Schwarze
Replace struct mdoc_node and struct man_node by a unified struct roff_node. To be able to use the tok member for both mdoc(7) and man(7) without defining all the macros in roff.h, sacrifice a tiny bit of type safety and make tok an int rather than an enum. Almost mechanical, no functional change. Written on the Eurostar from Bruxelles to London on the way to p2k15.
2015-04-02First step towards parser unification:Ingo Schwarze
Replace enum mdoc_type and enum man_type by a unified enum roff_type. Almost mechanical, no functional change. Written on the ICE train from Frankfurt to Bruxelles on the way to p2k15.
2015-02-23oops, in NAME, don't nag about the comma after .NmIngo Schwarze
2015-02-23improve NAME section diagnostics;Ingo Schwarze
confusing messages reported by Jan Stary <hans at stare dot cz>
2015-02-17Render \(lq and \(rq as '"' in -Tascii mode but leave the renderingIngo Schwarze
of .Do/.Dc, .Dq, .Lb, and .St untouched. Reduces groff-mandoc differences in base by about 7%. Reminded of the issue by naddy@.
2015-02-16clean up post_dt() validation function;Ingo Schwarze
improved diagnostics, minus six lines of code
2015-02-14shut up about tabs in SYNOPSIS .Fd lines, there is no good way to avoid themIngo Schwarze
2015-02-12Delete the mdoc_node.pending pointer and the function calculatingIngo Schwarze
it, make_pending(), which was the most difficult function of the whole mdoc(7) parser. After almost five years of maintaining this hellhole, i just noticed the pointer isn't needed after all. Blocks are always rewound in the reverse order they were opened; that even holds for broken blocks. Consequently, it is sufficient to just mark broken blogs with the flag MDOC_BROKEN and breaking blocks with the flag MDOC_ENDED. When rewinding, instead of iterating the pending pointers, just iterate from each broken block to its parents, rewinding all that are MDOC_ENDED and stopping after processing the first ancestor that it not MDOC_BROKEN. For ENDBODY markers, use the mdoc_node.body pointer in place of the former mdoc_node.pending. This also fixes an assertion failure found by jsg@ with afl, test case #467 (Bo Bl It Bd Bc It), where (surprise surprise) the pending pointer got corrupted. Improved functionality, minus one function, minus one struct field, minus 50 lines of code.
2015-02-10trim trailing white space, no code change;Ingo Schwarze
from Svyatoslav Mishyn <juef at openmailboxd dot org>, Crux Linux
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-02-06Delete the legacy generic warning type MANDOCERR_ARGCWARN,Ingo Schwarze
replacing the last instances by more specific warnings. Improved functionality, minus 50 lines of code.
2015-02-06better handle .Fo and .Fd without argumentIngo Schwarze
better handle .Fo with more than one argument
2015-02-06better handle empty .Bd .Bl .D1 .Dl blocksIngo Schwarze
2015-02-06better handle .In .Sh .Ss .St .Xr without argumentsIngo Schwarze
2015-02-05fix handling of empty .An macrosIngo Schwarze
2015-02-04Discard excess head arguments for .Bd .Bl .Bk and delete hwarn_eq0().Ingo Schwarze
Discard empty .Bk blocks. Improve related diagnostics.
2015-02-04improve diagnostics regarding arguments of .An .Pp .Lp .br .spIngo Schwarze
in particular, get rid of check_count(..., CHECK_EQ, 0)