-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_bonus.h
126 lines (115 loc) · 4.11 KB
/
ft_printf_bonus.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_bonus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaibar-h <aaibar-h@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/01 22:28:22 by aaibar-h #+# #+# */
/* Updated: 2023/09/11 15:01:57 by aaibar-h ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_BONUS_H
# define FT_PRINTF_BONUS_H
# include <stddef.h>
# include <unistd.h>
# ifndef FORM_CVS
# define FORM_CVS "cspdiuxX%"
# endif
# ifndef FORM_FLAGS
# define FORM_FLAGS "# +-.0"
# endif
# ifndef FLAG_ALT_FORM
# define FLAG_ALT_FORM 0x1
# endif
# ifndef FLAG_SPACE
# define FLAG_SPACE 0x2
# endif
# ifndef FLAG_PLUS
# define FLAG_PLUS 0x4
# endif
# ifndef STR_FORM_CVS
# define STR_FORM_CVS "cs%"
# endif
# ifndef NBR_FORM_CVS
# define NBR_FORM_CVS "pdiuxX"
# endif
# ifndef STDOUT_FD
# define STDOUT_FD 1
# endif
/**
* @brief Produces an output based on a given formatted string. Additional
* arguments may be passed with varags.
*
* @param str Formatted string about to be printed
* @param ... Varargs containing values
* @return int Uppon success, number of ouptutted characters of `str`, excluding
* NUL character and including the ones inserted after formatting.
* A negative handle will be return if some error is found
*/
int ft_printf(const char *str, ...);
/**
* @brief Writes into stdout any standard string.
*
* @param str String to be printed.
* @return int Upon success, returns the characters written, excluding NUL
* terminator.
*/
int ft_prints(const char *str);
/**
* @brief Given a pointer to a string (starting with the formatter character),
* parses printf flags and returns a bit flag variable. Moves the pointer after
* the last flag.
*
* @param pstr Pointer to the string
* @return Bit flag variable
*/
size_t ft_read_flags(const char **pstr);
/**
* @brief Returns a string after converting the int `n` to hexadecimal.
*
* @param n Number to be converted
* @param achr Character to be used as the first character of the hexadecimal
* @return char* String containing the hexadecimal representation of `n`.
*/
char *ft_itoh(unsigned int n, char achr);
/**
* @brief Returns a string after converting the int `n` to hexadecimal,
* prefixed with `0x`.
*
* @param n Number to be converted
* @param achr Character to be used as the first character of the hexadecimal
* @return char* String containing the hexadecimal representation of `n`.
*/
char *ft_itoph(unsigned int n, char achr);
char *ft_ultoh(size_t n, char achr);
/**
* @brief Returns a string after converting the size_t `n` to hexadecimal,
* prefixed with `0x`.
*
* @param n Number to be converted
* @param achr Character to be used as the first character of the hexadecimal
* @return char* String containing the hexadecimal representation of `n`.
*/
char *ft_ultoph(size_t n, char achr);
/**
* @brief Takes a decimal number, and returns a string containing the decimal
* representation of the number, after applying the formatter flags.
*
* @param dec Number to be converted
* @param flags Variable containing bit flags
* @return char* Resulting string
*/
char *ft_parse_dec_flags(int dec, size_t flags);
/**
* @brief Takes a hex format character ('x' or 'X') and a hexadecimal number,
* and returns a string containing the hexadecimal representation of the number,
* after applying the formatter flags.
*
* @param fmtc Format character
* @param hex Number to be converted
* @param flags Variable containing bit flags
* @return char* Resulting string
*/
char *ft_parse_hex_flags(const char *fmtc, unsigned int hex, size_t flags);
#endif