home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_06 / 2n06038a < prev    next >
Text File  |  1991-04-11  |  6KB  |  256 lines

  1.  
  2.               Listing 3, Foreground Monitor Program
  3.               -------------------------------------
  4.  
  5. /*
  6. **  MONITOR.C
  7. **  Foreground Monitor Program
  8. **
  9. **  Written in MicroSoft C version 6.00
  10. **  Build String:
  11. **    cl monitor.c -link graphics
  12. **
  13. **  Written By:  John R. Naleszkiewicz
  14. **        Date:  March 15, 1991
  15. **     Version:  1.00
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <graph.h>
  21. #include <dos.h>
  22.  
  23. #define SINGLE   0
  24. #define DOUBLE   1
  25.  
  26. #define CHAR     0
  27. #define STRING   1
  28. #define SHORT    2
  29. #define LONG     3
  30. #define ESCape   27
  31.  
  32. char boxChar[2][6] = {
  33.   { 0xda, 0xc4, 0xbf, 0xc0, 0xd9, 0xb3, },
  34.   { 0xc9, 0xcd, 0xbb, 0xc8, 0xbc, 0xba, }
  35. };
  36.  
  37. /* This structure defines which variables are monitored */
  38. struct Variable_Struct {
  39.   char far * name;           /*  Far Pointer to Variable Name  */
  40.   unsigned char type;        /*  Variable Type  */
  41.   unsigned char indirect;    /*  Indirection Count  */
  42.   unsigned short ind_flag;   /*  Indirection Type Flag  */
  43.   void far * var;            /*  Far Pointer to Variable  */
  44. } far * element;
  45.  
  46.  
  47. /* the interrupt vector number used to gain entry into TSR */
  48. #define  INT_VECTOR    0x68
  49. #define  FORMAT_ID     01
  50.  
  51. union    REGS  regs;
  52.  
  53.  
  54. static int  frameColor, textColor;
  55. static int  uRow, uColumn, lRow, lColumn;
  56. static int  rowMAX, colMAX;
  57. static char filler[10] = "         ";
  58. static char chbuf[2]   = " ";
  59.  
  60.  
  61. void drawBox( int type,
  62.               int ulr, int ulc, int lrr, int lrc,
  63.               int frame, int text, int background )
  64. {
  65.   int i;
  66.   char buffer[81];
  67.  
  68.   _settextwindow( ulr, ulc, lrr, lrc );
  69.   _setbkcolor( (long) background );
  70.   _settextcolor( textColor = text );
  71.   _clearscreen( _GWINDOW );
  72.   _wrapon( _GWRAPOFF );
  73.   _settextcolor( frameColor = frame );
  74.  
  75.   rowMAX = lrr - ulr + 1;
  76.   colMAX = lrc - ulc + 1;
  77.  
  78.   strset( filler, boxChar[type][1] );
  79.  
  80.   buffer[colMAX] = '\0';
  81.   for( i = 1; i < colMAX-1 ; i++ )
  82.     buffer[i] = boxChar[type][1];
  83.  
  84.   _settextposition( rowMAX, 1 );
  85.   buffer[0]        = boxChar[type][3];
  86.   buffer[colMAX-1] = boxChar[type][4];
  87.   _outtext( buffer );
  88.  
  89.   _settextposition( 1, 1 );
  90.   buffer[0]        = boxChar[type][0];
  91.   buffer[colMAX-1] = boxChar[type][2];
  92.   _outtext( buffer );
  93.  
  94.   chbuf[0] = boxChar[type][5];
  95.   for( i = 2 ; i < rowMAX ; i++ ) {
  96.     _settextposition( i, 1 );
  97.     _outtext( chbuf );
  98.     _settextposition( i, colMAX );
  99.     _outtext( chbuf );
  100.   }
  101.   _settextposition( 23, 19 );
  102.   _outtext( "Press the ESCape Key to EXIT the Monitor" );
  103.  
  104.   _settextcolor( text );
  105.   _settextposition( 1, 27 );
  106.   _outtext( " Non-Intrusive TSR Monitor " );
  107.  
  108.   _settextwindow( uRow = ulr+1, uColumn = ulc+1,
  109.                   lRow = lrr-1, lColumn = lrc-1 );
  110. }
  111.  
  112.  
  113. void clearEOL()
  114. {
  115.   struct rccoord loc;
  116.  
  117.   loc = _gettextposition();
  118.   if( loc.col < colMAX-2 ) {
  119.     _settextwindow( loc.row+uRow-1, 
  120.                     loc.col+uColumn-1, loc.row+uRow-1, lColumn );
  121.     _scrolltextwindow( _GSCROLLUP );
  122.     _settextwindow( uRow, uColumn, lRow, lColumn );
  123.     _settextposition( loc.row, loc.col );
  124.   }
  125. }
  126.  
  127.  
  128. void dotFill( int x )
  129. {
  130.   struct rccoord pos;
  131.  
  132.   pos = _gettextposition();
  133.   x -= pos.col;
  134.   while( --x > 0 )
  135.     _outtext( "." );
  136. }
  137.  
  138.  
  139. void far * resolve( int index )
  140. {
  141.   int      pos, cnt;
  142.   void     far * pointer;
  143.   unsigned mask;
  144.  
  145.   if( element[index].indirect == 0 )
  146.     return element[index].var;
  147.  
  148.   cnt = element[index].indirect;
  149.   pointer = element[index].var;
  150.  
  151.   for( mask = 1 ; cnt ; cnt--, mask <<= 1 ) {
  152.     if( (element[index].ind_flag & mask) == 0 ) {
  153.       /* resolve the near pointer */
  154.       (unsigned) pointer = *( (unsigned far *) pointer );
  155.     }
  156.     else {
  157.       /* resolve the far pointer */
  158.       pointer = *( (void far * far *) pointer );
  159.     }
  160.   }
  161.  
  162.   return pointer;
  163. }
  164.  
  165.  
  166. void putValue( int index )
  167. {
  168.   char str[20];
  169.  
  170.   switch( element[index].type ) {
  171.     case CHAR:
  172.       str[0] = *( (char far *) resolve( index ));
  173.       str[1] = '\0';
  174.       _outtext( str );
  175.       break;
  176.  
  177.     case STRING:
  178.       _outtext( (char far *) resolve( index ) );
  179.       break;
  180.  
  181.     case SHORT:
  182.       _outtext( itoa( *((int far *) resolve( index )), str, 10 ) );
  183.       break;
  184.  
  185.     case LONG:
  186.       _outtext( ltoa( *((long far *) resolve( index )), str, 10 ));
  187.       break;
  188.   }
  189.  
  190.   clearEOL();
  191. }
  192.  
  193.  
  194. void nothingToMonitor()
  195. {
  196.   printf( "Non-Intrusive Monitor\nVersion 1.00\n" );
  197.   printf( "Written by John R. Naleszkiewicz\n\n" );
  198.   printf( "No TSR loaded that can be monitored" );
  199.   exit( 1 );
  200. }
  201.  
  202.  
  203. void main()
  204. {
  205.   int cc;
  206.   int vars;
  207.   int index;
  208.  
  209.   if( _dos_getvect( INT_VECTOR ) == NULL )
  210.     nothingToMonitor();
  211.  
  212.   /* Check for a Valid Data Block Format */
  213.   regs.x.ax = 0;
  214.   if( int86( INT_VECTOR, ®s, ®s ) != FORMAT_ID )
  215.     nothingToMonitor();
  216.  
  217.   /* Find out How Many Variables to Monitor */
  218.   regs.x.ax = 1;
  219.   if( (vars = int86( INT_VECTOR, ®s, ®s )) == 0 )
  220.     nothingToMonitor();
  221.  
  222.   /* Get the Data Block Address */
  223.   regs.x.ax = 2;
  224.   int86( INT_VECTOR, ®s, ®s );
  225.   element = (struct Variable_Struct far *) 
  226.              (((long) regs.x.dx << 16) + (long) regs.x.ax);
  227.  
  228.   drawBox( DOUBLE, 1, 1, 25, 80, 14, 15, 1 );
  229.  
  230.   /* display the variable names */
  231.   for( index = 0 ; index < vars ; index++ ) {
  232.     _settextposition( index+3, 10 );
  233.     _outtext( element[index].name );
  234.     dotFill( 40 );
  235.   }
  236.  
  237.   for( cc = 0 ; cc != ESCape ; ) {
  238.     for( index = 0 ; index < vars ; index++ ) {
  239.       _settextposition( index+3, 40 );
  240.       putValue( index );
  241.     }
  242.  
  243.     /* check if any keyboard characters have been pressed */
  244.     if( kbhit() ) {
  245.       if( (cc = getch()) == 0 )
  246.         (void) getch();
  247.     }
  248.   }
  249.  
  250.   /* restore screen colors and exit */
  251.   _setbkcolor( 0 );
  252.   _settextcolor( 7 );
  253.   _clearscreen( _GCLEARSCREEN );
  254. }
  255.  
  256.