diff --git a/Makefile b/Makefile index 3ac1765..ac9d00c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -SRCS = main.c +UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_getstr.c filetester.c +SRCS = main.c ${UTILS_SRC} OBJS = ${SRCS:.c=.o} @@ -16,6 +17,7 @@ LIBS = libftx/libftx.a all: ${NAME} ${NAME}: ${OBJS} + make -C libftx all ${CC} ${OBJS} -o ${NAME} ${LIBS} clean: diff --git a/argprinter b/argprinter new file mode 100755 index 0000000..11c8a1d Binary files /dev/null and b/argprinter differ diff --git a/filetester.c b/filetester.c new file mode 100644 index 0000000..0e72bf4 --- /dev/null +++ b/filetester.c @@ -0,0 +1,41 @@ +#include "minishell" + +int ft_file_is_readable(char *path) +{ + int readable; + + 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(char *path) +{ + int writeable; + + fd = open(path, O_WRONLY | O_CREAT, 0644); + if (fd == -1) + { + ft_eprintf("bizarre l'erreur"); + return (0); + } + writeable = write(fd, "", 0); + if (writeable == -1) + { + ft_eprintf("minishell: %s: Permission denied\n", path); + return (0); + } + close(fd); + return (1); +} diff --git a/libftx/extra/extra.a b/libftx/extra/extra.a new file mode 100644 index 0000000..74485b5 Binary files /dev/null and b/libftx/extra/extra.a differ diff --git a/libftx/extra/ft_contain_only.o b/libftx/extra/ft_contain_only.o new file mode 100644 index 0000000..4b885eb Binary files /dev/null and b/libftx/extra/ft_contain_only.o differ diff --git a/libftx/extra/ft_freer.o b/libftx/extra/ft_freer.o new file mode 100644 index 0000000..cf50d16 Binary files /dev/null and b/libftx/extra/ft_freer.o differ diff --git a/libftx/extra/ft_is_in.o b/libftx/extra/ft_is_in.o new file mode 100644 index 0000000..9ac5767 Binary files /dev/null and b/libftx/extra/ft_is_in.o differ diff --git a/libftx/extra/ft_random_generator.o b/libftx/extra/ft_random_generator.o new file mode 100644 index 0000000..a64dbb0 Binary files /dev/null and b/libftx/extra/ft_random_generator.o differ diff --git a/libftx/extra/ft_strchri.o b/libftx/extra/ft_strchri.o new file mode 100644 index 0000000..230ddca Binary files /dev/null and b/libftx/extra/ft_strchri.o differ diff --git a/libftx/extra/ft_strcmp.o b/libftx/extra/ft_strcmp.o new file mode 100644 index 0000000..0ed8391 Binary files /dev/null and b/libftx/extra/ft_strcmp.o differ diff --git a/libftx/extra/ft_strfjoin.o b/libftx/extra/ft_strfjoin.o new file mode 100644 index 0000000..1a4743d Binary files /dev/null and b/libftx/extra/ft_strfjoin.o differ diff --git a/libftx/extra/ft_strgen.o b/libftx/extra/ft_strgen.o new file mode 100644 index 0000000..261ec45 Binary files /dev/null and b/libftx/extra/ft_strgen.o differ diff --git a/libftx/extra/ft_strmerger.o b/libftx/extra/ft_strmerger.o new file mode 100644 index 0000000..3526a30 Binary files /dev/null and b/libftx/extra/ft_strmerger.o differ diff --git a/libftx/extra/ft_strndup.o b/libftx/extra/ft_strndup.o new file mode 100644 index 0000000..14ec377 Binary files /dev/null and b/libftx/extra/ft_strndup.o differ diff --git a/libftx/extra/ft_tabrealloc.o b/libftx/extra/ft_tabrealloc.o new file mode 100644 index 0000000..973478b Binary files /dev/null and b/libftx/extra/ft_tabrealloc.o differ diff --git a/libftx/extra/ft_ultoa_base.o b/libftx/extra/ft_ultoa_base.o new file mode 100644 index 0000000..155c917 Binary files /dev/null and b/libftx/extra/ft_ultoa_base.o differ diff --git a/libftx/gnl/get_next_line.a b/libftx/gnl/get_next_line.a new file mode 100644 index 0000000..7d3ebe9 Binary files /dev/null and b/libftx/gnl/get_next_line.a differ diff --git a/libftx/gnl/get_next_line.o b/libftx/gnl/get_next_line.o new file mode 100644 index 0000000..46741e0 Binary files /dev/null and b/libftx/gnl/get_next_line.o differ diff --git a/libftx/libft/ft_atoi.o b/libftx/libft/ft_atoi.o new file mode 100644 index 0000000..749693b Binary files /dev/null and b/libftx/libft/ft_atoi.o differ diff --git a/libftx/libft/ft_bzero.o b/libftx/libft/ft_bzero.o new file mode 100644 index 0000000..77fec06 Binary files /dev/null and b/libftx/libft/ft_bzero.o differ diff --git a/libftx/libft/ft_calloc.o b/libftx/libft/ft_calloc.o new file mode 100644 index 0000000..a17b032 Binary files /dev/null and b/libftx/libft/ft_calloc.o differ diff --git a/libftx/libft/ft_isalnum.o b/libftx/libft/ft_isalnum.o new file mode 100644 index 0000000..717e49b Binary files /dev/null and b/libftx/libft/ft_isalnum.o differ diff --git a/libftx/libft/ft_isalpha.o b/libftx/libft/ft_isalpha.o new file mode 100644 index 0000000..fbdbbb4 Binary files /dev/null and b/libftx/libft/ft_isalpha.o differ diff --git a/libftx/libft/ft_isascii.o b/libftx/libft/ft_isascii.o new file mode 100644 index 0000000..67137be Binary files /dev/null and b/libftx/libft/ft_isascii.o differ diff --git a/libftx/libft/ft_isdigit.o b/libftx/libft/ft_isdigit.o new file mode 100644 index 0000000..6a91375 Binary files /dev/null and b/libftx/libft/ft_isdigit.o differ diff --git a/libftx/libft/ft_isprint.o b/libftx/libft/ft_isprint.o new file mode 100644 index 0000000..bde8775 Binary files /dev/null and b/libftx/libft/ft_isprint.o differ diff --git a/libftx/libft/ft_itoa.o b/libftx/libft/ft_itoa.o new file mode 100644 index 0000000..c75cfcb Binary files /dev/null and b/libftx/libft/ft_itoa.o differ diff --git a/libftx/libft/ft_memchr.o b/libftx/libft/ft_memchr.o new file mode 100644 index 0000000..f1c3326 Binary files /dev/null and b/libftx/libft/ft_memchr.o differ diff --git a/libftx/libft/ft_memcmp.o b/libftx/libft/ft_memcmp.o new file mode 100644 index 0000000..6b0da03 Binary files /dev/null and b/libftx/libft/ft_memcmp.o differ diff --git a/libftx/libft/ft_memcpy.o b/libftx/libft/ft_memcpy.o new file mode 100644 index 0000000..98e41b8 Binary files /dev/null and b/libftx/libft/ft_memcpy.o differ diff --git a/libftx/libft/ft_memmove.o b/libftx/libft/ft_memmove.o new file mode 100644 index 0000000..71f160b Binary files /dev/null and b/libftx/libft/ft_memmove.o differ diff --git a/libftx/libft/ft_memset.o b/libftx/libft/ft_memset.o new file mode 100644 index 0000000..2737808 Binary files /dev/null and b/libftx/libft/ft_memset.o differ diff --git a/libftx/libft/ft_putchar_fd.o b/libftx/libft/ft_putchar_fd.o new file mode 100644 index 0000000..58df18e Binary files /dev/null and b/libftx/libft/ft_putchar_fd.o differ diff --git a/libftx/libft/ft_putendl_fd.o b/libftx/libft/ft_putendl_fd.o new file mode 100644 index 0000000..50cfa1e Binary files /dev/null and b/libftx/libft/ft_putendl_fd.o differ diff --git a/libftx/libft/ft_putnbr_fd.o b/libftx/libft/ft_putnbr_fd.o new file mode 100644 index 0000000..17d4db5 Binary files /dev/null and b/libftx/libft/ft_putnbr_fd.o differ diff --git a/libftx/libft/ft_putstr_fd.o b/libftx/libft/ft_putstr_fd.o new file mode 100644 index 0000000..f795861 Binary files /dev/null and b/libftx/libft/ft_putstr_fd.o differ diff --git a/libftx/libft/ft_split.o b/libftx/libft/ft_split.o new file mode 100644 index 0000000..41a6b9f Binary files /dev/null and b/libftx/libft/ft_split.o differ diff --git a/libftx/libft/ft_strchr.o b/libftx/libft/ft_strchr.o new file mode 100644 index 0000000..dcad448 Binary files /dev/null and b/libftx/libft/ft_strchr.o differ diff --git a/libftx/libft/ft_strdup.o b/libftx/libft/ft_strdup.o new file mode 100644 index 0000000..82b9840 Binary files /dev/null and b/libftx/libft/ft_strdup.o differ diff --git a/libftx/libft/ft_striteri.o b/libftx/libft/ft_striteri.o new file mode 100644 index 0000000..8ecd945 Binary files /dev/null and b/libftx/libft/ft_striteri.o differ diff --git a/libftx/libft/ft_strjoin.o b/libftx/libft/ft_strjoin.o new file mode 100644 index 0000000..ec8e4ff Binary files /dev/null and b/libftx/libft/ft_strjoin.o differ diff --git a/libftx/libft/ft_strlcat.o b/libftx/libft/ft_strlcat.o new file mode 100644 index 0000000..01a3aa5 Binary files /dev/null and b/libftx/libft/ft_strlcat.o differ diff --git a/libftx/libft/ft_strlcpy.o b/libftx/libft/ft_strlcpy.o new file mode 100644 index 0000000..f3e39eb Binary files /dev/null and b/libftx/libft/ft_strlcpy.o differ diff --git a/libftx/libft/ft_strlen.o b/libftx/libft/ft_strlen.o new file mode 100644 index 0000000..3c92240 Binary files /dev/null and b/libftx/libft/ft_strlen.o differ diff --git a/libftx/libft/ft_strmapi.o b/libftx/libft/ft_strmapi.o new file mode 100644 index 0000000..c36b41b Binary files /dev/null and b/libftx/libft/ft_strmapi.o differ diff --git a/libftx/libft/ft_strncmp.o b/libftx/libft/ft_strncmp.o new file mode 100644 index 0000000..5af8cfb Binary files /dev/null and b/libftx/libft/ft_strncmp.o differ diff --git a/libftx/libft/ft_strnstr.o b/libftx/libft/ft_strnstr.o new file mode 100644 index 0000000..80ab0e1 Binary files /dev/null and b/libftx/libft/ft_strnstr.o differ diff --git a/libftx/libft/ft_strrchr.o b/libftx/libft/ft_strrchr.o new file mode 100644 index 0000000..4b6be03 Binary files /dev/null and b/libftx/libft/ft_strrchr.o differ diff --git a/libftx/libft/ft_strtrim.o b/libftx/libft/ft_strtrim.o new file mode 100644 index 0000000..b08e9b2 Binary files /dev/null and b/libftx/libft/ft_strtrim.o differ diff --git a/libftx/libft/ft_substr.o b/libftx/libft/ft_substr.o new file mode 100644 index 0000000..982ffda Binary files /dev/null and b/libftx/libft/ft_substr.o differ diff --git a/libftx/libft/ft_tolower.o b/libftx/libft/ft_tolower.o new file mode 100644 index 0000000..a1107d9 Binary files /dev/null and b/libftx/libft/ft_tolower.o differ diff --git a/libftx/libft/ft_toupper.o b/libftx/libft/ft_toupper.o new file mode 100644 index 0000000..a7c9dbf Binary files /dev/null and b/libftx/libft/ft_toupper.o differ diff --git a/libftx/libft/libft.a b/libftx/libft/libft.a new file mode 100644 index 0000000..6734924 Binary files /dev/null and b/libftx/libft/libft.a differ diff --git a/libftx/libftx.a b/libftx/libftx.a new file mode 100644 index 0000000..707690d Binary files /dev/null and b/libftx/libftx.a differ diff --git a/libftx/libftx.h b/libftx/libftx.h index e9d6a7a..3f74279 100644 --- a/libftx/libftx.h +++ b/libftx/libftx.h @@ -6,7 +6,7 @@ /* By: cchauvet +# include +# include -typedef struct s_list -{ - void *content; - void *next; - int tag; -} t_list +int ft_file_is_readable(char *path); +int ft_file_is_writeable(char *path); typedef struct cmd { diff --git a/utils/.ft_is_a_quote.c.swp b/utils/.ft_is_a_quote.c.swp new file mode 100644 index 0000000..222da86 Binary files /dev/null and b/utils/.ft_is_a_quote.c.swp differ diff --git a/utils/ft_getstr.c b/utils/ft_getstr.c new file mode 100644 index 0000000..c55fed4 --- /dev/null +++ b/utils/ft_getstr.c @@ -0,0 +1,27 @@ +#include "utils.h" + +char *ft_getstr(char *str, size_t n) +{ + size_t start; + size_t stop; + char c; + int quote; + + start = n; + stop = n; + quote = ft_is_in_quote(str, n); + if (quote == 0) + c = ' '; + else + { + if (quote == 1) + c = '\''; + else + c = '"'; + } + while (str[start - 1] != c && start > 0) + start--; + while (str[stop] != c && str[stop] != '\0') + stop++; + return (ft_strndup(str + start, stop - start)); +} diff --git a/utils/ft_getstr.o b/utils/ft_getstr.o new file mode 100644 index 0000000..8e8314f Binary files /dev/null and b/utils/ft_getstr.o differ diff --git a/utils/ft_is_in_quote.c b/utils/ft_is_in_quote.c new file mode 100644 index 0000000..3b697d1 --- /dev/null +++ b/utils/ft_is_in_quote.c @@ -0,0 +1,29 @@ +#include "utils.h" + +int ft_is_in_quote(char *str, size_t n) +{ + size_t double_quoted; + size_t simple_quoted; + size_t i; + + double_quoted = 0; + simple_quoted = 0; + i = 0; + while (str[i] != '\0' && i < n) + { + if (str[i] == '"') + { + if (simple_quoted == 0) + double_quoted = !double_quoted; + + } + if (str[i] == '\'') + { + if (double_quoted == 0) + simple_quoted = !simple_quoted; + + } + i++; + } + return (simple_quoted == 1 + (double_quoted == 1) * 2); +} diff --git a/utils/ft_is_in_quote.o b/utils/ft_is_in_quote.o new file mode 100644 index 0000000..e732a62 Binary files /dev/null and b/utils/ft_is_in_quote.o differ diff --git a/utils/ft_strnchr.c b/utils/ft_strnchr.c new file mode 100644 index 0000000..6654db9 --- /dev/null +++ b/utils/ft_strnchr.c @@ -0,0 +1,15 @@ +#include "utils.h" + +ssize_t ft_strnchr(char *str, char c) +{ + size_t i; + + i = 0; + while (str[i] != '\0') + { + if (str[i] == c) + return (i); + i++; + } + return (-1); +} diff --git a/utils/ft_strnchr.o b/utils/ft_strnchr.o new file mode 100644 index 0000000..d90543e Binary files /dev/null and b/utils/ft_strnchr.o differ diff --git a/utils/ft_strncpy.c b/utils/ft_strncpy.c new file mode 100644 index 0000000..16de576 --- /dev/null +++ b/utils/ft_strncpy.c @@ -0,0 +1,14 @@ +#include "utils.h" + +size_t ft_strncpy(char *dst, char *src, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + dst[i] = src[i]; + i++; + } + return (i); +} diff --git a/utils/ft_strncpy.o b/utils/ft_strncpy.o new file mode 100644 index 0000000..ba1c26e Binary files /dev/null and b/utils/ft_strncpy.o differ diff --git a/utils/ft_strreplace.c b/utils/ft_strreplace.c new file mode 100644 index 0000000..8a2a2ba --- /dev/null +++ b/utils/ft_strreplace.c @@ -0,0 +1,17 @@ +#include "utils.h" + +char *ft_strreplace(char *str, 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))); + if (out == NULL) + return (NULL); + ft_strncpy(out, str, start); + ft_strncpy(out + start, fill, ft_strlen(fill)); + sum = start + ft_strlen(fill); + ft_strncpy(out + sum, str + stop, ft_strlen(str) - stop); + out[sum + ft_strlen(str) - stop] = '\0'; + return (out); +} diff --git a/utils/ft_strreplace.o b/utils/ft_strreplace.o new file mode 100644 index 0000000..d5ff2c5 Binary files /dev/null and b/utils/ft_strreplace.o differ diff --git a/utils/utils.h b/utils/utils.h new file mode 100644 index 0000000..0f24105 --- /dev/null +++ b/utils/utils.h @@ -0,0 +1,12 @@ +#ifndef FT_UTILS +# define FT_UTILS +# 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); + +#endif