implemented llists in memory-identifiers && memory fix
lol haven't done anything in a while lmao
This commit is contained in:
parent
92e6632fbc
commit
58ed9ed8d5
@ -18,8 +18,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <why2/flags.h>
|
#include <why2/flags.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <why2/llist.h>
|
||||||
#include <why2/memory.h>
|
#include <why2/memory.h>
|
||||||
|
|
||||||
//CONSTS (this is just local)
|
//CONSTS (this is just local)
|
||||||
@ -36,66 +39,16 @@ why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation;
|
|||||||
why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
|
why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
|
||||||
char *memory_identifier = DEFAULT_MEMORY_IDENTIFIER;
|
char *memory_identifier = DEFAULT_MEMORY_IDENTIFIER;
|
||||||
|
|
||||||
//LINKED LIST SHIT
|
why2_list_t identifier_list = WHY2_LIST_EMPTY;
|
||||||
typedef struct node
|
|
||||||
{
|
|
||||||
char *identifier;
|
|
||||||
struct node *next;
|
|
||||||
} node_t;
|
|
||||||
|
|
||||||
node_t *list_head = NULL;
|
|
||||||
|
|
||||||
void push_to_list_end(char *identifier)
|
|
||||||
{
|
|
||||||
node_t *new_node = malloc(sizeof(node_t));
|
|
||||||
node_t *buffer = list_head;
|
|
||||||
|
|
||||||
new_node -> identifier = identifier;
|
|
||||||
new_node -> next = NULL;
|
|
||||||
|
|
||||||
if (list_head == NULL) //LIST IS EMTPY
|
|
||||||
{
|
|
||||||
list_head = new_node;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
while (buffer -> next != NULL) buffer = buffer -> next; //GO TO THE END OF LIST
|
|
||||||
|
|
||||||
buffer -> next = new_node; //LINK
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove_node_from_end(void)
|
|
||||||
{
|
|
||||||
if (list_head == NULL) return; //EMPTY LIST
|
|
||||||
|
|
||||||
node_t *buffer = list_head;
|
|
||||||
node_t *deallocating_node;
|
|
||||||
|
|
||||||
if (buffer -> next == NULL) //ONLY ONE NODE
|
|
||||||
{
|
|
||||||
deallocating_node = buffer;
|
|
||||||
|
|
||||||
list_head = NULL;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
|
|
||||||
|
|
||||||
deallocating_node = buffer -> next;
|
|
||||||
|
|
||||||
buffer -> next = NULL; //UNLINK
|
|
||||||
}
|
|
||||||
|
|
||||||
free(deallocating_node);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_last_node_identifier(void)
|
char *get_last_node_identifier(void)
|
||||||
{
|
{
|
||||||
if (list_head == NULL) return DEFAULT_MEMORY_IDENTIFIER;
|
if (identifier_list.head == NULL) return DEFAULT_MEMORY_IDENTIFIER;
|
||||||
|
|
||||||
node_t *buffer = list_head;
|
why2_node_t *buffer = identifier_list.head;
|
||||||
while (buffer -> next != NULL) buffer = buffer -> next;
|
while (buffer -> next != NULL) buffer = buffer -> next;
|
||||||
|
|
||||||
return buffer -> identifier;
|
return buffer -> value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GETTERS
|
//GETTERS
|
||||||
@ -188,14 +141,14 @@ void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOpe
|
|||||||
|
|
||||||
void why2_set_memory_identifier(char *new_memory_identifier)
|
void why2_set_memory_identifier(char *new_memory_identifier)
|
||||||
{
|
{
|
||||||
push_to_list_end(new_memory_identifier);
|
why2_list_push(&identifier_list, new_memory_identifier, strlen(new_memory_identifier) + 1); //TODO: Check memory problems
|
||||||
|
|
||||||
memory_identifier = new_memory_identifier;
|
memory_identifier = new_memory_identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void why2_reset_memory_identifier(void)
|
void why2_reset_memory_identifier(void)
|
||||||
{
|
{
|
||||||
remove_node_from_end();
|
why2_list_remove_back(&identifier_list);
|
||||||
|
|
||||||
memory_identifier = get_last_node_identifier();
|
memory_identifier = get_last_node_identifier();
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ void why2_list_remove_back(why2_list_t *list)
|
|||||||
{
|
{
|
||||||
deallocating_node = buffer;
|
deallocating_node = buffer;
|
||||||
|
|
||||||
head = NULL;
|
list -> head = NULL;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
|
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
|
||||||
@ -108,6 +108,7 @@ void why2_list_remove_back(why2_list_t *list)
|
|||||||
buffer -> next = NULL; //UNLINK
|
buffer -> next = NULL; //UNLINK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(deallocating_node -> value);
|
||||||
free(deallocating_node);
|
free(deallocating_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user