Remove the unneeded $Id$ blabla from the source code.
[reactos.git] / rosapps / applications / sysutils / regexpl / Prompt.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 // prompt for Registry Explorer
23
24 #include "ph.h"
25 #include "Prompt.h"
26
27 #define ESCAPE_CHAR _T("\\")
28 #define CURRENT_PATH_ALIAS_CHAR _T("w")
29 #define CURRENT_PATH_ALIAS ESCAPE_CHAR CURRENT_PATH_ALIAS_CHAR
30 #define DEFAULT_PROMPT CURRENT_PATH_ALIAS _T("\n# ")
31
32 CPrompt::CPrompt(CRegistryTree& rTree, HRESULT& rhr):m_rTree(rTree)
33 {
34 m_pszPrompt = new (std::nothrow) TCHAR[_tcslen(DEFAULT_PROMPT)+1];
35 if (!m_pszPrompt)
36 {
37 rhr = E_OUTOFMEMORY;
38 return;
39 }
40
41 _tcscpy(m_pszPrompt,DEFAULT_PROMPT);
42 }
43
44 HRESULT CPrompt::SetPrompt(LPCTSTR pszPrompt)
45 {
46 if (!pszPrompt)
47 {
48 ASSERT(FALSE);
49 return E_UNEXPECTED;
50 }
51
52 m_pszPrompt = new (std::nothrow) TCHAR[_tcslen(pszPrompt)+1];
53 if (!m_pszPrompt)
54 return E_OUTOFMEMORY;
55
56 _tcscpy(m_pszPrompt,pszPrompt);
57
58 return S_OK;
59 }
60
61 CPrompt::~CPrompt()
62 {
63 if (m_pszPrompt)
64 delete[] m_pszPrompt;
65 }
66
67 void CPrompt::ShowPrompt(CConsole &rConsole)
68 {
69 TCHAR *pch = m_pszPrompt;
70 TCHAR Buffer[2] = " ";
71
72 const TCHAR *pszCurrentPath;
73
74 while (*pch)
75 {
76 if (_tcsncmp(pch,CURRENT_PATH_ALIAS,_tcslen(CURRENT_PATH_ALIAS)) == 0)
77 {
78 pszCurrentPath = m_rTree.GetCurrentPath();
79 rConsole.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)"));
80 pch += _tcslen(CURRENT_PATH_ALIAS);
81 }
82 else
83 {
84 Buffer[0] = *pch++;
85 rConsole.Write(Buffer);
86 }
87 }
88 }
89
90 LPCTSTR CPrompt::GetDefaultPrompt()
91 {
92 return DEFAULT_PROMPT;
93 }