From da27fbe414e09284215ffb6dd636de2e050a0aee Mon Sep 17 00:00:00 2001 From: tomoron Date: Sat, 17 Feb 2024 00:31:54 +0100 Subject: [PATCH] parsing ~ --- srcs/parsing.c | 21 +++++++++++++++++++-- srcs/parsing_var.c | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/srcs/parsing.c b/srcs/parsing.c index 457ea08..21fdc2e 100755 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/02/16 16:34:13 by tomoron ### ########.fr */ +/* Updated: 2024/02/17 00:29:12 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -16,6 +16,21 @@ int is_cmd_char(char c) return (!ft_isspace(c) && c != '|' && c != '&' && c != '<' && c != '>'); } +int add_home_to_str(char *res) +{ + int i; + char *str; + + i = 0; + str = getenv("HOME"); + while(str[i]) + { + res[i] = str[i]; + i++; + } + return(i); +} + char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) { char *res; @@ -33,9 +48,11 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) *in_quote = !*in_quote; if (**cmd == '$' && !*in_quote) { - (*cmd) += EXIT_FAILURE; + (*cmd)++; i += add_var_to_str(res + i, cmd, env); } + if(**cmd == '~' && !*in_quote && !*in_dquote) + i+= add_home_to_str(res + i); else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) || (**cmd != '\'' && **cmd != '"')) res[i++] = **cmd; diff --git a/srcs/parsing_var.c b/srcs/parsing_var.c index 175d0d9..d0f46d8 100755 --- a/srcs/parsing_var.c +++ b/srcs/parsing_var.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ -/* Updated: 2024/02/13 16:25:37 by marde-vr ### ########.fr */ +/* Updated: 2024/02/17 00:23:02 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,6 +58,8 @@ int get_token_len(char *command, t_env *env) in_quote = !in_quote; if (*command == '$' && !in_quote) res += get_var_len(&command, env); + if (*command == '~' && !in_quote && !in_dquote) + res += ft_strlen(getenv("HOME")); else if (*command != '\'' && *command != '"') res++; else if ((*command == '\'' && in_dquote)