aboutsummaryrefslogtreecommitdiff
path: root/header.h
blob: 72108ab438f042144733ac593844b910479fe690 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   header.h                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/10/29 00:06:46 by cacharle          #+#    #+#             */
/*   Updated: 2019/10/29 05:01:00 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef HEADER_H
# define HEADER_H

# include <stdarg.h>
# include "libft.h"

# define TRUE 1
# define FALSE 0

# define HEX_SYMBOLS "0123456789abcdef"
# define HEX_MAJ_SYMBOLS "0123456789ABCDEF"

# define IS_STANDALONE_FLAG(c) (c == '0' || c == '-')

# define CONVERSIONS_STR "cspdiuxX%"

# define CONVERSION_CHAR 'c'
# define CONVERSION_STR 's'
# define CONVERSION_PTR 'p'
# define CONVERSION_DECIMAL 'd'
# define CONVERSION_INT 'i'
# define CONVERSION_UINT 'u'
# define CONVERSION_HEX_LOWER 'x'
# define CONVERSION_HEX_UPPER 'X'
# define CONVERSION_PERCENT '%'

# define FLAG_LEFT_ADJUSTED       0b00000001
# define FLAG_ZERO_PADDING        0b00000010
# define FLAG_MIN_WIDTH_WILDCARD  0b00000100
# define FLAG_PRECISION_WILDCARD  0b00001000
# define FLAG_MIN_WIDTH_OVERWRITE 0b00010000

#include <stdio.h>

typedef char			t_conversion;
typedef int				t_bool;
typedef unsigned char	t_flags;

typedef struct
{
	int				precision;
	int				min_width;
	t_flags			flags;
	t_conversion	conversion;
	int				len;
}					t_pformat;

typedef struct		s_flist
{
	struct s_flist	*next;
	t_pformat		*content;
}					t_flist;

/*
** ft_printf.c
*/

int					ft_printf(const char *format, ...);

/*
** parse.c
*/

t_flist				*parse(char *format);
t_pformat			*parse_reduced(char *fmt);

/*
** printer.c
*/

char	*convert(t_pformat *pformat, va_list ap);
char	*convert_type(t_conversion conversion, va_list ap);
char	*handle_padding(t_pformat *pformat, char *str);
char	*handle_precision(t_pformat *pformat, char *str);
char				*add_address_prefix(char *addr);

/*
** utils.c
*/

int					strrchr_index(const char *s, char c);

/*
** extract.c
*/

char				*extract_standalone_flags(t_pformat *pformat, char *fmt);
char				*extract_min_width(t_pformat *pformat, char *fmt);
char				*extract_precision(t_pformat *pformat, char *fmt);

/*
** list.c
*/

t_flist				*list_new(t_pformat *content);
void				*list_destroy(t_flist **lst);
void				list_push_front(t_flist **lst, t_flist *new);
void				list_pop_front(t_flist **lst);
t_flist				*list_reverse(t_flist *lst);

#endif