Incorporate rosapps. 0.3.15 was branched somewhat incorrectly so rosapps is not synce...
[reactos.git] / modules / rosapps / applications / sysutils / regexpl / ShellCommandsLinkedList.cpp
1 /*
2 * regexpl - Console Registry Explorer
3 *
4 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22 // ShellCommandsLinkedList.cpp: implementation of the CShellCommandsLinkedList class.
23 //
24 //////////////////////////////////////////////////////////////////////
25
26 #include "ph.h"
27 #include "ShellCommandsLinkedList.h"
28
29 //////////////////////////////////////////////////////////////////////
30 // Construction/Destruction
31 //////////////////////////////////////////////////////////////////////
32
33 CShellCommandsLinkedList::CShellCommandsLinkedList(CConsole& rConsole):m_rConsole(rConsole)
34 {
35 m_pRoot = NULL;
36 }
37
38 CShellCommandsLinkedList::~CShellCommandsLinkedList()
39 {
40 }
41
42 void CShellCommandsLinkedList::AddCommand(CShellCommand *pCommand)
43 {
44 // Create new node
45 SNode *pNewNode = new (std::nothrow) SNode;
46 if (pNewNode == NULL)
47 return;
48
49 pNewNode->m_pData = pCommand;
50
51 // add new node to the end
52 if (m_pRoot)
53 {
54 SNode *pLastNode = m_pRoot;
55
56 while (pLastNode->m_pNext)
57 pLastNode = pLastNode->m_pNext;
58
59 pLastNode->m_pNext = pNewNode;
60 }
61 else
62 {
63 m_pRoot = pNewNode;
64 }
65 }
66
67 int CShellCommandsLinkedList::Execute(CArgumentParser& rArgumentParser, int& nReturnValue)
68 {
69 rArgumentParser.ResetArgumentIteration();
70
71 const TCHAR *pchCommand = rArgumentParser.GetNextArgument();
72
73 if (pchCommand == NULL) // empty command line
74 return -2;
75
76 int i = -1;
77
78 SNode *pNode = m_pRoot;
79
80 while(pNode)
81 {
82 i++;
83 if (pNode->m_pData->Match(pchCommand))
84 {
85 nReturnValue = pNode->m_pData->Execute(m_rConsole,rArgumentParser);
86 return i;
87 }
88 pNode = pNode->m_pNext;
89 }
90
91 return -1;
92 }
93
94 CShellCommand * CShellCommandsLinkedList::Match(const TCHAR * pchCommand)
95 {
96 SNode *pNode = m_pRoot;
97
98 while(pNode)
99 {
100 if (pNode->m_pData->Match(pchCommand))
101 return pNode->m_pData;
102 pNode = pNode->m_pNext;
103 }
104
105 return NULL;
106 }
107
108 POSITION CShellCommandsLinkedList::GetFirstCommandPosition()
109 {
110 return (POSITION)m_pRoot;
111 }
112
113 CShellCommand * CShellCommandsLinkedList::GetNextCommand(POSITION& rPos)
114 {
115 CShellCommand * pCommand = ((SNode *)rPos)->m_pData;
116 rPos = (POSITION)(((SNode *)rPos)->m_pNext);
117 return pCommand;
118 }
119