added remove api + small integratio test close #9

This commit is contained in:
prozessorkern
2020-02-03 21:35:20 +01:00
parent 1c294bb7d1
commit d1649e5e86
4 changed files with 140 additions and 1 deletions

View File

@@ -183,6 +183,67 @@ shellmatta_retCode_t shellmatta_addCmd(shellmatta_handle_t handle, shellmatta_cm
return ret;
}
/**
* @brief removes a command from the command list
* @param[in] handle shellmatta instance handle
* @param[in] cmd pointer to the command to remove type #shellmatta_cmd_t
* @return errorcode #SHELLMATTA_OK
* #SHELLMATTA_USE_FAULT (param err)
*/
shellmatta_retCode_t shellmatta_removeCmd(shellmatta_handle_t handle, shellmatta_cmd_t *cmd)
{
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
shellmatta_cmd_t *prevCmd;
shellmatta_cmd_t *tempCmd;
shellmatta_retCode_t ret = SHELLMATTA_OK;
/** -# check parameters for plausibility */
if( (NULL != inst)
&& (SHELLMATTA_MAGIC == inst->magic)
&& (false == inst->cmdListIsConst))
{
tempCmd = inst->cmdList;
prevCmd = NULL;
/*! -# loop through command list */
while(NULL != tempCmd)
{
/*! -# compare command strings to find the command to delete */
if (0 == strcmp( tempCmd->cmd,
cmd->cmd)
&& (strlen(tempCmd->cmd) == strlen(cmd->cmd)))
{
/*! -# first command removed */
if(NULL == prevCmd)
{
inst->cmdList = tempCmd->next;
}
/*! -# last command removed */
else if(NULL == tempCmd->next)
{
prevCmd->next = NULL;
}
/*! -# command removed from the middle of the list */
else
{
prevCmd->next = tempCmd->next;
}
break;
}
prevCmd = tempCmd;
tempCmd = tempCmd->next;
}
}
else
{
ret = SHELLMATTA_USE_FAULT;
}
return ret;
}
/**
* @brief processes the passed amount of data
* @param[in] handle shellmatta instance handle
@@ -308,7 +369,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
/* TODO it is difficult to store the complete command in the history buffer if it is restructured before...
* So this should be an extra function that can be called after parsing the command and before calling the command funktion */
* So this should be an extra function that can be called after parsing the command and before calling the command function */
for(idx = 1u; idx <= inst->hereStartIdx; idx++)
{
inst->buffer[inst->hereDelimiterIdx + inst->hereLength - idx] = inst->buffer[inst->hereStartIdx - idx];