fix #47 now calling a continued command even without new input data
added integration tests
This commit is contained in:
@@ -101,6 +101,7 @@ shellmatta_retCode_t shellmatta_doInit(
|
||||
inst->continuousCmd = NULL;
|
||||
inst->busyCmd = NULL;
|
||||
inst->cmdListIsConst = false;
|
||||
shellmatta_opt_init(inst, 0u);
|
||||
|
||||
/** -# copy the help command structure to this instance */
|
||||
memcpy(&(inst->helpCmd), &helpCmd, sizeof(shellmatta_cmd_t));
|
||||
@@ -158,6 +159,7 @@ shellmatta_retCode_t shellmatta_resetShell( shellmatta_handle_t handle, bool pri
|
||||
inst->hereStartIdx = 0u;
|
||||
inst->hereDelimiterIdx = 0u;
|
||||
inst->hereLength = 0u;
|
||||
shellmatta_opt_init(inst, 0u);
|
||||
|
||||
if(true == printPrompt)
|
||||
{
|
||||
@@ -385,20 +387,44 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
||||
if(NULL != inst->busyCmd)
|
||||
{
|
||||
/** -# just call the function until it is not busy anymore */
|
||||
cmdRet = inst->busyCmd->cmdFct(handle, inst->buffer, inst->inputCount);
|
||||
(void)shellmatta_opt_reInit(inst);
|
||||
ret = inst->busyCmd->cmdFct(handle, inst->buffer, inst->inputCount);
|
||||
|
||||
if(SHELLMATTA_BUSY != cmdRet)
|
||||
if(SHELLMATTA_BUSY == ret)
|
||||
{
|
||||
utils_terminateInput(inst);
|
||||
/** -# do nothing - still busy */
|
||||
}
|
||||
else if(SHELLMATTA_CONTINUE == cmdRet)
|
||||
else if(SHELLMATTA_CONTINUE == ret)
|
||||
{
|
||||
inst->continuousCmd = inst->busyCmd;
|
||||
inst->busyCmd = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = cmdRet;
|
||||
utils_terminateInput(inst);
|
||||
}
|
||||
}
|
||||
/** -# call continuous function even if there is no data */
|
||||
else if((0u == size) && (NULL != inst->continuousCmd))
|
||||
{
|
||||
/** -# just call the function without any new data */
|
||||
inst->stdinLength = 0u;
|
||||
inst->buffer[inst->stdinIdx] = '\0';
|
||||
(void)shellmatta_opt_reInit(inst);
|
||||
ret = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
|
||||
|
||||
if(SHELLMATTA_CONTINUE == ret)
|
||||
{
|
||||
/** -# do nothing just continue */
|
||||
}
|
||||
else if(SHELLMATTA_BUSY == ret)
|
||||
{
|
||||
inst->busyCmd = inst->continuousCmd;
|
||||
inst->continuousCmd = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
utils_terminateInput(inst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,21 +435,25 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
||||
if(NULL != inst->continuousCmd)
|
||||
{
|
||||
/** -# copy data and call command function */
|
||||
inst->buffer[inst->stdinIdx] = data[inst->byteCounter];
|
||||
inst->stdinLength = 1u;
|
||||
cmdRet = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
|
||||
inst->buffer[inst->stdinIdx] = data[inst->byteCounter];
|
||||
inst->buffer[inst->stdinIdx + 1u] = '\0';
|
||||
inst->stdinLength = 1u;
|
||||
(void)shellmatta_opt_reInit(inst);
|
||||
ret = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
|
||||
|
||||
/** -# check if continuous mode is canceled or interrupted by busy mode */
|
||||
if(SHELLMATTA_BUSY == cmdRet)
|
||||
if(SHELLMATTA_BUSY == ret)
|
||||
{
|
||||
inst->busyCmd = inst->continuousCmd;
|
||||
inst->continuousCmd = NULL;
|
||||
}
|
||||
else if(('\x03' == data[inst->byteCounter]))
|
||||
{
|
||||
/** -# cancel continue session */
|
||||
utils_terminateInput(inst);
|
||||
ret = SHELLMATTA_OK;
|
||||
}
|
||||
else if(SHELLMATTA_CONTINUE == cmdRet)
|
||||
else if(SHELLMATTA_CONTINUE == ret)
|
||||
{
|
||||
/** -# do nothing - continue */
|
||||
}
|
||||
@@ -589,6 +619,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
||||
inst->stdinIdx = inst->inputCount + 1u;
|
||||
inst->stdinLength = 0u;
|
||||
inst->continuousCmd = cmd;
|
||||
ret = cmdRet;
|
||||
break;
|
||||
|
||||
case SHELLMATTA_BUSY:
|
||||
@@ -668,7 +699,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
||||
}
|
||||
}
|
||||
|
||||
/*! -# initialize the byte buffer if processing of the input is finished */
|
||||
/** -# initialize the byte buffer if processing of the input is finished */
|
||||
if(ret != SHELLMATTA_BUSY)
|
||||
{
|
||||
inst->byteCounter = 0u;
|
||||
|
@@ -410,12 +410,21 @@ shellmatta_retCode_t shellmatta_opt_long( shellmatta_handle_t handle,
|
||||
* @param[in, out] inst pointer to a shellmatta instance
|
||||
* @param[in] argStart start offset of the arguments (after command name/alias)
|
||||
*/
|
||||
shellmatta_retCode_t shellmatta_opt_init(shellmatta_instance_t *inst, uint32_t argStart)
|
||||
void shellmatta_opt_init(shellmatta_instance_t *inst, uint32_t argStart)
|
||||
{
|
||||
/** -# initialize all relevant option parser variables */
|
||||
inst->optionParser.nextOffset = argStart;
|
||||
inst->optionParser.argStart = argStart;
|
||||
inst->optionParser.nextOffset = argStart;
|
||||
}
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
/**
|
||||
* @brief re-initializes the option parser instance using the data from the last init
|
||||
* @param[in, out] inst pointer to a shellmatta instance
|
||||
*/
|
||||
void shellmatta_opt_reInit(shellmatta_instance_t *inst)
|
||||
{
|
||||
/** -# initialize all relevant option parser variables */
|
||||
inst->optionParser.nextOffset = inst->optionParser.argStart;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,9 +34,11 @@ shellmatta_retCode_t shellmatta_opt_long( shellmatta_handle_t handle,
|
||||
char **argument,
|
||||
uint32_t *argLen);
|
||||
|
||||
shellmatta_retCode_t shellmatta_opt_init( shellmatta_instance_t *inst,
|
||||
void shellmatta_opt_init( shellmatta_instance_t *inst,
|
||||
uint32_t argStart);
|
||||
|
||||
void shellmatta_opt_reInit( shellmatta_instance_t *inst);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
Reference in New Issue
Block a user