-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.c
81 lines (73 loc) · 1.9 KB
/
parse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kaoyama <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/08 11:05:46 by takokamo #+# #+# */
/* Updated: 2022/05/08 20:49:51 by kaoyama ### ########.fr */
/* */
/* ************************************************************************** */
#include "declaration.h"
unsigned int ft_strlen_arg(unsigned int argc, char **argv)
{
unsigned int i;
i = 0;
while (argv[argc - 1][i] != '\0')
{
i++;
}
return (i);
}
void ft_putstr(char *str)
{
while (*str != '\0')
{
write(1, str, 1);
str++;
}
}
long ft_atoi_mini(int argc, char **argv)
{
unsigned int j;
long check_max;
long num;
j = 0;
num = 0;
check_max = 0;
while (argv[argc - 1][j] != '\0')
{
check_max = (check_max * 10) + (argv[argc - 1][j] - '0');
if (check_max > 4294967295)
{
ft_putstr("Error\n");
return (-1);
}
j++;
}
num = check_max;
return (num);
}
long ft_argcheck(int argc, char **argv)
{
int j;
int input_len;
long conv_num;
input_len = ft_strlen_arg(argc, argv);
j = 0;
while (argv[argc - 1][j] <= '9' && argv[argc - 1][j] >= '0')
j++;
if (input_len != j)
{
ft_putstr("Error\n");
return (-1);
}
if (argv[argc - 1][0] == '0' && argv[argc - 1][1] != '\0')
{
ft_putstr("Error\n");
return (-1);
}
conv_num = ft_atoi_mini(argc, argv);
return (conv_num);
}