ReactOS  0.4.13-dev-259-g5ca9c9c
Prompt.cpp
Go to the documentation of this file.
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 
42 }
43 
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 
62 {
63  if (m_pszPrompt)
64  delete[] m_pszPrompt;
65 }
66 
68 {
70  TCHAR Buffer[2] = " ";
71 
72  const TCHAR *pszCurrentPath;
73 
74  while (*pch)
75  {
77  {
78  pszCurrentPath = m_rTree.GetCurrentPath();
79  rConsole.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)"));
81  }
82  else
83  {
84  Buffer[0] = *pch++;
85  rConsole.Write(Buffer);
86  }
87  }
88 }
89 
91 {
92  return DEFAULT_PROMPT;
93 }
HRESULT SetPrompt(LPCTSTR pszPrompt)
Definition: Prompt.cpp:44
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define DEFAULT_PROMPT
Definition: Prompt.cpp:30
void ShowPrompt(CConsole &rConsole)
Definition: Prompt.cpp:67
const TCHAR * GetCurrentPath() const
LPTSTR m_pszPrompt
Definition: Prompt.h:18
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
CPrompt(CRegistryTree &rTree, HRESULT &rhr)
Definition: Prompt.cpp:32
#define pch(ap)
Definition: match.c:418
#define CURRENT_PATH_ALIAS
Definition: Prompt.cpp:29
CRegistryTree & m_rTree
Definition: Prompt.h:17
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
static LPCTSTR GetDefaultPrompt()
Definition: Prompt.cpp:90
~CPrompt()
Definition: Prompt.cpp:61
Definition: bufpool.h:45
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
LONG HRESULT
Definition: typedefs.h:77
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define S_OK
Definition: intsafe.h:59
BOOL Write(const TCHAR *p, DWORD dwChars=0)
Definition: Console.cpp:90
#define E_UNEXPECTED
Definition: winerror.h:2456
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9