2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// CommandOutput.cpp
|
|
|
|
|
|
|
|
// Implements the various classes that process command output
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "CommandOutput.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-07-29 07:13:03 -04:00
|
|
|
// cCommandOutputCallback:
|
|
|
|
|
2020-05-04 14:21:48 -04:00
|
|
|
void cCommandOutputCallback::vOut(const char * a_Fmt, fmt::printf_args a_ArgList)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-05-04 14:21:48 -04:00
|
|
|
AString Output = ::vPrintf(a_Fmt, a_ArgList);
|
2013-07-29 07:13:03 -04:00
|
|
|
Output.append("\n");
|
|
|
|
Out(Output);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-05-10 16:51:16 -04:00
|
|
|
// cStringAccumCommandOutputCallback:
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2015-05-10 16:51:16 -04:00
|
|
|
void cStringAccumCommandOutputCallback::Out(const AString & a_Text)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2015-05-10 16:51:16 -04:00
|
|
|
m_Accum.append(a_Text);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-10 16:51:16 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cLogCommandOutputCallback:
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cLogCommandOutputCallback::Finished(void)
|
|
|
|
{
|
|
|
|
// Log each line separately:
|
2015-05-10 16:51:16 -04:00
|
|
|
size_t len = m_Accum.length();
|
2013-07-29 07:13:03 -04:00
|
|
|
size_t last = 0;
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
2015-05-10 16:51:16 -04:00
|
|
|
switch (m_Accum[i])
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
case '\n':
|
|
|
|
{
|
2015-05-10 16:51:16 -04:00
|
|
|
LOG("%s", m_Accum.substr(last, i - last).c_str());
|
2013-07-29 07:13:03 -04:00
|
|
|
last = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for i - m_Buffer[]
|
|
|
|
if (last < len)
|
|
|
|
{
|
2015-05-10 16:51:16 -04:00
|
|
|
LOG("%s", m_Accum.substr(last).c_str());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Clear the buffer for the next command output:
|
2015-05-10 16:51:16 -04:00
|
|
|
m_Accum.clear();
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|