home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c006 / 1.ddi / UPDILVL.C / CBTREE / LIBRARY / UPDILVL.C
Encoding:
C/C++ Source or Header  |  1987-11-04  |  2.0 KB  |  64 lines

  1. /* (C) Copyright 1984,85,86,87 Walter L. Peacock   All Rights Reserved    */
  2. /* u p d i l v l . c  9/19/87                     */
  3. /* THIS PROGRAM BELONGS TO WALTER L. PEACOCK.  IT IS CONSIDERED A TRADE */
  4. /* SECRET AND IS NOT TO BE DIVULGED OR USED BY PARTIES WHO HAVE NOT    */
  5. /* RECEIVED WRITTEN AUTHORIZATION FROM THE OWNER.          */
  6. /*---------------------------------------------------------------------------- 
  7.  * updilvl() will update the upper level index node when the END KEY
  8.  * of a lower level node is deleted.  The new end key is copied into the 
  9.  * upper level index node and repeated as needed for each upper level.
  10.  *---------------------------------------------------------------------------*/
  11.  
  12. #include "cbtree.h"
  13.  
  14. int updilvl(fdidx, node, keystr, btparmst)
  15. int fdidx;
  16. long node;     /* original node */
  17. char *keystr;  /* that node's end key */
  18. struct btcommo *btparmst;
  19. {
  20.    extern long poptop();
  21.    extern char *calloc();
  22.    extern int strcmp();
  23.    extern void free();
  24.    extern int sp;
  25.    static BTIDXBLK *lvlblk;
  26.    long int lvlnode;
  27.    int savsp;
  28.    register int i;
  29.  
  30.    /* allocate space for the parent node */
  31.    i = sizeof(BTIDXBLK) + btparmst->btcells * sizeof(BTIDX);
  32.    if( !(lvlblk = (BTIDXBLK *) calloc(i, SZCHAR) ))
  33.       ckerror(- CK_NOMEM, "99");
  34.  
  35.    savsp = sp;     /* save the stack pointer */
  36.  
  37.    while( (lvlnode = poptop() ) != 0L){
  38.       getidxr(fdidx, lvlnode, lvlblk, btparmst->btidxlen, btparmst->btkeylen);
  39.       i = 0;
  40.       
  41.       while (lvlblk->btpage[i++].btptr != node){   /* loc lower node ptr */
  42.          if(i >= lvlblk->cellicnt)
  43.             ckerror(- CK_INDX, "100");
  44.       }
  45.       i--;
  46.  
  47.       strcpy(lvlblk->btpage[i].skeynme, keystr);
  48.       putidxr(fdidx, lvlnode, lvlblk, btparmst);
  49.  
  50.       if (i < lvlblk->cellicnt -1)   /* then not an end point */
  51.          break;
  52.  
  53.       node = lvlnode;   /* continue back up the tree */
  54.    }
  55.  
  56.    freekeys(lvlblk);
  57.    FREE(lvlblk);
  58.    
  59.    sp = savsp;     /* restore the stack */
  60.  
  61.    return(BTCALLOK);
  62. }
  63.  
  64.