home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a011 / 2.ddi / C86XBTRV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-04-28  |  3.9 KB  |  121 lines

  1. /* C86 interface to Btrieve Record Manager, version 4 */
  2.  
  3. /* ProcId is used for communicating with the Multi Tasking Version of  */
  4. /* Btrieve. It contains the process id returned from BMulti and should */
  5. /* not be changed once it has been set.                    */
  6. /*                                       */
  7. static int ProcId = 0;            /* initialize to no process id */
  8. static char MULTI = 0;              /* flag set to true if MultiUser */
  9. static char VSet = 0;        /* flag set to true if checked version */
  10.  
  11. BTRV (OP, POS_BLK, DATA_BUF, DATA_LEN, KEY_BUF, KEY_NUM)
  12.   int  OP;
  13.   char POS_BLK[];
  14.   char DATA_BUF[];
  15.   int  *DATA_LEN;
  16.   char KEY_BUF[];
  17.   int  KEY_NUM;
  18.  
  19. {
  20. #define BTR_ERR     20           /* record manager not started */
  21. #define BTR_VECTOR  0x7B * 4       /* offset for interrupt */
  22. #define VARIABLE_ID 0x6176       /* id for variable length records - 'va' */
  23. #define POS_LEN_ERR 23           /* invalid position block length */
  24.  
  25. struct REGVAL { int AX,BX,CX,DX,SI,DI,D_SEG,E_SEG; } REGS;
  26.  
  27. struct SEGREG { int CS,SS,DS,ES; } SREGS;
  28.  
  29. struct BTRIEVE_PARMS           /* structure passed to Record Man */
  30.   {char *USER_BUF_OFFSET;       /* callers data buffer offset */
  31.    int    USER_BUF_SEG;           /* callers data buffer segment */
  32.    int    USER_BUF_LEN;           /* length of data buffer */
  33.    char *USER_CUR_OFFSET;       /* user position block offset */
  34.    int    USER_CUR_SEG;           /* user position block segment */
  35.    char *USER_FCB_OFFSET;       /* offset of disk FCB */
  36.    int    USER_FCB_SEG;           /* segment of disk FCB */
  37.    int    USER_FUNCTION;           /* requested function */
  38.    char *USER_KEY_OFFSET;       /* offset of user's key buffer */
  39.    int    USER_KEY_SEG;           /* segment of user's key buffer */
  40.    char USER_KEY_LENGTH;       /* length of user's key buffer */
  41.    char USER_KEY_NUMBER;       /* key of reference for request */
  42.    int    *USER_STAT_OFFSET;       /* offset of status word */
  43.    int    USER_STAT_SEG;           /* segment of status word */
  44.    int    XFACE_ID;};           /* language identifier */
  45.  
  46. struct BTRIEVE_PARMS XDATA;
  47. int    STAT;               /* status of Btrieve call */
  48.  
  49. /*                                    */
  50. /*  Check to see that the Btrieve Record Manager has been started.    */
  51. /*                                    */
  52.  
  53. REGS.AX = 0x357B;
  54. sysint (0x21, ®S, ®S);
  55. if (REGS.BX != 0x33)
  56.    return (BTR_ERR);
  57.  
  58. if (!VSet)
  59.  {
  60.   VSet = 1;
  61.   REGS.AX = 0x3000;
  62.   sysint (0x21, ®S, ®S);
  63.   if ((REGS.AX & 0x00FF) >= 3)
  64.    {
  65.     REGS.AX = 0xAB00;
  66.     sysint(0x2F, ®S,®S);
  67.     MULTI = ((REGS.AX & 0x00FF) == 'M');
  68.    }
  69.  }
  70.  
  71. /*  Read segment registers and initialize segment part of addresses to    */
  72. /*  user's data segment.                                                */
  73. /*                                    */
  74. segread(&SREGS);
  75. XDATA.USER_BUF_SEG = XDATA.USER_CUR_SEG = XDATA.USER_FCB_SEG =
  76.   XDATA.USER_KEY_SEG = XDATA.USER_STAT_SEG = SREGS.DS;
  77. /*                                    */
  78. /*  Move user parameters to XDATA, the block where Btrieve expects them.*/
  79. /*                                    */
  80. XDATA.USER_FUNCTION = OP;
  81. XDATA.USER_STAT_OFFSET = &STAT;
  82. XDATA.USER_FCB_OFFSET = POS_BLK;
  83. XDATA.USER_CUR_OFFSET = POS_BLK + 38;
  84. XDATA.USER_BUF_OFFSET = DATA_BUF;
  85. XDATA.USER_BUF_LEN    = *DATA_LEN;
  86. XDATA.USER_KEY_OFFSET = KEY_BUF;
  87. XDATA.USER_KEY_LENGTH = 255;         /* use max since we don't know */
  88. XDATA.USER_KEY_NUMBER = KEY_NUM;
  89. XDATA.XFACE_ID = VARIABLE_ID;
  90.  
  91. REGS.DX = (unsigned) &XDATA; /* parameter block is expected to be in DX */
  92. REGS.D_SEG = SREGS.DS;
  93. REGS.E_SEG = SREGS.ES;
  94.  
  95. /*                                      */
  96. /*  Make call to Btrieve Record Manager                   */
  97. /*                                      */
  98.  
  99. if (!MULTI)
  100.   sysint(0x7B, ®S,®S);
  101. else
  102.  {
  103.   while (1)
  104.    {
  105.     REGS.AX = 1;             /* initialize to having a process id */
  106.     if ((REGS.BX = ProcId) != 0)      /* do we have a process id yet? */
  107.       REGS.AX = 2;           /* no process id, send request for one */
  108.     REGS.AX += 0xAB00;
  109.     sysint(0x2F, ®S,®S);
  110.     if ((REGS.AX & 0x00FF) == 0) break;
  111.     REGS.AX = 0x0200;
  112.     sysint(0x7F, ®S,®S);
  113.    }
  114.   if (ProcId == 0)               /* keep PID only if requesting one */
  115.     ProcId = REGS.BX;
  116.  }
  117.  
  118. *DATA_LEN = XDATA.USER_BUF_LEN;
  119. return(STAT);
  120. }
  121.