diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-08 14:35:53 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-08 14:35:53 +0100 |
| commit | ad7ed73c124c8fcda6629350307f0f4f41b87fe3 (patch) | |
| tree | 5faf9809401b64fecffe709f20cc9bb980aa7406 /common/src/args.c | |
| parent | 907debbb7d1e7ccc4914805cfe4acbed92b82bcc (diff) | |
| download | philosophers-ad7ed73c124c8fcda6629350307f0f4f41b87fe3.tar.gz philosophers-ad7ed73c124c8fcda6629350307f0f4f41b87fe3.tar.bz2 philosophers-ad7ed73c124c8fcda6629350307f0f4f41b87fe3.zip | |
Updated Makefile, restructuring common files
Diffstat (limited to 'common/src/args.c')
| -rw-r--r-- | common/src/args.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/common/src/args.c b/common/src/args.c new file mode 100644 index 0000000..2070e46 --- /dev/null +++ b/common/src/args.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* args.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 23:12:55 by cacharle #+# #+# */ +/* Updated: 2020/12/30 13:44:54 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "common.h" + +bool parse_args(t_philo_args *args, int argc, char **argv) +{ + if (argc != 5 && argc != 6) + { + return (h_err(false, "Usage: %s philosophers_num death_timeout" + "eat_timeout sleep_timeout [meal_num]", argv[0])); + } + if ((args->philo_num = h_atou_strict(argv[1])) == -1 + || (args->timeout_death = h_atou_strict(argv[2])) == -1 + || (args->timeout_eat = h_atou_strict(argv[3])) == -1 + || (args->timeout_sleep = h_atou_strict(argv[4])) == -1) + return (false); + if (argc == 6) + { + if ((args->meal_num = h_atou_strict(argv[5])) == -1) + return (false); + } + else + args->meal_num = -1; + return (true); +} |
