-
Notifications
You must be signed in to change notification settings - Fork 0
/
credits.c
87 lines (80 loc) · 2.17 KB
/
credits.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
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* credits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vspinell <vspinell@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/26 11:23:35 by vspinell #+# #+# */
/* Updated: 2021/10/27 17:47:23 by vspinell ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_names(t_term *term, int fd, int count)
{
char *line;
dup2(fd, 0);
line = readline(GRN"");
while (line && *line)
{
free(line);
usleep(120000);
if (count < 13)
line = readline(GRN"");
else if (count > 12 && count < 69)
line = readline(BBLU"");
else
line = readline("");
count++;
}
free(line);
dup2(term->fd_0, 0);
printf(KNRM);
printf("\n\nTRY TO GUESS WHO MADE ALL OF THIS POSSIBLE\n");
printf("\nType in the name below in lowercase\n");
return (count);
}
int ft_printbus(int fd)
{
char *line;
dup2(fd, 0);
line = readline("");
while (line && *line)
{
free(line);
usleep(120000);
line = readline("");
if (!ft_strncmp(line, "Ottima scelta...", 16)
&& ft_strlen(line) == 16)
{
printf(KNRM);
return (1);
}
}
return (0);
}
void ft_credits(t_term *term)
{
char *line;
int fd;
int tries;
int count;
count = 0;
tries = 4;
fd = open("credits.txt", O_RDONLY);
count = ft_names(term, fd, count);
while (tries--)
{
line = readline("");
if (!ft_strncmp(line, "mbus", 3) && ft_strlen(line) == 4)
{
if (ft_printbus(fd))
return ;
}
else
printf("\n%sWrong answer: %stry again:\n", RED, KNRM);
}
printf(KNRM);
printf("\nWe are sorry but the names that you");
printf(" typed in didn't contributed to this project\n");
}