summaryrefslogtreecommitdiffstats
path: root/src/CommandOutput.cpp
blob: 48a695969852696b94083658e8ba0fbae73a016a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

// CommandOutput.cpp

// Implements the various classes that process command output

#include "Globals.h"
#include "CommandOutput.h"





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cCommandOutputCallback:

void cCommandOutputCallback::Out(const char * a_Fmt, ...)
{
	AString Output;
	va_list args, argsCopy;
	va_start(args, a_Fmt);
	va_start(argsCopy, a_Fmt);
	AppendVPrintf(Output, a_Fmt, args, argsCopy);
	va_end(argsCopy);
	va_end(args);
	Output.append("\n");
	Out(Output);
}





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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':
			{
				LOG(m_Buffer.substr(last, i - last).c_str());
				last = i + 1;
				break;
			}
		}
	}  // for i - m_Buffer[]
	if (last < len)
	{
		LOG(m_Buffer.substr(last).c_str());
	}
	
	// Clear the buffer for the next command output:
	m_Buffer.clear();
}