2
***************************************************************************
4
* This source is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This code is distributed in the hope that it will be useful, but *
10
* WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12
* General Public License for more details. *
14
* A copy of the GNU General Public License is available on the World *
15
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
16
* obtain it by writing to the Free Software Foundation, *
17
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************
21
Author: Mattias Gaertner
24
Demo for parsing fpc compiler/msg/error*.msg files.
31
Classes, SysUtils, FileProcs,
32
CodeToolManager, CodeCache, CodeToolsFPCMsgs;
44
if Paramcount<>1 then begin
45
writeln('Usage: '+ParamStr(0)+' fpc_file_errore.msg');
49
Filename:=TrimAndExpandFilename(ParamStrUTF8(1));
52
Code:=CodeToolBoss.LoadFile(Filename,false,false);
54
raise Exception.Create('unable to read '+Filename);
56
MsgFile:=TFPCMsgFile.Create;
57
MsgFile.LoadFromText(Code.Source);
58
for s:=succ(fmisiNone) to high(TfmiSpecialItem) do
59
if MsgFile.SpecialItems[s]=nil then
60
raise Exception.Create('special message '+dbgs(s)+' is missing');
62
// check a specific message
63
Item:=MsgFile.FindWithID(1009);
64
Msg:=MsgFile.GetMsgText(Item);
65
if MsgFile.PatternFits(Item,Msg)<0 then begin
66
writeln('message does not fit itself: ',Item.GetName,'="',Item.Pattern,'"');
68
writeln('Fits=',MsgFile.PatternFits(Item,Msg));
69
raise Exception.Create('bug?');
72
for i:=0 to MsgFile.Count-1 do begin
74
Msg:=MsgFile.GetMsgText(Item);
75
Found:=MsgFile.FindWithMessage(Msg);
76
if Found=nil then begin
77
// this should never happen
78
writeln('message does not fit itself: i=',i,
79
' MsgFile[i]=',Item.GetName,'="',Item.Pattern,'"');
81
writeln('Fits=',Item.PatternFits(Msg));
82
raise Exception.Create('bug?');
83
end else if Found<>Item then begin
84
writeln('message pattern is ambiguous: i=',i,
85
' MsgFile[i]=',Item.GetName,'="',Item.Pattern,'"',
86
' Other=',Found.GetName,'="',Found.Pattern,'"');