fix: args[0] aliased is now edited too

This commit is contained in:
starnakin 2023-07-04 16:52:30 +02:00
parent b073baa06b
commit 52612b9aa5

View File

@ -2,31 +2,43 @@
char* parsing_executable(const char* executable, data_t *data) char* parsing_executable(const char* executable, data_t *data)
{ {
const char* tmp;
if (executable == NULL) if (executable == NULL)
return NULL; return NULL;
if (executable[0] == '\\') if (strchr("./", executable[0]))
tmp = executable + 1; return strdup(executable);
else return (get_executable_path(executable, data->env));
{
tmp = get_alias(data->aliases, executable);
if (tmp == NULL)
tmp = executable;
}
if (strchr("./", tmp[0]))
return strdup(tmp);
return (get_executable_path(tmp, data->env));
} }
int parsing_cmd(char *str, cmd* command, data_t *data) int parsing_cmd(char *str, cmd* command, data_t *data)
{ {
char* tmp;
if (get_redirections(str, command)) if (get_redirections(str, command))
return 1; return 1;
command->args = split_quoted_charset(str, "\t "); command->args = split_quoted_charset(str, "\t ");
if (command->args == NULL) if (command->args == NULL)
return 1; return 1;
for (size_t i = 0; command->args[i]; i++) for (size_t i = 0; command->args[i]; i++)
quote_remover(command->args[i]); quote_remover(command->args[i]);
if (command->args[0][0] == '\\')
{
tmp = strdup(command->args[0] + 1);
if (tmp != NULL)
{
free(command->args[0]);
command->args[0] = strdup(tmp);
}
}
else
{
tmp = get_alias(data->aliases, command->args[0]);
if (tmp != NULL)
{
free(command->args[0]);
command->args[0] = strdup(tmp);
}
}
if (command->args[0] == NULL)
return 1;
command->executable = parsing_executable(command->args[0], data); command->executable = parsing_executable(command->args[0], data);
return 0; return 0;
} }