diff --git a/Filelist.sh.mk b/Filelist.sh.mk index 9b920b0b..91b48ec4 100644 --- a/Filelist.sh.mk +++ b/Filelist.sh.mk @@ -1,8 +1,8 @@ SRC_FILES = \ -env \ _env_norm_helper \ -ft_exit \ _helper_main \ +env \ +ft_exit \ main \ signal_handler \ diff --git a/allocator/Filelist.aq.mk b/allocator/Filelist.aq.mk index 63698d77..ead60e1c 100644 --- a/allocator/Filelist.aq.mk +++ b/allocator/Filelist.aq.mk @@ -9,11 +9,11 @@ me_alloc/merge_blocks \ me_alloc/pages \ me_alloc/realloc \ vg/dummy_block \ +vg/dummy_mem_status \ vg/dummy_mempool \ vg/dummy_mempool_bis \ -vg/dummy_mem_status \ vg/valgrind_block \ +vg/valgrind_mem_status \ vg/valgrind_mempool \ vg/valgrind_mempool_bis \ -vg/valgrind_mem_status \ diff --git a/exec/Filelist.exec.mk b/exec/Filelist.exec.mk index 57752618..959253b5 100644 --- a/exec/Filelist.exec.mk +++ b/exec/Filelist.exec.mk @@ -1,41 +1,40 @@ SRC_FILES = \ -builtins/cd \ +_read_dir \ builtins/_debug \ +builtins/cd \ builtins/echo \ builtins/env \ builtins/exit \ builtins/export \ builtins/pwd \ builtins/unset \ -_read_dir \ -run_arithmetic/arithmetic \ -run_arithmetic/arithmetic_operation \ run_arithmetic/_get_op \ -run_arithmetic/operator_bis \ run_arithmetic/_run_arith \ run_arithmetic/_to_ast_node \ +run_arithmetic/arithmetic \ +run_arithmetic/arithmetic_operation \ +run_arithmetic/operator_bis \ run_ast/_ast_into_str \ run_ast/_ast_into_str2 \ run_ast/_ast_into_str3 \ run_ast/_ast_into_str4 \ run_ast/_ast_into_str5 \ -run_ast/_ast_into_str6 \ run_ast/_get_pid \ +run_ast/_run_exit_code \ +run_ast/_run_exp_operators \ +run_ast/_spawn_cmd \ +run_ast/_spawn_cmd_redir_fd \ +run_ast/_spawn_cmd_redir_heredoc \ run_ast/run_builtins \ run_ast/run_builtins2 \ run_ast/run_cmd_sub \ run_ast/run_command \ -run_ast/_run_exit_code \ run_ast/run_expansion \ run_ast/run_expansion_builtin \ -run_ast/_run_exp_operators \ run_ast/run_list \ run_ast/run_pipeline \ run_ast/run_pipeline_helper \ run_ast/run_program \ run_ast/run_subshell \ run_ast/run_words \ -run_ast/_spawn_cmd \ -run_ast/_spawn_cmd_redir_fd \ -run_ast/_spawn_cmd_redir_heredoc \ diff --git a/exec/src/builtins/exit.c b/exec/src/builtins/exit.c index c748a95c..8b167eb0 100644 --- a/exec/src/builtins/exit.c +++ b/exec/src/builtins/exit.c @@ -6,13 +6,14 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:51:18 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:24:19 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "exec/builtins.h" #include "me/convert/str_to_numbers.h" #include "me/types.h" +#include "me/printf/printf.h" t_error builtin_exit__(\ t_state *state, t_builtin_spawn_info info, t_i32 *exit_code) @@ -23,8 +24,10 @@ t_error builtin_exit__(\ if (info.args.len < 2) actual_exit_code = 0; else if (str_to_i32(info.args.buffer[1], 10, &actual_exit_code)) - return (\ - printf("info.args.buffer[1] = %s\n", info.args.buffer[1]), ERROR); + { + me_printf_fd(info.stderr, "Error: invalid argument: not a number\n"); + me_exit(2); + } *exit_code = actual_exit_code; me_exit(actual_exit_code); return (NO_ERROR); diff --git a/exec/src/builtins/export.c b/exec/src/builtins/export.c index 9ff539fd..3bd5c218 100644 --- a/exec/src/builtins/export.c +++ b/exec/src/builtins/export.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */ -/* Updated: 2024/10/12 17:51:18 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:24:39 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,7 @@ static void _assign_export(t_usize idx, t_str *arg, void *vctx) ctx = vctx; first_eq = str_find_chr(*arg, '='); if (first_eq == NULL || first_eq == *arg) - return ; + hmap_env_insert(ctx->state->env, *arg, NULL); key = str_substring(*arg, 0, first_eq - *arg); value = str_substring(first_eq, 1, ~0llu); if (hmap_env_insert(ctx->state->env, key, value)) diff --git a/exec/src/builtins/pwd.c b/exec/src/builtins/pwd.c index 1b21225b..c48557bf 100644 --- a/exec/src/builtins/pwd.c +++ b/exec/src/builtins/pwd.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/07 13:58:37 by rparodi #+# #+# */ -/* Updated: 2024/10/12 17:51:19 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:22:56 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ t_error builtin_pwd___(\ string_reserve(&s, s.capacity * 3); else return (*exit_code = 1, string_free(s), me_printf_fd(\ - info.stderr, "cd: Unable to get current directory\n"), NO_ERROR); + info.stderr, "pwd: Unable to get current directory\n"), NO_ERROR); } me_printf_fd(info.stdout, "%s\n", s.buf); string_free(s); diff --git a/exec/src/run_ast/_ast_into_str.c b/exec/src/run_ast/_ast_into_str.c index 18dc9944..73055a4b 100644 --- a/exec/src/run_ast/_ast_into_str.c +++ b/exec/src/run_ast/_ast_into_str.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:51:23 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:30:06 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,7 @@ t_error _word_no_quote(t_state *state, t_word_result *res, t_vec_str *append) return (NO_ERROR); } -t_error _word_do_quote(t_state *state, t_word_result *res, t_vec_str *append) +t_error _word_pass_quote(t_state *state, t_word_result *res, t_vec_str *append) { t_string tmp; t_usize i; @@ -66,12 +66,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append) return (_word_handle_star(&self->data.word, state, append)); if (run_word(&self->data.word, state, &res)) return (ERROR); - if (res.kind == AST_WORD_NO_QUOTE) - { - if (_word_no_quote(state, &res, append)) - return (ERROR); - } - else if (_word_do_quote(state, &res, append)) + if (_word_pass_quote(state, &res, append)) return (ERROR); return (vec_estr_free(res.value), NO_ERROR); } diff --git a/exec/src/run_ast/_ast_into_str6.c b/exec/src/run_ast/_ast_into_str6.c deleted file mode 100644 index 82b262ea..00000000 --- a/exec/src/run_ast/_ast_into_str6.c +++ /dev/null @@ -1,87 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* _ast_into_str6.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:51:22 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "exec/_run_ast.h" -#include "me/string/string.h" -#include "me/str/str.h" -#include "me/convert/numbers_to_str.h" -#include "me/vec/vec_str.h" - -bool _word_is_star(t_ast_word *word); -t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out); -t_error list_files_in_current_directory(t_vec_str *out); - -t_error _word_into_str_inner3(struct s_word_str_args args) -{ - t_usize j; - t_usize len; - - j = 0; - while (j + 1 < args.splitted->len) - { - if (vec_str_pop_front(args.splitted, args.tmp_str)) - return (vec_estr_free(args.res->value), ERROR); - vec_str_push(args.append, *args.tmp_str); - j++; - } - len = str_len(args.res->value.buffer[args.i].value); - if (len != 0 && str_find_chr(args.ifs, - args.res->value.buffer[args.i].value[len - 1]) == NULL) - (string_push(args.tmp, *args.tmp_str), str_free(*args.tmp_str)); - else - vec_str_push(args.append, *args.tmp_str); - return (NO_ERROR); -} - -t_error _word_into_str_inner2(struct s_word_str_args args) -{ - t_str ifs; - t_str tmp_str; - t_vec_str splitted; - - ifs = _get_ifs_value(args.state); - if (str_split(args.res->value.buffer[args.i].value, ifs, &splitted)) - return (vec_estr_free(args.res->value), ERROR); - if (!vec_str_pop_front(&splitted, &tmp_str)) - { - if (str_find_chr(ifs, - args.res->value.buffer[args.i].value[0]) == NULL) - (string_push(args.tmp, tmp_str), str_free(tmp_str)); - else - { - vec_str_push(args.append, args.tmp->buf); - *args.tmp = string_new(64); - string_push(args.tmp, tmp_str); - str_free(tmp_str); - } - if (_word_into_str_inner3((struct s_word_str_args){args.i, args.state, \ - args.tmp, args.res, args.append, &tmp_str, &splitted, ifs})) - return (ERROR); - } - return (NO_ERROR); -} - -t_error _word_into_str_inner(struct s_word_str_args args) -{ - t_str ifs; - - ifs = _get_ifs_value(args.state); - while (ifs != NULL && *ifs != '\0' - && str_find_chr(args.res->value.buffer[args.i].value, *ifs) == NULL) - ifs++; - if (ifs == NULL || *ifs == '\0') - string_push(args.tmp, args.res->value.buffer[args.i].value); - else if (_word_into_str_inner2((struct s_word_str_args){args.i, \ - args.state, args.tmp, args.res, args.append, NULL, NULL, NULL})) - return (ERROR); - return (NO_ERROR); -} diff --git a/exec/src/run_ast/_spawn_cmd.c b/exec/src/run_ast/_spawn_cmd.c index c81f6421..bb35d4e5 100644 --- a/exec/src/run_ast/_spawn_cmd.c +++ b/exec/src/run_ast/_spawn_cmd.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:51:27 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:32:14 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ #include #include "line/line.h" #include "me/types.h" +#include t_error _redirection_fd(\ t_spawn_info *info, t_state *state, t_ast_node red); @@ -70,12 +71,12 @@ t_error _spawn_cmd_and_run_end(\ return (close_fd(cmd_pipe.input), out->exit = 127, ERROR); if (cmd_pipe.create_output || cmd_pipe.input != NULL) return (out->exit = -1, NO_ERROR); - if (waitpid(out->process.pid, &status, 0) == -1) + if (waitpid(out->process.pid, &status, 0) == -1 && errno != ESRCH) return (ERROR); if (WIFEXITED(status)) out->exit = WEXITSTATUS(status); if (WIFSIGNALED(status)) - out->exit = WTERMSIG(status); + out->exit = WTERMSIG(status) + 128; state->last_exit = out->exit; return (NO_ERROR); } @@ -86,6 +87,8 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_redirections redirs, t_spawn_info info; info = (t_spawn_info){}; + for (t_usize i = 0; i < args.len; i++) + printf("args[%zu] = %s\n", i, args.buffer[i]); if (_setup_redirection(&info, state, redirs.cmd_pipe, &redirs.redirections)) return (ERROR); redirs.redirections.len = 0; diff --git a/exec/src/run_ast/run_subshell.c b/exec/src/run_ast/run_subshell.c index c6ab0301..9f8c1498 100644 --- a/exec/src/run_ast/run_subshell.c +++ b/exec/src/run_ast/run_subshell.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:35:02 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:51:27 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:24:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "me/mem/mem.h" #include "me/os/os.h" #include +#include t_error _spawn_info_to_subshell(\ t_spawn_info *info, struct s_subshell_info *sinfo) @@ -75,13 +76,12 @@ t_error _wait_subshell(\ (dup2(sinfo.stderr->fd, 2), close_fd(sinfo.stderr)); if (cmd_pipe.create_output || cmd_pipe.input != NULL) return (out->stdout = sinfo.ret_stdout, NO_ERROR); - if (waitpid(forked, &status, 0) == -1) + if (waitpid(forked, &status, 0) == -1 && errno != ESRCH) return (ERROR); if (WIFEXITED(status)) out->exit = WEXITSTATUS(status); if (WIFSIGNALED(status)) - out->exit = WTERMSIG(status); - printf("out->exit for subshell is %i\n", out->exit); + out->exit = WTERMSIG(status) + 130; sinfo.state->last_exit = out->exit; return (NO_ERROR); } diff --git a/line/Filelist.line.mk b/line/Filelist.line.mk index 2c93bfb5..4d84cc2e 100644 --- a/line/Filelist.line.mk +++ b/line/Filelist.line.mk @@ -2,11 +2,11 @@ SRC_FILES = \ line \ line_edit_actions \ line_edit_actions2 \ -line_editing \ -line_editing2 \ line_edit_mode \ line_edit_mode_interal \ line_edit_mode_specific_key \ +line_editing \ +line_editing2 \ line_globals \ line_history \ line_internals \ diff --git a/parser/Filelist.parser.mk b/parser/Filelist.parser.mk index 6509fd1c..2ff18ebf 100644 --- a/parser/Filelist.parser.mk +++ b/parser/Filelist.parser.mk @@ -14,11 +14,11 @@ passes/paren_to_nquote \ passes/remove_whitespace \ passes/split_double_paren \ passes/verify_invalid_tokens \ -tokenizer \ -tokenizer_utils \ token_lifetime \ token_name \ token_utils \ +tokenizer \ +tokenizer_utils \ ts_print \ yard/yard \ yard/yard_cmd \ diff --git a/stdme/Filelist.me.mk b/stdme/Filelist.me.mk index 5b83a1f7..b7582c81 100644 --- a/stdme/Filelist.me.mk +++ b/stdme/Filelist.me.mk @@ -18,10 +18,10 @@ fs/fs_internal \ fs/getters \ fs/putfd \ gnl/get_next_line \ -hash/hasher \ hash/hash_signed \ hash/hash_str \ hash/hash_unsigned \ +hash/hasher \ hash/sip/sip13 \ hash/sip/sip_utils \ hash/sip/sip_utils2 \ @@ -69,10 +69,6 @@ printf/printf \ printf/printf_fd \ printf/printf_str \ printf/vprintf \ -string/mod \ -string/string_insert \ -string/string_remove \ -string/string_reserve \ str/str_clone \ str/str_compare \ str/str_find_chr \ @@ -89,6 +85,10 @@ str/str_n_find_str \ str/str_split \ str/str_substring \ str/str_trim \ +string/mod \ +string/string_insert \ +string/string_remove \ +string/string_reserve \ GEN_FILES = \ convert/i16_to_str \ diff --git a/stdme/src/printf/callbacks.c b/stdme/src/printf/callbacks.c index a93e871f..bf55c463 100644 --- a/stdme/src/printf/callbacks.c +++ b/stdme/src/printf/callbacks.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/07 18:01:52 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:52:39 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:35:46 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "me/printf/_internal_printf.h" #include "me/string/string.h" #include "me/types.h" +#include void me_printf_append_string(t_const_str to_write, t_usize to_write_len, void *p_args) @@ -31,6 +32,6 @@ void me_printf_write(t_const_str to_write, \ t_fprintf_arg *arg; arg = (t_fprintf_arg *)p_args; - write_fd(arg->fd, (t_u8 *)to_write, to_write_len, NULL); + (write_fd(arg->fd, (t_u8 *)to_write, to_write_len, NULL)); arg->total_print += to_write_len; } diff --git a/stdme/src/printf/printf_fd.c b/stdme/src/printf/printf_fd.c index 282bf334..5fadae9e 100644 --- a/stdme/src/printf/printf_fd.c +++ b/stdme/src/printf/printf_fd.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/05 19:55:09 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:52:43 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:42:02 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,13 +18,18 @@ t_usize me_vprintf_fd(t_fd *fd, t_const_str fmt, va_list *args) { - t_fprintf_arg passthru; + t_sprintf_arg passthru; + t_string buf; if (fd == NULL || fmt == NULL || args == NULL) return (0); - passthru.fd = fd; + buf = string_new(16); + passthru.buffer = &buf; passthru.total_print = 0; - me_printf_str_inner(fmt, &me_printf_write, args, (void *)&passthru); + me_printf_str_inner(fmt, &me_printf_append_string, args, (void *)&passthru); + if (write_fd(fd, (void *)buf.buf, buf.len, NULL)) + perror("write"); + string_free(buf); return (passthru.total_print); } diff --git a/stdme/src/printf/vprintf.c b/stdme/src/printf/vprintf.c index 400c8c56..3dbcbec7 100644 --- a/stdme/src/printf/vprintf.c +++ b/stdme/src/printf/vprintf.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 14:57:28 by maiboyer #+# #+# */ -/* Updated: 2024/10/12 17:52:44 by rparodi ### ########.fr */ +/* Updated: 2024/10/13 17:41:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */