]> Untitled Git - axy/ft/ft_printf.git/commitdiff
Extra flag compliance
author= <=>
Thu, 30 Oct 2025 17:05:32 +0000 (18:05 +0100)
committer= <=>
Thu, 30 Oct 2025 17:05:32 +0000 (18:05 +0100)
ft_printf.c

index d2817f51040b933b3a630b239ddda7965ae2bfc8..415463b7a3eaa5da81cb86b9ef5bed7cb0d761ea 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/10/29 14:24:47 by agilliar          #+#    #+#             */
-/*   Updated: 2025/10/30 17:42:47 by agilliar         ###   ########.fr       */
+/*   Updated: 2025/10/30 18:00:09 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -49,12 +49,6 @@ typedef enum e_justify
        JUSTIFY_RIGHT,
 }      t_justify;
 
-typedef enum e_padding_type
-{
-       PADDING_SPACE,
-       PADDING_ZEROS,
-}      t_padding_type;
-
 typedef enum e_specifier
 {
        SPECIFIER_NONE,
@@ -81,7 +75,7 @@ typedef struct s_format
        t_justify               justify;
        t_num_prefix    num_prefix;
        int                             width;
-       t_padding_type  padding_type;
+       bool                    zero_pad;
        int                             precision;
        bool                    enable_precision;
 }      t_format;
@@ -168,7 +162,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.zero_pad = false;
        res.precision = 0;
        res.enable_precision = false;
        return (res);
@@ -199,7 +193,7 @@ bool        ft_parse_flag(char c, t_format *format)
        else if (c == '#')
                format->num_prefix = NUM_PREFIX_FORMAT;
        else if (c == '0')
-               format->padding_type = PADDING_ZEROS;
+               format->zero_pad = true;
        else
                return (false);
        return (true);
@@ -246,6 +240,12 @@ t_specifier        ft_parse_specifier(char c)
        return (SPECIFIER_NONE);
 }
 
+void   ft_format_normalize(t_format *format)
+{
+       if (format->justify == JUSTIFY_LEFT)
+               format->zero_pad = false;
+}
+
 t_format       ft_parse_format(const char **s)
 {
        t_format        res;
@@ -256,6 +256,7 @@ t_format    ft_parse_format(const char **s)
        ft_parse_width(s, &res);
        ft_parse_precision(s, &res);
        res.specifier = ft_parse_specifier(*((*s)++));
+       ft_format_normalize(&res);
        return (res);
 }
 
@@ -320,6 +321,6 @@ int ft_printf(const char *s, ...)
 int    main(void)
 {
        const char      *s = "hai";
-       ft_printf("c%-10.2s", s);
-       printf("c%-10.2s", s);
+       ft_printf("c%-10p", s);
+       printf("c%-10p", s);
 }