Fixed up Console::printFormat
This commit is contained in:
parent
af8a3c379e
commit
d5c7ded8c9
2 changed files with 17 additions and 56 deletions
|
@ -7,10 +7,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "Console.hh"
|
||||||
|
#include "kstd/ASCII.hh"
|
||||||
|
#include "kstd/CString.hh"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
void itoa(int value, char* buffer, int base);
|
void itoa(int value, char* buffer, int base);
|
||||||
|
|
||||||
|
|
||||||
struct PrintfSpec
|
struct PrintfSpec
|
||||||
{
|
{
|
||||||
enum Size {
|
enum Size {
|
||||||
|
@ -50,7 +54,7 @@ struct PrintfSpec
|
||||||
Value value;
|
Value value;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
int print(Console& console);
|
int print(kernel::Console& console);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +69,7 @@ PrintfSpec::clear()
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
PrintfSpec::print(Console& console)
|
PrintfSpec::print(kernel::Console& console)
|
||||||
{
|
{
|
||||||
int nchars = 0;
|
int nchars = 0;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
@ -82,9 +86,9 @@ PrintfSpec::print(Console& console)
|
||||||
width = 1;
|
width = 1;
|
||||||
}
|
}
|
||||||
for (int i = 1; i < width; i++) {
|
for (int i = 1; i < width; i++) {
|
||||||
putchar(' ');
|
console.printChar(' ');
|
||||||
}
|
}
|
||||||
putchar(value.c);
|
console.printChar(value.c);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,13 +133,13 @@ PrintfSpec::print(Console& console)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
length = strlen(buf);
|
length = kstd::CString::length(buf);
|
||||||
if (width < length) {
|
if (width < length) {
|
||||||
width = length;
|
width = length;
|
||||||
}
|
}
|
||||||
str = buf;
|
str = buf;
|
||||||
} else if (type == TypeString) {
|
} else if (type == TypeString) {
|
||||||
length = strlen(value.s);
|
length = kstd::CString::length(value.s);
|
||||||
if (width < length) {
|
if (width < length) {
|
||||||
width = length;
|
width = length;
|
||||||
}
|
}
|
||||||
|
@ -194,46 +198,6 @@ itoa(int value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
to_upper(char* buffer)
|
|
||||||
{
|
|
||||||
char* p = buffer;
|
|
||||||
for (char* p = buffer; *p != 0; p++) {
|
|
||||||
if (*p >= 'a' && *p <= 'z') {
|
|
||||||
*p = (*p - 'a') + 'A';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
is_digit(char c)
|
|
||||||
{
|
|
||||||
return c >= '0' && c <= '9';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
is_hex(char c)
|
|
||||||
{
|
|
||||||
return is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
is_lower(char c)
|
|
||||||
{
|
|
||||||
return c >= 'a' && c <= 'z';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
is_upper(char c)
|
|
||||||
{
|
|
||||||
return c >= 'A' && c <= 'Z';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
is_size(char c)
|
is_size(char c)
|
||||||
{
|
{
|
||||||
|
@ -247,12 +211,7 @@ is_specifier(char c)
|
||||||
return c == 'd' || c == 'x' || c == 'X' || c == 'c' || c == 's';
|
return c == 'd' || c == 'x' || c == 'X' || c == 'c' || c == 's';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} /* anonymous namespace */
|
||||||
inline bool
|
|
||||||
is_letter(char c)
|
|
||||||
{
|
|
||||||
return is_lower(c) || is_upper(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
|
|
||||||
|
@ -289,7 +248,7 @@ Console::printFormat(const char* fmt,
|
||||||
state = StateDefault;
|
state = StateDefault;
|
||||||
printChar(*p);
|
printChar(*p);
|
||||||
nchars++;
|
nchars++;
|
||||||
} else if (is_digit(*p)) {
|
} else if (kstd::Char::isDigit(*p)) {
|
||||||
if (*p == '0' && !spec.zero) {
|
if (*p == '0' && !spec.zero) {
|
||||||
spec.zero = true;
|
spec.zero = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -303,7 +262,7 @@ Console::printFormat(const char* fmt,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StateWidth:
|
case StateWidth:
|
||||||
if (is_digit(*p)) {
|
if (kstd::Char::isDigit(*p)) {
|
||||||
spec.width = 10 * spec.width + (*p - '0');
|
spec.width = 10 * spec.width + (*p - '0');
|
||||||
} else if (is_size(*p)) {
|
} else if (is_size(*p)) {
|
||||||
state = StateSize;
|
state = StateSize;
|
||||||
|
|
|
@ -17,6 +17,8 @@ files = [
|
||||||
'PIC.cc',
|
'PIC.cc',
|
||||||
'cxa.cc',
|
'cxa.cc',
|
||||||
'isr.S',
|
'isr.S',
|
||||||
|
|
||||||
|
'kstd/CString.cc'
|
||||||
]
|
]
|
||||||
|
|
||||||
toolchain_bin = Dir(os.environ['POLKA_TOOLCHAIN']).Dir('bin')
|
toolchain_bin = Dir(os.environ['POLKA_TOOLCHAIN']).Dir('bin')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue