home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE51.TAR / mbase51 / src / internal.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  6.6 KB  |  201 lines

  1. /*
  2.  * METALBASE 5.1
  3.  *
  4.  * Released January 1st, 1993 by Huan-Ti [ t-richj@microsoft.com ]
  5.  *
  6.  */
  7.  
  8. #ifndef INTERNAL_H
  9. #define INTERNAL_H
  10.  
  11. #ifndef MBASE_H
  12. #include <mbase.h>
  13. #endif
  14.  
  15.  
  16. /*
  17.  * RELATION FORMAT ------------------------------------------------------------
  18.  *
  19.  */
  20.  
  21. #define POS_OLDFIELDPTR  2L   /* For 4.0 compatibility         */
  22. #define POS_OLDNUMREC   14L   /* For 4.0 compatibility         */
  23. #define POS_OLDINDICES  26L   /* For 4.0 compatibility         */
  24.  
  25. #define POS_SIGNATURE    0L   /* This information is described */
  26. #define POS_WORKFLAG     1L   /* in more detail in the file    */
  27. #define POS_NUMQUE       2L   /*    ../tech/chapter.1          */
  28. #define POS_FIELDPTR     6L
  29. #define POS_INDEXPTR    10L
  30. #define POS_RECZERO     14L
  31. #define POS_NUMREC      18L
  32. #define POS_NEXTSER     22L
  33. #define POS_NUMFIELD    26L
  34. #define POS_NUMINDEX    28L
  35. #define POS_INDICES     30L
  36.  
  37. #define lckPOS_USERS     0L
  38. #define lckPOS_ELOCK     2L
  39. #define lckPOS_HLOCK     4L
  40. #define lckPOS_QUEUE    10L
  41. #define lckPOS_STROBE   70L
  42.  
  43.  
  44. /*
  45.  * INTERNAL STRUCTURE DEFINITIONS AND UTILITIES -------------------------------
  46.  *
  47.  */
  48.  
  49. EXTERN relation *aRel[MAX_REL];
  50. EXTERN bool      fStarted        ASSIGN( = FALSE );
  51.  
  52. typedef struct
  53.    {
  54.    long    num;
  55.    long    left, right, parent;
  56.    char    parbal;
  57.    int     changed;
  58.    } cache;
  59.  
  60. #define _change_cache(p,f,v)   { p->changed = 1; _changeqcache(p,f,v); }
  61. #define _changeqcache(p,f,v)     p->f = v
  62. #define _cache_field(p,d) (d==1?p->right: (d==-1?p->left : p->parent))
  63.  
  64.  
  65. /*
  66.  * POSITIONING MACROS ---------------------------------------------------------
  67.  *
  68.  */
  69.  
  70. #define GO_BASE(rel,rcd,idx,off)                                          \
  71.                 lseek (rel->fhRel,                                        \
  72.                        rel->posRecZ                                       \
  73.                        + (rcd-1)*(rel->cbRecord+ (long)cbINDEX*rel->nIdx) \
  74.                        + (long)cbINDEX*idx                                \
  75.                        + off, 0)
  76.  
  77. #define GO_TOP(rel,idx)                                             \
  78.                 lseek (rel->fhRel,                                  \
  79.                        POS_INDICES + (long)4*idx,                   \
  80.                        0)
  81.  
  82. #define GO_NEXTS(rel)                                               \
  83.                 lseek (rel->fhRel,                                  \
  84.                        POS_NEXTSER,                                 \
  85.                        0)
  86.  
  87. #define GO_INDEX(rel,rcd,idx)    GO_BASE (rel, rcd,       idx,  0L)
  88. #define GO_START(rel,rcd)        GO_BASE (rel, rcd,         0,  0L)
  89. #define GO_RECID(rel,rcd)        GO_BASE (rel, rcd, rel->nIdx,  0L)
  90. #define GO_BAL(rel,rcd,idx)      GO_BASE (rel, rcd,       idx, 12L)
  91.  
  92. #define GO_POINT(rel,rcd,idx,d) \
  93.                 GO_BASE (rel, rcd, idx, (((d)==-1)?0L:((d)==1?4L:8L)) )
  94.  
  95.  
  96. /*
  97.  * DEFINITIONS ----------------------------------------------------------------
  98.  *
  99.  */
  100.  
  101. #define cbINDEX 13        /* 4,4,4,1 == Thirteen bytes make up an index */
  102.  
  103. #define PARDIR (int)0x80
  104. #define BAL    (int)0x7F
  105.  
  106. #define BAL_LT (BAL_EV - MAX_FRAG)   /* Balance == Left (first off-balance)  */
  107. #define BAL_EV '='                   /* Balance == Even (perfectly balanced) */
  108. #define BAL_RT (BAL_EV + MAX_FRAG)   /* Balance == Right (first off-balance) */
  109.  
  110. #define VAL_BAL(b)  ((int)(b-BAL_EV))
  111. #define NUM_BAL(b)  ( (b < BAL_EV) ? -1 : (bal > BAL_EV) ? 1 : 0 )
  112. #define BALANCED(b) ( (b > BAL_LT) && (b < BAL_RT) )
  113.  
  114.  
  115. #define round2(x) (x%2==0?x:(x+2-(x%2)))
  116. #define round4(x) (x%4==0?x:(x+4-(x%4)))
  117. #define round8(x) (x%8==0?x:(x+8-(x%8)))
  118.  
  119. #if 0
  120. #ifndef __LINE__
  121. #define __LINE__ 0
  122. #endif
  123. #ifndef __FILE__
  124. #define __FILE__ "unknown"
  125. #endif
  126. #endif
  127.  
  128. #define Error(e)      { SetError(e); goto lblERROR;   }
  129. #define Error_2(e)    { SetError(e); goto lblERROR_2; }
  130. #define Error_3(e)    { SetError(e); goto lblERROR_3; }
  131.  
  132. #define Assert_Rel(e)  if (!(e)) { _Corrupt (rel, FALSE); Error (MB_CORRUPT);  }
  133. #define Assert_Dat(e)  if (!(e)) { _Corrupt (rel, TRUE);  Error (MB_BAD_DATA); }
  134. #define Assert(e)      if (!(e)) \
  135.                         { _Assert (#e, __FILE__, __LINE__); Error(MB_ASSERT); }
  136.  
  137.  
  138. /*
  139.  * PROTOTYPES -----------------------------------------------------------------
  140.  *
  141.  */
  142.  
  143. /* MB_MULTI.C -------------------------------------------------------------- */
  144.  
  145.    mb_err     _fieldFill     XARGS( (relation *, dataptr, int) );
  146.    mb_err     _recMove       XARGS( (relation *, dataptr, dataptr) );
  147.    mb_err     _recWrite      XARGS( (relation *, dataptr, long) );
  148.    mb_err     _recFill       XARGS( (relation *, dataptr) );
  149.    mb_err     _remove_m      XARGS( (relation *, long) );
  150.  
  151.  
  152. /* MB_COMP.C --------------------------------------------------------------- */
  153.  
  154.    long       _fhDecompress  XARGS( (file, file) );
  155.    long       _fhCompress    XARGS( (file, file) );
  156.    long       _fhCopy        XARGS( (file, file, long) );
  157.  
  158.  
  159. /* MB_RMV.C ---------------------------------------------------------------- */
  160.  
  161.    void       _Assert        XARGS( (char *, char *, long) );
  162.    void       _Corrupt       XARGS( (relation *, bool) );
  163.  
  164.  
  165. /* MB_CACHE.C -------------------------------------------------------------- */
  166.  
  167.    cache     *_read_cache    XARGS( (relation *, long, int) );
  168.    void       _flush_cache   XARGS( (relation *, int) );
  169.    void       _free_cache    XARGS( (void) );
  170.  
  171.  
  172. /* MB_UTIL.C --------------------------------------------------------------- */
  173.  
  174.    int        _identify      XARGS( (relation *) );
  175.    int        _compare       XARGS( (relation *, dataptr, dataptr, int) );
  176.    dataptr    _memrec        XARGS( (relation *, dataptr, long) );
  177.    mb_err     _drop          XARGS( (relation *, long, int, long) );
  178.    mb_err     _check         XARGS( (relation *, long, long, int) );
  179.    void       _dislink       XARGS( (relation *, long, int, long) );
  180.    void       _replace       XARGS( (relation *, long, long, int) );
  181.    long       _find_seq      XARGS( (relation *, long, long, int, int) );
  182.    void       _crypt         XARGS( (relation *, dataptr) );
  183.    void       _cryptf        XARGS( (charptr, int, int) );
  184.    void       _serHash       XARGS( (charptr) );
  185.  
  186. #define _encrypt   _crypt     /* These defines are used for clarity; */
  187. #define _decrypt   _crypt     /* encryption/decryption routines are  */
  188. #define _encryptf  _cryptf    /* all reversable, through the same    */
  189. #define _decryptf  _cryptf    /* algorithms.                         */
  190.  
  191.  
  192. /* MB_LOCK.C --------------------------------------------------------------- */
  193.  
  194.    mb_err     _chk_elck      XARGS( (relation *, bool) );
  195.    mb_err     _set_lck       XARGS( (relation *) );
  196.    void       _clr_lck       XARGS( (relation *) );
  197.    void       _strobe        XARGS( (relation *, int) );
  198.  
  199. #endif /* INTERNAL_H */
  200.  
  201.