|
|
@ -0,0 +1,149 @@ |
|
|
|
Index: ./lib/__v_printf.c
|
|
|
|
===================================================================
|
|
|
|
RCS file: /cvs/dietlibc/lib/__v_printf.c,v |
|
|
|
retrieving revision 1.33 |
|
|
|
retrieving revision 1.35 |
|
|
|
diff -u -r1.33 -r1.35
|
|
|
|
--- ./lib/__v_printf.c 10 Jan 2007 22:51:09 -0000 1.33
|
|
|
|
+++ ./lib/__v_printf.c 17 May 2007 05:00:42 -0000 1.35
|
|
|
|
@@ -19,9 +19,9 @@
|
|
|
|
#define B_WRITE(fn,buf,sz) { if ((unsigned long)(sz) > (((unsigned long)(int)(-1))>>1) || len+(int)(sz)<len) return -1; A_WRITE(fn,buf,sz); } while (0) |
|
|
|
|
|
|
|
static const char pad_line[2][16]= { " ", "0000000000000000", }; |
|
|
|
-static int write_pad(int* dlen,struct arg_printf* fn, int len, int padwith) {
|
|
|
|
+static int write_pad(unsigned int* dlen,struct arg_printf* fn, unsigned int len, int padwith) {
|
|
|
|
int nr=0; |
|
|
|
- if (len<0 || *dlen+len<len) return -1;
|
|
|
|
+ if ((int)len<0 || *dlen+len<len) return -1;
|
|
|
|
for (;len>15;len-=16,nr+=16) { |
|
|
|
A_WRITE(fn,pad_line[(padwith=='0')?1:0],16); |
|
|
|
} |
|
|
|
@@ -34,7 +34,7 @@
|
|
|
|
|
|
|
|
int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr) |
|
|
|
{ |
|
|
|
- int len=0;
|
|
|
|
+ unsigned int len=0;
|
|
|
|
#ifdef WANT_ERROR_PRINTF |
|
|
|
int _errno = errno; |
|
|
|
#endif |
|
|
|
@@ -51,7 +51,7 @@
|
|
|
|
#define s u_str.s |
|
|
|
|
|
|
|
int retval; |
|
|
|
- unsigned char ch, padwith=' ';
|
|
|
|
+ unsigned char ch, padwith=' ', precpadwith=' ';
|
|
|
|
|
|
|
|
char flag_in_sign=0; |
|
|
|
char flag_upcase=0; |
|
|
|
@@ -172,7 +172,7 @@
|
|
|
|
if (flag_dot && sz>preci) sz=preci; |
|
|
|
preci=0; |
|
|
|
flag_dot^=flag_dot; |
|
|
|
- padwith=' ';
|
|
|
|
+ padwith=precpadwith=' ';
|
|
|
|
|
|
|
|
print_out: |
|
|
|
{ |
|
|
|
@@ -192,46 +192,46 @@
|
|
|
|
sz-=todo; |
|
|
|
width-=todo; |
|
|
|
} |
|
|
|
-
|
|
|
|
- if (!flag_left) {
|
|
|
|
- if (flag_dot) {
|
|
|
|
- vs=preci>sz?preci:sz;
|
|
|
|
- if (write_pad(&len,fn,(signed int)width-(signed int)vs,' '))
|
|
|
|
- return -1;
|
|
|
|
- if (todo) {
|
|
|
|
- B_WRITE(fn,sign,todo);
|
|
|
|
- len+=todo;
|
|
|
|
- }
|
|
|
|
- if (write_pad(&len,fn,(signed int)preci-(signed int)sz,'0'))
|
|
|
|
- return -1;
|
|
|
|
- } else {
|
|
|
|
- if (todo && padwith=='0') {
|
|
|
|
- B_WRITE(fn,sign,todo);
|
|
|
|
- len+=todo; todo=0;
|
|
|
|
- }
|
|
|
|
- if (write_pad(&len,fn,(signed int)width-(signed int)sz, padwith))
|
|
|
|
- return -1;
|
|
|
|
- if (todo) {
|
|
|
|
- B_WRITE(fn,sign,todo);
|
|
|
|
- len+=todo;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- B_WRITE(fn,s,sz); len+=sz;
|
|
|
|
- } else if (flag_left) {
|
|
|
|
- if (todo) {
|
|
|
|
- B_WRITE(fn,sign,todo);
|
|
|
|
- len+=todo;
|
|
|
|
- }
|
|
|
|
- if (write_pad(&len,fn,(signed int)preci-(signed int)sz, '0'))
|
|
|
|
+
|
|
|
|
+ /* These are the cases for 1234 or "1234" respectively:
|
|
|
|
+ %.6u -> "001234"
|
|
|
|
+ %6u -> " 1234"
|
|
|
|
+ %06u -> "001234"
|
|
|
|
+ %-6u -> "1234 "
|
|
|
|
+ %.6s -> "1234"
|
|
|
|
+ %6s -> " 1234"
|
|
|
|
+ %06s -> " 1234"
|
|
|
|
+ %-6s -> "1234 "
|
|
|
|
+ %6.5u -> " 01234"
|
|
|
|
+ %6.5s -> " 1234"
|
|
|
|
+ In this code, for %6.5s, 6 is width, 5 is preci.
|
|
|
|
+ flag_dot means there was a '.' and preci is set.
|
|
|
|
+ flag_left means there was a '-'.
|
|
|
|
+ sz is 4 (strlen("1234")).
|
|
|
|
+ padwith will be '0' for %06u, ' ' otherwise.
|
|
|
|
+ precpadwith is '0' for %u, ' ' for %s.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ if (flag_dot && width==0) width=preci;
|
|
|
|
+ if (!flag_dot) preci=sz;
|
|
|
|
+ if (!flag_left) { /* do left-side padding */
|
|
|
|
+ if (write_pad(&len,fn,width-preci,padwith))
|
|
|
|
return -1; |
|
|
|
- B_WRITE(fn,s,sz); len+=sz;
|
|
|
|
- vs=preci>sz?preci:sz;
|
|
|
|
- if ((signed int)width-(signed int)vs<0) return -1;
|
|
|
|
- if (write_pad(&len,fn,(signed int)width-(signed int)vs, ' '))
|
|
|
|
+ }
|
|
|
|
+ if (todo) {
|
|
|
|
+ B_WRITE(fn,sign,todo);
|
|
|
|
+ len+=todo;
|
|
|
|
+ }
|
|
|
|
+ /* do preci padding */
|
|
|
|
+ if (write_pad(&len,fn,preci-sz,precpadwith))
|
|
|
|
+ return -1;
|
|
|
|
+ /* write actual string */
|
|
|
|
+ B_WRITE(fn,s,sz); len+=sz;
|
|
|
|
+ if (flag_left) {
|
|
|
|
+ if (write_pad(&len,fn,width-preci,padwith))
|
|
|
|
return -1; |
|
|
|
- } else {
|
|
|
|
- B_WRITE(fn,s,sz); len+=sz;
|
|
|
|
} |
|
|
|
+
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -327,6 +327,8 @@
|
|
|
|
++sz; |
|
|
|
} else flag_in_sign=0; |
|
|
|
|
|
|
|
+ precpadwith='0';
|
|
|
|
+
|
|
|
|
goto print_out; |
|
|
|
|
|
|
|
#ifdef WANT_FLOATING_POINT_IN_PRINTF |
|
|
|
@@ -374,6 +376,8 @@
|
|
|
|
} |
|
|
|
|
|
|
|
sz=strlen(s); |
|
|
|
+ if (width<sz) width=sz;
|
|
|
|
+ padwith='0';
|
|
|
|
flag_dot=0; |
|
|
|
flag_hash=0; |
|
|
|
goto print_out; |