'
This commit is contained in:
parent
e106a4ca66
commit
1fe9f668b6
13 changed files with 368 additions and 333 deletions
|
|
@ -1,3 +1,26 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla
|
||||||
|
DBG_CFLAGS = -fsanitize=address -g
|
||||||
|
|
||||||
|
SRC_DIR = src
|
||||||
|
LIB_SRCS = lines/lines.c hash_maps/hash_maps.c lists/lists.c
|
||||||
|
MAIN_SRCS = main.c minimake.c
|
||||||
|
|
||||||
|
# SRCS = $(patsubst %,$(SRC_DIR)/%, $(MAIN_SRCS))
|
||||||
|
SRCS = $(MAIN_SRCS:%=$(SRC_DIR)/%) $(LIB_SRCS:%=$(SRC_DIR)/%)
|
||||||
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
TARGET= minimake
|
||||||
|
# DBG_TARGET = minimake-dbg
|
||||||
|
|
||||||
|
$(TARGET): $(OBJS)
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||||
|
@echo $(OBJS)
|
||||||
|
|
||||||
|
debug: CFLAGS += $(DBG_CFLAGS)
|
||||||
|
debug: $(OBJS)
|
||||||
|
$(CC) -o $(TARGET) $^ $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(TARGET)
|
||||||
|
$(RM) $(OBJS)
|
||||||
|
|
|
||||||
BIN
minimake/minimake
Executable file
BIN
minimake/minimake
Executable file
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
||||||
#include "hash_map.h"
|
#include "hash_maps.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
@ -1,101 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "list.h"
|
|
||||||
|
|
||||||
struct list *list_insert(struct list *list, void *value, size_t index)
|
|
||||||
{
|
|
||||||
if (list == NULL || index == 0)
|
|
||||||
{
|
|
||||||
struct list *new_elt = malloc(sizeof(struct list));
|
|
||||||
new_elt->data = value;
|
|
||||||
new_elt->next = list;
|
|
||||||
return new_elt;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *elt = list;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < index - 1; i++)
|
|
||||||
{
|
|
||||||
if (elt->next == NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *new_elt = malloc(sizeof(struct list));
|
|
||||||
new_elt->data = value;
|
|
||||||
new_elt->next = elt->next;
|
|
||||||
elt->next = new_elt;
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *list_remove(struct list *list, size_t index)
|
|
||||||
{
|
|
||||||
struct list *elt = list;
|
|
||||||
struct list *prev_elt;
|
|
||||||
|
|
||||||
if (index == 0)
|
|
||||||
{
|
|
||||||
struct list *res = elt->next;
|
|
||||||
free(elt);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < index; i++)
|
|
||||||
{
|
|
||||||
if (elt == NULL)
|
|
||||||
{
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
prev_elt = elt;
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
if (elt == NULL)
|
|
||||||
{
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
prev_elt->next = elt->next;
|
|
||||||
free(elt);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
int list_find(struct list *list, void *value)
|
|
||||||
{
|
|
||||||
if (list == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int res = 0;
|
|
||||||
while (list->data != value)
|
|
||||||
{
|
|
||||||
list = list->next;
|
|
||||||
res++;
|
|
||||||
if (list == NULL)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *list_concat(struct list *list, struct list *list2)
|
|
||||||
{
|
|
||||||
if (list == NULL)
|
|
||||||
{
|
|
||||||
return list2;
|
|
||||||
}
|
|
||||||
struct list *elt = list;
|
|
||||||
while (elt->next != NULL)
|
|
||||||
{
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
elt->next = list2;
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "list.h"
|
|
||||||
|
|
||||||
struct list *list_prepend(struct list *list, void *value)
|
|
||||||
{
|
|
||||||
struct list *new_elt = malloc(sizeof(struct list));
|
|
||||||
if (new_elt == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
new_elt->next = list;
|
|
||||||
new_elt->data = value;
|
|
||||||
|
|
||||||
return new_elt;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t list_length(struct list *list)
|
|
||||||
{
|
|
||||||
size_t len = 0;
|
|
||||||
while (list != NULL)
|
|
||||||
{
|
|
||||||
len++;
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// void list_print(struct list *list)
|
|
||||||
// {
|
|
||||||
// if (list == NULL)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// while (list != NULL)
|
|
||||||
// {
|
|
||||||
// if (list->next != NULL)
|
|
||||||
// {
|
|
||||||
// printf("%p ", list->data);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// printf("%p\n", list->data);
|
|
||||||
// }
|
|
||||||
// list = list->next;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
void list_destroy(struct list *list)
|
|
||||||
{
|
|
||||||
struct list *elt = list;
|
|
||||||
struct list *next_elt;
|
|
||||||
while (elt != NULL)
|
|
||||||
{
|
|
||||||
next_elt = elt->next;
|
|
||||||
free(elt);
|
|
||||||
elt = next_elt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *list_append(struct list *list, void *value)
|
|
||||||
{
|
|
||||||
if (list == NULL)
|
|
||||||
{
|
|
||||||
struct list *new_elt = malloc(sizeof(struct list));
|
|
||||||
new_elt->data = value;
|
|
||||||
new_elt->next = NULL;
|
|
||||||
return new_elt;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *elt = list;
|
|
||||||
|
|
||||||
while (elt->next != NULL)
|
|
||||||
{
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct list *new_elt = malloc(sizeof(struct list));
|
|
||||||
new_elt->data = value;
|
|
||||||
new_elt->next = NULL;
|
|
||||||
elt->next = new_elt;
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
@ -1,138 +0,0 @@
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "list.h"
|
|
||||||
|
|
||||||
void swap_next(struct list *elt)
|
|
||||||
{
|
|
||||||
void *c = elt->next->data;
|
|
||||||
elt->next->data = elt->data;
|
|
||||||
elt->data = c;
|
|
||||||
}
|
|
||||||
struct list *list_sort(struct list *list)
|
|
||||||
{
|
|
||||||
// Bubble sort go !
|
|
||||||
if (list == NULL)
|
|
||||||
{
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
struct list *elt = list;
|
|
||||||
int len = 0;
|
|
||||||
while (elt->next != NULL)
|
|
||||||
{
|
|
||||||
if (elt->data > elt->next->data)
|
|
||||||
{
|
|
||||||
swap_next(elt);
|
|
||||||
}
|
|
||||||
elt = elt->next;
|
|
||||||
len++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 1; i < len; i++)
|
|
||||||
{
|
|
||||||
elt = list;
|
|
||||||
while (elt->next != NULL)
|
|
||||||
{
|
|
||||||
if (elt->data > elt->next->data)
|
|
||||||
{
|
|
||||||
swap_next(elt);
|
|
||||||
}
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Old proto
|
|
||||||
// WARNING no malloc/free allowed (moulinette issue)
|
|
||||||
struct list *list_reverse(struct list *list)
|
|
||||||
{
|
|
||||||
if (list == NULL)
|
|
||||||
{
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get len
|
|
||||||
struct list *elt = list;
|
|
||||||
int len = 0;
|
|
||||||
while (elt->next != NULL)
|
|
||||||
{
|
|
||||||
len++;
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
elt = list;
|
|
||||||
|
|
||||||
// Bring each elt to end
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
{
|
|
||||||
elt = list;
|
|
||||||
for (int j = 0; j < len - i; j++)
|
|
||||||
{
|
|
||||||
swap_next(elt);
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Doesn't work neither
|
|
||||||
// struct list *list_reverse(struct list *list)
|
|
||||||
// {
|
|
||||||
// struct list *new_list = NULL;
|
|
||||||
// struct list *elt = list;
|
|
||||||
// while (elt != NULL)
|
|
||||||
// {
|
|
||||||
// struct list *new_elt = malloc(sizeof(struct list));
|
|
||||||
// if (new_elt == NULL)
|
|
||||||
// {
|
|
||||||
// return NULL;
|
|
||||||
// }
|
|
||||||
// new_elt->data = elt->data;
|
|
||||||
// new_elt->next = new_list;
|
|
||||||
|
|
||||||
// struct list *next_elt = elt->next;
|
|
||||||
// free(elt);
|
|
||||||
// elt = next_elt;
|
|
||||||
// }
|
|
||||||
// return new_list;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Moulinette issue
|
|
||||||
// struct list *list_reverse(struct list *list)
|
|
||||||
// {
|
|
||||||
// if (list == NULL)
|
|
||||||
// {
|
|
||||||
// return list;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// struct list *new_list = NULL;
|
|
||||||
// while (list != NULL)
|
|
||||||
// {
|
|
||||||
// new_list = list_prepend(new_list, list->data);
|
|
||||||
// list = list_remove(list, 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return new_list;
|
|
||||||
// }
|
|
||||||
|
|
||||||
struct list *list_split(struct list *list, size_t index)
|
|
||||||
{
|
|
||||||
struct list *elt = list;
|
|
||||||
for (size_t i = 0; i < index; i++)
|
|
||||||
{
|
|
||||||
if (elt == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
elt = elt->next;
|
|
||||||
}
|
|
||||||
if (elt == NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
struct list *res = elt->next;
|
|
||||||
elt->next = NULL;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
333
minimake/src/lists/lists.c
Normal file
333
minimake/src/lists/lists.c
Normal file
|
|
@ -0,0 +1,333 @@
|
||||||
|
#include "lists.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct list *list_prepend(struct list *list, void *value)
|
||||||
|
{
|
||||||
|
struct list *new_elt = malloc(sizeof(struct list));
|
||||||
|
if (new_elt == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
new_elt->next = list;
|
||||||
|
new_elt->data = value;
|
||||||
|
|
||||||
|
return new_elt;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t list_length(struct list *list)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
while (list != NULL)
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
// void list_print(struct list *list)
|
||||||
|
// {
|
||||||
|
// if (list == NULL)
|
||||||
|
// {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// while (list != NULL)
|
||||||
|
// {
|
||||||
|
// if (list->next != NULL)
|
||||||
|
// {
|
||||||
|
// printf("%p ", list->data);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// printf("%p\n", list->data);
|
||||||
|
// }
|
||||||
|
// list = list->next;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
void list_destroy(struct list *list)
|
||||||
|
{
|
||||||
|
struct list *elt = list;
|
||||||
|
struct list *next_elt;
|
||||||
|
while (elt != NULL)
|
||||||
|
{
|
||||||
|
next_elt = elt->next;
|
||||||
|
free(elt);
|
||||||
|
elt = next_elt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *list_append(struct list *list, void *value)
|
||||||
|
{
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
struct list *new_elt = malloc(sizeof(struct list));
|
||||||
|
new_elt->data = value;
|
||||||
|
new_elt->next = NULL;
|
||||||
|
return new_elt;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *elt = list;
|
||||||
|
|
||||||
|
while (elt->next != NULL)
|
||||||
|
{
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *new_elt = malloc(sizeof(struct list));
|
||||||
|
new_elt->data = value;
|
||||||
|
new_elt->next = NULL;
|
||||||
|
elt->next = new_elt;
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*******************
|
||||||
|
* Advanced *
|
||||||
|
*******************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct list *list_insert(struct list *list, void *value, size_t index)
|
||||||
|
{
|
||||||
|
if (list == NULL || index == 0)
|
||||||
|
{
|
||||||
|
struct list *new_elt = malloc(sizeof(struct list));
|
||||||
|
new_elt->data = value;
|
||||||
|
new_elt->next = list;
|
||||||
|
return new_elt;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *elt = list;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < index - 1; i++)
|
||||||
|
{
|
||||||
|
if (elt->next == NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *new_elt = malloc(sizeof(struct list));
|
||||||
|
new_elt->data = value;
|
||||||
|
new_elt->next = elt->next;
|
||||||
|
elt->next = new_elt;
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *list_remove(struct list *list, size_t index)
|
||||||
|
{
|
||||||
|
struct list *elt = list;
|
||||||
|
struct list *prev_elt;
|
||||||
|
|
||||||
|
if (index == 0)
|
||||||
|
{
|
||||||
|
struct list *res = elt->next;
|
||||||
|
free(elt);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < index; i++)
|
||||||
|
{
|
||||||
|
if (elt == NULL)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
prev_elt = elt;
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
if (elt == NULL)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_elt->next = elt->next;
|
||||||
|
free(elt);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
int list_find(struct list *list, void *value)
|
||||||
|
{
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
while (list->data != value)
|
||||||
|
{
|
||||||
|
list = list->next;
|
||||||
|
res++;
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct list *list_concat(struct list *list, struct list *list2)
|
||||||
|
{
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
return list2;
|
||||||
|
}
|
||||||
|
struct list *elt = list;
|
||||||
|
while (elt->next != NULL)
|
||||||
|
{
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
elt->next = list2;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
******************
|
||||||
|
* Ultimate *
|
||||||
|
******************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void swap_next(struct list *elt)
|
||||||
|
{
|
||||||
|
void *c = elt->next->data;
|
||||||
|
elt->next->data = elt->data;
|
||||||
|
elt->data = c;
|
||||||
|
}
|
||||||
|
struct list *list_sort(struct list *list)
|
||||||
|
{
|
||||||
|
// Bubble sort go !
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
struct list *elt = list;
|
||||||
|
int len = 0;
|
||||||
|
while (elt->next != NULL)
|
||||||
|
{
|
||||||
|
if (elt->data > elt->next->data)
|
||||||
|
{
|
||||||
|
swap_next(elt);
|
||||||
|
}
|
||||||
|
elt = elt->next;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < len; i++)
|
||||||
|
{
|
||||||
|
elt = list;
|
||||||
|
while (elt->next != NULL)
|
||||||
|
{
|
||||||
|
if (elt->data > elt->next->data)
|
||||||
|
{
|
||||||
|
swap_next(elt);
|
||||||
|
}
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Old proto
|
||||||
|
// WARNING no malloc/free allowed (moulinette issue)
|
||||||
|
struct list *list_reverse(struct list *list)
|
||||||
|
{
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get len
|
||||||
|
struct list *elt = list;
|
||||||
|
int len = 0;
|
||||||
|
while (elt->next != NULL)
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
elt = list;
|
||||||
|
|
||||||
|
// Bring each elt to end
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
elt = list;
|
||||||
|
for (int j = 0; j < len - i; j++)
|
||||||
|
{
|
||||||
|
swap_next(elt);
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Doesn't work neither
|
||||||
|
// struct list *list_reverse(struct list *list)
|
||||||
|
// {
|
||||||
|
// struct list *new_list = NULL;
|
||||||
|
// struct list *elt = list;
|
||||||
|
// while (elt != NULL)
|
||||||
|
// {
|
||||||
|
// struct list *new_elt = malloc(sizeof(struct list));
|
||||||
|
// if (new_elt == NULL)
|
||||||
|
// {
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
|
// new_elt->data = elt->data;
|
||||||
|
// new_elt->next = new_list;
|
||||||
|
|
||||||
|
// struct list *next_elt = elt->next;
|
||||||
|
// free(elt);
|
||||||
|
// elt = next_elt;
|
||||||
|
// }
|
||||||
|
// return new_list;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Moulinette issue
|
||||||
|
// struct list *list_reverse(struct list *list)
|
||||||
|
// {
|
||||||
|
// if (list == NULL)
|
||||||
|
// {
|
||||||
|
// return list;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// struct list *new_list = NULL;
|
||||||
|
// while (list != NULL)
|
||||||
|
// {
|
||||||
|
// new_list = list_prepend(new_list, list->data);
|
||||||
|
// list = list_remove(list, 0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return new_list;
|
||||||
|
// }
|
||||||
|
|
||||||
|
struct list *list_split(struct list *list, size_t index)
|
||||||
|
{
|
||||||
|
struct list *elt = list;
|
||||||
|
for (size_t i = 0; i < index; i++)
|
||||||
|
{
|
||||||
|
if (elt == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
elt = elt->next;
|
||||||
|
}
|
||||||
|
if (elt == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
struct list *res = elt->next;
|
||||||
|
elt->next = NULL;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
// Look at perror for stdlib functions
|
// Look at perror for stdlib functions
|
||||||
// Create an enum for error handling
|
// Create an enum for error handling
|
||||||
|
|
||||||
int handle_args(int argc, char **argv)
|
static int handle_args(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
|
|
@ -25,7 +25,11 @@ int handle_args(int argc, char **argv)
|
||||||
else
|
else
|
||||||
errx(INVALID_ARG, ": Pleaase give an argument");
|
errx(INVALID_ARG, ": Pleaase give an argument");
|
||||||
}
|
}
|
||||||
|
printf("%s: done", argv[0]);
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{}
|
{
|
||||||
|
return handle_args(argc, argv);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "hash_map/hash_map.h"
|
#include "hash_maps/hash_maps.h"
|
||||||
#include "lines/lines.h"
|
#include "lines/lines.h"
|
||||||
#include "list/list.h"
|
#include "lists/lists.h"
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
struct hash_map *variables = NULL;
|
struct hash_map *variables = NULL;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "list/list.h"
|
#include "lists/lists.h"
|
||||||
|
|
||||||
// Holds variable information
|
// Holds variable information
|
||||||
// WARNING its values must be freed after use
|
// WARNING its values must be freed after use
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue