~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to compiler/utils/usubst.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{$mode objfpc}
 
2
{$H+}
 
3
{
 
4
    $Id: usubst.pp,v 1.1 2005/02/05 10:25:30 peter Exp $
 
5
    This file is part of Free Pascal build tools
 
6
    Copyright (c) 2005 by Michael Van Canneyt
 
7
 
 
8
    Implements string substitutions
 
9
 
 
10
    See the file COPYING.FPC, included in this distribution,
 
11
    for details about the copyright.
 
12
 
 
13
    This program is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
16
 
 
17
 **********************************************************************}
 
18
unit usubst;
 
19
 
 
20
interface
 
21
 
 
22
uses SysUtils,Classes;
 
23
 
 
24
// Add N=V pair to list.
 
25
Procedure AddToList(List : TStrings; Const N,V : String);
 
26
// Split NV to N/V and call AddToList
 
27
Function  AddPair(List : TStrings; Const NV : String) : Boolean;
 
28
// Perform substitutions in S, from List.
 
29
Function  DoSubStitutions(List : TStrings; Var S : String) : Integer;
 
30
 
 
31
implementation
 
32
 
 
33
Procedure AddToList(List : TStrings; Const N,V : String);
 
34
 
 
35
var
 
36
  I : Integer;
 
37
 
 
38
begin
 
39
  I:=List.IndexOfName(N);
 
40
  If (V='') then
 
41
    begin
 
42
    If (I<>-1) then
 
43
      List.Delete(I)
 
44
    end
 
45
  else
 
46
    begin
 
47
    If (I=-1) then
 
48
      List.Add(N+'='+V)
 
49
    else
 
50
      List[I]:=N+'='+V;
 
51
    end;
 
52
end;
 
53
 
 
54
Function AddPair(List : TStrings; Const NV : String) : Boolean;
 
55
 
 
56
Var
 
57
  P,I : Integer;
 
58
  N,V : string;
 
59
 
 
60
begin
 
61
  P:=Pos('=',NV);
 
62
  Result:=(P<>0);
 
63
  If Result then
 
64
    begin
 
65
    V:=NV;
 
66
    N:=Copy(V,1,P-1);
 
67
    Delete(V,1,P);
 
68
    AddToList(List,N,V);
 
69
    end;
 
70
end;
 
71
 
 
72
Function DoSubstitutions(List : TStrings; Var S : String) : Integer;
 
73
 
 
74
Var
 
75
  N,T : String;
 
76
  P : Integer;
 
77
 
 
78
begin
 
79
  Result:=0;
 
80
  T:=S;
 
81
  S:='';
 
82
  P:=Pos('%',T);
 
83
  While (P>0) do
 
84
    begin
 
85
    S:=S+Copy(T,1,P-1);
 
86
    Delete(T,1,P);
 
87
    If (Length(T)>0) then
 
88
      if (T[1]='%') then
 
89
        begin
 
90
        S:=S+'%';
 
91
        Delete(T,1,1);
 
92
        end
 
93
      else
 
94
        begin
 
95
        P:=Pos('%',T);
 
96
        If (P=0) then
 
97
          S:=S+'%'
 
98
        else
 
99
          begin
 
100
          N:=Copy(T,1,P-1);
 
101
          Delete(T,1,P);
 
102
          S:=S+List.Values[N];
 
103
          end;
 
104
        end;
 
105
    P:=Pos('%',T);
 
106
    end;
 
107
  S:=S+T;
 
108
end;
 
109
 
 
110
end.
 
111
{
 
112
  $Log: usubst.pp,v $
 
113
  Revision 1.1  2005/02/05 10:25:30  peter
 
114
    * move tools to compiler/utils/
 
115
 
 
116
  Revision 1.2  2005/01/09 15:19:03  peter
 
117
    * fix linebreak
 
118
 
 
119
  Revision 1.1  2005/01/09 13:36:12  michael
 
120
  + Initial implementation of installer tools
 
121
 
 
122
 
 
123
}
 
124
 
 
125