version 1.253, 2015/10/06 18:32:19 |
version 1.257, 2016/08/20 14:43:50 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012-2016 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 121 mdoc_macro(MACRO_PROT_ARGS) |
|
Line 121 mdoc_macro(MACRO_PROT_ARGS) |
|
{ |
{ |
assert(tok > TOKEN_NONE && tok < MDOC_MAX); |
assert(tok > TOKEN_NONE && tok < MDOC_MAX); |
|
|
if (mdoc->flags & MDOC_PBODY) { |
|
if (tok == MDOC_Dt) { |
|
mandoc_vmsg(MANDOCERR_DT_LATE, |
|
mdoc->parse, line, ppos, |
|
"Dt %s", buf + *pos); |
|
return; |
|
} |
|
} else if ( ! (mdoc_macros[tok].flags & MDOC_PROLOGUE)) { |
|
if (mdoc->meta.title == NULL) { |
|
mandoc_vmsg(MANDOCERR_DT_NOTITLE, |
|
mdoc->parse, line, ppos, "%s %s", |
|
mdoc_macronames[tok], buf + *pos); |
|
mdoc->meta.title = mandoc_strdup("UNTITLED"); |
|
} |
|
if (NULL == mdoc->meta.vol) |
|
mdoc->meta.vol = mandoc_strdup("LOCAL"); |
|
mdoc->flags |= MDOC_PBODY; |
|
} |
|
(*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf); |
(*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf); |
} |
} |
|
|
Line 182 mdoc_block_alloc(struct roff_man *mdoc, int line, int |
|
Line 164 mdoc_block_alloc(struct roff_man *mdoc, int line, int |
|
|
|
switch (tok) { |
switch (tok) { |
case MDOC_Bd: |
case MDOC_Bd: |
/* FALLTHROUGH */ |
|
case MDOC_Bf: |
case MDOC_Bf: |
/* FALLTHROUGH */ |
|
case MDOC_Bl: |
case MDOC_Bl: |
/* FALLTHROUGH */ |
|
case MDOC_En: |
case MDOC_En: |
/* FALLTHROUGH */ |
|
case MDOC_Rs: |
case MDOC_Rs: |
p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); |
p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); |
break; |
break; |
Line 227 mdoc_node_relink(struct roff_man *mdoc, struct roff_no |
|
Line 205 mdoc_node_relink(struct roff_man *mdoc, struct roff_no |
|
{ |
{ |
|
|
roff_node_unlink(mdoc, p); |
roff_node_unlink(mdoc, p); |
|
p->prev = p->next = NULL; |
roff_node_append(mdoc, p); |
roff_node_append(mdoc, p); |
} |
} |
|
|
Line 240 mdoc_ptext(struct roff_man *mdoc, int line, char *buf, |
|
Line 219 mdoc_ptext(struct roff_man *mdoc, int line, char *buf, |
|
struct roff_node *n; |
struct roff_node *n; |
char *c, *ws, *end; |
char *c, *ws, *end; |
|
|
assert(mdoc->last); |
|
n = mdoc->last; |
n = mdoc->last; |
|
|
/* |
/* |
* Divert directly to list processing if we're encountering a |
* If a column list contains plain text, assume an implicit item |
* columnar ROFFT_BLOCK with or without a prior ROFFT_BLOCK entry |
* macro. This can happen one or more times at the beginning |
* (a ROFFT_BODY means it's already open, in which case we should |
* of such a list, intermixed with non-It mdoc macros and with |
* process within its context in the normal way). |
* nodes generated on the roff level, for example by tbl. |
*/ |
*/ |
|
|
if (n->tok == MDOC_Bl && n->type == ROFFT_BODY && |
if ((n->tok == MDOC_Bl && n->type == ROFFT_BODY && |
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) { |
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) || |
/* `Bl' is open without any children. */ |
(n->parent != NULL && n->parent->tok == MDOC_Bl && |
|
n->parent->norm->Bl.type == LIST_column)) { |
mdoc->flags |= MDOC_FREECOL; |
mdoc->flags |= MDOC_FREECOL; |
mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf); |
mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf); |
return 1; |
return 1; |
} |
} |
|
|
if (n->tok == MDOC_It && n->type == ROFFT_BLOCK && |
|
NULL != n->parent && |
|
MDOC_Bl == n->parent->tok && |
|
LIST_column == n->parent->norm->Bl.type) { |
|
/* `Bl' has block-level `It' children. */ |
|
mdoc->flags |= MDOC_FREECOL; |
|
mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf); |
|
return 1; |
|
} |
|
|
|
/* |
/* |
* Search for the beginning of unescaped trailing whitespace (ws) |
* Search for the beginning of unescaped trailing whitespace (ws) |
* and for the first character not to be output (end). |
* and for the first character not to be output (end). |
Line 323 mdoc_ptext(struct roff_man *mdoc, int line, char *buf, |
|
Line 292 mdoc_ptext(struct roff_man *mdoc, int line, char *buf, |
|
* behaviour that we want to work around it. |
* behaviour that we want to work around it. |
*/ |
*/ |
roff_elem_alloc(mdoc, line, offs, MDOC_sp); |
roff_elem_alloc(mdoc, line, offs, MDOC_sp); |
|
mdoc->last->flags |= MDOC_VALID | MDOC_ENDED; |
mdoc->next = ROFF_NEXT_SIBLING; |
mdoc->next = ROFF_NEXT_SIBLING; |
mdoc_valid_post(mdoc); |
|
return 1; |
return 1; |
} |
} |
|
|
Line 414 mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, |
|
Line 383 mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, |
|
* into macro processing. |
* into macro processing. |
*/ |
*/ |
|
|
if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) { |
n = mdoc->last; |
|
if (n == NULL || tok == MDOC_It || tok == MDOC_El) { |
mdoc_macro(mdoc, tok, ln, sv, &offs, buf); |
mdoc_macro(mdoc, tok, ln, sv, &offs, buf); |
return 1; |
return 1; |
} |
} |
|
|
n = mdoc->last; |
|
assert(mdoc->last); |
|
|
|
/* |
/* |
* If the first macro of a `Bl -column', open an `It' block |
* If a column list contains a non-It macro, assume an implicit |
* context around the parsed macro. |
* item macro. This can happen one or more times at the |
|
* beginning of such a list, intermixed with text lines and |
|
* with nodes generated on the roff level, for example by tbl. |
*/ |
*/ |
|
|
if (n->tok == MDOC_Bl && n->type == ROFFT_BODY && |
if ((n->tok == MDOC_Bl && n->type == ROFFT_BODY && |
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) { |
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) || |
|
(n->parent != NULL && n->parent->tok == MDOC_Bl && |
|
n->parent->norm->Bl.type == LIST_column)) { |
mdoc->flags |= MDOC_FREECOL; |
mdoc->flags |= MDOC_FREECOL; |
mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf); |
mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf); |
return 1; |
return 1; |
} |
} |
|
|
/* |
|
* If we're following a block-level `It' within a `Bl -column' |
|
* context (perhaps opened in the above block or in ptext()), |
|
* then open an `It' block context around the parsed macro. |
|
*/ |
|
|
|
if (n->tok == MDOC_It && n->type == ROFFT_BLOCK && |
|
NULL != n->parent && |
|
MDOC_Bl == n->parent->tok && |
|
LIST_column == n->parent->norm->Bl.type) { |
|
mdoc->flags |= MDOC_FREECOL; |
|
mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf); |
|
return 1; |
|
} |
|
|
|
/* Normal processing of a macro. */ |
/* Normal processing of a macro. */ |
|
|
mdoc_macro(mdoc, tok, ln, sv, &offs, buf); |
mdoc_macro(mdoc, tok, ln, sv, &offs, buf); |
Line 472 mdoc_isdelim(const char *p) |
|
Line 428 mdoc_isdelim(const char *p) |
|
if ('\0' == p[1]) |
if ('\0' == p[1]) |
switch (p[0]) { |
switch (p[0]) { |
case '(': |
case '(': |
/* FALLTHROUGH */ |
|
case '[': |
case '[': |
return DELIM_OPEN; |
return DELIM_OPEN; |
case '|': |
case '|': |
return DELIM_MIDDLE; |
return DELIM_MIDDLE; |
case '.': |
case '.': |
/* FALLTHROUGH */ |
|
case ',': |
case ',': |
/* FALLTHROUGH */ |
|
case ';': |
case ';': |
/* FALLTHROUGH */ |
|
case ':': |
case ':': |
/* FALLTHROUGH */ |
|
case '?': |
case '?': |
/* FALLTHROUGH */ |
|
case '!': |
case '!': |
/* FALLTHROUGH */ |
|
case ')': |
case ')': |
/* FALLTHROUGH */ |
|
case ']': |
case ']': |
return DELIM_CLOSE; |
return DELIM_CLOSE; |
default: |
default: |
Line 506 mdoc_isdelim(const char *p) |
|
Line 454 mdoc_isdelim(const char *p) |
|
return DELIM_MIDDLE; |
return DELIM_MIDDLE; |
|
|
return DELIM_NONE; |
return DELIM_NONE; |
|
} |
|
|
|
void |
|
mdoc_validate(struct roff_man *mdoc) |
|
{ |
|
|
|
mdoc->last = mdoc->first; |
|
mdoc_node_validate(mdoc); |
|
mdoc_state_reset(mdoc); |
} |
} |