Scaffold
This commit is contained in:
parent
f8b6ac11d4
commit
f6681abf47
|
@ -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' "<<<Norminette Failed!"; exit 1; }
|
||||
@#norminette $< >/dev/null || { printf '\033[107;41m%s\033[m\n' "!Norminette Failed>>>"; norminette $<; printf '\033[107;41m%s\033[m\n' "<<<Norminette Failed!"; exit 1; }
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR):
|
||||
|
@ -53,5 +57,15 @@ tests: test
|
|||
|
||||
test: re run fclean
|
||||
|
||||
SUCCESS_MSG=printf '\n\033[32m --- %s --- \033[m\n\n' "Test passed!"
|
||||
FAIL_MSG=printf '\n\033[31m --- %s --- \033[m\n\n' "Test failed!"
|
||||
SUCCESS=&& $(SUCCESS_MSG) || $(FAIL_MSG)
|
||||
FAIL=&& $(FAIL_MSG) || $(SUCCESS_MSG)
|
||||
run:
|
||||
./$(NAME)
|
||||
@clear
|
||||
./$(NAME) $(FAIL)
|
||||
./$(NAME) 1 $(SUCCESS)
|
||||
./$(NAME) "./dicts/numbers.dict" 1 $(SUCCESS)
|
||||
./$(NAME) 1 "./dicts/numbers.dict" $(FAIL)
|
||||
./$(NAME) 1 "./dicts/numb.dict" $(FAIL)
|
||||
./$(NAME) 1 2 3 $(FAIL)
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
Activate norminette in Makefile!!!
|
||||
Change .DEFAULT_GOAL in Makefile to 'all'
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_io.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/01 08:51:59 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/01 08:58:01 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_io.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* colors.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_io.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
|
@ -6,15 +6,19 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <unistd.h>
|
||||
# include <limits.h>
|
||||
# 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
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
26
ex00/main.c
26
ex00/main.c
|
@ -6,16 +6,32 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue