norm 1
This commit is contained in:
parent
8bb6c5d5fe
commit
a5e877fdd5
43
sources.mk
43
sources.mk
@ -1,23 +1,22 @@
|
||||
VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/debug:src/expander:src/builtin:src/signal:src/redirect:
|
||||
SOURCES = history_load.c history_write.c prompt.c error_msg.c \
|
||||
ft_lstclear_safe.c ft_lstnew_safe.c ft_strdup_safe.c \
|
||||
ft_strjoin_safe.c init_minishell.c malloc_safe.c print_banner.c \
|
||||
check_malloc.c free_command_list.c free_freelist.c free_lexer.c \
|
||||
free_minishell.c free_minishell_line.c free_safe.c free_token.c \
|
||||
free_token_list.c lexer_read_char.c lexer_new.c lexer_parse_input.c \
|
||||
lexer_read_word.c lexer_token_next.c token_new.c token_parse.c \
|
||||
environment_add.c environment_del.c environment_free.c \
|
||||
environment_free_list.c environment_get.c environment_get_arr.c \
|
||||
environment_parse.c environment_print.c executor_close_fds.c \
|
||||
executor_absolute_path.c executor_child.c executor_count_fds.c \
|
||||
executor_create_pipes.c executor_create_redirects.c \
|
||||
executor_execute_pipeline.c executor_fork.c executor_open_fds.c \
|
||||
parser_get_arguments.c parser_get_commands.c parser_new_command.c \
|
||||
print_commands.c print_freelist.c expander_is_character.c \
|
||||
expander_expand_dollar.c expander_allocate_memory.c \
|
||||
VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/signal:src/debug:src/expander:src/builtin:src/redirect:
|
||||
SOURCES = history_load.c history_write.c prompt.c ft_lstclear_safe.c \
|
||||
ft_lstnew_safe.c ft_strdup_safe.c ft_strjoin_safe.c init_minishell.c \
|
||||
malloc_safe.c free_minishell_line.c free_safe.c print_banner.c \
|
||||
error_msg.c check_malloc.c free_command_list.c free_freelist.c \
|
||||
free_lexer.c free_minishell.c free_token.c free_token_list.c \
|
||||
lexer_read_char.c lexer_new.c lexer_parse_input.c lexer_read_word.c \
|
||||
lexer_token_next.c token_new.c token_parse.c environment_add.c \
|
||||
environment_del.c environment_free.c environment_free_list.c \
|
||||
environment_get.c environment_get_arr.c environment_print.c \
|
||||
environment_parse.c executor_close_fds.c executor_absolute_path.c \
|
||||
executor_child.c executor_count_fds.c executor_create_pipes.c \
|
||||
executor_create_redirects.c executor_fork.c executor_open_fds.c \
|
||||
executor_execute_pipeline.c parser_get_commands.c \
|
||||
parser_new_command.c parser_get_arguments.c signal.c print_freelist.c \
|
||||
print_commands.c expander_expand_dollar.c expander_is_character.c \
|
||||
expander_get_variable.c expander_parse_string.c \
|
||||
expander_parse_variables.c builtin_echo.c builtin_router.c \
|
||||
simple_builtins.c is_builtin.c builtin_cd.c builtin_env.c \
|
||||
builtin_exit.c builtin_export.c builtin_pwd.c builtin_unset.c \
|
||||
signal.c redirect_valid_type.c redirect_get_inputs.c \
|
||||
redirect_get_outputs.c redirect_new.c main.c \
|
||||
expander_parse_variables.c expander_allocate_memory.c builtin_echo.c \
|
||||
builtin_router.c simple_builtins.c is_builtin.c builtin_cd.c \
|
||||
builtin_env.c builtin_export.c builtin_unset.c builtin_pwd.c \
|
||||
builtin_exit.c redirect_valid_type.c redirect_get_outputs.c \
|
||||
redirect_new.c redirect_get_inputs.c main.c \
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* builtin_exit.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/20 11:32:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/25 20:56:29 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/02/26 15:19:51 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
//TODO EXIT last exit status r:20
|
||||
int builtin_exit(t_minishell *minishell, t_command *cmd)
|
||||
{
|
||||
int exit_status;
|
||||
|
||||
exit_status = 0; //TODO EXIT last exit status
|
||||
exit_status = 0;
|
||||
if (ft_count_arr(cmd->args) > 2)
|
||||
{
|
||||
ft_putstr_fd("exit\n", STDERR_FILENO);
|
||||
@ -36,7 +36,6 @@ int builtin_exit(t_minishell *minishell, t_command *cmd)
|
||||
}
|
||||
exit_status = ft_atoi(cmd->args[1]);
|
||||
}
|
||||
//print_freelist(minishell);
|
||||
free_minishell(&minishell);
|
||||
rl_clear_history();
|
||||
exit(exit_status);
|
||||
|
||||
@ -6,13 +6,12 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/20 11:03:33 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/20 15:36:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 14:42:49 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
int is_builtin(char *cmd)
|
||||
{
|
||||
const char *builtins[] = {"echo", "cd", "pwd", "export",
|
||||
|
||||
@ -6,13 +6,12 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/20 15:06:40 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 14:42:54 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
void simple_builtins(t_minishell *minishell)
|
||||
{
|
||||
if (minishell->commands == NULL)
|
||||
|
||||
@ -53,4 +53,3 @@ void token_print(void *param)
|
||||
token = (t_token *)param;
|
||||
printf("token type %i, value %s\n", token->type, token->value);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/25 15:46:03 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/25 18:17:13 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 14:44:46 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/08 13:59:48 by willem #+# #+# */
|
||||
/* Updated: 2025/02/25 14:29:49 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 14:45:35 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,12 +20,14 @@ char **environment_get_arr(t_minishell *minishell)
|
||||
t_list *environment;
|
||||
|
||||
environment = minishell->environment;
|
||||
arr = malloc_safe(minishell, sizeof(char *) * (ft_lstsize(environment) + 1));
|
||||
arr = malloc_safe(minishell,
|
||||
sizeof(char *) * (ft_lstsize(environment) + 1));
|
||||
i = 0;
|
||||
while (environment != NULL)
|
||||
{
|
||||
env = (t_environment *)environment->content;
|
||||
arr[i] = malloc_safe(minishell, ft_strlen(env->name) + ft_strlen(env->value) + 2);
|
||||
arr[i] = malloc_safe(minishell,
|
||||
ft_strlen(env->name) + ft_strlen(env->value) + 2);
|
||||
ft_strlcpy(arr[i], env->name, ft_strlen(env->name) + 1);
|
||||
ft_strlcat(arr[i], "=", ft_strlen(env->name) + 2);
|
||||
ft_strlcat(arr[i], env->value,
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* environment_parse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* environment_parse.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/05 15:52:33 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/25 21:17:06 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/02/26 15:20:09 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,7 +16,6 @@ int environment_parse(t_minishell *minishell, char **envp)
|
||||
{
|
||||
char **env;
|
||||
|
||||
|
||||
if (envp == NULL)
|
||||
return (FAILURE);
|
||||
while (*envp != NULL)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/12 21:25:10 by willem #+# #+# */
|
||||
/* Updated: 2025/02/25 13:52:53 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:20:25 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/21 12:42:26 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/21 13:05:55 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:20:33 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,16 +6,16 @@
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */
|
||||
/* Updated: 2025/02/25 13:51:48 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:21:42 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
//TODO should parent close the fds?
|
||||
pid_t executor_fork(t_minishell *minishell, t_command *command)
|
||||
{
|
||||
pid_t pid;
|
||||
// int status;
|
||||
|
||||
pid = fork();
|
||||
if (pid > 0)
|
||||
@ -24,8 +24,6 @@ pid_t executor_fork(t_minishell *minishell, t_command *command)
|
||||
close(command->fd_in);
|
||||
if (command->fd_out != 1)
|
||||
close(command->fd_out);
|
||||
// waitpid(pid, &status, 0);
|
||||
// return (((status) & 0xff00) >> 8);
|
||||
signal_init_parent();
|
||||
}
|
||||
else if (pid == 0)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/21 12:50:42 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/21 13:15:04 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:21:56 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,5 +35,4 @@ int executor_open_fds(t_list *redirect_list, int og_fd)
|
||||
redirect_list = redirect_list->next;
|
||||
}
|
||||
return (fd);
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/19 13:57:19 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 17:54:08 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:22:11 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 16:14:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:22:54 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,6 +26,7 @@ static void free_variables(t_minishell *minishell, t_list *variables)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Figure out why echo "> echo "\as"" breaks
|
||||
char *expander_parse_string(char *s, t_minishell *minishell)
|
||||
{
|
||||
t_list *variables;
|
||||
@ -51,8 +52,6 @@ char *expander_parse_string(char *s, t_minishell *minishell)
|
||||
else
|
||||
string[j++] = s[i++];
|
||||
}
|
||||
//TODO: Figure out why echo "> echo "\as"" breaks
|
||||
|
||||
string[j] = 0;
|
||||
free_variables(minishell, variables);
|
||||
return (string);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/19 13:58:13 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 16:51:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:23:17 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
|
||||
t_list *expander_parse_variables(const char *s, t_minishell *minishell)
|
||||
{
|
||||
|
||||
int i;
|
||||
t_list *var_list;
|
||||
t_environment *env;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/05 19:03:01 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 16:40:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:23:52 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
t_lexer *ft_lexer_new(t_minishell *minishell)
|
||||
{
|
||||
char *input;
|
||||
|
||||
t_lexer *lexer;
|
||||
|
||||
input = minishell->line;
|
||||
lexer = malloc_safe(minishell, sizeof(t_lexer));
|
||||
lexer->input = ft_strdup_safe(minishell, input);
|
||||
|
||||
@ -6,11 +6,12 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/05 19:09:20 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 16:51:27 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/26 15:24:39 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
//TODO: Check if unicode support is viable
|
||||
|
||||
/**
|
||||
* @brief Parses the input from the lexer and returns a list of tokens.
|
||||
@ -33,9 +34,8 @@ t_list *ft_parse_input(t_minishell *minishell)
|
||||
list = NULL;
|
||||
while (TRUE)
|
||||
{
|
||||
//TODO: Check if unicode support is viable
|
||||
token = ft_token_next(minishell, lexer);
|
||||
if (token->type == T_EOF || token->type == T_ERROR) //TODO T_ERROR removes the inf loop
|
||||
if (token->type == T_EOF || token->type == T_ERROR)
|
||||
break ;
|
||||
ft_lstadd_back(&list, ft_lstnew_safe(minishell, token));
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parser_get_arguments.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* :::::::: */
|
||||
/* parser_get_arguments.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/11 16:20:09 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 20:14:18 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/02/26 15:26:32 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -38,8 +38,10 @@ static int parser_should_expand(t_list *value)
|
||||
token = (t_token *)value->content;
|
||||
if (!token)
|
||||
return (0);
|
||||
return (token->type == T_DQWORD || (token->type == T_WORD &&
|
||||
token->value[0] == '$' && token->value[1]));
|
||||
return (token->type == T_DQWORD
|
||||
|| (token->type == T_WORD
|
||||
&& token->value[0] == '$'
|
||||
&& token->value[1]));
|
||||
}
|
||||
|
||||
char **parser_get_arguments(t_list *list, t_minishell *minishell)
|
||||
@ -56,10 +58,12 @@ char **parser_get_arguments(t_list *list, t_minishell *minishell)
|
||||
while ((++i) < cmds && current)
|
||||
{
|
||||
if (parser_should_expand(current))
|
||||
args[i] = expander_parse_string(((t_token *)current->content)->value, minishell);
|
||||
else if (((t_token *)current->content)->type == T_WORD ||
|
||||
((t_token *)current->content)->type == T_SQWORD)
|
||||
args[i] = ft_strdup_safe(minishell, ((t_token *)current->content)->value);
|
||||
args[i] = expander_parse_string(
|
||||
((t_token *)current->content)->value, minishell);
|
||||
else if (((t_token *)current->content)->type == T_WORD
|
||||
|| ((t_token *)current->content)->type == T_SQWORD)
|
||||
args[i] = ft_strdup_safe(minishell,
|
||||
((t_token *)current->content)->value);
|
||||
current = current->next;
|
||||
}
|
||||
args[i] = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user