int ft_put_long(t_param *data, void *nbr) { int size; int min; size = 0; min = printf_fill_nbrlen(data, nbr); if (!(data->param & PARAM_MI)) size += printf_fill(min); if (!(data->param & PARAM_L)) size += ft_put_long_sub(data, nbr); else if (data->param & PARAM_L) { if (data->param & PARAM_PL) size += printf_putchar('+'); else if (data->param & PARAM_WH && *(long *)nbr >= 0) size += printf_putchar(' '); if (data->param & PARAM_D || data->param & PARAM_I) size += ft_putlong(*(long *)nbr, 0); else if (data->param & PARAM_U) size += ft_putlong(*(unsigned long *)nbr, 0); } if (data->param & PARAM_MI) size += printf_fill(min); return (size); }
static void printf_puthexdigit( uint8_t i ) { if(i<10) { printf_putchar('0'+i); } else { printf_putchar('a'+i-10); } }
int ft_put_long_sub(t_param *data, void *nbr) { int size; size = 0; if (data->param & PARAM_PL) size += printf_putchar('+'); else if (data->param & PARAM_WH && *(int *)nbr >= 0) size += printf_putchar(' '); if (data->param & PARAM_D || data->param & PARAM_I) size += ft_putlong(*(int *)nbr, 0); else if (data->param & PARAM_U) size += ft_putlong(*(unsigned int *)nbr, 0); return (size); }
static void printf_putint( int32_t i ) { int f, d; if(i<0 && i!=0) { printf_putchar('-'); i=-i; } f = 1; while((i/f)>0) { f*=10; } f=f/10; if(f==0) f=1; while(f>0) { d = i/f; printf_putchar('0'+d); i = i-d*f; f = f/10; } }
void printf( const char *s, ... ) { va_list args; uint32_t u; int32_t i; char *str; va_start(args,s); while(*s) { if(*s!='%') { printf_putchar(*s); } else { s++; switch(*s) { case 'd': i = va_arg(args,int32_t); printf_putint(i); break; case 'x': u = va_arg(args,uint32_t); printf_puthex(u); break; case 's': str = va_arg(args,char*); printf_putstring(str); break; case 0: return; break; default: printf_putchar(*s); break; } } s++; } va_end(args); }
int ft_putlong(long n, int size) { if (n < 0) { write(1, "-", 1); n *= -1; size += 1; } if (n >= 10) size = ft_putlong(n / 10, size); size += printf_putchar(n % 10 + '0'); return (size); }