diff --git a/42sh/Makefile b/42sh/Makefile index 2b16e5a0..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 03:25:35 by wescande ### ########.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 4ce95f9b..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/21 12:25:27 by gwojda ### ########.fr # +# Updated: 2017/03/23 16:49:31 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/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/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); } 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 ; } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 2fe96836..2b2f966c 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 16:42:30 by ariard ### ########.fr */ +/* Updated: 2017/03/23 16:58:43 by ariard ### ########.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;