|
@@ -77,6 +77,8 @@ shellmatta_retCode_t shellmatta_doInit(
|
|
|
inst->inputCount = 0u;
|
|
|
inst->lastNewlineIdx = 0u;
|
|
|
inst->cursor = 0u;
|
|
|
+ inst->stdinIdx = 0u;
|
|
|
+ inst->stdinLength = 0u;
|
|
|
inst->historyBuffer = historyBuffer;
|
|
|
inst->historyBufferSize = historyBufferSize;
|
|
|
inst->historyStart = 0u;
|
|
@@ -137,6 +139,8 @@ shellmatta_retCode_t shellmatta_resetShell( shellmatta_handle_t handle, bool pri
|
|
|
inst->inputCount = 0u;
|
|
|
inst->lastNewlineIdx = 0u;
|
|
|
inst->cursor = 0u;
|
|
|
+ inst->stdinIdx = 0u;
|
|
|
+ inst->stdinLength = 0u;
|
|
|
inst->historyStart = 0u;
|
|
|
inst->historyEnd = 0u;
|
|
|
inst->historyRead = 0u;
|
|
@@ -356,10 +360,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
uint8_t cmdExecuted = 0u;
|
|
|
uint32_t cmdLen;
|
|
|
char *tempString;
|
|
|
- char *argumentString;
|
|
|
- uint32_t argumentLength;
|
|
|
uint32_t byteCounter;
|
|
|
- uint32_t idx;
|
|
|
|
|
|
shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
|
@@ -371,10 +372,6 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
/** -# process byte wise */
|
|
|
for (byteCounter = 0u; byteCounter < size; byteCounter++)
|
|
|
{
|
|
|
- /*! -# set default values for the command argument - can be overwritten by heredoc */
|
|
|
- argumentString = inst->buffer;
|
|
|
- argumentLength = inst->inputCount;
|
|
|
-
|
|
|
/** -# handle escape sequences */
|
|
|
if(inst->escapeCounter != 0u)
|
|
|
{
|
|
@@ -458,23 +455,28 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
tempString,
|
|
|
inst->hereLength)))
|
|
|
{
|
|
|
- argumentLength = inst->lastNewlineIdx;
|
|
|
-
|
|
|
/** -# store the current command and reset the history buffer */
|
|
|
inst->dirty = true;
|
|
|
history_storeCmd(inst);
|
|
|
history_reset(inst);
|
|
|
|
|
|
-
|
|
|
- /* 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 function */
|
|
|
- for(idx = 1u; idx <= inst->hereStartIdx; idx++)
|
|
|
+ /*! -# process heredoc as stdin like input */
|
|
|
+ /*! -# find start of heredoc data */
|
|
|
+ inst->stdinIdx = inst->hereDelimiterIdx + inst->hereLength;
|
|
|
+ while( ('\n' == inst->buffer[inst->stdinIdx])
|
|
|
+ || ('\r' == inst->buffer[inst->stdinIdx]))
|
|
|
{
|
|
|
- inst->buffer[inst->hereDelimiterIdx + inst->hereLength - idx] = inst->buffer[inst->hereStartIdx - idx];
|
|
|
+ inst->stdinIdx ++;
|
|
|
}
|
|
|
-
|
|
|
- argumentString = &(inst->buffer[inst->hereDelimiterIdx + inst->hereLength - inst->hereStartIdx]);
|
|
|
- argumentLength = inst->lastNewlineIdx - ((inst->hereDelimiterIdx + inst->hereLength) - inst->hereStartIdx);
|
|
|
+ /** -# calculate length and terminate stdin string */
|
|
|
+ inst->stdinLength = inst->lastNewlineIdx - inst->stdinIdx;
|
|
|
+ inst->buffer[inst->lastNewlineIdx] = '\0';
|
|
|
+
|
|
|
+ /** -# calculate length and terminate argument string */
|
|
|
+ inst->inputCount = inst->hereStartIdx;
|
|
|
+ inst->buffer[inst->hereStartIdx] = '\0';
|
|
|
+
|
|
|
+ /** -# terminate heredoc session */
|
|
|
inst->hereLength = 0u;
|
|
|
}
|
|
|
else
|
|
@@ -487,16 +489,15 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
|
|
|
if(0u == inst->hereLength)
|
|
|
{
|
|
|
- cmd = inst->cmdList;
|
|
|
- argumentString[argumentLength] = 0u;
|
|
|
+ cmd = inst->cmdList;
|
|
|
|
|
|
/** -# determine the cmd len (chars until first space or \0 is found */
|
|
|
cmdLen = 0u;
|
|
|
- while( (cmdLen < argumentLength)
|
|
|
- && (' ' != argumentString[cmdLen])
|
|
|
- && ('\r' != argumentString[cmdLen])
|
|
|
- && ('\n' != argumentString[cmdLen])
|
|
|
- && ('\0' != argumentString[cmdLen]))
|
|
|
+ while( (cmdLen < inst->inputCount)
|
|
|
+ && (' ' != inst->buffer[cmdLen])
|
|
|
+ && ('\r' != inst->buffer[cmdLen])
|
|
|
+ && ('\n' != inst->buffer[cmdLen])
|
|
|
+ && ('\0' != inst->buffer[cmdLen]))
|
|
|
{
|
|
|
cmdLen ++;
|
|
|
}
|
|
@@ -505,12 +506,12 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
while (NULL != cmd)
|
|
|
{
|
|
|
/** -# compare command and alias string and length */
|
|
|
- if ( ((0 == strncmp( argumentString,
|
|
|
+ if ( ((0 == strncmp( inst->buffer,
|
|
|
cmd->cmd,
|
|
|
cmdLen))
|
|
|
&& (cmdLen == strlen(cmd->cmd)))
|
|
|
|| ((NULL != cmd->cmdAlias)
|
|
|
- && ((0 == strncmp( argumentString,
|
|
|
+ && ((0 == strncmp( inst->buffer,
|
|
|
cmd->cmdAlias,
|
|
|
cmdLen))
|
|
|
&& (cmdLen == strlen(cmd->cmdAlias)))))
|
|
@@ -518,7 +519,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
utils_writeEcho(inst, "\r\n", 2u);
|
|
|
shellmatta_opt_init(inst, cmdLen + 1u);
|
|
|
cmdExecuted = 1u;
|
|
|
- cmd->cmdFct(inst, argumentString, argumentLength);
|
|
|
+ cmd->cmdFct(inst, inst->buffer, inst->inputCount);
|
|
|
cmd = NULL;
|
|
|
}
|
|
|
else
|
|
@@ -530,7 +531,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
|
if ((cmdExecuted == 0u) && (inst->inputCount > 0))
|
|
|
{
|
|
|
inst->write("\r\nCommand: ", 11u);
|
|
|
- inst->write(argumentString, argumentLength);
|
|
|
+ inst->write(inst->buffer, inst->inputCount);
|
|
|
inst->write(" not found", 10u);
|
|
|
}
|
|
|
utils_terminateInput(inst);
|
|
@@ -610,6 +611,34 @@ shellmatta_retCode_t shellmatta_write( shellmatta_handle_t handle,
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief reads the stdin like buffer
|
|
|
+ * @param[in] handle shellmatta instance handle
|
|
|
+ * @param[out] data pointer to pointer to store ref to the buffer
|
|
|
+ * @param[out] length size of the stdin data
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+shellmatta_retCode_t shellmatta_read( 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)
|
|
|
+ && (NULL != data)
|
|
|
+ && (NULL != length))
|
|
|
+ {
|
|
|
+ /** -# return a pointer to the data */
|
|
|
+ *data = &(inst->buffer[inst->stdinIdx]);
|
|
|
+ *length = inst->stdinLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
#ifndef SHELLMATTA_STRIP_PRINTF
|
|
|
|
|
|
/**
|