mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
subst/variable: remove special handling of positional variables
Including only half support does not make sense, it could cause more problems than it solves.
This commit is contained in:
parent
d53e40d3f4
commit
49a897b44e
2 changed files with 11 additions and 13 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/19 17:28:29 by khais #+# #+# */
|
/* Created: 2025/03/19 17:28:29 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/16 17:45:36 by khais ### ########.fr */
|
/* Updated: 2025/04/16 18:03:52 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,11 +20,7 @@
|
||||||
** word: the worddesc to be modified
|
** word: the worddesc to be modified
|
||||||
** i: the index at which the $ marking the start of expansion is located
|
** i: the index at which the $ marking the start of expansion is located
|
||||||
** id_len: the length of the string that constitutes a valid bash
|
** id_len: the length of the string that constitutes a valid bash
|
||||||
** identifier (it is to be noted that it can be zero and yet still
|
** identifier
|
||||||
** conduct to a replacement of more that just $ if $ is immediately
|
|
||||||
** followed by a digit -- this cans be modified as it is not strictly
|
|
||||||
** required to consider positionnal arguments at all or indeed treat
|
|
||||||
** them as holding no value)
|
|
||||||
** rep: a malloc-allocated string previously calculated to correspond to
|
** rep: a malloc-allocated string previously calculated to correspond to
|
||||||
** the actual value to set as the expansion
|
** the actual value to set as the expansion
|
||||||
** This function exists to actually modify the worddesc word by modifying the
|
** This function exists to actually modify the worddesc word by modifying the
|
||||||
|
|
@ -53,11 +49,9 @@ static t_worddesc *word_update(t_worddesc *word, size_t i, size_t id_len,
|
||||||
{
|
{
|
||||||
char *new_word;
|
char *new_word;
|
||||||
size_t rep_len;
|
size_t rep_len;
|
||||||
size_t digit;
|
|
||||||
|
|
||||||
digit = ft_isdigit(word->word[i + 1]);
|
|
||||||
rep_len = ft_strlen(rep);
|
rep_len = ft_strlen(rep);
|
||||||
new_word = replace_in_str(word->word, i, i + id_len + digit, rep);
|
new_word = replace_in_str(word->word, i, i + id_len, rep);
|
||||||
free(rep);
|
free(rep);
|
||||||
free(word->word);
|
free(word->word);
|
||||||
word->word = new_word;
|
word->word = new_word;
|
||||||
|
|
@ -67,7 +61,7 @@ static t_worddesc *word_update(t_worddesc *word, size_t i, size_t id_len,
|
||||||
rep = construct_repeting_char_string('$', rep_len);
|
rep = construct_repeting_char_string('$', rep_len);
|
||||||
if (!rep)
|
if (!rep)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
new_word = replace_in_str(word->marker, i, i + id_len + digit, rep);
|
new_word = replace_in_str(word->marker, i, i + id_len, rep);
|
||||||
free(rep);
|
free(rep);
|
||||||
if (!new_word)
|
if (!new_word)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
@ -118,9 +112,6 @@ static char *calculate_replacement(t_worddesc *word, t_minishell *app, size_t i,
|
||||||
** identifier with the corresponding value if present in env, the return value
|
** identifier with the corresponding value if present in env, the return value
|
||||||
** of the last foreground executed pipeline in the case of $? or nothing if
|
** of the last foreground executed pipeline in the case of $? or nothing if
|
||||||
** the corresponding identifier does not have an entry in env.
|
** the corresponding identifier does not have an entry in env.
|
||||||
** Additionnally if the first character following is a digit both the '$'
|
|
||||||
** and digit are removed even though we do not deal with those type of bash
|
|
||||||
** parameters (we consider them to never hold a value).
|
|
||||||
** Similarly if the character following the '$' is neither '_' or
|
** Similarly if the character following the '$' is neither '_' or
|
||||||
** alphanumerical the dollar is removed except for the appearance of a '\0'
|
** alphanumerical the dollar is removed except for the appearance of a '\0'
|
||||||
** signaling the end of the word.
|
** signaling the end of the word.
|
||||||
|
|
|
||||||
7
test.sh
7
test.sh
|
|
@ -674,4 +674,11 @@ expecting <<EOF
|
||||||
$ $
|
$ $
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "handling of positional arguments"
|
||||||
|
echo \$9HOME
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
\$9HOME
|
||||||
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue