From 17770aa6ae940d2a40ca34a5c6ed549d26ab66f6 Mon Sep 17 00:00:00 2001 From: joris schaft Date: Tue, 23 Apr 2024 16:04:24 +0200 Subject: [PATCH] a --- a.out | Bin 0 -> 17528 bytes ft_split.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ main.c | 54 +++++++++++++++++++++++++ minish.h | 22 +++++++++++ path.c | 61 ++++++++++++++++++++++++++++ util.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 348 insertions(+) create mode 100755 a.out create mode 100644 ft_split.c create mode 100644 main.c create mode 100644 minish.h create mode 100644 path.c create mode 100644 util.c diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..be87549ab3f9043f84983c8317a63101a04c8848 GIT binary patch literal 17528 zcmeHPeRN#Kb)VJxLx3&G!3Nt!vkb~{VdUtJYSnaC& z0aA`k9Ap!3gj`Wb;x_bP+UA5dHdXuI3GgS#wQK9mr zH=S6WcT;1wl4Hu{c6~loE?jg#*T>YUN51Jk|1-QU0aod*r|T^p##1 zIgiRWQy~)1FMMAQ>iPSSoM((l087gR9dz|Yq`tso}@$JZ<1k z4L`_v)V5vLwqD5kkU#6E+VlC3T>1B0`FCCUw_W)+ocZPN)n{JaVP<||b`Fhg-rCST z{i0cLMfdDSu|qYxtLI{4o16C(R8IFG`%^Gx_w?6@tQk+ugX<0w57(WS8!TV67rhb3 zG==;>O8HfPN93AwW@gNM_Wc{pXUDy!=LPfCbE&y75Y`4tbA!8NKUtsrySJK(Mf%z% zv$ML6STpl(YL?kmy#bl*i|2B=YzWSKVR|+4p6$@J>nHu;dr(MB6ZFi?o@{39fHBl( zj8jAVj59<=(w)W`PnU7V3=WuGM%MHUls_%1jG@#o-Qd376eK1JUe{@idq$=evjdfR zMO4!N>IV1qmhY$5b{XT_kJ(M`9QDa&r-w34gI&g8XRpURWM=xZW$3z@F~-f#J>w#M zA(}N#aNpTn?uhJFW1n$aGE2IehPsT?o`HP-x|&X#!I#Xgrg78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Hb+rxFrVSgm7+bBawRH^!S(V=@1(RvnZ~2u{P0c6$Oeu*+!NF#Wnk~PN zD%9KsXQUF*a7>D{he1~-88DQ zyOy;xnbd8N-*>4GzY3+5?a#&O^DiA4l1U|E!4|3zAARxg($`=`Kk+L3z|2(vzDFxW zgg@Edk_zkuO(hgQyR>psz6Hw#*{jSNceHnx8O!DoIifg98HT@ zim({&V z`FzCG$AX%=^=|`?Kd;2O{d|sM%Ju7GxBYy8%?7~Gdv2`H&jXnH$hk<=M`F4Ed@hdw zqb{>PpUap&hB9Z;=4|LMz|mQq_4)k9l+^Y#X|ERK`rZBin%1w=a{PRQX^%sn`r_6n|Bz4EJ~j<1Y3e=+xySzzm%dNyF>Tf6 zn7GV~Z@TpPyvmg2C)0n@rGHo}Fuju%HD!BDf8f&ReH7DG_JcBIfc4lc?f;zq<8v}o zey+yyZvQ>6^?Ce-PfKb#)1|=Ur=`SCz)=0H&*yHY&#<7TE_32%E`2_qGo}5OGr8-h z^B0|US&W|-@^|uXdCoKa0J`N4eLn9WS_%+}#Ft?!nn zx}0f_u3wAWMXZ0VjVOloos?t8DO#fq*60S%@pKg~ZV%6k^qiF2?$qB~rE&{hg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:13:52 by jschaft #+# #+# */ +/* Updated: 2024/04/23 16:00:34 by jschaft ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minish.h" + +static int get_word_count(char const *s, char c) +{ + int count; + int i; + + count = 0; + i = 0; + while (s[i] != '\0') + { + while (s[i] == c) + i++; + if (s[i] != '\0' && s[i] != c) + { + count++; + while (s[i] != '\0' && s[i] != c) + i++; + } + } + return (count); +} + +static char *strdup_split(const char *src, int start, int len) +{ + char *dst; + int i; + + dst = (char *)malloc(len + 1); + if (dst == NULL) + { + free(dst); + return (NULL); + } + i = 0; + while (i < len) + { + dst[i] = src[start + i]; + i++; + } + dst[i] = '\0'; + return (dst); +} + +static void fill_re(char const *s, char c, char **re) +{ + int i; + int y; + int start; + + i = 0; + y = 0; + while (s[i] != '\0') + { + while (s[i] == c) + i++; + if (s[i] != '\0' && s[i] != c) + { + start = i; + while (s[i] != '\0' && s[i] != c) + i++; + re[y] = strdup_split(s, start, i - start); + if (re[y] == NULL) + return ; + y++; + } + } + re[y] = NULL; +} + +char **ft_split(char const *s, char c) +{ + char **re; + + if (s == NULL) + return (NULL); + re = malloc(sizeof(char *) * (get_word_count(s, c) + 1)); + if (re == NULL) + { + free(re); + return (NULL); + } + fill_re(s, c, re); + return (re); +} diff --git a/main.c b/main.c new file mode 100644 index 0000000..8636ca1 --- /dev/null +++ b/main.c @@ -0,0 +1,54 @@ +#include "minish.h" + +void execclear(char *p, char **envp) +{ + execve(p, &p, envp); +} + +static void print_hi(void) +{ + printf("Welcome to____________________________________\n"); + printf("|| ___ ___ ||\n"); + printf("|| | \\ / | ||\n"); + printf("|| | |\\ \\ / /| | __ __ __ __ ||\n"); + printf("|| | | \\ \\ / / | | |__| ||\\ || |__| ||\n"); + printf("|| | | \\ \\/ / | | __ || \\ || __ ||\n"); + printf("|| | | \\ / | | || || \\ || || ||\n"); + printf("|| | | \\/ | | || || \\ || || ||\n"); + printf("|| | | | | || || \\ || || ||\n"); + printf("|| |_| |_| || || \\|| || ||\n"); + printf("|| _____ ||\n"); + printf("|| / ___| By: Mylan COLONNA ||\n"); + printf("|| \\ \\ And: Joris SCHAFT ||\n"); + printf("|| \\ \\ ||\n"); + printf("|| \\ \\ __ __ __ __ __ ||\n"); + printf("|| \\ \\ || || ||=== || || ||\n"); + printf("|| \\ \\ || || || || || ||\n"); + printf("|| / / ||===|| ||=== || || ||\n"); + printf("|| ___/ / || || || || || ||\n"); + printf("|| |____/ || || ||=== ||=== ||=== ||\n"); + printf("|_____________________________________________|\n\n"); +} + +void hello_message(char **path, char **envp) +{ + char **p = cp_path(path); + int i = 0; + pid_t pid; + + while (p[i] != NULL) + { + p[i] = ft_strjoin(p[i], "/"); + p[i] = ft_strjoin(p[i], "clear"); + i++; + } + i = search_path(p); + pid = fork(); + if (pid == 0) + execclear(p[i], envp); +} + +int main(char **envp) +{ + char **path = get_path(envp); +} \ No newline at end of file diff --git a/minish.h b/minish.h new file mode 100644 index 0000000..0762bda --- /dev/null +++ b/minish.h @@ -0,0 +1,22 @@ +#ifndef MINISH_H +# define MINISH_H + +# include +# include +# include +# include +# include +# include + +char **get_path(char **envp); +int search_path(char **path); +char **cp_path(char **path); + +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +int ft_strncmp(char *s1, char *s2, size_t n); +char **ft_split(char const *s, char c); +size_t ft_strlen(char const *s); +char *ft_strdup(const char *s); + +#endif \ No newline at end of file diff --git a/path.c b/path.c new file mode 100644 index 0000000..3a9d504 --- /dev/null +++ b/path.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* path.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jschaft +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 12:07:26 by jschaft #+# #+# */ +/* Updated: 2024/04/23 15:08:11 by jschaft ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minish.h" + +char **get_path(char **envp) +{ + int i; + char **re; + char *path; + + i = 0; + while (ft_strncmp(envp[i], "PATH=", 5) != 0) + i++; + path = ft_substr(envp[i], 5, ft_strlen(envp[i]) - 5); + re = ft_split(path, ':'); + free(path); + return (re); +} + +int search_path(char **path) +{ + int i; + + i = 0; + while (path[i] != NULL) + { + if (access(path[i], X_OK) >= 0) + return (i); + i++; + } + return (-1); +} + +char **cp_path(char **path) +{ + char **re; + int i; + + i = 0; + while (path[i] != NULL) + i++; + re = malloc(sizeof(char *) * i + 1); + i = 0; + while (path[i] != NULL) + { + re[i] = ft_strdup(path[i]); + i++; + } + re[i] == NULL; + return (re); +} diff --git a/util.c b/util.c new file mode 100644 index 0000000..48230d6 --- /dev/null +++ b/util.c @@ -0,0 +1,114 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* util.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jschaft +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 12:07:26 by jschaft #+# #+# */ +/* Updated: 2024/04/23 16:00:41 by jschaft ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minish.h" + +size_t ft_strlen(char const *s) +{ + int i; + + i = 0; + while (s[i] != '\0') + i++; + return (i); +} + +int ft_strncmp(char *s1, char *s2, size_t n) +{ + int i; + unsigned char *st1; + unsigned char *st2; + + i = 0; + st1 = (unsigned char *)s1; + st2 = (unsigned char *)s2; + if (n == 0) + { + return (0); + } + while (st1[i] == st2[i] && st1[i] != '\0' && st2[i] != '\0' + && i < (int)n - 1) + i++; + return (st1[i] - st2[i]); +} + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + int i; + char *null_re; + char *re; + + i = 0; + null_re = malloc(sizeof(char)); + re = malloc(sizeof(char) * (len + 1)); + if (re == NULL || null_re == NULL) + return (NULL); + null_re[0] = '\0'; + if (start >= ft_strlen(s)) + return (null_re); + while (s[i + start] != '\0' && i < (int)len) + { + re[i] = s[i + start]; + i++; + } + re[i] = '\0'; + return (re); +} + +char *ft_strjoin(char const *s1, char const *s2) +{ + int i; + int y; + int size; + char *re; + + i = 0; + y = 0; + size = ft_strlen(s1) + ft_strlen(s2) + 1; + re = malloc(sizeof(char) * size); + if (re == NULL) + return (NULL); + while (s1[i] != '\0') + { + re[i] = s1[i]; + i++; + } + while (s2[y] != '\0') + { + re[i + y] = s2[y]; + y++; + } + re[i + y] = '\0'; + return (re); +} + +char *ft_strdup(const char *s) +{ + int i; + int len; + char *re; + + len = 0; + while (s[len] != '\0') + len++; + re = malloc(sizeof(char) * (len + 1)); + if (re == NULL) + return (NULL); + i = 0; + while (i < len) + { + re[i] = s[i]; + i++; + } + re[i] = '\0'; + return (re); +}