py: Fix pfenv_print_strn to return correct number of chars printed.

With this fix, all tests in tests/basics pass on pyboard.
This commit is contained in:
Damien George 2014-04-17 18:58:09 +01:00
parent 71d3112f7e
commit d0f9f6cd3f
2 changed files with 8 additions and 4 deletions

View File

@ -29,6 +29,7 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
int right_pad = 0;
int pad = width - len;
int pad_size;
int total_chars_printed = 0;
const char *pad_chars;
if (!fill || fill == ' ' ) {
@ -53,7 +54,8 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
left_pad = pad;
}
if (left_pad) {
if (left_pad > 0) {
total_chars_printed += left_pad;
while (left_pad > 0) {
int p = left_pad;
if (p > pad_size) {
@ -64,7 +66,9 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
}
}
pfenv->print_strn(pfenv->data, str, len);
if (right_pad) {
total_chars_printed += len;
if (right_pad > 0) {
total_chars_printed += right_pad;
while (right_pad > 0) {
int p = right_pad;
if (p > pad_size) {
@ -74,7 +78,7 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
right_pad -= p;
}
}
return len;
return total_chars_printed;
}
// 32-bits is 10 digits, add 3 for commas, 1 for sign, 1 for terminating null