-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.c
More file actions
120 lines (110 loc) · 2.67 KB
/
errors.c
File metadata and controls
120 lines (110 loc) · 2.67 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* ************************************************************************** */
/* */
/* :::::::: */
/* errors.c :+: :+: */
/* +:+ */
/* By: dkramer <dkramer@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/12/14 14:29:27 by dkramer #+# #+# */
/* Updated: 2022/01/19 18:33:41 by dkramer ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft/ft_printf/libftprintf.h"
#include "libft/libft.h"
#include <stdlib.h>
#include "push_swap.h"
int ft_specatoi(const char *st, t_str *str)
{
long long int nmb;
int i;
int a;
nmb = 0;
i = 0;
a = 1;
while (((st[i] >= 9 && st[i] <= 13) || st[i] == 32) && st[i])
i++;
if ((st[i] == '-' || st[i] == '+') && st[i])
{
if (st[i] == '-')
a = a * -1;
i++;
}
if (st[i] == '-' || st[i] == '+')
str->extraminusorplus = 1;
while (st[i] != '\0' && st[i] >= '0' && st[i] <= '9' && st[i])
{
nmb = (nmb * 10) + st[i] - 48;
i++;
}
return (extrachecks(nmb, a, str));
}
int *noninteger(char **argv, t_str *str)
{
int i;
int a;
i = 1;
while (i < str->argc)
{
a = 0;
while (argv[i][a])
{
if (!ft_strrchr("-+0123456789", argv[i][a]))
return (returnft(str));
a++;
}
i++;
}
return ((int *)1);
}
int *maxint(int *stacka, char **argv, t_str *str)
{
int i;
int a;
a = 1;
i = 0;
str->isminusone = 0;
str->extraminusorplus = 0;
while (i < str->argc - 1 && a < str->argc)
{
stacka[i] = ft_specatoi(argv[a], str);
if (str->extraminusorplus == 1)
return (returnft(str));
if (stacka[i] == -1 && str->isminusone != 1)
return (returnft(str));
i++;
a++;
}
return ((int *)1);
}
int *duplicates(char **argv, t_str *str)
{
char *save;
int i;
int a;
i = 1;
while (i < str->argc)
{
save = argv[i];
a = 1;
while (a < str->argc)
{
if (!ft_strncmp(save, argv[a], 11) && a != i)
return (returnft(str));
a++;
}
i++;
}
return ((int *)1);
}
/* some arguments are not integers, some arguments are bigger than an integer,
there are duplicates*/
int *errors(int *stacka, char **argv, t_str *str)
{
if (!noninteger(argv, str))
return (0);
if (!maxint(stacka, argv, str))
return (0);
if (!duplicates(argv, str))
return (0);
return ((int *)1);
}