Compare commits

..

No commits in common. "4533b7a75da17bf932030e676fcefddb4f36e48b" and "6ab114eeeb5157198bfe4934b791f4353c497fa8" have entirely different histories.

101 changed files with 52 additions and 227 deletions

BIN
.main.c.swp Normal file

Binary file not shown.

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_getstr.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c ft_split_quoted.c env.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c ft_split_quoted.c
OBJS = ${SRCS:.c=.o}

BIN
.execution.c.swp → a.out Normal file → Executable file

Binary file not shown.

24
d Executable file
View File

@ -0,0 +1,24 @@
a.out
argprinter
d
execution.c
file.c
file.o
ft_split_quoted.c
ft_split_quoted.o
heredoc.c
heredoc.o
infile.c
infile.o
libftx
main.c
main.o
Makefile
minishell
minishell.h
outfile.c
outfile.o
syntatics.c
syntatics.o
t
utils

194
env.c
View File

@ -1,194 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/02/03 16:04:16 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int get_index(char *s, char c)
{
int i;
i = -1;
while (s[++i])
if (s[i] == c)
return (i);
return (-1);
}
void print_export(t_list **head, int fd)
{
t_list *current;
char *ctn;
int v;
current = *head;
while (current != NULL)
{
ctn = current->content;
if (*(ft_strchr(ctn, '=') - 1) != '_')
{
v = get_index(ctn, '=');
write(fd, "declare -x ", 11);
write(fd, ctn, v + 1);
write(fd, "\"", 1);
ft_putstr_fd(ctn + v + 1, fd);
write(fd, "\"\n", 2);
}
current = current->next;
}
}
void print_env(t_list **head, int fd)
{
t_list *current;
current = *head;
while (current != NULL)
{
ft_putstr_fd(current->content, fd);
write(fd, "\n", 1);
current = current->next;
}
}
int strcmp_alphabet(char *s1, char *s2)
{
int i;
if (!s1 || !s2)
return (-2);
i = 0;
while (s1[i] && s2[i])
{
if (s1[i] < s2[i])
return (0);
else if (s1[i] > s2[i])
return (1);
i++;
}
return (-1);
}
void ft_double_swap(char **a, char **b)
{
void *c;
c = *a;
*a = *b;
*b = c;
}
void exchange(char **a, char **b, char **c)
{
void *d;
d = *a;
*a = *b;
*b = *c;
*c = d;
}
void add_sort(t_list **head, char *str)
{
t_list *current;
char *last;
current = *head;
while (current->next != NULL && strcmp_alphabet(str, current->content) != 0)
current = current->next;
if (strcmp_alphabet(str, current->content) == 1)
last = str;
else
exchange(&last, (char **)(&current->content), &str);
while (current != NULL)
{
if (current->next == NULL)
current->next = ft_calloc(1, sizeof(t_list));
if (current->next == NULL)
return ;
current = current->next;
if (current->content == NULL)
{
current->content = last;
return ;
}
else
ft_double_swap((char **)(&current->content), &last);
}
}
char *get_value_index(int index, t_list **head)
{
t_list *current;
int i;
current = *head;
i = -1;
while (current != NULL && ++i != index)
current = current->next;
if (i == index)
return (ft_strchr(current->content, '=') + 1);
return (NULL);
}
int is_start(char *big, char *little)
{
int i;
i = 0;
while (big[i])
{
if (little[i] != big[i])
return (0);
i++;
if (!little[i])
return (1);
}
return (0);
}
char *get_value_key(char *key, t_list **head)
{
t_list *current;
current = *head;
while (current != NULL)
{
if (is_start(current->content, key))
return (ft_strchr(current->content, '=') + 1);
current = current->next;
}
return (NULL);
}
t_list **init_env(char **env)
{
t_list **head;
int i;
head = ft_calloc(1, sizeof(t_list *));
*head = ft_calloc(1, sizeof(t_list));
if (*head == NULL)
return (NULL);
i = -1;
while (env[++i])
add_sort(head, env[i]);
return (head);
}
/*int main(int argc, char *argv[], char **env)
{
(void)argc;
(void)argv;
ft_putstr_fd(get_value_index(10, init_env(env)), 1);
//print_env(init_env(env), 1);
return (0);
}*/

View File

@ -7,27 +7,32 @@ int main(int ac, char **av, char **env)
}
/* char *ft_get_executable_path(t_data *data, char *executable) */
/* { */
/* if (ft_strcmp(executable, "env") == 0) */
/* return (ft_strjoin("", executable)); */
/* else */
/* return */
/* } */
int ft_excutor(t_cmd *cmd)
char *ft_get_executable_path(t_data *data, char *executable)
{
int pid;
if (ft_strcmp(executable, "env"))
return (ft_strjoin("/usr/bin/bo", const char *s2))
}
int ft_excutor(t_cmd *cmd, )
{
char cmd[13] = "/usr/bin/ls";
char *args[3] = {NULL, "cat", NULL};
int pid;
int fd_in;
int fd_out;
if (ac != 3)
return (1);
fd_out = open(av[2], O_WRONLY | O_CREAT | O_TRUNC);
fd_in = open(av[1], O_RDONLY);
pid = fork();
if (pid == -1)
return (1);
if (pid == 0)
{
dup2(cmd->fd_out, 1);
dup2(cmd->fd_in, 0);
//TODO ADD ENV VARIABLES
execve(cmd->executable, cmd->args, NULL);
dup2(fd_out, 1);
dup2(fd_in, 0);
execve(cmd, args, env);
}
else
waitpid(pid);

BIN
file.o Normal file

Binary file not shown.

BIN
ft_split_quoted.o Normal file

Binary file not shown.

BIN
heredoc.o Normal file

Binary file not shown.

BIN
infile.o Normal file

Binary file not shown.

BIN
libftx/extra/extra.a Normal file

Binary file not shown.

Binary file not shown.

BIN
libftx/extra/ft_freer.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_is_in.o Normal file

Binary file not shown.

Binary file not shown.

BIN
libftx/extra/ft_strchri.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strcmp.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strfjoin.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strgen.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strmerger.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_strndup.o Normal file

Binary file not shown.

BIN
libftx/extra/ft_swap.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/gnl/get_next_line.a Normal file

Binary file not shown.

BIN
libftx/gnl/get_next_line.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_atoi.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_bzero.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_calloc.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isalnum.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isalpha.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isascii.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isdigit.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_isprint.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_itoa.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/libft/ft_lstclear.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstdelone.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstiter.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstlast.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstmap.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstnew.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_lstsize.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memchr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memcmp.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memcpy.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memmove.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_memset.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/libft/ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_putstr_fd.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_split.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strchr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strdup.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_striteri.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strjoin.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strlcat.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strlcpy.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strlen.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strmapi.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strncmp.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strnstr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strrchr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_strtrim.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_substr.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_tolower.o Normal file

Binary file not shown.

BIN
libftx/libft/ft_toupper.o Normal file

Binary file not shown.

BIN
libftx/libft/libft.a Normal file

Binary file not shown.

BIN
libftx/libftx.a Normal file

Binary file not shown.

BIN
libftx/printf/ft_dprintX.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/printf/ft_dprintul.o Normal file

Binary file not shown.

Binary file not shown.

BIN
libftx/printf/ft_dprintx.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_eprintf.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_isarg.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_isdigit.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_printf.a Normal file

Binary file not shown.

BIN
libftx/printf/ft_printf.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libftx/printf/ft_skipflag.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_strlen.o Normal file

Binary file not shown.

BIN
libftx/printf/ft_vdprintf.o Normal file

Binary file not shown.

BIN
main.o Normal file

Binary file not shown.

BIN
minishell Executable file

Binary file not shown.

View File

@ -1,18 +1,13 @@
#ifndef MINISHELL_H
# define MINISHELL_H
#ifndef FT_MINISHELL
# define FT_MINISHELL
# include "libftx/libftx.h"
# include "utils/utils.h"
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <sys/wait.h>
# include <stdio.h>
# include <readline/readline.h>
# include <readline/history.h>
t_list **init_env(char **env);
char *get_value_index(int index, t_list **head);
char *get_value_key(char *key, t_list **head);
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
int ft_syntatic_verif(const char *str);
int ft_file_is_readable(const char *path);
@ -26,15 +21,10 @@ char **ft_split_quoted(const char *s, char c);
typedef struct s_cmd
{
int fd_in;
int fd_out;
int fd_in;
int fd_out;
char *executable;
char **args;
} t_cmd;
typedef struct s_data
{
t_list **env;
} t_data;
} t_cmd;
#endif

BIN
outfile.o Normal file

Binary file not shown.

BIN
syntatics.o Normal file

Binary file not shown.

0
t Normal file
View File

BIN
utils/ft_getstr.o Normal file

Binary file not shown.

BIN
utils/ft_is_in_quote.o Normal file

Binary file not shown.

BIN
utils/ft_strnchr.o Normal file

Binary file not shown.

BIN
utils/ft_strncpy.o Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More