Compare commits

..

No commits in common. "373629b541a8d1dbc4a93246ade6c399bdff0dd4" and "ca09c8ed26f568c186dcf51d68e4a36aaeae95d3" have entirely different histories.

12 changed files with 28 additions and 169 deletions

View File

@ -1,5 +1,5 @@
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c cd.c builtins/export.c builtins/env.c
OBJS = ${SRCS:.c=.o}

7
env2.c
View File

@ -1,3 +1,4 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env2.c :+: :+: :+: */
@ -9,7 +10,6 @@
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
int get_index(char *s, char c)
@ -46,14 +46,9 @@ void env_del(void *ptr)
{
t_env *content;
if (ptr == NULL)
return ;
content = ptr;
if (content->key != NULL)
free(content->key);
if (content->key != NULL)
free(content->value);
if (content != NULL)
free(content);
}

26
env3.c
View File

@ -6,11 +6,10 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
/* Updated: 2023/02/21 14:09:42 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 17:31:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
char *get_value(char *str)
@ -38,26 +37,3 @@ char *get_key(char *str)
s[i] = str[i];
return (s);
}
int create_value_by_key_dup(char *key, char *value, t_list **env)
{
char *key_dup;
char *value_dup;
key_dup = ft_strdup(key);
if (key_dup == NULL)
{
ft_eprintf("minishell: malloc failed\n");
return (1);
}
value_dup = ft_strdup(value);
if (value_dup == NULL)
{
free(key);
ft_eprintf("minishell: malloc failed\n");
return (1);
}
if (create_value_by_key(key_dup, value_dup, env))
return (1);
return (0);
}

View File

@ -1,17 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* execution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
/* Updated: 2023/02/21 13:48:39 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
#include "utils/utils.h"
#include <unistd.h>
static char *ft_get_executable_path(char *executable_name, t_list **env)
{
@ -93,31 +83,10 @@ static int ft_excutor(t_cmd *cmd, t_list **env)
return (return_value);
}
static int ft_own_cmd(t_list **env, t_cmd *cmd)
{
/* if (ft_strcmp(cmd->executable, "pwd") == 0) */
/* return (pwd(env, cmd->fd_out)); */
if (ft_strcmp(cmd->executable, "env") == 0)
return (print_env(env, cmd->fd_out));
if (ft_strcmp(cmd->executable, "export") == 0)
return (print_export(env, cmd->fd_out));
/* if (ft_strcmp(cmd->executable, "cd") == 0) */
/* return (move_folder(cmd->args[0], cmd->fd_out)); */
/* if (ft_strcmp(cmd->executable, "unset") == 0) */
/* return (unset(env, cmd->args, cmd->fd_out)); */
/* if (ft_strcmp(cmd->executable, "echo") == 0) */
/* return (echo(cmd->fd_out, cmd->args[0])); */
if (ft_strcmp(cmd->executable, "exit") == 0)
return (-2);
return (-1);
}
int ft_cmds_executor(t_list **cmds, t_list **env)
{
t_cmd *content;
t_list *current;
char *return_value;
int cmd_return;
int fds[2];
current = *cmds;
@ -134,25 +103,13 @@ int ft_cmds_executor(t_list **cmds, t_list **env)
content->fd_out = fds[1];
((t_cmd *) current->next->content)->fd_in = fds[0];
}
cmd_return = ft_own_cmd(env, content);
if (cmd_return == -1)
{
content->executable = ft_get_executable_path(
content->executable, env);
content->executable = ft_get_executable_path(content->executable, env);
if (content->executable != NULL)
cmd_return = ft_excutor(content, env);
}
ft_excutor(content, env);
if (content->fd_in != 0)
close(content->fd_in);
if (content->fd_out != 1 && content->fd_out != 2)
close(content->fd_out);
return_value = ft_itoa(cmd_return);
if (return_value == NULL)
{
ft_eprintf("minishell: malloc failed\n");
return (1);
}
set_value_by_key("?", return_value, env);
current = current->next;
}
return (0);

10
main.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
/* Updated: 2023/02/21 14:24:45 by cchauvet ### ########.fr */
/* Updated: 2023/02/20 15:24:42 by starnakin ### ########.fr */
/* */
/* ************************************************************************** */
@ -108,13 +108,7 @@ int main(int ac, char **av, char **env)
data.env = init_env(env);
if (data.env == NULL)
return (1);
if (create_value_by_key_dup("", "$", data.env) == 1
|| create_value_by_key_dup("?", "0", data.env) == 1)
{
ft_lstclear(data.env, env_del);
free(data.env);
return (1);
}
create_value_by_key("", "$", data.env);
line = ft_get_user_input(data.env);
if (line == NULL)
{

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
/* Updated: 2023/02/21 14:09:21 by cchauvet ### ########.fr */
/* Updated: 2023/02/21 13:22:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,7 +46,6 @@ char **env_to_strs(t_list **head);
t_list **init_env(char **env);
char **env_to_strs(t_list **head);
int create_value_by_key(char *key, char *value, t_list **head);
int create_value_by_key_dup(char *key, char *value, t_list **head);
int set_value_by_key(char *key, char *value, t_list **head);
char *get_value_by_key(char *key, t_list **head);
int get_index(char *s, char c);

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntatics.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
/* Updated: 2023/02/21 13:00:06 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
#include "utils/utils.h"

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:43 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int ft_is_in_quote(const char *str, size_t n)
@ -27,11 +15,13 @@ int ft_is_in_quote(const char *str, size_t n)
{
if (simple_quoted == 0)
double_quoted = !double_quoted;
}
if (str[i] == '\'')
{
if (double_quoted == 0)
simple_quoted = !simple_quoted;
}
i++;
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
/* Updated: 2023/02/21 14:33:28 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 18:27:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,6 @@ char *ft_quote_remover(char *str)
ssize_t stop;
start = -1;
stop = -1;
i = 0;
while (str[i] != '\0')
{
@ -28,18 +27,17 @@ char *ft_quote_remover(char *str)
if (start == -1)
start = i;
else if (str[i] == str[start])
{
stop = i;
break ;
}
if (stop != -1)
}
i++;
}
if (start != -1)
{
ft_strshift(str + start, -1);
ft_strshift(str + stop - 1, -1);
start = -1;
stop = -1;
i = i - 2;
}
else
i++;
}
return (str);
}

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:06 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:07 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
ssize_t ft_strnchr(const char *str, char c)

View File

@ -1,15 +1,3 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:16 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:59:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
size_t ft_strncpy(char *dst, const char *src, size_t n)

View File

@ -1,25 +1,11 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strreplace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:46:20 by cchauvet #+# #+# */
/* Updated: 2023/02/21 12:58:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
char *ft_strreplace(const char *str, const char *fill,
size_t start, size_t stop)
char *ft_strreplace(const char *str, const char *fill, size_t start, size_t stop)
{
char *out;
size_t sum;
out = malloc((ft_strlen(str) + ft_strlen(fill) -\
(stop - start) + 1 * sizeof(char)));
out = malloc((ft_strlen(str) + ft_strlen(fill) - (stop - start) + 1 * sizeof(char)));
if (out == NULL)
return (NULL);
ft_strncpy(out, str, start);