version 1.134, 2014/07/02 11:43:20 |
version 1.143, 2014/09/07 00:05:28 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#ifdef HAVE_CONFIG_H |
|
#include "config.h" |
#include "config.h" |
#endif |
|
|
|
|
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <stdlib.h> |
#include <stdlib.h> |
Line 210 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 210 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ in_line_eoln, 0 }, /* sp */ |
{ in_line_eoln, 0 }, /* sp */ |
{ in_line_eoln, 0 }, /* %U */ |
{ in_line_eoln, 0 }, /* %U */ |
{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */ |
{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */ |
{ in_line_eoln, 0 }, /* ll */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* ll */ |
}; |
}; |
|
|
const struct mdoc_macro * const mdoc_macros = __mdoc_macros; |
const struct mdoc_macro * const mdoc_macros = __mdoc_macros; |
Line 234 mdoc_macroend(struct mdoc *mdoc) |
|
Line 234 mdoc_macroend(struct mdoc *mdoc) |
|
for ( ; n; n = n->parent) |
for ( ; n; n = n->parent) |
if (MDOC_BLOCK == n->type && |
if (MDOC_BLOCK == n->type && |
MDOC_EXPLICIT & mdoc_macros[n->tok].flags) |
MDOC_EXPLICIT & mdoc_macros[n->tok].flags) |
mdoc_nmsg(mdoc, n, MANDOCERR_SCOPEEXIT); |
mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse, |
|
n->line, n->pos, mdoc_macronames[n->tok]); |
|
|
/* Rewind to the first. */ |
/* Rewind to the first. */ |
|
|
Line 423 rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
Line 424 rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
return(REWIND_NONE); |
return(REWIND_NONE); |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MDOC_Sh: |
case MDOC_Sh: |
|
if (MDOC_ROOT == p->parent->type) |
|
return(REWIND_THIS); |
if (MDOC_Nd == p->tok || MDOC_Ss == p->tok || |
if (MDOC_Nd == p->tok || MDOC_Ss == p->tok || |
MDOC_Sh == p->tok) |
MDOC_Sh == p->tok) |
return(REWIND_MORE); |
return(REWIND_MORE); |
Line 528 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
Line 531 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
taker->pending = broken->pending; |
taker->pending = broken->pending; |
} |
} |
broken->pending = breaker; |
broken->pending = breaker; |
mandoc_vmsg(MANDOCERR_BLOCK_NEST, mdoc->parse, line, ppos, |
mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos, |
"%s breaks %s", mdoc_macronames[tok], |
"%s breaks %s", mdoc_macronames[tok], |
mdoc_macronames[broken->tok]); |
mdoc_macronames[broken->tok]); |
return(1); |
return(1); |
Line 558 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
Line 561 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
! (MDOC_EXPLICIT & mdoc_macros[tok].flags)); |
! (MDOC_EXPLICIT & mdoc_macros[tok].flags)); |
break; |
break; |
case REWIND_FORCE: |
case REWIND_FORCE: |
mandoc_vmsg(MANDOCERR_SCOPEBROKEN, mdoc->parse, |
mandoc_vmsg(MANDOCERR_BLK_BROKEN, mdoc->parse, |
line, ppos, "%s breaks %s", |
line, ppos, "%s breaks %s", |
mdoc_macronames[tok], |
mdoc_macronames[tok], |
mdoc_macronames[n->tok]); |
mdoc_macronames[n->tok]); |
Line 574 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
Line 577 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
return(1); |
return(1); |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case REWIND_ERROR: |
case REWIND_ERROR: |
mdoc_pmsg(mdoc, line, ppos, MANDOCERR_NOSCOPE); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, |
|
mdoc->parse, line, ppos, |
|
mdoc_macronames[tok]); |
return(1); |
return(1); |
} |
} |
break; |
break; |
Line 769 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 774 blk_exp_close(MACRO_PROT_ARGS) |
|
later = n; |
later = n; |
} |
} |
|
|
if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) { |
if ( ! (MDOC_PARSED & mdoc_macros[tok].flags)) { |
/* FIXME: do this in validate */ |
if ('\0' != buf[*pos]) |
if (buf[*pos]) |
mandoc_vmsg(MANDOCERR_ARG_SKIP, |
mdoc_pmsg(mdoc, line, ppos, MANDOCERR_ARGSLOST); |
mdoc->parse, line, ppos, |
|
"%s %s", mdoc_macronames[tok], |
|
buf + *pos); |
if ( ! rew_sub(MDOC_BODY, mdoc, tok, line, ppos)) |
if ( ! rew_sub(MDOC_BODY, mdoc, tok, line, ppos)) |
return(0); |
return(0); |
return(rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)); |
return(rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos)); |
Line 837 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 843 blk_exp_close(MACRO_PROT_ARGS) |
|
static int |
static int |
in_line(MACRO_PROT_ARGS) |
in_line(MACRO_PROT_ARGS) |
{ |
{ |
int la, scope, cnt, nc, nl; |
int la, scope, cnt, mayopen, nc, nl; |
enum margverr av; |
enum margverr av; |
enum mdoct ntok; |
enum mdoct ntok; |
enum margserr ac; |
enum margserr ac; |
Line 888 in_line(MACRO_PROT_ARGS) |
|
Line 894 in_line(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
} |
} |
|
|
|
mayopen = 1; |
for (cnt = scope = 0;; ) { |
for (cnt = scope = 0;; ) { |
la = *pos; |
la = *pos; |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
Line 919 in_line(MACRO_PROT_ARGS) |
|
Line 926 in_line(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
} else if ( ! nc && 0 == cnt) { |
} else if ( ! nc && 0 == cnt) { |
mdoc_argv_free(arg); |
mdoc_argv_free(arg); |
mdoc_pmsg(mdoc, line, ppos, |
mandoc_msg(MANDOCERR_MACRO_EMPTY, |
MANDOCERR_MACROEMPTY); |
mdoc->parse, line, ppos, |
|
mdoc_macronames[tok]); |
} |
} |
|
|
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
Line 943 in_line(MACRO_PROT_ARGS) |
|
Line 951 in_line(MACRO_PROT_ARGS) |
|
* If we encounter closing punctuation, no word |
* If we encounter closing punctuation, no word |
* has been omitted, no scope is open, and we're |
* has been omitted, no scope is open, and we're |
* allowed to have an empty element, then start |
* allowed to have an empty element, then start |
* a new scope. `Ar', `Fl', and `Li', only do |
* a new scope. |
* this once per invocation. There may be more |
|
* of these (all of them?). |
|
*/ |
*/ |
if (0 == cnt && (nc || MDOC_Li == tok) && |
if ((d == DELIM_CLOSE || |
DELIM_CLOSE == d && ! scope) { |
(d == DELIM_MIDDLE && tok == MDOC_Fl)) && |
|
(nc || tok == MDOC_Li) && |
|
!scope && !cnt && mayopen) { |
if ( ! mdoc_elem_alloc(mdoc, |
if ( ! mdoc_elem_alloc(mdoc, |
line, ppos, tok, arg)) |
line, ppos, tok, arg)) |
return(0); |
return(0); |
if (MDOC_Ar == tok || MDOC_Li == tok || |
|
MDOC_Fl == tok) |
|
cnt++; |
|
scope = 1; |
scope = 1; |
|
cnt++; |
|
if (MDOC_Li == tok || MDOC_Nm == tok) |
|
mayopen = 0; |
} |
} |
/* |
/* |
* Close out our scope, if one is open, before |
* Close out our scope, if one is open, before |
Line 964 in_line(MACRO_PROT_ARGS) |
|
Line 972 in_line(MACRO_PROT_ARGS) |
|
if (scope && ! rew_elem(mdoc, tok)) |
if (scope && ! rew_elem(mdoc, tok)) |
return(0); |
return(0); |
scope = 0; |
scope = 0; |
} else if ( ! scope) { |
} else if (mayopen && !scope) { |
if ( ! mdoc_elem_alloc(mdoc, line, ppos, tok, arg)) |
if ( ! mdoc_elem_alloc(mdoc, line, ppos, tok, arg)) |
return(0); |
return(0); |
scope = 1; |
scope = 1; |
|
cnt++; |
} |
} |
|
|
if (DELIM_NONE == d) |
|
cnt++; |
|
|
|
if ( ! dword(mdoc, line, la, p, d, |
if ( ! dword(mdoc, line, la, p, d, |
MDOC_JOIN & mdoc_macros[tok].flags)) |
MDOC_JOIN & mdoc_macros[tok].flags)) |
return(0); |
return(0); |
Line 1005 in_line(MACRO_PROT_ARGS) |
|
Line 1011 in_line(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
} else if ( ! nc && 0 == cnt) { |
} else if ( ! nc && 0 == cnt) { |
mdoc_argv_free(arg); |
mdoc_argv_free(arg); |
mdoc_pmsg(mdoc, line, ppos, MANDOCERR_MACROEMPTY); |
mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse, |
|
line, ppos, mdoc_macronames[tok]); |
} |
} |
|
|
if ( ! nl) |
if ( ! nl) |
Line 1029 blk_full(MACRO_PROT_ARGS) |
|
Line 1036 blk_full(MACRO_PROT_ARGS) |
|
|
|
nl = MDOC_NEWLINE & mdoc->flags; |
nl = MDOC_NEWLINE & mdoc->flags; |
|
|
|
/* Skip items outside lists. */ |
|
|
|
if (tok == MDOC_It) { |
|
for (n = mdoc->last; n; n = n->parent) |
|
if (n->tok == MDOC_Bl && |
|
! (n->flags & MDOC_VALID)) |
|
break; |
|
if (n == NULL) { |
|
mandoc_vmsg(MANDOCERR_IT_STRAY, mdoc->parse, |
|
line, ppos, "It %s", buf + *pos); |
|
if ( ! mdoc_elem_alloc(mdoc, line, ppos, |
|
MDOC_br, NULL)) |
|
return(0); |
|
return(rew_elem(mdoc, MDOC_br)); |
|
} |
|
} |
|
|
/* Close out prior implicit scope. */ |
/* Close out prior implicit scope. */ |
|
|
if ( ! (MDOC_EXPLICIT & mdoc_macros[tok].flags)) { |
if ( ! (MDOC_EXPLICIT & mdoc_macros[tok].flags)) { |
Line 1760 phrase_ta(MACRO_PROT_ARGS) |
|
Line 1784 phrase_ta(MACRO_PROT_ARGS) |
|
while (NULL != n && MDOC_Bl != n->tok) |
while (NULL != n && MDOC_Bl != n->tok) |
n = n->parent; |
n = n->parent; |
if (NULL == n || LIST_column != n->norm->Bl.type) { |
if (NULL == n || LIST_column != n->norm->Bl.type) { |
mdoc_pmsg(mdoc, line, ppos, MANDOCERR_STRAYTA); |
mandoc_msg(MANDOCERR_TA_STRAY, mdoc->parse, |
|
line, ppos, "Ta"); |
return(1); |
return(1); |
} |
} |
|
|