Fix umpnpmgr build
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandHelp.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 // ShellCommandHelp.cpp: implementation of the CShellCommandHelp class.
24 //
25 //////////////////////////////////////////////////////////////////////
26
27 #include "ph.h"
28 #include "ShellCommandHelp.h"
29
30 #define HELP_CMD _T("HELP")
31 #define HELP_CMD_SHORT_DESC HELP_CMD _T(" command provides help information about Registry Explorer commands.\n")
32
33 //////////////////////////////////////////////////////////////////////
34 // Construction/Destruction
35 //////////////////////////////////////////////////////////////////////
36
37 CShellCommandHelp::CShellCommandHelp(CShellCommandsLinkedList& rCommandsLinkedList):m_rCommandsLinkedList(rCommandsLinkedList)
38 {
39 }
40
41 CShellCommandHelp::~CShellCommandHelp()
42 {
43
44 }
45
46 BOOL CShellCommandHelp::Match(const TCHAR *pchCommand)
47 {
48 return _tcsicmp(pchCommand,HELP_CMD) == 0;
49 }
50
51 int CShellCommandHelp::Execute(CConsole &rConsole, CArgumentParser& rArguments)
52 {
53 const TCHAR *pchArg = rArguments.GetNextArgument();
54 CShellCommand *pCommand;
55 if (pchArg == NULL)
56 {
57 POSITION pos = m_rCommandsLinkedList.GetFirstCommandPosition();
58 while(pos)
59 {
60 pCommand = m_rCommandsLinkedList.GetNextCommand(pos);
61 rConsole.Write(pCommand->GetHelpShortDescriptionString());
62 }
63
64 return 0;
65 }
66
67 if (_tcsicmp(pchArg,_T("GPL")) == 0)
68 {
69 HRSRC hrcGPL;
70 HGLOBAL hGPL;
71 char *pchGPL;
72 DWORD dwSize;
73 if ((hrcGPL = FindResource(NULL, _T("GPL"), _T("LICENSE")))&&
74 (hGPL = LoadResource(NULL,hrcGPL))&&
75 (pchGPL = (char *)LockResource(hGPL))&&
76 (dwSize = SizeofResource(NULL,hrcGPL)))
77 {
78 // save last char
79 char pchSaved[2];
80 pchSaved[0] = pchGPL[dwSize-1];
81 pchSaved[1] = 0;
82
83 // make null-terminated string
84 pchGPL[dwSize-1] = 0;
85
86 // replace all non-printable chars except CR, LF and HTAB with spaces
87 for (DWORD i = 0; i < dwSize ; i++)
88 if ((!isprint(pchGPL[i]))&&(pchGPL[i] != '\r')&&(pchGPL[i] != '\n')&&(pchGPL[i] != '\t'))
89 pchGPL[i] = ' ';
90
91 rConsole.Write(pchGPL);
92 rConsole.Write(pchSaved);
93 }
94 else
95 {
96 rConsole.Write(_T("Internal error cannot load GPL.\n"));
97 }
98 return 0;
99 }
100
101 while (pchArg)
102 {
103 pCommand = m_rCommandsLinkedList.Match(pchArg);
104 if ((!pCommand)&&((_tcsicmp(pchArg,_T("/?")) == 0)||(_tcsicmp(pchArg,_T("-?")) == 0)))
105 pCommand = this;
106
107 if (pCommand)
108 {
109 rConsole.Write(pCommand->GetHelpString());
110 }
111 else
112 {
113 rConsole.Write(_T("HELP: Unknown command \""));
114 rConsole.Write(pchArg);
115 rConsole.Write(_T("\"\n"));
116 }
117
118 pchArg = rArguments.GetNextArgument();
119 }
120 return 0;
121 }
122
123 const TCHAR * CShellCommandHelp::GetHelpString()
124 {
125 return HELP_CMD_SHORT_DESC
126 _T("Syntax: ") HELP_CMD _T(" [<COMMAND>] [/?]\n")
127 _T(" COMMAND - Command for which help will be displayed.\n")
128 _T(" /? - This help.\n\n")
129 _T("Without parameters, command lists available commands.\n");
130 }
131
132 const TCHAR * CShellCommandHelp::GetHelpShortDescriptionString()
133 {
134 return HELP_CMD_SHORT_DESC;
135 }