home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 1.ddi / CTUPDT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  3.7 KB  |  191 lines

  1. /*
  2.  *    update support routines (used in ctaddk & ctdelk)
  3.  *
  4.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  5.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  6.  *    transfer of this program is strictly prohibited.
  7.  *
  8.  *      Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 FairCom Corporation
  9.  *    (Subject to limited distribution and
  10.  *     restricted disclosure only.)
  11.  *    *** ALL RIGHTS RESERVED ***
  12.  *
  13.  *    4006 West Broadway
  14.  *    Columbia, MO 65203
  15.  *
  16.  *
  17.  *    c-tree(R)    Version 4.3
  18.  *            Release C
  19.  *            February 7, 1989 17:30
  20.  *
  21.  */
  22.  
  23. #include "ctstdr.h"        /* standard i/o header         */
  24. #include "ctoptn.h"        /* c-tree configuration options */
  25. #include "cterrc.h"        /* c-tree error codes        */
  26. #include "ctstrc.h"        /* c-tree data structures    */
  27. #include "ctgvar.h"        /* c-tree global variables    */
  28.  
  29. /*
  30.  * To disable the index entry count as described in Section 6.2,
  31.  * add the following #define to the CTOPTN.H module:
  32.  *
  33.  *    #define NO_IDXENT
  34.  *
  35.  */
  36.  
  37.  
  38. #ifdef FPUTFGET
  39.     COUNT LOCK(),UNLOCK();
  40. #endif
  41.  
  42. /* --------------------------------------------------------------------
  43.    hdrupd updates index header information, either on disk or in memory
  44. */
  45.  
  46. COUNT hdrupd(knum,chgnum)
  47.  
  48. KEYFILE *knum;
  49. POINTER chgnum;
  50.  
  51. {
  52. #ifndef NO_IDXENT
  53.     COUNT redhdr(),wrthdr();
  54.  
  55. #ifdef FPUTFGET
  56.     if (LOCK(NODEZERO,knum) || redhdr(knum - knum->kmem))
  57.         return(uerr_cod);
  58. #endif
  59.  
  60.     knum->nument += chgnum;
  61.  
  62. #ifdef NOTFORCE
  63.     /* no action */
  64. #else
  65.     if (wrthdr(knum))
  66.         return(uerr_cod);
  67. #endif
  68.  
  69. #ifdef FPUTFGET
  70.     if (UNLOCK(NODEZERO,knum))
  71.         return(uerr_cod);
  72. #endif
  73. #endif
  74.     return(NO_ERROR);
  75. }
  76.  
  77.     
  78. /* --------------------------------------------------------------------
  79.    routine to update node size and note that node has been updated
  80.  */
  81.  
  82. COUNT putnod(buf,nodsiz)
  83.  
  84. PFAST TREEBUFF *buf;
  85. PFAST COUNT     nodsiz;
  86.  
  87. {
  88.     VOID  inracs();
  89.     COUNT wrtnod();
  90.  
  91.     if (nodsiz < 0)
  92.         terr(216);
  93.     inracs(buf);
  94.     buf->update = 'y';
  95.     buf->nkv = nodsiz;
  96.  
  97. #ifdef NOTFORCE
  98.     /* no action */
  99. #else
  100.     if (wrtnod(buf))
  101.         return(uerr_cod);
  102. #endif
  103.  
  104.     return(NO_ERROR);
  105. }
  106.  
  107.  
  108. /* ---------------------------------------------------------------------
  109.    setup duplicate ct_key entry for ADDKEY & DELKEY
  110.  */
  111.  
  112. VOID prpdup(ip,knum,pntrp)
  113.  
  114. TEXT *ip;
  115. KEYFILE *knum;
  116. POINTER *pntrp;
  117.  
  118. {
  119.     FAST COUNT kl;
  120.     FAST TEXT *suffix,*tp;
  121.  
  122.     suffix = ip + knum->length - sizeof(POINTER);
  123.     tp = (TEXT *) pntrp;
  124.  
  125. #ifdef LOW_HIGH
  126.     tp += sizeof(POINTER);
  127.     for (kl = 0; kl < sizeof(POINTER); kl++)
  128.         *suffix++ = *--tp;
  129. #else
  130.     for (kl = 0; kl < sizeof(POINTER); kl++)
  131.         *suffix++ = *tp++;
  132. #endif
  133.  
  134. }
  135.  
  136. /* --------------------------------------------------------------------
  137.    move right with left-to-right locking
  138. */
  139.  
  140. TREEBUFF *movrgt(idxval,knum,buffer)
  141.  
  142. TEXT *idxval; /* pointer to target key value */
  143. PFAST KEYFILE *knum; /* key number pointer */
  144. PFAST TREEBUFF *buffer; /* pointer to buffer containing leaf node */
  145.  
  146. {
  147.     LOCAL LONG    node;
  148.  
  149.     COUNT nodser();
  150.     TREEBUFF *getnod();
  151.                         /* NOTE: nodser sets ct_elm */
  152.     while (buffer != NULL && nodser(buffer,idxval,'L') == -1) {
  153.         if (LOCK((node = buffer->sucesr),knum))
  154.             return(NULL);
  155.         if (UNLOCK(buffer->nodeid,knum))
  156.             return(NULL);
  157.         buffer = getnod(node,knum);
  158.     }
  159.     return(buffer);
  160. }
  161.  
  162. /* shift right */
  163.  
  164. VOID shfrgt(n,bp,strbyt)
  165. PFAST COUNT n;
  166. TREEBUFF     *bp;
  167. UCOUNT           strbyt;
  168. {
  169.     FAST TEXT *dp,*sp;
  170.  
  171.     sp = bp->ct_kyval + bp->nkb - 1;
  172.     dp = sp + n;
  173.     for (n = bp->nkb - strbyt; n-- > 0; ) /* strbyt org at 0, nkb org 1 */
  174.         *dp-- = *sp--;    
  175. }
  176.  
  177. /* shift left */
  178.  
  179. VOID shflft(n,bp,strbyt)
  180. PFAST COUNT n;
  181. TREEBUFF     *bp;
  182. UCOUNT           strbyt;
  183. {
  184.     FAST TEXT *sp;
  185.  
  186.     sp = bp->ct_kyval + strbyt;
  187.     cpybuf(sp - n,sp,bp->nkb - strbyt);
  188. }
  189.  
  190. /* end of ctupdt.c */
  191.