home *** CD-ROM | disk | FTP | other *** search
- /* (C) Copyright 1984,85,86,87 Walter L. Peacock All Rights Reserved */
- /* b l d b t r e e . C 11/28/84 */
- /* b-tree rebuild utility. */
-
- #include <stdio.h>
- #include "cbtree.h"
- /* btfio.h *must* be included when bt_open() is used */
- #include "btfio.h"
- #include "patrec.str"
-
- #define MAKEKY (*btc.btmakeky) /* clean invocation */
-
- #if CI | DC
- #else
- #include <ctype.h>
- #endif
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- extern char *calloc();
- extern char *strnncpy(), *bldkey();
- BTC btc;
- PATREC pr;
- BTBLKHDR freespc; /* freelist pointers in blk header */
- long eofpat;
- char *nam_btdat, *nam_btnme;
- int fdidx, fddat, btretcd, varlen;
-
- wopen("CON:0/0/640/100/Bldbtree"); /* open Amiga window */
-
- varlen = (argc > 1 && strcmp(argv[1], "-v") == 0);
- if (varlen)
- {
- nam_btdat = "patient.var";
- nam_btnme = "btvarnme";
- }
- else
- {
- nam_btdat = "patient.dat";
- nam_btnme = "btpatnme";
- }
-
- if (btrinit(nam_btnme, &btc) == ERR)
- ckerror(- CK_BTRIN, "bldbtree.c: nam_btnme");
-
- scr_clr();
-
- scr_curs(3, 18);
- printf("Rebuilding B-tree Index File:");
-
- creatbtr(&btc);
-
- scr_curs(5, 25);
- printf(btc.idxname);
-
- /* open btc.idx file */
- if((fdidx = bt_open(btc.idxname,O_RDWR)) == ERR)
- ckerror(- CK_OPEN, "bldbtree: btc.idx");
-
- /* open data file */
- if((fddat = bt_open(nam_btdat, O_RDONLY)) == ERR)
- ckerror(- CK_OPEN, "bldbtree: datname");
-
- memset(&pr, NUL, sizeof(PATREC));
-
- /* M A I N C O N T R O L P R O G R A M */
-
- scr_curs(7, 18);
- printf("Working on record number: ");
-
- getfhdr(&freespc, fddat);
- eofpat = freespc.eoflst;
-
- btc.btoptype = ISRTKY;
- btc.btloc = 1L;
-
- for(;;)
- {
- if (varlen)
- btc.btloc = btnxtvar(fddat, btc.btloc);
- else
- ++btc.btloc;
- if (btc.btloc >= eofpat)
- break;
-
- scr_curs(7, 44);
- printf("%ld",btc.btloc - !varlen);
- #if MW
- fflush(stdout); /* MW holds it in */
- #endif
-
- if (varlen)
- getfpatv(&pr, fddat, &btc); /* get record & length */
- else
- getfpat(&pr, fddat, btc.btloc);
-
- bldkey(btc.btkey, btc.btkeylen, &pr);
-
- if ((btretcd = cbtree(fddat, fdidx, &btc)) != BTCALLOK)
- cberror(btretcd, "bldbtree", &btc);
- }
-
- close(fdidx);
- close(fddat);
- wclose();
- puts("");
- }
-