ReactOS  0.4.12-dev-14-gd0c8636
main.c File Reference
#include "net.h"
Include dependency graph for main.c:

Go to the source code of this file.

Classes

struct  _COMMAND
 

Macros

#define MAX_BUFFER_SIZE   4096
 

Typedefs

typedef struct _COMMAND COMMAND
 
typedef struct _COMMANDPCOMMAND
 

Functions

VOID PrintPaddedResourceString (UINT uID, INT nPaddedLength)
 
VOID PrintPadding (WCHAR chr, INT nPaddedLength)
 
VOID PrintErrorMessage (DWORD dwError)
 
VOID ReadFromConsole (LPWSTR lpInput, DWORD dwLength, BOOL bEcho)
 
int wmain (int argc, WCHAR **argv)
 
INT unimplemented (INT argc, WCHAR **argv)
 

Variables

COMMAND cmds []
 

Macro Definition Documentation

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   4096

Definition at line 12 of file main.c.

Referenced by PrintPadding().

Typedef Documentation

◆ COMMAND

◆ PCOMMAND

Function Documentation

◆ PrintErrorMessage()

VOID PrintErrorMessage ( DWORD  dwError)

Definition at line 80 of file main.c.

82 {
83  WCHAR szDllBuffer[MAX_PATH];
84  WCHAR szErrorBuffer[16];
85  HMODULE hMsgDll = NULL;
86  PWSTR pBuffer;
87  PWSTR pErrorInserts[2] = {NULL, NULL};
88 
89  /* Load netmsg.dll */
90  GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
91  wcscat(szDllBuffer, L"\\netmsg.dll");
92 
93  hMsgDll = LoadLibrary(szDllBuffer);
94  if (hMsgDll == NULL)
95  {
96  ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
97  return;
98  }
99 
100  if (dwError >= MIN_LANMAN_MESSAGE_ID && dwError <= MAX_LANMAN_MESSAGE_ID)
101  {
104  hMsgDll,
105  dwError,
107  (LPWSTR)&pBuffer,
108  0,
109  NULL);
110  if (pBuffer)
111  {
112  ConPrintf(StdErr, L"%s\n", pBuffer);
113  LocalFree(pBuffer);
114  pBuffer = NULL;
115  }
116  }
117  else
118  {
121  NULL,
122  dwError,
124  (LPWSTR)&pBuffer,
125  0,
126  NULL);
127  if (pBuffer)
128  {
129  ConPrintf(StdErr, L"%s\n", pBuffer);
130  LocalFree(pBuffer);
131  pBuffer = NULL;
132  }
133  }
134 
135  if (dwError != ERROR_SUCCESS)
136  {
137  /* Format insert for the 3514 message */
138  swprintf(szErrorBuffer, L"%lu", dwError);
139  pErrorInserts[0] = szErrorBuffer;
140 
141  /* Format and print the 3514 message */
144  hMsgDll,
145  3514,
147  (LPWSTR)&pBuffer,
148  0,
149  (va_list *)pErrorInserts);
150  if (pBuffer)
151  {
152  ConPrintf(StdErr, L"%s\n", pBuffer);
153  LocalFree(pBuffer);
154  pBuffer = NULL;
155  }
156  }
157 
158  FreeLibrary(hMsgDll);
159 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LoadLibrary
Definition: winbase.h:3676
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint16_t * PWSTR
Definition: typedefs.h:54
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define MIN_LANMAN_MESSAGE_ID
Definition: lmcons.h:10
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
char * va_list
Definition: acmsvcex.h:78
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
#define FreeLibrary(x)
Definition: compat.h:405
#define MAX_LANMAN_MESSAGE_ID
Definition: lmcons.h:11
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define StdErr
Definition: stream.h:77
static const WCHAR L[]
Definition: oid.c:1087
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

◆ PrintPaddedResourceString()

VOID PrintPaddedResourceString ( UINT  uID,
INT  nPaddedLength 
)

Definition at line 51 of file main.c.

Referenced by cmdAccounts(), DisplayGroup(), DisplayLocalGroup(), DisplayServerConfig(), DisplayServerStatistics(), DisplayUser(), DisplayWorkstationConfig(), and DisplayWorkstationStatistics().

54 {
55  INT nLength;
56 
57  nLength = ConResPuts(StdOut, uID);
58  if (nLength < nPaddedLength)
59  PrintPadding(L' ', nPaddedLength - nLength);
60 }
_In_ DWORD nLength
Definition: wincon.h:461
int32_t INT
Definition: typedefs.h:56
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:64
#define StdOut
Definition: stream.h:76

◆ PrintPadding()

VOID PrintPadding ( WCHAR  chr,
INT  nPaddedLength 
)

Definition at line 64 of file main.c.

Referenced by DisplayGroup(), DisplayLocalGroup(), DisplayUser(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateUsers(), and PrintPaddedResourceString().

67 {
68  INT i;
69  WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
70 
71  for (i = 0; i < nPaddedLength; i++)
72  szMsgBuffer[i] = chr;
73  szMsgBuffer[nPaddedLength] = UNICODE_NULL;
74 
75  ConPuts(StdOut, szMsgBuffer);
76 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
int32_t INT
Definition: typedefs.h:56
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define UNICODE_NULL
#define MAX_BUFFER_SIZE
Definition: main.c:12
int chr(char *serport)
Definition: gdblib.c:152
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76

◆ ReadFromConsole()

VOID ReadFromConsole ( LPWSTR  lpInput,
DWORD  dwLength,
BOOL  bEcho 
)

Definition at line 163 of file main.c.

Referenced by ReadPassword().

167 {
168  DWORD dwOldMode;
169  DWORD dwRead = 0;
170  HANDLE hFile;
171  LPWSTR p;
172  PCHAR pBuf;
173 
174  pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
175  ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
177  GetConsoleMode(hFile, &dwOldMode);
178 
180 
181  ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
182 
183  MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
184  HeapFree(GetProcessHeap(), 0, pBuf);
185 
186  for (p = lpInput; *p; p++)
187  {
188  if (*p == L'\x0d')
189  {
190  *p = L'\0';
191  break;
192  }
193  }
194 
195  SetConsoleMode(hFile, dwOldMode);
196 }
signed char * PCHAR
Definition: retypes.h:7
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
BOOL bEcho
Definition: batch.c:68
#define ZeroMemory
Definition: winbase.h:1635
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
smooth NULL
Definition: ftsmooth.c:416
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static DWORD DWORD * dwLength
Definition: fusion.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ENABLE_LINE_INPUT
Definition: wincon.h:76
static const WCHAR L[]
Definition: oid.c:1087
_In_ HANDLE hFile
Definition: mswsock.h:90
#define MultiByteToWideChar
Definition: compat.h:100
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define CP_OEMCP
Definition: winnls.h:219
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ unimplemented()

INT unimplemented ( INT  argc,
WCHAR **  argv 
)

Definition at line 226 of file main.c.

227 {
228  ConPuts(StdOut, L"This command is not implemented yet\n");
229  return 1;
230 }
static const WCHAR L[]
Definition: oid.c:1087
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76

◆ wmain()

int wmain ( int  argc,
WCHAR **  argv 
)

Definition at line 199 of file main.c.

200 {
201  PCOMMAND cmdptr;
202 
203  /* Initialize the Console Standard Streams */
205 
206  if (argc < 2)
207  {
209  return 1;
210  }
211 
212  /* Scan the command table */
213  for (cmdptr = cmds; cmdptr->name; cmdptr++)
214  {
215  if (_wcsicmp(argv[1], cmdptr->name) == 0)
216  {
217  return cmdptr->func(argc, argv);
218  }
219  }
220 
222 
223  return 1;
224 }
static int argc
Definition: ServiceArgs.c:12
COMMAND cmds[]
Definition: main.c:21
INT(* func)(INT, WCHAR **)
Definition: main.c:17
static char ** argv
Definition: ServiceArgs.c:11
#define ConInitStdStreams()
Definition: stream.h:122
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define IDS_NET_SYNTAX
Definition: resource.h:85
#define StdOut
Definition: stream.h:76
Definition: main.c:14
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
WCHAR * name
Definition: main.c:16

Variable Documentation

◆ cmds

COMMAND cmds[]
Initial value:
=
{
{L"accounts", cmdAccounts},
{L"computer", unimplemented},
{L"config", cmdConfig},
{L"continue", cmdContinue},
{L"file", unimplemented},
{L"group", cmdGroup},
{L"help", cmdHelp},
{L"helpmsg", cmdHelpMsg},
{L"localgroup", cmdLocalGroup},
{L"name", unimplemented},
{L"pause", cmdPause},
{L"print", unimplemented},
{L"send", unimplemented},
{L"session", unimplemented},
{L"share", unimplemented},
{L"start", cmdStart},
{L"statistics", cmdStatistics},
{L"stop", cmdStop},
{L"time", unimplemented},
{L"use", cmdUse},
{L"user", cmdUser},
{L"view", unimplemented},
}
INT unimplemented(INT argc, WCHAR **argv)
Definition: main.c:226
INT cmdStart(INT argc, WCHAR **argv)
Definition: cmdStart.c:163
INT cmdHelp(INT argc, WCHAR **argv)
Definition: help.c:12
INT cmdConfig(INT argc, WCHAR **argv)
Definition: cmdConfig.c:151
smooth NULL
Definition: ftsmooth.c:416
INT cmdHelpMsg(INT argc, WCHAR **argv)
Definition: cmdHelpMsg.c:14
INT cmdAccounts(INT argc, WCHAR **argv)
Definition: cmdAccounts.c:13
INT cmdContinue(INT argc, WCHAR **argv)
Definition: cmdContinue.c:12
static const WCHAR L[]
Definition: oid.c:1087
INT cmdUse(INT argc, WCHAR **argv)
Definition: cmdUse.c:102
INT cmdUser(INT argc, WCHAR **argv)
Definition: cmdUser.c:616
INT cmdStop(INT argc, WCHAR **argv)
Definition: cmdStop.c:12
INT cmdStatistics(INT argc, WCHAR **argv)
INT cmdLocalGroup(INT argc, WCHAR **argv)
INT cmdPause(INT argc, WCHAR **argv)
Definition: cmdPause.c:12
INT cmdGroup(INT argc, WCHAR **argv)
Definition: cmdGroup.c:154

Definition at line 21 of file main.c.

Referenced by DoCommand(), handle_edit_event(), help_cmdlist(), help_main(), test_ioctlsocket(), and test_OleCommandTarget().