home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c023 / 1.img / PROGRAMS / BLDBTREE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-02  |  2.4 KB  |  110 lines

  1. /* (C) Copyright 1984,85,86,87 Walter L. Peacock   All Rights Reserved   */
  2. /*  b l d b t r e e . C   11/28/84 */
  3. /* b-tree rebuild utility.   */
  4.  
  5. #include <stdio.h>
  6. #include "cbtree.h"
  7. /* btfio.h *must* be included when bt_open() is used */
  8. #include "btfio.h"
  9. #include "patrec.str"
  10.  
  11. #define MAKEKY (*btc.btmakeky)   /* clean invocation */
  12.  
  13. #if CI | DC
  14. #else
  15. #include <ctype.h>
  16. #endif
  17.  
  18. void main(argc, argv)
  19. int argc;
  20. char *argv[];
  21. {
  22.    extern char *calloc();
  23.    extern char *strnncpy(), *bldkey();
  24.    BTC      btc;
  25.    PATREC   pr;
  26.    BTBLKHDR freespc;   /* freelist pointers in blk header */
  27.    long eofpat;
  28.    char *nam_btdat, *nam_btnme;
  29.    int fdidx, fddat, btretcd, varlen;
  30.  
  31.    wopen("CON:0/0/640/100/Bldbtree");     /* open Amiga window */
  32.  
  33.    varlen = (argc > 1 && strcmp(argv[1], "-v") == 0);
  34.    if (varlen)
  35.    {
  36.       nam_btdat = "patient.var";
  37.       nam_btnme = "btvarnme";
  38.    }
  39.    else
  40.    {
  41.       nam_btdat = "patient.dat";
  42.       nam_btnme = "btpatnme";
  43.    }
  44.  
  45.    if (btrinit(nam_btnme, &btc) == ERR)
  46.       ckerror(- CK_BTRIN, "bldbtree.c: nam_btnme");
  47.  
  48.    scr_clr();
  49.  
  50.    scr_curs(3, 18);
  51.    printf("Rebuilding B-tree Index File:");
  52.  
  53.    creatbtr(&btc);
  54.  
  55.    scr_curs(5, 25);
  56.    printf(btc.idxname);
  57.  
  58.       /* open btc.idx file   */
  59.    if((fdidx = bt_open(btc.idxname,O_RDWR)) == ERR)
  60.       ckerror(- CK_OPEN, "bldbtree: btc.idx");
  61.  
  62.       /* open data file   */
  63.    if((fddat = bt_open(nam_btdat, O_RDONLY)) == ERR)
  64.       ckerror(- CK_OPEN, "bldbtree: datname");
  65.  
  66.    memset(&pr, NUL, sizeof(PATREC));
  67.  
  68.       /*   M A I N   C O N T R O L   P R O G R A M */
  69.  
  70.    scr_curs(7, 18);
  71.    printf("Working on record number: ");
  72.  
  73.    getfhdr(&freespc, fddat);
  74.    eofpat = freespc.eoflst;
  75.  
  76.    btc.btoptype = ISRTKY;
  77.    btc.btloc = 1L;
  78.  
  79.    for(;;)
  80.    {
  81.       if (varlen)
  82.          btc.btloc = btnxtvar(fddat, btc.btloc);
  83.       else
  84.          ++btc.btloc;
  85.       if (btc.btloc >= eofpat)
  86.          break;
  87.  
  88.       scr_curs(7, 44);
  89.       printf("%ld",btc.btloc - !varlen);
  90. #if MW
  91.       fflush(stdout);   /* MW holds it in */
  92. #endif
  93.  
  94.       if (varlen)
  95.          getfpatv(&pr, fddat, &btc);   /* get record & length */
  96.       else
  97.          getfpat(&pr, fddat, btc.btloc);
  98.  
  99.       bldkey(btc.btkey, btc.btkeylen, &pr);
  100.  
  101.       if ((btretcd = cbtree(fddat, fdidx, &btc)) != BTCALLOK)
  102.          cberror(btretcd, "bldbtree", &btc);
  103.    }
  104.  
  105.    close(fdidx);
  106.    close(fddat);
  107.    wclose();
  108.    puts("");
  109. }
  110.