home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a011 / 2.ddi / WAT2BTRV.C < prev   
Encoding:
C/C++ Source or Header  |  1989-07-28  |  3.4 KB  |  85 lines

  1. /*                                                                      */
  2. /*           WatCom C interface to the Btrieve Record Manager           */
  3. /*                                                                      */
  4.  
  5.  
  6. typedef unsigned short int INT;
  7. #define SINT short
  8. #define BTR_ERR     20                    /* record manager not started */
  9. #define BTR_INT     0x7B                    /* Btrieve interrupt vector */
  10. #define BTR_OFFSET  0x33               /* Btrieve offset within segment */
  11. #define VARIABLE_ID 0x6176     /* id for variable length records - 'va' */
  12.  
  13.  
  14. SINT BTRV (SINT operation,
  15.            char *posBlock,
  16.            char *dataBuf,
  17.            INT  *dataLen,
  18.            char *keyBuf,
  19.            SINT  keyNum
  20.           )
  21.  
  22. {
  23. struct REGVAL { SINT AX, BX, CX, DX, SI, DI, CY; } regs;
  24.  
  25. struct SEGREG { SINT ES, CS, SS, DS; } sregs;
  26.  
  27. struct BTRIEVE_PARMS      /* structure passed to Btrieve Record Manager */
  28.  {
  29.    char far *bufAddress;                 /* callers data buffer Address */
  30.    INT      bufLength;                         /* length of data buffer */
  31.    char far *curAddress;                 /* user position block Address */
  32.    char far *fcbAddress;                         /* Address of disk FCB */
  33.    INT      function;                             /* requested function */
  34.    char far *keyAddress;                /* Address of user's key buffer */
  35.    char     keyLength;                   /* length of user's key buffer */
  36.    char     keyNumber;                  /* key of reference for request */
  37.    INT  far *statAddress;                     /* Address of status word */
  38.    INT      xfaceID;                             /* language identifier */
  39.  } xData;
  40.  
  41. INT stat = 0;                                 /* status of Btrieve call */
  42.  
  43. /*                                                                      */
  44. /*  Check to see that the Btrieve Record Manager has been started.      */
  45. /*                                                                      */
  46.  
  47.   regs.AX = 0x3500 + BTR_INT;
  48.   int86x (0x21, ®s, ®s, &sregs);
  49.   if (regs.BX != BTR_OFFSET)
  50.      return (BTR_ERR);
  51.  
  52. /*  Read segment registers and initialize segment part of addresses to  */
  53. /*  user's data segment.                                                */
  54. /*                                                                      */
  55.  
  56. segread (&sregs);
  57.  
  58. /*                                                                      */
  59. /*  Move user parameters to xData, the block where Btrieve expects them.*/
  60. /*                                                                      */
  61.  
  62. xData.function    = operation;
  63. xData.statAddress = &stat;
  64. xData.fcbAddress  = posBlock;
  65. xData.curAddress  = posBlock + 38;
  66. xData.bufAddress  = dataBuf;
  67. xData.bufLength  = *dataLen;
  68. xData.keyAddress  = keyBuf;
  69. xData.keyLength  = 255;                 /* use max since we don't know */
  70. xData.keyNumber  = keyNum;
  71. xData.xfaceID    = VARIABLE_ID;
  72.  
  73. /*                                                                      */
  74. /*  Make call to the Btrieve Record Manager.                            */
  75. /*                                                                      */
  76.  
  77. regs.DX = (INT) &xData;      /* parameter block is expected to be in DX */
  78. sregs.DS = sregs.SS;
  79. int86x (BTR_INT, ®s, ®s, &sregs);
  80.  
  81. *dataLen = xData.bufLength;
  82. return (stat);                                         /* return status */
  83. }
  84.  
  85.