<commit_before>#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

/* These can be removed once integrated into PDCLIB make procedure */
#undef TEST
#include </home/solar/src/pdclib/functions/_PDCLIB/digits.c>
#include </home/solar/src/pdclib/functions/_PDCLIB/Xdigits.c>

/* Using an integer's bits as flags for both the conversion flags and length
   modifiers.
*/
#define E_minus    1<<0
#define E_plus     1<<1
#define E_alt      1<<2
#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_llong    1<<9
#define E_intmax   1<<10
#define E_size     1<<11
#define E_ptrdiff  1<<12
#define E_double   1<<13
#define E_lower    1<<14
#define E_unsigned 1<<15

struct status_t
{
    int           base;  /* base to which the value shall be converted       */
    int_fast32_t  flags; /* flags and length modifiers                       */
    size_t        n;     /* maximum number of characters to be written       */
    size_t        i;     /* number of characters already written             */
    size_t        this;  /* number of output chars in the current conversion */
    char *        s;     /* target buffer                                    */
    size_t        width; /* width of current field                           */
    size_t        prec;  /* precision of current field                       */
    FILE *        stream;/* for to-stream output                             */
    va_list       ap;    /* the argument stack passed to the printf function */
};

const char * parse_out( const char * spec, struct status_t * status );
inline void test( size_t n, const char * expect, ... );
int _PDCLIB_sprintf( char * buffer, size_t n, const char * format, va_list ap );

/* The following only for testing. */
#include <limits.h>
#include <string.h>

int main( void )
{
    puts( "- Signed min / max -\n" );
    test( SIZE_MAX, "%hhd", CHAR_MIN );
    test( SIZE_MAX, "%hhd", CHAR_MAX );
    test( SIZE_MAX, "%hhd", 0 );
    test( SIZE_MAX, "%hd", SHRT_MIN );
    test( SIZE_MAX, "%hd", SHRT_MAX );
    test( SIZE_MAX, "%hd", 0 );
    test( SIZE_MAX, "%d", INT_MIN );
    test( SIZE_MAX, "%d", INT_MAX );
    test( SIZE_MAX, "%d", 0 );
    test( SIZE_MAX, "%ld", LONG_MIN );
    test( SIZE_MAX, "%ld", LONG_MAX );
    test( SIZE_MAX, "%ld", 0l );
    test( SIZE_MAX, "%lld", LLONG_MIN );
    test( SIZE_MAX, "%lld", LLONG_MAX );
    test( SIZE_MAX, "%lld", 0ll );
    puts( "- Unsigned min / max -\n" );
    test( SIZE_MAX, "%hhu", UCHAR_MAX );
    test( SIZE_MAX, "%hhu", (unsigned char)-1 );
    test( SIZE_MAX, "%hu", USHRT_MAX );
    test( SIZE_MAX, "%hu", (unsigned short)-1 );
    test( SIZE_MAX, "%u", UINT_MAX );
    test( SIZE_MAX, "%u", -1u );
    test( SIZE_MAX, "%lu", ULONG_MAX );
    test( SIZE_MAX, "%lu", -1ul );
    test( SIZE_MAX, "%llu", ULLONG_MAX );
    test( SIZE_MAX, "%llu", -1ull );
    puts( "- Hex and Octal, normal and alternative, upper and lowercase -\n" );
    test( SIZE_MAX, "%X", UINT_MAX );
    test( SIZE_MAX, "%#X", -1u );
    test( SIZE_MAX, "%x", UINT_MAX );
    test( SIZE_MAX, "%#x", -1u );
    test( SIZE_MAX, "%o", UINT_MAX );
    test( SIZE_MAX, "%#o", -1u );
    puts( "- Plus flag -\n" );
    test( SIZE_MAX, "%+d", INT_MIN );
    test( SIZE_MAX, "%+d", INT_MAX );
    test( SIZE_MAX, "%+d", 0 );
    test( SIZE_MAX, "%+u", UINT_MAX );
    test( SIZE_MAX, "%+u", -1u );
    puts( "- Space flag -\n" );
    test( SIZE_MAX, "% d", INT_MIN );
    test( SIZE_MAX, "% d", INT_MAX );
    test( SIZE_MAX, "% d", 0 );
    test( SIZE_MAX, "% u", UINT_MAX );
    test( SIZE_MAX, "% u", -1u );
    puts( "- Field width -\n" );
    test( SIZE_MAX, "%9d", INT_MIN );
    test( SIZE_MAX, "%9d", INT_MAX );
    test( SIZE_MAX, "%10d", INT_MIN );
    test( SIZE_MAX, "%10d", INT_MAX );
    test( SIZE_MAX, "%11d", INT_MIN );
    test( SIZE_MAX, "%11d", INT_MAX );
    test( SIZE_MAX, "%12d", INT_MIN );
    test( SIZE_MAX, "%12d", INT_MAX );
    puts( "- Field width (left bound) -\n" );
    test( SIZE_MAX, "%-9d", INT_MIN );
    test( SIZE_MAX, "%-9d", INT_MAX );
    test( SIZE_MAX, "%-10d", INT_MIN );
    test( SIZE_MAX, "%-10d", INT_MAX );
    test( SIZE_MAX, "%-11d", INT_MIN );
    test( SIZE_MAX, "%-11d", INT_MAX );
    test( SIZE_MAX, "%-12d", INT_MIN );
    test( SIZE_MAX, "%-12d", INT_MAX );
    puts( "- Field width, zero padding -\n");
    test( SIZE_MAX, "%09d", INT_MIN );
    test( SIZE_MAX, "%09d", INT_MAX );
    test( SIZE_MAX, "%010d", INT_MIN );
    test( SIZE_MAX, "%010d", INT_MAX );
    test( SIZE_MAX, "%011d", INT_MIN );
    test( SIZE_MAX, "%011d", INT_MAX );
    test( SIZE_MAX, "%012d", INT_MIN );
    test( SIZE_MAX, "%012d", INT_MAX );
    puts( "- Field width, zero padding (left bound) -\n" );
    test( SIZE_MAX, "%-09d", INT_MIN );
    test( SIZE_MAX, "%-09d", INT_MAX );
    test( SIZE_MAX, "%-010d", INT_MIN );
    test( SIZE_MAX, "%-010d", INT_MAX );
    test( SIZE_MAX, "%-011d", INT_MIN );
    test( SIZE_MAX, "%-011d", INT_MAX );
    test( SIZE_MAX, "%-012d", INT_MIN );
    test( SIZE_MAX, "%-012d", INT_MAX );
    puts( "- Limited n -\n" );
    test( 8, "%9d", INT_MAX );
    test( 8, "%9d", INT_MIN );
    test( 9, "%9d", INT_MAX );
    test( 9, "%9d", INT_MIN );
    test( 10, "%9d", INT_MAX );
    test( 10, "%9d", INT_MIN );
    test( 9, "%10d", INT_MAX );
    test( 9, "%10d", INT_MIN );
    test( 10, "%10d", INT_MAX );
    test( 10, "%10d", INT_MIN );
    test( 11, "%10d", INT_MAX );
    test( 11, "%10d", INT_MIN );
    test( 10, "%11d", INT_MAX );
    test( 10, "%11d", INT_MIN );
    test( 11, "%11d", INT_MAX );
    test( 11, "%11d", INT_MIN );
    test( 12, "%11d", INT_MAX );
    test( 12, "%11d", INT_MIN );
    test( 11, "%12d", INT_MAX );
    test( 11, "%12d", INT_MIN );
    test( 12, "%12d", INT_MAX );
    test( 12, "%12d", INT_MIN );
    test( 13, "%12d", INT_MAX );
    test( 13, "%12d", INT_MIN );
    puts( "- Precision -\n" );
    test( SIZE_MAX, "%030.20d", INT_MAX );
    test( SIZE_MAX, "%.6x", UINT_MAX );
    test( SIZE_MAX, "%#6.3x", UINT_MAX );
    test( SIZE_MAX, "%#3.6x", UINT_MAX );
    test( SIZE_MAX, "%.6d", INT_MIN );
    test( SIZE_MAX, "%6.3d", INT_MIN );
    test( SIZE_MAX, "%3.6d", INT_MIN );
    test( SIZE_MAX, "%#0.6x", UINT_MAX );
    test( SIZE_MAX, "%#06.3x", UINT_MAX );
    test( SIZE_MAX, "%#03.6x", UINT_MAX );
    test( SIZE_MAX, "%#0.6d", INT_MAX );
    test( SIZE_MAX, "%#06.3d", INT_MAX );
    test( SIZE_MAX, "%#03.6d", INT_MAX );
    test( SIZE_MAX, "%#+.6d", INT_MAX );
    test( SIZE_MAX, "%#+6.3d", INT_MAX );
    test( SIZE_MAX, "%#+3.6d", INT_MAX );
    test( SIZE_MAX, "%+0.6d", INT_MAX );
    test( SIZE_MAX, "%+06.3d", INT_MAX );
    test( SIZE_MAX, "%+03.6d", INT_MAX );
    puts( "- Multiple outputs -\n" );
    test( SIZE_MAX, "- %d", INT_MAX );
    test( SIZE_MAX, "- %d %% %d", INT_MAX, INT_MIN );
    return 0;
}

/* This macro delivers a given character to either a memory buffer or a stream,
   depending on the contents of 'status' (struct status_t).
   x - the character to be delivered
   i - pointer to number of characters already delivered in this call
   n - pointer to maximum number of characters to be delivered in this call
   s - the buffer into which the character shall be delivered
*/
#define DELIVER( x ) do { if ( status->i < status->n ) { if ( status->stream != NULL ) putc( x, status->stream ); else status->s[status->i] = x; } ++(status->i); } while ( 0 )
<commit_msg>Removed the header outputs from the test driver.<commit_after>#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

/* These can be removed once integrated into PDCLIB make procedure */
#undef TEST
#include </home/solar/src/pdclib/functions/_PDCLIB/digits.c>
#include </home/solar/src/pdclib/functions/_PDCLIB/Xdigits.c>

/* Using an integer's bits as flags for both the conversion flags and length
   modifiers.
*/
#define E_minus    1<<0
#define E_plus     1<<1
#define E_alt      1<<2
#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_llong    1<<9
#define E_intmax   1<<10
#define E_size     1<<11
#define E_ptrdiff  1<<12
#define E_double   1<<13
#define E_lower    1<<14
#define E_unsigned 1<<15

struct status_t
{
    int           base;  /* base to which the value shall be converted       */
    int_fast32_t  flags; /* flags and length modifiers                       */
    size_t        n;     /* maximum number of characters to be written       */
    size_t        i;     /* number of characters already written             */
    size_t        this;  /* number of output chars in the current conversion */
    char *        s;     /* target buffer                                    */
    size_t        width; /* width of current field                           */
    size_t        prec;  /* precision of current field                       */
    FILE *        stream;/* for to-stream output                             */
    va_list       ap;    /* the argument stack passed to the printf function */
};

const char * parse_out( const char * spec, struct status_t * status );
inline void test( size_t n, const char * expect, ... );
int _PDCLIB_sprintf( char * buffer, size_t n, const char * format, va_list ap );

/* The following only for testing. */
#include <limits.h>
#include <string.h>

int main( void )
{
    test( SIZE_MAX, "%hhd", CHAR_MIN );
    test( SIZE_MAX, "%hhd", CHAR_MAX );
    test( SIZE_MAX, "%hhd", 0 );
    test( SIZE_MAX, "%hd", SHRT_MIN );
    test( SIZE_MAX, "%hd", SHRT_MAX );
    test( SIZE_MAX, "%hd", 0 );
    test( SIZE_MAX, "%d", INT_MIN );
    test( SIZE_MAX, "%d", INT_MAX );
    test( SIZE_MAX, "%d", 0 );
    test( SIZE_MAX, "%ld", LONG_MIN );
    test( SIZE_MAX, "%ld", LONG_MAX );
    test( SIZE_MAX, "%ld", 0l );
    test( SIZE_MAX, "%lld", LLONG_MIN );
    test( SIZE_MAX, "%lld", LLONG_MAX );
    test( SIZE_MAX, "%lld", 0ll );
    test( SIZE_MAX, "%hhu", UCHAR_MAX );
    test( SIZE_MAX, "%hhu", (unsigned char)-1 );
    test( SIZE_MAX, "%hu", USHRT_MAX );
    test( SIZE_MAX, "%hu", (unsigned short)-1 );
    test( SIZE_MAX, "%u", UINT_MAX );
    test( SIZE_MAX, "%u", -1u );
    test( SIZE_MAX, "%lu", ULONG_MAX );
    test( SIZE_MAX, "%lu", -1ul );
    test( SIZE_MAX, "%llu", ULLONG_MAX );
    test( SIZE_MAX, "%llu", -1ull );
    test( SIZE_MAX, "%X", UINT_MAX );
    test( SIZE_MAX, "%#X", -1u );
    test( SIZE_MAX, "%x", UINT_MAX );
    test( SIZE_MAX, "%#x", -1u );
    test( SIZE_MAX, "%o", UINT_MAX );
    test( SIZE_MAX, "%#o", -1u );
    test( SIZE_MAX, "%+d", INT_MIN );
    test( SIZE_MAX, "%+d", INT_MAX );
    test( SIZE_MAX, "%+d", 0 );
    test( SIZE_MAX, "%+u", UINT_MAX );
    test( SIZE_MAX, "%+u", -1u );
    test( SIZE_MAX, "% d", INT_MIN );
    test( SIZE_MAX, "% d", INT_MAX );
    test( SIZE_MAX, "% d", 0 );
    test( SIZE_MAX, "% u", UINT_MAX );
    test( SIZE_MAX, "% u", -1u );
    test( SIZE_MAX, "%9d", INT_MIN );
    test( SIZE_MAX, "%9d", INT_MAX );
    test( SIZE_MAX, "%10d", INT_MIN );
    test( SIZE_MAX, "%10d", INT_MAX );
    test( SIZE_MAX, "%11d", INT_MIN );
    test( SIZE_MAX, "%11d", INT_MAX );
    test( SIZE_MAX, "%12d", INT_MIN );
    test( SIZE_MAX, "%12d", INT_MAX );
    test( SIZE_MAX, "%-9d", INT_MIN );
    test( SIZE_MAX, "%-9d", INT_MAX );
    test( SIZE_MAX, "%-10d", INT_MIN );
    test( SIZE_MAX, "%-10d", INT_MAX );
    test( SIZE_MAX, "%-11d", INT_MIN );
    test( SIZE_MAX, "%-11d", INT_MAX );
    test( SIZE_MAX, "%-12d", INT_MIN );
    test( SIZE_MAX, "%-12d", INT_MAX );
    test( SIZE_MAX, "%09d", INT_MIN );
    test( SIZE_MAX, "%09d", INT_MAX );
    test( SIZE_MAX, "%010d", INT_MIN );
    test( SIZE_MAX, "%010d", INT_MAX );
    test( SIZE_MAX, "%011d", INT_MIN );
    test( SIZE_MAX, "%011d", INT_MAX );
    test( SIZE_MAX, "%012d", INT_MIN );
    test( SIZE_MAX, "%012d", INT_MAX );
    test( SIZE_MAX, "%-09d", INT_MIN );
    test( SIZE_MAX, "%-09d", INT_MAX );
    test( SIZE_MAX, "%-010d", INT_MIN );
    test( SIZE_MAX, "%-010d", INT_MAX );
    test( SIZE_MAX, "%-011d", INT_MIN );
    test( SIZE_MAX, "%-011d", INT_MAX );
    test( SIZE_MAX, "%-012d", INT_MIN );
    test( SIZE_MAX, "%-012d", INT_MAX );
    test( 8, "%9d", INT_MAX );
    test( 8, "%9d", INT_MIN );
    test( 9, "%9d", INT_MAX );
    test( 9, "%9d", INT_MIN );
    test( 10, "%9d", INT_MAX );
    test( 10, "%9d", INT_MIN );
    test( 9, "%10d", INT_MAX );
    test( 9, "%10d", INT_MIN );
    test( 10, "%10d", INT_MAX );
    test( 10, "%10d", INT_MIN );
    test( 11, "%10d", INT_MAX );
    test( 11, "%10d", INT_MIN );
    test( 10, "%11d", INT_MAX );
    test( 10, "%11d", INT_MIN );
    test( 11, "%11d", INT_MAX );
    test( 11, "%11d", INT_MIN );
    test( 12, "%11d", INT_MAX );
    test( 12, "%11d", INT_MIN );
    test( 11, "%12d", INT_MAX );
    test( 11, "%12d", INT_MIN );
    test( 12, "%12d", INT_MAX );
    test( 12, "%12d", INT_MIN );
    test( 13, "%12d", INT_MAX );
    test( 13, "%12d", INT_MIN );
    test( SIZE_MAX, "%030.20d", INT_MAX );
    test( SIZE_MAX, "%.6x", UINT_MAX );
    test( SIZE_MAX, "%#6.3x", UINT_MAX );
    test( SIZE_MAX, "%#3.6x", UINT_MAX );
    test( SIZE_MAX, "%.6d", INT_MIN );
    test( SIZE_MAX, "%6.3d", INT_MIN );
    test( SIZE_MAX, "%3.6d", INT_MIN );
    test( SIZE_MAX, "%#0.6x", UINT_MAX );
    test( SIZE_MAX, "%#06.3x", UINT_MAX );
    test( SIZE_MAX, "%#03.6x", UINT_MAX );
    test( SIZE_MAX, "%#0.6d", INT_MAX );
    test( SIZE_MAX, "%#06.3d", INT_MAX );
    test( SIZE_MAX, "%#03.6d", INT_MAX );
    test( SIZE_MAX, "%#+.6d", INT_MAX );
    test( SIZE_MAX, "%#+6.3d", INT_MAX );
    test( SIZE_MAX, "%#+3.6d", INT_MAX );
    test( SIZE_MAX, "%+0.6d", INT_MAX );
    test( SIZE_MAX, "%+06.3d", INT_MAX );
    test( SIZE_MAX, "%+03.6d", INT_MAX );
    test( SIZE_MAX, "- %d", INT_MAX );
    test( SIZE_MAX, "- %d %% %d", INT_MAX, INT_MIN );
    return 0;
}

/* This macro delivers a given character to either a memory buffer or a stream,
   depending on the contents of 'status' (struct status_t).
   x - the character to be delivered
   i - pointer to number of characters already delivered in this call
   n - pointer to maximum number of characters to be delivered in this call
   s - the buffer into which the character shall be delivered
*/
#define DELIVER( x ) do { if ( status->i < status->n ) { if ( status->stream != NULL ) putc( x, status->stream ); else status->s[status->i] = x; } ++(status->i); } while ( 0 )

{'fraction_non_alphanumeric': 0.18382504642046626, 'fraction_numerical': 0.035623409669211195, 'mean_word_length': 2.6537688442211054, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6967919', 'n_tokens_mistral': 5931, 'n_tokens_neox': 5474, 'n_words': 1595}