-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmacro.pas
1022 lines (946 loc) · 27.5 KB
/
macro.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Open Source 1.51.08
// Based on Dos Navigator (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
{$I STDEFINE.INC}
unit Macro;
interface
uses
Advance, Defines, Objects2, Views, Objects,
Microed, highlite, Strings
;
type
PEditMacros = ^TEditMacros;
TEditMacros = object(TObject)
Name: PString;
Commands: PCollection;
constructor Init(S: String; var F: PTextReader);
procedure Play(Editor: PView);
destructor Done; virtual;
end;
PMacroCommand = ^TMacroCommand;
TMacroCommand = object(TObject)
Command: Integer;
Repetitions: Integer;
constructor Init(ACommand, ARepetitions: Word);
procedure ExecCommand(Editor: PView); virtual;
end;
PMacroGoto = ^TMacroGoto;
TMacroGoto = object(TMacroCommand)
procedure ExecCommand(Editor: PView); virtual;
end;
PMacroMark = ^TMacroMark;
TMacroMark = object(TMacroCommand)
Mark: Boolean;
constructor Init(AN: Integer; AMark: Boolean);
procedure ExecCommand(Editor: PView); virtual;
end;
PMacroString = ^TMacroString;
TMacroString = object(TMacroCommand)
S: PString;
constructor Init(const AString: String; ARepetitions: Word);
procedure ExecCommand(Editor: PView); virtual;
destructor Done; virtual;
end;
PIDCollection = ^TIDCollection;
TIDCollection = object(TSortedCollection)
function Compare(P1, P2: Pointer): Integer; virtual;
end;
procedure EditDOSEnvironment(Env: PByteArray);
function InitHighLight
(const FName: String;
var HiLitePar: THighliteParams;
Macros: PCollection;
EdOptions: PEditOptions): Boolean;
implementation
uses
Messages, Drivers, Dialogs, Commands, DNHelp, DNApp,
Startup, Advance1, Advance2, VPUtils
, VPSysLow {JO: for SysBeepEx}
;
type
PLngWord = ^TLngWord;
TLngWord = object(TObject)
Name: String;
// removed [30] by unxed to fix build
//Name: String[30];
l: Word;
constructor Init(AL: Word; const AName: String);
end;
function Token(const S: String; var Pos: LongInt): String;
var
A: String;
B, Cmd: Boolean;
M: String;
J: Integer;
begin
Token := '';
A := '';
B := False;
Cmd := False;
while (S[Pos] = ' ') and (Length(S) >= Pos) do
Inc(Pos);
while Pos <= Length(S) do
begin
case S[Pos] of
'''':
if (S[Pos+1] = '''') and B and (Pos < Length(S)) then
begin
Inc(Pos);
AddStr(A, '''')
end
else
B := not B;
',', ' ':
if not B or Cmd then
Break
else if B then
AddStr(A, S[Pos]);
'^':
if B then
AddStr(A, S[Pos])
else
begin
Inc(Pos);
AddStr(A, Char(Byte(UpCase(S[Pos]))-64));
end;
'#':
if B then
AddStr(A, S[Pos])
else
begin
J := 1;
M := '';
repeat
Inc(Pos);
AddStr(M, S[Pos]);
until not (S[Pos+1] in ['0'..'9']) or (Pos >= Length(S));
AddStr(A, Char(StoI(M)));
end;
else {case}
if B then
AddStr(A, S[Pos])
else
begin
B := True;
Cmd := True;
AddStr(A, S[Pos])
end;
end {case};
Inc(Pos);
end;
Inc(Pos);
Token := A;
end { Token };
function TIDCollection.Compare;
begin
if PLngWord(P1)^.Name > PLngWord(P2)^.Name then
Compare := 1
else if PLngWord(P1)^.Name < PLngWord(P2)^.Name then
Compare := -1
else
Compare := 0;
end;
constructor TLngWord.Init;
begin
Name := AName;
UpStr(Name);
l := AL;
end;
constructor TEditMacros.Init;
var
I, J: LongInt;
IDs: PIDCollection;
Error: Boolean;
function GetID(const S: String): LongInt;
var
T: TLngWord;
I: LongInt;
L: LongInt;
qq: Integer;
begin
FreeStr := S;
DelRight(FreeStr);
if S[Length(S)] = ',' then
SetLength(FreeStr, Length(FreeStr)-1);
DelRight(FreeStr);
T.Init(0, FreeStr);
if IDs^.Search(@T, I) then
begin
GetID := PLngWord(IDs^.At(I))^.L;
end
else
begin
Val(FreeStr, L, qq);
{if I > 0 then MessageBox(^M^C'Unknown identifier ('+FreeStr+')', nil, mfError+mfOKButton);}
GetID := L;
end;
end { GetID };
function Found(const SS: String): Boolean;
begin
if UpStrg(Copy(S, 1, Length(SS))) = SS then
begin
Found := True;
Delete(S, 1, Length(SS));
DelLeft(S);
end
else
Found := False;
end;
procedure MakePrint;
begin
Commands^.Insert(New(PMacroString, Init(Token(S, i), GetID(Token(S,
i)))));
end;
procedure MakeGotoXY(X, Y: Integer);
begin
Commands^.Insert(New(PMacroGoto, Init(X, Y)));
end;
procedure MakeIDs;
procedure Add(N: Word; const S: String);
begin
IDs^.Insert(New(PLngWord, Init(N, S)))
end;
begin
Add(cmSaveText, 'SaveText');
Add(cmLoadText, 'LoadText');
Add(cmSaveTextAs, 'SaveTextAs');
Add(cmSwitchBlock, 'SwitchBlock');
Add(cmSwitchIndent, 'SwitchIndent');
Add(cmSwitchFill, 'SwitchFill');
Add(cmSwitchBack, 'SwitchBack');
Add(cmSwitchSave, 'SwitchSave');
Add(cmWordLeft, 'WordLeft');
Add(cmWordRight, 'WordRight');
Add(cmDelWordRight, 'DelWordRight');
Add(cmDelWordLeft, 'DelWordLeft');
Add(cmScrollUp, 'ScrollUp');
Add(cmScrollDn, 'ScrollDn');
Add(cmCenter, 'Center');
Add(cmStartSearch, 'StartSearch');
Add(cmContSearch, 'ContSearch');
Add(cmDelBackChar, 'DelBackChar');
Add(cmDelChar, 'DelChar');
Add(cmSwitchIns, 'SwitchIns');
Add(cmPgUp, 'PgUp');
Add(cmPgDn, 'PgDn');
Add(cmMoveUp, 'MoveUp');
Add(cmMoveLeft, 'MoveLeft');
Add(cmMoveRight, 'MoveRight');
Add(cmMoveDown, 'MoveDown');
Add(cmBlockStart, 'BlockStart');
Add(cmBlockEnd, 'BlockEnd');
Add(cmMarkWord, 'MarkWord');
Add(cmMarkLine, 'MarkLine');
Add(cmBlockRead, 'BlockRead');
Add(cmBlockWrite, 'BlockWrite');
{$IFDEF Printer}
Add(cmBlockPrint, 'BlockPrint');
{$ENDIF}
Add(cmIndentBlock, 'IndentBlock');
Add(cmUnIndentBlock, 'UnIndentBlock');
Add(cmTab, 'Tab');
Add(cmPlaceMarker1, 'PlaceMarker1');
Add(cmPlaceMarker2, 'PlaceMarker2');
Add(cmPlaceMarker3, 'PlaceMarker3');
Add(cmPlaceMarker4, 'PlaceMarker4');
Add(cmPlaceMarker5, 'PlaceMarker5');
Add(cmPlaceMarker6, 'PlaceMarker6');
Add(cmPlaceMarker7, 'PlaceMarker7');
Add(cmPlaceMarker8, 'PlaceMarker8');
Add(cmPlaceMarker9, 'PlaceMarker9');
Add(cmGoToMarker1, 'GoToMarker1');
Add(cmGoToMarker2, 'GoToMarker2');
Add(cmGoToMarker3, 'GoToMarker3');
Add(cmGoToMarker4, 'GoToMarker4');
Add(cmGoToMarker5, 'GoToMarker5');
Add(cmGoToMarker6, 'GoToMarker6');
Add(cmGoToMarker7, 'GoToMarker7');
Add(cmGoToMarker8, 'GoToMarker8');
Add(cmGoToMarker9, 'GoToMarker9');
Add(cmSpecChar, 'SpecChar');
Add(cmReplace, 'Replace');
Add(cmEnd, 'End');
Add(cmEnter, 'Enter');
Add(cmInsLine, 'InsLine');
Add(cmFJustify, 'FJustify');
Add(cmFCenter, 'FCenter');
Add(cmFLeft, 'FLeft');
Add(cmFRight, 'FRight');
Add(cmLJustify, 'LJustify');
Add(cmLCenter, 'LCenter');
Add(cmLLeft, 'LLeft');
Add(cmLRight, 'LRight');
Add(cmDeltoEOLN, 'DeltoEOLN');
Add(cmSetMargins, 'SetMargins');
Add(cmCtrlHome, 'CtrlHome');
Add(cmCtrlEnd, 'CtrlEnd');
Add(cmSwitchHighLight, 'SwitchHighLight');
Add(cmGotoLineNumber, 'GotoLineNumber');
Add(cmGotoLineNumber2, 'GotoLineNumber2');
Add(cmSwitchWrap, 'SwitchWrap');
Add(cmSwitchHiLine, 'SwitchHiLine');
Add(cmSwitchHiColumn, 'SwitchHiColumn');
Add(cmUpString, 'UpString');
Add(cmLowString, 'LowString');
Add(cmCapString, 'CapString');
Add(cmUpcaseBlock, 'UpBlock');
Add(cmLowcaseBlock, 'LowBlock');
Add(cmCapitalizeBlock, 'CapBlock');
Add(cmInsertTime, 'InsertTime');
Add(cmInsertDate, 'InsertDate');
Add(cmSortBlock, 'SortBlock');
Add(cmCalcBlock, 'CalcBlock');
Add(cmCopyBlock, 'CopyBlock');
Add(cmMoveBlock, 'MoveBlock');
Add(cmHideBlock, 'HideBlock');
Add(cmMoveBlockStart, 'MoveBlockStart');
Add(cmMoveBlockEnd, 'MoveBlockEnd');
Add(cmInsertOn, 'InsertOn');
Add(cmInsertOff, 'InsertOff');
Add(cmIndentOn, 'IndentOn');
Add(cmIndentOff, 'IndentOff');
end { MakeIDs };
begin { TEditMacros.Init }
inherited Init;
New(Commands, Init(10, 10));
New(IDs, Init(100, 10));
MakeIDs;
while (S <> '') and (S[1] = ' ') do
Delete(FreeStr, 1, 1);
if S = '' then
S := '0';
Name := NewStr(S);
while not F^.Eof do
begin
S := F^.GetStr;
DelRight(S);
DelLeft(S);
if (S[1] <> ';') and (S <> '') then
begin
I := 1;
if Found('ENDMACRO') then
Break;
if Found('PRINT ') then
MakePrint
else if Found('GOTOXY ') then
MakeGotoXY(GetID(Token(S, I)), GetID(Token(S, I)))
else if Found('GOTOX ') then
MakeGotoXY(GetID(Token(S, I)), -1)
else if Found('GOTOY ') then
MakeGotoXY(-1, GetID(Token(S, I)))
else if Found('GOTO ') then
Commands^.Insert(New(PMacroMark, Init(GetID(Token(S, I)),
False)))
else if Found('MARK ') then
Commands^.Insert(New(PMacroMark, Init(GetID(Token(S, I)),
True)))
else
begin
J := GetID(Token(S, I));
if J > 0 then
Commands^.Insert(New(PMacroCommand, Init(J, GetID(Token(S,
I)))));
end;
end;
end;
Dispose(IDs, Done);
IDs := nil;
end { TEditMacros.Init };
procedure TEditMacros.Play;
procedure DoPlay(P: PMacroCommand);
begin
P^.ExecCommand(Editor);
end;
begin
Commands^.ForEach(@DoPlay);
end;
destructor TEditMacros.Done;
begin
DisposeStr(Name);
Dispose(Commands, Done);
Commands := nil;
end;
constructor TMacroCommand.Init;
begin
inherited Init;
Command := ACommand;
Repetitions := ARepetitions;
end;
procedure TMacroCommand.ExecCommand;
var
I: Integer;
begin
for I := 1 to Max(1, Repetitions) do
Message(Editor^.Owner, evCommand, Command, nil);
end;
procedure TMacroGoto.ExecCommand;
begin
if (Command < 0) then
PFileEditor(Editor)^.ScrollTo(PFileEditor(Editor)^.Delta.X,
Repetitions)
else if (Repetitions < 0) then
PFileEditor(Editor)^.ScrollTo(Command, PFileEditor(Editor)^.Delta.Y)
else
PFileEditor(Editor)^.ScrollTo(Command, Repetitions);
end;
constructor TMacroMark.Init;
begin
TObject.Init;
Command := Max(1, Min(AN, 9));
Mark := AMark;
end;
procedure TMacroMark.ExecCommand;
begin
if Mark then
with PFileEditor(Editor)^ do
MarkPos[Command] := Delta
else
with PFileEditor(Editor)^ do
ScrollTo(MarkPos[Command].X, MarkPos[Command].Y);
end;
constructor TMacroString.Init;
begin
TObject.Init;
S := NewStr(AString);
Repetitions := ARepetitions;
end;
procedure TMacroString.ExecCommand;
var
I, J: Integer;
begin
if S = nil then
Exit;
for J := 1 to Max(1, Repetitions) do
for I := 1 to Length(S^) do
Message(Application, evKeyDown, Byte(S^[I]), nil);
end;
destructor TMacroString.Done;
begin
DisposeStr(S);
end;
{---------------------------- EditDOSEnvironment -----------------------------}
//JO: 29-01-2005 - ¯®¤¤¥p¦ª § 票© ¯¥p¥¬¥ëå ®ªp㦥¨ï
// ¤«¨®© ¡®«¥¥ 255 ᨬ¢®«®¢
//p¨¬.: ¢ áâ®ï騩 ¬®¬¥â ¯®¯ë⪠¨á¯®«ì§®¢ âì áâp®ªã ¢¢®¤ ¤«¨®© ¡®«¥¥
// 18517 ᨬ¢®«®¢ ¯p¨¢®¤¨â ª ¯ ¤¥¨î DN/2. ®ª ¢á直© á«ãç ©
// ®£p ¨ç¨« ¤«¨ã áâp®ª¨ ¢¢®¤ 16383 ᨬ¢®« ¬¨ (á¬. dn.dnr, p¥áãpáë
// ¤¨ «®£ dlgEditEnvironment)
type
PDOSVar = ^TDOSVar;
TDOSVar = object(TObject)
Name: PString;
Value: AnsiString; {JO}
constructor Init(P: PChar; NameLen, ValueLen: Longint);
destructor Done; virtual;
end;
PVarList = ^TVarList;
TVarList = object(TListBox)
Line: PLongInputLine;
PrevFocused: Integer;
SText: PView;
procedure FocusItem(Item: LongInt); virtual;
function GetText(Item: LongInt; MaxLen: Integer): String; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
end;
{ TDOSVar }
constructor TDOSVar.Init(P: PChar; NameLen, ValueLen: Longint);
{P - ®¯à¥¤¥«¥¨¥ ®¤®© ¯¥à¥¬¥®© ®ªà㦥¨ï ¢¨¤ 'LANG=ru_RU',
#0 ¢ ª®æ¥ ¥ £ à â¨àã¥âáï.
H ¯à¨¬¥à, ¤«ï 'LANG=ru_RU' ¡ã¤¥â NameLen=4, ValueLen=5 }
begin
Inherited Init;
{ ã⠥ᯮ¤àãç® ¢ë§ë¢ âì NewStr, ¯®íâ®ã ¤¨. áâபã ä®à¬¨à㥬 á ¬¨ }
GetMem(Name, NameLen+1);
SetLength(Name^, NameLen);
Move((P)^, Name^[1], NameLen);
SetLength(Value, ValueLen);
StrLCopy(@Value[1], P+NameLen+1, ValueLen)
end;
destructor TDOSVar.Done;
begin
DisposeStr(Name);
inherited Done;
end;
{ TVarList }
procedure TVarList.FocusItem;
var
P: PDOSVar;
begin
if (PrevFocused >= 0) and
(List <> nil) and (Focused < List^.Count)
then
P := List^.At(Focused)
else
P := nil;
if P <> nil then
Line^.GetData(P^.Value);
PrevFocused := Focused;
inherited FocusItem(Item);
if (List <> nil) and (Focused < List^.Count) then
P := List^.At(Focused)
else
P := nil;
if P <> nil then
begin
Line^.SetData(P^.Value);
Line^.DrawView;
end;
end { TVarList.FocusItem };
function TVarList.GetText;
var
P: PDOSVar;
begin
P := List^.At(Item);
if P <> nil then
GetText := CnvString(P^.Name)
else
GetText := '';
end;
procedure TVarList.HandleEvent;
var
P: PDOSVar;
procedure DeleteVar;
begin
if (P <> nil) and (MessageBox(GetString(dlEnvDelConfirm),
@P^.Name, mfYesNoConfirm) = cmYes)
then
begin
PrevFocused := -1;
List^.AtFree(Focused);
SetRange(List^.Count);
FocusItem(Focused);
end;
ClearEvent(Event);
DrawView;
end;
procedure AppendVar;
var
S: String;
begin
ClearEvent(Event);
S := '';
if InputBox(GetString(dlEnvAddTitle), GetString(dlEnvVariable), S,
255, hsNewVariable) <> cmOK
then
Exit;
PrevFocused := -1;
UpStr(S);
List^.AtInsert(Focused,
New(PDOSVar, Init(@s[1], Length(S), 0)));
SetRange(List^.Count);
FocusItem(Focused);
DrawView;
end;
procedure RenameVar;
var
S: String;
begin
ClearEvent(Event);
if (P = nil) then
Exit;
S := CnvString(P^.Name);
FormatStr(FreeStr, GetString(dlEnvRenVar), P^.Name);
if InputBox(FreeStr, GetString(dlFCRenameNew), S, 255, hsNewVariable)
<> cmOK
then
Exit;
UpStr(S);
DisposeStr(P^.Name);
P^.Name := NewStr(S);
DrawView;
end;
begin { TVarList.HandleEvent }
inherited HandleEvent(Event);
if (List <> nil) and (Focused < List^.Count) then
P := List^.At(Focused)
else
P := nil;
case Event.What of
evCommand:
case Event.Command of
cmOK:
begin
if P <> nil then
Line^.GetData(P^.Value);
end;
cmAddVariable:
AppendVar;
cmRenVariable:
RenameVar;
cmDelVariable:
DeleteVar;
end {case};
evBroadcast:
case Event.Command of
cmOK:
AppendVar;
cmNo:
DeleteVar;
cmYes:
RenameVar;
end {case};
end {case};
end { TVarList.HandleEvent };
procedure EditDOSEnvironment;
var
D: PDialog;
P: PView;
R: TRect;
PC: PCollection;
I: LongInt;
procedure MakeDialog;
var
R: TRect;
Control, Labl, Histry: PView;
PL: PVarList;
PI: PLongInputLine;
function IsLongInputLine(P: PView): Boolean;
begin
IsLongInputLine := TypeOf(P^) = TypeOf(TLongInputLine)
end;
function IsButton(P: PView): Boolean;
begin
IsButton := TypeOf(P^) = TypeOf(TButton)
end;
begin
D := PDialog(LoadResource(dlgEditEnvironment));
Control := D^.FirstThat(@IsButton);
R.A.X := Control^.Origin.X-1;
R.B.X := R.A.X+1;
R.A.Y := 3;
R.B.Y := 14;
Control := New(PScrollBar, Init(R));
D^.Insert(Control);
R.B.X := R.A.X;
R.A.X := 3;
PL := New(PVarList, Init(R, 1, PScrollBar(Control)));
D^.Insert(PL);
PI := PLongInputLine(D^.FirstThat(@IsLongInputLine));
if PI = nil then
begin
D^.Free;
D := nil;
exit;
end;
R.Assign(2, 2, 43, 3);
Labl := New(PLabel, Init(R, GetString(dlEnvVarLabel), PL));
D^.Insert(Labl);
PL^.Options := PL^.Options or ofPostProcess;
PL^.PrevFocused := -1;
PL^.Line := PI;
PL^.NewLisT(PC);
end { MakeDialog };
procedure DoPut(P: PDOSVar);
var
J: LongInt;
procedure Put(C: Char);
begin
Env^[i] := Byte(C);
Inc(i);
end;
begin
if (P^.Name <> nil) then
begin
for J := 1 to Length(P^.Name^) do
Put(P^.Name^[J]);
Put('=');
for J := 1 to Length(P^.Value) do
Put(P^.Value[J]);
Put(#0);
end;
end;
var
n1, n2: Longint;
begin { EditDOSEnvironment }
New(PC, Init(10, 10));
I := 0;
while Env^[I] <> 0 do
begin
n1 := I; n2 := I;
while Env^[I] <> 0 do
begin
if Char(Env^[I]) = '=' then
n2 := I;
Inc(I)
end;
// JO: ¨¬ï ¯¥p¥¬¥®© ®ªp㦥¨ï ¥ ¬®¦¥â ¡ëâì ¤«¨¥¥ 255 ᨬ¢®«®¢,
// ¯® ªp ©¥© ¬¥p¥ ¬¥ â ª¨¥ ¨§¢p âë ¥¨§¢¥áâë. ª çâ® ¥á«¨
// çâ®-â® â ª®¥ áâp ®¥ ¢áâp¥â¨âáï (çâ® ¯p ªâ¨ç¥áª¨ ¬ «®¢¥p®ïâ®),
// â® p §ã¬¥¥ ¡ã¤¥â â ªãî ¯¥p¥¬¥ãî ®ªp㦥¨ï ¯p®áâ® ¯p®¨£®p¨p®¢ âì
if (n1 <> n2) and (n2 - n1 < 255) then
PC^.Insert(New(PDOSVar, Init(PChar(Env) + n1, n2-n1, I-n2-1)));
Inc(I);
end;
MakeDialog;
if Desktop^.ExecView(D) = cmOK then
begin
I := 0;
PC^.ForEach(@DoPut);
Env^[I] := 0;
Env^[I+1] := 0;
Env^[I+2] := 0;
Env^[I+3] := 0;
Env^[I+4] := 0;
Env^[I+5] := 0;
end;
D^.Free;
Dispose(PC, Done);
end { EditDOSEnvironment };
(*****************************************************************
*
* FUNCTION: InitHighLight
*
* PURPOSE: This function initializes highlight parameters and
* editor options defined in DN.HGL file.
*
* INPUTS: FName - Source file openend with viewer of
* editor.
* HiLitePar - Buffer for parameters used during
* coloring text.
* Macros - A collection for editor macros.
* Can be nil for viewers.
* EdOptions - Pointer to buffer for additional editor
* options. Can be nil for viewers.
*
* OUTPUTS: HiLitePar - Buffer with highlighting data.
* Macros - With new macros.
* EdOptions - With updated options.
*
* RETURNS: FALSE - When file is not defined in DN.HGL or
* if there is a definition 'HIGHLIGHT OFF'.
* TRUE - Elsewhere.
*
* NOTES:
*
* HISTORY: 2000.06.09 - PZ - Changed interface.
*
*****************************************************************)
function InitHighLight
(const FName: String;
var HiLitePar: THighliteParams;
Macros: PCollection;
EdOptions: PEditOptions): Boolean;
var
F: PTextReader;
I: Integer;
CaseStr: String; {PZ - 2000.04.11}
function Found(const S: String): Boolean;
begin
if Copy(FreeStr, 1, Length(S)) = S then
begin
Found := True;
Delete(FreeStr, 1, Length(S));
DelLeft(FreeStr);
Delete(CaseStr, 1, Length(S)); {PZ - 2000.04.11}
DelLeft(CaseStr); {PZ}
end
else
Found := False;
end;
procedure InsertMacro;
var
P: PEditMacros;
begin
if Macros = nil then
Exit;
New(P, Init(FreeStr, F));
if (P^.Commands^.Count = 0) or (Macros^.IndexOf(P) >= 0)
then
Dispose(P, Done)
else
Macros^.Insert(P);
end;
function IsOn: Boolean;
begin
IsOn := (FreeStr = 'YES') or (FreeStr = 'ON');
end;
procedure MakeValue(var V: Word);
var
J: Integer;
begin
System.Val(FreeStr, J, i);
if (J >= 0) and (i = 0) then
V := J;
end;
{PZ - 2000.05.13 - begin }
procedure MakeStrings(Index: THighliteRule);
begin
while CaseStr <> '' do
begin
i := System.Pos(',', CaseStr);
if i = 0 then
i := Length(CaseStr)+1;
if i > 1 then
InsertHighliteRule(HiLitePar, Index, Copy(CaseStr, 1, i-1));
Delete(CaseStr, 1, i);
DelLeft(CaseStr);
end;
end;
{PZ - end }
procedure MakeDefaults;
var
j: Integer;
begin
while not F^.Eof do
begin
CaseStr := fDelLeft(fDelRight(F^.GetStr));
FreeStr := UpStrg(CaseStr);
if (FreeStr = '') or (FreeStr[1] = ';') then
Continue;
if Found('FILES ') or Found('END') then
Break;
if Found('MACRO ') then
InsertMacro
else
{PZ - 2000.04.14 - begin }
if Found('COMMENT ') then
begin
while CaseStr <> '' do
begin
i := System.Pos(',', CaseStr);
j := System.Pos(' ', CaseStr);
if i = 0 then
i := Length(CaseStr)+1;
if (j > 1) and (j < i-1) then
begin
FreeStr := Copy(CaseStr, 1, j-1)+#13;
Delete(CaseStr, 1, j);
DelLeft(CaseStr);
i := System.Pos(',', CaseStr);
if i = 0 then
i := Length(CaseStr)+1;
FreeStr := FreeStr+Copy(CaseStr, 1, i-1);
DelRight(FreeStr);
InsertHighliteRule(HiLitePar, hrCommentStrings, FreeStr);
end;
Delete(CaseStr, 1, i);
DelLeft(CaseStr);
end;
end
else if Found('COMMENTSTART ') then
MakeStrings(hrCommentStarts)
else if Found('COMMENTSTRING ') then
MakeStrings(hrCommentStrings)
else if Found('KEYWORDS1 ') then
MakeStrings(hrKeywords1)
else if Found('KEYWORDS2 ') then
MakeStrings(hrKeywords2)
else if Found('GENERALFLAGS ') then
MakeValue(HiLitePar.GenFlags)
else if Found('HEXNUMFLAGS ') then
MakeValue(HiLitePar.HexFlags)
else if Found('DECNUMFLAGS ') then
MakeValue(HiLitePar.DecFlags)
else if Found('OCTONUMFLAGS ') then
MakeValue(HiLitePar.OctFlagsO)
else if Found('OCTQNUMFLAGS ') then
MakeValue(HiLitePar.OctFlagsQ)
else if Found('BINNUMFLAGS ') then
MakeValue(HiLitePar.BinFlags)
else if Found('STRINGFLAGS ') then
MakeValue(HiLitePar.StrFlags)
else
{PZ - end }
{PZ - 2000.06.09 - begin }
if Found('HIGHLIGHT ') then
InitHighLight := IsOn
else if EdOptions <> nil then
begin
if Found('H_LINE ') or Found('H_ROW ') then
EdOptions^.HiliteLine := IsOn
else if Found('H_COLUMN ') then
EdOptions^.HiliteColumn := IsOn
else if Found('WRAPJUSTIFY ') then
EdOptions^.AutoJustify := IsOn
else if Found('AUTOWRAP ') then
EdOptions^.AutoWrap := IsOn
else if Found('LEFTMARGIN ') then
MakeValue(EdOptions^.LeftSide)
else if Found('RIGHTMARGIN ') then
MakeValue(EdOptions^.RightSide)
else if Found('PARAGRAPH ') then
MakeValue(EdOptions^.InSide)
else if Found('FORCECRLF ') then
EdOptions^.ForcedCRLF := cfCRLF
else if Found('FORCECR ') then
EdOptions^.ForcedCRLF := cfCR
else if Found('FORCELF ') then
EdOptions^.ForcedCRLF := cfLF
end
{PZ - end }
end
end { MakeDefaults };
begin { InitHighLight }
if Macros <> nil then
Macros^.FreeAll;
InitHighLight := False; {PZ 2000.06.09 Default is No Highlight }
FillChar(HiLitePar, SizeOf(HiLitePar), 0);
F := New(PTextReader, Init(SourceDir+'DN.HGL'));
if F = nil then
Exit;
while not F^.Eof do
begin