@@ -101,6 +101,7 @@ TParams = class(TObject)
101
101
var
102
102
fParamQueue: TQueue<string>; // Queue of parameters to be processed
103
103
fCmdLookup: TDictionary<string, TCommandId>;
104
+ fV1CommandLookup: TList<string>;
104
105
fSwitchCmdLookup: TList<string>;
105
106
fConfigBlacklist: TList<TCommandId>;
106
107
fEncodingLookup: TDictionary<string, TOutputEncodingId>;
@@ -110,6 +111,7 @@ TParams = class(TObject)
110
111
fPaddingLookup: TDictionary<string, Char>;
111
112
fViewportLookup: TDictionary<string, TViewport>;
112
113
fConfig: TConfig; // Reference to program's configuration object
114
+ fWarnings: TList<string>;
113
115
procedure GetConfigParams ;
114
116
procedure GetCmdLineParams ;
115
117
procedure ParseCommand (const IsConfigCmd: Boolean);
@@ -123,10 +125,15 @@ TParams = class(TObject)
123
125
UInt16;
124
126
function GetPaddingParameter (const Cmd: TCommand): Char;
125
127
function GetViewportParameter (const Cmd: TCommand): TViewport;
128
+ function GetWarnings : TArray<string>;
129
+ function AdjustCommandName (const Name : string; IsCfgCmd: Boolean): string;
130
+ function IsV1Command (const Name : string): Boolean;
126
131
public
127
132
constructor Create(const Config: TConfig);
128
133
destructor Destroy; override;
129
134
procedure Parse ;
135
+ property Warnings: TArray<string> read GetWarnings;
136
+ function HasWarnings : Boolean;
130
137
end ;
131
138
132
139
// / <summary>Type of exception raised for a command related error.</summary>
@@ -166,6 +173,20 @@ implementation
166
173
167
174
{ TParams }
168
175
176
+ function TParams.AdjustCommandName (const Name : string;
177
+ IsCfgCmd: Boolean): string;
178
+ begin
179
+ if IsCfgCmd then
180
+ begin
181
+ if StartsStr(' --' , Name ) then
182
+ Result := RightStr(Name , Length(Name ) - 2 )
183
+ else
184
+ Result := Name ;
185
+ end
186
+ else
187
+ Result := Name ;
188
+ end ;
189
+
169
190
constructor TParams.Create(const Config: TConfig);
170
191
begin
171
192
Assert(Assigned(Config), ' TParams.Create: Config is nil' );
@@ -231,6 +252,16 @@ constructor TParams.Create(const Config: TConfig);
231
252
Add(' -rc' , siInputClipboard);
232
253
Add(' -wc' , siOutputClipboard);
233
254
end ;
255
+ fV1CommandLookup := TList<string>.Create(
256
+ TTextComparer.Create
257
+ );
258
+ with fV1CommandLookup do
259
+ begin
260
+ Add(' -wc' );
261
+ Add(' -rc' );
262
+ Add(' -hidecss' );
263
+ Add(' -frag' );
264
+ end ;
234
265
// list of short form commands that are switches
235
266
fSwitchCmdLookup := TList<string>.Create;
236
267
with fSwitchCmdLookup do
@@ -322,17 +353,20 @@ constructor TParams.Create(const Config: TConfig);
322
353
Add(' phone' , vpPhone);
323
354
Add(' tablet' , vpPhone);
324
355
end ;
356
+ fWarnings := TList<string>.Create(TTextComparer.Create);
325
357
end ;
326
358
327
359
destructor TParams.Destroy;
328
360
begin
361
+ fWarnings.Free;
329
362
fViewportLookup.Free;
330
363
fPaddingLookup.Free;
331
364
fVerbosityLookup.Free;
332
365
fBooleanLookup.Free;
333
366
fDocTypeLookup.Free;
334
367
fEncodingLookup.Free;
335
368
fSwitchCmdLookup.Free;
369
+ fV1CommandLookup.Free;
336
370
fCmdLookup.Free;
337
371
fParamQueue.Free;
338
372
inherited ;
@@ -467,37 +501,47 @@ function TParams.GetViewportParameter(const Cmd: TCommand): TViewport;
467
501
Result := fViewportLookup[Param];
468
502
end ;
469
503
470
- procedure TParams.Parse ;
504
+ function TParams.GetWarnings : TArray<string>;
505
+ var
506
+ Idx: Integer;
507
+ begin
508
+ SetLength(Result, fWarnings.Count);
509
+ for Idx := 0 to Pred(fWarnings.Count) do
510
+ Result[Idx] := fWarnings[Idx];
511
+ end ;
471
512
472
- procedure ParseQueue (const IsConfigCmd: Boolean; const ErrorFmtStr: string);
513
+ function TParams.HasWarnings : Boolean;
514
+ begin
515
+ Result := fWarnings.Count > 0 ;
516
+ end ;
473
517
474
- function AdjustCommandName (const Name : string): string;
475
- begin
476
- WriteLn(' DBG: ' , Name );
477
- if IsConfigCmd then
478
- begin
479
- if StartsStr(' --' , Name ) then
480
- Result := RightStr(Name , Length(Name ) - 2 )
481
- else
482
- Result := Name ;
483
- end
484
- else
485
- Result := Name ;
486
- end ;
518
+ function TParams.IsV1Command (const Name : string): Boolean;
519
+ begin
520
+ Result := fV1CommandLookup.Contains(Name );
521
+ end ;
522
+
523
+ procedure TParams.Parse ;
487
524
525
+ procedure ParseQueue (const IsConfigCmd: Boolean; const ErrorFmtStr: string);
526
+ var
527
+ CmdName: string;
488
528
begin
489
529
try
490
530
while fParamQueue.Count > 0 do
491
531
begin
492
532
if AnsiStartsStr(' -' , fParamQueue.Peek) then
493
- ParseCommand(IsConfigCmd)
533
+ begin
534
+ CmdName := fParamQueue.Peek;
535
+ ParseCommand(IsConfigCmd);
536
+ end
494
537
else
495
538
ParseFileName;
496
539
end ;
497
540
except
498
541
on E: ECommandError do
499
542
raise Exception.CreateFmt(
500
- ErrorFmtStr, [Format(E.FormatStr, [AdjustCommandName(E.CommandName)])]
543
+ ErrorFmtStr,
544
+ [Format(E.FormatStr, [AdjustCommandName(E.CommandName, IsConfigCmd)])]
501
545
);
502
546
on E: Exception do
503
547
raise Exception.CreateFmt(ErrorFmtStr, [E.Message]);
@@ -522,6 +566,9 @@ procedure TParams.ParseCommand(const IsConfigCmd: Boolean);
522
566
sMustBeSwitch = ' %s must be a switch command: append "+" or "-"' ;
523
567
sBlacklisted = ' The "%s" command is not permitted in the config file.' #13 #10
524
568
+ ' Please edit the file' ;
569
+ // Warnings
570
+ sDeprecatedCmd = ' *** The "%s" command is deprecated' ;
571
+ sDepDocType = ' The "html4" parameter to the "%s" command deprecated' ;
525
572
var
526
573
Command: TCommand;
527
574
CommandId: TCommandId;
@@ -541,11 +588,19 @@ procedure TParams.ParseCommand(const IsConfigCmd: Boolean);
541
588
542
589
case CommandId of
543
590
siInputClipboard:
591
+ begin
592
+ if IsV1Command(Command.Name ) then
593
+ fWarnings.Add(Format(sDeprecatedCmd, [Command.Name ]));
544
594
fConfig.InputSource := isClipboard;
595
+ end ;
545
596
siInputStdIn:
546
597
fConfig.InputSource := isStdIn;
547
598
siOutputClipboard:
599
+ begin
600
+ if IsV1Command(Command.Name ) then
601
+ fWarnings.Add(Format(sDeprecatedCmd, [Command.Name ]));
548
602
fConfig.OutputSink := osClipboard;
603
+ end ;
549
604
siOutputFile:
550
605
begin
551
606
fConfig.OutputFile := GetStringParameter(Command);
@@ -562,14 +617,30 @@ procedure TParams.ParseCommand(const IsConfigCmd: Boolean);
562
617
siOutputDocType:
563
618
begin
564
619
fConfig.DocType := GetDocTypeParameter(Command);
620
+ if fConfig.DocType = dtHTML4 then
621
+ fWarnings.Add(
622
+ Format(sDepDocType, [AdjustCommandName(Command.Name , IsConfigCmd)])
623
+ );
565
624
fParamQueue.Dequeue;
566
625
end ;
567
626
siFragment:
627
+ begin
628
+ if IsV1Command(Command.Name ) then
629
+ fWarnings.Add(Format(sDeprecatedCmd, [Command.Name ]));
568
630
fConfig.DocType := dtFragment;
631
+ end ;
569
632
siForceHideCSS:
633
+ begin
634
+ fWarnings.Add(
635
+ Format(sDeprecatedCmd, [AdjustCommandName(Command.Name , IsConfigCmd)])
636
+ );
570
637
fConfig.HideCSS := True;
638
+ end ;
571
639
siHideCSS:
572
640
begin
641
+ fWarnings.Add(
642
+ Format(sDeprecatedCmd, [AdjustCommandName(Command.Name , IsConfigCmd)])
643
+ );
573
644
if Command.IsSwitch then
574
645
fConfig.HideCSS := Command.SwitchValue
575
646
else
@@ -597,6 +668,9 @@ procedure TParams.ParseCommand(const IsConfigCmd: Boolean);
597
668
end ;
598
669
siLegacyCSS:
599
670
begin
671
+ fWarnings.Add(
672
+ Format(sDeprecatedCmd, [AdjustCommandName(Command.Name , IsConfigCmd)])
673
+ );
600
674
fConfig.LegacyCSSNames := GetBooleanParameter(Command);
601
675
fParamQueue.Dequeue;
602
676
end ;
0 commit comments