298b875caf96245d770a8eff43c6ceacaf417da2
[reactos.git] / base / applications / network / net / main.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/main.c
5 * PURPOSE:
6 *
7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
8 */
9
10 #include "net.h"
11
12 #define MAX_BUFFER_SIZE 4096
13
14 typedef struct _COMMAND
15 {
16 WCHAR *name;
17 INT (*func)(INT, WCHAR**);
18 // VOID (*help)(INT, WCHAR**);
19 } COMMAND, *PCOMMAND;
20
21 COMMAND cmds[] =
22 {
23 {L"accounts", cmdAccounts},
24 {L"computer", unimplemented},
25 {L"config", cmdConfig},
26 {L"continue", cmdContinue},
27 {L"file", unimplemented},
28 {L"group", cmdGroup},
29 {L"help", cmdHelp},
30 {L"helpmsg", cmdHelpMsg},
31 {L"localgroup", cmdLocalGroup},
32 {L"name", unimplemented},
33 {L"pause", cmdPause},
34 {L"print", unimplemented},
35 {L"send", unimplemented},
36 {L"session", unimplemented},
37 {L"share", unimplemented},
38 {L"start", cmdStart},
39 {L"statistics", cmdStatistics},
40 {L"stop", cmdStop},
41 {L"time", unimplemented},
42 {L"use", cmdUse},
43 {L"user", cmdUser},
44 {L"view", unimplemented},
45 {NULL, NULL}
46 };
47
48
49
50 VOID
51 PrintPaddedResourceString(
52 UINT uID,
53 INT nPaddedLength)
54 {
55 INT nLength;
56
57 nLength = ConResPuts(StdOut, uID);
58 if (nLength < nPaddedLength)
59 PrintPadding(L' ', nPaddedLength - nLength);
60 }
61
62
63 VOID
64 PrintPadding(
65 WCHAR chr,
66 INT nPaddedLength)
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 }
77
78
79 VOID
80 ReadFromConsole(
81 LPWSTR lpInput,
82 DWORD dwLength,
83 BOOL bEcho)
84 {
85 DWORD dwOldMode;
86 DWORD dwRead = 0;
87 HANDLE hFile;
88 LPWSTR p;
89 PCHAR pBuf;
90
91 pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
92 ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
93 hFile = GetStdHandle(STD_INPUT_HANDLE);
94 GetConsoleMode(hFile, &dwOldMode);
95
96 SetConsoleMode(hFile, ENABLE_LINE_INPUT | (bEcho ? ENABLE_ECHO_INPUT : 0));
97
98 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
99
100 MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
101 HeapFree(GetProcessHeap(), 0, pBuf);
102
103 for (p = lpInput; *p; p++)
104 {
105 if (*p == L'\x0d')
106 {
107 *p = L'\0';
108 break;
109 }
110 }
111
112 SetConsoleMode(hFile, dwOldMode);
113 }
114
115
116 int wmain(int argc, WCHAR **argv)
117 {
118 PCOMMAND cmdptr;
119
120 /* Initialize the Console Standard Streams */
121 ConInitStdStreams();
122
123 if (argc < 2)
124 {
125 ConResPuts(StdOut, IDS_NET_SYNTAX);
126 return 1;
127 }
128
129 /* Scan the command table */
130 for (cmdptr = cmds; cmdptr->name; cmdptr++)
131 {
132 if (_wcsicmp(argv[1], cmdptr->name) == 0)
133 {
134 return cmdptr->func(argc, argv);
135 }
136 }
137
138 ConResPuts(StdOut, IDS_NET_SYNTAX);
139
140 return 1;
141 }
142
143 INT unimplemented(INT argc, WCHAR **argv)
144 {
145 ConPuts(StdOut, L"This command is not implemented yet\n");
146 return 1;
147 }