/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/29 14:24:47 by agilliar #+# #+# */
-/* Updated: 2025/10/30 12:01:14 by agilliar ### ########.fr */
+/* Updated: 2025/10/30 12:12:46 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
/*
- Because of variadic argument promotion, we represent an expected char as an int
+ Because of variadic argument promotion,
+ we represent an expected char as an int
*/
typedef enum e_step
{
STEP_INT,
- STEP_UNSIGNED,
+ STEP_UINT,
STEP_PTR,
STEP_NONE,
} t_step;
*/
typedef union u_step_arg
{
- int v_int;
- unsigned v_uint;
- void *v_ptr;
+ int v_int;
+ unsigned int v_uint;
+ void *v_ptr;
} t_step_arg;
typedef enum e_sign_flag
SPECIFIER_STRING,
SPECIFIER_VOID_PTR,
SPECIFIER_INT,
- SPECIFIER_UNSIGNED,
+ SPECIFIER_UINT,
SPECIFIER_INT_HEX_LOWER,
SPECIFIER_INT_HEX_UPPER,
SPECIFIER_PERCENT,
typedef enum e_num_prefix
{
NUM_PREFIX_NONE,
- NUM_PREFIX_FORMAT;
+ NUM_PREFIX_FORMAT,
} t_num_prefix;
typedef struct s_format
t_justify justify;
t_num_prefix num_prefix;
size_t width;
- s_padding_type padding_type;
+ t_padding_type padding_type;
size_t precision;
bool enable_precision;
} t_format;
res.justify = JUSTIFY_RIGHT;
res.num_prefix = NUM_PREFIX_NONE;
res.width = 0;
- res.padding_type PADDING_SPACE;
+ res.padding_type = PADDING_SPACE;
res.precision = 0;
res.enable_precision = false;
return (res);
format->num_prefix = NUM_PREFIX_FORMAT;
else if (c == '0')
format->padding_type = PADDING_ZEROS;
+ else
+ return (false);
+ return (true);
}
t_specifier ft_parse_specifier(char c)
if (c == 'd' || c == 'i')
return (SPECIFIER_INT);
if (c == 'u')
- return (SPECIFIER_UNSIGNED);
+ return (SPECIFIER_UINT);
if (c == 'x')
return (SPECIFIER_INT_HEX_LOWER);
if (c == 'X')
return (SPECIFIER_NONE);
}
-t_format ft_parse_format(const char **format)
+t_format ft_parse_format(const char **format)
{
t_format res;
return (STEP_NONE);
if (spec == SPECIFIER_STRING || spec == SPECIFIER_VOID_PTR)
return (STEP_PTR);
- if (spec == SPECIFIER_UNSIGNED)
- return (STEP_UNSIGNED);
+ if (spec == SPECIFIER_UINT)
+ return (STEP_UINT);
return (STEP_INT);
}
count += written;
if (specifier_to_step(step.specifier) == STEP_INT)
arg.v_int = va_arg(args, int);
- if (specifier_to_step(step.specifier) == STEP_UNSIGNED)
+ if (specifier_to_step(step.specifier) == STEP_UINT)
arg.v_uint = va_arg(args, unsigned);
if (specifier_to_step(step.specifier) == STEP_PTR)
arg.v_ptr = va_arg(args, void *);