home *** CD-ROM | disk | FTP | other *** search
- /* (C) Copyright 1984,85,86,87 Walter L. Peacock All Rights Reserved */
-
- /* THIS PROGRAM BELONGS TO WALTER L. PEACOCK. IT IS CONSIDERED A TRADE */
- /* SECRET AND IS NOT TO BE DIVULGED OR USED BY PARTIES WHO HAVE NOT */
- /* RECEIVED WRITTEN AUTHORIZATION FROM THE OWNER. */
-
- /* 01/30/85 C B T R S E Q . C Process B+tree sequentially. */
-
- #include <stdio.h>
- #include "cbtree.h"
- /* btfio.h *must* be included when bt_open() is used */
- #include "btfio.h"
- #include "patrec.str"
-
- #if AmigaDOS & LC
- #define printf iprintf
- #endif
-
- #define MAXLINES 21
-
- #if CI | DC
- #else
- #include <ctype.h>
- #endif
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- extern long getroot();
- extern char *calloc();
- extern void free();
- BTC btcommo;
- BTIDXBLK *idxblk;
- PATREC pr;
- long moreidx, rootptr;
- int fdpat, fdnme, varlen;
- char *nam_btdat, *nam_btnme;
- char dummy[14];
- register int j, m;
-
- wopen("CON:0/0/640/200/Cbtrseq");
-
- 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, &btcommo) == ERR)
- ckerror(- CK_BTRIN, "cbtrseq.c");
-
- /* open .idx file */
- if( (fdnme = bt_open(btcommo.idxname, O_RDWR) ) == ERR)
- ckerror(- CK_OPEN, "cbtrseq: btpatnme");
-
- /* open patient.dat file */
- if( (fdpat = bt_open(nam_btdat, O_RDWR) ) == ERR)
- ckerror(- CK_OPEN, "cbtrseq: patient.dat");
-
- /* CLIMB DOWN THE TREE TO THE LEAF NODE */
-
- /* make buffer for index node */
- if( !(idxblk = (BTIDXBLK *)calloc(
- sizeof(BTIDXBLK) + btcommo.btcells * SZBTIDX, SZCHAR) ))
- ckerror(- CK_NOMEM, "cbtrseq: idxblk");
-
- idxblk->blkalloc = 0;
-
- /* read up the root node into the buffer */
- rootptr = getroot(fdnme, btcommo.findroot); /* get ptr to idx root node */
-
- getidxr(fdnme, rootptr, idxblk, btcommo.btidxlen, btcommo.btkeylen);
-
- /* keep reading the first child node until we hit a LEAF node */
- while(idxblk->blktype == 0) /* until data block type = 1 located */
- getidxr(fdnme, idxblk->btpage[0].btptr, idxblk, btcommo.btidxlen,
- btcommo.btkeylen);
-
- scr_clr();
-
- j = 0;
- moreidx = 1;
-
- /* traverse the BOTTOM level of the tree SIDEWAYS and pick up all */
- /* record locations in order */
- while(moreidx){
-
- /* first do all the cells in the current node */
- for(m = 0; m < idxblk->cellicnt; m++){
-
- if (idxblk->btpage[m].btptr == 0L)
- break;
-
- if (varlen)
- {
- btcommo.btloc = idxblk->btpage[m].btptr;
- getfpatv(&pr, fdpat, &btcommo);
- }
- else
- getfpat(&pr, fdpat, (long) idxblk->btpage[m].btptr);
-
- /* process records retrieved */
- scr_curs(j, 1);
- printf("%s, %s %s",pr.lname, pr.fname, pr.minit);
- scr_curs(j, 27);
- printf("%-9.9s %-12.12s %-.30s", pr.ssn, pr.hphone, pr.addr);
-
- if(++j > MAXLINES)
- {
- printf("\nPress <CR> to continue...");
- gets(dummy);
- scr_clr();
- j = 0;
- }
- }
-
- /* then move sideways to the next node if there is one */
- if (idxblk->fwdpage > 1)
- {
- /* read the brother node */
- getidxr(fdnme, idxblk->fwdpage, idxblk, btcommo.btidxlen, btcommo.btkeylen);
- if(idxblk->fwdpage < 1)
- idxblk->cellicnt--; /* don't print null cell */
- }
- else
- moreidx = 0;
- }
-
- freekeys(idxblk);
- FREE(idxblk);
-
- close(fdnme);
- close(fdpat);
-
- btrterm(&btcommo);
- wclose(); /* close Amiga window */
- }
-