source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Start roff formatter modules for HTML and termininal output,
@ 2017-05-04 22:16 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-05-04 22:16 UTC (permalink / raw)
  To: source

Log Message:
-----------
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).

Modified Files:
--------------
    mdocml:
        Makefile
        html.h
        man_html.c
        man_term.c
        mandoc_headers.3
        mdoc_html.c
        mdoc_term.c
        term.h

Added Files:
-----------
    mdocml:
        roff_html.c
        roff_term.c

Revision Data
-------------
Index: mdoc_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_term.c,v
retrieving revision 1.351
retrieving revision 1.352
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.351 -r1.352
--- mdoc_term.c
+++ 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);
--- /dev/null
+++ 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);
+	}
+}
Index: mandoc_headers.3
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc_headers.3,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lmandoc_headers.3 -Lmandoc_headers.3 -u -p -r1.11 -r1.12
--- mandoc_headers.3
+++ 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,7 +482,20 @@ 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
Index: html.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/html.h,v
retrieving revision 1.84
retrieving revision 1.85
diff -Lhtml.h -Lhtml.h -u -p -r1.84 -r1.85
--- html.h
+++ 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 *, ...);
--- /dev/null
+++ 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. */
+}
Index: man_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_term.c,v
retrieving revision 1.193
retrieving revision 1.194
diff -Lman_term.c -Lman_term.c -u -p -r1.193 -r1.194
--- man_term.c
+++ 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;
 	}
 
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_html.c,v
retrieving revision 1.281
retrieving revision 1.282
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.281 -r1.282
--- mdoc_html.c
+++ 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);
 
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/Makefile,v
retrieving revision 1.509
retrieving revision 1.510
diff -LMakefile -LMakefile -u -p -r1.509 -r1.510
--- Makefile
+++ 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 \
Index: man_html.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man_html.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -Lman_html.c -Lman_html.c -u -p -r1.137 -r1.138
--- man_html.c
+++ 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_M
 	{ 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);
 
Index: term.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.h,v
retrieving revision 1.118
retrieving revision 1.119
diff -Lterm.h -Lterm.h -u -p -r1.118 -r1.119
--- term.h
+++ 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,10 +109,9 @@ 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 *);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-04 22:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-04 22:16 mdocml: Start roff formatter modules for HTML and termininal output, schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).