4 files changed, +63, -27
f72e574change: moves dispatch to its own dir for extra modularity
+3, -1
@@ -16,6 +16,7 @@ INCLUDE_DIR = include
1616 UTILS_DIR = utils
1717 PARSER_DIR = parser
1818 PRINTERS_DIR = printers
19+DISPATCHER_DIR = dispatcher
1920 OBJ_DIR = obj
2021
2122 #============================#
@@ -25,7 +26,8 @@ OBJ_DIR = obj
2526 SRCS = ft_printf.c \
2627 $(wildcard $(UTILS_DIR)/*.c) \
2728 $(wildcard $(PARSER_DIR)/*.c) \
28 - $(wildcard $(PRINTERS_DIR)/*.c)
29+ $(wildcard $(PRINTERS_DIR)/*.c) \
30+ $(wildcard $(DISPATCHER_DIR)/*.c)
2931
3032 OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o)
3133
+38, -0
@@ -0,0 +1,38 @@
1+/* ************************************************************************** */
2+/* */
3+/* ::: :::::::: */
4+/* dispatch.c :+: :+: :+: */
5+/* +:+ +:+ +:+ */
6+/* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7+/* +#+#+#+#+#+ +#+ */
8+/* Created: 2026/04/04 03:21:25 by mleitao #+# #+# */
9+/* Updated: 2026/04/04 03:21:43 by mleitao ### ########.fr */
10+/* */
11+/* ************************************************************************** */
12+
13+#include <dispatcher.h>
14+#include <printers.h>
15+
16+int dispatch(t_data *d)
17+{
18+ char spec;
19+
20+ spec = d->format.spec;
21+ if (spec == 'c')
22+ return (print_c(d, va_arg(d->args, int)));
23+ else if (spec == 's')
24+ return (print_s(d, va_arg(d->args, char *)));
25+ else if (spec == '%')
26+ return (print_c(d, spec));
27+ else if (spec == 'd' || spec == 'i')
28+ return (print_diu(d, (long)va_arg(d->args, int), 1));
29+ else if (spec == 'u')
30+ return (print_diu(d, (unsigned long)va_arg(d->args, unsigned int), 0));
31+ else if (spec == 'x')
32+ return (print_xx(d, va_arg(d->args, unsigned int), 0));
33+ else if (spec == 'X')
34+ return (print_xx(d, va_arg(d->args, unsigned int), 1));
35+ else if (spec == 'p')
36+ return (print_p(d, va_arg(d->args, void *)));
37+ return (-1);
38+}
+2, -26
@@ -6,14 +6,14 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/30 01:31:08 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 02:56:55 by mleitao ### ########.fr */
9+/* Updated: 2026/04/04 03:23:31 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
1313 #include <core.h>
1414 #include <utils.h>
1515 #include <parser.h>
16 -#include <printers.h>
16+#include <dispatcher.h>
1717
1818 static void init_data(t_data *d, const char *fmt)
1919 {
@@ -21,30 +21,6 @@ static void init_data(t_data *d, const char *fmt)
2121 d->chars_written = 0;
2222 }
2323
24 -static int dispatch(t_data *d)
25 -{
26 - char spec;
27 -
28 - spec = d->format.spec;
29 - if (spec == 'c')
30 - return (print_c(d, va_arg(d->args, int)));
31 - else if (spec == 's')
32 - return (print_s(d, va_arg(d->args, char *)));
33 - else if (spec == '%')
34 - return (print_c(d, spec));
35 - else if (spec == 'd' || spec == 'i')
36 - return (print_diu(d, (long)va_arg(d->args, int), 1));
37 - else if (spec == 'u')
38 - return (print_diu(d, (unsigned long)va_arg(d->args, unsigned int), 0));
39 - else if (spec == 'x')
40 - return (print_xx(d, va_arg(d->args, unsigned int), 0));
41 - else if (spec == 'X')
42 - return (print_xx(d, va_arg(d->args, unsigned int), 1));
43 - else if (spec == 'p')
44 - return (print_p(d, va_arg(d->args, void *)));
45 - return (-1);
46 -}
47 -
4824 static int inner_logic(t_data *d, char *next)
4925 {
5026 int written;
+20, -0
@@ -0,0 +1,20 @@
1+/* ************************************************************************** */
2+/* */
3+/* ::: :::::::: */
4+/* dispatcher.h :+: :+: :+: */
5+/* +:+ +:+ +:+ */
6+/* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7+/* +#+#+#+#+#+ +#+ */
8+/* Created: 2026/04/04 03:20:27 by mleitao #+# #+# */
9+/* Updated: 2026/04/04 03:21:05 by mleitao ### ########.fr */
10+/* */
11+/* ************************************************************************** */
12+
13+#ifndef DISPATCHER_H
14+# define DISPATCHER_H
15+
16+# include <core.h>
17+
18+int dispatch(t_data *d);
19+
20+#endif