From: Jes.Sorensen@redhat.com
To: kevin@koconnor.net
Cc: Jes Sorensen <Jes.Sorensen@redhat.com>,
seabios@seabios.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] SeaBIOS: Fix bvprintf() to respect padding for hex printing.
Date: Mon, 14 Jun 2010 14:04:31 +0200 [thread overview]
Message-ID: <1276517071-17746-1-git-send-email-Jes.Sorensen@redhat.com> (raw)
From: Jes Sorensen <Jes.Sorensen@redhat.com>
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 <Jes.Sorensen@redhat.com>
---
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;
--
1.6.5.2
next reply other threads:[~2010-06-14 12:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 12:04 Jes.Sorensen [this message]
2010-06-17 2:42 ` [Qemu-devel] Re: [PATCH] SeaBIOS: Fix bvprintf() to respect padding for hex printing Kevin O'Connor
2010-06-17 7:11 ` Jes Sorensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1276517071-17746-1-git-send-email-Jes.Sorensen@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=kevin@koconnor.net \
--cc=qemu-devel@nongnu.org \
--cc=seabios@seabios.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).