home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xtrapv33.zip / clients / xtrap / xtrapstats.c < prev   
C/C++ Source or Header  |  1992-09-14  |  4KB  |  125 lines

  1. /*****************************************************************************
  2. Copyright 1987, 1988, 1989, 1990, 1991, 1992 by Digital Equipment Corp., 
  3. Maynard, MA
  4.  
  5. Permission to use, copy, modify, and distribute this software and its 
  6. documentation for any purpose and without fee is hereby granted, 
  7. provided that the above copyright notice appear in all copies and that
  8. both that copyright notice and this permission notice appear in 
  9. supporting documentation, and that the name of Digital not be
  10. used in advertising or publicity pertaining to distribution of the
  11. software without specific, written prior permission.  
  12.  
  13. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  14. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  15. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  16. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  17. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  18. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  19. SOFTWARE.
  20.  
  21. *****************************************************************************/
  22. /*
  23.  *
  24.  *  CONTRIBUTORS:
  25.  *
  26.  *      Dick Annicchiarico
  27.  *      Robert Chesler
  28.  *      Dan Coutu
  29.  *      Gene Durso
  30.  *      Marc Evans
  31.  *      Alan Jamison
  32.  *      Mark Henry
  33.  *      Ken Miller
  34.  *
  35.  */
  36. #include <stdio.h>
  37. #include "Xlib.h"
  38. #include "xtraplib.h"
  39. #include "xtraplibp.h"
  40. #ifdef sun
  41. #include <ctype.h>
  42. #endif
  43.  
  44. #ifdef FUNCTION_PROTOS
  45. main(int argc, char *argv[])
  46. #else
  47. main(argc,argv)
  48.     int argc;
  49.     char *argv[];
  50. #endif
  51. {
  52.     XETrapGetAvailRep     ret_avail;
  53.     XETrapGetStatsRep     ret_stats;
  54.     Widget  appW;
  55.     XtAppContext app;
  56.     char *tmp = NULL;
  57.     XETC    *tc;
  58.     Display *dpy;
  59.     Bool done;
  60.     char    buffer[10];
  61.     ReqFlags   requests;
  62.     EventFlags events;
  63.     int i;
  64.  
  65.     /* Connect to Server */
  66.     appW = XtAppInitialize(&app,"XTrap",NULL,(Cardinal)0L,
  67.         (Cardinal *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
  68.         (Cardinal)NULL);
  69.     dpy = XtDisplay(appW);
  70. #ifdef DEBUG
  71.     XSynchronize(dpy, True);
  72. #endif
  73.     printf("Display:  %s \n", DisplayString(dpy));
  74.     if ((tc = XECreateTC(dpy,0L, NULL)) == False)
  75.     {
  76.         fprintf(stderr,"%s: could not initialize extension\n",argv[0]);
  77.         exit(1L);
  78.     }
  79.  
  80.     (void)XEGetAvailableRequest(tc,&ret_avail);
  81.     if (BitIsFalse(ret_avail.valid, XETrapStatistics))
  82.     {
  83.         printf("\nStatistics not available from '%s'.\n",
  84.             DisplayString(dpy));
  85.         exit(1L);
  86.     }
  87.     XETrapSetStatistics(tc, True);
  88.     for (i=0; i<256L; i++)
  89.     {
  90.         BitTrue(requests, i);
  91.     }
  92.     XETrapSetRequests(tc, True, requests);
  93.     for (i=KeyPress; i<=MotionNotify; i++)
  94.     {
  95.         BitTrue(events, i);
  96.     }
  97.     XETrapSetEvents(tc, True, events);
  98.     done = False;
  99.     while(done == False)
  100.     {
  101.         fprintf(stderr,"Stats Command (Zero, Quit, [Show])? ");
  102.         fgets(buffer, sizeof(buffer), stdin);
  103.         switch(toupper(buffer[0]))
  104.         {
  105.             case '\n':  /* Default command */
  106.             case 'S':   /* Request fresh counters & display */
  107.                 (void)XEGetStatisticsRequest(tc,&ret_stats);
  108.                 (void)XEPrintStatistics(stdout,&ret_stats);
  109.                 break;
  110.             case 'Z':  /* Zero out counters */
  111.                 XETrapSetStatistics(tc, False);
  112.                 break;
  113.             case 'Q':
  114.                 done = True;
  115.                 break;
  116.             default:
  117.                 printf("Invalid command, reenter!\n");
  118.                 break;
  119.         }
  120.     }
  121.     (void)XEFreeTC(tc);
  122.     (void)XCloseDisplay(dpy);
  123.     exit(0L);
  124. }
  125.