-/* $Id: mdoc_macro.c,v 1.173 2015/02/04 18:03:47 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.181 2015/02/10 17:47:45 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
assert(to);
mdoc->next = MDOC_NEXT_SIBLING;
while (mdoc->last != to) {
- if ( ! (mdoc->last->flags & MDOC_VALID))
- mdoc->last->lastline = to->lastline -
- (mdoc->flags & MDOC_NEWLINE ? 1 : 0);
/*
* Save the parent here, because we may delete the
* mdoc->last node in the post-validation phase and reset
/* Remember the start of our own body. */
if (n->type == MDOC_BODY && atok == n->tok) {
- if (n->end == ENDBODY_NOT) {
+ if (n->end == ENDBODY_NOT)
body = n;
- n->lastline = line;
- }
continue;
}
}
if (atok == n->tok) {
- n->lastline = line;
assert(body);
/*
*/
if (ac == ARGS_PUNCT) {
- if (cnt == 0 && nc == 0)
+ if (cnt == 0 && (nc == 0 || tok == MDOC_An))
mdoc->flags |= MDOC_NODELIMC;
break;
}
nl = MDOC_NEWLINE & mdoc->flags;
+ if (buf[*pos] == '\0' && (tok == MDOC_Sh || tok == MDOC_Ss)) {
+ mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
+ line, ppos, mdoc_macronames[tok]);
+ return;
+ }
+
if ( ! (mdoc_macros[tok].flags & MDOC_EXPLICIT)) {
/* Here, tok is one of Sh Ss Nm Nd It. */
mdoc_macronames[tok],
mdoc_macronames[n->tok]);
rew_pending(mdoc, n);
+ n = mdoc->last;
continue;
case MDOC_It:
/* Delay in case it's astray. */
body = mdoc_body_alloc(mdoc, line, ppos, tok);
break;
}
+ if (tok == MDOC_Bd || tok == MDOC_Bk) {
+ mandoc_vmsg(MANDOCERR_ARG_EXCESS,
+ mdoc->parse, line, la, "%s ... %s",
+ mdoc_macronames[tok], buf + la);
+ break;
+ }
if (tok == MDOC_Rs) {
mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse,
line, la, "Rs %s", buf + la);
return;
if (head == NULL)
head = mdoc_head_alloc(mdoc, line, ppos, tok);
- if (nl && tok != MDOC_Rs)
+ if (nl && tok != MDOC_Bd && tok != MDOC_Bl && tok != MDOC_Rs)
append_delims(mdoc, line, pos, buf);
if (body != NULL)
goto out;
static void
in_line_argn(MACRO_PROT_ARGS)
{
- int la, flushed, j, maxargs, nl;
- enum margserr ac;
struct mdoc_arg *arg;
char *p;
+ enum margserr ac;
enum mdoct ntok;
+ int state; /* arg#; -1: not yet open; -2: closed */
+ int la, maxargs, nl;
nl = mdoc->flags & MDOC_NEWLINE;
mdoc_argv(mdoc, line, tok, &arg, pos, buf);
+ state = -1;
p = NULL;
- flushed = j = 0;
for (;;) {
la = *pos;
ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
+
+ if (ac == ARGS_WORD && state == -1 &&
+ ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) &&
+ mdoc_isdelim(p) == DELIM_OPEN) {
+ dword(mdoc, line, la, p, DELIM_OPEN, 0);
+ continue;
+ }
+
+ if (state == -1 && tok != MDOC_In &&
+ tok != MDOC_St && tok != MDOC_Xr) {
+ mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
+ state = 0;
+ }
+
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) {
- if (j < 2 && tok == MDOC_Pf)
+ if (abs(state) < 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 &&
- mdoc_isdelim(p) == DELIM_OPEN) {
- dword(mdoc, line, la, p, DELIM_OPEN, 0);
- continue;
- } else if (j == 0)
- mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
-
- if (j == maxargs && ! flushed) {
+ if (state == maxargs) {
rew_elem(mdoc, tok);
- flushed = 1;
+ state = -2;
}
- ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && j == 0)) ?
+ ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && state == 0)) ?
MDOC_MAX : lookup(mdoc, tok, line, la, p);
if (ntok != MDOC_MAX) {
- if ( ! flushed)
+ if (state >= 0) {
rew_elem(mdoc, tok);
- flushed = 1;
+ state = -2;
+ }
mdoc_macro(mdoc, ntok, line, la, pos, buf);
- j++;
break;
}
- if ( ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) &&
- ac != ARGS_QWORD && ! flushed &&
- mdoc_isdelim(p) != DELIM_NONE) {
+ if (ac == ARGS_QWORD ||
+ mdoc_macros[tok].flags & MDOC_IGNDELIM ||
+ mdoc_isdelim(p) == DELIM_NONE) {
+ if (state == -1) {
+ mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
+ state = 1;
+ } else if (state >= 0)
+ state++;
+ } else if (state >= 0) {
rew_elem(mdoc, tok);
- flushed = 1;
+ state = -2;
}
dword(mdoc, line, la, p, DELIM_MAX,
MDOC_JOIN & mdoc_macros[tok].flags);
- j++;
}
- if (j == 0) {
- mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
- if (ac == ARGS_PUNCT && tok == MDOC_Pf)
- append_delims(mdoc, line, pos, buf);
+ if (state == -1) {
+ mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
+ line, ppos, mdoc_macronames[tok]);
+ return;
}
- if ( ! flushed)
+
+ if (state == 0 && tok == MDOC_Pf)
+ append_delims(mdoc, line, pos, buf);
+ if (state >= 0)
rew_elem(mdoc, tok);
if (nl)
append_delims(mdoc, line, pos, buf);
rew_last(mdoc, mdoc->last->parent);
}
+ if (buf[*pos] == '\0' &&
+ (tok == MDOC_Fd || mdoc_macronames[tok][0] == '%')) {
+ mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
+ line, ppos, mdoc_macronames[tok]);
+ return;
+ }
+
mdoc_argv(mdoc, line, tok, &arg, pos, buf);
mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
if (parse_rest(mdoc, tok, line, pos, buf))