From patchwork Mon Jun 14 12:04:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 55520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C32F8B7D68 for ; Mon, 14 Jun 2010 22:06:35 +1000 (EST) Received: from localhost ([127.0.0.1]:33966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OO8Q3-0002jG-6R for incoming@patchwork.ozlabs.org; Mon, 14 Jun 2010 08:05:35 -0400 Received: from [140.186.70.92] (port=36630 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OO8PH-0002i4-MT for qemu-devel@nongnu.org; Mon, 14 Jun 2010 08:04:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OO8PC-0005Vd-4Z for qemu-devel@nongnu.org; Mon, 14 Jun 2010 08:04:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22358) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OO8PB-0005VF-Tp for qemu-devel@nongnu.org; Mon, 14 Jun 2010 08:04:42 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5EC4cQq004177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Jun 2010 08:04:39 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5EC4a0R029165; Mon, 14 Jun 2010 08:04:37 -0400 From: Jes.Sorensen@redhat.com To: kevin@koconnor.net Date: Mon, 14 Jun 2010 14:04:31 +0200 Message-Id: <1276517071-17746-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jes Sorensen , seabios@seabios.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] SeaBIOS: Fix bvprintf() to respect padding for hex printing. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jes Sorensen Fix bvprintf to respect space padding when printing hex numbers and the caller specifies alignment without zero padding, eg. %2x as opposed to %02x Signed-off-by: Jes Sorensen --- src/output.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/output.c b/src/output.c index 3de565a..a0d07e3 100644 --- a/src/output.c +++ b/src/output.c @@ -195,7 +195,7 @@ putsinglehex(struct putcinfo *action, u32 val) // Output an integer in hexadecimal. static void -puthex(struct putcinfo *action, u32 val, int width) +puthex(struct putcinfo *action, u32 val, int width, int spacepad) { if (!width) { u32 tmp = val; @@ -210,6 +210,17 @@ puthex(struct putcinfo *action, u32 val, int width) } if (tmp > 0xf) width += 1; + } else if (spacepad) { + int count = 1; + u32 tmp = val; + while (tmp >>= 4) { + count++; + } + count = width - count; + width -= count; + while (count--) { + putc(action, ' '); + } } switch (width) { @@ -244,11 +255,15 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) } const char *n = s+1; int field_width = 0; + int spacepad = 1; for (;;) { c = GET_GLOBAL(*(u8*)n); if (!isdigit(c)) break; - field_width = field_width * 10 + c - '0'; + if (!field_width && (c == '0')) + spacepad = 0; + else + field_width = field_width * 10 + c - '0'; n++; } if (c == 'l') { @@ -281,7 +296,7 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) field_width = 8; case 'x': val = va_arg(args, s32); - puthex(action, val, field_width); + puthex(action, val, field_width, spacepad); break; case 'c': val = va_arg(args, int); @@ -333,7 +348,7 @@ __dprintf(const char *fmt, ...) if (cur != &MainThread) { // Show "thread id" for this debug message. putc_debug(&debuginfo, '|'); - puthex(&debuginfo, (u32)cur, 8); + puthex(&debuginfo, (u32)cur, 8, 0); putc_debug(&debuginfo, '|'); putc_debug(&debuginfo, ' '); } @@ -411,12 +426,12 @@ hexdump(const void *d, int len) while (len > 0) { if (count % 8 == 0) { putc(&debuginfo, '\n'); - puthex(&debuginfo, count*4, 8); + puthex(&debuginfo, count*4, 8, 0); putc(&debuginfo, ':'); } else { putc(&debuginfo, ' '); } - puthex(&debuginfo, *(u32*)d, 8); + puthex(&debuginfo, *(u32*)d, 8, 0); count++; len-=4; d+=4;