From b7b4182cd2d0c7e3add9a6963fe80746eb10ee76 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 16 Apr 2023 15:39:49 -0500 Subject: [PATCH] printf: ignore '0' flag if '-' is also used. This is what the standards require. Previously, the '0' flag would effectively override '-'. Here is a program that demonstrates the problem: #include int main(void) { printf("|%-020d|\n", 123); printf("|%0-20d|\n", 123); printf("|%0*d|\n", -20, 123); } --- stdio.asm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdio.asm b/stdio.asm index 1b2917f..2e440c1 100644 --- a/stdio.asm +++ b/stdio.asm @@ -4942,11 +4942,15 @@ Flag lda [format] get the character bne fl1 lda #1 left justify the output sta ~leftJustify + lda #' ' pad with spaces (ignore any '0' flag) + sta ~paddChar bra fl5 fl1 cmp #'0' if it is a '0' then bne fl2 - sta ~paddChar padd with '0' characters + ldx ~leftJustify if not left justifying then + bne fl5 + sta ~paddChar padd with '0' characters bra fl5 fl2 cmp #'+' if it is a '+' or ' ' then @@ -4988,6 +4992,8 @@ GetSize stz val assume a value of 0 inc a positive with - flag ldx #1 stx ~leftJustify + ldx #' ' + stx ~paddChar bra fv1 fv0 lda #0 negative precision is ignored stz ~precisionSpecified