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         PrintMessageString(4381);
27         ConPuts(StdOut, L"\n");
28         PrintNetMessage(MSG_HELPMSG_SYNTAX);
29         return 1;
30     }
31 
32     for (i = 2; i < argc; i++)
33     {
34         if (_wcsicmp(argv[i], L"/help") == 0)
35         {
36             PrintMessageString(4381);
37             ConPuts(StdOut, L"\n");
38             PrintNetMessage(MSG_HELPMSG_SYNTAX);
39             PrintNetMessage(MSG_HELPMSG_HELP);
40             return 1;
41         }
42     }
43 
44     errNum = wcstol(argv[2], &endptr, 10);
45     if (*endptr != 0)
46     {
47         PrintMessageString(4381);
48         ConPuts(StdOut, L"\n");
49         PrintNetMessage(MSG_HELPMSG_SYNTAX);
50         return 1;
51     }
52 
53     if (errNum >= MIN_LANMAN_MESSAGE_ID && errNum <= MAX_LANMAN_MESSAGE_ID)
54     {
55         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE |
56                        FORMAT_MESSAGE_ARGUMENT_ARRAY,
57                        hModuleNetMsg,
58                        errNum,
59                        LANG_USER_DEFAULT,
60                        (LPWSTR)&pBuffer,
61                        0,
62                        (va_list *)pInserts);
63         if (pBuffer)
64         {
65             ConPrintf(StdOut, L"\n%s\n", pBuffer);
66             LocalFree(pBuffer);
67         }
68         else
69         {
70             PrintErrorMessage(3871);
71         }
72     }
73     else
74     {
75         /* Retrieve the message string without appending extra newlines */
76         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
77                        FORMAT_MESSAGE_ARGUMENT_ARRAY,
78                        NULL,
79                        errNum,
80                        LANG_USER_DEFAULT,
81                        (LPWSTR)&pBuffer,
82                        0,
83                        (va_list *)pInserts);
84         if (pBuffer)
85         {
86             ConPrintf(StdOut, L"\n%s\n", pBuffer);
87             LocalFree(pBuffer);
88         }
89         else
90         {
91             PrintErrorMessage(3871);
92         }
93     }
94 
95     return 0;
96 }
97 
98 /* EOF */
99 
100