1
{************************************************}
3
{ Grep message filter example }
4
{ Copyright (c) 1992 by Borland International }
6
{************************************************}
10
{ Message filters read input from the target program (in this case, GREP)
11
by way of StdIn (by using Read or ReadLn), filter the input, then write
12
output back to StdOut (using Write or WriteLn). The IDE takes care of
13
redirecting the transfer program's output to the filter program, as well
14
as redirecting the filter program's output back to the IDE itself.
23
InputBuffer: array[0..4095] of Char;
24
OutputBuffer: array[0..4095] of Char;
27
{ The first data passed back to the IDE by a message filter must always
28
be the string 'BI#PIP#OK', followed by a null terminator.
30
procedure WriteHeader;
35
{ The beginning of a new file is marked by a #0, the file's name, terminated
38
procedure WriteNewFile(const FileName: String);
40
Write(#0, FileName, #0);
43
{ Each message line begins with a #1, followed the line number (in low/high
44
order), followed by the column number (in low/high order), then the
45
message text itself, terminated with a #0 character.
47
procedure WriteMessage(Line, Col: Word; const Message: String);
49
Write(#1, Chr(Lo(Line)), Chr(Hi(Line)), Chr(Lo(Col)), Chr(Hi(Col)),
53
{ The end of the input stream is marked by a #127 character }
59
function TrimLeft(S:String): String;
65
while (i <= Length(s)) and (s[i] = #32) do Inc(i);
66
if i <= Length(s) then
68
Move(s[i], n[1], Length(s) - i + 1);
69
n[0] := Char(Length(s) - i + 1);
75
const LastFileName: string = '';
78
SetTextBuf(Input, InputBuffer);
79
SetTextBuf(Output, OutputBuffer);
87
if copy(Line, 1, P1)<>LastFileName then
89
LastFileName:=copy(Line,1,P1-1);
90
WriteNewFile(LastFileName);
92
P2:=Pos(':',copy(Line,P1+1,255));
95
Val(Copy(Line, P1+1, P2-1), LineNo, E);
96
if E = 0 then WriteMessage(LineNo, 1, TrimLeft(Copy(Line, P1+1+P2, 132)));