From owner-freebsd-audit Sat Jun 1 6:25:32 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 09E6837B409 for ; Sat, 1 Jun 2002 06:25:27 -0700 (PDT) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id XAA15313; Sat, 1 Jun 2002 23:25:14 +1000 Date: Sat, 1 Jun 2002 23:28:48 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Dag-Erling Smorgrav Cc: Dima Dorfman , Subject: Re: %j for printf(9) In-Reply-To: Message-ID: <20020601232049.E2458-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 31 May 2002, Dag-Erling Smorgrav wrote: > Bruce Evans writes: > > I don't remember all the context for this. Is everything restructured so > > that all the va_arg()'s for fetching integers are in the above patch? > > Yes. > > > If so, consider the following further restructurings: > > > > - merge fetch_nosign with nosign (rename it to something like > > handle_unsigned) and use it handle all the unsigned cases that are now > > handled by fetch_number. > > - rename fetch_number to handle_signed and use it for only the signed cases > > (%d and %+z). > > These two would actually increase code duplication. It came out 1 line shorter with less duplication for me. Here is a patch relative to the version in your next mail. I didn't rename fetch* to handle*, and I may have broken something moved the initializations of `sign' around too much. I reordered some initializations (especially for %p) so that the order is almost (?) always (base, ..., sign, num). %%% --- subr_prf.c~~ Sat Jun 1 22:59:01 2002 +++ subr_prf.c Sat Jun 1 23:21:44 2002 @@ -596,7 +596,7 @@ break; case 'd': - sign = 1; base = 10; - goto fetch_number; + sign = 1; + goto fetch_sign; case 'j': jflag = 1; @@ -613,8 +613,9 @@ goto fetch_nosign; case 'p': - num = (uintptr_t)va_arg(ap, void *); base = 16; sharpflag = (width == 0); - goto nosign; + sign = 0; + num = (uintptr_t)va_arg(ap, void *); + goto number; case 'q': qflag = 1; @@ -623,5 +624,7 @@ case 'r': base = radix; - goto fetch_number; + if (sign) + goto fetch_sign; + goto fetch_nosign; case 's': p = va_arg(ap, char *); @@ -654,6 +657,8 @@ case 'z': base = 16; - goto fetch_number; + if (sign) + goto fetch_sign; fetch_nosign: + sign = 0; if (jflag) num = va_arg(ap, uintmax_t); @@ -664,20 +669,14 @@ else num = va_arg(ap, u_int); - goto nosign; -fetch_number: + goto number; +fetch_sign: if (jflag) num = va_arg(ap, intmax_t); else if (qflag) - num = sign ? va_arg(ap, quad_t) : - va_arg(ap, u_quad_t); + num = va_arg(ap, quad_t); else if (lflag) - num = sign ? va_arg(ap, long) : - va_arg(ap, u_long); + num = va_arg(ap, long); else - num = sign ? va_arg(ap, int) : - va_arg(ap, u_int); - goto number; -nosign: - sign = 0; + num = va_arg(ap, int); number: if (sign && (intmax_t)num < 0) { %%% To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message