source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: My favourite: removing lots of code in favour of smaller,
@ 2010-12-06 14:04 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-12-06 14:04 UTC (permalink / raw)
  To: source

Log Message:
-----------
My favourite: removing lots of code in favour of smaller, tighter code.
Merge patch by schwarze@ consolidating RB, BR, etc. into one function.
man_html.c already does this.

Modified Files:
--------------
    mdocml:
        man_term.c

Revision Data
-------------
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -Lman_term.c -Lman_term.c -u -p -r1.87 -r1.88
--- man_term.c
+++ man_term.c
@@ -80,14 +80,12 @@ static	void		  print_man_foot(struct ter
 static	void		  print_bvspace(struct termp *, 
 				const struct man_node *);
 
+static	int		  pre_alternate(DECL_ARGS);
 static	int		  pre_B(DECL_ARGS);
-static	int		  pre_BI(DECL_ARGS);
 static	int		  pre_HP(DECL_ARGS);
 static	int		  pre_I(DECL_ARGS);
 static	int		  pre_IP(DECL_ARGS);
 static	int		  pre_PP(DECL_ARGS);
-static	int		  pre_RB(DECL_ARGS);
-static	int		  pre_RI(DECL_ARGS);
 static	int		  pre_RS(DECL_ARGS);
 static	int		  pre_SH(DECL_ARGS);
 static	int		  pre_SS(DECL_ARGS);
@@ -117,15 +115,15 @@ static	const struct termact termacts[MAN
 	{ pre_HP, post_HP, 0 }, /* HP */ 
 	{ NULL, NULL, 0 }, /* SM */
 	{ pre_B, NULL, 0 }, /* SB */
-	{ pre_BI, NULL, 0 }, /* BI */
-	{ pre_BI, NULL, 0 }, /* IB */
-	{ pre_RB, NULL, 0 }, /* BR */
-	{ pre_RB, NULL, 0 }, /* RB */
+	{ pre_alternate, NULL, 0 }, /* BI */
+	{ pre_alternate, NULL, 0 }, /* IB */
+	{ pre_alternate, NULL, 0 }, /* BR */
+	{ pre_alternate, NULL, 0 }, /* RB */
 	{ NULL, NULL, 0 }, /* R */
 	{ pre_B, NULL, 0 }, /* B */
 	{ pre_I, NULL, 0 }, /* I */
-	{ pre_RI, NULL, 0 }, /* IR */
-	{ pre_RI, NULL, 0 }, /* RI */
+	{ pre_alternate, NULL, 0 }, /* IR */
+	{ pre_alternate, NULL, 0 }, /* RI */
 	{ NULL, NULL, MAN_NOTEXT }, /* na */
 	{ pre_I, NULL, 0 }, /* i */
 	{ pre_sp, NULL, MAN_NOTEXT }, /* sp */
@@ -250,94 +248,67 @@ pre_literal(DECL_ARGS)
 {
 
 	term_newln(p);
-	switch (n->tok) {
-	case (MAN_nf):
+
+	if (MAN_nf == n->tok)
 		mt->fl |= MANT_LITERAL;
-		break;
-	default:
+	else
 		mt->fl &= ~MANT_LITERAL;
-		break;
-	}
 
 	return(1);
 }
 
-
-
 /* ARGSUSED */
 static int
-pre_RB(DECL_ARGS)
+pre_alternate(DECL_ARGS)
 {
-	const struct man_node *nn;
-	int		 i;
-
-	for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
-		if (i % 2 && MAN_RB == n->tok)
-			term_fontrepl(p, TERMFONT_BOLD);
-		else if ( ! (i % 2) && MAN_RB != n->tok)
-			term_fontrepl(p, TERMFONT_BOLD);
-		else
-			term_fontrepl(p, TERMFONT_NONE);
-
-		if (i > 0)
-			p->flags |= TERMP_NOSPACE;
+	enum termfont		 font[2];
+	const struct man_node	*nn;
+	int			 savelit, i;
 
-		print_man_node(p, mt, nn, m);
+	switch (n->tok) {
+	case (MAN_RB):
+		font[0] = TERMFONT_NONE;
+		font[1] = TERMFONT_BOLD;
+		break;
+	case (MAN_RI):
+		font[0] = TERMFONT_NONE;
+		font[1] = TERMFONT_UNDER;
+		break;
+	case (MAN_BR):
+		font[0] = TERMFONT_BOLD;
+		font[1] = TERMFONT_NONE;
+		break;
+	case (MAN_BI):
+		font[0] = TERMFONT_BOLD;
+		font[1] = TERMFONT_UNDER;
+		break;
+	case (MAN_IR):
+		font[0] = TERMFONT_UNDER;
+		font[1] = TERMFONT_NONE;
+		break;
+	case (MAN_IB):
+		font[0] = TERMFONT_UNDER;
+		font[1] = TERMFONT_BOLD;
+		break;
+	default:
+		abort();
 	}
-	return(0);
-}
 
+	savelit = MANT_LITERAL & mt->fl;
+	mt->fl &= ~MANT_LITERAL;
 
-/* ARGSUSED */
-static int
-pre_RI(DECL_ARGS)
-{
-	const struct man_node *nn;
-	int		 i;
-
-	for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
-		if (i % 2 && MAN_RI == n->tok)
-			term_fontrepl(p, TERMFONT_UNDER);
-		else if ( ! (i % 2) && MAN_RI != n->tok)
-			term_fontrepl(p, TERMFONT_UNDER);
-		else
-			term_fontrepl(p, TERMFONT_NONE);
-
-		if (i > 0)
-			p->flags |= TERMP_NOSPACE;
-
+	for (i = 0, nn = n->child; nn; nn = nn->next, i = 1 - i) {
+		term_fontrepl(p, font[i]);
+		if (savelit && NULL == nn->next)
+			mt->fl |= MANT_LITERAL;
 		print_man_node(p, mt, nn, m);
-	}
-	return(0);
-}
-
-
-/* ARGSUSED */
-static int
-pre_BI(DECL_ARGS)
-{
-	const struct man_node	*nn;
-	int			 i;
-
-	for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
-		if (i % 2 && MAN_BI == n->tok)
-			term_fontrepl(p, TERMFONT_UNDER);
-		else if (i % 2)
-			term_fontrepl(p, TERMFONT_BOLD);
-		else if (MAN_BI == n->tok)
-			term_fontrepl(p, TERMFONT_BOLD);
-		else
-			term_fontrepl(p, TERMFONT_UNDER);
-
-		if (i)
+		if (nn->next)
 			p->flags |= TERMP_NOSPACE;
-
-		print_man_node(p, mt, nn, m);
 	}
+
 	return(0);
 }
 
-
 /* ARGSUSED */
 static int
 pre_B(DECL_ARGS)
@@ -346,7 +317,6 @@ pre_B(DECL_ARGS)
 	term_fontrepl(p, TERMFONT_BOLD);
 	return(1);
 }
-
 
 /* ARGSUSED */
 static int
--
 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:[~2010-12-06 14:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-06 14:04 mdocml: My favourite: removing lots of code in favour of smaller, kristaps

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).