Merge branch 'master' into Dennis_buffer
This commit is contained in:
		
						commit
						7eab42c3b9
					
				| @ -6,7 +6,7 @@ | |||||||
| #include <limits.h> | #include <limits.h> | ||||||
| 
 | 
 | ||||||
| // #include <config.h>
 | // #include <config.h>
 | ||||||
| #define HISTORY 1 | #define HISTORY | ||||||
| 
 | 
 | ||||||
| #include "../FIFOBuff/FIFOBuffChar.h" | #include "../FIFOBuff/FIFOBuffChar.h" | ||||||
| #ifdef HISTORY | #ifdef HISTORY | ||||||
| @ -69,7 +69,7 @@ bool CLI_deinit() | |||||||
| 
 | 
 | ||||||
| 	FIFOBuffChar_delete(FIFO); | 	FIFOBuffChar_delete(FIFO); | ||||||
| #ifdef HISTORY | #ifdef HISTORY | ||||||
| 	History_deinit(History); | 	History_deinit(History, true); | ||||||
| #endif | #endif | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,14 +8,14 @@ | |||||||
| // initilises a CMDList_t with all NULL pointers
 | // initilises a CMDList_t with all NULL pointers
 | ||||||
| CMDList_t* CMDList_init() | CMDList_t* CMDList_init() | ||||||
| { | { | ||||||
| 	CMDList_t *list = malloc(sizeof(CMDList_t)); | 	CMDList_t* list = malloc(sizeof(CMDList_t)); | ||||||
| 	memset(list, 0, sizeof(CMDList_t)); | 	memset(list, 0, sizeof(CMDList_t)); | ||||||
| 	return list; | 	return list; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // free up the full tree from memory
 | // free up the full tree from memory
 | ||||||
| // does not free up the commands
 | // 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; | 	CMDList_t** list_p = (CMDList_t**)list; | ||||||
| 
 | 
 | ||||||
| @ -28,7 +28,7 @@ int CMDList_deinit(CMDList_t *list) | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	free(*list_p); | 	free(list); | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -44,7 +44,7 @@ int CMDList_add(CMDList_t *list, CMD_t* cmd, char* cmdName) | |||||||
| 		read_p = cmd->cmd; | 		read_p = cmd->cmd; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	while (returnCode == 0) | 	while (returnCode >= 0) | ||||||
| 	{ | 	{ | ||||||
| 		char c = *read_p & (~0x20); // convert to uppercase
 | 		char c = *read_p & (~0x20); // convert to uppercase
 | ||||||
| 		if ((c >= 'A') && (c <= 'Z')) | 		if ((c >= 'A') && (c <= 'Z')) | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ add_library(history History/History.c) | |||||||
| 
 | 
 | ||||||
| # CLI | # CLI | ||||||
| add_library(CLI CLI/CLI.c) | 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) | add_library(CLI_History CLI/CLI.c) | ||||||
| target_link_libraries(CLI_History CMDList FIFOBuffChar history) | target_link_libraries(CLI_History CMDList FIFOBuffChar history) | ||||||
|  | |||||||
| @ -4,8 +4,6 @@ | |||||||
| #include <stddef.h> | #include <stddef.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| 
 | 
 | ||||||
| int i = 0; |  | ||||||
| 
 |  | ||||||
| History_t* History_init() | History_t* History_init() | ||||||
| { | { | ||||||
| 	History_t* history = malloc(sizeof(History_t)); | 	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
 | 	// Check if the buffer there is something in the buffer
 | ||||||
| 	if (history->FirstEl_p == NULL) | 	if (history->FirstEl_p == NULL) | ||||||
| @ -31,6 +29,10 @@ int History_deinit(History_t* history) | |||||||
| 		while (el != NULL) | 		while (el != NULL) | ||||||
| 		{ | 		{ | ||||||
| 			History_element_t* nextEl = el->nextEl_p; | 			History_element_t* nextEl = el->nextEl_p; | ||||||
|  | 			if (freeLines) | ||||||
|  | 			{ | ||||||
|  | 				free(el->line); | ||||||
|  | 			} | ||||||
| 			free(el); | 			free(el); | ||||||
| 			el = nextEl; | 			el = nextEl; | ||||||
| 		} | 		} | ||||||
| @ -151,6 +153,7 @@ int History_getFullHistory(History_t* history, char*** list) | |||||||
| 	*list = malloc(sizeof(char**) * (History_getSize(history) + 1)); | 	*list = malloc(sizeof(char**) * (History_getSize(history) + 1)); | ||||||
| 	History_element_t* el = history->FirstEl_p; | 	History_element_t* el = history->FirstEl_p; | ||||||
| 
 | 
 | ||||||
|  | 	int i; | ||||||
| 	for (i = 0; (i < History_getSize(history)-1) && (retCode >= 0); i++) | 	for (i = 0; (i < History_getSize(history)-1) && (retCode >= 0); i++) | ||||||
| 	{ | 	{ | ||||||
| 		*((*list) + i) = el->line; | 		*((*list) + i) = el->line; | ||||||
| @ -180,6 +183,7 @@ int History_getCurrPos(History_t* history) | |||||||
| 	if (history->CurrEl_p != NULL) | 	if (history->CurrEl_p != NULL) | ||||||
| 	{ | 	{ | ||||||
| 		History_element_t* el = history->FirstEl_p; | 		History_element_t* el = history->FirstEl_p; | ||||||
|  | 		int i; | ||||||
| 		for (i = 0; (el != history->CurrEl_p) && (retCode >= 0); i++) | 		for (i = 0; (el != history->CurrEl_p) && (retCode >= 0); i++) | ||||||
| 		{ | 		{ | ||||||
| 			if (el->nextEl_p == NULL) | 			if (el->nextEl_p == NULL) | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ typedef struct History_s { | |||||||
| extern History_t* History_init(); | extern History_t* History_init(); | ||||||
| 
 | 
 | ||||||
| // destroy a fifo buffer (free up its space)
 | // 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
 | // put value i in buffer if there is still memory avaliable
 | ||||||
| extern int History_put(History_t *history, char* line); | extern int History_put(History_t *history, char* line); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user