OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.9 KiB

  1. Index: ./lib/__v_printf.c
  2. ===================================================================
  3. RCS file: /cvs/dietlibc/lib/__v_printf.c,v
  4. retrieving revision 1.33
  5. retrieving revision 1.35
  6. diff -u -r1.33 -r1.35
  7. --- ./lib/__v_printf.c 10 Jan 2007 22:51:09 -0000 1.33
  8. +++ ./lib/__v_printf.c 17 May 2007 05:00:42 -0000 1.35
  9. @@ -19,9 +19,9 @@
  10. #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)
  11. static const char pad_line[2][16]= { " ", "0000000000000000", };
  12. -static int write_pad(int* dlen,struct arg_printf* fn, int len, int padwith) {
  13. +static int write_pad(unsigned int* dlen,struct arg_printf* fn, unsigned int len, int padwith) {
  14. int nr=0;
  15. - if (len<0 || *dlen+len<len) return -1;
  16. + if ((int)len<0 || *dlen+len<len) return -1;
  17. for (;len>15;len-=16,nr+=16) {
  18. A_WRITE(fn,pad_line[(padwith=='0')?1:0],16);
  19. }
  20. @@ -34,7 +34,7 @@
  21. int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr)
  22. {
  23. - int len=0;
  24. + unsigned int len=0;
  25. #ifdef WANT_ERROR_PRINTF
  26. int _errno = errno;
  27. #endif
  28. @@ -51,7 +51,7 @@
  29. #define s u_str.s
  30. int retval;
  31. - unsigned char ch, padwith=' ';
  32. + unsigned char ch, padwith=' ', precpadwith=' ';
  33. char flag_in_sign=0;
  34. char flag_upcase=0;
  35. @@ -172,7 +172,7 @@
  36. if (flag_dot && sz>preci) sz=preci;
  37. preci=0;
  38. flag_dot^=flag_dot;
  39. - padwith=' ';
  40. + padwith=precpadwith=' ';
  41. print_out:
  42. {
  43. @@ -192,46 +192,46 @@
  44. sz-=todo;
  45. width-=todo;
  46. }
  47. -
  48. - if (!flag_left) {
  49. - if (flag_dot) {
  50. - vs=preci>sz?preci:sz;
  51. - if (write_pad(&len,fn,(signed int)width-(signed int)vs,' '))
  52. - return -1;
  53. - if (todo) {
  54. - B_WRITE(fn,sign,todo);
  55. - len+=todo;
  56. - }
  57. - if (write_pad(&len,fn,(signed int)preci-(signed int)sz,'0'))
  58. - return -1;
  59. - } else {
  60. - if (todo && padwith=='0') {
  61. - B_WRITE(fn,sign,todo);
  62. - len+=todo; todo=0;
  63. - }
  64. - if (write_pad(&len,fn,(signed int)width-(signed int)sz, padwith))
  65. - return -1;
  66. - if (todo) {
  67. - B_WRITE(fn,sign,todo);
  68. - len+=todo;
  69. - }
  70. - }
  71. - B_WRITE(fn,s,sz); len+=sz;
  72. - } else if (flag_left) {
  73. - if (todo) {
  74. - B_WRITE(fn,sign,todo);
  75. - len+=todo;
  76. - }
  77. - if (write_pad(&len,fn,(signed int)preci-(signed int)sz, '0'))
  78. +
  79. + /* These are the cases for 1234 or "1234" respectively:
  80. + %.6u -> "001234"
  81. + %6u -> " 1234"
  82. + %06u -> "001234"
  83. + %-6u -> "1234 "
  84. + %.6s -> "1234"
  85. + %6s -> " 1234"
  86. + %06s -> " 1234"
  87. + %-6s -> "1234 "
  88. + %6.5u -> " 01234"
  89. + %6.5s -> " 1234"
  90. + In this code, for %6.5s, 6 is width, 5 is preci.
  91. + flag_dot means there was a '.' and preci is set.
  92. + flag_left means there was a '-'.
  93. + sz is 4 (strlen("1234")).
  94. + padwith will be '0' for %06u, ' ' otherwise.
  95. + precpadwith is '0' for %u, ' ' for %s.
  96. + */
  97. +
  98. + if (flag_dot && width==0) width=preci;
  99. + if (!flag_dot) preci=sz;
  100. + if (!flag_left) { /* do left-side padding */
  101. + if (write_pad(&len,fn,width-preci,padwith))
  102. return -1;
  103. - B_WRITE(fn,s,sz); len+=sz;
  104. - vs=preci>sz?preci:sz;
  105. - if ((signed int)width-(signed int)vs<0) return -1;
  106. - if (write_pad(&len,fn,(signed int)width-(signed int)vs, ' '))
  107. + }
  108. + if (todo) {
  109. + B_WRITE(fn,sign,todo);
  110. + len+=todo;
  111. + }
  112. + /* do preci padding */
  113. + if (write_pad(&len,fn,preci-sz,precpadwith))
  114. + return -1;
  115. + /* write actual string */
  116. + B_WRITE(fn,s,sz); len+=sz;
  117. + if (flag_left) {
  118. + if (write_pad(&len,fn,width-preci,padwith))
  119. return -1;
  120. - } else {
  121. - B_WRITE(fn,s,sz); len+=sz;
  122. }
  123. +
  124. break;
  125. }
  126. @@ -327,6 +327,8 @@
  127. ++sz;
  128. } else flag_in_sign=0;
  129. + precpadwith='0';
  130. +
  131. goto print_out;
  132. #ifdef WANT_FLOATING_POINT_IN_PRINTF
  133. @@ -374,6 +376,8 @@
  134. }
  135. sz=strlen(s);
  136. + if (width<sz) width=sz;
  137. + padwith='0';
  138. flag_dot=0;
  139. flag_hash=0;
  140. goto print_out;