- /* More digits to be done - recurse deeper */
- int2base( value / status->base, status );
- }
- else
- {
- /* We reached the last digit, the deepest point of our recursion, and
- only now know how long the number to be printed actually is. Now we
- have to do the sign, prefix, width, and precision padding stuff
- before printing the numbers while we resurface from the recursion.
- */
- /* At worst, we need two prefix characters (hex prefix). */
- char preface[3] = "\0";
- size_t preidx = 0;
- if ( ( status->flags & E_alt ) && ( status->base == 16 || status->base == 8 ) )
- {
- /* Octal / hexadecimal prefix for "%#" conversions */
- preface[ preidx++ ] = '0';
- if ( status->base == 16 )
- {
- preface[ preidx++ ] = ( status->flags & E_lower ) ? 'x' : 'X';
- }
- }
- if ( value < 0 )
- {
- /* Negative sign for negative values - at all times. */
- preface[ preidx++ ] = '-';
- }
- else if ( ! ( status->flags & E_unsigned ) )
- {
- /* plus sign / extra space are only for unsigned conversions */
- if ( status->flags & E_plus )
- {
- preface[ preidx++ ] = '+';
- }
- else if ( status->flags & E_space )
- {
- preface[ preidx++ ] = ' ';
- }
- }
- {
- size_t prec_pads = ( status->prec > status->this ) ? ( status->prec - status->this ) : 0;
- if ( ! ( status->flags & ( E_minus | E_zero ) ) )
- {
- /* Space padding is only done if no zero padding or left alignment
- is requested. Leave space for any prefixes determined above.
- */
- /* The number of characters to be printed, plus prefixes if any. */
- /* This line contained probably the most stupid, time-wasting bug
- I've ever perpetrated. Greetings to Samface, DevL, and all
- sceners at Breakpoint 2006.
- */
- size_t characters = preidx + ( ( status->this > status->prec ) ? status->this : status->prec );
- if ( status->width > characters )
- {
- for ( int i = 0; i < status->width - characters; ++i )
- {
- DELIVER( ' ' );
- ++(status->this);
- }
- }
- }
- /* Now we did the padding, do the prefixes (if any). */
- preidx = 0;
- while ( preface[ preidx ] != '\0' )