summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-12-23 03:27:37 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-12-23 03:27:37 +0000
commite5129de0952a58ee691dc37979e5667df22c646b (patch)
tree212d51c05dda1f45b93301bf1d78764465811bcf /usr.bin/mandoc
parent3be93801b90d382b4273ca2cf58cdbb95fab39df (diff)
In a2roffsu(), do not parse the number twice.
Gets rid of 25 lines of code and one static buffer. No functional change for numbers shorter than BUFSIZ characters.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/out.c57
1 files changed, 13 insertions, 44 deletions
diff --git a/usr.bin/mandoc/out.c b/usr.bin/mandoc/out.c
index 402ea1e9000..a7c3a6b9eea 100644
--- a/usr.bin/mandoc/out.c
+++ b/usr.bin/mandoc/out.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: out.c,v 1.26 2014/12/04 02:05:16 schwarze Exp $ */
+/* $OpenBSD: out.c,v 1.27 2014/12/23 03:27:36 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -18,8 +18,6 @@
#include <sys/types.h>
#include <assert.h>
-#include <ctype.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -37,53 +35,23 @@ static void tblcalc_number(struct rofftbl *, struct roffcol *,
/*
- * Convert a `scaling unit' to a consistent form, or fail. Scaling
- * units are documented in groff.7, mdoc.7, man.7.
+ * Parse the *src string and store a scaling unit into *dst.
+ * If the string doesn't specify the unit, use the default.
+ * If no default is specified, fail.
+ * Return 1 on success and 0 on failure.
*/
int
a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
{
- char buf[BUFSIZ], hasd;
- int i;
+ char *endptr;
+ double scale;
enum roffscale unit;
- if ('\0' == *src)
- return(0);
-
- i = hasd = 0;
-
- switch (*src) {
- case '+':
- src++;
- break;
- case '-':
- buf[i++] = *src++;
- break;
- default:
- break;
- }
-
- if ('\0' == *src)
- return(0);
-
- while (i < BUFSIZ) {
- if ( ! isdigit((unsigned char)*src)) {
- if ('.' != *src)
- break;
- else if (hasd)
- break;
- else
- hasd = 1;
- }
- buf[i++] = *src++;
- }
-
- if (BUFSIZ == i || (*src && *(src + 1)))
+ scale = strtod(src, &endptr);
+ if (endptr == src || (endptr[0] != '\0' && endptr[1] != '\0'))
return(0);
- buf[i] = '\0';
-
- switch (*src) {
+ switch (*endptr) {
case 'c':
unit = SCALE_CM;
break;
@@ -124,8 +92,9 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
}
/* FIXME: do this in the caller. */
- if ((dst->scale = atof(buf)) < 0.0)
- dst->scale = 0.0;
+ if (scale < 0.0)
+ scale = 0.0;
+ dst->scale = scale;
dst->unit = unit;
return(1);
}