home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c023 / 1.img / PROGRAMS / TIMECB5.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-13  |  8.8 KB  |  362 lines

  1. /* (C) Copyright 1984,85,86,87 Walter L. Peacock   All Rights Reserved   */
  2. /*  t i m e c b 5 . C   01/31/85   */
  3.  
  4. #include <stdio.h>
  5. #include "cbtree.h"
  6. /* btfio.h *must* be included when bt_open() is used */
  7. #include "btfio.h"
  8. #include "patrec.str"
  9.  
  10. #undef FREE   /* this needs to be here for a weird EC bug */
  11.  
  12. #if AmigaDOS & LC
  13. #include "time.h"
  14. TM startime, stoptime;
  15. #define printf iprintf   /* use fast version */
  16. #endif
  17.  
  18. /* DEH 10/19/86 */
  19. #if AmigaDOS & MX
  20. long *DateStamp();
  21. long startime[3], stoptime[3];
  22. #endif
  23.  
  24. #if CI | DC
  25. #else
  26. #include <ctype.h>
  27. #endif
  28.  
  29. #if LC & MSDOS
  30. #include <dos.h>
  31. #if LCVER >= 300
  32. #define SVC_TIME 0x2c
  33. #endif
  34. #endif
  35.  
  36. #if (XENIX & MS)
  37. #include <sys/types.h>
  38. #include <sys/timeb.h>
  39. #endif
  40.  
  41. #if (MSDOS & MS) | TC
  42. #include <dos.h>
  43. #define SVC_TIME 0x2c      /* get time */
  44. #endif
  45.  
  46. #if EC
  47. #include <dtstr.h>   /* defines time structure */
  48. #endif
  49.  
  50. /* DEH 10/19/86 */
  51. #if MX & MSDOS
  52. struct dostime {
  53.    int sec;
  54.    int min;
  55.    int hours;
  56.    int day;
  57.    int month;
  58.    int year;
  59.    int dayofwk;
  60.    int dayofyr;
  61.    int dstflag;
  62.    int hunsec;
  63. } ;
  64.  
  65. #define MONITOR 0   /* these are for monitoring purposes */
  66. #define MONSIZE 20000
  67. int _Corg();
  68. int _Cend();
  69. short monbuf[MONSIZE];
  70. #endif
  71.  
  72. #if MW
  73. #undef DELETE             /* prevent MW warning message */
  74. #include <dos.h>
  75. #ifdef DELETE
  76. #undef DELETE             /* prevent MW warning message */
  77. #endif
  78. #define DELETE 6          /* for cbtree() */
  79. #define SVC_TIME 0x2c00   /* get time */
  80. #endif
  81.  
  82. void main(argc, argv)
  83. int   argc;
  84. char *argv[];
  85. {
  86.    extern long atol(), btnxtvar();
  87.    extern void free();
  88.    extern FILE *fopen();
  89.    extern char *calloc();
  90.    FILE  *fdtm;
  91.    PATREC pr;
  92.    BTC    btc;
  93.    BTBLKHDR freespc;
  94.    long eofpat, patloc, keycnt, keynum, avgdiff;
  95.    int btretcd, optype, diff, varlen, fdnme, fd1;
  96.    uint tmstrt, tmstop;
  97.    char *nam_btnme, *nam_btdat;
  98.    char ans[8];
  99.  
  100. #if MW
  101.    struct   reg dostrt;   /* Contains register values for intcall() */
  102.    struct   reg dostop;   /* Contains register values for intcall() */
  103.    dostrt.r_ax = dostop.r_ax = SVC_TIME;
  104. #endif
  105.  
  106. #if (MS & XENIX)
  107.    struct timeb dostrt;
  108.    struct timeb dostop;
  109. #endif
  110.  
  111. #if (LC & MSDOS) | (MS & MSDOS) | TC
  112.    union REGS dostrt;
  113.    union REGS dostop;
  114.  
  115.    dostrt.h.ah = dostop.h.ah = SVC_TIME;
  116. #endif
  117.  
  118. #if EC
  119.    struct time dostrt;
  120.    struct time dostop;
  121. #endif
  122.  
  123. #if CI
  124. #define SVC_TIME 0x2c00
  125.    struct regs { int ax, bx, cx, dx, si, di, ds, es; } ;
  126.    struct regs dostrt;
  127.    struct regs dostop;
  128.    dostrt.ax = dostop.ax = SVC_TIME;
  129. #endif
  130.  
  131. #if DC
  132. #define SVC_TIME 0x2c00
  133.    extern uint _rax, _rdx;
  134.    _rax = SVC_TIME;
  135. #endif
  136.  
  137. /* DEH 10/19/86 */
  138. #if MX & MSDOS
  139.    struct dostime dostrt;
  140.    struct dostime dostop;
  141.  
  142. #if MONITOR   /* *MUST* be first executable statment!!! */
  143. /*   _int_sp(60);   set interrupt to 60 ticks per second */
  144.    monitor(_Corg, _Cend, monbuf, MONSIZE, 0);
  145. #endif
  146. #endif
  147.  
  148.    varlen = (argc > 1 && strcmp(argv[1], "-v") == 0);
  149.  
  150.    if (varlen)
  151.    {
  152.       nam_btdat = "patient.var";
  153.       nam_btnme = "btvarnme";
  154.    }
  155.    else
  156.    {
  157.       nam_btdat = "patient.dat";
  158.       nam_btnme = "btpatnme";
  159.    }
  160.  
  161.    if( (btrinit(nam_btnme, &btc) ) == ERR)
  162.       ckerror(- CK_BTRIN, "timecb5: btpatnme");
  163.  
  164.    /* Make new window */
  165.    wopen("CON:0/0/640/150/Timecb5");
  166.  
  167.    scr_clr();
  168.  
  169.    scr_curs(0, 20);
  170.    printf("TIMECB5: CBTREE Operation Timing System");
  171.  
  172.    optype = calltype();   /* get call type from user */
  173.  
  174.    printf("\n\nEnter number of keys ==> ");
  175.    gets(ans);
  176.    keynum = atol(ans);
  177.    if (keynum == 0L)
  178.       goto tim0_exit;
  179.  
  180.    if (optype == 0)   /* NEWIDX */
  181.    {
  182.       optype = ISRTKY;
  183.       creatbtr(&btc);
  184.    }
  185.  
  186.    /* open btpatnme.idx file   */
  187.    if ((fdnme = bt_open(btc.idxname, O_RDWR)) == ERR)
  188.       ckerror(- CK_OPEN, "timecb5: BTPATNME.IDX");
  189.  
  190.    /* open patnme.dat file   */
  191.    if((fd1 = bt_open(nam_btdat, O_RDWR)) == ERR)
  192.       ckerror(- CK_OPEN, "timecb5: patient.dat");
  193.  
  194.       /*   M A I N   C O N T R O L   P R O G R A M */
  195.  
  196.    memset(&pr, NUL, sizeof(PATREC));
  197.  
  198.    getfhdr(&freespc, fd1);
  199.    eofpat = freespc.eoflst;
  200.  
  201.    scr_curs(11, 36);
  202.    printf("count   time   average ");
  203.    scr_curs(12, 8);
  204.    printf("Last record number: %ld", eofpat-2);
  205.  
  206.    btc.btoptype = optype;
  207.  
  208.    diff = tmstrt = tmstop = 0;
  209.    avgdiff = keycnt = 0L;
  210.  
  211.    while (keycnt < keynum)
  212.    {
  213.       patloc = btc.btloc = 1L;
  214.  
  215.       for(;;)
  216.       {
  217.          if (varlen)
  218.             patloc = btc.btloc = btnxtvar(fd1, patloc);
  219.          else
  220.             btc.btloc = ++patloc;
  221.          if (btc.btloc >= eofpat)
  222.             break;
  223.  
  224.          if (varlen)
  225.             getfpatv(&pr, fd1, &btc);
  226.          else
  227.             getfpat(&pr, fd1, btc.btloc);
  228.  
  229.          bldkey(btc.btkey, btc.btkeylen, &pr);
  230.  
  231. #if MW
  232.          intcall(&dostrt, &dostrt, DOSINT);      /* DOS interrupt 0x21 */
  233.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  234.             cberror(btretcd, "timecb5", &btc);
  235.          intcall(&dostop, &dostop, DOSINT);
  236.          tmstop = (dostop.r_dx>>8)*100 + (dostop.r_dx&0xff);
  237.          tmstrt = (dostrt.r_dx>>8)*100 + (dostrt.r_dx&0xff);
  238. #endif
  239.  
  240. #if (MS & XENIX)
  241.          ftime(&dostrt);
  242.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  243.             cberror(btretcd, "timecb5", &btc);
  244.          ftime(&dostop);
  245.          tmstop = dostop.time*100 + dostop.millitm/10;   /* hundredths */
  246.          tmstrt = dostrt.time*100 + dostrt.millitm/10;
  247. #endif
  248.  
  249. #if MSDOS & (LC | MS | TC)
  250.          intdos(&dostrt, &dostrt);
  251.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  252.             cberror(btretcd, "timecb5", &btc);
  253.          intdos(&dostop, &dostop);
  254.          tmstop = dostop.h.dh*100 + dostop.h.dl;   /* use hundredths */
  255.          tmstrt = dostrt.h.dh*100 + dostrt.h.dl;
  256. #endif
  257.  
  258. #if EC
  259.          gettime(&dostrt);
  260.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  261.             cberror(btretcd, "timecb5", &btc);
  262.          gettime(&dostop);
  263.          tmstop = dostop.second*100 + dostop.hundred;   /* hundredths */
  264.          tmstrt = dostrt.second*100 + dostrt.hundred;
  265. #endif
  266.  
  267. #if MSDOS & MX
  268.          dostime(&dostrt);
  269.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  270.             cberror(btretcd, "timecb5", &btc);
  271.          dostime(&dostop);
  272.          tmstop = dostop.sec * 100 + dostop.hunsec;   /* use hundredths */
  273.          tmstrt = dostrt.sec * 100 + dostrt.hunsec;
  274. #endif
  275.  
  276. #if CI
  277.          sysint21(&dostrt, &dostrt);
  278.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  279.             cberror(btretcd, "timecb5", &btc);
  280.          sysint21(&dostop, &dostop);
  281.          tmstop = (dostop.dx>>8)*100 + (dostop.dx&0xff);
  282.          tmstrt = (dostrt.dx>>8)*100 + (dostrt.dx&0xff);
  283. #endif
  284.  
  285. #if DC
  286.          _doint(0x21);   /* do a dos interrupt */
  287.          tmstrt = (_rdx>>8)*100 + (_rdx & 0xff);
  288.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  289.             cberror(btretcd, "timecb5", &btc);
  290.          _doint(0x21);
  291.          tmstop = (_rdx>>8)*100 + (_rdx & 0xff);
  292. #endif
  293.  
  294. /* DEH 10/19/86 */
  295. #if AmigaDOS & LC
  296.          curtime(&startime);
  297.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  298.             cberror(btretcd, "timecb5", &btc);
  299.          curtime(&stoptime);
  300.          tmstop = stoptime.tm_sec*100 + stoptime.tm_mil/10; /* 100ths */
  301.          tmstrt = startime.tm_sec*100 + startime.tm_mil/10;
  302. #endif
  303.  
  304. /* DEH 10/19/86 */
  305. #if AmigaDOS & MX
  306.          DateStamp(&startime);
  307.          if ((btretcd = cbtree(fd1, fdnme, &btc)) != BTCALLOK)
  308.             cberror(btretcd, "timecb5", &btc);
  309.          DateStamp(&stoptime);
  310.          tmstop = (stoptime[2]/50)*100 + (stoptime[2]%50)*2; /* 100ths */
  311.          tmstrt = (startime[2]/50)*100 + (startime[2]%50)*2;
  312. #endif
  313.  
  314.          if ((int)(diff = tmstop - tmstrt) < 0) /* adjust for wrap */
  315.             diff += 6000;                          /* ticks per min */
  316.  
  317.          avgdiff += diff;
  318.  
  319.          keycnt++;
  320.          scr_curs(12, 34);
  321. #if CI
  322.          printf("   %03ld    %d.%02d     0.%02ld",
  323. #else
  324.          printf("%6.6ld    %d.%02d     0.%02ld\n",
  325. #endif
  326.             keycnt, diff/100, diff%100, avgdiff/keycnt);
  327.          if (keycnt >= keynum)
  328.             break;
  329.  
  330.       }
  331.    }
  332.  
  333.    close(fdnme);
  334.    close(fd1);
  335.  
  336.    if ((fdtm = fopen("cbtime.tst","a")) == NULL)
  337.       ckerror(- CK_OPEN, "timecb5: cb2time.tst");
  338.  
  339.    avgdiff = ( avgdiff / keynum );
  340.  
  341.    fprintf(fdtm,
  342.       "\ntype %d, idxlen %d, #cells %d, keylen %d, #keys %ld, avg time .%02ld.",
  343.       optype, btc.btidxlen, btc.btcells, btc.btkeylen,
  344.       keynum, avgdiff);
  345.  
  346.    fclose(fdtm);
  347.  
  348. tim0_exit:
  349.  
  350.    btrterm(&btc);
  351.    puts("");
  352.  
  353.    wclose();   /* close Amiga window */
  354.  
  355. #if MSDOS & MX
  356. #if MONITOR   /* *MUST* be last executable statment!!! */
  357.    monitor(0, 0, 0, 0, 0);
  358. #endif
  359. #endif
  360.  
  361. }
  362.