-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_s.c
108 lines (99 loc) · 2.35 KB
/
ft_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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_s.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oltkache <oltkache@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/14 16:24:17 by oltkache #+# #+# */
/* Updated: 2018/02/16 16:43:55 by oltkache ### ########.fr */
/* */
/* ************************************************************************** */
#include "printf.h"
int ft_space_s(int *l, wchar_t *a, char *t, int r)
{
int j;
j = 0;
if (l[7] == 1)
j = l[3] - ft_strlen_u(a);
else
{
if (r == 1)
j = l[3] - ft_strlen(t);
else
j = l[3] - ft_strlen((char*)a);
}
if (l[1] == 1 && l[0] != 1)
ft_spaces(j, 2);
else
ft_spaces(j, 1);
if (j > 0)
return (j);
return (0);
}
int ft_print_s(wchar_t *a, char *t, int f, int r)
{
int s;
s = 0;
if (f == 1)
ft_putstr_u(a, &s);
else
{
if (r == 1)
{
ft_putstr(t);
s += ft_strlen(t);
}
else
{
ft_putstr((char*)a);
s += ft_strlen((char*)a);
}
}
return (s);
}
int ft_ch_s(wchar_t *a, int *s, int *l)
{
if (a == NULL)
{
write(1, "(null)", 6);
*s += 6;
ft_memdel((void*)(&l));
return (1);
}
return (0);
}
void ft_del(int r, int *l, char *t, wchar_t *a)
{
if (r == 1 && l[7] != 1)
ft_memdel((void*)(&t));
else if (r == 1 && l[7] == 1)
ft_memdel((void*)(&a));
ft_memdel((void*)(&l));
}
void ft_s(char *str, wchar_t *a, int j, int *s)
{
int *l;
int r;
char *t;
r = 0;
t = NULL;
l = ft_loop(j, str, 0);
if (str[j] == 'S')
l[7] = 1;
if (ft_ch_s(a, s, l) == 1)
return ;
if (l[7] != 1)
{
if (l[4] != -1 && l[4] < (int)ft_strlen((char*)a) && (r = 1))
t = ft_strsub((char*)a, 0, l[4]);
}
else if (l[4] != -1 && l[4] < ft_strlen_u(a) && (r = 1))
a = ft_sub_u(a, l[4]);
if (l[0] == 1)
*s += ft_print_s(a, t, l[7], r);
*s += ft_space_s(l, a, t, r);
if (l[0] != 1)
*s += ft_print_s(a, t, l[7], r);
ft_del(r, l, t, a);
}