diff --git a/exec/src/run_ast.c b/exec/src/run_ast.c index 36a76a12..ef5dd6a0 100644 --- a/exec/src/run_ast.c +++ b/exec/src/run_ast.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */ -/* Updated: 2024/07/16 13:27:18 by maiboyer ### ########.fr */ +/* Updated: 2024/07/17 16:42:19 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,11 @@ struct s_expansion_result t_str str; }; +#ifdef ERROR +# undef ERROR +#endif +#define ERROR ((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1) + #define NOT_DONE \ { \ printf("function `%s` isn't done !\n", __func__); \ @@ -61,9 +66,9 @@ t_error _run_expansion_special_var(t_ast_expansion *self, t_state *state, t_expa name = self->var_name[0]; *out = (t_expansion_result){.exists = false, .str = NULL}; if (name == '*') - ; // return all args exept argv[0] - if (name == '@') ; // return all args with argv[0] + if (name == '@') + ; // return all args without argv[0] if (name == '?') ; // return exit code of last run program if (name == '!') @@ -95,7 +100,7 @@ t_error _get_expansion_value(t_ast_expansion *self, t_state *state, t_expansion_ return (NO_ERROR); } -#include "me/convert/itoa.h" +#include "me/convert/numbers_to_str.h" t_error _handle_len_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) { @@ -106,7 +111,8 @@ t_error _handle_len_operator(t_ast_expansion *self, t_state *state, t_expansion_ len = str_len(value->str); else len = 0; - len_str = me_itoa(len); + if (u64_to_str(len, &len_str)) + return (ERROR); mem_free(value->str); value->exists = true; value->str = len_str; @@ -186,8 +192,8 @@ t_error _handle_expansion_operator(t_ast_expansion *self, t_state *state, t_expa // End Internals funcs t_error run_expansion(t_ast_expansion *self, t_state *state, t_expansion_result *out); +t_error run_command(t_ast_command *command, t_state *state, void *out); -t_error run_command(t_ast_command *command, t_state *state, void *out) NOT_DONE; t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, void *out) NOT_DONE; t_error run_case_(t_ast_case *case_, t_state *state, void *out) NOT_DONE; t_error run_case_item(t_ast_case_item *case_item, t_state *state, void *out) NOT_DONE; @@ -236,6 +242,11 @@ t_error run_expansion(t_ast_expansion *self, t_state *state, t_expansion_result return (*out = ret, NO_ERROR); } +t_error run_command(t_ast_command *command, t_state *state, void *out) +{ + return (ERROR); +} + // FUNCTIONS /* diff --git a/stdme/include/me/convert/atoi.h b/stdme/include/me/convert/atoi.h deleted file mode 100644 index 1cce430c..00000000 --- a/stdme/include/me/convert/atoi.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* atoi.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */ -/* Updated: 2024/01/11 15:36:12 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ATOI_H -# define ATOI_H - -# include "me/types.h" - -t_i32 me_atoi(t_const_str str); -t_i64 me_atoi_64(t_const_str str); - -#endif diff --git a/stdme/include/me/convert/itoa.h b/stdme/include/me/convert/itoa.h deleted file mode 100644 index a4afbf67..00000000 --- a/stdme/include/me/convert/itoa.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* itoa.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:48:37 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ITOA_H -# define ITOA_H - -# include "me/types.h" - -t_str me_itoa(t_i32 nb); - -#endif diff --git a/stdme/src.list b/stdme/src.list index d6ee3636..f8010c57 100644 --- a/stdme/src.list +++ b/stdme/src.list @@ -25,8 +25,6 @@ char/isspace char/isupper char/tolower char/toupper -convert/atoi -convert/itoa convert/numbers_to_str fs/close fs/fs_internal diff --git a/stdme/src/convert/atoi.c b/stdme/src/convert/atoi.c deleted file mode 100644 index 32fc8319..00000000 --- a/stdme/src/convert/atoi.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */ -/* Updated: 2024/01/11 15:37:28 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/char/char.h" -#include "me/char/char.h" -#include "me/convert/atoi.h" - -t_i32 me_atoi(t_const_str str) -{ - t_u64 out; - t_u64 sign; - t_usize i; - - out = 0; - i = 0; - sign = 1; - while (me_isspace(str[i])) - i++; - if (str[i] == '+' || str[i] == '-') - if (str[i++] == '-') - sign = -1; - while (me_isdigit(str[i])) - { - out *= 10; - out += str[i] - '0'; - i++; - } - return ((t_i32)(out * sign)); -} - -t_i64 me_atoi_64(t_const_str str) -{ - t_u64 out; - t_u64 sign; - t_usize i; - - out = 0; - i = 0; - sign = 1; - while (me_isspace(str[i])) - i++; - if (str[i] == '+' || str[i] == '-') - if (str[i++] == '-') - sign = -1; - while (me_isdigit(str[i])) - { - out *= 10; - out += str[i] - '0'; - i++; - } - return ((t_i64)(out * sign)); -} diff --git a/stdme/src/convert/itoa.c b/stdme/src/convert/itoa.c deleted file mode 100644 index a3a4a3fc..00000000 --- a/stdme/src/convert/itoa.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */ -/* Updated: 2023/11/10 14:56:42 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "me/convert/itoa.h" -#include "me/mem/mem.h" -#include "me/str/str.h" -#include - -static void me_itoa_inner(t_u64 nb, t_str out) -{ - t_i32 modulus; - bool need_print; - char c; - t_usize idx; - - need_print = false; - modulus = 1000000000; - idx = 0; - while (modulus) - { - c = (char)(nb / modulus) + '0'; - if (c != '0' || need_print) - { - out[idx++] = c; - need_print = true; - } - nb = nb % modulus; - modulus /= 10; - } -} - -t_str me_itoa(t_i32 nb) -{ - char out[12]; - t_u64 n; - - n = (t_u64)nb; - mem_set(out, 0, 12); - if (nb < 0) - { - out[0] = '-'; - me_itoa_inner(-n, out + 1); - } - else if (nb == 0) - out[0] = '0'; - else - me_itoa_inner(n, out); - return (str_clone(out)); -} -/*R -int main(void) -{ - me_putnbr(-2147483648); - write(1, "\n", 1); - me_putnbr(0); - write(1, "\n", 1); - me_putnbr(12345); - return (0); -} -R*/ diff --git a/stdme/src/printf/formatter/utils.c b/stdme/src/printf/formatter/utils.c index 88417f0b..c7268157 100644 --- a/stdme/src/printf/formatter/utils.c +++ b/stdme/src/printf/formatter/utils.c @@ -6,12 +6,12 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */ -/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */ +/* Updated: 2024/07/17 15:38:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ +#include "me/convert/str_to_numbers.h" #include "me/mem/mem.h" -#include "me/convert/atoi.h" #include "me/printf/formatter/utils.h" #include "me/printf/matchers/matchers.h" #include "me/str/str.h" @@ -23,27 +23,28 @@ bool handle_atoi_stuff(t_const_str fmt, t_usize *c_idx, t_usize *nxt, t_printf_arg *c_arg) { - t_i32 atoi_res; - - atoi_res = me_atoi(&fmt[*c_idx]); - if (atoi_res < 0) + t_str str; + t_usize i; + + i = 0; + while (fmt[*c_idx + i] != '\0' && fmt[*c_idx + i] >= '0' && \ + fmt[*c_idx + i] <= '9') + i++; + str = str_substring(fmt, *c_idx, i); + if (str == NULL) { *c_idx = *nxt; *nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt); return (false); } - advance_atoi(fmt, c_idx); - c_arg->extra.align = (t_u64)atoi_res; - handle_prec_and_align(fmt, c_idx, c_arg); - atoi_res = atoi(&fmt[*c_idx]); - if (atoi_res < 0) + if (str_to_u64(str, 10, &c_arg->extra.precision)) { *c_idx = *nxt; *nxt = (t_usize)(str_find_chr(fmt + *nxt + 1, '%') - fmt); - return (false); + return (mem_free(str), false); } + mem_free(str); advance_atoi(fmt, c_idx); - c_arg->extra.precision = (t_u64)atoi_res; return (true); }