/* By: lnikolov <lnikolov@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */
-/* Updated: 2024/08/29 18:24:21 by ljiriste ### ########.fr */
+/* Updated: 2024/08/30 14:18:21 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
static const char space = ' ';
-int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int quote)
+int add_word(t_vec *exp_str, const char *word, const t_execution_env *env, int enquote_result)
{
size_t i;
char *var;
char *value;
const char *const_val;
- int single_quoted;
+ char quote;
int error;
error = 0;
- single_quoted = 0;
+ quote = '\0';
i = 0;
while (word[i])
{
- if (word[i] == '\'')
- single_quoted = !single_quoted;
- if (word[i] == '$' && !single_quoted && (ft_isalnum(word[i + 1]) || word[i + 1] == '_' || word[i + 1] == '?'))
+ if (word[i] == '\'' && quote != '"')
+ quote = '\'' * !quote;
+ else if (word[i] == '"' && quote != '\'')
+ quote = '"' * !quote;
+ if (word[i] == '$' && quote != '\'' && (ft_isalnum(word[i + 1]) || word[i + 1] == '_' || word[i + 1] == '?'))
{
++i;
if (word[i] == '?')
}
if (!value)
return (1);
- if (quote)
+ if (enquote_result)
error = error || ft_vec_append(exp_str, "'") != success;
error = error || ft_vec_append_range(exp_str, value, ft_strlen(value)) != success;
- if (quote)
+ if (enquote_result)
error = error || ft_vec_append(exp_str, "'") != success;
free(value);
if (error)