ReactOS  0.4.12-dev-14-gd0c8636
help.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS help utility
4  * FILE: base/applications/cmdutils/help/help.c
5  * PURPOSE: Provide help for command-line utilities
6  * PROGRAMMERS: Lee Schroeder (spaceseel at gmail dot com)
7  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8  */
9 
10 #include <stdlib.h>
11 
12 #define WIN32_NO_STATUS
13 #include <windef.h>
14 #include <winbase.h>
15 
16 #include <strsafe.h>
17 
18 #include <conutils.h>
19 
20 #include "help.h"
21 #include "resource.h"
22 
23 static BOOL
25 {
26  size_t i;
27  int res;
28 
29  /* Invalid command */
30  if (!Cmd) return FALSE;
31 
32  for (i = 0; i < ARRAYSIZE(InternalCommands); ++i)
33  {
34  res = _wcsicmp(InternalCommands[i], Cmd);
35  if (res == 0)
36  {
37  /* This is an internal command */
38  return TRUE;
39  }
40  else if (res > 0)
41  {
42  /*
43  * The internal commands list is sorted in alphabetical order.
44  * We can quit the loop immediately since the current internal
45  * command is lexically greater than the command to be tested.
46  */
47  break;
48  }
49  }
50 
51  /* Command not found */
52  return FALSE;
53 }
54 
55 int wmain(int argc, WCHAR* argv[])
56 {
58 
59  /* Initialize the Console Standard Streams */
61 
62  /*
63  * If the user hasn't asked for specific help,
64  * then print out the list of available commands.
65  */
66  if (argc <= 1)
67  {
70  return 0;
71  }
72 
73  /*
74  * Bad usage (too much options) or we use the /? switch.
75  * Display help for the HELP command.
76  */
77  if ((argc > 2) || (wcscmp(argv[1], L"/?") == 0))
78  {
80  return 0;
81  }
82 
83  /*
84  * If the command is not an internal one,
85  * display an information message and exit.
86  */
87  if (!IsInternalCommand(argv[1]))
88  {
89  ConResPrintf(StdOut, IDS_NO_ENTRY, argv[1]);
90  return 0;
91  }
92 
93  /*
94  * Run "<command> /?" in the current command processor.
95  */
96  StringCbPrintfW(CmdLine, sizeof(CmdLine), L"%ls /?", argv[1]);
97 
98  _flushall();
99  return _wsystem(CmdLine);
100 }
101 
102 /* EOF */
static int argc
Definition: ServiceArgs.c:12
char CmdLine[0x100]
Definition: mach.c:35
#define IDS_NO_ENTRY
Definition: resource.h:7
#define TRUE
Definition: types.h:120
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CMDLINE_LENGTH
Definition: help.h:12
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define IDS_USAGE
Definition: resource.h:3
static char ** argv
Definition: ServiceArgs.c:11
int wmain(int argc, WCHAR *argv[])
Definition: help.c:55
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_HELP1
Definition: resource.h:4
#define ConInitStdStreams()
Definition: stream.h:122
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_HELP2
Definition: resource.h:5
LPCWSTR InternalCommands[]
Definition: help.h:18
_CRTIMP int __cdecl _wsystem(_In_opt_z_ const wchar_t *_Command)
static BOOL IsInternalCommand(PCWSTR Cmd)
Definition: help.c:24
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
Definition: sacdrv.h:278
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_opt_ _CRTIMP int __cdecl _flushall(void)
Definition: file.c:893
GLuint res
Definition: glext.h:9613
#define StdOut
Definition: stream.h:76
const uint16_t * PCWSTR
Definition: typedefs.h:55
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)