Skip to content

Commit

Permalink
Merge pull request #137 from Haliris/dollar_string_fixes
Browse files Browse the repository at this point in the history
Dollar string fixes
  • Loading branch information
Haliris authored Jul 30, 2024
2 parents afc04f6 + 5f2edae commit fc8fb73
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 26 deletions.
4 changes: 3 additions & 1 deletion include/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 19:30:56 by bthomas #+# #+# */
/* Updated: 2024/07/29 10:24:37 by bthomas ### ########.fr */
/* Updated: 2024/07/30 13:21:30 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,6 +15,8 @@

# include "minishell.h"

# define DOLLAR_LITERAL ";:/,.~^=+-@*"

typedef struct s_data t_data;
typedef enum e_tokentype
{
Expand Down
11 changes: 7 additions & 4 deletions src/built_ins/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/12 20:32:33 by bthomas #+# #+# */
/* Updated: 2024/07/29 16:02:44 by bthomas ### ########.fr */
/* Updated: 2024/07/30 13:27:36 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -70,10 +70,13 @@ static char *get_export_val(t_data *data, char *key, char **cmd, int cmd_len)
i = 0;
while (ret[i])
{
if (invalid_path_char(ret[i]))
if (!is_space(ret[i]) && !ft_isalnum(ret[i]))
{
free(ret);
return (NULL);
if (!in(ret[i], DOLLAR_LITERAL))
{
free(ret);
return (NULL);
}
}
i++;
}
Expand Down
8 changes: 4 additions & 4 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: bthomas <bthomas@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/14 16:48:40 by bthomas #+# #+# */
/* Updated: 2024/07/28 17:11:22 by jteissie ### ########.fr */
/* Updated: 2024/07/30 12:55:52 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -87,15 +87,15 @@ int init(t_data *data, char **env)
data->errcode = EXIT_SUCCESS;
data->parsedata = ft_calloc(1, sizeof(t_parser));
if (!data->parsedata)
return (PANIC);
return (1);
data->parsedata->table = NULL;
data->parsedata->next = NULL;
data->heredata = NULL;
data->piddata = NULL;
data->prev_fd = STDIN_FILENO;
g_sig_offset = 0;
if (init_env(data, env))
return (PANIC);
return (1);
add_dummies(data);
return (0);
}
5 changes: 2 additions & 3 deletions src/lexer/lex_bools2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/20 12:36:56 by bthomas #+# #+# */
/* Updated: 2024/07/29 14:12:46 by bthomas ### ########.fr */
/* Updated: 2024/07/30 11:34:21 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -43,8 +43,7 @@ static bool space_before_last_equals(char *input, size_t idx)
{
while (input[idx] != '=')
idx--;
idx--;
if (is_space(input[idx - 1]))
if (is_space(input[idx - 1]) || is_space(input[idx + 1]))
return (true);
return (false);
}
Expand Down
5 changes: 4 additions & 1 deletion src/lexer/lex_concat_tks.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/28 16:23:45 by bthomas #+# #+# */
/* Updated: 2024/07/29 12:17:02 by bthomas ### ########.fr */
/* Updated: 2024/07/30 12:44:05 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,6 +65,9 @@ static void change_start_idx(t_data *data, t_token **token)
quote = 0;
while ((*token)->startidx > 1)
{
if (in(data->input[(*token)->startidx], "\'\"")
&& data->input[(*token)->startidx - 1] == '$')
(*token)->startidx -= 1;
if (in(data->input[(*token)->startidx - 1], "\'\""))
quote = data->input[(*token)->startidx - 1];
if (data->input[(*token)->startidx - 2] == quote)
Expand Down
4 changes: 2 additions & 2 deletions src/lexer/lex_expand_str_vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/19 10:41:19 by bthomas #+# #+# */
/* Updated: 2024/07/28 15:36:48 by bthomas ### ########.fr */
/* Updated: 2024/07/30 13:21:41 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,7 +20,7 @@ char *extract_key_from_str(char *str, size_t start)
return (ft_strdup("$"));
end = start + 1;
while (str[end] && (!is_delim(str[end], false)
&& !in(str[end], ";:/,.~^=")))
&& !in(str[end], DOLLAR_LITERAL)))
end++;
if (end == start + 1)
return (NULL);
Expand Down
11 changes: 8 additions & 3 deletions src/lexer/lex_retrieve_str_tk.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/25 10:40:12 by bthomas #+# #+# */
/* Updated: 2024/07/29 14:44:11 by bthomas ### ########.fr */
/* Updated: 2024/07/30 12:41:11 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

#include "lexer.h"

t_token *get_doll_str_tk(t_data *data, char *input, size_t *start_idx)
{
t_token *doll_tk;
char *outstr;

outstr = ft_substr(input, *start_idx, 2);
(*start_idx) += 2;
if (!outstr)
return (NULL);
return (get_token(data, outstr, NULL, TK_STRING));
doll_tk = get_token(data, outstr, NULL, TK_STRING);
if (!doll_tk)
return (NULL);
doll_tk->startidx = *start_idx;
(*start_idx) += 2;
return (doll_tk);
}

static size_t get_word_len(t_data *data, size_t startidx, bool echo_str)
Expand Down
10 changes: 5 additions & 5 deletions src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/28 17:48:06 by bento #+# #+# */
/* Updated: 2024/07/29 14:56:01 by bthomas ### ########.fr */
/* Updated: 2024/07/30 13:22:05 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,8 +33,8 @@ static void skip_invalid_chars(t_data *data, size_t input_len, size_t *i)
&& !in(input[(*i) + 1], "$?")
&& !is_space(input[(*i) + 1])
&& (!ft_isalpha(input[(*i) + 1])
&& !in(input[(*i) + 1], ":/,.~^=_")))
(*i) += 1 + (1 * (!in(input[(*i) + 1], "\"\'")));
&& !in(input[(*i) + 1], DOLLAR_LITERAL)))
(*i) += 1 + (1 * ft_isdigit(input[*i + 1]));
else
return ;
}
Expand All @@ -50,7 +50,7 @@ static t_token *build_tokenlist2(t_data *data, size_t *i)
else if (data->input[*i] == '=')
curr_tk = get_token(data, ft_strdup("="), NULL, TK_OPERATOR);
else if (data->input[*i] == '$' && data->input[(*i) + 1]
&& in(data->input[(*i) + 1], ":/,.~^="))
&& in(data->input[(*i) + 1], DOLLAR_LITERAL))
return (get_doll_str_tk(data, data->input, i));
else if (data->input[*i] == '$'
&& (!data->input[*i + 1] || is_space(data->input[*i + 1])))
Expand All @@ -74,7 +74,7 @@ static int build_tokenlist1(t_data *data, size_t input_len)
while (i < input_len)
{
if (is_invalid_export(data, i))
return (PANIC);
return (1);
skip_invalid_chars(data, input_len, &i);
if (i >= input_len)
break ;
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: bthomas <bthomas@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/25 13:43:42 by bthomas #+# #+# */
/* Updated: 2024/07/29 13:32:12 by bthomas ### ########.fr */
/* Updated: 2024/07/30 13:22:15 by bthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
34 changes: 33 additions & 1 deletion test_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,36 @@ cat < output.txt
echo "Appending to file" >> output.txt
cat output.txt
ls -la
pwd
pwd
echo $
echo $:
echo $:====
echo $HOME
echo $9HOME
echo $::":"$":"
echo ""'$HOME'
echo "$HOME"
echo $'WOW'
echo "$"awooga""
echo "$notreal" $HOME
echo "$notreal""wow"
echo $LESS$VAR
unset ++++++
expr $? + $?
ls | exit
echo '$notreal'
echo "":$::::????"$HOME"
echo "simple string with no worries"
echo simple string with no worries
echo $VAR:$:$VAR::$:
echo "$HOME$PATH:${UNSET:-default}"
echo '$HOME'"$HOME"'$HOME'
echo ::::???'''""$PATH""'''????::::
echo $HOME::::$USER::::$PATH
echo $VAR:$VAR::"$VAR"::$VAR
echo $1 $2 $3 $@ $*
echo ${#HOME} ${HOME#/} ${HOME%/}
echo $+
echo $-
echo $`
echo $~

0 comments on commit fc8fb73

Please sign in to comment.