- /* 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.
- */
- intformat( value, status );
- }
- /* Recursion tail - print the current digit. */
- {
- int digit = value % status->base;
- if ( digit < 0 )
- {
- digit *= -1;
- }
- if ( status->flags & E_lower )
- {
- /* Lowercase letters. Same array used for strto...(). */
- PUT( _PDCLIB_digits[ digit ] );
+ // Simple case or left justification
+ while ( str[status->current] &&
+ ( status->prec < 0 || (long)status->current < status->prec ) )
+ {
+ PUT( str[status->current++] );
+ }
+
+ while( status->current < status->width )
+ {
+ PUT( ' ' );
+ status->current++;
+ }
+ } else {
+ // Right justification
+ size_t len = status->prec >= 0 ? strnlen( str, status->prec )
+ : strlen( str );
+ int padding = status->width - len;
+ while((long)status->current < padding)
+ {
+ PUT( ' ' );
+ status->current++;
+ }
+
+ for( size_t i = 0; i != len; i++ )
+ {
+ PUT( str[i] );
+ status->current++;
+ }