From 33b1ccbdab76baf9acad6f57d7e7a18e74c02cca Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Mon, 27 Oct 2014 16:04:44 +0800 Subject: [BUILTIN] Remove getintmax in printf This patch removes getintmax and moves its functionality into getuintmax in order to reduce code duplication. Signed-off-by: Herbert Xu --- src/bltin/printf.c | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/bltin/printf.c b/src/bltin/printf.c index d1181e3..ebc74ae 100644 --- a/src/bltin/printf.c +++ b/src/bltin/printf.c @@ -44,8 +44,7 @@ static int conv_escape_str(char *, char **); static char *conv_escape(char *, int *); static int getchr(void); static double getdouble(void); -static intmax_t getintmax(void); -static uintmax_t getuintmax(void); +static uintmax_t getuintmax(int); static char *getstr(void); static char *mklong(const char *, const char *); static void check_conversion(const char *, const char *); @@ -179,14 +178,14 @@ pc: /* skip to field width */ fmt += strspn(fmt, SKIP1); if (*fmt == '*') - *param++ = getintmax(); + *param++ = getuintmax(1); /* skip to possible '.', get following precision */ fmt += strspn(fmt, SKIP2); if (*fmt == '.') ++fmt; if (*fmt == '*') - *param++ = getintmax(); + *param++ = getuintmax(1); fmt += strspn(fmt, SKIP2); @@ -220,18 +219,18 @@ pc: } case 'd': case 'i': { - intmax_t p = getintmax(); - char *f = mklong(start, fmt); - PF(f, p); + uintmax_t p = getuintmax(1); + start = mklong(start, fmt); + PF(start, p); break; } case 'o': case 'u': case 'x': case 'X': { - uintmax_t p = getuintmax(); - char *f = mklong(start, fmt); - PF(f, p); + uintmax_t p = getuintmax(0); + start = mklong(start, fmt); + PF(start, p); break; } case 'a': @@ -404,30 +403,8 @@ getstr(void) return val; } -static intmax_t -getintmax(void) -{ - intmax_t val = 0; - char *cp, *ep; - - cp = *gargv; - if (cp == NULL) - goto out; - gargv++; - - val = (unsigned char) cp[1]; - if (*cp == '\"' || *cp == '\'') - goto out; - - errno = 0; - val = strtoimax(cp, &ep, 0); - check_conversion(cp, ep); -out: - return val; -} - static uintmax_t -getuintmax(void) +getuintmax(int sign) { uintmax_t val = 0; char *cp, *ep; @@ -442,7 +419,7 @@ getuintmax(void) goto out; errno = 0; - val = strtoumax(cp, &ep, 0); + val = sign ? strtoimax(cp, &ep, 0) : strtoumax(cp, &ep, 0); check_conversion(cp, ep); out: return val; -- cgit 1.4.1