Add leading zero format to printf_fast ("%07d", "%017lu", etc)
authorpjs <pjs@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 7 Apr 2003 01:56:14 +0000 (01:56 +0000)
committerpjs <pjs@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 7 Apr 2003 01:56:14 +0000 (01:56 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2489 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/lib/printf_fast.c

index 636e61b4a3fbb79666f93486a7627adae9e2c7cf..e82a278bced165937a559ecaf50653dcb9636d52 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2003-04-06    Paul Stoffregen <paul@pjrc.com>
+
+       * device/lib/printf_fast.c: added leading zero format ("%06d", etc)
+
 2003-04-06    Paul Stoffregen <paul@pjrc.com>
 
        * src/SDCCpeeph.c: added labelIsReturnOnly test
index fc067d18ece1fb964bf5620a9858492f6716ef4a..6f492c9d3925ac04b048020661439495d7147a71 100644 (file)
@@ -31,6 +31,7 @@ static bit long_flag, short_flag, print_zero_flag, negative_flag;
 
 #ifdef FIELD_WIDTH
 static bit field_width_flag;
+static bit leading_zero_flag;
 static data unsigned char field_width;
 #endif
 
@@ -64,6 +65,7 @@ printf_format:
        clr     _negative_flag
 #ifdef FIELD_WIDTH
        clr     _field_width_flag
+       clr     _leading_zero_flag
        mov     _field_width, #0
 #endif
 
@@ -80,6 +82,10 @@ printf_format_loop:
        jnc     printf_nondigit2
 #ifdef FIELD_WIDTH
 printf_digit:
+       jnz     printf_digit_2
+       cjne    a, _field_width, printf_digit_2
+       setb    _leading_zero_flag
+printf_digit_2:
        setb    _field_width_flag
        mov     r1, a
        mov     a, _field_width
@@ -163,6 +169,7 @@ printf_string:
 
 #ifdef FIELD_WIDTH
        jnb     _field_width_flag, printf_str_loop
+       clr     _leading_zero_flag      // never leading zeros for strings
        push    dpl
        push    dph
 printf_str_fw_loop:
@@ -660,6 +667,10 @@ printf_bcd_add10:
 printf_space_loop:
        //mov   a, #' '
        mov     a, #32
+       jnb     _leading_zero_flag, printf_space_output
+       //mov   a, #'0'
+       mov     a, #48
+printf_space_output:
        lcall   printf_putchar
        dec     _field_width
 printf_space: