From 789580a2a2366243d622766fdadd094931ca6596 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 8 Jun 2017 12:54:58 +0000 Subject: 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 --- out.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'out.c') diff --git a/out.c b/out.c index 22cdfbba..25aa2d47 100644 --- a/out.c +++ b/out.c @@ -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 * Copyright (c) 2011, 2014, 2015, 2017 Ingo Schwarze @@ -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; } /* -- cgit v1.2.3-56-ge451