aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--html.h4
-rw-r--r--man_html.c26
-rw-r--r--man_term.c14
-rw-r--r--mandoc_headers.316
-rw-r--r--mdoc_html.c26
-rw-r--r--mdoc_term.c10
-rw-r--r--roff_html.c48
-rw-r--r--roff_term.c52
-rw-r--r--term.h12
10 files changed, 152 insertions, 62 deletions
diff --git a/Makefile b/Makefile
index 1e204500..decfe75f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.509 2017/04/29 12:45:41 schwarze Exp $
+# $Id: Makefile,v 1.510 2017/05/04 22:16:09 schwarze Exp $
#
# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
# Copyright (c) 2011, 2013-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 02d5c57d..7cb6f609 100644
--- a/html.h
+++ b/html.h
@@ -1,4 +1,4 @@
-/* $Id: html.h,v 1.84 2017/03/15 11:29:53 schwarze Exp $ */
+/* $Id: html.h,v 1.85 2017/05/04 22:16:09 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 ef2f282c..d9fc43f2 100644
--- a/man_html.c
+++ b/man_html.c
@@ -1,4 +1,4 @@
-/* $Id: man_html.c,v 1.137 2017/05/04 17:48:28 schwarze Exp $ */
+/* $Id: man_html.c,v 1.138 2017/05/04 22:16:09 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 87579adb..d6ddf762 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.193 2017/05/04 17:48:28 schwarze Exp $ */
+/* $Id: man_term.c,v 1.194 2017/05/04 22:16:09 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 ea51b385..38660bac 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.281 2017/05/04 17:48:29 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.282 2017/05/04 22:16:09 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 12cd0336..327ecea3 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.351 2017/05/04 17:48:29 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.352 2017/05/04 22:16:09 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 fabc117d..2121dde6 100644
--- a/term.h
+++ b/term.h
@@ -1,7 +1,7 @@
-/* $Id: term.h,v 1.118 2015/11/07 14:01:16 schwarze Exp $ */
+/* $Id: term.h,v 1.119 2017/05/04 22:16:09 schwarze Exp $ */
/*
* 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 *);