home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / mbase.zip / MBASE.H < prev    next >
C/C++ Source or Header  |  1991-02-11  |  7KB  |  123 lines

  1. /*   ********************************************************************   *
  2.   ***                                                   unix compatible  ***
  3.  *    MetalBase 3.0....................................................     *
  4.  *                                                                          *
  5.  *    Multi-user simultaneous use of relations (On multi-user hardware)     *
  6.  *    Users may have many relations open at once, even the same one!        *
  7.  *    Unlimited length records (Really!  Just redefine BUF_LEN!)            *
  8.  *    Up to 20 indicies per relation, 5 fields max per composite index      *
  9.  *    Up to 4.2 billion records per relation                                *
  10.  *    Bizzare intermittent bugs, just like the expensive programs           *
  11.  *    And, unless they're weird, your kids will eat it                      *
  12.  *                                                               /\         *
  13.  *    Written starting in August 1989, by Huan-Ti            rj /  \        *
  14.  *                                                             /    \       *
  15.  *   "Ye hath mushrooms for $1.99 a pound.  Ye art             \    /       *
  16.  *    truly a Calvinist."                                       \  / tp     *
  17.  *                       -- II Calvin 7:1                        \/         *
  18.   ***                                                                    ***
  19.  *   ********************************************************************   */
  20.  
  21. #include "stdinc.h"
  22.  
  23. #ifndef BUF_LEN            /* Maximum possible needed buffer (Length = 1 +  */
  24. #define BUF_LEN 256        /* record_length + 13*number_of_indicies         */
  25. #endif                     /* If needed, redefine before #including         */
  26.  
  27. #ifndef MAX_REL            /* Maximum possible # of relations open at once, */
  28. #define MAX_REL 5          /* for this user.  DOES NOT CHANGE STDIO'S # of  */
  29. #endif                     /* FILES OPEN AT ONCE (#_of_rel + 3)             */
  30.  
  31. #ifndef MAX_FLDS           /* Maximum number of fields in any given         */
  32. #define MAX_FLDS 30        /* relation.  If you need more than 30, redefine */
  33. #endif                     /* before #including <mbase.h>                   */
  34.  
  35. #define OKAY                  0   /* Generic no-problem number.  Thank IBM. */
  36. #define NOT_ENOUGH_ROOM   -1000   /* Too many files are open at once        */
  37. #define CANNOT_OPEN_REL   -1001   /* Can't open FILE.REL                    */
  38. #define RELATION_HUNG     -1002   /* User left during add/del/upd.  See dox */
  39. #define CANNOT_READ_REL   -1003   /* FILE.REL is protected (Need rw access) */
  40. #define RELATION_BUSY     -1004   /* 120 users on one relation=max (Hah!)   */
  41. #define RELATION_LOCKED   -1005   /* Someone has locked the relation        */
  42. #define LOCK_DENIED       -1006   /* Can't lock with other users.  See dox  */
  43. #define ILLEGAL_DUPLICATE -1007   /* Record would violate a nodups index    */
  44. #define CORRUPT_INDEX     -1008   /* Means you're fucked.  Probly not used  */
  45. #define INVALID_FILE_CODE -1009   /* You've passed an unreal relation numb  */
  46. #define NOT_OPEN          -1010   /* You've tried to work with a closed rel */
  47. #define RCD_INVALID       -1011   /* Bad-size or # of flds given to add/upd */
  48. #define INVALID_COMP      -1012   /* SELECT's record for comparison is bad  */
  49. #define UNKNOWN_ACTION    -1013   /* You'll probly never get this one.      */
  50. #define NOT_FOUND         -1014   /* Generic.  Can't find the record U want */
  51. #define NO_CURRENT_RECORD -1015   /* Must select a record before del/upd    */
  52. #define INVALID_INDEX     -1016   /* A bad index # has been sent to mb_sel  */
  53.  
  54. #define CURR                  1   /* Re-read the current record (4 mb_sel)  */
  55. #define EQUL                  2   /* Get rec that matches exactly (see dox) */
  56. #define FRST                  3   /* Get the first record, sequentially     */
  57. #define GTEQ                  4   /* If not exact, get the one right after  */
  58. #define GTHN                  5   /* Like GTEQ, but won't accept exact one  */
  59. #define LAST                  6   /* Get the last record, sequentially      */
  60. #define LTEQ                  7   /* If not exact, get the one right before */
  61. #define LTHN                  8   /* Like LTEQ, but won't accept exact one  */
  62. #define NEXT                  9   /* Get the next record, sequentially      */
  63. #define PREV                 10   /* Get the previous record, sequentially  */
  64.  
  65. #define CURRENT            CURR   /* These are included to reduce errors    */
  66. #define EQUAL              EQUL   /* due to stupid humans who insist on     */
  67. #define FIRST              FRST   /* using long words instead of short ones */
  68. #define GTHAN              GTHN   /*                                        */
  69. #define LTHAN              LTHN   /* Gee, I'm considerate.                  */
  70. #define PREVIOUS           PREV   /*                                        */
  71.  
  72. #define ZEROES "\001\001\001\001\001\001\001\001\001\001\001\001."
  73.  
  74. /****************************************************************************/
  75. /*                                                                          */
  76. /* A reminder of the single rule that applies to EVERYTHING in this file:   */
  77. /*                                                                          */
  78. /* If you don't understand it, DON'T SCREW WITH IT.                         */
  79. /*                                                                          */
  80. /* I'd like to emphasize that this rule is _most_important_ in viewing the  */
  81. /* follow section of definitions.  If you wanna change the internal         */
  82. /* structure of the relations, and think you can (successfully, that is),   */
  83. /* go right ahead.  And send me a copy of the "better" MetalBase when you   */
  84. /* think you're finished... I'd like to see it.  :-)                        */
  85. /*                                                                          */
  86. /****************************************************************************/
  87.  
  88. #define _t_top(f,i)    4 +  4*i
  89. #define _idxs(f)           13*(_list[f].num_idx)
  90. #define _num_recs(f)   5 +  4*(_list[f].num_idx)
  91.  
  92. #define _block(f)      11+(4*_list[f].num_idx)
  93. #define _base(f,r)     _block(f)+_list[f].relbase+(r-1)*((13*_list[f].num_idx)+\
  94.                           2+(_list[f].rec_len))
  95. #define _l_ptr(f,i,r)  _base  (f, r)    + 13*i
  96. #define _r_ptr(f,i,r)  _l_ptr (f, i, r) +  4
  97. #define _b_ptr(f,i,r)  _r_ptr (f, i, r) +  4
  98. #define _rec(f,r)      _base  (f, r)    + (13*_list[f].num_idx) + 1
  99.  
  100. #define _len(f)        2 + _idxs (f) + _list[f].rec_len
  101.  
  102. /*                               Whew!                                      */
  103.  
  104. char   buffer [BUF_LEN];
  105.  
  106. int  _Started = -1;
  107.  
  108. #define mb_key(a,b,c) _skey(a,b-1,c)
  109.  
  110. struct
  111. {  long  int   pos,      relbase;
  112.          int   relcode;
  113.          int   num_idx,  rec_len;
  114.  
  115.          int   idx_dups  [20];
  116.          int   idx_just  [MAX_FLDS];
  117.          int   idx_num   [20][6];
  118.          int   idx_start [20][6];
  119.          int   idx_stop  [20][5];
  120.  
  121.          char  filename  [80];     } _list [MAX_REL];
  122.  
  123.