1
1
Program Teco;
2
- {
3
- The Last remake of TECO, a nice editor....
4
-
5
- Copyright (C) 1989-2021 Michael Warot, all rights reserved.
6
-
7
- Disclaimer: The author makes no warantee, expressed or implied.
8
- Use this software strickly at your own risk.
9
-
10
- "Back when I was 25, we didn't have any fancy windows and mice...
11
- AND WE LIKED IT THAT WAY!", yeah, SSSSSUUUURRRRREEEEE....
12
-
13
- Rev
14
- 4 - Add command input routine, begin implementing a simple
15
- command interpreter
16
- 5 - Implement string parameters
17
- 6 - Implement number parameters and a small (10) stack
18
- 7 - Implement a simple form of numeric expressions
19
- 8 - Procedure Execute added, to allow commands to come from multiple
20
- sources, and allow the "current" buffer to be one of many.
21
- Add LineOriented()
22
- 9 - Move TBuffer and Tstack out to separate units
23
- Add ExecStr()
24
- 10 - More debugging....
25
- 11 - File oriented I/O, buffers, etc.
26
- 12 - Remove ExecStr()
27
- Make all q-registers general purpose.... (You're right, Ken)
28
- procedures use pointers instead of VAR parameters
29
- 13 - Add search and replace. (Pattern matching supported, but slow).
30
-
31
- 1/21/91 - MAW
32
- 14 - Write first draft of TECO.DOC, revise code to more closely match
33
- definitions in DEC's manual.
34
-
35
- 1/21/91 - MAW - Big problem, because of the interpretive nature of the
36
- current implementation, conditional branching looks to be
37
- a real problem. Considering "compiling" commands, which
38
- would eliminate most semantic ambiguities, in addition
39
- to increasing the speed of operations.
40
-
41
-
42
- Varsion 100 - experimental, compiling version. (NOT COMPILING!)
43
-
44
- Notes: Flag "C" and 1 is the Case Sensitive flag, default off (0)
45
- Flag "T" and 8 is the NO ECHO flags, default off (echo keys)
46
-
47
- 7/17/91 - Replace all tbuffer references with tbuf, to allow for file I/O.
48
- A simple search/replace command actually works now!
49
- First release to the public
50
-
51
- 7/22/91 - Correct bug in GetConstant which pushed junk on the stack
52
- - Correct logic fault, never allow GetStringParam to be inside
53
- a conditional if an argument is REQUIRED, if the procedure isn't
54
- called, the argument becomes part of the command, not just
55
- another parameter! Append is the one exception to this rule.
56
- 7/23/91 - Fix bug in Search, wouldn't find a match at the current cursor
57
- position.
58
-
59
- 7/25/91 - Fix bug (feature?) which caused EX in a .INI file to be ignored
60
- - Add StringSearch, a MUCH faster engine for searching through
61
- the buffer. Supports most of the "String Build" characters
62
-
63
- 1.03á--- release?
64
-
65
- 12/03/91 - Modify code to use Release(QStack.Pop,Done) to eliminate bug
66
- which eats memory. Old version didn't properly page text...
67
-
68
- Modify ExitLoop to pass F> in a command
69
-
70
- 01/03/2021 - Modify code to work in Windows 10, 64 Bit,
71
- on a machine with with more Disk and RAM than MS-DOS could even access.
72
-
73
- }
74
2
Uses
75
3
Stacks,
76
- Buff ,
4
+ TextBuffers ,
77
5
DOS,CRT;
78
6
Const
79
7
ESC = #27 ;
@@ -104,24 +32,6 @@ begin
104
32
GetKey := x;
105
33
end ;
106
34
107
- (*
108
- Function GetKey : Word; Assembler;
109
- Asm
110
- xor ax,ax { Keyboard int, get key }
111
- int $16
112
- End;
113
-
114
- Function KeyPressed : Boolean; Assembler;
115
- Asm
116
- mov ax,1
117
- int $16 { Keyboard int, get status }
118
- mov ax,0 { Zero flag set = no key }
119
- jz @@1
120
- inc ax
121
- @@1: { 1 if key ready, 0 if not }
122
- End;
123
- *)
124
-
125
35
Function Qnum (X : Char):Byte;
126
36
Const
127
37
Qxlat : Array [0 ..127 ] of Byte =
146
56
QStack : OStack;
147
57
Done : Boolean;
148
58
Flags : Array [0 ..37 ] of Longint;
149
- Qregs : Array [0 ..37 ] of PBuf ; { Q registers }
59
+ Qregs : Array [0 ..37 ] of PTextFileBuffer ; { Q registers }
150
60
Qnums : Array [0 ..37 ] of Longint; { Q registers, numeric part }
151
61
BitMask : Array [0 ..255 ] of Longint; { Used in StringSearch }
152
62
153
- function CmdChar (cmd : pbuf ):Char;
63
+ function CmdChar (cmd : PTextFileBuffer ):Char;
154
64
var
155
65
c : char;
156
66
begin
@@ -169,15 +79,15 @@ Function StringCompare(P1,P2 : Pointer):Longint;
169
79
}
170
80
Var
171
81
Data,
172
- Pattern : pbuf ;
82
+ Pattern : PTextFileBuffer ;
173
83
Old1,Old2 : TextPtr;
174
84
CaseSensitive : Boolean;
175
85
c : char;
176
86
Match : Boolean;
177
87
Size : Longint;
178
88
Begin
179
- Pattern := pbuf (P1);
180
- Data := pbuf (P2);
89
+ Pattern := PTextFileBuffer (P1);
90
+ Data := PTextFileBuffer (P2);
181
91
CaseSensitive := (Flags[13 ] AND 1 ) <> 0 ;
182
92
Match := True;
183
93
Old1 := Pattern^.WhereAt;
216
126
217
127
218
128
219
- Function StringSearch (Pattern,Data : PBuf ):Longint;
129
+ Function StringSearch (Pattern,Data : PTextFileBuffer ):Longint;
220
130
{
221
131
A new, faster search engine.
222
132
ONLY GOES 31 characters!
@@ -364,13 +274,13 @@ Begin
364
274
end ;
365
275
End ;
366
276
367
- Procedure Compile_And_Execute (Var Cmd, Data : pbuf );
277
+ Procedure Compile_And_Execute (Var Cmd, Data : PTextFileBuffer );
368
278
Begin
369
279
End ;
370
280
371
281
372
282
373
- Procedure Execute (Var Cmd, Data : pbuf );
283
+ Procedure Execute (Var Cmd, Data : PTextFileBuffer );
374
284
Var
375
285
Delim : Char; { #0 if '@' prefix used }
376
286
ColonPrefix : Boolean;
415
325
GetConstant := T;
416
326
End ;
417
327
418
- Function ValidNumber (Var B : pbuf ) : Boolean;
328
+ Function ValidNumber (Var B : PTextFileBuffer ) : Boolean;
419
329
var
420
330
ok : boolean;
421
331
t : longint;
479
389
480
390
(* ******* String parameter routines **********)
481
391
482
- Function GetStringParam (Var B : pbuf ;
392
+ Function GetStringParam (Var B : PTextFileBuffer ;
483
393
Var P : Pointer;
484
- Var S : Word ) : Boolean;
394
+ Var Size : NativeUint ) : Boolean;
485
395
Var
486
396
Ok : Boolean;
487
397
Begin
@@ -491,12 +401,12 @@ Var
491
401
cmd^.Move(+1 );
492
402
end ;
493
403
P := cmd^.ThisCharP; { Pointer to buffer }
494
- S := cmd^.WhereAt; { Current char # }
404
+ Size := cmd^.WhereAt; { Current char # }
495
405
While (NOT Cmd^.AtEnd) AND (cmd^.ThisChar <> Delim) do
496
406
cmd^.Move(+1 );
497
407
If cmd^.ThisChar = Delim then
498
408
begin
499
- S := (cmd^.WhereAt - S );
409
+ Size := (cmd^.WhereAt - Size );
500
410
Ok := True;
501
411
cmd^.Move(+1 );
502
412
end
@@ -523,11 +433,11 @@ Var
523
433
end ;
524
434
end ; { LineOriented }
525
435
526
- procedure InsertMacro (Var Dest : pbuf );
436
+ procedure InsertMacro (Var Dest : PTextFileBuffer );
527
437
var
528
438
x : char;
529
439
p1 : pointer;
530
- s1 : word ;
440
+ s1 : NativeUint ;
531
441
begin
532
442
If ColonPrefix then { Append }
533
443
Dest^.JumpTo(Dest^.EndPtr);
@@ -543,12 +453,12 @@ Var
543
453
end ;
544
454
end ;
545
455
546
- function Qregister : pbuf ;
456
+ function Qregister : PTextFileBuffer ;
547
457
var
548
458
c : integer;
549
459
begin
550
460
c := Qnum(cmd^.ThisChar); cmd^.Move(+1 );
551
- if qregs[c] = nil then qregs[c] := new(PBuf ,Init(DefaultSize));
461
+ if qregs[c] = nil then qregs[c] := new(PTextFileBuffer ,Init(DefaultSize));
552
462
Qregister := Qregs[c];
553
463
end ;
554
464
567
477
end ;
568
478
569
479
if cmd^.thischar <> ' >' then
570
- error (' loop missing ending ">"!' )
480
+ ReportError (' loop missing ending ">"!' )
571
481
else
572
482
if xout then cmd^.move(+1 ); { Mod for skip to > }
573
483
end ;
577
487
begin
578
488
If LoopStack.Empty then
579
489
begin
580
- Error (' not in a loop!' );
490
+ ReportError (' not in a loop!' );
581
491
inloop := false;
582
492
end
583
493
else
598
508
end ;
599
509
600
510
if (cmd^.thischar <> ' |' ) AND (cmd^.thischar <> ' '' ' ) then
601
- error (' loop missing ending ">"!' )
511
+ ReportError (' loop missing ending ">"!' )
602
512
else
603
513
cmd^.move(+1 );
604
514
end ;
616
526
end ;
617
527
618
528
if cmd^.thischar <> ' '' ' then
619
- error (' loop missing ending "'' "!' )
529
+ ReportError (' loop missing ending "'' "!' )
620
530
else
621
531
cmd^.move(+1 );
622
532
end ;
625
535
C,X : Char;
626
536
I,J,K : Longint;
627
537
P1,P2 : Pointer;
628
- S1,S2 : Word ;
538
+ S1,S2 : NativeUint ;
629
539
S : String;
630
- Q : pbuf ;
540
+ Q : PTextFileBuffer ;
631
541
kludge : integer;
632
542
begin
633
543
cmd^.JumpTo(0 );
@@ -702,8 +612,8 @@ begin
702
612
else k := Stack.Pop;
703
613
If GetStringParam(Cmd,P1,S1) then
704
614
begin
705
- QStack.Push(New(pbuffer ,Cpy(P1,S1)));
706
- Stack.Push( StringSearch(Pbuf (Qstack.Top),Data) );
615
+ QStack.Push(New(PTextBuffer ,Cpy(P1,S1)));
616
+ Stack.Push( StringSearch(PTextFileBuffer (Qstack.Top),Data) );
707
617
Dispose(QStack.Pop,Done);
708
618
end ;
709
619
end ;
@@ -714,15 +624,15 @@ begin
714
624
else k := Stack.Pop;
715
625
If GetStringParam(Cmd,P1,S1) then
716
626
begin
717
- QStack.Push(New(pbuffer ,Cpy(P1,S1)));
627
+ QStack.Push(New(PTextBuffer ,Cpy(P1,S1)));
718
628
719
629
While (k > 0 ) AND (Not Data^.AtEnd) do
720
630
begin
721
631
i := StringCompare(QStack.Top,Data);
722
632
if (i <> 0 ) then
723
633
begin
724
634
dec(k);
725
- Data^.Move(pbuf (QStack.Top)^.EndPtr); { AFTER match}
635
+ Data^.Move(PTextFileBuffer (QStack.Top)^.EndPtr); { AFTER match}
726
636
end
727
637
else
728
638
Data^.Move(+1 );
@@ -735,7 +645,7 @@ begin
735
645
if k <> 0 then
736
646
Data^.Move(-1 )
737
647
else
738
- Data^.Move(pbuf (QStack.Top)^.EndPtr); { AFTER match}
648
+ Data^.Move(PTextFileBuffer (QStack.Top)^.EndPtr); { AFTER match}
739
649
end ;
740
650
741
651
Dispose(QStack.Pop,Done);
@@ -798,7 +708,7 @@ begin
798
708
end ;
799
709
' C' : begin { close the current buffer }
800
710
Data^.Done;
801
- Data := New(PBuf ,Init(DefaultSize));
711
+ Data := New(PTextFileBuffer ,Init(DefaultSize));
802
712
end ;
803
713
804
714
' Q' : begin
@@ -1009,7 +919,7 @@ begin
1009
919
{ Not Zero } ' N' : If I = 0 then
1010
920
GotoElse;
1011
921
else
1012
- Error (' Undefined Conditional!' );
922
+ ReportError (' Undefined Conditional!' );
1013
923
End ;
1014
924
end ;
1015
925
@@ -1029,7 +939,7 @@ begin
1029
939
end ;
1030
940
end ; { Execute() }
1031
941
1032
- procedure GetCommand (var cmd : pbuf );
942
+ procedure GetCommand (var cmd : PTextFileBuffer );
1033
943
var
1034
944
C,X,Last : KeyStroke;
1035
945
begin
@@ -1109,10 +1019,10 @@ Begin
1109
1019
LoopStack.Init;
1110
1020
QStack.Init;
1111
1021
1112
- Qregs[11 ] := PBuf (New(PBuffer ,Cpy(@CommandP[1 ],Length(CommandP)) ) );
1022
+ Qregs[11 ] := PTextFileBuffer (New(PTextBuffer ,Cpy(@CommandP[1 ],Length(CommandP)) ) );
1113
1023
1114
- Qregs[37 ] := New(PBuf ,Load(INIname));
1115
- Qregs[Current] := New(PBuf ,Init(DefaultSize));
1024
+ Qregs[37 ] := New(PTextFileBuffer ,Load(INIname));
1025
+ Qregs[Current] := New(PTextFileBuffer ,Init(DefaultSize));
1116
1026
1117
1027
Done := False;
1118
1028
0 commit comments