This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_printf.h
93 lines (83 loc) · 3.09 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/10 13:25:09 by mcombeau #+# #+# */
/* Updated: 2021/12/17 16:21:09 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdarg.h>
# include <unistd.h>
# include <stdlib.h>
# include <stdio.h>
# include "libft/libft.h"
# if defined (__linux__)
# define PTRNULL "(nil)"
# elif defined (__APPLE__)
# define PTRNULL "0x0"
# endif
/* ---------- FLAGS --------------------- */
typedef struct s_flags
{
int spec;
int width;
int left;
int zero;
int star;
int precision;
int hash;
int space;
int plus;
} t_flags;
t_flags ft_flags_init(void);
t_flags ft_flag_left(t_flags flags);
t_flags ft_flag_digit(char c, t_flags flags);
t_flags ft_flag_width(va_list args, t_flags flags);
int ft_flag_precision(const char *str, int pos,
va_list args, t_flags *flags);
/* ---------- PRINTF -------------------- */
int ft_printf(const char *format, ...);
int ft_print_arg(char type, va_list args, t_flags flags);
/* ---------- PRINT SPECIFIERS ---------- */
// c
int ft_print_char(char c, t_flags flags);
int ft_print_c(char c);
// s
int ft_print_str(const char *str, t_flags flags);
int ft_print_s(const char *str);
int ft_print_s_pre(const char *str, int precision);
int ft_print_sign_pre(int n, t_flags *flags);
// i, d
int ft_print_int(int n, t_flags flags);
int ft_print_integer(char *nbstr, int n, t_flags flags);
int ft_print_i(char *nbstr, int n, t_flags flags);
// u
int ft_print_unsigned(unsigned int n, t_flags flags);
int ft_print_u(char *nbstr, t_flags flags);
int ft_print_unint(char *nbstr, t_flags flags);
// x, X
int ft_print_hex(unsigned int n, int is_upper, t_flags flags);
int ft_print_x(char *nbstr, int n, int is_upper, t_flags flags);
int ft_print_hexadec(char *nbstr, int n, int is_upper, t_flags flags);
// p
int ft_print_ptr(unsigned long int n, t_flags flags);
int ft_print_p(unsigned long int n);
void ft_print_adr(unsigned long int n);
/* ---------- HELPER FUNCTIONS ---------- */
char *ft_printf_itoa(long nb);
char *ft_printf_utoa(unsigned int nb);
char *ft_printf_xtoa(unsigned long int nb, int is_upper);
int ft_unint_len(unsigned int n);
int ft_hex_len(unsigned int n);
int ft_ptr_len(unsigned long int n);
int ft_istype(int c);
int ft_isspec(int c);
int ft_isflag(int c);
/* ---------- FLAG FUNCTIONS ------------ */
int ft_pad_width(int total_width, int size, int zero);
#endif