2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/main.c
7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
12 #define MAX_BUFFER_SIZE 4096
14 typedef struct _COMMAND
17 INT (*func
)(INT
, WCHAR
**);
18 // VOID (*help)(INT, WCHAR**);
23 {L
"accounts", cmdAccounts
},
24 {L
"computer", cmdComputer
},
25 {L
"config", cmdConfig
},
26 {L
"continue", cmdContinue
},
27 {L
"file", unimplemented
},
30 {L
"helpmsg", cmdHelpMsg
},
31 {L
"localgroup", cmdLocalGroup
},
32 {L
"name", unimplemented
},
34 {L
"print", unimplemented
},
35 {L
"send", unimplemented
},
36 {L
"session", unimplemented
},
37 {L
"share", unimplemented
},
39 {L
"statistics", cmdStatistics
},
41 {L
"syntax", cmdSyntax
},
42 {L
"time", unimplemented
},
45 {L
"view", unimplemented
},
49 HMODULE hModuleNetMsg
= NULL
;
53 PrintPaddedResourceString(
59 nLength
= ConResPuts(StdOut
, uID
);
60 if (nLength
< nPaddedLength
)
61 PrintPadding(L
' ', nPaddedLength
- nLength
);
71 WCHAR szMsgBuffer
[MAX_BUFFER_SIZE
];
73 for (i
= 0; i
< nPaddedLength
; i
++)
75 szMsgBuffer
[nPaddedLength
] = UNICODE_NULL
;
77 ConPuts(StdOut
, szMsgBuffer
);
89 va_start(args
, dwMessage
);
91 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
,
102 ConPuts(StdOut
, pBuffer
);
114 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
115 FORMAT_MESSAGE_IGNORE_INSERTS
,
124 ConPuts(StdOut
, pBuffer
);
132 PrintPaddedMessageString(
139 dwLength
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
140 FORMAT_MESSAGE_IGNORE_INSERTS
,
149 ConPuts(StdOut
, pBuffer
);
154 if (dwLength
< (DWORD
)nPaddedLength
)
155 PrintPadding(L
' ', (DWORD
)nPaddedLength
- dwLength
);
163 WCHAR szErrorBuffer
[16];
165 PWSTR pErrorInserts
[2] = {NULL
, NULL
};
167 if (dwError
>= MIN_LANMAN_MESSAGE_ID
&& dwError
<= MAX_LANMAN_MESSAGE_ID
)
169 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
170 FORMAT_MESSAGE_IGNORE_INSERTS
,
179 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
186 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|
187 FORMAT_MESSAGE_IGNORE_INSERTS
,
196 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
202 if (dwError
!= ERROR_SUCCESS
)
204 /* Format insert for the 3514 message */
205 swprintf(szErrorBuffer
, L
"%lu", dwError
);
206 pErrorInserts
[0] = szErrorBuffer
;
208 /* Format and print the 3514 message */
209 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
210 FORMAT_MESSAGE_ARGUMENT_ARRAY
,
216 (va_list *)pErrorInserts
);
219 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
233 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
234 FORMAT_MESSAGE_FROM_HMODULE
|
235 FORMAT_MESSAGE_IGNORE_INSERTS
,
236 GetModuleHandleW(NULL
),
244 ConPuts(StdOut
, pBuffer
);
245 ConPuts(StdOut
, L
"\n");
264 pBuf
= HeapAlloc(GetProcessHeap(), 0, dwLength
- 1);
265 ZeroMemory(lpInput
, dwLength
* sizeof(WCHAR
));
266 hFile
= GetStdHandle(STD_INPUT_HANDLE
);
267 GetConsoleMode(hFile
, &dwOldMode
);
269 SetConsoleMode(hFile
, ENABLE_LINE_INPUT
| (bEcho
? ENABLE_ECHO_INPUT
: 0));
271 ReadFile(hFile
, (PVOID
)pBuf
, dwLength
- 1, &dwRead
, NULL
);
273 MultiByteToWideChar(CP_OEMCP
, 0, pBuf
, dwRead
, lpInput
, dwLength
- 1);
274 HeapFree(GetProcessHeap(), 0, pBuf
);
276 for (p
= lpInput
; *p
; p
++)
285 SetConsoleMode(hFile
, dwOldMode
);
289 int wmain(int argc
, WCHAR
**argv
)
291 WCHAR szDllBuffer
[MAX_PATH
];
296 /* Initialize the Console Standard Streams */
299 /* Load netmsg.dll */
300 GetSystemDirectoryW(szDllBuffer
, ARRAYSIZE(szDllBuffer
));
301 wcscat(szDllBuffer
, L
"\\netmsg.dll");
303 hModuleNetMsg
= LoadLibrary(szDllBuffer
);
304 if (hModuleNetMsg
== NULL
)
306 ConPrintf(StdErr
, L
"Failed to load netmsg.dll\n");
316 /* Scan the command table */
317 for (cmdptr
= cmds
; cmdptr
->name
; cmdptr
++)
319 if (_wcsicmp(argv
[1], cmdptr
->name
) == 0)
321 nResult
= cmdptr
->func(argc
, argv
);
330 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
331 PrintNetMessage(MSG_NET_SYNTAX
);
334 if (hModuleNetMsg
!= NULL
)
335 FreeLibrary(hModuleNetMsg
);
340 INT
unimplemented(INT argc
, WCHAR
**argv
)
342 ConPuts(StdOut
, L
"This command is not implemented yet\n");