* Sync up to trunk head (r65095).
[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:
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", unimplemented},
26 {L"continue", cmdContinue},
27 {L"file", unimplemented},
28 {L"group", unimplemented},
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", unimplemented},
40 {L"stop", cmdStop},
41 {L"time", unimplemented},
42 {L"use", unimplemented},
43 {L"user", cmdUser},
44 {L"view", unimplemented},
45 {NULL, NULL}
46 };
47
48
49 VOID
50 PrintResourceString(
51 INT resID,
52 ...)
53 {
54 WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
55 WCHAR szOutBuffer[MAX_BUFFER_SIZE];
56 va_list arg_ptr;
57
58 va_start(arg_ptr, resID);
59 LoadStringW(GetModuleHandle(NULL), resID, szMsgBuffer, MAX_BUFFER_SIZE);
60 _vsnwprintf(szOutBuffer, MAX_BUFFER_SIZE, szMsgBuffer, arg_ptr);
61 va_end(arg_ptr);
62
63 WriteToConsole(szOutBuffer);
64 }
65
66
67 VOID
68 PrintToConsole(
69 LPWSTR lpFormat,
70 ...)
71 {
72 WCHAR szBuffer[MAX_BUFFER_SIZE];
73 va_list arg_ptr;
74
75 va_start(arg_ptr, lpFormat);
76 _vsnwprintf(szBuffer, MAX_BUFFER_SIZE, lpFormat, arg_ptr);
77 va_end(arg_ptr);
78
79 WriteToConsole(szBuffer);
80 }
81
82
83 VOID
84 WriteToConsole(
85 LPWSTR lpString)
86 {
87 CHAR szOemBuffer[MAX_BUFFER_SIZE * 2];
88 HANDLE hOutput;
89 DWORD dwLength;
90
91 dwLength = wcslen(lpString);
92
93 hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
94 if ((GetFileType(hOutput) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR)
95 {
96 WriteConsoleW(hOutput,
97 lpString,
98 dwLength,
99 &dwLength,
100 NULL);
101 }
102 else
103 {
104 dwLength = WideCharToMultiByte(CP_OEMCP,
105 0,
106 lpString,
107 dwLength,
108 szOemBuffer,
109 MAX_BUFFER_SIZE * 2,
110 NULL,
111 NULL);
112 WriteFile(hOutput,
113 szOemBuffer,
114 dwLength,
115 &dwLength,
116 NULL);
117 }
118 }
119
120
121 int wmain(int argc, WCHAR **argv)
122 {
123 PCOMMAND cmdptr;
124
125 if (argc < 2)
126 {
127 PrintResourceString(IDS_NET_SYNTAX);
128 return 1;
129 }
130
131 /* Scan the command table */
132 for (cmdptr = cmds; cmdptr->name; cmdptr++)
133 {
134 if (_wcsicmp(argv[1], cmdptr->name) == 0)
135 {
136 return cmdptr->func(argc, argv);
137 }
138 }
139
140 PrintResourceString(IDS_NET_SYNTAX);
141
142 return 1;
143 }
144
145 INT unimplemented(INT argc, WCHAR **argv)
146 {
147 puts("This command is not implemented yet");
148 return 1;
149 }