17: m_commands(commands),
19 m_lineBuffer{lineBuffer},
20 m_lineBufferSize{lineBufferSize},
22 m_argvSize{argvBufferSize}
24 std::fill_n(m_argv, m_argvSize,
nullptr);
34 if (m_lineBuffer[0] ==
'\0')
43 for (
const Command& command : m_commands)
45 if (command.name() == m_argv[0])
47 m_currentCommand = &command;
52 m_lastExitStatus = -1;
58 if (m_currentCommand ==
nullptr)
61 m_currentCommand->command(m_argc, m_argv, m_printer, m_lastExitStatus);
62 std::fill_n(m_argv, m_argvSize,
nullptr);
63 m_currentCommand =
nullptr;
67void Processor::parseLine()
70 int length = std::char_traits<char>::length(m_lineBuffer);
75 if (m_lineBuffer[pos] !=
'\t' && m_lineBuffer[pos] !=
' ' && m_lineBuffer[pos] !=
'\0')
76 m_argv[m_argc++] = &m_lineBuffer[pos];
78 for (; m_lineBuffer[pos] !=
'\t' && m_lineBuffer[pos] !=
' ' && m_lineBuffer[pos] !=
'\0'; pos++)
82 if (m_lineBuffer[pos] ==
'\t' || m_lineBuffer[pos] ==
' ')
83 m_lineBuffer[pos] =
'\0';
89void Processor::printError()
91 m_printer.dataWritten.connect(m_onQuotationMarkPrintedSlot);
92 m_printer.
print(
"\r\n\"");
95void Processor::onQuotationMarkPrinted()
97 m_printer.dataWritten.disconnect(m_onQuotationMarkPrintedSlot);
98 m_printer.dataWritten.connect(m_onNamePrintedSlot);
99 m_printer.
print(m_argv[0]);
101void Processor::onNamePrinted()
103 m_printer.dataWritten.disconnect(m_onNamePrintedSlot);
104 m_printer.dataWritten.connect(m_onDoneSlot);
105 m_printer.
print(
"\": command not found.\r\n");
107void Processor::onDone()
109 m_printer.dataWritten.disconnect(m_onDoneSlot);
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
LinkedList is an managed double linked list implementation.
Wrapper class for shell command. The user has to create object of this class for adding their functio...
Class for string related UART communication. Using this class outside of an esh-context can make sens...
void print(char character, size_t count)
Prints a single character count times.
Processor(const LinkedList< Command > &commands, Printer &printer, char lineBuffer[], size_t lineBufferSize, char **argvBuffer, size_t argvBufferSize)
Constructor.
void loadCommand()
Load a command for execution according to the current command line.
void execLoadedCommand()
Execute the currenty loaded command. Returns with no error if no command is loaded....