version 1.107, 2011/04/19 16:38:48 |
version 1.118, 2012/11/16 13:40:36 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012 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 |
Line 74 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 74 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ in_line_eoln, MDOC_PROLOGUE }, /* Dd */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Dd */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Dt */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Dt */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Os */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Os */ |
{ blk_full, 0 }, /* Sh */ |
{ blk_full, MDOC_PARSED }, /* Sh */ |
{ blk_full, 0 }, /* Ss */ |
{ blk_full, MDOC_PARSED }, /* Ss */ |
{ in_line_eoln, 0 }, /* Pp */ |
{ in_line_eoln, 0 }, /* Pp */ |
{ blk_part_imp, MDOC_PARSED }, /* D1 */ |
{ blk_part_imp, MDOC_PARSED }, /* D1 */ |
{ blk_part_imp, MDOC_PARSED }, /* Dl */ |
{ blk_part_imp, MDOC_PARSED }, /* Dl */ |
Line 228 mdoc_macroend(struct mdoc *m) |
|
Line 228 mdoc_macroend(struct mdoc *m) |
|
static enum mdoct |
static enum mdoct |
lookup(enum mdoct from, const char *p) |
lookup(enum mdoct from, const char *p) |
{ |
{ |
/* FIXME: make -diag lists be un-PARSED. */ |
|
|
|
if ( ! (MDOC_PARSED & mdoc_macros[from].flags)) |
if ( ! (MDOC_PARSED & mdoc_macros[from].flags)) |
return(MDOC_MAX); |
return(MDOC_MAX); |
Line 600 dword(struct mdoc *m, int line, |
|
Line 599 dword(struct mdoc *m, int line, |
|
|
|
if (DELIM_OPEN == d) |
if (DELIM_OPEN == d) |
m->last->flags |= MDOC_DELIMO; |
m->last->flags |= MDOC_DELIMO; |
else if (DELIM_CLOSE == d) |
|
|
/* |
|
* Closing delimiters only suppress the preceding space |
|
* when they follow something, not when they start a new |
|
* block or element, and not when they follow `No'. |
|
* |
|
* XXX Explicitly special-casing MDOC_No here feels |
|
* like a layering violation. Find a better way |
|
* and solve this in the code related to `No'! |
|
*/ |
|
|
|
else if (DELIM_CLOSE == d && m->last->prev && |
|
m->last->prev->tok != MDOC_No) |
m->last->flags |= MDOC_DELIMC; |
m->last->flags |= MDOC_DELIMC; |
|
|
return(1); |
return(1); |
Line 631 append_delims(struct mdoc *m, int line, int *pos, char |
|
Line 642 append_delims(struct mdoc *m, int line, int *pos, char |
|
* If we encounter end-of-sentence symbols, then trigger |
* If we encounter end-of-sentence symbols, then trigger |
* the double-space. |
* the double-space. |
* |
* |
* XXX: it's easy to allow this to propogate outward to |
* XXX: it's easy to allow this to propagate outward to |
* the last symbol, such that `. )' will cause the |
* the last symbol, such that `. )' will cause the |
* correct double-spacing. However, (1) groff isn't |
* correct double-spacing. However, (1) groff isn't |
* smart enough to do this and (2) it would require |
* smart enough to do this and (2) it would require |
* knowing which symbols break this behaviour, for |
* knowing which symbols break this behaviour, for |
* example, `. ;' shouldn't propogate the double-space. |
* example, `. ;' shouldn't propagate the double-space. |
*/ |
*/ |
if (mandoc_eos(p, strlen(p), 0)) |
if (mandoc_eos(p, strlen(p), 0)) |
m->last->flags |= MDOC_EOS; |
m->last->flags |= MDOC_EOS; |
Line 727 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 738 blk_exp_close(MACRO_PROT_ARGS) |
|
if (later && |
if (later && |
MDOC_EXPLICIT & mdoc_macros[later->tok].flags) |
MDOC_EXPLICIT & mdoc_macros[later->tok].flags) |
continue; |
continue; |
if (MDOC_CALLABLE & mdoc_macros[n->tok].flags) |
if (MDOC_It != n->tok) |
later = n; |
later = n; |
} |
} |
|
|
Line 972 in_line(MACRO_PROT_ARGS) |
|
Line 983 in_line(MACRO_PROT_ARGS) |
|
static int |
static int |
blk_full(MACRO_PROT_ARGS) |
blk_full(MACRO_PROT_ARGS) |
{ |
{ |
int la, nl; |
int la, nl, nparsed; |
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 *body; /* save of body macro */ |
struct mdoc_node *body; /* save of body macro */ |
Line 995 blk_full(MACRO_PROT_ARGS) |
|
Line 1006 blk_full(MACRO_PROT_ARGS) |
|
} |
} |
|
|
/* |
/* |
* This routine accomodates implicitly- and explicitly-scoped |
* This routine accommodates implicitly- and explicitly-scoped |
* macro openings. Implicit ones first close out prior scope |
* macro openings. Implicit ones first close out prior scope |
* (seen above). Delay opening the head until necessary to |
* (seen above). Delay opening the head until necessary to |
* allow leading punctuation to print. Special consideration |
* allow leading punctuation to print. Special consideration |
Line 1027 blk_full(MACRO_PROT_ARGS) |
|
Line 1038 blk_full(MACRO_PROT_ARGS) |
|
head = body = NULL; |
head = body = NULL; |
|
|
/* |
/* |
|
* Exception: Heads of `It' macros in `-diag' lists are not |
|
* parsed, even though `It' macros in general are parsed. |
|
*/ |
|
nparsed = MDOC_It == tok && |
|
MDOC_Bl == m->last->parent->tok && |
|
LIST_diag == m->last->parent->norm->Bl.type; |
|
|
|
/* |
* The `Nd' macro has all arguments in its body: it's a hybrid |
* The `Nd' macro has all arguments in its body: it's a hybrid |
* of block partial-explicit and full-implicit. Stupid. |
* of block partial-explicit and full-implicit. Stupid. |
*/ |
*/ |
Line 1134 blk_full(MACRO_PROT_ARGS) |
|
Line 1153 blk_full(MACRO_PROT_ARGS) |
|
continue; |
continue; |
} |
} |
|
|
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p); |
ntok = nparsed || ARGS_QWORD == ac ? |
|
MDOC_MAX : lookup(tok, p); |
|
|
if (MDOC_MAX == ntok) { |
if (MDOC_MAX == ntok) { |
if ( ! dword(m, line, la, p, DELIM_MAX)) |
if ( ! dword(m, line, la, p, DELIM_MAX)) |
Line 1292 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1312 blk_part_imp(MACRO_PROT_ARGS) |
|
if (mandoc_eos(n->string, strlen(n->string), 1)) |
if (mandoc_eos(n->string, strlen(n->string), 1)) |
n->flags |= MDOC_EOS; |
n->flags |= MDOC_EOS; |
|
|
/* Up-propogate the end-of-space flag. */ |
/* Up-propagate the end-of-space flag. */ |
|
|
if (n && (MDOC_EOS & n->flags)) { |
if (n && (MDOC_EOS & n->flags)) { |
body->flags |= MDOC_EOS; |
body->flags |= MDOC_EOS; |
Line 1339 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1359 blk_part_imp(MACRO_PROT_ARGS) |
|
if (n && ! rew_sub(MDOC_BLOCK, m, tok, line, ppos)) |
if (n && ! rew_sub(MDOC_BLOCK, m, tok, line, ppos)) |
return(0); |
return(0); |
|
|
|
/* Move trailing .Ns out of scope. */ |
|
|
|
for (n = body->child; n && n->next; n = n->next) |
|
/* Do nothing. */ ; |
|
if (n && MDOC_Ns == n->tok) |
|
mdoc_node_relink(m, n); |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 1431 blk_part_exp(MACRO_PROT_ARGS) |
|
Line 1458 blk_part_exp(MACRO_PROT_ARGS) |
|
|
|
/* Clean-up to leave in a consistent state. */ |
/* Clean-up to leave in a consistent state. */ |
|
|
if (NULL == head) { |
if (NULL == head) |
if ( ! mdoc_head_alloc(m, line, ppos, tok)) |
if ( ! mdoc_head_alloc(m, line, ppos, tok)) |
return(0); |
return(0); |
head = m->last; |
|
} |
|
|
|
if (NULL == body) { |
if (NULL == body) { |
if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) |
if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) |
return(0); |
return(0); |
if ( ! mdoc_body_alloc(m, line, ppos, tok)) |
if ( ! mdoc_body_alloc(m, line, ppos, tok)) |
return(0); |
return(0); |
body = m->last; |
|
} |
} |
|
|
/* Standard appending of delimiters. */ |
/* Standard appending of delimiters. */ |
Line 1559 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1583 in_line_argn(MACRO_PROT_ARGS) |
|
return(0); |
return(0); |
flushed = 1; |
flushed = 1; |
} |
} |
|
|
/* |
|
* XXX: this is a hack to work around groff's ugliness |
|
* as regards `Xr' and extraneous arguments. It should |
|
* ideally be deprecated behaviour, but because this is |
|
* code is no here, it's unlikely to be removed. |
|
*/ |
|
|
|
#ifdef __OpenBSD__ |
|
if (MDOC_Xr == tok && j == maxargs) { |
|
if ( ! mdoc_elem_alloc(m, line, la, MDOC_Ns, NULL)) |
|
return(0); |
|
if ( ! rew_elem(m, MDOC_Ns)) |
|
return(0); |
|
} |
|
#endif |
|
|
|
if ( ! dword(m, line, la, p, DELIM_MAX)) |
if ( ! dword(m, line, la, p, DELIM_MAX)) |
return(0); |
return(0); |