From 17770aa6ae940d2a40ca34a5c6ed549d26ab66f6 Mon Sep 17 00:00:00 2001 From: joris schaft Date: Tue, 23 Apr 2024 16:04:24 +0200 Subject: [PATCH 1/2] 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#X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`!yZHb+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); +} From d26cd021f23b81b9721ec6beb5e3e847b20137b7 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 23 Apr 2024 16:46:55 +0200 Subject: [PATCH 2/2] save --- a.out | Bin 17528 -> 20328 bytes libft/Makefile | 47 ++++++++++ libft/ft_atoi.c | 50 ++++++++++ libft/ft_bzero.c | 18 ++++ libft/ft_calloc.c | 29 ++++++ libft/ft_isalnum.c | 18 ++++ libft/ft_isalpha.c | 16 ++++ libft/ft_isascii.c | 16 ++++ libft/ft_isdigit.c | 16 ++++ libft/ft_isprint.c | 16 ++++ libft/ft_itoa.c | 67 ++++++++++++++ libft/ft_lstadd_back.c | 24 +++++ libft/ft_lstadd_front.c | 19 ++++ libft/ft_lstclear.c | 25 +++++ libft/ft_lstdelone.c | 22 +++++ libft/ft_lstiter.c | 22 +++++ libft/ft_lstlast.c | 22 +++++ libft/ft_lstmap.c | 38 ++++++++ libft/ft_lstnew.c | 26 ++++++ libft/ft_lstsize.c | 26 ++++++ libft/ft_memchr.c | 28 ++++++ libft/ft_memcmp.c | 25 +++++ libft/ft_memcpy.c | 30 ++++++ libft/ft_memmove.c | 31 +++++++ libft/ft_memset.c | 28 ++++++ libft/ft_putchar_fd.c | 18 ++++ libft/ft_putendl_fd.c | 20 ++++ libft/ft_putnbr_fd.c | 40 ++++++++ libft/ft_putstr_fd.c | 19 ++++ libft/ft_split.c | 98 ++++++++++++++++++++ libft/ft_strchr.c | 29 ++++++ libft/ft_strdup.c | 35 +++++++ libft/ft_striteri.c | 25 +++++ libft/ft_strjoin.c | 42 +++++++++ libft/ft_strlcat.c | 44 +++++++++ libft/ft_strlcpy.c | 30 ++++++ libft/ft_strlen.c | 23 +++++ libft/ft_strmapi.c | 32 +++++++ libft/ft_strncmp.c | 25 +++++ libft/ft_strnstr.c | 47 ++++++++++ libft/ft_strrchr.c | 31 +++++++ libft/ft_strtrim.c | 80 ++++++++++++++++ libft/ft_substr.c | 41 +++++++++ libft/ft_tolower.c | 18 ++++ libft/ft_toupper.c | 18 ++++ libft/libft.h | 196 ++++++++++++++++++++++++++++++++++++++++ main.c | 12 ++- minish.h | 18 ++-- path.c | 4 +- util.c | 114 ----------------------- 50 files changed, 1591 insertions(+), 127 deletions(-) create mode 100644 libft/Makefile create mode 100644 libft/ft_atoi.c create mode 100644 libft/ft_bzero.c create mode 100644 libft/ft_calloc.c create mode 100644 libft/ft_isalnum.c create mode 100644 libft/ft_isalpha.c create mode 100644 libft/ft_isascii.c create mode 100644 libft/ft_isdigit.c create mode 100644 libft/ft_isprint.c create mode 100644 libft/ft_itoa.c create mode 100644 libft/ft_lstadd_back.c create mode 100644 libft/ft_lstadd_front.c create mode 100644 libft/ft_lstclear.c create mode 100644 libft/ft_lstdelone.c create mode 100644 libft/ft_lstiter.c create mode 100644 libft/ft_lstlast.c create mode 100644 libft/ft_lstmap.c create mode 100644 libft/ft_lstnew.c create mode 100644 libft/ft_lstsize.c create mode 100644 libft/ft_memchr.c create mode 100644 libft/ft_memcmp.c create mode 100644 libft/ft_memcpy.c create mode 100644 libft/ft_memmove.c create mode 100644 libft/ft_memset.c create mode 100644 libft/ft_putchar_fd.c create mode 100644 libft/ft_putendl_fd.c create mode 100644 libft/ft_putnbr_fd.c create mode 100644 libft/ft_putstr_fd.c create mode 100644 libft/ft_split.c create mode 100644 libft/ft_strchr.c create mode 100644 libft/ft_strdup.c create mode 100644 libft/ft_striteri.c create mode 100644 libft/ft_strjoin.c create mode 100644 libft/ft_strlcat.c create mode 100644 libft/ft_strlcpy.c create mode 100644 libft/ft_strlen.c create mode 100644 libft/ft_strmapi.c create mode 100644 libft/ft_strncmp.c create mode 100644 libft/ft_strnstr.c create mode 100644 libft/ft_strrchr.c create mode 100644 libft/ft_strtrim.c create mode 100644 libft/ft_substr.c create mode 100644 libft/ft_tolower.c create mode 100644 libft/ft_toupper.c create mode 100644 libft/libft.h delete mode 100644 util.c diff --git a/a.out b/a.out index be87549ab3f9043f84983c8317a63101a04c8848..a82e98a6040dc978bd87fb8ab7fdf82a35f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17:45:41 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 12:03:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +static int is_in(char c, char *chars) +{ + int i; + + i = 0; + while (chars[i]) + { + if (c == chars[i]) + return (1); + i++; + } + return (0); +} + +int ft_atoi(const char *nptr) +{ + int sign; + int i; + int r; + + sign = 1; + i = 0; + r = 0; + while (is_in(nptr[i], " \f\n\r\t\v")) + i++; + if (is_in(nptr[i], "+-")) + { + if (nptr[i] == '-') + sign *= -1; + i++; + } + while (is_in(nptr[i], "0123456789")) + { + r = r * 10 + (nptr[i] - '0'); + i++; + } + return (r * sign); +} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100644 index 0000000..026084e --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:10:31 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 13:12:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, '\0', n); +} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100644 index 0000000..c1fd1b0 --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:41:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 15:58:33 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *dest; + int len; + + if ((long)nmemb * (long)size > (long)INT_MAX) + return (NULL); + len = size * nmemb; + dest = malloc(len); + if (!dest) + return (NULL); + ft_bzero(dest, len); + return (dest); +} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c new file mode 100644 index 0000000..e0492c9 --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:02:39 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isdigit(c) || ft_isalpha(c)); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100644 index 0000000..0719231 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:46:27 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100644 index 0000000..addccb1 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:50:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + return ((c >= 0 && c <= 127)); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100644 index 0000000..618ea3a --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:47:07 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100644 index 0000000..725a23e --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:51:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int c) +{ + return (c >= 32 && c <= 126); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100644 index 0000000..2b509b5 --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:51:10 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:49:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static char get_digit_at(long pos_n, int i, int nb_len) +{ + int w; + long ten_power; + + w = nb_len - i - 1; + ten_power = 1; + while (w--) + ten_power *= 10; + return ('0' + pos_n / ten_power % 10); +} + +static int get_nb_len(long pos_n) +{ + int r; + long ten_powers; + + r = 1; + ten_powers = 10; + while (pos_n >= ten_powers) + { + r++; + ten_powers *= 10; + } + return (r); +} + +char *ft_itoa(int n) +{ + long pos_n; + int sign; + int nb_len; + char *dest; + int i; + + sign = (n >= 0) - (n < 0); + pos_n = (long)n * sign; + nb_len = get_nb_len(pos_n); + dest = malloc(((sign == -1) + nb_len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + if (sign == -1) + dest[i++] = '-'; + while (i - (sign == -1) < nb_len) + { + dest[i] = get_digit_at(pos_n, i - (sign == -1), nb_len); + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_lstadd_back.c b/libft/ft_lstadd_back.c new file mode 100644 index 0000000..f2668da --- /dev/null +++ b/libft/ft_lstadd_back.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:24:03 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:56:42 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *last; + + last = ft_lstlast(*lst); + if (last) + last->next = new; + else + *lst = new; +} diff --git a/libft/ft_lstadd_front.c b/libft/ft_lstadd_front.c new file mode 100644 index 0000000..432dffc --- /dev/null +++ b/libft/ft_lstadd_front.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:19:20 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:20:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + new->next = *lst; + *lst = new; +} diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c new file mode 100644 index 0000000..8a440e2 --- /dev/null +++ b/libft/ft_lstclear.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:31:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 11:40:24 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *next; + + while (*lst) + { + next = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = next; + } +} diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c new file mode 100644 index 0000000..0a29cbf --- /dev/null +++ b/libft/ft_lstdelone.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:28:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:55:39 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (!lst) + return ; + (*del)(lst->content); + free(lst); +} diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c new file mode 100644 index 0000000..9bc8cdf --- /dev/null +++ b/libft/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:36:27 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:37:48 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + while (lst) + { + (*f)(lst->content); + lst = lst->next; + } +} diff --git a/libft/ft_lstlast.c b/libft/ft_lstlast.c new file mode 100644 index 0000000..bf5d7a2 --- /dev/null +++ b/libft/ft_lstlast.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:22:57 by mcolonna #+# #+# */ +/* Updated: 2023/10/05 12:53:31 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst->next) + lst = lst->next; + return (lst); +} diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c new file mode 100644 index 0000000..64561be --- /dev/null +++ b/libft/ft_lstmap.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:37:57 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 13:17:57 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *dest; + t_list *new; + void *new_content; + + dest = NULL; + if (!lst) + return (NULL); + while (lst) + { + new_content = (*f)(lst->content); + new = ft_lstnew(new_content); + if (!new) + { + (*del)(new_content); + ft_lstclear(&dest, del); + return (NULL); + } + ft_lstadd_back(&dest, new); + lst = lst->next; + } + return (dest); +} diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c new file mode 100644 index 0000000..adbf062 --- /dev/null +++ b/libft/ft_lstnew.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:14:54 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:51:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *r; + + r = malloc(sizeof(t_list)); + if (!r) + return (NULL); + r->content = content; + r->next = NULL; + return (r); +} diff --git a/libft/ft_lstsize.c b/libft/ft_lstsize.c new file mode 100644 index 0000000..5323ea2 --- /dev/null +++ b/libft/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/04 16:21:29 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 16:44:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int i; + + i = 0; + while (lst) + { + lst = lst->next; + i++; + } + return (i); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..44a6ae3 --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:28:00 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:31:16 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + const char *s2 = s; + + i = 0; + while (i < n) + { + if (s2[i] == (char) c) + return ((void *) s + i); + i++; + } + return (NULL); +} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100644 index 0000000..ff7039f --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:37:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 12:00:22 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + + if (n == 0) + return (0); + i = 0; + while (i < n - 1 && ((unsigned char *)s1)[i] == ((unsigned char *)s2)[i]) + i++; + return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]); +} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100644 index 0000000..33e973f --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:12:53 by mcolonna #+# #+# */ +/* Updated: 2023/10/16 13:40:19 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t i; + char *dest2; + char *src2; + + dest2 = (char *)dest; + src2 = (char *)src; + i = 0; + while (i < n) + { + dest2[i] = src2[i]; + i++; + } + return (dest); +} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100644 index 0000000..985be90 --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:17:41 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 10:44:37 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t i; + + if (!dest || !src) + return (NULL); + i = 0; + while (i < n) + { + if (dest < src) + ((char *)dest)[i] = ((char *)src)[i]; + else + ((char *)dest)[n - i - 1] = ((char *)src)[n - i - 1]; + i++; + } + return (dest); +} diff --git a/libft/ft_memset.c b/libft/ft_memset.c new file mode 100644 index 0000000..2ce9b1c --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 13:05:27 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:27:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t i; + char *dest; + + dest = (char *)s; + i = 0; + while (i < n) + { + dest[i] = (char)c; + i++; + } + return (dest); +} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..9b4b60a --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 14:29:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100644 index 0000000..d38533e --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 14:17:01 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); + write(fd, "\n", 1); +} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100644 index 0000000..426a0eb --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:32:29 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 17:23:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft.h" + +static void putunsigned(long nb, int fd) +{ + if (nb == 0) + return ; + putunsigned(nb / 10, fd); + ft_putchar_fd((char)(nb % 10) + '0', fd); +} + +void ft_putnbr_fd(int n, int fd) +{ + long nb; + + if (n < 0) + { + ft_putchar_fd('-', fd); + nb = -(long)n; + } + else + nb = n; + if (n == 0) + ft_putchar_fd('0', fd); + else + putunsigned(nb, fd); +} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100644 index 0000000..ce573ed --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 14:34:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); +} diff --git a/libft/ft_split.c b/libft/ft_split.c new file mode 100644 index 0000000..6bf5d24 --- /dev/null +++ b/libft/ft_split.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:47:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/12 13:24:04 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static int count_until(char const *s, char const c) +{ + int i; + + i = 0; + while (s[i] && s[i] != c) + i++; + return (i); +} + +static int count_words(char const *s, char c) +{ + int i; + int r; + int in_a_word; + + i = 0; + r = 0; + in_a_word = 0; + while (s[i]) + { + if (s[i] == c) + { + in_a_word = 0; + } + else if (!in_a_word) + { + in_a_word = 1; + r++; + } + i++; + } + return (r); +} + +static char **free_array(char ***array, int size) +{ + int i; + + i = 0; + while (i < size) + { + free((*array)[i]); + (*array)[i] = NULL; + i++; + } + free(*array); + *array = NULL; + return (NULL); +} + +static void ignore_sep(char const *s, char c, int *i) +{ + while (s[*i] == c) + (*i)++; +} + +char **ft_split(char const *s, char c) +{ + int size; + char **dest; + int i; + int str_i; + int len_until; + + size = count_words(s, c); + dest = malloc((size + 1) * sizeof(char *)); + if (!dest) + return (NULL); + i = -1; + str_i = 0; + while (++i < size) + { + ignore_sep(s, c, &str_i); + len_until = count_until(s + str_i, c); + dest[i] = ft_substr(s, str_i, len_until); + if (!dest[i]) + return (free_array(&dest, i)); + str_i += len_until; + } + dest[i] = NULL; + return (dest); +} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100644 index 0000000..9905568 --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 13:17:35 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strchr(const char *s, int c) +{ + int i; + + i = 0; + while (s[i]) + { + if (s[i] == c) + return ((char *)s + i); + i++; + } + if (s[i] == c) + return ((char *)s + i); + return (NULL); +} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100644 index 0000000..532571e --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/30 09:18:39 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 11:27:46 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strdup(const char *s) +{ + int len; + int i; + char *dest; + + len = 0; + while (s[len]) + len++; + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s[i]) + { + dest[i] = s[i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100644 index 0000000..7b5d2f7 --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 11:10:28 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + i = 0; + while (s[i]) + { + (*f)(i, s + i); + i++; + } +} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100644 index 0000000..f57b64d --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:31:45 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 11:25:38 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + int len; + char *dest; + int i; + int j; + + len = ft_strlen(s1) + ft_strlen(s2); + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s1[i]) + { + dest[i] = s1[i]; + i++; + } + j = 0; + while (s2[j]) + { + dest[i] = s2[j]; + i++; + j++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100644 index 0000000..ec95531 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/28 10:40:23 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 16:20:20 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t min(size_t a, size_t b) +{ + if (a < b) + return (a); + else + return (b); +} + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t dest_len; + size_t dest_i; + size_t src_i; + + dest_len = min(ft_strlen(dest), size); + if (dest_len < size - 1) + { + dest_i = dest_len; + src_i = 0; + while (src[src_i] && size > 0 && dest_i < size - 1) + { + dest[dest_i] = src[src_i]; + src_i++; + dest_i++; + } + if (size > 0) + dest[dest_i] = '\0'; + } + return (dest_len + ft_strlen(src)); +} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100644 index 0000000..80de6c9 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/25 20:39:39 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 11:44:13 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t i; + + i = 0; + while (src[i] && size > 0 && i < size - 1) + { + dest[i] = src[i]; + i++; + } + if (i < size) + dest[i] = '\0'; + while (src[i]) + i++; + return (i); +} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100644 index 0000000..f6c8804 --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/24 13:10:16 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:09:44 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + int i; + + i = 0; + while (s[i]) + i++; + return (i); +} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100644 index 0000000..556ad76 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */ +/* Updated: 2023/10/03 15:20:49 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *dest; + unsigned int i; + + dest = malloc((ft_strlen(s) + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (s[i]) + { + dest[i] = (*f)(i, s[i]); + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c new file mode 100644 index 0000000..c10af4c --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/10 12:21:33 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:39:03 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned int i; + + if (n == 0) + return (0); + i = 0; + while (i < n - 1 && s1[i] && s1[i] == s2[i]) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100644 index 0000000..ca93e48 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:50:23 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 16:09:21 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +// Return 1 if there is 'little' at the pos 'i' of 'big', or else 0. +static int match(const char *big, const char *little, size_t len, size_t i) +{ + int j; + + j = 0; + while (little[j]) + { + if (len <= i || big[i] != little[j]) + return (0); + i++; + j++; + } + return (1); +} + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + + i = 0; + if (!little[0]) + return ((char *)big); + if (!big[i] || i >= len) + return (NULL); + while (!match(big, little, len, i)) + { + i++; + if (!big[i] || i >= len) + return (NULL); + } + return ((char *)big + i); +} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100644 index 0000000..8b76716 --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 13:16:58 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strrchr(const char *s, int c) +{ + char *r; + int i; + + r = NULL; + i = 0; + while (s[i]) + { + if (s[i] == c) + r = (char *)s + i; + i++; + } + if (s[i] == c) + r = (char *)s + i; + return (r); +} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100644 index 0000000..e6d422e --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:39:33 by mcolonna #+# #+# */ +/* Updated: 2023/10/04 13:07:54 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static int is_in(char const c, char const *set) +{ + int i; + + i = 0; + while (set[i]) + { + if (set[i] == c) + return (1); + i++; + } + return (0); +} + +static size_t get_length(char const *s1, char const *set) +{ + size_t i; + size_t r; + size_t tmp; + + i = 0; + while (is_in(s1[i], set)) + i++; + r = 0; + tmp = 0; + while (s1[i]) + { + if (is_in(s1[i], set)) + { + tmp++; + } + else + { + r += tmp; + tmp = 0; + r++; + } + i++; + } + return (r); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t len; + char *dest; + size_t start; + size_t i; + + len = get_length(s1, set); + dest = malloc((len + 1) * sizeof(char)); + if (!dest) + return (NULL); + start = 0; + while (is_in(s1[start], set)) + start++; + i = 0; + while (i < len) + { + dest[i] = s1[start + i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_substr.c b/libft/ft_substr.c new file mode 100644 index 0000000..3a98490 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/03 11:17:12 by mcolonna #+# #+# */ +/* Updated: 2023/10/09 13:27:30 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *dest; + size_t s_len; + size_t dest_len; + size_t i; + + s_len = ft_strlen(s); + if (s_len < start) + dest_len = 0; + else if (s_len < start + len) + dest_len = s_len - start; + else + dest_len = len; + dest = malloc((dest_len + 1) * sizeof(char)); + if (!dest) + return (NULL); + i = 0; + while (i < dest_len) + { + dest[i] = s[start + i]; + i++; + } + dest[i] = '\0'; + return (dest); +} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100644 index 0000000..aa8f85f --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:58:02 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c - 'A' + 'a'); + return (c); +} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100644 index 0000000..f1b6727 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */ +/* Updated: 2023/10/02 16:56:52 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 'a' + 'A'); + return (c); +} diff --git a/libft/libft.h b/libft/libft.h new file mode 100644 index 0000000..6dbd635 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,196 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/02 11:46:15 by mcolonna #+# #+# */ +/* Updated: 2023/10/10 14:11:08 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include + +///// CHAR ///// + +// (In libc) Return 1 if the char 'c' is a specific type of char, or else 0. +int ft_isalpha(int c); // A-Za-z +int ft_isdigit(int c); // 0-9 +int ft_isalnum(int c); // A-Za-z0-9 +int ft_isascii(int c); // (0)-(127) +int ft_isprint(int c); // (32)-(126) + +// (In libc) Return the uppercase/lowercase version of the letter, +// or the char itself if it's not a letter. +int ft_toupper(int c); +int ft_tolower(int c); + +///// STR ///// + +// (In libc) Compare 2 strings until n +int ft_strncmp(const char *s1, const char *s2, size_t n); + +// (In libc) Return the length of the string 's'. +size_t ft_strlen(const char *s); + +// (In libc) Copy/Append src on dst. +// 'dst' will be 'size' chars max, including \0, +// except if 'dst' is already longer for strlcat(). +// 1. Never do more than size. +// 2. Always end by \0, except if it doesn't respect 1. +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlcat(char *dst, const char *src, size_t size); + +// (In libc) Return a pointer to the first of last char 'c' in 's', +// or return NULL if there aren't any. +char *ft_strchr(const char *s, int c); // First char. +char *ft_strrchr(const char *s, int c); // Last char. + +// (In libc) Return a pointer to the first occurence +// of string 'little' in string 'big'. +// Don't look chars after 'size'. +char *ft_strnstr(const char *big, const char *little, size_t len); + +// (In libc) Return an malloced duplicate of 's'. +// Uses: malloc +// Error: return NULL +char *ft_strdup(const char *s); + +// (Perso) Apply 'f' on each char of the string 's' and returns the result. +// Uses: malloc +// Error: return NULL +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); + +// (Perso) Call 'f' for each char of 's'. +void ft_striteri(char *s, void (*f)(unsigned int, char *)); + +// (Perso) Return the substring of 's' which starts at 'start' +// and is of length 'len'. +// Don't take chars after the end of the string. +// Uses: malloc +// Error: return NULL +char *ft_substr(char const *s, unsigned int start, size_t len); + +// (Perso) Concatenate the two strings. +// Uses: malloc +// Error: return NULL +char *ft_strjoin(char const *s1, char const *s2); + +// (Perso) Remove the characters 'set' from the beginning +// and the end of the string. +// Uses: malloc +// Error: return NULL +char *ft_strtrim(char const *s1, char const *set); + +// (Perso) Split 's' by the chars 'c'. +// Return an array ended by NULL. +// Uses: malloc +// Error: return NULL +char **ft_split(char const *s, char c); + +///// MEM ///// + +// (In libc) Fills 's' with 'n' times the char 'c'. +// Return 'c'. +void *ft_memset(void *s, int c, size_t n); + +// (In libc) Just ft_memset(s, '\0', n) lol. +void ft_bzero(void *s, size_t n); + +// (In libc) Copy 'n' bytes from 'src' to 'dest'. +// The 'src' and 'dest' areas mustn't overlap. +// Return 'dest'. +void *ft_memcpy(void *dest, const void *src, size_t n); + +// (In libc) Same, but the areas can overlap. +// Return 'dest'. +void *ft_memmove(void *dest, const void *src, size_t n); + +// (In libc) Find the character 'c' in 's', 's' being of length 'n'. +// NULL if none. +void *ft_memchr(const void *s, int c, size_t n); + +// (In libc) Compare 'n' bytes of 's1' and 's2'. +int ft_memcmp(const void *s1, const void *s2, size_t n); + +// (In libc) Alloc an array of 'size' elements with each element +// being of size 'size'. +// Uses: malloc +// Error: return NULL +void *ft_calloc(size_t nmemb, size_t size); + +///// CAST ///// + +// (In libc) Cast a string to an int. +// /[ \f\n\r\t\v]*[-+]?[0-9]*.*/ +int ft_atoi(const char *nptr); + +// (Perso) Cast an int to a string. +// Uses: malloc +// Error: return NULL +char *ft_itoa(int n); + +///// WRITE ///// + +// (Perso) Write the char/string on the file descriptor 'fd'. +// Uses: write +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int fd); + +// (Perso) Write the string 's' followed by a newline. +// Uses: write +void ft_putendl_fd(char *s, int fd); + +// (Perso) Write the number 'n'. +// Uses: write +void ft_putnbr_fd(int n, int fd); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +///// BONUS ///// + +// Create an malloced list of size = 1: {content} +// Uses: malloc +// Error: return NULL +t_list *ft_lstnew(void *content); + +// Add 'new' at the beginning of the list. +void ft_lstadd_front(t_list **lst, t_list *new); + +// Get the length of the list. +int ft_lstsize(t_list *lst); + +// Return the last node of the list. +t_list *ft_lstlast(t_list *lst); + +// Add 'new' at the end of the list. +void ft_lstadd_back(t_list **lst, t_list *new); + +// Apply 'del' on the element's content, then free lst. +// Uses: free +void ft_lstdelone(t_list *lst, void (*del)(void *)); + +// Free every element's content with del and free the elements. +// *lst will be set to NULL. +// Uses: free +void ft_lstclear(t_list **lst, void (*del)(void *)); + +// Apply f on the content of each node. +void ft_lstiter(t_list *lst, void (*f)(void *)); + +// Apply f on the content of each node +// and create a new list with the resulting contents. +// Uses: free, malloc +// Error: return NULL +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); + +#endif diff --git a/main.c b/main.c index 8636ca1..d1caa5e 100644 --- a/main.c +++ b/main.c @@ -2,9 +2,11 @@ void execclear(char *p, char **envp) { - execve(p, &p, envp); + (void)p; + (void)envp; } +// Print hi :D static void print_hi(void) { printf("Welcome to____________________________________\n"); @@ -48,7 +50,11 @@ void hello_message(char **path, char **envp) execclear(p[i], envp); } -int main(char **envp) +int main(int argc, char **argv, char **envp) { char **path = get_path(envp); -} \ No newline at end of file + + (void)argc; + (void)argv; + (void)path; +} diff --git a/minish.h b/minish.h index 0762bda..5d71ea1 100644 --- a/minish.h +++ b/minish.h @@ -7,16 +7,18 @@ # include # include # include +# include "libft.h" +///// PATH ///// + +// Get the PATH values. +// Return a list of strings ended by NULL. char **get_path(char **envp); + +// ??? TODO int search_path(char **path); + +// Copy the path list. 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 +#endif diff --git a/path.c b/path.c index 3a9d504..7cc903c 100644 --- a/path.c +++ b/path.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/16 12:07:26 by jschaft #+# #+# */ -/* Updated: 2024/04/23 15:08:11 by jschaft ### ########.fr */ +/* Updated: 2024/04/23 16:24:57 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,6 +56,6 @@ char **cp_path(char **path) re[i] = ft_strdup(path[i]); i++; } - re[i] == NULL; + re[i] = NULL; return (re); } diff --git a/util.c b/util.c deleted file mode 100644 index 48230d6..0000000 --- a/util.c +++ /dev/null @@ -1,114 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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); -}