aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--chars.c24
-rw-r--r--libroff.h41
-rw-r--r--mandoc.h17
-rw-r--r--roff.c12
-rw-r--r--tbl.c38
-rw-r--r--tbl_data.c10
-rw-r--r--tbl_layout.c20
-rw-r--r--tbl_opts.c26
8 files changed, 97 insertions, 91 deletions
diff --git a/chars.c b/chars.c
index 43fedd6a..5edf947a 100644
--- a/chars.c
+++ b/chars.c
@@ -1,4 +1,4 @@
-/* $Id: chars.c,v 1.30 2010/09/15 13:10:30 kristaps Exp $ */
+/* $Id: chars.c,v 1.31 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -54,22 +54,22 @@ struct ln {
#include "chars.in"
-struct tbl {
+struct ctab {
enum chars type;
struct ln **htab;
};
static inline int match(const struct ln *,
const char *, size_t, int);
-static const struct ln *find(struct tbl *, const char *, size_t, int);
+static const struct ln *find(struct ctab *, const char *, size_t, int);
void
chars_free(void *arg)
{
- struct tbl *tab;
+ struct ctab *tab;
- tab = (struct tbl *)arg;
+ tab = (struct ctab *)arg;
free(tab->htab);
free(tab);
@@ -79,7 +79,7 @@ chars_free(void *arg)
void *
chars_init(enum chars type)
{
- struct tbl *tab;
+ struct ctab *tab;
struct ln **htab;
struct ln *pp;
int i, hash;
@@ -91,7 +91,7 @@ chars_init(enum chars type)
* (they're in-line re-ordered during lookup).
*/
- tab = malloc(sizeof(struct tbl));
+ tab = malloc(sizeof(struct ctab));
if (NULL == tab) {
perror(NULL);
exit((int)MANDOCLEVEL_SYSERR);
@@ -130,7 +130,7 @@ chars_spec2cp(void *arg, const char *p, size_t sz)
{
const struct ln *ln;
- ln = find((struct tbl *)arg, p, sz, CHARS_CHAR);
+ ln = find((struct ctab *)arg, p, sz, CHARS_CHAR);
if (NULL == ln)
return(-1);
return(ln->unicode);
@@ -145,7 +145,7 @@ chars_res2cp(void *arg, const char *p, size_t sz)
{
const struct ln *ln;
- ln = find((struct tbl *)arg, p, sz, CHARS_STRING);
+ ln = find((struct ctab *)arg, p, sz, CHARS_STRING);
if (NULL == ln)
return(-1);
return(ln->unicode);
@@ -160,7 +160,7 @@ chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz)
{
const struct ln *ln;
- ln = find((struct tbl *)arg, p, sz, CHARS_CHAR);
+ ln = find((struct ctab *)arg, p, sz, CHARS_CHAR);
if (NULL == ln)
return(NULL);
@@ -177,7 +177,7 @@ chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz)
{
const struct ln *ln;
- ln = find((struct tbl *)arg, p, sz, CHARS_STRING);
+ ln = find((struct ctab *)arg, p, sz, CHARS_STRING);
if (NULL == ln)
return(NULL);
@@ -187,7 +187,7 @@ chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz)
static const struct ln *
-find(struct tbl *tab, const char *p, size_t sz, int type)
+find(struct ctab *tab, const char *p, size_t sz, int type)
{
struct ln *pp, *prev;
struct ln **htab;
diff --git a/libroff.h b/libroff.h
index 1c9147b4..70c21398 100644
--- a/libroff.h
+++ b/libroff.h
@@ -1,4 +1,4 @@
-/* $Id: libroff.h,v 1.14 2011/01/01 22:19:15 kristaps Exp $ */
+/* $Id: libroff.h,v 1.15 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -25,46 +25,35 @@ enum tbl_part {
TBL_PART_DATA /* creating data rows */
};
-struct tbl {
+struct tbl_node {
mandocmsg msg; /* status messages */
void *data; /* privdata for messages */
- enum tbl_part part;
- char tab; /* cell-separator */
- char decimal; /* decimal point */
int pos; /* invocation column */
int line; /* invocation line */
- int linesize;
- char delims[2];
- int opts;
-#define TBL_OPT_CENTRE (1 << 0)
-#define TBL_OPT_EXPAND (1 << 1)
-#define TBL_OPT_BOX (1 << 2)
-#define TBL_OPT_DBOX (1 << 3)
-#define TBL_OPT_ALLBOX (1 << 4)
-#define TBL_OPT_NOKEEP (1 << 5)
-#define TBL_OPT_NOSPACE (1 << 6)
+ enum tbl_part part;
+ struct tbl opts;
struct tbl_row *first_row;
struct tbl_row *last_row;
struct tbl_span *first_span;
struct tbl_span *last_span;
struct tbl_head *first_head;
struct tbl_head *last_head;
- struct tbl *next;
+ struct tbl_node *next;
};
#define TBL_MSG(tblp, type, line, col) \
(*(tblp)->msg)((type), (tblp)->data, (line), (col), NULL)
-struct tbl *tbl_alloc(int, int, void *, mandocmsg);
-void tbl_restart(int, int, struct tbl *);
-void tbl_free(struct tbl *);
-void tbl_reset(struct tbl *);
-enum rofferr tbl_read(struct tbl *, int, const char *, int);
-int tbl_option(struct tbl *, int, const char *);
-int tbl_layout(struct tbl *, int, const char *);
-int tbl_data(struct tbl *, int, const char *);
-const struct tbl_span *tbl_span(const struct tbl *);
-void tbl_end(struct tbl *);
+struct tbl_node *tbl_alloc(int, int, void *, mandocmsg);
+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);
+int tbl_option(struct tbl_node *, int, const char *);
+int tbl_layout(struct tbl_node *, int, const char *);
+int tbl_data(struct tbl_node *, int, const char *);
+const struct tbl_span *tbl_span(const struct tbl_node *);
+void tbl_end(struct tbl_node *);
__END_DECLS
diff --git a/mandoc.h b/mandoc.h
index 66c3afb1..789e9b60 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.42 2011/01/01 22:27:08 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.43 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -145,6 +145,21 @@ enum mandocerr {
MANDOCERR_MAX
};
+struct tbl {
+ char tab; /* cell-separator */
+ char decimal; /* decimal point */
+ int linesize;
+ char delims[2];
+ int opts;
+#define TBL_OPT_CENTRE (1 << 0)
+#define TBL_OPT_EXPAND (1 << 1)
+#define TBL_OPT_BOX (1 << 2)
+#define TBL_OPT_DBOX (1 << 3)
+#define TBL_OPT_ALLBOX (1 << 4)
+#define TBL_OPT_NOKEEP (1 << 5)
+#define TBL_OPT_NOSPACE (1 << 6)
+};
+
enum tbl_headt {
TBL_HEAD_DATA, /* plug in data from tbl_dat */
TBL_HEAD_VERT, /* vertical spacer */
diff --git a/roff.c b/roff.c
index 8ea194e7..65989cd1 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.117 2011/01/01 16:18:39 kristaps Exp $ */
+/* $Id: roff.c,v 1.118 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -86,9 +86,9 @@ struct roff {
struct regset *regs; /* read/writable registers */
struct roffstr *first_string; /* user-defined strings & macros */
const char *current_string; /* value of last called user macro */
- struct tbl *first_tbl; /* first table parsed */
- struct tbl *last_tbl; /* last table parsed */
- struct tbl *tbl; /* current table being parsed */
+ struct tbl_node *first_tbl; /* first table parsed */
+ struct tbl_node *last_tbl; /* last table parsed */
+ struct tbl_node *tbl; /* current table being parsed */
};
struct roffnode {
@@ -301,7 +301,7 @@ roffnode_push(struct roff *r, enum rofft tok, const char *name,
static void
roff_free1(struct roff *r)
{
- struct tbl *t;
+ struct tbl_node *t;
while (r->first_tbl) {
t = r->first_tbl;
@@ -1152,7 +1152,7 @@ roff_T_(ROFF_ARGS)
static enum rofferr
roff_TS(ROFF_ARGS)
{
- struct tbl *t;
+ struct tbl_node *t;
if (r->tbl) {
(*r->msg)(MANDOCERR_SCOPEBROKEN, r->data, ln, ppos, NULL);
diff --git a/tbl.c b/tbl.c
index 878c394c..d881e0a8 100644
--- a/tbl.c
+++ b/tbl.c
@@ -1,4 +1,4 @@
-/* $Id: tbl.c,v 1.16 2011/01/01 23:00:46 kristaps Exp $ */
+/* $Id: tbl.c,v 1.17 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -25,14 +25,14 @@
#include "libmandoc.h"
#include "libroff.h"
-static void tbl_calc(struct tbl *);
-static void tbl_calc_data(struct tbl *, struct tbl_dat *);
+static void tbl_calc(struct tbl_node *);
+static void tbl_calc_data(struct tbl_node *, struct tbl_dat *);
static void tbl_calc_data_literal(struct tbl_dat *);
-static void tbl_calc_data_number(struct tbl *, struct tbl_dat *);
+static void tbl_calc_data_number(struct tbl_node *, struct tbl_dat *);
static void tbl_calc_data_spanner(struct tbl_dat *);
enum rofferr
-tbl_read(struct tbl *tbl, int ln, const char *p, int offs)
+tbl_read(struct tbl_node *tbl, int ln, const char *p, int offs)
{
int len;
const char *cp;
@@ -69,25 +69,25 @@ tbl_read(struct tbl *tbl, int ln, const char *p, int offs)
return(tbl_data(tbl, ln, p) ? ROFF_TBL : ROFF_IGN);
}
-struct tbl *
+struct tbl_node *
tbl_alloc(int pos, int line, void *data, const mandocmsg msg)
{
- struct tbl *p;
+ struct tbl_node *p;
- p = mandoc_calloc(1, sizeof(struct tbl));
+ p = mandoc_calloc(1, sizeof(struct tbl_node));
p->line = line;
p->pos = pos;
p->data = data;
p->msg = msg;
p->part = TBL_PART_OPTS;
- p->tab = '\t';
- p->linesize = 12;
- p->decimal = '.';
+ p->opts.tab = '\t';
+ p->opts.linesize = 12;
+ p->opts.decimal = '.';
return(p);
}
void
-tbl_free(struct tbl *p)
+tbl_free(struct tbl_node *p)
{
struct tbl_row *rp;
struct tbl_cell *cp;
@@ -126,7 +126,7 @@ tbl_free(struct tbl *p)
}
void
-tbl_restart(int line, int pos, struct tbl *tbl)
+tbl_restart(int line, int pos, struct tbl_node *tbl)
{
tbl->part = TBL_PART_LAYOUT;
@@ -138,7 +138,7 @@ tbl_restart(int line, int pos, struct tbl *tbl)
}
const struct tbl_span *
-tbl_span(const struct tbl *tbl)
+tbl_span(const struct tbl_node *tbl)
{
assert(tbl);
@@ -146,7 +146,7 @@ tbl_span(const struct tbl *tbl)
}
void
-tbl_end(struct tbl *tbl)
+tbl_end(struct tbl_node *tbl)
{
if (NULL == tbl->first_span || NULL == tbl->first_span->first)
@@ -156,7 +156,7 @@ tbl_end(struct tbl *tbl)
}
static void
-tbl_calc(struct tbl *tbl)
+tbl_calc(struct tbl_node *tbl)
{
struct tbl_span *sp;
struct tbl_dat *dp;
@@ -193,7 +193,7 @@ tbl_calc(struct tbl *tbl)
}
static void
-tbl_calc_data(struct tbl *tbl, struct tbl_dat *data)
+tbl_calc_data(struct tbl_node *tbl, struct tbl_dat *data)
{
/*
@@ -237,7 +237,7 @@ tbl_calc_data_spanner(struct tbl_dat *data)
}
static void
-tbl_calc_data_number(struct tbl *tbl, struct tbl_dat *data)
+tbl_calc_data_number(struct tbl_node *tbl, struct tbl_dat *data)
{
int sz, d;
char *dp, pnt;
@@ -255,7 +255,7 @@ tbl_calc_data_number(struct tbl *tbl, struct tbl_dat *data)
assert(data->string);
sz = (int)strlen(data->string);
- pnt = tbl->decimal;
+ pnt = tbl->opts.decimal;
if (NULL == (dp = strchr(data->string, pnt)))
d = sz + 1;
diff --git a/tbl_data.c b/tbl_data.c
index cc264eb4..560c7bf8 100644
--- a/tbl_data.c
+++ b/tbl_data.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_data.c,v 1.7 2011/01/01 22:27:08 kristaps Exp $ */
+/* $Id: tbl_data.c,v 1.8 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -24,11 +24,11 @@
#include "libmandoc.h"
#include "libroff.h"
-static void data(struct tbl *, struct tbl_span *,
+static void data(struct tbl_node *, struct tbl_span *,
int, const char *, int *);
void
-data(struct tbl *tbl, struct tbl_span *dp,
+data(struct tbl_node *tbl, struct tbl_span *dp,
int ln, const char *p, int *pos)
{
struct tbl_dat *dat;
@@ -62,7 +62,7 @@ data(struct tbl *tbl, struct tbl_span *dp,
dp->last = dp->first = dat;
sv = *pos;
- while (p[*pos] && p[*pos] != tbl->tab)
+ while (p[*pos] && p[*pos] != tbl->opts.tab)
(*pos)++;
dat->string = mandoc_malloc(*pos - sv + 1);
@@ -85,7 +85,7 @@ data(struct tbl *tbl, struct tbl_span *dp,
}
int
-tbl_data(struct tbl *tbl, int ln, const char *p)
+tbl_data(struct tbl_node *tbl, int ln, const char *p)
{
struct tbl_span *dp;
struct tbl_row *rp;
diff --git a/tbl_layout.c b/tbl_layout.c
index 05018f3e..9829c9eb 100644
--- a/tbl_layout.c
+++ b/tbl_layout.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_layout.c,v 1.5 2011/01/01 22:19:15 kristaps Exp $ */
+/* $Id: tbl_layout.c,v 1.6 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -45,18 +45,18 @@ static const struct tbl_phrase keys[KEYS_MAX] = {
{ '|', TBL_CELL_VERT }
};
-static int mods(struct tbl *, struct tbl_cell *,
+static int mods(struct tbl_node *, struct tbl_cell *,
int, const char *, int *);
-static int cell(struct tbl *, struct tbl_row *,
+static int cell(struct tbl_node *, struct tbl_row *,
int, const char *, int *);
-static void row(struct tbl *, int, const char *, int *);
-static struct tbl_cell *cell_alloc(struct tbl *,
+static void row(struct tbl_node *, int, const char *, int *);
+static struct tbl_cell *cell_alloc(struct tbl_node *,
struct tbl_row *, enum tbl_cellt);
static void head_adjust(const struct tbl_cell *,
struct tbl_head *);
static int
-mods(struct tbl *tbl, struct tbl_cell *cp,
+mods(struct tbl_node *tbl, struct tbl_cell *cp,
int ln, const char *p, int *pos)
{
char buf[5];
@@ -154,7 +154,7 @@ mod:
}
static int
-cell(struct tbl *tbl, struct tbl_row *rp,
+cell(struct tbl_node *tbl, struct tbl_row *rp,
int ln, const char *p, int *pos)
{
int i;
@@ -197,7 +197,7 @@ cell(struct tbl *tbl, struct tbl_row *rp,
static void
-row(struct tbl *tbl, int ln, const char *p, int *pos)
+row(struct tbl_node *tbl, int ln, const char *p, int *pos)
{
struct tbl_row *rp;
@@ -248,7 +248,7 @@ cell:
}
int
-tbl_layout(struct tbl *tbl, int ln, const char *p)
+tbl_layout(struct tbl_node *tbl, int ln, const char *p)
{
int pos;
@@ -260,7 +260,7 @@ tbl_layout(struct tbl *tbl, int ln, const char *p)
}
static struct tbl_cell *
-cell_alloc(struct tbl *tbl, struct tbl_row *rp, enum tbl_cellt pos)
+cell_alloc(struct tbl_node *tbl, struct tbl_row *rp, enum tbl_cellt pos)
{
struct tbl_cell *p, *pp;
struct tbl_head *h, *hp;
diff --git a/tbl_opts.c b/tbl_opts.c
index 91fd0ce5..8500b74d 100644
--- a/tbl_opts.c
+++ b/tbl_opts.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_opts.c,v 1.4 2010/12/29 14:38:14 kristaps Exp $ */
+/* $Id: tbl_opts.c,v 1.5 2011/01/02 10:10:57 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -71,11 +71,13 @@ static const struct tbl_phrase keys[KEY_MAXKEYS] = {
{ "nospaces", TBL_OPT_NOSPACE, KEY_NOSPACE},
};
-static int arg(struct tbl *, int, const char *, int *, int);
-static void opt(struct tbl *, int, const char *, int *);
+static int arg(struct tbl_node *, int,
+ const char *, int *, int);
+static void opt(struct tbl_node *, int,
+ const char *, int *);
static int
-arg(struct tbl *tbl, int ln, const char *p, int *pos, int key)
+arg(struct tbl_node *tbl, int ln, const char *p, int *pos, int key)
{
int i;
char buf[KEY_MAXNUMSZ];
@@ -100,18 +102,18 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, int key)
switch (key) {
case (KEY_DELIM):
- if ('\0' == (tbl->delims[0] = p[(*pos)++])) {
+ if ('\0' == (tbl->opts.delims[0] = p[(*pos)++])) {
TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);
return(0);
}
- if ('\0' == (tbl->delims[1] = p[(*pos)++])) {
+ if ('\0' == (tbl->opts.delims[1] = p[(*pos)++])) {
TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);
return(0);
}
break;
case (KEY_TAB):
- if ('\0' != (tbl->tab = p[(*pos)++]))
+ if ('\0' != (tbl->opts.tab = p[(*pos)++]))
break;
TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);
@@ -125,14 +127,14 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, int key)
if (i < KEY_MAXNUMSZ) {
buf[i] = '\0';
- tbl->linesize = atoi(buf);
+ tbl->opts.linesize = atoi(buf);
break;
}
(*tbl->msg)(MANDOCERR_TBL, tbl->data, ln, *pos, NULL);
return(0);
case (KEY_DPOINT):
- if ('\0' != (tbl->decimal = p[(*pos)++]))
+ if ('\0' != (tbl->opts.decimal = p[(*pos)++]))
break;
TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);
@@ -152,7 +154,7 @@ arg(struct tbl *tbl, int ln, const char *p, int *pos, int key)
}
static void
-opt(struct tbl *tbl, int ln, const char *p, int *pos)
+opt(struct tbl_node *tbl, int ln, const char *p, int *pos)
{
int i, sv;
char buf[KEY_MAXNAME];
@@ -220,7 +222,7 @@ again: /*
*/
if (keys[i].key)
- tbl->opts |= keys[i].key;
+ tbl->opts.opts |= keys[i].key;
else if ( ! arg(tbl, ln, p, pos, keys[i].ident))
return;
@@ -240,7 +242,7 @@ again: /*
}
int
-tbl_option(struct tbl *tbl, int ln, const char *p)
+tbl_option(struct tbl_node *tbl, int ln, const char *p)
{
int pos;