1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS net command
4  * FILE:            base/applications/network/net/cmdHelpMsg.c
5  * PURPOSE:
6  *
7  * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
8  */
9 
10 #include "net.h"
11 
12 #include <stdlib.h>
13 
14 INT cmdHelpMsg(INT argc, WCHAR **argv)
15 {
16     INT i;
17     LONG errNum;
18     PWSTR endptr;
19     PWSTR pBuffer;
20     PWSTR pInserts[10] = {L"***", L"***", L"***", L"***",
21                           L"***", L"***", L"***", L"***",
22                           L"***", NULL};
23 
24     if (argc < 3)
25     {
26         ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
27         PrintNetMessage(MSG_HELPMSG_SYNTAX);
28         return 1;
29     }
30 
31     for (i = 2; i < argc; i++)
32     {
33         if (_wcsicmp(argv[i], L"/help") == 0)
34         {
35             ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
36             PrintNetMessage(MSG_HELPMSG_SYNTAX);
37             PrintNetMessage(MSG_HELPMSG_HELP);
38             return 1;
39         }
40     }
41 
42     errNum = wcstol(argv[2], &endptr, 10);
43     if (*endptr != 0)
44     {
45         ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
46         PrintNetMessage(MSG_HELPMSG_SYNTAX);
47         return 1;
48     }
49 
50     if (errNum >= MIN_LANMAN_MESSAGE_ID && errNum <= MAX_LANMAN_MESSAGE_ID)
51     {
52         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE |
53                        FORMAT_MESSAGE_ARGUMENT_ARRAY,
54                        hModuleNetMsg,
55                        errNum,
56                        LANG_USER_DEFAULT,
57                        (LPWSTR)&pBuffer,
58                        0,
59                        (va_list *)pInserts);
60         if (pBuffer)
61         {
62             ConPrintf(StdOut, L"\n%s\n", pBuffer);
63             LocalFree(pBuffer);
64         }
65         else
66         {
67             PrintErrorMessage(3871);
68         }
69     }
70     else
71     {
72         /* Retrieve the message string without appending extra newlines */
73         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
74                        FORMAT_MESSAGE_ARGUMENT_ARRAY,
75                        NULL,
76                        errNum,
77                        LANG_USER_DEFAULT,
78                        (LPWSTR)&pBuffer,
79                        0,
80                        (va_list *)pInserts);
81         if (pBuffer)
82         {
83             ConPrintf(StdOut, L"\n%s\n", pBuffer);
84             LocalFree(pBuffer);
85         }
86         else
87         {
88             PrintErrorMessage(3871);
89         }
90     }
91 
92     return 0;
93 }
94 
95 /* EOF */
96 
97