aboutsummaryrefslogtreecommitdiffstats
path: root/libft/src/ft_printf_use_flags.c
diff options
context:
space:
mode:
Diffstat (limited to 'libft/src/ft_printf_use_flags.c')
-rw-r--r--libft/src/ft_printf_use_flags.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/libft/src/ft_printf_use_flags.c b/libft/src/ft_printf_use_flags.c
new file mode 100644
index 0000000..7b1299e
--- /dev/null
+++ b/libft/src/ft_printf_use_flags.c
@@ -0,0 +1,68 @@
+/* ************************************************************************** */
+/* LE - / */
+/* / */
+/* ft_printf_use_flags.c .:: .:/ . .:: */
+/* +:+:+ +: +: +:+:+ */
+/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
+/* #+# #+ #+ #+# */
+/* Created: 2019/12/31 14:41:02 by rbousset #+# ## ## #+# */
+/* Updated: 2019/12/31 14:41:03 by rbousset ### #+. /#+ ###.fr */
+/* / */
+/* / */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+
+static void
+ ft_printf_noflags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist)
+{
+ ft_printf_process(format + pos, arg, pflist);
+}
+
+static void
+ ft_printf_withflags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist)
+{
+ ft_memdel(pflist->fullflag);
+ pflist->fullflag = ft_printf_get_flags(format, pos, pflist);
+ ft_printf_treat_flags(arg, pflist);
+ ft_printf_process(format + pos, arg, pflist);
+}
+
+int
+ ft_printf_flags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist)
+{
+ int plen;
+
+ plen = 0;
+ if (ft_ischarset(FT_PRINTF_CONV_CHARSET, *(format + pos + 1)))
+ {
+ ft_printf_noflags(format, pos, arg, pflist);
+ plen = ft_printf_get_partlen(format + pos + 2);
+ ft_printf_putpart(format, pos + 2, plen, pflist);
+ if (plen == (int)ft_strlen(format + pos + 2))
+ return (-1);
+ else
+ return (pos + plen + 2);
+ }
+ else
+ {
+ ft_printf_withflags(format, pos, arg, pflist);
+ plen = ft_printf_get_partlen(format + pos + pflist->flaglen + 2);
+ ft_printf_putpart(format, pos + pflist->flaglen + 2,
+ plen, pflist);
+ if (plen == (int)ft_strlen(format + pos + pflist->flaglen + 2))
+ return (-1);
+ else
+ return (pos + plen + pflist->flaglen + 2);
+ }
+}