Compare commits
2 Commits
6ab114eeeb
...
4533b7a75d
Author | SHA1 | Date | |
---|---|---|---|
|
4533b7a75d | ||
|
cf4bacd42e |
BIN
a.out → .execution.c.swp
Executable file → Normal file
BIN
a.out → .execution.c.swp
Executable file → Normal file
Binary file not shown.
BIN
.main.c.swp
BIN
.main.c.swp
Binary file not shown.
2
Makefile
2
Makefile
@ -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
|
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
|
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c ft_split_quoted.c env.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
24
d
24
d
@ -1,24 +0,0 @@
|
|||||||
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
Normal file
194
env.c
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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 **)(¤t->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 **)(¤t->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);
|
||||||
|
}*/
|
29
execution.c
29
execution.c
@ -7,32 +7,27 @@ int main(int ac, char **av, char **env)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ft_get_executable_path(t_data *data, char *executable)
|
/* char *ft_get_executable_path(t_data *data, char *executable) */
|
||||||
{
|
/* { */
|
||||||
if (ft_strcmp(executable, "env"))
|
/* if (ft_strcmp(executable, "env") == 0) */
|
||||||
return (ft_strjoin("/usr/bin/bo", const char *s2))
|
/* return (ft_strjoin("", executable)); */
|
||||||
}
|
/* else */
|
||||||
|
/* return */
|
||||||
|
/* } */
|
||||||
|
|
||||||
int ft_excutor(t_cmd *cmd, )
|
int ft_excutor(t_cmd *cmd)
|
||||||
{
|
{
|
||||||
char cmd[13] = "/usr/bin/ls";
|
|
||||||
char *args[3] = {NULL, "cat", NULL};
|
|
||||||
int pid;
|
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();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
return (1);
|
return (1);
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
dup2(fd_out, 1);
|
dup2(cmd->fd_out, 1);
|
||||||
dup2(fd_in, 0);
|
dup2(cmd->fd_in, 0);
|
||||||
execve(cmd, args, env);
|
//TODO ADD ENV VARIABLES
|
||||||
|
execve(cmd->executable, cmd->args, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
waitpid(pid);
|
waitpid(pid);
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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/libftx.a
BIN
libftx/libftx.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26
minishell.h
26
minishell.h
@ -1,13 +1,18 @@
|
|||||||
#ifndef FT_MINISHELL
|
#ifndef MINISHELL_H
|
||||||
# define FT_MINISHELL
|
# define MINISHELL_H
|
||||||
# include "libftx/libftx.h"
|
# include "libftx/libftx.h"
|
||||||
# include "utils/utils.h"
|
# include "utils/utils.h"
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
#include <stdio.h>
|
# include <sys/wait.h>
|
||||||
#include <readline/readline.h>
|
# include <stdio.h>
|
||||||
#include <readline/history.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);
|
||||||
|
|
||||||
int ft_syntatic_verif(const char *str);
|
int ft_syntatic_verif(const char *str);
|
||||||
int ft_file_is_readable(const char *path);
|
int ft_file_is_readable(const char *path);
|
||||||
@ -21,10 +26,15 @@ char **ft_split_quoted(const char *s, char c);
|
|||||||
|
|
||||||
typedef struct s_cmd
|
typedef struct s_cmd
|
||||||
{
|
{
|
||||||
int fd_in;
|
int fd_in;
|
||||||
int fd_out;
|
int fd_out;
|
||||||
char *executable;
|
char *executable;
|
||||||
char **args;
|
char **args;
|
||||||
} t_cmd;
|
} t_cmd;
|
||||||
|
|
||||||
|
typedef struct s_data
|
||||||
|
{
|
||||||
|
t_list **env;
|
||||||
|
} t_data;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
BIN
syntatics.o
BIN
syntatics.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user