SRCS := main.c \
parsing.c \
parsing_misc.c \
+ pars_arg.c \
+ inner_pars_arg.c \
mem_management.c \
mutex.c \
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* inner_pars_arg.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/28 11:35:59 by ljiriste #+# #+# */
+/* Updated: 2024/03/28 11:36:24 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "parsing.h"
+#include <stdlib.h>
+
+// Maybe this should be changed so that it only changes
+// res when the parse is successful?
+int inner_parse_arg(t_big_uint *res, const char *arg)
+{
+ char *tmp;
+
+ *res = ft_atobui(arg);
+ tmp = ft_buitoa(*res);
+ if (!same_number(tmp, arg))
+ {
+ free(tmp);
+ return (1);
+ }
+ free(tmp);
+ return (0);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* pars_arg.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/28 11:29:47 by ljiriste #+# #+# */
+/* Updated: 2024/03/28 11:36:24 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "parsing.h"
+#include <stddef.h>
+#include <stdlib.h>
+
+int parse_arg_usec(useconds_t *res, const char *arg)
+{
+ t_big_uint tmp;
+
+ if (inner_parse_arg(&tmp, arg))
+ return (1);
+ if (tmp > (useconds_t)-1)
+ return (1);
+ *res = (useconds_t)tmp;
+ return (0);
+}
+
+#if SIZE_MAX > UINT_MAX
+
+int parse_arg_size(size_t *res, const char *arg)
+{
+ t_big_uint tmp;
+
+ if (inner_parse_arg(&tmp, arg))
+ return (1);
+ if (tmp > (size_t)-1)
+ return (1);
+ *res = (size_t)tmp;
+ return (0);
+}
+
+#else
+
+int parse_arg_size(size_t *res, const char *arg)
+{
+ t_big_uint tmp;
+
+ if (inner_parse_arg(&tmp, arg))
+ return (1);
+ *res = (size_t)tmp;
+ return (0);
+}
+
+#endif //SIZE_MAX > UINT_MAX
+
+#if UINT_MAX > SIZE_MAX
+
+int parse_arg_uint(unsigned int *res, const char *arg)
+{
+ t_big_uint tmp;
+
+ if (inner_parse_arg(&tmp, arg))
+ return (1);
+ if (tmp > (unsigned int)-1)
+ return (1);
+ *res = (unsigned int)tmp;
+ return (0);
+}
+
+#else
+
+int parse_arg_uint(unsigned int *res, const char *arg)
+{
+ t_big_uint tmp;
+
+ if (inner_parse_arg(&tmp, arg))
+ return (1);
+ *res = (unsigned int)tmp;
+ return (0);
+}
+
+#endif //UINT_MAX > SIZE_MAX
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/26 09:31:35 by ljiriste #+# #+# */
-/* Updated: 2024/03/28 09:32:31 by ljiriste ### ########.fr */
+/* Updated: 2024/03/28 11:32:40 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
+#include "parsing.h"
#include "philo.h"
#include <stddef.h>
#include <stdlib.h>
-// Maybe this should be changed so that it only changes
-// res when the parse is successful?
-static int inner_parse_arg(t_big_uint *res, const char *arg)
-{
- char *tmp;
-
- *res = ft_atobui(arg);
- tmp = ft_buitoa(*res);
- if (!same_number(tmp, arg))
- {
- free(tmp);
- return (1);
- }
- free(tmp);
- return (0);
-}
-
-static int parse_arg_size(size_t *res, const char *arg)
-{
- t_big_uint tmp;
-
- if (inner_parse_arg(&tmp, arg))
- return (1);
- if (tmp > (size_t)-1)
- return (1);
- *res = (size_t)tmp;
- return (0);
-}
-
-static int parse_arg_usec(useconds_t *res, const char *arg)
-{
- t_big_uint tmp;
-
- if (inner_parse_arg(&tmp, arg))
- return (1);
- if (tmp > (useconds_t)-1)
- return (1);
- *res = (useconds_t)tmp;
- return (0);
-}
-
-static int parse_arg_uint(unsigned int *res, const char *arg)
-{
- t_big_uint tmp;
-
- if (inner_parse_arg(&tmp, arg))
- return (1);
- if (tmp > (unsigned int)-1)
- return (1);
- *res = (unsigned int)tmp;
- return (0);
-}
-
int parse_input(t_settings *settings, int argc, char **argv)
{
if (argc != 5 && argc != 6)
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* parsing.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/28 11:24:41 by ljiriste #+# #+# */
+/* Updated: 2024/03/28 11:40:04 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PARSING_H
+# define PARSING_H
+
+# include <limits.h>
+# include <stddef.h>
+# include <unistd.h>
+
+// This done to make parsing easier/non-repetitive
+// but it cannot be a part of parsing.c as more files depend on it
+//
+// This assumes useconds_t is not the biggest type
+// The assumption is made because it is not easy to check
+# if SIZE_MAX > UINT_MAX
+
+typedef size_t t_big_uint;
+
+# else
+
+typedef unsigned int t_big_uint;
+
+# endif //SIZE_MAX > UINT_MAX
+
+t_big_uint ft_atobui(const char *str);
+char *ft_buitoa(t_big_uint num);
+int same_number(const char *num1, const char *num2);
+
+int inner_parse_arg(t_big_uint *res, const char *arg);
+
+int parse_arg_usec(useconds_t *res, const char *arg);
+int parse_arg_size(size_t *res, const char *arg);
+int parse_arg_uint(unsigned int *res, const char *arg);
+
+#endif //PARSING_H
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/26 10:42:02 by ljiriste #+# #+# */
-/* Updated: 2024/03/28 09:31:14 by ljiriste ### ########.fr */
+/* Updated: 2024/03/28 11:28:12 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
-#include "philo.h"
+#include "parsing.h"
#include <stdlib.h>
t_big_uint ft_atobui(const char *str)
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 11:10:17 by ljiriste #+# #+# */
-/* Updated: 2024/03/28 10:50:26 by ljiriste ### ########.fr */
+/* Updated: 2024/03/28 11:27:15 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
# include <stddef.h>
# include <pthread.h>
# include <sys/time.h>
-# include <limits.h>
# include <unistd.h>
-// This done to make parsing easier/non-repetitive
-// but it cannot be a part of parsing.c as more files depend on it
-// May it should have its own header file?
-//
-// This assumes useconds_t is not the biggest type
-// The assumption is made because it is not easy to check
-# if SIZE_MAX > UINT_MAX
-
-typedef size_t t_big_uint;
-# else
-
-typedef unsigned int t_big_uint;
-# endif //SIZE_MAX > UINT_MAX
-
typedef struct s_mutex
{
int is_init;
} t_diner;
int parse_input(t_settings *settings, int argc, char **argv);
-t_big_uint ft_atobui(const char *str);
-char *ft_buitoa(t_big_uint num);
-int same_number(const char *num1, const char *num2);
int init(t_diner *diner, pthread_t **threads);
void cleanup(t_diner *diner, pthread_t *threads);