bless
This commit is contained in:
parent
6b48a73535
commit
850ca79fc6
19
minishell/Dockerfile
Normal file
19
minishell/Dockerfile
Normal file
@ -0,0 +1,19 @@
|
||||
FROM alpine:edge
|
||||
ENV USERNAME="shelluser" \
|
||||
PASSWORD="" \
|
||||
SUDO_OK="false" \
|
||||
AUTOLOGIN="true" \
|
||||
TZ="Etc/UTC"
|
||||
|
||||
COPY ./entrypoint.sh /
|
||||
COPY --chmod=011 minishell_src/bin/minishell /bin/minishell
|
||||
|
||||
RUN apk update && \
|
||||
apk add --no-cache tini ttyd tzdata vim nano && \
|
||||
chmod 700 /entrypoint.sh && \
|
||||
touch /etc/.firstrun && \
|
||||
ln -s "/usr/share/zoneinfo/$TZ" /etc/localtime && \
|
||||
echo $TZ > /etc/timezone
|
||||
|
||||
ENTRYPOINT ["/sbin/tini", "--"]
|
||||
CMD ["/entrypoint.sh"]
|
||||
54
minishell/entrypoint.sh
Normal file
54
minishell/entrypoint.sh
Normal file
@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
TTYD_ARGS="login"
|
||||
|
||||
# Check if this is the container's first run
|
||||
if [ -f /etc/.firstrun ]; then
|
||||
# Create user account
|
||||
echo >> /etc/shells /bin/minishell
|
||||
adduser -D --shell=/bin/sh $USERNAME
|
||||
echo "#!/bin/sh
|
||||
trap '' SIGINT
|
||||
while :
|
||||
do
|
||||
echo "*** Starting Minishell ***"
|
||||
minishell
|
||||
done" >> /home/$USERNAME/.runshell.sh
|
||||
chmod +x /home/$USERNAME/.runshell.sh
|
||||
echo >> /home/$USERNAME/.profile "./.runshell.sh"
|
||||
|
||||
# Add a password to the user
|
||||
echo "$USERNAME:$PASSWORD" | chpasswd
|
||||
|
||||
# Allow access to sudo if permitted
|
||||
if [ $SUDO_OK == "true" ]; then
|
||||
addgroup $USERNAME wheel
|
||||
sed -i '/%wheel ALL=(ALL) ALL/s/^# //g' /etc/sudoers
|
||||
fi
|
||||
|
||||
# Prevent this from running again
|
||||
rm /etc/.firstrun
|
||||
fi
|
||||
|
||||
# Optionally set a timezone
|
||||
CURRENT_TZ=$(cat /etc/timezone)
|
||||
if [ "$TZ" != "$CURRENT_TZ" ]; then
|
||||
echo "Setting timezone to $TZ"
|
||||
|
||||
# delete symlink if it exists
|
||||
[ -f /etc/localtime ] && rm /etc/localtime
|
||||
|
||||
# set timezone
|
||||
ln -s "/usr/share/zoneinfo/$TZ" /etc/localtime
|
||||
echo $TZ > /etc/timezone
|
||||
fi
|
||||
|
||||
# Auto login the user, if allowed
|
||||
[ $AUTOLOGIN == "true" ] && TTYD_ARGS="$TTYD_ARGS -f $USERNAME"
|
||||
|
||||
passwd -l root
|
||||
|
||||
# Start ttyd
|
||||
exec ttyd -W -m 5 -p 8006 $TTYD_ARGS
|
||||
112
minishell/minishell_src/Makefile
Normal file
112
minishell/minishell_src/Makefile
Normal file
@ -0,0 +1,112 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: anarama <anarama@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/07/05 12:24:47 by victor #+# #+# #
|
||||
# Updated: 2025/02/15 15:18:58 by victor ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# COMPILER AND FLAGS
|
||||
CC := cc
|
||||
CFLAGS := -Werror -Wall -Wextra
|
||||
|
||||
# DIRECTORIES
|
||||
SRCDIR := src
|
||||
ASTDIR := ast
|
||||
BULDINDIR := builtin
|
||||
OBJDIR := obj
|
||||
TOKENDIR := tokenizer
|
||||
BINDIR := bin
|
||||
|
||||
SRC := src/commands.c src/environment_variables.c \
|
||||
src/handle_signals.c src/input.c src/list_memory.c \
|
||||
src/list.c src/minishell.c \
|
||||
src/path_utils.c src/termios.c \
|
||||
src/utils.c src/utils2.c src/utils3.c \
|
||||
src/environment_variables_manip.c \
|
||||
src/wildcards.c src/execution.c \
|
||||
src/non_interactive.c src/wildcards_hanlde_match.c \
|
||||
src/wildcards_helper.c
|
||||
|
||||
PROMPT_SRC := prompt/prompt_input.c prompt/prompt_string_management.c \
|
||||
prompt/prompt_utils.c prompt/tab_completion.c \
|
||||
prompt/escape_sequences.c prompt/arrowkeys.c \
|
||||
prompt/prompt_print.c prompt/tab_get_word.c \
|
||||
prompt/non_blocking_mode.c prompt/prompt_handle_chars.c \
|
||||
|
||||
AST_SRC := ast/ast_utils.c \
|
||||
ast/handle_command.c ast/handle_fds.c \
|
||||
ast/parse_tokens.c ast/parser.c \
|
||||
ast/syntax_check.c ast/handle_redirs.c \
|
||||
ast/handle_heredoc.c ast/parse_tokens_helper.c \
|
||||
ast/syntax_check_helper.c ast/buildin.c
|
||||
|
||||
TOKEN_SRC := tokenizer/check_special_symbol.c \
|
||||
tokenizer/create_token_double_special_symbol.c \
|
||||
tokenizer/create_token_single_special_symbol.c \
|
||||
tokenizer/create_token_word.c \
|
||||
tokenizer/create_token.c \
|
||||
tokenizer/tokenizer.c \
|
||||
tokenizer/subshell.c tokenizer/evaluate_input.c \
|
||||
tokenizer/input_skip_patterns.c \
|
||||
tokenizer/token_heredoc.c \
|
||||
tokenizer/tokenizer_heredoc_helper.c tokenizer/evaluate_input_helper.c \
|
||||
tokenizer/evaluate_input_helper2.c
|
||||
|
||||
BUILDIN_SRC := builtin/ft_echo.c builtin/ft_env.c \
|
||||
builtin/ft_pwd.c builtin/ft_unset.c \
|
||||
builtin/ft_export.c builtin/ft_exit.c \
|
||||
builtin/ft_cd.c
|
||||
|
||||
# OBJECT FILES
|
||||
OBJ := $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
AST_OBJ := $(AST_SRC:ast/%.c=$(OBJDIR)/ast/%.o)
|
||||
BUILDIN_OBJ := $(BUILDIN_SRC:builtin/%.c=$(OBJDIR)/builtin/%.o)
|
||||
PROMPT_OBJ := $(PROMPT_SRC:prompt/%.c=$(OBJDIR)/prompt/%.o)
|
||||
TOKEN_OBJ := $(TOKEN_SRC:tokenizer/%.c=$(OBJDIR)/tokenizer/%.o)
|
||||
|
||||
NAME := $(BINDIR)/minishell
|
||||
LIBS := libft/libft.a
|
||||
|
||||
# Create object directory if none exists
|
||||
$(shell mkdir -p $(BINDIR) $(OBJDIR) $(OBJDIR)/ast $(OBJDIR)/src $(OBJDIR)/tokenizer $(OBJDIR)/builtin $(OBJDIR)/prompt)
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ) $(AST_OBJ) $(TOKEN_OBJ) $(BUILDIN_OBJ) $(PROMPT_OBJ) $(LIBS) minishell.h
|
||||
$(CC) -static $(CFLAGS) $(OBJ) $(AST_OBJ) $(TOKEN_OBJ) $(BUILDIN_OBJ) $(PROMPT_OBJ) $(LIBS) -o $(NAME)
|
||||
|
||||
test: $(TEST_OBJ) $(AST_OBJ) $(TOKEN_OBJ) $(LIBS) minishell.h
|
||||
$(CC) $(CFLAGS) $(TEST_OBJ) $(AST_OBJ) $(TOKEN_OBJ) $(LIBS) -o $(TEST_NAME)
|
||||
|
||||
clean:
|
||||
make clean -C libft
|
||||
rm -rf $(OBJ) $(BINDIR) $(AST_OBJ) $(TEST_OBJ) $(TOKEN_OBJ) $(PROMPT_OBJ) $(BUILDIN_OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME) $(TEST_NAME)
|
||||
make fclean -C libft
|
||||
|
||||
re: fclean all
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/builtin/%.o: builtin/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/prompt/%.o: prompt/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/ast/%.o: ast/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/tokenizer/%.o: tokenizer/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(LIBS):
|
||||
make bonus -C libft
|
||||
62
minishell/minishell_src/ast/ast_utils.c
Normal file
62
minishell/minishell_src/ast/ast_utils.c
Normal file
@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ast_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: anarama <anarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/20 17:43:20 by anarama #+# #+# */
|
||||
/* Updated: 2024/08/16 11:36:37 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
int get_tokens_len(t_token *tokens)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tokens[i].token_type != TOKEN_EOL)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char **copy_args(t_ast *node, char **src)
|
||||
{
|
||||
char **temp;
|
||||
|
||||
node->args = ft_calloc(get_split_size((const char **)src) \
|
||||
+ 1, sizeof(char *));
|
||||
if (!node->args)
|
||||
{
|
||||
free(node);
|
||||
perror("calloc in copy args");
|
||||
lst_memory(NULL, NULL, CLEAN);
|
||||
}
|
||||
lst_memory(node->args, free_split, ADD);
|
||||
temp = node->args;
|
||||
while (*src)
|
||||
{
|
||||
*node->args = ft_strdup(*src);
|
||||
if (!*node->args)
|
||||
{
|
||||
free(node);
|
||||
perror("strdup in copy args");
|
||||
lst_memory(NULL, NULL, CLEAN);
|
||||
}
|
||||
src++;
|
||||
node->args++;
|
||||
}
|
||||
return (temp);
|
||||
}
|
||||
|
||||
int is_redirection(t_token_type token_type)
|
||||
{
|
||||
return (token_type == TOKEN_REDIRECT_IN
|
||||
|| token_type == TOKEN_REDIRECT_OUT
|
||||
|| token_type == TOKEN_REDIRECT_APPEND
|
||||
|| token_type == TOKEN_HEREDOC);
|
||||
}
|
||||
28
minishell/minishell_src/ast/buildin.c
Normal file
28
minishell/minishell_src/ast/buildin.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* buildin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/26 12:39:13 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/26 12:39:22 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
bool is_buildin(t_ast *node)
|
||||
{
|
||||
if (!node->args || !*node->args)
|
||||
return (false);
|
||||
if (ft_memcmp(node->args[0], "echo", ft_strlen("echo") + 1) == 0
|
||||
|| ft_memcmp(node->args[0], "env", ft_strlen("env") + 1) == 0
|
||||
|| ft_memcmp(node->args[0], "cd", ft_strlen("cd") + 1) == 0
|
||||
|| ft_memcmp(node->args[0], "pwd", ft_strlen("pwd") + 1) == 0
|
||||
|| ft_memcmp(node->args[0], "unset", ft_strlen("unset") + 1) == 0
|
||||
|| ft_memcmp(node->args[0], "export", ft_strlen("export") + 1) == 0
|
||||
|| ft_memcmp(node->args[0], "exit", ft_strlen("exit") + 1) == 0)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
126
minishell/minishell_src/ast/handle_command.c
Normal file
126
minishell/minishell_src/ast/handle_command.c
Normal file
@ -0,0 +1,126 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_command.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: anarama <anarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/25 18:14:10 by anarama #+# #+# */
|
||||
/* Updated: 2024/08/27 15:22:42 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
bool buildin_apply_pipe(t_ast *node, int32_t *exit_status)
|
||||
{
|
||||
if (node->type == NODE_PIPE)
|
||||
{
|
||||
ft_dup2(node->pipefd[1], STDOUT_FILENO, "dup2 in buildin_execute");
|
||||
ft_close(node->pipefd[1], "close in buildin_execute");
|
||||
}
|
||||
if (node->has_redir_in || node->has_redir_out)
|
||||
{
|
||||
return (handle_fds_child_proccess(node, exit_status));
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
void execute_parent(t_ast *command, int32_t *exit_status, pid_t pid)
|
||||
{
|
||||
command->cpid = pid;
|
||||
if (command->type == NODE_PIPE)
|
||||
handle_pipe_in_parent(command);
|
||||
if (command->has_redir_in || command->has_redir_out)
|
||||
handle_fds_parent_proccess(command, exit_status);
|
||||
}
|
||||
|
||||
void execute_command( t_ast *command, \
|
||||
int32_t *exit_status, \
|
||||
int std[2], \
|
||||
char *path)
|
||||
{
|
||||
pid_t pid;
|
||||
char **env;
|
||||
bool should_execute;
|
||||
|
||||
should_execute = true;
|
||||
ft_fork(&pid, "execute command");
|
||||
if (pid == 0)
|
||||
{
|
||||
env = env_static(NULL);
|
||||
if (command->type == NODE_PIPE)
|
||||
handle_pipe_in_child(command);
|
||||
if (command->has_redir_in || command->has_redir_out)
|
||||
should_execute = handle_fds_child_proccess(command, exit_status);
|
||||
if (is_buildin(command) && should_execute)
|
||||
buildin_execute(command, (const char **)env, exit_status);
|
||||
else if (path && should_execute)
|
||||
{
|
||||
execve(path, command->args, (char **)env);
|
||||
perror("execve");
|
||||
}
|
||||
return (lst_memory(NULL, NULL, END), \
|
||||
close_fds(std), exit(*exit_status));
|
||||
}
|
||||
else
|
||||
execute_parent(command, exit_status, pid);
|
||||
}
|
||||
|
||||
bool buildin_execute( t_ast *node, \
|
||||
const char **environment, \
|
||||
int *e)
|
||||
{
|
||||
if (!node->args || !*node->args)
|
||||
return (false);
|
||||
if (ft_memcmp(node->args[0], "echo", ft_strlen(node->args[0]) + 1) == 0)
|
||||
return (ft_echo(node->args, e), 1);
|
||||
else if (ft_memcmp(node->args[0], "env", ft_strlen(node->args[0]) + 1) == 0)
|
||||
return (ft_env(environment, e), 1);
|
||||
else if (ft_memcmp(node->args[0], "cd", ft_strlen(node->args[0]) + 1) == 0)
|
||||
return (ft_cd(environment, \
|
||||
(const char **)node->args, e), 1);
|
||||
else if (ft_memcmp(node->args[0], "pwd", ft_strlen(node->args[0]) + 1) == 0)
|
||||
return (ft_pwd(environment, e), 1);
|
||||
else if (ft_memcmp(node->args[0], "unset", \
|
||||
ft_strlen(node->args[0]) + 1) == 0)
|
||||
return (ft_unset((char **)environment, \
|
||||
(const char **)node->args, e), 1);
|
||||
else if (ft_memcmp(node->args[0], "export", \
|
||||
ft_strlen(node->args[0]) + 1) == 0)
|
||||
ft_export((const char **)node->args, e);
|
||||
else if (ft_memcmp(node->args[0], "exit", \
|
||||
ft_strlen(node->args[0]) + 1) == 0)
|
||||
return (ft_exit(node, e), *e = 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void handle_command( t_ast *current, \
|
||||
const char **env, \
|
||||
int *exit_status, \
|
||||
int std[2])
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (current->type == NODE_PIPE)
|
||||
ft_pipe(current->pipefd, "in handle_command");
|
||||
check_and_expand_wildcards(¤t->args);
|
||||
if (is_buildin(current) && current->type != NODE_PIPE \
|
||||
&& current->was_pipe == false)
|
||||
{
|
||||
if (buildin_apply_pipe(current, exit_status))
|
||||
buildin_execute(current, env, exit_status);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = NULL;
|
||||
if (current->args && current->args[0] && current->args[0][0])
|
||||
{
|
||||
if (!is_buildin(current))
|
||||
path = find_absolute_path(\
|
||||
environment_variable_value_get("PATH", \
|
||||
env), current->args[0], exit_status);
|
||||
}
|
||||
execute_command(current, exit_status, std, path);
|
||||
}
|
||||
}
|
||||
83
minishell/minishell_src/ast/handle_fds.c
Normal file
83
minishell/minishell_src/ast/handle_fds.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_fds.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: andrejarama <andrejarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/25 18:17:10 by anarama #+# #+# */
|
||||
/* Updated: 2024/08/27 14:14:23 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
bool fd_out(t_ast *command, int *exit_status)
|
||||
{
|
||||
if (command->has_redir_out && command->path_file_out)
|
||||
{
|
||||
if (command->fd_out > 0)
|
||||
{
|
||||
ft_dup2(command->fd_out, STDOUT_FILENO, "in hanlde_fds_child");
|
||||
}
|
||||
else
|
||||
return (*exit_status = 1, false);
|
||||
}
|
||||
return (*exit_status = 0, true);
|
||||
}
|
||||
|
||||
bool handle_fds_child_proccess(t_ast *command, int32_t *exit_status)
|
||||
{
|
||||
if (command->has_redir_in && command->path_file_in != 0)
|
||||
{
|
||||
if (access(command->path_file_in, F_OK) == 0)
|
||||
{
|
||||
ft_open(&command->fd_in, command->path_file_in, O_RDONLY, 0644);
|
||||
if (command->is_heredoc == true)
|
||||
{
|
||||
command->is_heredoc = false;
|
||||
if (unlink(command->path_file_in))
|
||||
perror("unlink");
|
||||
ft_free(&command->path_file_in);
|
||||
}
|
||||
ft_dup2(command->fd_in, STDIN_FILENO, "in hanlde_fds_child");
|
||||
}
|
||||
else
|
||||
return (p_stderr(2, "minishell: %s: No such file or directory\n", \
|
||||
command->path_file_in), command->type = NODE_INVALID, \
|
||||
*exit_status = 1, false);
|
||||
}
|
||||
if (command->has_redir_out && command->path_file_out)
|
||||
return (fd_out(command, exit_status));
|
||||
return (*exit_status = 0, true);
|
||||
}
|
||||
|
||||
void handle_fds_parent_proccess(t_ast *command, int32_t *exit_status)
|
||||
{
|
||||
if (command->has_redir_in)
|
||||
{
|
||||
if (command->fd_in == -1 && command->path_file_in == 0)
|
||||
*exit_status = 1;
|
||||
if (command->is_heredoc == true && command->path_file_in)
|
||||
ft_free(&command->path_file_in);
|
||||
}
|
||||
if (command->has_redir_out && command->path_file_out && command->fd_out > 0)
|
||||
{
|
||||
ft_close(command->fd_out, "in hanlde_fds_parents");
|
||||
command->fd_out = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_pipe_in_child(t_ast *command)
|
||||
{
|
||||
ft_dup2(command->pipefd[1], STDOUT_FILENO, "dup2 in pipe_child");
|
||||
ft_close(command->pipefd[0], "close in pipe_child");
|
||||
ft_close(command->pipefd[1], "close in pipe_child");
|
||||
}
|
||||
|
||||
void handle_pipe_in_parent(t_ast *command)
|
||||
{
|
||||
ft_dup2(command->pipefd[0], STDIN_FILENO, "dup2 in pipe_parent");
|
||||
ft_close(command->pipefd[1], "close in pipe_parent");
|
||||
ft_close(command->pipefd[0], "close in pipe_parent");
|
||||
}
|
||||
85
minishell/minishell_src/ast/handle_heredoc.c
Normal file
85
minishell/minishell_src/ast/handle_heredoc.c
Normal file
@ -0,0 +1,85 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_heredoc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/21 11:15:25 by vvobis #+# #+# */
|
||||
/* Updated: 2025/02/15 14:59:42 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void remove_quotes(char *s)
|
||||
{
|
||||
uint i;
|
||||
|
||||
i = 0;
|
||||
if (!s)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] == '\'' || s[i] == '\"')
|
||||
{
|
||||
ft_memmove(&s[i], &s[i] + 1, ft_strlen(&s[i]));
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void print_value(char *value, int fd)
|
||||
{
|
||||
if (value && value[ft_strlen(value) - 1] == '\n')
|
||||
value[ft_strlen(value) - (ft_strlen(value) > 0)] = 0;
|
||||
ft_putendl_fd(value, fd);
|
||||
}
|
||||
|
||||
bool has_been_done_helper(t_token *token, char *value, \
|
||||
uint value_length, int fd)
|
||||
{
|
||||
char *token_value;
|
||||
bool has_been_done;
|
||||
|
||||
has_been_done = false;
|
||||
if (token->token_value)
|
||||
{
|
||||
token_value = token->token_value;
|
||||
token->token_type = TOKEN_DONE;
|
||||
while (token_value && *token_value)
|
||||
{
|
||||
if (*token_value++ == '\n')
|
||||
{
|
||||
if (ft_strncmp(token_value, value, value_length) == 0 \
|
||||
&& (*(token_value + value_length) == '\n' \
|
||||
|| *(token_value + value_length) == '\0'))
|
||||
{
|
||||
*token_value = 0;
|
||||
has_been_done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (print_value(token->token_value, fd), has_been_done);
|
||||
}
|
||||
|
||||
bool heredoc_has_been_done(t_token *token, char *value, int fd)
|
||||
{
|
||||
uint32_t value_length;
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
while (token[i].token_type != TOKEN_NEWLINE \
|
||||
&& token[i].token_type != TOKEN_EOL)
|
||||
i++;
|
||||
while ((token[i].token_type == TOKEN_NEWLINE \
|
||||
|| token[i].token_type == TOKEN_DONE) \
|
||||
&& token[i].token_type != TOKEN_EOL)
|
||||
i++;
|
||||
value_length = ft_strlen(value);
|
||||
if (token[i].token_type == TOKEN_EOL)
|
||||
return (false);
|
||||
return (has_been_done_helper(&token[i], value, value_length, fd));
|
||||
}
|
||||
144
minishell/minishell_src/ast/handle_redirs.c
Normal file
144
minishell/minishell_src/ast/handle_redirs.c
Normal file
@ -0,0 +1,144 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* handle_redirs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: andrejarama <andrejarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/22 11:56:47 by anarama #+# #+# */
|
||||
/* Updated: 2025/02/15 14:59:25 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
bool handle_temp(t_token *token)
|
||||
{
|
||||
char *was_variable;
|
||||
int32_t i;
|
||||
char **temp;
|
||||
|
||||
if (token->token_value && token->token_value[0] == '$')
|
||||
was_variable = token->token_value;
|
||||
else
|
||||
was_variable = NULL;
|
||||
temp = (char **)(char *[]){token->token_value, NULL};
|
||||
evaluate_input(&temp, &i, 0);
|
||||
token->token_value = temp[0];
|
||||
if (was_variable)
|
||||
if (temp[0][0] == 0)
|
||||
return (p_stderr(2, \
|
||||
"minishell: %s: ambiguos redirect\n", was_variable), false);
|
||||
return (true);
|
||||
}
|
||||
|
||||
void handle_redir_in(t_ast *branch, \
|
||||
t_token *token, \
|
||||
t_token *token_next)
|
||||
{
|
||||
if (token->token_type == TOKEN_REDIRECT_IN)
|
||||
{
|
||||
if (branch->path_file_in == 0 \
|
||||
|| ft_strncmp(token_next->token_value, branch->path_file_in, \
|
||||
ft_strlen(branch->path_file_in)) != 0)
|
||||
{
|
||||
if (handle_temp(token_next))
|
||||
{
|
||||
if (branch->has_redir_in)
|
||||
ft_close(branch->fd_in, "in hanlde_redir_in");
|
||||
branch->path_file_in = token_next->token_value;
|
||||
ft_open(&branch->fd_in, branch->path_file_in, O_RDONLY, 0);
|
||||
branch->has_redir_in = true;
|
||||
if (branch->fd_in == -1)
|
||||
branch->type = NODE_INVALID;
|
||||
}
|
||||
else
|
||||
branch->type = NODE_INVALID;
|
||||
}
|
||||
token->token_type = TOKEN_DONE;
|
||||
token_next->token_type = TOKEN_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_redir_out( t_ast *branch, \
|
||||
t_token *token, \
|
||||
t_token *token_next)
|
||||
{
|
||||
if (token->token_type == TOKEN_REDIRECT_OUT)
|
||||
{
|
||||
if (branch->path_file_out == 0 \
|
||||
|| ft_strncmp(token_next->token_value, branch->path_file_out, \
|
||||
ft_strlen(branch->path_file_out)) != 0)
|
||||
{
|
||||
if (handle_temp(token_next))
|
||||
{
|
||||
if (branch->has_redir_out == true)
|
||||
ft_close(branch->fd_out, "in branch redir_out");
|
||||
branch->path_file_out = token_next->token_value;
|
||||
ft_open(&branch->fd_out, branch->path_file_out, \
|
||||
O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
branch->has_redir_out = true;
|
||||
if (branch->fd_out == -1)
|
||||
branch->type = NODE_INVALID;
|
||||
}
|
||||
else
|
||||
branch->type = NODE_INVALID;
|
||||
}
|
||||
token->token_type = TOKEN_DONE;
|
||||
token_next->token_type = TOKEN_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_redir_append(t_ast *branch, \
|
||||
t_token *token, \
|
||||
t_token *token_next)
|
||||
{
|
||||
if (token->token_type == TOKEN_REDIRECT_APPEND)
|
||||
{
|
||||
if (branch->path_file_out == 0 \
|
||||
|| ft_strncmp(token_next->token_value, branch->path_file_out, \
|
||||
ft_strlen(branch->path_file_out)) != 0)
|
||||
{
|
||||
if (handle_temp(token_next))
|
||||
{
|
||||
branch->path_file_out = token_next->token_value;
|
||||
if (branch->has_redir_out == true)
|
||||
ft_close(branch->fd_out, "in branch redir_out");
|
||||
ft_open(&branch->fd_out, branch->path_file_out, \
|
||||
O_WRONLY | O_CREAT | O_APPEND, 0644);
|
||||
if (branch->fd_out == -1)
|
||||
branch->type = NODE_INVALID;
|
||||
branch->has_redir_out = true;
|
||||
}
|
||||
else
|
||||
branch->type = NODE_INVALID;
|
||||
}
|
||||
token->token_type = TOKEN_DONE;
|
||||
token_next->token_type = TOKEN_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_redir_heredoc( t_ast *branch, \
|
||||
t_token *token, \
|
||||
uint8_t token_id)
|
||||
{
|
||||
if (token->token_type == TOKEN_HEREDOC)
|
||||
{
|
||||
branch->path_file_in = ft_strdup((char []){'.', '/', '.', 't', \
|
||||
'm', 'p', token_id + 33, 0});
|
||||
branch->is_heredoc = true;
|
||||
ft_open(&branch->fd_in, branch->path_file_in, O_CREAT | O_WRONLY, 0644);
|
||||
remove_quotes(token[1].token_value);
|
||||
if (!heredoc_has_been_done(token, \
|
||||
token[1].token_value, branch->fd_in) && isatty(0))
|
||||
{
|
||||
token_heredoc_get(token, token[1].token_value);
|
||||
print_value(token->token_value, branch->fd_in);
|
||||
}
|
||||
ft_close(branch->fd_in, "fd_in in heredoc");
|
||||
branch->has_redir_in = true;
|
||||
token[0].token_type = TOKEN_DONE;
|
||||
token[1].token_type = TOKEN_DONE;
|
||||
}
|
||||
}
|
||||
125
minishell/minishell_src/ast/parse_tokens.c
Normal file
125
minishell/minishell_src/ast/parse_tokens.c
Normal file
@ -0,0 +1,125 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_tokens.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: anarama <anarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/20 17:46:26 by anarama #+# #+# */
|
||||
/* Updated: 2024/08/27 15:04:45 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
static void parse_branch(t_token *tokens, t_ast *branch)
|
||||
{
|
||||
int capacity;
|
||||
int count;
|
||||
uint32_t i;
|
||||
|
||||
count = 0;
|
||||
capacity = INITIAL_TOKEN_CAPACITY;
|
||||
branch->args = ft_calloc(capacity + 1, sizeof(char *));
|
||||
if (!branch->args)
|
||||
return (perror("calloc in parse tokens"), \
|
||||
lst_memory(NULL, NULL, CLEAN));
|
||||
i = -1;
|
||||
while (!is_delimiter_token(&tokens[++i]))
|
||||
{
|
||||
if (tokens[i].token_type != TOKEN_DONE)
|
||||
{
|
||||
fill_args(&branch->args, count++, tokens[i].token_value, &capacity);
|
||||
tokens[i].token_type = TOKEN_DONE;
|
||||
}
|
||||
}
|
||||
if (tokens[i].token_type == TOKEN_EOL)
|
||||
return ;
|
||||
if (branch->type != NODE_INVALID)
|
||||
branch->type = (t_node_type)tokens[i].token_type;
|
||||
tokens[i].token_type = TOKEN_DONE;
|
||||
}
|
||||
|
||||
static t_ast collect_redirection(t_token *token, \
|
||||
int has_syntax_error)
|
||||
{
|
||||
uint32_t i;
|
||||
t_ast branch;
|
||||
|
||||
i = 0;
|
||||
branch = (t_ast){0};
|
||||
branch.fd_in = STDIN_FILENO;
|
||||
branch.fd_out = STDOUT_FILENO;
|
||||
while (!is_delimiter_token(&token[i]) && branch.type != NODE_INVALID)
|
||||
{
|
||||
if (token[i + 1].token_type == TOKEN_SEMICOLON)
|
||||
token[i + 1].token_type = TOKEN_NEWLINE;
|
||||
if (token[i + 1].token_type == TOKEN_WORD)
|
||||
{
|
||||
if (!has_syntax_error)
|
||||
{
|
||||
handle_redir_in(&branch, &token[i], &token[i + 1]);
|
||||
handle_redir_out(&branch, &token[i], &token[i + 1]);
|
||||
handle_redir_append(&branch, &token[i], &token[i + 1]);
|
||||
}
|
||||
}
|
||||
if (has_syntax_error == 0)
|
||||
handle_redir_heredoc(&branch, &token[i], i);
|
||||
i++;
|
||||
}
|
||||
return (branch);
|
||||
}
|
||||
|
||||
void check_syntax_errors(t_token *token, int *error_catched)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (token[i].token_type != TOKEN_NEWLINE \
|
||||
&& token[i].token_type != TOKEN_EOL \
|
||||
&& token[i].token_type != TOKEN_SEMICOLON \
|
||||
&& *error_catched == 0)
|
||||
{
|
||||
if (token[i].token_type == TOKEN_REDIRECT_IN \
|
||||
|| token[i].token_type == TOKEN_REDIRECT_OUT \
|
||||
|| token[i].token_type == TOKEN_REDIRECT_APPEND \
|
||||
|| token[i].token_type == TOKEN_HEREDOC)
|
||||
check_valid_redir(token, i, error_catched);
|
||||
else if (token[i].token_type == TOKEN_PIPE)
|
||||
check_valid_pipe(token, i, error_catched);
|
||||
else if (token[i].token_type == TOKEN_AND \
|
||||
|| token[i].token_type == TOKEN_OR)
|
||||
check_valid_logical_operator(token, i, error_catched);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
t_ast *parse_tokens( t_token *tokens, \
|
||||
int32_t *exit_status)
|
||||
{
|
||||
t_ast *tree;
|
||||
int i;
|
||||
uint32_t tree_count;
|
||||
int has_syntax_error;
|
||||
|
||||
if (!tokens)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
tree_count = determine_trees(tokens);
|
||||
tree = ft_calloc(tree_count + 1, sizeof(t_ast));
|
||||
lst_memory(tree, tree_destroy, ADD);
|
||||
tree[tree_count].type = NODE_END;
|
||||
has_syntax_error = false;
|
||||
while (tree[i].type != NODE_END && !has_syntax_error)
|
||||
{
|
||||
check_syntax_errors(tokens, &has_syntax_error);
|
||||
tree[i] = collect_redirection(tokens, has_syntax_error);
|
||||
if (tree[i].type == NODE_INVALID)
|
||||
*exit_status = 1;
|
||||
parse_branch(tokens, &tree[i]);
|
||||
i++;
|
||||
}
|
||||
if (has_syntax_error != false)
|
||||
return (*exit_status = 2, lst_memory(tree, NULL, FREE), NULL);
|
||||
return (tree);
|
||||
}
|
||||
67
minishell/minishell_src/ast/parse_tokens_helper.c
Normal file
67
minishell/minishell_src/ast/parse_tokens_helper.c
Normal file
@ -0,0 +1,67 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_tokens_helper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/23 14:36:35 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/26 14:22:12 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
uint32_t determine_trees(t_token *tokens)
|
||||
{
|
||||
uint32_t tree_count;
|
||||
uint32_t i;
|
||||
bool has_heredoc;
|
||||
|
||||
i = 0;
|
||||
tree_count = 1;
|
||||
has_heredoc = false;
|
||||
while (tokens[i].token_type != TOKEN_EOL)
|
||||
{
|
||||
if (tokens[i].token_type == TOKEN_HEREDOC)
|
||||
has_heredoc = true;
|
||||
if (is_delimiter_token(&tokens[i]) || \
|
||||
(tokens[i].token_type == TOKEN_NEWLINE && has_heredoc == true))
|
||||
{
|
||||
has_heredoc = false;
|
||||
tree_count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (tree_count);
|
||||
}
|
||||
|
||||
void tree_destroy(void *tree_ptr)
|
||||
{
|
||||
uint32_t i;
|
||||
t_ast *tree;
|
||||
|
||||
i = 0;
|
||||
tree = (t_ast *)tree_ptr;
|
||||
while (tree && tree[i].type != NODE_END)
|
||||
{
|
||||
if (tree[i].has_redir_out == true)
|
||||
ft_close(tree[i].fd_out, "fd_out in tree_destroy");
|
||||
if (tree[i].is_heredoc)
|
||||
ft_free(&tree->path_file_in);
|
||||
if (tree[i].args)
|
||||
ft_free(&tree[i].args);
|
||||
i++;
|
||||
}
|
||||
ft_free(&tree);
|
||||
}
|
||||
|
||||
bool is_delimiter_token(t_token *token)
|
||||
{
|
||||
return (token->token_type == TOKEN_EOL \
|
||||
|| token->token_type == TOKEN_AND \
|
||||
|| token->token_type == TOKEN_OR \
|
||||
|| token->token_type == TOKEN_NEWLINE \
|
||||
|| token->token_type == TOKEN_PIPE \
|
||||
|| token->token_type == TOKEN_SEMICOLON);
|
||||
}
|
||||
44
minishell/minishell_src/ast/parser.c
Normal file
44
minishell/minishell_src/ast/parser.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parser.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: anarama <anarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/17 13:17:47 by anarama #+# #+# */
|
||||
/* Updated: 2024/08/10 22:20:35 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void **custom_realloc(void ***args, int old_capacity, int new_capacity)
|
||||
{
|
||||
void **new_args;
|
||||
|
||||
new_args = ft_calloc(new_capacity + 1, sizeof(void *));
|
||||
if (!new_args)
|
||||
{
|
||||
perror("Malloc failed while reallocing memory");
|
||||
lst_memory(NULL, NULL, CLEAN);
|
||||
}
|
||||
ft_memcpy(new_args, *args, old_capacity * sizeof(void *));
|
||||
free(*args);
|
||||
return (new_args);
|
||||
}
|
||||
|
||||
void fill_args(char ***args, int count, char *token_value, int *capacity)
|
||||
{
|
||||
if (count >= *capacity)
|
||||
{
|
||||
*args = (char **)custom_realloc((void ***)args,
|
||||
*capacity, *capacity * 2);
|
||||
if (!args)
|
||||
{
|
||||
perror("calloc in parse tokens");
|
||||
lst_memory(NULL, NULL, CLEAN);
|
||||
}
|
||||
*capacity *= 2;
|
||||
}
|
||||
(*args)[count] = token_value;
|
||||
}
|
||||
117
minishell/minishell_src/ast/syntax_check.c
Normal file
117
minishell/minishell_src/ast/syntax_check.c
Normal file
@ -0,0 +1,117 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* syntax_check.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: anarama <anarama@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/04 14:19:12 by anarama #+# #+# */
|
||||
/* Updated: 2024/08/26 14:18:42 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void check_valid_redir_helper(t_token *token, int index, int *error_catched)
|
||||
{
|
||||
if (token[index + 1].token_type == TOKEN_AND
|
||||
|| token[index + 1].token_type == TOKEN_OR)
|
||||
{
|
||||
print_error_logical_operator(token[index + 1].token_type);
|
||||
*error_catched = 1;
|
||||
}
|
||||
else if (token[index + 1].token_type == TOKEN_PIPE)
|
||||
return (print_error_pipe(), *error_catched = 1, (void)0);
|
||||
else if (token[index + 1].token_type == TOKEN_REDIRECT_IN \
|
||||
|| token[index + 1].token_type == TOKEN_REDIRECT_OUT \
|
||||
|| token[index + 1].token_type == TOKEN_REDIRECT_APPEND \
|
||||
|| token[index + 1].token_type == TOKEN_HEREDOC)
|
||||
{
|
||||
print_error_redir(token[index + 1].token_type);
|
||||
*error_catched = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void check_valid_redir(t_token *token, int index, int *error_catched)
|
||||
{
|
||||
if (token[index + 1].token_type == TOKEN_EOL \
|
||||
|| token[index + 1].token_type == TOKEN_NEWLINE \
|
||||
|| token[index + 1].token_type == 0 \
|
||||
|| (token[index + 1].token_type == TOKEN_WORD \
|
||||
&& token[index + 1].token_value == NULL))
|
||||
{
|
||||
ft_putendl_fd(\
|
||||
"minishell: syntax error near unexpected token `newline'", 2);
|
||||
*error_catched = 1;
|
||||
}
|
||||
check_valid_redir_helper(token, index, error_catched);
|
||||
}
|
||||
|
||||
void check_valid_pipe(t_token *token, int index, int *error_catched)
|
||||
{
|
||||
if (index == 0 || token[index + 1].token_type == 0 \
|
||||
|| token[index + 1].token_type == TOKEN_EOL
|
||||
|| (token[index + 1].token_type == TOKEN_WORD \
|
||||
&& token[index + 1].token_value == NULL))
|
||||
{
|
||||
print_error_pipe();
|
||||
*error_catched = 1;
|
||||
}
|
||||
else if (token[index + 1].token_type == TOKEN_AND
|
||||
|| token[index + 1].token_type == TOKEN_OR)
|
||||
{
|
||||
print_error_logical_operator(token[index + 1].token_type);
|
||||
*error_catched = 1;
|
||||
}
|
||||
else if (token[index + 1].token_type == TOKEN_PIPE)
|
||||
{
|
||||
print_error_pipe();
|
||||
*error_catched = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void check_valid_logical_operator( t_token *token, \
|
||||
int index, \
|
||||
int *error_catched)
|
||||
{
|
||||
if (index == 0 || token[index + 1].token_type == TOKEN_EOL \
|
||||
|| token[index + 1].token_type == TOKEN_NEWLINE \
|
||||
|| token[index + 1].token_type == 0)
|
||||
{
|
||||
print_error_logical_operator(token[index].token_type);
|
||||
*error_catched = 1;
|
||||
}
|
||||
else if (token[index + 1].token_type == TOKEN_AND
|
||||
|| token[index + 1].token_type == TOKEN_OR)
|
||||
{
|
||||
print_error_logical_operator(token[index + 1].token_type);
|
||||
*error_catched = 1;
|
||||
}
|
||||
else if (token[index + 1].token_type == TOKEN_PIPE)
|
||||
{
|
||||
print_error_pipe();
|
||||
*error_catched = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void check_valid_heredoc(t_token *token, int index, int *error_catched)
|
||||
{
|
||||
if (token[index + 1].token_value == 0 \
|
||||
|| *token[index + 1].token_value == 0 || token[index + 1].token_type == 0)
|
||||
{
|
||||
*error_catched = 2;
|
||||
if (token[index + 1].token_type == TOKEN_AND \
|
||||
|| token[index + 1].token_type == TOKEN_OR)
|
||||
print_error_logical_operator(token[index].token_type);
|
||||
else if (token[index + 1].token_type == TOKEN_PIPE)
|
||||
print_error_pipe();
|
||||
else if (token[index + 1].token_type == TOKEN_REDIRECT_IN \
|
||||
|| token[index + 1].token_type == TOKEN_REDIRECT_OUT \
|
||||
|| token[index + 1].token_type == TOKEN_REDIRECT_APPEND \
|
||||
|| token[index + 1].token_type == TOKEN_HEREDOC)
|
||||
print_error_redir(token[index + 1].token_type);
|
||||
else
|
||||
ft_putendl_fd(\
|
||||
"minishell: syntax error near unexpected token `newline'", 2);
|
||||
}
|
||||
}
|
||||
38
minishell/minishell_src/ast/syntax_check_helper.c
Normal file
38
minishell/minishell_src/ast/syntax_check_helper.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* syntax_check_helper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/23 14:38:50 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/23 14:40:12 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void print_error_logical_operator(t_token_type token_type)
|
||||
{
|
||||
if (token_type == TOKEN_AND)
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `&&'", 2);
|
||||
if (token_type == TOKEN_OR)
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `||'", 2);
|
||||
}
|
||||
|
||||
void print_error_pipe(void)
|
||||
{
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `|'", 2);
|
||||
}
|
||||
|
||||
void print_error_redir(t_token_type token_type)
|
||||
{
|
||||
if (token_type == TOKEN_REDIRECT_APPEND)
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `>>'", 2);
|
||||
else if (token_type == TOKEN_REDIRECT_IN)
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `<'", 2);
|
||||
else if (token_type == TOKEN_REDIRECT_OUT)
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `>'", 2);
|
||||
else if (token_type == TOKEN_HEREDOC)
|
||||
ft_putendl_fd("minishell: syntax error near unexpected token `<<'", 2);
|
||||
}
|
||||
BIN
minishell/minishell_src/bin/minishell
Executable file
BIN
minishell/minishell_src/bin/minishell
Executable file
Binary file not shown.
71
minishell/minishell_src/builtin/ft_cd.c
Normal file
71
minishell/minishell_src/builtin/ft_cd.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_cd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 14:10:08 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/27 16:57:49 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
static void pwd_update(const char **environment)
|
||||
{
|
||||
char *pwd;
|
||||
char *old_pwd;
|
||||
|
||||
pwd = getcwd(NULL, 0);
|
||||
if (!pwd)
|
||||
{
|
||||
perror("getcwd");
|
||||
lst_memory(NULL, NULL, CLEAN);
|
||||
}
|
||||
old_pwd = environment_variable_value_get("PWD", environment);
|
||||
environment_variable_value_change(environment, "OLDPWD", old_pwd);
|
||||
environment_variable_value_change(environment, "PWD", pwd);
|
||||
ft_free(&pwd);
|
||||
}
|
||||
|
||||
void cd_correct(char *args, const char **environment, int *exit_status)
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (ft_memcmp(args, "-\0", 2) == 0)
|
||||
{
|
||||
path = environment_variable_value_get("OLDPWD", environment);
|
||||
ft_putendl_fd(path, 1);
|
||||
}
|
||||
else
|
||||
path = args;
|
||||
if (chdir(path) != 0)
|
||||
return (*exit_status = 1, ft_putstr_fd("minishell: cd: ", 2), \
|
||||
perror(path));
|
||||
*exit_status = 0;
|
||||
}
|
||||
|
||||
void ft_cd( const char **environment, \
|
||||
const char **args, \
|
||||
int32_t *exit_status)
|
||||
{
|
||||
uint32_t args_size;
|
||||
char *path;
|
||||
|
||||
args_size = get_split_size((const char **)args);
|
||||
if (args_size > 2)
|
||||
return (*exit_status = 1, \
|
||||
ft_putendl_fd("minishell: cd: too many arguments", 2));
|
||||
else if (args_size == 1)
|
||||
{
|
||||
path = environment_variable_value_get("HOME", environment);
|
||||
if (chdir(path) != 0)
|
||||
return (*exit_status = 1, perror("cd"));
|
||||
*exit_status = 0;
|
||||
}
|
||||
else
|
||||
cd_correct((char *)args[1], environment, exit_status);
|
||||
if (*exit_status == 0)
|
||||
pwd_update((const char **)environment);
|
||||
}
|
||||
110
minishell/minishell_src/builtin/ft_echo.c
Normal file
110
minishell/minishell_src/builtin/ft_echo.c
Normal file
@ -0,0 +1,110 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_echo.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 11:39:04 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/22 10:30:26 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void trim_spaces(char *args)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t j;
|
||||
|
||||
i = 0;
|
||||
if (!args)
|
||||
return ;
|
||||
while (args[i])
|
||||
{
|
||||
j = i;
|
||||
while (ft_isspace(args[j]))
|
||||
j++;
|
||||
ft_memmove(&args[i], &args[j - (j > i && i > 0)], \
|
||||
ft_strlen(&args[i]) + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_dash_n(char *arg)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
if (arg[i] && arg[i] == '-')
|
||||
{
|
||||
while (arg[i] && arg[++i] == 'n')
|
||||
;
|
||||
if (arg[i] == 0)
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
int32_t echo_no_newline(char **args)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
while (args[i] && is_dash_n(args[i]))
|
||||
i++;
|
||||
while (args[i])
|
||||
{
|
||||
ft_putstr_fd(args[i], 1);
|
||||
if (*args[i] && args[i + 1])
|
||||
ft_putchar_fd(' ', 1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int32_t echo_newline(char **args, bool is_single)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
while (args[i + 1])
|
||||
{
|
||||
if (is_single)
|
||||
trim_spaces(args[i]);
|
||||
ft_putstr_fd(args[i], 1);
|
||||
ft_putchar_fd(' ', 1);
|
||||
i++;
|
||||
}
|
||||
if (is_single)
|
||||
trim_spaces(args[i]);
|
||||
if (args[i] && args[i][ft_strlen(args[i]) - \
|
||||
(ft_strlen(args[i]) > 0)] == '\n')
|
||||
ft_putstr_fd(args[i], 1);
|
||||
else
|
||||
ft_putendl_fd(args[i], 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int32_t ft_echo(char **args, int32_t *exit_status)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
*exit_status = 0;
|
||||
if (args[1])
|
||||
{
|
||||
if (ft_memcmp(args[1], "-n", 2) == 0)
|
||||
{
|
||||
while (args[1][++i] == 'n')
|
||||
;
|
||||
if (args[1][i] == 0)
|
||||
return (echo_no_newline(&args[2]), *exit_status = 0);
|
||||
}
|
||||
echo_newline(&args[1], 0);
|
||||
*exit_status = 0;
|
||||
}
|
||||
else
|
||||
ft_putchar_fd('\n', 1);
|
||||
return (0);
|
||||
}
|
||||
24
minishell/minishell_src/builtin/ft_env.c
Normal file
24
minishell/minishell_src/builtin/ft_env.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 13:56:33 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/04 10:31:19 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void ft_env(const char **environment, int32_t *exit_status)
|
||||
{
|
||||
if (!environment)
|
||||
*exit_status = 1;
|
||||
else
|
||||
{
|
||||
*exit_status = 0;
|
||||
environment_print(environment);
|
||||
}
|
||||
}
|
||||
88
minishell/minishell_src/builtin/ft_exit.c
Normal file
88
minishell/minishell_src/builtin/ft_exit.c
Normal file
@ -0,0 +1,88 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 16:52:07 by vvobis #+# #+# */
|
||||
/* Updated: 2025/02/15 14:59:55 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
bool check_exit_status(char *status)
|
||||
{
|
||||
char *number_string;
|
||||
int64_t number;
|
||||
uint8_t is_too_big;
|
||||
|
||||
if (!status || !*status)
|
||||
return (false);
|
||||
is_too_big = false;
|
||||
while (*status && *status == '0')
|
||||
status++;
|
||||
if (*status == '+' || *status == '0')
|
||||
status++;
|
||||
number = ft_atol(status, &is_too_big);
|
||||
if (is_too_big == true)
|
||||
return (false);
|
||||
number_string = ft_ltoa(number);
|
||||
if (!number_string)
|
||||
return (perror("malloc"), lst_memory(NULL, NULL, CLEAN), 0);
|
||||
if (ft_strncmp(status, number_string, ft_strlen(status)) == 0)
|
||||
return (ft_free(&number_string), true);
|
||||
ft_free(&number_string);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool exit_with_args( char **args, \
|
||||
bool *invalid_message_print, \
|
||||
uint32_t args_length, \
|
||||
int32_t *exit_status)
|
||||
{
|
||||
*invalid_message_print = check_exit_status(args[1]);
|
||||
if (*invalid_message_print && args_length == 2)
|
||||
*exit_status = ft_atol(args[1], \
|
||||
(uint8_t *)invalid_message_print);
|
||||
else if (!*invalid_message_print)
|
||||
{
|
||||
*exit_status = 2;
|
||||
p_stderr(2, "minishell: exit: %s: numeric argument required\n", \
|
||||
args[1]);
|
||||
}
|
||||
else if (*invalid_message_print && args_length > 2)
|
||||
return (ft_putendl_fd("minishell: exit: too many arguments", \
|
||||
2), 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
uint get_tree_size(t_ast *tree)
|
||||
{
|
||||
uint i;
|
||||
|
||||
i = 0;
|
||||
while (tree[i].type != NODE_END)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
void ft_exit(t_ast *tree, int *exit_status_prev)
|
||||
{
|
||||
uint32_t args_length;
|
||||
int32_t exit_status;
|
||||
bool invalid_message_print;
|
||||
|
||||
exit_status = *exit_status_prev;
|
||||
args_length = get_split_size((const char **)tree->args);
|
||||
invalid_message_print = false;
|
||||
ft_putendl_fd("exit", 2);
|
||||
if (args_length > 1)
|
||||
if (exit_with_args(tree->args, &invalid_message_print, \
|
||||
args_length, &exit_status))
|
||||
return ;
|
||||
wait_pids(tree, get_tree_size(tree), tree->cpid, NULL);
|
||||
lst_memory(NULL, NULL, END);
|
||||
exit(exit_status % 256);
|
||||
}
|
||||
122
minishell/minishell_src/builtin/ft_export.c
Normal file
122
minishell/minishell_src/builtin/ft_export.c
Normal file
@ -0,0 +1,122 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_export.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 14:41:32 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/19 23:26:58 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static void print_environment_a_la_export(char **env)
|
||||
{
|
||||
char *variable_name;
|
||||
char *variable_value;
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
while (env[i])
|
||||
{
|
||||
variable_name = env[i];
|
||||
variable_value = ft_strchr(variable_name, '=');
|
||||
if (variable_value)
|
||||
{
|
||||
*variable_value++ = 0;
|
||||
ft_printf("declare -x %s=\"%s\"\n", variable_name, variable_value);
|
||||
*--variable_value = '=';
|
||||
}
|
||||
else
|
||||
ft_printf("declare -x %s=\"\"\n", variable_name);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static void environment_print_sorted(const char **environment)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t length1;
|
||||
char *tmp;
|
||||
|
||||
i = 0;
|
||||
while (environment[i] && environment[i + 1])
|
||||
{
|
||||
tmp = ft_strchr(environment[i], '=');
|
||||
if (!tmp)
|
||||
tmp = ft_strchr(environment[i], 0);
|
||||
length1 = tmp - environment[i];
|
||||
if (ft_strncmp(environment[i], environment[i + 1], length1) > 0)
|
||||
{
|
||||
tmp = (char *)environment[i];
|
||||
environment[i] = environment[i + 1];
|
||||
environment[i + 1] = tmp;
|
||||
environment_print_sorted(environment);
|
||||
break ;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (environment[i + 1] == NULL)
|
||||
print_environment_a_la_export((char **)environment);
|
||||
}
|
||||
|
||||
static void print_sorted(const char **environment)
|
||||
{
|
||||
char **env;
|
||||
uint32_t i;
|
||||
|
||||
env = ft_calloc(get_split_size(environment) + 1, sizeof(*env));
|
||||
if (!env)
|
||||
return (perror("malloc"), lst_memory(NULL, NULL, CLEAN));
|
||||
i = -1;
|
||||
while (environment[++i])
|
||||
env[i] = (char *)environment[i];
|
||||
environment_print_sorted((const char **)env);
|
||||
ft_free(&env);
|
||||
}
|
||||
|
||||
bool is_allowed_char(const char *s)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
i = 0;
|
||||
if (!ft_isalpha(s[i]) && s[i] != '_')
|
||||
return (false);
|
||||
i++;
|
||||
while (s[i] && (ft_isalnum(s[i]) || s[i] == '_'))
|
||||
i++;
|
||||
if (s[i] == '=' || s[i] == 0)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
void ft_export(const char **args, int32_t *exit_status)
|
||||
{
|
||||
uint32_t i;
|
||||
char *variable_name;
|
||||
char *variable_value;
|
||||
char **environment;
|
||||
|
||||
environment = env_static(NULL);
|
||||
if (get_split_size(args) < 2)
|
||||
return (print_sorted((const char **)environment));
|
||||
i = 1;
|
||||
while (args[i])
|
||||
{
|
||||
if (!is_allowed_char(args[i]))
|
||||
return (p_stderr(2, \
|
||||
"minishell: export: `%s': not a valid identifier\n", \
|
||||
args[i]), *exit_status = 1, (void)0);
|
||||
variable_name = (char *)args[i];
|
||||
variable_value = ft_strchr(args[i], '=');
|
||||
if (variable_value)
|
||||
*variable_value++ = 0;
|
||||
environment_variable_add(&environment, variable_name, variable_value);
|
||||
i++;
|
||||
}
|
||||
*exit_status = 0;
|
||||
}
|
||||
28
minishell/minishell_src/builtin/ft_pwd.c
Normal file
28
minishell/minishell_src/builtin/ft_pwd.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pwd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: victor </var/spool/mail/victor> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 22:49:03 by victor #+# #+# */
|
||||
/* Updated: 2024/08/16 23:50:58 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void ft_pwd(const char **environment, int32_t *exit_status)
|
||||
{
|
||||
char *pwd;
|
||||
|
||||
if (!environment)
|
||||
*exit_status = 1;
|
||||
else
|
||||
{
|
||||
*exit_status = 0;
|
||||
pwd = getcwd(NULL, 0);
|
||||
ft_putendl_fd(pwd, 1);
|
||||
ft_free(&pwd);
|
||||
}
|
||||
}
|
||||
33
minishell/minishell_src/builtin/ft_unset.c
Normal file
33
minishell/minishell_src/builtin/ft_unset.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_unset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/24 14:29:41 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/10 22:25:27 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
void ft_unset(char **envivonment, const char **args, int32_t *exit_status)
|
||||
{
|
||||
uint32_t args_size;
|
||||
uint32_t i;
|
||||
|
||||
args_size = get_split_size(args);
|
||||
if (args_size < 2)
|
||||
return ;
|
||||
else if (args[1] && *args[1] == '-')
|
||||
return (ft_putendl_fd("unset: usage: unset [name ...]", \
|
||||
*exit_status = 2));
|
||||
i = 1;
|
||||
while (args[i])
|
||||
{
|
||||
environment_variable_remove(envivonment, args[i]);
|
||||
i++;
|
||||
}
|
||||
*exit_status = 0;
|
||||
}
|
||||
40
minishell/minishell_src/libft/Makefile
Normal file
40
minishell/minishell_src/libft/Makefile
Normal file
@ -0,0 +1,40 @@
|
||||
NAME := libft.a
|
||||
CC := cc
|
||||
CFLAGS:= -Wall -Wextra -Werror -g3
|
||||
SRC := ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isdigit.c \
|
||||
ft_isprint.c ft_memcpy.c ft_memmove.c ft_memset.c \
|
||||
ft_strlcat.c ft_strlcpy.c ft_strlen.c \
|
||||
ft_isascii.c ft_strchr.c ft_strrchr.c ft_strncmp.c \
|
||||
ft_toupper.c ft_tolower.c ft_memchr.c ft_strnstr.c \
|
||||
ft_atoi.c ft_memcmp.c ft_calloc.c ft_strdup.c \
|
||||
ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c \
|
||||
ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c \
|
||||
ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \
|
||||
get_next_line.c get_next_line_utils.c ft_puthex.c \
|
||||
ft_printf.c ft_putascii.c ft_putptr.c ft_free.c \
|
||||
ft_atol.c ft_ltoa.c
|
||||
SRCBON := ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c
|
||||
|
||||
OBJBON := $(SRC:%.c=%.o) $(SRCBON:%.c=%.o)
|
||||
|
||||
OBJ := $(SRC:%.c=%.o)
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
bonus: $(OBJBON)
|
||||
ar rcs libft.a $(OBJ) $(OBJBON)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
ar rcs libft.a $(OBJ)
|
||||
|
||||
$(OBJ): $(SRC)
|
||||
$(CC) -c $(CFLAGS) $(SRC)
|
||||
|
||||
re: fclean all
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(OBJBON)
|
||||
|
||||
42
minishell/minishell_src/libft/ft_atoi.c
Normal file
42
minishell/minishell_src/libft/ft_atoi.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/10 10:49:04 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/17 21:39:08 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int is_space(char const c)
|
||||
{
|
||||
if ((c >= 9 && c <= 13) || c == ' ')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_atoi(char const *s)
|
||||
{
|
||||
int nb;
|
||||
char const *tmp;
|
||||
|
||||
nb = 0;
|
||||
while (is_space(*s))
|
||||
s++;
|
||||
tmp = s;
|
||||
if (*tmp == '+' || *tmp == '-')
|
||||
tmp++;
|
||||
while (*tmp >= '0' && *tmp <= '9')
|
||||
{
|
||||
nb *= 10;
|
||||
nb += (*tmp - '0');
|
||||
tmp++;
|
||||
}
|
||||
if (*s == '-')
|
||||
nb = -nb;
|
||||
return (nb);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_atoi.o
Normal file
BIN
minishell/minishell_src/libft/ft_atoi.o
Normal file
Binary file not shown.
37
minishell/minishell_src/libft/ft_atol.c
Normal file
37
minishell/minishell_src/libft/ft_atol.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atol.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/10 10:49:04 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/26 21:00:15 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
long ft_atol(char const *s, uint8_t *too_big)
|
||||
{
|
||||
unsigned long long nb;
|
||||
char const *tmp;
|
||||
|
||||
nb = 0;
|
||||
while (is_space(*s))
|
||||
s++;
|
||||
tmp = s;
|
||||
if (*tmp == '+' || *tmp == '-')
|
||||
tmp++;
|
||||
while (*tmp >= '0' && *tmp <= '9')
|
||||
{
|
||||
nb *= 10;
|
||||
nb += (*tmp - '0');
|
||||
tmp++;
|
||||
if (nb > (uint64_t)LLONG_MAX + (*s == '-'))
|
||||
return (*too_big == 1);
|
||||
}
|
||||
if (*s == '-')
|
||||
nb = -nb;
|
||||
return (nb);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_atol.o
Normal file
BIN
minishell/minishell_src/libft/ft_atol.o
Normal file
Binary file not shown.
19
minishell/minishell_src/libft/ft_bzero.c
Normal file
19
minishell/minishell_src/libft/ft_bzero.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 16:04:55 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 20:54:53 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
while (n--)
|
||||
*(char *)s++ = 0;
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_bzero.o
Normal file
BIN
minishell/minishell_src/libft/ft_bzero.o
Normal file
Binary file not shown.
30
minishell/minishell_src/libft/ft_calloc.c
Normal file
30
minishell/minishell_src/libft/ft_calloc.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/04 13:44:00 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/10 16:39:56 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t n, size_t s)
|
||||
{
|
||||
char *tmp;
|
||||
unsigned long i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
return (malloc(0));
|
||||
if (SIZE_MAX / n < s)
|
||||
return (NULL);
|
||||
tmp = malloc(n * s);
|
||||
if (tmp)
|
||||
while (i < n * s)
|
||||
tmp[i++] = 0;
|
||||
return ((void *)tmp);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_calloc.o
Normal file
BIN
minishell/minishell_src/libft/ft_calloc.o
Normal file
Binary file not shown.
19
minishell/minishell_src/libft/ft_free.c
Normal file
19
minishell/minishell_src/libft/ft_free.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/13 15:23:16 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/10 22:39:49 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_free(void *ptr)
|
||||
{
|
||||
free(*(void **)ptr);
|
||||
*(void **)ptr = NULL;
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_free.o
Normal file
BIN
minishell/minishell_src/libft/ft_free.o
Normal file
Binary file not shown.
20
minishell/minishell_src/libft/ft_isalnum.c
Normal file
20
minishell/minishell_src/libft/ft_isalnum.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 15:59:18 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/02 15:59:23 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (ft_isdigit(c) || ft_isalpha(c))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_isalnum.o
Normal file
BIN
minishell/minishell_src/libft/ft_isalnum.o
Normal file
Binary file not shown.
20
minishell/minishell_src/libft/ft_isalpha.c
Normal file
20
minishell/minishell_src/libft/ft_isalpha.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 15:59:49 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/02 16:00:04 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_isalpha.o
Normal file
BIN
minishell/minishell_src/libft/ft_isalpha.o
Normal file
Binary file not shown.
20
minishell/minishell_src/libft/ft_isascii.c
Normal file
20
minishell/minishell_src/libft/ft_isascii.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 19:48:35 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/02 19:49:36 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_isascii.o
Normal file
BIN
minishell/minishell_src/libft/ft_isascii.o
Normal file
Binary file not shown.
18
minishell/minishell_src/libft/ft_isdigit.c
Normal file
18
minishell/minishell_src/libft/ft_isdigit.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 16:14:56 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/02 19:38:45 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_isdigit.o
Normal file
BIN
minishell/minishell_src/libft/ft_isdigit.o
Normal file
Binary file not shown.
18
minishell/minishell_src/libft/ft_isprint.c
Normal file
18
minishell/minishell_src/libft/ft_isprint.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 16:00:49 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/02 16:00:52 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_isprint.o
Normal file
BIN
minishell/minishell_src/libft/ft_isprint.o
Normal file
Binary file not shown.
75
minishell/minishell_src/libft/ft_itoa.c
Normal file
75
minishell/minishell_src/libft/ft_itoa.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/05 20:16:48 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/11 14:48:59 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int get_len(int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (n < 0)
|
||||
n = -n;
|
||||
i = 0;
|
||||
while (n)
|
||||
{
|
||||
i++;
|
||||
n /= 10;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char *is_negative(int n)
|
||||
{
|
||||
int i;
|
||||
char *num;
|
||||
|
||||
i = get_len(n);
|
||||
num = malloc(sizeof(*num) * i + 2);
|
||||
if (!num)
|
||||
return (NULL);
|
||||
num[i + 1] = 0;
|
||||
while (n)
|
||||
{
|
||||
num[i--] = -(n % 10) + 48;
|
||||
n /= 10;
|
||||
}
|
||||
num[i] = 0x2d;
|
||||
return (num);
|
||||
}
|
||||
|
||||
static char *is_positive(int n)
|
||||
{
|
||||
int i;
|
||||
char *num;
|
||||
|
||||
i = get_len(n);
|
||||
num = malloc(sizeof(*num) * i + 1);
|
||||
if (!num)
|
||||
return (NULL);
|
||||
num[i--] = 0;
|
||||
while (n)
|
||||
{
|
||||
num[i--] = (n % 10) + 48;
|
||||
n /= 10;
|
||||
}
|
||||
return (num);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
if (n == 0)
|
||||
return (ft_strdup("0"));
|
||||
else if (n < 0)
|
||||
return (is_negative(n));
|
||||
else
|
||||
return (is_positive(n));
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_itoa.o
Normal file
BIN
minishell/minishell_src/libft/ft_itoa.o
Normal file
Binary file not shown.
30
minishell/minishell_src/libft/ft_lstadd_back_bonus.c
Normal file
30
minishell/minishell_src/libft/ft_lstadd_back_bonus.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 13:51:32 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 18:17:12 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!new)
|
||||
return ;
|
||||
if (*lst)
|
||||
{
|
||||
tmp = *lst;
|
||||
while (tmp->next)
|
||||
tmp = tmp->next;
|
||||
tmp->next = new;
|
||||
}
|
||||
else
|
||||
*lst = new;
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstadd_back_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstadd_back_bonus.o
Normal file
Binary file not shown.
26
minishell/minishell_src/libft/ft_lstadd_front_bonus.c
Normal file
26
minishell/minishell_src/libft/ft_lstadd_front_bonus.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 12:53:08 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 18:17:50 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (!lst || !new)
|
||||
return ;
|
||||
if (!*lst)
|
||||
*lst = new;
|
||||
else
|
||||
{
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstadd_front_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstadd_front_bonus.o
Normal file
Binary file not shown.
28
minishell/minishell_src/libft/ft_lstclear_bonus.c
Normal file
28
minishell/minishell_src/libft/ft_lstclear_bonus.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 15:44:23 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 22:35:41 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!*lst || !del || !lst)
|
||||
return ;
|
||||
while (*lst)
|
||||
{
|
||||
tmp = (*lst)->next;
|
||||
del((*lst)->content);
|
||||
free(*lst);
|
||||
*lst = tmp;
|
||||
}
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstclear_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstclear_bonus.o
Normal file
Binary file not shown.
21
minishell/minishell_src/libft/ft_lstdelone_bonus.c
Normal file
21
minishell/minishell_src/libft/ft_lstdelone_bonus.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 14:24:03 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 15:42:04 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstdelone_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstdelone_bonus.o
Normal file
Binary file not shown.
24
minishell/minishell_src/libft/ft_lstiter_bonus.c
Normal file
24
minishell/minishell_src/libft/ft_lstiter_bonus.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 15:57:51 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 18:20:05 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!lst || !f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstiter_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstiter_bonus.o
Normal file
Binary file not shown.
22
minishell/minishell_src/libft/ft_lstlast_bonus.c
Normal file
22
minishell/minishell_src/libft/ft_lstlast_bonus.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 13:47:08 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 15:11:51 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstlast_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstlast_bonus.o
Normal file
Binary file not shown.
44
minishell/minishell_src/libft/ft_lstmap_bonus.c
Normal file
44
minishell/minishell_src/libft/ft_lstmap_bonus.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 16:18:03 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 23:40:57 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void *free_list(t_list **head, void (*del)(void *), void *fcontent)
|
||||
{
|
||||
if (fcontent)
|
||||
del(fcontent);
|
||||
ft_lstclear(head, del);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
t_list *head;
|
||||
void *fcontent;
|
||||
|
||||
if (!lst || !f || !del)
|
||||
return (NULL);
|
||||
head = NULL;
|
||||
while (lst)
|
||||
{
|
||||
fcontent = f(lst->content);
|
||||
if (!fcontent)
|
||||
return (free_list(&head, del, fcontent));
|
||||
tmp = ft_lstnew(fcontent);
|
||||
if (!tmp)
|
||||
return (free_list(&head, del, fcontent));
|
||||
ft_lstadd_back(&head, tmp);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (head);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstmap_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstmap_bonus.o
Normal file
Binary file not shown.
25
minishell/minishell_src/libft/ft_lstnew_bonus.c
Normal file
25
minishell/minishell_src/libft/ft_lstnew_bonus.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 11:10:05 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 18:59:48 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
tmp = malloc(sizeof(*tmp));
|
||||
if (!tmp)
|
||||
return (NULL);
|
||||
tmp->next = NULL;
|
||||
tmp->content = content;
|
||||
return (tmp);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstnew_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstnew_bonus.o
Normal file
Binary file not shown.
28
minishell/minishell_src/libft/ft_lstsize_bonus.c
Normal file
28
minishell/minishell_src/libft/ft_lstsize_bonus.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/09 13:43:08 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 18:21:11 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!lst)
|
||||
return (0);
|
||||
i = 1;
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_lstsize_bonus.o
Normal file
BIN
minishell/minishell_src/libft/ft_lstsize_bonus.o
Normal file
Binary file not shown.
75
minishell/minishell_src/libft/ft_ltoa.c
Normal file
75
minishell/minishell_src/libft/ft_ltoa.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ltoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/05 20:16:48 by vvobis #+# #+# */
|
||||
/* Updated: 2024/08/23 15:54:04 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int get_len(long long n)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (n < 0)
|
||||
n = -n;
|
||||
i = 0;
|
||||
while (n)
|
||||
{
|
||||
i++;
|
||||
n /= 10;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char *is_negative(long long n)
|
||||
{
|
||||
int i;
|
||||
char *num;
|
||||
|
||||
i = get_len(n);
|
||||
num = malloc(sizeof(*num) * i + 2);
|
||||
if (!num)
|
||||
return (NULL);
|
||||
num[i + 1] = 0;
|
||||
while (n)
|
||||
{
|
||||
num[i--] = -(n % 10) + 48;
|
||||
n /= 10;
|
||||
}
|
||||
num[i] = 0x2d;
|
||||
return (num);
|
||||
}
|
||||
|
||||
static char *is_positive(long long n)
|
||||
{
|
||||
int i;
|
||||
char *num;
|
||||
|
||||
i = get_len(n);
|
||||
num = malloc(sizeof(*num) * i + 1);
|
||||
if (!num)
|
||||
return (NULL);
|
||||
num[i--] = 0;
|
||||
while (n)
|
||||
{
|
||||
num[i--] = (n % 10) + 48;
|
||||
n /= 10;
|
||||
}
|
||||
return (num);
|
||||
}
|
||||
|
||||
char *ft_ltoa(long long n)
|
||||
{
|
||||
if (n == 0)
|
||||
return (ft_strdup("0"));
|
||||
else if (n < 0)
|
||||
return (is_negative(n));
|
||||
else
|
||||
return (is_positive(n));
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_ltoa.o
Normal file
BIN
minishell/minishell_src/libft/ft_ltoa.o
Normal file
Binary file not shown.
31
minishell/minishell_src/libft/ft_memchr.c
Normal file
31
minishell/minishell_src/libft/ft_memchr.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/03 15:13:59 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 20:55:24 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *p;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
p = (unsigned char *)s;
|
||||
while (i < n)
|
||||
{
|
||||
if (p[i] == (unsigned char)c)
|
||||
return ((void *)&p[i]);
|
||||
i++;
|
||||
}
|
||||
if (p[i - 1] == (unsigned char)c)
|
||||
return ((void *)&p[i]);
|
||||
return (NULL);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_memchr.o
Normal file
BIN
minishell/minishell_src/libft/ft_memchr.o
Normal file
Binary file not shown.
31
minishell/minishell_src/libft/ft_memcmp.c
Normal file
31
minishell/minishell_src/libft/ft_memcmp.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/03 15:27:15 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 19:21:02 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(void *s1, void const *s2, size_t n)
|
||||
{
|
||||
unsigned char *p1;
|
||||
unsigned char *p2;
|
||||
unsigned int i;
|
||||
|
||||
p1 = (unsigned char *)s1;
|
||||
p2 = (unsigned char *)s2;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (p1[i] != p2[i])
|
||||
return (p1[i] - p2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_memcmp.o
Normal file
BIN
minishell/minishell_src/libft/ft_memcmp.o
Normal file
Binary file not shown.
32
minishell/minishell_src/libft/ft_memcpy.c
Normal file
32
minishell/minishell_src/libft/ft_memcpy.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:13:18 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 19:21:29 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, void const *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
char *s;
|
||||
|
||||
if (n == 0 || (dest == NULL && src == NULL))
|
||||
return (dest);
|
||||
if (dest == NULL || src == NULL)
|
||||
{
|
||||
*(char *)dest = 1;
|
||||
*(char *)src = 1;
|
||||
}
|
||||
d = (char *) dest;
|
||||
s = (char *) src;
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
return (dest);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_memcpy.o
Normal file
BIN
minishell/minishell_src/libft/ft_memcpy.o
Normal file
Binary file not shown.
30
minishell/minishell_src/libft/ft_memmove.c
Normal file
30
minishell/minishell_src/libft/ft_memmove.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:42:28 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 19:21:54 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, void const *src, size_t n)
|
||||
{
|
||||
unsigned char *d;
|
||||
unsigned char *s;
|
||||
|
||||
if (!dest && !src)
|
||||
return (dest);
|
||||
d = (unsigned char *)dest;
|
||||
s = (unsigned char *)src;
|
||||
if (s < d)
|
||||
while (n--)
|
||||
d[n] = s[n];
|
||||
else
|
||||
ft_memcpy(dest, (void *)src, n);
|
||||
return (dest);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_memmove.o
Normal file
BIN
minishell/minishell_src/libft/ft_memmove.o
Normal file
Binary file not shown.
23
minishell/minishell_src/libft/ft_memset.c
Normal file
23
minishell/minishell_src/libft/ft_memset.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 15:57:27 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/03 11:18:10 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = (char *)s;
|
||||
while (n--)
|
||||
str[n] = c;
|
||||
return (s);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_memset.o
Normal file
BIN
minishell/minishell_src/libft/ft_memset.o
Normal file
Binary file not shown.
61
minishell/minishell_src/libft/ft_printf.c
Normal file
61
minishell/minishell_src/libft/ft_printf.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 17:50:35 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/26 16:54:14 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int handle_arg(va_list args, char format, int *count)
|
||||
{
|
||||
if (format == 'd' || format == 'i')
|
||||
ft_putnbr(va_arg(args, int), count);
|
||||
else if (format == 'u')
|
||||
ft_putnbr(va_arg(args, unsigned int), count);
|
||||
else if (format == 's')
|
||||
ft_putstr(va_arg(args, char *), count);
|
||||
else if (format == 'X')
|
||||
ft_puthex_upper(va_arg(args, unsigned int), count);
|
||||
else if (format == 'x')
|
||||
ft_puthex_lower(va_arg(args, unsigned int), count);
|
||||
else if (format == 'p')
|
||||
ft_putptr(va_arg(args, void *), count);
|
||||
else if (format == 'c')
|
||||
ft_putchar(va_arg(args, int), count);
|
||||
else if (format == '%')
|
||||
ft_putchar('%', count);
|
||||
else
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int count;
|
||||
|
||||
if (!format)
|
||||
return (-1);
|
||||
va_start(args, format);
|
||||
count = 0;
|
||||
while (1)
|
||||
{
|
||||
while (*format != '%' && *format)
|
||||
ft_putchar(*format++, &count);
|
||||
if (!*format)
|
||||
break ;
|
||||
else
|
||||
format++;
|
||||
if (!*format || !handle_arg(args, *format, &count))
|
||||
return (-1);
|
||||
format++;
|
||||
}
|
||||
va_end(args);
|
||||
return (count);
|
||||
}
|
||||
29
minishell/minishell_src/libft/ft_printf.h
Normal file
29
minishell/minishell_src/libft/ft_printf.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 12:50:35 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/18 20:47:09 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PRINTF_H
|
||||
|
||||
# define FT_PRINTF_H
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
void ft_puthex_lower(unsigned long nbr, int *count);
|
||||
void ft_puthex_upper(unsigned long nbr, int *count);
|
||||
void ft_putchar(int c, int *count);
|
||||
void ft_putnbr(long n, int *count);
|
||||
void ft_putstr(const char *str, int *count);
|
||||
void ft_putptr(void *ptr, int *count);
|
||||
|
||||
#endif
|
||||
BIN
minishell/minishell_src/libft/ft_printf.o
Normal file
BIN
minishell/minishell_src/libft/ft_printf.o
Normal file
Binary file not shown.
44
minishell/minishell_src/libft/ft_putascii.c
Normal file
44
minishell/minishell_src/libft/ft_putascii.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 17:54:53 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/18 17:55:04 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void ft_putchar(int c, int *count)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
*count += 1;
|
||||
}
|
||||
|
||||
void ft_putnbr(long n, int *count)
|
||||
{
|
||||
if (n < 0)
|
||||
ft_putchar(0x2d, count);
|
||||
if (n <= -10)
|
||||
ft_putnbr(n / -10, count);
|
||||
if (n >= 10)
|
||||
ft_putnbr(n / 10, count);
|
||||
if (n >= 0)
|
||||
ft_putchar(n % 10 + 0x30, count);
|
||||
if (n < 0)
|
||||
ft_putchar(-(n % -10) + 0x30, count);
|
||||
}
|
||||
|
||||
void ft_putstr(const char *str, int *count)
|
||||
{
|
||||
if (!str)
|
||||
{
|
||||
*count += ft_printf("(null)");
|
||||
return ;
|
||||
}
|
||||
while (*str)
|
||||
ft_putchar(*str++, count);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_putascii.o
Normal file
BIN
minishell/minishell_src/libft/ft_putascii.o
Normal file
Binary file not shown.
18
minishell/minishell_src/libft/ft_putchar_fd.c
Normal file
18
minishell/minishell_src/libft/ft_putchar_fd.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/07 17:34:30 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/07 17:53:33 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_putchar_fd.o
Normal file
BIN
minishell/minishell_src/libft/ft_putchar_fd.o
Normal file
Binary file not shown.
21
minishell/minishell_src/libft/ft_putendl_fd.c
Normal file
21
minishell/minishell_src/libft/ft_putendl_fd.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/07 17:57:33 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/07 18:00:49 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *str, int fd)
|
||||
{
|
||||
if (!str)
|
||||
return ;
|
||||
ft_putstr_fd(str, fd);
|
||||
ft_putchar_fd(0x0a, fd);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_putendl_fd.o
Normal file
BIN
minishell/minishell_src/libft/ft_putendl_fd.o
Normal file
Binary file not shown.
33
minishell/minishell_src/libft/ft_puthex.c
Normal file
33
minishell/minishell_src/libft/ft_puthex.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_puthex.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 17:52:38 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/18 20:46:13 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void ft_puthex_upper(unsigned long nbr, int *count)
|
||||
{
|
||||
char *base_str;
|
||||
|
||||
base_str = "0123456789ABCDEF";
|
||||
if (nbr >= 16)
|
||||
ft_puthex_upper(nbr / 16, count);
|
||||
ft_putchar(base_str[(nbr % 16)], count);
|
||||
}
|
||||
|
||||
void ft_puthex_lower(unsigned long nbr, int *count)
|
||||
{
|
||||
char *base_str;
|
||||
|
||||
base_str = "0123456789abcdef";
|
||||
if (nbr >= 16)
|
||||
ft_puthex_lower(nbr / 16, count);
|
||||
ft_putchar(base_str[(nbr % 16)], count);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_puthex.o
Normal file
BIN
minishell/minishell_src/libft/ft_puthex.o
Normal file
Binary file not shown.
27
minishell/minishell_src/libft/ft_putnbr_fd.c
Normal file
27
minishell/minishell_src/libft/ft_putnbr_fd.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/07 18:02:14 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/11 11:23:10 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (n < 0)
|
||||
ft_putchar_fd(0x2d, fd);
|
||||
if (n <= -10)
|
||||
ft_putnbr_fd(n / -10, fd);
|
||||
if (n >= 10)
|
||||
ft_putnbr_fd(n / 10, fd);
|
||||
if (n >= 0)
|
||||
ft_putchar_fd(n % 10 + 0x30, fd);
|
||||
if (n < 0)
|
||||
ft_putchar_fd(-(n % -10) + 0x30, fd);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_putnbr_fd.o
Normal file
BIN
minishell/minishell_src/libft/ft_putnbr_fd.o
Normal file
Binary file not shown.
27
minishell/minishell_src/libft/ft_putptr.c
Normal file
27
minishell/minishell_src/libft/ft_putptr.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putptr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/18 17:53:53 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/18 20:44:46 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void ft_putptr(void *ptr, int *count)
|
||||
{
|
||||
void **to_print;
|
||||
|
||||
if (!ptr)
|
||||
{
|
||||
*count += ft_printf("(nil)");
|
||||
return ;
|
||||
}
|
||||
to_print = &ptr;
|
||||
*count += ft_printf("0x");
|
||||
ft_puthex_lower((long)*to_print, count);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_putptr.o
Normal file
BIN
minishell/minishell_src/libft/ft_putptr.o
Normal file
Binary file not shown.
21
minishell/minishell_src/libft/ft_putstr_fd.c
Normal file
21
minishell/minishell_src/libft/ft_putstr_fd.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/07 17:48:41 by vvobis #+# #+# */
|
||||
/* Updated: 2024/07/31 10:01:48 by victor ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(const char *str, int fd)
|
||||
{
|
||||
if (!str)
|
||||
return ;
|
||||
while (*str)
|
||||
ft_putchar_fd(*str++, fd);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_putstr_fd.o
Normal file
BIN
minishell/minishell_src/libft/ft_putstr_fd.o
Normal file
Binary file not shown.
84
minishell/minishell_src/libft/ft_split.c
Normal file
84
minishell/minishell_src/libft/ft_split.c
Normal file
@ -0,0 +1,84 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/05 20:14:20 by vvobis #+# #+# */
|
||||
/* Updated: 2024/06/14 16:06:51 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int count(char const *s, char const c)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
if (*s != c && *s)
|
||||
n = 1;
|
||||
while (*s)
|
||||
{
|
||||
if (*s == c && *(s + 1) != c && *(s + 1))
|
||||
n++;
|
||||
s++;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
static int count_sub(char const *s, char const c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (*s != c && *s)
|
||||
{
|
||||
i++;
|
||||
s++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char **free_all(char **back)
|
||||
{
|
||||
char **tmp;
|
||||
|
||||
tmp = back;
|
||||
while (*back)
|
||||
{
|
||||
free(*back);
|
||||
back++;
|
||||
}
|
||||
free(tmp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char const c)
|
||||
{
|
||||
char **tmp;
|
||||
char **back;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
tmp = (char **)ft_calloc(sizeof(*tmp), count(s, c) + 1);
|
||||
if (!tmp)
|
||||
return (NULL);
|
||||
back = tmp;
|
||||
while (*s && tmp)
|
||||
{
|
||||
while (*s == c && *s)
|
||||
s++;
|
||||
if (*s)
|
||||
{
|
||||
*tmp = ft_substr(s, 0, count_sub(s, c));
|
||||
if (!*tmp)
|
||||
return (free_all(back));
|
||||
}
|
||||
tmp++;
|
||||
while (*s != c && *s)
|
||||
s++;
|
||||
}
|
||||
return (back);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_split.o
Normal file
BIN
minishell/minishell_src/libft/ft_split.o
Normal file
Binary file not shown.
29
minishell/minishell_src/libft/ft_strchr.c
Normal file
29
minishell/minishell_src/libft/ft_strchr.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/03 12:20:50 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 20:54:14 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(char const *s, int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)&s[i]);
|
||||
i++;
|
||||
}
|
||||
if ((char)c == 0)
|
||||
return ((char *)&s[i]);
|
||||
return (NULL);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_strchr.o
Normal file
BIN
minishell/minishell_src/libft/ft_strchr.o
Normal file
Binary file not shown.
31
minishell/minishell_src/libft/ft_strdup.c
Normal file
31
minishell/minishell_src/libft/ft_strdup.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/04 18:44:05 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/12 10:44:23 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(char const *s)
|
||||
{
|
||||
char *tmp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
tmp = ft_calloc(ft_strlen(s) + 1, sizeof(*tmp));
|
||||
if (!tmp)
|
||||
return (NULL);
|
||||
while (s[i])
|
||||
{
|
||||
tmp[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
tmp[i] = 0;
|
||||
return (tmp);
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_strdup.o
Normal file
BIN
minishell/minishell_src/libft/ft_strdup.o
Normal file
Binary file not shown.
27
minishell/minishell_src/libft/ft_striteri.c
Normal file
27
minishell/minishell_src/libft/ft_striteri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvobis <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/07 17:24:08 by vvobis #+# #+# */
|
||||
/* Updated: 2024/04/09 19:27:07 by vvobis ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char const *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!s || !f)
|
||||
return ;
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, (char *)&s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
BIN
minishell/minishell_src/libft/ft_striteri.o
Normal file
BIN
minishell/minishell_src/libft/ft_striteri.o
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user