summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang W <[email protected]>2023-07-10 00:02:21 +0800
committerAnup Patel <[email protected]>2023-07-12 09:39:38 +0530
commit60539176266fa37b4bc20054128bebec5bbe7055 (patch)
tree738ae25199b5a185eeaad2dd17a97451db2b7186
parent976895c57e3b0655466e20c6eb0d7c670b9e8452 (diff)
lib: sbi: Fix how print gets flags
The flags for print should be able to appear in any order. The previous code required the order to be fixed. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/sbi_console.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
index 168dffd0..d87b5c20 100644
--- a/lib/sbi/sbi_console.c
+++ b/lib/sbi/sbi_console.c
@@ -236,6 +236,7 @@ static int printi(char **out, u32 *out_len, long long i, int b, int sg,
static int print(char **out, u32 *out_len, const char *format, va_list args)
{
+ bool flags_done;
int width, flags, pc = 0;
char scr[2], *tout;
bool use_tbuf = (!out) ? true : false;
@@ -268,17 +269,24 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
if (*format == '%')
goto literal;
/* Get flags */
- if (*format == '-') {
- ++format;
- flags = PAD_RIGHT;
- }
- if (*format == '#') {
- ++format;
- flags |= PAD_ALTERNATE;
- }
- while (*format == '0') {
- ++format;
- flags |= PAD_ZERO;
+ flags_done = false;
+ while (!flags_done) {
+ switch (*format) {
+ case '-':
+ flags |= PAD_RIGHT;
+ break;
+ case '#':
+ flags |= PAD_ALTERNATE;
+ break;
+ case '0':
+ flags |= PAD_ZERO;
+ break;
+ default:
+ flags_done = true;
+ break;
+ }
+ if (!flags_done)
+ ++format;
}
/* Get width */
for (; *format >= '0' && *format <= '9'; ++format) {