diff options
author | joe <rbousset@42lyon.fr> | 2020-11-30 15:09:26 +0100 |
---|---|---|
committer | joe <rbousset@42lyon.fr> | 2020-11-30 15:09:26 +0100 |
commit | 46e785f7a047e3cf51a43b54223110c654503880 (patch) | |
tree | 91539bef97ec7f6a2a884cfd29a4ccd7e88673a6 | |
parent | Fixed alias but norme (diff) | |
download | 42-minishell-46e785f7a047e3cf51a43b54223110c654503880.tar.gz 42-minishell-46e785f7a047e3cf51a43b54223110c654503880.tar.bz2 42-minishell-46e785f7a047e3cf51a43b54223110c654503880.tar.xz 42-minishell-46e785f7a047e3cf51a43b54223110c654503880.tar.zst 42-minishell-46e785f7a047e3cf51a43b54223110c654503880.zip |
get normed
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/b_alias.c | 38 | ||||
-rw-r--r-- | src/b_alias_register.c | 67 | ||||
-rw-r--r-- | src/b_alias_register.h | 20 |
4 files changed, 89 insertions, 37 deletions
@@ -17,6 +17,7 @@ LFT_SRCS_DIR = ${LFT_DIR}src/ #==============================================================================# SRCS_NAME = b_alias SRCS_NAME += b_alias_print +SRCS_NAME += b_alias_register SRCS_NAME += b_cd SRCS_NAME += b_echo SRCS_NAME += b_env diff --git a/src/b_alias.c b/src/b_alias.c index fc1651b..c94a6db 100644 --- a/src/b_alias.c +++ b/src/b_alias.c @@ -20,6 +20,7 @@ #endif #include "b_alias_print.h" +#include "b_alias_register.h" #include "d_define.h" #include "s_struct.h" #include "u_alias.h" @@ -72,43 +73,6 @@ static unsigned char b_print_arg(const char arg[], t_msh *msh) return (b_print_arg_next(ptr, arg, invalid, msh)); } -#include <stdlib.h> -static void b_register_arg(const char arg[], t_msh *msh) -{ - char *ptr; - char *rptr; - char name[255]; - char value[ARG_MAX]; - char tmp; - - ptr = (char*)arg; - while (*ptr != C_NUL && *ptr != C_EQUALS) - { - ptr++; - } - if (*ptr == C_EQUALS) - { - ft_strlcpy(name, arg, (ptr - arg < 255) ? ((ptr - arg) + 1) : (255)); - ptr += 1; - rptr = ptr; - while (*rptr != C_NUL && ft_iswhitespace(*rptr) == TRUE) - rptr++; - tmp = *(rptr + ft_strlen(name)); - *(rptr + ft_strlen(name)) = C_NUL; - if (ft_strncmp(rptr, name, ft_strlen(name) + 1) == 0) { - *(rptr + ft_strlen(name)) = tmp; - ft_strlcpy(value, ptr, ARG_MAX); - ft_memmove(value + (rptr - ptr) + 1, value + (rptr - ptr), ft_strlen(value + (rptr - ptr)) + 1); - *(value + (rptr - ptr)) = C_BACKS; - } - else { - *(rptr + ft_strlen(name)) = tmp; - ft_strlcpy(value, ptr, ARG_MAX); - } - u_set_alias_value(name, value, msh); - } -} - unsigned char b_alias(char *args[], t_msh *msh) { const unsigned long argc = u_builtins_get_argc((const char**)args); diff --git a/src/b_alias_register.c b/src/b_alias_register.c new file mode 100644 index 0000000..8f75e36 --- /dev/null +++ b/src/b_alias_register.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* b_alias_register.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#ifdef __linux__ +# include <linux/limits.h> +#else +# include <limits.h> +#endif + +#include "d_define.h" +#include "s_struct.h" +#include "u_alias.h" + +static void b_cpy_alias(char name[], char *ptr, char value[]) +{ + char *rptr; + char tmp; + + rptr = ptr; + while (*rptr != C_NUL && ft_iswhitespace(*rptr) == TRUE) + rptr++; + tmp = *(rptr + ft_strlen(name)); + *(rptr + ft_strlen(name)) = C_NUL; + if (ft_strncmp(rptr, name, ft_strlen(name) + 1) == 0) { + *(rptr + ft_strlen(name)) = tmp; + ft_strlcpy(value, ptr, ARG_MAX); + ft_memmove(value + (rptr - ptr) + 1, value + (rptr - ptr), + ft_strlen(value + (rptr - ptr)) + 1); + *(value + (rptr - ptr)) = C_BACKS; + } + else { + *(rptr + ft_strlen(name)) = tmp; + ft_strlcpy(value, ptr, ARG_MAX); + } +} + +void b_register_arg(const char arg[], t_msh *msh) +{ + char name[255]; + char *ptr; + char value[ARG_MAX]; + + ptr = (char*)arg; + while (*ptr != C_NUL && *ptr != C_EQUALS) + { + ptr++; + } + if (*ptr == C_EQUALS) + { + ft_strlcpy(name, arg, (ptr - arg < 255) ? ((ptr - arg) + 1) : (255)); + ptr += 1; + b_cpy_alias(name, ptr, value); + u_set_alias_value(name, value, msh); + } +} + + diff --git a/src/b_alias_register.h b/src/b_alias_register.h new file mode 100644 index 0000000..d64f999 --- /dev/null +++ b/src/b_alias_register.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* b_alias_register.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef B_ALIAS_REGISTER_H +# define B_ALIAS_REGISTER_H + +# include "s_struct.h" + +void b_register_arg(const char arg[], t_msh *msh); + +#endif |