-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
28 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/08 13:04:06 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/19 09:46:19 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/09 11:23:44 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -29,10 +29,13 @@ void get_args(void) | |
idx = ((t_token *)next->content)->str_idx; | ||
else | ||
idx = ft_strlen(g_glob->input); | ||
token->arg = ft_substr(g_glob->input, \ | ||
token->str_idx + ft_strlen(token->str), \ | ||
idx - token->str_idx - ft_strlen(token->str)); | ||
token->arg = ft_strtrimf(token->arg, " \t"); | ||
if (token->label != VARIABLE) | ||
{ | ||
token->arg = ft_substr(g_glob->input, \ | ||
token->str_idx + ft_strlen(token->str), \ | ||
idx - token->str_idx - ft_strlen(token->str)); | ||
token->arg = ft_strtrimf(token->arg, " \t"); | ||
} | ||
curr = curr->next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,30 +6,35 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/06 13:06:15 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/26 16:39:32 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/09 11:25:54 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft/includes/libft.h" | ||
#include "minishell.h" | ||
|
||
static void expand_bis(t_list *curr, t_token *var, char *env, char char_tmp) | ||
static void expand_bis(t_list *curr, t_token *var, char *env, char *tmp) | ||
{ | ||
if (char_tmp != '?') | ||
if (tmp[0] != '?') | ||
{ | ||
if (curr && env) | ||
var->arg = ft_strdup(ft_strchr(env, '=') + 1); | ||
else | ||
var->arg = ft_strdup(""); | ||
{ | ||
if (ft_strlen(tmp) == 1) | ||
var->arg = ft_strdup("$"); | ||
else | ||
var->arg = ft_strdup(""); | ||
} | ||
} | ||
else | ||
var->arg = ft_strjoinf(ft_itoa(g_glob->exit_ret), \ | ||
var->not_expanded + 1); | ||
free(tmp); | ||
} | ||
|
||
void expand(t_token *var) | ||
{ | ||
char char_tmp; | ||
char *tmp; | ||
char *env; | ||
t_list *curr; | ||
|
@@ -44,17 +49,15 @@ void expand(t_token *var) | |
if (curr) | ||
env = (char *)curr->content; | ||
} | ||
char_tmp = var->arg[0]; | ||
free(tmp); | ||
free(var->arg); | ||
expand_bis(curr, var, env, char_tmp); | ||
expand_bis(curr, var, env, tmp); | ||
} | ||
|
||
static bool str_is_op(char *needle) | ||
{ | ||
int i; | ||
static const char *op_tab[13] = {"<<", ">>", "|", \ | ||
">", "<", "$", " ", "\"", "'", "/", "\t", NULL}; | ||
">", "<", " ", "$", "\"", "'", "/", "\t", NULL}; | ||
|
||
i = 0; | ||
while (op_tab[i]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/11/27 19:39:54 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/20 13:18:54 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/09 11:25:09 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -96,9 +96,13 @@ void get_ops(const char *input, t_list **head) | |
double_q = !double_q; | ||
else if (input[i] == '\'' && !double_q) | ||
single_q = !single_q; | ||
// if (input[i] == '$' && input[i + 1] == '$') | ||
// while (input[i + 1] == '$') | ||
// i++; | ||
else if (input[i] == '$' && !ft_isprint_nospace_nodollar(input[i + 1])) | ||
i++; | ||
if (input[i] && (!single_q && !double_q) || (input[i] == '$' && double_q)) | ||
if (input[i] && ((!single_q && !double_q) \ | ||
|| (input[i] == '$' && double_q))) | ||
i += add_ops(input, head, i); | ||
i++; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/01 11:49:37 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/05 14:48:20 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/09 11:05:43 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/13 13:16:51 by zhabri #+# #+# */ | ||
/* Updated: 2022/12/22 12:56:40 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/09 11:17:04 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|