Merge branch 'Dennis_CCS' into Dennis_buffer

This commit is contained in:
Dennis Boekholtz 2024-04-13 23:19:12 +02:00
commit ee501b17ce
4 changed files with 14 additions and 12 deletions

View File

@ -9,6 +9,7 @@
CLI_charOutFn CLI_charOut; CLI_charOutFn CLI_charOut;
CMDList_t* CMDList; CMDList_t* CMDList;
FIFOBuffChar_t* FIFO; FIFOBuffChar_t* FIFO;
int i;
// initilize and register the lineout print function // initilize and register the lineout print function
bool CLI_init(CLI_charOutFn lineOut, CMDList_t* cmdList) bool CLI_init(CLI_charOutFn lineOut, CMDList_t* cmdList)
@ -41,7 +42,7 @@ char* fifoToString(FIFOBuffChar_t* fifo)
char* out = malloc(fifo->size + 1); char* out = malloc(fifo->size + 1);
char* write_p = out; char* write_p = out;
for (int i = fifo->size; i > 0; i--) for (i = fifo->size; i > 0; i--)
{ {
FIFOBuffChar_get(fifo, write_p); FIFOBuffChar_get(fifo, write_p);
write_p++; write_p++;
@ -74,7 +75,7 @@ int tryExecute(FIFOBuffChar_t* fifo)
{ {
char err[100]; char err[100];
sprintf(&err[0], "command not found: %s\n> ", line); sprintf(&err[0], "command not found: %s\n> ", line);
for (int i=0; err[i] != 0; i++) for (i=0; err[i] != 0; i++)
{ {
char c[2] = {err[i], 0}; char c[2] = {err[i], 0};
(*CLI_charOut)(&c[0]); (*CLI_charOut)(&c[0]);
@ -139,7 +140,7 @@ bool CLI_charIn(char c)
case 27: // escape (start for arrow keys) case 27: // escape (start for arrow keys)
sprintf(&str[0], "\ninvlid char: ESC - (%i)\n", c); sprintf(&str[0], "\ninvlid char: ESC - (%i)\n", c);
for (int i=0; str[i] != 0; i++) for (i=0; str[i] != 0; i++)
{ {
char ch[2] = {str[i], 0}; char ch[2] = {str[i], 0};
(*CLI_charOut)(&ch[0]); (*CLI_charOut)(&ch[0]);
@ -148,7 +149,7 @@ bool CLI_charIn(char c)
default: default:
sprintf(&str[0], "\ninvlid char: '%c' - (%i)\n", c, c); sprintf(&str[0], "\ninvlid char: '%c' - (%i)\n", c, c);
for (int i=0; str[i] != 0; i++) for (i=0; str[i] != 0; i++)
{ {
char ch[2] = {str[i], 0}; char ch[2] = {str[i], 0};
(*CLI_charOut)(&ch[0]); (*CLI_charOut)(&ch[0]);

View File

@ -5,6 +5,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
int i;
// initilises a CMDList_t with all NULL pointers // initilises a CMDList_t with all NULL pointers
CMDList_t* CMDList_init() CMDList_t* CMDList_init()
{ {
@ -21,7 +22,7 @@ int CMDList_deinit(CMDList_t *list)
// printf("deinit %p\n", (void*)list); // printf("deinit %p\n", (void*)list);
// printf("deinit e %p\n", list->e); // printf("deinit e %p\n", list->e);
for (int i = 0; i < 26; i++) for (i = 0; i < 26; i++)
{ {
if (*(list_p + i) != NULL) if (*(list_p + i) != NULL)
{ {
@ -31,20 +32,20 @@ int CMDList_deinit(CMDList_t *list)
} }
//TODO: fix "free(): invalid pointer" //TODO: fix "free(): invalid pointer"
// free(list); free(list);
return 0; return 0;
} }
// add a command in the command tree // add a command in the command tree
int CMDList_add(CMDList_t *list, CMD_t* cmd) int CMDList_add(CMDList_t *list, CMD_t* cmd, char* cmdName)
{ {
int returnCode = 0; int returnCode = 0;
char* read_p = cmd->cmd; char* read_p = cmdName;
CMDList_t** list_p = (CMDList_t**)list; CMDList_t** list_p = (CMDList_t**)list;
if (read_p == NULL) if (read_p == NULL)
{ // cmd is missing a string for the commnad name {
returnCode = -1; read_p = cmd->cmd;
} }
while (returnCode == 0) while (returnCode == 0)

View File

@ -46,7 +46,7 @@ extern CMDList_t* CMDList_init();
extern int CMDList_deinit(CMDList_t *list); extern int CMDList_deinit(CMDList_t *list);
// add a command in the command tree // add a command in the command tree
extern int CMDList_add(CMDList_t *list, CMD_t* cmd); extern int CMDList_add(CMDList_t *list, CMD_t* cmd, char* cmdName);
// search command in the tree // search command in the tree
extern CMD_t* CMDList_get(CMDList_t *list, char* cmd); extern CMD_t* CMDList_get(CMDList_t *list, char* cmd);

View File

@ -1,4 +1,4 @@
#include "FIFOBuffChar.h" #include "C:\Users\denbo\git\ems31_2023-2024_groep_09_ccs\ ems31_2023-2024_groep_09_submodules_2\FIFOBuff\FIFOBuffChar.h"
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>