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", unimplemented
},
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
"time", unimplemented
},
44 {L
"view", unimplemented
},
48 HMODULE hModuleNetMsg
= NULL
;
52 PrintPaddedResourceString(
58 nLength
= ConResPuts(StdOut
, uID
);
59 if (nLength
< nPaddedLength
)
60 PrintPadding(L
' ', nPaddedLength
- nLength
);
70 WCHAR szMsgBuffer
[MAX_BUFFER_SIZE
];
72 for (i
= 0; i
< nPaddedLength
; i
++)
74 szMsgBuffer
[nPaddedLength
] = UNICODE_NULL
;
76 ConPuts(StdOut
, szMsgBuffer
);
84 WCHAR szErrorBuffer
[16];
86 PWSTR pErrorInserts
[2] = {NULL
, NULL
};
88 if (dwError
>= MIN_LANMAN_MESSAGE_ID
&& dwError
<= MAX_LANMAN_MESSAGE_ID
)
90 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
91 FORMAT_MESSAGE_IGNORE_INSERTS
,
100 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
107 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|
108 FORMAT_MESSAGE_IGNORE_INSERTS
,
117 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
123 if (dwError
!= ERROR_SUCCESS
)
125 /* Format insert for the 3514 message */
126 swprintf(szErrorBuffer
, L
"%lu", dwError
);
127 pErrorInserts
[0] = szErrorBuffer
;
129 /* Format and print the 3514 message */
130 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
|
131 FORMAT_MESSAGE_ARGUMENT_ARRAY
,
137 (va_list *)pErrorInserts
);
140 ConPrintf(StdErr
, L
"%s\n", pBuffer
);
160 pBuf
= HeapAlloc(GetProcessHeap(), 0, dwLength
- 1);
161 ZeroMemory(lpInput
, dwLength
* sizeof(WCHAR
));
162 hFile
= GetStdHandle(STD_INPUT_HANDLE
);
163 GetConsoleMode(hFile
, &dwOldMode
);
165 SetConsoleMode(hFile
, ENABLE_LINE_INPUT
| (bEcho
? ENABLE_ECHO_INPUT
: 0));
167 ReadFile(hFile
, (PVOID
)pBuf
, dwLength
- 1, &dwRead
, NULL
);
169 MultiByteToWideChar(CP_OEMCP
, 0, pBuf
, dwRead
, lpInput
, dwLength
- 1);
170 HeapFree(GetProcessHeap(), 0, pBuf
);
172 for (p
= lpInput
; *p
; p
++)
181 SetConsoleMode(hFile
, dwOldMode
);
185 int wmain(int argc
, WCHAR
**argv
)
187 WCHAR szDllBuffer
[MAX_PATH
];
192 /* Initialize the Console Standard Streams */
195 /* Load netmsg.dll */
196 GetSystemDirectoryW(szDllBuffer
, ARRAYSIZE(szDllBuffer
));
197 wcscat(szDllBuffer
, L
"\\netmsg.dll");
199 hModuleNetMsg
= LoadLibrary(szDllBuffer
);
200 if (hModuleNetMsg
== NULL
)
202 ConPrintf(StdErr
, L
"Failed to load netmsg.dll\n");
212 /* Scan the command table */
213 for (cmdptr
= cmds
; cmdptr
->name
; cmdptr
++)
215 if (_wcsicmp(argv
[1], cmdptr
->name
) == 0)
217 nResult
= cmdptr
->func(argc
, argv
);
225 ConResPuts(StdOut
, IDS_NET_SYNTAX
);
227 if (hModuleNetMsg
!= NULL
)
228 FreeLibrary(hModuleNetMsg
);
233 INT
unimplemented(INT argc
, WCHAR
**argv
)
235 ConPuts(StdOut
, L
"This command is not implemented yet\n");