home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / cdb112.zip / DBMGR.H < prev    next >
Text File  |  1991-02-02  |  12KB  |  284 lines

  1. /*
  2.  *  dbmgr.h
  3.  *
  4.  *  This file contains structures, macros and #defines for
  5.  *  the database layout.
  6.  */
  7.  
  8. extern short    cdb( short, ...);
  9. extern char     dbpath[];
  10.  
  11. typedef char            CHAR;
  12. typedef unsigned char   UCHAR;
  13. typedef short           INT;
  14. typedef unsigned short  UINT;
  15. typedef long            LONG;
  16. typedef unsigned long   ULONG;
  17.  
  18. #define NBRHANDLES      12      /* Maximum number of file handles       */
  19. #define MAXKEY          8       /* Maximum # of keys per key record     */
  20. #define KEYPAGESIZE     512     /* Key page buffer size                 */
  21. #define NBRPAGES        16      /* Number of key page buffers           */
  22. #define DATAPAGESIZE    2048    /* Data page buffer size                */
  23. #define DATASLOTSIZE    1024    /* Data file slot buffer size           */
  24.  
  25. /* Field index structure defines */
  26. #define KEY_FIELD       0x01
  27.  
  28. /* Handle index structure defines */
  29. #define FILE_MODIFIED   0x01
  30.  
  31. /* Key file index structure defines */
  32. #define PAGE_FULL       0x01
  33.  
  34. /* Error defines */
  35. #define E_INVALIDCASE   -2
  36. #define E_DOS           -1
  37. #define E_NORECNAME     1
  38. #define E_NOFLDNAME     2
  39. #define E_INVALIDSET    3
  40. #define E_NOTAKEY       4
  41. #define E_NOTFOUND      5
  42. #define E_NEXTGUESS     6
  43. #define E_NOCURRENT     7
  44. #define E_NONEXT        8
  45. #define E_NOPREV        9
  46. #define E_NOMEMBER      10
  47. #define E_NOOWNER       11
  48.  
  49. /* DBC call defines */
  50. #define D_OPEN                  0
  51. #define D_CLOSE                 1
  52. #define D_FLUSH                 2
  53. #define D_GET_CURRENCY          3
  54. #define D_UPDATE_CURRENCY       4
  55. #define D_FIND_FIRST_RECORD     5
  56. #define D_FIND_LAST_RECORD      6
  57. #define D_FIND_NEXT_RECORD      7
  58. #define D_FIND_PREV_RECORD      8
  59. #define D_FIND_RECORD_BY_KEY    9
  60. #define D_GET_FIRST_RECORD      10
  61. #define D_GET_LAST_RECORD       11
  62. #define D_GET_NEXT_RECORD       12
  63. #define D_GET_PREV_RECORD       13
  64. #define D_GET_RECORD_BY_KEY     14
  65. #define D_GET_CURRENT_RECORD    15
  66. #define D_ADD_RECORD            16
  67. #define D_UPDATE_RECORD         17
  68. #define D_DELETE_RECORD         18
  69. #define D_FIND_FIRST_SET        19
  70. #define D_FIND_LAST_SET         20
  71. #define D_FIND_NEXT_SET         21
  72. #define D_FIND_PREV_SET         22
  73. #define D_GET_FIRST_SET         23
  74. #define D_GET_LAST_SET          24
  75. #define D_GET_NEXT_SET          25
  76. #define D_GET_PREV_SET          26
  77. #define D_GET_SET_OWNER         27
  78. #define D_ADD_SET               28
  79. #define D_DELETE_SET            29
  80.  
  81. /* DataBase Macros */
  82. #define DbOpen(a)                       cdb(D_OPEN, a)
  83. #define DbClose()                       cdb(D_CLOSE)
  84. #define DbFlush()                       cdb(D_FLUSH)
  85. #define DbRecordGetCurrency(a,b)        cdb(D_GET_CURRENCY,a,b)
  86. #define DbRecordUpdCurrency(a,b)        cdb(D_UPDATE_CURRENCY,a,b)
  87. #define DbRecordFindFirst(a,b)          cdb(D_FIND_FIRST_RECORD,a,b)
  88. #define DbRecordFindLast(a,b)           cdb(D_FIND_LAST_RECORD,a,b)
  89. #define DbRecordFindNext(a,b)           cdb(D_FIND_NEXT_RECORD,a,b)
  90. #define DbRecordFindPrev(a,b)           cdb(D_FIND_PREV_RECORD,a,b)
  91. #define DbRecordFindByKey(a,b,c)        cdb(D_FIND_RECORD_BY_KEY,a,b,c)
  92. #define DbRecordGetFirst(a,b,c)         cdb(D_GET_FIRST_RECORD,a,b,c)
  93. #define DbRecordGetLast(a,b,c)          cdb(D_GET_LAST_RECORD,a,b,c)
  94. #define DbRecordGetNext(a,b,c)          cdb(D_GET_NEXT_RECORD,a,b,c)
  95. #define DbRecordGetPrev(a,b,c)          cdb(D_GET_PREV_RECORD,a,b,c)
  96. #define DbRecordGetByKey(a,b,c,d)       cdb(D_GET_RECORD_BY_KEY,a,b,c,d)
  97. #define DbRecordGetCurrent(a,b,c)       cdb(D_GET_CURRENT_RECORD,a,b,c)
  98. #define DbRecordAdd(a,b)                cdb(D_ADD_RECORD,a,b)
  99. #define DbRecordUpdate(a,b)             cdb(D_UPDATE_RECORD,a,b)
  100. #define DbRecordDelete(a)               cdb(D_DELETE_RECORD,a)
  101. #define DbSetFindFirst(a,b)             cdb(D_FIND_FIRST_SET,a,b)
  102. #define DbSetFindLast(a,b)              cdb(D_FIND_LAST_SET,a,b)
  103. #define DbSetFindNext(a,b)              cdb(D_FIND_NEXT_SET,a,b)
  104. #define DbSetFindPrev(a,b)              cdb(D_FIND_PREV_SET,a,b)
  105. #define DbSetGetFirst(a,b,c)            cdb(D_GET_FIRST_SET,a,b,c)
  106. #define DbSetGetLast(a,b,c)             cdb(D_GET_LAST_SET,a,b,c)
  107. #define DbSetGetNext(a,b,c)             cdb(D_GET_NEXT_SET,a,b,c)
  108. #define DbSetGetPrev(a,b,c)             cdb(D_GET_PREV_SET,a,b,c)
  109. #define DbSetGetOwner(a,b,c)            cdb(D_GET_SET_OWNER,a,b,c)
  110. #define DbSetAdd(a,b)                   cdb(D_ADD_SET,a,b)
  111. #define DbSetDelete(a,b)                cdb(D_DELETE_SET,a,b)
  112.  
  113.  
  114. /* DataBase structures and unions */
  115. union  type
  116.     {
  117.     CHAR                charval;
  118.     INT                 intval;
  119.     LONG                longval;
  120.     float               floatval;
  121.     double              doubleval;
  122.     CHAR                *ptrval;
  123.     UCHAR               ucharval;
  124.     UINT                uintval;
  125.     ULONG               ulongval;
  126.     };
  127.  
  128. struct dbheader                         /* 128 bytes                    */
  129.     {               
  130.     CHAR                title[96];      /* DBD title                    */
  131.     UINT                totrecs;        /* Total number of records      */
  132.     UINT                totowns;        /* Total number of owners       */
  133.     UINT                totmems;        /* Total number of members      */
  134.     UINT                totflds;        /* Total number of fields       */
  135.     CHAR                prefix[6];      /* File prefix description      */
  136.     CHAR                filler[18];
  137.     };
  138.  
  139. struct record_index                     /* 46 bytes                     */
  140.     {
  141.     UINT                firstown;       /* First owner                  */
  142.     UINT                nbrowns;        /* Number of owners             */
  143.     UINT                firstmem;       /* First member                 */
  144.     UINT                nbrmems;        /* Number of members            */
  145.     UINT                firstfld;       /* First field                  */
  146.     UINT                nbrflds;        /* Number of fields             */
  147.     UINT                reclen;         /* Record length                */
  148.     CHAR                recname[32];    /* Record name                  */
  149.     };
  150.  
  151. struct owner_index                      /* 4 bytes                      */
  152.     {
  153.     UINT                nextown;        /* Next owner                   */
  154.     UINT                ownnum;         /* Owner record number          */
  155.     };
  156.  
  157. struct member_index                     /* 4 bytes                      */
  158.     {
  159.     UINT                nextmem;        /* Next member                  */
  160.     UINT                memnum;         /* Member record number         */
  161.     };
  162.  
  163. struct field_index                      /* 40 bytes                     */
  164.     {
  165.     UCHAR               fldtype;        /* Field type  Bit 0 - char     */
  166.                                         /*             Bit 1 - int      */
  167.                                         /*             Bit 2 - short    */
  168.                                         /*             Bit 3 - long     */
  169.                                         /*             Bit 4 - float    */
  170.                                         /*             Bit 5 - double   */
  171.                                         /*             Bit 7 - unsigned */
  172.     UINT                fldlen;         /* Field length                 */
  173.     UINT                flddim;         /* Field dimension              */
  174.     CHAR                fldname[32];    /* Field name                   */
  175.     UINT                fldkey;         /* Key number of data struct    */
  176.     UCHAR               fldflags;       /* Bit 0 - key field            */
  177.     };
  178.  
  179. /* Field casting defines */
  180. #define FLDTYPE_CHAR            0x01
  181. #define FLDTYPE_INT             0x02
  182. #define FLDTYPE_SHORT           0x04
  183. #define FLDTYPE_LONG            0x08
  184. #define FLDTYPE_FLOAT           0x10
  185. #define FLDTYPE_DOUBLE          0x20
  186. #define FLDTYPE_UNSIGNED        0x80
  187.  
  188. struct  key_file_index                  /* 32 bytes                     */
  189.     {
  190.     CHAR        name[12];               /* Key file name                */
  191.     UINT        nextavailpage;          /* Next available page          */
  192.     UINT        firstdelpage;           /* First page in the delete     */
  193.                                         /* chain.                       */
  194.     UINT        pagenbr[MAXKEY];        /* Key 1st page index           */
  195.     };
  196.  
  197. struct  key_page_index                  /* 10 bytes                     */
  198.     {
  199.     UINT        prevpage;               /* Previous page in sort tree   */
  200.     UINT        nextpage;               /* Next page in sort tree       */
  201.     UINT        slotsused;              /* Number of slots used on page */
  202.     UINT        slotsize;               /* Size of key slot             */
  203.     UINT        flags;                  /* Bit 0 - page is full         */
  204.     };
  205.  
  206. struct  data_file_index                 /* 32 bytes                     */
  207.     {
  208.     CHAR        name[12];               /* Data file name               */
  209.     ULONG       nextavailslot;          /* Next available slot          */
  210.     ULONG       firstdelslot;           /* First slot in the delete     */
  211.                                         /* chain.                       */
  212.     UINT        slotsize;               /* Size of data slot            */
  213.     CHAR        filler[10];
  214.     };
  215.  
  216. struct  data_slot_index                 /* 6 bytes                      */
  217.     {
  218.     UINT        offsettodata;           /* Offset to actual data        */
  219.     ULONG       nextdel;                /* DBA of next member in the    */
  220.                                         /* delete chain.                */
  221.     };
  222.  
  223. struct  ownptr_index                    /* 8 bytes                      */
  224.     {
  225.     ULONG       firstmem;               /* Dba of first member          */
  226.     ULONG       lastmem;                /* Dba of last member           */
  227.     };
  228.  
  229. struct  memptr_index                    /* 12 bytes                     */
  230.     {
  231.     ULONG       owndba;                 /* Dba of owner record          */
  232.     ULONG       prevmem;                /* Dba of prev member in chain  */
  233.     ULONG       nextmem;                /* Dba of next member in chain  */
  234.     };
  235.  
  236. struct handle_index                     /* 4 bytes                      */
  237.     {
  238.     INT         handle;                 /* Handle number                */
  239.     UINT        flags;                  /* Bit 0 - set if modified      */
  240.     };
  241.  
  242. struct page_index                       /* 518 bytes                    */
  243.     {
  244.     UINT        recnbr;                 /* Record number                */
  245.     UINT        fldnbr;                 /* Field number                 */
  246.     UINT        diskpagenbr;            /* Page number                  */
  247.     CHAR        buffer[KEYPAGESIZE];    /* Data buffer                  */
  248.     };
  249.  
  250. struct currency_index                   /* 36 bytes                     */
  251.     {
  252.     struct 
  253.         {
  254.         UINT    page;
  255.         UINT    slot;
  256.         } keydba[MAXKEY];               /* Array of key dba's           */
  257.     ULONG       datadba;                /* Data database address        */
  258.     };
  259.  
  260.  
  261. /* Microsoft C _dos_find definitions */
  262.  
  263. #ifndef MSC
  264.  
  265. #define _A_NORMAL       0x00    /* Normal file - No read/write restrictions */
  266. #define _A_RDONLY       0x01    /* Read only file */
  267. #define _A_HIDDEN       0x02    /* Hidden file */
  268. #define _A_SYSTEM       0x04    /* System file */
  269. #define _A_VOLID        0x08    /* Volume ID file */
  270. #define _A_SUBDIR       0x10    /* Subdirectory */
  271. #define _A_ARCH         0x20    /* Archive file */
  272.  
  273. struct find_t
  274.     {
  275.     char        reserved[21];
  276.     char        attrib;
  277.     unsigned    wr_time;
  278.     unsigned    wr_date;
  279.     long        size;
  280.     char        name[13];
  281.     };
  282.  
  283. #endif
  284.