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
);
85 WCHAR szErrorBuffer
[16];
87 PWSTR pErrorInserts
[2] = {NULL
, NULL
};
89 if (dwError
>= MIN_LANMAN_MESSAGE_ID
&& dwError
<= MAX_LANMAN_MESSAGE_ID
)
91 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
92 FORMAT_MESSAGE_IGNORE_INSERTS
,
101 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
108 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|
109 FORMAT_MESSAGE_IGNORE_INSERTS
,
118 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
124 if (dwError
!= ERROR_SUCCESS
)
126 /* Format insert for the 3514 message */
127 swprintf(szErrorBuffer
, L
"%lu", dwError
);
128 pErrorInserts
[0] = szErrorBuffer
;
130 /* Format and print the 3514 message */
131 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
132 FORMAT_MESSAGE_ARGUMENT_ARRAY
,
138 (va_list *)pErrorInserts
);
141 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
155 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
156 FORMAT_MESSAGE_FROM_HMODULE
|
157 FORMAT_MESSAGE_IGNORE_INSERTS
,
158 GetModuleHandleW(NULL
),
166 ConPuts(StdOut
, pBuffer
);
167 ConPuts(StdOut
, L
"\n");
186 pBuf
= HeapAlloc(GetProcessHeap(), 0, dwLength
- 1);
187 ZeroMemory(lpInput
, dwLength
* sizeof(WCHAR
));
188 hFile
= GetStdHandle(STD_INPUT_HANDLE
);
189 GetConsoleMode(hFile
, &dwOldMode
);
191 SetConsoleMode(hFile
, ENABLE_LINE_INPUT
| (bEcho
? ENABLE_ECHO_INPUT
: 0));
193 ReadFile(hFile
, (PVOID
)pBuf
, dwLength
- 1, &dwRead
, NULL
);
195 MultiByteToWideChar(CP_OEMCP
, 0, pBuf
, dwRead
, lpInput
, dwLength
- 1);
196 HeapFree(GetProcessHeap(), 0, pBuf
);
198 for (p
= lpInput
; *p
; p
++)
207 SetConsoleMode(hFile
, dwOldMode
);
211 int wmain(int argc
, WCHAR
**argv
)
213 WCHAR szDllBuffer
[MAX_PATH
];
218 /* Initialize the Console Standard Streams */
221 /* Load netmsg.dll */
222 GetSystemDirectoryW(szDllBuffer
, ARRAYSIZE(szDllBuffer
));
223 wcscat(szDllBuffer
, L
"\\netmsg.dll");
225 hModuleNetMsg
= LoadLibrary(szDllBuffer
);
226 if (hModuleNetMsg
== NULL
)
228 ConPrintf(StdErr
, L
"Failed to load netmsg.dll\n");
238 /* Scan the command table */
239 for (cmdptr
= cmds
; cmdptr
->name
; cmdptr
++)
241 if (_wcsicmp(argv
[1], cmdptr
->name
) == 0)
243 nResult
= cmdptr
->func(argc
, argv
);
252 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
253 PrintNetMessage(MSG_NET_SYNTAX
);
256 if (hModuleNetMsg
!= NULL
)
257 FreeLibrary(hModuleNetMsg
);
262 INT
unimplemented(INT argc
, WCHAR
**argv
)
264 ConPuts(StdOut
, L
"This command is not implemented yet\n");