source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: implement .Ap .Bd .Bo .Bq .D1 .Ic .Lp .Oo .Pf .Po .Ss .Sx .Sy
@ 2011-09-30  0:13 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2011-09-30  0:13 UTC (permalink / raw)
  To: source

Log Message:
-----------
implement .Ap .Bd .Bo .Bq .D1 .Ic .Lp .Oo .Pf .Po .Ss .Sx .Sy .br .sp
implement .Bl -bullet
add more information to the .TH line
escape dots at the beginnings of lines
add trailing newline character at the end of the file
do not misinterpret the ROOT block as .Ap

Modified Files:
--------------
    mdocml:
        mdoc.c
        mdoc_man.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_man.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.2 -r1.3
--- mdoc_man.c
+++ mdoc_man.c
@@ -43,33 +43,40 @@ static	int	  cond_body(DECL_ARGS);
 static	int	  pre_enc(DECL_ARGS);
 static	void	  post_enc(DECL_ARGS);
 static	void	  post_percent(DECL_ARGS);
+static	int	  pre_sect(DECL_ARGS);
+static	void	  post_sect(DECL_ARGS);
 
+static	int	  pre_ap(DECL_ARGS);
+static	int	  pre_bd(DECL_ARGS);
+static	void	  post_bd(DECL_ARGS);
+static	int	  pre_br(DECL_ARGS);
 static	int	  pre_dl(DECL_ARGS);
 static	void	  post_dl(DECL_ARGS);
 static	int	  pre_it(DECL_ARGS);
 static	int	  pre_nm(DECL_ARGS);
 static	void	  post_nm(DECL_ARGS);
 static	int	  pre_ns(DECL_ARGS);
+static	void	  post_pf(DECL_ARGS);
 static	int	  pre_pp(DECL_ARGS);
-static	int	  pre_sh(DECL_ARGS);
-static	void	  post_sh(DECL_ARGS);
+static	int	  pre_sp(DECL_ARGS);
+static	void	  post_sp(DECL_ARGS);
 static	int	  pre_xr(DECL_ARGS);
 
 
-static	const struct manact manacts[MDOC_MAX] = {
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Ap */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Dd */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Dt */
+static	const struct manact manacts[MDOC_MAX + 1] = {
+	{ NULL, pre_ap, NULL, NULL, NULL }, /* Ap */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Dd */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Dt */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Os */
-	{ NULL, pre_sh, post_sh, NULL, NULL }, /* Sh */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Ss */
+	{ NULL, pre_sect, post_sect, ".SH", NULL }, /* Sh */
+	{ NULL, pre_sect, post_sect, ".SS", NULL }, /* Ss */
 	{ NULL, pre_pp, NULL, NULL, NULL }, /* Pp */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _D1 */
+	{ cond_body, pre_dl, post_dl, NULL, NULL }, /* D1 */
 	{ cond_body, pre_dl, post_dl, NULL, NULL }, /* Dl */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Bd */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Ed */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Bl */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _El */
+	{ cond_body, pre_bd, post_bd, NULL, NULL }, /* Bd */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Ed */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Bl */
+	{ NULL, NULL, NULL, NULL, NULL }, /* El */
 	{ NULL, pre_it, NULL, NULL, NULL }, /* _It */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ad */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _An */
@@ -87,7 +94,7 @@ static	const struct manact manacts[MDOC_
 	{ NULL, pre_enc, post_enc, "\\fB-", "\\fP" }, /* Fl */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Fn */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ft */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Ic */
+	{ NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Ic */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _In */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Li */
 	{ cond_head, pre_enc, NULL, "\\- ", NULL }, /* Nd */
@@ -115,10 +122,10 @@ static	const struct manact manacts[MDOC_
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ao */
 	{ cond_body, pre_enc, post_enc, "<", ">" }, /* Aq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _At */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Bc */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Bc */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Bf */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Bo */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Bq */
+	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bo */
+	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Bsx */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Bx */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Db */
@@ -127,7 +134,7 @@ static	const struct manact manacts[MDOC_
 	{ cond_body, pre_enc, post_enc, "``", "''" }, /* Dq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ec */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ef */
-	{ NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* _Em */
+	{ NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Em */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Eo */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Fx */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ms */
@@ -135,10 +142,10 @@ static	const struct manact manacts[MDOC_
 	{ NULL, pre_ns, NULL, NULL, NULL }, /* Ns */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Nx */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ox */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Pc */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Pf */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Po */
-	{ cond_body, pre_enc, post_enc, "(", ")" }, /* _Pq */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Pc */
+	{ NULL, NULL, post_pf, NULL, NULL }, /* Pf */
+	{ cond_body, pre_enc, post_enc, "(", ")" }, /* Po */
+	{ cond_body, pre_enc, post_enc, "(", ")" }, /* Pq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Qc */
 	{ cond_body, pre_enc, post_enc, "`", "'" }, /* Ql */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Qo */
@@ -149,15 +156,15 @@ static	const struct manact manacts[MDOC_
 	{ NULL, NULL, NULL, NULL, NULL }, /* _So */
 	{ cond_body, pre_enc, post_enc, "`", "'" }, /* Sq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Sm */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Sx */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Sy */
+	{ NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Sx */
+	{ NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Sy */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Tn */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ux */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Xc */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Xo */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Fo */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Fc */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Oo */
+	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Oo */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Oc */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Bk */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ek */
@@ -166,7 +173,7 @@ static	const struct manact manacts[MDOC_
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Fr */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ud */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Lb */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _Lp */
+	{ NULL, pre_pp, NULL, NULL, NULL }, /* Lp */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Lk */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Mt */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Brq */
@@ -177,10 +184,11 @@ static	const struct manact manacts[MDOC_
 	{ NULL, NULL, NULL, NULL, NULL }, /* _En */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Dx */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _%Q */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _br */
-	{ NULL, NULL, NULL, NULL, NULL }, /* _sp */
+	{ NULL, pre_br, NULL, NULL, NULL }, /* br */
+	{ NULL, pre_sp, post_sp, NULL, NULL }, /* sp */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _%U */
 	{ NULL, NULL, NULL, NULL, NULL }, /* _Ta */
+	{ NULL, NULL, NULL, NULL, NULL }, /* ROOT */
 };
 
 
@@ -219,11 +227,13 @@ man_mdoc(void *arg, const struct mdoc *m
 	m = mdoc_meta(mdoc);
 	n = mdoc_node(mdoc);
 
-	printf(".TH \"%s\" \"%s\" \"%s\"", m->title, m->msec, m->date);
+	printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
+	    m->title, m->msec, m->date, m->os, m->vol);
 	need_nl = 1;
 	need_space = 0;
 
 	print_node(m, n);
+	putchar('\n');
 }
 
 static void
@@ -240,6 +250,10 @@ print_node(DECL_ARGS)
 	cond = 0;
 	do_sub = 1;
 	if (MDOC_TEXT == n->type) {
+		if (need_nl && ('.' == *n->string || '\'' == *n->string)) {
+			print_word("\\&");
+			need_space = 0;
+		}
 		print_word(n->string);
 	} else {
 		act = manacts + n->tok;
@@ -307,6 +321,75 @@ post_percent(DECL_ARGS)
 }
 
 static int
+pre_sect(DECL_ARGS)
+{
+
+	if (MDOC_HEAD != n->type)
+		return(1);
+	need_nl = 1;
+	print_word(manacts[n->tok].prefix);
+	print_word("\"");
+	need_space = 0;
+	return(1);
+}
+
+static void
+post_sect(DECL_ARGS)
+{
+
+	if (MDOC_HEAD != n->type)
+		return;
+	need_space = 0;
+	print_word("\"");
+	need_nl = 1;
+}
+
+static int
+pre_ap(DECL_ARGS)
+{
+
+	need_space = 0;
+	print_word("'");
+	need_space = 0;
+	return(0);
+}
+
+static int
+pre_bd(DECL_ARGS)
+{
+
+	if (DISP_unfilled == n->norm->Bd.type ||
+	    DISP_literal  == n->norm->Bd.type) {
+		need_nl = 1;
+		print_word(".nf");
+	}
+	need_nl = 1;
+	return(1);
+}
+
+static void
+post_bd(DECL_ARGS)
+{
+
+	if (DISP_unfilled == n->norm->Bd.type ||
+	    DISP_literal  == n->norm->Bd.type) {
+		need_nl = 1;
+		print_word(".fi");
+	}
+	need_nl = 1;
+}
+
+static int
+pre_br(DECL_ARGS)
+{
+
+	need_nl = 1;
+	print_word(".br");
+	need_nl = 1;
+	return(0);
+}
+
+static int
 pre_dl(DECL_ARGS)
 {
 
@@ -334,7 +417,17 @@ pre_it(DECL_ARGS)
 		need_nl = 1;
 		print_word(".TP");
 		bln = n->parent->parent->prev;
-		print_word(bln->norm->Bl.width);
+		switch (bln->norm->Bl.type) {
+		case (LIST_bullet):
+			print_word("4n");
+			need_nl = 1;
+			print_word("\\fBo\\fP");
+			break;
+		default:
+			if (bln->norm->Bl.width)
+				print_word(bln->norm->Bl.width);
+			break;
+		}
 		need_nl = 1;
 	}
 	return(1);
@@ -371,6 +464,13 @@ pre_ns(DECL_ARGS)
 	return(0);
 }
 
+static void
+post_pf(DECL_ARGS)
+{
+
+	need_space = 0;
+}
+
 static int
 pre_pp(DECL_ARGS)
 {
@@ -385,25 +485,18 @@ pre_pp(DECL_ARGS)
 }
 
 static int
-pre_sh(DECL_ARGS)
+pre_sp(DECL_ARGS)
 {
 
-	if (MDOC_HEAD != n->type)
-		return(1);
 	need_nl = 1;
-	print_word(".SH \"");
-	need_space = 0;
+	print_word(".sp");
 	return(1);
 }
 
 static void
-post_sh(DECL_ARGS)
+post_sp(DECL_ARGS)
 {
 
-	if (MDOC_HEAD != n->type)
-		return;
-	need_space = 0;
-	print_word("\"");
 	need_nl = 1;
 }
 
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.195
retrieving revision 1.196
diff -Lmdoc.c -Lmdoc.c -u -p -r1.195 -r1.196
--- mdoc.c
+++ mdoc.c
@@ -160,6 +160,7 @@ mdoc_alloc1(struct mdoc *mdoc)
 	mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node));
 	mdoc->first = mdoc->last;
 	mdoc->last->type = MDOC_ROOT;
+	mdoc->last->tok = MDOC_MAX;
 	mdoc->next = MDOC_NEXT_CHILD;
 }
 
--
 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:[~2011-09-30  0:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-30  0:13 mdocml: implement .Ap .Bd .Bo .Bq .D1 .Ic .Lp .Oo .Pf .Po .Ss .Sx .Sy 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).