mirror of
https://github.com/LucasCodeur/alcu.git
synced 2026-04-28 17:44:34 +02:00
FEAT: works and no leaks
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -32,7 +32,7 @@ bool check_input(t_vector* lines)
|
|||||||
line = (char*)lines->pfVectorGet(lines, j);
|
line = (char*)lines->pfVectorGet(lines, j);
|
||||||
i = -1;
|
i = -1;
|
||||||
while (line[++i])
|
while (line[++i])
|
||||||
if (!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n')
|
if ((!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n') || i > 5)
|
||||||
return (false);
|
return (false);
|
||||||
if (ft_atoi(line) < 1 || ft_atoi(line) > 10000)
|
if (ft_atoi(line) < 1 || ft_atoi(line) > 10000)
|
||||||
return (false);
|
return (false);
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */
|
/* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */
|
||||||
/* Updated: 2026/03/29 14:58:09 by lud-adam ### ########.fr */
|
/* Updated: 2026/03/29 16:31:19 by lud-adam ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -6,7 +6,7 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */
|
/* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */
|
||||||
/* Updated: 2026/03/29 14:58:10 by lud-adam ### ########.fr */
|
/* Updated: 2026/03/29 16:31:17 by lud-adam ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -51,9 +51,6 @@ int main(int argc, char *argv[])
|
|||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (argc == 1)
|
|
||||||
fd = open("/dev/tty", O_RDONLY);
|
|
||||||
// // fd = get_fd(argc, argv);
|
|
||||||
lines_int = fill_array(&lines, &size);
|
lines_int = fill_array(&lines, &size);
|
||||||
if (!lines_int)
|
if (!lines_int)
|
||||||
{
|
{
|
||||||
|
|||||||
+34
-31
@@ -13,26 +13,25 @@
|
|||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int vectorResize(t_vector *v, int capacity);
|
int vector_resize(t_vector *v, int capacity);
|
||||||
int vectorPushBack(t_vector *v, void *item);
|
int vector_push_back(t_vector *v, void *item);
|
||||||
int vectorSet(t_vector *v, int index, void *item);
|
int vector_set(t_vector *v, int index, void *item);
|
||||||
void *vectorGet(t_vector *v, int index);
|
void *vector_get(t_vector *v, int index);
|
||||||
int vectorDelete(t_vector *v, int index);
|
int vector_delete(t_vector *v, int index);
|
||||||
int vectorFree(t_vector *v);
|
int vector_free(t_vector *v);
|
||||||
int vectorTotal(t_vector *v);
|
int vector_total(t_vector *v);
|
||||||
|
|
||||||
void vector_init(t_vector *v)
|
void vector_init(t_vector *v)
|
||||||
{
|
{
|
||||||
// Initialize function pointers
|
v->pfVectorTotal = vector_total;
|
||||||
v->pfVectorTotal = vectorTotal;
|
v->pfVectorResize = vector_resize;
|
||||||
v->pfVectorResize = vectorResize;
|
v->pfVectorAdd = vector_push_back;
|
||||||
v->pfVectorAdd = vectorPushBack;
|
v->pfVectorSet = vector_set;
|
||||||
v->pfVectorSet = vectorSet;
|
v->pfVectorGet = vector_get;
|
||||||
v->pfVectorGet = vectorGet;
|
v->pfVectorFree = vector_free;
|
||||||
v->pfVectorFree = vectorFree;
|
v->pfVectorDelete = vector_delete;
|
||||||
v->pfVectorDelete = vectorDelete;
|
|
||||||
// Allocate memory and check for failure
|
|
||||||
v->vector_list.capacity = VECTOR_INIT_CAPACITY;
|
v->vector_list.capacity = VECTOR_INIT_CAPACITY;
|
||||||
v->vector_list.total = 0;
|
v->vector_list.total = 0;
|
||||||
v->vector_list.items = malloc(sizeof(void *) * v->vector_list.capacity);
|
v->vector_list.items = malloc(sizeof(void *) * v->vector_list.capacity);
|
||||||
@@ -43,7 +42,7 @@ void vector_init(t_vector *v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorTotal(t_vector *v)
|
int vector_total(t_vector *v)
|
||||||
{
|
{
|
||||||
int totalCount = UNDEFINE;
|
int totalCount = UNDEFINE;
|
||||||
if(v)
|
if(v)
|
||||||
@@ -53,30 +52,34 @@ int vectorTotal(t_vector *v)
|
|||||||
return totalCount;
|
return totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorResize(t_vector *v, int capacity)
|
int vector_resize(t_vector *v, int capacity)
|
||||||
{
|
{
|
||||||
int status = UNDEFINE;
|
int status = UNDEFINE;
|
||||||
if(v)
|
if(v)
|
||||||
{
|
{
|
||||||
void **items = realloc(v->vector_list.items, sizeof(void *) * capacity);
|
void **items_copy = malloc(sizeof(void *) * capacity);
|
||||||
if (items)
|
if (!items_copy)
|
||||||
|
return (status);
|
||||||
|
ft_memcpy(items_copy, v->vector_list.items, sizeof(void *) * v->pfVectorTotal(v));
|
||||||
|
if (items_copy)
|
||||||
{
|
{
|
||||||
v->vector_list.items = items;
|
free(v->vector_list.items);
|
||||||
|
v->vector_list.items = items_copy;
|
||||||
v->vector_list.capacity = capacity;
|
v->vector_list.capacity = capacity;
|
||||||
status = SUCCESS;
|
status = SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return status;
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorPushBack(t_vector *v, void *item)
|
int vector_push_back(t_vector *v, void *item)
|
||||||
{
|
{
|
||||||
int status = UNDEFINE;
|
int status = UNDEFINE;
|
||||||
if(v)
|
if(v)
|
||||||
{
|
{
|
||||||
if (v->vector_list.capacity == v->vector_list.total)
|
if (v->vector_list.capacity == v->vector_list.total)
|
||||||
{
|
{
|
||||||
status = vectorResize(v, v->vector_list.capacity * 2);
|
status = vector_resize(v, v->vector_list.capacity * 2);
|
||||||
if(status != UNDEFINE)
|
if(status != UNDEFINE)
|
||||||
{
|
{
|
||||||
v->vector_list.items[v->vector_list.total++] = item;
|
v->vector_list.items[v->vector_list.total++] = item;
|
||||||
@@ -91,7 +94,7 @@ int vectorPushBack(t_vector *v, void *item)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorSet(t_vector *v, int index, void *item)
|
int vector_set(t_vector *v, int index, void *item)
|
||||||
{
|
{
|
||||||
int status = UNDEFINE;
|
int status = UNDEFINE;
|
||||||
if(v)
|
if(v)
|
||||||
@@ -105,7 +108,7 @@ int vectorSet(t_vector *v, int index, void *item)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vectorGet(t_vector *v, int index)
|
void *vector_get(t_vector *v, int index)
|
||||||
{
|
{
|
||||||
void *readData = NULL;
|
void *readData = NULL;
|
||||||
if(v)
|
if(v)
|
||||||
@@ -118,7 +121,7 @@ void *vectorGet(t_vector *v, int index)
|
|||||||
return readData;
|
return readData;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorDelete(t_vector *v, int index)
|
int vector_delete(t_vector *v, int index)
|
||||||
{
|
{
|
||||||
int status = UNDEFINE;
|
int status = UNDEFINE;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -135,17 +138,17 @@ int vectorDelete(t_vector *v, int index)
|
|||||||
v->vector_list.total--;
|
v->vector_list.total--;
|
||||||
if ((v->vector_list.total > 0) && ((v->vector_list.total) == (v->vector_list.capacity / 4)))
|
if ((v->vector_list.total > 0) && ((v->vector_list.total) == (v->vector_list.capacity / 4)))
|
||||||
{
|
{
|
||||||
vectorResize(v, v->vector_list.capacity / 2);
|
vector_resize(v, v->vector_list.capacity / 2);
|
||||||
}
|
}
|
||||||
status = SUCCESS;
|
status = SUCCESS;
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorFree(t_vector *v)
|
int vector_free(t_vector *v)
|
||||||
{
|
{
|
||||||
int status = UNDEFINE;
|
int status = UNDEFINE;
|
||||||
int total = v->pfVectorTotal(v);
|
int total = v->pfVectorTotal(v);
|
||||||
if(v)
|
if(v)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < total; i++)
|
for (int i = 0; i < total; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user