home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / memory / heapdbg / screen.c < prev   
Encoding:
C/C++ Source or Header  |  1994-06-12  |  6.0 KB  |  204 lines

  1. /*********************************SCREEN.C***************************************/
  2.  
  3. /*
  4.  * Author:       Mark Nelson
  5.  *
  6.  * Date:         October 28, 1989
  7.  *
  8.  * Description:  This module contains the screen I/O routines used in
  9.  *               the heap debugger module.  These are very simplified
  10.  *               screen I/O routines.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #include <string.h>
  16. #include "_heap.h"
  17. /*
  18.  * These are all the line drawing constants defined.
  19.  */
  20. #define UL_CORNER       218
  21. #define UR_CORNER       191
  22. #define LL_CORNER       192
  23. #define LR_CORNER       217
  24. #define UPPER_TEE       194
  25. #define LOWER_TEE       193
  26. #define LEFT_TEE        195
  27. #define RIGHT_TEE       180
  28. #define CENTER_TEE      197
  29. #define HORIZONTAL_LINE 196
  30. #define VERTICAL_LINE   179
  31.  
  32. /*
  33.  * I create a structure so I can write directly to screen as if it were
  34.  * a big array.  That way the compiler takes care of computing the
  35.  * addresses, all I have to do is insert the row and column.
  36.  */
  37. struct video_element {
  38.                           unsigned char character;
  39.                           unsigned char attribute;
  40.                      };
  41. struct video_element (far *physical_screen)[25][80];
  42. struct video_element saved_screen[25][80];
  43.  
  44. /*
  45.  * This routine draws the box I use up on the screen.  It is passed a
  46.  * list of labels to draw at the head of the columns, plus a count
  47.  * of how many rows are to be left open for data entry.  It depends
  48.  * on some earlier code somewhere to have initialized an array called
  49.  * columns[] that tells it where to draw each column on the screen.
  50.  * There is a lot of code here to draw the boxes, but it is all
  51.  * straightforward.
  52.  */
  53. int columns[10];
  54. int column_count=0;
  55.  
  56. void draw_boxes_and_titles(char *labels[],int row_count)
  57. {
  58. int col;
  59. int row;
  60. int i;
  61. int j;
  62. int rows[3];
  63. /*
  64.  * The three rows I define are the top and bottom of the box, plus the
  65.  * line that divides the title lines from the data lines.
  66.  */
  67.     rows[0]=0;
  68.     rows[1]=2;
  69.     rows[2]=3+row_count;
  70.     for (col=1;col<columns[column_count];col++)
  71.         for (i=0;i<3;i++)
  72.             (*physical_screen)[rows[i]][col].character = HORIZONTAL_LINE;
  73.     for (i=0;i<=column_count;i++)
  74.         for (row=0;row<(row_count+4);row++)
  75.             (*physical_screen)[row][columns[i]].character = VERTICAL_LINE;
  76.     (*physical_screen)[0][columns[0]].character = UL_CORNER;
  77.     (*physical_screen)[row_count+3][columns[0]].character = LL_CORNER;
  78.     (*physical_screen)[0][columns[column_count]].character = UR_CORNER;
  79.     (*physical_screen)[row_count+3][columns[column_count]].character = LR_CORNER;
  80.  
  81.     (*physical_screen)[rows[1]][columns[0]].character = LEFT_TEE;
  82.     (*physical_screen)[rows[1]][columns[column_count]].character = RIGHT_TEE;
  83.     for (j=1;j<column_count;j++)
  84.         (*physical_screen)[0][columns[j]].character = UPPER_TEE;
  85.     for (j=1;j<column_count;j++)
  86.         (*physical_screen)[row_count+3][columns[j]].character = LOWER_TEE;
  87.  
  88.     for (j=1;j<column_count;j++)
  89.         (*physical_screen)[rows[1]][columns[j]].character = CENTER_TEE;
  90. /*
  91.  * Here is where I draw the labels.  They need to go in the center of
  92.  * their little boxes.
  93.  */
  94.     for (i=0;i<column_count;i++)
  95.     {
  96.         col=columns[i]+1;
  97.         col += (columns[i+1]-columns[i]-1)/2;
  98.         col -= strlen(labels[i])/2;
  99.         screenputs(1,col,labels[i]);
  100.     }
  101. }
  102. /*
  103.  * This is a general purpose routine to print a formatted string on
  104.  * the screen.
  105.  */
  106. void screenputf(int row,int col,char *format,...)
  107. {
  108.     char buffer[81];
  109.     va_list args;
  110.  
  111.     va_start(args,format);
  112.     vsprintf(buffer,format,args);
  113.     screenputs(row,col,buffer);
  114. }
  115. /*
  116.  * This is a general purpose routine to put an unformatted string
  117.  * out to the screen.
  118.  */
  119. void screenputs(int row,int col,char *string)
  120. {
  121. char c;
  122.  
  123.     while (1)
  124.     {
  125.         c=*string++;
  126.         if (c=='\0')
  127.             break;
  128.         (*physical_screen)[row][col++].character=c;
  129.     }
  130. }
  131. /*
  132.  * This is a general purpose routine to clear a whole line on the
  133.  * screen.
  134.  */
  135. void screenclearline(int row)
  136. {
  137. int col;
  138.  
  139.     for (col=0;col<80;col++)
  140.         (*physical_screen)[row][col].character=' ';
  141. }
  142. /*
  143.  * This is the screen initialization code.  It is a trap door routine that
  144.  * gets called all the time, but only executes once.  It computes what
  145.  * columns the vertical lines are going to go in, based on the widths needed
  146.  * for each column, passed as a parameter.
  147.  * Note that if you are using a monochrome monitor, you need to change
  148.  * the screen pointer to be 0xb0000000L.
  149.  * This routine also initializes the tag table
  150.  */
  151. void initialize_screen(char *labels[],int widths[])
  152. {
  153. int row;
  154. int col;
  155. int i;
  156. static int first_time=0;
  157.  
  158.     if (first_time==0)
  159.     {
  160.         first_time=1;
  161.         columns[0]=1;
  162.         column_count=0;
  163.         while (strlen(labels[column_count]) != 0)
  164.         {
  165.             columns[column_count+1] = columns[column_count]+widths[column_count]+1;
  166.             column_count++;
  167.         }
  168.     }
  169.     physical_screen=(struct video_element (far *)[25][80])0xb8000000L;
  170.     for (row=0;row<25;row++)
  171.         for (col=0;col<80;col++)
  172.         {
  173.              saved_screen[row][col]=(*physical_screen)[row][col];
  174.              (*physical_screen)[row][col].character=' ';
  175.              (*physical_screen)[row][col].attribute=0x1b;
  176.         }
  177. }
  178.  
  179. /*
  180.  *  Whenever the heap routines decide they need to print a screen message,
  181.  *  they set up the screen first by calling this guy.
  182.  */
  183. void setup_screen(char *labels[],int widths[],int rows)
  184. {
  185.     initialize_screen(labels,widths);
  186.     draw_boxes_and_titles(labels,rows);
  187. }
  188.  
  189. /*
  190.  * After the heap routines are done printing debug information, they
  191.  * have to restore the screen back to where it was when they got called.
  192.  * This routine does that.
  193.  */
  194. void restore_screen()
  195. {
  196. int row;
  197. int col;
  198.  
  199.     for (row=0;row<25;row++)
  200.         for (col=0;col<80;col++)
  201.              (*physical_screen)[row][col]=saved_screen[row][col];
  202. }
  203.  
  204.