feat: fuckning working
This commit is contained in:
parent
56f0a979a7
commit
028d4312af
4 changed files with 28 additions and 49 deletions
|
|
@ -125,9 +125,31 @@ static char **list_to_argv(struct list *command_list)
|
|||
|
||||
static int try_builtin(char **argv, struct hash_map *vars);
|
||||
|
||||
static int exec_assignment(struct list *assignment_list, struct hash_map *vars)
|
||||
{
|
||||
while (assignment_list != NULL)
|
||||
{
|
||||
if (!ast_is_assignment(assignment_list->data))
|
||||
{
|
||||
fprintf(stderr, "list of assignements contains something else");
|
||||
return 1;
|
||||
}
|
||||
struct ast_assignment *assignment =
|
||||
ast_get_assignment(assignment_list->data);
|
||||
|
||||
char *key = strdup(assignment->name);
|
||||
char *value = strdup(assignment->value);
|
||||
hash_map_insert(vars, key, value, NULL);
|
||||
|
||||
assignment_list = assignment_list->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
||||
{
|
||||
(void)vars;
|
||||
exec_assignment(command->assignments, vars);
|
||||
set_all_redir(command->redirections);
|
||||
|
||||
if (!command || !(command->command))
|
||||
|
|
@ -255,52 +277,6 @@ void unset_all_redir(struct list *redir_list)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int exec_ast_redir(struct ast_redir *redir, struct hash_map *vars)
|
||||
{
|
||||
int fd_target = get_fd_target(redir);
|
||||
int saved_fd = dup(fd_target);
|
||||
int new_fd = -1, flags = 0, mode = 0644;
|
||||
if (redir->type == AST_REDIR_TYPE_GREAT
|
||||
|| redir->type == AST_REDIR_TYPE_CLOBBER
|
||||
|| redir->type == AST_REDIR_TYPE_DGREAT
|
||||
|| redir->type == AST_REDIR_TYPE_LESS)
|
||||
{
|
||||
new_fd = open_redir_file(redir, &flags, &mode);
|
||||
if (new_fd == -1)
|
||||
{
|
||||
perror("open");
|
||||
if (saved_fd != -1)
|
||||
close(saved_fd);
|
||||
return 1;
|
||||
}
|
||||
if (dup2(new_fd, fd_target) == -1)
|
||||
{
|
||||
perror("dup2");
|
||||
close(new_fd);
|
||||
if (saved_fd != -1)
|
||||
close(saved_fd);
|
||||
return 1;
|
||||
}
|
||||
close(new_fd);
|
||||
}
|
||||
else if (redir->type == AST_REDIR_TYPE_GREATAND
|
||||
|| redir->type == AST_REDIR_TYPE_LESSAND)
|
||||
{
|
||||
new_fd = atoi(redir->filename);
|
||||
if (dup2(new_fd, fd_target) == -1)
|
||||
{
|
||||
perror("dup2");
|
||||
if (saved_fd != -1)
|
||||
close(saved_fd);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
int ret = execution(redir->child, vars);
|
||||
handle_and_restore_fd(saved_fd, fd_target);
|
||||
return ret;
|
||||
} */
|
||||
|
||||
// --- Builtins ---
|
||||
|
||||
static int builtin_echo(char **argv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue