2 * regexpl - Console Registry Explorer
4 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
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.
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.
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.
22 // ShellCommandsLinkedList.cpp: implementation of the CShellCommandsLinkedList class.
24 //////////////////////////////////////////////////////////////////////
27 #include "ShellCommandsLinkedList.h"
29 //////////////////////////////////////////////////////////////////////
30 // Construction/Destruction
31 //////////////////////////////////////////////////////////////////////
33 CShellCommandsLinkedList::CShellCommandsLinkedList(CConsole
& rConsole
):m_rConsole(rConsole
)
38 CShellCommandsLinkedList::~CShellCommandsLinkedList()
42 void CShellCommandsLinkedList::AddCommand(CShellCommand
*pCommand
)
45 SNode
*pNewNode
= new (std::nothrow
) SNode
;
49 pNewNode
->m_pData
= pCommand
;
51 // add new node to the end
54 SNode
*pLastNode
= m_pRoot
;
56 while (pLastNode
->m_pNext
)
57 pLastNode
= pLastNode
->m_pNext
;
59 pLastNode
->m_pNext
= pNewNode
;
67 int CShellCommandsLinkedList::Execute(CArgumentParser
& rArgumentParser
, int& nReturnValue
)
69 rArgumentParser
.ResetArgumentIteration();
71 const TCHAR
*pchCommand
= rArgumentParser
.GetNextArgument();
73 if (pchCommand
== NULL
) // empty command line
78 SNode
*pNode
= m_pRoot
;
83 if (pNode
->m_pData
->Match(pchCommand
))
85 nReturnValue
= pNode
->m_pData
->Execute(m_rConsole
,rArgumentParser
);
88 pNode
= pNode
->m_pNext
;
94 CShellCommand
* CShellCommandsLinkedList::Match(const TCHAR
* pchCommand
)
96 SNode
*pNode
= m_pRoot
;
100 if (pNode
->m_pData
->Match(pchCommand
))
101 return pNode
->m_pData
;
102 pNode
= pNode
->m_pNext
;
108 POSITION
CShellCommandsLinkedList::GetFirstCommandPosition()
110 return (POSITION
)m_pRoot
;
113 CShellCommand
* CShellCommandsLinkedList::GetNextCommand(POSITION
& rPos
)
115 CShellCommand
* pCommand
= ((SNode
*)rPos
)->m_pData
;
116 rPos
= (POSITION
)(((SNode
*)rPos
)->m_pNext
);