aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-30 18:36:30 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-30 18:36:30 +0100
commitaa244ec3fb071a7fd08494d04cc865b281502804 (patch)
tree4050030647cb9649b374b576c4dad7470840fc44
parentaa9613efb6fb39bd96fc4836b5d38c3746af1b15 (diff)
downloadlibft-aa244ec3fb071a7fd08494d04cc865b281502804.tar.gz
libft-aa244ec3fb071a7fd08494d04cc865b281502804.tar.bz2
libft-aa244ec3fb071a7fd08494d04cc865b281502804.zip
renaming header files, .libftignore file for simpler features selection
-rw-r--r--.gitignore3
-rw-r--r--.gitmodules3
-rw-r--r--.libftignore3
-rw-r--r--Makefile49
-rw-r--r--README.md15
-rw-r--r--include/ft_get_next_line.h35
-rw-r--r--include/libft.h25
-rw-r--r--include/libft_ctype.h (renamed from include/ft_ctype.h)0
-rw-r--r--include/libft_io.h (renamed from include/ft_io.h)19
-rw-r--r--include/libft_lst.h (renamed from include/ft_lst.h)0
-rw-r--r--include/libft_mem.h (renamed from include/ft_mem.h)0
-rw-r--r--include/libft_printf.h (renamed from include/ft_printf.h)0
-rw-r--r--include/libft_str.h (renamed from include/ft_str.h)0
-rw-r--r--include/libft_types.h (renamed from include/ft_types.h)3
-rw-r--r--libft.conf7
-rwxr-xr-xscript/find_src.sh21
-rwxr-xr-x[-rw-r--r--]script/generate_rendu.sh (renamed from scripts/generate_rendu.sh)0
-rw-r--r--src/io/ft_get_next_line.c113
-rw-r--r--src/io/ft_next_line.c101
19 files changed, 165 insertions, 232 deletions
diff --git a/.gitignore b/.gitignore
index a406d47..407a87b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,5 +5,4 @@
a.out
test_libft
main.c
-build/*
-test/*
+obj/*
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index b2fc13a..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "test/ctest"]
- path = test/ctest
- url = https://github.com/HappyTramp/ctest
diff --git a/.libftignore b/.libftignore
new file mode 100644
index 0000000..dfb5df9
--- /dev/null
+++ b/.libftignore
@@ -0,0 +1,3 @@
+*ft_printf*
+*ft_ht*
+*ft_lst*
diff --git a/Makefile b/Makefile
index f7e97c6..27ac82e 100644
--- a/Makefile
+++ b/Makefile
@@ -17,55 +17,26 @@ MAKE_ARGS = --no-print-directory
CC = gcc
CCFLAGS = -I$(INCLUDE_DIR) -Wall -Wextra -Werror
-NAME = libft.a
SRC_DIR = src
INCLUDE_DIR = include
-BUILD_DIR = build
-TEST_DIR = test
-
-# AVAILABLE_FEATURES = get_next_line ft_printf ft_lst
-CONF_FILE = libft.conf
+OBJ_DIR = obj
+SCRIPT_DIR = script
-ifndef (FEATURES)
-endif
-ifeq ($(wildcard $(CONF_FILE)),)
-$(warning "No configuration file found with name $(CONF_FILE), using default")
- FEATURES = get_next_line
- CCFLAGS += -D FT_FEATURES_FT_GET_NEXT_LINE
-else
- FEATURES = $(shell sed -n 's/FEATURES=//p' $(CONF_FILE))
-endif
+IGNORE_FILE = .libftignore
+IGNORE_DEFAULT = ft_printf
-ifeq ($(findstring get_next_line,$(FEATURES)),)
- FIND_ARGS += -not -name "ft_get_next_line.c"
-else
- CCFLAGS += -D FT_FEATURES_FT_GET_NEXT_LINE
-endif
-ifeq ($(findstring ft_printf,$(FEATURES)),)
- FIND_ARGS += -not -path "*printf*"
-else
- CCFLAGS += -D FT_FEATURES_FT_PRINTF
-endif
-ifeq ($(findstring ft_lst,$(FEATURES)),)
- FIND_ARGS += -not -name "ft_lst*.c"
-else
- CCFLAGS += -D FT_FEATURES_FT_LST
-endif
+NAME = libft.a
-SRC = $(shell find $(SRC_DIR) $(FIND_ARGS) -name "*.c")
-OBJ = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
+SRC = $(shell sh $(SCRIPT_DIR)/find_src.sh $(IGNORE_FILE))
+OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
HEADER = $(shell find $(INCLUDE_DIR) -name "*.h")
all: make_build_dirs $(NAME)
-.PHONY: test
-test:
- @$(MAKE) $(MAKE_ARGS) -C $(TEST_DIR) run_raw
-
make_build_dirs:
@for dir in $$(find $(SRC_DIR)/* $(FIND_ARGS) -type d | \
- sed 's_$(SRC_DIR)/_$(BUILD_DIR)/_g'); \
+ sed 's_$(SRC_DIR)/_$(OBJ_DIR)/_g'); \
do \
if [ ! -d "$$dir" ]; then \
mkdir -p $$dir; echo "Making build dir: $$dir"; fi \
@@ -75,13 +46,13 @@ $(NAME): $(OBJ) $(HEADER)
@echo "Linking: $@"
@$(LIB) $@ $(OBJ)
-$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@echo "Compiling: $@"
@$(CC) $(CCFLAGS) -c -o $@ $<
clean:
@echo "Removing objects"
- @$(RM) -r $(BUILD_DIR)
+ @$(RM) -r $(OBJ_DIR)
fclean: clean
@echo "Removing library"
diff --git a/README.md b/README.md
index 632fa8b..875f6e0 100644
--- a/README.md
+++ b/README.md
@@ -12,20 +12,9 @@ make all
This will produce a `libft.a` library which you can link to your project.
-## Testing
+## .libftignore
-To install the test, you will have to clone this repo with the `--recurse-submodules` flag or run the following commands:
-
-```
-git submodule init
-git submodule update
-```
-
-Then: `make test`
-
-## Dependencies
-
-* [CTest](https://github.com/HappyTramp/ctest) - my testing library
+Much like the `.gitignore` file, you can put the files/directory to ignore when compiling.
### School turn in
diff --git a/include/ft_get_next_line.h b/include/ft_get_next_line.h
deleted file mode 100644
index 03bf344..0000000
--- a/include/ft_get_next_line.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* get_next_line.h :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 13:52:59 by cacharle #+# #+# */
-/* Updated: 2020/01/17 10:53:43 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#ifndef FT_GET_NEXT_LINE_H
-# define FT_GET_NEXT_LINE_H
-
-# include <unistd.h>
-# include <stdlib.h>
-# include <limits.h>
-# include "libft.h"
-
-# ifndef GNL_BUFFER_SIZE
-# define GNL_BUFFER_SIZE 32
-# endif
-
-# define GNL_STATUS_LINE 1
-# define GNL_STATUS_EOF 0
-# define GNL_STATUS_ERROR -1
-
-/*
-** get_next_line.c
-*/
-
-int get_next_line(int fd, char **line);
-
-#endif
diff --git a/include/libft.h b/include/libft.h
index 0b4d608..898c7d9 100644
--- a/include/libft.h
+++ b/include/libft.h
@@ -20,30 +20,15 @@
# include <limits.h>
# include <errno.h>
-# include "ft_types.h"
-# include "ft_ctype.h"
-# include "ft_io.h"
-# include "ft_mem.h"
-# include "ft_str.h"
-
-# ifdef FT_FEATURES_FT_LST
-# include "ft_lst.h"
-# endif
-
-# ifdef FT_FEATURES_FT_GET_NEXT_LINE
-# include "ft_get_next_line.h"
-# endif
-
-# ifdef FT_FEATURES_FT_PRINTF
-# include "ft_printf.h"
-# endif
+# include "libft_types.h"
+# include "libft_ctype.h"
+# include "libft_io.h"
+# include "libft_mem.h"
+# include "libft_str.h"
# ifdef __linux__
# include <stdio.h>
# define OPEN_MAX FOPEN_MAX
# endif
-# define TRUE 1
-# define FALSE 0
-
#endif
diff --git a/include/ft_ctype.h b/include/libft_ctype.h
index 44e88b8..44e88b8 100644
--- a/include/ft_ctype.h
+++ b/include/libft_ctype.h
diff --git a/include/ft_io.h b/include/libft_io.h
index 8c633fb..f4c223b 100644
--- a/include/ft_io.h
+++ b/include/libft_io.h
@@ -13,6 +13,11 @@
#ifndef FT_IO_H
# define FT_IO_H
+# include <unistd.h>
+# include <stdlib.h>
+# include <limits.h>
+# include "libft.h"
+
void ft_putendl(char *s);
void ft_putchar(char c);
void ft_putstr(char const *s);
@@ -22,4 +27,18 @@ void ft_putstr_fd(char *s, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
+# ifndef FTNL_BUFFER_SIZE
+# define FTNL_BUFFER_SIZE 32
+# endif
+
+# define FTNL_STATUS_LINE 1
+# define FTNL_STATUS_EOF 0
+# define FTNL_STATUS_ERROR -1
+
+/*
+** get_next_line.c
+*/
+
+int ft_next_line(int fd, char **line);
+
#endif
diff --git a/include/ft_lst.h b/include/libft_lst.h
index 23fb192..23fb192 100644
--- a/include/ft_lst.h
+++ b/include/libft_lst.h
diff --git a/include/ft_mem.h b/include/libft_mem.h
index d1e47f6..d1e47f6 100644
--- a/include/ft_mem.h
+++ b/include/libft_mem.h
diff --git a/include/ft_printf.h b/include/libft_printf.h
index 615039b..615039b 100644
--- a/include/ft_printf.h
+++ b/include/libft_printf.h
diff --git a/include/ft_str.h b/include/libft_str.h
index 105da79..105da79 100644
--- a/include/ft_str.h
+++ b/include/libft_str.h
diff --git a/include/ft_types.h b/include/libft_types.h
index b465382..04c9f02 100644
--- a/include/ft_types.h
+++ b/include/libft_types.h
@@ -13,6 +13,9 @@
#ifndef FT_TYPES_H
# define FT_TYPES_H
+# define TRUE 1
+# define FALSE 0
+
typedef unsigned char t_ftbyte;
typedef int t_ftbool;
typedef unsigned int t_ftsize;
diff --git a/libft.conf b/libft.conf
deleted file mode 100644
index 47f2a55..0000000
--- a/libft.conf
+++ /dev/null
@@ -1,7 +0,0 @@
-# Making
-
-FEATURES=get_next_line ft_lst
-
-# Repository
-
-RENDU_IGNORE=subject.pdf README.md scripts build test libft.conf
diff --git a/script/find_src.sh b/script/find_src.sh
new file mode 100755
index 0000000..1d645a1
--- /dev/null
+++ b/script/find_src.sh
@@ -0,0 +1,21 @@
+#!bin/sh
+
+if [ $# -ne 1 ]; then
+ echo "Usage $0 ignore_file"
+ exit 1
+fi
+
+IGNORE_FILE=$1
+
+if [ ! -e $IGNORE_FILE ]; then
+ echo "Ignore file doesnt exist"
+ exit 1
+fi
+
+SRC_DIR=src
+
+IGNORE_FIND_ARGS=`sed 's/.*/-not -path "&"/' $IGNORE_FILE | paste -sd " "`
+IGNORE_FIND_ARGS="$IGNORE_FIND_ARGS -not -name \"*inter*\""
+
+sh -c "find $SRC_DIR $IGNORE_FIND_ARGS -name \"*.c\""
+# find $SRC_DIR $IGNORE_FIND_ARGS -name "*.c"
diff --git a/scripts/generate_rendu.sh b/script/generate_rendu.sh
index 1b68a97..1b68a97 100644..100755
--- a/scripts/generate_rendu.sh
+++ b/script/generate_rendu.sh
diff --git a/src/io/ft_get_next_line.c b/src/io/ft_get_next_line.c
deleted file mode 100644
index 4aecf3c..0000000
--- a/src/io/ft_get_next_line.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* get_next_line.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */
-/* Updated: 2020/01/17 10:53:23 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-
-static int gnl_find_newline(char *str)
-{
- int i;
-
- i = -1;
- while (str[++i])
- if (str[i] == '\n')
- return (i);
- return (-1);
-}
-
-static int gnl_free_return(char **ptr, char **ptr2, int ret)
-{
- if (ptr != NULL)
- {
- free(*ptr);
- *ptr = NULL;
- }
- if (ptr2 != NULL)
- {
- free(*ptr2);
- *ptr2 = NULL;
- }
- return (ret);
-}
-
-static int gnl_read_line(int fd, char **line, char *rest)
-{
- int ret;
- int split_at;
- char *buf;
-
- if ((buf = malloc(sizeof(char) * (GNL_BUFFER_SIZE + 1))) == NULL)
- return (gnl_free_return(line, NULL, GNL_STATUS_ERROR));
- while ((ret = read(fd, buf, GNL_BUFFER_SIZE)) > 0)
- {
- buf[ret] = '\0';
- if ((split_at = gnl_find_newline(buf)) != -1)
- {
- ft_strcpy(rest, buf + split_at + 1);
- buf[split_at] = '\0';
- if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL)
- return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR));
- return (gnl_free_return(&buf, NULL, GNL_STATUS_LINE));
- }
- if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL)
- return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR));
- }
- if (ret == -1)
- return (gnl_free_return(&buf, line, GNL_STATUS_ERROR));
- return (gnl_free_return(&buf, NULL, ret));
-}
-
-/*
-** if has rest:
-** if rest has newline:
-** push rest until newline in line, shift rest
-** return LINE_READ
-** else:
-** push rest in line
-**
-** while can read fd in buf
-** if buf has newline:
-** push buf until newline in line
-** push buf after newline in rest
-** return LINE_READ
-** push buf in line
-**
-** return GNL_EOF
-*/
-
-int get_next_line(int fd, char **line)
-{
- int split_at;
- static char rest[OPEN_MAX][GNL_BUFFER_SIZE + 1] = {{0}};
-
- if (fd < 0 || fd > OPEN_MAX || line == NULL || GNL_BUFFER_SIZE <= 0)
- return (GNL_STATUS_ERROR);
- if ((*line = ft_strdup("")) == NULL)
- return (GNL_STATUS_ERROR);
- if (rest[fd][0] == '\0')
- return (gnl_read_line(fd, line, rest[fd]));
- if ((split_at = gnl_find_newline(rest[fd])) != -1)
- {
- free(*line);
- if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL)
- return (GNL_STATUS_ERROR);
- ft_strncpy(*line, rest[fd], split_at);
- (*line)[split_at] = '\0';
- ft_strcpy(rest[fd], rest[fd] + split_at + 1);
- return (GNL_STATUS_LINE);
- }
- free(*line);
- if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1))))
- return (GNL_STATUS_ERROR);
- ft_strcpy(*line, rest[fd]);
- rest[fd][0] = '\0';
- return (gnl_read_line(fd, line, rest[fd]));
-}
diff --git a/src/io/ft_next_line.c b/src/io/ft_next_line.c
new file mode 100644
index 0000000..59e245b
--- /dev/null
+++ b/src/io/ft_next_line.c
@@ -0,0 +1,101 @@
+#include "libft.h"
+
+static int st_find_newline(char *str)
+{
+ int i;
+
+ i = -1;
+ while (str[++i])
+ if (str[i] == '\n')
+ return (i);
+ return (-1);
+}
+
+static int st_free_return(char **ptr, char **ptr2, int ret)
+{
+ if (ptr != NULL)
+ {
+ free(*ptr);
+ *ptr = NULL;
+ }
+ if (ptr2 != NULL)
+ {
+ free(*ptr2);
+ *ptr2 = NULL;
+ }
+ return (ret);
+}
+
+static int st_read_line(int fd, char **line, char *rest)
+{
+ int ret;
+ int split_at;
+ char *buf;
+
+ if ((buf = malloc(sizeof(char) * (FTNL_BUFFER_SIZE + 1))) == NULL)
+ return (st_free_return(line, NULL, FTNL_STATUS_ERROR));
+ while ((ret = read(fd, buf, FTNL_BUFFER_SIZE)) > 0)
+ {
+ buf[ret] = '\0';
+ if ((split_at = st_find_newline(buf)) != -1)
+ {
+ ft_strcpy(rest, buf + split_at + 1);
+ buf[split_at] = '\0';
+ if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL)
+ return (st_free_return(&buf, NULL, FTNL_STATUS_ERROR));
+ return (st_free_return(&buf, NULL, FTNL_STATUS_LINE));
+ }
+ if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL)
+ return (st_free_return(&buf, NULL, FTNL_STATUS_ERROR));
+ }
+ if (ret == -1)
+ return (st_free_return(&buf, line, FTNL_STATUS_ERROR));
+ return (st_free_return(&buf, NULL, ret));
+}
+
+/*
+** if has rest:
+** if rest has newline:
+** push rest until newline in line, shift rest
+** return LINE_READ
+** else:
+** push rest in line
+**
+** while can read fd in buf
+** if buf has newline:
+** push buf until newline in line
+** push buf after newline in rest
+** return LINE_READ
+** push buf in line
+**
+** return FTNL_EOF
+*/
+
+int ft_next_line(int fd, char **line)
+{
+ int split_at;
+ static char rest[OPEN_MAX][FTNL_BUFFER_SIZE + 1] = {{0}};
+
+ if (fd < 0 || fd > OPEN_MAX || line == NULL || FTNL_BUFFER_SIZE <= 0)
+ return (FTNL_STATUS_ERROR);
+ if ((*line = ft_strdup("")) == NULL)
+ return (FTNL_STATUS_ERROR);
+ if (rest[fd][0] == '\0')
+ return (st_read_line(fd, line, rest[fd]));
+ if ((split_at = st_find_newline(rest[fd])) != -1)
+ {
+ free(*line);
+ if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL)
+ return (FTNL_STATUS_ERROR);
+ ft_strncpy(*line, rest[fd], split_at);
+ (*line)[split_at] = '\0';
+ ft_strcpy(rest[fd], rest[fd] + split_at + 1);
+ return (FTNL_STATUS_LINE);
+ }
+ free(*line);
+ if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1))))
+ return (FTNL_STATUS_ERROR);
+ ft_strcpy(*line, rest[fd]);
+ rest[fd][0] = '\0';
+ return (st_read_line(fd, line, rest[fd]));
+}