=================================================================== RCS file: /cvs/mandoc/mdoc_macro.c,v retrieving revision 1.70 retrieving revision 1.74 diff -u -p -r1.70 -r1.74 --- mandoc/mdoc_macro.c 2010/05/29 18:47:54 1.70 +++ mandoc/mdoc_macro.c 2010/05/30 22:56:02 1.74 @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.70 2010/05/29 18:47:54 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.74 2010/05/30 22:56:02 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -937,6 +937,7 @@ blk_full(MACRO_PROT_ARGS) #ifdef UGLY struct mdoc_node *n; #endif + enum mdoc_type mtt; enum mdoct ntok; enum margserr ac, lac; enum margverr av; @@ -1005,7 +1006,8 @@ blk_full(MACRO_PROT_ARGS) for ( ; ; ) { la = *pos; - lac = ac; + /* Initialise last-phrase-type with ARGS_PHRASE. */ + lac = ARGS_ERROR == ac ? ARGS_PHRASE : ac; ac = mdoc_args(m, line, pos, buf, tok, &p); if (ARGS_ERROR == ac) @@ -1013,16 +1015,13 @@ blk_full(MACRO_PROT_ARGS) if (ARGS_EOLN == ac) break; - if (ARGS_PEND == ac) { - if (ARGS_PPHRASE == lac) - ac = ARGS_PPHRASE; - else - ac = ARGS_PHRASE; - } + /* + * Emit leading punctuation (i.e., punctuation before + * the MDOC_HEAD) for non-phrase types. + */ - /* Don't emit leading punct. for phrases. */ - if (NULL == head && + ARGS_PEND != ac && ARGS_PHRASE != ac && ARGS_PPHRASE != ac && ARGS_QWORD != ac && @@ -1032,24 +1031,50 @@ blk_full(MACRO_PROT_ARGS) continue; } - /* Always re-open head for phrases. */ + /* Open a head if one hasn't been opened. */ - if (NULL == head || - ARGS_PHRASE == ac || - ARGS_PPHRASE == ac) { + if (NULL == head) { if ( ! mdoc_head_alloc(m, line, ppos, tok)) return(0); head = m->last; } - if (ARGS_PHRASE == ac || ARGS_PPHRASE == ac) { + if (ARGS_PHRASE == ac || + ARGS_PEND == ac || + ARGS_PPHRASE == ac) { + /* + * If we haven't opened a body yet, rewind the + * head; if we have, rewind that instead. + */ + + mtt = body ? MDOC_BODY : MDOC_HEAD; + if ( ! rew_sub(mtt, m, tok, line, ppos)) + return(0); + + /* Then allocate our body context. */ + + if ( ! mdoc_body_alloc(m, line, ppos, tok)) + return(0); + body = m->last; + + /* + * Process phrases: set whether we're in a + * partial-phrase (this effects line handling) + * then call down into the phrase parser. + */ + if (ARGS_PPHRASE == ac) m->flags |= MDOC_PPHRASE; - if ( ! phrase(m, line, la, buf, ac)) + if (ARGS_PEND == ac && ARGS_PPHRASE == lac) + m->flags |= MDOC_PPHRASE; + + if (ARGS_PEND == ac) { + if ( ! phrase(m, line, la, buf, lac)) + return(0); + } else if ( ! phrase(m, line, la, buf, ac)) return(0); + m->flags &= ~MDOC_PPHRASE; - if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) - return(0); continue; }