56 lines
1.9 KiB
C
56 lines
1.9 KiB
C
/*
|
|
** EPITECH PROJECT, 2018
|
|
** task01
|
|
** File description:
|
|
** I do task
|
|
*/
|
|
#include "lib/my_stdio.h"
|
|
|
|
/* */
|
|
/* it's a bit ugly but it's the best */
|
|
/* maniere to get exacly what we want */
|
|
/* */
|
|
static void get_signed_arg(printf_t *print)
|
|
{
|
|
if (print->type & PRINT_TYPE_CHAR)
|
|
print->value = (uintmax_t)(char)print->value;
|
|
if (!print->type)
|
|
print->value = (uintmax_t)(int)print->value;
|
|
if (print->type & PRINT_TYPE_INTM)
|
|
print->value = (uintmax_t)(intmax_t)print->value;
|
|
if (print->type & PRINT_TYPE_SINT || print->type & PRINT_TYPE_SIZE)
|
|
print->value = (uintmax_t)(short int)print->value;
|
|
if (print->type & PRINT_TYPE_LLONG)
|
|
print->value = (uintmax_t)(long long int)print->value;
|
|
if (print->type & PRINT_TYPE_LONG)
|
|
print->value = (uintmax_t)(long int)print->value;
|
|
if (print->type & PRINT_TYPE_PTRD)
|
|
print->value = (uintmax_t)(ptrdiff_t)print->value;
|
|
}
|
|
|
|
static void get_unsigned_arg(printf_t *print)
|
|
{
|
|
if (print->type & PRINT_TYPE_CHAR)
|
|
print->value = (uintmax_t)(unsigned char)print->value;
|
|
if (!print->type)
|
|
print->value = (uintmax_t)(unsigned int)print->value;
|
|
if (print->type & PRINT_TYPE_SINT || print->type & PRINT_TYPE_SIZE)
|
|
print->value = (uintmax_t)(unsigned short int)print->value;
|
|
if (print->type & PRINT_TYPE_LLONG)
|
|
print->value = (uintmax_t)(unsigned long long int)print->value;
|
|
if (print->type & PRINT_TYPE_LONG)
|
|
print->value = (intmax_t)(unsigned long int)print->value;
|
|
if (print->type & PRINT_TYPE_PTRD)
|
|
print->value = (uintmax_t)(ptrdiff_t)print->value;
|
|
}
|
|
|
|
void vfprintf_get_arg(printf_t *print, char type)
|
|
{
|
|
print->value = va_arg(print->ap, uintmax_t);
|
|
if (type == 'o' || type == 'x' || type == 'X'
|
|
|| type == 'p' || type == 'b' || type == 'u')
|
|
get_unsigned_arg(print);
|
|
else
|
|
get_signed_arg(print);
|
|
}
|