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:
|
|
|
|
|
|
|
|
void cCommandOutputCallback::Out(const char * a_Fmt, ...)
|
|
|
|
{
|
|
|
|
AString Output;
|
2014-01-16 02:34:10 -05:00
|
|
|
va_list args;
|
2013-07-29 07:13:03 -04:00
|
|
|
va_start(args, a_Fmt);
|
2014-01-16 02:34:10 -05:00
|
|
|
AppendVPrintf(Output, a_Fmt, args);
|
2013-07-29 07:13:03 -04:00
|
|
|
va_end(args);
|
|
|
|
Output.append("\n");
|
|
|
|
Out(Output);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-07-29 07:13:03 -04:00
|
|
|
// cLogCommandOutputCallback:
|
|
|
|
|
|
|
|
void cLogCommandOutputCallback::Out(const AString & a_Text)
|
|
|
|
{
|
|
|
|
m_Buffer.append(a_Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cLogCommandOutputCallback::Finished(void)
|
|
|
|
{
|
|
|
|
// Log each line separately:
|
|
|
|
size_t len = m_Buffer.length();
|
|
|
|
size_t last = 0;
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
switch (m_Buffer[i])
|
|
|
|
{
|
|
|
|
case '\n':
|
|
|
|
{
|
2014-03-14 09:11:49 -04:00
|
|
|
LOG("%s", m_Buffer.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)
|
|
|
|
{
|
2014-03-14 09:11:49 -04:00
|
|
|
LOG("%s", m_Buffer.substr(last).c_str());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the buffer for the next command output:
|
|
|
|
m_Buffer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|