1 |
torben |
2671 |
// Upgraded to Delphi 2009: Sebastian Zierer
|
2 |
|
|
|
3 |
|
|
(* ***** BEGIN LICENSE BLOCK *****
|
4 |
|
|
* Version: MPL 1.1
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
7 |
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
8 |
|
|
* the License. You may obtain a copy of the License at
|
9 |
|
|
* http://www.mozilla.org/MPL/
|
10 |
|
|
*
|
11 |
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
12 |
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
13 |
|
|
* for the specific language governing rights and limitations under the
|
14 |
|
|
* License.
|
15 |
|
|
*
|
16 |
|
|
* The Original Code is TurboPower SysTools
|
17 |
|
|
*
|
18 |
|
|
* The Initial Developer of the Original Code is
|
19 |
|
|
* TurboPower Software
|
20 |
|
|
*
|
21 |
|
|
* Portions created by the Initial Developer are Copyright (C) 1996-2002
|
22 |
|
|
* the Initial Developer. All Rights Reserved.
|
23 |
|
|
*
|
24 |
|
|
* Contributor(s):
|
25 |
|
|
*
|
26 |
|
|
* ***** END LICENSE BLOCK ***** *)
|
27 |
|
|
|
28 |
|
|
{*********************************************************}
|
29 |
|
|
{* SysTools: StToHTML.pas 4.04 *}
|
30 |
|
|
{*********************************************************}
|
31 |
|
|
{* SysTools: HTML Text Formatter *}
|
32 |
|
|
{*********************************************************}
|
33 |
|
|
|
34 |
|
|
{$I StDefine.inc}
|
35 |
|
|
|
36 |
|
|
unit StToHTML;
|
37 |
|
|
|
38 |
|
|
interface
|
39 |
|
|
|
40 |
|
|
uses
|
41 |
|
|
SysUtils, Windows,
|
42 |
|
|
Messages, Classes, Graphics, Controls,
|
43 |
|
|
Forms, Dialogs, StStrms, StBase;
|
44 |
|
|
|
45 |
|
|
type
|
46 |
|
|
TStOnProgressEvent = procedure(Sender : TObject; Percent : Word) of object;
|
47 |
|
|
|
48 |
|
|
TStStreamToHTML = class(TObject)
|
49 |
|
|
protected {private}
|
50 |
|
|
{ Private declarations }
|
51 |
|
|
FCaseSensitive : Boolean;
|
52 |
|
|
FCommentMarkers : TStringList;
|
53 |
|
|
FEmbeddedHTML : TStringList;
|
54 |
|
|
FInFileSize : Cardinal;
|
55 |
|
|
FInFixedLineLen : integer;
|
56 |
|
|
FInLineTermChar : Char;
|
57 |
|
|
FInLineTerminator: TStLineTerminator;
|
58 |
|
|
FInputStream : TStream;
|
59 |
|
|
FInSize : Cardinal;
|
60 |
|
|
FInTextStream : TStAnsiTextStream;
|
61 |
|
|
FIsCaseSensitive : Boolean;
|
62 |
|
|
FKeywords : TStringList;
|
63 |
|
|
FOnProgress : TStOnProgressEvent;
|
64 |
|
|
FOutputStream : TStream;
|
65 |
|
|
FOutTextStream : TStAnsiTextStream;
|
66 |
|
|
FPageFooter : TStringList;
|
67 |
|
|
FPageHeader : TStringList;
|
68 |
|
|
FStringMarkers : TStringList;
|
69 |
|
|
FWordDelims : String;
|
70 |
|
|
protected
|
71 |
|
|
{ Protected declarations }
|
72 |
|
|
|
73 |
|
|
{internal methods}
|
74 |
|
|
function ParseBuffer : Boolean;
|
75 |
|
|
|
76 |
|
|
procedure SetCommentMarkers(Value : TStringList);
|
77 |
|
|
procedure SetEmbeddedHTML(Value : TStringList);
|
78 |
|
|
procedure SetKeywords(Value : TStringList);
|
79 |
|
|
procedure SetPageFooter(Value : TStringList);
|
80 |
|
|
procedure SetPageHeader(Value : TStringList);
|
81 |
|
|
procedure SetStringMarkers(Value : TStringList);
|
82 |
|
|
|
83 |
|
|
public
|
84 |
|
|
{ Public declarations }
|
85 |
|
|
|
86 |
|
|
property CaseSensitive : Boolean
|
87 |
|
|
read FCaseSensitive
|
88 |
|
|
write FCaseSensitive;
|
89 |
|
|
|
90 |
|
|
property CommentMarkers : TStringList
|
91 |
|
|
read FCommentMarkers
|
92 |
|
|
write SetCommentMarkers;
|
93 |
|
|
|
94 |
|
|
property EmbeddedHTML : TStringList
|
95 |
|
|
read FEmbeddedHTML
|
96 |
|
|
write SetEmbeddedHTML;
|
97 |
|
|
|
98 |
|
|
property InFixedLineLength : integer
|
99 |
|
|
read FInFixedLineLen
|
100 |
|
|
write FInFixedLineLen;
|
101 |
|
|
|
102 |
|
|
property InLineTermChar : Char
|
103 |
|
|
read FInLineTermChar
|
104 |
|
|
write FInLineTermChar;
|
105 |
|
|
|
106 |
|
|
property InLineTerminator : TStLineTerminator
|
107 |
|
|
read FInLineTerminator
|
108 |
|
|
write FInLineTerminator;
|
109 |
|
|
|
110 |
|
|
property InputStream : TStream
|
111 |
|
|
read FInputStream
|
112 |
|
|
write FInputStream;
|
113 |
|
|
|
114 |
|
|
property Keywords : TStringList
|
115 |
|
|
read FKeywords
|
116 |
|
|
write SetKeywords;
|
117 |
|
|
|
118 |
|
|
property OnProgress : TStOnProgressEvent
|
119 |
|
|
read FOnProgress
|
120 |
|
|
write FOnProgress;
|
121 |
|
|
|
122 |
|
|
property OutputStream : TStream
|
123 |
|
|
read FOutputStream
|
124 |
|
|
write FOutputStream;
|
125 |
|
|
|
126 |
|
|
property PageFooter : TStringList
|
127 |
|
|
read FPageFooter
|
128 |
|
|
write SetPageFooter;
|
129 |
|
|
|
130 |
|
|
property PageHeader : TStringList
|
131 |
|
|
read FPageHeader
|
132 |
|
|
write SetPageHeader;
|
133 |
|
|
|
134 |
|
|
property StringMarkers : TStringList
|
135 |
|
|
read FStringMarkers
|
136 |
|
|
write SetStringMarkers;
|
137 |
|
|
|
138 |
|
|
property WordDelimiters : String
|
139 |
|
|
read FWordDelims
|
140 |
|
|
write FWordDelims;
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
constructor Create;
|
144 |
|
|
destructor Destroy; override;
|
145 |
|
|
|
146 |
|
|
procedure GenerateHTML;
|
147 |
|
|
end;
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
TStFileToHTML = class(TStComponent)
|
151 |
|
|
protected {private}
|
152 |
|
|
{ Private declarations }
|
153 |
|
|
|
154 |
|
|
FCaseSensitive : Boolean;
|
155 |
|
|
FCommentMarkers : TStringList;
|
156 |
|
|
FEmbeddedHTML : TStringList;
|
157 |
|
|
FInFile : TFileStream;
|
158 |
|
|
FInFileName : String;
|
159 |
|
|
FInLineLength : integer;
|
160 |
|
|
FInLineTermChar : Char;
|
161 |
|
|
FInLineTerminator : TStLineTerminator;
|
162 |
|
|
FKeywords : TStringList;
|
163 |
|
|
FOnProgress : TStOnProgressEvent;
|
164 |
|
|
FOutFile : TFileStream;
|
165 |
|
|
FOutFileName : String;
|
166 |
|
|
FPageFooter : TStringList;
|
167 |
|
|
FPageHeader : TStringList;
|
168 |
|
|
FStream : TStStreamToHTML;
|
169 |
|
|
FStringMarkers : TStringList;
|
170 |
|
|
FWordDelims : String;
|
171 |
|
|
|
172 |
|
|
protected
|
173 |
|
|
|
174 |
|
|
procedure SetCommentMarkers(Value : TStringList);
|
175 |
|
|
procedure SetEmbeddedHTML(Value : TStringList);
|
176 |
|
|
procedure SetKeywords(Value : TStringList);
|
177 |
|
|
procedure SetPageFooter(Value : TStringList);
|
178 |
|
|
procedure SetPageHeader(Value : TStringList);
|
179 |
|
|
procedure SetStringMarkers(Value : TStringList);
|
180 |
|
|
|
181 |
|
|
public
|
182 |
|
|
constructor Create(AOwner : TComponent); override;
|
183 |
|
|
destructor Destroy; override;
|
184 |
|
|
|
185 |
|
|
procedure Execute;
|
186 |
|
|
|
187 |
|
|
published
|
188 |
|
|
property CaseSensitive : Boolean
|
189 |
|
|
read FCaseSensitive
|
190 |
|
|
write FCaseSensitive default False;
|
191 |
|
|
|
192 |
|
|
property CommentMarkers : TStringList
|
193 |
|
|
read FCommentMarkers
|
194 |
|
|
write SetCommentMarkers;
|
195 |
|
|
|
196 |
|
|
property EmbeddedHTML : TStringList
|
197 |
|
|
read FEmbeddedHTML
|
198 |
|
|
write SetEmbeddedHTML;
|
199 |
|
|
|
200 |
|
|
property InFileName : String
|
201 |
|
|
read FInFileName
|
202 |
|
|
write FInFileName;
|
203 |
|
|
|
204 |
|
|
property InFixedLineLength : integer
|
205 |
|
|
read FInLineLength
|
206 |
|
|
write FInLineLength default 80;
|
207 |
|
|
|
208 |
|
|
property InLineTermChar : Char
|
209 |
|
|
read FInLineTermChar
|
210 |
|
|
write FInLineTermChar default #10;
|
211 |
|
|
|
212 |
|
|
property InLineTerminator : TStLineTerminator
|
213 |
|
|
read FInLineTerminator
|
214 |
|
|
write FInLineTerminator default ltCRLF;
|
215 |
|
|
|
216 |
|
|
property Keywords : TStringList
|
217 |
|
|
read FKeywords
|
218 |
|
|
write SetKeywords;
|
219 |
|
|
|
220 |
|
|
property OnProgress : TStOnProgressEvent
|
221 |
|
|
read FOnProgress
|
222 |
|
|
write FOnProgress;
|
223 |
|
|
|
224 |
|
|
property OutFileName : String
|
225 |
|
|
read FOutFileName
|
226 |
|
|
write FOutFileName;
|
227 |
|
|
|
228 |
|
|
property PageFooter : TStringList
|
229 |
|
|
read FPageFooter
|
230 |
|
|
write SetPageFooter;
|
231 |
|
|
|
232 |
|
|
property PageHeader : TStringList
|
233 |
|
|
read FPageHeader
|
234 |
|
|
write SetPageHeader;
|
235 |
|
|
|
236 |
|
|
property StringMarkers : TStringList
|
237 |
|
|
read FStringMarkers
|
238 |
|
|
write SetStringMarkers;
|
239 |
|
|
|
240 |
|
|
property WordDelimiters : String
|
241 |
|
|
read FWordDelims
|
242 |
|
|
write FWordDelims;
|
243 |
|
|
end;
|
244 |
|
|
|
245 |
|
|
implementation
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
uses
|
249 |
|
|
StConst,
|
250 |
|
|
StDict;
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
(*****************************************************************************)
|
254 |
|
|
(* TStStreamToHTML Implementation *)
|
255 |
|
|
(*****************************************************************************)
|
256 |
|
|
|
257 |
|
|
constructor TStStreamToHTML.Create;
|
258 |
|
|
begin
|
259 |
|
|
inherited Create;
|
260 |
|
|
|
261 |
|
|
FCommentMarkers := TStringList.Create;
|
262 |
|
|
FEmbeddedHTML := TStringList.Create;
|
263 |
|
|
FKeywords := TStringList.Create;
|
264 |
|
|
FPageFooter := TStringList.Create;
|
265 |
|
|
FPageHeader := TStringList.Create;
|
266 |
|
|
FStringMarkers := TStringList.Create;
|
267 |
|
|
|
268 |
|
|
FInputStream := nil;
|
269 |
|
|
FOutputStream := nil;
|
270 |
|
|
|
271 |
|
|
FInFileSize := 0;
|
272 |
|
|
FWordDelims := ',; .()';
|
273 |
|
|
|
274 |
|
|
FInLineTerminator := ltCRLF; {normal Windows text file terminator}
|
275 |
|
|
FInLineTermChar := #10;
|
276 |
|
|
FInFixedLineLen := 80;
|
277 |
|
|
|
278 |
|
|
with FEmbeddedHTML do begin
|
279 |
|
|
Add('"="');
|
280 |
|
|
Add('&=&');
|
281 |
|
|
Add('<=<');
|
282 |
|
|
Add('>=>');
|
283 |
|
|
Add('¡=¡');
|
284 |
|
|
Add('¢=¢');
|
285 |
|
|
Add('£=£');
|
286 |
|
|
Add('©=©');
|
287 |
|
|
Add('®=®');
|
288 |
|
|
Add('±=±');
|
289 |
|
|
Add('¼=¼');
|
290 |
|
|
Add('½=½');
|
291 |
|
|
Add('¾=¾');
|
292 |
|
|
Add('÷=÷');
|
293 |
|
|
end;
|
294 |
|
|
end;
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
destructor TStStreamToHTML.Destroy;
|
298 |
|
|
begin
|
299 |
|
|
FCommentMarkers.Free;
|
300 |
|
|
FCommentMarkers := nil;
|
301 |
|
|
|
302 |
|
|
FEmbeddedHTML.Free;
|
303 |
|
|
FEmbeddedHTML := nil;
|
304 |
|
|
|
305 |
|
|
FKeywords.Free;
|
306 |
|
|
FKeywords := nil;
|
307 |
|
|
|
308 |
|
|
FPageFooter.Free;
|
309 |
|
|
FPageFooter := nil;
|
310 |
|
|
|
311 |
|
|
FPageHeader.Free;
|
312 |
|
|
FPageHeader := nil;
|
313 |
|
|
|
314 |
|
|
FStringMarkers.Free;
|
315 |
|
|
FStringMarkers := nil;
|
316 |
|
|
|
317 |
|
|
FInTextStream.Free;
|
318 |
|
|
FInTextStream := nil;
|
319 |
|
|
|
320 |
|
|
FOutTextStream.Free;
|
321 |
|
|
FOutTextStream := nil;
|
322 |
|
|
|
323 |
|
|
inherited Destroy;
|
324 |
|
|
end;
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
procedure TStStreamToHTML.GenerateHTML;
|
328 |
|
|
begin
|
329 |
|
|
if not ((Assigned(FInputStream) and (Assigned(FOutputStream)))) then
|
330 |
|
|
RaiseStError(EStToHTMLError, stscBadStream)
|
331 |
|
|
else
|
332 |
|
|
ParseBuffer;
|
333 |
|
|
end;
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
procedure DisposeString(Data : Pointer); far;
|
337 |
|
|
begin
|
338 |
|
|
Dispose(PString(Data));
|
339 |
|
|
end;
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
function TStStreamToHTML.ParseBuffer : Boolean;
|
343 |
|
|
var
|
344 |
|
|
I, J,
|
345 |
|
|
P1,
|
346 |
|
|
P2,
|
347 |
|
|
BRead,
|
348 |
|
|
PC : Longint;
|
349 |
|
|
CloseStr,
|
350 |
|
|
SStr,
|
351 |
|
|
EStr,
|
352 |
|
|
S,
|
353 |
|
|
VS,
|
354 |
|
|
AStr,
|
355 |
|
|
TmpStr : String;
|
356 |
|
|
P : Pointer;
|
357 |
|
|
PS : PString;
|
358 |
|
|
CommentDict : TStDictionary;
|
359 |
|
|
HTMLDict : TStDictionary;
|
360 |
|
|
KeywordsDict : TStDictionary;
|
361 |
|
|
StringDict : TStDictionary;
|
362 |
|
|
CommentPend : Boolean;
|
363 |
|
|
|
364 |
|
|
function ConvertEmbeddedHTML(const Str2 : String) : String;
|
365 |
|
|
var
|
366 |
|
|
L,
|
367 |
|
|
J : Longint;
|
368 |
|
|
PH : Pointer;
|
369 |
|
|
begin
|
370 |
|
|
Result := '';
|
371 |
|
|
{avoid memory reallocations}
|
372 |
|
|
SetLength(Result, 1024);
|
373 |
|
|
J := 1;
|
374 |
|
|
for L := 1 to Length(Str2) do begin
|
375 |
|
|
if (not HTMLDict.Exists(Str2[L], PH)) then begin
|
376 |
|
|
Result[J] := Str2[L];
|
377 |
|
|
Inc(J);
|
378 |
|
|
end else begin
|
379 |
|
|
Move(String(PH^)[1], Result[J], Length(String(PH^)) * SizeOf(Char));
|
380 |
|
|
Inc(J, Length(String(PH^)));
|
381 |
|
|
end;
|
382 |
|
|
end;
|
383 |
|
|
Dec(J);
|
384 |
|
|
SetLength(Result, J);
|
385 |
|
|
end;
|
386 |
|
|
|
387 |
|
|
procedure CheckSubString(const Str1 : String);
|
388 |
|
|
var
|
389 |
|
|
S2 : String;
|
390 |
|
|
begin
|
391 |
|
|
if (KeywordsDict.Exists(Str1, P)) then begin
|
392 |
|
|
VS := String(P^);
|
393 |
|
|
S2 := Copy(VS, 1, pos(';', VS)-1)
|
394 |
|
|
+ ConvertEmbeddedHTML(Str1)
|
395 |
|
|
+ Copy(VS, pos(';', VS)+1, Length(VS));
|
396 |
|
|
if (P1 >= Length(Str1)) and (P1 <= Length(TmpStr)) then
|
397 |
|
|
S2 := S2 + ConvertEmbeddedHTML(TmpStr[P1]);
|
398 |
|
|
end else begin
|
399 |
|
|
S2 := ConvertEmbeddedHTML(Str1);
|
400 |
|
|
if (P1 >= Length(Str1)) and (P1 <= Length(TmpStr)) then
|
401 |
|
|
S2 := S2 + ConvertEmbeddedHTML(TmpStr[P1]);
|
402 |
|
|
end;
|
403 |
|
|
S := S + S2;
|
404 |
|
|
end;
|
405 |
|
|
|
406 |
|
|
begin
|
407 |
|
|
if (Length(FWordDelims) = 0) then
|
408 |
|
|
RaiseStError(EStToHTMLError, stscWordDelimiters);
|
409 |
|
|
|
410 |
|
|
{create Dictionaries for lookups}
|
411 |
|
|
CommentDict := TStDictionary.Create(FCommentMarkers.Count+1);
|
412 |
|
|
KeywordsDict := TStDictionary.Create(FKeywords.Count+1);
|
413 |
|
|
HTMLDict := TStDictionary.Create(FEmbeddedHTML.Count+1);
|
414 |
|
|
StringDict := TStDictionary.Create(FStringMarkers.Count+1);
|
415 |
|
|
|
416 |
|
|
CommentDict.DisposeData := DisposeString;
|
417 |
|
|
KeywordsDict.DisposeData := DisposeString;
|
418 |
|
|
HTMLDict.DisposeData := DisposeString;
|
419 |
|
|
StringDict.DisposeData := DisposeString;
|
420 |
|
|
|
421 |
|
|
FInTextStream := TStAnsiTextStream.Create(FInputStream);
|
422 |
|
|
FInTextStream.LineTermChar := AnsiChar(FInLineTermChar);
|
423 |
|
|
FInTextStream.LineTerminator := FInLineTerminator;
|
424 |
|
|
FInTextStream.FixedLineLength := FInFixedLineLen;
|
425 |
|
|
FInFileSize := FInTextStream.Size;
|
426 |
|
|
|
427 |
|
|
FOutTextStream := TStAnsiTextStream.Create(FOutputStream);
|
428 |
|
|
FOutTextStream.LineTermChar := #10;
|
429 |
|
|
FOutTextStream.LineTerminator := ltCRLF;
|
430 |
|
|
FOutTextStream.FixedLineLength := 80;
|
431 |
|
|
|
432 |
|
|
FInLineTerminator := ltCRLF; {normal Windows text file terminator}
|
433 |
|
|
FInLineTermChar := #10;
|
434 |
|
|
FInFixedLineLen := 80;
|
435 |
|
|
|
436 |
|
|
try
|
437 |
|
|
if (FCaseSensitive) then begin
|
438 |
|
|
CommentDict.Hash := AnsiHashStr;
|
439 |
|
|
CommentDict.Equal := AnsiCompareStr;
|
440 |
|
|
HTMLDict.Hash := AnsiHashStr;
|
441 |
|
|
HTMLDict.Equal := AnsiCompareStr;
|
442 |
|
|
KeywordsDict.Hash := AnsiHashStr;
|
443 |
|
|
KeywordsDict.Equal:= AnsiCompareStr;
|
444 |
|
|
StringDict.Hash := AnsiHashStr;
|
445 |
|
|
StringDict.Equal := AnsiCompareStr;
|
446 |
|
|
end else begin
|
447 |
|
|
CommentDict.Hash := AnsiHashText;
|
448 |
|
|
CommentDict.Equal := AnsiCompareText;
|
449 |
|
|
HTMLDict.Hash := AnsiHashText;
|
450 |
|
|
HTMLDict.Equal := AnsiCompareText;
|
451 |
|
|
KeywordsDict.Hash := AnsiHashText;
|
452 |
|
|
KeywordsDict.Equal:= AnsiCompareText;
|
453 |
|
|
StringDict.Hash := AnsiHashText;
|
454 |
|
|
StringDict.Equal := AnsiCompareText;
|
455 |
|
|
end;
|
456 |
|
|
|
457 |
|
|
{Add items from string lists to dictionaries}
|
458 |
|
|
for I := 0 to pred(FKeywords.Count) do begin
|
459 |
|
|
if (Length(FKeywords[I]) = 0) then
|
460 |
|
|
continue;
|
461 |
|
|
if (pos('=', FKeywords[I]) > 0) then begin
|
462 |
|
|
New(PS);
|
463 |
|
|
S := FKeywords.Names[I];
|
464 |
|
|
PS^ := FKeywords.Values[S];
|
465 |
|
|
if (not KeywordsDict.Exists(S, P)) then
|
466 |
|
|
KeywordsDict.Add(S, PS)
|
467 |
|
|
else
|
468 |
|
|
Dispose(PS);
|
469 |
|
|
end else
|
470 |
|
|
RaiseStError(EStToHTMLError, stscInvalidSLEntry);
|
471 |
|
|
end;
|
472 |
|
|
|
473 |
|
|
for I := 0 to pred(FStringMarkers.Count) do begin
|
474 |
|
|
if (Length(FStringMarkers[I]) = 0) then
|
475 |
|
|
continue;
|
476 |
|
|
if (pos('=', FStringMarkers[I]) > 0) then begin
|
477 |
|
|
New(PS);
|
478 |
|
|
S := FStringMarkers.Names[I];
|
479 |
|
|
PS^ := FStringMarkers.Values[S];
|
480 |
|
|
if (not StringDict.Exists(S, P)) then
|
481 |
|
|
StringDict.Add(S, PS)
|
482 |
|
|
else
|
483 |
|
|
Dispose(PS);
|
484 |
|
|
end else
|
485 |
|
|
RaiseStError(EStToHTMLError, stscInvalidSLEntry);
|
486 |
|
|
end;
|
487 |
|
|
|
488 |
|
|
for I := 0 to pred(FCommentMarkers.Count) do begin
|
489 |
|
|
if (Length(FCommentMarkers[I]) = 0) then
|
490 |
|
|
continue;
|
491 |
|
|
if (pos('=', FCommentMarkers[I]) > 0) then begin
|
492 |
|
|
New(PS);
|
493 |
|
|
S := FCommentMarkers.Names[I];
|
494 |
|
|
if (Length(S) = 1) then
|
495 |
|
|
PS^ := FCommentMarkers.Values[S]
|
496 |
|
|
else begin
|
497 |
|
|
PS^ := ':1' + S[2] + ';' + FCommentMarkers.Values[S];
|
498 |
|
|
S := S[1];
|
499 |
|
|
end;
|
500 |
|
|
if (not CommentDict.Exists(S, P)) then
|
501 |
|
|
CommentDict.Add(S, PS)
|
502 |
|
|
else begin
|
503 |
|
|
AStr := String(P^);
|
504 |
|
|
AStr := AStr + PS^;
|
505 |
|
|
String(P^) := AStr;
|
506 |
|
|
CommentDict.Update(S, P);
|
507 |
|
|
Dispose(PS);
|
508 |
|
|
end;
|
509 |
|
|
end else
|
510 |
|
|
RaiseStError(EStToHTMLError, stscInvalidSLEntry);
|
511 |
|
|
end;
|
512 |
|
|
|
513 |
|
|
for I := 0 to pred(FEmbeddedHTML.Count) do begin
|
514 |
|
|
if (pos('=', FEmbeddedHTML[I]) > 0) then begin
|
515 |
|
|
New(PS);
|
516 |
|
|
S := FEmbeddedHTML.Names[I];
|
517 |
|
|
PS^ := FEmbeddedHTML.Values[S];
|
518 |
|
|
if (not HTMLDict.Exists(S, P)) then
|
519 |
|
|
HTMLDict.Add(S, PS)
|
520 |
|
|
else
|
521 |
|
|
Dispose(PS);
|
522 |
|
|
end else
|
523 |
|
|
RaiseStError(EStToHTMLError, stscInvalidSLEntry);
|
524 |
|
|
end;
|
525 |
|
|
|
526 |
|
|
BRead := 0;
|
527 |
|
|
if (FPageHeader.Count > 0) then begin
|
528 |
|
|
for I := 0 to pred(FPageHeader.Count) do
|
529 |
|
|
FOutTextStream.WriteLine(FPageHeader[I]);
|
530 |
|
|
end;
|
531 |
|
|
FOutTextStream.WriteLine('<pre>');
|
532 |
|
|
CommentPend := False;
|
533 |
|
|
AStr := '';
|
534 |
|
|
SStr := '';
|
535 |
|
|
EStr := '';
|
536 |
|
|
|
537 |
|
|
{make sure buffer is at the start}
|
538 |
|
|
FInTextStream.Position := 0;
|
539 |
|
|
while not FInTextStream.AtEndOfStream do begin
|
540 |
|
|
TmpStr := FInTextStream.ReadLine;
|
541 |
|
|
Inc(BRead, Length(TmpStr) + Length(FInTextStream.LineTermChar));
|
542 |
|
|
if (FInFileSize > 0) then begin
|
543 |
|
|
PC := Round((BRead / FInFileSize * 100));
|
544 |
|
|
if (Assigned(FOnProgress)) then
|
545 |
|
|
FOnProgress(Self, PC);
|
546 |
|
|
end;
|
547 |
|
|
|
548 |
|
|
if (TmpStr = '') then begin
|
549 |
|
|
if (CommentPend) then
|
550 |
|
|
FOutTextStream.WriteLine(EStr)
|
551 |
|
|
else
|
552 |
|
|
FOutTextStream.WriteLine(' ');
|
553 |
|
|
continue;
|
554 |
|
|
end;
|
555 |
|
|
|
556 |
|
|
if (CommentPend) then
|
557 |
|
|
S := SStr
|
558 |
|
|
else
|
559 |
|
|
S := '';
|
560 |
|
|
|
561 |
|
|
P1 := 1;
|
562 |
|
|
repeat
|
563 |
|
|
if (not CommentPend) and (CommentDict.Exists(TmpStr[P1], P)) then begin
|
564 |
|
|
VS := String(P^);
|
565 |
|
|
if (Copy(VS, 1 , 2) = ':1') then begin
|
566 |
|
|
while (Copy(VS, 1 , 2) = ':1') do begin
|
567 |
|
|
System.Delete(VS, 1, 2);
|
568 |
|
|
if (TmpStr[P1+1] = VS[1]) then begin
|
569 |
|
|
System.Delete(VS, 1, 2);
|
570 |
|
|
CloseStr := Copy(VS, 1, pos(';', VS)-1);
|
571 |
|
|
System.Delete(VS, 1, pos(';', VS));
|
572 |
|
|
SStr := Copy(VS, 1, pos(';', VS)-1);
|
573 |
|
|
System.Delete(VS, 1, pos(';', VS));
|
574 |
|
|
J := pos(':1', VS);
|
575 |
|
|
if (J = 0) then
|
576 |
|
|
EStr := Copy(VS, pos(';', VS)+1, Length(VS))
|
577 |
|
|
else begin
|
578 |
|
|
EStr := Copy(VS, 1, J-1);
|
579 |
|
|
System.Delete(VS, 1, J+2);
|
580 |
|
|
end;
|
581 |
|
|
|
582 |
|
|
if (CloseStr = '') then begin
|
583 |
|
|
S := S + SStr;
|
584 |
|
|
AStr := Copy(TmpStr, P1, Length(TmpStr));
|
585 |
|
|
CheckSubString(AStr);
|
586 |
|
|
S := S + EStr;
|
587 |
|
|
CloseStr := '';
|
588 |
|
|
SStr := '';
|
589 |
|
|
EStr := '';
|
590 |
|
|
TmpStr := '';
|
591 |
|
|
continue;
|
592 |
|
|
end else begin
|
593 |
|
|
I := pos(CloseStr, TmpStr);
|
594 |
|
|
if (I = 0) then begin
|
595 |
|
|
CommentPend := True;
|
596 |
|
|
S := SStr + S;
|
597 |
|
|
end else begin
|
598 |
|
|
S := S + SStr;
|
599 |
|
|
AStr := Copy(TmpStr, P1, I-P1+Length(CloseStr));
|
600 |
|
|
CheckSubstring(AStr);
|
601 |
|
|
S := S + EStr;
|
602 |
|
|
System.Delete(TmpStr, P1, I-P1+Length(CloseStr));
|
603 |
|
|
end;
|
604 |
|
|
end;
|
605 |
|
|
end else begin
|
606 |
|
|
J := pos(':1', VS);
|
607 |
|
|
if (J > 0) then
|
608 |
|
|
System.Delete(VS, 1, J-1);
|
609 |
|
|
end;
|
610 |
|
|
end;
|
611 |
|
|
end else begin
|
612 |
|
|
{is it really the beginning of a comment?}
|
613 |
|
|
CloseStr := Copy(VS, 1, pos(';', VS)-1);
|
614 |
|
|
System.Delete(VS, 1, pos(';', VS));
|
615 |
|
|
SStr := Copy(VS, 1, pos(';', VS)-1);
|
616 |
|
|
EStr := Copy(VS, pos(';', VS)+1, Length(VS));
|
617 |
|
|
I := pos(CloseStr, TmpStr);
|
618 |
|
|
if (I > 0) and (I > P1) then begin
|
619 |
|
|
{ending marker found}
|
620 |
|
|
CommentPend := False;
|
621 |
|
|
S := S + SStr;
|
622 |
|
|
AStr := Copy(TmpStr, P1, I-P1+Length(CloseStr));
|
623 |
|
|
CheckSubstring(AStr);
|
624 |
|
|
S := S + EStr;
|
625 |
|
|
System.Delete(TmpStr, P1, I-P1+Length(CloseStr));
|
626 |
|
|
P1 := 1;
|
627 |
|
|
CloseStr := '';
|
628 |
|
|
SStr := '';
|
629 |
|
|
EStr := '';
|
630 |
|
|
if (TmpStr = '') then
|
631 |
|
|
continue;
|
632 |
|
|
end else begin {1}
|
633 |
|
|
CommentPend := True;
|
634 |
|
|
S := S + SStr;
|
635 |
|
|
if (Length(TmpStr) > 1) then begin
|
636 |
|
|
AStr := Copy(TmpStr, P1, Length(TmpStr));
|
637 |
|
|
CheckSubstring(AStr);
|
638 |
|
|
end else
|
639 |
|
|
S := S + TmpStr;
|
640 |
|
|
S := S + EStr;
|
641 |
|
|
TmpStr := '';
|
642 |
|
|
continue;
|
643 |
|
|
end;
|
644 |
|
|
end;
|
645 |
|
|
end;
|
646 |
|
|
|
647 |
|
|
if (CommentPend) then begin
|
648 |
|
|
I := pos(CloseStr, TmpStr);
|
649 |
|
|
if (I < 1) then begin
|
650 |
|
|
AStr := Copy(TmpStr, P1, Length(TmpStr));
|
651 |
|
|
CheckSubstring(AStr);
|
652 |
|
|
S := S + EStr;
|
653 |
|
|
TmpStr := '';
|
654 |
|
|
continue;
|
655 |
|
|
end else begin {2}
|
656 |
|
|
CommentPend := False;
|
657 |
|
|
if (Length(TmpStr) > 1) then begin
|
658 |
|
|
AStr := Copy(TmpStr, P1, I-P1+Length(CloseStr));
|
659 |
|
|
CheckSubstring(AStr);
|
660 |
|
|
end else
|
661 |
|
|
S := S + TmpStr;
|
662 |
|
|
S := S + EStr;
|
663 |
|
|
System.Delete(TmpStr, P1, I-P1+Length(CloseStr));
|
664 |
|
|
CloseStr := '';
|
665 |
|
|
SStr := '';
|
666 |
|
|
EStr := '';
|
667 |
|
|
if (TmpStr = '') then
|
668 |
|
|
continue
|
669 |
|
|
else
|
670 |
|
|
P1 := 1;
|
671 |
|
|
end;
|
672 |
|
|
end else begin
|
673 |
|
|
CloseStr := '';
|
674 |
|
|
SStr := '';
|
675 |
|
|
EStr := '';
|
676 |
|
|
end;
|
677 |
|
|
|
678 |
|
|
if (TmpStr = '') then
|
679 |
|
|
continue;
|
680 |
|
|
|
681 |
|
|
P := nil;
|
682 |
|
|
while (P1 <= Length(TmpStr)) and (pos(TmpStr[P1], FWordDelims) = 0) and
|
683 |
|
|
(not StringDict.Exists(TmpStr[P1], P)) do
|
684 |
|
|
Inc(P1);
|
685 |
|
|
if (Assigned(P)) then begin
|
686 |
|
|
P2 := P1+1;
|
687 |
|
|
VS := String(P^);
|
688 |
|
|
CloseStr := Copy(VS, 1, pos(';', VS)-1);
|
689 |
|
|
System.Delete(VS, 1, pos(';', VS));
|
690 |
|
|
SStr := Copy(VS, 1, pos(';', VS)-1);
|
691 |
|
|
System.Delete(VS, 1, pos(';', VS));
|
692 |
|
|
EStr := Copy(VS, pos(';', VS)+1, Length(VS));
|
693 |
|
|
|
694 |
|
|
while (TmpStr[P2] <> CloseStr) and (P2 <= Length(TmpStr)) do
|
695 |
|
|
Inc(P2);
|
696 |
|
|
S := S + SStr;
|
697 |
|
|
AStr := Copy(TmpStr, P1, P2-P1+1);
|
698 |
|
|
CheckSubString(AStr);
|
699 |
|
|
S := S + EStr;
|
700 |
|
|
|
701 |
|
|
System.Delete(TmpStr, P1, P2);
|
702 |
|
|
if (TmpStr = '') then
|
703 |
|
|
continue
|
704 |
|
|
else
|
705 |
|
|
P1 := 1;
|
706 |
|
|
P := nil;
|
707 |
|
|
end else if (P1 <= Length(TmpStr)) and (pos(TmpStr[P1], FWordDelims) > 0) then begin
|
708 |
|
|
if (P1 = 1) then begin
|
709 |
|
|
S := S + ConvertEmbeddedHTML(TmpStr[1]);
|
710 |
|
|
System.Delete(TmpStr, 1, 1);
|
711 |
|
|
P1 := 1;
|
712 |
|
|
end else begin
|
713 |
|
|
AStr := Copy(TmpStr, 1, P1-1);
|
714 |
|
|
if (Length(AStr) > 0) then
|
715 |
|
|
CheckSubstring(AStr);
|
716 |
|
|
System.Delete(TmpStr, 1, P1);
|
717 |
|
|
P1 := 1;
|
718 |
|
|
end;
|
719 |
|
|
end else begin
|
720 |
|
|
AStr := TmpStr;
|
721 |
|
|
CheckSubString(AStr);
|
722 |
|
|
TmpStr := '';
|
723 |
|
|
end;
|
724 |
|
|
until (Length(TmpStr) = 0);
|
725 |
|
|
FOutTextStream.WriteLine(S);
|
726 |
|
|
end;
|
727 |
|
|
if (Assigned(FOnProgress)) then
|
728 |
|
|
FOnProgress(Self, 0);
|
729 |
|
|
|
730 |
|
|
Result := True;
|
731 |
|
|
FOutTextStream.WriteLine('</pre>');
|
732 |
|
|
if (FPageFooter.Count > 0) then begin
|
733 |
|
|
for I := 0 to pred(FPageFooter.Count) do
|
734 |
|
|
FOutTextStream.WriteLine(FPageFooter[I]);
|
735 |
|
|
end;
|
736 |
|
|
finally
|
737 |
|
|
CommentDict.Free;
|
738 |
|
|
HTMLDict.Free;
|
739 |
|
|
KeywordsDict.Free;
|
740 |
|
|
StringDict.Free;
|
741 |
|
|
|
742 |
|
|
FInTextStream.Free;
|
743 |
|
|
FInTextStream := nil;
|
744 |
|
|
|
745 |
|
|
FOutTextStream.Free;
|
746 |
|
|
FOutTextStream := nil;
|
747 |
|
|
end;
|
748 |
|
|
end;
|
749 |
|
|
|
750 |
|
|
|
751 |
|
|
procedure TStStreamToHTML.SetCommentMarkers(Value : TStringList);
|
752 |
|
|
begin
|
753 |
|
|
FCommentMarkers.Assign(Value);
|
754 |
|
|
end;
|
755 |
|
|
|
756 |
|
|
|
757 |
|
|
procedure TStStreamToHTML.SetEmbeddedHTML(Value : TStringList);
|
758 |
|
|
begin
|
759 |
|
|
FEmbeddedHTML.Assign(Value);
|
760 |
|
|
end;
|
761 |
|
|
|
762 |
|
|
|
763 |
|
|
procedure TStStreamToHTML.SetKeywords(Value : TStringList);
|
764 |
|
|
begin
|
765 |
|
|
FKeywords.Assign(Value);
|
766 |
|
|
end;
|
767 |
|
|
|
768 |
|
|
|
769 |
|
|
procedure TStStreamToHTML.SetPageFooter(Value : TStringList);
|
770 |
|
|
begin
|
771 |
|
|
FPageFooter.Assign(Value);
|
772 |
|
|
end;
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
procedure TStStreamToHTML.SetPageHeader(Value : TStringList);
|
776 |
|
|
begin
|
777 |
|
|
FPageHeader.Assign(Value);
|
778 |
|
|
end;
|
779 |
|
|
|
780 |
|
|
|
781 |
|
|
procedure TStStreamToHTML.SetStringMarkers(Value : TStringList);
|
782 |
|
|
begin
|
783 |
|
|
FStringMarkers.Assign(Value);
|
784 |
|
|
end;
|
785 |
|
|
|
786 |
|
|
|
787 |
|
|
|
788 |
|
|
(*****************************************************************************)
|
789 |
|
|
(* TStFileToHTML Implementation *)
|
790 |
|
|
(*****************************************************************************)
|
791 |
|
|
|
792 |
|
|
|
793 |
|
|
constructor TStFileToHTML.Create(AOwner : TComponent);
|
794 |
|
|
begin
|
795 |
|
|
inherited Create(AOwner);
|
796 |
|
|
|
797 |
|
|
FCommentMarkers := TStringList.Create;
|
798 |
|
|
FEmbeddedHTML := TStringList.Create;
|
799 |
|
|
FKeywords := TStringList.Create;
|
800 |
|
|
FPageFooter := TStringList.Create;
|
801 |
|
|
FPageHeader := TStringList.Create;
|
802 |
|
|
FStringMarkers := TStringList.Create;
|
803 |
|
|
|
804 |
|
|
FWordDelims := ',; .()';
|
805 |
|
|
|
806 |
|
|
FInLineTerminator := ltCRLF;
|
807 |
|
|
FInLineTermChar := #10;
|
808 |
|
|
FInLineLength := 80;
|
809 |
|
|
|
810 |
|
|
with FEmbeddedHTML do begin
|
811 |
|
|
Add('"="');
|
812 |
|
|
Add('&=&');
|
813 |
|
|
Add('<=<');
|
814 |
|
|
Add('>=>');
|
815 |
|
|
Add('¡=¡');
|
816 |
|
|
Add('¢=¢');
|
817 |
|
|
Add('£=£');
|
818 |
|
|
Add('©=©');
|
819 |
|
|
Add('®=®');
|
820 |
|
|
Add('±=±');
|
821 |
|
|
Add('¼=¼');
|
822 |
|
|
Add('½=½');
|
823 |
|
|
Add('¾=¾');
|
824 |
|
|
Add('÷=÷');
|
825 |
|
|
end;
|
826 |
|
|
end;
|
827 |
|
|
|
828 |
|
|
|
829 |
|
|
destructor TStFileToHTML.Destroy;
|
830 |
|
|
begin
|
831 |
|
|
FCommentMarkers.Free;
|
832 |
|
|
FCommentMarkers := nil;
|
833 |
|
|
|
834 |
|
|
FEmbeddedHTML.Free;
|
835 |
|
|
FEmbeddedHTML := nil;
|
836 |
|
|
|
837 |
|
|
FKeywords.Free;
|
838 |
|
|
FKeywords := nil;
|
839 |
|
|
|
840 |
|
|
FPageFooter.Free;
|
841 |
|
|
FPageFooter := nil;
|
842 |
|
|
|
843 |
|
|
FPageHeader.Free;
|
844 |
|
|
FPageHeader := nil;
|
845 |
|
|
|
846 |
|
|
FStringMarkers.Free;
|
847 |
|
|
FStringMarkers := nil;
|
848 |
|
|
|
849 |
|
|
FInFile.Free;
|
850 |
|
|
FInFile := nil;
|
851 |
|
|
|
852 |
|
|
FOutFile.Free;
|
853 |
|
|
FOutFile := nil;
|
854 |
|
|
|
855 |
|
|
FStream.Free;
|
856 |
|
|
FStream := nil;
|
857 |
|
|
|
858 |
|
|
inherited Destroy;
|
859 |
|
|
end;
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
procedure TStFileToHTML.Execute;
|
863 |
|
|
begin
|
864 |
|
|
FStream := TStStreamToHTML.Create;
|
865 |
|
|
try
|
866 |
|
|
if (FInFileName = '') then
|
867 |
|
|
RaiseStError(EStToHTMLError, stscNoInputFile)
|
868 |
|
|
else if (FOutFileName = '') then
|
869 |
|
|
RaiseStError(EStToHTMLError, stscNoOutputFile)
|
870 |
|
|
else begin
|
871 |
|
|
if (Assigned(FInFile)) then
|
872 |
|
|
FInFile.Free;
|
873 |
|
|
try
|
874 |
|
|
FInFile := TFileStream.Create(FInFileName, fmOpenRead or fmShareDenyWrite);
|
875 |
|
|
except
|
876 |
|
|
RaiseStError(EStToHTMLError, stscInFileError);
|
877 |
|
|
Exit;
|
878 |
|
|
end;
|
879 |
|
|
|
880 |
|
|
if (Assigned(FOutFile)) then
|
881 |
|
|
FOutFile.Free;
|
882 |
|
|
try
|
883 |
|
|
FOutFile := TFileStream.Create(FOutFileName, fmCreate);
|
884 |
|
|
except
|
885 |
|
|
RaiseStError(EStToHTMLError, stscOutFileError);
|
886 |
|
|
Exit;
|
887 |
|
|
end;
|
888 |
|
|
|
889 |
|
|
try
|
890 |
|
|
FStream.InputStream := FInFile;
|
891 |
|
|
FStream.OutputStream := FOutFile;
|
892 |
|
|
FStream.CaseSensitive := CaseSensitive;
|
893 |
|
|
FStream.CommentMarkers := CommentMarkers;
|
894 |
|
|
FStream.EmbeddedHTML := EmbeddedHTML;
|
895 |
|
|
FStream.InFixedLineLength := InFixedLineLength;
|
896 |
|
|
FStream.InLineTermChar := InLineTermChar;
|
897 |
|
|
FStream.InLineTerminator := InLineTerminator;
|
898 |
|
|
FStream.Keywords := Keywords;
|
899 |
|
|
FStream.OnProgress := OnProgress;
|
900 |
|
|
FStream.PageFooter := PageFooter;
|
901 |
|
|
FStream.PageHeader := PageHeader;
|
902 |
|
|
FStream.StringMarkers := StringMarkers;
|
903 |
|
|
FStream.WordDelimiters := WordDelimiters;
|
904 |
|
|
|
905 |
|
|
FStream.GenerateHTML;
|
906 |
|
|
finally
|
907 |
|
|
FInFile.Free;
|
908 |
|
|
FInFile := nil;
|
909 |
|
|
FOutFile.Free;
|
910 |
|
|
FOutFile := nil;
|
911 |
|
|
end;
|
912 |
|
|
end;
|
913 |
|
|
finally
|
914 |
|
|
FStream.Free;
|
915 |
|
|
FStream := nil;
|
916 |
|
|
end;
|
917 |
|
|
end;
|
918 |
|
|
|
919 |
|
|
|
920 |
|
|
procedure TStFileToHTML.SetCommentMarkers(Value : TStringList);
|
921 |
|
|
begin
|
922 |
|
|
FCommentMarkers.Assign(Value);
|
923 |
|
|
end;
|
924 |
|
|
|
925 |
|
|
|
926 |
|
|
procedure TStFileToHTML.SetEmbeddedHTML(Value : TStringList);
|
927 |
|
|
begin
|
928 |
|
|
FEmbeddedHTML.Assign(Value);
|
929 |
|
|
end;
|
930 |
|
|
|
931 |
|
|
|
932 |
|
|
|
933 |
|
|
procedure TStFileToHTML.SetKeywords(Value : TStringList);
|
934 |
|
|
begin
|
935 |
|
|
FKeywords.Assign(Value);
|
936 |
|
|
end;
|
937 |
|
|
|
938 |
|
|
|
939 |
|
|
procedure TStFileToHTML.SetPageFooter(Value : TStringList);
|
940 |
|
|
begin
|
941 |
|
|
FPageFooter.Assign(Value);
|
942 |
|
|
end;
|
943 |
|
|
|
944 |
|
|
|
945 |
|
|
procedure TStFileToHTML.SetPageHeader(Value : TStringList);
|
946 |
|
|
begin
|
947 |
|
|
FPageHeader.Assign(Value);
|
948 |
|
|
end;
|
949 |
|
|
|
950 |
|
|
|
951 |
|
|
procedure TStFileToHTML.SetStringMarkers(Value : TStringList);
|
952 |
|
|
begin
|
953 |
|
|
FStringMarkers.Assign(Value);
|
954 |
|
|
end;
|
955 |
|
|
|
956 |
|
|
|
957 |
|
|
end.
|