summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-05-04 22:16:09 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-05-04 22:16:09 +0000
commit9ec7fd0e6d519550b4d3ae0ae9dd5c53d10e6cab (patch)
treeafaaee54c2f56b82235088f352b9382a1117f9d6
parent5fbabdf032b370e99e8685958b6e15eb3b2ff0f7 (diff)
downloadmandoc-9ec7fd0e6d519550b4d3ae0ae9dd5c53d10e6cab.tar.gz
Start roff formatter modules for HTML and termininal output,
used by both the mdoc and man formatters, with the ultimate goal of reducing code duplication between the two macro formatters. Made possible by the parser unification. Add the first formatting function (for the .br request).
-rw-r--r--Makefile4
-rw-r--r--html.h2
-rw-r--r--man_html.c24
-rw-r--r--man_term.c12
-rw-r--r--mandoc_headers.316
-rw-r--r--mdoc_html.c24
-rw-r--r--mdoc_term.c8
-rw-r--r--roff_html.c48
-rw-r--r--roff_term.c52
-rw-r--r--term.h10
10 files changed, 145 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index 95c976c2..1b7ddba4 100644
--- a/Makefile
+++ b/Makefile
@@ -110,6 +110,8 @@ SRCS = att.c \
preconv.c \
read.c \
roff.c \
+ roff_html.c \
+ roff_term.c \
soelim.c \
st.c \
tag.c \
@@ -246,11 +248,13 @@ MANDOC_HTML_OBJS = eqn_html.o \
html.o \
man_html.o \
mdoc_html.o \
+ roff_html.o \
tbl_html.o
MANDOC_TERM_OBJS = eqn_term.o \
man_term.o \
mdoc_term.o \
+ roff_term.o \
term.o \
term_ascii.o \
term_ps.o \
diff --git a/html.h b/html.h
index e228be5d..f7785e2f 100644
--- a/html.h
+++ b/html.h
@@ -116,6 +116,8 @@ struct roff_node;
struct tbl_span;
struct eqn;
+void roff_html_pre(struct html *, const struct roff_node *);
+
void print_gen_decls(struct html *);
void print_gen_head(struct html *);
struct tag *print_otag(struct html *, enum htmltag, const char *, ...);
diff --git a/man_html.c b/man_html.c
index 5f5d65ff..dccd15af 100644
--- a/man_html.c
+++ b/man_html.c
@@ -65,11 +65,11 @@ static int man_SM_pre(MAN_ARGS);
static int man_SS_pre(MAN_ARGS);
static int man_UR_pre(MAN_ARGS);
static int man_alt_pre(MAN_ARGS);
-static int man_br_pre(MAN_ARGS);
static int man_ign_pre(MAN_ARGS);
static int man_in_pre(MAN_ARGS);
static void man_root_post(MAN_ARGS);
static void man_root_pre(MAN_ARGS);
+static int man_sp_pre(MAN_ARGS);
static const struct htmlman __mans[MAN_MAX - MAN_TH] = {
{ NULL, NULL }, /* TH */
@@ -92,7 +92,7 @@ static const struct htmlman __mans[MAN_MAX - MAN_TH] = {
{ man_I_pre, NULL }, /* I */
{ man_alt_pre, NULL }, /* IR */
{ man_alt_pre, NULL }, /* RI */
- { man_br_pre, NULL }, /* sp */
+ { man_sp_pre, NULL }, /* sp */
{ NULL, NULL }, /* nf */
{ NULL, NULL }, /* fi */
{ NULL, NULL }, /* RE */
@@ -305,13 +305,7 @@ print_man_node(MAN_ARGS)
t = h->tag;
if (n->tok < ROFF_MAX) {
- switch(n->tok) {
- case ROFF_br:
- man_br_pre(man, n, h);
- break;
- default:
- abort();
- }
+ roff_html_pre(h, n);
break;
}
@@ -423,18 +417,14 @@ man_root_post(MAN_ARGS)
static int
-man_br_pre(MAN_ARGS)
+man_sp_pre(MAN_ARGS)
{
struct roffsu su;
SCALE_VS_INIT(&su, 1);
-
- if (MAN_sp == n->tok) {
- if (NULL != (n = n->child))
- if ( ! a2roffsu(n->string, &su, SCALE_VS))
- su.scale = 1.0;
- } else
- su.scale = 0.0;
+ if (NULL != (n = n->child))
+ if ( ! a2roffsu(n->string, &su, SCALE_VS))
+ su.scale = 1.0;
print_otag(h, TAG_DIV, "suh", &su);
diff --git a/man_term.c b/man_term.c
index 891cdfe0..a3d687af 100644
--- a/man_term.c
+++ b/man_term.c
@@ -457,9 +457,7 @@ pre_sp(DECL_ARGS)
}
}
- if (n->tok == ROFF_br)
- len = 0;
- else if (n->child == NULL)
+ if (n->child == NULL)
len = 1;
else {
if ( ! a2roffsu(n->child->string, &su, SCALE_VS))
@@ -987,13 +985,7 @@ print_man_node(DECL_ARGS)
}
if (n->tok < ROFF_MAX) {
- switch (n->tok) {
- case ROFF_br:
- pre_sp(p, mt, n, meta);
- break;
- default:
- abort();
- }
+ roff_term_pre(p, n);
return;
}
diff --git a/mandoc_headers.3 b/mandoc_headers.3
index 96100f21..ecb730f2 100644
--- a/mandoc_headers.3
+++ b/mandoc_headers.3
@@ -437,6 +437,7 @@ Provides
.Vt enum termtype ,
.Vt struct termp_tbl ,
.Vt struct termp ,
+.Fn roff_term_pre ,
and many terminal formatting functions.
.Pp
Uses the opaque type
@@ -451,6 +452,8 @@ from
.Pa mandoc.h
and
.Vt struct roff_meta
+and
+.Vt struct roff_node
from
.Pa roff.h
as opaque types for function prototypes.
@@ -479,8 +482,21 @@ Provides
.Vt struct tagq ,
.Vt struct htmlpair ,
.Vt struct html ,
+.Fn roff_html_pre ,
and many HTML formatting functions.
.Pp
+Uses
+.Vt struct tbl_span
+and
+.Vt struct eqn
+from
+.Pa mandoc.h
+and
+.Vt struct roff_node
+from
+.Pa roff.h
+as opaque types for function prototypes.
+.Pp
When this header is included, the same file should not include
.Pa term.h
or
diff --git a/mdoc_html.c b/mdoc_html.c
index f4fc9699..e8606abb 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -394,13 +394,7 @@ print_mdoc_node(MDOC_ARGS)
}
assert(h->tblt == NULL);
if (n->tok < ROFF_MAX) {
- switch(n->tok) {
- case ROFF_br:
- mdoc_sp_pre(meta, n, h);
- break;
- default:
- abort();
- }
+ roff_html_pre(h, n);
break;
}
assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
@@ -1337,16 +1331,12 @@ mdoc_sp_pre(MDOC_ARGS)
struct roffsu su;
SCALE_VS_INIT(&su, 1);
-
- if (MDOC_sp == n->tok) {
- if (NULL != (n = n->child)) {
- if ( ! a2roffsu(n->string, &su, SCALE_VS))
- su.scale = 1.0;
- else if (su.scale < 0.0)
- su.scale = 0.0;
- }
- } else
- su.scale = 0.0;
+ if (NULL != (n = n->child)) {
+ if ( ! a2roffsu(n->string, &su, SCALE_VS))
+ su.scale = 1.0;
+ else if (su.scale < 0.0)
+ su.scale = 0.0;
+ }
print_otag(h, TAG_DIV, "suh", &su);
diff --git a/mdoc_term.c b/mdoc_term.c
index 849fc894..503ce71f 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -365,13 +365,7 @@ print_mdoc_node(DECL_ARGS)
break;
default:
if (n->tok < ROFF_MAX) {
- switch (n->tok) {
- case ROFF_br:
- termp_sp_pre(p, &npair, meta, n);
- break;
- default:
- abort();
- }
+ roff_term_pre(p, n);
break;
}
assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
diff --git a/roff_html.c b/roff_html.c
new file mode 100644
index 00000000..533fb9b7
--- /dev/null
+++ b/roff_html.c
@@ -0,0 +1,48 @@
+/* $OpenBSD$ */
+/*
+ * Copyright (c) 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
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sys/types.h>
+
+#include <assert.h>
+
+#include "roff.h"
+#include "out.h"
+#include "html.h"
+
+#define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
+
+typedef void (*roff_html_pre_fp)(ROFF_HTML_ARGS);
+
+static void roff_html_pre_br(ROFF_HTML_ARGS);
+
+static const roff_html_pre_fp roff_html_pre_acts[ROFF_MAX] = {
+ roff_html_pre_br, /* br */
+};
+
+
+void
+roff_html_pre(struct html *h, const struct roff_node *n)
+{
+ assert(n->tok < ROFF_MAX);
+ (*roff_html_pre_acts[n->tok])(h, n);
+}
+
+static void
+roff_html_pre_br(ROFF_HTML_ARGS)
+{
+ print_otag(h, TAG_DIV, "");
+ print_text(h, "\\~"); /* So the div isn't empty. */
+}
diff --git a/roff_term.c b/roff_term.c
new file mode 100644
index 00000000..d96d9dd8
--- /dev/null
+++ b/roff_term.c
@@ -0,0 +1,52 @@
+/* $OpenBSD$ */
+/*
+ * Copyright (c) 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
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sys/types.h>
+
+#include <assert.h>
+
+#include "roff.h"
+#include "out.h"
+#include "term.h"
+
+#define ROFF_TERM_ARGS struct termp *p, const struct roff_node *n
+
+typedef void (*roff_term_pre_fp)(ROFF_TERM_ARGS);
+
+static void roff_term_pre_br(ROFF_TERM_ARGS);
+
+static const roff_term_pre_fp roff_term_pre_acts[ROFF_MAX] = {
+ roff_term_pre_br, /* br */
+};
+
+
+void
+roff_term_pre(struct termp *p, const struct roff_node *n)
+{
+ assert(n->tok < ROFF_MAX);
+ (*roff_term_pre_acts[n->tok])(p, n);
+}
+
+static void
+roff_term_pre_br(ROFF_TERM_ARGS)
+{
+ term_newln(p);
+ if (p->flags & TERMP_BRIND) {
+ p->offset = p->rmargin;
+ p->rmargin = p->maxrmargin;
+ p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
+ }
+}
diff --git a/term.h b/term.h
index cc8764cc..b2fbe5b8 100644
--- a/term.h
+++ b/term.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-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
@@ -38,7 +38,10 @@ enum termfont {
#define TERM_MAXMARGIN 100000 /* FIXME */
+struct eqn;
struct roff_meta;
+struct roff_node;
+struct tbl_span;
struct termp;
typedef void (*term_margin)(struct termp *, const struct roff_meta *);
@@ -106,11 +109,10 @@ struct termp {
};
-struct tbl_span;
-struct eqn;
-
const char *ascii_uc2str(int);
+void roff_term_pre(struct termp *, const struct roff_node *);
+
void term_eqn(struct termp *, const struct eqn *);
void term_tbl(struct termp *, const struct tbl_span *);
void term_free(struct termp *);