···6868 IDS_ERROR_INVALID_STOP_BITS "ERROR: Invalid value for Stop Bits %d:\n"
6969 IDS_ERROR_NO_MEMORY "ERROR: Not enough memory.\n"
7070 IDS_ERROR_SCREEN_LINES_COL "The screen cannot be set to the number of lines and columns specified.\n"
7171+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7172END
+1
base/applications/cmdutils/mode/lang/en-US.rc
···6868 IDS_ERROR_INVALID_STOP_BITS "ERROR: Invalid value for Stop Bits %d:\n"
6969 IDS_ERROR_NO_MEMORY "ERROR: Not enough memory.\n"
7070 IDS_ERROR_SCREEN_LINES_COL "The screen cannot be set to the number of lines and columns specified.\n"
7171+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7172END
+1
base/applications/cmdutils/mode/lang/it-IT.rc
···6868 IDS_ERROR_INVALID_STOP_BITS "ERRORE: valore non valido per i bit di stop %d:\n"
6969 IDS_ERROR_NO_MEMORY "ERRORE: memoria insufficiente.\n"
7070 IDS_ERROR_SCREEN_LINES_COL "Lo schermo non può essere impostato con il numero di righe e colonne specificato.\n"
7171+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7172END
+1
base/applications/cmdutils/mode/lang/pl-PL.rc
···6868 IDS_ERROR_INVALID_STOP_BITS "BŁĄD: Nieprawidłowa wartość dla bitów separatora %d:\n"
6969 IDS_ERROR_NO_MEMORY "BŁĄD: Za mało pamięci.\n"
7070 IDS_ERROR_SCREEN_LINES_COL "BŁĄD: Nie można ustawić ekranu na określoną liczbę wierszy i kolumn.\n"
7171+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7172END
+1
base/applications/cmdutils/mode/lang/ro-RO.rc
···7777 IDS_ERROR_INVALID_STOP_BITS "EROARE: Valoare eronată pentru biții delimitori %d:\n"
7878 IDS_ERROR_NO_MEMORY "ERAORE: Nu există suficientă memorie.\n"
7979 IDS_ERROR_SCREEN_LINES_COL "Ecranul nu poate fi stabilit cu numărul de linii sau coloane specificate.\n"
8080+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
8081END
+1
base/applications/cmdutils/mode/lang/ru-RU.rc
···6868 IDS_ERROR_INVALID_STOP_BITS "ОШИБКА: Неверное значение стоповых битов %d:\n"
6969 IDS_ERROR_NO_MEMORY "ОШИБКА: Недостаточно памяти.\n"
7070 IDS_ERROR_SCREEN_LINES_COL "The screen cannot be set to the number of lines and columns specified.\n"
7171+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7172END
+1
base/applications/cmdutils/mode/lang/tr-TR.rc
···7070 IDS_ERROR_INVALID_STOP_BITS "YANLIŞLIK: %d Durma İkilleri için geçersiz değer:\n"
7171 IDS_ERROR_NO_MEMORY "YANLIŞLIK: Yeterli bellek yok.\n"
7272 IDS_ERROR_SCREEN_LINES_COL "Görüntülük, belirtilen yataç ve dikeç sayısına ayarlanamıyor.\n"
7373+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7374END
+1
base/applications/cmdutils/mode/lang/zh-CN.rc
···6868 IDS_ERROR_INVALID_STOP_BITS "错误: 终止位 %d 值无效:\n"
6969 IDS_ERROR_NO_MEMORY "错误: 内存不足。\n"
7070 IDS_ERROR_SCREEN_LINES_COL "屏幕无法被设置成指定的行数和列数。\n"
7171+ IDS_ERROR_INVALID_CODEPAGE "The code page specified is not valid.\n"
7172END
+49-16
base/applications/cmdutils/mode/mode.c
···11+/*
22+ * PROJECT: ReactOS Mode Utility
33+ * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
44+ * PURPOSE: Provides fast mode setup for DOS devices.
55+ * COPYRIGHT: Copyright 2002 Robert Dickenson
66+ * Copyright 2016-2021 Hermes Belusca-Maito
77+ */
18/*
29 * ReactOS mode console command
310 *
···1825 * You should have received a copy of the GNU General Public License
1926 * along with this program; if not, write to the Free Software
2027 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2121- */
2222-/*
2323- * COPYRIGHT: See COPYING in the top level directory
2424- * PROJECT: ReactOS Mode Utility
2525- * FILE: base/applications/cmdutils/mode/mode.c
2626- * PURPOSE: Provides fast mode setup for DOS devices.
2727- * PROGRAMMERS: Robert Dickenson
2828- * Hermes Belusca-Maito
2928 */
30293130#include <stdio.h>
···453452int SetConsoleCPState(IN PCWSTR ArgStr)
454453{
455454 PCWSTR argStr = ArgStr;
456456- DWORD CodePage = 0;
455455+ DWORD value = 0;
456456+ UINT uOldCodePage, uNewCodePage;
457457458458 if ( (_wcsnicmp(argStr, L"SELECT=", 7) == 0 && (argStr += 7)) ||
459459 (_wcsnicmp(argStr, L"SEL=", 4) == 0 && (argStr += 4)) )
460460 {
461461- argStr = ParseNumber(argStr, &CodePage);
461461+ argStr = ParseNumber(argStr, &value);
462462 if (!argStr) goto invalid_parameter;
463463464464 /* This should be the end of the string */
465465 while (*argStr == L' ') argStr++;
466466 if (*argStr) goto invalid_parameter;
467467-468468- SetConsoleCP(CodePage);
469469- SetConsoleOutputCP(CodePage);
470470- // "The code page specified is not valid."
471471- ShowConsoleCPStatus();
472467 }
473468 else
474469 {
···477472 return 1;
478473 }
479474480480- return 0;
475475+ uNewCodePage = value;
476476+477477+/**
478478+ ** IMPORTANT NOTE: This code must be kept synchronized with CHCP.COM
479479+ **/
480480+481481+ /*
482482+ * Save the original console code page to be restored
483483+ * in case SetConsoleCP() or SetConsoleOutputCP() fails.
484484+ */
485485+ uOldCodePage = GetConsoleCP();
486486+487487+ /*
488488+ * Try changing the console input and output code pages.
489489+ * If it succeeds, refresh the local code page information.
490490+ */
491491+ if (SetConsoleCP(uNewCodePage))
492492+ {
493493+ if (SetConsoleOutputCP(uNewCodePage))
494494+ {
495495+ /* Success, reset the current thread UI language
496496+ * and update the streams cached code page. */
497497+ ConSetThreadUILanguage(0);
498498+ ConStdStreamsSetCacheCodePage(uNewCodePage, uNewCodePage);
499499+500500+ /* Display the current console status */
501501+ ShowConsoleStatus();
502502+ return 0;
503503+ }
504504+ else
505505+ {
506506+ /* Failure, restore the original console code page */
507507+ SetConsoleCP(uOldCodePage);
508508+ }
509509+ }
510510+511511+ /* An error happened, display an error and bail out */
512512+ ConResPuts(StdErr, IDS_ERROR_INVALID_CODEPAGE);
513513+ return 1;
481514}
482515483516