generated from NaBuchholz/ft_template_repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nathalia Vitoria Buchholz
committed
Jan 3, 2025
1 parent
260defd
commit fa0cfaf
Showing
14 changed files
with
320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: nbuchhol <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2025/01/03 12:09:52 by nbuchhol #+# #+# # | ||
# Updated: 2025/01/03 12:12:09 by nbuchhol ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME = solong | ||
CC = cc | ||
CFLAGS = -Wall -Wextra -Werror | ||
SRC = | ||
OBJ = ${SRC:.c=.o} | ||
RM = rm -f | ||
|
||
all: ${NAME} | ||
|
||
${NAME}: ${OBJ} | ||
ar rcs ${NAME} ${OBJ} | ||
|
||
%.o: %.c | ||
@${CC} ${CFLAGS} -c $^ -o $@ | ||
|
||
clean: | ||
${RM} ${OBJ} | ||
|
||
fclean: clean | ||
${RM} ${NAME} | ||
|
||
re: fclean all | ||
|
||
.PHONY = all clean fclean re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* so_long.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: nbuchhol <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2025/01/03 12:15:22 by nbuchhol #+# #+# */ | ||
/* Updated: 2025/01/03 13:51:07 by nbuchhol ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef SO_LONG_H | ||
# define SO_LONG_H | ||
|
||
# include <stdlib.h> | ||
# include <unistd.h> | ||
|
||
# ifndef BUFFER_SIZE | ||
# define BUFFER_SIZE 42 | ||
# endif // END BUFFER_SIZE | ||
|
||
int validate_map(char *map); | ||
size_t ft_strlen(const char *s); | ||
char *ft_strchr(const char *s, int c); | ||
char *ft_strjoin(const char *s1, const char *s2); | ||
void *ft_calloc(size_t nmemb, size_t size); | ||
char *ft_substr(const char *s, unsigned int start, size_t len); | ||
char *get_next_line(int fd); | ||
|
||
#endif // SO_LONG | ||
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* get_next_line.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: nbuchhol <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/10/29 13:06:53 by nbuchhol #+# #+# */ | ||
/* Updated: 2025/01/03 13:50:05 by nbuchhol ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/so_long.h" | ||
|
||
static char *ft_strdup(const char *s1) | ||
{ | ||
char *buffer; | ||
size_t len; | ||
size_t i; | ||
|
||
len = ft_strlen(s1); | ||
buffer = malloc(len + 1); | ||
if (!buffer) | ||
return (NULL); | ||
i = 0; | ||
while (s1[i] != '\0') | ||
{ | ||
buffer[i] = s1[i]; | ||
i++; | ||
} | ||
buffer[i] = '\0'; | ||
return (buffer); | ||
} | ||
|
||
static char *ft_free(char **buffer, char **stash) | ||
{ | ||
if (buffer && *buffer) | ||
{ | ||
free(*buffer); | ||
*buffer = NULL; | ||
} | ||
if (stash && *stash) | ||
{ | ||
free(*stash); | ||
*stash = NULL; | ||
} | ||
return (NULL); | ||
} | ||
|
||
static char *read_and_stash(int fd, char *stash) | ||
{ | ||
char *temp; | ||
char *read_buffer; | ||
ssize_t bytes_read; | ||
|
||
if (!stash) | ||
stash = ft_calloc(1, sizeof(char)); | ||
read_buffer = ft_calloc(BUFFER_SIZE + 1, sizeof(char)); | ||
bytes_read = 1; | ||
while (!ft_strchr(stash, '\n') && bytes_read != 0) | ||
{ | ||
bytes_read = read(fd, read_buffer, BUFFER_SIZE); | ||
if (bytes_read == -1) | ||
return (ft_free(&read_buffer, &stash)); | ||
read_buffer[bytes_read] = '\0'; | ||
temp = ft_strjoin(stash, read_buffer); | ||
ft_free(NULL, &stash); | ||
stash = temp; | ||
} | ||
ft_free(&read_buffer, NULL); | ||
if ((stash[0] == '\0' || !stash) && bytes_read == 0) | ||
ft_free(NULL, &stash); | ||
return (stash); | ||
} | ||
|
||
static char *get_line(char **stash) | ||
{ | ||
char *line; | ||
char *new_buffer; | ||
size_t len; | ||
|
||
if (ft_strchr(*stash, '\n')) | ||
{ | ||
len = ft_strchr(*stash, '\n') - *stash + 1; | ||
line = ft_substr(*stash, 0, len); | ||
new_buffer = ft_strdup(*stash + len); | ||
ft_free(NULL, stash); | ||
*stash = new_buffer; | ||
} | ||
else | ||
{ | ||
line = ft_strdup(*stash); | ||
ft_free(NULL, stash); | ||
} | ||
return (line); | ||
} | ||
|
||
char *get_next_line(int fd) | ||
{ | ||
static char *stash; | ||
char *line; | ||
|
||
if (fd < 0 || BUFFER_SIZE <= 0) | ||
return (NULL); | ||
stash = read_and_stash(fd, stash); | ||
if (!stash) | ||
return (NULL); | ||
line = get_line(&stash); | ||
if (!line) | ||
return (ft_free(NULL, &stash)); | ||
return (line); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* get_next_line_utils.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: nbuchhol <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/10/29 13:06:56 by nbuchhol #+# #+# */ | ||
/* Updated: 2025/01/03 13:50:23 by nbuchhol ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/so_long.h" | ||
|
||
size_t ft_strlen(const char *s) | ||
{ | ||
size_t i; | ||
|
||
i = 0; | ||
while (s[i]) | ||
i++; | ||
return (i); | ||
} | ||
|
||
char *ft_strchr(const char *s1, int c) | ||
{ | ||
if (!s1) | ||
return (NULL); | ||
while (*s1) | ||
{ | ||
if (*s1 == (char)c) | ||
return ((char *)s1); | ||
s1++; | ||
} | ||
if (*s1 == (char)c) | ||
return ((char *)s1); | ||
return (NULL); | ||
} | ||
|
||
char *ft_strjoin(const char *prefix, const char *suffix) | ||
{ | ||
char *str; | ||
size_t i; | ||
size_t j; | ||
|
||
if (!prefix && !suffix) | ||
return (NULL); | ||
str = malloc(sizeof(char) * (ft_strlen(prefix) + ft_strlen(suffix) + 1)); | ||
if (!str) | ||
return (NULL); | ||
i = 0; | ||
while (*prefix) | ||
str[i++] = *prefix++; | ||
j = 0; | ||
while (suffix[j]) | ||
str[i++] = suffix[j++]; | ||
str[i] = '\0'; | ||
return (str); | ||
} | ||
|
||
void *ft_calloc(size_t nmemb, size_t size) | ||
{ | ||
size_t length; | ||
void *buffer; | ||
unsigned char *ptr; | ||
size_t i; | ||
|
||
if ((nmemb != 0 && size) > ((size_t)-1) / nmemb) | ||
return (NULL); | ||
length = size * nmemb; | ||
buffer = malloc(length); | ||
if (!buffer) | ||
return (NULL); | ||
ptr = (unsigned char *)buffer; | ||
i = 0; | ||
while (i < length) | ||
ptr[i++] = 0; | ||
return (buffer); | ||
} | ||
|
||
char *ft_substr(const char *s, unsigned int start, size_t len) | ||
{ | ||
size_t size; | ||
size_t i; | ||
char *buffer; | ||
|
||
if (!s) | ||
return (NULL); | ||
size = ft_strlen(s); | ||
if (start >= size) | ||
return (ft_calloc(1, sizeof(char))); | ||
if (start + len > size) | ||
len = size - start; | ||
buffer = malloc(len + 1); | ||
if (!buffer) | ||
return (NULL); | ||
i = 0; | ||
while (i < len) | ||
buffer[i++] = s[start++]; | ||
buffer[i] = '\0'; | ||
return (buffer); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* so_long.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: nbuchhol <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2025/01/03 12:12:47 by nbuchhol #+# #+# */ | ||
/* Updated: 2025/01/03 12:24:48 by nbuchhol ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/so_long.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 2 || argv == NULL) | ||
return (1); | ||
if (!validate_map) | ||
return (1); | ||
return (0); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* validate_map.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: nbuchhol <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2025/01/03 12:22:54 by nbuchhol #+# #+# */ | ||
/* Updated: 2025/01/03 12:28:07 by nbuchhol ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int validate_map(char *map) | ||
{ | ||
return (0); | ||
} |