-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathduck.c
70 lines (63 loc) · 1.78 KB
/
duck.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* duck.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/07 10:57:41 by ggiannit #+# #+# */
/* Updated: 2023/04/17 11:12:45 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_magic_duck(int keepit)
{
static int duck = 0;
if (duck)
{
duck = 0;
return (0);
}
if (keepit)
duck = keepit;
return (1);
}
void ft_sign_handler_duck(int sig)
{
if (sig == SIGINT)
ft_magic_duck(1);
}
void ft_ducktime(t_mish *meta)
{
int i;
int fd;
char **fnames;
i = 0;
fnames = ft_calloc(57, sizeof(char *));
fd = open("dduck/dduck.lst", O_RDONLY);
fnames[i] = get_next_line(fd);
while (fnames[i++])
fnames[i] = get_next_line(fd);
i = -1;
while (fnames[++i])
fnames[i][ft_strlen(fnames[i]) - 1] = '\0';
i = 0;
while (ft_magic_duck(0))
{
ft_print_file(meta, fnames[i++]);
usleep(110000);
if (i == 55)
i = 0;
}
ft_free_matrix(&fnames);
}
int ft_duck(t_mish *meta)
{
signal(SIGINT, ft_sign_handler_duck);
chdir(meta->duckpath);
write(1, "\033[0;97m", 7);
ft_ducktime(meta);
chdir(meta->curdir);
signal(SIGINT, ft_sign_handler_exec);
return (130);
}