Author: hbelusca
Date: Wed Oct 19 17:04:29 2016
New Revision: 72996
URL:
http://svn.reactos.org/svn/reactos?rev=72996&view=rev
Log:
[MODE]
- Localization of output based on a patch by Lee Schroeder, but where I haven't
modified yet the output localization of errors.
- Dynamically underline the headers of the device status reports (by me).
CORE-12178
Added:
trunk/reactos/base/applications/cmdutils/mode/lang/
trunk/reactos/base/applications/cmdutils/mode/lang/en-US.rc (with props)
trunk/reactos/base/applications/cmdutils/mode/resource.h (with props)
Modified:
trunk/reactos/base/applications/cmdutils/mode/CMakeLists.txt
trunk/reactos/base/applications/cmdutils/mode/mode.c
trunk/reactos/base/applications/cmdutils/mode/mode.rc
Modified: trunk/reactos/base/applications/cmdutils/mode/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/mode/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/mode/CMakeLists.txt [iso-8859-1] Wed Oct 19
17:04:29 2016
@@ -1,6 +1,9 @@
+
+include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils)
add_executable(mode mode.c mode.rc)
set_module_type(mode win32cui UNICODE)
+target_link_libraries(mode conutils ${PSEH_LIB})
add_importlibs(mode user32 msvcrt kernel32)
set_target_properties(mode PROPERTIES SUFFIX ".com")
add_cd_file(TARGET mode DESTINATION reactos/system32 FOR all)
Added: trunk/reactos/base/applications/cmdutils/mode/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/mode/lang/en-US.rc (added)
+++ trunk/reactos/base/applications/cmdutils/mode/lang/en-US.rc [iso-8859-1] Wed Oct 19
17:04:29 2016
@@ -0,0 +1,67 @@
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+
+STRINGTABLE
+BEGIN
+ IDS_USAGE "Configure System Devices.\n\n\
+Device Status: MODE [device] [/STATUS]\n\
+Serial port: MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]\n\
+ [to=on|off] [xon=on|off] [odsr=on|off]\n\
+ [octs=on|off] [dtr=on|off|hs]\n\
+ [rts=on|off|hs|tg] [idsr=on|off]\n\
+Redirect printing: MODE LPTn[:]=COMm[:]\n\
+Select code page: MODE CON[:] CP SELECT=yyy\n\
+Code page status: MODE CON[:] CP [/STATUS]\n\
+Display mode: MODE CON[:] [COLS=c] [LINES=n]\n\
+Typematic rate: MODE CON[:] [RATE=r DELAY=d]\n"
+
+ IDS_QUERY_SERIAL_FOUND " Found serial device - %s\n"
+ IDS_QUERY_PRINTER_FOUND " Found printer device - %s\n"
+ IDS_QUERY_PARALLEL_FOUND " Found parallel device - %s\n"
+ IDS_QUERY_DOSDEV_FOUND " Found DOS device - %s\n"
+ // IDS_QUERY_MISC_FOUND " Found other device - %s\n"
+
+ // IDS_QUERY_DEVICE_FOUND " Found %s device - %s\n"
+ // IDS_SERIAL "serial"
+ // IDS_PRINTER "parallel"
+ // IDS_OTHER "other"
+END
+
+STRINGTABLE
+BEGIN
+ IDS_DEVICE_STATUS_HEADER "Status for device %s:"
+
+ IDS_COM_STATUS_BAUD " Baud: %ld\n"
+ IDS_COM_STATUS_PARITY " Parity: %s\n"
+ IDS_COM_STATUS_DATA_BITS " Data Bits: %d\n"
+ IDS_COM_STATUS_STOP_BITS " Stop Bits: %s\n"
+ IDS_COM_STATUS_TIMEOUT " Timeout: %s\n"
+ IDS_COM_STATUS_XON_XOFF " XON/XOFF: %s\n"
+ IDS_COM_STATUS_CTS_HANDSHAKING " CTS handshaking: %s\n"
+ IDS_COM_STATUS_DSR_HANDSHAKING " DSR handshaking: %s\n"
+ IDS_COM_STATUS_DSR_SENSITIVITY " DSR sensitivity: %s\n"
+ IDS_COM_STATUS_DTR_CIRCUIT " DTR circuit: %s\n"
+ IDS_COM_STATUS_RTS_CIRCUIT " RTS circuit: %s\n"
+
+ IDS_CONSOLE_STATUS_LINES " Lines: %d\n"
+ IDS_CONSOLE_STATUS_COLS " Columns: %d\n"
+ IDS_CONSOLE_KBD_DELAY " Keyboard delay: %ld\n"
+ IDS_CONSOLE_KBD_RATE " Keyboard rate: %ld\n"
+ IDS_CONSOLE_CODEPAGE " Code page: %d\n"
+
+ IDS_PRINTER_OUTPUT_NOT_REROUTED " Printer output is not being
rerouted.\n"
+ IDS_PRINTER_OUTPUT_REROUTED_SERIAL " Printer output is being rerouted to
serial port %s.\n"
+END
+
+STRINGTABLE
+BEGIN
+ IDS_ERROR_QUERY_DEVICES "ERROR: Unable to query DOS devices (0x%lx).\n"
+ IDS_ERROR_QUERY_DEVICES_FORM " QueryDosDeviceW(%s) returned unrecognised form
%s.\n"
+ IDS_ERROR_SET_PARALLEL_STATE "SetParallelState(%d) - DefineDosDevice(%s)
(0x%lx)\n"
+ IDS_ERROR_INVALID_PARAMETER "ERROR: Invalid parameter - %s\n"
+ IDS_ERROR_ILLEGAL_DEVICE_NAME "ERROR: Illegal device name - %s (0x%lx)\n"
+ IDS_ERROR_STATUS_GET_DEVICE "ERROR: Failed to get the status for device
COM%d:\n"
+ IDS_ERROR_STATUS_SET_DEVICE "ERROR: Failed to set the status for device
COM%d:\n"
+ IDS_ERROR_INVALID_PARITY_BITS "ERROR: Invalid value for Parity Bits %d:\n"
+ IDS_ERROR_INVALID_STOP_BITS "ERROR: Invalid value for Stop Bits %d:\n"
+ IDS_ERROR_NO_MEMORY "ERROR: Not enough memory.\n"
+END
Propchange: trunk/reactos/base/applications/cmdutils/mode/lang/en-US.rc
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/cmdutils/mode/mode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/mode/mode.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/mode/mode.c [iso-8859-1] Wed Oct 19 17:04:29
2016
@@ -35,35 +35,44 @@
#include <winuser.h>
#include <wincon.h>
+#include <conutils.h>
+
+#include "resource.h"
+
#define MAX_PORTNAME_LEN 20
#define MAX_COMPORT_NUM 10
#define ASSERT(a)
-const WCHAR* const usage_strings[] =
-{
- L"Device Status: MODE [device] [/STATUS]",
- L"Select code page: MODE CON[:] CP SELECT=yyy",
- L"Code page status: MODE CON[:] CP [/STATUS]",
- L"Display mode: MODE CON[:] [COLS=c] [LINES=n]",
- L"Typematic rate: MODE CON[:] [RATE=r DELAY=d]",
- L"Redirect printing: MODE LPTn[:]=COMm[:]",
- L"Serial port: MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]\n"
\
- L" [to=on|off] [xon=on|off] [odsr=on|off]\n"
\
- L" [octs=on|off] [dtr=on|off|hs]\n"
\
- L" [rts=on|off|hs|tg] [idsr=on|off]",
-};
-
-void Usage(void)
-{
- UINT i;
-
- wprintf(L"\nConfigures system devices.\n\n");
- for (i = 0; i < ARRAYSIZE(usage_strings); i++)
- {
- wprintf(L"%s\n", usage_strings[i]);
- }
- wprintf(L"\n");
+/*** For fixes, see also network/net/main.c ***/
+// VOID PrintPadding(...)
+INT
+__cdecl
+UnderlinedResPrintf(
+ IN PCON_STREAM Stream,
+ IN UINT uID,
+ ...)
+{
+ INT Len;
+ va_list args;
+
+#define MAX_BUFFER_SIZE 4096
+ INT i;
+ WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
+
+ va_start(args, uID);
+ Len = ConResPrintfV(Stream, uID, args);
+ va_end(args);
+
+ ConPuts(Stream, L"\n");
+ for (i = 0; i < Len; i++)
+ szMsgBuffer[i] = L'-';
+ szMsgBuffer[Len] = UNICODE_NULL;
+
+ // FIXME: Use ConStreamWrite instead.
+ ConPuts(Stream, szMsgBuffer);
+
+ return Len;
}
int QueryDevices(VOID)
@@ -79,26 +88,30 @@
{
if (wcsstr(ptr, L"COM"))
{
- wprintf(L" Found serial device - %s\n", ptr);
+ ConResPrintf(StdOut, IDS_QUERY_SERIAL_FOUND, ptr);
}
else if (wcsstr(ptr, L"PRN"))
{
- wprintf(L" Found printer device - %s\n", ptr);
+ ConResPrintf(StdOut, IDS_QUERY_PRINTER_FOUND, ptr);
}
else if (wcsstr(ptr, L"LPT"))
{
- wprintf(L" Found parallel device - %s\n", ptr);
+ ConResPrintf(StdOut, IDS_QUERY_PARALLEL_FOUND, ptr);
+ }
+ else if (wcsstr(ptr, L"AUX") || wcsstr(ptr, L"NUL"))
+ {
+ ConResPrintf(StdOut, IDS_QUERY_DOSDEV_FOUND, ptr);
}
else
{
- // wprintf(L" Found other device - %s\n", ptr);
+ // ConResPrintf(StdOut, IDS_QUERY_MISC_FOUND, ptr);
}
ptr += (wcslen(ptr) + 1);
}
}
else
{
- wprintf(L" ERROR: QueryDosDeviceW(...) failed: 0x%lx\n",
GetLastError());
+ wprintf(L"ERROR: QueryDosDeviceW(...) failed: 0x%lx\n",
GetLastError());
}
return 1;
}
@@ -109,21 +122,21 @@
WCHAR szPortName[MAX_PORTNAME_LEN];
swprintf(szPortName, L"LPT%d", nPortNum);
- wprintf(L"\nStatus for device LPT%d:\n", nPortNum);
- wprintf(L"-----------------------\n");
+
+ ConPuts(StdOut, L"\n");
+ UnderlinedResPrintf(StdOut, IDS_DEVICE_STATUS_HEADER, szPortName);
+ ConPuts(StdOut, L"\n");
+
if (QueryDosDeviceW(szPortName, buffer, ARRAYSIZE(buffer)))
{
WCHAR* ptr = wcsrchr(buffer, L'\\');
if (ptr != NULL)
{
if (_wcsicmp(szPortName, ++ptr) == 0)
- {
- wprintf(L" Printer output is not being rerouted.\n");
- }
+ ConResPuts(StdOut, IDS_PRINTER_OUTPUT_NOT_REROUTED);
else
- {
- wprintf(L" Printer output is being rerouted to serial port
%s\n", ptr);
- }
+ ConResPrintf(StdOut, IDS_PRINTER_OUTPUT_REROUTED_SERIAL, ptr);
+
return 0;
}
else
@@ -133,8 +146,9 @@
}
else
{
- wprintf(L" ERROR: QueryDosDeviceW(%s) failed: 0x%lx\n", szPortName,
GetLastError());
- }
+ wprintf(L"ERROR: QueryDosDeviceW(%s) failed: 0x%lx\n", szPortName,
GetLastError());
+ }
+
return 1;
}
@@ -193,30 +207,34 @@
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwKbdDelay, dwKbdSpeed;
- wprintf(L"\nStatus for device CON:\n");
- wprintf(L"-----------------------\n");
+ ConPuts(StdOut, L"\n");
+ UnderlinedResPrintf(StdOut, IDS_DEVICE_STATUS_HEADER, L"CON");
+ ConPuts(StdOut, L"\n");
+
if (GetConsoleScreenBufferInfo(hConOut, &csbi))
{
- wprintf(L" Lines: %d\n", csbi.dwSize.Y);
- wprintf(L" Columns: %d\n", csbi.dwSize.X);
+ ConResPrintf(StdOut, IDS_CONSOLE_STATUS_LINES, csbi.dwSize.Y);
+ ConResPrintf(StdOut, IDS_CONSOLE_STATUS_COLS , csbi.dwSize.X);
}
if (SystemParametersInfoW(SPI_GETKEYBOARDDELAY, 0, &dwKbdDelay, 0))
{
- wprintf(L" Keyboard delay: %ld\n", dwKbdDelay);
+ ConResPrintf(StdOut, IDS_CONSOLE_KBD_DELAY, dwKbdDelay);
}
if (SystemParametersInfoW(SPI_GETKEYBOARDSPEED, 0, &dwKbdSpeed, 0))
{
- wprintf(L" Keyboard rate: %ld\n", dwKbdSpeed);
- }
- wprintf(L" Code page: %d\n", GetConsoleOutputCP());
+ ConResPrintf(StdOut, IDS_CONSOLE_KBD_RATE, dwKbdSpeed);
+ }
+ ConResPrintf(StdOut, IDS_CONSOLE_CODEPAGE, GetConsoleOutputCP());
return 0;
}
int ShowConsoleCPStatus(VOID)
{
- wprintf(L"\nStatus for device CON:\n");
- wprintf(L"-----------------------\n");
- wprintf(L" Code page: %d\n", GetConsoleOutputCP());
+ ConPuts(StdOut, L"\n");
+ UnderlinedResPrintf(StdOut, IDS_DEVICE_STATUS_HEADER, L"CON");
+ ConPuts(StdOut, L"\n");
+
+ ConResPrintf(StdOut, IDS_CONSOLE_CODEPAGE, GetConsoleOutputCP());
return 0;
}
@@ -567,6 +585,7 @@
DCB dcb;
COMMTIMEOUTS CommTimeouts;
+ WCHAR szPortName[MAX_PORTNAME_LEN];
if (!SerialPortQuery(nPortNum, &dcb, &CommTimeouts, FALSE))
{
@@ -582,21 +601,30 @@
wprintf(L"ERROR: Invalid value for Stop Bits %d:\n", dcb.StopBits);
dcb.StopBits = 0;
}
- wprintf(L"\nStatus for device COM%d:\n", nPortNum);
- wprintf(L"-----------------------\n");
- wprintf(L" Baud: %ld\n", dcb.BaudRate);
- wprintf(L" Parity: %s\n", parity_strings[dcb.Parity]);
- wprintf(L" Data Bits: %d\n", dcb.ByteSize);
- wprintf(L" Stop Bits: %s\n", stopbit_strings[dcb.StopBits]);
- wprintf(L" Timeout: %s\n",
- (CommTimeouts.ReadTotalTimeoutConstant != 0) ||
- (CommTimeouts.WriteTotalTimeoutConstant != 0) ? L"ON" :
L"OFF");
- wprintf(L" XON/XOFF: %s\n", dcb.fOutX ? L"ON"
: L"OFF");
- wprintf(L" CTS handshaking: %s\n", dcb.fOutxCtsFlow ? L"ON"
: L"OFF");
- wprintf(L" DSR handshaking: %s\n", dcb.fOutxDsrFlow ? L"ON"
: L"OFF");
- wprintf(L" DSR sensitivity: %s\n", dcb.fDsrSensitivity ? L"ON"
: L"OFF");
- wprintf(L" DTR circuit: %s\n", control_strings[dcb.fDtrControl]);
- wprintf(L" RTS circuit: %s\n", control_strings[dcb.fRtsControl]);
+
+ swprintf(szPortName, L"COM%d", nPortNum);
+
+ ConPuts(StdOut, L"\n");
+ UnderlinedResPrintf(StdOut, IDS_DEVICE_STATUS_HEADER, szPortName);
+ ConPuts(StdOut, L"\n");
+
+ ConResPrintf(StdOut, IDS_COM_STATUS_BAUD, dcb.BaudRate);
+ ConResPrintf(StdOut, IDS_COM_STATUS_PARITY, parity_strings[dcb.Parity]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_DATA_BITS, dcb.ByteSize);
+ ConResPrintf(StdOut, IDS_COM_STATUS_STOP_BITS, stopbit_strings[dcb.StopBits]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_TIMEOUT,
+ control_strings[(CommTimeouts.ReadTotalTimeoutConstant != 0) ||
+ (CommTimeouts.WriteTotalTimeoutConstant != 0) ? 1 : 0]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_XON_XOFF,
+ control_strings[dcb.fOutX ? 1 : 0]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_CTS_HANDSHAKING,
+ control_strings[dcb.fOutxCtsFlow ? 1 : 0]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_DSR_HANDSHAKING,
+ control_strings[dcb.fOutxDsrFlow ? 1 : 0]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_DSR_SENSITIVITY,
+ control_strings[dcb.fDsrSensitivity ? 1 : 0]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_DTR_CIRCUIT, control_strings[dcb.fDtrControl]);
+ ConResPrintf(StdOut, IDS_COM_STATUS_RTS_CIRCUIT, control_strings[dcb.fRtsControl]);
return 0;
}
@@ -1079,6 +1107,9 @@
PCWSTR ArgStr, argStr;
INT nPortNum;
+
+ /* Initialize the Console Standard Streams */
+ ConInitStdStreams();
/*
*
MODE.COM has a very peculiar way of parsing its arguments,
@@ -1130,7 +1161,7 @@
if (wcsstr(argStr, L"/?") || wcsstr(argStr, L"-?"))
{
- Usage();
+ ConResPuts(StdOut, IDS_USAGE);
goto Quit;
}
else if (_wcsnicmp(argStr, L"/STA", 4) == 0)
Modified: trunk/reactos/base/applications/cmdutils/mode/mode.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/mode/mode.rc [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/mode/mode.rc [iso-8859-1] Wed Oct 19 17:04:29
2016
@@ -1,5 +1,17 @@
+#include <windef.h>
+
+#include "resource.h"
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Mode Utility"
#define REACTOS_STR_INTERNAL_NAME "mode"
#define REACTOS_STR_ORIGINAL_FILENAME "mode.com"
#include <reactos/version.rc>
+
+/* UTF-8 */
+#pragma code_page(65001)
+
+#ifdef LANGUAGE_EN_US
+ #include "lang/en-US.rc"
+#endif
Added: trunk/reactos/base/applications/cmdutils/mode/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/mode/resource.h (added)
+++ trunk/reactos/base/applications/cmdutils/mode/resource.h [iso-8859-1] Wed Oct 19
17:04:29 2016
@@ -0,0 +1,47 @@
+#ifndef RESOURCE_H
+#define RESOURCE_H
+
+#define IDS_USAGE 0
+
+#define IDS_QUERY_SERIAL_FOUND 1
+#define IDS_QUERY_PRINTER_FOUND 2
+#define IDS_QUERY_PARALLEL_FOUND 3
+// #define IDS_QUERY_MISC_FOUND 4
+#define IDS_QUERY_DOSDEV_FOUND 4
+// #define IDS_QUERY_DEVICE_FOUND 1
+// #define IDS_SERIAL 2
+// #define IDS_PRINTER 3
+// #define IDS_OTHER 4
+
+#define IDS_DEVICE_STATUS_HEADER 5
+#define IDS_COM_STATUS_BAUD 6
+#define IDS_COM_STATUS_PARITY 7
+#define IDS_COM_STATUS_DATA_BITS 8
+#define IDS_COM_STATUS_STOP_BITS 9
+#define IDS_COM_STATUS_TIMEOUT 10
+#define IDS_COM_STATUS_XON_XOFF 11
+#define IDS_COM_STATUS_CTS_HANDSHAKING 12
+#define IDS_COM_STATUS_DSR_HANDSHAKING 13
+#define IDS_COM_STATUS_DSR_SENSITIVITY 14
+#define IDS_COM_STATUS_DTR_CIRCUIT 15
+#define IDS_COM_STATUS_RTS_CIRCUIT 16
+#define IDS_CONSOLE_STATUS_LINES 17
+#define IDS_CONSOLE_STATUS_COLS 18
+#define IDS_CONSOLE_KBD_DELAY 19
+#define IDS_CONSOLE_KBD_RATE 20
+#define IDS_CONSOLE_CODEPAGE 21
+#define IDS_PRINTER_OUTPUT_NOT_REROUTED 22
+#define IDS_PRINTER_OUTPUT_REROUTED_SERIAL 23
+
+#define IDS_ERROR_QUERY_DEVICES 24
+#define IDS_ERROR_QUERY_DEVICES_FORM 25
+#define IDS_ERROR_SET_PARALLEL_STATE 26
+#define IDS_ERROR_INVALID_PARAMETER 27
+#define IDS_ERROR_ILLEGAL_DEVICE_NAME 28
+#define IDS_ERROR_STATUS_GET_DEVICE 29
+#define IDS_ERROR_STATUS_SET_DEVICE 30
+#define IDS_ERROR_INVALID_PARITY_BITS 31
+#define IDS_ERROR_INVALID_STOP_BITS 32
+#define IDS_ERROR_NO_MEMORY 33
+
+#endif /* RESOURCE_H */
Propchange: trunk/reactos/base/applications/cmdutils/mode/resource.h
------------------------------------------------------------------------------
svn:eol-style = native