22 files changed, +107, -126
1f2536brefactor: add src dir and update makefile and readme
Makefile
+29, -49
README.md
+24, -23
include/dispatcher.h
+2, -2
include/parser.h
+2, -2
include/printers.h
+2, -2
+29, -49
@@ -1,51 +1,31 @@
1 -#============================#
2 -# VARIABLES #
3 -#============================#
4 -
5 -NAME = libftprintf.a
6 -
7 -CC = cc
8 -CFLAGS = -Wall -Wextra -Werror -I$(INCLUDE_DIR)
9 -
10 -INCLUDE_DIR = include
11 -
12 -#============================#
13 -# DIRECTORIES #
14 -#============================#
15 -
16 -UTILS_DIR = utils
17 -PARSER_DIR = parser
18 -PRINTERS_DIR = printers
19 -DISPATCHER_DIR = dispatcher
20 -OBJ_DIR = obj
21 -
22 -#============================#
23 -# SOURCE FILES #
24 -#============================#
25 -
26 -SRCS = ft_printf.c \
27 - $(UTILS_DIR)/char.c \
28 - $(UTILS_DIR)/io.c \
29 - $(UTILS_DIR)/memory.c \
30 - $(UTILS_DIR)/numbers.c \
31 - $(UTILS_DIR)/string.c \
32 - $(PARSER_DIR)/parse_format.c \
33 - $(PARSER_DIR)/parse_utils.c \
34 - $(PRINTERS_DIR)/format_number.c \
35 - $(PRINTERS_DIR)/format_padding.c \
36 - $(PRINTERS_DIR)/print_c.c \
37 - $(PRINTERS_DIR)/print_diu.c \
38 - $(PRINTERS_DIR)/print_hex.c \
39 - $(PRINTERS_DIR)/print_number.c \
40 - $(PRINTERS_DIR)/print_percent.c \
41 - $(PRINTERS_DIR)/print_s.c \
42 - $(DISPATCHER_DIR)/dispatch.c
43 -
44 -OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o)
45 -
46 -#============================#
47 -# RULES #
48 -#============================#
1+NAME := libftprintf.a
2+
3+SRC_DIR := src
4+INC_DIR := include
5+OBJ_DIR := build
6+
7+CC := cc
8+CFLAGS := -Wall -Wextra -Werror -I$(INC_DIR)
9+
10+SRCS := ft_printf.c \
11+ utils/char.c \
12+ utils/io.c \
13+ utils/memory.c \
14+ utils/numbers.c \
15+ utils/string.c \
16+ parser/parse_format.c \
17+ parser/parse_utils.c \
18+ printers/format_number.c \
19+ printers/format_padding.c \
20+ printers/print_c.c \
21+ printers/print_diu.c \
22+ printers/print_hex.c \
23+ printers/print_number.c \
24+ printers/print_percent.c \
25+ printers/print_s.c \
26+ dispatcher/dispatch.c
27+
28+OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.c=.o))
4929
5030 all: $(NAME)
5131
@@ -54,7 +34,7 @@ bonus: all
5434 $(NAME): $(OBJS)
5535 ar rcs $(NAME) $(OBJS)
5636
57 -$(OBJ_DIR)/%.o: %.c
37+$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
5838 mkdir -p $(dir $@)
5939 $(CC) $(CFLAGS) -c $< -o $@
6040
+24, -23
@@ -209,12 +209,9 @@ Each part of this implementation is isolated in its own directory to improve rea
209209
210210 The following tree outlines the overall structure:
211211
212 -```
212+```bash
213213 .
214 -├── dispatcher # route specifiers to printers
215 -│ └── dispatch.c
216 -├── ft_printf.c # main ft_printf point
217 -├── include # shared headers and prototypes
214+├── include
218215 │ ├── core.h
219216 │ ├── dispatcher.h
220217 │ ├── ft_printf.h
@@ -222,27 +219,31 @@ The following tree outlines the overall structure:
222219 │ ├── printers.h
223220 │ └── utils.h
224221 ├── Makefile
225 -├── parser # parse format string
226 -│ ├── parse_format.c
227 -│ └── parse_utils.c
228 -├── printers # conversion handlers
229 -│ ├── format_number.c
230 -│ ├── format_padding.c
231 -│ ├── print_c.c
232 -│ ├── print_diu.c
233 -│ ├── print_hex.c
234 -│ ├── print_number.c
235 -│ └── print_s.c
236222 ├── README.md
237 -└── utils # helper functions
238 - ├── char.c
239 - ├── io.c
240 - ├── memory.c
241 - ├── numbers.c
242 - └── string.c
223+└── src
224+ ├── dispatcher
225+ │ └── dispatch.c
226+ ├── ft_printf.c
227+ ├── parser
228+ │ ├── parse_format.c
229+ │ └── parse_utils.c
230+ ├── printers
231+ │ ├── format_number.c
232+ │ ├── format_padding.c
233+ │ ├── print_c.c
234+ │ ├── print_diu.c
235+ │ ├── print_hex.c
236+ │ ├── print_number.c
237+ │ ├── print_percent.c
238+ │ └── print_s.c
239+ └── utils
240+ ├── char.c
241+ ├── io.c
242+ ├── memory.c
243+ ├── numbers.c
244+ └── string.c
243245 ```
244246
245 -
246247 <h3 id="parsing_strategy">Parsing Strategy</h3>
247248
248249 The format string is processed until the first occurrence of the character `%`. If it is encountered, all subsequent characters up to the specifier are parsed to extract:
+2, -2
@@ -6,14 +6,14 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/04 03:20:27 by mleitao #+# #+# */
9 -/* Updated: 2026/04/04 03:21:05 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:04:16 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
1313 #ifndef DISPATCHER_H
1414 # define DISPATCHER_H
1515
16 -# include <core.h>
16+# include "core.h"
1717
1818 int dispatch(t_data *d);
1919
+2, -2
@@ -6,14 +6,14 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/30 18:24:06 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:28:19 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:04:30 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
1313 #ifndef PARSER_H
1414 # define PARSER_H
1515
16 -# include <core.h>
16+# include "core.h"
1717
1818 int parse_format(t_data *d);
1919
+2, -2
@@ -6,14 +6,14 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/31 01:35:58 by mleitao #+# #+# */
9 -/* Updated: 2026/04/17 17:39:27 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:04:40 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
1313 #ifndef PRINTERS_H
1414 # define PRINTERS_H
1515
16 -# include <core.h>
16+# include "core.h"
1717
1818 typedef struct s_num
1919 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/04 03:21:25 by mleitao #+# #+# */
9 -/* Updated: 2026/04/17 17:38:04 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:05:06 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <dispatcher.h>
14 -#include <printers.h>
13+#include "dispatcher.h"
14+#include "printers.h"
1515
1616 int dispatch(t_data *d)
1717 {
@@ -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/04 03:23:31 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:03:52 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <core.h>
14 -#include <utils.h>
15 -#include <parser.h>
16 -#include <dispatcher.h>
13+#include "core.h"
14+#include "utils.h"
15+#include "parser.h"
16+#include "dispatcher.h"
1717
1818 static void init_data(t_data *d, const char *fmt)
1919 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/30 17:45:38 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:29:04 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:05:27 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <parser.h>
14 -#include <utils.h>
13+#include "parser.h"
14+#include "utils.h"
1515
1616 static void reset_format(t_data *d)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/30 18:11:57 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:32:09 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:05:43 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <parser.h>
14 -#include <utils.h>
13+#include "parser.h"
14+#include "utils.h"
1515
1616 void set_flags(t_data *d)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/02 23:49:35 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 01:06:54 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:06:02 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
14 -#include <printers.h>
13+#include "utils.h"
14+#include "printers.h"
1515
1616 int print_sign(t_data *d, t_numdata *n)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/03 00:28:09 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 01:06:35 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:06:21 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
14 -#include <printers.h>
13+#include "utils.h"
14+#include "printers.h"
1515
1616 int calculate_width(int width, int len)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/31 01:38:40 by mleitao #+# #+# */
9 -/* Updated: 2026/04/17 17:40:54 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:06:37 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <printers.h>
14 -#include <utils.h>
13+#include "printers.h"
14+#include "utils.h"
1515
1616 int print_c(t_data *d, char c)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/31 17:51:31 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 00:51:56 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:06:52 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <printers.h>
14 -#include <utils.h>
13+#include "printers.h"
14+#include "utils.h"
1515 #include <stdlib.h>
1616
1717 static int init_signed(t_data *d, t_numdata *n, long nb)
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/02 02:08:13 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 00:56:27 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:07:09 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <printers.h>
14 -#include <utils.h>
13+#include "printers.h"
14+#include "utils.h"
1515 #include <stdlib.h>
1616
1717 static int init_hex(t_data *d, t_numdata *n,
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/31 01:40:51 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 01:15:33 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:07:22 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <printers.h>
14 -#include <utils.h>
13+#include "printers.h"
14+#include "utils.h"
1515
1616 static int print_formatted(t_data *d, t_numdata *n, int left_align)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <marvin@42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/17 17:33:54 by mleitao #+# #+# */
9 -/* Updated: 2026/04/17 17:39:02 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:07:33 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <printers.h>
14 -#include <utils.h>
13+#include "printers.h"
14+#include "utils.h"
1515
1616 int print_percent(t_data *d)
1717 {
@@ -6,12 +6,12 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/31 02:13:27 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 00:42:43 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:07:45 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <printers.h>
14 -#include <utils.h>
13+#include "printers.h"
14+#include "utils.h"
1515
1616 int print_s(t_data *d, char *str)
1717 {
@@ -6,11 +6,11 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/02 03:53:58 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:33:06 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:07:59 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
13+#include "utils.h"
1414
1515 size_t ft_isdigit(int c)
1616 {
+2, -2
@@ -6,11 +6,11 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/30 17:49:31 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:54:08 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:08:14 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
13+#include "utils.h"
1414
1515 int putnchar(char c, int n)
1616 {
@@ -6,11 +6,11 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/12 20:15:18 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:33:19 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:08:23 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
13+#include "utils.h"
1414 #include <stdlib.h>
1515 #include <stdint.h>
1616
@@ -6,11 +6,11 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/03/15 14:49:46 by mleitao #+# #+# */
9 -/* Updated: 2026/04/03 01:08:32 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:08:33 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
13+#include "utils.h"
1414
1515 static size_t count_digits(long long n)
1616 {
@@ -6,11 +6,11 @@
6 6 /* By: mleitao <mleitao@student.42.fr> +#+ +:+ +#+ */
7 7 /* +#+#+#+#+#+ +#+ */
8 8 /* Created: 2026/04/02 03:54:37 by mleitao #+# #+# */
9 -/* Updated: 2026/04/02 14:33:21 by mleitao ### ########.fr */
9+/* Updated: 2026/04/30 15:08:41 by mleitao ### ########.fr */
1010 /* */
1111 /* ************************************************************************** */
1212
13 -#include <utils.h>
13+#include "utils.h"
1414 #include <stddef.h>
1515
1616 char *ft_strchr(const char *s, int c)