]> Untitled Git - axy/ft/ft_printf.git/commitdiff
Various fixes
authorAxy <gilliardmarthey.axel@gmail.com>
Thu, 30 Oct 2025 11:12:57 +0000 (12:12 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Thu, 30 Oct 2025 11:12:57 +0000 (12:12 +0100)
ft_printf.c

index 6ea6fc6285b4b78e7994e938533ed7966f9844da..48b730950e37c80b06a3b81588d32b7e1d14dd1c 100644 (file)
@@ -6,7 +6,7 @@
 /*   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;
@@ -31,9 +32,9 @@ typedef enum e_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
@@ -62,7 +63,7 @@ typedef enum e_specifier
        SPECIFIER_STRING,
        SPECIFIER_VOID_PTR,
        SPECIFIER_INT,
-       SPECIFIER_UNSIGNED,
+       SPECIFIER_UINT,
        SPECIFIER_INT_HEX_LOWER,
        SPECIFIER_INT_HEX_UPPER,
        SPECIFIER_PERCENT,
@@ -71,7 +72,7 @@ typedef enum e_specifier
 typedef enum e_num_prefix
 {
        NUM_PREFIX_NONE,
-       NUM_PREFIX_FORMAT;
+       NUM_PREFIX_FORMAT,
 }      t_num_prefix;
 
 typedef struct s_format
@@ -81,7 +82,7 @@ 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;
@@ -97,7 +98,7 @@ t_format      ft_format_default(void)
        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);
@@ -125,6 +126,9 @@ bool        ft_parse_flag(char c, t_format *format)
                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)
@@ -138,7 +142,7 @@ 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')
@@ -148,7 +152,7 @@ t_specifier ft_parse_specifier(char c)
        return (SPECIFIER_NONE);
 }
 
-t_format ft_parse_format(const char **format)
+t_format       ft_parse_format(const char **format)
 {
        t_format        res;
 
@@ -185,8 +189,8 @@ t_step      specifier_to_step(t_specifier spec)
                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);
 }
 
@@ -209,7 +213,7 @@ int ft_printf(const char *format, ...)
                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 *);