History: add to cmake and fix errors
This commit is contained in:
@@ -9,3 +9,6 @@ add_library(CMDListPrint CMDList/printList.c)
|
||||
# CLI
|
||||
add_library(CLI CLI/CLI.c)
|
||||
target_link_libraries(CLI CMDList FIFOBuffChar)
|
||||
|
||||
# History
|
||||
add_library(history History/History.c)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "FIFOBuffChar.h"
|
||||
#include "history.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
@@ -6,11 +6,12 @@
|
||||
|
||||
History_t* History_init()
|
||||
{
|
||||
History_t* history = malloc(sizeof(FIFOBuffChar_t));
|
||||
|
||||
History_t* history = malloc(sizeof(History_t));
|
||||
|
||||
if (history != NULL) {
|
||||
history->FirstEl_p = NULL;
|
||||
history->LastEl_p = NULL;
|
||||
history->CurrEl_p = NULL;
|
||||
history->size = 0;
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ int History_deinit(History_t* history)
|
||||
History_element_t* el = history->FirstEl_p;
|
||||
while (el != NULL)
|
||||
{
|
||||
FIFOBuffChar_element_t* nextEl = el->nextEl;
|
||||
History_element_t* nextEl = el->nextEl_p;
|
||||
free(el);
|
||||
el = nextEl;
|
||||
}
|
||||
@@ -47,8 +48,8 @@ int History_put(History_t *history, char* line)
|
||||
if (history->FirstEl_p != NULL)
|
||||
{
|
||||
history->FirstEl_p->line = line;
|
||||
history->FirstEl_p->prev_p = NULL;
|
||||
history->FirstEl_p->next_p = NULL;
|
||||
history->FirstEl_p->prevEl_p = NULL;
|
||||
history->FirstEl_p->nextEl_p = NULL;
|
||||
|
||||
history->LastEl_p = history->FirstEl_p;
|
||||
history->size = 1;
|
||||
@@ -65,8 +66,8 @@ int History_put(History_t *history, char* line)
|
||||
History_element_t* el = malloc(sizeof(History_element_t));
|
||||
if (el != NULL)
|
||||
{
|
||||
el->character = i; // "value" to "character"
|
||||
el->PrevEl_p = history->LastEl_p;
|
||||
el->line = line;
|
||||
el->prevEl_p = history->LastEl_p;
|
||||
el->nextEl_p = NULL;
|
||||
history->LastEl_p->nextEl_p = el;
|
||||
history->LastEl_p = el;
|
||||
@@ -86,7 +87,7 @@ int History_put(History_t *history, char* line)
|
||||
if (retCode >= 0)
|
||||
{
|
||||
// reset current pointer
|
||||
history->currEl_p = NULL;
|
||||
history->CurrEl_p = NULL;
|
||||
}
|
||||
|
||||
return retCode;
|
||||
@@ -95,18 +96,39 @@ int History_put(History_t *history, char* line)
|
||||
int History_getPrev(History_t* history, char** line)
|
||||
{
|
||||
int retCode;
|
||||
if (history->currEl_p != NULL)
|
||||
if (history->CurrEl_p == NULL)
|
||||
{
|
||||
history->currEl_p = history->LastEl_p;
|
||||
history->CurrEl_p = history->LastEl_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
history->currEl_p = history->currEl_p->PrevEl_p;
|
||||
history->CurrEl_p = history->CurrEl_p->prevEl_p;
|
||||
}
|
||||
|
||||
if (history->currEl_p != NULL)
|
||||
if (history->CurrEl_p != NULL)
|
||||
{
|
||||
*line = history->currEl_p->line;
|
||||
*line = history->CurrEl_p->line;
|
||||
retCode = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*line = NULL;
|
||||
retCode = -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int History_getNext(History_t* history, char** line)
|
||||
{
|
||||
int retCode;
|
||||
if (history->CurrEl_p != NULL)
|
||||
{
|
||||
history->CurrEl_p = history->CurrEl_p->nextEl_p;
|
||||
}
|
||||
|
||||
if (history->CurrEl_p != NULL)
|
||||
{
|
||||
*line = history->CurrEl_p->line;
|
||||
retCode = 0;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user