|
@@ -74,6 +74,7 @@ shellmatta_retCode_t shellmatta_doInit(
|
|
inst->buffer = buffer;
|
|
inst->buffer = buffer;
|
|
inst->bufferSize = bufferSize;
|
|
inst->bufferSize = bufferSize;
|
|
inst->inputCount = 0u;
|
|
inst->inputCount = 0u;
|
|
|
|
+ inst->lastNewlineIdx = 0u;
|
|
inst->cursor = 0u;
|
|
inst->cursor = 0u;
|
|
inst->historyBuffer = historyBuffer;
|
|
inst->historyBuffer = historyBuffer;
|
|
inst->historyBufferSize = historyBufferSize;
|
|
inst->historyBufferSize = historyBufferSize;
|
|
@@ -87,6 +88,7 @@ shellmatta_retCode_t shellmatta_doInit(
|
|
inst->dirty = false;
|
|
inst->dirty = false;
|
|
inst->tabCounter = 0u;
|
|
inst->tabCounter = 0u;
|
|
inst->escapeCounter = 0u;
|
|
inst->escapeCounter = 0u;
|
|
|
|
+ inst->hereLength = 0u;
|
|
inst->mode = SHELLMATTA_MODE_INSERT;
|
|
inst->mode = SHELLMATTA_MODE_INSERT;
|
|
inst->cmdList = &helpCmd;
|
|
inst->cmdList = &helpCmd;
|
|
inst->cmdListIsConst = false;
|
|
inst->cmdListIsConst = false;
|
|
@@ -194,6 +196,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
shellmatta_cmd_t *cmd;
|
|
shellmatta_cmd_t *cmd;
|
|
uint8_t cmdExecuted = 0u;
|
|
uint8_t cmdExecuted = 0u;
|
|
uint32_t cmdLen;
|
|
uint32_t cmdLen;
|
|
|
|
+ char *tempString;
|
|
shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
|
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
|
|
|
|
|
@@ -218,56 +221,131 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
|
/** -# handle return as start of processing the command */
|
|
/** -# handle return as start of processing the command */
|
|
else if ('\r' == *data)
|
|
else if ('\r' == *data)
|
|
{
|
|
{
|
|
- cmd = inst->cmdList;
|
|
|
|
- inst->buffer[inst->inputCount] = 0u;
|
|
|
|
|
|
+ if(0u == inst->hereLength)
|
|
|
|
+ {
|
|
|
|
+ /**
|
|
|
|
+ * \dot
|
|
|
|
+ * digraph heredocParser {
|
|
|
|
+ * start -> wait [ label="<< in first line - store delimiter" ];
|
|
|
|
+ * wait -> wait [ label="delimiter not detected" ];
|
|
|
|
+ * wait -> end [ label="delimiter found - remove all heredoc stuff and send the input to the command" ];
|
|
|
|
+ * }
|
|
|
|
+ * \enddot */
|
|
|
|
|
|
- /** -# store the current command and reset the history buffer */
|
|
|
|
- inst->dirty = true;
|
|
|
|
- history_storeCmd(inst);
|
|
|
|
- history_reset(inst);
|
|
|
|
|
|
+ /** -# check for heredoc */
|
|
|
|
+ tempString = strstr(inst->buffer, "<<");
|
|
|
|
+ if(NULL != tempString)
|
|
|
|
+ {
|
|
|
|
+ /*' -# check if length of heredoc delimiter is valid */
|
|
|
|
+ if(inst->inputCount > ((uint32_t)(tempString - inst->buffer) + 2u))
|
|
|
|
+ {
|
|
|
|
+ inst->hereLength = inst->inputCount - ((uint32_t)(tempString - inst->buffer) + 2u);
|
|
|
|
|
|
- /** -# determine the cmd len (chars until first space or \0 is found */
|
|
|
|
- cmdLen = 0u;
|
|
|
|
- while( (cmdLen < inst->inputCount)
|
|
|
|
- && (' ' != inst->buffer[cmdLen])
|
|
|
|
- && ('\0' != inst->buffer[cmdLen]))
|
|
|
|
- {
|
|
|
|
- cmdLen ++;
|
|
|
|
- }
|
|
|
|
|
|
+ if(sizeof(inst->hereDelimiter) < inst->hereLength)
|
|
|
|
+ {
|
|
|
|
+ inst->write("\r\nHeredoc delimiter too long\r\n", 30u);
|
|
|
|
+ inst->inputCount = 0u;
|
|
|
|
+ inst->hereLength = 0u;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ /** -# store delimiter and remove it from the input buffer */
|
|
|
|
+ strncpy(inst->hereDelimiter, &(tempString[2u]), inst->hereLength);
|
|
|
|
|
|
- /** -# search for a matching command */
|
|
|
|
- while (NULL != cmd)
|
|
|
|
|
|
+ inst->inputCount -= (inst->hereLength + 2u);
|
|
|
|
+ inst->cursor = inst->inputCount;
|
|
|
|
+ inst->dirty = true;
|
|
|
|
+ utils_insertChars(inst, data, 1);
|
|
|
|
+ inst->lastNewlineIdx = inst->inputCount;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ inst->hereLength = 0u;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- /** -# compare command string and length */
|
|
|
|
- if ( ((0 == strncmp( inst->buffer,
|
|
|
|
- cmd->cmd,
|
|
|
|
- cmdLen))
|
|
|
|
- && (cmdLen == strlen(cmd->cmd)))
|
|
|
|
- || ((0 == strncmp( inst->buffer,
|
|
|
|
- cmd->cmdAlias,
|
|
|
|
- cmdLen))
|
|
|
|
- && (cmdLen == strlen(cmd->cmdAlias))))
|
|
|
|
|
|
+ tempString = &inst->buffer[inst->lastNewlineIdx];
|
|
|
|
+ cmdLen = inst->inputCount - inst->lastNewlineIdx;
|
|
|
|
+
|
|
|
|
+ /** -# skip newline characters before comparison */
|
|
|
|
+ while(('\n' == *tempString) || ('\r' == *tempString))
|
|
{
|
|
{
|
|
- inst->write("\r\n", 2u);
|
|
|
|
|
|
+ tempString ++;
|
|
|
|
+ cmdLen --;
|
|
|
|
+ }
|
|
|
|
|
|
- cmdExecuted = 1u;
|
|
|
|
- cmd->cmdFct(inst, inst->buffer, inst->inputCount);
|
|
|
|
- cmd = NULL;
|
|
|
|
|
|
+ if( (inst->hereLength == cmdLen)
|
|
|
|
+ && (0 == strncmp( inst->hereDelimiter,
|
|
|
|
+ tempString,
|
|
|
|
+ inst->hereLength)))
|
|
|
|
+ {
|
|
|
|
+ inst->inputCount = inst->lastNewlineIdx;
|
|
|
|
+ inst->hereLength = 0u;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- cmd = cmd->next;
|
|
|
|
|
|
+ inst->lastNewlineIdx = inst->inputCount;
|
|
|
|
+ utils_insertChars(inst, data, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if ((cmdExecuted == 0u) && (inst->inputCount > 0))
|
|
|
|
|
|
+ if(0u == inst->hereLength)
|
|
{
|
|
{
|
|
- inst->buffer[inst->inputCount] = '\0';
|
|
|
|
- inst->write("\r\nCommand: ", 11u);
|
|
|
|
- inst->write(inst->buffer, inst->inputCount);
|
|
|
|
- inst->write(" not found", 10u);
|
|
|
|
|
|
+ cmd = inst->cmdList;
|
|
|
|
+ inst->buffer[inst->inputCount] = 0u;
|
|
|
|
+
|
|
|
|
+ /** -# store the current command and reset the history buffer */
|
|
|
|
+ inst->dirty = true;
|
|
|
|
+ history_storeCmd(inst);
|
|
|
|
+ history_reset(inst);
|
|
|
|
+
|
|
|
|
+ /** -# determine the cmd len (chars until first space or \0 is found */
|
|
|
|
+ cmdLen = 0u;
|
|
|
|
+ while( (cmdLen < inst->inputCount)
|
|
|
|
+ && (' ' != inst->buffer[cmdLen])
|
|
|
|
+ && ('\0' != inst->buffer[cmdLen]))
|
|
|
|
+ {
|
|
|
|
+ cmdLen ++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** -# search for a matching command */
|
|
|
|
+ while (NULL != cmd)
|
|
|
|
+ {
|
|
|
|
+ /** -# compare command string and length */
|
|
|
|
+ if ( ((0 == strncmp( inst->buffer,
|
|
|
|
+ cmd->cmd,
|
|
|
|
+ cmdLen))
|
|
|
|
+ && (cmdLen == strlen(cmd->cmd)))
|
|
|
|
+ || ((0 == strncmp( inst->buffer,
|
|
|
|
+ cmd->cmdAlias,
|
|
|
|
+ cmdLen))
|
|
|
|
+ && (cmdLen == strlen(cmd->cmdAlias))))
|
|
|
|
+ {
|
|
|
|
+ inst->write("\r\n", 2u);
|
|
|
|
+
|
|
|
|
+ cmdExecuted = 1u;
|
|
|
|
+ cmd->cmdFct(inst, inst->buffer, inst->inputCount);
|
|
|
|
+ cmd = NULL;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ cmd = cmd->next;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((cmdExecuted == 0u) && (inst->inputCount > 0))
|
|
|
|
+ {
|
|
|
|
+ inst->buffer[inst->inputCount] = '\0';
|
|
|
|
+ inst->write("\r\nCommand: ", 11u);
|
|
|
|
+ inst->write(inst->buffer, inst->inputCount);
|
|
|
|
+ inst->write(" not found", 10u);
|
|
|
|
+ }
|
|
|
|
+ utils_terminateInput(inst);
|
|
}
|
|
}
|
|
- utils_terminateInput(inst);
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
/** -# check for tabulator key - auto complete */
|
|
/** -# check for tabulator key - auto complete */
|
|
else if('\t' == *data)
|
|
else if('\t' == *data)
|