-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.h
109 lines (95 loc) · 2.88 KB
/
ft_printf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printf.h :+: :+: */
/* +:+ */
/* By: jsaariko <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/01/14 13:02:19 by jsaariko #+# #+# */
/* Updated: 2020/03/14 12:06:33 by jsaariko ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdarg.h>
# include "libft/libft.h"
typedef union u_type
{
long long i;
unsigned long long u;
char c;
char *s;
unsigned long long p;
double f;
} t_type;
typedef enum e_conversion
{
d,
i,
u,
c,
s,
x,
X,
p,
f,
} t_conversion;
typedef enum e_padding
{
p_normal,
p_zero,
p_left,
} t_padding;
typedef struct s_printf_arg
{
t_conversion conv;
t_type arg;
t_padding pad_type;
size_t field_width;
size_t arg_width;
ssize_t precision;
struct s_printf_arg *next;
} t_printf_arg;
typedef enum e_transition_code
{
t_dash,
t_zero,
t_num,
t_dot,
t_ast,
t_error,
t_exit,
} t_transition_code;
typedef char *(*t_func)(t_printf_arg **);
int ft_printf(const char *str, ...);
/*
** PARSER
*/
void manage_parser(t_printf_arg **arg, char *tokens, va_list ap);
t_transition_code get_transition(char token);
t_transition_code get_transition_code(char token);
void store_int(char c, t_printf_arg **cur, va_list ap);
void store_uint(char c, t_printf_arg **cur, va_list ap);
void store_char(char c, t_printf_arg **cur, va_list ap);
void store_float(t_printf_arg **cur, va_list ap);
int store_other(char c, t_printf_arg **cur, va_list ap);
void add_conv(char **final, char *conv, t_printf_arg **arg);
/*
** EXECUTOR
*/
int manage_print(const char *str, t_printf_arg **head);
char *execute_arg(t_printf_arg **cur_arg);
int gen_arg_list(t_printf_arg **head, const char *str,
va_list ap);
char *convert_char(t_printf_arg **arg);
char *convert_int(t_printf_arg **arg);
char *convert_uint(t_printf_arg **arg);
char *convert_str(t_printf_arg **arg);
char *convert_hex_lc(t_printf_arg **arg);
char *convert_hex_uc(t_printf_arg **arg);
char *convert_ptr(t_printf_arg **arg);
char *convert_float(t_printf_arg **arg);
char *apply_precision(t_printf_arg **arg, char *str);
char *fill_buffer(t_printf_arg **arg);
void clear_list(t_printf_arg **head);
#endif