ReactOS 0.4.15-dev-8417-gb6b82fe
netsh.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS NetSh
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Network Shell main file
5 * COPYRIGHT: Copyright 2023 Eric Kohl <eric.kohl@reactos.org>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include "precomp.h"
11
12#define NDEBUG
13#include <debug.h>
14
15/* FUNCTIONS ******************************************************************/
16
17BOOL
20{
21 FILE *script;
22 WCHAR tmp_string[MAX_STRING_SIZE];
23
24 /* Open the file for processing */
25 script = _wfopen(filename, L"r");
26 if (script == NULL)
27 {
29 return FALSE;
30 }
31
32 /* Read and process the script */
33 while (fgetws(tmp_string, MAX_STRING_SIZE, script) != NULL)
34 {
35 if (InterpretScript(tmp_string) == FALSE)
36 {
38 return FALSE;
39 }
40 }
41
42 /* Close the file */
44
45 return TRUE;
46}
47
48/*
49 * wmain():
50 * Main entry point of the application.
51 */
52int
54 _In_ int argc,
55 _In_ const LPWSTR argv[])
56{
57 LPCWSTR tmpBuffer = NULL;
59 int index;
60 int result = EXIT_SUCCESS;
61
62 DPRINT("main()\n");
63
64 /* Initialize the Console Standard Streams */
66
67 /* FIXME: Init code goes here */
70
71 if (argc < 2)
72 {
73 /* If there are no command arguments, then go straight to the interpreter */
75 }
76 else
77 {
78 /* If there are command arguments, then process them */
79 for (index = 1; index < argc; index++)
80 {
81 if ((argv[index][0] == '/')||
82 (argv[index][0] == '-'))
83 {
84 tmpBuffer = argv[index] + 1;
85 }
86 else
87 {
88 if (pszFileName != NULL)
89 {
92 goto done;
93 }
94
95 /* Run a command from the command line */
98 goto done;
99 }
100
101 if (_wcsicmp(tmpBuffer, L"?") == 0)
102 {
103 /* Help option */
106 goto done;
107 }
108 else if (_wcsicmp(tmpBuffer, L"a") == 0)
109 {
110 /* Aliasfile option */
111 if ((index + 1) < argc)
112 {
113 index++;
114 ConPuts(StdOut, L"\nThe -a option is not implemented yet\n");
115// aliasfile = argv[index];
116 }
117 else
118 {
121 }
122 }
123 else if (_wcsicmp(tmpBuffer, L"c") == 0)
124 {
125 /* Context option */
126 if ((index + 1) < argc)
127 {
128 index++;
129 ConPuts(StdOut, L"\nThe -c option is not implemented yet\n");
130// context = argv[index];
131 }
132 else
133 {
136 }
137 }
138 else if (_wcsicmp(tmpBuffer, L"f") == 0)
139 {
140 /* File option */
141 if ((index + 1) < argc)
142 {
143 index++;
145 }
146 else
147 {
150 }
151 }
152 else if (_wcsicmp(tmpBuffer, L"r") == 0)
153 {
154 /* Remote option */
155 if ((index + 1) < argc)
156 {
157 index++;
158 ConPuts(StdOut, L"\nThe -r option is not implemented yet\n");
159// remote = argv[index];
160 }
161 else
162 {
165 }
166 }
167 else
168 {
169 /* Invalid command */
172 goto done;
173 }
174 }
175
176 /* Now we process the filename if it exists */
177 if (pszFileName != NULL)
178 {
180 {
182 goto done;
183 }
184 }
185 }
186
187done:
188 /* FIXME: Cleanup code goes here */
190
191 return result;
192}
193
194
195DWORD
196WINAPI
199 _In_ LPCWSTR pwcArg,
200 _In_ DWORD dwNumArg,
201 _In_ const TOKEN_VALUE *pEnumTable,
202 _Out_ PDWORD pdwValue)
203{
204 DPRINT1("MatchEnumTag()\n");
205 return 0;
206}
207
208BOOL
209WINAPI
211 _In_ LPCWSTR pwszUserToken,
212 _In_ LPCWSTR pwszCmdToken)
213{
214 DPRINT1("MatchToken %S %S\n", pwszUserToken, pwszCmdToken);
215 return (wcsicmp(pwszUserToken, pwszCmdToken) == 0) ? TRUE : FALSE;
216}
217
218DWORD
219CDECL
222 _In_ DWORD dwErrId,
223 ...)
224{
225 DPRINT1("PrintError()\n");
226 return 1;
227}
228
229DWORD
230CDECL
233 _In_ DWORD dwMsgId,
234 ...)
235{
236 DPRINT1("PrintMessageFromModule()\n");
237 return 1;
238}
239
240DWORD
241CDECL
243 _In_ LPCWSTR pwszFormat,
244 ...)
245{
246 INT Length;
247 va_list ap;
248
249 va_start(ap, pwszFormat);
250 Length = ConPrintf(StdOut, pwszFormat);
251 va_end(ap);
252
253 return Length;
254}
static int argc
Definition: ServiceArgs.c:12
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
BOOL InterpretCommand(_In_ LPWSTR *argv, _In_ DWORD dwArgCount)
Definition: interpreter.c:18
VOID InterpretInteractive(VOID)
Definition: interpreter.c:188
BOOL InterpretScript(_In_ LPWSTR pszInputLine)
Definition: interpreter.c:150
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define index(s, c)
Definition: various.h:29
BOOL CreateRootContext(VOID)
Definition: context.c:282
#define MAX_STRING_SIZE
Definition: precomp.h:34
#define IDS_OPEN_FAILED
Definition: resource.h:15
#define IDS_INVALID_COMMAND
Definition: resource.h:14
#define IDS_APP_USAGE
Definition: resource.h:12
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HMODULE hModule
Definition: animate.c:44
#define CDECL
Definition: compat.h:29
#define wcsicmp
Definition: compat.h:15
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint index
Definition: glext.h:6031
GLuint64EXT * result
Definition: glext.h:11304
VOID LoadHelpers(VOID)
Definition: helper.c:241
VOID UnloadHelpers(VOID)
Definition: helper.c:318
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:137
#define EXIT_FAILURE
Definition: jerror.c:33
#define argv
Definition: mplay32.c:18
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
script
Definition: msipriv.h:383
DWORD WINAPI MatchEnumTag(_In_ HANDLE hModule, _In_ LPCWSTR pwcArg, _In_ DWORD dwNumArg, _In_ const TOKEN_VALUE *pEnumTable, _Out_ PDWORD pdwValue)
Definition: netsh.c:197
DWORD CDECL PrintError(_In_opt_ HANDLE hModule, _In_ DWORD dwErrId,...)
Definition: netsh.c:220
DWORD CDECL PrintMessage(_In_ LPCWSTR pwszFormat,...)
Definition: netsh.c:242
BOOL WINAPI MatchToken(_In_ LPCWSTR pwszUserToken, _In_ LPCWSTR pwszCmdToken)
Definition: netsh.c:210
BOOL RunScript(_In_ LPCWSTR filename)
Definition: netsh.c:18
DWORD CDECL PrintMessageFromModule(_In_ HANDLE hModule, _In_ DWORD dwMsgId,...)
Definition: netsh.c:231
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
DWORD * PDWORD
Definition: pedump.c:68
int wmain()
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define DPRINT
Definition: sndvol32.h:73
int32_t INT
Definition: typedefs.h:58
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44
#define WINAPI
Definition: msvc.h:6
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185