]> pd.if.org Git - pdclib.old/commitdiff
PDCLIB-20 #resolve Add support for "unusual" cases. Ammend test suite to verify support.
authorOwen Shepherd <owen.shepherd@e43.eu>
Tue, 23 Apr 2013 18:29:41 +0000 (19:29 +0100)
committerOwen Shepherd <owen.shepherd@e43.eu>
Tue, 23 Apr 2013 18:29:41 +0000 (19:29 +0100)
functions/stdio/_PDCLIB_print.c
functions/stdio/fprintf.c
functions/stdio/printf.c
functions/stdio/snprintf.c
functions/stdio/sprintf.c
functions/stdio/vfprintf.c
functions/stdio/vprintf.c
functions/stdio/vsnprintf.c
functions/stdio/vsprintf.c
testing/printf_testcases.h

index ec7dc4a33b1f6914510f15af73813b7786c6d7db..21177af13a2f49ad9e8e1d2025bd72544de50546 100644 (file)
@@ -30,6 +30,7 @@
 #define E_space    (1<<3)
 #define E_zero     (1<<4)
 #define E_done     (1<<5)
+
 #define E_char     (1<<6)
 #define E_short    (1<<7)
 #define E_long     (1<<8)
 #define E_size     (1<<11)
 #define E_ptrdiff  (1<<12)
 #define E_intptr   (1<<13)
+
 #define E_ldouble  (1<<14)
+
 #define E_lower    (1<<15)
 #define E_unsigned (1<<16)
 
+#define E_TYPES (E_char | E_short | E_long | E_llong | E_intmax \
+                | E_size | E_ptrdiff | E_intptr)
+
 /* This macro delivers a given character to either a memory buffer or a stream,
    depending on the contents of 'status' (struct _PDCLIB_status_t).
    x - the character to be delivered
@@ -423,9 +429,8 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status
                 return ++spec;
             }
         case 'p':
-            /* TODO: E_long -> E_intptr */
             status->base = 16;
-            status->flags |= ( E_lower | E_unsigned | E_alt | E_long );
+            status->flags |= ( E_lower | E_unsigned | E_alt | E_intptr );
             break;
         case 'n':
            {
@@ -437,7 +442,6 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status
             /* No conversion specifier. Bad conversion. */
             return orig_spec;
     }
-
     /* Do the actual output based on our findings */
     if ( status->base != 0 )
     {
@@ -446,7 +450,7 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status
         if ( status->flags & E_unsigned )
         {
             uintmax_t value;
-            switch ( status->flags & ( E_char | E_short | E_long | E_llong | E_size ) )
+            switch ( status->flags & E_TYPES )
             {
                 case E_char:
                     value = (uintmax_t)(unsigned char)va_arg( status->arg, int );
@@ -466,12 +470,20 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status
                 case E_size:
                     value = (uintmax_t)va_arg( status->arg, size_t );
                     break;
+                case E_intptr:
+                    value = (uintmax_t)va_arg( status->arg, uintptr_t );
+                    break;
+                case E_ptrdiff:
+                    value = (uintmax_t)va_arg( status->arg, ptrdiff_t );
+                    break;
+                case E_intmax:
+                    value = va_arg( status->arg, uintmax_t );
             }
             int2base( value, status );
         }
         else
         {
-            switch ( status->flags & ( E_char | E_short | E_long | E_llong | E_intmax ) )
+            switch ( status->flags & E_TYPES )
             {
                 case E_char:
                     int2base( (intmax_t)(char)va_arg( status->arg, int ), status );
@@ -488,6 +500,12 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status
                 case E_llong:
                     int2base( (intmax_t)va_arg( status->arg, long long ), status );
                     break;
+                case E_size:
+                    int2base( (intmax_t)va_arg( status->arg, size_t ), status );
+                    break;
+                case E_intptr:
+                    int2base( (intmax_t)va_arg( status->arg, intptr_t ), status );
+                    break;
                 case E_ptrdiff:
                     int2base( (intmax_t)va_arg( status->arg, ptrdiff_t ), status );
                     break;
index 66566a4d5a6fb953e57a3a15df3defacec8b2daa..07283b2d162dc5ac0c6c80bfc32d515ab94aef1c 100644 (file)
@@ -39,6 +39,8 @@ int fprintf( FILE * _PDCLIB_restrict stream,
 #endif
 
 #ifdef TEST
+#include <stdint.h>
+#include <stddef.h>
 #define _PDCLIB_FILEID "stdio/fprintf.c"
 #define _PDCLIB_FILEIO
 
index 2b147e4b63f0e659b94a130c0ce1cff056c3af37..9dcb4fc0fdcd73fe49da53ad1d4ee87d54292d43 100644 (file)
@@ -37,6 +37,8 @@ int _PDCLIB_printf_unlocked( const char * _PDCLIB_restrict format, ... )
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/printf.c"
 #define _PDCLIB_FILEIO
+#include <stdint.h>
+#include <stddef.h>
 
 #include <_PDCLIB_test.h>
 
index 564436a2612d9f22141a246a5856eba471bb3cab..69d4106ffe74305cc47b2f4f1cab5a579b19cc1b 100644 (file)
@@ -26,6 +26,8 @@ int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/snprintf.c"
 #define _PDCLIB_STRINGIO
+#include <stdint.h>
+#include <stddef.h>
 
 #include <_PDCLIB_test.h>
 
index 4f4a5d4a37a609b3b0ab89ff94dff4ef26067945..11328eedd3eb4d65142ee8533459d00a8a2cb81a 100644 (file)
@@ -27,6 +27,7 @@ int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ..
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/sprintf.c"
 #define _PDCLIB_STRINGIO
+#include <stddef.h>
 
 #include <_PDCLIB_test.h>
 
index 9be5b2d7f29b1cf89138c4036826984ea080965e..7dd7f2dfe1e6b4855c99b2217e063fce91ebf1da 100644 (file)
@@ -65,7 +65,7 @@ int vfprintf( FILE * _PDCLIB_restrict stream,
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/vfprintf.c"
 #define _PDCLIB_FILEIO
-
+#include <stddef.h>
 #include <_PDCLIB_test.h>
 
 static int testprintf( FILE * stream, const char * format, ... )
index ae2b0377863a94674e1a45eb2b5afe21472938d6..6d2b55c9b4d3e839bb87e6d138f6cf6439c3fc08 100644 (file)
@@ -28,7 +28,8 @@ int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg )
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/vprintf.c"
 #define _PDCLIB_FILEIO
-
+#include <stdint.h>
+#include <stddef.h>
 #include <_PDCLIB_test.h>
 
 static int testprintf( FILE * stream, const char * format, ... )
index fd29580db984b072ed1d80b699b51b97d452f167..cda7ab6579d4f45ef9d47580fb5ef540e070d094 100644 (file)
@@ -62,7 +62,8 @@ int vsnprintf( char * _PDCLIB_restrict s,
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/vsnprintf.c"
 #define _PDCLIB_STRINGIO
-
+#include <stdint.h>
+#include <stddef.h>
 #include <_PDCLIB_test.h>
 
 static int testprintf( char * s, const char * format, ... )
index 5f08688b7c00825e36eaaa2914f86ccb4cbfa261..9ace50dc85047806abe1dc5a00ed52edbf1ae872 100644 (file)
@@ -24,7 +24,8 @@ int vsprintf( char * _PDCLIB_restrict s,
 #ifdef TEST
 #define _PDCLIB_FILEID "stdio/vsprintf.c"
 #define _PDCLIB_STRINGIO
-
+#include <stdint.h>
+#include <stddef.h>
 #include <_PDCLIB_test.h>
 
 static int testprintf( char * s, const char * format, ... )
index f7f1413dfcde7d9aa710b581847d14d04e4611a4..a36be11eff79e845a454b55be98c418a5ece360d 100644 (file)
     }
 #endif
     }
+    /* PDCLIB-20: Verify "unusual" combinations of length and signedness */
+    PRINTF_TEST( 1,  "1", "%tu", (ptrdiff_t)  1); // unsigned prtdiff_t
+    PRINTF_TEST( 2, "-1", "%jd", (intmax_t)  -1); // intmax_t
+    PRINTF_TEST( 1,  "1", "%ju", (uintmax_t)  1); // uintmax_t
+    PRINTF_TEST( 1,  "1", "%zd", (size_t)     1); // signed size_t
 
 #ifndef TEST_CONVERSION_ONLY
 /******************************************************************************