mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
libs: added libft
This commit is contained in:
parent
6e1552a35d
commit
ddb2306630
63 changed files with 2989 additions and 4 deletions
70
libft/ft_printf_utils2.c
Normal file
70
libft/ft_printf_utils2.c
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf_utils2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/05 17:10:15 by jguelen #+# #+# */
|
||||
/* Updated: 2024/12/11 14:23:21 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_isnumeric_conv(t_printf_format *format)
|
||||
{
|
||||
t_printf_spec spec;
|
||||
|
||||
spec = format->specifier;
|
||||
if (spec == PRINTF_HEXA_LOWSPEC || spec == PRINTF_HEXA_UPSPEC
|
||||
|| spec == PRINTF_INTSPEC || spec == PRINTF_UINTSPEC)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void get_prefix_format_util(t_printf_format *format)
|
||||
{
|
||||
t_printf_spec spec;
|
||||
|
||||
spec = format->specifier;
|
||||
if (ft_isnumeric_conv(format) && (format->flags & PRINTF_DOTFLAG))
|
||||
format->flags &= ~PRINTF_ZEROFLAG;
|
||||
if (spec == PRINTF_POINTERSPEC)
|
||||
{
|
||||
ft_strlcpy(format->prefix, HEXA_RADIX_LOW, 3);
|
||||
format->prefix_len = 2;
|
||||
}
|
||||
if (spec == PRINTF_INTSPEC
|
||||
|| (spec == PRINTF_POINTERSPEC && format->var.p)
|
||||
|| ((spec == PRINTF_HEXA_LOWSPEC || spec == PRINTF_HEXA_UPSPEC)
|
||||
&& format->var.u))
|
||||
format->total_len += format->prefix_len;
|
||||
}
|
||||
|
||||
void get_prefix_format(t_printf_format *format)
|
||||
{
|
||||
if ((format->flags & PRINTF_PLUSFLAG)
|
||||
&& format->specifier == PRINTF_INTSPEC && format->var.i >= 0)
|
||||
{
|
||||
format->flags &= ~PRINTF_SPACEFLAG;
|
||||
format->prefix[0] = '+';
|
||||
format->prefix_len = 1;
|
||||
}
|
||||
else if ((format->flags & PRINTF_HASHTAGFLAG)
|
||||
&& (format->specifier == PRINTF_HEXA_LOWSPEC
|
||||
|| format->specifier == PRINTF_HEXA_UPSPEC) && format->var.u != 0)
|
||||
{
|
||||
ft_strlcpy(format->prefix, HEXA_RADIX_LOW, 3);
|
||||
if (format->specifier == PRINTF_HEXA_UPSPEC)
|
||||
ft_strlcpy(format->prefix, HEXA_RADIX_UP, 3);
|
||||
format->prefix_len = 2;
|
||||
}
|
||||
else if ((format->flags & PRINTF_SPACEFLAG)
|
||||
&& format->specifier == PRINTF_INTSPEC && format->var.i >= 0)
|
||||
{
|
||||
format->prefix[0] = ' ';
|
||||
format->prefix_len = 1;
|
||||
}
|
||||
get_prefix_format_util(format);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue