-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag3.c
46 lines (42 loc) · 2.06 KB
/
flag3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flag3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abello-r <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/03 17:16:04 by abello-r #+# #+# */
/* Updated: 2020/03/03 17:16:07 by abello-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_decision(t_printf *format, char *str, int len)
{
format->len_str += write(1, str, (format->dot == '.' &&
format->precision == -1) ? 0 : len);
}
void ft_display_s(t_printf *format, char *str)
{
int space;
int len;
int len_null;
str = (str == NULL) ? "(null)" : str;
len = ft_strlen(str);
len -= (format->precision > 0 &&
format->precision < len) ? (len - format->precision) : 0;
len -= (format->dot == '.' && format->tab == '-' &&
format->precision == 0 && format->width == 0) ? len : 0;
len -= (format->dot == '.' && format->tab != '-' &&
format->precision == 0 && format->width == 0) ? len : 0;
len -= (format->precision == 0 && format->width > 0 &&
format->zero_space == ' ' && format->dot == '.') ? len : 0;
space = (format->width > 0) ? (format->width - len) : 0;
space += (format->tab == '-') ? 1 : 0;
format->zero_space = (format->tab == '-' &&
format->zero_space == '0') ? ' ' : format->zero_space;
while (space-- > 0 && format->tab != '-')
format->len_str += write(1, &format->zero_space, 1);
(str == NULL) ? 0 : ft_decision(format, str, len);
while (space-- > 0 && format->tab == '-')
format->len_str += write(1, &format->zero_space, 1);
}