-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_getspace.c
46 lines (43 loc) · 1.7 KB
/
ft_printf_getspace.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_getspace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfrisby <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/11 13:12:12 by mfrisby #+# #+# */
/* Updated: 2017/07/11 13:16:15 by mfrisby ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
static char *flagcompar(t_env *e, char *s)
{
if (e->type == 'c' && ft_strcmp(s, "") == 0)
e->field_width -= 1;
if (e->type == 'c')
e->precision = -1;
if ((e->flag_moins == 1 || e->precision >= 0) && e->flag_zero == 1 &&
(e->type == 'd' || e->type == 'u' || e->type == 'o'
|| e->type == 'x' || e->type == 'X'))
e->flag_zero = 0;
if (e->flag_plus == 1 && e->neg == 1)
e->flag_plus = 0;
if (e->flag_plus == 1 && e->flag_space == 1)
e->flag_space = 0;
if (e->neg == 1 && e->flag_space == 1)
e->flag_space = 0;
if (e->flag_space == 1)
e->field_width -= 1;
return (s);
}
char *getspace(t_env *e, char *space, char *s)
{
flagcompar(e, s);
space = malloc(sizeof(char) * 2);
if (e->type == 'd' && e->flag_space == 1)
space[0] = ' ';
else
space[0] = '\0';
space[1] = '\0';
return (space);
}