diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-06-08 12:54:58 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-06-08 12:54:58 +0000 |
commit | 789580a2a2366243d622766fdadd094931ca6596 (patch) | |
tree | 60a78614bcfb83b55ebd45464a5bc77e4c61c98c /out.c | |
parent | 76a6887f123b221e7a8851c1b0d0008119492613 (diff) | |
download | mandoc-789580a2a2366243d622766fdadd094931ca6596.tar.gz mandoc-789580a2a2366243d622766fdadd094931ca6596.tar.zst mandoc-789580a2a2366243d622766fdadd094931ca6596.zip |
make the internal a2roffsu() interface more powerful by returning
a pointer to the end of the parsed data, making it easier to
parse subsequent bytes
Diffstat (limited to 'out.c')
-rw-r--r-- | out.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.63 2017/05/01 20:54:59 schwarze Exp $ */ +/* $Id: out.c,v 1.64 2017/06/08 12:54:58 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -40,10 +40,10 @@ static void tblcalc_number(struct rofftbl *, struct roffcol *, * 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 2 on complete success, 1 when a conversion was done, - * but there was trailing garbage, and 0 on total failure. + * Return a pointer to the byte after the last byte used, + * or NULL on total failure. */ -int +const char * a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) { char *endptr; @@ -51,7 +51,7 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) dst->unit = def == SCALE_MAX ? SCALE_BU : def; dst->scale = strtod(src, &endptr); if (endptr == src) - return 0; + return NULL; switch (*endptr++) { case 'c': @@ -89,12 +89,11 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) /* FALLTHROUGH */ default: if (SCALE_MAX == def) - return 0; + return NULL; dst->unit = def; break; } - - return *endptr == '\0' ? 2 : 1; + return endptr; } /* |