Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/upstream' into litezarus
Browse files Browse the repository at this point in the history
  • Loading branch information
x2nie committed May 30, 2014
2 parents 942bde2 + 04e2d27 commit 7efe582
Show file tree
Hide file tree
Showing 78 changed files with 3,995 additions and 1,623 deletions.
46 changes: 43 additions & 3 deletions components/codetools/codetoolsfpcmsgs.pas
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ TFPCMsgFile = class
function MsgTypToSpecialItem(const Typ: string): TFPCMsgItem;
end;

function CompareFPCMsgId(item1, item2: Pointer): integer;
function CompareIDWithFPCMsgId(PtrID, Item: Pointer): integer;

type
TFPCMsgRange = record
StartPos: integer;
Expand All @@ -128,7 +125,39 @@ TFPCMsgRanges = class
destructor Destroy; override;
end;

type
TFPCMsgFileToEncoding = record
Filename: PChar;
Encoding: PChar;
end;
const
FPCMsgFileToEncoding: array[1..20] of TFPCMsgFileToEncoding = (
(Filename: 'errorct.msg'; Encoding: 'CP1252'), // Catalan
(Filename: 'errord.msg'; Encoding: 'CP437'), // German
(Filename: 'errorda.msg'; Encoding: 'UTF-8'), // Danish
(Filename: 'errordu.msg'; Encoding: 'UTF-8'), // German
(Filename: 'errore.msg'; Encoding: 'UTF-8'), // English
(Filename: 'errores.msg'; Encoding: 'CP1252'), // Spanish
(Filename: 'errorf.msg'; Encoding: 'CP850'), // French
(Filename: 'errorfi.msg'; Encoding: 'ISO-8859-1'), // French
(Filename: 'errorhe.msg'; Encoding: 'CP1255'), // Hebrew
(Filename: 'errorheu.msg'; Encoding: 'UTF-8'), // Hebrew
(Filename: 'errorid.msg'; Encoding: 'UTF-8'), // Indonesian
(Filename: 'erroriu.msg'; Encoding: 'CP1252'), // Italian
(Filename: 'errorn.msg'; Encoding: 'CP850'), // Dutch
(Filename: 'errorpl.msg'; Encoding: 'CP852'), // Polish
(Filename: 'errorpli.msg'; Encoding: 'ISO-8859-2'), // Polish
(Filename: 'errorpt.msg'; Encoding: 'CP850'), // Portuguese
(Filename: 'errorptu.msg'; Encoding: 'UTF-8'), // Portuguese
(Filename: 'errorr.msg'; Encoding: 'CP866'), // Russian
(Filename: 'errorru.msg'; Encoding: 'UTF-8'), // Russian
(Filename: 'errorues.msg'; Encoding: 'UTF-8') // Spanish
);

function CompareFPCMsgId(item1, item2: Pointer): integer;
function CompareIDWithFPCMsgId(PtrID, Item: Pointer): integer;
procedure ExtractFPCMsgParameters(const Mask, Txt: string; var Ranges: TFPCMsgRanges);
function GetDefaultFPCErrorMsgFileEncoding(Filename: string): string;

function dbgs(i: TfmiSpecialItem): string; overload;

Expand Down Expand Up @@ -236,6 +265,17 @@ procedure ExtractFPCMsgParameters(const Mask, Txt: string;
end;
end;

function GetDefaultFPCErrorMsgFileEncoding(Filename: string): string;
var
i: Integer;
begin
Filename:=ExtractFileNameOnly(Filename);
for i:=low(FPCMsgFileToEncoding) to high(FPCMsgFileToEncoding) do
if FPCMsgFileToEncoding[i].Filename=Filename then
exit(FPCMsgFileToEncoding[i].Encoding);
Result:='';
end;

function dbgs(i: TfmiSpecialItem): string;
begin
case i of
Expand Down
7 changes: 5 additions & 2 deletions components/codetools/definetemplates.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8511,9 +8511,12 @@ function TFPCDefinesCache.GetFPCVersion(const CompilerFilename, TargetOS,
Result:={$I %FPCVersion%}
else
Result:='';
if not IsFPCExecutable(CompilerFilename,ErrorMsg) then exit;
if not IsFPCExecutable(CompilerFilename,ErrorMsg) then
exit;
CfgCache:=ConfigCaches.Find(CompilerFilename,ExtraOptions,TargetOS,TargetCPU,true);
if not CfgCache.Update(TestFilename,ExtraOptions) then exit;
if CfgCache.NeedsUpdate
and not CfgCache.Update(TestFilename,ExtraOptions) then
exit;
if CfgCache.FullVersion='' then exit;
Result:=CfgCache.FullVersion;
end;
Expand Down
77 changes: 77 additions & 0 deletions components/codetools/examples/scanfpcerrormsgfiles.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<General>
<Flags>
<SaveClosedFiles Value="False"/>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<SaveFoldState Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="scanfpcerrormsgfiles"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="CodeTools"/>
</Item1>
</RequiredPackages>
<Units Count="1">
<Unit0>
<Filename Value="scanfpcerrormsgfiles.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="scanfpcerrormsgfiles"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="scanfpcerrormsgfiles"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>
156 changes: 156 additions & 0 deletions components/codetools/examples/scanfpcerrormsgfiles.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
Author: Mattias Gaertner
Abstract:
Scan all FPC error message files (fpc/compiler/msg/error*.msg) and compare
them with the original file (english, errore.msg).
}
program scanfpcerrormsgfiles;

{$mode objfpc}{$H+}

uses
Classes, sysutils, CodeToolsFPCMsgs, CodeToolsStructs, LazFileUtils;

procedure WriteUsage;
begin
writeln('Usage:');
writeln;
writeln(' ',ParamStr(0),' <fpcsrcdirectory>/compiler/msg [-v]');
writeln('');
writeln(' -v - verbose output, showing exactly what messages are missing and/or mismatched');
end;

type
THaveParams = array[0..9] of boolean;

procedure GetHaveParams(Pattern: string; out Params: THaveParams);
var
i: integer;
p: PChar;
begin
for i:=0 to 9 do
Params[i]:=false;
p:=PChar(Pattern);
repeat
case p^ of
#0: break;
'$':
if p[1] in ['0'..'9'] then begin
inc(p);
Params[ord(p^)-ord('0')]:=true;
end;
end;
inc(p);
until false;
end;

procedure ScanDir(Dir: string; ShowVerbose: Boolean = false );
var
Info: TSearchRec;
Filename: TFilename;
aFile: TFPCMsgFile;
FPCMsgFileList: TFilenameToPointerTree;
EnglishFile: TFPCMsgFile;
S2PItem: PStringToPointerTreeItem;
i: Integer;
EnglishMsg: TFPCMsgItem;
TranslatedMsg: TFPCMsgItem;
GoodCount: Integer;
MissingCount: Integer;
MismatchCount: Integer;
EnglishParams, TranslatedParams: THaveParams;
k: integer;
msd: String;
begin
FPCMsgFileList:=TFilenameToPointerTree.Create(false);
FPCMsgFileList.FreeValues:=true;
try
// search *.msg files
Dir:=AppendPathDelim(Dir);
if not FindFirstUTF8(Dir+'*.msg',faAnyFile,Info)=0 then begin
writeln('Error: no *.msg file found in ',Dir);
Halt(3);
end;

// load all *.msg files
EnglishFile:=nil;
repeat
Filename:=Info.Name;
if (Filename='') or (Filename='.') or (Filename='..') then continue;
if faDirectory and Info.Attr>0 then continue;
//writeln('loading "',Filename,'" ...');
aFile:=TFPCMsgFile.Create;
aFile.LoadFromFile(Dir+Filename);
if Filename='errore.msg' then
EnglishFile:=aFile
else
FPCMsgFileList[Filename]:=aFile;
until FindNextUTF8(Info)<>0;
FindCloseUTF8(Info);

if EnglishFile=nil then begin
writeln('Error: missing file errore.msg');
Halt(4);
end;

// compare each file with errore
writeln('errore.msg Count=',EnglishFile.Count);
for S2PItem in FPCMsgFileList do begin
Filename:=S2PItem^.Name;
aFile:=TFPCMsgFile(S2PItem^.Value);
GoodCount:=0;
MissingCount:=0;
MismatchCount:=0; // id is there, but $ parameters don't fit
msd:='';
for i:=0 to EnglishFile.Count-1 do begin
EnglishMsg:=EnglishFile[i];
TranslatedMsg:=aFile.FindWithID(EnglishMsg.ID);
if TranslatedMsg=nil then begin
inc(MissingCount);
if ShowVerbose then msd:=msd+' missing: '+IntToStr(EnglishMsg.ID)+' '+EnglishMsg.Pattern+LineEnding;
end else begin
GetHaveParams(EnglishMsg.Pattern,EnglishParams);
GetHaveParams(TranslatedMsg.Pattern,TranslatedParams);
k:=9;
while (k>=0) and (EnglishParams[k]=TranslatedParams[k]) do
dec(k);
if k<0 then
inc(GoodCount)
else begin
//writeln('Mismatch in ',Filename,' English="',EnglishMsg.Pattern,'" Translated="',TranslatedMsg.Pattern,'"');
inc(MismatchCount);
if ShowVerbose then begin
msd:=msd+' mismatch: '+LineEnding;
msd:=msd+' eng: '+EnglishMsg.Pattern+LineEnding;
msd:=msd+' trn: '+TranslatedMsg.Pattern+LineEnding;
end;
end;
end;
end;
writeln(Filename,' Count=',aFile.Count,' Good=',GoodCount,' Missing=',MissingCount,' Mismatch=',MismatchCount);
if ShowVerbose then write(msd);
end;

finally
FPCMsgFileList.Free;
end;
end;

var
MsgDir: String;
ShowVerbose: Boolean = false;
begin
if ParamCount<1 then begin
WriteUsage;
Halt(1);
end;
MsgDir:=CleanAndExpandDirectory(ParamStr(1));
if not DirPathExists(MsgDir) then begin
writeln('Error: directory not found: ',MsgDir);
Halt(2);
end;
ShowVerbose:=(ParamCount>1) and (LowerCase(ParamStr(2))='-v');
ScanDir(MsgDir, ShowVerbose);
end.

Loading

0 comments on commit 7efe582

Please sign in to comment.