-/* This function recursively converts a given integer value to a character
- stream. The conversion is done under the control of a given status struct
- and written either to a character string or a stream, depending on that
- same status struct. The status struct also keeps the function from exceeding
- snprintf() limits, and enables any necessary padding / prefixing of the
- output once the number of characters to be printed is known, which happens
- at the lowermost recursion level.
-*/
-static void int2base( intmax_t value, struct _PDCLIB_status_t * status )
-{
- /* Registering the character being printed at the end of the function here
- already so it will be taken into account when the deepestmost recursion
- does the prefix / padding stuff.
- */
- ++(status->current);
- if ( ( value / status->base ) != 0 )
- {
- /* 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...(). */
- DELIVER( _PDCLIB_digits[ digit ] );
- }
- else