more pushing
This commit is contained in:
parent
74323b15a4
commit
0688039329
38
README.md
38
README.md
@ -23,42 +23,14 @@ A lot of amazing shell stuff
|
||||
|
||||
|
||||
## TODO
|
||||
- [x] Find absolute path for command input ('/', './', 'cmd')
|
||||
- [x]Add heredoc to tokenizer
|
||||
- [x] Environment to `t_list`
|
||||
- [x] Get environment array (export)
|
||||
- [x] Set environment variable (export)
|
||||
- [x] Simple builtin export
|
||||
- [x] builtins
|
||||
- [x] Preliminary signals
|
||||
- [x] Define struct for commands, something like (
|
||||
```c
|
||||
typedef struct s_command
|
||||
{
|
||||
char *command;
|
||||
char *path;
|
||||
char **args;
|
||||
int fd_in;
|
||||
int fd_out;
|
||||
} t_command;
|
||||
```
|
||||
)
|
||||
- [x] Make the `executor`, run a command
|
||||
- [x] Make a parser to create a command list
|
||||
- [x] Add redirects, appends, pipe etc. File descriptor functions
|
||||
a command can have multiple redirects but only the last is used for stdout
|
||||
Redirects take precedence over pipes, but pipes are still created and managed.
|
||||
should it close the unused pipe-end?
|
||||
all redirects are opened and closed, but only last fd is used.
|
||||
multiple HEREDOCs can be nested, only last is used.
|
||||
- [x] Expand \$ vars & support \$ ~?
|
||||
* [x] $var
|
||||
* [x] $?
|
||||
* [ ] ~
|
||||
- [ ] export without arguments
|
||||
- [ ] ft_free_arr_safe in environment mess
|
||||
- [ ] builtins not first in pipeline? wtf is happening HAHAHAHAHAH its not using builtin, but core-utils
|
||||
- CB command to change banner
|
||||
- [ ] Remove -c option parsing as split can break
|
||||
- [ ] Only `""` as input shows command not found, that invalid
|
||||
- [ ] CTRL+\ during `sleep 5` should do nothing, but returns a new prompt
|
||||
- [ ] echo "hello" > /root/protected.txt gives the error but still prints
|
||||
- [ ] cat < filenoexit returns `minishell: minishell: unable to write to temp file: No such file or directory` but we're not writin
|
||||
- __Bonus:__ Command tree for &&, ||, *
|
||||
|
||||
## Signals
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* executor_child.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/12 21:25:10 by willem #+# #+# */
|
||||
/* Updated: 2025/03/06 11:36:33 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* executor_child.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/12 21:25:10 by willem #+# #+# */
|
||||
/* Updated: 2025/03/06 14:12:17 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* executor_execute_pipeline.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
|
||||
/* Updated: 2025/03/05 13:10:59 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* executor_execute_pipeline.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
|
||||
/* Updated: 2025/03/06 14:39:56 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,8 +20,10 @@ static int execute_builtin(t_minishell *msh, t_command *cmd)
|
||||
|
||||
original_stdin = dup(STDIN_FILENO);
|
||||
original_stdout = dup(STDOUT_FILENO);
|
||||
dup2(cmd->fd_in, STDIN_FILENO);
|
||||
dup2(cmd->fd_out, STDOUT_FILENO);
|
||||
if (dup2(cmd->fd_in, STDIN_FILENO) < 0)
|
||||
return (1);
|
||||
if (dup2(cmd->fd_out, STDOUT_FILENO) < 0)
|
||||
return (1);
|
||||
signal_init_child();
|
||||
exit_status = builtin_router(msh, cmd);
|
||||
signal_init_minishell();
|
||||
@ -36,6 +38,9 @@ static int execute_builtin(t_minishell *msh, t_command *cmd)
|
||||
|
||||
static int executor_execute_command(t_minishell *msh, t_command *cmd)
|
||||
{
|
||||
//TODO: Discuss
|
||||
if (cmd->args[0] && ft_strcmp(cmd->args[0], "") == 0)
|
||||
return (0);
|
||||
if (is_builtin(cmd->args[0]) >= 0)
|
||||
msh->exit_status = execute_builtin(msh, cmd);
|
||||
else if (cmd->args[0] != NULL)
|
||||
|
||||
@ -35,13 +35,9 @@ int expander_expand_dollar(char *src, char *dest, int *j, t_list *variables)
|
||||
env = (t_environment *)variables->content;
|
||||
v_len = ft_strlen(env->name);
|
||||
while (env->value[i])
|
||||
{
|
||||
dest[(*j)++] = env->value[i++];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
v_len = get_var_len(src);
|
||||
}
|
||||
return (v_len);
|
||||
}
|
||||
|
||||
@ -33,6 +33,20 @@ static t_list *create_exit_status_env(t_minishell *msh)
|
||||
return (ft_lstnew_safe(msh, env));
|
||||
}
|
||||
|
||||
static t_list *create_tilde_env(t_minishell *msh)
|
||||
{
|
||||
t_environment *home;
|
||||
t_environment *env;
|
||||
|
||||
home = environment_get(msh, "HOME");
|
||||
if (!home)
|
||||
return (ft_lstnew_safe(msh, NULL));
|
||||
env = malloc_safe(msh, sizeof(t_environment));
|
||||
env->name = ft_strdup_safe(msh, "~");
|
||||
env->value = home->value;
|
||||
return (ft_lstnew_safe(msh, env));
|
||||
}
|
||||
|
||||
t_list *expander_parse_variables(const char *s, t_minishell *msh)
|
||||
{
|
||||
int i;
|
||||
@ -57,7 +71,7 @@ t_list *expander_parse_variables(const char *s, t_minishell *msh)
|
||||
}
|
||||
}
|
||||
else if (s[i] == '~')
|
||||
ft_lstadd_back(&var_list, ft_lstnew_safe(msh, environment_get(msh, "HOME")));
|
||||
ft_lstadd_back(&var_list, create_tilde_env(msh));
|
||||
i++;
|
||||
}
|
||||
return (var_list);
|
||||
|
||||
@ -27,7 +27,8 @@ static int parser_should_expand(t_list *value)
|
||||
while (token->value[i])
|
||||
{
|
||||
t_val = token->value;
|
||||
if (t_val[i] == '~' && (t_val[i + 1] == '/' || t_val[i + 1] == ' ' || t_val[i + 1] == 0) && token->type == T_WORD)
|
||||
if (t_val[i] == '~' && (t_val[i + 1] == '/' || t_val[i + 1] == ' '
|
||||
|| t_val[i + 1] == 0) && token->type == T_WORD)
|
||||
return (1);
|
||||
else if (t_val[i] == '$' && expander_character_valid(t_val[i + 1]))
|
||||
return (1);
|
||||
@ -51,7 +52,7 @@ char *parser_process_token(t_minishell *msh, t_list *prev, t_list *t_head)
|
||||
p_token = (t_token *)prev->content;
|
||||
str = NULL;
|
||||
if (ft_strcmp(token->value, "") == 0)
|
||||
return (NULL);
|
||||
return (ft_strdup_safe(msh, ""));
|
||||
if (parser_should_expand(t_head))
|
||||
str = expander_parse_string(token->value, msh);
|
||||
if (!str)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* signal_init.c.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/26 15:39:01 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/26 15:39:46 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* signal_init.c.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/26 15:39:01 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/06 14:42:28 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user