-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr_type.c
More file actions
90 lines (81 loc) · 2.17 KB
/
Copy pathstr_type.c
File metadata and controls
90 lines (81 loc) · 2.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_type.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgomez-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/11 08:45:36 by pgomez-a #+# #+# */
/* Updated: 2021/03/12 08:55:06 by pgomez-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void man_pre(char **output, char **pre)
{
char *aux;
int num;
(**pre) = '\0';
(*pre)++;
aux = *output;
num = ft_atoi(*pre);
if (num < (int)ft_strlen(*output) && num >= 0)
{
while (num > 0)
{
aux++;
num--;
}
*aux = '\0';
}
}
static void str_pos_width(char **output, char **width, int **result)
{
int num;
num = ft_atoi(*width) - ft_strlen(*output);
while (num > 0)
{
if (**width == '0')
ft_putchar_fd('0', 1);
else
ft_putchar_fd(' ', 1);
(**result) += 1;
num--;
}
ft_putstr_fd(*output, 1);
(**result) += ft_strlen(*output);
}
static void str_neg_width(char **output, char **width, int **result)
{
char *aux;
int num;
aux = ft_strchr(*width, '-');
aux++;
num = ft_atoi(aux) - ft_strlen(*output);
ft_putstr_fd(*output, 1);
(**result) += ft_strlen(*output);
while (num > 0)
{
ft_putchar_fd(' ', 1);
(**result) += 1;
num--;
}
}
void pf_find_str(va_list *ap, char **width, int **result)
{
char *str;
char *output;
char *pre;
str = va_arg(*ap, char *);
if (str)
output = ft_strdup(str);
else
output = ft_strdup("(null)");
pre = ft_strchr(*width, '.');
if (pre)
man_pre(&output, &pre);
if (ft_strchr(*width, '-'))
str_neg_width(&output, width, result);
else
str_pos_width(&output, width, result);
free(output);
}