Skip to content

Commit

Permalink
$ fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zakissimo committed Jan 9, 2023
1 parent 6ee1f67 commit 217f0e6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
13 changes: 8 additions & 5 deletions arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand All @@ -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;
}
}
21 changes: 12 additions & 9 deletions dollar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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])
Expand Down
8 changes: 6 additions & 2 deletions find_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion utils_bis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit 217f0e6

Please sign in to comment.