From 6b6376fe70e0a9c5b520260de8e750f3743134c7 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 23 Mar 2017 16:39:51 +0100 Subject: [PATCH 1/3] setlocal not allowed --- 42sh/Makefile | 4 ++-- 42sh/libft/Makefile | 4 ++-- 42sh/src/main/main.c | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 715952e6..bb747d52 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/23 03:25:35 by wescande ### ########.fr # +# Updated: 2017/03/23 16:37:26 by gwojda ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden #-fsanitize=address +FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 4ce95f9b..a7370723 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/21 12:25:27 by gwojda ### ########.fr # +# Updated: 2017/03/23 16:38:05 by gwojda ### ########.fr # # # # **************************************************************************** # @@ -19,7 +19,7 @@ RM = /bin/rm -rf W_FLAGS = -Wall -Wextra -Werror -g D_FLAGS = -g -V_FLAGS = #-fvisibility=hidden +V_FLAGS = -fvisibility=hidden FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS) DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 69fedd03..d6e7106a 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/23 00:28:58 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:39:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,6 @@ int main(int ac, char **av) g_argv = av; DG("----------------"); - setlocale(LC_ALL, ""); if (shell_init(ac, av) != 0) return (1); token = NULL; From d2d63089e21b48a280c186e9cbcf85f9314760a3 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 23 Mar 2017 16:41:53 +0100 Subject: [PATCH 2/3] rectif printf --- 42sh/libft/src/str/ft_strcatf.c | 2 +- 42sh/scriptheader.sh | 51 +++++++++++++++++++++---------- 42sh/src/builtin/builtin_math.c | 6 ++-- 42sh/src/lexer/get_state_global.c | 2 ++ 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/42sh/libft/src/str/ft_strcatf.c b/42sh/libft/src/str/ft_strcatf.c index 0656d6b0..8caa7036 100644 --- a/42sh/libft/src/str/ft_strcatf.c +++ b/42sh/libft/src/str/ft_strcatf.c @@ -14,7 +14,7 @@ char *ft_strcatf(char *s1, const char *s2) { - char buf[ft_strlen(s2)]; + char buf[ft_strlen(s1) + 1]; ft_strcpy(buf, s1); ft_strcpy(s1, s2); diff --git a/42sh/scriptheader.sh b/42sh/scriptheader.sh index 6331ec00..9dd5cec2 100755 --- a/42sh/scriptheader.sh +++ b/42sh/scriptheader.sh @@ -1,10 +1,16 @@ #!/bin/sh -function elem_in_array() +word=$(git status -s | sed 's/.* //') +red="\033[38;5;1m" +gre="\033[38;5;2m" +cya="\033[38;5;6m" +res="\033[0m" + +elem_in_array () { for cur in $2 do - if [ "$1" == "$cur" ] + if [ "$1" = "$cur" ] then echo "1" return 1 @@ -14,7 +20,7 @@ function elem_in_array() return 0 } -function array_in_array() +array_in_array () { for cur in $1 do @@ -29,11 +35,29 @@ function array_in_array() return 1 } -word=$(git status -s | sed 's/.* //') -red="\033[38;5;1m" -gre="\033[38;5;2m" -cya="\033[38;5;6m" -res="\033[0m" +confirm () +{ + # call with a prompt string or use a default + echo "$cya${1:-Are you sure? [y/N]}$res" + read -r -p " " response + case "$response" in + [yY][eE][sS]|[yY]) + true + ;; + *) + false + ;; + esac +} + +do_checkout () +{ + i_tmp=$(echo $i | sed 's/\//_/g') + cp $i "$HOME/Documents/.$i_tmp.back" + git checkout $i + echo "$gre D - O - N - E $res" + echo "$cya $i was checked out. A copy still exist in $HOME/Documents/.$i_tmp.back$res\n" +} for i in $word do @@ -52,15 +76,10 @@ do then echo "\n$cya CHANGES on $i :$res" echo "$diff" - echo "$cya Are you sure?$res" - read -r -p " [y/N]" response - if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]] + confirm + if [ $? -eq 0 ] then - i_tmp=$(echo $i | sed 's/\//_/g') - cp $i "$HOME/Documents/.$i_tmp.back" - git checkout $i - echo "$gre D - O - N - E $res" - echo "$cya $i was checked out. A copy still exist in $HOME/Documents/.$i_tmp.back$res\n" + do_checkout else echo "$cya Nothing done for $i$res\n" fi diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index d2916c52..80beea28 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -25,8 +25,8 @@ static char *do_math(char *value, char operator, char *operand) ope1 = ft_atoi(value); ope2 = ft_atoi(operand); - DG("value %s -> %i", value, ope1); - DG("operand %s -> %i", operand, ope2); + DG("value %s -> %li", value, ope1); + DG("operand %s -> %li", operand, ope2); if ((operator == '/') && ope2 == 0) return (SH_ERR(MATHERR_4) ? NULL : NULL); if ((operator == '%') && ope2 == 0) @@ -36,7 +36,7 @@ static char *do_math(char *value, char operator, char *operand) ope1 = (operator == '/') ? ope1 / ope2 : ope1; ope1 = (operator == '*') ? ope1 * ope2 : ope1; ope1 = (operator == '%') ? ope1 % ope2 : ope1; - DG("output=%s (%i)", ft_itoa(ope1), ope1); + DG("output=%s (%li)", ft_itoa(ope1), ope1); return (ft_itoa(ope1)); } diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 96b29593..0fa045fc 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -34,6 +34,8 @@ t_lexstate get_state_global(t_lexer *lexer) || (((c == '{' && cn == ' ') || (c == '}' && cl == ' ')) && (ret = CURLY_BRACKETS)) || ((c == 0) && (ret = END))) + { ; + } return (ret); } From 9cd96b13f0b99bb1b401bcf4bbf347b581a81381 Mon Sep 17 00:00:00 2001 From: gwojda Date: Thu, 23 Mar 2017 16:52:45 +0100 Subject: [PATCH 3/3] fix retour copy/cut --- 42sh/Makefile | 4 ++-- 42sh/libft/Makefile | 2 +- 42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 919a1bd9..fc426b65 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/23 16:37:26 by gwojda ### ########.fr # +# Updated: 2017/03/23 16:49:08 by gwojda ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address +FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden -fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index a7370723..c0902fc6 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/23 16:38:05 by gwojda ### ########.fr # +# Updated: 2017/03/23 16:49:31 by gwojda ### ########.fr # # # # **************************************************************************** # diff --git a/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c index 508d73f5..1d4cbf84 100644 --- a/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c +++ b/42sh/src/line_editing/copy_cut_paste/copy_cut_paste.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/23 16:28:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 16:52:38 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ int ft_x(char **str, size_t *pos) while (g_cpy[i].value && g_cpy[i].value != ret) ++i; if (g_cpy[i].value && (ret = g_cpy[i].f(str, pos, pos_ref))) - return (ret); + return (0); else break ; } @@ -72,7 +72,7 @@ int ft_c(char **str, size_t *pos) while (g_cpy[i].value && g_cpy[i].value != ret) ++i; if (g_cpy[i].value && (ret = g_cpy[i].f(str, pos, pos_ref))) - return (ret); + return (0); else if (!g_cpy[i].value) break ; }