blob: face0b576313bbe3f2a729ea0666bf1faf40581b (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* common.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/08 23:12:55 by cacharle #+# #+# */
/* Updated: 2020/02/15 00:54:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "common.h"
t_bool parse_args(t_philo_args *philo_args, int argc, char **argv)
{
if (argc != 5 && argc != 6)
return (FALSE);
if ((philo_args->philo_num = h_strtoposint(argv[1])) == -1 ||
(philo_args->timeout_death = h_strtoposint(argv[2])) == -1 ||
(philo_args->timeout_eat = h_strtoposint(argv[3])) == -1 ||
(philo_args->timeout_sleep = h_strtoposint(argv[4])) == -1)
return (FALSE);
if (argc == 6)
{
if ((philo_args->meal_num = h_strtoposint(argv[5])) == -1)
return (FALSE);
}
else
philo_args->meal_num = -1;
return (TRUE);
}
void philo_put_state_change(int id, t_philo_event event) // not correct for philo3
{
h_putnbr(h_time_now());
h_putchar(' ');
h_putnbr(id);
if (event == EVENT_FORK)
h_putstr(" has taken fork\n");
else if (event == EVENT_EATING)
h_putstr(" is eating\n");
else if (event == EVENT_SLEEPING)
h_putstr(" is sleeping\n");
else if (event == EVENT_THINKING)
h_putstr(" is thinking\n");
else if (event == EVENT_DIED)
h_putstr(" died\n");
}
|