Skip to content

Commit 90a2be3

Browse files
author
Jeremy CAROL
committed
added some functions / some updates
1 parent 7a3eb91 commit 90a2be3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+181
-66
lines changed

Makefile

+21-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
# By: jecarol <[email protected]> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2016/12/07 12:20:17 by jecarol #+# #+# #
9-
# Updated: 2016/12/14 15:48:28 by jecarol ### ########.fr #
9+
# Updated: 2017/04/11 20:24:17 by jecarol ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

1313
NAME = libft.a
1414

15-
CFLAGS += -Wall -Wextra -Werror
15+
CFLAGS += -Wall -Wextra -Werror -g
1616

1717
SRC = ft_atoi.c \
1818
ft_putchar.c \
@@ -51,6 +51,7 @@ SRC = ft_atoi.c \
5151
ft_memcpy.c \
5252
ft_memccpy.c \
5353
ft_memmove.c \
54+
ft_freejoin.c \
5455
ft_memchr.c \
5556
ft_memcmp.c \
5657
ft_memalloc.c \
@@ -73,18 +74,32 @@ SRC = ft_atoi.c \
7374
ft_lstiter.c \
7475
ft_lstmap.c \
7576
ft_printstrs.c \
77+
ft_lstaddend.c \
78+
ft_lstforeach.c \
79+
80+
CC = @cc
7681

7782
OBJ = $(SRC:.c=.o)
7883

84+
# COLOR
85+
C_GOOD = "\033[32m"
86+
C_DURING = "\033[36m"
87+
88+
# MESSAGE
89+
SUCCESS = $(C_GOOD)COMPILATION SUCCEEDED
90+
7991
all: $(NAME)
8092

8193
$(NAME): $(OBJ)
82-
ar rc $(NAME) $(OBJ)
83-
ranlib $(NAME)
94+
@echo $(C_DURING)"Compiling" [ $(NAME) . . . ]
95+
@ar rc $(NAME) $(OBJ)
96+
@ranlib $(NAME)
97+
@echo $(SUCCESS)
98+
8499
clean:
85-
/bin/rm -f $(OBJ)
100+
@/bin/rm -f $(OBJ)
86101

87102
fclean: clean
88-
/bin/rm -f $(NAME)
103+
@/bin/rm -f $(NAME)
89104

90105
re: fclean all

README.md

-2
This file was deleted.

ft_atoi.o

2.02 KB
Binary file not shown.

ft_bzero.o

1.91 KB
Binary file not shown.

ft_freejoin.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_freejoin.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2016/12/02 14:21:04 by jecarol #+# #+# */
9+
/* Updated: 2017/04/22 03:51:25 by rlkcmptr ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
char *ft_freejoin(char *dst, char *src)
16+
{
17+
char *tmp;
18+
19+
tmp = malloc(sizeof(char) * (ft_strlen(dst) + 1));
20+
tmp[0] = '\0';
21+
ft_strcpy(tmp, dst);
22+
ft_strdel(&dst);
23+
if ((dst = ft_strjoin(tmp, src)) == NULL)
24+
return (NULL);
25+
ft_strdel(&tmp);
26+
return (dst);
27+
}

ft_freejoin.o

2.61 KB
Binary file not shown.

ft_isalnum.o

1.58 KB
Binary file not shown.

ft_isalpha.o

1.59 KB
Binary file not shown.

ft_isascii.o

1.57 KB
Binary file not shown.

ft_isdigit.o

1.57 KB
Binary file not shown.

ft_isprint.o

1.57 KB
Binary file not shown.

ft_itoa.o

2 KB
Binary file not shown.

ft_lstadd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/12/08 19:17:35 by jecarol #+# #+# */
9-
/* Updated: 2016/12/08 19:17:38 by jecarol ### ########.fr */
9+
/* Updated: 2017/02/11 17:21:45 by jecarol ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

ft_lstadd.o

2.02 KB
Binary file not shown.

ft_lstaddend.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_lstaddend.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/03/08 19:55:44 by jecarol #+# #+# */
9+
/* Updated: 2017/04/11 19:11:12 by jecarol ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_lstaddend(t_list **alst, t_list *new)
16+
{
17+
t_list *tmp;
18+
19+
if (*alst)
20+
{
21+
tmp = *alst;
22+
while (tmp->next)
23+
tmp = tmp->next;
24+
tmp->next = new;
25+
}
26+
else
27+
*alst = new;
28+
}

ft_lstaddend.o

2.79 KB
Binary file not shown.

ft_lstdel.o

2.14 KB
Binary file not shown.

ft_lstdelone.o

2.07 KB
Binary file not shown.

ft_lstforeach.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_lstforeach.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2017/03/10 11:59:09 by jecarol #+# #+# */
9+
/* Updated: 2017/03/10 11:59:22 by jecarol ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
void ft_lstforeach(t_list *lst, void (*f)())
16+
{
17+
while (lst)
18+
{
19+
f(lst->content);
20+
lst = lst->next;
21+
}
22+
}

ft_lstforeach.o

2.7 KB
Binary file not shown.

ft_lstiter.o

2.04 KB
Binary file not shown.

ft_lstmap.o

2.13 KB
Binary file not shown.

ft_lstnew.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/12/07 17:57:52 by jecarol #+# #+# */
9-
/* Updated: 2016/12/08 19:19:36 by jecarol ### ########.fr */
9+
/* Updated: 2017/03/23 14:45:07 by jecarol ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -25,10 +25,10 @@ t_list *ft_lstnew(void const *content, size_t content_size)
2525
}
2626
else
2727
{
28-
new->content = malloc(content_size);
28+
new->content = malloc(content_size + 1);
2929
if (!new->content)
3030
return (NULL);
31-
ft_memcpy((new->content), content, content_size);
31+
ft_memcpy((new->content), content, content_size + 1);
3232
new->content_size = content_size;
3333
}
3434
new->next = NULL;

ft_lstnew.o

2.16 KB
Binary file not shown.

ft_memalloc.o

1.84 KB
Binary file not shown.

ft_memccpy.o

2.13 KB
Binary file not shown.

ft_memchr.o

2 KB
Binary file not shown.

ft_memcmp.o

2.09 KB
Binary file not shown.

ft_memcpy.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/11/22 19:57:55 by jecarol #+# #+# */
9-
/* Updated: 2016/12/13 14:09:13 by jecarol ### ########.fr */
9+
/* Updated: 2017/03/23 14:47:25 by jecarol ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -27,5 +27,6 @@ void *ft_memcpy(void *dst, const void *src, size_t n)
2727
dest[i] = source[i];
2828
i++;
2929
}
30+
dest[i] = '\0';
3031
return (dst);
3132
}

ft_memcpy.o

2 KB
Binary file not shown.

ft_memdel.o

1.54 KB
Binary file not shown.

ft_memmove.o

2.08 KB
Binary file not shown.

ft_memset.o

2.03 KB
Binary file not shown.

ft_printstrs.o

1.67 KB
Binary file not shown.

ft_putchar.o

1.55 KB
Binary file not shown.

ft_putchar_fd.o

1.63 KB
Binary file not shown.

ft_putendl.o

1.59 KB
Binary file not shown.

ft_putendl_fd.o

1.66 KB
Binary file not shown.

ft_putnbr.o

1.64 KB
Binary file not shown.

ft_putnbr_fd.o

1.68 KB
Binary file not shown.

ft_putstr.o

1.67 KB
Binary file not shown.

ft_putstr_fd.o

1.7 KB
Binary file not shown.

ft_strcat.o

1.74 KB
Binary file not shown.

ft_strchr.o

1.74 KB
Binary file not shown.

ft_strclr.o

1.67 KB
Binary file not shown.

ft_strcmp.o

1.81 KB
Binary file not shown.

ft_strcpy.o

1.71 KB
Binary file not shown.

ft_strdel.o

1.61 KB
Binary file not shown.

ft_strdup.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
/* +:+ +:+ +:+ */
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
8-
/* Created: 2016/11/22 19:46:50 by jecarol #+# #+# */
9-
/* Updated: 2016/11/25 13:03:15 by jecarol ### ########.fr */
8+
/* Created: 2017/02/11 17:36:32 by jecarol #+# #+# */
9+
/* Updated: 2017/02/11 17:36:33 by jecarol ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "libft.h"
1414

15-
char *ft_strdup(const char *s1)
15+
char *ft_strdup(const char *s1)
1616
{
17+
char *result;
1718
int i;
18-
char *s2;
19+
int j;
1920

2021
i = 0;
21-
s2 = (char*)malloc(sizeof(*s2) * (ft_strlen(s1) + 1));
22-
if (s2 == NULL)
22+
if (!(result = (char*)malloc(sizeof(char) * (ft_strlen(s1) + 1))))
2323
return (NULL);
24-
while (s1[i])
24+
j = (ft_strlen(s1));
25+
while (j >= 0)
2526
{
26-
s2[i] = s1[i];
27+
result[i] = s1[i];
2728
i++;
29+
j--;
2830
}
29-
s2[i] = '\0';
30-
return (s2);
31+
return (result);
3132
}

ft_strdup.o

1.77 KB
Binary file not shown.

ft_strequ.o

1.68 KB
Binary file not shown.

ft_striter.o

1.65 KB
Binary file not shown.

ft_striteri.o

1.74 KB
Binary file not shown.

ft_strjoin.o

1.72 KB
Binary file not shown.

ft_strlcat.o

2.09 KB
Binary file not shown.

ft_strlen.o

1.87 KB
Binary file not shown.

ft_strmap.o

1.8 KB
Binary file not shown.

ft_strmapi.o

1.84 KB
Binary file not shown.

ft_strncat.o

1.98 KB
Binary file not shown.

ft_strncmp.o

2.11 KB
Binary file not shown.

ft_strncpy.o

1.97 KB
Binary file not shown.

ft_strnequ.o

1.96 KB
Binary file not shown.

ft_strnew.o

1.82 KB
Binary file not shown.

ft_strnstr.o

2.05 KB
Binary file not shown.

ft_strrchr.o

1.75 KB
Binary file not shown.

ft_strsplit.c

+43-41
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,69 @@
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/12/02 19:17:52 by jecarol #+# #+# */
9-
/* Updated: 2016/12/07 16:33:25 by jecarol ### ########.fr */
9+
/* Updated: 2017/04/22 03:52:59 by rlkcmptr ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "libft.h"
1414

15-
static int ft_words(const char *s, char c)
15+
static int ft_cnt_parts(const char *s, char c)
1616
{
17-
unsigned int i;
18-
int compteur;
17+
int cnt;
18+
int in_substring;
1919

20-
i = 0;
21-
compteur = 0;
22-
while (s[i])
20+
in_substring = 0;
21+
cnt = 0;
22+
while (*s != '\0')
2323
{
24-
while (s[i] == c)
25-
i++;
26-
if (s[i] != '\0')
27-
compteur++;
28-
while (s[i] && (s[i] != c))
29-
i++;
24+
if (in_substring == 1 && *s == c)
25+
in_substring = 0;
26+
if (in_substring == 0 && *s != c)
27+
{
28+
in_substring = 1;
29+
cnt++;
30+
}
31+
s++;
3032
}
31-
return (compteur);
33+
return (cnt);
3234
}
3335

34-
char **ft_split1(char const *s, char c, char **str)
36+
static int ft_wlen(const char *s, char c)
3537
{
36-
int i;
37-
int j;
38-
int k;
39-
int l;
38+
int len;
4039

41-
i = 0;
42-
k = 0;
43-
while (s[i])
40+
len = 0;
41+
while (*s != c && *s != '\0')
4442
{
45-
l = 0;
46-
while (s[i] == c)
47-
i++;
48-
j = i;
49-
while (s[i] && s[i] != c)
50-
i++;
51-
if (i > j)
52-
{
53-
str[k] = (char *)malloc(sizeof(char) * (i - j + 1));
54-
while (j < i)
55-
str[k][l++] = s[j++];
56-
str[k++][l] = '\0';
57-
}
43+
len++;
44+
s++;
5845
}
59-
str[k] = NULL;
60-
return (str);
46+
return (len);
6147
}
6248

6349
char **ft_strsplit(char const *s, char c)
6450
{
65-
char **str;
51+
char **t;
52+
int nb_word;
53+
int index;
6654

67-
if (!s)
55+
if (s == NULL)
6856
return (NULL);
69-
if ((str = (char **)malloc(sizeof(char*) * ft_words(s, c) + 1)) == NULL)
57+
index = 0;
58+
nb_word = ft_cnt_parts((const char *)s, c);
59+
t = (char **)malloc(sizeof(*t) * (ft_cnt_parts((const char *)s, c) + 1));
60+
if (t == NULL)
7061
return (NULL);
71-
return (ft_split1(s, c, str));
62+
while (nb_word--)
63+
{
64+
while (*s == c && *s != '\0')
65+
s++;
66+
t[index] = ft_strsub((const char *)s, 0, ft_wlen((const char *)s, c));
67+
if (t[index] == NULL)
68+
return (NULL);
69+
s = s + ft_wlen(s, c);
70+
index++;
71+
}
72+
t[index] = NULL;
73+
return (t);
7274
}

ft_strsplit.o

2.34 KB
Binary file not shown.

ft_strstr.o

1.8 KB
Binary file not shown.

ft_strsub.o

2.06 KB
Binary file not shown.

ft_strtrim.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/12/02 15:38:48 by jecarol #+# #+# */
9-
/* Updated: 2016/12/02 18:37:12 by jecarol ### ########.fr */
9+
/* Updated: 2017/04/24 18:24:06 by jecarol ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

ft_strtrim.o

1.92 KB
Binary file not shown.

ft_tolower.o

1.58 KB
Binary file not shown.

ft_toupper.o

1.58 KB
Binary file not shown.

libft.a

117 KB
Binary file not shown.

libft.h

+22-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jecarol <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2016/11/22 18:48:21 by jecarol #+# #+# */
9-
/* Updated: 2016/12/14 15:49:07 by jecarol ### ########.fr */
9+
/* Updated: 2017/04/19 17:10:37 by jecarol ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,6 +15,24 @@
1515
# include <unistd.h>
1616
# include <string.h>
1717
# include <stdlib.h>
18+
# include <stdarg.h>
19+
20+
# define DEFAULT "\033[0m"
21+
# define BLACK "\033[30m"
22+
# define RED "\033[31m"
23+
# define GREEN "\033[32m"
24+
# define YELLOW "\033[33m"
25+
# define BLUE "\033[34m"
26+
# define PURPLE "\033[35m"
27+
# define TURQUOISE "\033[36m"
28+
# define REDCOVER "\033[41m"
29+
# define GREENCOVER "\033[42m"
30+
# define YELLOWCOVER "\033[43m"
31+
# define BLUECOVER "\033[44m"
32+
# define PURPLECOVER "\033[45m"
33+
# define UGLYBLUECOVER "\033[46m"
34+
# define GREYCOVER "\033[47m"
35+
# define TEST "\033[51m"
1836

1937
typedef struct s_list
2038
{
@@ -23,6 +41,8 @@ typedef struct s_list
2341
struct s_list *next;
2442
} t_list;
2543

44+
void ft_lstaddend(t_list **alst, t_list *new);
45+
char *ft_freejoin(char *s1, char *s2);
2646
size_t ft_strlen(const char *str);
2747
char *ft_strdup(const char *s1);
2848
int ft_atoi(const char *str);
@@ -83,5 +103,6 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
83103
void ft_lstiter(t_list *lst, void(*f)(t_list *elem));
84104
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
85105
void ft_printstrs(char **str);
106+
void ft_lstforeach(t_list *lst, void(*f)());
86107

87108
#endif

0 commit comments

Comments
 (0)