close #30 added overwritable help command parameter and fixed some compiler issues (some of them only appeared when compiling with optimization)

This commit is contained in:
prozessorkern 2020-03-01 17:53:27 +01:00
parent 4f9ff4fe3c
commit c04accdb55
10 changed files with 65 additions and 14 deletions

View File

@ -52,6 +52,9 @@ static shellmatta_retCode_t doSome(shellmatta_handle_t handle, const char *argum
shellmatta_write(handle, "blubb\r\n", 7u); shellmatta_write(handle, "blubb\r\n", 7u);
(void)arguments;
(void)length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }
shellmatta_cmd_t doSomeCmd = {"adoSome2", "adof2", "Function does something", "use me, please", doSome, NULL}; shellmatta_cmd_t doSomeCmd = {"adoSome2", "adof2", "Function does something", "use me, please", doSome, NULL};
@ -62,6 +65,9 @@ static shellmatta_retCode_t removeCmdFct(shellmatta_handle_t handle, const char
shellmatta_removeCmd(handle, &doSomeCmd); shellmatta_removeCmd(handle, &doSomeCmd);
(void)arguments;
(void)length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }
shellmatta_cmd_t removeCommand = {"remove", "r", "Function removes a command", "", removeCmdFct, NULL}; shellmatta_cmd_t removeCommand = {"remove", "r", "Function removes a command", "", removeCmdFct, NULL};
@ -71,6 +77,10 @@ static shellmatta_retCode_t quit(shellmatta_handle_t handle, const char *argumen
{ {
exitRequest = true; exitRequest = true;
(void)handle;
(void)arguments;
(void)length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }
shellmatta_cmd_t quitCommand = {"quit", "q", "Function quits the shell", "", quit, NULL}; shellmatta_cmd_t quitCommand = {"quit", "q", "Function quits the shell", "", quit, NULL};
@ -83,17 +93,23 @@ shellmatta_retCode_t writeFct(const char* data, uint32_t length)
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }
int main(void) int main(int argc, char **argv)
{ {
static char buffer[1024]; static char buffer[1024];
static char historyBuffer[4096]; static char historyBuffer[4096];
static shellmatta_instance_t instance; static shellmatta_instance_t instance;
f = open("/dev/pts/3", O_RDWR | O_SYNC); if(2 != argc)
{
printf("%s <serial device>\n", argv[0u]);
return -1;
}
f = open(argv[1u], O_RDWR | O_SYNC);
if (f < 0) if (f < 0)
{ {
printf("failure %d\n", errno); printf("failure opening device %s %d\n", argv[1u], errno);
return f; return f;
} }

View File

@ -43,8 +43,8 @@ UNITTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(UNITTEST_SOURCES))
INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES)) INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -pedantic CFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic -DSHELLMATTA_HELP_ALIAS=\"?\"
TESTFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -fprofile-arcs -ftest-coverage -pedantic TESTFLAGS := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -fprofile-arcs -ftest-coverage -pedantic
TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM

View File

@ -260,8 +260,8 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
uint8_t cmdExecuted = 0u; uint8_t cmdExecuted = 0u;
uint32_t cmdLen; uint32_t cmdLen;
char *tempString; char *tempString;
char *argumentString; char *argumentString = NULL;
uint32_t argumentLength; uint32_t argumentLength = 0u;
uint32_t byteCounter; uint32_t byteCounter;
uint32_t idx; uint32_t idx;

View File

@ -327,7 +327,12 @@ static shellmatta_retCode_t helpCmdFct(shellmatta_handle_t handle, const char *a
return ret; return ret;
} }
shellmatta_cmd_t helpCmd = {(char*)"help", (char*)"h", (char*)"Print this help text", (char*)"help", helpCmdFct, NULL}; shellmatta_cmd_t helpCmd = { SHELLMATTA_HELP_COMMAND
, SHELLMATTA_HELP_ALIAS
, SHELLMATTA_HELP_HELP_TEXT
, SHELLMATTA_HELP_USAGE_TEXT
, helpCmdFct
, NULL};
/** /**
* @brief terminates an input and prints the prompt again * @brief terminates an input and prints the prompt again

View File

@ -22,7 +22,7 @@
#include "shellmatta.h" #include "shellmatta.h"
#include <stdint.h> #include <stdint.h>
/* some helper macros */
#define SHELLMATTA_MIN(a,b) (((a) > (b)) ? (b) : (a)) #define SHELLMATTA_MIN(a,b) (((a) > (b)) ? (b) : (a))
#define SHELLMATTA_MAX(a,b) (((a) < (b)) ? (b) : (a)) #define SHELLMATTA_MAX(a,b) (((a) < (b)) ? (b) : (a))
#define SHELLMATTA_PRINT_BUFFER(buffer,cnt,fct) \ #define SHELLMATTA_PRINT_BUFFER(buffer,cnt,fct) \
@ -40,10 +40,38 @@ extern shellmatta_cmd_t helpCmd;
#define SHELLMATTA_MAGIC 0x5101E110u #define SHELLMATTA_MAGIC 0x5101E110u
/*! \brief overwritable output buffer size */
#ifndef SHELLMATTA_OUTPUT_BUFFER_SIZE #ifndef SHELLMATTA_OUTPUT_BUFFER_SIZE
#define SHELLMATTA_OUTPUT_BUFFER_SIZE 128u #define SHELLMATTA_OUTPUT_BUFFER_SIZE 128u
#endif #endif
/*! @defgroup Shellmatta Help command overwrites
* @{
* overwritable help command parameters - the help command is built in and cannot be removed, but you can change
* the command, alias and help texts by defining them in your build process
* To change the settings set one of these defines:
* #SHELLMATTA_HELP_COMMAND to overwrite the help command
* #SHELLMATTA_HELP_ALIAS to overwrite the help alias
* #SHELLMATTA_HELP_HELP_TEXT to overwrite the help text
* #SHELLMATTA_HELP_USAGE_TEXT to overwrite the usage text
* e.g. use _-DSHELLMATTA_HELP_ALIAS=\"?\"_ as compile option to change the alias to ?
*/
#ifndef SHELLMATTA_HELP_COMMAND
#define SHELLMATTA_HELP_COMMAND (char*)"help" /*!< help command */
#endif
#ifndef SHELLMATTA_HELP_ALIAS
#define SHELLMATTA_HELP_ALIAS (char*)"h" /*!< help command alias */
#endif
#ifndef SHELLMATTA_HELP_HELP_TEXT
#define SHELLMATTA_HELP_HELP_TEXT (char*)"Print this help text" /*!< help command help text */
#endif
#ifndef SHELLMATTA_HELP_USAGE_TEXT
#define SHELLMATTA_HELP_USAGE_TEXT (char*)"help" /*!< help command usage text */
#endif
/*!
* @}
*/
void utils_writeEcho( shellmatta_instance_t *inst, void utils_writeEcho( shellmatta_instance_t *inst,
const char *data, const char *data,
uint32_t length); uint32_t length);

View File

@ -4,6 +4,8 @@
static shellmatta_retCode_t writeFct(const char* data, uint32_t length) static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
{ {
(void)data;
(void)length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }

View File

@ -9,7 +9,7 @@ static uint32_t write_length;
static shellmatta_retCode_t writeFct(const char* data, uint32_t length) static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
{ {
write_callCnt ++; write_callCnt ++;
strncpy(write_data, data, length); memcpy(write_data, data, length);
write_length = length; write_length = length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }

View File

@ -9,7 +9,7 @@ static uint32_t write_length;
static shellmatta_retCode_t writeFct(const char* data, uint32_t length) static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
{ {
write_callCnt ++; write_callCnt ++;
strncpy(write_data, data, length); memcpy(write_data, data, length);
write_length = length; write_length = length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }

View File

@ -3,13 +3,13 @@
#include <string.h> #include <string.h>
static uint32_t write_callCnt = 0u; static uint32_t write_callCnt = 0u;
static char write_data[10]; static char write_data[10u];
static uint32_t write_length; static uint32_t write_length;
static shellmatta_retCode_t writeFct(const char* data, uint32_t length) static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
{ {
write_callCnt ++; write_callCnt ++;
strncpy(write_data, data, length); memcpy(write_data, data, length);
write_length = length; write_length = length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }

View File

@ -9,7 +9,7 @@ static uint32_t write_idx;
static shellmatta_retCode_t writeFct(const char* data, uint32_t length) static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
{ {
write_callCnt ++; write_callCnt ++;
strncpy(&write_data[write_idx], data, length); memcpy(&write_data[write_idx], data, length);
write_idx += length; write_idx += length;
return SHELLMATTA_OK; return SHELLMATTA_OK;
} }