aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_macro.c
Commit message (Collapse)AuthorAgeFilesLines
* mdoc_valid_post() may indirectly call roff_node_unlink() which mayIngo Schwarze2015-05-011-2/+2
| | | | | | | | | | | set ROFF_NEXT_CHILD, which is desirable for the final call to mdoc_valid_post() - in case the target itself gets deleted, the parse point may need this adjustment - but not for the intermediate calls - if intermediate nodes get deleted, that mustn't clobber the parse point. So move setting ROFF_NEXT_SIBLING to the proper place in rew_last(). This fixes the assertion failure in jsg@'s afl test case 108/Apr27.
* Setting the "last" member of struct roff_node was done at an extremelyIngo Schwarze2015-05-011-4/+2
| | | | | | | | 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).
* Minor bug fix: When .Pp rewinds .Nm, rewind the whole block,Ingo Schwarze2015-05-011-2/+2
| | | | | not just the body. In some unusual edge cases, this caused the .Pp to become a sibling of the .Nm body inside the .Nm block.
* If a block body gets broken, that's no good reason to extend theIngo Schwarze2015-04-291-2/+4
| | | | | | | scope of the end macro. Instead, only keep the tail scope open if the end macro macro calls an explicit macro and actually breaks that. This corrects syntax tree structure and fixes an assertion found by jsg@ with afl (test case 098/Apr27).
* Do not mark a block with the MDOC_BROKEN flag if it merely containsIngo Schwarze2015-04-291-1/+3
| | | | | | a mismatching explicit end macro without actually being broken. Avoids a subsequent upward search for the non-existent breaker ending up in a NULL pointer access; afl test case 005/Apr27 from jsg@.
* Get rid of two empty wrapper functions. No functional change.Ingo Schwarze2015-04-231-2/+2
|
* Avoid a use after free when the target node is deleted during validation.Ingo Schwarze2015-04-211-13/+16
| | | | Bug reported by jsg@.
* Unify trickier node handling functions.Ingo Schwarze2015-04-191-4/+4
| | | | | | | * 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.
* Unify some node handling functions that use TOKEN_NONE.Ingo Schwarze2015-04-191-3/+3
| | | | | | | | * 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.
* Decouple the token code for "no request or macro" from the individualIngo Schwarze2015-04-191-18/+19
| | | | | | 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.
* Unify node handling functions:Ingo Schwarze2015-04-191-17/+18
| | | | | | | | | | | * 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.
* Replace the structs mdoc and man by a unified struct roff_man.Ingo Schwarze2015-04-181-21/+22
| | | | | Almost completely mechanical, no functional change. Written on the train from Exeter to London returning from p2k15.
* If a partial explicit block extending to the next input line followsIngo Schwarze2015-04-051-4/+16
| | | | | the end macro of a broken block, put all of it into the breaking block. Needed for example by mutella(1).
* Reduce code duplication, no functional change:Ingo Schwarze2015-04-051-51/+45
| | | | | Both partial and full implicit blocks can break explicit blocks. Put the code to handle both cases into a common function.
* Arguments to end macros of broken partial explicit blocksIngo Schwarze2015-04-051-10/+8
| | | | | | | | must go inside the breaking block. For example, in .It Ic cmd Oo .Ar optional_arg Oc Ar mandatory_arg the mandatory_arg is still inside the .It block. Used for example by mutella(1).
* Second step towards parser unification:Ingo Schwarze2015-04-021-40/+38
| | | | | | | | | 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.
* First step towards parser unification:Ingo Schwarze2015-04-021-20/+21
| | | | | | 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.
* Delete the mdoc_node.pending pointer and the function calculatingIngo Schwarze2015-02-121-110/+78
| | | | | | | | | | | | | | | | | | | | | | | 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.
* explicit blocks close out .Nd; fixing data structure corruptionIngo Schwarze2015-02-111-1/+8
| | | | | eventually leading to NULL pointer access; found by jsg@ with afl, text case #455.
* Be more careful to not generate empty .In, .St, and .Xr nodes.Ingo Schwarze2015-02-101-34/+44
| | | | | | | | That could happen when their first argument was another called macro, causing a NULL pointer access in .St validation found by jsg@ with afl. Make in_line_argn() easier to understand by using one state variable rather than two.
* Closing a block validates it, which may end up deleting it,Ingo Schwarze2015-02-071-1/+2
| | | | | so if we are in a loop over blocks, cleanly restart the loop rather than risking use after free; found by jsg@ with afl.
* Delete the legacy generic warning type MANDOCERR_ARGCWARN,Ingo Schwarze2015-02-061-3/+4
| | | | | replacing the last instances by more specific warnings. Improved functionality, minus 50 lines of code.
* better handle .Fo and .Fd without argumentIngo Schwarze2015-02-061-1/+7
| | | | better handle .Fo with more than one argument
* better handle .In .Sh .Ss .St .Xr without argumentsIngo Schwarze2015-02-061-1/+12
|
* fix handling of empty .An macrosIngo Schwarze2015-02-051-2/+2
|
* Simplify by deleting the "lastline" member of struct mdoc_node.Ingo Schwarze2015-02-051-8/+2
| | | | Minus one struct member, minus 17 lines of code, no functional change.
* Discard excess head arguments for .Bd .Bl .Bk and delete hwarn_eq0().Ingo Schwarze2015-02-041-2/+8
| | | | | Discard empty .Bk blocks. Improve related diagnostics.
* discard .Rs head arguments and improve .Rs diagnosticsIngo Schwarze2015-02-041-4/+9
|
* Avoid closing out an explicit block twice when broken by .ItIngo Schwarze2015-02-031-1/+2
| | | | (assertion failure); regression found in jsg@'s afl test case 847.
* Finally delete the kitchensink functions rew_sub() and rew_dohalt().Ingo Schwarze2015-02-031-160/+75
| | | | | | | They were a maintenance and auditing nightmare because if you changed one bit in there, stuff tended to break at seemingly unrelated places. No functional change except getting rid of one bogus error message, but minus 80 lines of code.
* Bring .Pp/.Lp handling inside .Nm blocks closer to groff;Ingo Schwarze2015-02-031-4/+11
| | | | as a bonus, get rid of another call to rew_sub().
* Simplify and reindent make_pending(). No functional changeIngo Schwarze2015-02-021-57/+50
| | | | | | except that some error messages become less confusing. Now the function is almost readable (but still requires nineteen lines of comments for fourteen lines of code).
* Simplify: Do not call rew_dohalt() from make_pending(),Ingo Schwarze2015-02-021-31/+21
| | | | | the calling macro handler already found the breaking block. No functional change except tiny variations in error messages.
* Get rid of all remaining calls to rew_sub() where the target blockIngo Schwarze2015-02-021-66/+37
| | | | | is known. This only leaves three that do actual searching. No functional change, minus 30 lines of code.
* Get rid of all calls to rew_sub() in blk_exp_close(); only ten callsIngo Schwarze2015-02-021-65/+67
| | | | | | remain in other functions. As a bonus, this fixes an assertion failure jsg@ found some time ago with afl (test case 982) and improves minor details in error reporting.
* When a full block macro gets closed out by a mismatchingIngo Schwarze2015-02-021-4/+7
| | | | | | | | | block closure macro it calls, do not attempt to open its body. This can for example happen for (nonsensical) constructions like .Fo .Nm Fc in the SYNOPSIS. Fixing an assertion failure jsg@ found with afl some time ago (test case number 731).
* get rid of rew_sub() in blk_part_imp(); no functional changeIngo Schwarze2015-02-011-3/+14
|
* Simplify blk_part_exp(), no functional change.Ingo Schwarze2015-02-011-24/+8
| | | | | | * Replace calls to rew_sub() with rew_last() - two less out of 18. * No need to keep track of the body, it's always opened right after the head and never used for anything in this function.
* The function rew_sub() tries to rewind any all all kinds of blocksIngo Schwarze2015-02-011-5/+4
| | | | | | | | | | and elements under any and all circumstances, even handling some bad block nesting now and then. Little surprisingly, this ends up in excessive complexity and has caused many bugs in the past. Start to slowly disentangle this mess by replacing calls to rew_sub() immediately following mdoc_head_alloc() by the much simpler rew_last(). Gets rid of the first two rew_sub() calls out of twenty. No functional change.
* The code already pays attention not to close the same block twice.Ingo Schwarze2014-12-221-3/+3
| | | | | | | Similarly, avoid having the same block break two other blocks. In some situations, this could lead to an endless loop in rew_sub() found by jsg@ with afl. Minimal example: .Po Ao Pc Bo Pc Ac Bc
* Fix two issues causing a class of assertion failures found by jsg@ with afl.Ingo Schwarze2014-12-201-9/+20
| | | | | | | | 1) rew_sub(): Make sure REWIND_MORE is acted upon even when followed by REWIND_NONE. This prevents .It from ending up inside other children of .Bl. 2) blk_exp_close(): Only allow extension of .Bl when it has at least one .It. Otherwise, a broken child block could be moved in front of the .Bl, effectively resulting in a .Bl that ended before it began.
* Don't let .Ta creep into an already-closed list; same as for .It.Ingo Schwarze2014-12-181-2/+3
| | | | Fixes an assertion found by jsg@ with afl.
* The code is already careful to not add items to lists that wereIngo Schwarze2014-12-181-21/+32
| | | | | | | already closed. In this respect, also consider lists closed that have broken another block, their closure pending until the end of the broken block. This avoids syntax tree corruption leading to a NULL pointer access found by jsg@ with afl.
* Fix a regression found by Carsten dot Kunze at arcor dot de:Ingo Schwarze2014-12-131-5/+3
| | | | Do not show bogus quotes when .Bl -column phrases are quoted.
* Multiple fixes with respect to .Pf:Ingo Schwarze2014-11-301-7/+17
| | | | | | | * The first argument of .Pf is not parsed. * Normal delimiter handling does not apply to the first argument of .Pf. * Warn if nothing follows a prefix (inspired by groff_mdoc(7)). * In that case, do not suppress spacing.
* warn about attempts to call non-callable macros;Ingo Schwarze2014-11-301-9/+17
| | | | inspired by a similar warning in the groff_mdoc(7) macros
* Reduce code duplication by reusing the same argument parserIngo Schwarze2014-11-291-19/+21
| | | | | for in_line_eoln() macros and .Bl -column phrases. No functional change.
* Provide a helper function macro_or_word() and use it to prune theIngo Schwarze2014-11-291-116/+63
| | | | | | | | | | same chunk of argument parsing code out of five of the eight callback functions. The other three have too much special handling to participate. As a bonus, let lookup() and mdoc_args() deal with line macros and retire the lookup_raw() helper and the mdoc_zargs() internal interface function. No functional change, minus 40 lines of code.
* Fold the loop around mdoc_argv() into the function itself,Ingo Schwarze2014-11-281-47/+5
| | | | | | it was the same in all four cases. As a bonus, get rid of one enum type that was used for internal communication. No functional change, minus 40 lines of code.
* Simplify by making the mdoc parser callbacks void, and some cleanup;Ingo Schwarze2014-11-281-199/+117
| | | | no functional change, minus 50 lines of code.