home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / gbench / part01 / exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-12  |  6.6 KB  |  282 lines

  1. #include <gbench.h>
  2.  
  3. void Start(sp,cp)
  4.     State*  sp;
  5.     Cmd*    cp;
  6. {
  7.     int i;
  8.     int    style;
  9.  
  10.     cp->colorfg = _WhitePixel;
  11.     cp->colorbg = _BlackPixel;
  12.     if (cp->p.maxshift>0) cp->dx = cp->dy = 1;
  13.     else cp->dx = cp->dy = 0;
  14.     cp->gc = sp->gc1;
  15.     cp->shift = 0;
  16.     cp->w = sp->w1;
  17.     sp->dest1 = sp->w1;
  18.     sp->src1 = sp->w1;
  19. #   ifdef X11
  20.     if (cp->o.offdest||cp->o.offsrc) {
  21.         if (!sp->offpix) {
  22.         cp->o.offdest = cp->o.offsrc = false;
  23.         cp->result = NoOffscreenMem;
  24.         }
  25.         else {
  26.         if (cp->o.offdest) sp->dest1 = sp->offpix;
  27.         if (cp->o.offsrc) sp->src1 = sp->offpix;
  28.         XFillRectangle(
  29.             sp->d,sp->offpix,DefaultGC(sp->d,DefaultScreen(sp->d)),0,0,
  30.             sp->winsize,sp->winsize
  31.         );
  32.         }
  33.     }
  34. #   endif X11
  35.     cp->dest = sp->dest1;
  36.     cp->src = sp->src1;
  37.     fprintf(Out(sp,cp),"%s",OpNames[(int)cp->index][0]);
  38.     for (i=0;(i<MaxPositional)&&OpNames[(int)cp->index][1+i];i++) {
  39.     PrintParam(Out(sp,cp),&cp->p,"  ",OpNames[(int)cp->index][1+i],"");
  40.     }
  41.     PrintParam(Out(sp,cp),&cp->p,"  ","count","\n");
  42.     fflush(Out(sp,cp));
  43.     if (cp->o.altwin&&!sp->altwin) {
  44.     MapWin(sp,sp->w2);
  45.     sp->altwin = true;
  46.     }
  47.     else if (sp->altwin&&!cp->o.altwin) {
  48.     UnmapWin(sp,sp->w2);
  49.     sp->altwin = false;
  50.     }
  51.     if (cp->o.overlap) {
  52.     XMapWindow(DARGC sp->cw1);
  53.     if (cp->o.altwin) XMapWindow(DARGC sp->cw2);
  54.     }
  55.     XClearWindow(DARGC sp->w1);
  56.     XClearWindow(DARGC sp->w2);
  57.     XRaiseWindow(DARGC sp->w1);
  58.     if (cp->o.altwin) XRaiseWindow(DARGC sp->w2);
  59.     XSelectInput(DARGC sp->w1,InputMask(cp));
  60.     if (cp->o.altwin) XSelectInput(DARGC sp->w2,InputMask(cp));
  61. #   ifdef X11
  62.     XSetBackground(sp->d,sp->gc1,cp->colorbg);
  63.     XSetForeground(sp->d,sp->gc1,cp->colorfg);
  64.     XSetFunction(sp->d,sp->gc1,cp->func);
  65.     XSetFunction(sp->d,sp->gc2,cp->func);
  66.     if (cp->o.stipple&&cp->o.tile) style = FillOpaqueStippled;
  67.     else if (cp->o.stipple) style = FillStippled;
  68.     else if (cp->o.tile) style = FillTiled;
  69.     else style = FillSolid;
  70.     XSetFillStyle(sp->d,sp->gc1,style);
  71.     XSetFillStyle(sp->d,sp->gc2,style);
  72.     if (cp->o.stipple) style = LineOnOffDash;
  73.     else if (cp->o.tile) style = LineDoubleDash;
  74.     else style = LineSolid;
  75.     XSetLineAttributes(sp->d,sp->gc1,cp->p.lwidth,style,CapButt,JoinMiter);
  76.     XSetLineAttributes(sp->d,sp->gc2,cp->p.lwidth,style,CapButt,JoinMiter);
  77. #   endif X11
  78.     XSync(DARGC 1);
  79.     if (cp->o.profile) ProfControl(1);
  80. }
  81.  
  82. void StartIteration(sp,cp)
  83.     State*  sp;
  84.     Cmd*    cp;
  85. {
  86.     Pixel colortemp;
  87.  
  88.     if (!cp->o.drag) {
  89.     cp->shift += cp->dx;
  90.     if ((cp->shift<0)||(cp->shift>cp->p.maxshift)) {
  91.         cp->dx = -cp->dx;
  92.         cp->dy = -cp->dy;
  93.         cp->shift += 2*cp->dx;
  94.     }
  95.     cp->x += cp->dx;
  96.     cp->y += cp->dy;
  97.     }
  98.     if (cp->o.altcolor) {
  99.     colortemp = cp->colorbg;
  100.     cp->colorbg = cp->colorfg;
  101.     cp->colorfg = colortemp;
  102. #    ifdef X11
  103.         XSetBackground(sp->d,sp->gc1,cp->colorbg);
  104.         XSetForeground(sp->d,sp->gc1,cp->colorfg);
  105. #    endif X11
  106.     }
  107.     if ((cp->o.altgc)&&(cp->gc==sp->gc1)) cp->gc = sp->gc2;
  108.     else cp->gc = sp->gc1;
  109.     if ((cp->o.altwin)&&(cp->w==sp->w1)) {
  110.     cp->dest = sp->dest2;
  111.     cp->src = sp->src2;
  112.     cp->w = sp->w2;
  113.     }
  114.     else {
  115.     cp->dest = sp->dest1;
  116.     cp->src = sp->src1;
  117.     cp->w = sp->w1;
  118.     }
  119.     if (cp->o.unbatched) XFlush(DARG);
  120. }
  121.  
  122. void Erase(sp,cp)
  123.     State*  sp;
  124.     Cmd*    cp;
  125. {
  126.     int x = cp->x;
  127.     int y = cp->y;
  128.     int bbx = cp->bbx;
  129.     int bby = cp->bby;
  130.  
  131.     if (cp->bbx<0) {
  132.     x += cp->bbx;
  133.     bbx = -bbx;
  134.     }
  135.     if (cp->bby<0) {
  136.     y += cp->bby;
  137.     bby = -bby;
  138.     }
  139. #   ifdef X10
  140.     XPixFill(cp->w,x,y,bbx,bby,_BlackPixel,0,GXcopy,AllPlanes);
  141. #   else
  142.     XFillRectangle(
  143.         sp->d,cp->dest,DefaultGC(sp->d,DefaultScreen(sp->d)),x,y,bbx,bby
  144.     );
  145. #   endif
  146. }
  147.  
  148. void Finish(sp,cp)
  149.     State*  sp;
  150.     Cmd*    cp;
  151. {
  152.     int        i;
  153.  
  154.     if (cp->o.profile) ProfControl(0);
  155.     if (cp->o.overlap) {
  156.     XUnmapWindow(DARGC sp->cw1);
  157.     if (cp->o.altwin) XUnmapWindow(DARGC sp->cw2);
  158.     }
  159. #   ifdef X11
  160.     if (cp->o.offdest) {
  161.         XCopyArea(
  162.         sp->d,sp->offpix,sp->w1,sp->gc1,0,0,sp->winsize,sp->winsize,0,0
  163.         );
  164.     }
  165. #   endif X11
  166.     XSync(DARGC 0);
  167.     fprintf(Out(sp,cp),"# ");
  168.     if (cp->result!=Succeeded) {
  169.     fprintf(Out(sp,cp),"result=%s",ResultMsgs[(int)cp->result]);
  170.     }
  171.     else {
  172.     fprintf(
  173.         Out(sp,cp),"hload=%.1f  time=%.3fmsec  rate=%.1f/sec",GetLoad(),
  174.         cp->time*1000/cp->iterations,cp->iterations/cp->time
  175.     );
  176.     }
  177.     if (strlen(cp->p.tag)) fprintf(Out(sp,cp),"  tag=%s  ",cp->p.tag);
  178.     putc('\n',Out(sp,cp));
  179.     putc('\n',stderr);
  180.     fflush(Out(sp,cp));
  181.     fflush(stderr);
  182.     if (strcmp(sp->fonts,sp->defaults.fonts)) SetFonts(sp,&sp->defaults);
  183.     if (strcmp(sp->outfile,sp->defaults.outfile)) SetOutfile(sp,&sp->defaults);
  184.     if (sp->winsize!=sp->defaults.winsize) SetWinsize(sp,&sp->defaults);
  185. }
  186.  
  187. void ExecDrag(sp,cp)
  188.     State*  sp;
  189.     Cmd*    cp;
  190. {
  191.     XEvent        e;
  192.     int            i;
  193.     XMotionEvent*   mep;
  194.     double        t1;
  195.     Window        qw;
  196.  
  197. #   ifdef X10
  198.     mep = (XMotionEvent*)&e;
  199. #   else
  200.     mep = &e.xmotion;
  201. #   endif
  202.     cp->iterations = 0;
  203.     cp->o.altwin = false;
  204.     XClearWindow(DARGC sp->w1);
  205.     (*Ops[(int)cp->index][(int)StartOp])(sp,cp);
  206.     Help(
  207.     stderr,
  208.     "    Drag test: move cursor in window while pressing a mouse button"
  209.     );
  210.     fflush(stderr);
  211.     XDefineCursor(DARGC cp->w,sp->cursor);
  212.     do XNextEvent(DARGC &e); while (e.type!=ButtonPress);
  213.     t1 = GetTime(sp);
  214.     while (e.type!=ButtonRelease) {
  215.     XSync(DARGC false);
  216.     if (cp->o.poll) {
  217.         if (!XCheckMaskEvent(DARGC ButtonReleaseMask,&e)) {
  218.         e.type = MotionNotify;
  219. #        ifdef X10
  220.             XQueryMouse(cp->w,&mep->x,&mep->y,&qw);
  221. #        else
  222.             XQueryPointer(
  223.             sp->d,cp->w,&qw,&qw,&i,&i,&mep->x,&mep->y,&i
  224.             );
  225. #        endif
  226.         }
  227.     }
  228.     else do {
  229.         XNextEvent(DARGC &e);
  230.     } while (QLength(DARG) && (e.type==MotionNotify));
  231.     (*Ops[(int)cp->index][(int)EraseOp])(sp,cp);
  232.     cp->dx = mep->x-cp->x;
  233.     cp->dy = mep->y-cp->y;
  234.     cp->x = mep->x;
  235.     cp->y = mep->y;
  236.     (*Ops[(int)cp->index][(int)DoOp])(sp,cp);
  237.     cp->iterations++;
  238.     }
  239.     cp->time = GetTime(sp)-t1;
  240.     XUndefineCursor(DARGC cp->w);
  241.     (*Ops[(int)cp->index][(int)FinishOp])(sp,cp);
  242.     XFlush(DARG);
  243. }
  244.  
  245. void ExecOp(sp,cp)
  246.     State*  sp;
  247.     Cmd*    cp;
  248. {
  249.     
  250.     bool    done;
  251.     int        i;
  252.     double  t1;
  253.  
  254.     (*Ops[(int)cp->index][(int)StartOp])(sp,cp);
  255.     cp->iterations = 1;
  256.     done = (bool)(cp->result!=Succeeded);
  257.     while (!done) {
  258.     t1 = GetTime(sp);
  259.     for (i=0;i<cp->iterations;i++) {
  260.         (*Ops[(int)cp->index][(int)DoOp])(sp,cp);
  261.     }
  262.     cp->time = GetTime(sp)-t1;
  263.     if (((int)cp->time)>=cp->p.timegoal) done = true;
  264.     else {
  265.         cp->iterations =
  266.         (int)(cp->iterations*cp->p.timegoal/(cp->time+.0001))+1;
  267.     }
  268.     }
  269.     (*Ops[(int)cp->index][(int)FinishOp])(sp,cp);
  270. }
  271.  
  272. void ExecCmds(sp)
  273.     State* sp;
  274. {
  275.     Cmd    c;
  276.  
  277.     while (GetCmd(sp,&c)) {
  278.     if (c.o.drag) ExecDrag(sp,&c);
  279.     else ExecOp(sp,&c);
  280.     }
  281. }
  282.