You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/11/27 21:59:30 UTC

[nuttx] 04/04: libc/stdio: Remove putc macro from lib_libvsprintf.c

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 7c7ab96b5349203d69be387484a2137df8c50a8e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Nov 26 02:20:49 2022 +0800

    libc/stdio: Remove putc macro from lib_libvsprintf.c
    
    call lib_stream_put directly instead
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/stdio/lib_libvsprintf.c | 76 ++++++++++++++++++---------------------
 1 file changed, 34 insertions(+), 42 deletions(-)

diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c
index 9fb6c9117d..2a1ee104d6 100644
--- a/libs/libc/stdio/lib_libvsprintf.c
+++ b/libs/libc/stdio/lib_libvsprintf.c
@@ -67,14 +67,6 @@
 #  undef CONFIG_LIBC_LONG_LONG
 #endif
 
-/* [Re]define putc() */
-
-#ifdef putc
-#  undef putc
-#endif
-
-#define putc(c,stream)  (stream)->put(stream, c)
-
 /* Order is relevant here and matches order in format string */
 
 #define FL_ZFILL           0x0001
@@ -229,10 +221,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
 #ifdef CONFIG_LIBC_NUMBERED_ARGS
           if (stream != NULL)
             {
-              putc(c, stream);
+              lib_stream_put(stream, c);
             }
 #else
-          putc(c, stream);
+          lib_stream_put(stream, c);
 #endif
         }
 
@@ -661,7 +653,7 @@ flt_oper:
                     {
                       do
                         {
-                          putc(' ', stream);
+                          lib_stream_put(stream, ' ');
                         }
                       while (--width);
                     }
@@ -673,7 +665,7 @@ flt_oper:
 
               if (sign)
                 {
-                  putc(sign, stream);
+                  lib_stream_put(stream, sign);
                 }
 
               p = "inf";
@@ -692,7 +684,7 @@ flt_oper:
                       ndigs += 'I' - 'i';
                     }
 
-                  putc(ndigs, stream);
+                  lib_stream_put(stream, ndigs);
                   p++;
                 }
 
@@ -766,21 +758,21 @@ flt_oper:
             {
               while (width)
                 {
-                  putc(' ', stream);
+                  lib_stream_put(stream, ' ');
                   width--;
                 }
             }
 
           if (sign != 0)
             {
-              putc(sign, stream);
+              lib_stream_put(stream, sign);
             }
 
           if ((flags & FL_LPAD) == 0)
             {
               while (width)
                 {
-                  putc('0', stream);
+                  lib_stream_put(stream, '0');
                   width--;
                 }
             }
@@ -804,7 +796,7 @@ flt_oper:
 
                   if (n == -1)
                     {
-                      putc('.', stream);
+                      lib_stream_put(stream, '.');
                     }
 
                   /* Pull digits from buffer when in-range, otherwise use 0 */
@@ -822,13 +814,13 @@ flt_oper:
                     {
                       if ((flags & FL_ALT) != 0 && n == -1)
                         {
-                          putc('.', stream);
+                          lib_stream_put(stream, '.');
                         }
 
                       break;
                     }
 
-                  putc(out, stream);
+                  lib_stream_put(stream, out);
                 }
               while (1);
 
@@ -838,7 +830,7 @@ flt_oper:
                   out = '1';
                 }
 
-              putc(out, stream);
+              lib_stream_put(stream, out);
             }
           else
             {
@@ -852,25 +844,25 @@ flt_oper:
                   _dtoa.flags &= ~DTOA_CARRY;
                 }
 
-              putc(_dtoa.digits[0], stream);
+              lib_stream_put(stream, _dtoa.digits[0]);
               if (prec > 0)
                 {
                   uint8_t pos;
 
-                  putc('.', stream);
+                  lib_stream_put(stream, '.');
                   for (pos = 1; pos < 1 + prec; pos++)
                     {
-                      putc(pos < ndigs ? _dtoa.digits[pos] : '0', stream);
+                      lib_stream_put(stream, pos < ndigs ? _dtoa.digits[pos] : '0');
                     }
                 }
               else if ((flags & FL_ALT) != 0)
                 {
-                  putc('.', stream);
+                  lib_stream_put(stream, '.');
                 }
 
               /* Exponent */
 
-              putc(flags & FL_FLTUPP ? 'E' : 'e', stream);
+              lib_stream_put(stream, flags & FL_FLTUPP ? 'E' : 'e');
               ndigs = '+';
               if (exp < 0 || (exp == 0 && (_dtoa.flags & DTOA_CARRY) != 0))
                 {
@@ -878,7 +870,7 @@ flt_oper:
                   ndigs = '-';
                 }
 
-              putc(ndigs, stream);
+              lib_stream_put(stream, ndigs);
               for (ndigs = '0'; exp >= 10; exp -= 10)
                 {
                   ndigs += 1;
@@ -890,17 +882,17 @@ flt_oper:
                 {
                   if (ndigs >= 'd')
                     {
-                      putc(((ndigs - '0') / 100) + '0', stream);
+                      lib_stream_put(stream, ((ndigs - '0') / 100) + '0');
                       ndigs = (ndigs - '0') % 100 + '0';
                     }
                   else if (ndigs >= ':')
                     {
-                      putc(((ndigs - '0') / 10) + '0', stream);
+                      lib_stream_put(stream, ((ndigs - '0') / 10) + '0');
                       ndigs = (ndigs - '0') % 10 + '0';
                     }
                   else if(ndigs >= '0')
                     {
-                      putc(ndigs, stream);
+                      lib_stream_put(stream, ndigs);
                       break;
                     }
                   else
@@ -909,7 +901,7 @@ flt_oper:
                     }
                  }
 
-               putc('0' + exp, stream);
+               lib_stream_put(stream, '0' + exp);
             }
 
           goto tail;
@@ -972,14 +964,14 @@ str_lpad:
             {
               while (size < width)
                 {
-                  putc(' ', stream);
+                  lib_stream_put(stream, ' ');
                   width--;
                 }
             }
 
           while (size)
             {
-              putc(*pnt++, stream);
+              lib_stream_put(stream, *pnt++);
               if (width != 0)
                 {
                   width -= 1;
@@ -1189,7 +1181,7 @@ str_lpad:
                           pnt = symbol->sym_name;
                           while (*pnt != '\0')
                             {
-                              putc(*pnt++, stream);
+                              lib_stream_put(stream, *pnt++);
                             }
 
                           if (c == 'S')
@@ -1234,8 +1226,8 @@ str_lpad:
               break;
 
             default:
-              putc('%', stream);
-              putc(c, stream);
+              lib_stream_put(stream, '%');
+              lib_stream_put(stream, c);
               continue;
             }
 
@@ -1303,7 +1295,7 @@ str_lpad:
 
           while (len < width)
             {
-              putc(' ', stream);
+              lib_stream_put(stream, ' ');
               len++;
             }
         }
@@ -1312,10 +1304,10 @@ str_lpad:
 
       if ((flags & FL_ALT) != 0)
         {
-          putc('0', stream);
+          lib_stream_put(stream, '0');
           if ((flags & FL_ALTHEX) != 0)
             {
-              putc(flags & FL_ALTUPP ? 'X' : 'x', stream);
+              lib_stream_put(stream, flags & FL_ALTUPP ? 'X' : 'x');
             }
         }
       else if ((flags & (FL_NEGATIVE | FL_PLUS | FL_SPACE)) != 0)
@@ -1331,18 +1323,18 @@ str_lpad:
               z = '-';
             }
 
-          putc(z, stream);
+          lib_stream_put(stream, z);
         }
 
       while (prec > c)
         {
-          putc('0', stream);
+          lib_stream_put(stream, '0');
           prec--;
         }
 
       while (c)
         {
-          putc(buf[--c], stream);
+          lib_stream_put(stream, buf[--c]);
         }
 
 tail:
@@ -1351,7 +1343,7 @@ tail:
 
       while (width)
         {
-          putc(' ', stream);
+          lib_stream_put(stream, ' ');
           width--;
         }
     }