From fcea6dda9b6b9cbf8f380aa97b8213aad84c2d42 Mon Sep 17 00:00:00 2001 From: "ariard@student.42.fr" Date: Fri, 3 Feb 2017 15:41:14 +0100 Subject: [PATCH] scripting stable before new lexing and parsing(merged with master) --- 42sh/Makefile | 53 ++++--- 42sh/ffile2 | 0 42sh/file2 | 1 + 42sh/includes/exec.h | 4 +- 42sh/includes/ft_input.h | 2 +- 42sh/includes/ft_readline.h | 4 +- 42sh/includes/lexer.h | 4 +- 42sh/src/builtin/is_builtin.c | 3 +- 42sh/src/exec/exec_default.c | 2 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/lexer/command_getoutput.c | 6 +- 42sh/src/lexer/ft_lexer.c | 6 +- 42sh/src/lexer/ft_post_tokenize.c | 11 +- 42sh/src/lexer/ft_tokenize.c | 6 +- 42sh/src/lexer/get_reserved_words.c | 8 +- 42sh/src/lexer/lexer_backslash.c | 6 +- 42sh/src/lexer/lexer_default.c | 10 +- 42sh/src/lexer/lexer_delim.c | 6 +- 42sh/src/lexer/lexer_dquote.c | 6 +- 42sh/src/lexer/lexer_great.c | 6 +- 42sh/src/lexer/lexer_greatand.c | 6 +- 42sh/src/lexer/lexer_if.c | 4 +- 42sh/src/lexer/lexer_less.c | 6 +- 42sh/src/lexer/lexer_list.c | 6 +- 42sh/src/lexer/lexer_number.c | 6 +- 42sh/src/lexer/lexer_while.c | 4 +- 42sh/src/lexer/lexer_word.c | 2 +- 42sh/src/lexer/token_append.c | 2 +- 42sh/src/line-editing/builtin_history.c | 38 ----- 42sh/src/line-editing/check_backslash.c | 35 ----- 42sh/src/line-editing/control_c_and_d.c | 49 ------- 42sh/src/line-editing/copy_cut_paste.c | 106 -------------- 42sh/src/line-editing/curs_ask.c | 57 -------- 42sh/src/line-editing/curs_move.c | 45 ------ 42sh/src/line-editing/curs_setup.c | 82 ----------- 42sh/src/line-editing/curs_term_setup.c | 62 --------- 42sh/src/line-editing/curs_write.c | 63 --------- 42sh/src/line-editing/ft_readline.c | 106 -------------- 42sh/src/line-editing/ft_split_whitespaces.c | 79 ----------- 42sh/src/line-editing/get_touch.c | 69 ---------- 42sh/src/line-editing/get_touch_toolz.c | 113 --------------- 42sh/src/line-editing/get_touch_toolz_2.c | 130 ------------------ 42sh/src/line-editing/heredoc.c | 77 ----------- 42sh/src/line-editing/history.c | 87 ------------ 42sh/src/line-editing/history_parsing.c | 90 ------------ 42sh/src/line-editing/history_parsing_toolz.c | 94 ------------- .../line-editing/history_parsing_toolz_2.c | 64 --------- 42sh/src/line-editing/list_toolz.c | 51 ------- 42sh/src/line-editing/move_to_line.c | 106 -------------- 42sh/src/line-editing/print_and_del.c | 112 --------------- 42sh/src/line-editing/prompt.c | 65 --------- 42sh/src/line-editing/quotes_gest.c | 88 ------------ 42sh/src/line-editing/reader.c | 66 --------- 42sh/src/line-editing/readline.c | 99 ------------- 42sh/src/line-editing/surch_in_history.c | 87 ------------ 42sh/src/line-editing/tool_line.c | 61 -------- 42sh/src/line-editing/tool_line_2.c | 94 ------------- 42sh/src/line-editing/toolz.c | 66 --------- 42sh/src/line-editing/toolz2.c | 67 --------- 42sh/src/line-editing/toolz_parseur.c | 51 ------- 42sh/src/line-editing/toolz_termcaps.c | 45 ------ 42sh/src/main/main.c | 8 +- 42sh/src/main/shell_get_ast.c | 4 +- 42sh/src/main/shell_script.c | 8 +- 42sh/src/parser/parse_word.c | 5 +- 65 files changed, 77 insertions(+), 2634 deletions(-) create mode 100644 42sh/ffile2 create mode 100644 42sh/file2 delete mode 100644 42sh/src/line-editing/builtin_history.c delete mode 100644 42sh/src/line-editing/check_backslash.c delete mode 100644 42sh/src/line-editing/control_c_and_d.c delete mode 100644 42sh/src/line-editing/copy_cut_paste.c delete mode 100644 42sh/src/line-editing/curs_ask.c delete mode 100644 42sh/src/line-editing/curs_move.c delete mode 100644 42sh/src/line-editing/curs_setup.c delete mode 100644 42sh/src/line-editing/curs_term_setup.c delete mode 100644 42sh/src/line-editing/curs_write.c delete mode 100644 42sh/src/line-editing/ft_readline.c delete mode 100644 42sh/src/line-editing/ft_split_whitespaces.c delete mode 100644 42sh/src/line-editing/get_touch.c delete mode 100644 42sh/src/line-editing/get_touch_toolz.c delete mode 100644 42sh/src/line-editing/get_touch_toolz_2.c delete mode 100644 42sh/src/line-editing/heredoc.c delete mode 100644 42sh/src/line-editing/history.c delete mode 100644 42sh/src/line-editing/history_parsing.c delete mode 100644 42sh/src/line-editing/history_parsing_toolz.c delete mode 100644 42sh/src/line-editing/history_parsing_toolz_2.c delete mode 100644 42sh/src/line-editing/list_toolz.c delete mode 100644 42sh/src/line-editing/move_to_line.c delete mode 100644 42sh/src/line-editing/print_and_del.c delete mode 100644 42sh/src/line-editing/prompt.c delete mode 100644 42sh/src/line-editing/quotes_gest.c delete mode 100644 42sh/src/line-editing/reader.c delete mode 100644 42sh/src/line-editing/readline.c delete mode 100644 42sh/src/line-editing/surch_in_history.c delete mode 100644 42sh/src/line-editing/tool_line.c delete mode 100644 42sh/src/line-editing/tool_line_2.c delete mode 100644 42sh/src/line-editing/toolz.c delete mode 100644 42sh/src/line-editing/toolz2.c delete mode 100644 42sh/src/line-editing/toolz_parseur.c delete mode 100644 42sh/src/line-editing/toolz_termcaps.c diff --git a/42sh/Makefile b/42sh/Makefile index e240d66b..344b95ff 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -14,7 +14,7 @@ NAME = 42sh CC = gcc FLAGS = -Wall -Wextra -Werror -D_FLAGS = -g +D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) @@ -44,15 +44,20 @@ exec/ast_free.c\ exec/exec_ampersand.c\ exec/exec_and_if.c\ exec/exec_command.c\ +exec/exec_default.c\ exec/exec_dgreat.c\ exec/exec_great.c\ exec/exec_less.c\ +exec/exec_list.c\ exec/exec_or_if.c\ exec/exec_pipe.c\ exec/exec_semi.c\ +exec/exec_while.c\ exec/ft_exec.c\ exec/ft_findexec.c\ exec/launch_process.c\ +exec/loop_del.c\ +exec/loop_exec.c\ exec/process_redirect.c\ exec/process_reset.c\ exec/process_setexec.c\ @@ -120,19 +125,29 @@ lexer/ft_lexer.c\ lexer/ft_post_tokenize.c\ lexer/ft_tokenize.c\ lexer/get_lexer_state.c\ +lexer/get_reserved_words.c\ lexer/lexer_backslash.c\ +lexer/lexer_comment.c\ lexer/lexer_default.c\ lexer/lexer_delim.c\ +lexer/lexer_do.c\ +lexer/lexer_done.c\ lexer/lexer_dquote.c\ +lexer/lexer_fi.c\ lexer/lexer_great.c\ lexer/lexer_greatand.c\ +lexer/lexer_if.c\ lexer/lexer_less.c\ lexer/lexer_lessand.c\ +lexer/lexer_list.c\ +lexer/lexer_newline.c\ lexer/lexer_number.c\ lexer/lexer_quote.c\ lexer/lexer_sep.c\ lexer/lexer_special.c\ +lexer/lexer_then.c\ lexer/lexer_var.c\ +lexer/lexer_while.c\ lexer/lexer_word.c\ lexer/reduce_bquotes.c\ lexer/reduce_parens.c\ @@ -142,55 +157,37 @@ lexer/token_expand_var.c\ lexer/token_free.c\ lexer/token_init.c\ lexer/token_print.c\ -line-editing/builtin_history.c\ -line-editing/check_backslash.c\ -line-editing/control_c_and_d.c\ -line-editing/copy_cut_paste.c\ -line-editing/ft_split_whitespaces.c\ -line-editing/get_touch.c\ -line-editing/get_touch_toolz.c\ -line-editing/get_touch_toolz_2.c\ -line-editing/heredoc.c\ -line-editing/history.c\ -line-editing/history_parsing.c\ -line-editing/history_parsing_toolz.c\ -line-editing/history_parsing_toolz_2.c\ -line-editing/list_toolz.c\ -line-editing/move_to_line.c\ -line-editing/print_and_del.c\ -line-editing/prompt.c\ -line-editing/quotes_gest.c\ -line-editing/reader.c\ -line-editing/readline.c\ -line-editing/surch_in_history.c\ -line-editing/tool_line.c\ -line-editing/tool_line_2.c\ -line-editing/toolz.c\ -line-editing/toolz2.c\ -line-editing/toolz_parseur.c\ -line-editing/toolz_termcaps.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ main/ft_cleanup.c\ +main/ft_print_all_ast.c\ main/ft_putast.c\ main/ft_putast2.c\ main/lib_expansion.c\ main/main.c\ +main/read_script.c\ main/shell_exit.c\ +main/shell_get_ast.c\ main/shell_get_avdata.c\ main/shell_get_opts.c\ main/shell_init.c\ +main/shell_script.c\ main/sig_handler.c\ parser/ft_parse.c\ parser/parse_dgreat.c\ parser/parse_dless.c\ +parser/parse_do.c\ +parser/parse_done.c\ parser/parse_great.c\ parser/parse_greatand.c\ parser/parse_less.c\ parser/parse_lessand.c\ +parser/parse_list.c\ +parser/parse_newline.c\ parser/parse_separator.c\ parser/parse_subshell.c\ +parser/parse_while.c\ parser/parse_word.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) diff --git a/42sh/ffile2 b/42sh/ffile2 new file mode 100644 index 00000000..e69de29b diff --git a/42sh/file2 b/42sh/file2 new file mode 100644 index 00000000..32524ff3 --- /dev/null +++ b/42sh/file2 @@ -0,0 +1 @@ +/Users/ariard/Projects/42sh-2 diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 9e753070..f15c74f8 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/01/31 23:20:42 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:09:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,6 +90,8 @@ int exec_command(t_btree **ast); int exec_while(t_btree **ast); int exec_list(t_btree **ast); +int exec_default(t_btree **ast); + int launch_process(t_process *p); int process_setexec(t_type type, t_process *p); diff --git a/42sh/includes/ft_input.h b/42sh/includes/ft_input.h index b7820668..a7e44e03 100644 --- a/42sh/includes/ft_input.h +++ b/42sh/includes/ft_input.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */ -/* Updated: 2017/01/23 21:45:15 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:18:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 323f7eb0..1c7cd31b 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/02/03 14:43:56 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:25:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,8 @@ # include # include +# include "ft_input.h" + # define FLECHE_HAUT 4283163 # define FLECHE_BAS 4348699 # define FLECHE_GAUCHE 4479771 diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 58fbdd49..8ada16e5 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:43:12 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:31:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -116,7 +116,7 @@ int ft_is_delim(char c); int ft_is_delim_list(char c); t_lexstate get_lexer_state(char *str); -t_lexstate get_reserved_words(char *str); +int get_reserved_words(t_list **alst); int lexer_default(t_list **alst, char *str); int lexer_newline(t_list **alst, char *str); int lexer_delim(t_list **alst, char *str); diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index eba6e445..b44063b7 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/01/26 14:58:02 by gwojda ### ########.fr */ +/* Updated: 2017/02/03 15:31:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,6 @@ t_stof g_builtin[] = {"jobs", &builtin_jobs}, {"fg", &builtin_fg}, {"bg", &builtin_bg}, - {"history", &builtin_history}, {"read", &builtin_read}, {NULL, NULL}, }; diff --git a/42sh/src/exec/exec_default.c b/42sh/src/exec/exec_default.c index c37f3d73..5b02f375 100644 --- a/42sh/src/exec/exec_default.c +++ b/42sh/src/exec/exec_default.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 19:29:59 by ariard #+# #+# */ -/* Updated: 2017/02/02 15:54:31 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:31:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 117bf317..831d7500 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:40:05 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:31:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/command_getoutput.c b/42sh/src/lexer/command_getoutput.c index 56becc79..8982d96f 100644 --- a/42sh/src/lexer/command_getoutput.c +++ b/42sh/src/lexer/command_getoutput.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/20 00:31:42 by ariard ### ########.fr */ -======= -/* Updated: 2017/02/02 15:16:25 by jhalford ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:46:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_lexer.c b/42sh/src/lexer/ft_lexer.c index a0abdd90..8d4939b5 100644 --- a/42sh/src/lexer/ft_lexer.c +++ b/42sh/src/lexer/ft_lexer.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */ -/* Updated: 2017/02/02 15:42:24 by jhalford ### ########.fr */ +/* Updated: 2017/02/03 15:36:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,8 @@ int ft_lexer(t_list **alst, char **command) ret = 1; else if (ft_tokenize(alst, *command, DEFAULT)) ret = 1; - else if (ft_post_tokenize(alst, command)) - ret = 1; +// else if (ft_post_tokenize(alst, command)) +// ret = 1; ft_strdel(command); return (ret); } diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index e1a1856f..8d7b1056 100644 --- a/42sh/src/lexer/ft_post_tokenize.c +++ b/42sh/src/lexer/ft_post_tokenize.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/02/02 17:50:45 by ariard ### ########.fr */ -======= -/* Updated: 2017/02/02 15:29:57 by jhalford ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:47:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,12 +17,9 @@ int ft_post_tokenize(t_list **alst, char **str) int ret; t_flag tk; -<<<<<<< HEAD + // get_reserverd_words(alst, str); - while ((ret = reduce_parens(alst, str))) -======= while ((ret = reduce_parens(alst, *str))) ->>>>>>> master if (ret == -1) { ft_dprintf(2, "{red}%s: parse error near '('{eoc}\n", SHELL_NAME); diff --git a/42sh/src/lexer/ft_tokenize.c b/42sh/src/lexer/ft_tokenize.c index 8e2bf6d4..8f12b94f 100644 --- a/42sh/src/lexer/ft_tokenize.c +++ b/42sh/src/lexer/ft_tokenize.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/02/02 17:50:28 by ariard ### ########.fr */ -======= -/* Updated: 2017/02/02 15:34:45 by jhalford ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:47:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 8c8d4b99..bd679000 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/02/03 14:27:09 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:31:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,10 @@ int get_reserved_words(t_list **alst) { - t_token token; +// t_token token; + (void)alst; +/* while (*alst) { token = (*alst)->content; @@ -36,5 +38,5 @@ int get_reserved_words(t_list **alst) } (*alst) = (*alst)->next; } - return (0); +*/ return (0); } diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index 374f5090..a2b5b004 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/23 23:24:40 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/30 13:07:52 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:47:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_default.c b/42sh/src/lexer/lexer_default.c index ae3371f3..886f6d96 100644 --- a/42sh/src/lexer/lexer_default.c +++ b/42sh/src/lexer/lexer_default.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/26 18:16:02 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/27 15:53:10 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 15:39:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,10 +30,6 @@ int lexer_default(t_list **alst, char *str) else state = WORD; token = (*alst)->content; -<<<<<<< HEAD -======= - token_append(token, *str, 0); ->>>>>>> master token->type = TK_N_WORD; return (ft_tokenize(alst, str, state)); } diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index d655aca5..c7e260d6 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/26 23:37:49 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/26 16:30:43 by jhalford ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:48:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index 929d48e2..ddc4abae 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/25 22:52:47 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/27 15:53:31 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:49:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_great.c b/42sh/src/lexer/lexer_great.c index 69589914..8457ef2b 100644 --- a/42sh/src/lexer/lexer_great.c +++ b/42sh/src/lexer/lexer_great.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/24 19:06:00 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/27 15:54:53 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:49:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_greatand.c b/42sh/src/lexer/lexer_greatand.c index 75c78d4a..a0268048 100644 --- a/42sh/src/lexer/lexer_greatand.c +++ b/42sh/src/lexer/lexer_greatand.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/25 22:52:39 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/27 15:55:04 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:49:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_if.c b/42sh/src/lexer/lexer_if.c index e22002ff..0c15d9c7 100644 --- a/42sh/src/lexer/lexer_if.c +++ b/42sh/src/lexer/lexer_if.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 23:25:47 by ariard #+# #+# */ -/* Updated: 2017/01/31 23:28:52 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:12:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int lexer_if(t_list **alst, char *str) token->type = TK_IF; else if (ft_isalnum(*str)) { - token_append(token, *str); + token_append(token, *str, 0); return (ft_tokenize(alst, str + 1, WORD)); } return (ft_tokenize(&(*alst)->next, str + 3, LIST)); diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index 910cb3af..0b00c6a1 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/26 18:26:28 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/27 15:55:16 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:50:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_list.c b/42sh/src/lexer/lexer_list.c index 31e470b9..78edf1eb 100644 --- a/42sh/src/lexer/lexer_list.c +++ b/42sh/src/lexer/lexer_list.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:55:33 by ariard #+# #+# */ -/* Updated: 2017/02/02 17:31:07 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:12:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int lexer_list(t_list **alst, char *str) { if (ft_is_delim_list(*str)) { - token_append(token, *str++); + token_append(token, *str++, 0); while (ft_is_delim(*str) || *str == '\n') str++; if (ft_strncmp(str, "done", 4) == 0 && ft_isalpha(*(str + 4)) == 0) @@ -36,7 +36,7 @@ int lexer_list(t_list **alst, char *str) else if (ft_strncmp(str, "fi", 2) == 0 && ft_isalpha(*(str + 2)) == 0) return (ft_tokenize(alst, str, FI)); } - token_append(token, *str++); + token_append(token, *str++, 0); } return (0); } diff --git a/42sh/src/lexer/lexer_number.c b/42sh/src/lexer/lexer_number.c index 5ed39325..5406bead 100644 --- a/42sh/src/lexer/lexer_number.c +++ b/42sh/src/lexer/lexer_number.c @@ -6,11 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */ -<<<<<<< HEAD -/* Updated: 2017/01/25 23:05:08 by ariard ### ########.fr */ -======= -/* Updated: 2017/01/30 13:08:05 by wescande ### ########.fr */ ->>>>>>> master +/* Updated: 2017/02/03 14:50:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_while.c b/42sh/src/lexer/lexer_while.c index ec150596..46a24567 100644 --- a/42sh/src/lexer/lexer_while.c +++ b/42sh/src/lexer/lexer_while.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 21:58:12 by ariard #+# #+# */ -/* Updated: 2017/01/31 23:28:54 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:14:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int lexer_while(t_list **alst, char *str) token->type = TK_WHILE; else if (ft_isalnum(*str)) { - token_append(token, *str); + token_append(token, *str, 0); return (ft_tokenize(alst, str + 1, WORD)); } return (ft_tokenize(&(*alst)->next, str + 6, LIST)); diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index ea9e7bb8..265ad499 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:37:13 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:40:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index c02d1488..e49e5b56 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:36:09 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:12:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/builtin_history.c b/42sh/src/line-editing/builtin_history.c deleted file mode 100644 index 019af98e..00000000 --- a/42sh/src/line-editing/builtin_history.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* builtin_history.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/24 14:54:53 by gwojda #+# #+# */ -/* Updated: 2017/01/26 14:58:41 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int builtin_history(const char *path, char *const av[], char *const envp[]) -{ - size_t len; - t_list_history *head; - - (void)path; - (void)av; - (void)envp; - head = data_singleton()->line.list_end; - len = 1; - if (!head) - return (0); - if (head && !head->str) - head = head->next; - while (head && head->str) - { - ft_putnc(' ', ft_nbr_len(data_singleton()->line.list_size) - - ft_nbr_len(len)); - ft_printf("%zu %s\n", len, head->str); - ++len; - head = head->next; - } - return (0); -} diff --git a/42sh/src/line-editing/check_backslash.c b/42sh/src/line-editing/check_backslash.c deleted file mode 100644 index 1ab0256e..00000000 --- a/42sh/src/line-editing/check_backslash.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* check_backslash.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:01:25 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_check_backslash(char **str) -{ - char *tmp1; - char *tmp2; - - if (!*str || !**str) - return ; - if ((*str)[ft_strlen(*str) - 1] == '\\') - { - ft_putstr("> "); - data_singleton()->line.prompt_size = 2; - tmp1 = *str; - tmp2 = ft_strjoin(tmp1, "\n"); - free(tmp1); - tmp1 = ft_read_stdin(); - *str = ft_strjoin(tmp2, tmp1); - free(tmp1); - free(tmp2); - ft_putchar('\n'); - } -} diff --git a/42sh/src/line-editing/control_c_and_d.c b/42sh/src/line-editing/control_c_and_d.c deleted file mode 100644 index a194e7a0..00000000 --- a/42sh/src/line-editing/control_c_and_d.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* control_c_and_d.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:43:15 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_buff_f6(void) -{ - int ret; - - ret = 0; - read(0, &ret, sizeof(int)); -} - -void ft_control_d(void) -{ - char **str; - size_t *pos; - - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!(*str) || (*str)[0] == '\0') - builtin_exit(NULL, (char*[]){"exit", NULL}, NULL); - else if (*pos < ft_strlen(*str)) - ft_del(); - else - ft_puttermcaps("bl"); -} - -void ft_control_c(void) -{ - char **str; - size_t *pos; - - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - ft_putchar('\n'); - ft_prompt(); - ft_strdel(str); - *pos = 0; -} diff --git a/42sh/src/line-editing/copy_cut_paste.c b/42sh/src/line-editing/copy_cut_paste.c deleted file mode 100644 index 587469bb..00000000 --- a/42sh/src/line-editing/copy_cut_paste.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* copy_cut_paste.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:10:51 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static char *ft_strdupi_space(char const *s) -{ - int i; - char *str; - - i = 0; - while (s[i] && s[i] != '\n') - ++i; - if (s[i] == '\n') - ++i; - str = (char *)malloc(sizeof(char) * (i + 1)); - if (str) - { - str[i] = '\0'; - --i; - while (i >= 0) - { - str[i] = s[i]; - --i; - } - } - return (str); -} - -void ft_v(void) -{ - size_t tmp_pos; - int i; - char *tmp; - char **str; - size_t *pos; - - tmp = data_singleton()->line.copy_tmp; - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - i = 0; - tmp_pos = *pos; - if (!*str || !tmp) - return ; - while (tmp[i]) - { - *str = ft_realloc_imput(*str, tmp[i], *pos + i); - ++i; - } - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(*str, pos); - } - ft_current_str(*str, *pos); - ft_get_next_str(*str, pos); - ft_putnc('\b', *pos - tmp_pos); - (*pos) = tmp_pos; -} - -void ft_x(void) -{ - int i; - char **tmp; - char **str; - size_t *pos; - - tmp = &data_singleton()->line.copy_tmp; - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!*str) - return ; - if (*tmp) - ft_strdel(tmp); - *tmp = ft_strdupi_space(&(*str)[(*pos)]); - i = ft_strlen(*tmp); - while (i >= 0) - { - *str = ft_remove_imput(*str, *pos + i); - --i; - } - ft_puttermcaps("cd"); -} - -void ft_c(void) -{ - char *tmp; - char **str; - size_t *pos; - - tmp = data_singleton()->line.copy_tmp; - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (tmp) - ft_strdel(&tmp); - tmp = ft_strdupi_space((*str) + (*pos)); -} diff --git a/42sh/src/line-editing/curs_ask.c b/42sh/src/line-editing/curs_ask.c deleted file mode 100644 index 62634544..00000000 --- a/42sh/src/line-editing/curs_ask.c +++ /dev/null @@ -1,57 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_ask.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:03:49 by sbenning #+# #+# */ -/* Updated: 2017/01/21 22:22:36 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Read the line number for cursor's coordonate -*/ - -int curs_li_ask(void) -{ - char buff; - int li; - - li = 0; - buff = 0; - while (buff != ';') - { - buff = 0; - if (read(0, &buff, 1) < 0) - return (-1); - if (ft_isdigit(buff)) - li = li * 10 + (buff - '0'); - } - return (li); -} - -/* - * Read the colomn number for cursor's coordonate -*/ - -int curs_co_ask(void) -{ - char buff; - int co; - - co = 0; - buff = 0; - while (buff != 'R') - { - buff = 0; - if (read(0, &buff, 1) < 0) - return (-1); - if (ft_isdigit(buff)) - co = co * 10 + (buff - '0'); - } - return (co); -} diff --git a/42sh/src/line-editing/curs_move.c b/42sh/src/line-editing/curs_move.c deleted file mode 100644 index 18373634..00000000 --- a/42sh/src/line-editing/curs_move.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_forward.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:21:08 by sbenning #+# #+# */ -/* Updated: 2017/01/21 22:23:09 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Move the cursor forward (right/down) -*/ - -void curs_forward(t_curs *curs, int offset) -{ - int size; - int div; - int mod; - - size = (curs->li * curs->win_co + curs->co) + offset; - div = size / curs->win_co; - mod = size % curs->win_co; - curs_goto(curs, div, mod); -} - -/* - * Move the cursor backward (left/up) -*/ - -void curs_backward(t_curs *curs, int offset) -{ - int size; - int div; - int mod; - - size = (curs->li * curs->win_co + curs->co) - offset; - div = size / curs->win_co; - mod = size % curs->win_co; - curs_goto(curs, div, mod); -} diff --git a/42sh/src/line-editing/curs_setup.c b/42sh/src/line-editing/curs_setup.c deleted file mode 100644 index 5c43b795..00000000 --- a/42sh/src/line-editing/curs_setup.c +++ /dev/null @@ -1,82 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_setup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 16:36:43 by sbenning #+# #+# */ -/* Updated: 2017/01/21 22:23:21 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Set coordonate cursor data - * "\033[6n" ask for terminal to write on standard entry the cursor's coordonate -*/ - -int curs_coo_setup(t_curs *curs) -{ - ft_putstr("\033[6n"); - curs->li = curs_li_ask() - 1; - curs->co = curs_co_ask() - 1; - return ((curs->li < 0 || curs->co < 0 ? -1 : 0)); -} - -/* - * Set windows cursor data -*/ - -void curs_win_setup(t_curs *curs) -{ - struct winsize ws; - - ioctl(0, TIOCGWINSZ, &ws); - curs->win_li = ws.ws_row; - curs->win_co = ws.ws_col; -} - -/* - * Reset saved cursor data -*/ - -void curs_reset(int sig) -{ - t_curs *curs; - - curs = curs_single(NULL, 0); - curs_win_setup(curs); - curs_coo_setup(curs); - return ; - (void)sig; -} - -/* - * Save the cursor reference, init termcap and set cursor data -*/ - -int curs_setup(t_curs *curs) -{ - curs_single(curs, 1); - signal(SIGWINCH, curs_reset); - if (tgetent(NULL, "xterm") != 1) - return (-1); - if (curs_term_setup() < 0) - return (-1); - curs_win_setup(curs); - if (curs_coo_setup(curs) < 0) - return (-1); - return (0); -} - -/* - * Erase cursor data and reset terminal -*/ - -int curs_cleanup(t_curs *curs) -{ - ft_bzero(curs, sizeof(t_curs)); - return (curs_term_cleanup()); -} diff --git a/42sh/src/line-editing/curs_term_setup.c b/42sh/src/line-editing/curs_term_setup.c deleted file mode 100644 index 8bd5eeaa..00000000 --- a/42sh/src/line-editing/curs_term_setup.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_term_setup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 16:50:26 by sbenning #+# #+# */ -/* Updated: 2017/01/21 22:23:38 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Return a static termios structure reference -*/ - -static struct termios *curs_term(void) -{ - static struct termios term; - - return (&term); -} - -/* - * Save the current termios state and set termios to RAW -*/ - -int curs_term_setup(void) -{ - struct termios *single; - struct termios term; - - single = curs_term(); - if (tcgetattr(0, single) < 0) - return (-1); - term = *single; - term.c_lflag &= ~(ECHO | ICANON | ISIG); - term.c_cc[VTIME] = 0; - term.c_cc[VMIN] = 1; - if (tcsetattr(0, TCSADRAIN, &term) < 0) - return (-1); - return (0); -} - -/* - * Set termios to the saved state -*/ - -int curs_term_cleanup(void) -{ - struct termios *single; - struct termios term; - - single = curs_term(); - term = *single; - term.c_lflag |= ECHO | ICANON | ISIG; - if (tcsetattr(0, TCSADRAIN, single) < 0) - return (-1); - return (0); -} diff --git a/42sh/src/line-editing/curs_write.c b/42sh/src/line-editing/curs_write.c deleted file mode 100644 index c9e4297a..00000000 --- a/42sh/src/line-editing/curs_write.c +++ /dev/null @@ -1,63 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* curs_write.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 17:52:20 by sbenning #+# #+# */ -/* Updated: 2017/01/21 22:25:56 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_curs.h" - -/* - * Write some buffer to stdout and recalc coordonate (go to next line and scroll if necessary) -*/ - -void curs_write(t_curs *curs, char *str, size_t len) -{ - int size; - int div; - int mod; - - size = (curs->li * curs->win_co + curs->co) + len; - div = size / curs->win_co; - mod = size % curs->win_co; - write(1, str, len); - curs_goto(curs, div, mod); -} - -/* - * curs_write in video mode -*/ - -void curs_video_write(t_curs *curs, char *str, size_t len) -{ - ft_putstr(tgetstr("so", NULL)); - curs_write(curs, str, len); - ft_putstr(tgetstr("me", NULL)); -} - -/* - * curs_write in video mode without moving the cursor -*/ - -void curs_video_write_static(t_curs *curs, char *str, size_t len) -{ - ft_putstr(tgetstr("so", NULL)); - curs_write(curs, str, len); - ft_putstr(tgetstr("me", NULL)); - curs_backward(curs, len); -} - -/* - * curs_write without moving the cursor -*/ - -void curs_write_static(t_curs *curs, char *str, size_t len) -{ - curs_write(curs, str, len); - curs_backward(curs, len); -} diff --git a/42sh/src/line-editing/ft_readline.c b/42sh/src/line-editing/ft_readline.c deleted file mode 100644 index 2570d0f3..00000000 --- a/42sh/src/line-editing/ft_readline.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_readline.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: sbenning +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */ -/* Updated: 2017/01/22 23:15:27 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_readline.h" - -static t_input g_input[] = {\ - {RL_NL_CODE, rl_nl_function},\ - {RL_COMP_CODE, rl_comp_function},\ - {RL_INSERT_CODE, rl_insert_function},\ - {RL_CLEAR_CODE, rl_clear_function},\ - {RL_RETARR_CODE, rl_retarr_function},\ - {RL_SUPPR_CODE, rl_suppr_function},\ - {RL_ESC_CODE, rl_esc_function},\ - {RL_QUOTE_CODE, rl_quote_function},\ - {RL_DQUOTE_CODE, rl_dquote_function},\ - {RL_LEFT_CODE, rl_left_function},\ - {RL_SELECT_LEFT_CODE, rl_select_left_function},\ - {RL_RIGHT_CODE, rl_right_function},\ - {RL_SELECT_RIGHT_CODE, rl_select_right_function},\ - {RL_WLEFT_CODE, rl_wleft_function},\ - {RL_SELECT_WLEFT_CODE, rl_select_wleft_function},\ - {RL_WRIGHT_CODE, rl_wright_function},\ - {RL_SELECT_WRIGHT_CODE, rl_select_wright_function},\ - {RL_HOME_CODE, rl_home_function},\ - {RL_SELECT_HOME_CODE, rl_select_home_function},\ - {RL_END_CODE, rl_end_function},\ - {RL_SELECT_END_CODE, rl_select_end_function},\ - {RL_PAGEUP_CODE, rl_pageup_function},\ - {RL_SELECT_PAGEUP_CODE, rl_select_pageup_function},\ - {RL_PAGEDOWN_CODE, rl_pagedown_function},\ - {RL_SELECT_PAGEDOWN_CODE, rl_select_pagedown_function},\ - {RL_COPY_CODE, rl_copy_function},\ - {RL_CUT_CODE, rl_cut_function},\ - {RL_PASTE_CODE, rl_paste_function},\ - {0x0, rl_default_function}\ -}; - -static t_input_function rl_get_function(long int input) -{ - int i; - - i = -1; - while (g_input[++i].code) - { - if (input == g_input[i].code) - break ; - } - return (g_input[i].function); -} - -static long int rl_read(void) -{ - long int input; - - ft_bzero(&input, sizeof(long int)); - if (read(0, &input, sizeof(long int)) < 0) - return (0); - return (input); -} - -static int rl_loop(t_line *line) -{ - long int input; - int ret; - - rl_put_prompt(line); - while (42) - { - input = rl_read(); - if (input == 0) - continue ; - rl_toogle_bitset(line, 0); - if (rl_get_function(input)(line, input) < 0) - return (-1); - if ((ret = rl_finish(line))) - break ; - rl_toogle_bitset(line, 1); - } - return ((ret < 0 ? -1 : 0)); -} - -int ft_readline() -{ - t_line *line; - - line = &data_singleton()->line; - if (rl_setup(line) < 0) - return (-1); - if (rl_loop(line) < 0) - { - rl_teardown(line); - return (-1); - } - if (rl_cleanup(line) < 0) - return (-1); - return (0); -} diff --git a/42sh/src/line-editing/ft_split_whitespaces.c b/42sh/src/line-editing/ft_split_whitespaces.c deleted file mode 100644 index 05506cfb..00000000 --- a/42sh/src/line-editing/ft_split_whitespaces.c +++ /dev/null @@ -1,79 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split_whitespaces.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/02 17:52:52 by gwojda #+# #+# */ -/* Updated: 2017/01/25 15:49:21 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -char *ft_strdupi_w(char const *s) -{ - int i; - char *str; - - i = 0; - while (s[i] && s[i] != ' ' && s[i] != '\t') - i++; - str = (char *)malloc(sizeof(char) * (i + 1)); - if (str) - { - str[i--] = '\0'; - while (i >= 0) - { - str[i] = s[i]; - i--; - } - } - return (str); -} - -static int ft_len_words(char const *s) -{ - int i; - int len; - - i = 0; - len = 0; - while (s[i]) - { - if ((i == 0 && s[i] != ' ' && s[i] != '\t') || ((s[i] != ' ' - && s[i] != '\t') && (s[i - 1] == ' ' || s[i - 1] == '\t'))) - len++; - i++; - } - return (len); -} - -char **ft_split_whitespaces(char const *s) -{ - int i; - char **str; - int j; - - str = NULL; - if (!(s)) - return (str); - str = (char **)malloc(sizeof(char *) * (ft_len_words(s) + 1)); - i = 0; - j = 0; - if (!(str)) - return (str); - while (s[i]) - { - if ((i == 0 && s[i] != ' ' && s[i] != '\t') || ((s[i] != ' ' - && s[i] != '\t') && (s[i - 1] == ' ' || s[i - 1] == '\t'))) - { - str[j] = ft_strdupi_w((s + i)); - j++; - } - i++; - } - str[j] = NULL; - return (str); -} diff --git a/42sh/src/line-editing/get_touch.c b/42sh/src/line-editing/get_touch.c deleted file mode 100644 index 2ecde44c..00000000 --- a/42sh/src/line-editing/get_touch.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_touch.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ -/* Updated: 2017/02/02 18:27:07 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -t_key g_key[] = -{ - {FLECHE_HAUT , &ft_history_up }, - {FLECHE_BAS , &ft_history_down }, - {FLECHE_GAUCHE , &ft_move_left }, - {FLECHE_DROITE , &ft_move_right }, - {TOUCHE_DELETE , &ft_del }, - {TOUCHE_CTRL_C , &ft_control_c }, - {TOUCHE_CTRL_D , &ft_control_d }, - {TOUCHE_CTRL_R , &ft_history_parsing }, - {TOUCHE_SUPPR , &ft_suppr }, - {TOUCHE_HOME , &ft_home }, - {TOUCHE_END , &ft_end }, - {TOUCHE_OPT_UP , &ft_up }, - {TOUCHE_OPT_DOWN , &ft_down }, - {TOUCHE_OPT_LEFT , &ft_found_prev_word }, - {TOUCHE_OPT_RIGHT , &ft_found_next_word }, - {TOUCHE_OPT_C , &ft_c }, - {TOUCHE_OPT_V , &ft_v }, - {TOUCHE_OPT_X , &ft_x }, - {TOUCHE_F5 , &ft_printall }, - {TOUCHE_F6 , &ft_buff_f6 }, - {0 , 0 }, -}; - -char *ft_read_stdin(void) -{ - int ret; - int j; - - if (data_singleton()->line.input) - { - ft_current_str(data_singleton()->line.input, data_singleton()->line.pos); - ft_get_next_str(data_singleton()->line.input, &data_singleton()->line.pos); - if (data_singleton()->line.input[data_singleton()->line.pos]) - ++(data_singleton()->line.pos); - } - while (42) - { - ret = 0; - j = 0; - read(0, &ret, sizeof(int)); - while (g_key[j].value && g_key[j].value != ret) - ++j; - if (g_key[j].value) - g_key[j].f(); - else if (ft_isprint(ret)) - ft_print(ret); - else if (ret == 10) - return (data_singleton()->line.input); - else if (ft_isascii(ret) == 0) - ft_read_it(ret, &data_singleton()->line.pos, - &data_singleton()->line.input); - } -} diff --git a/42sh/src/line-editing/get_touch_toolz.c b/42sh/src/line-editing/get_touch_toolz.c deleted file mode 100644 index e5937fac..00000000 --- a/42sh/src/line-editing/get_touch_toolz.c +++ /dev/null @@ -1,113 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_touch_toolz.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */ -/* Updated: 2017/02/02 15:22:35 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_found_prev_word(void) -{ - int i; - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - i = 0; - if (!*pos) - return ; - if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' ')) - { - ft_puttermcaps("le"); - --(*pos); - } - while ((int)*pos - i - 1 > 0 && str[*pos - i - 1] == ' ') - { - ft_puttermcaps("le"); - ++i; - } - (*pos) = (i && str[*pos - i] == '\n') ? *pos - i + 1 : *pos - i; - i = 0; - if (*pos >= 1 && str[*pos - 1] == '\n') - { - ft_puttermcaps("cd"); - if (*pos >= 2) - (*pos) -= 2; - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - ++(*pos); - } - else - { - if (*pos && !(str[*pos] == '\n' || str[*pos] == ' ')) - { - ft_puttermcaps("le"); - --(*pos); - } - while (*pos - i && (str[*pos - i] == '\n' || str[*pos - i] == ' ')) - { - ft_puttermcaps("le"); - ++i; - } - while (*pos - i && str[*pos - i] != '\n' && str[*pos - i] != ' ') - { - ft_puttermcaps("le"); - ++i; - } - if (str[*pos - i] == '\n' || str[*pos - i] == ' ') - { - ft_puttermcaps("nd"); - ++(*pos); - } - (*pos) -= i; - } -} - -void ft_found_next_word(void) -{ - int i; - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - i = 0; - while (str[i + *pos] && str[i + *pos] == ' ') - { - ft_putchar(str[i + *pos]); - ++i; - } - if (str[*pos] == '\n') - { - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - ft_puttermcaps("cd"); - ft_get_next_str(str, pos); - (*pos) += (*pos) ? 2 : 1; - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - if (!str[*pos]) - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - else - { - while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ') - { - ft_putchar(str[i + *pos]); - ++i; - } - *pos += i; - } -} diff --git a/42sh/src/line-editing/get_touch_toolz_2.c b/42sh/src/line-editing/get_touch_toolz_2.c deleted file mode 100644 index 05805aa2..00000000 --- a/42sh/src/line-editing/get_touch_toolz_2.c +++ /dev/null @@ -1,130 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_touch_toolz_2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */ -/* Updated: 2017/02/02 17:54:27 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int ft_put(int nb) -{ - write(1, &nb, 1); - return (1); -} - -void ft_end(void) -{ - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!str) - return ; - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - ft_puttermcaps("cd"); - while (str[*pos]) - ++(*pos); - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); -} - -void ft_home(void) -{ - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!str) - return ; - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(str, pos); - if (str[*pos + 1] == '\n') - ft_puttermcaps("nd"); - } - ft_puttermcaps("cd"); - *pos = 0; - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - ft_check_end_of_line(str, *pos); - if (!str[*pos]) - --(*pos); - ft_get_beggin_with_curs(str, pos); -} - -void ft_move_right(void) -{ - size_t tmp; - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (ft_strlen(str) <= *pos) - return ; - if (str[*pos] == '\n') - { - if (*pos) - { - tmp = *pos - 1; - ft_get_beggin_with_curs(str, &tmp); - } - ft_puttermcaps("cd"); - ++(*pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - if (!str[*pos]) - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - else - { - ft_putchar(str[*pos]); - ++(*pos); - } -} - -void ft_move_left(void) -{ - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!*pos) - return ; - if (str[*pos - 1] == '\n') - { - if (*pos - 1 == 0) - { - ft_puttermcaps("cd"); - --(*pos); - return ; - } - ft_puttermcaps("cd"); - (*pos) -= 2; - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - ++(*pos); - } - else - { - ft_puttermcaps("le"); - --(*pos); - } -} diff --git a/42sh/src/line-editing/heredoc.c b/42sh/src/line-editing/heredoc.c deleted file mode 100644 index 7637dcbd..00000000 --- a/42sh/src/line-editing/heredoc.c +++ /dev/null @@ -1,77 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* heredoc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/24 15:52:34 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:09:42 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -char *ft_get_next_word(char *str) -{ - int j; - int k; - - j = 0; - k = 0; - while (str[j] && str[j] == ' ') - ++j; - while (str[j + k] && str[j + k] != ' ') - ++k; - return (ft_strndup(str + j, k)); -} - -static void ft_check_heredoc_2(char **str, char *end) -{ - char boolean; - char *tmp; - char *tmp2; - - boolean = 0; - while (!boolean) - { - ft_putstr("heredoc> "); - data_singleton()->line.prompt_size = 9; - tmp = *str; - *str = ft_strjoin(*str, "\n"); - free(tmp); - tmp = *str; - tmp2 = ft_read_stdin(); - if (!ft_strcmp(end, tmp2)) - boolean = 1; - *str = ft_strjoin(tmp, tmp2); - free(tmp); - free(tmp2); - ft_putchar('\n'); - } -} - -void ft_check_heredoc(char **str) -{ - int i; - char *end; - - i = 0; - end = NULL; - if (!*str) - return ; - while ((*str)[i]) - { - if ((*str)[i] == '<' && !ft_strncmp(*str + i, "<<", 2)) - { - if ((*str)[i + 1] == '<' && (*str)[i + 2]) - end = ft_get_next_word(*str + i + 2); - else - return ; - } - ++i; - } - if (!end) - return ; - ft_check_heredoc_2(str, end); -} diff --git a/42sh/src/line-editing/history.c b/42sh/src/line-editing/history.c deleted file mode 100644 index 295af73e..00000000 --- a/42sh/src/line-editing/history.c +++ /dev/null @@ -1,87 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* history.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */ -/* Updated: 2017/02/02 18:04:16 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_history_down(void) -{ - t_list_history *head; - char **str; - size_t *pos; - - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - head = data_singleton()->line.list_cur; - if (!head || !*str) - return ; - if (*str) - { - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(*str, pos); - } - ft_puttermcaps("cd"); - *pos = 0; - ft_strdel(str); - } - if (head->next) - head = head->next; - if (!head->str) - *str = NULL; - else - *str = ft_strdup(head->str); - if (*str) - ft_current_str(*str, *pos); - if (*str) - *pos = ft_strlen_next(*str, *pos); - else - *pos = 0; - data_singleton()->line.list_cur = head; -} - -void ft_history_up(void) -{ - t_list_history *head; - char **str; - size_t *pos; - - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - head = data_singleton()->line.list_cur; - if (!head) - return ; - if (*str) - { - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(*str, pos); - } - ft_puttermcaps("cd"); - *pos = 0; - ft_strdel(str); - } - if (head->prev) - head = head->prev; - if (!head->str) - *str = NULL; - else - *str = ft_strdup(head->str); - if (*str) - ft_current_str(*str, *pos); - if (*str) - *pos = ft_strlen_next(*str, *pos); - else - *pos = 0; - data_singleton()->line.list_cur = head; -} diff --git a/42sh/src/line-editing/history_parsing.c b/42sh/src/line-editing/history_parsing.c deleted file mode 100644 index bd3f67d4..00000000 --- a/42sh/src/line-editing/history_parsing.c +++ /dev/null @@ -1,90 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* history_parsing.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:20:26 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static int ft_history_parsing_4(char *str, int *i) -{ - if (!ft_strncmp("!!", str + *i, 2)) - { - ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2); - ++(*i); - return (1); - } - else if (ft_isdigit(str[(*i) + 1])) - { - ft_realloc_str_history(&(data_singleton()->line.input), *i, - ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1); - (*i) += ft_nbr_len(ft_atoi(str + *i + 1)); - return (1); - } - return (0); -} - -static int ft_history_parsing_3(char *str, int *i) -{ - if (ft_history_parsing_4(str, i)) - return (1); - else if (str[*i + 1] == '-') - { - ft_realloc_str_history(&(data_singleton()->line.input), *i, - data_singleton()->line.list_size - ft_atoi(str + *i + 2), - ft_nbr_len(ft_atoi(str + *i + 2)) + 2); - (*i) += ft_nbr_len(ft_atoi(str + *i + 2) + 1); - } - else if (str[*i + 1] == '?') - ft_realloc_str_history_3(&(data_singleton()->line.input), *i, - ft_strdupi_w(str + *i + 2)); - else if (str[*i + 1] != ' ') - ft_realloc_str_history_2(&(data_singleton()->line.input), *i, - ft_strdupi_w(str + *i + 1)); - else - return (0); - return (1); -} - -static void ft_history_parsing_2(void) -{ - data_singleton()->line.opt = data_singleton()->line.opt | HIST; - ft_prompt(); - data_singleton()->line.input = ft_read_stdin(); - ft_putchar('\n'); - data_singleton()->line.opt = data_singleton()->line.opt | ~HIST; - ft_check_quotes(&data_singleton()->line.input); - ft_check_heredoc(&data_singleton()->line.input); - ft_history_parsing(); -} - -void ft_history_parsing(void) -{ - char *str; - int i; - char boolean; - - i = 0; - boolean = 0; - str = data_singleton()->line.input; - if (!str) - return ; - while (str[i]) - { - if (str[i] == '!') - { - boolean = 1; - if (!ft_history_parsing_3(str, &i)) - boolean = 0; - } - ++i; - } - if (boolean) - ft_history_parsing_2(); -} diff --git a/42sh/src/line-editing/history_parsing_toolz.c b/42sh/src/line-editing/history_parsing_toolz.c deleted file mode 100644 index 31a4b818..00000000 --- a/42sh/src/line-editing/history_parsing_toolz.c +++ /dev/null @@ -1,94 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* history_parsing_toolz.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */ -/* Updated: 2017/01/25 14:41:29 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static char *ft_nget_histo(size_t nb_his) -{ - t_list_history *list; - size_t i; - - i = 0; - list = data_singleton()->line.list_beg; - if (!list) - return (NULL); - if (!list->str) - list = list->prev; - while (i < nb_his && list->str) - { - list = list->prev; - ++i; - } - return (list->str); -} - -void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len) -{ - char *new_str; - char *new_str2; - char *new_str3; - - if (!*str) - return ; - new_str = ft_strndup(*str, pos); - ft_printf("\n\npos = %d\n\n", len); - new_str3 = ft_nget_histo(nb_his); - if (new_str3) - { - new_str2 = ft_strjoin(new_str, new_str3); - free(new_str); - new_str3 = ft_strjoin(new_str2, (*str) + pos + len); - free(new_str2); - } - else - new_str3 = ft_strjoin(new_str, (*str) + pos + len); - free(*str); - *str = new_str3; -} - -static char *ft_strget_histo(char *str) -{ - t_list_history *list; - - list = data_singleton()->line.list_beg; - if (!list) - return (NULL); - if (!list->str) - list = list->prev; - while (list->str && ft_strncmp(list->str, str, ft_strlen(str))) - list = list->prev; - return (list->str); -} - -void ft_realloc_str_history_2(char **str, size_t pos, char *s) -{ - char *new_str; - char *new_str2; - char *new_str3; - - if (!*str) - return ; - new_str = ft_strndup(*str, pos); - new_str3 = ft_strget_histo(s); - if (new_str3) - { - new_str2 = ft_strjoin(new_str, new_str3); - free(new_str); - new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 1); - free(new_str2); - } - else - new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 1); - free(s); - free(*str); - *str = new_str3; -} diff --git a/42sh/src/line-editing/history_parsing_toolz_2.c b/42sh/src/line-editing/history_parsing_toolz_2.c deleted file mode 100644 index 23ce77ae..00000000 --- a/42sh/src/line-editing/history_parsing_toolz_2.c +++ /dev/null @@ -1,64 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* history_parsing_toolz_2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/25 20:04:16 by gwojda #+# #+# */ -/* Updated: 2017/01/26 11:33:22 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -char *ft_strget_history(char *str) -{ - t_list_history *list; - size_t i; - char *tmp; - - list = data_singleton()->line.list_beg; - if (!list) - return (NULL); - if (!list->str) - list = list->prev; - while (list->str) - { - tmp = list->str; - i = 0; - while (tmp[i]) - { - if (ft_strlen(tmp + i) >= ft_strlen(str) - && !ft_strncmp(tmp + i, str, ft_strlen(str))) - return (tmp); - ++i; - } - list = list->prev; - } - return (list->str); -} - -void ft_realloc_str_history_3(char **str, size_t pos, char *s) -{ - char *new_str; - char *new_str2; - char *new_str3; - - if (!*str) - return ; - new_str = ft_strndup(*str, pos); - new_str3 = ft_strget_history(s); - if (new_str3) - { - new_str2 = ft_strjoin(new_str, new_str3); - free(new_str); - new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2); - free(new_str2); - } - else - new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2); - free(s); - free(*str); - *str = new_str3; -} diff --git a/42sh/src/line-editing/list_toolz.c b/42sh/src/line-editing/list_toolz.c deleted file mode 100644 index 51bde359..00000000 --- a/42sh/src/line-editing/list_toolz.c +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list_toolz.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:08:01 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -t_list_history *ft_create_history_list(char *str) -{ - t_list_history *list; - - list = (t_list_history *)malloc(sizeof(t_list_history)); - if (!list) - return (NULL); - if (!str) - list->str = NULL; - else - list->str = ft_strdup(str); - list->prev = NULL; - list->next = NULL; - return (list); -} - -void ft_push_back_history(t_list_history **head, t_list_history *new) -{ - ++(data_singleton()->line.list_size); - if (!*head) - { - *head = new; - (*head)->prev = ft_create_history_list(NULL); - (*head)->prev->next = (*head); - (*head)->next = ft_create_history_list(NULL); - (*head)->next->prev = (*head); - (*head) = (*head)->next; - (data_singleton())->line.list_end = new; - return ; - } - while ((*head)->next) - (*head) = (*head)->next; - new->prev = (*head)->prev; - (*head)->prev->next = new; - new->next = (*head); - (*head)->prev = new; -} diff --git a/42sh/src/line-editing/move_to_line.c b/42sh/src/line-editing/move_to_line.c deleted file mode 100644 index c8161cfb..00000000 --- a/42sh/src/line-editing/move_to_line.c +++ /dev/null @@ -1,106 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* move_to_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */ -/* Updated: 2017/02/02 15:07:08 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static void ft_up_2(size_t *pos, char *str) -{ - int len; - int i; - - i = 0; - len = ft_size_term(); - if (str[*pos - i] == '\n') - { - --len; - ft_puttermcaps("le"); - ++i; - } - while (*pos - i && str[*pos - i] != '\n' && --len + 1) - { - ft_puttermcaps("le"); - ++i; - } - if (str[*pos - i] == '\n') - { - ft_puttermcaps("nd"); - ++(*pos); - } - (*pos) -= i; -} - -void ft_up(void) -{ - int i; - char *str; - size_t *pos; - - i = 0; - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!str) - return ; - if (str[*pos - 1] == '\n') - { - ft_puttermcaps("cd"); - (*pos) -= 2; - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - ++(*pos); - } - else - ft_up_2(pos, str); -} - -static void ft_down_2(size_t *pos, char *str) -{ - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(str, pos); - } - ft_puttermcaps("cd"); - ft_get_next_str(str, pos); - (*pos) += 2; - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - if (!(str[*pos])) - --(*pos); - ft_get_beggin_with_curs(str, pos); -} - -void ft_down(void) -{ - int i; - int len; - char *str; - size_t *pos; - - i = 0; - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - if (!str) - return ; - if (str[*pos] == '\n') - ft_down_2(pos, str); - else - { - len = ft_size_term(); - while (str[i + *pos] && str[i + *pos] != '\n' && --len + 1) - { - ft_putchar(str[i + *pos]); - ++i; - } - *pos += i; - } -} diff --git a/42sh/src/line-editing/print_and_del.c b/42sh/src/line-editing/print_and_del.c deleted file mode 100644 index ac352ae1..00000000 --- a/42sh/src/line-editing/print_and_del.c +++ /dev/null @@ -1,112 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* print_and_del.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ -/* Updated: 2017/02/02 15:10:50 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int ft_found_next_char(char *str, size_t i) -{ - while (str[i]) - { - if (str[i] == '\n') - return (1); - ++i; - } - return (0); -} - -void ft_print(int ret) -{ - int j; - char **str; - size_t *i; - - j = 0; - str = &data_singleton()->line.input; - i = &data_singleton()->line.pos; - *str = ft_realloc_imput(*str, ret, *i); - while (*((*str) + *i + j) && *((*str) + *i + j) != '\n') - { - ft_putchar(*((*str) + *i + j)); - ++j; - } - ft_check_end_of_line(*str, *i + j); - ft_putnc('\b', j - 1); - ++(*i); -} - -void ft_suppr_2(char **str, size_t *i, size_t tmp) -{ - ft_puttermcaps("cd"); - ft_current_str(*str, *i); - ft_get_next_str(*str, i); - if (*i && (*str)[*i] && ft_found_next_char(*str, *i)) - ++(*i); - ft_putnc('\b', *i - tmp); - (*i) = tmp; - if (ft_strlen(*str) == 0) - ft_strdel(str); -} - -void ft_suppr(void) -{ - size_t tmp; - char boolean; - char **str; - size_t *i; - - str = &data_singleton()->line.input; - i = &data_singleton()->line.pos; - boolean = 0; - if (*i <= 0) - return ; - if ((*str)[*i - 1] != '\n') - boolean = 1; - --(*i); - tmp = *i; - if (boolean) - { - ft_get_beggin_with_curs(*str, i); - *str = ft_remove_imput((*str), tmp); - } - else - { - *str = ft_remove_imput((*str), tmp); - ft_get_beggin(*str, i); - } - ft_suppr_2(str, i, tmp); -} - -void ft_del(void) -{ - size_t tmp; - char **str; - size_t *i; - - str = &data_singleton()->line.input; - i = &data_singleton()->line.pos; - tmp = *i; - *str = ft_remove_imput((*str), tmp); - if (!((*str) && (*i) < ft_strlen((*str)))) - return ; - if (*i) - { - --(*i); - ft_get_beggin_with_curs(*str, i); - } - ft_puttermcaps("cd"); - ft_current_str(*str, *i); - ft_get_next_str(*str, i); - if ((*str)[*i]) - ++(*i); - ft_putnc('\b', *i - tmp); - (*i) = tmp; -} diff --git a/42sh/src/line-editing/prompt.c b/42sh/src/line-editing/prompt.c deleted file mode 100644 index 94482a27..00000000 --- a/42sh/src/line-editing/prompt.c +++ /dev/null @@ -1,65 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* prompt.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/01/25 16:31:24 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -/* -**ft_printf de la lib bug avec unicode -*/ - -static void ft_get_date(void) -{ - time_t t; - struct tm tm; - - t = time(NULL); - tm = *localtime(&t); - ft_putstr("\033[22;32m"); - printf("%.2d:%.2d:%.2d ", tm.tm_hour, tm.tm_min, tm.tm_sec); - fflush(NULL); - if (tm.tm_hour >= 8 && tm.tm_hour < 20) - printf("\033[22;33m%C ", L'☀'); - else - printf("\033[22;33m%C ", L'★'); - fflush(NULL); -} - -static int ft_currend_dir(void) -{ - int i; - int j; - char **env; - - i = 0; - env = data_singleton()->env; - while (ft_strncmp(env[i], "PWD=", 4)) - ++i; - j = ft_strlen(env[i]); - while (j && env[i][j] != '/') - --j; - ft_putstr(env[i] + j + 1); - return (ft_strlen(env[i] + j + 1)); -} - -void ft_prompt(void) -{ - int ret; - - ft_get_date(); - ft_putstr("\033[22;36m"); - ret = ft_currend_dir(); - ft_putstr("\033[22;33m"); - printf(" %C", L'›'); - fflush(NULL); - ft_putstr("\033[22;37m"); - data_singleton()->line.prompt_size = ret + 12; -} diff --git a/42sh/src/line-editing/quotes_gest.c b/42sh/src/line-editing/quotes_gest.c deleted file mode 100644 index c4be15f9..00000000 --- a/42sh/src/line-editing/quotes_gest.c +++ /dev/null @@ -1,88 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* quotes_gest.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */ -/* Updated: 2017/02/02 17:53:41 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int ft_check_quotes_num(char *s) -{ - int i; - char simp; - char doub; - - i = 0; - simp = 0; - doub = 0; - while (s[i]) - { - if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i)) - { - simp = 1; - ++i; - while (s[i] && !(s[i] == '\'' && ((i && s[i - 1] != '\\') || !i))) - ++i; - if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i)) - simp = 0; - } - else if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i)) - { - doub = 1; - ++i; - while (s[i] && !(s[i] == '"' && ((i && s[i - 1] != '\\') || !i))) - ++i; - if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i)) - doub = 0; - } - if (s[i]) - ++i; - } - if (doub) - return (2); - else if (simp) - return (1); - return (0); -} - -void ft_check_quotes(char **s) -{ - int ret; - char *tmp; - char *tmp2; - int prompt_size_mem; - t_list_history *head; - - head = data_singleton()->line.list_beg; - if (!*s) - return ; - while ((ret = (ft_check_quotes_num(*s)))) - { - if (ret == 1) - ft_putstr("squote> "); - else if (ret == 2) - ft_putstr("dquote> "); - tmp = *s; - *s = ft_strjoin(*s, "\n"); - ft_strdel(&tmp); - tmp = *s; - prompt_size_mem = data_singleton()->line.prompt_size; - data_singleton()->line.input = NULL; - data_singleton()->line.pos = 0; - tmp2 = ft_read_stdin(); - data_singleton()->line.prompt_size = prompt_size_mem; - ft_putchar('\n'); - if (!tmp2) - continue ; - *s = ft_strjoin(tmp, tmp2); - data_singleton()->line.input = *s; - ft_strdel(&tmp); - ft_strdel(&tmp2); - } -} diff --git a/42sh/src/line-editing/reader.c b/42sh/src/line-editing/reader.c deleted file mode 100644 index 4a3e17d3..00000000 --- a/42sh/src/line-editing/reader.c +++ /dev/null @@ -1,66 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* reader.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */ -/* Updated: 2017/01/25 19:07:39 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j) -{ - int i; - - i = 0; - while (i < 4 && t[i] == '\0') - ++i; - while (i < 4) - { - if (t[i] && ft_isprint(t[i])) - { - *str = ft_realloc_imput(*str, t[i], *pos); - ++(*pos); - ++(*j); - } - ++i; - } -} - -static void ft_read_it_2(int input, char t[5]) -{ - t[3] = (input / ft_pow(256, 3)) ? (input / ft_pow(256, 3)) : '\0'; - if (t[3]) - input = input % ft_pow(256, 3); - t[2] = (input / ft_pow(256, 2)) ? (input / ft_pow(256, 2)) : '\0'; - if (t[2]) - input = input % ft_pow(256, 2); - t[1] = (input / ft_pow(256, 1)) ? (input / ft_pow(256, 1)) : '\0'; - if (t[1]) - input = input % ft_pow(256, 1); - t[0] = (input / ft_pow(256, 0)) ? (input / ft_pow(256, 0)) : '\0'; - if (t[0]) - input = input % ft_pow(256, 0); - t[4] = '\0'; -} - -void ft_read_it(int input, size_t *pos, char **str) -{ - int j; - char t[5]; - - j = 0; - if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || - input == 126 || input == 993090331 || input == 925981467 || - input == 21298 || input == 892427035 || input == 8270395 || - input == 942758683 || input == 993090331 || input == 18489 || input == 17977) - return ; - ft_read_it_2(input, t); - ft_read_it_3(str, t, pos, &j); - ft_putstr((*str) + (*pos) - j); - ft_putnc('\b', ft_strlen((*str)) - ((*pos))); -} diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c deleted file mode 100644 index f48668b4..00000000 --- a/42sh/src/line-editing/readline.c +++ /dev/null @@ -1,99 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* readline.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/02/02 18:03:23 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_init_line(void) -{ - data_singleton()->line.input = NULL; - data_singleton()->line.copy_tmp = NULL; - data_singleton()->line.pos = 0; - data_singleton()->line.prompt_size = 0; - data_singleton()->line.list_size = 0; - data_singleton()->line.list_end = NULL; - data_singleton()->line.list_beg = NULL; - data_singleton()->line.opt = 0; -} - -void ft_init_history(void) -{ - int fd; - char *str; - - fd = open(".42sh_history", O_RDONLY); - if (fd == -1) - return ; - while (get_next_line(fd, &str) > 0) - { - ft_push_back_history(&data_singleton()->line.list_beg, - ft_create_history_list(str)); - free(str); - } - free(str); - close(fd); -} - -struct termios *ft_save_stats_term(void) -{ - static struct termios *term_save = NULL; - - if (!term_save) - { - term_save = (struct termios *)malloc(sizeof(struct termios)); - tcgetattr(0, term_save); - } - return (term_save); -} - -struct termios *ft_stats_term_termcaps(void) -{ - static struct termios *term = NULL; - - if (!term) - { - ft_init_line(); - ft_init_history(); - term = (struct termios *)malloc(sizeof(struct termios)); - tcgetattr(0, term); - (*term).c_lflag &= ~(ECHO | ICANON | ISIG); - (*term).c_cc[VMIN] = 1; - (*term).c_cc[VTIME] = 0; - } - return (term); -} - -int ft_readline(void) -{ - ft_save_stats_term(); - if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1) - return (-1); - if (data_singleton()->line.input) - ft_strdel(&data_singleton()->line.input); - data_singleton()->line.list_cur = data_singleton()->line.list_beg; - data_singleton()->line.pos = 0; - ft_prompt(); - data_singleton()->line.input = ft_read_stdin(); - ft_putchar('\n'); - ft_check_quotes(&data_singleton()->line.input); - ft_check_heredoc(&data_singleton()->line.input); - ft_check_backslash(&data_singleton()->line.input); - ft_history_parsing(); - if (data_singleton()->line.input) - { - ft_push_back_history(&data_singleton()->line.list_beg, - ft_create_history_list(data_singleton()->line.input)); - ft_add_in_history_file(data_singleton()->line.input); - } - if (tcsetattr(0, TCSANOW, ft_save_stats_term()) == -1) - return (-1); - return (0); -} diff --git a/42sh/src/line-editing/surch_in_history.c b/42sh/src/line-editing/surch_in_history.c deleted file mode 100644 index 424dc5d2..00000000 --- a/42sh/src/line-editing/surch_in_history.c +++ /dev/null @@ -1,87 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* surch_in_history.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/02/02 15:16:42 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_clear_prompt(char *str, size_t *pos, size_t srch_pos) -{ - if (str) - ft_get_beggin_with_curs(str, pos); - else if (*pos) - { - ft_putnc('\b', *pos); - (*pos) = 0; - } - ft_putnc('\b', data_singleton()->line.prompt_size + srch_pos + 1); - ft_puttermcaps("cd"); -} - -void ft_surch_and_realloc(char **str, char **str_srch, int ret, size_t *srch_pos) -{ - *str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos); - ++(*srch_pos); - *str = ft_strget_history(*str_srch); -} - -void ft_surch_in_history(void) -{ - char *str_srch; - int ret; - size_t srch_pos; - char **str; - size_t *pos; - - str = &data_singleton()->line.input; - pos = &data_singleton()->line.pos; - srch_pos = 0; - str_srch = NULL; - if (*str) - ft_strdel(str); - while (42) - { - ft_clear_prompt(*str, pos, srch_pos); - data_singleton()->line.prompt_size = 21; - if (str_srch) - ft_printf("\033[35m(reverse-i-search)`\033[32m%s\033[35m': \033[37m", str_srch); - else - ft_putstr("\033[35m(reverse-i-search)`': \033[37m"); - if (*str) - { - ft_current_str(*str, *pos); - ft_get_next_str(*str, pos); - } - ret = 0; - read(0, &ret, sizeof(int)); - if (ft_isprint(ret)) - ft_surch_and_realloc(str, &str_srch, ret, &srch_pos); - else if (ret == 127) - { - if (srch_pos) - { - --srch_pos; - str_srch = ft_remove_imput(str_srch, srch_pos); - ft_puttermcaps("le"); - } - } - else - break ; - } - ft_clear_prompt(*str, pos, srch_pos); - ft_prompt(); - if (*str) - { - *str = ft_strdup(*str); - ft_current_str(*str, *pos); - ft_get_next_str(*str, pos); - } - free(str_srch); -} diff --git a/42sh/src/line-editing/tool_line.c b/42sh/src/line-editing/tool_line.c deleted file mode 100644 index 0745579b..00000000 --- a/42sh/src/line-editing/tool_line.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* tool_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/20 18:20:23 by gwojda #+# #+# */ -/* Updated: 2017/02/01 15:27:31 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_get_beggin(char *str, size_t *pos) -{ - while ((*pos) && str[(*pos)] != '\n') - --(*pos); - if (*pos && str[(*pos)] == '\n') - ++(*pos); -} - -void ft_get_next_str(char *str, size_t *pos) -{ - while (str[(*pos)] && str[(*pos)] != '\n') - ++(*pos); - if (*pos && str[(*pos)] == '\n') - --(*pos); -} - -void ft_putall_current_str(char *str, size_t *pos) -{ - int len; - - len = 0; - ft_get_beggin(str, pos); - while (str[(*pos) + len] && str[(*pos) + len] != '\n') - ++len; - write(1, str + *pos, len); -} - -void ft_current_str(char *str, size_t pos) -{ - int len; - - len = 0; - while (str[pos + len] && str[pos + len] != '\n') - ++len; - write(1, str + pos, len); - ft_check_end_of_line(str, pos + len); -} - -int ft_strlen_next(char *str, size_t pos) -{ - int len; - - len = 0; - while (str[pos + len] && str[pos + len] != '\n') - ++len; - return (len); -} diff --git a/42sh/src/line-editing/tool_line_2.c b/42sh/src/line-editing/tool_line_2.c deleted file mode 100644 index c5c9dd8e..00000000 --- a/42sh/src/line-editing/tool_line_2.c +++ /dev/null @@ -1,94 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* tool_line_2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */ -/* Updated: 2017/02/02 14:16:24 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -static void ft_clear_window() -{ - pid_t soon_pid; - char *tab_str[2] = {(char *){"/usr/bin/clear"}, NULL}; - - soon_pid = fork(); - if (soon_pid != 0) - wait(NULL); - else - execve("/usr/bin/clear", tab_str, data_singleton()->env); -} - -void ft_printall(void) -{ - size_t pos_tmp; - int ret; - char *str; - size_t *pos; - - str = data_singleton()->line.input; - pos = &data_singleton()->line.pos; - ret = 0; - if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str) - return ; - ft_clear_window(); - ft_prompt(); - pos_tmp = *pos; - ft_putstr("\033[31m"); - ft_puttermcaps("cd"); - ft_puttermcaps("sc"); - ft_putstr(str); - while (42) - { - ret = 0; - read(0, &ret, sizeof(int)); - if (ret == TOUCHE_F6) - { - ret = 0; - if (read(0, &ret, sizeof(int)) && ret == 126) - break ; - } - } - ft_puttermcaps("rc"); - ft_puttermcaps("cd"); - ft_putstr("\033[37m"); - if (*pos) - --(*pos); - ft_get_beggin(str, pos); - ft_current_str(str, *pos); - ft_get_next_str(str, pos); - if (*pos && !str[*pos]) - --(*pos); - if (*pos) - ft_putnc('\b', *pos - pos_tmp + 1); - *pos = pos_tmp; -} - -void ft_check_end_of_line(char *str, size_t pos) -{ - if (!str) - return ; - if (ft_nb_last_line(str, pos) == 0) - { - ft_putchar(' '); - ft_puttermcaps("le"); - } -} - -void ft_get_beggin_with_curs(char *str, size_t *pos) -{ - while ((*pos) && str[(*pos)] != '\n') - { - --(*pos); - ft_puttermcaps("le"); - } - if (!*pos && str[(*pos)] != '\n') - ft_puttermcaps("le"); - if (str[(*pos)] == '\n') - ++(*pos); -} diff --git a/42sh/src/line-editing/toolz.c b/42sh/src/line-editing/toolz.c deleted file mode 100644 index 1051442e..00000000 --- a/42sh/src/line-editing/toolz.c +++ /dev/null @@ -1,66 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toolz.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:22:47 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_putnc(char c, int n) -{ - int i; - - i = 0; - while (i < n) - { - write(1, &c, 1); - ++i; - } -} - -char *ft_strndup(char const *s, int n) -{ - int i; - char *str; - - i = 0; - str = (char *)malloc(sizeof(char) * (n + 1)); - if (str) - { - while (i < n) - { - str[i] = s[i]; - i++; - } - str[i] = '\0'; - } - return (str); -} - -char *ft_strdupi(char const *s) -{ - int i; - char *str; - - i = 0; - while (s[i] && s[i] != ';' && s[i] != '>' && s[i] != '<' - && ft_strncmp(s + i, "||", 2)) - i++; - str = (char *)malloc(sizeof(char) * (i + 1)); - if (str) - { - str[i--] = '\0'; - while (i >= 0) - { - str[i] = s[i]; - i--; - } - } - return (str); -} diff --git a/42sh/src/line-editing/toolz2.c b/42sh/src/line-editing/toolz2.c deleted file mode 100644 index ce1c62f6..00000000 --- a/42sh/src/line-editing/toolz2.c +++ /dev/null @@ -1,67 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toolz2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */ -/* Updated: 2017/02/02 16:04:55 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void ft_add_in_history_file(char *str) -{ - int fd; - - fd = open(".42sh_history", O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR); - if (fd == -1) - return ; - write(fd, str, ft_strlen(str)); - write(fd, "\n", 1); - close(fd); -} - -int ft_nbr_len(int nbr) -{ - if (nbr % 10 != nbr) - return (ft_nbr_len(nbr / 10) + 1); - else - return (1); -} - -void ft_puttermcaps(char *str) -{ - char *res; - char *env; - - env = getenv("TERM"); - if ((res = tgetstr(str, &env)) == NULL) - return ; - tputs(res, 0, ft_put); -} - -int ft_size_term(void) -{ - struct winsize w; - - ioctl(0, TIOCGWINSZ, &w); - return (w.ws_col); -} - -long long ft_pow(int nbr, int power) -{ - int i; - long long ret; - - i = 0; - ret = 1; - while (i < power) - { - ret *= nbr; - i++; - } - return (ret); -} diff --git a/42sh/src/line-editing/toolz_parseur.c b/42sh/src/line-editing/toolz_parseur.c deleted file mode 100644 index a0781e12..00000000 --- a/42sh/src/line-editing/toolz_parseur.c +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toolz_parseur.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ -/* Updated: 2017/02/02 14:29:34 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -char *ft_realloc_imput(char *str, int a, size_t pos) -{ - int i; - char tmp[2]; - char *str_tmp; - char *new_str; - - i = 0; - tmp[0] = (char)a; - tmp[1] = '\0'; - if (!str) - { - new_str = ft_strdup(tmp); - return (new_str); - } - str_tmp = ft_strndup(str, pos); - new_str = ft_strjoin(str_tmp, tmp); - free(str_tmp); - str_tmp = ft_strjoin(new_str, str + pos); - free(new_str); - free(str); - return (str_tmp); -} - -char *ft_remove_imput(char *str, size_t pos) -{ - char *new_str; - char *new_str2; - - if (!str) - return (str); - new_str = ft_strndup(str, pos); - new_str2 = ft_strjoin(new_str, &str[pos + 1]); - free(str); - free(new_str); - return (new_str2); -} diff --git a/42sh/src/line-editing/toolz_termcaps.c b/42sh/src/line-editing/toolz_termcaps.c deleted file mode 100644 index 901b026e..00000000 --- a/42sh/src/line-editing/toolz_termcaps.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toolz_termcaps.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gwojda +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */ -/* Updated: 2017/01/24 11:19:34 by gwojda ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int ft_get_ind_prev(char *str, size_t pos) -{ - while (pos && str[pos] != '\n') - --pos; - return (pos); -} - -int ft_get_size_prev(char *str, size_t pos) -{ - size_t len; - - len = 0; - while (pos && str[pos] != '\n') - { - --pos; - ++len; - } - return (len); -} - -int ft_nb_last_line(char *str, size_t pos) -{ - int len; - - len = 1; - if (pos && str[pos] == '\n') - --pos; - len += data_singleton()->line.prompt_size; - len += ft_get_size_prev(str, pos); - return ((len) ? len % ft_size_term() : -1); -} diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index ed06bf53..bb4682cd 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:31:46 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:40:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,8 @@ int shell_single_command(char *command) if (ft_lexer(&token, &command) || !token) return (1); token_print(token); - if (ft_parse(&ast, &token)) - return (1); +// if (ft_parse(&ast, &token)) +// return (1); btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); @@ -49,8 +49,6 @@ int main(int ac, char **av) } while (1) { - if (ft_readline()) - return (1); if (shell_single_command(ft_strdup(data_singleton()->line.input)) < 0) return (1); } diff --git a/42sh/src/main/shell_get_ast.c b/42sh/src/main/shell_get_ast.c index 7005119a..36809962 100644 --- a/42sh/src/main/shell_get_ast.c +++ b/42sh/src/main/shell_get_ast.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 18:19:13 by ariard #+# #+# */ -/* Updated: 2017/01/30 23:14:32 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:29:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ t_list **shell_get_ast(char *command) return (NULL); if (!token) return (NULL); - if (ft_post_tokenize(&token, command)) + if (ft_post_tokenize(&token, &command)) return (NULL); DG("after post_tokenize"); token_print(token); diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 87b5fff4..6667c5de 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ -/* Updated: 2017/02/02 17:50:21 by ariard ### ########.fr */ +/* Updated: 2017/02/03 15:37:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,11 +23,7 @@ int shell_script() token = NULL; ast = NULL; list_ast = NULL; - if (ft_tokenize(&token, data_singleton()->script.buffer , DEFAULT)) - return (1); - if (!token) - return (0); - if (ft_post_tokenize(&token, data_singleton()->script.buffer)) + if (ft_lexer(&token, &data_singleton()->script.buffer) || !token) return (1); DG("after post_tokenize"); token_print(token); diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index 6f7126b3..951678d0 100644 --- a/42sh/src/parser/parse_word.c +++ b/42sh/src/parser/parse_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/02/03 14:30:10 by ariard ### ########.fr */ +/* Updated: 2017/02/03 14:52:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ int parse_word(t_list **list_ast, t_btree **ast, t_token *token; char **my_tab; + (void)list_ast; (void)start; my_tab = NULL; token = (*lst)->content; @@ -27,7 +28,7 @@ int parse_word(t_list **list_ast, t_btree **ast, my_tab = ft_sstradd(my_tab, token->data); my_tab = ft_sstradd(my_tab, (char *)token->esc); ft_ld_pushback(&node->data.token, my_tab); - ft_parse(ast, &(*lst)->next); +// ft_parse(ast, &(*lst)->next); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); return (0); }