Merge branch 'master' into Dennis_buffer

This commit is contained in:
Dennis Boekholtz 2024-04-14 23:35:52 +02:00
commit 7eab42c3b9
5 changed files with 15 additions and 11 deletions

View File

@ -6,7 +6,7 @@
#include <limits.h>
// #include <config.h>
#define HISTORY 1
#define HISTORY
#include "../FIFOBuff/FIFOBuffChar.h"
#ifdef HISTORY
@ -69,7 +69,7 @@ bool CLI_deinit()
FIFOBuffChar_delete(FIFO);
#ifdef HISTORY
History_deinit(History);
History_deinit(History, true);
#endif
return true;
}

View File

@ -8,14 +8,14 @@
// initilises a CMDList_t with all NULL pointers
CMDList_t* CMDList_init()
{
CMDList_t *list = malloc(sizeof(CMDList_t));
CMDList_t* list = malloc(sizeof(CMDList_t));
memset(list, 0, sizeof(CMDList_t));
return list;
}
// free up the full tree from memory
// does not free up the commands
int CMDList_deinit(CMDList_t *list)
int CMDList_deinit(CMDList_t* list)
{
CMDList_t** list_p = (CMDList_t**)list;
@ -28,7 +28,7 @@ int CMDList_deinit(CMDList_t *list)
}
}
free(*list_p);
free(list);
return 0;
}
@ -44,7 +44,7 @@ int CMDList_add(CMDList_t *list, CMD_t* cmd, char* cmdName)
read_p = cmd->cmd;
}
while (returnCode == 0)
while (returnCode >= 0)
{
char c = *read_p & (~0x20); // convert to uppercase
if ((c >= 'A') && (c <= 'Z'))

View File

@ -11,7 +11,7 @@ add_library(history History/History.c)
# CLI
add_library(CLI CLI/CLI.c)
target_link_libraries(CLI CMDList FIFOBuffChar)
target_link_libraries(CLI CMDList FIFOBuffChar history)
add_library(CLI_History CLI/CLI.c)
target_link_libraries(CLI_History CMDList FIFOBuffChar history)

View File

@ -4,8 +4,6 @@
#include <stddef.h>
#include <stdio.h>
int i = 0;
History_t* History_init()
{
History_t* history = malloc(sizeof(History_t));
@ -21,7 +19,7 @@ History_t* History_init()
}
int History_deinit(History_t* history)
int History_deinit(History_t* history, bool freeLines)
{
// Check if the buffer there is something in the buffer
if (history->FirstEl_p == NULL)
@ -31,6 +29,10 @@ int History_deinit(History_t* history)
while (el != NULL)
{
History_element_t* nextEl = el->nextEl_p;
if (freeLines)
{
free(el->line);
}
free(el);
el = nextEl;
}
@ -151,6 +153,7 @@ int History_getFullHistory(History_t* history, char*** list)
*list = malloc(sizeof(char**) * (History_getSize(history) + 1));
History_element_t* el = history->FirstEl_p;
int i;
for (i = 0; (i < History_getSize(history)-1) && (retCode >= 0); i++)
{
*((*list) + i) = el->line;
@ -180,6 +183,7 @@ int History_getCurrPos(History_t* history)
if (history->CurrEl_p != NULL)
{
History_element_t* el = history->FirstEl_p;
int i;
for (i = 0; (el != history->CurrEl_p) && (retCode >= 0); i++)
{
if (el->nextEl_p == NULL)

View File

@ -22,7 +22,7 @@ typedef struct History_s {
extern History_t* History_init();
// destroy a fifo buffer (free up its space)
extern int History_deinit(History_t* history);
extern int History_deinit(History_t* history, bool freeLines);
// put value i in buffer if there is still memory avaliable
extern int History_put(History_t *history, char* line);