home *** CD-ROM | disk | FTP | other *** search
- /* (C) Copyright 1984,85,86,87 Walter L. Peacock All Rights Reserved */
- /* t i m e c b 5 . C 01/31/85 */
-
- #include <stdio.h>
- #include "cbtree.h"
- /* btfio.h *must* be included when bt_open() is used */
- #include "btfio.h"
- #include "patrec.str"
-
- #undef FREE /* this needs to be here for a weird EC bug */
-
- #if AmigaDOS & LC
- #include "time.h"
- TM startime, stoptime;
- #define printf iprintf /* use fast version */
- #endif
-
- /* DEH 10/19/86 */
- #if AmigaDOS & MX
- long *DateStamp();
- long startime[3], stoptime[3];
- #endif
-
- #if CI | DC
- #else
- #include <ctype.h>
- #endif
-
- #if LC & MSDOS
- #include <dos.h>
- #if LCVER >= 300
- #define SVC_TIME 0x2c
- #endif
- #endif
-
- #if (XENIX & MS)
- #include <sys/types.h>
- #include <sys/timeb.h>
- #endif
-
- #if (MSDOS & MS) | TC
- #include <dos.h>
- #define SVC_TIME 0x2c /* get time */
- #endif
-
- #if EC
- #include <dtstr.h> /* defines time structure */
- #endif
-
- /* DEH 10/19/86 */
- #if MX & MSDOS
- struct dostime {
- int sec;
- int min;
- int hours;
- int day;
- int month;
- int year;
- int dayofwk;
- int dayofyr;
- int dstflag;
- int hunsec;
- } ;
-
- #define MONITOR 0 /* these are for monitoring purposes */
- #define MONSIZE 20000
- int _Corg();
- int _Cend();
- short monbuf[MONSIZE];
- #endif
-
- #if MW
- #undef DELETE /* prevent MW warning message */
- #include <dos.h>
- #ifdef DELETE
- #undef DELETE /* prevent MW warning message */
- #endif
- #define DELETE 6 /* for cbtree() */
- #define SVC_TIME 0x2c00 /* get time */
- #endif
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- extern long atol(), btnxtvar();
- extern void free();
- extern FILE *fopen();
- extern char *calloc();
- FILE *fdtm;
- PATREC pr;
- BTC btc;
- BTBLKHDR freespc;
- long eofpat, patloc, keycnt, keynum, avgdiff;
- int btretcd, optype, diff, varlen, fdnme, fd1;
- uint tmstrt, tmstop;
- char *nam_btnme, *nam_btdat;
- char ans[8];
-
- #if MW
- struct reg dostrt; /* Contains register values for intcall() */
- struct reg dostop; /* Contains register values for intcall() */
- dostrt.r_ax = dostop.r_ax = SVC_TIME;
- #endif
-
- #if (MS & XENIX)
- struct timeb dostrt;
- struct timeb dostop;
- #endif
-
- #if (LC & MSDOS) | (MS & MSDOS) | TC
- union REGS dostrt;
- union REGS dostop;
-
- dostrt.h.ah = dostop.h.ah = SVC_TIME;
- #endif
-
- #if EC
- struct time dostrt;
- struct time dostop;
- #endif
-
- #if CI
- #define SVC_TIME 0x2c00
- struct regs { int ax, bx, cx, dx, si, di, ds, es; } ;
- struct regs dostrt;
- struct regs dostop;
- dostrt.ax = dostop.ax = SVC_TIME;
- #endif
-
- #if DC
- #define SVC_TIME 0x2c00
- extern uint _rax, _rdx;
- _rax = SVC_TIME;
- #endif
-
- /* DEH 10/19/86 */
- #if MX & MSDOS
- struct dostime dostrt;
- struct dostime dostop;
-
- #if MONITOR /* *MUST* be first executable statment!!! */
- /* _int_sp(60); set interrupt to 60 ticks per second */
- monitor(_Corg, _Cend, monbuf, MONSIZE, 0);
- #endif
- #endif
-
- 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, "timecb5: btpatnme");
-
- /* Make new window */
- wopen("CON:0/0/640/150/Timecb5");
-
- scr_clr();
-
- scr_curs(0, 20);
- printf("TIMECB5: CBTREE Operation Timing System");
-
- optype = calltype(); /* get call type from user */
-
- printf("\n\nEnter number of keys ==> ");
- gets(ans);
- keynum = atol(ans);
- if (keynum == 0L)
- goto tim0_exit;
-
- if (optype == 0) /* NEWIDX */
- {
- optype = ISRTKY;
- creatbtr(&btc);
- }
-
- /* open btpatnme.idx file */
- if ((fdnme = bt_open(btc.idxname, O_RDWR)) == ERR)
- ckerror(- CK_OPEN, "timecb5: BTPATNME.IDX");
-
- /* open patnme.dat file */
- if((fd1 = bt_open(nam_btdat, O_RDWR)) == ERR)
- ckerror(- CK_OPEN, "timecb5: patient.dat");
-
- /* M A I N C O N T R O L P R O G R A M */
-
- memset(&pr, NUL, sizeof(PATREC));
-
- getfhdr(&freespc, fd1);
- eofpat = freespc.eoflst;
-
- scr_curs(11, 36);
- printf("count time average ");
- scr_curs(12, 8);
- printf("Last record number: %ld", eofpat-2);
-
- btc.btoptype = optype;
-
- diff = tmstrt = tmstop = 0;
- avgdiff = keycnt = 0L;
-
- while (keycnt < keynum)
- {
- patloc = btc.btloc = 1L;
-
- for(;;)
- {
- if (varlen)
- patloc = btc.btloc = btnxtvar(fd1, patloc);
- else
- btc.btloc = ++patloc;
- if (btc.btloc >= eofpat)
- break;
-
- if (varlen)
- getfpatv(&pr, fd1, &btc);
- else
- getfpat(&pr, fd1, btc.btloc);
-
- bldkey(btc.btkey, btc.btkeylen, &pr);
-
- #if MW
- intcall(&dostrt, &dostrt, DOSINT); /* DOS interrupt 0x21 */
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- intcall(&dostop, &dostop, DOSINT);
- tmstop = (dostop.r_dx>>8)*100 + (dostop.r_dx&0xff);
- tmstrt = (dostrt.r_dx>>8)*100 + (dostrt.r_dx&0xff);
- #endif
-
- #if (MS & XENIX)
- ftime(&dostrt);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- ftime(&dostop);
- tmstop = dostop.time*100 + dostop.millitm/10; /* hundredths */
- tmstrt = dostrt.time*100 + dostrt.millitm/10;
- #endif
-
- #if MSDOS & (LC | MS | TC)
- intdos(&dostrt, &dostrt);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- intdos(&dostop, &dostop);
- tmstop = dostop.h.dh*100 + dostop.h.dl; /* use hundredths */
- tmstrt = dostrt.h.dh*100 + dostrt.h.dl;
- #endif
-
- #if EC
- gettime(&dostrt);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- gettime(&dostop);
- tmstop = dostop.second*100 + dostop.hundred; /* hundredths */
- tmstrt = dostrt.second*100 + dostrt.hundred;
- #endif
-
- #if MSDOS & MX
- dostime(&dostrt);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- dostime(&dostop);
- tmstop = dostop.sec * 100 + dostop.hunsec; /* use hundredths */
- tmstrt = dostrt.sec * 100 + dostrt.hunsec;
- #endif
-
- #if CI
- sysint21(&dostrt, &dostrt);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- sysint21(&dostop, &dostop);
- tmstop = (dostop.dx>>8)*100 + (dostop.dx&0xff);
- tmstrt = (dostrt.dx>>8)*100 + (dostrt.dx&0xff);
- #endif
-
- #if DC
- _doint(0x21); /* do a dos interrupt */
- tmstrt = (_rdx>>8)*100 + (_rdx & 0xff);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- _doint(0x21);
- tmstop = (_rdx>>8)*100 + (_rdx & 0xff);
- #endif
-
- /* DEH 10/19/86 */
- #if AmigaDOS & LC
- curtime(&startime);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- curtime(&stoptime);
- tmstop = stoptime.tm_sec*100 + stoptime.tm_mil/10; /* 100ths */
- tmstrt = startime.tm_sec*100 + startime.tm_mil/10;
- #endif
-
- /* DEH 10/19/86 */
- #if AmigaDOS & MX
- DateStamp(&startime);
- if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
- cberror(btretcd, "timecb5", &btc);
- DateStamp(&stoptime);
- tmstop = (stoptime[2]/50)*100 + (stoptime[2]%50)*2; /* 100ths */
- tmstrt = (startime[2]/50)*100 + (startime[2]%50)*2;
- #endif
-
- if ((int)(diff = tmstop - tmstrt) < 0) /* adjust for wrap */
- diff += 6000; /* ticks per min */
-
- avgdiff += diff;
-
- keycnt++;
- scr_curs(12, 34);
- #if CI
- printf(" %03ld %d.%02d 0.%02ld",
- #else
- printf("%6.6ld %d.%02d 0.%02ld\n",
- #endif
- keycnt, diff/100, diff%100, avgdiff/keycnt);
- if (keycnt >= keynum)
- break;
-
- }
- }
-
- close(fdnme);
- close(fd1);
-
- if ((fdtm = fopen("cbtime.tst","a")) == NULL)
- ckerror(- CK_OPEN, "timecb5: cb2time.tst");
-
- avgdiff = ( avgdiff / keynum );
-
- fprintf(fdtm,
- "\ntype %d, idxlen %d, #cells %d, keylen %d, #keys %ld, avg time .%02ld.",
- optype, btc.btidxlen, btc.btcells, btc.btkeylen,
- keynum, avgdiff);
-
- fclose(fdtm);
-
- tim0_exit:
-
- btrterm(&btc);
- puts("");
-
- wclose(); /* close Amiga window */
-
- #if MSDOS & MX
- #if MONITOR /* *MUST* be last executable statment!!! */
- monitor(0, 0, 0, 0, 0);
- #endif
- #endif
-
- }
-