updated to compile in pic16/
[fw/sdcc] / device / lib / printf_fast.c
index 09150b3267838e08b5d648e55393fe67f6f80d25..6f492c9d3925ac04b048020661439495d7147a71 100644 (file)
@@ -2,11 +2,11 @@
  * Copyright (c) 2001, Paul Stoffregen, paul@pjrc.com
  *
  * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
+ * modify it under the terms of the GNU Library General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
@@ -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
@@ -149,12 +155,12 @@ printf_eot:
 
 
        /* print a string... just grab each byte with __gptrget */
-       /* the user much pass a 24 bit _generic pointer */
+       /* the user much pass a 24 bit generic pointer */
 
 printf_string:
        push    dph             // save addr in fmt onto stack
        push    dpl
-       mov     b, @r0          // b has type of address (_generic *)
+       mov     b, @r0          // b has type of address (generic *)
        dec     r0
        mov     dph, @r0
        dec     r0
@@ -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: