mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[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. svn path=/trunk/; revision=71601
This commit is contained in:
parent
732c3f3d40
commit
25c377e044
2 changed files with 62 additions and 56 deletions
|
@ -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, ...)
|
||||
VOID PrintResourceString(INT resID, ...)
|
||||
{
|
||||
TCHAR * res_string;
|
||||
va_list vargs;
|
||||
WCHAR bufSrc[RC_STRING_MAX_SIZE];
|
||||
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))
|
||||
{
|
||||
_vtprintf(res_string, vargs);
|
||||
}
|
||||
if (LoadStringW(GetModuleHandleW(NULL), resID, bufSrc, ARRAYSIZE(bufSrc)))
|
||||
vswprintf(bufFormatted, bufSrc, args);
|
||||
else
|
||||
{
|
||||
_tprintf(_T("Resource loading error!"));
|
||||
}
|
||||
swprintf(bufFormatted, L"Resource loading error!");
|
||||
|
||||
va_end(vargs);
|
||||
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 @@ INT FileSize(FILE * fd)
|
|||
/* Print program usage */
|
||||
VOID Usage(VOID)
|
||||
{
|
||||
ResPrint(IDS_HELP);
|
||||
PrintResourceString(IDS_HELP);
|
||||
}
|
||||
|
||||
|
||||
int _tmain (int argc, TCHAR *argv[])
|
||||
int wmain (int argc, WCHAR* argv[])
|
||||
{
|
||||
INT i;
|
||||
|
||||
|
@ -89,7 +94,7 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
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
|
||||
|
@ -104,26 +109,26 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
/* 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 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
|
||||
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 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
Buff2 = (PBYTE)malloc(STRBUF);
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
|
||||
ResPrint(IDS_COMPARING, File1, File2);
|
||||
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 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
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 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
|
||||
if (ferror(fp1) || ferror(fp2))
|
||||
{
|
||||
ResPrint(IDS_READERROR);
|
||||
PrintResourceString(IDS_READERROR);
|
||||
Status = EXIT_FAILURE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
@ -223,22 +227,23 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
/* 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]);
|
||||
PrintResourceString(IDS_HEXADECIMALDIFF, 1, Buff1[i]);
|
||||
PrintResourceString(IDS_HEXADECIMALDIFF, 2, Buff2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Offset++;
|
||||
|
@ -247,10 +252,9 @@ int _tmain (int argc, TCHAR *argv[])
|
|||
LineNumber++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FilesOK)
|
||||
ResPrint(IDS_MATCH);
|
||||
PrintResourceString(IDS_MATCH);
|
||||
|
||||
Cleanup:
|
||||
if (fp2)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#define RC_STRING_MAX_SIZE 4096
|
||||
|
||||
#define IDS_HELP 100
|
||||
#define IDS_INVALIDSWITCH 101
|
||||
#define IDS_BADSYNTAX 102
|
||||
|
|
Loading…
Reference in a new issue