-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlesimplecase.c
84 lines (76 loc) · 2.86 KB
/
handlesimplecase.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handlesimplecase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpernia- <mpernia-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/12 23:17:37 by mpernia- #+# #+# */
/* Updated: 2020/01/15 21:56:36 by mpernia- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include "libft/libft.h"
int print_singlechar(t_case *format, va_list args)
{
format = check_flags(format, args);
format->width = (format->width > 0 ? format->width : 1);
if (format->width > 1 && format->left_align == 0)
(format->zero_filler == 0 ? ft_putcharntimes(' ', format->width - 1) :
ft_putcharntimes('0', format->width - 1));
if (!ft_strchr(format->flags, 'l'))
(format->var_type == 'c' ? ft_putchar(va_arg(args, int)) :
ft_putchar('%'));
else
ft_putchar_wchart(va_arg(args, wint_t));
if (format->width > 1 && format->left_align == 1)
ft_putcharntimes(' ', format->width - 1);
return (format->width);
}
int print_0(char *s)
{
ft_putstr(s);
return (ft_strlen(s));
}
int print_s(t_case *format, va_list args)
{
format = check_flags(format, args);
return ((ft_strchr(format->flags, 'l') ? print_swchar(format, args) :
print_schar(format, args)));
}
int print_schar(t_case *format, va_list args)
{
char *aux;
int len;
int i;
aux = va_arg(args, char*);
if (aux == NULL)
aux = ft_strdup("(null)");
len = (int)ft_strlen(aux);
format = get_wp(format, len);
if (format->left_align == 0 && format->width > format->precision)
ft_putcharntimes(' ', format->width - format->precision);
i = 0;
write(1, aux, format->precision);
if (format->left_align == 1 && format->width > format->precision)
ft_putcharntimes(' ', format->width - format->precision);
return (format->width);
}
int print_swchar(t_case *format, va_list args)
{
wchar_t *aux;
int len;
int i;
aux = va_arg(args, wchar_t*);
if (aux == NULL)
aux = (wchar_t*)ft_strdup("(null)");
len = ft_strlen_wchart(aux);
format = get_wp(format, len);
if (format->left_align == 0 && format->width > format->precision)
ft_putcharntimes(' ', format->width - format->precision);
i = 0;
write(1, aux, format->precision);
if (format->left_align == 1 && format->width > format->precision)
ft_putcharntimes(' ', format->width - format->precision);
return (format->width);
}