From 616e4d5242299c862e319316d782b94f5967ac39 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Mon, 16 Apr 2001 04:53:31 +0000 Subject: [PATCH] Prompt now supports customization. Implementation is based on customization string with escape sequences. The prompt currently recognizes only one sequence in the customization string, \w - the current path. svn path=/trunk/; revision=1799 --- rosapps/sysutils/regexpl/Prompt.cpp | 94 +++++++++++++++++++++++++++++ rosapps/sysutils/regexpl/Prompt.h | 21 +++++++ 2 files changed, 115 insertions(+) create mode 100644 rosapps/sysutils/regexpl/Prompt.cpp create mode 100644 rosapps/sysutils/regexpl/Prompt.h diff --git a/rosapps/sysutils/regexpl/Prompt.cpp b/rosapps/sysutils/regexpl/Prompt.cpp new file mode 100644 index 00000000000..5964e0202a6 --- /dev/null +++ b/rosapps/sysutils/regexpl/Prompt.cpp @@ -0,0 +1,94 @@ +/* $Id: Prompt.cpp,v 1.1 2001/04/16 04:53:31 narnaoud Exp $ + * + * regexpl - Console Registry Explorer + * + * Copyright (C) 2000,2001 Nedko Arnaoudov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +// prompt for Registry Explorer + +#include "ph.h" +#include "Prompt.h" + +#define ESCAPE_CHAR _T("\\") +#define CURRENT_PATH_ALIAS_CHAR _T("w") +#define CURRENT_PATH_ALIAS ESCAPE_CHAR CURRENT_PATH_ALIAS_CHAR +#define DEFAULT_PROMPT CURRENT_PATH_ALIAS _T("\n# ") + +CPrompt::CPrompt(CRegistryTree& rTree, HRESULT& rhr):m_rTree(rTree) +{ + m_pszPrompt = new TCHAR[_tcslen(DEFAULT_PROMPT)+1]; + if (!m_pszPrompt) + { + rhr = E_OUTOFMEMORY; + return; + } + + _tcscpy(m_pszPrompt,DEFAULT_PROMPT); +} + +HRESULT CPrompt::SetPrompt(LPCTSTR pszPrompt) +{ + if (!pszPrompt) + { + ASSERT(FALSE); + return E_UNEXPECTED; + } + + m_pszPrompt = new TCHAR[_tcslen(pszPrompt)+1]; + if (!m_pszPrompt) + return E_OUTOFMEMORY; + + _tcscpy(m_pszPrompt,pszPrompt); + + return S_OK; +} + +CPrompt::~CPrompt() +{ + if (m_pszPrompt) + delete m_pszPrompt; +} + +void CPrompt::ShowPrompt(CConsole &rConsole) +{ + TCHAR *pch = m_pszPrompt; + TCHAR Buffer[2] = " "; + + const TCHAR *pszCurrentPath; + + while (*pch) + { + if (_tcsncmp(pch,CURRENT_PATH_ALIAS,_tcslen(CURRENT_PATH_ALIAS)) == 0) + { + pszCurrentPath = m_rTree.GetCurrentPath(); + rConsole.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)")); + pch += _tcslen(CURRENT_PATH_ALIAS); + } + else + { + Buffer[0] = *pch++; + rConsole.Write(Buffer); + } + } +} + +LPCTSTR CPrompt::GetDefaultPrompt() +{ + return DEFAULT_PROMPT; +} diff --git a/rosapps/sysutils/regexpl/Prompt.h b/rosapps/sysutils/regexpl/Prompt.h new file mode 100644 index 00000000000..7565dc68aab --- /dev/null +++ b/rosapps/sysutils/regexpl/Prompt.h @@ -0,0 +1,21 @@ +#ifndef PROMPT_H__d2442d41_b6b3_47b5_8cb8_e6c597e570b9__INCLUDED +#define PROMPT_H__d2442d41_b6b3_47b5_8cb8_e6c597e570b9__INCLUDED + +#include "RegistryTree.h" +#include "Console.h" + +class CPrompt +{ +public: + CPrompt(CRegistryTree& rTree, HRESULT& rhr); + ~CPrompt(); + HRESULT SetPrompt(LPCTSTR pszPrompt); + void ShowPrompt(CConsole &rConsole); + static LPCTSTR GetDefaultPrompt(); + +private: + CRegistryTree& m_rTree; + LPTSTR m_pszPrompt; +}; + +#endif // #ifndef PROMPT_H__d2442d41_b6b3_47b5_8cb8_e6c597e570b9__INCLUDED