[REGEXPL]
[reactos.git] / rosapps / applications / sysutils / regexpl / Prompt.cpp
1 /* $Id$
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 // prompt for Registry Explorer
24
25 #include "ph.h"
26 #include "Prompt.h"
27
28 #define ESCAPE_CHAR _T("\\")
29 #define CURRENT_PATH_ALIAS_CHAR _T("w")
30 #define CURRENT_PATH_ALIAS ESCAPE_CHAR CURRENT_PATH_ALIAS_CHAR
31 #define DEFAULT_PROMPT CURRENT_PATH_ALIAS _T("\n# ")
32
33 CPrompt::CPrompt(CRegistryTree& rTree, HRESULT& rhr):m_rTree(rTree)
34 {
35 m_pszPrompt = new (std::nothrow) TCHAR[_tcslen(DEFAULT_PROMPT)+1];
36 if (!m_pszPrompt)
37 {
38 rhr = E_OUTOFMEMORY;
39 return;
40 }
41
42 _tcscpy(m_pszPrompt,DEFAULT_PROMPT);
43 }
44
45 HRESULT CPrompt::SetPrompt(LPCTSTR pszPrompt)
46 {
47 if (!pszPrompt)
48 {
49 ASSERT(FALSE);
50 return E_UNEXPECTED;
51 }
52
53 m_pszPrompt = new (std::nothrow) TCHAR[_tcslen(pszPrompt)+1];
54 if (!m_pszPrompt)
55 return E_OUTOFMEMORY;
56
57 _tcscpy(m_pszPrompt,pszPrompt);
58
59 return S_OK;
60 }
61
62 CPrompt::~CPrompt()
63 {
64 if (m_pszPrompt)
65 delete[] m_pszPrompt;
66 }
67
68 void CPrompt::ShowPrompt(CConsole &rConsole)
69 {
70 TCHAR *pch = m_pszPrompt;
71 TCHAR Buffer[2] = " ";
72
73 const TCHAR *pszCurrentPath;
74
75 while (*pch)
76 {
77 if (_tcsncmp(pch,CURRENT_PATH_ALIAS,_tcslen(CURRENT_PATH_ALIAS)) == 0)
78 {
79 pszCurrentPath = m_rTree.GetCurrentPath();
80 rConsole.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)"));
81 pch += _tcslen(CURRENT_PATH_ALIAS);
82 }
83 else
84 {
85 Buffer[0] = *pch++;
86 rConsole.Write(Buffer);
87 }
88 }
89 }
90
91 LPCTSTR CPrompt::GetDefaultPrompt()
92 {
93 return DEFAULT_PROMPT;
94 }