=================================================================== RCS file: /cvs/mandoc/mdoc_macro.c,v retrieving revision 1.150 retrieving revision 1.157 diff -u -p -r1.150 -r1.157 --- mandoc/mdoc_macro.c 2014/11/28 03:14:18 1.150 +++ mandoc/mdoc_macro.c 2014/12/13 13:14:39 1.157 @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.150 2014/11/28 03:14:18 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.157 2014/12/13 13:14:39 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze @@ -40,24 +40,26 @@ enum rew { /* see rew_dohalt() */ REWIND_ERROR }; -static int blk_full(MACRO_PROT_ARGS); -static int blk_exp_close(MACRO_PROT_ARGS); -static int blk_part_exp(MACRO_PROT_ARGS); -static int blk_part_imp(MACRO_PROT_ARGS); -static int ctx_synopsis(MACRO_PROT_ARGS); -static int in_line_eoln(MACRO_PROT_ARGS); -static int in_line_argn(MACRO_PROT_ARGS); -static int in_line(MACRO_PROT_ARGS); -static int phrase_ta(MACRO_PROT_ARGS); +static void blk_full(MACRO_PROT_ARGS); +static void blk_exp_close(MACRO_PROT_ARGS); +static void blk_part_exp(MACRO_PROT_ARGS); +static void blk_part_imp(MACRO_PROT_ARGS); +static void ctx_synopsis(MACRO_PROT_ARGS); +static void in_line_eoln(MACRO_PROT_ARGS); +static void in_line_argn(MACRO_PROT_ARGS); +static void in_line(MACRO_PROT_ARGS); +static void phrase_ta(MACRO_PROT_ARGS); static void dword(struct mdoc *, int, int, const char *, enum mdelim, int); static void append_delims(struct mdoc *, int, int *, char *); -static enum mdoct lookup(enum mdoct, const char *); -static enum mdoct lookup_raw(const char *); +static enum mdoct lookup(struct mdoc *, enum mdoct, + int, int, const char *); +static int macro_or_word(MACRO_PROT_ARGS, int); static int make_pending(struct mdoc_node *, enum mdoct, struct mdoc *, int, int); -static int phrase(struct mdoc *, int, int, char *); +static int parse_rest(struct mdoc *, enum mdoct, + int, int *, char *); static enum mdoct rew_alt(enum mdoct); static enum rew rew_dohalt(enum mdoct, enum mdoc_type, const struct mdoc_node *); @@ -218,52 +220,46 @@ const struct mdoc_macro * const mdoc_macros = __mdoc_m * closing out open [implicit] scopes. Obviously, open explicit scopes * are errors. */ -int +void mdoc_macroend(struct mdoc *mdoc) { struct mdoc_node *n; /* Scan for open explicit scopes. */ - n = MDOC_VALID & mdoc->last->flags ? + n = mdoc->last->flags & MDOC_VALID ? mdoc->last->parent : mdoc->last; for ( ; n; n = n->parent) - if (MDOC_BLOCK == n->type && - MDOC_EXPLICIT & mdoc_macros[n->tok].flags) + if (n->type == MDOC_BLOCK && + mdoc_macros[n->tok].flags & MDOC_EXPLICIT) mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse, n->line, n->pos, mdoc_macronames[n->tok]); /* Rewind to the first. */ rew_last(mdoc, mdoc->first); - return(1); } /* - * Look up a macro from within a subsequent context. + * Look up the macro at *p called by "from", + * or as a line macro if from == MDOC_MAX. */ static enum mdoct -lookup(enum mdoct from, const char *p) +lookup(struct mdoc *mdoc, enum mdoct from, int line, int ppos, const char *p) { - - if ( ! (MDOC_PARSED & mdoc_macros[from].flags)) - return(MDOC_MAX); - return(lookup_raw(p)); -} - -/* - * Lookup a macro following the initial line macro. - */ -static enum mdoct -lookup_raw(const char *p) -{ enum mdoct res; - if (MDOC_MAX == (res = mdoc_hash_find(p))) - return(MDOC_MAX); - if (MDOC_CALLABLE & mdoc_macros[res].flags) - return(res); + if (from == MDOC_MAX || mdoc_macros[from].flags & MDOC_PARSED) { + res = mdoc_hash_find(p); + if (res != MDOC_MAX) { + if (mdoc_macros[res].flags & MDOC_CALLABLE) + return(res); + if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll) + mandoc_msg(MANDOCERR_MACRO_CALL, + mdoc->parse, line, ppos, p); + } + } return(MDOC_MAX); } @@ -634,17 +630,15 @@ dword(struct mdoc *mdoc, int line, int col, const char static void append_delims(struct mdoc *mdoc, int line, int *pos, char *buf) { - int la; - enum margserr ac; char *p; + int la; if (buf[*pos] == '\0') return; for (;;) { la = *pos; - ac = mdoc_zargs(mdoc, line, pos, buf, &p); - if (ac == ARGS_EOLN) + if (mdoc_args(mdoc, line, pos, buf, MDOC_MAX, &p) == ARGS_EOLN) break; dword(mdoc, line, la, p, DELIM_MAX, 1); @@ -666,9 +660,41 @@ append_delims(struct mdoc *mdoc, int line, int *pos, c } /* - * Close out block partial/full explicit. + * Parse one word. + * If it is a macro, call it and return 1. + * Otherwise, allocate it and return 0. */ static int +macro_or_word(MACRO_PROT_ARGS, int parsed) +{ + char *p; + enum mdoct ntok; + + p = buf + ppos; + ntok = MDOC_MAX; + if (*p == '"') + p++; + else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT)) + ntok = lookup(mdoc, tok, line, ppos, p); + + if (ntok == MDOC_MAX) { + dword(mdoc, line, ppos, p, DELIM_MAX, tok == MDOC_MAX || + mdoc_macros[tok].flags & MDOC_JOIN); + return(0); + } else { + if (mdoc_macros[tok].fp == in_line_eoln) + rew_elem(mdoc, tok); + mdoc_macro(mdoc, ntok, line, ppos, pos, buf); + if (tok == MDOC_MAX) + append_delims(mdoc, line, pos, buf); + return(1); + } +} + +/* + * Close out block partial/full explicit. + */ +static void blk_exp_close(MACRO_PROT_ARGS) { struct mdoc_node *body; /* Our own body. */ @@ -689,6 +715,7 @@ blk_exp_close(MACRO_PROT_ARGS) break; case MDOC_Ek: mdoc->flags &= ~MDOC_KEEP; + /* FALLTHROUGH */ default: maxargs = 0; break; @@ -698,6 +725,7 @@ blk_exp_close(MACRO_PROT_ARGS) * Search backwards for beginnings of blocks, * both of our own and of pending sub-blocks. */ + atok = rew_alt(tok); body = endbody = later = NULL; for (n = mdoc->last; n; n = n->parent) { @@ -705,6 +733,7 @@ blk_exp_close(MACRO_PROT_ARGS) continue; /* Remember the start of our own body. */ + if (n->type == MDOC_BODY && atok == n->tok) { if (n->end == ENDBODY_NOT) body = n; @@ -721,6 +750,7 @@ blk_exp_close(MACRO_PROT_ARGS) * When there is no pending sub block, * just proceed to closing out. */ + if (later == NULL) break; @@ -729,14 +759,24 @@ blk_exp_close(MACRO_PROT_ARGS) * postpone closing out the current block * until the rew_sub() closing out the sub-block. */ + make_pending(later, tok, mdoc, line, ppos); /* * Mark the place where the formatting - but not * the scope - of the current block ends. */ + mdoc_endbody_alloc(mdoc, line, ppos, atok, body, ENDBODY_SPACE); + + /* + * If a block closing macro taking arguments + * breaks another block, put the arguments + * into the end marker and remeber the + * end marker in order to close it out. + */ + if (maxargs) { endbody = mdoc->last; mdoc->next = MDOC_NEXT_CHILD; @@ -749,12 +789,14 @@ blk_exp_close(MACRO_PROT_ARGS) * open explicit block, or, in case there are only * implicit ones, the first open implicit block. */ + if (later && mdoc_macros[later->tok].flags & MDOC_EXPLICIT) continue; if (n->tok != MDOC_It) later = n; } + rew_sub(MDOC_BODY, mdoc, tok, line, ppos); if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) { if (buf[*pos] != '\0') @@ -762,11 +804,9 @@ blk_exp_close(MACRO_PROT_ARGS) mdoc->parse, line, ppos, "%s %s", mdoc_macronames[tok], buf + *pos); - rew_sub(MDOC_BODY, mdoc, tok, line, ppos); rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); - return(1); + return; } - rew_sub(MDOC_BODY, mdoc, tok, line, ppos); if (maxargs && endbody == NULL) { if (n == NULL) { @@ -796,7 +836,8 @@ blk_exp_close(MACRO_PROT_ARGS) if (ac == ARGS_PUNCT || ac == ARGS_EOLN) break; - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); + ntok = ac == ARGS_QWORD ? MDOC_MAX : + lookup(mdoc, tok, line, lastarg, p); if (ntok == MDOC_MAX) { dword(mdoc, line, lastarg, p, DELIM_MAX, @@ -811,11 +852,8 @@ blk_exp_close(MACRO_PROT_ARGS) rew_last(mdoc, endbody); flushed = 1; } - mdoc->flags &= ~MDOC_NEWLINE; - - if ( ! mdoc_macro(mdoc, ntok, line, lastarg, pos, buf)) - return(0); + mdoc_macro(mdoc, ntok, line, lastarg, pos, buf); break; } @@ -827,14 +865,12 @@ blk_exp_close(MACRO_PROT_ARGS) } if (nl) append_delims(mdoc, line, pos, buf); - return(1); } -static int +static void in_line(MACRO_PROT_ARGS) { int la, scope, cnt, firstarg, mayopen, nc, nl; - enum margverr av; enum mdoct ntok; enum margserr ac; enum mdelim d; @@ -867,23 +903,8 @@ in_line(MACRO_PROT_ARGS) break; } - for (arg = NULL;; ) { - la = *pos; - av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); + mdoc_argv(mdoc, line, tok, &arg, pos, buf); - if (ARGV_WORD == av) { - *pos = la; - break; - } - if (ARGV_EOLN == av) - break; - if (ARGV_ARG == av) - continue; - - mdoc_argv_free(arg); - return(0); - } - d = DELIM_NONE; firstarg = 1; mayopen = 1; @@ -917,7 +938,7 @@ in_line(MACRO_PROT_ARGS) } ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ? - MDOC_MAX : lookup(tok, p); + MDOC_MAX : lookup(mdoc, tok, line, la, p); /* * In this case, we've located a submacro and must @@ -938,12 +959,10 @@ in_line(MACRO_PROT_ARGS) mdoc->parse, line, ppos, mdoc_macronames[tok]); } - - if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) - return(0); + mdoc_macro(mdoc, ntok, line, la, pos, buf); if (nl) append_delims(mdoc, line, pos, buf); - return(1); + return; } /* @@ -1029,20 +1048,17 @@ in_line(MACRO_PROT_ARGS) } if (nl) append_delims(mdoc, line, pos, buf); - return(1); } -static int +static void blk_full(MACRO_PROT_ARGS) { - int la, nl, nparsed; + int la, nl, parsed; struct mdoc_arg *arg; struct mdoc_node *head; /* save of head macro */ struct mdoc_node *body; /* save of body macro */ struct mdoc_node *n; - enum mdoct ntok; enum margserr ac, lac; - enum margverr av; char *p; nl = MDOC_NEWLINE & mdoc->flags; @@ -1059,7 +1075,7 @@ blk_full(MACRO_PROT_ARGS) line, ppos, "It %s", buf + *pos); mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL); rew_elem(mdoc, MDOC_br); - return(1); + return; } } @@ -1079,24 +1095,7 @@ blk_full(MACRO_PROT_ARGS) * regular child nodes. */ - for (arg = NULL;; ) { - la = *pos; - av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); - - if (ARGV_WORD == av) { - *pos = la; - break; - } - - if (ARGV_EOLN == av) - break; - if (ARGV_ARG == av) - continue; - - mdoc_argv_free(arg); - return(0); - } - + mdoc_argv(mdoc, line, tok, &arg, pos, buf); mdoc_block_alloc(mdoc, line, ppos, tok, arg); head = body = NULL; @@ -1104,10 +1103,11 @@ blk_full(MACRO_PROT_ARGS) * Exception: Heads of `It' macros in `-diag' lists are not * parsed, even though `It' macros in general are parsed. */ - nparsed = tok == MDOC_It && - mdoc->last->parent->tok == MDOC_Bl && - mdoc->last->parent->norm->Bl.type == LIST_diag; + parsed = tok != MDOC_It || + mdoc->last->parent->tok != MDOC_Bl || + mdoc->last->parent->norm->Bl.type != LIST_diag; + /* * The `Nd' macro has all arguments in its body: it's a hybrid * of block partial-explicit and full-implicit. Stupid. @@ -1167,6 +1167,7 @@ blk_full(MACRO_PROT_ARGS) if (ac == ARGS_PHRASE || ac == ARGS_PEND || ac == ARGS_PPHRASE) { + /* * If we haven't opened a body yet, rewind the * head; if we have, rewind that instead. @@ -1174,9 +1175,6 @@ blk_full(MACRO_PROT_ARGS) rew_sub(body ? MDOC_BODY : MDOC_HEAD, mdoc, tok, line, ppos); - - /* Then allocate our body context. */ - body = mdoc_body_alloc(mdoc, line, ppos, tok); /* @@ -1189,36 +1187,20 @@ blk_full(MACRO_PROT_ARGS) mdoc->flags |= MDOC_PPHRASE; if (ac == ARGS_PEND && lac == ARGS_PPHRASE) mdoc->flags |= MDOC_PPHRASE; - - if ( ! phrase(mdoc, line, la, buf)) - return(0); - + parse_rest(mdoc, MDOC_MAX, line, &la, buf); mdoc->flags &= ~MDOC_PPHRASE; continue; } - ntok = nparsed || ac == ARGS_QWORD ? - MDOC_MAX : lookup(tok, p); - - if (ntok == MDOC_MAX) { - dword(mdoc, line, la, p, DELIM_MAX, - MDOC_JOIN & mdoc_macros[tok].flags); - continue; - } - - if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) - return(0); - break; + if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed)) + break; } if (head == NULL) head = mdoc_head_alloc(mdoc, line, ppos, tok); if (nl) append_delims(mdoc, line, pos, buf); - - /* If we've already opened our body, exit now. */ - - if (NULL != body) + if (body != NULL) goto out; /* @@ -1228,11 +1210,11 @@ blk_full(MACRO_PROT_ARGS) * sub-block. */ for (n = mdoc->last; n && n != head; n = n->parent) { - if (MDOC_BLOCK == n->type && - MDOC_EXPLICIT & mdoc_macros[n->tok].flags && - ! (MDOC_VALID & n->flags)) { + if (n->type == MDOC_BLOCK && + mdoc_macros[n->tok].flags & MDOC_EXPLICIT && + ! (n->flags & MDOC_VALID)) { n->pending = head; - return(1); + return; } } @@ -1240,21 +1222,18 @@ blk_full(MACRO_PROT_ARGS) rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); mdoc_body_alloc(mdoc, line, ppos, tok); - out: if (mdoc->flags & MDOC_FREECOL) { rew_sub(MDOC_BODY, mdoc, tok, line, ppos); rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); mdoc->flags &= ~MDOC_FREECOL; } - return(1); } -static int +static void blk_part_imp(MACRO_PROT_ARGS) { int la, nl; - enum mdoct ntok; enum margserr ac; char *p; struct mdoc_node *blk; /* saved block context */ @@ -1297,21 +1276,9 @@ blk_part_imp(MACRO_PROT_ARGS) if (body == NULL) body = mdoc_body_alloc(mdoc, line, ppos, tok); - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); - - if (ntok == MDOC_MAX) { - dword(mdoc, line, la, p, DELIM_MAX, - MDOC_JOIN & mdoc_macros[tok].flags); - continue; - } - - if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) - return(0); - break; + if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) + break; } - - /* Clean-ups to leave in a consistent state. */ - if (body == NULL) body = mdoc_body_alloc(mdoc, line, ppos, tok); @@ -1320,6 +1287,7 @@ blk_part_imp(MACRO_PROT_ARGS) * postpone closing out the current block * until the rew_sub() call closing out the sub-block. */ + for (n = mdoc->last; n && n != body && n != blk->parent; n = n->parent) { if (n->type == MDOC_BLOCK && @@ -1328,19 +1296,13 @@ blk_part_imp(MACRO_PROT_ARGS) make_pending(n, tok, mdoc, line, ppos); mdoc_endbody_alloc(mdoc, line, ppos, tok, body, ENDBODY_NOSPACE); - return(1); + return; } } assert(n == body); rew_sub(MDOC_BODY, mdoc, tok, line, ppos); - - /* Standard appending of delimiters. */ - if (nl) append_delims(mdoc, line, pos, buf); - - /* Rewind scope, if applicable. */ - rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); /* Move trailing .Ns out of scope. */ @@ -1349,11 +1311,9 @@ blk_part_imp(MACRO_PROT_ARGS) /* Do nothing. */ ; if (n && n->tok == MDOC_Ns) mdoc_node_relink(mdoc, n); - - return(1); } -static int +static void blk_part_exp(MACRO_PROT_ARGS) { int la, nl; @@ -1361,7 +1321,6 @@ blk_part_exp(MACRO_PROT_ARGS) struct mdoc_node *head; /* keep track of head */ struct mdoc_node *body; /* keep track of body */ char *p; - enum mdoct ntok; nl = MDOC_NEWLINE & mdoc->flags; @@ -1409,15 +1368,8 @@ blk_part_exp(MACRO_PROT_ARGS) } assert(head != NULL && body != NULL); - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); - if (ntok == MDOC_MAX) { - dword(mdoc, line, la, p, DELIM_MAX, - MDOC_JOIN & mdoc_macros[tok].flags); - continue; - } - if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) - return(0); - break; + if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) + break; } /* Clean-up to leave in a consistent state. */ @@ -1429,25 +1381,20 @@ blk_part_exp(MACRO_PROT_ARGS) rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); mdoc_body_alloc(mdoc, line, ppos, tok); } - - /* Standard appending of delimiters. */ - if (nl) append_delims(mdoc, line, pos, buf); - return(1); } -static int +static void in_line_argn(MACRO_PROT_ARGS) { int la, flushed, j, maxargs, nl; enum margserr ac; - enum margverr av; struct mdoc_arg *arg; char *p; enum mdoct ntok; - nl = MDOC_NEWLINE & mdoc->flags; + nl = mdoc->flags & MDOC_NEWLINE; /* * A line macro that has a fixed number of arguments (maxargs). @@ -1477,29 +1424,20 @@ in_line_argn(MACRO_PROT_ARGS) break; } - for (arg = NULL; ; ) { - la = *pos; - av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); + mdoc_argv(mdoc, line, tok, &arg, pos, buf); - if (ARGV_WORD == av) { - *pos = la; - break; - } - - if (ARGV_EOLN == av) - break; - if (ARGV_ARG == av) - continue; - - mdoc_argv_free(arg); - return(0); - } - - for (flushed = j = 0; ; ) { + p = NULL; + flushed = j = 0; + for (;;) { la = *pos; ac = mdoc_args(mdoc, line, pos, buf, tok, &p); - if (ac == ARGS_PUNCT || ac == ARGS_EOLN) + if (ac == ARGS_PUNCT || ac == ARGS_EOLN) { + if (j < 2 && tok == MDOC_Pf) + mandoc_vmsg(MANDOCERR_PF_SKIP, + mdoc->parse, line, ppos, "Pf %s", + p == NULL ? "at eol" : p); break; + } if ( ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) && ac != ARGS_QWORD && j == 0 && @@ -1514,14 +1452,14 @@ in_line_argn(MACRO_PROT_ARGS) flushed = 1; } - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); + ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && j == 0)) ? + MDOC_MAX : lookup(mdoc, tok, line, la, p); if (ntok != MDOC_MAX) { if ( ! flushed) rew_elem(mdoc, tok); flushed = 1; - if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) - return(0); + mdoc_macro(mdoc, ntok, line, la, pos, buf); j++; break; } @@ -1538,105 +1476,63 @@ in_line_argn(MACRO_PROT_ARGS) j++; } - if (j == 0) + if (j == 0) { mdoc_elem_alloc(mdoc, line, ppos, tok, arg); - - /* Close out in a consistent state. */ - + if (ac == ARGS_PUNCT && tok == MDOC_Pf) + append_delims(mdoc, line, pos, buf); + } if ( ! flushed) rew_elem(mdoc, tok); if (nl) append_delims(mdoc, line, pos, buf); - return(1); } -static int +static void in_line_eoln(MACRO_PROT_ARGS) { - int la; - enum margserr ac; - enum margverr av; struct mdoc_arg *arg; - char *p; - enum mdoct ntok; - assert( ! (MDOC_PARSED & mdoc_macros[tok].flags)); - if (tok == MDOC_Pp) rew_sub(MDOC_BLOCK, mdoc, MDOC_Nm, line, ppos); - /* Parse macro arguments. */ - - for (arg = NULL; ; ) { - la = *pos; - av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); - - if (ARGV_WORD == av) { - *pos = la; - break; - } - if (ARGV_EOLN == av) - break; - if (ARGV_ARG == av) - continue; - - mdoc_argv_free(arg); - return(0); - } - - /* Open element scope. */ - + mdoc_argv(mdoc, line, tok, &arg, pos, buf); mdoc_elem_alloc(mdoc, line, ppos, tok, arg); + if (parse_rest(mdoc, tok, line, pos, buf)) + return; + rew_elem(mdoc, tok); +} - /* Parse argument terms. */ +/* + * The simplest argument parser available: Parse the remaining + * words until the end of the phrase or line and return 0 + * or until the next macro, call that macro, and return 1. + */ +static int +parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf) +{ + int la; for (;;) { la = *pos; - ac = mdoc_args(mdoc, line, pos, buf, tok, &p); - if (ac == ARGS_EOLN) - break; - - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); - - if (ntok == MDOC_MAX) { - dword(mdoc, line, la, p, DELIM_MAX, - MDOC_JOIN & mdoc_macros[tok].flags); - continue; - } - rew_elem(mdoc, tok); - return(mdoc_macro(mdoc, ntok, line, la, pos, buf)); + if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN) + return(0); + if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) + return(1); } - - /* Close out (no delimiters). */ - - rew_elem(mdoc, tok); - return(1); } -static int +static void ctx_synopsis(MACRO_PROT_ARGS) { - int nl; - nl = MDOC_NEWLINE & mdoc->flags; - - /* If we're not in the SYNOPSIS, go straight to in-line. */ - if ( ! (MDOC_SYNOPSIS & mdoc->flags)) - return(in_line(mdoc, tok, line, ppos, pos, buf)); - - /* If we're a nested call, same place. */ - if ( ! nl) - return(in_line(mdoc, tok, line, ppos, pos, buf)); - - /* - * XXX: this will open a block scope; however, if later we end - * up formatting the block scope, then child nodes will inherit - * the formatting. Be careful. - */ - if (MDOC_Nm == tok) - return(blk_full(mdoc, tok, line, ppos, pos, buf)); - assert(MDOC_Vt == tok); - return(blk_part_imp(mdoc, tok, line, ppos, pos, buf)); + if (~mdoc->flags & (MDOC_SYNOPSIS | MDOC_NEWLINE)) + in_line(mdoc, tok, line, ppos, pos, buf); + else if (tok == MDOC_Nm) + blk_full(mdoc, tok, line, ppos, pos, buf); + else { + assert(tok == MDOC_Vt); + blk_part_imp(mdoc, tok, line, ppos, pos, buf); + } } /* @@ -1644,80 +1540,25 @@ ctx_synopsis(MACRO_PROT_ARGS) * They're unusual because they're basically free-form text until a * macro is encountered. */ -static int -phrase(struct mdoc *mdoc, int line, int ppos, char *buf) -{ - int la, pos; - enum margserr ac; - enum mdoct ntok; - char *p; - - for (pos = ppos; ; ) { - la = pos; - - ac = mdoc_zargs(mdoc, line, &pos, buf, &p); - if (ac == ARGS_EOLN) - break; - - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup_raw(p); - - if (ntok == MDOC_MAX) { - dword(mdoc, line, la, p, DELIM_MAX, 1); - continue; - } - - if ( ! mdoc_macro(mdoc, ntok, line, la, &pos, buf)) - return(0); - append_delims(mdoc, line, &pos, buf); - return(1); - } - - return(1); -} - -static int +static void phrase_ta(MACRO_PROT_ARGS) { struct mdoc_node *n; - int la; - enum mdoct ntok; - enum margserr ac; - char *p; /* Make sure we are in a column list or ignore this macro. */ + n = mdoc->last; - while (NULL != n && MDOC_Bl != n->tok) + while (n != NULL && n->tok != MDOC_Bl) n = n->parent; - if (NULL == n || LIST_column != n->norm->Bl.type) { + if (n == NULL || n->norm->Bl.type != LIST_column) { mandoc_msg(MANDOCERR_TA_STRAY, mdoc->parse, line, ppos, "Ta"); - return(1); + return; } /* Advance to the next column. */ rew_sub(MDOC_BODY, mdoc, MDOC_It, line, ppos); mdoc_body_alloc(mdoc, line, ppos, MDOC_It); - - for (;;) { - la = *pos; - ac = mdoc_zargs(mdoc, line, pos, buf, &p); - if (ac == ARGS_EOLN) - break; - - ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup_raw(p); - - if (ntok == MDOC_MAX) { - dword(mdoc, line, la, p, DELIM_MAX, - MDOC_JOIN & mdoc_macros[tok].flags); - continue; - } - - if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) - return(0); - append_delims(mdoc, line, pos, buf); - return(1); - } - - return(1); + parse_rest(mdoc, MDOC_MAX, line, pos, buf); }