From 67fb6d0533f56a0d63ffeebd9fde7cdc75919eb2 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Tue, 14 Feb 2023 07:26:18 +0100 Subject: [PATCH] -m --- .env.c.swp | Bin 12288 -> 0 bytes Makefile | 10 +- argprinter | Bin 0 -> 31064 bytes execution.c | 34 ++++ file.c | 66 +++++++ ft_split_quoted.c | 75 ++++++++ heredoc.c | 25 +++ infile.c | 89 +++++++++ libftx/extra/Makefile | 2 +- libftx/extra/extra.h | 6 +- libftx/extra/ft_strndup.c | 2 +- libftx/extra/ft_swap.c | 28 +++ libftx/extra/ft_tabrealloc-5f29f43f.o.tmp | 0 libftx/libft/Makefile | 14 +- libftx/libft/ft_split.c | 4 +- libftx/libft/libft.h | 2 +- libftx/libftx.h | 10 +- libftx/printf/ft_dprintarg.c | 4 +- libftx/printf/ft_dprintptr.c | 6 +- libftx/printf/ft_dprintstrtab.c | 4 +- libftx/printf/ft_eprintf.c | 2 +- libftx/printf/ft_printf.h | 4 +- libftx/printf/ft_putstr_fd.c | 4 +- main.c | 222 +++++++++++++++++++--- main.o | Bin 1608 -> 0 bytes minishell.h | 38 ++-- outfile.c | 89 +++++++++ syntatics.c | 56 ++++++ test1 | 50 ----- test2 | 50 ----- utils/ft_getstr.c | 4 +- utils/ft_is_in_quote.c | 2 +- utils/ft_strnchr.c | 2 +- utils/ft_strncpy.c | 2 +- utils/ft_strreplace.c | 5 +- utils/utils.h | 10 +- 36 files changed, 734 insertions(+), 187 deletions(-) delete mode 100644 .env.c.swp create mode 100755 argprinter create mode 100644 execution.c create mode 100644 file.c create mode 100644 ft_split_quoted.c create mode 100644 heredoc.c create mode 100644 infile.c create mode 100644 libftx/extra/ft_swap.c delete mode 100644 libftx/extra/ft_tabrealloc-5f29f43f.o.tmp delete mode 100644 main.o create mode 100644 outfile.c create mode 100644 syntatics.c delete mode 100644 test1 delete mode 100644 test2 diff --git a/.env.c.swp b/.env.c.swp deleted file mode 100644 index 4e351b5c9b51b62efa40867e91c09e12d893a74e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2K~EDw6vqc{tD;1Y#xRtaY!|w10TYs1N#tNm&>LK^X_nntI>|C6yR!vtP@{=Q zP4okJ(f9$p`vvrd2QhvF55_NG{7<{vLLkI&Bff=ScIWN9H*bD(YTEV6>fL*M!L2e} zmYQfDDiUGC&5%02w%o2K3eldxFMCv*vpr4)8pZjq`gpq#GF^17v^gE!zccnUT^02<&nSOj%& z6V$*pa21>fqhJJlzsT4}@D{uTFF*&Zf<;gPE+_#8{-CFyU>|$~pTQ^a4!i;#kbq@S z1umEbW-q_7ryqbWGC&5%02v?yWPl8i0Wv@a{tpAY%!-9hW5w-CvBs=jhQFgh%ktAW z7E1H_k(WmT?7(cE<&|zJv7@no73$_zER_!J!u8~VD$ES0_-&=JhUufrtnHSJ1h?~r zC+qzF%JOoN4O`)k65CDu8X5`N6R&gpOj?_u4NNJ!)0RQei#N=)!N9LEX6a@m6Ky%! z8hGE2aA#P#%g`*}^rW)Q1M2u_x#h*&F*Vm3`N%QrG5E`j+AZM)rh!8W(4g4{!j=~V zO{tpgI1q7f@(f3bH90-qFlpKTd!YulEs$?@UIb(uNl!%hc>X|nQTf_0qIlvI9{27(tNxgP4Ba{uPG3I|?6y$SpU D5r{N$ 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 0000000000000000000000000000000000000000..11c8a1d74e19662e5d5007ee01e96d5892e16f61 GIT binary patch literal 31064 zcmeHwdvsIRneRT5jwIV)$>wDq2@ZkAlwu4aloUda0VT3|#0}Wjd4LeM{AgrbwI$*t z*EbHfQxxIU=_+e6(-&RS&d^!Olyy7FC2*lm$O_PAt-80Jgf(raZbK5eVG>P;PMwt2 z_xJ6`(UB}C>0`~zAKr=1xA*tn-+pf$qep$)@33haQ_03QF)Gz~4UQ5|#!5cRixRh< z6)=O{z)G1D7zaKErw|l51zT)_prBjw*#SxJxTGJq87NWNAix&!XBsLG36fko88Rzi zL=qKbUO^@~owBmbWc?KM%@%wLDn8R*g`l$vLu4e}$CWaspjD1ypJ=SX(e0?r30v0HFe1(O_pZ&=zcMXAgF^ zMnmk*?Nyt%1lE+VDZd3g&21g+k|#jsY`ms6)RF#64};i();ywqoS2YOcNrW~+p5?Q zV%&nKxT#c9WALmCPtvPWsRgh4nxaj^=?F|mU^)WR5txp^bOfd&Fdc#E2uw%dza|3z z?z#Sbf8Q0iKcSD^&X|8-IBJ_1@%O#tKF1xJxaF5XPb|BPr)RN&9F<#$Ha0qewCta$ zOk4l45fn+^>VK_@|8TEA{!4$~@?^jFww3UO#b(v|<8LG%MlD{}7XqX0IXB53@xT2<+6NLr{JiIV z*T~s;&$vGxOZD}PYn~_ROyy7bQi&boeJ@PJcZ~ZRF8UK|FZjRfs4$3|onXl?;WRb& z3T&RF7$WfAJ=S<|{Zgy{ye~;ofTI##;xOSG_a}B-@|>OFUOn9R9y{cF&C_2aT}Is~JX)I48= zzpp;wdzBlu1|%aM@!F&ri-d0!HBEZ@ZW8{b5Ru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EMuXAThCrm1pKgT*be1;V zktb$cJ#=+RfA~*z@oKA~lV+#0y(udX@n)HyV$-)Ka;Oo%*=J-yerbmK?B20O_8wN= z^-vq`i~;%GF<^_z;lv&4jIi={8pqA;v2wa7XT9%_-3PfH_YRY^#QSx88z zJQN4pS{q=s1G?}i=LUo_gq@XRGHk;f2WLb3W6c;VO&uy9+`qpwbU>BxlX4-IM{LB5 z{pUUD#70X9mRFwCeZg^w$UeErKOGa9Ul2u;a zKP08X(hP3e>t?2{DEpW!fg&d4E;-M{(w zQ!0M+rZB~X;>(lV$6?dOQ}&I5R4a&h#__SrmrD6kDX;uj0urs%voB`JtNmh)WPD?m zk`z$ME9_rq$*aFFTfbCr%v6jLX8V5(c=BJx-@IRvj@L*z1+wLjXUVI3DD^v;4pMGO z+49eUX0@;GtLj$^A$OL5YJa727#X^Qk=@O_*HXWmna!`t3evd+rvp=7oj*%90g0se zL@8ZX_)8#A-%<9}IaU2G>4>bq>R(Duwc{@!ODsxW-KV8)2NFr~iPB{IZ-QWzH}BmH zAyK9TB~44DygF}{8A4zx`%)eI4Kk!l`LFiv>kYx7?1+-ErSb&d$A|1!P{ERv ze7yxnS>mOnpdA^N7ZmXvG6eh&HGxTDHZT2jK{k$9AKxYfzM~p$3i<1%kiYeAA@CSY z?v|8oi|(limtFr;dxX$^DzH+AlD9&0>{{%U1Vy1&)_*aIetcAWsQC}?!<%gsRH6;wJ~=a&CPhu~P7C6HBQ{~u$nNb3Lq literal 0 HcmV?d00001 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 3f8ef4e97bb657bff92853efba050ef02a0aede3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1608 zcmbu9&x_Mg5XUF&?zU*vA_}5{xp>^?wkqgBsYu)$R*{7s1f^t~bhp?hHBFbgP!-Cm zB^M7~{4e|qbWy>7K`-J(sL;cDksbNsW2feX5=F0+!N>FVA#73J z=(s^guQn`qQ{Q&{cHMLJLQ$-UmF0__Xt404h}k7^Ihyf=oLAdf2d$ge&g3%LSGa?- z$mt<_Lq9i;=AWl-9$8AgMg@Unvk))9uW8a~8d6CZ(pV9+eaS<>dvkM@6r(ub}=>{OGUbE@A0W__;3tr1{LAYMvh}Apg<#u3I zAA)E!wwo2pw(%BiLM^DY{JI;|pxW@-j_l=ZRcgM~bij8kJL)B>AliW+SR3dcHzV(R zwiQ@}3!)$w_@8bI>(%$b?Iv>5FBnKq=cn2dCdA0AR+0(dA0CU}MXKd@${O;zoPSS3 z`X~wUCv!^jE_&)wlsUVvGN5;=8n2%{{nt>uqKYv7CUX(vT*v+#j&rO^b4f5kyFOzr z^^Q@WysW=MiDJBeMz=9YI=}C-A)gbSAAN^h&-?!ujZ*3rpZ^aML$tX7 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