home *** CD-ROM | disk | FTP | other *** search
- /* C86 interface to Btrieve Record Manager, version 4 */
-
- /* ProcId is used for communicating with the Multi Tasking Version of */
- /* Btrieve. It contains the process id returned from BMulti and should */
- /* not be changed once it has been set. */
- /* */
- static int ProcId = 0; /* initialize to no process id */
- static char MULTI = 0; /* flag set to true if MultiUser */
- static char VSet = 0; /* flag set to true if checked version */
-
- BTRV (OP, POS_BLK, DATA_BUF, DATA_LEN, KEY_BUF, KEY_NUM)
- int OP;
- char POS_BLK[];
- char DATA_BUF[];
- int *DATA_LEN;
- char KEY_BUF[];
- int KEY_NUM;
-
- {
- #define BTR_ERR 20 /* record manager not started */
- #define BTR_VECTOR 0x7B * 4 /* offset for interrupt */
- #define VARIABLE_ID 0x6176 /* id for variable length records - 'va' */
- #define POS_LEN_ERR 23 /* invalid position block length */
-
- struct REGVAL { int AX,BX,CX,DX,SI,DI,D_SEG,E_SEG; } REGS;
-
- struct SEGREG { int CS,SS,DS,ES; } SREGS;
-
- struct BTRIEVE_PARMS /* structure passed to Record Man */
- {char *USER_BUF_OFFSET; /* callers data buffer offset */
- int USER_BUF_SEG; /* callers data buffer segment */
- int USER_BUF_LEN; /* length of data buffer */
- char *USER_CUR_OFFSET; /* user position block offset */
- int USER_CUR_SEG; /* user position block segment */
- char *USER_FCB_OFFSET; /* offset of disk FCB */
- int USER_FCB_SEG; /* segment of disk FCB */
- int USER_FUNCTION; /* requested function */
- char *USER_KEY_OFFSET; /* offset of user's key buffer */
- int USER_KEY_SEG; /* segment of user's key buffer */
- char USER_KEY_LENGTH; /* length of user's key buffer */
- char USER_KEY_NUMBER; /* key of reference for request */
- int *USER_STAT_OFFSET; /* offset of status word */
- int USER_STAT_SEG; /* segment of status word */
- int XFACE_ID;}; /* language identifier */
-
- struct BTRIEVE_PARMS XDATA;
- int STAT; /* status of Btrieve call */
-
- /* */
- /* Check to see that the Btrieve Record Manager has been started. */
- /* */
-
- REGS.AX = 0x357B;
- sysint (0x21, ®S, ®S);
- if (REGS.BX != 0x33)
- return (BTR_ERR);
-
- if (!VSet)
- {
- VSet = 1;
- REGS.AX = 0x3000;
- sysint (0x21, ®S, ®S);
- if ((REGS.AX & 0x00FF) >= 3)
- {
- REGS.AX = 0xAB00;
- sysint(0x2F, ®S,®S);
- MULTI = ((REGS.AX & 0x00FF) == 'M');
- }
- }
-
- /* Read segment registers and initialize segment part of addresses to */
- /* user's data segment. */
- /* */
- segread(&SREGS);
- XDATA.USER_BUF_SEG = XDATA.USER_CUR_SEG = XDATA.USER_FCB_SEG =
- XDATA.USER_KEY_SEG = XDATA.USER_STAT_SEG = SREGS.DS;
- /* */
- /* Move user parameters to XDATA, the block where Btrieve expects them.*/
- /* */
- XDATA.USER_FUNCTION = OP;
- XDATA.USER_STAT_OFFSET = &STAT;
- XDATA.USER_FCB_OFFSET = POS_BLK;
- XDATA.USER_CUR_OFFSET = POS_BLK + 38;
- XDATA.USER_BUF_OFFSET = DATA_BUF;
- XDATA.USER_BUF_LEN = *DATA_LEN;
- XDATA.USER_KEY_OFFSET = KEY_BUF;
- XDATA.USER_KEY_LENGTH = 255; /* use max since we don't know */
- XDATA.USER_KEY_NUMBER = KEY_NUM;
- XDATA.XFACE_ID = VARIABLE_ID;
-
- REGS.DX = (unsigned) &XDATA; /* parameter block is expected to be in DX */
- REGS.D_SEG = SREGS.DS;
- REGS.E_SEG = SREGS.ES;
-
- /* */
- /* Make call to Btrieve Record Manager */
- /* */
-
- if (!MULTI)
- sysint(0x7B, ®S,®S);
- else
- {
- while (1)
- {
- REGS.AX = 1; /* initialize to having a process id */
- if ((REGS.BX = ProcId) != 0) /* do we have a process id yet? */
- REGS.AX = 2; /* no process id, send request for one */
- REGS.AX += 0xAB00;
- sysint(0x2F, ®S,®S);
- if ((REGS.AX & 0x00FF) == 0) break;
- REGS.AX = 0x0200;
- sysint(0x7F, ®S,®S);
- }
- if (ProcId == 0) /* keep PID only if requesting one */
- ProcId = REGS.BX;
- }
-
- *DATA_LEN = XDATA.USER_BUF_LEN;
- return(STAT);
- }