-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCALC.PAS
4193 lines (3867 loc) · 122 KB
/
CALC.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
{Remarque
ÍÍÍÍÍÍÍÍ
þ Cette unit‚ est bƒtie … partir du tableau de Borland Turbo Pascal 5.5.
}
Unit Calc;
INTERFACE
{$I DEF.INC}
Uses {$IFDEF Adele}Adele,{$ELSE}Chantal,{$ENDIF}
Systex,Systems,Video,Dials,Dos,Numerix,CalcType;
Function GetKeyUpCase:Wd;
Function GetKeyChar(Legal:CharSet):Char;
Function Col2Str(Col:Wd):String;
Function Str2Col(S:String;MaxCols:Wd):Wd;
Function Str2Row(Const S:String;MaxRows:Wd):Wd;
Type
BasePtr=^Base;
Base=Object
Destructor Done;Virtual;
End;
StreamPtr=^Stream;
Stream=Object(Base)
TypeCount:Wd;
TypeList:STypeListPtr;
ProcList:SProcListPtr;
Status:Int;
Constructor Init;
Destructor Done;Virtual;
Procedure Error(Code:Int);Virtual;
Procedure Flush;Virtual;
Function GetPos:Long;Virtual;
Procedure Read(Var Buf;Count:Wd);Virtual;
Procedure RegisterTypes;Virtual;
Procedure SetPos(Pos:Long;Mode:Byte);Virtual;
Procedure Truncate; Virtual;
Procedure Write(Var Buf;Count:Wd);Virtual;
Function Get:BasePtr;
Function GetSize:Long;
Procedure Put(B:BasePtr);
Procedure Register(TypePtr,StorePtr,LoadPtr:Pointer);
Procedure Seek(Pos:Long);
End;
DosStreamPtr=^DosStream;
DosStream=Object(Stream)
Handle:Wd;
Constructor Init(FileName:PathStr;Mode:Wd);
Destructor Done;Virtual;
Function GetPos:Long;Virtual;
Procedure Read(Var Buf;Count:Wd);Virtual;
Procedure SetPos(Pos:Long;Mode:Byte);Virtual;
Procedure Truncate;Virtual;
Procedure Write(Var Buf;Count:Wd);Virtual;
Procedure Close;
Procedure Open(Var Name;Mode:Wd);
End;
BufStreamPtr=^BufStream;
BufStream=Object(DosStream)
Buffer:Pointer; BufSize,BufPtr,BufEnd:Wd;
Constructor Init(FileName:PathStr;Mode,Size:Wd);
Destructor Done; Virtual;
Procedure Flush; Virtual;
Function GetPos:Long; Virtual;
Procedure Read(Var Buf;Count:Wd); Virtual;
Procedure Write(Var Buf;Count:Wd); Virtual;
End;
InputField=Record
W:Wins; StartCol:Byte; StopCol,InputRow:Int; MaxInputLen:Wd;
Quit:Bool;InputData:LStringPtr;UCase:Bool;
{InputArea:ScreenArea;}
End;
BucketRange=1..MaxBuckets;
HashItemSizeRange=1..MaxHashItemSize;
HashItemData=Array[0..Pred(MaxHashItemSize)]of Byte;
HashItemDataPtr=^HashItemData;
HashItemPtr=^HashItem;
HashItem=Record Next:HashItemPtr; Data:HashItemData; End;
HashItemArray=Array[BucketRange]of HashItemPtr;
HashTable=Object
Buckets:BucketRange; Items:Long; CurrItem:HashItemPtr;
CurrBucket:BucketRange; HashData:^HashItemArray;
Constructor Init(InitBuckets:BucketRange);
Destructor Done;
Function Add:Bool;
Procedure Delete(Deleted:Pointer);
Function FirstItem:HashItemPtr;
Function NextItem:HashItemPtr;
Function Change:Bool;
Function Search:HashItemPtr;
Function HashValue:Wd;Virtual;
Function Found(Item:HashItemPtr):Bool;Virtual;
Procedure CreateItem(Var Item:HashItemPtr);Virtual;
Function ItemSize:HashItemSizeRange;Virtual;
Function CurrItemSize(Item:HashItemPtr):HashItemSizeRange;Virtual;
End;
SSStream=Object(DosStream)Procedure RegisterTypes;Virtual;End;
Block=Record
Start,Stop:CellPos;
End;
CellHashTablePtr=^CellHashTable;
CellPtr=^Cell;
CellHashTable=Object(HashTable)
CurrCell:CellPtr;
CurrLoc:CellPos;
Constructor Init(InitBuckets:BucketRange);
Destructor Done;
Function Add(ACell:CellPtr):Bool;
Procedure Delete(DelLoc:CellPos;Var DeletedCell:CellPtr);
Function Search(SPos:CellPos):CellPtr;
Function HashValue:Wd;Virtual;
Function Found(Item:HashItemPtr):Bool;Virtual;
Procedure CreateItem(Var Item:HashItemPtr);Virtual;
Function ItemSize:HashItemSizeRange;Virtual;
Procedure Load(Var S:SSStream;Total:Long);
Procedure Store(Var S:SSStream);
Function FirstItem:CellPtr;
Function NextItem:CellPtr;
End;
FormatHashTable=Object(HashTable)
CurrStart,CurrStop:CellPos;
CurrFormat:Byte;
Constructor Init;
Destructor Done;
Function Overwrite(NewStart,NewStop:CellPos):Bool;
Function Add(NewStart,NewStop:CellPos;NewFormat:Byte):Bool;
Function Delete(DStart,DStop:CellPos):Bool;
Function Search(SPos:CellPos;Var F:Byte):Bool;
Function HashValue:Wd;Virtual;
Function Found(Item:HashItemPtr):Bool;Virtual;
Procedure CreateItem(Var Item:HashItemPtr);Virtual;
Function ItemSize:HashItemSizeRange;Virtual;
Procedure Load(Var S:SSStream;Total:Long);
Procedure Store(Var S:SSStream);
End;
WidthHashTable=Object(HashTable)
CurrCol:Wd; CurrWidth,DefaultColWidth:Byte;
Constructor Init(InitBuckets:BucketRange;InitDefaultColWidth:Byte);
Destructor Done;
Function Add(SCol:Wd;NewWidth:Byte):Bool;
Procedure Delete(Col:Wd);
Function Search(Col:Wd):Byte;
Function HashValue:Wd;Virtual;
Function Found(Item:HashItemPtr):Boolean;Virtual;
Procedure CreateItem(Var Item:HashItemPtr);Virtual;
Function ItemSize:HashItemSizeRange;Virtual;
Function GetDefaultColWidth:Byte;
Procedure Load(Var S:SSStream;Total:Long);
Procedure Store(Var S:SSStream);
End;
OverwriteHashTable=Object(HashTable)
CurrCell:CellPtr; CurrPos:CellPos; EndCol:Wd;
Constructor Init(InitBuckets:BucketRange);
Destructor Done;
Function Add(SCell:CellPtr;Overwritten:Wd):Bool;
Procedure Delete(SPos:CellPos);
Function Change(SCell:CellPtr;Overwritten:Wd):Bool;
Function Search(SPos:CellPos):CellPtr;
Function HashValue:Wd;Virtual;
Function Found(Item:HashItemPtr):Bool;Virtual;
Procedure CreateItem(Var Item:HashItemPtr);Virtual;
Function ItemSize:HashItemSizeRange;Virtual;
End;
GetColWidthFunc=Function(Var WHash:WidthHashTable;C:Wd):Byte;
Cell=Object(Base)
Loc:CellPos;
Constructor Init(InitLoc:CellPos);
Destructor Done;Virtual;
Function CellType:CellTypes;Virtual;
Function LegalValue:Bool;Virtual;
Function Name:String;Virtual;
Function Format(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Byte;Virtual;
Function Width(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Wd;Virtual;
Function Overwritten(Var CHash:CellHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;Var LastPos:CellPos;MaxCols:Wd;
GetColWidth:GetColWidthFunc;FormulasDisplayed:Bool):Wd;Virtual;
Function ShouldUpdate:Bool;Virtual;
Function HasError:Bool;Virtual;
Function CurrValue:Extended;Virtual;
Function OverwriteStart(Var FHash:FormatHashTable;Var WHash:WidthHashTable;
GetColWidth:GetColWidthFunc;EndCol:Wd;DisplayFormulas:Bool):Wd;Virtual;
Procedure EditString(MaxDecPlaces:Byte;Var L:LStringPtr);Virtual;
Function DisplayString(FormulasDisplayed:Bool;MaxDecPlaces:Byte):String;Virtual;
Function FormattedString(Var OHash:OverwriteHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;GetColWidth:GetColWidthFunc;CPos:CellPos;
FormulasDisplayed:Bool;Start:Wd;ColWidth:Byte;Var DString:DollarStr;
Var Color:Byte):String;Virtual;
Function CopyString(ColLit,RowLit:Bool;Diff:Long;Var L:LStringPtr):LStringPtr;Virtual;
End;
EmptyCellPtr=^EmptyCell;
EmptyCell=Object(Cell)
Constructor Init;
Function CellType:CellTypes;Virtual;
Function LegalValue:Bool;Virtual;
Function Name:String;Virtual;
Function Format(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Byte;Virtual;
Function Width(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Wd;Virtual;
Function Overwritten(Var CHash:CellHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;Var LastPos:CellPos;MaxCols:Wd;
GetColWidth:GetColWidthFunc;FormulasDisplayed:Boolean):Wd;Virtual;
Function ShouldUpdate:Bool;Virtual;
Function HasError:Bool;Virtual;
Function CurrValue:Extended;Virtual;
Function OverwriteStart(Var FHash:FormatHashTable;Var WHash:WidthHashTable;
GetColWidth:GetColWidthFunc;EndCol:Wd;DisplayFormulas:Bool):Wd;Virtual;
Procedure EditString(MaxDecPlaces:Byte;Var L:LStringPtr);Virtual;
Function DisplayString(FormulasDisplayed:Bool;MaxDecPlaces:Byte):String;Virtual;
Function FormattedString(Var OHash:OverwriteHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;GetColWidth:GetColWidthFunc;CPos:CellPos;
FormulasDisplayed:Bool;Start:Wd;ColWidth:Byte;Var DString:DollarStr;
Var Color:Byte):String;Virtual;
Function CopyString(ColLit,RowLit:Bool;Diff:Long;Var L:LStringPtr):LStringPtr;Virtual;
End;
ValueCellPtr=^ValueCell;
ValueCell=Object(Cell)
Error:Bool; Value:Extended;
Constructor Init(InitLoc:CellPos;InitError:Bool;InitValue:Extended);
Function CellType:CellTypes;Virtual;
Function LegalValue:Bool;Virtual;
Function Name:String;Virtual;
Function Format(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Byte;Virtual;
Function Width(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Wd;Virtual;
Function Overwritten(Var CHash:CellHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;Var LastPos:CellPos;MaxCols:Wd;
GetColWidth:GetColWidthFunc;FormulasDisplayed:Boolean):Wd;Virtual;
Function ShouldUpdate:Bool;Virtual;
Function HasError:Bool;Virtual;
Function CurrValue:Extended;Virtual;
Function OverwriteStart(Var FHash:FormatHashTable;Var WHash:WidthHashTable;
GetColWidth:GetColWidthFunc;EndCol:Wd;DisplayFormulas:Bool):Wd;Virtual;
Procedure EditString(MaxDecPlaces:Byte;Var L:LStringPtr);Virtual;
Function DisplayString(FormulasDisplayed:Bool;MaxDecPlaces:Byte):String;Virtual;
Function FormattedString(Var OHash:OverwriteHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;GetColWidth:GetColWidthFunc;CPos:CellPos;
FormulasDisplayed:Bool;Start:Wd;ColWidth:Byte;Var DString:DollarStr;
Var Color:Byte):String;Virtual;
Function CopyString(ColLit,RowLit:Bool;Diff:Long;Var L:LStringPtr):LStringPtr;Virtual;
Constructor Load(Var S:SSStream);
Procedure Store(Var S:SSStream);
End;
TextCellPtr=^TextCell;
TextCell=Object(Cell)
Txt:LStringPtr;
Constructor Init(InitLoc:CellPos;InitTxt:LStringPtr);
Destructor Done;Virtual;
Function CellType:CellTypes;Virtual;
Function LegalValue:Bool;Virtual;
Function Name:String;Virtual;
Function Format(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Byte;Virtual;
Function Width(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Wd;Virtual;
Function Overwritten(Var CHash:CellHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;Var LastPos:CellPos;MaxCols:Wd;
GetColWidth:GetColWidthFunc;FormulasDisplayed:Bool):Wd;Virtual;
Function ShouldUpdate:Bool;Virtual;
Function HasError:Bool;Virtual;
Function CurrValue:Extended;Virtual;
Function OverwriteStart(Var FHash:FormatHashTable;Var WHash:WidthHashTable;
GetColWidth:GetColWidthFunc;EndCol:Wd;DisplayFormulas:Bool):Wd;Virtual;
Procedure EditString(MaxDecPlaces:Byte;Var L:LStringPtr);Virtual;
Function DisplayString(FormulasDisplayed:Bool;MaxDecPlaces:Byte):String;Virtual;
Function FormattedString(Var OHash:OverwriteHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;GetColWidth:GetColWidthFunc;CPos:CellPos;
FormulasDisplayed:Bool;Start:Wd;ColWidth:Byte;Var DString:DollarStr;
Var Color:Byte):String;Virtual;
Function CopyString(ColLit,RowLit:Bool;Diff:Long;Var L:LStringPtr):LStringPtr;Virtual;
Constructor Load(Var S:SSStream);
Procedure Store(Var S:SSStream);
End;
FormulaCellPtr=^FormulaCell;
FormulaCell=Object(Cell)
Error:Bool; Value:Extended; Formula:LStringPtr;
Constructor Init(InitLoc:CellPos;InitError:Bool;InitValue:Extended;InitFormula:LStringPtr);
Destructor Done;Virtual;
Function CellType:CellTypes;Virtual;
Function LegalValue:Bool;Virtual;
Function Name:String;Virtual;
Function Format(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Byte;Virtual;
Function Width(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Wd;Virtual;
Function Overwritten(Var CHash:CellHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;Var LastPos:CellPos;MaxCols:Wd;
GetColWidth:GetColWidthFunc;FormulasDisplayed:Bool):Wd;Virtual;
Function ShouldUpdate:Bool;Virtual;
Function HasError:Bool;Virtual;
Function CurrValue:Extended;Virtual;
Function OverwriteStart(Var FHash:FormatHashTable;Var WHash:WidthHashTable;
GetColWidth:GetColWidthFunc;EndCol:Wd;DisplayFormulas:Bool):Wd;Virtual;
Procedure EditString(MaxDecPlaces:Byte;Var L:LStringPtr);Virtual;
Function DisplayString(FormulasDisplayed:Bool;MaxDecPlaces:Byte):String;Virtual;
Function FormattedString(Var OHash:OverwriteHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;GetColWidth:GetColWidthFunc;CPos:CellPos;
FormulasDisplayed:Bool;Start:Wd;ColWidth:Byte;Var DString:DollarStr;
Var Color:Byte):String;Virtual;
Function CopyString(ColLit,RowLit:Bool;Diff:Long;Var L:LStringPtr):LStringPtr;Virtual;
Constructor Load(Var S:SSStream);
Procedure Store(Var S:SSStream);
Function GetFormula:LStringPtr;
End;
RepeatCellPtr=^RepeatCell;
RepeatCell=Object(Cell)
RepeatChar:Char;
Constructor Init(InitLoc:CellPos;InitChar:Char);
Function CellType:CellTypes;Virtual;
Function LegalValue:Bool;Virtual;
Function Name:String;Virtual;
Function Format(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Byte;Virtual;
Function Width(Var FHash:FormatHashTable;FormulasDisplayed:Bool):Wd;Virtual;
Function Overwritten(Var CHash:CellHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;Var LastPos:CellPos;MaxCols:Wd;
GetColWidth:GetColWidthFunc;FormulasDisplayed:Bool):Wd;Virtual;
Function ShouldUpdate:Bool;Virtual;
Function HasError:Bool;Virtual;
Function CurrValue:Extended;Virtual;
Function OverwriteStart(Var FHash:FormatHashTable;Var WHash:WidthHashTable;
GetColWidth:GetColWidthFunc;EndCol:Wd;DisplayFormulas:Bool):Wd;Virtual;
Procedure EditString(MaxDecPlaces:Byte;Var L:LStringPtr);Virtual;
Function DisplayString(FormulasDisplayed:Bool;MaxDecPlaces:Byte):String;Virtual;
Function FormattedString(Var OHash:OverwriteHashTable;Var FHash:FormatHashTable;
Var WHash:WidthHashTable;GetColWidth:GetColWidthFunc;CPos:CellPos;
FormulasDisplayed:Bool;Start:Wd;ColWidth:Byte;Var DString:DollarStr;
Var Color:Byte):String;Virtual;
Function CopyString(ColLit,RowLit:Bool;Diff:Long;Var L:LStringPtr):LStringPtr;Virtual;
Constructor Load(Var S:SSStream);
Procedure Store(Var S:SSStream);
End;
ParserObj=Record
Inp:LStringPtr;
ParserHash:CellHashTablePtr;
PMaxCols,PMaxRows,Position:Wd;
CurrToken:TokenRec;
StackTop:0..ParserStackSize;
TokenError:ErrorRange;
ParseError:Bool;
CType:CellTypes;
ParseValue:Extended;
Stack:Array[1..ParserStackSize]of TokenRec;
TokenType:TokenTypes;
TokenLen:Wd;
MathError,IsFormula:Bool;
End;
ColStartArray=Array[0..80]of Byte;
ColStartPtr=^ColStartArray;
SpreadsheetPtr=^Spreadsheet;
Spreadsheet=Record
W:Wins;Number:Byte;MaxRows,MaxCols:Wd;
MaxDecimalPlaces,MaxColWidth,MaxScreenCols,DefaultColWidth:Byte;
DefaultDecimalPlaces,RowNumberSpace,ColSpace:Byte; Current,Changed:Bool;
CurrPos,LastPos:CellPos; ScreenBlock,CurrBlock:Block; BlockOn:Bool;
FileName:PathStr; TotalRows:Byte; DisplayArea,BlankArea:ScreenArea;
NoBlankArea:Bool; ColStart:ColStartPtr; DisplayFormulas,AutoCalc:Bool;
CellHash:CellHashTable; OverwriteHash:OverwriteHashTable;
WidthHash:WidthHashTable; FormatHash:FormatHashTable; Next:SpreadsheetPtr;
End;
Lotus=Record
W:Wins;
SSData,CurrSS:SpreadSheetPtr;TotalSheets:Byte;
CellInput:InputField;MaxSpreadSheets:Byte;
End;
Function IFInit(Var Q:InputField;C1:Byte;C2,R:Int;InitMaxInputLen:Wd;InitUCase:Bool):Bool;
Procedure IFDone(Var Q:InputField);
Function IFGetQuit(Var Q:InputField):Bool;
Procedure IFEdit(Var Q:InputField;StartCursor:Wd);
Procedure IFClearInput(Var Q:InputField);
Procedure BKInit(Var Q:Block;InitStart:CellPos);
Function BKExtendTo(Var Q:Block;NewLoc:CellPos):Boolean;
Function BKCellInBlock(Var Q:Block;CheckCell:CellPos):Bool;
Procedure SAInit(Var Q:ScreenArea;InitX1,InitY1,InitX2,InitY2,InitAttrib:Byte);
Procedure SAClear(Var Q:ScreenArea);
Procedure POInit(Var Q:ParserObj;InitHash:CellHashTablePtr;InitInp:LStringPtr;InitPMaxCols,InitPMaxRows:Wd);
Procedure POPush(Var Q:ParserObj;Token:TokenRec);
Procedure POPop(Var Q:ParserObj;Var Token:TokenRec);
Procedure POShift(Var Q:ParserObj;State:Wd);
Procedure POReduce(Var Q:ParserObj;Reduction:Wd);
Procedure POParse(Var Q:ParserObj);
Function POCellValue(Var Q:ParserObj;P:CellPos):Extended;
Function POGotoState(Var Q:ParserObj;Production:Wd):Wd;
Function POIsFunc(Var Q:ParserObj;Const S:String):Bool;
Function PONextToken(Var Q:ParserObj):TokenTypes;
Function SSInit(Var Q:Spreadsheet;InitCells:Long;InitMaxCols,InitMaxRows:Wd;
InitMaxDecimalPlaces,InitDefaultDecimalPlaces,InitDefaultColWidth:Byte):Bool;
Procedure SSDone(Var Q:Spreadsheet);
Function SSGetColStart(Var Q:Spreadsheet;Col:Wd):Byte;
Procedure _SSSetAreas(Var Q:Spreadsheet;NewNumber:Wd;X1,Y1,X2,Y2:Byte);
Procedure SSDisplayCols(Var Q:Spreadsheet);
Procedure SSDisplayRows(Var Q:Spreadsheet);
Procedure SSDisplayInfo(Var Q:Spreadsheet);
Procedure SSDisplayAllCells(Var Q:Spreadsheet);
Procedure SSDisplay(Var Q:Spreadsheet);
Procedure SSDisplayCell(Var Q:Spreadsheet;P:CellPos);
Procedure SSDisplayCellData(Var Q:Spreadsheet);
Procedure SSDisplayCellBlock(Var Q:Spreadsheet;C1,R1,C2,R2:Wd);
Procedure SSDisplayBlock(Var Q:Spreadsheet;B:Block);
Procedure SSDisplayBlockDiff(Var Q:Spreadsheet;B1,B2:Block);
Procedure SSDisplayCol(Var Q:Spreadsheet;Col:Wd);
Procedure SSDisplayRow(Var Q:Spreadsheet;Row:Wd);
Procedure SSDisplayFileName(Var Q:Spreadsheet);
Procedure SSSetChanged(Var Q:Spreadsheet;IsChanged:Bool);
Procedure SSMakeCurrent(Var Q:Spreadsheet);
Procedure SSMakeNotCurrent(Var Q:Spreadsheet);
Procedure SSUpdate(Var Q:Spreadsheet;UDisplay:Bool);
Procedure SSToggleFormulaDisplay(Var Q:Spreadsheet);
Procedure SSSetScreenColStart(Var Q:Spreadsheet;NewCol:Wd);
Procedure SSSetScreenColStop(Var Q:Spreadsheet;NewCol:Wd);
Procedure SSSetScreenRowStart(Var Q:Spreadsheet;NewRow:Wd);
Procedure SSSetScreenRowStop(Var Q:Spreadsheet;NewRow:Wd);
Procedure SSFindScreenColStart(Var Q:Spreadsheet);
Procedure SSFindScreenColStop(Var Q:Spreadsheet);
Procedure SSFindScreenRowStart(Var Q:Spreadsheet);
Procedure SSFindScreenRowStop(Var Q:Spreadsheet);
Procedure SSSetBlankArea(Var Q:Spreadsheet);
Function SSAddCell(Var Q:Spreadsheet;CellType:CellTypes;P:CellPos;E:Bool;V:Extended;I:LStringPtr):Bool;
Procedure SSDeleteCell(Var Q:Spreadsheet;P:CellPos;var Deleted:Bool);
Procedure SSDeleteBlock(Var Q:Spreadsheet;B:Block;var Deleted:Bool);
Function SSCellToFString(Var Q:Spreadsheet;P:CellPos;var Color:Byte):String;
Procedure SSSetLastPos(Var Q:Spreadsheet;DPos:CellPos);
Function SSGetCurrCol(Var Q:Spreadsheet):Wd;
Function SSGetCurrRow(Var Q:Spreadsheet):Wd;
Function SSColToX(Var Q:Spreadsheet;Col:Wd):Byte;
Function SSRowToY(Var Q:Spreadsheet;Row:Wd):Byte;
Function SSColWidth(Var Q:Spreadsheet;Col:Wd):Byte;
Function SSSameCellPos(Var Q:Spreadsheet;P1,P2:CellPos):Bool;
Procedure SSFixOverwrite(Var Q:Spreadsheet);
Function SSFromFile(Var Q:Spreadsheet;Name:PathStr):Bool;
Procedure SSToFile(Var Q:Spreadsheet;Name:PathStr);
Procedure SSCheckForSave(Var Q:Spreadsheet);
Procedure SSChangeWidth(Var Q:Spreadsheet);
Function SSCellHashStart(Var Q:Spreadsheet;TotalCells:Long):BucketRange;
Function SSWidthHashStart(Var Q:Spreadsheet;TotalCells:Long):BucketRange;
Function SSOverwriteHashStart(Var Q:Spreadsheet;TotalCells:Long):BucketRange;
Procedure SSPrint(Var Q:Spreadsheet);
Procedure SSDeleteColumn(Var Q:Spreadsheet);
Procedure SSInsertColumn(Var Q:Spreadsheet);
Procedure SSDeleteRow(Var Q:Spreadsheet);
Procedure SSInsertRow(Var Q:Spreadsheet);
Procedure LSInit(Var Q:LString);
Procedure LSDone(Var Q:LString);
Function LSSetValue(Var Q:LString;NewLen:LStringRange;NewData:Pointer):Bool;
Function LSFromString(Var Q:LString;Const S:String):Bool;
Function LS2String(Var Q:LString):String;
Function LSCopy(Var Q:LString;Start,Amt:LStringRange):String;
Function LSInsert(Var Q:LString;S:String;Start:LStringRange):Bool;
Procedure LSDelete(Var Q:LString;Start,Amt:LStringRange);
Function LSAppend(Var Q:LString;Const S:String):Boolean;
Procedure LSChange(Var Q:LString;Ch:Char;Start:LStringRange);
Function LSAssign(Var Q:LString;LS:LString):Bool;
Function LSFromStream(Var Q:LString;Var S:DosStream):Bool;
Procedure LS2Stream(Var Q:LString;Var S:DosStream);
Procedure SCInit(Var Q:Lotus);
Procedure SCDone(Var Q:Lotus);
Function SCRun(Var Q:Lotus):Wd;
Procedure SCMovePgRight(Var Q:Lotus);
Procedure SCMovePgLeft(Var Q:Lotus);
Procedure SCMoveRight(Var Q:Lotus);
Procedure SCMoveLeft(Var Q:Lotus);
Procedure SCMovePgDn(Var Q:Lotus);
Procedure SCMovePgUp(Var Q:Lotus);
Procedure SCMoveDown(Var Q:Lotus);
Procedure SCMoveUp(Var Q:Lotus);
Procedure SCMoveEnd(Var Q:Lotus);
Procedure SCMoveHome(Var Q:Lotus);
Procedure SCRemoveCell(Var Q:Lotus);
Procedure SCToggleCurrBlock(Var Q:Lotus);
Procedure SCExtendCurrBlock(Var Q:Lotus;Redraw:Bool);
Procedure SCEditInput(Var Q:Lotus;Ch:Wd;Editing:Bool);
Procedure SCOpenSpreadSheet(Var Q:Lotus;Const Name:String);
Procedure SCClearCurrBlock(Var Q:Lotus);
Procedure SCReplaceSpreadSheet(Var Q:Lotus);
Procedure SCNameSaveSpreadSheet(Var Q:Lotus);
Procedure SCZapSpreadSheet(Var Q:Lotus);
Procedure SCSaveCurrSpreadSheet(Var Q:Lotus);
Procedure SCCloseSpreadSheet(Var Q:Lotus);
Procedure SCNextSpreadSheet(Var Q:Lotus);
Procedure SCNewSpreadSheet(Var Q:Lotus);
Procedure SCNewBlankSpreadSheet(Var Q:Lotus);
Procedure SCPrintSpreadSheet(Var Q:Lotus);
Procedure SCHandleInput(Var Q:Lotus;Ch:Wd);
Procedure SCCopyBlock(Var Q:Lotus);
Procedure SCDeleteBlock(Var Q:Lotus);
Procedure SCFormatBlock(Var Q:Lotus);
Procedure SCFormatDefault(Var Q:Lotus);
Procedure SCColInsert(Var Q:Lotus);
Procedure SCColDelete(Var Q:Lotus);
Procedure SCChangeColWidth(Var Q:Lotus);
Procedure SCRowInsert(Var Q:Lotus);
Procedure SCRowDelete(Var Q:Lotus);
Procedure SCRecalc(Var Q:Lotus);
Procedure SCToggleFormulas(Var Q:Lotus);
Procedure SCToggleAutoCalc(Var Q:Lotus);
Procedure SCFormatCell(Var Q:Lotus);
Procedure SCGotoCell(Var Q:Lotus);
Procedure SCEditCell(Var Q:Lotus);
Procedure SCSetDisplayAreas(Var Q:Lotus);
Procedure SCDisplayAll(Var Q:Lotus);
Function SCGetFormat(Var Q:Lotus;Var Format:Byte):Bool;
Function SCAddSheet(Var Q:Lotus;Name:PathStr):Bool;
Procedure SCDeleteSheet(Var Q:Lotus);
Procedure FixFormulaCol(CP:CellPtr;Diff:Long;MaxCols,MaxRows:Wd);
Procedure FixFormulaRow(CP:CellPtr;Diff:Long;MaxCols,MaxRows:Wd);
Function GetColumn(Const Prompt:String;MaxCols,ColSpace:Wd):Wd;
Function GetLegalChar(Const Prompt:String;Legal:CharSet;Var ESCPressed:Boolean):Char;
Function GetNumber(Const Prompt:String;Low,High:Longint;Var Result:Boolean):Longint;
Function GetRow(Const Prompt:String;MaxRows:Wd):Wd;
Function GetCellPos(Const Prompt:String;MaxCols,MaxRows,ColSpace,
RowNumberSpace:Wd;Var P:CellPos):Boolean;
Function FormulaStart(Inp:LStringPtr;Start,MaxCols,MaxRows:Wd;
Var P:CellPos;Var FormLen:Wd):Boolean;
Function GetColWidth(Var WHash:WidthHashTable;C:Wd):Byte;
Function HashItemPtr2CellPtr(H:HashItemPtr):CellPtr;
Function ReadString(Const Prompt:String;Len:Wd;Var EscPressed:Bool):String;
Var
Parser:ParserObj;
Empty:CellPtr;
IMPLEMENTATION
{$F-}
Var SavedExitProc:Pointer;
Procedure PutFreeMemory;Begin;End;
Destructor Base.Done;Begin End;
Constructor Stream.Init;Begin
TypeCount:=0;TypeList:=Nil;ProcList:=Nil;Status:=0;
RegisterTypes;
TypeList:=MemAlloc(TypeCount*SizeOf(Wd));
If(TypeList=Nil)Then Fail;
ProcList:=MemAlloc(TypeCount*SizeOf(SProc));
If(ProcList=Nil)Then Begin;FreeMem(TypeList,TypeCount*SizeOf(Wd));Exit;End;
TypeCount:=0;
RegisterTypes;
End;
Destructor Stream.Done;Begin
FreeMem(ProcList,TypeCount*SizeOf(SProc));
FreeMem(TypeList,TypeCount*SizeOf(Wd));
End;
Procedure Stream.Error;Begin;Status:=Code;End;
Procedure Stream.Flush;Begin;End;
Function Stream.GetPos;Begin;End;
Procedure Stream.Read;Begin;End;
Procedure Stream.RegisterTypes;Begin;End;
Procedure Stream.SetPos;Begin;End;
Procedure Stream.Truncate;Begin;End;
Procedure Stream.Write;Begin;End;
Function Stream.Get:BasePtr;Assembler;ASM
PUSH AX
MOV AX,SP
PUSH SS
PUSH AX
MOV AX,2
PUSH AX
LES DI,Self
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL Read
POP BX
OR BX,BX
JE @@2
LES DI,Self
DEC BX
CMP BX,ES:[DI].Stream.TypeCount
JAE @@1
PUSH ES
PUSH DI
LES DI,ES:[DI].Stream.TypeList
SHL BX,1
PUSH WORD PTR ES:[DI+BX]
XOR AX,AX
PUSH AX
PUSH AX
LES DI,Self
LES DI,ES:[DI].Stream.ProcList
SHL BX,1
SHL BX,1
CALL ES:[DI+BX].SProc.LoadProc
JMP @@3
@@1:
MOV AX,-2
PUSH ES
PUSH DI
PUSH AX
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL Error
POP DI
POP ES
@@2:
XOR AX,AX
MOV DX,AX
@@3:
END;
Function Stream.GetSize;Var P:Long;Begin
P:=GetPos;
SetPos(0,PosEnd);
GetSize:=GetPos;
SetPos(P,PosAbs);
End;
Procedure Stream.Put;Assembler;ASM
LES DI,B
MOV CX,ES
OR CX,DI
JE @@1
MOV AX,ES:[DI]
LES DI,Self
MOV CX,Stream(ES:[DI]).TypeCount
JCXZ @@2
MOV BX,CX
LES DI,Stream(ES:[DI]).TypeList
CLD
REPNE SCASW
JNE @@2
NEG CX
ADD CX,BX
@@1:
PUSH CX
MOV AX,SP
PUSH SS
PUSH AX
MOV AX,2
PUSH AX
LES DI,Self
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL Write
POP BX
DEC BX
JS @@3
LES DI,Self
PUSH ES
PUSH DI
PUSH B.Word[2]
PUSH B.Word[0]
LES DI,Stream(ES:[DI]).ProcList
SHL BX,1
SHL BX,1
SHL BX,1
CALL SProc(ES:[DI+BX]).StoreProc
JMP @@3
@@2:
LES DI,Self
MOV AX,-1
PUSH ES
PUSH DI
PUSH AX
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL Error
POP DI
POP ES
@@3:
END;
Procedure StreamError;Near;Begin End;
Procedure Stream.Register;Begin
Inc(TypeCount);
If(TypeList<>Nil)Then Begin
TypeList^[TypeCount]:=PtrRec(TypePtr).Ofs;
With ProcList^[TypeCount]do Begin;StoreProc:=StorePtr;LoadProc:=LoadPtr;End;
End;
End;
Procedure Stream.Seek;Begin;SetPos(Pos,PosAbs)End;
Constructor DosStream.Init;Var L:Int;Begin
If Not(Stream.Init)Then Fail;
L:=Length(FileName);
MoveLeft(FileName[1],FileName[0],L);
FileName[L]:=#0;
Open(FileName,Mode);
{ If(Mode=sCreate)Then Handle:=Systems.New(FileName)
Else Handle:=Systems.Open(FileName,fmDef);}
End;
Destructor DosStream.Done;Begin
Systems.Close(Hdl(Handle));
Stream.Done;
End;
Function DosStream.GetPos;Assembler;ASM
XOR DX,DX
XOR CX,CX
MOV BX,Handle
MOV AX,4201h
INT $21
END;
Procedure DosStream.Read;Begin
_GetRec(Handle,Count,Buf);
End;
Procedure DosStream.SetPos;Begin
_SetFilePos(Handle,Pos,Mode);
End;
Procedure DosStream.Truncate;Assembler;ASM
LES DI,Self
PUSH ES
PUSH DI
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL Flush
POP DI
POP ES
CMP ES:[DI].Stream.Status,0
JNE @@1
XOR CX,CX
MOV BX,ES:[DI].DosStream.Handle
MOV AH,40h
INT 21h
JNC @@1
CALL StreamError
@@1:
END;
Procedure DosStream.Write;Begin
_SetRec(Handle,Count,Buf)
End;
Procedure DosStream.Close;Assembler;ASM
LES DI,Self
PUSH ES
PUSH DI
PUSH ES
PUSH DI
MOV DI,ES:[DI]
CALL Flush
POP DI
POP ES
CMP ES:[DI].Stream.Status,0
JNE @@1
MOV BX,ES:[DI].DosStream.Handle
MOV AH,3EH
INT 21H
@@1:
END;
Procedure DosStream.Open;Assembler;ASM
LES DI,Self
PUSH DS
LDS DX,Name
XOR CX,CX
MOV AX,Mode
INT 21H
POP DS
JNC @@1
CALL StreamError
MOV AX,0FFFFH
@@1:
MOV ES:[DI].DosStream.Handle,AX
END;
Constructor BufStream.Init;Begin
Buffer:=MemAlloc(Size);
If(Buffer=Nil)Then Fail;
If Not(DosStream.Init(FileName,Mode))Then Begin;FreeMem(Buffer,Size);Fail;End;
BufSize:=Size;BufPtr:=0;BufEnd:=0;
End;
Destructor BufStream.Done;Begin
DosStream.Done;
FreeMem(Buffer,BufSize);
End;
Procedure BufStream.Flush;Assembler;ASM
LES DI,Self
CMP ES:[DI].Stream.Status,0
JNE @@9
MOV AL,2
MOV CX,ES:[DI].BufStream.BufPtr
SUB CX,ES:[DI].BufStream.BufEnd
JE @@4
MOV BX,ES:[DI].DosStream.Handle
JA @@1
CMP AL,1
JE @@4
MOV DX,CX
MOV CX,-1
MOV AX,4201H
INT 21H
JMP @@3
@@1:
CMP AL,0
JE @@4
PUSH DS
LDS DX,ES:[DI].BufStream.Buffer
MOV AH,40H
INT 21H
POP DS
JC @@2
CMP AX,CX
JE @@3
MOV AX,101
@@2:
CALL StreamError
@@3:
XOR AX,AX
MOV ES:[DI].BufStream.BufPtr,AX
MOV ES:[DI].BufStream.BufEnd,AX
CMP AX,ES:[DI].Stream.Status
@@4:
@@9:
END;
Function BufStream.GetPos;Assembler;ASM
LES DI,Self
PUSH ES
PUSH DI
PUSH CS
CALL DosStream.GetPos
OR DX,DX
JS @@1
LES DI,Self
SUB AX,ES:[DI].BufStream.BufEnd
SBB DX,0
ADD AX,ES:[DI].BufStream.BufPtr
ADC DX,0
@@1:
END;
Procedure BufStream.Read;Assembler;ASM
LES DI,Self
CMP ES:[DI].Stream.Status,0
JNE @@6
MOV AL,1
MOV CX,ES:[DI].BufStream.BufPtr
SUB CX,ES:[DI].BufStream.BufEnd
JE @F4
MOV BX,ES:[DI].DosStream.Handle
JA @F1
CMP AL,1
JE @F4
MOV DX,CX
MOV CX,-1
MOV AX,4201H
INT 21H
JMP @F3
@F1:
CMP AL,0
JE @F4
PUSH DS
LDS DX,ES:[DI].BufStream.Buffer
MOV AH,40H
INT 21H
POP DS
JC @F2
CMP AX,CX
JE @F3
MOV AX,101
@F2:
CALL StreamError
@F3:
XOR AX,AX
MOV ES:[DI].BufStream.BufPtr,AX
MOV ES:[DI].BufStream.BufEnd,AX
CMP AX,ES:[DI].Stream.Status
@F4:
JNE @@6
XOR DX,DX
@@1:
MOV CX,Count
SUB CX,DX
JE @@7
LES DI,Self
MOV AX,ES:[DI].BufStream.BufEnd
SUB AX,ES:[DI].BufStream.BufPtr
JA @@2
PUSH CX
PUSH DX
PUSH DS
LDS DX,ES:[DI].BufStream.Buffer
MOV CX,ES:[DI].BufStream.BufSize
MOV BX,ES:[DI].DosStream.Handle
MOV AH,3FH
INT 21H
POP DS
POP DX
POP CX
JC @@5
MOV ES:[DI].BufStream.BufPtr,0
MOV ES:[DI].BufStream.BufEnd,AX
OR AX,AX
JE @@4
@@2:
CMP CX,AX
JB @@3
MOV CX,AX
@@3:
PUSH DS
LDS SI,ES:[DI].BufStream.Buffer
ADD SI,ES:[DI].BufStream.BufPtr
ADD ES:[DI].BufStream.BufPtr,CX
LES DI,Buf
ADD DI,DX
ADD DX,CX
CLD
REP MOVSB
POP DS
JMP @@1
@@4:
MOV AX,101
@@5:
CALL StreamError
@@6:
LES DI,Buf
MOV CX,Count
XOR AL,AL
CLD
REP STOSB
@@7:
END;
Procedure BufStream.Write;Assembler;ASM
LES DI,Self
CMP ES:[DI].Stream.Status,0
JNE @@4
MOV AL,0
MOV CX,ES:[DI].BufStream.BufPtr
SUB CX,ES:[DI].BufStream.BufEnd
JE @F4
MOV BX,ES:[DI].DosStream.Handle
JA @F1
CMP AL,1
JE @F4
MOV DX,CX
MOV CX,-1
MOV AX,4201H
INT 21H
JMP @F3
@F1:
CMP AL,0
JE @F4
PUSH DS
LDS DX,ES:[DI].BufStream.Buffer
MOV AH,40H
INT 21H
POP DS
JC @F2
CMP AX,CX
JE @F3
MOV AX,101
@F2:
CALL StreamError
@F3:
XOR AX,AX
MOV ES:[DI].BufStream.BufPtr,AX
MOV ES:[DI].BufStream.BufEnd,AX
CMP AX,ES:[DI].Stream.Status
@F4:
JNE @@4
XOR DX,DX
@@1:
MOV CX,Count
SUB CX,DX
JE @@4
LES DI,Self
MOV AX,ES:[DI].BufStream.BufSize
SUB AX,ES:[DI].BufStream.BufPtr