https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ac01e4cd72ffc3f0e2cdfe03e306ab2b5d6a2cfd

commit ac01e4cd72ffc3f0e2cdfe03e306ab2b5d6a2cfd
Author:     Eric Kohl <eric.k...@reactos.org>
AuthorDate: Sat May 9 12:28:40 2020 +0200
Commit:     Eric Kohl <eric.k...@reactos.org>
CommitDate: Sat May 9 12:30:11 2020 +0200

    [ARP] Replace some hard-coded strings by message resources
---
 base/applications/network/arp/CMakeLists.txt |   1 +
 base/applications/network/arp/arp.c          | 121 ++++++++++++++++----------
 base/applications/network/arp/arp.rc         |   1 +
 sdk/include/reactos/mc/CMakeLists.txt        |   1 +
 sdk/include/reactos/mc/arp_msg.mc            | 123 +++++++++++++++++++++++++++
 5 files changed, 200 insertions(+), 47 deletions(-)

diff --git a/base/applications/network/arp/CMakeLists.txt 
b/base/applications/network/arp/CMakeLists.txt
index 7f86c4cb4ba..6aba57385c9 100644
--- a/base/applications/network/arp/CMakeLists.txt
+++ b/base/applications/network/arp/CMakeLists.txt
@@ -1,5 +1,6 @@
 
 add_executable(arp arp.c arp.rc)
 set_module_type(arp win32cui)
+add_dependencies(arp arp_msg)
 add_importlibs(arp iphlpapi ws2_32 shlwapi msvcrt kernel32)
 add_cd_file(TARGET arp DESTINATION reactos/system32 FOR all)
diff --git a/base/applications/network/arp/arp.c 
b/base/applications/network/arp/arp.c
index 4c9322119a6..5df10ed4f93 100644
--- a/base/applications/network/arp/arp.c
+++ b/base/applications/network/arp/arp.c
@@ -60,7 +60,7 @@ VOID Usage(VOID);
  */
 DWORD DoFormatMessage(VOID)
 {
-    LPVOID lpMsgBuf;
+    LPTSTR lpMsgBuf;
     DWORD RetVal;
 
     DWORD ErrorCode = GetLastError();
@@ -79,8 +79,7 @@ DWORD DoFormatMessage(VOID)
 
         if (RetVal != 0)
         {
-            _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
-
+            _putts(lpMsgBuf);
             LocalFree(lpMsgBuf);
             /* return number of TCHAR's stored in output buffer
              * excluding '\0' - as FormatMessage does*/
@@ -90,6 +89,56 @@ DWORD DoFormatMessage(VOID)
     return 0;
 }
 
+VOID
+PrintMessage(
+    DWORD dwMessage)
+{
+    LPTSTR lpMsgBuf;
+    DWORD RetVal;
+
+    RetVal = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                           FORMAT_MESSAGE_FROM_HMODULE |
+                           FORMAT_MESSAGE_IGNORE_INSERTS,
+                           GetModuleHandleW(NULL),
+                           dwMessage,
+                           LANG_USER_DEFAULT,
+                           (LPTSTR)&lpMsgBuf,
+                           0,
+                           NULL);
+    if (RetVal != 0)
+    {
+        _putts(lpMsgBuf);
+        LocalFree(lpMsgBuf);
+    }
+}
+
+VOID
+PrintMessageV(
+    DWORD dwMessage,
+    ...)
+{
+    LPTSTR lpMsgBuf;
+    va_list args = NULL;
+    DWORD RetVal;
+
+    va_start(args, dwMessage);
+
+    RetVal = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_HMODULE,
+                           GetModuleHandleW(NULL),
+                           dwMessage,
+                           LANG_USER_DEFAULT,
+                           (LPTSTR)&lpMsgBuf,
+                           0,
+                           &args);
+    va_end(args);
+
+    if (RetVal != 0)
+    {
+        _putts(lpMsgBuf);
+        LocalFree(lpMsgBuf);
+    }
+}
+
 /*
  *
  * Takes an ARP entry and prints the IP address,
@@ -118,14 +167,21 @@ INT PrintEntries(PMIB_IPNETROW pIpAddRow)
     /* print cache type */
     switch (pIpAddRow->dwType)
     {
-        case MIB_IPNET_TYPE_DYNAMIC : _tprintf(_T("dynamic\n"));
-                                      break;
-        case MIB_IPNET_TYPE_STATIC : _tprintf(_T("static\n"));
-                                      break;
-        case MIB_IPNET_TYPE_INVALID : _tprintf(_T("invalid\n"));
-                                      break;
-        case MIB_IPNET_TYPE_OTHER : _tprintf(_T("other\n"));
-                                      break;
+        case MIB_IPNET_TYPE_DYNAMIC:
+            PrintMessage(10007);
+            break;
+
+        case MIB_IPNET_TYPE_STATIC:
+            PrintMessage(10008);
+            break;
+
+        case MIB_IPNET_TYPE_INVALID:
+            PrintMessage(10006);
+            break;
+
+        case MIB_IPNET_TYPE_OTHER:
+            PrintMessage(10005);
+            break;
     }
     return EXIT_SUCCESS;
 }
@@ -173,7 +229,7 @@ INT DisplayArpEntries(PTCHAR pszInetAddr, PTCHAR pszIfAddr)
     /* check there are entries in the table */
     if (pIpNetTable->dwNumEntries == 0)
     {
-        _tprintf(_T("No ARP entires found\n"));
+        PrintMessage(10018);
         goto cleanup;
     }
 
@@ -213,8 +269,7 @@ INT DisplayArpEntries(PTCHAR pszInetAddr, PTCHAR pszIfAddr)
 
 
     /* print header, including interface IP address and index number */
-    _tprintf(_T("\nInterface: %s --- 0x%lx \n"), szIntIpAddr, 
pIpNetTable->table[0].dwIndex);
-    _tprintf(_T("  Internet Address      Physical Address      Type\n"));
+    PrintMessageV(10003, szIntIpAddr, pIpNetTable->table[0].dwIndex);
 
     /* go through all ARP entries */
     for (i=0; i < pIpNetTable->dwNumEntries; i++)
@@ -269,7 +324,7 @@ INT Addhost(PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR 
pszIfAddr)
     {
         if ((dwIpAddr = inet_addr(pszInetAddr)) == INADDR_NONE)
         {
-            _tprintf(_T("ARP: bad IP address: %s\n"), pszInetAddr);
+            PrintMessageV(10001, pszInetAddr);
             return EXIT_FAILURE;
         }
     }
@@ -282,7 +337,7 @@ INT Addhost(PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR 
pszIfAddr)
     /* check MAC address */
     if (strlen(pszEthAddr) != 17)
     {
-        _tprintf(_T("ARP: bad argument: %s\n"), pszEthAddr);
+        PrintMessageV(10002, pszEthAddr);
         return EXIT_FAILURE;
     }
     for (i=0; i<17; i++)
@@ -292,7 +347,7 @@ INT Addhost(PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR 
pszIfAddr)
 
         if (!isxdigit(pszEthAddr[i]))
         {
-            _tprintf(_T("ARP: bad argument: %s\n"), pszEthAddr);
+            PrintMessageV(10002, pszEthAddr);
             return EXIT_FAILURE;
         }
     }
@@ -412,7 +467,7 @@ INT Deletehost(PTCHAR pszInetAddr, PTCHAR pszIfAddr)
             bFlushTable = TRUE;
         else if ((dwIpAddr = inet_addr(pszInetAddr)) == INADDR_NONE)
         {
-            _tprintf(_T("ARP: bad IP address: %s\n"), pszInetAddr);
+            PrintMessageV(10001, pszInetAddr);
             exit(EXIT_FAILURE);
         }
     }
@@ -508,35 +563,7 @@ cleanup:
  */
 VOID Usage(VOID)
 {
-    _tprintf(_T("\nDisplays and modifies the IP-to-Physical address 
translation tables used by\n"
-                "address resolution protocol (ARP).\n"
-                "\n"
-                "ARP -s inet_addr eth_addr [if_addr]\n"
-                "ARP -d inet_addr [if_addr]\n"
-                "ARP -a [inet_addr] [-N if_addr]\n"
-                "\n"
-                "  -a            Displays current ARP entries by interrogating 
the current\n"
-                "                protocol data.  If inet_addr is specified, 
the IP and Physical\n"
-                "                addresses for only the specified computer are 
displayed.  If\n"
-                "                more than one network interface uses ARP, 
entries for each ARP\n"
-                "                table are displayed.\n"
-                "  -g            Same as -a.\n"
-                "  inet_addr     Specifies an internet address.\n"
-                "  -N if_addr    Displays the ARP entries for the network 
interface specified\n"
-                "                by if_addr.\n"
-                "  -d            Deletes the host specified by inet_addr. 
inet_addr may be\n"
-                "                wildcarded with * to delete all hosts.\n"
-                "  -s            Adds the host and associates the Internet 
address inet_addr\n"
-                "                with the Physical address eth_addr.  The 
Physical address is\n"
-                "                given as 6 hexadecimal bytes separated by 
hyphens. The entry\n"
-                "                is permanent.\n"
-                "  eth_addr      Specifies a physical address.\n"
-                "  if_addr       If present, this specifies the Internet 
address of the\n"
-                "                interface whose address translation table 
should be modified.\n"
-                "                If not present, the first applicable 
interface will be used.\n"
-                "Example:\n"
-                "  > arp -s 157.55.85.212   00-aa-00-62-c6-09  .... Adds a 
static entry.\n"
-                "  > arp -a                                    .... Displays 
the arp table.\n\n"));
+    PrintMessage(10000);
 }
 
 /*
diff --git a/base/applications/network/arp/arp.rc 
b/base/applications/network/arp/arp.rc
index f206cd790ee..0076cca8d9c 100644
--- a/base/applications/network/arp/arp.rc
+++ b/base/applications/network/arp/arp.rc
@@ -3,3 +3,4 @@
 #define REACTOS_STR_ORIGINAL_FILENAME  "arp.exe"
 #define REACTOS_STR_ORIGINAL_COPYRIGHT "Ged Murphy (gedmur...@gmail.com)"
 #include <reactos/version.rc>
+#include <arp_msg.rc>
diff --git a/sdk/include/reactos/mc/CMakeLists.txt 
b/sdk/include/reactos/mc/CMakeLists.txt
index 46753f3bc16..9899bb8a800 100644
--- a/sdk/include/reactos/mc/CMakeLists.txt
+++ b/sdk/include/reactos/mc/CMakeLists.txt
@@ -3,6 +3,7 @@ list(APPEND ANSI_SOURCE
      bugcodes.mc)
 
 list(APPEND UNICODE_SOURCE
+     arp_msg.mc
      errcodes.mc
      net_msg.mc
      neteventmsg.mc
diff --git a/sdk/include/reactos/mc/arp_msg.mc 
b/sdk/include/reactos/mc/arp_msg.mc
new file mode 100644
index 00000000000..15aa4095cf1
--- /dev/null
+++ b/sdk/include/reactos/mc/arp_msg.mc
@@ -0,0 +1,123 @@
+MessageIdTypedef=DWORD
+
+SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
+               Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
+               Warning=0x2:STATUS_SEVERITY_WARNING
+               Error=0x3:STATUS_SEVERITY_ERROR
+              )
+
+FacilityNames=(System=0x0:FACILITY_SYSTEM
+              )
+
+LanguageNames=(English=0x409:MSG00409
+              )
+
+MessageId=10000
+SymbolicName=MSG_ARP_SYNTAX
+Severity=Success
+Facility=System
+Language=English
+Displays and modifies the IP-to-Physical address translation tables used by
+address resolution protocol (ARP).
+
+ARP -s inet_addr eth_addr [if_addr]
+ARP -d inet_addr [if_addr]
+ARP -a [inet_addr] [-N if_addr]
+
+  -a            Displays current ARP entries by interrogating the current
+                protocol data.  If inet_addr is specified, the IP and Physical
+                addresses for only the specified computer are displayed.  If
+                more than one network interface uses ARP, entries for each ARP
+                table are displayed.
+  -g            Same as -a.
+  inet_addr     Specifies an internet address.
+  -N if_addr    Displays the ARP entries for the network interface specified
+                by if_addr.
+  -d            Deletes the host specified by inet_addr. inet_addr may be
+                wildcarded with * to delete all hosts.
+  -s            Adds the host and associates the Internet address inet_addr
+                with the Physical address eth_addr.  The Physical address is
+                given as 6 hexadecimal bytes separated by hyphens. The entry
+                is permanent.
+  eth_addr      Specifies a physical address.
+  if_addr       If present, this specifies the Internet address of the
+                interface whose address translation table should be modified.
+                If not present, the first applicable interface will be used.
+Example:
+  > arp -s 157.55.85.212   00-aa-00-62-c6-09  .... Adds a static entry.
+  > arp -a                                    .... Displays the arp table.
+.
+
+MessageId=10001
+SymbolicName=MSG_ARP_BAD_IP_ADDRESS
+Severity=Success
+Facility=System
+Language=English
+ARP: bad IP address: %1
+.
+
+MessageId=10002
+SymbolicName=MSG_ARP_BAD_ARGUMENT
+Severity=Success
+Facility=System
+Language=English
+ARP: bad argument: %1
+.
+
+MessageId=10003
+SymbolicName=MSG_ARP_INTERFACE
+Severity=Success
+Facility=System
+Language=English
+
+Interface: %1!s! --- 0x%2!lx!
+  Internet Address      Physical Address      Type
+.
+
+MessageId=10005
+SymbolicName=MSG_ARP_OTHER
+Severity=Success
+Facility=System
+Language=English
+other%0
+.
+
+MessageId=10006
+SymbolicName=MSG_ARP_INVALID
+Severity=Success
+Facility=System
+Language=English
+invalid%0
+.
+
+MessageId=10007
+SymbolicName=MSG_ARP_DYNAMIC
+Severity=Success
+Facility=System
+Language=English
+dynamic%0
+.
+
+MessageId=10008
+SymbolicName=MSG_ARP_STATIC
+Severity=Success
+Facility=System
+Language=English
+static%0
+.
+
+MessageId=10013
+SymbolicName=MSG_ARP_ENTRY_FORMAT
+Severity=Success
+Facility=System
+Language=English
+  %1!-20s!  %2!-20s!  %3!-10s!
+.
+
+MessageId=10018
+SymbolicName=MSG_ARP_NO_ENTRIES
+Severity=Success
+Facility=System
+Language=English
+No ARP entires found
+.

Reply via email to