version 1.215, 2014/06/20 17:24:00 |
version 1.221, 2014/07/30 21:18:24 |
|
|
#include "libmdoc.h" |
#include "libmdoc.h" |
#include "libmandoc.h" |
#include "libmandoc.h" |
|
|
const char *const __mdoc_macronames[MDOC_MAX] = { |
const char *const __mdoc_macronames[MDOC_MAX + 1] = { |
"Ap", "Dd", "Dt", "Os", |
"Ap", "Dd", "Dt", "Os", |
"Sh", "Ss", "Pp", "D1", |
"Sh", "Ss", "Pp", "D1", |
"Dl", "Bd", "Ed", "Bl", |
"Dl", "Bd", "Ed", "Bl", |
Line 66 const char *const __mdoc_macronames[MDOC_MAX] = { |
|
Line 66 const char *const __mdoc_macronames[MDOC_MAX] = { |
|
"Lk", "Mt", "Brq", "Bro", |
"Lk", "Mt", "Brq", "Bro", |
"Brc", "%C", "Es", "En", |
"Brc", "%C", "Es", "En", |
"Dx", "%Q", "br", "sp", |
"Dx", "%Q", "br", "sp", |
"%U", "Ta", "ll", |
"%U", "Ta", "ll", "text", |
}; |
}; |
|
|
const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
Line 104 const struct mdoc_node * |
|
Line 104 const struct mdoc_node * |
|
mdoc_node(const struct mdoc *mdoc) |
mdoc_node(const struct mdoc *mdoc) |
{ |
{ |
|
|
assert( ! (MDOC_HALT & mdoc->flags)); |
|
return(mdoc->first); |
return(mdoc->first); |
} |
} |
|
|
Line 112 const struct mdoc_meta * |
|
Line 111 const struct mdoc_meta * |
|
mdoc_meta(const struct mdoc *mdoc) |
mdoc_meta(const struct mdoc *mdoc) |
{ |
{ |
|
|
assert( ! (MDOC_HALT & mdoc->flags)); |
|
return(&mdoc->meta); |
return(&mdoc->meta); |
} |
} |
|
|
Line 189 mdoc_free(struct mdoc *mdoc) |
|
Line 187 mdoc_free(struct mdoc *mdoc) |
|
*/ |
*/ |
struct mdoc * |
struct mdoc * |
mdoc_alloc(struct roff *roff, struct mparse *parse, |
mdoc_alloc(struct roff *roff, struct mparse *parse, |
char *defos, int quick) |
const char *defos, int quick) |
{ |
{ |
struct mdoc *p; |
struct mdoc *p; |
|
|
Line 205 mdoc_alloc(struct roff *roff, struct mparse *parse, |
|
Line 203 mdoc_alloc(struct roff *roff, struct mparse *parse, |
|
return(p); |
return(p); |
} |
} |
|
|
/* |
|
* Climb back up the parse tree, validating open scopes. Mostly calls |
|
* through to macro_end() in macro.c. |
|
*/ |
|
int |
int |
mdoc_endparse(struct mdoc *mdoc) |
mdoc_endparse(struct mdoc *mdoc) |
{ |
{ |
|
|
assert( ! (MDOC_HALT & mdoc->flags)); |
return(mdoc_macroend(mdoc)); |
if (mdoc_macroend(mdoc)) |
|
return(1); |
|
mdoc->flags |= MDOC_HALT; |
|
return(0); |
|
} |
} |
|
|
int |
int |
Line 225 mdoc_addeqn(struct mdoc *mdoc, const struct eqn *ep) |
|
Line 215 mdoc_addeqn(struct mdoc *mdoc, const struct eqn *ep) |
|
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
|
assert( ! (MDOC_HALT & mdoc->flags)); |
|
|
|
/* No text before an initial macro. */ |
|
|
|
if (SEC_NONE == mdoc->lastnamed) { |
|
mdoc_pmsg(mdoc, ep->ln, ep->pos, MANDOCERR_NOTEXT); |
|
return(1); |
|
} |
|
|
|
n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN); |
n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN); |
n->eqn = ep; |
n->eqn = ep; |
|
|
Line 249 mdoc_addspan(struct mdoc *mdoc, const struct tbl_span |
|
Line 230 mdoc_addspan(struct mdoc *mdoc, const struct tbl_span |
|
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
|
assert( ! (MDOC_HALT & mdoc->flags)); |
|
|
|
/* No text before an initial macro. */ |
|
|
|
if (SEC_NONE == mdoc->lastnamed) { |
|
mdoc_pmsg(mdoc, sp->line, 0, MANDOCERR_NOTEXT); |
|
return(1); |
|
} |
|
|
|
n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, MDOC_TBL); |
n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, MDOC_TBL); |
n->span = sp; |
n->span = sp; |
|
|
|
|
mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int offs) |
mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int offs) |
{ |
{ |
|
|
assert( ! (MDOC_HALT & mdoc->flags)); |
|
|
|
mdoc->flags |= MDOC_NEWLINE; |
mdoc->flags |= MDOC_NEWLINE; |
|
|
/* |
/* |
Line 516 mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, |
|
Line 486 mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MDOC_Bl: |
case MDOC_Bl: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
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 720 mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int |
|
Line 692 mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int |
|
char *c, *ws, *end; |
char *c, *ws, *end; |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
|
/* No text before an initial macro. */ |
|
|
|
if (SEC_NONE == mdoc->lastnamed) { |
|
mdoc_pmsg(mdoc, line, offs, MANDOCERR_NOTEXT); |
|
return(1); |
|
} |
|
|
|
assert(mdoc->last); |
assert(mdoc->last); |
n = mdoc->last; |
n = mdoc->last; |
|
|
Line 795 mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int |
|
Line 760 mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int |
|
*end = '\0'; |
*end = '\0'; |
|
|
if (ws) |
if (ws) |
mdoc_pmsg(mdoc, line, (int)(ws-buf), MANDOCERR_EOLNSPACE); |
mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse, |
|
line, (int)(ws-buf), NULL); |
|
|
if ('\0' == buf[offs] && ! (MDOC_LITERAL & mdoc->flags)) { |
if ('\0' == buf[offs] && ! (MDOC_LITERAL & mdoc->flags)) { |
mdoc_pmsg(mdoc, line, (int)(c-buf), MANDOCERR_NOBLANKLN); |
mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse, |
|
line, (int)(c - buf), NULL); |
|
|
/* |
/* |
* Insert a `sp' in the case of a blank line. Technically, |
* Insert a `sp' in the case of a blank line. Technically, |
Line 848 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
Line 815 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
/* Empty post-control lines are ignored. */ |
/* Empty post-control lines are ignored. */ |
|
|
if ('"' == buf[offs]) { |
if ('"' == buf[offs]) { |
mdoc_pmsg(mdoc, ln, offs, MANDOCERR_BADCOMMENT); |
mandoc_msg(MANDOCERR_COMMENT_BAD, mdoc->parse, |
|
ln, offs, NULL); |
return(1); |
return(1); |
} else if ('\0' == buf[offs]) |
} else if ('\0' == buf[offs]) |
return(1); |
return(1); |
Line 891 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
Line 859 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
*/ |
*/ |
|
|
if ('\0' == buf[offs] && ' ' == buf[offs - 1]) |
if ('\0' == buf[offs] && ' ' == buf[offs - 1]) |
mdoc_pmsg(mdoc, ln, offs - 1, MANDOCERR_EOLNSPACE); |
mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse, |
|
ln, offs - 1, NULL); |
|
|
/* |
/* |
* If an initial macro or a list invocation, divert directly |
* If an initial macro or a list invocation, divert directly |
* into macro processing. |
* into macro processing. |
*/ |
*/ |
|
|
if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) { |
if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) |
if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) |
return(mdoc_macro(mdoc, tok, ln, sv, &offs, buf)); |
goto err; |
|
return(1); |
|
} |
|
|
|
n = mdoc->last; |
n = mdoc->last; |
assert(mdoc->last); |
assert(mdoc->last); |
Line 915 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
Line 881 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
if (MDOC_Bl == n->tok && MDOC_BODY == n->type && |
if (MDOC_Bl == n->tok && MDOC_BODY == n->type && |
LIST_column == n->norm->Bl.type) { |
LIST_column == n->norm->Bl.type) { |
mdoc->flags |= MDOC_FREECOL; |
mdoc->flags |= MDOC_FREECOL; |
if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) |
return(mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)); |
goto err; |
|
return(1); |
|
} |
} |
|
|
/* |
/* |
Line 931 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
Line 895 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
MDOC_Bl == n->parent->tok && |
MDOC_Bl == n->parent->tok && |
LIST_column == n->parent->norm->Bl.type) { |
LIST_column == n->parent->norm->Bl.type) { |
mdoc->flags |= MDOC_FREECOL; |
mdoc->flags |= MDOC_FREECOL; |
if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) |
return(mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)); |
goto err; |
|
return(1); |
|
} |
} |
|
|
/* Normal processing of a macro. */ |
/* Normal processing of a macro. */ |
|
|
if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) |
if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) |
goto err; |
return(0); |
|
|
/* In quick mode (for mandocdb), abort after the NAME section. */ |
/* In quick mode (for mandocdb), abort after the NAME section. */ |
|
|
Line 948 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
Line 910 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int |
|
return(2); |
return(2); |
|
|
return(1); |
return(1); |
|
|
err: /* Error out. */ |
|
|
|
mdoc->flags |= MDOC_HALT; |
|
return(0); |
|
} |
} |
|
|
enum mdelim |
enum mdelim |