version 1.45, 2010/03/30 06:52:08 |
version 1.47, 2010/03/31 07:13:53 |
Line 42 static int blk_exp_close(MACRO_PROT_ARGS); |
|
Line 42 static int blk_exp_close(MACRO_PROT_ARGS); |
|
static int blk_part_imp(MACRO_PROT_ARGS); |
static int blk_part_imp(MACRO_PROT_ARGS); |
|
|
static int phrase(struct mdoc *, int, int, char *); |
static int phrase(struct mdoc *, int, int, char *); |
static int rew_dohalt(int, enum mdoc_type, |
static int rew_dohalt(enum mdoct, enum mdoc_type, |
const struct mdoc_node *); |
const struct mdoc_node *); |
static int rew_alt(int); |
static enum mdoct rew_alt(enum mdoct); |
static int rew_dobreak(int, const struct mdoc_node *); |
static int rew_dobreak(enum mdoct, const struct mdoc_node *); |
static int rew_elem(struct mdoc *, int); |
static int rew_elem(struct mdoc *, enum mdoct); |
static int rew_sub(enum mdoc_type, struct mdoc *, |
static int rew_sub(enum mdoc_type, struct mdoc *, |
int, int, int); |
enum mdoct, int, int); |
static int rew_last(struct mdoc *, |
static int rew_last(struct mdoc *, |
const struct mdoc_node *); |
const struct mdoc_node *); |
static int append_delims(struct mdoc *, int, int *, char *); |
static int append_delims(struct mdoc *, int, int *, char *); |
Line 318 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
Line 318 rew_last(struct mdoc *mdoc, const struct mdoc_node *to |
|
* Return the opening macro of a closing one, e.g., `Ec' has `Eo' as its |
* Return the opening macro of a closing one, e.g., `Ec' has `Eo' as its |
* matching pair. |
* matching pair. |
*/ |
*/ |
static int |
static enum mdoct |
rew_alt(int tok) |
rew_alt(enum mdoct tok) |
{ |
{ |
switch (tok) { |
switch (tok) { |
case (MDOC_Ac): |
case (MDOC_Ac): |
Line 369 rew_alt(int tok) |
|
Line 369 rew_alt(int tok) |
|
* The scope-closing and so on occurs in the various rew_* routines. |
* The scope-closing and so on occurs in the various rew_* routines. |
*/ |
*/ |
static int |
static int |
rew_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p) |
rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
const struct mdoc_node *p) |
{ |
{ |
|
|
if (MDOC_ROOT == p->type) |
if (MDOC_ROOT == p->type) |
Line 508 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
Line 509 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
* REWIND_NOHALT). |
* REWIND_NOHALT). |
*/ |
*/ |
static int |
static int |
rew_dobreak(int tok, const struct mdoc_node *p) |
rew_dobreak(enum mdoct tok, const struct mdoc_node *p) |
{ |
{ |
|
|
assert(MDOC_ROOT != p->type); |
assert(MDOC_ROOT != p->type); |
Line 537 rew_dobreak(int tok, const struct mdoc_node *p) |
|
Line 538 rew_dobreak(int tok, const struct mdoc_node *p) |
|
return(1); |
return(1); |
break; |
break; |
case (MDOC_Oc): |
case (MDOC_Oc): |
/* XXX - experimental! */ |
#ifdef UGLY |
if (MDOC_Op == p->tok) |
if (MDOC_Op == p->tok) |
return(1); |
return(1); |
|
#endif |
break; |
break; |
default: |
default: |
break; |
break; |
Line 555 rew_dobreak(int tok, const struct mdoc_node *p) |
|
Line 557 rew_dobreak(int tok, const struct mdoc_node *p) |
|
|
|
|
|
static int |
static int |
rew_elem(struct mdoc *mdoc, int tok) |
rew_elem(struct mdoc *mdoc, enum mdoct tok) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
|
Line 571 rew_elem(struct mdoc *mdoc, int tok) |
|
Line 573 rew_elem(struct mdoc *mdoc, int tok) |
|
|
|
static int |
static int |
rew_sub(enum mdoc_type t, struct mdoc *m, |
rew_sub(enum mdoc_type t, struct mdoc *m, |
int tok, int line, int ppos) |
enum mdoct tok, int line, int ppos) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
int c; |
int c; |
Line 595 rew_sub(enum mdoc_type t, struct mdoc *m, |
|
Line 597 rew_sub(enum mdoc_type t, struct mdoc *m, |
|
} |
} |
|
|
assert(n); |
assert(n); |
return(rew_last(m, n)); |
if ( ! rew_last(m, n)) |
|
return(0); |
|
|
|
#ifdef UGLY |
|
/* |
|
* The current block extends an enclosing block beyond a line |
|
* break. Now that the current block ends, close the enclosing |
|
* block, too. |
|
*/ |
|
if (NULL != (n = n->pending)) { |
|
assert(MDOC_HEAD == n->type); |
|
if ( ! rew_last(m, n)) |
|
return(0); |
|
if ( ! mdoc_body_alloc(m, n->line, n->pos, n->tok)) |
|
return(0); |
|
} |
|
#endif |
|
|
|
return(1); |
} |
} |
|
|
|
|
Line 861 blk_full(MACRO_PROT_ARGS) |
|
Line 881 blk_full(MACRO_PROT_ARGS) |
|
int c, la; |
int c, la; |
struct mdoc_arg *arg; |
struct mdoc_arg *arg; |
struct mdoc_node *head; /* save of head macro */ |
struct mdoc_node *head; /* save of head macro */ |
|
struct mdoc_node *n; |
char *p; |
char *p; |
|
|
/* Close out prior implicit scope. */ |
/* Close out prior implicit scope. */ |
Line 978 blk_full(MACRO_PROT_ARGS) |
|
Line 999 blk_full(MACRO_PROT_ARGS) |
|
if (MDOC_Nd == tok) |
if (MDOC_Nd == tok) |
return(1); |
return(1); |
|
|
|
#ifdef UGLY |
|
/* |
|
* If there is an open sub-block requiring explicit close-out, |
|
* postpone switching the current block from head to body until |
|
* the rew_sub() call closing out that sub-block. |
|
*/ |
|
for (n = m->last; n && n != head; n = n->parent) { |
|
if (MDOC_EXPLICIT & mdoc_macros[n->tok].flags && |
|
MDOC_BLOCK == n->type) { |
|
n->pending = head; |
|
return(1); |
|
} |
|
} |
|
#endif |
|
|
/* Close out scopes to remain in a consistent state. */ |
/* Close out scopes to remain in a consistent state. */ |
|
|
if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) |
if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) |
Line 1066 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1102 blk_part_imp(MACRO_PROT_ARGS) |
|
body = m->last; |
body = m->last; |
} |
} |
|
|
|
#ifdef UGLY |
/* |
/* |
* If we can't rewind to our body, then our scope has already |
* If we can't rewind to our body, then our scope has already |
* been closed by another macro (like `Oc' closing `Op'). This |
* been closed by another macro (like `Oc' closing `Op'). This |
* is ugly behaviour nodding its head to OpenBSD's overwhelming |
* is ugly behaviour nodding its head to OpenBSD's overwhelming |
* crufty use of `Op' breakage. XXX: DEPRECATE. |
* crufty use of `Op' breakage. |
*/ |
*/ |
|
|
for (n = m->last; n; n = n->parent) |
for (n = m->last; n; n = n->parent) |
if (body == n) |
if (body == n) |
break; |
break; |
|
#endif |
|
|
if (NULL == n && ! mdoc_nwarn(m, body, EIMPBRK)) |
if (NULL == n && ! mdoc_nwarn(m, body, EIMPBRK)) |
return(0); |
return(0); |
Line 1209 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1246 in_line_argn(MACRO_PROT_ARGS) |
|
struct mdoc_arg *arg; |
struct mdoc_arg *arg; |
char *p; |
char *p; |
|
|
/* Fixed maximum arguments per macro, if applicable. */ |
/* |
|
* A line macro that has a fixed number of arguments (maxargs). |
|
* Only open the scope once the first non-leading-punctuation is |
|
* found (unless MDOC_IGNDELIM is noted, like in `Pf'), then |
|
* keep it open until the maximum number of arguments are |
|
* exhausted. |
|
*/ |
|
|
switch (tok) { |
switch (tok) { |
case (MDOC_Ap): |
case (MDOC_Ap): |
Line 1229 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1272 in_line_argn(MACRO_PROT_ARGS) |
|
break; |
break; |
} |
} |
|
|
/* Macro argument processing. */ |
for (arg = NULL; ; ) { |
|
|
for (arg = NULL;; ) { |
|
la = *pos; |
la = *pos; |
c = mdoc_argv(m, line, tok, &arg, pos, buf); |
c = mdoc_argv(m, line, tok, &arg, pos, buf); |
|
|
Line 1249 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1290 in_line_argn(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
} |
} |
|
|
/* Open the element scope. */ |
for (flushed = j = 0; ; ) { |
|
|
if ( ! mdoc_elem_alloc(m, line, ppos, tok, arg)) |
|
return(0); |
|
|
|
/* Process element arguments. */ |
|
|
|
for (flushed = j = 0; ; j++) { |
|
la = *pos; |
la = *pos; |
|
|
if (j == maxargs && ! flushed) { |
|
if ( ! rew_elem(m, tok)) |
|
return(0); |
|
flushed = 1; |
|
} |
|
|
|
c = mdoc_args(m, line, pos, buf, tok, &p); |
c = mdoc_args(m, line, pos, buf, tok, &p); |
|
|
if (ARGS_ERROR == c) |
if (ARGS_ERROR == c) |
Line 1274 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1301 in_line_argn(MACRO_PROT_ARGS) |
|
if (ARGS_EOLN == c) |
if (ARGS_EOLN == c) |
break; |
break; |
|
|
|
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) && |
|
0 == j && 1 == mdoc_isdelim(p)) { |
|
if ( ! mdoc_word_alloc(m, line, la, p)) |
|
return(0); |
|
continue; |
|
} else if (0 == j) |
|
if ( ! mdoc_elem_alloc(m, line, la, tok, arg)) |
|
return(0); |
|
|
|
if (j == maxargs && ! flushed) { |
|
if ( ! rew_elem(m, tok)) |
|
return(0); |
|
flushed = 1; |
|
} |
|
|
if (MDOC_MAX != (c = lookup(tok, p))) { |
if (MDOC_MAX != (c = lookup(tok, p))) { |
if ( ! flushed && ! rew_elem(m, tok)) |
if ( ! flushed && ! rew_elem(m, tok)) |
return(0); |
return(0); |
flushed = 1; |
flushed = 1; |
if ( ! mdoc_macro(m, c, line, la, pos, buf)) |
if ( ! mdoc_macro(m, c, line, la, pos, buf)) |
return(0); |
return(0); |
|
j++; |
break; |
break; |
} |
} |
|
|
Line 1297 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1340 in_line_argn(MACRO_PROT_ARGS) |
|
* code is no here, it's unlikely to be removed. |
* code is no here, it's unlikely to be removed. |
*/ |
*/ |
|
|
|
#ifdef __OpenBSD__ |
if (MDOC_Xr == tok && j == maxargs) { |
if (MDOC_Xr == tok && j == maxargs) { |
if ( ! mdoc_elem_alloc(m, line, ppos, MDOC_Ns, NULL)) |
if ( ! mdoc_elem_alloc(m, line, la, MDOC_Ns, NULL)) |
return(0); |
return(0); |
if ( ! rew_elem(m, MDOC_Ns)) |
if ( ! rew_elem(m, MDOC_Ns)) |
return(0); |
return(0); |
} |
} |
|
#endif |
|
|
if ( ! mdoc_word_alloc(m, line, la, p)) |
if ( ! mdoc_word_alloc(m, line, la, p)) |
return(0); |
return(0); |
|
j++; |
} |
} |
|
|
/* Close out and append delimiters. */ |
if (0 == j && ! mdoc_elem_alloc(m, line, la, tok, arg)) |
|
return(0); |
|
|
|
/* Close out in a consistent state. */ |
|
|
if ( ! flushed && ! rew_elem(m, tok)) |
if ( ! flushed && ! rew_elem(m, tok)) |
return(0); |
return(0); |