diff --git a/.env.c.swp b/.env.c.swp deleted file mode 100644 index 4e351b5..0000000 Binary files a/.env.c.swp and /dev/null differ diff --git a/Makefile b/Makefile index 2aeb7de..a5c2e5d 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ -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 = env.c ${UTILS_SRC} +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 OBJS = ${SRCS:.c=.o} NAME = minishell -CC = clang +CC = gcc -CFLAGS = -g -Wall -Werror -Wextra +CFLAGS = -Wall -Werror -Wextra -g LIBS = libftx/libftx.a @@ -18,7 +18,7 @@ all: ${NAME} ${NAME}: ${OBJS} make -C libftx all - ${CC} ${OBJS} -o ${NAME} ${LIBS} + ${CC} ${OBJS} -o ${NAME} ${LIBS} -lreadline clean: make -C libftx clean diff --git a/argprinter b/argprinter new file mode 100755 index 0000000..11c8a1d Binary files /dev/null and b/argprinter differ diff --git a/execution.c b/execution.c new file mode 100644 index 0000000..49294f6 --- /dev/null +++ b/execution.c @@ -0,0 +1,34 @@ +#include "libftx/libftx.h" +#include "minishell.h" +#include + +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) +{ + int pid; + + 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); + } + else + waitpid(pid); +} diff --git a/file.c b/file.c new file mode 100644 index 0000000..d03757d --- /dev/null +++ b/file.c @@ -0,0 +1,66 @@ +#include "minishell.h" + +int ft_file_is_readable(const char *path) +{ + int readable; + int fd; + + fd = open(path, O_RDONLY); + if (fd == -1) + { + ft_eprintf("minishell: %s: No such file or directory\n", path); + return (0); + } + readable = read(fd, "", 0); + if (readable == -1) + { + ft_eprintf("minishell: %s: Permission denied\n", path); + return (0); + } + close(fd); + return (1); +} + +int ft_file_is_writeable(const char *path) +{ + int writeable; + int fd; + + fd = open(path, O_WRONLY | O_CREAT, 0644); + if (fd == -1) + { + ft_eprintf("minishell: %s: Permission denied\n", path); + return (0); + } + writeable = write(fd, "", 0); + if (writeable == -1) + { + ft_eprintf("minishell: %s: Permission denied\n", path); + return (0); + } + close(fd); + return (1); +} + +char *ft_get_file_path(const char *infile) +{ + size_t i; + size_t n; + + n = 1; + while (infile[-n] == infile[-1]) + n++; + i = 0; + while (infile[i] == ' ') + i++; + if (infile[i] == '\0' || infile[i] == '>' || infile[i] == '<') + { + ft_eprintf("minishell: syntax error near "); + if ((infile[0] == '<' && n > 3) || (infile[0] == '>' && n > 2)) + ft_eprintf("unexpected token `%c`\n", infile[i - 1]); + else + ft_eprintf("unexpected token `newline`\n"); + return (NULL); + } + return (ft_getstr(infile, i + 1)); +} diff --git a/ft_split_quoted.c b/ft_split_quoted.c new file mode 100644 index 0000000..03b1fb2 --- /dev/null +++ b/ft_split_quoted.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_quoted.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet + +int ft_heredoc(char *stop) +{ + int fds[2]; + char *line; + + pipe(fds); + line = readline("> "); + while (line != NULL) + { + if (ft_strcmp(line, stop) == 0) + { + free(line); + break ; + } + ft_putstr_fd(line, fds[1]); + add_history(line); + free(line); + line = readline("> "); + } + close(fds[1]); + return (fds[0]); +} diff --git a/infile.c b/infile.c new file mode 100644 index 0000000..279fa17 --- /dev/null +++ b/infile.c @@ -0,0 +1,89 @@ +#include "minishell.h" + +static int ft_get_infile(char *line) +{ + size_t i; + int fd; + char *path; + + fd = 0; + i = 0; + while (line[i] != '\0') + { + if (line[i] == '<' && ft_is_in_quote(line, i) == 0) + { + i++; + if (fd != 0) + close(fd); + if (line[i] == '<') + { + i++; + path = ft_get_file_path(line + i); + if (path == NULL) + return (-1); + fd = ft_heredoc(path); + } + else + { + path = ft_get_file_path(line + i); + if (path == NULL) + return (-1); + if (ft_file_is_readable(path) == 0) + { + free(path); + return (-1); + } + fd = open(path, O_RDONLY); + } + free(path); + } + i++; + } + return (fd); +} + +static int ft_remove_infile(char *line) +{ + size_t i; + int separator; + + i = 0; + while (line[i] != '\0') + { + if (line[i] == '<' && ft_is_in_quote(line, i) == 0) + { + while (line[i] == '<') + line[i++] = ' '; + while (line[i] == ' ') + i++; + separator = ft_is_in_quote(line, i); + if (separator == 0) + separator = ' '; + else if (separator == 1) + separator = '\''; + else + separator = '\"'; + while (line[i] != separator && line[i] != '\0') + line[i++] = ' '; + if (line[i] != '\0' + && (separator == '\'' || separator == '\"')) + line[i++] = ' '; + } + i++; + } + return (0); +} + +int ft_infile(char *line) +{ + int fd; + + fd = ft_get_infile(line); + if (ft_remove_infile(line)) + { + if (fd > 0) + close(fd); + return (-1); + } + return (fd); +} diff --git a/libftx/extra/Makefile b/libftx/extra/Makefile index 269a370..bc967dd 100644 --- a/libftx/extra/Makefile +++ b/libftx/extra/Makefile @@ -12,7 +12,7 @@ CC = clang -SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c +SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c OBJS = $(SRCS:.c=.o) diff --git a/libftx/extra/extra.h b/libftx/extra/extra.h index c5180fa..f745d3f 100644 --- a/libftx/extra/extra.h +++ b/libftx/extra/extra.h @@ -28,9 +28,13 @@ char *ft_strfjoin(char *s1, char *s2); char *ft_strmerger(size_t arg_len, ...); int ft_is_in(char *str, char c); char **ft_tabrealloc(char **tab, size_t current_size, size_t new_size); -char *ft_strndup(char *src, size_t n); +char *ft_strndup(const char *src, size_t n); ssize_t ft_strchri(char *str, char c); int ft_contain_only_str(char *str, char *to_find); int ft_contain_only(char *str, char c); int ft_strcmp(char *s1, char *s2); +void ft_swap(void *a, void *b); +void ft_swap_int(int *a, int *b); +void ft_swap_char(char *a, char *b); + #endif diff --git a/libftx/extra/ft_strndup.c b/libftx/extra/ft_strndup.c index c0fc2aa..c289878 100644 --- a/libftx/extra/ft_strndup.c +++ b/libftx/extra/ft_strndup.c @@ -12,7 +12,7 @@ #include "extra.h" -char *ft_strndup(char *src, size_t n) +char *ft_strndup(const char *src, size_t n) { char *out; size_t i; diff --git a/libftx/extra/ft_swap.c b/libftx/extra/ft_swap.c new file mode 100644 index 0000000..0a65b04 --- /dev/null +++ b/libftx/extra/ft_swap.c @@ -0,0 +1,28 @@ +#include "extra.h" + +void ft_swap(void *a, void *b) +{ + void *c; + + c = a; + a = b; + b = c; +} + +void ft_swap_char(char *a, char *b) +{ + char c; + + c = *a; + *a = *b; + *b = c; +} + +void ft_swap_int(int *a, int *b) +{ + int c; + + c = *a; + *a = *b; + *b = c; +} diff --git a/libftx/extra/ft_tabrealloc-5f29f43f.o.tmp b/libftx/extra/ft_tabrealloc-5f29f43f.o.tmp deleted file mode 100644 index e69de29..0000000 diff --git a/libftx/libft/Makefile b/libftx/libft/Makefile index 9a2c3b1..0102a19 100644 --- a/libftx/libft/Makefile +++ b/libftx/libft/Makefile @@ -45,9 +45,8 @@ SRCS = ft_isalpha.c \ ft_putchar_fd.c \ ft_putstr_fd.c \ ft_putendl_fd.c \ - ft_putnbr_fd.c - -BSRCS = ft_lstnew.c \ + ft_putnbr_fd.c \ + ft_lstnew.c \ ft_lstadd_front.c \ ft_lstsize.c \ ft_lstlast.c \ @@ -59,8 +58,6 @@ BSRCS = ft_lstnew.c \ OBJS = $(SRCS:.c=.o) -BOBJS = $(BSRCS:.c=.o) - NAME = libft.a CFLAGS = -Wall -Werror -Wextra -g @@ -73,15 +70,12 @@ all: $(NAME) $(NAME): $(OBJS) ar -rc $(NAME) $(OBJS) -bonus: $(OBJS) $(BOBJS) - ar -rc $(NAME) $(OBJS) $(BOBJS) - clean: - rm -f $(OBJS) $(BOBJS) + rm -f $(OBJS) fclean: clean rm -f $(NAME) re: fclean all -.PHONY: all bonus clean fclean re +.PHONY: all clean fclean re diff --git a/libftx/libft/ft_split.c b/libftx/libft/ft_split.c index ed71fc1..acd870d 100644 --- a/libftx/libft/ft_split.c +++ b/libftx/libft/ft_split.c @@ -12,7 +12,7 @@ #include "libft.h" -void *ft_cancel(char **tab, size_t len) +void *ft_cancel(void **tab, size_t len) { size_t i; @@ -68,7 +68,7 @@ static char **ft_segsplitter(char **tab, size_t len, const char *s, char c) let_index++; tab[tab_index] = ft_substr(s, start, let_index - start); if (tab[tab_index] == NULL) - return (ft_cancel(tab, tab_index)); + return (ft_cancel((void **)tab, tab_index)); tab_index++; } return (tab); diff --git a/libftx/libft/libft.h b/libftx/libft/libft.h index 3c98b38..11cc2c4 100644 --- a/libftx/libft/libft.h +++ b/libftx/libft/libft.h @@ -15,7 +15,7 @@ # include # include -void *ft_cancel(char **tab, size_t len); +void *ft_cancel(void **tab, size_t len); int ft_atoi(const char *nptr); void ft_bzero(void *s, size_t n); void *ft_calloc(size_t nmemb, size_t size); diff --git a/libftx/libftx.h b/libftx/libftx.h index 8d0d553..5735aa1 100644 --- a/libftx/libftx.h +++ b/libftx/libftx.h @@ -6,7 +6,7 @@ /* By: cchauvet executable != NULL) + free(content->executable); + if (content->args != NULL) + ft_freer_tab_ultimate(1, content->args); + free(content); +} + +int ft_cmds_init(t_list **cmds, size_t len) +{ + t_cmd *content; + t_list *current; + size_t i; + + *cmds = malloc(sizeof(t_list)); + current = *cmds; + i = 0; + while (i < len) + { + content = malloc(sizeof(t_cmd)); + if (content == NULL) + { + ft_lstclear(cmds, ft_lstdel); + return (1); + } + content->args = NULL; + content->executable = NULL; + content->fd_in = -1; + content->fd_out = -1; + current->content = content; + if (!((i + 1) < len)) + { + current->next = NULL; + return (0); + } + current->next = malloc(sizeof(t_list)); + if (current->next == NULL) + ft_lstclear(cmds, ft_lstdel); + current = current->next; + i++; + } + return (0); +} + +int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile) +{ + size_t len; + t_cmd *cmd; + t_list *current; + + len = ft_seglen_quoted(line, '|'); + if (len == 0) + return (0); + if (ft_cmds_init(cmds, ft_seglen_quoted(line, '|'))) + { + free(cmds); + return (1); + } + cmd = (t_cmd *)(*cmds)->content; + cmd->fd_in = infile; + current = *cmds; + while (current->next != NULL) + current = current->next; + cmd = (t_cmd *) current->content; + cmd->fd_out = outfile; + return (0); +} + +void ft_strshift(char *str, int shift) { size_t i; - char *path; - path = NULL; + if (shift > 0) + return ; i = 0; - while ((*line)[i] != '\0') + while (str[i - shift] != '\0') { - if ((*line)[i] == '<' && ft_is_in_quote(*line, i) == 0) + str[i] = str[i - shift]; + i++; + } + str[i + shift] = '\0'; +} + +void ft_quote_remover(char *str) +{ + size_t i; + ssize_t start; + ssize_t stop; + + start = -1; + i = 0; + while (str[i] != '\0') + { + if ((str[i] == '\"' || str[i] == '\'')) { - if (path != NULL) - free(path); - path = ft_getstr(*line, i); - if (path == NULL) - return (-1); - if (ft_file_is_readable(path) == 0) + if (start == -1) + start = i; + else if (str[i] == str[start]) { - free(path); - return (-1); + stop = i; + break ; } } i++; } - return (open(path, O_RDONLY)); + if (start != -1) + { + ft_strshift(str, -1); + str[stop] = '\0'; + } } -t_list **ft_parse_cmd(char *line) +int ft_cmd_filler(t_list *element, char **args) { - char infile; - char outfile; - t_list **cmds; + t_cmd *content; size_t i; - (void) outfile; - (void) cmds; + if (args == NULL) + return (1); + content = (t_cmd *)element->content; i = 0; - while (line[i] != '\0') + while (args[i] != NULL) { - + ft_quote_remover(args[i]); i++; } + content->args = args; + //TODO check if executable exist + //TODO change it by env value + //TODO add switch to bultin + content->executable = ft_strjoin("/usr/bin/", args[0]); + if (content->executable == NULL) + return (1); + return (0); +} + +int ft_cmds_fill(t_list **cmds, const char *line) +{ + char **tab; + char **args; + t_list *current; + size_t i; + + tab = ft_split_quoted(line, '|'); + if (tab == NULL) + return (1); + i = 0; + current = *cmds; + while (tab[i] != NULL) + { + args = ft_split_quoted(tab[i], ' '); + if (ft_cmd_filler(current, args) == 1) + { + ft_lstclear(cmds, ft_lstdel); + ft_freer_tab_ultimate(2, args, tab); + return (1); + } + current = current->next; + i++; + } + ft_freer_tab_ultimate(1, tab); + return (0); +} + +t_list **ft_parse_cmds(char *line) +{ + int infile; + int outfile; + t_list **cmds; + + cmds = malloc(sizeof(t_list *)); + outfile = ft_outfile(line); + infile = ft_infile(line); + if (ft_syntatic_verif(line) == 1) + return (NULL); + if (ft_cmds_prep(cmds, line, infile, outfile) == 1) + return (NULL); + if (ft_cmds_fill(cmds, line) == 1) + return (NULL); + ft_printf("%s\n", line); + return (cmds); +} + +int ft_cmds_excutor(t_list **cmds) +{ + t_cmd *content; + t_list *current; + size_t i; + + i = 0; + current = *cmds; + while (current != NULL) + { + content = current->content; + ft_printf("--- COMMAND %d\n", i); + ft_printf("excutable: %s\n", content->executable); + ft_printf("args:\n%S", content->args); + current = current->next; + i++; + } + return (0); } int main(int ac, char **av) { - int fd; - int i; + t_list **cmds; if (ac == 1) return (1); - ft_parse_cmd(av[1]); + cmds = ft_parse_cmds(av[1]); + if (cmds == NULL) + return (1); + if (ft_cmds_excutor(cmds) == 1) + { + ft_lstclear(cmds, ft_lstdel); + return (1); + } + ft_lstclear(cmds, ft_lstdel); + free(cmds); return (1); } diff --git a/main.o b/main.o deleted file mode 100644 index 3f8ef4e..0000000 Binary files a/main.o and /dev/null differ diff --git a/minishell.h b/minishell.h index efa5977..86edcfd 100644 --- a/minishell.h +++ b/minishell.h @@ -1,24 +1,36 @@ -#ifndef FT_MINISHELL -# define FT_MINISHELL +#ifndef MINISHELL_H +# define MINISHELL_H # include "libftx/libftx.h" # include "utils/utils.h" # include # include # include +# include +# include +# include +# include -int ft_file_is_readable(char *path); -int ft_file_is_writeable(char *path); -t_list **init_env(char **env); -char *get_value_index(int index, t_list **head); -char *get_value_key(char *key, t_list **head); +t_list **init_env(char **env); +char *get_value_index(int index, t_list **head); +char *get_value_key(char *key, t_list **head); -typedef struct cmd +int ft_syntatic_verif(const char *str); +int ft_file_is_readable(const char *path); +int ft_file_is_writeable(const char *path); +char *ft_get_file_path(const char *infile); +int ft_infile(char *line); +int ft_outfile(char *line); +int ft_heredoc(char *stop); +size_t ft_seglen_quoted(const char *str, char c); +char **ft_split_quoted(const char *s, char c); + +typedef struct s_cmd { - int fd_in; - int fd_out; - char *cmd; - char *args; -} cmd; + int fd_in; + int fd_out; + char *executable; + char **args; +} t_cmd; typedef struct s_data { diff --git a/outfile.c b/outfile.c new file mode 100644 index 0000000..2779606 --- /dev/null +++ b/outfile.c @@ -0,0 +1,89 @@ +#include "minishell.h" + +static int ft_get_outfile(char *line) +{ + size_t i; + int append; + char *path; + + path = NULL; + append = 0; + i = 0; + while (line[i] != '\0') + { + if (line[i] == '>' && ft_is_in_quote(line, i) == 0) + { + i++; + if (line[i] == '>') + { + i++; + append = 1; + } + else + append = 0; + if (path != NULL) + free(path); + path = ft_get_file_path(line + i); + if (path == NULL || ft_file_is_writeable(path) == 0) + { + free(path); + return (-1); + } + } + i++; + } + if (path == NULL) + return (-2); + if (append == 1) + i = open(path, O_APPEND | O_CREAT, 0664); + else + i = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0664); + free(path); + return (i); +} + +static int ft_remove_outfile(char *line) +{ + size_t i; + int separator; + + i = 0; + while (line[i] != '\0') + { + if (line[i] == '>' && ft_is_in_quote(line, i) == 0) + { + while (line[i] == '>') + line[i++] = ' '; + while (line[i] == ' ') + i++; + separator = ft_is_in_quote(line, i); + if (separator == 0) + separator = ' '; + else if (separator == 1) + separator = '\''; + else + separator = '\"'; + while (line[i] != separator && line[i] != '\0') + line[i++] = ' '; + if (line[i] != '\0' + && (separator == '\'' || separator == '\"')) + line[i++] = ' '; + } + i++; + } + return (0); +} + +int ft_outfile(char *line) +{ + int fd; + + fd = ft_get_outfile(line); + if (ft_remove_outfile(line)) + { + if (fd > 0) + close(fd); + return (-1); + } + return (fd); +} diff --git a/syntatics.c b/syntatics.c new file mode 100644 index 0000000..ab9cc7d --- /dev/null +++ b/syntatics.c @@ -0,0 +1,56 @@ +#include "libftx/libftx.h" +#include "minishell.h" + +static int ft_quote_verif(const char *str) +{ + if (ft_is_in_quote(str, ft_strlen(str))) + { + ft_eprintf("minishell: Quote is note closed"); + return (1); + } + else + return (0); +} + +static int ft_multipipe(const char *str) +{ + size_t i; + size_t y; + + i = 0; + while (str[i] != '\0') + { + y = 0; + while (str[i + y] == '|' && !ft_is_in_quote(str, i)) + { + if (y > 0) + { + ft_eprintf("minishell: Multiple pipes is not supported\n"); + return (1); + } + y++; + } + i++; + } + return (0); +} + +static int ft_pipe_is_alone(const char *str) +{ + size_t i; + + i = ft_strlen(str) - 1; + while (str[i] != '|' && i > 0) + { + if (str[i] != ' ') + return (0); + i--; + } + ft_eprintf("minishell: Pipe must be followed by a command or redirection\n"); + return (1); +} + +int ft_syntatic_verif(const char *str) +{ + return (ft_quote_verif(str) || ft_multipipe(str) || ft_pipe_is_alone(str)); +} diff --git a/test1 b/test1 deleted file mode 100644 index 20a15c2..0000000 --- a/test1 +++ /dev/null @@ -1,50 +0,0 @@ -COLORTERM=truecolor -DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/101231/bus,guid=621c3599211e51a4e50420bf63dcee5f -DBUS_STARTER_ADDRESS=unix:path=/run/user/101231/bus,guid=621c3599211e51a4e50420bf63dcee5f -DBUS_STARTER_BUS_TYPE=session -DESKTOP_SESSION=ubuntu -DISPLAY=:0 -DOCKER_HOST=unix:///run/user/101231/docker.sock -GDMSESSION=ubuntu -GDM_LANG=en -GNOME_DESKTOP_SESSION_ID=this-is-deprecated -GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/277eb9d7_4a54_437b_9556_e8825e1c7429 -GNOME_TERMINAL_SERVICE=:1.89 -GPG_AGENT_INFO=/run/user/101231/gnupg/S.gpg-agent:0:1 -GTK_MODULES=gail:atk-bridge -HOME=/nfs/homes/erey-bet -IM_CONFIG_PHASE=1 -INVOCATION_ID=9d85372853b94435bbce5d2edac38c19 -JOURNAL_STREAM=9:2506910 -KRB5CCNAME=FILE:/tmp/krb5cc_101231_mfTZPs -LANG=en_US.UTF-8 -LANGUAGE=en -LOGNAME=erey-bet -MANAGERPID=763384 -OLDPWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell -PATH=/nfs/homes/erey-bet/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin -PWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell -QT_ACCESSIBILITY=1 -QT_IM_MODULE=ibus -SESSION_MANAGER=local/1D2.42angouleme.fr:@/tmp/.ICE-unix/763641,unix/1D2.42angouleme.fr:/tmp/.ICE-unix/763641 -SHELL=/bin/zsh -SHLVL=2 -SSH_AGENT_PID=763603 -SSH_AUTH_SOCK=/run/user/101231/keyring/ssh -TERM=xterm-256color -USER=erey-bet -VTE_VERSION=6003 -XAUTHORITY=/nfs/homes/erey-bet/.Xauthority -XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg -XDG_CURRENT_DESKTOP=ubuntu:GNOME -XDG_DATA_DIRS=/usr/share/gnome:/usr/share/ubuntu:/nfs/homes/erey-bet/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop -XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/erey-bet -XDG_MENU_PREFIX=gnome- -XDG_RUNTIME_DIR=/run/user/101231 -XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 -XDG_SESSION_CLASS=user -XDG_SESSION_DESKTOP=ubuntu -XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session3 -XDG_SESSION_TYPE=x11 -XMODIFIERS=@im=ibus -_=./minishell diff --git a/test2 b/test2 deleted file mode 100644 index 11e75d9..0000000 --- a/test2 +++ /dev/null @@ -1,50 +0,0 @@ -SHELL=/bin/zsh -SESSION_MANAGER=local/1D2.42angouleme.fr:@/tmp/.ICE-unix/763641,unix/1D2.42angouleme.fr:/tmp/.ICE-unix/763641 -QT_ACCESSIBILITY=1 -COLORTERM=truecolor -XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg -XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session3 -XDG_MENU_PREFIX=gnome- -GNOME_DESKTOP_SESSION_ID=this-is-deprecated -LANGUAGE=en -SSH_AUTH_SOCK=/run/user/101231/keyring/ssh -XMODIFIERS=@im=ibus -DESKTOP_SESSION=ubuntu -SSH_AGENT_PID=763603 -GTK_MODULES=gail:atk-bridge -DBUS_STARTER_BUS_TYPE=session -KRB5CCNAME=FILE:/tmp/krb5cc_101231_mfTZPs -PWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell -LOGNAME=erey-bet -XDG_SESSION_DESKTOP=ubuntu -XDG_SESSION_TYPE=x11 -GPG_AGENT_INFO=/run/user/101231/gnupg/S.gpg-agent:0:1 -XAUTHORITY=/nfs/homes/erey-bet/.Xauthority -XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/erey-bet -GDM_LANG=en -HOME=/nfs/homes/erey-bet -IM_CONFIG_PHASE=1 -LANG=en_US.UTF-8 -XDG_CURRENT_DESKTOP=ubuntu:GNOME -VTE_VERSION=6003 -XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 -GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/277eb9d7_4a54_437b_9556_e8825e1c7429 -INVOCATION_ID=9d85372853b94435bbce5d2edac38c19 -MANAGERPID=763384 -XDG_SESSION_CLASS=user -TERM=xterm-256color -USER=erey-bet -GNOME_TERMINAL_SERVICE=:1.89 -DISPLAY=:0 -SHLVL=2 -QT_IM_MODULE=ibus -DBUS_STARTER_ADDRESS=unix:path=/run/user/101231/bus,guid=621c3599211e51a4e50420bf63dcee5f -XDG_RUNTIME_DIR=/run/user/101231 -DOCKER_HOST=unix:///run/user/101231/docker.sock -JOURNAL_STREAM=9:2506910 -XDG_DATA_DIRS=/usr/share/gnome:/usr/share/ubuntu:/nfs/homes/erey-bet/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop -PATH=/nfs/homes/erey-bet/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin -GDMSESSION=ubuntu -DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/101231/bus,guid=621c3599211e51a4e50420bf63dcee5f -OLDPWD=/nfs/homes/erey-bet/travaux/Cursus42/minishell -_=/usr/bin/env diff --git a/utils/ft_getstr.c b/utils/ft_getstr.c index c55fed4..b7f88ca 100644 --- a/utils/ft_getstr.c +++ b/utils/ft_getstr.c @@ -1,11 +1,11 @@ #include "utils.h" -char *ft_getstr(char *str, size_t n) +char *ft_getstr(const char *str, size_t n) { size_t start; size_t stop; char c; - int quote; + int quote; start = n; stop = n; diff --git a/utils/ft_is_in_quote.c b/utils/ft_is_in_quote.c index 3b697d1..c645ad3 100644 --- a/utils/ft_is_in_quote.c +++ b/utils/ft_is_in_quote.c @@ -1,6 +1,6 @@ #include "utils.h" -int ft_is_in_quote(char *str, size_t n) +int ft_is_in_quote(const char *str, size_t n) { size_t double_quoted; size_t simple_quoted; diff --git a/utils/ft_strnchr.c b/utils/ft_strnchr.c index 6654db9..d385f48 100644 --- a/utils/ft_strnchr.c +++ b/utils/ft_strnchr.c @@ -1,6 +1,6 @@ #include "utils.h" -ssize_t ft_strnchr(char *str, char c) +ssize_t ft_strnchr(const char *str, char c) { size_t i; diff --git a/utils/ft_strncpy.c b/utils/ft_strncpy.c index 16de576..8eca3f1 100644 --- a/utils/ft_strncpy.c +++ b/utils/ft_strncpy.c @@ -1,6 +1,6 @@ #include "utils.h" -size_t ft_strncpy(char *dst, char *src, size_t n) +size_t ft_strncpy(char *dst, const char *src, size_t n) { size_t i; diff --git a/utils/ft_strreplace.c b/utils/ft_strreplace.c index 8a2a2ba..cfe92bf 100644 --- a/utils/ft_strreplace.c +++ b/utils/ft_strreplace.c @@ -1,11 +1,12 @@ #include "utils.h" -char *ft_strreplace(char *str, char *fill, size_t start, size_t stop) +char *ft_strreplace(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); diff --git a/utils/utils.h b/utils/utils.h index 0f24105..23df973 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -3,10 +3,10 @@ # include # include "../libftx/libftx.h" -size_t ft_strncpy(char *dst, char *src, size_t n); -int ft_is_in_quote(char *str, size_t n); -char *ft_strreplace(char *str, char *fill, size_t start, size_t stop); -ssize_t ft_strnchr(char *str, char c); -char *ft_getstr(char *str, size_t n); +size_t ft_strncpy(char *dst, const char *src, size_t n); +int ft_is_in_quote(const char *str, size_t n); +char *ft_strreplace(char *str, const char *fill, size_t start, size_t stop); +ssize_t ft_strnchr(const char *str, char c); +char *ft_getstr(const char *str, size_t n); #endif