Removed all internal printf dependencies should solve #10.

Added a switch to strip the api printf implementation
Added a write function as alternative to printf.
This commit is contained in:
prozessorkern 2019-06-24 16:51:23 +02:00
parent 7344075ad1
commit 424ca84f61
2 changed files with 41 additions and 11 deletions

View File

@ -126,9 +126,14 @@ shellmatta_retCode_t shellmatta_addCmd( shellmatta_handle_t handle,
shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle, shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
char *data, char *data,
uint32_t size); uint32_t size);
shellmatta_retCode_t shellmatta_write( shellmatta_handle_t handle,
char *data,
uint32_t length);
#ifndef SHELLMATTA_STRIP_PRINTF
shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle, shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
const char *fmt, const char *fmt,
...); ...);
#endif
#endif #endif

View File

@ -579,7 +579,8 @@ static void terminateInput(shellmatta_instance_t *inst)
{ {
inst->inputCount = 0u; inst->inputCount = 0u;
inst->cursor = 0u; inst->cursor = 0u;
shellmatta_printf(inst, "\r\n%s", inst->prompt); inst->write("\r\n", 2u);
inst->write(inst->prompt, strlen(inst->prompt));
} }
/** /**
@ -773,16 +774,20 @@ static shellmatta_retCode_t helpCmdFct(shellmatta_handle_t handle, const char *a
cmdAliasLen = strlen(cmd->cmdAlias); cmdAliasLen = strlen(cmd->cmdAlias);
cmdHelpLen = strlen(cmd->helpText); cmdHelpLen = strlen(cmd->helpText);
shellmatta_printf(handle, "%s ", cmd->cmd); inst->write(cmd->cmd, strlen(cmd->cmd));
tabCnt = (maxCmdLen - cmdLen); tabCnt = (maxCmdLen - cmdLen) + 2u;
SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write); SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
shellmatta_printf(handle, "%s ", cmd->cmdAlias);
tabCnt = (maxCmdAliasLen - cmdAliasLen); inst->write(cmd->cmdAlias, strlen(cmd->cmdAlias));
tabCnt = (maxCmdAliasLen - cmdAliasLen) + 2u;
SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write); SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
shellmatta_printf(handle, "%s ", cmd->helpText);
tabCnt = (maxCmdHelpLen - cmdHelpLen); inst->write(cmd->helpText, strlen(cmd->helpText));
tabCnt = (maxCmdHelpLen - cmdHelpLen) + 2u;
SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write); SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
shellmatta_printf(handle, "%s\r\n", cmd->usageText);
inst->write(cmd->usageText, strlen(cmd->usageText));
inst->write("\r\n", 2u);
cmd = cmd->next; cmd = cmd->next;
} }
@ -1010,9 +1015,9 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
if ((cmdExecuted == 0u) && (inst->inputCount > 0)) if ((cmdExecuted == 0u) && (inst->inputCount > 0))
{ {
inst->buffer[inst->inputCount] = '\0'; inst->buffer[inst->inputCount] = '\0';
shellmatta_printf( inst, inst->write("\r\nCommand: ", 11u);
"\r\nCommand: %s not found", inst->write(inst->buffer, inst->inputCount);
inst->buffer); inst->write(" not found", 10u);
} }
terminateInput(inst); terminateInput(inst);
} }
@ -1069,6 +1074,25 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
return ret; return ret;
} }
shellmatta_retCode_t shellmatta_write( shellmatta_handle_t handle,
char *data,
uint32_t length)
{
shellmatta_retCode_t ret = SHELLMATTA_USE_FAULT;
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
/** -# check parameters for plausibility */
if( (NULL != inst)
&& (SHELLMATTA_MAGIC == inst->magic))
{
ret = inst->write(data, length);
}
return ret;
}
#ifndef SHELLMATTA_STRIP_PRINTF
/** /**
* @brief printf like function to print output to the instances output * @brief printf like function to print output to the instances output
* @param[in] handle shellmatta instance handle * @param[in] handle shellmatta instance handle
@ -1110,6 +1134,7 @@ shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
} }
return ret; return ret;
} }
#endif
/** @} */ /** @} */
/** @} */ /** @} */