+const char * parse_out( const char * spec, struct status_t * status, va_list ap );
+inline void test( char * buffer, size_t n, const char * expect, struct status_t * status, ... );
+
+/* The following only for testing. */
+#include <limits.h>
+#include <string.h>
+
+int main( void )
+{
+ struct status_t status;
+ char * buffer = malloc( 50 );
+ status.s = calloc( 50, 1 );
+ status.i = 0;
+ status.stream = NULL;
+ status.n = SIZE_MAX;
+ puts( "- Signed min / max -\n" );
+// inline void test( char * buffer, size_t n, const char * expect, struct status_t * status, ... );
+ test( buffer, SIZE_MAX, "%hhd", &status, CHAR_MIN );
+ test( buffer, SIZE_MAX, "%hhd", &status, CHAR_MAX );
+ test( buffer, SIZE_MAX, "%hhd", &status, 0 );
+ test( buffer, SIZE_MAX, "%hd", &status, SHRT_MIN );
+ test( buffer, SIZE_MAX, "%hd", &status, SHRT_MAX );
+ test( buffer, SIZE_MAX, "%hd", &status, 0 );
+ test( buffer, SIZE_MAX, "%d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%d", &status, 0 );
+ test( buffer, SIZE_MAX, "%ld", &status, LONG_MIN );
+ test( buffer, SIZE_MAX, "%ld", &status, LONG_MAX );
+ test( buffer, SIZE_MAX, "%ld", &status, 0l );
+ test( buffer, SIZE_MAX, "%lld", &status, LLONG_MIN );
+ test( buffer, SIZE_MAX, "%lld", &status, LLONG_MAX );
+ test( buffer, SIZE_MAX, "%lld", &status, 0ll );
+ puts( "- Unsigned min / max -\n" );
+ test( buffer, SIZE_MAX, "%hhu", &status, UCHAR_MAX );
+ test( buffer, SIZE_MAX, "%hhu", &status, (unsigned char)-1 );
+ test( buffer, SIZE_MAX, "%hu", &status, USHRT_MAX );
+ test( buffer, SIZE_MAX, "%hu", &status, (unsigned short)-1 );
+ test( buffer, SIZE_MAX, "%u", &status, UINT_MAX );
+ test( buffer, SIZE_MAX, "%u", &status, -1u );
+ test( buffer, SIZE_MAX, "%lu", &status, ULONG_MAX );
+ test( buffer, SIZE_MAX, "%lu", &status, -1ul );
+ test( buffer, SIZE_MAX, "%llu", &status, ULLONG_MAX );
+ test( buffer, SIZE_MAX, "%llu", &status, -1ull );
+ puts( "- Hex and Octal, normal and alternative, upper and lowercase -\n" );
+ test( buffer, SIZE_MAX, "%X", &status, UINT_MAX );
+ test( buffer, SIZE_MAX, "%#X", &status, -1u );
+ test( buffer, SIZE_MAX, "%x", &status, UINT_MAX );
+ test( buffer, SIZE_MAX, "%#x", &status, -1u );
+ test( buffer, SIZE_MAX, "%o", &status, UINT_MAX );
+ test( buffer, SIZE_MAX, "%#o", &status, -1u );
+ puts( "- Plus flag -\n" );
+ test( buffer, SIZE_MAX, "%+d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%+d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%+d", &status, 0 );
+ test( buffer, SIZE_MAX, "%+u", &status, UINT_MAX );
+ test( buffer, SIZE_MAX, "%+u", &status, -1u );
+ puts( "- Space flag -\n" );
+ test( buffer, SIZE_MAX, "% d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "% d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "% d", &status, 0 );
+ test( buffer, SIZE_MAX, "% u", &status, UINT_MAX );
+ test( buffer, SIZE_MAX, "% u", &status, -1u );
+ puts( "- Field width -\n" );
+ test( buffer, SIZE_MAX, "%9d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%9d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%10d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%10d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%11d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%11d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%12d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%12d", &status, INT_MAX );
+ puts( "- Field width (left bound) -\n" );
+ test( buffer, SIZE_MAX, "%-9d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-9d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%-10d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-10d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%-11d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-11d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%-12d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-12d", &status, INT_MAX );
+ puts( "- Field width, zero padding -\n");
+ test( buffer, SIZE_MAX, "%09d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%09d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%010d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%010d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%011d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%011d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%012d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%012d", &status, INT_MAX );
+ puts( "- Field width, zero padding (left bound) -\n" );
+ test( buffer, SIZE_MAX, "%-09d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-09d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%-010d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-010d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%-011d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-011d", &status, INT_MAX );
+ test( buffer, SIZE_MAX, "%-012d", &status, INT_MIN );
+ test( buffer, SIZE_MAX, "%-012d", &status, INT_MAX );
+ return 0;
+}
+