1 |
(* ***** BEGIN LICENSE BLOCK *****
|
2 |
* Version: MPL 1.1
|
3 |
*
|
4 |
* The contents of this file are subject to the Mozilla Public License Version
|
5 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
6 |
* the License. You may obtain a copy of the License at
|
7 |
* http://www.mozilla.org/MPL/
|
8 |
*
|
9 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
10 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
11 |
* for the specific language governing rights and limitations under the
|
12 |
* License.
|
13 |
*
|
14 |
* The Original Code is TurboPower SysTools
|
15 |
*
|
16 |
* The Initial Developer of the Original Code is
|
17 |
* TurboPower Software
|
18 |
*
|
19 |
* Portions created by the Initial Developer are Copyright (C) 1996-2002
|
20 |
* the Initial Developer. All Rights Reserved.
|
21 |
*
|
22 |
* Contributor(s):
|
23 |
*
|
24 |
* ***** END LICENSE BLOCK ***** *)
|
25 |
|
26 |
unit exregexu;
|
27 |
|
28 |
interface
|
29 |
|
30 |
uses
|
31 |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
32 |
StdCtrls, Buttons, StBase, StRegEx;
|
33 |
|
34 |
type
|
35 |
TForm1 = class(TForm)
|
36 |
Button1: TButton;
|
37 |
StRegEx1: TStRegEx;
|
38 |
gbOptions: TGroupBox;
|
39 |
cbSelect: TCheckBox;
|
40 |
cbIgnoreCase: TCheckBox;
|
41 |
edtSourceFile: TEdit;
|
42 |
Label1: TLabel;
|
43 |
sbSource: TSpeedButton;
|
44 |
OpenDialog1: TOpenDialog;
|
45 |
Label2: TLabel;
|
46 |
edtDestFile: TEdit;
|
47 |
sbDestination: TSpeedButton;
|
48 |
bntSelAvoid: TButton;
|
49 |
btnMatch: TButton;
|
50 |
btnReplace: TButton;
|
51 |
cbLineNumbers: TCheckBox;
|
52 |
Memo1: TMemo;
|
53 |
lblSelAvoid: TLabel;
|
54 |
lblMatch: TLabel;
|
55 |
lblReplace: TLabel;
|
56 |
cbxModOnly: TCheckBox;
|
57 |
cbxCountOnly: TCheckBox;
|
58 |
lblLPS: TLabel;
|
59 |
procedure SelectFile(Sender: TObject);
|
60 |
procedure bntSelAvoidClick(Sender: TObject);
|
61 |
procedure btnMatchClick(Sender: TObject);
|
62 |
procedure btnReplaceClick(Sender: TObject);
|
63 |
procedure Button1Click(Sender: TObject);
|
64 |
private
|
65 |
{ Private declarations }
|
66 |
|
67 |
public
|
68 |
{ Public declarations }
|
69 |
end;
|
70 |
|
71 |
var
|
72 |
Form1: TForm1;
|
73 |
|
74 |
implementation
|
75 |
|
76 |
uses
|
77 |
exregeu2;
|
78 |
|
79 |
{$R *.DFM}
|
80 |
|
81 |
procedure TForm1.SelectFile(Sender: TObject);
|
82 |
begin
|
83 |
if (Sender = sbSource) then begin
|
84 |
OpenDialog1.Title := 'Source File';
|
85 |
OpenDialog1.Options := OpenDialog1.Options + [ofFileMustExist];
|
86 |
if OpenDialog1.Execute then
|
87 |
edtSourceFile.Text := OpenDialog1.FileName;
|
88 |
end else begin
|
89 |
OpenDialog1.Title := 'Destination File';
|
90 |
OpenDialog1.Options := OpenDialog1.Options - [ofFileMustExist];
|
91 |
if OpenDialog1.Execute then
|
92 |
edtDestFile.Text := OpenDialog1.FileName;
|
93 |
end;
|
94 |
end;
|
95 |
|
96 |
procedure TForm1.bntSelAvoidClick(Sender: TObject);
|
97 |
begin
|
98 |
Form2 := TForm2.Create(Self);
|
99 |
try
|
100 |
Form2.Memo1.Clear;
|
101 |
Form2.Memo1.Lines.Assign(StRegEx1.SelAvoidPattern);
|
102 |
if (Form2.ShowModal = mrOK) then begin
|
103 |
StRegEx1.SelAvoidPattern.Clear;
|
104 |
StRegEx1.SelAvoidPattern.Assign(Form2.Memo1.Lines);
|
105 |
end;
|
106 |
finally
|
107 |
Form2.Free;
|
108 |
Form2 := nil;
|
109 |
end;
|
110 |
end;
|
111 |
|
112 |
procedure TForm1.btnMatchClick(Sender: TObject);
|
113 |
begin
|
114 |
Form2 := TForm2.Create(Self);
|
115 |
try
|
116 |
Form2.Memo1.Clear;
|
117 |
Form2.Memo1.Lines.Assign(StRegEx1.MatchPattern);
|
118 |
if (Form2.ShowModal = mrOK) then begin
|
119 |
StRegEx1.MatchPattern.Clear;
|
120 |
StRegEx1.MatchPattern.Assign(Form2.Memo1.Lines);
|
121 |
end;
|
122 |
finally
|
123 |
Form2.Free;
|
124 |
Form2 := nil;
|
125 |
end; Form2 := TForm2.Create(Self);
|
126 |
try
|
127 |
Form2.Memo1.Clear;
|
128 |
Form2.Memo1.Lines.Assign(StRegEx1.SelAvoidPattern);
|
129 |
if (Form2.ShowModal = mrOK) then begin
|
130 |
StRegEx1.SelAvoidPattern.Clear;
|
131 |
StRegEx1.SelAvoidPattern.Assign(Form2.Memo1.Lines);
|
132 |
end;
|
133 |
finally
|
134 |
Form2.Free;
|
135 |
Form2 := nil;
|
136 |
end;
|
137 |
end;
|
138 |
|
139 |
procedure TForm1.btnReplaceClick(Sender: TObject);
|
140 |
begin
|
141 |
Form2 := TForm2.Create(Self);
|
142 |
try
|
143 |
Form2.Memo1.Clear;
|
144 |
Form2.Memo1.Lines.Assign(StRegEx1.ReplacePattern);
|
145 |
if (Form2.ShowModal = mrOK) then begin
|
146 |
StRegEx1.ReplacePattern.Clear;
|
147 |
StRegEx1.ReplacePattern.Assign(Form2.Memo1.Lines);
|
148 |
end;
|
149 |
finally
|
150 |
Form2.Free;
|
151 |
Form2 := nil;
|
152 |
end;
|
153 |
end;
|
154 |
|
155 |
|
156 |
procedure TForm1.Button1Click(Sender: TObject);
|
157 |
begin
|
158 |
(*
|
159 |
// WindowState := wsMinimized;
|
160 |
// StRegEx1.SelAvoidPattern.Clear;
|
161 |
// StRegEx1.SelAvoidPattern.Add('((Hex)|(Word))');
|
162 |
*)
|
163 |
StRegEx1.MatchPattern.Clear;
|
164 |
StRegEx1.MatchPattern.Add('function');
|
165 |
(*
|
166 |
// StRegEx1.MatchPattern.Add('^{.+[^s]}\s*');
|
167 |
// StRegEx1.MatchPattern.Add('(procedure)|(function)');
|
168 |
*)
|
169 |
(*
|
170 |
StRegEx1.ReplacePattern.Clear;
|
171 |
StRegEx1.ReplacePattern.Add('\1');
|
172 |
*)
|
173 |
if (Trim(edtSourceFile.Text) = '') or (Trim(edtDestFile.Text) = '') then begin
|
174 |
MessageDlg('Source and/or Destination file cannot be blank',
|
175 |
mtError, [mbOK], 0);
|
176 |
Exit;
|
177 |
end;
|
178 |
|
179 |
if not (FileExists(edtSourceFile.Text)) then begin
|
180 |
MessageDlg('Source file not found', mtError, [mbOK], 0);
|
181 |
Exit;
|
182 |
end;
|
183 |
|
184 |
if (StRegEx1.SelAvoidPattern.Count = 0) and
|
185 |
(StRegEx1.MatchPattern.Count = 0) then begin
|
186 |
MessageDlg('You must specify a SelAvoid or Match Pattern',
|
187 |
mtError, [mbOK], 0);
|
188 |
Exit;
|
189 |
end;
|
190 |
|
191 |
StRegEx1.IgnoreCase := cbIgnoreCase.Checked;
|
192 |
StRegEx1.Avoid := not cbSelect.Checked;
|
193 |
StRegEx1.LineNumbers := cbLineNumbers.Checked;
|
194 |
StRegEx1.InputFile := edtSourceFile.Text;
|
195 |
StRegEx1.OutputFile := edtDestFile.Text;
|
196 |
if cbxModOnly.Checked then
|
197 |
StRegEx1.OutputOptions := StRegEx1.OutputOptions + [ooModifiedOnly]
|
198 |
else
|
199 |
StRegEx1.OutputOptions := StRegEx1.OutputOptions - [ooModifiedOnly];
|
200 |
if cbxCountOnly.Checked then
|
201 |
StRegEx1.OutputOptions := StRegEx1.OutputOptions + [ooCountOnly]
|
202 |
else
|
203 |
StRegEx1.OutputOptions := StRegEx1.OutputOptions - [ooCountOnly];
|
204 |
|
205 |
lblSelAvoid.Caption := 'Sel/Avoid: 0';
|
206 |
lblMatch.Caption := 'Match: 0';
|
207 |
lblReplace.Caption := 'ReplaceL 0';
|
208 |
lblLPS.Caption := 'Lines/Sec: 0';
|
209 |
|
210 |
StRegEx1.Execute;
|
211 |
|
212 |
Memo1.Clear;
|
213 |
Memo1.Lines.LoadFromFile(edtDestFile.Text);
|
214 |
|
215 |
lblSelAvoid.Caption := 'Sel/Avoid: ' + IntToStr(StRegEx1.LinesSelected);
|
216 |
lblMatch.Caption := 'Match: ' + IntToStr(StRegEx1.LinesMatched);
|
217 |
lblReplace.Caption := 'Replace: ' + IntToStr(StRegEx1.LinesReplaced);
|
218 |
lblLPS.Caption := 'Lines/Sec: ' + IntToStr(StRegEx1.LinesPerSecond);
|
219 |
end;
|
220 |
|
221 |
end.
|