- 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.

svn path=/trunk/; revision=71601
This commit is contained in:
Hermès Bélusca-Maïto 2016-06-09 19:20:35 +00:00
parent 732c3f3d40
commit 25c377e044
2 changed files with 62 additions and 56 deletions

View file

@ -24,43 +24,48 @@
* PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com) * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
*/ */
#include <windows.h>
#include <tchar.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> // #include <string.h>
// #include <wchar.h>
#include <assert.h> #include <assert.h>
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include "resource.h" #include "resource.h"
#define STRBUF 1024 #define STRBUF 1024
VOID ResPrint(INT res_no, ...) VOID PrintResourceString(INT resID, ...)
{ {
TCHAR * res_string; WCHAR bufSrc[RC_STRING_MAX_SIZE];
va_list vargs; WCHAR bufFormatted[RC_STRING_MAX_SIZE];
CHAR bufFormattedOem[RC_STRING_MAX_SIZE];
va_start(vargs, res_no); va_list args;
va_start(args, resID);
if (LoadString(GetModuleHandle(NULL), res_no, (TCHAR*)&res_string, 0)) if (LoadStringW(GetModuleHandleW(NULL), resID, bufSrc, ARRAYSIZE(bufSrc)))
{ vswprintf(bufFormatted, bufSrc, args);
_vtprintf(res_string, vargs);
}
else else
{ swprintf(bufFormatted, L"Resource loading error!");
_tprintf(_T("Resource loading error!"));
}
va_end(vargs); CharToOemW(bufFormatted, bufFormattedOem);
fputs(bufFormattedOem, stdout);
va_end(args);
} }
/* getline: read a line, return length */ /* 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); return fread(buff, sizeof(BYTE), STRBUF, in);
} }
INT FileSize(FILE * fd) INT FileSize(FILE* fd)
{ {
INT result = -1; INT result = -1;
if (fseek(fd, 0, SEEK_END) == 0 && (result = ftell(fd)) != -1) if (fseek(fd, 0, SEEK_END) == 0 && (result = ftell(fd)) != -1)
@ -74,11 +79,11 @@ INT FileSize(FILE * fd)
/* Print program usage */ /* Print program usage */
VOID Usage(VOID) VOID Usage(VOID)
{ {
ResPrint(IDS_HELP); PrintResourceString(IDS_HELP);
} }
int _tmain (int argc, TCHAR *argv[]) int wmain (int argc, WCHAR* argv[])
{ {
INT i; INT i;
@ -89,7 +94,7 @@ int _tmain (int argc, TCHAR *argv[])
INT BufLen1, BufLen2; INT BufLen1, BufLen2;
PBYTE Buff1 = NULL; PBYTE Buff1 = NULL;
PBYTE Buff2 = NULL; PBYTE Buff2 = NULL;
TCHAR File1[_MAX_PATH + 1], // File paths WCHAR File1[_MAX_PATH + 1], // File paths
File2[_MAX_PATH + 1]; File2[_MAX_PATH + 1];
BOOL bAscii = FALSE, // /A switch BOOL bAscii = FALSE, // /A switch
bLineNos = FALSE; // /L switch bLineNos = FALSE; // /L switch
@ -104,26 +109,26 @@ int _tmain (int argc, TCHAR *argv[])
/* Parse command line for options */ /* Parse command line for options */
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (argv[i][0] == _T('/')) if (argv[i][0] == L'/')
{ {
switch (argv[i][1]) switch (argv[i][1])
{ {
case _T('A'): case L'A':
bAscii = TRUE; bAscii = TRUE;
NumberOfOptions++; NumberOfOptions++;
break; break;
case _T('L'): case L'L':
bLineNos = TRUE; bLineNos = TRUE;
NumberOfOptions++; NumberOfOptions++;
break; break;
case _T('?'): case L'?':
Usage(); Usage();
return EXIT_SUCCESS; return EXIT_SUCCESS;
default: default:
ResPrint(IDS_INVALIDSWITCH, argv[i][1]); PrintResourceString(IDS_INVALIDSWITCH, argv[i][1]);
Usage(); Usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -132,19 +137,19 @@ int _tmain (int argc, TCHAR *argv[])
if (argc - NumberOfOptions == 3) if (argc - NumberOfOptions == 3)
{ {
_tcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH); wcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH);
_tcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH); wcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH);
} }
else else
{ {
ResPrint(IDS_BADSYNTAX); PrintResourceString(IDS_BADSYNTAX);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
Buff1 = (PBYTE)malloc(STRBUF); Buff1 = (PBYTE)malloc(STRBUF);
if (Buff1 == NULL) 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; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
@ -152,31 +157,30 @@ int _tmain (int argc, TCHAR *argv[])
Buff2 = (PBYTE)malloc(STRBUF); Buff2 = (PBYTE)malloc(STRBUF);
if (Buff2 == NULL) if (Buff2 == NULL)
{ {
_tprintf(_T("Can't get free memory for Buff2\n")); wprintf(L"Can't get free memory for Buff2\n");
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
if ((fp1 = _tfopen(File1, _T("rb"))) == NULL) if ((fp1 = _wfopen(File1, L"rb")) == NULL)
{ {
ResPrint(IDS_FILEERROR, File1); PrintResourceString(IDS_FILEERROR, File1);
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
if ((fp2 = _tfopen(File2, _T("rb"))) == NULL) if ((fp2 = _wfopen(File2, L"rb")) == NULL)
{ {
ResPrint(IDS_FILEERROR, File2); PrintResourceString(IDS_FILEERROR, File2);
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
PrintResourceString(IDS_COMPARING, File1, File2);
ResPrint(IDS_COMPARING, File1, File2);
FileSizeFile1 = FileSize(fp1); FileSizeFile1 = FileSize(fp1);
if (FileSizeFile1 == -1) if (FileSizeFile1 == -1)
{ {
ResPrint(IDS_FILESIZEERROR, File1); PrintResourceString(IDS_FILESIZEERROR, File1);
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
@ -184,14 +188,14 @@ int _tmain (int argc, TCHAR *argv[])
FileSizeFile2 = FileSize(fp2); FileSizeFile2 = FileSize(fp2);
if (FileSizeFile2 == -1) if (FileSizeFile2 == -1)
{ {
ResPrint(IDS_FILESIZEERROR, File2); PrintResourceString(IDS_FILESIZEERROR, File2);
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
if (FileSizeFile1 != FileSizeFile2) if (FileSizeFile1 != FileSizeFile2)
{ {
ResPrint(IDS_SIZEDIFFERS); PrintResourceString(IDS_SIZEDIFFERS);
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
@ -205,7 +209,7 @@ int _tmain (int argc, TCHAR *argv[])
if (ferror(fp1) || ferror(fp2)) if (ferror(fp1) || ferror(fp2))
{ {
ResPrint(IDS_READERROR); PrintResourceString(IDS_READERROR);
Status = EXIT_FAILURE; Status = EXIT_FAILURE;
goto Cleanup; goto Cleanup;
} }
@ -223,22 +227,23 @@ int _tmain (int argc, TCHAR *argv[])
/* Reporting here a mismatch */ /* Reporting here a mismatch */
if (bLineNos) if (bLineNos)
{ {
ResPrint(IDS_MISMATCHLINE, LineNumber); PrintResourceString(IDS_MISMATCHLINE, LineNumber);
} }
else else
{ {
ResPrint(IDS_MISMATCHOFFSET, Offset); PrintResourceString(IDS_MISMATCHOFFSET, Offset);
} }
if (bAscii) if (bAscii)
{ {
ResPrint(IDS_ASCIIDIFF, 1, Buff1[i]); PrintResourceString(IDS_ASCIIDIFF, 1, Buff1[i]);
ResPrint(IDS_ASCIIDIFF, 2, Buff2[i]); PrintResourceString(IDS_ASCIIDIFF, 2, Buff2[i]);
} }
else else
{ {
ResPrint(IDS_HEXADECIMALDIFF, 1, Buff1[i]); PrintResourceString(IDS_HEXADECIMALDIFF, 1, Buff1[i]);
ResPrint(IDS_HEXADECIMALDIFF, 2, Buff2[i]); PrintResourceString(IDS_HEXADECIMALDIFF, 2, Buff2[i]);
}
} }
Offset++; Offset++;
@ -247,10 +252,9 @@ int _tmain (int argc, TCHAR *argv[])
LineNumber++; LineNumber++;
} }
} }
}
if (FilesOK) if (FilesOK)
ResPrint(IDS_MATCH); PrintResourceString(IDS_MATCH);
Cleanup: Cleanup:
if (fp2) if (fp2)

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#define RC_STRING_MAX_SIZE 4096
#define IDS_HELP 100 #define IDS_HELP 100
#define IDS_INVALIDSWITCH 101 #define IDS_INVALIDSWITCH 101
#define IDS_BADSYNTAX 102 #define IDS_BADSYNTAX 102