Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zynthatrix committed Jun 14, 2023
1 parent 91b095f commit 707f6f5
Show file tree
Hide file tree
Showing 59 changed files with 1,851 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Users/superbia/Desktop/push_swap/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"cStandard": "c23",
"cppStandard": "c++23",
"intelliSenseMode": "macos-clang-arm64",
"compilerPath": "/usr/bin/gcc"
}
],
"version": 4
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"push_swap.h": "c",
"libft.h": "c"
}
}
54 changes: 54 additions & 0 deletions libft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: osericol <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/04/06 12:30:04 by osericol #+# #+# #
# Updated: 2023/04/26 12:05:42 by osericol ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a

SRCS = ./ft_isalpha.c ./ft_isdigit.c ./ft_isalnum.c ./ft_isascii.c \
./ft_isprint.c ./ft_strlen.c ./ft_memset.c ./ft_bzero.c ./ft_memcpy.c \
./ft_memmove.c ./ft_strlcpy.c ./ft_strlcat.c ./ft_toupper.c \
./ft_tolower.c ./ft_strchr.c ./ft_strrchr.c ./ft_strncmp.c \
./ft_memchr.c ./ft_memcmp.c ./ft_strnstr.c ./ft_atoi.c ./ft_calloc.c \
./ft_strdup.c ./ft_substr.c ./ft_strjoin.c ./ft_strtrim.c ./ft_split.c \
./ft_itoa.c ./ft_strmapi.c ./ft_striteri.c ./ft_putchar_fd.c \
./ft_putstr_fd.c ./ft_putendl_fd.c ./ft_putnbr_fd.c \

BONUS = ./ft_lstnew.c ./ft_lstadd_front.c ./ft_lstsize.c ./ft_lstlast.c \
./ft_lstadd_back.c ./ft_lstdelone.c ./ft_lstclear.c ./ft_lstiter.c \
./ft_lstmap.c \

OBJS = ${SRCS:.c=.o}

OBJSBONUS = ${BONUS:.c=.o}

CC = gcc
RM = rm -f

CFLAGS = -Wall -Wextra -Werror

.c.o:
${CC} ${CFLAGS} -g -c $< -o ${<:.c=.o}

$(NAME): ${OBJS}
ar rcs ${NAME} ${OBJS}

bonus: ${OBJSBONUS}
ar rcs ${NAME} ${OBJSBONUS}

all: ${NAME}

clean:
${RM} ${OBJS} ${OBJSBONUS}

fclean: clean
${RM} ${NAME}

re: fclean all
49 changes: 49 additions & 0 deletions libft/ft_atoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 17:15:28 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:29 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

static int ft_isspace(char ch)
{
if (ch == ' ' || ch == '\f' || ch == '\n' \
|| ch == '\r' || ch == '\t' || ch == '\v')
return (1);
return (0);
}

int ft_atoi(const char *str)
{
const char *ptr;
int sign;
int result;

ptr = str;
sign = 1;
result = 0;
while (ft_isspace(*ptr))
ptr++;
if (*ptr == '+')
{
ptr++;
}
else if (*ptr == '-')
{
sign *= -1;
ptr++;
}
while (*ptr >= '0' && *ptr <= '9')
{
result = (result * 10) + (*ptr - '0');
ptr++;
}
return (result * sign);
}
27 changes: 27 additions & 0 deletions libft/ft_bzero.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 14:15:46 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:30 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void ft_bzero(void *s, size_t n)
{
unsigned char *ptr;
size_t i;

ptr = (unsigned char *)s;
i = 0;
while (i < n)
{
ptr[i] = 0;
i++;
}
}
32 changes: 32 additions & 0 deletions libft/ft_calloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 17:29:41 by osericol #+# #+# */
/* Updated: 2023/04/26 10:45:45 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

void *ft_calloc(size_t count, size_t size)
{
void *ptr;
size_t i;

i = count * size;
if (count + size < count)
return (NULL);
ptr = malloc(count * size);
if (ptr == NULL)
return (NULL);
while (i > 0)
{
i--;
((char *)ptr)[i] = 0;
}
return (ptr);
}
21 changes: 21 additions & 0 deletions libft/ft_isalnum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 12:47:00 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:32 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isalnum(int c)
{
if (ft_isalpha(c) || ft_isdigit(c))
return (1);
else
return (0);
}
21 changes: 21 additions & 0 deletions libft/ft_isalpha.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 12:44:49 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:33 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
else
return (0);
}
21 changes: 21 additions & 0 deletions libft/ft_isascii.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 12:48:10 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:34 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
else
return (0);
}
21 changes: 21 additions & 0 deletions libft/ft_isdigit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 12:45:21 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:35 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
else
return (0);
}
21 changes: 21 additions & 0 deletions libft/ft_isprint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/27 12:48:56 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:40 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
else
return (0);
}
80 changes: 80 additions & 0 deletions libft/ft_itoa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: osericol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/03 18:39:17 by osericol #+# #+# */
/* Updated: 2023/04/26 11:52:37 by osericol ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

static void ft_swap(char *a, char *b)
{
char tmp;

tmp = *a;
*a = *b;
*b = tmp;
}

static char *ft_strrev(char *str)
{
char *start;
char *end;

start = str;
end = str;
while (*(end + 1))
end++;
while (end > start)
ft_swap(start++, end--);
return (str);
}

static int get_buffer_size(int n)
{
int size;

size = 1;
if (n == 0)
return (2);
if (n < 0)
size++;
while (n != 0)
{
n /= 10;
size++;
}
return (size);
}

char *ft_itoa(int n)
{
char *str;
int i;
int sign;

i = 0;
sign = 1;
if (n == -2147483648)
return (ft_strdup("-2147483648"));
if (n < 0)
sign = -1;
str = malloc(sizeof(char) * get_buffer_size(n));
if (!str)
return (NULL);
while (n / 10 != 0)
{
str[i++] = (sign * n) % 10 + '0';
n /= 10;
}
str[i++] = (sign * n) % 10 + '0';
if (sign == -1 && i != 0)
str[i++] = '-';
str[i] = '\0';
return (ft_strrev(str));
}
Loading

0 comments on commit 707f6f5

Please sign in to comment.