-/* $Id: mdoc.c,v 1.249 2015/04/19 14:25:41 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.256 2015/10/30 19:04:16 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
static int mdoc_pmacro(struct roff_man *, int, char *, int);
-void
-mdoc_endparse(struct roff_man *mdoc)
-{
-
- mdoc_macroend(mdoc);
-}
-
/*
* Main parse routine. Parses a single line -- really just hands off to
* the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
else
mdoc->flags &= ~MDOC_SYNOPSIS;
- return(roff_getcontrol(mdoc->roff, buf, &offs) ?
+ return roff_getcontrol(mdoc->roff, buf, &offs) ?
mdoc_pmacro(mdoc, ln, buf, offs) :
- mdoc_ptext(mdoc, ln, buf, offs));
+ mdoc_ptext(mdoc, ln, buf, offs);
}
void
{
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);
}
p->end = end;
roff_node_append(mdoc, p);
mdoc->next = ROFF_NEXT_SIBLING;
- return(p);
+ return p;
}
struct roff_node *
switch (tok) {
case MDOC_Bd:
- /* FALLTHROUGH */
case MDOC_Bf:
- /* FALLTHROUGH */
case MDOC_Bl:
- /* FALLTHROUGH */
case MDOC_En:
- /* FALLTHROUGH */
case MDOC_Rs:
p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
break;
}
roff_node_append(mdoc, p);
mdoc->next = ROFF_NEXT_CHILD;
- return(p);
+ return p;
}
void
{
roff_node_unlink(mdoc, p);
+ p->prev = p->next = NULL;
roff_node_append(mdoc, p);
}
/* `Bl' is open without any children. */
mdoc->flags |= MDOC_FREECOL;
mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf);
- return(1);
+ return 1;
}
if (n->tok == MDOC_It && n->type == ROFFT_BLOCK &&
/* `Bl' has block-level `It' children. */
mdoc->flags |= MDOC_FREECOL;
mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf);
- return(1);
+ return 1;
}
/*
* blank lines aren't allowed, but enough manuals assume this
* behaviour that we want to work around it.
*/
- mdoc_elem_alloc(mdoc, line, offs, MDOC_sp, NULL);
+ roff_elem_alloc(mdoc, line, offs, MDOC_sp);
+ mdoc->last->flags |= MDOC_VALID | MDOC_ENDED;
mdoc->next = ROFF_NEXT_SIBLING;
- mdoc_valid_post(mdoc);
- return(1);
+ return 1;
}
roff_word_alloc(mdoc, line, offs, buf+offs);
if (mdoc->flags & MDOC_LITERAL)
- return(1);
+ return 1;
/*
* End-of-sentence check. If the last character is an unescaped
if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
mdoc->last->flags |= MDOC_EOS;
- return(1);
+ return 1;
}
/*
if (tok == TOKEN_NONE) {
mandoc_msg(MANDOCERR_MACRO, mdoc->parse,
ln, sv, buf + sv - 1);
- return(1);
+ return 1;
}
/* Skip a leading escape sequence or tab. */
if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) {
mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
- return(1);
+ return 1;
}
n = mdoc->last;
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) {
mdoc->flags |= MDOC_FREECOL;
mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
- return(1);
+ return 1;
}
/*
LIST_column == n->parent->norm->Bl.type) {
mdoc->flags |= MDOC_FREECOL;
mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
- return(1);
+ return 1;
}
/* Normal processing of a macro. */
if (mdoc->quick && MDOC_Sh == tok &&
SEC_NAME != mdoc->last->sec)
- return(2);
+ return 2;
- return(1);
+ return 1;
}
enum mdelim
{
if ('\0' == p[0])
- return(DELIM_NONE);
+ return DELIM_NONE;
if ('\0' == p[1])
switch (p[0]) {
case '(':
- /* FALLTHROUGH */
case '[':
- return(DELIM_OPEN);
+ return DELIM_OPEN;
case '|':
- return(DELIM_MIDDLE);
+ return DELIM_MIDDLE;
case '.':
- /* FALLTHROUGH */
case ',':
- /* FALLTHROUGH */
case ';':
- /* FALLTHROUGH */
case ':':
- /* FALLTHROUGH */
case '?':
- /* FALLTHROUGH */
case '!':
- /* FALLTHROUGH */
case ')':
- /* FALLTHROUGH */
case ']':
- return(DELIM_CLOSE);
+ return DELIM_CLOSE;
default:
- return(DELIM_NONE);
+ return DELIM_NONE;
}
if ('\\' != p[0])
- return(DELIM_NONE);
+ return DELIM_NONE;
if (0 == strcmp(p + 1, "."))
- return(DELIM_CLOSE);
+ return DELIM_CLOSE;
if (0 == strcmp(p + 1, "fR|\\fP"))
- return(DELIM_MIDDLE);
+ return DELIM_MIDDLE;
- return(DELIM_NONE);
+ return DELIM_NONE;
}
void
-mdoc_deroff(char **dest, const struct roff_node *n)
+mdoc_validate(struct roff_man *mdoc)
{
- char *cp;
- size_t sz;
-
- if (n->type != ROFFT_TEXT) {
- for (n = n->child; n; n = n->next)
- mdoc_deroff(dest, n);
- return;
- }
-
- /* Skip leading whitespace. */
-
- for (cp = n->string; '\0' != *cp; cp++)
- if (0 == isspace((unsigned char)*cp))
- break;
-
- /* Skip trailing whitespace. */
-
- for (sz = strlen(cp); sz; sz--)
- if (0 == isspace((unsigned char)cp[sz-1]))
- break;
-
- /* Skip empty strings. */
-
- if (0 == sz)
- return;
-
- if (NULL == *dest) {
- *dest = mandoc_strndup(cp, sz);
- return;
- }
- mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
- free(*dest);
- *dest = cp;
+ mdoc->last = mdoc->first;
+ mdoc_node_validate(mdoc);
+ mdoc_state_reset(mdoc);
}