#include "philo.h"

int main(int argc, char *argv[])
{
    t_rules rules;

	if (FAILURE == parse_arguments(argc, argv, &rules))
        return (printf(ERROR_USAGE), EXIT_FAILURE);
	printf("arguments parsed\n");
	if (FAILURE == create_philos(&rules))
		return (printf(ERROR_MALLOC), EXIT_FAILURE);
	printf("philos created\n");
	if (FAILURE == create_mutexes(&rules))
		return (printf(ERROR_MUTEX), EXIT_FAILURE);
	printf("mutexes created\n");
	rules.start_time = get_time();
	if (FAILURE == create_threads(&rules))
		return (printf(ERROR_THREADS), EXIT_FAILURE);	
	printf("threads created\n");
	if (FAILURE == join_threads(&rules))
		return (printf(ERROR_THREADS), EXIT_FAILURE);

	if (FAILURE == destroy_mutexes(&rules))
		return (printf(ERROR_MUTEX), EXIT_FAILURE);
	printf("mutexes destroyed\n");
	free_philos(&rules);
    return(EXIT_SUCCESS);
}
