-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
60 lines (53 loc) · 1.61 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yel-hadd <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/21 18:24:45 by yel-hadd #+# #+# */
/* Updated: 2023/06/25 19:06:50 by yel-hadd ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
t_philo *make_circular(t_philo *ptr)
{
t_philo *copy;
t_philo *head;
copy = ptr;
head = ptr;
while (copy->next != NULL)
copy = copy->next;
copy->next = head;
return (head);
}
int check_args(char **args, int count)
{
int i;
i = 0;
while (i < count)
{
if (!is_all_digits(args[i]))
return (0);
i++;
}
return (1);
}
int main(int ac, char **av)
{
t_num *n;
if (ac < 5 || !check_args(av + 1, ac - 1))
return (write(2, "ERROR\n", 6), 1);
if (ac == 6 && ft_atoi(av[5]) == 0)
return (0);
n = NULL;
n = parse_params(av, ac);
if (!check_params(n))
return (1);
parse_forks(&n->f, n->n_phil);
parse_philos(n, &n->f, n->n_phil);
n->start_ts = get_ms_ts(0);
start_threads(n);
free_all(n);
return (0);
}