diff --git a/include/builtins.h b/include/builtins.h index b08a80f..dd75674 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -6,7 +6,7 @@ /* By: sede-san no_newline = (t_arg){ + .short_name = 'n', .long_name = NULL, + .data = {.b = false} + }; +} + +t_args read_args( + t_command cmd +){ + t_args args; + size_t i; + + assign_default_flags(&args); + i = 0; + assign_flags(&args, cmd, &i); + args.strings.data.sp = &cmd.argv[i]; + return (args); +} + +static void assign_flags( + t_args *args, + t_command cmd, + size_t *i +){ + while (cmd.argv[++(*i)] && ft_strchr(cmd.argv[*i], '-')) + { + if (!is_valid_flag(args, cmd.argv[*i])) + break ; + else + args->no_newline.data.b = true; + } +} + +static u_int8_t is_valid_flag( + t_args *args, + char *flag +){ + size_t i; + + if (!flag[1]) + return (0); + i = 0; + while (flag[++i]) + { + if (flag[i] != args->no_newline.short_name) + return (0); + } + return (1); +} diff --git a/src/builtins/echo/echo_def.h b/src/builtins/echo/echo_def.h new file mode 100644 index 0000000..818d725 --- /dev/null +++ b/src/builtins/echo/echo_def.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* echo_def.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: sede-san