forked from brock7/DataMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.cpp
97 lines (83 loc) · 1.52 KB
/
Command.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Command.cpp: implementation of the CCommand class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Command.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CmdMapEntry CCommand::_CmdMapEntry[] = {0, 0};
CCommand::CCommand()
{
m_szCmd[0x0] = '\0';
m_nParamCount = 0;
}
CCommand::~CCommand()
{
}
CmdMapEntry* CCommand::GetCommandMap()
{
return NULL;
}
int CCommand::OutputInfor(LPCTSTR pszFormat, ...)
{
return 0;
}
BOOL CCommand::Parse(LPCTSTR lpstr)
{
TCHAR* pbuf = m_szCmd;
const TCHAR* c = lpstr;
BOOL bOverFlag = TRUE;
m_nParamCount = 0;
while (*c)
{
if (*c == _T('\x020'))
{
*pbuf = _T('\0');
bOverFlag = TRUE;
}
else
{
if (bOverFlag)
{
m_arParam[m_nParamCount] = pbuf;
m_nParamCount ++;
bOverFlag = FALSE;
}
*pbuf = *c;
}
c++;
pbuf++;
}
*pbuf = _T('\0');
return TRUE;
}
LPCTSTR CCommand::GetParam(int nIndex)
{
return m_arParam[nIndex];
}
LPCTSTR CCommand::GetCmd()
{
if (m_nParamCount <= 0)
return NULL;
return m_arParam[0];
}
int CCommand::GetParamCount()
{
return m_nParamCount;
}
BOOL CCommand::Run()
{
CmdMapEntry* pMap = GetCommandMap();
if (pMap == NULL)
return FALSE;
while(pMap->lpCmd != NULL && pMap->pf != NULL)
{
if (lstrcmpi(pMap->lpCmd , GetCmd()) == 0) {
_XTrace(_T("'%s' Will run\n"), pMap->lpCmd);
return (this->*pMap->pf)();
}
pMap ++;
}
return FALSE;
}