parser complete
This commit is contained in:
parent
98e51402ec
commit
cb914510d5
@ -1,6 +1,6 @@
|
|||||||
.PHONY: all clean fclean re
|
.PHONY: all clean fclean re
|
||||||
|
|
||||||
SRCS = main.c utilc.c
|
SRCS = main.c utilc.c parser.c
|
||||||
|
|
||||||
|
|
||||||
SRC_DIR = ./srcs/
|
SRC_DIR = ./srcs/
|
||||||
|
|||||||
BIN
philo_one/obj/main.o
Normal file
BIN
philo_one/obj/main.o
Normal file
Binary file not shown.
BIN
philo_one/obj/parser.o
Normal file
BIN
philo_one/obj/parser.o
Normal file
Binary file not shown.
BIN
philo_one/obj/utilc.o
Normal file
BIN
philo_one/obj/utilc.o
Normal file
Binary file not shown.
BIN
philo_one/philo_one
Executable file
BIN
philo_one/philo_one
Executable file
Binary file not shown.
@ -1,81 +1,14 @@
|
|||||||
#include "../includes/philo_header.h"
|
#include "../includes/philo_header.h"
|
||||||
|
|
||||||
int check_param(t_all *all, int optional)
|
|
||||||
{
|
|
||||||
if (optional)
|
|
||||||
{
|
|
||||||
if (all->number_of_philosophers <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->time_to_die <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->time_to_eat <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->time_to_sleep <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->number_of_times_each_philosopher_must_eat <= 0)
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (all->number_of_philosophers <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->time_to_die <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->time_to_eat <= 0)
|
|
||||||
return(1);
|
|
||||||
if (all->time_to_sleep <= 0)
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int parse_param(t_all *all, int optional, char **argv)
|
|
||||||
{
|
|
||||||
if (optional)
|
|
||||||
{
|
|
||||||
all->number_of_philosophers = ft_atoi(argv[1]);
|
|
||||||
all->time_to_die = ft_atoi(argv[2]);
|
|
||||||
all->time_to_eat = ft_atoi(argv[3]);
|
|
||||||
all->time_to_sleep = ft_atoi(argv[4]);
|
|
||||||
all->number_of_times_each_philosopher_must_eat = ft_atoi(argv[5]);
|
|
||||||
return (check_param(all, 1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
all->number_of_philosophers = ft_atoi(argv[1]);
|
|
||||||
all->time_to_die = ft_atoi(argv[2]);
|
|
||||||
all->time_to_eat = ft_atoi(argv[3]);
|
|
||||||
all->time_to_sleep = ft_atoi(argv[4]);
|
|
||||||
return (check_param(all, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int parse_and_check_values(char **argv, int quantity)
|
|
||||||
{
|
|
||||||
t_all *all;
|
|
||||||
|
|
||||||
all = structalloc_and_bzero();
|
|
||||||
if (quantity == 5)
|
|
||||||
{
|
|
||||||
printf("ok standart run\n");
|
|
||||||
parse_param(all, 0, argv);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
else if (quantity == 6)
|
|
||||||
{
|
|
||||||
printf("ok run with optional\n");
|
|
||||||
parse_param(all, 1, argv);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("error please use argument 5 (optional) or 4 (standart) \n");
|
|
||||||
free(all);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
parse_and_check_values(argv, argc);
|
if (parse_and_check_values(argv, argc))
|
||||||
|
;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("exit because error\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|||||||
90
philo_one/srcs/parser.c
Normal file
90
philo_one/srcs/parser.c
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include "../includes/philo_header.h"
|
||||||
|
|
||||||
|
int check_param(t_all *all, int optional)
|
||||||
|
{
|
||||||
|
if (optional)
|
||||||
|
{
|
||||||
|
if (all->number_of_philosophers <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->time_to_die <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->time_to_eat <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->time_to_sleep <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->number_of_times_each_philosopher_must_eat <= 0)
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (all->number_of_philosophers <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->time_to_die <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->time_to_eat <= 0)
|
||||||
|
return(1);
|
||||||
|
if (all->time_to_sleep <= 0)
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int parse_param(t_all *all, int optional, char **argv)
|
||||||
|
{
|
||||||
|
if (optional)
|
||||||
|
{
|
||||||
|
all->number_of_philosophers = ft_atoi(argv[1]);
|
||||||
|
all->time_to_die = ft_atoi(argv[2]);
|
||||||
|
all->time_to_eat = ft_atoi(argv[3]);
|
||||||
|
all->time_to_sleep = ft_atoi(argv[4]);
|
||||||
|
all->number_of_times_each_philosopher_must_eat = ft_atoi(argv[5]);
|
||||||
|
return (check_param(all, 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
all->number_of_philosophers = ft_atoi(argv[1]);
|
||||||
|
all->time_to_die = ft_atoi(argv[2]);
|
||||||
|
all->time_to_eat = ft_atoi(argv[3]);
|
||||||
|
all->time_to_sleep = ft_atoi(argv[4]);
|
||||||
|
return (check_param(all, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int parse_and_check_values(char **argv, int quantity)
|
||||||
|
{
|
||||||
|
t_all *all;
|
||||||
|
|
||||||
|
all = structalloc_and_bzero();
|
||||||
|
if (quantity == 5)
|
||||||
|
{
|
||||||
|
if (!parse_param(all, 0, argv))
|
||||||
|
{
|
||||||
|
printf("ok standart run\n");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("bad arg\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (quantity == 6)
|
||||||
|
{
|
||||||
|
if (!parse_param(all, 1, argv))
|
||||||
|
{
|
||||||
|
printf("ok run with optional\n");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("bad arg\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("error please use argument 5 (optional) or 4 (standart) \n");
|
||||||
|
free(all);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user