-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_s.c
66 lines (61 loc) · 1.84 KB
/
type_s.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_s.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nahmed-m <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/19 22:20:22 by nahmed-m #+# #+# */
/* Updated: 2016/02/03 15:45:52 by nahmed-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void ft_putstr_left(char *str, t_var *e)
{
ft_putstr(str);
e->ret += ft_strlen(str);
ft_put_space(e->f_width - ft_strlen(str), e);
free(str);
}
static void ft_putstr_right(char *str, t_var *e)
{
if (e->f_zero == 0)
ft_put_space(e->f_width - ft_strlen(str), e);
else
ft_put_zero(e->f_width - ft_strlen(str), e);
ft_putstr(str);
e->ret += ft_strlen(str);
free(str);
}
void type_s(t_var *e)
{
char *str;
char *res;
res = va_arg(e->ap, char*);
if (res)
str = ft_strdup(res);
else if (!res && e->f_zero == 0)
{
ft_putstr("(null)");
e->ret += 6;
return ;
}
if (e->f_precis != 1)
str = ft_strsub(str, 0, e->f_precis);
else if (e->f_precis == 0)
{
ft_put_space(1000000, e);
return ;
}
if (e->f_width == 0)
{
ft_putstr(str);
e->ret += ft_strlen(str);
free(str);
return ;
}
else if (e->f_width != 0 && e->f_left == 1)
ft_putstr_left(str, e);
else if (e->f_width != 0 && e->f_left == 0)
ft_putstr_right(str, e);
}