This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.c
77 lines (68 loc) · 1.7 KB
/
error.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
/*
** EPITECH PROJECT, 2019
** CPool_infinadd_2019
** File description:
** Adding stuff together
*/
#include "include/my.h"
int check_dupe(char *str);
int check_repetition(char *str1, char *str2);
int print_error(void)
{
my_putstr("syntax error");
return 0;
}
int base_include_test(char *str, char *base, char *spec)
{
int check;
for (int x = 0; str[x] != '\n'; x++) {
check = 0;
for (int i = 0; base[i] != '\0'; i++)
if (base[i] == str[x])
check = 1;
for (int i = 0; spec[i] != '\0'; i++)
if (spec[i] == str[x])
check = 1;
if (!check)
return print_error();
}
return 1;
}
int char_in_array(char c, char *str)
{
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == c)
return 1;
}
return 0;
}
int cases_one(char *str, char *base, char *spec)
{
int count1 = 0;
int count2 = 0;
for (int i = 0; str[i] != '\n'; i++) {
if (char_in_array(str[i], base) && str[i+1] == spec[0])
return print_error();
if (char_in_array(str[i + 1], base) && str[i] == spec[1])
return print_error();
if (str[i] == spec[0])
count1++;
if (str[i] == spec[1])
count2++;
}
if (count1 != count2)
return print_error();
return 1;
}
int error_test(char *str, char *base, char *spec)
{
if (str[0] == '\n' || my_strlen(spec) != 7)
return print_error() + 1;
if (!check_dupe(base) || !check_dupe(spec) || !check_repetition(base, spec))
return 1;
if (!base_include_test(str, base, spec))
return 1;
if (!cases_one(str, base, spec))
return 1;
return 0;
}