-/* $Id: man.c,v 1.94 2011/01/01 12:59:17 kristaps Exp $ */
+/* $Id: man.c,v 1.97 2011/01/12 10:43:22 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
const char * const *man_macronames = __man_macronames;
-static struct man_node *man_node_alloc(int, int,
+static struct man_node *man_node_alloc(struct man *, int, int,
enum man_type, enum mant);
static int man_node_append(struct man *,
struct man_node *);
man_node(const struct man *m)
{
- return(MAN_HALT & m->flags ? NULL : m->first);
+ assert( ! (MAN_HALT & m->flags));
+ return(m->first);
}
man_meta(const struct man *m)
{
- return(MAN_HALT & m->flags ? NULL : &m->meta);
+ assert( ! (MAN_HALT & m->flags));
+ return(&m->meta);
}
man_endparse(struct man *m)
{
- if (MAN_HALT & m->flags)
- return(0);
- else if (man_macroend(m))
+ assert( ! (MAN_HALT & m->flags));
+ if (man_macroend(m))
return(1);
m->flags |= MAN_HALT;
return(0);
man_parseln(struct man *m, int ln, char *buf, int offs)
{
- if (MAN_HALT & m->flags)
- return(0);
+ m->flags |= MAN_NEWLINE;
+ assert( ! (MAN_HALT & m->flags));
return(('.' == buf[offs] || '\'' == buf[offs]) ?
man_pmacro(m, ln, buf, offs) :
man_ptext(m, ln, buf, offs));
static struct man_node *
-man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
+man_node_alloc(struct man *m, int line, int pos,
+ enum man_type type, enum mant tok)
{
struct man_node *p;
p->pos = pos;
p->type = type;
p->tok = tok;
+
+ if (MAN_NEWLINE & m->flags)
+ p->flags |= MAN_LINE;
+ m->flags &= ~MAN_NEWLINE;
return(p);
}
{
struct man_node *p;
- p = man_node_alloc(line, pos, MAN_ELEM, tok);
+ p = man_node_alloc(m, line, pos, MAN_ELEM, tok);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
{
struct man_node *p;
- p = man_node_alloc(line, pos, MAN_HEAD, tok);
+ p = man_node_alloc(m, line, pos, MAN_HEAD, tok);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
{
struct man_node *p;
- p = man_node_alloc(line, pos, MAN_BODY, tok);
+ p = man_node_alloc(m, line, pos, MAN_BODY, tok);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
{
struct man_node *p;
- p = man_node_alloc(line, pos, MAN_BLOCK, tok);
+ p = man_node_alloc(m, line, pos, MAN_BLOCK, tok);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
struct man_node *n;
/* FIXME: grab from span */
- n = man_node_alloc(0, 0, MAN_TBL, MAN_MAX);
+ n = man_node_alloc(m, 0, 0, MAN_TBL, MAN_MAX);
+ n->span = span;
if ( ! man_node_append(m, n))
return(0);
len = strlen(word);
- n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
+ n = man_node_alloc(m, line, pos, MAN_TEXT, MAN_MAX);
n->string = mandoc_malloc(len + 1);
sv = strlcpy(n->string, word, len + 1);
man_addspan(struct man *m, const struct tbl_span *sp)
{
+ assert( ! (MAN_HALT & m->flags));
if ( ! man_span_alloc(m, sp))
return(0);
return(man_descope(m, 0, 0));
}
-int
+static int
man_pmacro(struct man *m, int ln, char *buf, int offs)
{
int i, j, ppos;