diff --git a/ex00/Makefile b/ex00/Makefile index 89f2ffa..b7f10f8 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -1,6 +1,10 @@ SRC = main.c \ - ft_lib.c -HEADERS = ft_lib.h + ft_lib.c \ + ft_io.c +HEADERS = main.h \ + ft_lib.h \ + ft_io.h \ + colors.h OBJDIR = obj INCDIR = include @@ -43,7 +47,7 @@ $(NAME): $(OBJ) $(OBJ): | $(OBJDIR) $(OBJDIR)/%.o: %.c $(DEPS) - @norminette $< >/dev/null || { printf '\033[107;41m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[107;41m%s\033[m\n' "<</dev/null || { printf '\033[107;41m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[107;41m%s\033[m\n' "<< +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/01 08:51:59 by tischmid #+# #+# */ +/* Updated: 2023/04/01 08:58:01 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_io.h" +#include +#include +#include + +int file_exists(char *path) +{ + int fd_num_dict = open(path, O_RDONLY, 0); + if (fd_num_dict < 0) + return (0); + if (close(fd_num_dict) < 0) + return (0); + return (1); +} diff --git a/ex00/ft_lib.c b/ex00/ft_lib.c index 874a805..0ca4a94 100644 --- a/ex00/ft_lib.c +++ b/ex00/ft_lib.c @@ -6,7 +6,7 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 07:13:31 by tischmid #+# #+# */ -/* Updated: 2023/04/01 07:13:58 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 08:29:48 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,37 @@ void ft_putchar(char c) write(1, &c, 1); } -void ft_puts(char *str) +void ft_putstr(char *str) { while (*str) ft_putchar(*str++); - ft_putchar('\n'); +} + +void ft_putnbr(int nb) +{ + if (nb > 9) + { + ft_putnbr(nb / 10); + ft_putchar(nb % 10 + '0'); + } + else if (nb == INT_MIN) + { + ft_putnbr(nb / 10); + ft_putnbr(-(nb % 10)); + } + else if (nb < 0) + { + ft_putchar('-'); + ft_putnbr(-nb); + } + else + ft_putchar(nb % 10 + '0'); +} + +int puterr(char *errmsg, int errcode) +{ + ft_putstr(RED); + ft_putstr(errmsg); + ft_putstr(RESET); + return (errcode); } diff --git a/ex00/include/colors.h b/ex00/include/colors.h new file mode 100644 index 0000000..9326c41 --- /dev/null +++ b/ex00/include/colors.h @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* colors.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/01 08:20:09 by tischmid #+# #+# */ +/* Updated: 2023/04/01 08:20:46 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COLORS_H +# define COLORS_H +# define RESET "\x1b[m" +# define RED "\x1b[31m" +# define GREEN "\x1b[32m" +# define YELLOW "\x1b[33m" +#endif diff --git a/ex00/include/ft_io.h b/ex00/include/ft_io.h new file mode 100644 index 0000000..378e0ff --- /dev/null +++ b/ex00/include/ft_io.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_io.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/01 08:52:17 by tischmid #+# #+# */ +/* Updated: 2023/04/01 08:52:30 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_IO_H +# define FT_IO_H + +int file_exists(char *path); + +#endif diff --git a/ex00/include/ft_lib.h b/ex00/include/ft_lib.h index d287ae3..d1685c0 100644 --- a/ex00/include/ft_lib.h +++ b/ex00/include/ft_lib.h @@ -6,15 +6,19 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 07:14:29 by tischmid #+# #+# */ -/* Updated: 2023/04/01 07:23:26 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 08:30:14 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_LIB_H # define FT_LIB_H # include +# include +# include "colors.h" void ft_putchar(char c); -void ft_puts(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int puterr(char *errmsg, int errcode); #endif diff --git a/ex00/include/main.h b/ex00/include/main.h new file mode 100644 index 0000000..6d73526 --- /dev/null +++ b/ex00/include/main.h @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/01 08:15:08 by tischmid #+# #+# */ +/* Updated: 2023/04/01 08:56:56 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAIN_H +# define MAIN_H + +#endif diff --git a/ex00/main.c b/ex00/main.c index f9367db..88c98a9 100644 --- a/ex00/main.c +++ b/ex00/main.c @@ -6,16 +6,32 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/01 07:11:58 by tischmid #+# #+# */ -/* Updated: 2023/04/01 07:41:31 by tischmid ### ########.fr */ +/* Updated: 2023/04/01 09:02:34 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ +#include "main.h" #include "ft_lib.h" +#include "ft_io.h" -int main(int argc, char **argv) +int arguments_valid(int argc, char **argv) { - (void)argc; - (void)argv; - ft_puts("Hello, World!"); + if (argc > 3) + return (0); + if (argc == 3) + if (!file_exists(argv[1])) + return (0); + if (argc < 2) + { + // TODO: Bonus: Use read to take nbr from stdin + return (0); + } + return (1); +} + +int main(int argc, char **argv) +{ + if (!arguments_valid(argc, argv)) + return (puterr("Error\n", 1)); return (0); } diff --git a/ex00/obj/ft_io.o b/ex00/obj/ft_io.o new file mode 100644 index 0000000..f2d9023 Binary files /dev/null and b/ex00/obj/ft_io.o differ diff --git a/ex00/obj/ft_lib.o b/ex00/obj/ft_lib.o new file mode 100644 index 0000000..5ae350c Binary files /dev/null and b/ex00/obj/ft_lib.o differ diff --git a/ex00/obj/main.o b/ex00/obj/main.o new file mode 100644 index 0000000..6270259 Binary files /dev/null and b/ex00/obj/main.o differ diff --git a/ex00/rush-02 b/ex00/rush-02 new file mode 100755 index 0000000..986b59d Binary files /dev/null and b/ex00/rush-02 differ