-/* $OpenBSD: libmandoc.h,v 1.54 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: libmandoc.h,v 1.55 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
ROFF_REPARSE, /* re-run main parser on the result */
ROFF_SO, /* include another file */
ROFF_IGN, /* ignore current line */
- ROFF_TBL, /* a table row was successfully parsed */
};
struct buf {
struct mparse;
-struct tbl_span;
struct roff;
struct roff_man;
int roff_getcontrol(const struct roff *,
const char *, int *);
int roff_getformat(const struct roff *);
-
-const struct tbl_span *roff_span(const struct roff *);
-/* $OpenBSD: libroff.h,v 1.19 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: libroff.h,v 1.20 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
void tbl_restart(int, int, struct tbl_node *);
void tbl_free(struct tbl_node *);
void tbl_reset(struct tbl_node *);
-enum rofferr tbl_read(struct tbl_node *, int, const char *, int);
+void tbl_read(struct tbl_node *, int, const char *, int);
void tbl_option(struct tbl_node *, int, const char *, int *);
void tbl_layout(struct tbl_node *, int, const char *, int);
void tbl_data(struct tbl_node *, int, const char *, int);
-int tbl_cdata(struct tbl_node *, int, const char *, int);
+void tbl_cdata(struct tbl_node *, int, const char *, int);
const struct tbl_span *tbl_span(struct tbl_node *);
-int tbl_end(struct tbl_node **);
+int tbl_end(struct tbl_node *);
struct eqn_node *eqn_alloc(struct mparse *);
void eqn_box_free(struct eqn_box *);
void eqn_free(struct eqn_node *);
-/* $OpenBSD: read.c,v 1.162 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.163 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
#include "mdoc.h"
#include "man.h"
#include "libmandoc.h"
-#include "roff_int.h"
#define REPARSE_LIMIT 1000
static int
mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start)
{
- const struct tbl_span *span;
struct buf ln;
const char *save_file;
char *cp;
if (curp->man->macroset == MACROSET_NONE)
choose_parser(curp);
- /*
- * Lastly, push down into the parsers themselves.
- * If libroff returns ROFF_TBL, then add it to the
- * currently open parse. Since we only get here if
- * there does exist data (see tbl_data.c), we're
- * guaranteed that something's been allocated.
- */
-
- if (rr == ROFF_TBL)
- while ((span = roff_span(curp->roff)) != NULL)
- roff_addtbl(curp->man, span);
- else if ((curp->man->macroset == MACROSET_MDOC ?
+ if ((curp->man->macroset == MACROSET_MDOC ?
mdoc_parseln(curp->man, curp->line, ln.buf, of) :
man_parseln(curp->man, curp->line, ln.buf, of)) == 2)
break;
-/* $OpenBSD: roff.c,v 1.192 2017/07/08 15:28:05 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.193 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
static void roffnode_pop(struct roff *);
static void roffnode_push(struct roff *, enum roff_tok,
const char *, int, int);
+static void roff_addtbl(struct roff_man *, struct tbl_node *);
static enum rofferr roff_als(ROFF_ARGS);
static enum rofferr roff_block(ROFF_ARGS);
static enum rofferr roff_block_text(ROFF_ARGS);
return n;
}
-void
-roff_addtbl(struct roff_man *man, const struct tbl_span *tbl)
+static void
+roff_addtbl(struct roff_man *man, struct tbl_node *tbl)
{
struct roff_node *n;
+ const struct tbl_span *span;
if (man->macroset == MACROSET_MAN)
man_breakscope(man, ROFF_TS);
- n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
- n->span = tbl;
- roff_node_append(man, n);
- n->flags |= NODE_VALID | NODE_ENDED;
- man->next = ROFF_NEXT_SIBLING;
+ while ((span = tbl_span(tbl)) != NULL) {
+ n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
+ n->span = span;
+ roff_node_append(man, n);
+ n->flags |= NODE_VALID | NODE_ENDED;
+ man->next = ROFF_NEXT_SIBLING;
+ }
}
void
eqn_read(r->eqn, buf->buf + ppos);
return ROFF_IGN;
}
- if (r->tbl != NULL && ( ! ctl || buf->buf[pos] == '\0'))
- return tbl_read(r->tbl, ln, buf->buf, ppos);
+ if (r->tbl != NULL && (ctl == 0 || buf->buf[pos] == '\0')) {
+ tbl_read(r->tbl, ln, buf->buf, ppos);
+ roff_addtbl(r->man, r->tbl);
+ return ROFF_IGN;
+ }
if ( ! ctl)
return roff_parsetext(r, buf, pos, offs);
pos++;
while (buf->buf[pos] == ' ')
pos++;
- return tbl_read(r->tbl, ln, buf->buf, pos);
+ tbl_read(r->tbl, ln, buf->buf, pos);
+ roff_addtbl(r->man, r->tbl);
+ return ROFF_IGN;
}
/* For now, let high level macros abort .ce mode. */
void
roff_endparse(struct roff *r)
{
-
- if (r->last)
+ if (r->last != NULL)
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
r->last->line, r->last->col,
roff_name[r->last->tok]);
- if (r->eqn) {
+ if (r->eqn != NULL) {
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
r->eqn->node->line, r->eqn->node->pos, "EQ");
eqn_parse(r->eqn);
r->eqn = NULL;
}
- if (r->tbl) {
+ if (r->tbl != NULL) {
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
r->tbl->line, r->tbl->pos, "TS");
- tbl_end(&r->tbl);
+ tbl_end(r->tbl);
+ r->tbl = NULL;
}
}
static enum rofferr
roff_TE(ROFF_ARGS)
{
-
- if (NULL == r->tbl)
+ if (r->tbl == NULL) {
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
ln, ppos, "TE");
- else if ( ! tbl_end(&r->tbl)) {
+ return ROFF_IGN;
+ }
+ if (tbl_end(r->tbl) == 0) {
+ r->tbl = NULL;
free(buf->buf);
buf->buf = mandoc_strdup(".sp");
buf->sz = 4;
return ROFF_REPARSE;
}
+ r->tbl = NULL;
return ROFF_IGN;
}
static enum rofferr
roff_TS(ROFF_ARGS)
{
- struct tbl_node *tbl;
-
- if (r->tbl) {
+ if (r->tbl != NULL) {
mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse,
ln, ppos, "TS breaks TS");
- tbl_end(&r->tbl);
+ tbl_end(r->tbl);
}
-
- tbl = tbl_alloc(ppos, ln, r->parse);
-
+ r->tbl = tbl_alloc(ppos, ln, r->parse);
if (r->last_tbl)
- r->last_tbl->next = tbl;
+ r->last_tbl->next = r->tbl;
else
- r->first_tbl = r->last_tbl = tbl;
-
- r->tbl = r->last_tbl = tbl;
+ r->first_tbl = r->tbl;
+ r->last_tbl = r->tbl;
return ROFF_IGN;
}
/* --- accessors and utility functions ------------------------------------ */
-const struct tbl_span *
-roff_span(const struct roff *r)
-{
-
- return r->tbl ? tbl_span(r->tbl) : NULL;
-}
-
/*
* Duplicate an input string, making the appropriate character
* conversations (as stipulated by `tr') along the way.
-/* $OpenBSD: roff_int.h,v 1.8 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: roff_int.h,v 1.9 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
struct roff_node *roff_block_alloc(struct roff_man *, int, int, int);
struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
-void roff_addtbl(struct roff_man *, const struct tbl_span *);
void roff_node_unlink(struct roff_man *, struct roff_node *);
void roff_node_free(struct roff_node *);
void roff_node_delete(struct roff_man *, struct roff_node *);
-/* $OpenBSD: tbl.c,v 1.22 2017/06/08 18:11:15 schwarze Exp $ */
+/* $OpenBSD: tbl.c,v 1.23 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
#include "libroff.h"
-enum rofferr
+void
tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
{
const char *cp;
if (*cp == ';') {
tbl_option(tbl, ln, p, &pos);
if (p[pos] == '\0')
- return ROFF_IGN;
+ return;
}
}
switch (tbl->part) {
case TBL_PART_LAYOUT:
tbl_layout(tbl, ln, p, pos);
- return ROFF_IGN;
+ break;
case TBL_PART_CDATA:
- return tbl_cdata(tbl, ln, p, pos) ? ROFF_TBL : ROFF_IGN;
+ tbl_cdata(tbl, ln, p, pos);
+ break;
default:
+ tbl_data(tbl, ln, p, pos);
break;
}
-
- tbl_data(tbl, ln, p, pos);
- return ROFF_TBL;
}
struct tbl_node *
}
int
-tbl_end(struct tbl_node **tblp)
+tbl_end(struct tbl_node *tbl)
{
- struct tbl_node *tbl;
struct tbl_span *sp;
- tbl = *tblp;
- *tblp = NULL;
-
if (tbl->part == TBL_PART_CDATA)
mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse,
tbl->line, tbl->pos, "TE");
-/* $OpenBSD: tbl_data.c,v 1.31 2017/07/04 20:59:17 schwarze Exp $ */
+/* $OpenBSD: tbl_data.c,v 1.32 2017/07/08 17:52:42 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
tbl->parse, ln, sv, dat->string);
}
-int
+void
tbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos)
{
struct tbl_dat *dat;
pos++;
while (p[pos] != '\0')
getdata(tbl, tbl->last_span, ln, p, &pos);
- return 1;
+ return;
} else if (p[pos] == '\0') {
tbl->part = TBL_PART_DATA;
- return 1;
+ return;
}
/* Fallthrough: T} is part of a word. */
if (dat->layout->pos == TBL_CELL_DOWN)
mandoc_msg(MANDOCERR_TBLDATA_SPAN, tbl->parse,
ln, pos, dat->string);
-
- return 0;
}
static struct tbl_span *