-
Notifications
You must be signed in to change notification settings - Fork 2
/
BTRAPI.C
2390 lines (2137 loc) · 72.1 KB
/
BTRAPI.C
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
/*************************************************************************
**
** Copyright 1982-1997 Pervasive Software Inc. All Rights Reserved
**
*************************************************************************/
/*************************************************************************
BTRAPI.C
This module implements the Btrieve Interface for C/C++ applications
using MS Windows, Windows 95, Windows NT, OS2, DOS, Extended DOS. An
NLM application does not need to compile and link this module.
You must select a target platform switch. See the prologue inside
'btrapi.h' for a list of platform switches.
IMPORTANT
---------
Pervasive Software Inc., invites you to modify this file
if you find it necessary for your particular situation. However,
we cannot provide technical support for this module if you
do modify it.
*************************************************************************/
#if !defined(BTI_WIN) && !defined(BTI_OS2) && !defined(BTI_DOS) \
&& !defined(BTI_NLM) && !defined(BTI_DOS_32R) && !defined(BTI_DOS_32P) \
&& !defined(BTI_DOS_32B) && !defined(BTI_WIN_32) && !defined(BTI_OS2_32)
#error You must define one of the following: BTI_WIN, BTI_OS2, BTI_DOS, BTI_NLM, BTI_DOS_32R, BTI_DOS_32P, BTI_DOS_32B, BTI_WIN_32, BTI_OS2_32
#endif
#include <btrconst.h>
#include <btrapi.h>
#include <string.h>
#if defined( BTI_DOS ) || defined( BTI_DOS_32R ) || \
defined( BTI_DOS_32P ) || defined( BTI_DOS_32B )
#include <dos.h>
#define BTR_INTRPT 0x7B /* Btrieve interrupt vector */
#define BTR_OFFSET 0x33 /* Btrieve offset within segment */
#define VARIABLE_ID 0x6176 /* id for variable length records - 'va' */
#define PROTECTED_ID 0x6370 /* id for protected call - 'pc' */
#define VERSION_OFFSET 0
#define REVISION_OFFSET 2
#define TYPE_OFFSET 4
#define VERSION_BUF_SIZE 5
#define BTRV_CODE 7
#define TRUE 1
#define FALSE 0
typedef unsigned char BOOLEAN;
/* Protected Mode switch parameter block */
typedef struct
{
BTI_CHAR sign[ 4 ];
BTI_ULONG flags;
BTI_ULONG functionCode;
BTI_LONG pmSwitchStatus;
BTI_LONG dataLength;
BTI_VOID_PTR dataPtr;
} pmswParmBlock;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************
PROCESS7B IS IN PMSWITCH, AND IS RESOLVED AT RUN-TIME
***************************************************************************/
#if defined( BTI_DOS_32R )
typedef struct
{
char *Name;
void cdecl (*functionPtr) ( pmswParmBlock *bP );
} IMPORTS[];
#define PROCESS7B 75
IMPORTS * _ImportedFunctions_ = 0;
#endif
/****************************************************************************
RQSHELLINIT() Function for MS Windows
***************************************************************************/
#if defined( BTI_WIN ) || defined( BTI_WIN_32 )
BTI_API RQSHELLINIT( BTI_CHAR_PTR option )
{
return WBRQSHELLINIT( option );
}
#endif
/****************************************************************************
BTRV() Function for 16-Bit MS Windows or OS2
***************************************************************************/
#if defined( BTI_WIN ) || defined( BTI_OS2 )
BTI_API BTRV(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber )
{
BTI_BYTE keyLength = MAX_KEY_SIZE;
BTI_CHAR ckeynum = (BTI_CHAR)keyNumber;
return BTRCALL (
operation,
posBlock,
dataBuffer,
dataLength,
keyBuffer,
keyLength,
ckeynum );
}
#endif
/****************************************************************************
BTRVID() Function for 16-Bit MS Windows or OS2
***************************************************************************/
#if defined( BTI_WIN ) || defined( BTI_OS2 )
BTI_API BTRVID(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber,
BTI_BUFFER_PTR clientID )
{
BTI_BYTE keyLength = MAX_KEY_SIZE;
BTI_CHAR ckeynum = (BTI_CHAR)keyNumber;
return BTRCALLID (
operation,
posBlock,
dataBuffer,
dataLength,
keyBuffer,
keyLength,
ckeynum,
clientID );
}
#endif
/****************************************************************************
BTRV() Function for NT, Win32s, or 32-bit OS2
***************************************************************************/
#if defined( BTI_WIN_32 ) || defined( BTI_OS2_32 )
#if defined( BTI_OS2_32 )
#define BTRCALL BTRCALL32
#endif
BTI_API BTRV(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber )
{
BTI_BYTE keyLength = MAX_KEY_SIZE;
BTI_CHAR ckeynum = (BTI_CHAR)keyNumber;
BTI_ULONG dataLen32 = 0;
BTI_SINT status;
if ( dataLength != NULL )
dataLen32 = *dataLength;
status = BTRCALL (
operation,
posBlock,
dataBuffer,
&dataLen32,
keyBuffer,
keyLength,
ckeynum );
if ( dataLength != NULL )
*dataLength = (BTI_WORD)dataLen32;
return status;
}
#endif
/****************************************************************************
BTRVID() Function for NT, Win32s or 32-bit OS2
***************************************************************************/
#if defined( BTI_WIN_32 ) || defined( BTI_OS2_32 )
#if defined( BTI_OS2_32 )
#define BTRCALLID BTRCALLID32
#endif
BTI_API BTRVID(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber,
BTI_BUFFER_PTR clientID )
{
BTI_BYTE keyLength = MAX_KEY_SIZE;
BTI_CHAR ckeynum = (BTI_CHAR)keyNumber;
BTI_ULONG dataLen32 = 0;
BTI_SINT status;
if ( dataLength != NULL )
dataLen32 = *dataLength;
status = BTRCALLID (
operation,
posBlock,
dataBuffer,
&dataLen32,
keyBuffer,
keyLength,
ckeynum,
clientID );
if ( dataLength != NULL )
*dataLength = (BTI_WORD)dataLen32;
return status;
}
#endif
/****************************************************************************
BTRVID() Function for Real Mode DOS ( Btrieve 6.15 or later )
***************************************************************************/
#if defined( BTI_DOS )
BTI_API BTRVID(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber,
BTI_BUFFER_PTR clientID )
{
/* Microsoft changed function and structure names in 7.x . */
#if defined( _MSC_VER )
#if ( _MSC_VER > 600 )
#define segread _segread
#define int86x _int86x
#define REGS _REGS
#define SREGS _SREGS
#endif
#endif
static BOOLEAN btrieveVersionOkay = FALSE;
BTI_BYTE versionOffset;
BTI_BYTE revisionOffset;
BTI_BYTE typeOffset;
BOOLEAN done;
union REGS b_regs;
struct SREGS b_sregs;
BTI_SINT stat = B_NO_ERROR;
BTI_VOID_PTR fptr;
BTI_VOID_PTR twoPointersPtr;
pmswParmBlock newParms;
BTI_WORD version;
BTI_WORD revision;
struct /* structure passed to Btrieve */
{
BTI_VOID_PTR DATA_BUF; /* callers data buffer */
BTI_WORD BUF_LEN; /* length of data buffer */
BTI_VOID_PTR POS_BLOCK; /* user position block */
BTI_VOID_PTR FCB; /* disk FCB */
BTI_WORD FUNCTION; /* requested function */
BTI_VOID_PTR KEY_BUFFER; /* user's key buffer */
BTI_BYTE KEY_LENGTH; /* length of user's key buffer */
BTI_CHAR KEY_NUMBER; /* key of reference for request */
BTI_SINT_PTR STATUS; /* status word */
BTI_SINT XFACE_ID; /* language identifier */
} XDATA;
struct
{
BTI_VOID_PTR xdataPtr;
BTI_VOID_PTR clientIdPtr;
} twoPointers;
/* Btrieve Parameters for stat call */
BTI_BYTE posBlockx[ 128 ];
BTI_BYTE dataBufx[ 255 ];
BTI_WORD dataLenx;
BTI_BYTE keyBufx[ 255 ];
BTI_WORD keyNumx = 0;
segread( &b_sregs );
/*=========================================================================
Check to see that Btrieve has been started.
=========================================================================*/
b_regs.x.ax = 0x3500 + BTR_INTRPT;
int86x( 0x21, &b_regs, &b_regs, &b_sregs );
if ( b_regs.x.bx != BTR_OFFSET )
stat = B_RECORD_MANAGER_INACTIVE;
/*=========================================================================
Check for correct versions of requester and engine. This check is done
only once per application.
=========================================================================*/
if ( ( stat == B_NO_ERROR ) && ( !btrieveVersionOkay ) )
{
versionOffset = VERSION_OFFSET;
revisionOffset = REVISION_OFFSET;
typeOffset = TYPE_OFFSET;
done = FALSE;
dataLenx = sizeof( dataBufx );
stat = BTRV( B_VERSION, posBlockx, &dataBufx, &dataLenx, keyBufx,
keyNumx );
if ( stat == B_NO_ERROR )
{
while ( !done )
{
version = (*(BTI_WORD *)&dataBufx[ versionOffset ] );
revision = (*(BTI_WORD *)&dataBufx[ revisionOffset ] );
switch( *(BTI_BYTE *)&dataBufx[ typeOffset ] )
{
/* Must have requestor version 6.16 or higher. */
case 'N':
if ( ( ( version == 6 ) && ( revision < 16 ) ) ||
( version < 6 ) )
{
stat = B_INVALID_INTERFACE;
done = TRUE;
}
break;
/* Must have engine version 6 or higher. */
case 'D':
if ( version < 6 )
{
stat = B_INVALID_INTERFACE;
done = TRUE;
}
break;
case 0:
done = TRUE;
break;
}
if ( !done )
{
versionOffset = versionOffset + VERSION_BUF_SIZE;
revisionOffset = revisionOffset + VERSION_BUF_SIZE;
typeOffset = typeOffset + VERSION_BUF_SIZE;
continue;
}
}
}
else
stat = B_INVALID_INTERFACE;
}
if ( stat == B_NO_ERROR )
{
/*======================================================================
Move user parameters to XDATA, the block where Btrieve expects them.
======================================================================*/
XDATA.FUNCTION = operation;
XDATA.STATUS = &stat;
XDATA.FCB = posBlock;
XDATA.POS_BLOCK = (BTI_BUFFER_PTR)posBlock + 38;
XDATA.DATA_BUF = dataBuffer;
XDATA.BUF_LEN = *dataLength;
XDATA.KEY_BUFFER = keyBuffer;
XDATA.KEY_LENGTH = 255; /* use max since we don't know */
XDATA.KEY_NUMBER = (BTI_CHAR)keyNumber;
XDATA.XFACE_ID = VARIABLE_ID;
btrieveVersionOkay = TRUE;
twoPointers.xdataPtr = &XDATA;
twoPointers.clientIdPtr = clientID;
twoPointersPtr = &twoPointers;
*((BTI_LONG_PTR) &(newParms.sign)) = *((BTI_LONG_PTR) "PMSW" );
newParms.flags = 0;
newParms.functionCode = BTRV_CODE;
newParms.dataLength = sizeof( newParms );
newParms.dataPtr = twoPointersPtr;
/*======================================================================
Make call to Btrieve.
======================================================================*/
fptr = &newParms;
b_regs.x.dx = FP_OFF(fptr);
b_sregs.ds = FP_SEG(fptr);
int86x( BTR_INTRPT, &b_regs, &b_regs, &b_sregs );
*dataLength = XDATA.BUF_LEN;
}
return( stat );
}
#endif
/***************************************************************************
BTRV() Function for Real Mode DOS
***************************************************************************/
#if defined( BTI_DOS )
BTI_API BTRV(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber )
{
/* Microsoft changed function and structure names in 7.x . */
#if defined( _MSC_VER )
#if ( _MSC_VER > 600 )
#define segread _segread
#define int86x _int86x
#define REGS _REGS
#define SREGS _SREGS
#endif
#endif
union REGS b_regs;
struct SREGS b_sregs;
struct /* structure passed to Btrieve */
{
BTI_VOID_PTR DATA_BUF; /* callers data buffer */
BTI_WORD BUF_LEN; /* length of data buffer */
BTI_VOID_PTR POS_BLOCK; /* user position block */
BTI_VOID_PTR FCB; /* disk FCB */
BTI_WORD FUNCTION; /* requested function */
BTI_VOID_PTR KEY_BUFFER; /* user's key buffer */
BTI_BYTE KEY_LENGTH; /* length of user's key buffer */
BTI_CHAR KEY_NUMBER; /* key of reference for request */
BTI_SINT_PTR STATUS; /* status word */
BTI_SINT XFACE_ID; /* language identifier */
} XDATA;
BTI_VOID_PTR fptr;
BTI_SINT stat = B_NO_ERROR;
segread( &b_sregs );
/*=========================================================================
Check to see that Btrieve has been started.
=========================================================================*/
b_regs.x.ax = 0x3500 + BTR_INTRPT;
int86x( 0x21, &b_regs, &b_regs, &b_sregs );
if ( b_regs.x.bx != BTR_OFFSET )
stat = B_RECORD_MANAGER_INACTIVE;
/*=========================================================================
Move user parameters to XDATA, the block where Btrieve expects them.
=========================================================================*/
if ( stat == B_NO_ERROR )
{
XDATA.FUNCTION = operation;
XDATA.STATUS = &stat;
XDATA.FCB = posBlock;
XDATA.POS_BLOCK = (BTI_BUFFER_PTR)posBlock + 38;
XDATA.DATA_BUF = dataBuffer;
XDATA.BUF_LEN = *dataLength;
XDATA.KEY_BUFFER = keyBuffer;
XDATA.KEY_LENGTH = 255; /* use max since we don't know */
XDATA.KEY_NUMBER = (BTI_CHAR)keyNumber;
XDATA.XFACE_ID = VARIABLE_ID;
/*======================================================================
Make call to Btrieve.
======================================================================*/
fptr = &XDATA;
b_regs.x.dx = FP_OFF(fptr); /*parameter block is expected to be in DX */
b_sregs.ds = FP_SEG(fptr);
int86x( BTR_INTRPT, &b_regs, &b_regs, &b_sregs );
*dataLength = XDATA.BUF_LEN;
}
return( stat );
}
#endif
/***************************************************************************
BTRVID() Function for Extended DOS Using Rational + BSTUB.EXE
***************************************************************************/
#if defined( BTI_DOS_32R )
BTI_API BTRVID(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber,
BTI_BUFFER_PTR clientID )
{
BTI_SINT stat = B_NO_ERROR;
BTI_VOID_PTR twoPointersPtr;
pmswParmBlock newParms;
struct
{
BTI_VOID_PTR xdataPtr;
BTI_VOID_PTR clientIdPtr;
} twoPointers;
/*=========================================================================
Check to see that Btrieve has been started.
=========================================================================*/
/* bstub code will check for presence of Btrieve; no need to check ver */
/*=========================================================================
Move user parameters to XDATA, the block where Btrieve expects them.
=========================================================================*/
struct /* structure passed to Btrieve */
{
BTI_VOID_PTR DATA_BUF; /* callers data buffer */
BTI_WORD BUF_LEN; /* length of data buffer */
BTI_VOID_PTR POS_BLOCK; /* user position block */
BTI_VOID_PTR FCB; /* disk FCB */
BTI_WORD FUNCTION; /* requested function */
BTI_VOID_PTR KEY_BUFFER; /* user's key buffer */
BTI_BYTE KEY_LENGTH; /* length of user's key buffer */
BTI_CHAR KEY_NUMBER; /* key of reference for request */
BTI_SINT_PTR STATUS; /* status word */
BTI_SINT XFACE_ID; /* language identifier */
} XDATA;
/*======================================================================
Move user parameters to XDATA, the block where Btrieve expects them.
======================================================================*/
XDATA.FUNCTION = operation;
XDATA.STATUS = &stat;
XDATA.FCB = posBlock;
XDATA.POS_BLOCK = (BTI_BUFFER_PTR)posBlock + 38;
XDATA.DATA_BUF = dataBuffer;
XDATA.BUF_LEN = *dataLength;
XDATA.KEY_BUFFER = keyBuffer;
XDATA.KEY_LENGTH = 255; /* use max since we don't know */
XDATA.KEY_NUMBER = (BTI_CHAR)keyNumber;
XDATA.XFACE_ID = PROTECTED_ID;
/*=========================================================================
Set up the new parmeter block.
=========================================================================*/
twoPointers.xdataPtr = &XDATA;
twoPointers.clientIdPtr = clientID;
twoPointersPtr = &twoPointers;
*((BTI_LONG_PTR) &(newParms.sign)) = *((BTI_LONG_PTR) "PMSW" );
newParms.flags = 0;
newParms.functionCode = BTRV_CODE;
newParms.dataLength = sizeof( newParms );
newParms.dataPtr = twoPointersPtr;
/*======================================================================
Make call to Btrieve.
======================================================================*/
(*_ImportedFunctions_)[ PROCESS7B ].functionPtr(
(pmswParmBlock *)&newParms );
*dataLength = XDATA.BUF_LEN;
return( stat );
}
#endif
/***************************************************************************
BTRV() Function for Extended DOS Using Rational + BSTUB.EXE
***************************************************************************/
#if defined( BTI_DOS_32R )
BTI_API BTRV(
BTI_WORD operation,
BTI_VOID_PTR posBlock,
BTI_VOID_PTR dataBuffer,
BTI_WORD_PTR dataLength,
BTI_VOID_PTR keyBuffer,
BTI_SINT keyNumber )
{
BTI_SINT stat = B_NO_ERROR;
/*=========================================================================
Check to see that Btrieve has been started.
=========================================================================*/
/* bstub code will check for presence of Btrieve */
/*=========================================================================
Move user parameters to XDATA, the block where Btrieve expects them.
=========================================================================*/
struct /* structure passed to Btrieve */
{
BTI_VOID_PTR DATA_BUF; /* callers data buffer */
BTI_WORD BUF_LEN; /* length of data buffer */
BTI_VOID_PTR POS_BLOCK; /* user position block */
BTI_VOID_PTR FCB; /* disk FCB */
BTI_WORD FUNCTION; /* requested function */
BTI_VOID_PTR KEY_BUFFER; /* user's key buffer */
BTI_BYTE KEY_LENGTH; /* length of user's key buffer */
BTI_CHAR KEY_NUMBER; /* key of reference for request */
BTI_SINT_PTR STATUS; /* status word */
BTI_SINT XFACE_ID; /* language identifier */
} XDATA;
/*======================================================================
Move user parameters to XDATA, the block where Btrieve expects them.
======================================================================*/
XDATA.FUNCTION = operation;
XDATA.STATUS = &stat;
XDATA.FCB = posBlock;
XDATA.POS_BLOCK = (BTI_BUFFER_PTR)posBlock + 38;
XDATA.DATA_BUF = dataBuffer;
XDATA.BUF_LEN = *dataLength;
XDATA.KEY_BUFFER = keyBuffer;
XDATA.KEY_LENGTH = 255; /* use max since we don't know */
XDATA.KEY_NUMBER = (BTI_CHAR)keyNumber;
XDATA.XFACE_ID = PROTECTED_ID;
/*======================================================================
Make call to Btrieve.
======================================================================*/
(*_ImportedFunctions_)[ PROCESS7B ].functionPtr(
(pmswParmBlock *)&XDATA );
*dataLength = XDATA.BUF_LEN;
return( stat );
}
#endif
/***************************************************************************
'Borland PowerPack' and 'Phar-Lap TNT 6.0' 32-Bit Interfaces
***************************************************************************/
#if defined( BTI_DOS_32B ) || defined( BTI_DOS_32P )
#define min(a,b) (((a) < (b)) ? (a) : (b))
#if defined( BTI_DOS_32B )
/***************************************************************************
** Define Far pointer data type (selector:offset32)
**
** The Borland C 32-bit compiler does not support far pointers. For this
** compiler, a FARPTR is defined as a structure which has the same
** organization in memory as a standard 48-bit far pointer.
**
** The following macros are used to get and set the selector and offset
** fields of far pointers, and work both for compilers that directly
** support far pointers and compilers that don't have far pointer support.
** The FP_SEL macro returns the 16-bit selector number field
** of a far pointer. The FP_OFF macro returns the 32-bit offset
** field of a far pointer. The FP_SET macro is used to construct a far
** pointer from a selector number and offset. It takes three arguments:
** the name of the far pointer to be set, an offset, and a selector number.
** The FP_INCR macro increments the offset field of a far pointer.
***************************************************************************/
typedef struct
{
BTI_ULONG Off;
BTI_WORD Sel;
} FARPTR;
#ifndef FP_SEL
#define FP_SEL(fp) ((fp).Sel)
#endif
#ifndef FP_OFF
#define FP_OFF(fp) ((fp).Off)
#endif
#ifndef FP_SET
#define FP_SET(fp, off, sel) \
{\
(fp).Sel = (BTI_WORD) (sel);\
(fp).Off = (BTI_ULONG) (off);\
}
#endif
#ifndef FP_INCR
#define FP_INCR(fp, incr) ((fp).Off += (BTI_ULONG) (incr))
#endif
/*
** Include files for Borland Compiler
*/
#include <windows.h>
#else
/*
** Include files for PharLap extender
*/
#include <i86.h>
#include <pharlap.h>
#endif
#include <blobhdr.h> /* structure definitions for chunk operations */
/*
** Constant definitions
*/
#define structoffset(s,m) (unsigned)(((char *)(&((s *)0)->m))-((char *)0))
#define Normalize(x) ((BTI_ULONG)(x))
#define CLIENT_ID_SIZE 16
/*============================================================================
The XDATASTRUCT defines the Btrieve parameter block
============================================================================*/
typedef struct /* structure passed to Btrieve */
{
BTI_ULONG DATA_BUF; /* callers data buffer */
BTI_WORD BUF_LEN; /* length of data buffer */
BTI_ULONG POS_BLOCK; /* user position block */
BTI_ULONG FCB; /* disk FCB */
BTI_WORD FUNCTION; /* requested function */
BTI_ULONG KEY_BUFFER; /* user's key buffer */
BTI_BYTE KEY_LENGTH; /* length of user's key buffer */
BTI_CHAR KEY_NUMBER; /* key of reference for request */
BTI_ULONG STATUS; /* status word */
BTI_SINT XFACE_ID; /* language identifier */
} XDATASTRUCT;
/*============================================================================
This structure defines the real mode buffer. The DATA_BUF parameter is
set up as one byte for reference. Memory needs to be declared large enough
for data buffers that will be returned.
============================================================================*/
typedef struct
{
XDATASTRUCT XDATA;
BTI_SINT STATUS;
BTI_BYTE POS_BLOCK[128];
BTI_BYTE KEY_BUFFER[255];
BTI_BYTE DATA_BUF[1];
} RMBUFF;
/*============================================================================
Prototypes for functions in protected mode interface
=============================================================================*/
BTI_SINT BtrLoaded( void );
BTI_VOID CallBTRV(
BTI_ULONG );
BTI_SINT GetRealModeBuffer(
FARPTR *,
BTI_ULONG *,
BTI_ULONG );
BTI_SINT SetUpBTRVData(
FARPTR *,
BTI_VOID_PTR,
BTI_VOID_PTR,
BTI_VOID_PTR );
BTI_VOID RetrieveBTRVData(
FARPTR *,
BTI_VOID_PTR,
BTI_VOID_PTR,
BTI_VOID_PTR );
BTI_SINT BlobInputDBlen(
register XTRACTR *);
BTI_SINT ProcessIndirect(
FARPTR *,
BTI_VOID_PTR,
BTI_WORD,
BTI_SINT,
BTI_WORD * );
BTI_SINT VerifyChunk(
BTI_VOID_PTR,
BTI_WORD,
BTI_VOID_PTR,
BTI_WORD,
BTI_WORD,
BTI_WORD );
/*
** The following function are in assembly language- define with CDECL
*/
extern BTI_CHAR cdecl getLowMemByte(
BTI_WORD,
BTI_ULONG );
extern BTI_CHAR cdecl setLowMemByte(
BTI_WORD,
BTI_ULONG,
BTI_BYTE );
extern BTI_WORD cdecl getLowMemWord(
BTI_WORD,
BTI_ULONG );
extern BTI_WORD cdecl setLowMemWord(
BTI_WORD,
BTI_ULONG,
BTI_WORD );
extern BTI_ULONG cdecl getLowMemLong(
BTI_WORD,
BTI_ULONG );
extern BTI_ULONG cdecl setLowMemLong(
BTI_WORD,
BTI_ULONG,
BTI_ULONG );
extern void cdecl copyToLow(
unsigned short dst_sel,
unsigned dst_offset,
void * src,
unsigned int size);
extern void cdecl copyFromLow(
void * dst,
unsigned short src_sel,
unsigned src_offset,
unsigned int size);
/*
*****************************************************************************
**
** Prototype:
**
** BTI_SINT GetRealModeBuffer(
** FARPTR *protectedP,
** BTI_ULONG *realAddr,
** BTI_ULONG requestedSize )
**
** Description:
**
** This function returns a protected mode pointer and a real mode
** pointer to a block of memory allocated in DOS real memory.
** This memory is used for the Btrieve parameter block information.
** When BTI_DOS_32B is defined, this function allocates DOS real
** memory. When BTI_DOS_32P is defined, this function uses a
** DOS buffer that is preallocated by PharLap.
**
** Preconditions:
**
** None.
**
** Parameters:
**
** *protectedP: On output, protectedP is the protected mode
** <output> pointer to the real memory Btrieve parameter
** block.
**
** *realAddr: On output, realAddr contains the real mode
** <output> pointer the Btrieve parameter block in DOS
** real memory.
**
** requestedSize: Contains the size of memory to allocate.
** <input>
**
**
** Return value:
**
** B_NO_ERROR GetRealModeBuffer is successful.
**
** B_DATALENGTH_ERROR If BTI_DOS_32B is defined, this status code is
** returned if the int386 call fails to allocate
** the DOS real memory block.
**
** If BTI_DOS_32P is defined, this status is
** returned when the requestedSize + dataLength
** is smaller than the size of the DOS buffer.
** As an enhancement to the interface, a call to
** _dx_dosbuf_set could be made to set the
** size of the PharLap DOS buffer before the call
** to _dx_dosbuf_get instead of relying on the
** default buffer size.
**
**
** Globals:
**
** None.
**
** Called Functions:
**
** BTI_DOS_32B:
** int386() - Use DPMI services to allocate DOS memory.
**
** BTI_DOS_32P:
** _dx_dosbuf_get - PharLap function to return protected mode and
** real mode pointers to a DOS buffer that PharLap
** maintains.
**
** Comments:
**
** None.
**
*****************************************************************************
*/
BTI_SINT GetRealModeBuffer(
FARPTR *protectedP, /* protected mode pointer to real memory */
BTI_ULONG *realAddr, /* real mode pointer to real memory */
BTI_ULONG requestedSize ) /* size of buffer to allocate */
#if defined( BTI_DOS_32B )
{
/*=========================================================================
GetRealModeBuffer - Borland Power Pack
=========================================================================*/
BTI_SINT allocStatus;
union REGS inRegs, outRegs;
/*
** Allocate DOS Memory
** Interrupt 31h, function 100h
** Note: The DPMI server must support version 0.9 or later of the DPMI
** specification to support this this function. An error code
** will be returned in the AX register and returned to caller
** as B_DATALENGTH_ERROR.
**
** AX = 100h
** BX = Number of 16-byte paragraphs to allocate
**
** Returns:
**
** if carry flag is clear
** AX = real mode segment base address of allocated block
** DX = selector for allocated block
**
** if carry flag is set
** AX = error code
**
*/
inRegs.x.eax = 0x100;
inRegs.x.ebx = (requestedSize + 15) / 16; /* Number of paragraphs */
int386( 0x31, &inRegs, &outRegs );
if ( outRegs.x.cflag )
allocStatus = B_DATALENGTH_ERROR;
else
{
*realAddr = (outRegs.x.eax << 16) & 0xFFFF0000;
FP_SET( *protectedP, 0, (BTI_WORD) outRegs.x.edx );
allocStatus = B_NO_ERROR;
}
return allocStatus;
}
#else
{
/*=========================================================================
GetRealModeBuffer - Phar Lap Extender
=========================================================================*/
BTI_SINT stat; /* Return status code */
BTI_ULONG bufferSize;
/*
** Get Information about the DOS Data Buffer
**
** The _dx_dos_buf_get function returns real and protected-mode pointers
** to the buffer used to buffer data on MS-DOS and BIOS system calls. The
** size of the buffer is returned in the size parameter. Note: need to
** make this call each time because address of the MS_DOS buffer changes
** when anyone calls Load for Debug(_dx_dbg_ld) or the Set DOS Data Buffer
** Size(_dx_dosbuf_set).
*/
_dx_dosbuf_get( (FARPTR *) protectedP, realAddr, &bufferSize);
if ( bufferSize < requestedSize )
stat = B_DATALENGTH_ERROR;
else
stat = B_NO_ERROR;
return stat;
}
#endif
/*
*****************************************************************************
**
** Prototype:
**
** static void FreeRealModeBuffer( BTI_WORD sel )
**
** Description:
**
** FreeRealModeBuffer frees the memory allocated by GetRealModeBuffer
** when BTI_DOS_32B is defined. For BTI_DOS_32P there is nothing to do.
**
** Preconditions:
**
** None.
**
** Parameters:
**
** sel: Protected mode selector of the Real Mode buffer to
** <input> free.
**
**
** Return value:
**
** None.
**
**
** Globals:
**