-/* $Id: mdoc.c,v 1.226 2014/10/16 01:11:20 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.231 2014/11/28 03:14:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
static void mdoc_alloc1(struct mdoc *);
static struct mdoc_node *node_alloc(struct mdoc *, int, int,
enum mdoct, enum mdoc_type);
-static int node_append(struct mdoc *,
- struct mdoc_node *);
+static void node_append(struct mdoc *, struct mdoc_node *);
static int mdoc_ptext(struct mdoc *, int, char *, int);
static int mdoc_pmacro(struct mdoc *, int, char *, int);
n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN);
n->eqn = ep;
-
- if ( ! node_append(mdoc, n))
- return(0);
-
+ if (ep->ln > mdoc->last->line)
+ n->flags |= MDOC_LINE;
+ node_append(mdoc, n);
mdoc->next = MDOC_NEXT_SIBLING;
return(1);
}
n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, MDOC_TBL);
n->span = sp;
-
- if ( ! node_append(mdoc, n))
- return(0);
-
+ node_append(mdoc, n);
mdoc->next = MDOC_NEXT_SIBLING;
return(1);
}
mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int offs)
{
- mdoc->flags |= MDOC_NEWLINE;
+ if (mdoc->last->type != MDOC_EQN || ln > mdoc->last->line)
+ mdoc->flags |= MDOC_NEWLINE;
/*
* Let the roff nS register switch SYNOPSIS mode early,
}
-static int
+static void
node_append(struct mdoc *mdoc, struct mdoc_node *p)
{
break;
}
- if ( ! mdoc_valid_pre(mdoc, p))
- return(0);
+ mdoc_valid_pre(mdoc, p);
switch (p->type) {
case MDOC_HEAD:
case MDOC_TBL:
/* FALLTHROUGH */
case MDOC_TEXT:
- if ( ! mdoc_valid_post(mdoc))
- return(0);
+ mdoc_valid_post(mdoc);
break;
default:
break;
}
-
- return(1);
}
static struct mdoc_node *
return(p);
}
-int
+void
mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
{
struct mdoc_node *p;
p = node_alloc(mdoc, line, pos, tok, MDOC_TAIL);
- if ( ! node_append(mdoc, p))
- return(0);
+ node_append(mdoc, p);
mdoc->next = MDOC_NEXT_CHILD;
- return(1);
}
-int
+struct mdoc_node *
mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
{
struct mdoc_node *p;
assert(mdoc->first);
assert(mdoc->last);
-
p = node_alloc(mdoc, line, pos, tok, MDOC_HEAD);
- if ( ! node_append(mdoc, p))
- return(0);
+ node_append(mdoc, p);
mdoc->next = MDOC_NEXT_CHILD;
- return(1);
+ return(p);
}
-int
+struct mdoc_node *
mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
{
struct mdoc_node *p;
p = node_alloc(mdoc, line, pos, tok, MDOC_BODY);
- if ( ! node_append(mdoc, p))
- return(0);
+ node_append(mdoc, p);
mdoc->next = MDOC_NEXT_CHILD;
- return(1);
+ return(p);
}
-int
+void
mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok,
struct mdoc_node *body, enum mdoc_endbody end)
{
p->pending = body;
p->norm = body->norm;
p->end = end;
- if ( ! node_append(mdoc, p))
- return(0);
+ node_append(mdoc, p);
mdoc->next = MDOC_NEXT_SIBLING;
- return(1);
}
-int
+struct mdoc_node *
mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
enum mdoct tok, struct mdoc_arg *args)
{
default:
break;
}
-
- if ( ! node_append(mdoc, p))
- return(0);
+ node_append(mdoc, p);
mdoc->next = MDOC_NEXT_CHILD;
- return(1);
+ return(p);
}
-int
+void
mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos,
enum mdoct tok, struct mdoc_arg *args)
{
default:
break;
}
-
- if ( ! node_append(mdoc, p))
- return(0);
+ node_append(mdoc, p);
mdoc->next = MDOC_NEXT_CHILD;
- return(1);
}
-int
+void
mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, const char *p)
{
struct mdoc_node *n;
n = node_alloc(mdoc, line, pos, MDOC_MAX, MDOC_TEXT);
n->string = roff_strdup(mdoc->roff, p);
-
- if ( ! node_append(mdoc, n))
- return(0);
-
+ node_append(mdoc, n);
mdoc->next = MDOC_NEXT_SIBLING;
- return(1);
}
void
mdoc_node_free(p);
}
-int
+void
mdoc_node_relink(struct mdoc *mdoc, struct mdoc_node *p)
{
mdoc_node_unlink(mdoc, p);
- return(node_append(mdoc, p));
+ node_append(mdoc, p);
}
/*
mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
line, (int)(ws-buf), NULL);
- if ('\0' == buf[offs] && ! (MDOC_LITERAL & mdoc->flags)) {
+ if (buf[offs] == '\0' && ! (mdoc->flags & MDOC_LITERAL)) {
mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse,
line, (int)(c - buf), NULL);
* blank lines aren't allowed, but enough manuals assume this
* behaviour that we want to work around it.
*/
- if ( ! mdoc_elem_alloc(mdoc, line, offs, MDOC_sp, NULL))
- return(0);
-
+ mdoc_elem_alloc(mdoc, line, offs, MDOC_sp, NULL);
mdoc->next = MDOC_NEXT_SIBLING;
-
- return(mdoc_valid_post(mdoc));
+ mdoc_valid_post(mdoc);
+ return(1);
}
- if ( ! mdoc_word_alloc(mdoc, line, offs, buf+offs))
- return(0);
+ mdoc_word_alloc(mdoc, line, offs, buf+offs);
- if (MDOC_LITERAL & mdoc->flags)
+ if (mdoc->flags & MDOC_LITERAL)
return(1);
/*
static int
mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
{
+ struct mdoc_node *n;
+ const char *cp;
enum mdoct tok;
int i, sv;
char mac[5];
- struct mdoc_node *n;
sv = offs;
/*
* Copy the first word into a nil-terminated buffer.
- * Stop copying when a tab, space, or eoln is encountered.
+ * Stop when a space, tab, escape, or eoln is encountered.
*/
i = 0;
- while (i < 4 && '\0' != buf[offs] && ' ' != buf[offs] &&
- '\t' != buf[offs])
+ while (i < 4 && strchr(" \t\\", buf[offs]) == NULL)
mac[i++] = buf[offs++];
mac[i] = '\0';
tok = (i > 1 && i < 4) ? mdoc_hash_find(mac) : MDOC_MAX;
- if (MDOC_MAX == tok) {
+ if (tok == MDOC_MAX) {
mandoc_msg(MANDOCERR_MACRO, mdoc->parse,
ln, sv, buf + sv - 1);
return(1);
}
- /* Disregard the first trailing tab, if applicable. */
+ /* Skip a leading escape sequence or tab. */
- if ('\t' == buf[offs])
+ switch (buf[offs]) {
+ case '\\':
+ cp = buf + offs + 1;
+ mandoc_escape(&cp, NULL, NULL);
+ offs = cp - buf;
+ break;
+ case '\t':
offs++;
+ break;
+ default:
+ break;
+ }
/* Jump to the next non-whitespace word. */