提交 1fb67608 编写于 作者: S Simon Glass

tiny-printf: Tidy up a few nits

- Rename 'w' to 'width' to make it more obvious what it is used for
- Use bool and int types instead of char to avoid register-masking on
32-bit machines
Signed-off-by: NSimon Glass <sjg@chromium.org>
Reviewed-by: NStefan Roese <sr@denx.de>
上级 d0375f3c
...@@ -52,8 +52,8 @@ int vprintf(const char *fmt, va_list va) ...@@ -52,8 +52,8 @@ int vprintf(const char *fmt, va_list va)
if (ch != '%') { if (ch != '%') {
putc(ch); putc(ch);
} else { } else {
char lz = 0; bool lz = false;
char w = 0; int width = 0;
ch = *(fmt++); ch = *(fmt++);
if (ch == '0') { if (ch == '0') {
...@@ -62,9 +62,9 @@ int vprintf(const char *fmt, va_list va) ...@@ -62,9 +62,9 @@ int vprintf(const char *fmt, va_list va)
} }
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
w = 0; width = 0;
while (ch >= '0' && ch <= '9') { while (ch >= '0' && ch <= '9') {
w = (w * 10) + ch - '0'; width = (width * 10) + ch - '0';
ch = *fmt++; ch = *fmt++;
} }
} }
...@@ -73,7 +73,7 @@ int vprintf(const char *fmt, va_list va) ...@@ -73,7 +73,7 @@ int vprintf(const char *fmt, va_list va)
zs = 0; zs = 0;
switch (ch) { switch (ch) {
case 0: case '\0':
goto abort; goto abort;
case 'u': case 'u':
case 'd': case 'd':
...@@ -112,9 +112,9 @@ int vprintf(const char *fmt, va_list va) ...@@ -112,9 +112,9 @@ int vprintf(const char *fmt, va_list va)
*bf = 0; *bf = 0;
bf = p; bf = p;
while (*bf++ && w > 0) while (*bf++ && width > 0)
w--; width--;
while (w-- > 0) while (width-- > 0)
putc(lz ? '0' : ' '); putc(lz ? '0' : ' ');
if (p) { if (p) {
while ((ch = *p++)) while ((ch = *p++))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册