-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.c
More file actions
93 lines (83 loc) · 2.51 KB
/
Copy pathdisplay.c
File metadata and controls
93 lines (83 loc) · 2.51 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* display.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gdannay <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/29 15:03:31 by gdannay #+# #+# */
/* Updated: 2018/01/03 20:38:28 by gdannay ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int manage_display(t_flag *tmp, char *buff)
{
int length;
length = 0;
if (tmp->intdisplay == 1 || tmp->intdisplay == 6)
length = manage_nb(tmp, buff);
else if (tmp->intdisplay == 9)
length = manage_wstring(tmp, buff);
else if (tmp->intdisplay == 8)
length = manage_uni(tmp, buff);
else if (tmp->intdisplay == 2 || tmp->intdisplay == 9)
length = manage_char(tmp, buff);
else if (tmp->intdisplay == 3)
length = manage_string(tmp, buff);
return (length);
}
static int display_normal(char *str, int *i, char *buff)
{
int length;
int j;
length = 0;
j = *i;
while (str[*i] && str[*i] != '%')
{
length++;
*i = *i + 1;
}
return (manage_buff(buff, str + j, (size_t)(*i - j)));
}
static void manage_undefined(char *str, int *i, t_flag *tmp)
{
*i = *i + 1;
while (str[*i] && str[*i] != tmp->type)
*i = *i + 1;
if (tmp && str[*i] == tmp->type)
tmp = tmp->next;
}
static int print_arg(char *buff, t_flag **tmp, char *str, int *i)
{
int length;
length = 0;
length = manage_display(*tmp, buff);
*i = *i + 1;
while (str[*i + 1] && str[*i] != (*tmp)->type)
*i = *i + 1;
*tmp = (*tmp)->next;
*i = *i + 1;
return (length);
}
int display(char *str, t_flag *flag)
{
int i;
int length;
t_flag *tmp;
char buff[BUFF_SIZE];
i = 0;
length = 0;
buff[0] = '\0';
tmp = flag;
while (str && str[i] != '\0')
{
if (str[i] == '%' && str[i + 1] && tmp->inttype != 0)
length += print_arg(buff, &tmp, str, &i);
else if (str[i] == '%' && ((!tmp) || tmp->inttype == 0))
manage_undefined(str, &i, tmp);
else
length += display_normal(str, &i, buff);
}
length += print_buff(buff);
return (length);
}