-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.h
More file actions
139 lines (115 loc) · 3.55 KB
/
Copy pathft_printf.h
File metadata and controls
139 lines (115 loc) · 3.55 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmelvin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 14:52:35 by tmelvin #+# #+# */
/* Updated: 2019/12/18 15:25:03 by tmelvin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdio.h>
# include <stdlib.h>
# include <stdarg.h>
# include <unistd.h>
# include <wchar.h>
# include "libft/libft.h"
/*
** Flag masks definition
*/
# define F_HASH (1 << 0)
# define F_MINUS (1 << 1)
# define F_PLUS (1 << 2)
# define F_SPACE (1 << 3)
# define F_ZERO (1 << 4)
# define F_APOSTROPHE (1 << 5)
# define F_L (1 << 6)
# define F_LL (1 << 7)
# define F_H (1 << 8)
# define F_HH (1 << 9)
# define F_PRECISION (1 << 10)
# define INTEGER_CONVERSION (1 << 11)
# define SIGNED_CONVERSION (1 << 12)
# define NULL_TERMINATOR (1 << 13)
# define FLAG_ORDER "#-+ 0'"
/*
** Structure definition
*/
typedef struct s_printf
{
short flags;
int min_width;
int precision;
unsigned int c;
int is_negative;
int buf_index;
char *buf;
int buf_size;
va_list arg;
char *format;
short error;
char *conversion;
wint_t character;
} t_printf;
/*
** Main functions
*/
int ft_printf(const char *format, ...);
void process_format(t_printf *p);
void convert(t_printf *p);
void handle_initial_conversion(t_printf *p);
void ready_for_next_conversion(t_printf *p);
/*
** Functions to parse and store flags + min_width + precision + modifiers
*/
void get_info(t_printf *p);
void get_flags(t_printf *p);
void get_min_width(t_printf *p);
void get_precision(t_printf *p);
void get_modifiers(t_printf *p);
/*
** Functions to perform specific conversions
*/
void convert_c(t_printf *p);
void convert_s(t_printf *p);
void convert_p(t_printf *p);
void convert_di(t_printf *p);
void convert_u(t_printf *p);
void convert_x(t_printf *p);
void convert_n(t_printf *p);
void convert_percent(t_printf *p);
/*
** Functions to apply min width + precision to the converted string
*/
void handle_min_width(t_printf *p);
int get_pad_size(t_printf *p);
void handle_precision(t_printf *p);
/*
** Functions to apply certain flags to the converted string
*/
void handle_hash(t_printf *p);
void handle_sign(t_printf *p);
void add_separators(t_printf *p);
/*
** Buffer related functions
*/
void add_to_buf(t_printf *p, void *src, size_t size);
/*
** Other miscellaneous functions
*/
void error_return(t_printf *p, int error_number);
void prepend(t_printf *p, char *str, int dynamic);
void append(t_printf *p, char *str, int dynamic);
int max(int a, int b);
int min(int a, int b);
/*
** Functions used in wide conversions
*/
void convert_ws(t_printf *p, wchar_t *ws);
int check_ws(t_printf *p, wchar_t *ws);
char *convert_wchar(unsigned int wc, int wlen,
int nb_bytes, char *tmp);
#endif