~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/ide/utils/grep2msg.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{************************************************}
 
2
{                                                }
 
3
{   Grep message filter example                  }
 
4
{   Copyright (c) 1992 by Borland International  }
 
5
{                                                }
 
6
{************************************************}
 
7
 
 
8
program Grep2Msg;
 
9
 
 
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.
 
15
}
 
16
 
 
17
{$I-,S-}
 
18
 
 
19
var
 
20
  LineNo, E: Word;
 
21
  P1,P2: integer;
 
22
  Line: String;
 
23
  InputBuffer: array[0..4095] of Char;
 
24
  OutputBuffer: array[0..4095] of Char;
 
25
 
 
26
 
 
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.
 
29
}
 
30
procedure WriteHeader;
 
31
begin
 
32
  Write('BI#PIP#OK'#0);
 
33
end;
 
34
 
 
35
{ The beginning of a new file is marked by a #0, the file's name, terminated
 
36
  by a #0 character.
 
37
}
 
38
procedure WriteNewFile(const FileName: String);
 
39
begin
 
40
  Write(#0, FileName, #0);
 
41
end;
 
42
 
 
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.
 
46
}
 
47
procedure WriteMessage(Line, Col: Word; const Message: String);
 
48
begin
 
49
  Write(#1, Chr(Lo(Line)), Chr(Hi(Line)), Chr(Lo(Col)), Chr(Hi(Col)),
 
50
    Message, #0);
 
51
end;
 
52
 
 
53
{ The end of the input stream is marked by a #127 character }
 
54
procedure WriteEnd;
 
55
begin
 
56
  Write(#127);
 
57
end;
 
58
 
 
59
function TrimLeft(S:String): String;
 
60
var
 
61
  i: Integer;
 
62
  n: String;
 
63
begin
 
64
  i := 1;
 
65
  while (i <= Length(s)) and (s[i] = #32) do Inc(i);
 
66
  if i <= Length(s) then
 
67
  begin
 
68
    Move(s[i], n[1], Length(s) - i + 1);
 
69
    n[0] := Char(Length(s) - i + 1);
 
70
  end
 
71
  else n[0] := #0;
 
72
  TrimLeft := n;
 
73
end;
 
74
 
 
75
const LastFileName: string = '';
 
76
 
 
77
begin
 
78
  SetTextBuf(Input, InputBuffer);
 
79
  SetTextBuf(Output, OutputBuffer);
 
80
  WriteHeader;
 
81
  while not Eof do
 
82
  begin
 
83
    ReadLn(Line);
 
84
    if Line <> '' then
 
85
    begin
 
86
      P1:=Pos(':',Line);
 
87
      if copy(Line, 1, P1)<>LastFileName then
 
88
        begin
 
89
          LastFileName:=copy(Line,1,P1-1);
 
90
          WriteNewFile(LastFileName);
 
91
        end;
 
92
      P2:=Pos(':',copy(Line,P1+1,255));
 
93
      if P2>0 then
 
94
      begin
 
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)));
 
97
      end;
 
98
    end;
 
99
  end;
 
100
  WriteEnd;
 
101
end.