Author: hbelusca Date: Thu Jun 9 19:20:35 2016 New Revision: 71601
URL: http://svn.reactos.org/svn/reactos?rev=71601&view=rev Log: [COMP] - Fix the output of localized strings (and use the "well-known" PrintResourceString function already used in all the other cmdtools) - Unconditionally increase the number of lines & the offset when performing the comparison.
Modified: trunk/reactos/base/applications/cmdutils/comp/comp.c trunk/reactos/base/applications/cmdutils/comp/resource.h
Modified: trunk/reactos/base/applications/cmdutils/comp/comp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils/... ============================================================================== --- trunk/reactos/base/applications/cmdutils/comp/comp.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/cmdutils/comp/comp.c [iso-8859-1] Thu Jun 9 19:20:35 2016 @@ -24,43 +24,48 @@ * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com) */
-#include <windows.h> -#include <tchar.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> +// #include <string.h> +// #include <wchar.h> #include <assert.h>
+#define WIN32_NO_STATUS +#include <windef.h> +#include <winbase.h> +#include <winuser.h> + #include "resource.h"
#define STRBUF 1024
-VOID ResPrint(INT res_no, ...) -{ - TCHAR * res_string; - va_list vargs; - - va_start(vargs, res_no); - - if (LoadString(GetModuleHandle(NULL), res_no, (TCHAR*)&res_string, 0)) - { - _vtprintf(res_string, vargs); - } +VOID PrintResourceString(INT resID, ...) +{ + WCHAR bufSrc[RC_STRING_MAX_SIZE]; + WCHAR bufFormatted[RC_STRING_MAX_SIZE]; + CHAR bufFormattedOem[RC_STRING_MAX_SIZE]; + + va_list args; + va_start(args, resID); + + if (LoadStringW(GetModuleHandleW(NULL), resID, bufSrc, ARRAYSIZE(bufSrc))) + vswprintf(bufFormatted, bufSrc, args); else - { - _tprintf(_T("Resource loading error!")); - } - - va_end(vargs); + swprintf(bufFormatted, L"Resource loading error!"); + + CharToOemW(bufFormatted, bufFormattedOem); + fputs(bufFormattedOem, stdout); + + va_end(args); }
/* getline: read a line, return length */ -INT GetBuff(PBYTE buff, FILE *in) +INT GetBuff(PBYTE buff, FILE* in) { return fread(buff, sizeof(BYTE), STRBUF, in); }
-INT FileSize(FILE * fd) +INT FileSize(FILE* fd) { INT result = -1; if (fseek(fd, 0, SEEK_END) == 0 && (result = ftell(fd)) != -1) @@ -74,11 +79,11 @@ /* Print program usage */ VOID Usage(VOID) { - ResPrint(IDS_HELP); -} - - -int _tmain (int argc, TCHAR *argv[]) + PrintResourceString(IDS_HELP); +} + + +int wmain (int argc, WCHAR* argv[]) { INT i;
@@ -89,41 +94,41 @@ INT BufLen1, BufLen2; PBYTE Buff1 = NULL; PBYTE Buff2 = NULL; - TCHAR File1[_MAX_PATH + 1], // File paths + WCHAR File1[_MAX_PATH + 1], // File paths File2[_MAX_PATH + 1]; BOOL bAscii = FALSE, // /A switch bLineNos = FALSE; // /L switch - UINT LineNumber; - UINT Offset; + UINT LineNumber; + UINT Offset; INT FileSizeFile1; INT FileSizeFile2; INT NumberOfOptions = 0; INT FilesOK = 1; - INT Status = EXIT_SUCCESS; + INT Status = EXIT_SUCCESS;
/* Parse command line for options */ for (i = 1; i < argc; i++) { - if (argv[i][0] == _T('/')) + if (argv[i][0] == L'/') { switch (argv[i][1]) { - case _T('A'): + case L'A': bAscii = TRUE; NumberOfOptions++; break;
- case _T('L'): + case L'L': bLineNos = TRUE; NumberOfOptions++; break;
- case _T('?'): + case L'?': Usage(); return EXIT_SUCCESS;
default: - ResPrint(IDS_INVALIDSWITCH, argv[i][1]); + PrintResourceString(IDS_INVALIDSWITCH, argv[i][1]); Usage(); return EXIT_FAILURE; } @@ -132,19 +137,19 @@
if (argc - NumberOfOptions == 3) { - _tcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH); - _tcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH); + wcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH); + wcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH); } else { - ResPrint(IDS_BADSYNTAX); + PrintResourceString(IDS_BADSYNTAX); return EXIT_FAILURE; }
Buff1 = (PBYTE)malloc(STRBUF); if (Buff1 == NULL) { - _tprintf(_T("Can't get free memory for Buff1\n")); + wprintf(L"Can't get free memory for Buff1\n"); Status = EXIT_FAILURE; goto Cleanup; } @@ -152,31 +157,30 @@ Buff2 = (PBYTE)malloc(STRBUF); if (Buff2 == NULL) { - _tprintf(_T("Can't get free memory for Buff2\n")); - Status = EXIT_FAILURE; - goto Cleanup; - } - - if ((fp1 = _tfopen(File1, _T("rb"))) == NULL) - { - ResPrint(IDS_FILEERROR, File1); - Status = EXIT_FAILURE; - goto Cleanup; - } - if ((fp2 = _tfopen(File2, _T("rb"))) == NULL) - { - ResPrint(IDS_FILEERROR, File2); - Status = EXIT_FAILURE; - goto Cleanup; - } - - - ResPrint(IDS_COMPARING, File1, File2); + wprintf(L"Can't get free memory for Buff2\n"); + Status = EXIT_FAILURE; + goto Cleanup; + } + + if ((fp1 = _wfopen(File1, L"rb")) == NULL) + { + PrintResourceString(IDS_FILEERROR, File1); + Status = EXIT_FAILURE; + goto Cleanup; + } + if ((fp2 = _wfopen(File2, L"rb")) == NULL) + { + PrintResourceString(IDS_FILEERROR, File2); + Status = EXIT_FAILURE; + goto Cleanup; + } + + PrintResourceString(IDS_COMPARING, File1, File2);
FileSizeFile1 = FileSize(fp1); if (FileSizeFile1 == -1) { - ResPrint(IDS_FILESIZEERROR, File1); + PrintResourceString(IDS_FILESIZEERROR, File1); Status = EXIT_FAILURE; goto Cleanup; } @@ -184,14 +188,14 @@ FileSizeFile2 = FileSize(fp2); if (FileSizeFile2 == -1) { - ResPrint(IDS_FILESIZEERROR, File2); + PrintResourceString(IDS_FILESIZEERROR, File2); Status = EXIT_FAILURE; goto Cleanup; }
if (FileSizeFile1 != FileSizeFile2) { - ResPrint(IDS_SIZEDIFFERS); + PrintResourceString(IDS_SIZEDIFFERS); Status = EXIT_FAILURE; goto Cleanup; } @@ -205,7 +209,7 @@
if (ferror(fp1) || ferror(fp2)) { - ResPrint(IDS_READERROR); + PrintResourceString(IDS_READERROR); Status = EXIT_FAILURE; goto Cleanup; } @@ -223,34 +227,34 @@ /* Reporting here a mismatch */ if (bLineNos) { - ResPrint(IDS_MISMATCHLINE, LineNumber); + PrintResourceString(IDS_MISMATCHLINE, LineNumber); } else { - ResPrint(IDS_MISMATCHOFFSET, Offset); + PrintResourceString(IDS_MISMATCHOFFSET, Offset); }
if (bAscii) { - ResPrint(IDS_ASCIIDIFF, 1, Buff1[i]); - ResPrint(IDS_ASCIIDIFF, 2, Buff2[i]); + PrintResourceString(IDS_ASCIIDIFF, 1, Buff1[i]); + PrintResourceString(IDS_ASCIIDIFF, 2, Buff2[i]); } else { - ResPrint(IDS_HEXADECIMALDIFF, 1, Buff1[i]); - ResPrint(IDS_HEXADECIMALDIFF, 2, Buff2[i]); - } - - Offset++; - - if (Buff1[i] == '\n') - LineNumber++; + PrintResourceString(IDS_HEXADECIMALDIFF, 1, Buff1[i]); + PrintResourceString(IDS_HEXADECIMALDIFF, 2, Buff2[i]); + } } - } + + Offset++; + + if (Buff1[i] == '\n') + LineNumber++; + } }
if (FilesOK) - ResPrint(IDS_MATCH); + PrintResourceString(IDS_MATCH);
Cleanup: if (fp2)
Modified: trunk/reactos/base/applications/cmdutils/comp/resource.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils/... ============================================================================== --- trunk/reactos/base/applications/cmdutils/comp/resource.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/cmdutils/comp/resource.h [iso-8859-1] Thu Jun 9 19:20:35 2016 @@ -1,4 +1,6 @@ #pragma once + +#define RC_STRING_MAX_SIZE 4096
#define IDS_HELP 100 #define IDS_INVALIDSWITCH 101