source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Clean up -T[x]html by using a table instead of a switch
Date: Tue, 17 May 2011 06:48:06 -0400 (EDT)	[thread overview]
Message-ID: <201105171048.p4HAm6n9029084@krisdoz.my.domain> (raw)

Log Message:
-----------
Clean up -T[x]html by using a table instead of a switch statement for
the roff units.  Also remove a comment about CSS and number types (they
all accept decimal numbers).

Modified Files:
--------------
    mdocml:
        html.c

Revision Data
-------------
Index: html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.c,v
retrieving revision 1.139
retrieving revision 1.140
diff -Lhtml.c -Lhtml.c -u -p -r1.139 -r1.140
--- html.c
+++ html.c
@@ -94,6 +94,19 @@ static	const char	*const htmlattrs[ATTR_
 	"colspan", /* ATTR_COLSPAN */
 };
 
+static	const char	*const roffscales[SCALE_MAX] = {
+	"cm", /* SCALE_CM */
+	"in", /* SCALE_IN */
+	"pc", /* SCALE_PC */
+	"pt", /* SCALE_PT */
+	"em", /* SCALE_EM */
+	"em", /* SCALE_MM */
+	"ex", /* SCALE_EN */
+	"ex", /* SCALE_BU */
+	"em", /* SCALE_VS */
+	"ex", /* SCALE_FS */
+};
+
 static	void		  print_num(struct html *, const char *, size_t);
 static	void		  print_spec(struct html *, const char *, size_t);
 static	void		  print_res(struct html *, const char *, size_t);
@@ -729,50 +742,12 @@ void
 bufcat_su(struct html *h, const char *p, const struct roffsu *su)
 {
 	double		 v;
-	const char	*u;
 
 	v = su->scale;
+	if (SCALE_MM == su->unit && 0.0 == (v /= 100.0))
+		v = 1.0;
 
-	switch (su->unit) {
-	case (SCALE_CM):
-		u = "cm";
-		break;
-	case (SCALE_IN):
-		u = "in";
-		break;
-	case (SCALE_PC):
-		u = "pc";
-		break;
-	case (SCALE_PT):
-		u = "pt";
-		break;
-	case (SCALE_EM):
-		u = "em";
-		break;
-	case (SCALE_MM):
-		if (0 == (v /= 100))
-			v = 1;
-		u = "em";
-		break;
-	case (SCALE_EN):
-		u = "ex";
-		break;
-	case (SCALE_BU):
-		u = "ex";
-		break;
-	case (SCALE_VS):
-		u = "em";
-		break;
-	default:
-		u = "ex";
-		break;
-	}
-
-	/* 
-	 * XXX: the CSS spec isn't clear as to which types accept
-	 * integer or real numbers, so we just make them all decimals.
-	 */
-	buffmt(h, "%s: %.2f%s;", p, v, u);
+	buffmt(h, "%s: %.2f%s;", p, v, roffscales[su->unit]);
 }
 
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2011-05-17 10:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201105171048.p4HAm6n9029084@krisdoz.my.domain \
    --to=kristaps@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).