From 138ffb7a54e8a1025eb78f4c1f18a137a12b85a9 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 10 Nov 2016 17:07:05 +0100 Subject: [PATCH] env subdir for getenv --- libft/includes/libft.h | 12 ++++++++- libft/src/env/ft_getenv.c | 27 +++++++++++++++++++++ libft/src/ft_printf/ft_conversion.c | 2 +- libft/src/ft_printf/ft_fmt_validate_flags.c | 7 +++--- libft/src/ft_printf/ft_printf.c | 2 +- libft/src/ft_printf/ft_printf_parse.c | 2 +- libft/src/str/ft_strcat.c | 4 +-- libft/src/str/ft_strjoin.c | 2 +- libft/src/str/ft_strlen.c | 2 +- 9 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 libft/src/env/ft_getenv.c diff --git a/libft/includes/libft.h b/libft/includes/libft.h index b51bd194..37fc15c2 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/10 12:14:04 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 14:40:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,14 @@ # define FT_MAX(a, b) ((a) > (b) ? (a) : (b)) # define FT_DIST(a, b) (FT_ABS((a) - (b))) +typedef struct s_stof t_stof; + +struct s_stof +{ + char *name; + int (*f)(); +}; + void ft_debug(void); void *ft_memset(void *b, int c, size_t len); @@ -118,4 +126,6 @@ int ft_time_isrecent(time_t event); char *ft_path_notdir(char *path); int ft_printf(const char *format, ...); + +char *ft_getenv(char **env, char *key); #endif diff --git a/libft/src/env/ft_getenv.c b/libft/src/env/ft_getenv.c new file mode 100644 index 00000000..3c733605 --- /dev/null +++ b/libft/src/env/ft_getenv.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_getenv.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 14:30:00 by jhalford #+# #+# */ +/* Updated: 2016/11/10 14:30:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_getenv(char **env, char *key) +{ + if (!env) + return (NULL); + while (*env) + { + /* ft_printf("%s\n", env[i]); */ + if (ft_strcmp(*env, key) == '=') + return (*env + ft_strlen(key) + 1); + env++; + } + return (NULL); +} diff --git a/libft/src/ft_printf/ft_conversion.c b/libft/src/ft_printf/ft_conversion.c index 3dbd8429..e1908f19 100644 --- a/libft/src/ft_printf/ft_conversion.c +++ b/libft/src/ft_printf/ft_conversion.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:56:28 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:59:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/ft_printf/ft_fmt_validate_flags.c b/libft/src/ft_printf/ft_fmt_validate_flags.c index 82962cf4..cba3f389 100644 --- a/libft/src/ft_printf/ft_fmt_validate_flags.c +++ b/libft/src/ft_printf/ft_fmt_validate_flags.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */ -/* Updated: 2016/11/07 17:25:47 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 13:02:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,12 +38,15 @@ static void ft_fmt_validate_flag_conv(t_fmt *fmt) i = 0; flag_ptr = fmt->flags; + while (fmt->conversion != g_convs[i].id) + i++; while (*flag_ptr) { flag = *flag_ptr; if (!ft_strchr(g_convs[i].allowed_flags, flag)) { ft_fmt_error_flag_conv(flag, fmt->conversion); + /* ft_printf("allowed flags:%s\n", g_convs[i].allowed_flags); */ if (flag == '#') *flag_ptr = '.'; } @@ -56,8 +59,6 @@ void ft_fmt_validate_flags(t_fmt *fmt) int i; i = 0; - while (fmt->conversion != g_convs[i].id) - i++; ft_fmt_validate_flag_conv(fmt); ft_fmt_validate_flag_flag(fmt); } diff --git a/libft/src/ft_printf/ft_printf.c b/libft/src/ft_printf/ft_printf.c index 3f37644a..5c79a190 100644 --- a/libft/src/ft_printf/ft_printf.c +++ b/libft/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:20:10 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:59:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/ft_printf/ft_printf_parse.c b/libft/src/ft_printf/ft_printf_parse.c index 86a6cf74..fe3d2674 100644 --- a/libft/src/ft_printf/ft_printf_parse.c +++ b/libft/src/ft_printf/ft_printf_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:56:47 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:59:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/str/ft_strcat.c b/libft/src/str/ft_strcat.c index b2947ea8..f376d850 100644 --- a/libft/src/str/ft_strcat.c +++ b/libft/src/str/ft_strcat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */ -/* Updated: 2016/08/20 23:16:44 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:18:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ char *ft_strcat(char *s1, const char *s2) size = ft_strlen(s1); j = 0; - while (s2[j] != '\0') + while (s2 && s2[j]) { s1[size + j] = s2[j]; j++; diff --git a/libft/src/str/ft_strjoin.c b/libft/src/str/ft_strjoin.c index 58a57d14..943ded51 100644 --- a/libft/src/str/ft_strjoin.c +++ b/libft/src/str/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:18 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 10:14:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/str/ft_strlen.c b/libft/src/str/ft_strlen.c index 4075825e..536f2bcf 100644 --- a/libft/src/str/ft_strlen.c +++ b/libft/src/str/ft_strlen.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:23 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 10:14:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */