-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBTRV.mod
1228 lines (1091 loc) · 46 KB
/
BTRV.mod
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
IMPLEMENTATION MODULE BTRV;
(*# debug( vid => full ) *)
IMPORT SYSTEM,Lib,Str,IO,Window;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
(*%T _XTD*)
IMPORT TSXLIB;
(*%E*)
(* ------------------------------------------------------------------------ *)
(* TopSpeed Modula-2 Interface for BTRIEVE - Supports TopSpeed Extender *)
(* Public Domain - May be used without restriction *)
(* *)
(* Versi¢n para MYLIB 2.0 *)
(* (c) 1994. *)
(* Ver : 1.00. *)
(* Release: 1000.0. *)
(* Date : 19-05-94. *)
(* By : Hector Gustavo Saracca. *)
(* ------------------------------------------------------------------------ *)
(* ------------------------------------------------------------------------ *)
(* Internal Btrieve functions - for flex parameters use *)
(* ------------------------------------------------------------------------ *)
PROCEDURE BTrieve1( fn :CARDINAL );
VAR NullControl :File;
NullBuffer :LONGCARD;
NullBuffSize :CARDINAL;
NullKey :KeyType;
BEGIN
NullBuffSize := SIZE(NullBuffer);
BTrieve(fn,NullControl,NullBuffer,NullBuffSize,NullKey,0);
END BTrieve1;
PROCEDURE BTrieve2( fn :CARDINAL; VAR f :File );
VAR NullBuffer :LONGCARD;
NullBuffSize :CARDINAL;
NullKey :KeyType;
BEGIN
NullBuffSize := SIZE(NullBuffer);
BTrieve(fn,f,NullBuffer,NullBuffSize,NullKey,0);
END BTrieve2;
PROCEDURE BTrieve3( fn :CARDINAL; VAR f :File; Key :SHORTCARD );
VAR NullBuffer :LONGCARD;
NullBuffSize :CARDINAL;
NullKey :KeyType;
BEGIN
NullBuffSize := SIZE(NullBuffer);
BTrieve(fn,f,NullBuffer,NullBuffSize,NullKey,Key);
END BTrieve3;
PROCEDURE BTrieve4( fn :CARDINAL; VAR f :File; VAR KeyBuff :ARRAY OF BYTE; Key :SHORTCARD );
VAR NullBuffer :LONGCARD;
NullBuffSize :CARDINAL;
BEGIN
NullBuffSize := SIZE(NullBuffer);
BTrieve(fn,f,NullBuffer,NullBuffSize,KeyBuff,Key);
END BTrieve4;
(* ------------------------------------------------------------------------ *)
(* Btrieve file functions - function number in brackets *)
(* ------------------------------------------------------------------------ *)
PROCEDURE Open( FileName, OwnerName :ARRAY OF CHAR; op_enMode :SHORTCARD ) :File;
VAR DatBuff :ARRAY [ 0..7 ] OF CHAR;
KeyBuff :KeyType;
BuffSize :CARDINAL;
f :File;
BEGIN
Str.Copy(KeyBuff,FileName);
Str.Copy(DatBuff,OwnerName);
DatBuff[7] := 0C;
BuffSize := Str.Length(DatBuff) + 1;
BTrieve(op_Open,f,DatBuff,BuffSize,KeyBuff,op_enMode);
RETURN f;
END Open;
PROCEDURE Create( FileName :ARRAY OF CHAR; FileDesc :ARRAY OF BYTE; DescSize :CARDINAL ) :File;
VAR KeyBuff :KeyType;
f :File;
desc_size :CARDINAL;
BEGIN
Str.Copy(KeyBuff,FileName);
desc_size := DescSize;
BTrieve(op_Create,f,FileDesc,desc_size,KeyBuff,0);
RETURN f;
END Create;
PROCEDURE Close( VAR f :File );
BEGIN
BTrieve2(op_Close,f);
END Close;
PROCEDURE Status( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE );
BEGIN
BTrieve(op_Stat,f,DatBuff,BuffSize,KeyBuff,0);
END Status;
PROCEDURE Extend( VAR f :File; FileName :ARRAY OF CHAR; UseNow :BOOLEAN);
VAR KeyBuff :KeyType;
KeyID :SHORTCARD;
BEGIN
Str.Copy(KeyBuff,FileName);
IF UseNow THEN KeyID := 255 ELSE KeyID := 0; END;
BTrieve4(op_Extend,f,KeyBuff,KeyID);
END Extend;
PROCEDURE SetOwner( VAR f :File; OwnerName :ARRAY OF CHAR; AccessMode :SHORTCARD );
VAR DatBuff :OwnerType;
KeyBuff :KeyType;
BuffSize :CARDINAL;
BEGIN
Str.Copy(DatBuff,OwnerName);
Str.Copy(KeyBuff,OwnerName);
DatBuff[7] := 0C;
BuffSize := Str.Length(DatBuff) + 1;
BTrieve(op_SetOwner,f,DatBuff,BuffSize,KeyBuff,AccessMode);
END SetOwner;
PROCEDURE ClearOwner( VAR f :File );
BEGIN
BTrieve2( op_ClearOwner, f );
END ClearOwner;
(* ------------------------------------------------------------------------ *)
(* Btrieve transactions functions - function number in brackets *)
(* ------------------------------------------------------------------------ *)
PROCEDURE BeginTransaction();
BEGIN
BTrieve1(op_BeginTrans);
END BeginTransaction;
PROCEDURE EndTransaction();
BEGIN
BTrieve1(op_EndTrans);
END EndTransaction;
PROCEDURE AbortTransaction();
BEGIN
BTrieve1(op_AbortTrans);
END AbortTransaction;
(* ------------------------------------------------------------------------ *)
(* Btrieve records functions - function number in brackets *)
(* ------------------------------------------------------------------------ *)
PROCEDURE Insert( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_Insert,f,DatBuff,BuffSize,KeyBuff,KeyID);
END Insert;
PROCEDURE Update( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD);
BEGIN
BTrieve(op_Update,f,DatBuff,BuffSize,KeyBuff,0);
END Update;
PROCEDURE Delete( VAR f :File; KeyID :SHORTCARD );
BEGIN
BTrieve3(op_Delete,f,KeyID);
END Delete;
PROCEDURE GetPos( VAR f :File; VAR pos :PosType );
VAR BuffSize :CARDINAL;
NullKey :KeyType;
BEGIN
BuffSize := SIZE(pos);
BTrieve( op_GetPos, f, pos, BuffSize, NullKey, 0 );
END GetPos;
PROCEDURE GetDirect( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD);
BEGIN
BTrieve(op_GetDirect,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetDirect;
PROCEDURE StepDirect( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL );
VAR NullKey :KeyType;
BEGIN
BTrieve(op_StepDirect,f,DatBuff,BuffSize,NullKey,0);
END StepDirect;
(* ------------------------------------------------------------------------ *)
(* Btrieve Find functions. *)
(* ------------------------------------------------------------------------ *)
PROCEDURE FindEQ( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetEQ+op_KeyOnly,f,KeyBuff,KeyID);
END FindEQ;
PROCEDURE FindNext( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetNext+op_KeyOnly,f,KeyBuff,KeyID);
END FindNext;
PROCEDURE FindPrev( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetPrev+op_KeyOnly,f,KeyBuff,KeyID);
END FindPrev;
PROCEDURE FindGT( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetGT+op_KeyOnly,f,KeyBuff,KeyID);
END FindGT;
PROCEDURE FindGE( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetGE+op_KeyOnly,f,KeyBuff,KeyID);
END FindGE;
PROCEDURE FindLT( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetLT+op_KeyOnly,f,KeyBuff,KeyID);
END FindLT;
PROCEDURE FindLE( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetLE+op_KeyOnly,f,KeyBuff,KeyID);
END FindLE;
PROCEDURE FindFirst( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetFirst+op_KeyOnly,f,KeyBuff,KeyID);
END FindFirst;
PROCEDURE FindLast( VAR f :File; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve4(op_GetLast+op_KeyOnly,f,KeyBuff,KeyID);
END FindLast;
(* ------------------------------------------------------------------------ *)
(* Btrieve Get functions. *)
(* ------------------------------------------------------------------------ *)
PROCEDURE GetEQ( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD);
BEGIN
BTrieve(op_GetEQ,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetEQ;
PROCEDURE GetNext( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_GetNext,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetNext;
PROCEDURE GetPrev( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_GetPrev,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetPrev;
PROCEDURE GetGT( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD);
BEGIN
BTrieve(op_GetGT,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetGT;
PROCEDURE GetGE( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD);
BEGIN
BTrieve(op_GetGE,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetGE;
PROCEDURE GetLT( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_GetLT,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetLT;
PROCEDURE GetLE( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_GetLE,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetLE;
PROCEDURE GetFirst( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_GetFirst,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetFirst;
PROCEDURE GetLast( VAR f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve(op_GetLast,f,DatBuff,BuffSize,KeyBuff,KeyID);
END GetLast;
(* ------------------------------------------------------------------------ *)
(* Btrieve general functions - function number in brackets *)
(* ------------------------------------------------------------------------ *)
PROCEDURE Reset();
BEGIN
BTrieve1(op_Reset);
END Reset;
PROCEDURE Stop();
BEGIN
BTrieve1(op_Stop);
END Stop;
PROCEDURE SetDirectory( DirName :ARRAY OF CHAR );
VAR KeyBuff :KeyType;
NullControl :File;
BEGIN
Str.Copy(KeyBuff,DirName);
BTrieve4(op_SetDir,NullControl,KeyBuff,0);
END SetDirectory;
PROCEDURE GetDir( Drive :SHORTCARD; VAR DirName :ARRAY OF CHAR);
VAR NullControl :File;
BEGIN
BTrieve4(op_GetDir,NullControl,DirName,Drive);
END GetDir;
(* ------------------------------------------------------------------------ *)
(* Nuevas funciones de Extracci¢n de datos. *)
(* (c) 1994 *)
(* Implemetadas por: Saracca, H‚ctor Gustavo. *)
(* ------------------------------------------------------------------------ *)
PROCEDURE StepFirst( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_StepFirst, f, DatBuff, BuffSize, KeyBuff, KeyID );
END StepFirst;
PROCEDURE StepLast( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_StepLast, f, DatBuff, BuffSize, KeyBuff, KeyID );
END StepLast;
PROCEDURE StepPrev( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_StepPrev, f, DatBuff, BuffSize, KeyBuff, KeyID );
END StepPrev;
PROCEDURE GetNextExt( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_GetNextExt, f, DatBuff, BuffSize, KeyBuff, KeyID );
END GetNextExt;
PROCEDURE GetPrevExt( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_GetPrevExt, f, DatBuff, BuffSize, KeyBuff, KeyID );
END GetPrevExt;
PROCEDURE StepNextExt( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_StepNextExt, f, DatBuff, BuffSize, KeyBuff, KeyID );
END StepNextExt;
PROCEDURE StepPrevExt( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_StepPrevExt, f, DatBuff, BuffSize, KeyBuff, KeyID );
END StepPrevExt;
PROCEDURE InsertExt( f :File; VAR DatBuff :ARRAY OF BYTE; VAR BuffSize :CARDINAL; VAR KeyBuff :ARRAY OF BYTE; KeyID :SHORTCARD );
BEGIN
BTrieve( op_InsertExt, f, DatBuff, BuffSize, KeyBuff, KeyID );
END InsertExt;
(* ------------------------------------------------------------------------ *)
(* Low Level Btrieve Call *)
(* ------------------------------------------------------------------------ *)
VAR ProcId :CARDINAL; (* initialize to no process id *)
Multi :BOOLEAN; (* set to true if BMulti is loaded *)
VSet :BOOLEAN; (* set to true if we have checked for BMulti *)
(*%T _XTD*)
TYPE rADDRESS = LONGCARD;
PROCEDURE RealAlloc( VAR handle :CARDINAL; size :CARDINAL; VAR src :ARRAY OF BYTE) :rADDRESS;
(*
Needed to cop_y to Real Memory (i.e. addressable from real mode)
*)
VAR csize :CARDINAL;
BEGIN
IF size=0 THEN handle:=0; RETURN 0 END;
handle := TSXLIB.ALLOCLOWSEG(size);
IF Seg(src)<>0 THEN (* cop_y in *)
(* protect against buffers that are too short *)
csize := TSXLIB.GETSEGLIMIT(Seg(src));
IF (csize>=Ofs(src)) THEN
DEC(csize,Ofs(src)-1);
IF (csize=0)OR(csize>size) THEN csize := size END;
Lib.FastMove(ADR(src),[handle:0],csize);
END;
ELSE
Lib.Fill([handle:0],size,0);
END; (* if *)
RETURN TSXLIB.MAKEREALADDR(handle,0);
END RealAlloc;
PROCEDURE RealFree( handle :CARDINAL; size :CARDINAL; VAR dst :ARRAY OF BYTE );
VAR csize : CARDINAL;
BEGIN
IF handle=0 THEN RETURN END;
IF Seg(dst)<>0 THEN (* cop_y out *)
(* protect against buffers that are too short *)
csize := TSXLIB.GETSEGLIMIT(Seg(dst));
IF (csize>=Ofs(dst)) THEN
DEC(csize,Ofs(dst)-1);
IF (csize=0)OR(csize>size) THEN csize := size END;
Lib.FastMove([handle:0],ADR(dst),csize);
END; (* if *)
END; (* if *)
TSXLIB.FREESEG(handle);
END RealFree;
PROCEDURE BTrieve( op_ :CARDINAL; (* op_eration *)
VAR pos :File; (* Position Block *)
VAR data :ARRAY OF BYTE; (* Data Buffer *)
VAR datalen :CARDINAL; (* Data Size *)
VAR kbuf :ARRAY OF BYTE; (* Key Buffer *)
key :SHORTCARD ); (* Key Number *)
CONST VarID = 06176H; (* id for variable Size records - 'va'*)
BtrInt = 07BH;
Btr2Int = 02FH;
BtrOffset = 00033H;
MultiFunction = 0AB00H;
TYPE rBtrParms = RECORD
UserBufAddr :rADDRESS; (* data buffer address *)
UserBufLen :CARDINAL; (* data buffer Size *)
UserCurAddr :rADDRESS; (* currency block address *)
UserFCBAddr :rADDRESS; (* file control block address *)
UserFunction :CARDINAL; (* Btrieve op_eration *)
UserKeyAddr :rADDRESS; (* key buffer address *)
UserKeySize :SHORTCARD; (* key buffer Size *)
UserKeyNumber :SHORTCARD; (* key number *)
UserStatAddr :rADDRESS; (* return Error address *)
xFaceID :CARDINAL; (* language interface id *)
END;
VAR Stat :CARDINAL; (* Btrieve Error code *)
Params :rBtrParms; (* Btrieve parameter block *)
r :SYSTEM.Registers;
DataSel :CARDINAL;
PosSel :CARDINAL;
KeySel :CARDINAL;
StatSel :CARDINAL;
ParamSel :CARDINAL;
rParams :rADDRESS;
BEGIN
Lib.Fill(ADR(r),SIZE(r),0);
r.AX:= 03500H + BtrInt;
TSXLIB.REALINTR(ADR(r), 21H);
(* NB using Lib.Intr will return prot mode address *)
IF r.BX # BtrOffset THEN (* make sure Btrieve is installed *)
SetError( op_Null, BtrieveAbsent );
END;
IF NOT VSet THEN (* if we haven't checked for Multi-User version *)
r.AX:= 03000H;
Lib.Intr(r, 021H);
IF r.AL >= 3 THEN (* DOS version >= 3.0 *)
VSet:= TRUE;
r.AX:= MultiFunction;
Lib.Intr(r, Btr2Int);
Multi:= r.AL = 4DH (* ORD('M') *)
ELSE
Multi:= FALSE
END; (* if *)
END; (* make normal btrieve call *)
IF datalen > HIGH(data)+1 THEN datalen:= HIGH(data)+1 END;
WITH Params DO
UserBufAddr := RealAlloc(DataSel,datalen,data); (* set data buffer address *)
UserBufLen := datalen; (* set Size *)
UserFCBAddr := RealAlloc(PosSel,38+90,pos); (* set FCB address*)
UserCurAddr := UserFCBAddr+38;
UserFunction := op_; (* set Btrieve op_eration code *)
UserKeyAddr := RealAlloc(KeySel,255,kbuf); (* set key buffer address *)
UserKeySize := 255;
UserKeyNumber := key; (* set key number *)
UserStatAddr := RealAlloc(StatSel,SIZE(Stat),Stat);
xFaceID := VarID; (* set language id *)
END; (* with *)
rParams := RealAlloc(ParamSel,SIZE(Params),Params);
r.DX := CARDINAL(rParams);
r.DS := CARDINAL(rParams>>16);
IF NOT Multi THEN (* MultiUser version not installed *)
TSXLIB.REALINTR(ADR(r), BtrInt); (* passing real addresses *)
ELSE
LOOP
r.BX:= ProcId;
IF r.BX # 0 THEN r.AX:= 2 ELSE r.AX:= 1 END;
INC(r.AX, MultiFunction);
Lib.Intr(r, Btr2Int);
IF r.AL = 0 THEN EXIT END;
r.AX:= 200H;
TSXLIB.REALINTR(ADR(r), 07FH); (* passing real addresses *)
END; (* loop_ *)
IF ProcId = 0 THEN ProcId:= r.BX END
END; (* if *)
RealFree(ParamSel,SIZE(Params),Params);
RealFree(DataSel,datalen,data);
RealFree(PosSel,38,pos);
RealFree(KeySel,255,kbuf);
RealFree(StatSel,SIZE(Stat),Stat);
datalen:= Params.UserBufLen;
SetError( op_, ErrorType(Stat) );
END BTrieve;
(*%E*)
(*%F _XTD*)
PROCEDURE BTrieve( op_ :CARDINAL; (* op_eration *)
VAR pos :File; (* Position Block *)
VAR data :ARRAY OF BYTE; (* Data Buffer *)
VAR datalen :CARDINAL; (* Data Size *)
VAR kbuf :ARRAY OF BYTE; (* Key Buffer *)
key :SHORTCARD ); (* Key Number *)
CONST VarID = 06176H; (* id for variable Size records - 'va'*)
BtrInt = 07BH;
Btr2Int = 02FH;
BtrOffset = 00033H;
MultiFunction = 0AB00H;
TYPE BtrParms = RECORD
UserBufAddr :ADDRESS; (* data buffer address *)
UserBufLen :CARDINAL; (* data buffer Size *)
UserCurAddr :ADDRESS; (* currency block address *)
UserFCBAddr :ADDRESS; (* file control block address *)
UserFunction :CARDINAL; (* Btrieve op_eration *)
UserKeyAddr :ADDRESS; (* key buffer address *)
UserKeySize :SHORTCARD; (* key buffer Size *)
UserKeyNumber :SHORTCARD; (* key number *)
UserStatAddr :ADDRESS; (* return Error address *)
xFaceID :CARDINAL; (* language interface id *)
END;
VAR Stat :CARDINAL; (* Btrieve Error code *)
XData :BtrParms; (* Btrieve parameter block *)
r :SYSTEM.Registers;
BEGIN
r.AX:= 03500H + BtrInt;
Lib.Intr(r, 021H);
IF r.BX # BtrOffset THEN (* make sure Btrieve is installed *)
SetError( op_Null, BtrieveAbsent );
END; (* if *)
IF NOT VSet THEN (* if we haven't checked for Multi-User version *)
r.AX:= 03000H;
Lib.Intr(r, 021H);
IF r.AL >= 3 THEN (* DOS version >= 3.0 *)
VSet:= TRUE;
r.AX:= MultiFunction;
Lib.Intr(r, Btr2Int);
Multi:= r.AL = 4DH (* ORD('M') *)
ELSE
Multi:= FALSE
END; (* if *)
END; (* make normal btrieve call *)
IF datalen > HIGH(data)+1 THEN datalen:= HIGH(data)+1 END;
WITH XData DO
UserBufAddr := ADR(data); (* set data buffer address *)
UserBufLen := datalen; (* set Size *)
UserFCBAddr := ADR(pos); (* set FCB address*)
UserCurAddr := ADR(pos[38]);
UserFunction := op_; (* set Btrieve op_eration code *)
UserKeyAddr := ADR(kbuf); (* set key buffer address *)
UserKeySize := 255;
UserKeyNumber := key; (* set key number *)
UserStatAddr := ADR(Stat); (* set Error address *)
xFaceID := VarID; (* set language id *)
END; (* with *)
r.DX:= SYSTEM.Ofs(XData);
r.DS:= SYSTEM.Seg(XData);
IF NOT Multi THEN (* MultiUser version not installed *)
Lib.Intr(r, BtrInt)
ELSE
LOOP
r.BX:= ProcId;
IF r.BX # 0 THEN r.AX:= 2 ELSE r.AX:= 1 END;
INC(r.AX, MultiFunction);
Lib.Intr(r, Btr2Int);
IF r.AL = 0 THEN EXIT END;
r.AX:= 200H;
Lib.Intr(r, 07FH)
END; (* loop_ *)
IF ProcId = 0 THEN ProcId:= r.BX END
END; (* if *)
datalen:= XData.UserBufLen;
SetError( op_, ErrorType(Stat) );
END BTrieve;
(*%E*)
(* ------------------------------------------------------------------------ *)
(* Errores del BTrieve *)
(* ------------------------------------------------------------------------ *)
(*# define( write_err => on ) *)
(*# define( trace_msg => off ) *)
VAR Error :ErrorType;
Abort :BOOLEAN;
PROCEDURE SetError( op :CARDINAL; err :ErrorType );
BEGIN
Error := err;
IF (Error # Ok) & Abort THEN
(*%T write_err *)
WrError( op, err );
(*%E *)
HALT;
(*%T trace_msg *)
ELSE
(*%T write_err *)
WrError( op, err );
(*%E *)
(*%E *)
END; (* if *)
END SetError;
PROCEDURE GetError() :ErrorType;
BEGIN
RETURN Error;
END GetError;
PROCEDURE SetAbort( on :BOOLEAN );
BEGIN
Abort := on;
END SetAbort;
PROCEDURE ErrorStr( err :ErrorType; VAR str :ARRAY OF CHAR );
VAR msg :ARRAY [ 0..25 ] OF CHAR;
BEGIN
CASE err OF
Ok : msg := 'Ok'; |
BadOpcode : msg := 'Bad op-code'; |
IOError : msg := 'IO error'; |
NoOpen : msg := 'No Open'; |
KeyNotFound : msg := 'Key not found'; |
DuplicateKey : msg := 'Duplicate key'; |
InvalidKey : msg := 'Invalid key'; |
ChangedKey : msg := 'Cahnged key'; |
InvalidPosition : msg := 'Invalid position'; |
EndOfFile : msg := 'End of file'; |
NonModifiable : msg := 'Non modifable'; |
BadFileName : msg := 'Bad file name'; |
FileNotFound : msg := 'File not found'; |
ExtensionError : msg := 'Extension error'; |
PreOpenError : msg := 'Pre-open error'; |
PreImageError : msg := 'Pre-image error'; |
ExpansionError : msg := 'Expansion error'; |
CloseError : msg := 'Close error'; |
DiskFull : msg := 'Disk full'; |
Unrecoverable : msg := 'Unrecoverable'; |
BtrieveAbsent : msg := 'BTrieve absent'; |
KeyBuffSize : msg := 'Key buffer length'; |
RecBuffSize : msg := 'Rec buffer length'; |
PosBlockSize : msg := 'Pos block length'; |
PageSize : msg := 'Page length'; |
CreateError : msg := 'Create error'; |
KeySegments : msg := 'Key segments'; |
KeyPosition : msg := 'Key position'; |
RecSize : msg := 'Rec Size'; |
KeySize : msg := 'Key Size'; |
NotBtrieveFile : msg := 'Not btrieve file'; |
AlreadyExtended : msg := 'Already extended'; |
CantExtend : msg := "Can't extend"; |
BadExtendName : msg := 'Bad extend name'; |
DirectoryError : msg := 'Directory error'; |
TransactError : msg := 'Transact error'; |
NestedTransact : msg := 'Nested transact'; |
TransactControl : msg := 'Transact control'; |
EndAbortError : msg := 'En abort error'; |
TransactMaximum : msg := 'Transact maximun'; |
TransactFileErr : msg := 'Transact file error'; |
AccelFailure : msg := 'Accel failure'; |
BadRecAddress : msg := 'Bad rec address'; |
NullKeyPath : msg := 'Null-key path'; |
BadKeySpecs : msg := 'Bad-key specs'; |
AccessDenied : msg := 'Access denied'; |
MaxOpenFiles : msg := 'Max open files'; |
BadCollation : msg := 'Bad collation'; |
CollationKeyType : msg := 'Collation key-type'; |
OwnerSet : msg := 'Owner set'; |
InvalidOwner : msg := 'Invalid owner'; |
CacheWriteError : msg := 'Cache write error'; |
BadBtInterface : msg := 'Bad interface'; |
BadVariablePage : msg := 'Bad variable page'; |
AutoIncErr : msg := 'Auto-inc error'; |
IncompleteIndex : msg := 'Incomplete index'; |
EMSErr : msg := 'EMS error'; |
CompressBufTooShort : msg := 'Compress buffer too short'; |
FileAlreadyExists : msg := 'File already exists'; |
Err33, Err60..Err79 : msg := 'errors: 33, 60..79'; |
AccessConflict : msg := 'Access conflict'; |
LockFailed : msg := 'Lock failed'; |
LostPosition : msg := 'Lost position'; |
UnreadTransact : msg := 'Unread transact'; |
RecInUse : msg := 'Rec in use'; |
FileInUse : msg := 'File in use'; |
FileTableFull : msg := 'File table full'; |
HandleTableFull : msg := 'Handle table full'; |
OpenModeError : msg := 'Open mode error'; |
DeviceNameError : msg := 'Device name error'; |
DeviceTableFull : msg := 'Device table full'; |
ServerError : msg := 'Server error'; |
TransactTabFull : msg := 'Transact table full'; |
IncompatibleLockType : msg := 'Incompatible lock type'; |
PermissionErr : msg := 'Permision error'; |
SessionNoLongerValid : msg := 'Session no longer valid'; |
ComEnvErr : msg := 'Com. env. error'; |
DataBufTooSmall : msg := 'Data buffer too small'; |
InternalTransactionErr : msg := 'Internal transaction error'; |
DemoVersion : msg := 'Demo version'; |
ELSE
msg := 'error desconocido';
END; (* case *)
Str.Copy( str, msg );
END ErrorStr;
PROCEDURE OpStr( op :CARDINAL; VAR str :ARRAY OF CHAR );
VAR msg :ARRAY [ 0..20 ] OF CHAR;
BEGIN
CASE op OF
op_Open : msg := 'Open'; |
op_Close : msg := 'Close'; |
op_Insert : msg := 'Insert'; |
op_Update : msg := 'Update'; |
op_Delete : msg := 'Delete'; |
op_GetEQ : msg := 'Get Equal'; |
op_GetNext : msg := 'Get Next'; |
op_GetPrev : msg := 'Get Prev'; |
op_GetGT : msg := 'Get Great-That'; |
op_GetGE : msg := 'Get Great-Equal'; |
op_GetLT : msg := 'Get Less-That'; |
op_GetLE : msg := 'Get Less-Equal'; |
op_GetFirst : msg := 'Get First'; |
op_GetLast : msg := 'Get Last'; |
op_Create : msg := 'Create'; |
op_Stat : msg := 'Status'; |
op_Extend : msg := 'Extend file'; |
op_SetDir : msg := 'Set Dir'; |
op_GetDir : msg := 'Get Dir'; |
op_BeginTrans : msg := 'Begin Transaction'; |
op_EndTrans : msg := 'End Transaction'; |
op_AbortTrans : msg := 'Abort Transaction'; |
op_GetPos : msg := 'Get Pos'; |
op_GetDirect : msg := 'Get Direct'; |
op_StepDirect : msg := 'Step Direct'; |
op_Stop : msg := 'Stop'; |
op_Version : msg := 'Version'; |
op_Unlock : msg := 'Un-lock'; |
op_Reset : msg := 'Reset'; |
op_SetOwner : msg := 'Set Owner'; |
op_ClearOwner : msg := 'Clear Owner'; |
op_CreateSuppIdx : msg := 'Create Supp Idx'; |
op_DropSuppIdx : msg := 'Drop Supp Idx'; |
op_StepFirst : msg := 'Step First'; |
op_StepLast : msg := 'Step Last'; |
op_StepPrev : msg := 'Step Prev'; |
op_GetNextExt : msg := 'GetNext Ext'; |
op_GetPrevExt : msg := 'Get Prev Ext'; |
op_StepNextExt : msg := 'Step Next Ext'; |
op_StepPrevExt : msg := 'Step Prev Ext'; |
op_InsertExt : msg := 'Insert Ext'; |
op_KeyOnly : msg := 'Key Only'; |
op_Null : msg := 'Null-operation'; |
ELSE
msg := 'operaci¢n desconocida';
END; (* case *)
Str.Copy( str, msg );
END OpStr;
PROCEDURE WrError( op :CARDINAL; err :ErrorType );
VAR msg :ARRAY [ 0..25 ] OF CHAR;
BEGIN
Window.GotoXY(1,1);
Win.WrStr( 'BTrieve error: ');
Win.WrStr( '"' );
ErrorStr( err, msg );
Win.WrStr( msg );
Win.WrStr( '" #:' );
Win.WrCard( ORD(err), 3 );
IF op # op_Null THEN
Win.WrStr( ', in operation: "' );
OpStr( op, msg );
Win.WrStr( msg );
Win.WrStr( '"' );
END; (* if *)
Win.WrStr( '.' );
Win.WrLn();
END WrError;
PROCEDURE GetVer( VAR str :ARRAY OF CHAR );
TYPE VerType = RECORD
Number :CARDINAL;
Rev :INTEGER;
Product :CHAR;
END; (* VerType *)
VAR NullControl :File;
NullKey :KeyType;
aux_str :ARRAY [ 0..1 ] OF CHAR;
ver :VerType;
size :CARDINAL;
ok :BOOLEAN;
BEGIN
size := SIZE(VerType);
BTrieve( op_Version, NullControl, ver, size, NullKey, 0 );
Str.CardToStr( LONGCARD(ver.Number), aux_str, 10, ok );
Str.Concat( str, aux_str, '.' );
Str.IntToStr( LONGINT(ver.Rev), aux_str, 10, ok );
Str.Append( str, aux_str );
Str.Append( str, ver.Product );
END GetVer;
(* ------------------------------------------------------------------------ *)
(* Procedimientos varios de ayuda de BTrieve. *)
(* ------------------------------------------------------------------------ *)
PROCEDURE Lng2pos( i :LONGCARD ) :PosType;
VAR pos :PosType;
BEGIN
pos[0] := CARDINAL( i DIV 65536 );
pos[1] := CARDINAL( i MOD 65536 );
RETURN pos;
END Lng2pos;
PROCEDURE Pos2lng( p :PosType ) :LONGCARD;
BEGIN
RETURN LONGCARD(p[0]) * 65536 + LONGCARD(p[1]);
END Pos2lng;
TYPE BFile = POINTER TO RECORD
file :File;
num_segs :CARDINAL;
spec :FileSpec;
spec_size :CARDINAL;
index_buff :KeyType;
cur_index :SHORTCARD; (* KeyRange *)
END; (* BTFile *)
PROCEDURE CountSegs( fdesc :FileSpec ) :CARDINAL;
VAR NumSegs :CARDINAL;
i :CARDINAL;
j :KeyRange;
PROCEDURE Count();
BEGIN
WITH fdesc DO
REPEAT
IF (KeyArray[j].KeyFlags & Segmented) = Segmented THEN
IF (KeyArray[j].KeyFlags & AltCol) = AltCol THEN
(* HasAltCol := TRUE; *)
END; (* if *)
INC(NumSegs);
INC(j);
ELSE
IF (KeyArray[j].KeyFlags & AltCol) = AltCol THEN
(* HasAltCol := TRUE; *)
END; (* if *)
INC(i);
INC(j);
END; (* if *)
UNTIL (KeyArray[j-1].KeyFlags & Segmented) # Segmented;
END; (* with *)
END Count;
BEGIN
i := 1;
j := 0;
NumSegs := fdesc.NumKeys;
WHILE i <= fdesc.NumKeys DO
Count();
END; (* while *)
RETURN NumSegs;
END CountSegs;
PROCEDURE InitSpecs( rec_size :CARDINAL;
file_flgs :CARDINAL;
page_size :CARDINAL;
pre_alloc :CARDINAL;
keys :ARRAY OF KeySpec;
VAR num_segs :CARDINAL ) :FileSpec;
VAR spec :FileSpec;
i :KeyRange;
BEGIN
WITH spec DO
RecSize := rec_size; (* only serve to reserve space for *)
PageSize := page_size; (* the buffer. *)
NumKeys := HIGH(keys)+1;
NumRecs := 0;
FileFlags := file_flgs;
Reserved[0] := CHR(0);
Reserved[1] := CHR(0);
PreAlloc := pre_alloc;
Lib.Fill( ADR(KeyArray), SIZE(KeyArray), 0 );
FOR i := 0 TO HIGH(keys) DO
KeyArray[i] := keys[i];
END; (* next *)
num_segs := CountSegs( spec );
END; (* with *)
RETURN spec;
END InitSpecs;
PROCEDURE BCreate( name :ARRAY OF CHAR; specs :FileSpec ) :BFile;
VAR bfile :BFile;
BEGIN
specs.Reserved[0] := CHR(0);
specs.Reserved[1] := CHR(0);
NEW(bfile);
bfile^.num_segs := CountSegs( specs );
bfile^.spec := specs;
bfile^.spec_size := 16 + (bfile^.num_segs * 16);
bfile^.file := Create( name, bfile^.spec, bfile^.spec_size );
bfile^.file := Open( name, '', BTRV.Normal );
RETURN bfile;
END BCreate;
TYPE MaxSpecType = ARRAY [ 0..664 ] OF BYTE;
(* 665 = 16 for filespec + 384 for max key specs *)
PROCEDURE BOpen( name :ARRAY OF CHAR; open_mode :SHORTCARD ) :BFile;
VAR FileBufLen :CARDINAL; (* + 265 for an alternate collating sequence. *)
KeyBufLen :CARDINAL; (* Max of 24 keys * 16 bytes per key spec. *)
bfile :BFile;
SpecBuff :MaxSpecType;
BEGIN
NEW( bfile );
FileBufLen := 665; (* + 265 for an alternate collating sequence. *)
KeyBufLen := 384; (* Max of 24 keys * 16 bytes per key spec. *)
bfile^.file := Open( name, '', open_mode );
IF GetError() = Ok THEN
Status( bfile^.file, SpecBuff, FileBufLen, KeyBufLen );
IF GetError() = Ok THEN
bfile^.spec := FileSpec(SpecBuff);
bfile^.spec_size := FileBufLen;
bfile^.num_segs := CountSegs(bfile^.spec);
ELSE
Close( bfile^.file );
END; (* if *)
END; (* if *)
RETURN bfile;
END BOpen;
PROCEDURE BClose( VAR f :BFile );
BEGIN
Close( f^.file );
DISPOSE( f );
END BClose;
PROCEDURE SUpdate( VAR f :BFile );
VAR SpecBuff :MaxSpecType;
FileBufLen :CARDINAL; (* + 265 for an alternate collating sequence. *)
KeyBufLen :CARDINAL; (* Max of 24 keys * 16 bytes per key spec. *)
BEGIN
FileBufLen := 665; (* + 265 for an alternate collating sequence. *)
KeyBufLen := 384; (* Max of 24 keys * 16 bytes per key spec. *)
Status( f^.file, SpecBuff, FileBufLen, KeyBufLen );
IF GetError() = Ok THEN
f^.spec := FileSpec(SpecBuff);
END; (* if *)
END SUpdate;
PROCEDURE SetIDX( VAR f :BFile; index :KeyRange );
BEGIN
f^.cur_index := SHORTCARD(index);
END SetIDX;
PROCEDURE GetSpec( VAR f :BFile ) :FileSpec;
BEGIN
RETURN f^.spec;
END GetSpec;
PROCEDURE BRecords( VAR f :BFile ) :LONGCARD;
BEGIN
BTRV.BeginTransaction();
BTRV.SUpdate( f );
BTRV.EndTransaction();
RETURN f^.spec.NumRecs;
END BRecords;
PROCEDURE BGetPos( VAR f :BFile ) :LONGCARD;
VAR pos :PosType;
BEGIN
GetPos( f^.file, pos );
RETURN Pos2lng(pos);
END BGetPos;
PROCEDURE BAdd( VAR f :BFile; VAR d :ARRAY OF BYTE ) :LONGCARD;
BEGIN
Insert( f^.file, d, f^.spec.RecSize, f^.index_buff, f^.cur_index );
RETURN BGetPos( f );
END BAdd;
PROCEDURE BGet( VAR f :BFile; i :LONGCARD; VAR d :ARRAY OF BYTE );
VAR pos :BTRV.PosType;
BEGIN
pos := Lng2pos(i);
Lib.Move( ADR(pos), ADR(d), SIZE(pos) );
BTRV.GetDirect( f^.file, d, f^.spec.RecSize, f^.index_buff, 0 );
END BGet;
PROCEDURE BPut( VAR f :BFile; i :LONGCARD; VAR d :ARRAY OF BYTE );
VAR d1 :ARRAY [ 0..MaxRecSize ] OF BYTE;
BEGIN