source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Wonders of roff(7): Integer numbers in numerical expressions can
@ 2015-01-23  0:42 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-01-23  0:42 UTC (permalink / raw)
  To: source

Log Message:
-----------
Wonders of roff(7): Integer numbers in numerical expressions can carry
scaling units, and some manuals (e.g. in devel/grcs) actually use that,
so let's support it.  Missing feature reported by naddy@.

Modified Files:
--------------
    mdocml:
        roff.7
        roff.c

Revision Data
-------------
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.66
retrieving revision 1.67
diff -Lroff.7 -Lroff.7 -u -p -r1.66 -r1.67
--- roff.7
+++ roff.7
@@ -1715,6 +1715,14 @@ prefixed by an optional sign
 .Sq +
 or
 .Sq - .
+Each number may be followed by one optional scaling unit described below
+.Sx Scaling Widths .
+The following equations hold:
+.Bd -literal -offset indent
+1i = 6v = 6P = 10m = 10n = 72p = 1000M = 240u = 240
+254c = 100i = 24000u = 24000 
+1f = 65536u = 65536
+.Ed
 .Pp
 The following binary operators are implemented.
 Unless otherwise stated, they behave as in the C language:
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.253
retrieving revision 1.254
diff -Lroff.c -Lroff.c -u -p -r1.253 -r1.254
--- roff.c
+++ roff.c
@@ -1641,8 +1641,46 @@ roff_getnum(const char *v, int *pos, int
 	if (n)
 		*res = -*res;
 
-	*pos = p;
-	return 1;
+	/* Each number may be followed by one optional scaling unit. */
+
+	switch (v[p]) {
+	case 'f':
+		*res *= 65536;
+		break;
+	case 'i':
+		*res *= 240;
+		break;
+	case 'c':
+		*res *= 240;
+		*res /= 2.54;
+		break;
+	case 'v':
+		/* FALLTROUGH */
+	case 'P':
+		*res *= 40;
+		break;
+	case 'm':
+		/* FALLTROUGH */
+	case 'n':
+		*res *= 24;
+		break;
+	case 'p':
+		*res *= 10;
+		*res /= 3;
+		break;
+	case 'u':
+		break;
+	case 'M':
+		*res *= 6;
+		*res /= 25;
+		break;
+	default:
+		p--;
+		break;
+	}
+
+	*pos = p + 1;
+	return(1);
 }
 
 /*
--
 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:[~2015-01-23  0:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23  0:42 mdocml: Wonders of roff(7): Integer numbers in numerical expressions can 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).