home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / HELP / DISPLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-07  |  5.0 KB  |  247 lines

  1. /* ==( help/display.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   JPK  26-Sep-88                        */
  9. /* Modified  Geo  12-Dec-89  See comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  *  Modifications
  15.  *
  16.  *  12-Dec-89  Geo - V2 version with variable lines
  17.  *  25-Oct-89  Geo - 1.32 Merge
  18.  *
  19.  *
  20. */
  21.  
  22. /* 
  23.  * Routines in this file:
  24.  *
  25.  * int getline(char *, int, int)
  26.  *    gets the next line of help from the help text file
  27.  *
  28.  * static void tbdisp_w(int, int, int, int, int, char *, int)
  29.  *    displays the line in the window
  30.  *
  31.  * void display(int, struct help_hdr)
  32.  *     uses getline and tbdisp_w to display a window full of help
  33.  *
  34.  * void display_help(struct help_hdr)
  35.  *     gets input for help and controls the display of help
  36.  *
  37.  */
  38.  
  39. # include <stdio.h>
  40. # include <bench.h>
  41. # include "help.h"
  42.  
  43. static PROTO (int getline, (char *, int, int));
  44. static PROTO (void tbdisp_w, (int, int, int, int, int, char *, int));
  45.  
  46. static int right;
  47. static int end_reached = 0;
  48. static char eoh[] = "*** End of Help ***";
  49.  
  50. static int getline(line, lmax, num)
  51.     char    * line;
  52.     int    lmax;
  53.     int num;
  54. {
  55.     if (read_help_index(num) == TRUE)
  56.     {
  57.         if (read_help(line, (h_tdx.size>lmax ?lmax :h_tdx.size), &h_tdx)
  58.             != FALSE)
  59.         {
  60.             return(TRUE);
  61.         }
  62.     }
  63.     return(-1);
  64. }
  65.  
  66. static void    tbdisp_w(row, col, attr, battr, n, buf, tab)
  67.     int        row, col;
  68.     int        attr;
  69.     int        battr;
  70.     int        n;
  71.     char    * buf;
  72.     int        tab;
  73. {
  74.     int i, k;
  75.     int a = 0;
  76.  
  77.     for (i = 0; i < n; i++)
  78.     {
  79.         if (*buf == '\0')
  80.             break;
  81.  
  82.         if (*buf == '^')
  83.             a = 1 - a;
  84.         else if (*buf == '\t')
  85.         {
  86.             for (k = (i % tab); k < tab && i < n; k++, i++)
  87.                 poke_w(row, col++, a ? battr : attr, ' ');
  88.             i--;
  89.         }
  90.         else
  91.             poke_w(row, col++, a ? battr : attr, *buf);
  92.         buf++;
  93.     }
  94.     if (i  <  n)
  95.         rephoriz_w(row, col, a ? battr : attr, n - i, ' ');
  96. }
  97.  
  98.  
  99. void display(first, hptr)
  100.     int first;
  101.     struct    help_hdr * hptr;
  102. {
  103.     char    *line;
  104.     int    i, j;
  105.     int    col;
  106.  
  107.     line = (char *)alloc(w_ncols);
  108.  
  109.     for (i=2; i < hptr->height; i++)
  110.     {
  111.         j = 0;
  112.         col = 2;
  113.         if (getline(line, w_ncols, first) != -1)
  114.         {
  115.             while (j < right && line[j] != '\0')
  116.                 j++;
  117.             line[hptr->width-2+j] = '\0';
  118.         }
  119.         else
  120.             line[0] = '\0';
  121.  
  122.         tbdisp_w(i, col, hptr->disp_attr, hptr->box_attr, hptr->width-2,
  123.             line+j, hptr->tabs);
  124.         first++;
  125.     }
  126.     if (end_reached)
  127.     {
  128.         /* put out a end of help message */
  129.         tbdisp_w(hptr->height-1, 2, hptr->disp_attr, hptr->box_attr,
  130.             hptr->width-2, eoh, hptr->tabs);
  131.         end_reached = 0;
  132.     }
  133.     free(line);
  134. }
  135.  
  136. void display_help(hptr)
  137.     struct help_hdr *hptr;
  138. {
  139.     int    ch;
  140.     int    last_col;
  141.     int    page;
  142.     int    max_first;
  143.  
  144.     /* set buffer display parameters */
  145.     last_col  = w_ncols - hptr->width;
  146.     page = hptr->height - 2;
  147.     max_first = (h_part.len > page  ?  h_part.len-page+1 : 1);
  148.  
  149.     /* initialize the help window */
  150.     setup_w(hptr);
  151.     h_part.pos = 1;
  152.     right = 0;
  153.  
  154. # ifdef MOUSE
  155.     mouse_level++;
  156. # endif
  157.  
  158.     /* display a user prompt line */
  159.     keys_w(K_PGUP, ",", K_PGDN, scroll_prompt, K_F2, choice_prompt, K_ESC, exit_prompt, 0);
  160.  
  161.     /* display the buffer and allow user to scroll thru it */
  162.     display(h_part.pos, hptr);
  163.     while ((ch = inchar())  !=  K_ESC)
  164.     {
  165.         switch(ch)
  166.         {
  167. # ifdef MOUSE
  168.         case M_PRESS:
  169.         case M_RELEASE:
  170.             { /* Start forced local block */
  171.             int dummy;
  172.  
  173.                 mouse_click( &dummy , ch ); 
  174.  
  175.             } /* End forced local block */
  176.             break;
  177. # endif
  178.         case K_UP:
  179.             h_part.pos--;
  180.             h_part.pos = (h_part.pos < 1 ? 1 : h_part.pos);
  181.             break;
  182.  
  183.         case K_CR:
  184.         case K_DOWN:
  185.             h_part.pos++;
  186.             h_part.pos = (h_part.pos > max_first ? max_first : h_part.pos);
  187.             break;
  188.  
  189.         case K_PGUP:
  190.             h_part.pos -= (page - 1);
  191.             if(h_part.pos  <  1)
  192.                 h_part.pos = 1;
  193.             break;
  194.  
  195.         case K_PGDN:
  196.             h_part.pos += (page - 1);
  197.             h_part.pos = (h_part.pos > max_first ? max_first : h_part.pos);
  198.             break;
  199.  
  200.         case K_LEFT:
  201.             if(right  >  0)
  202.                 right--;
  203.             break;
  204.  
  205.         case K_RIGHT:
  206.             if(right  <  last_col)
  207.                 right++;
  208.             break;
  209.  
  210.         case K_HOME:
  211.             h_part.pos = 1;
  212.             right = 0;
  213.             break;
  214.  
  215.         case K_END:
  216.             h_part.pos = max_first;
  217.             right = 0;
  218.             break;
  219.  
  220.         case K_F2:
  221.             popup_menu(hptr);
  222.             /* Due to resizing and moving */
  223.             keys_w(K_PGUP, ",", K_PGDN, scroll_prompt, K_F2, choice_prompt, K_ESC, exit_prompt, 0);
  224.             last_col  = w_ncols - hptr->width;
  225.             page = hptr->height - 2;
  226.             if (h_part.len  >  page)
  227.                 max_first = h_part.len - page + 1;
  228.             else
  229.                 max_first = 1;
  230.             border_w(hptr->box_style, hptr->box_attr);
  231.             break;
  232.  
  233.         default:
  234.             continue;
  235.         }
  236.         if (h_part.pos  ==  max_first)
  237.             end_reached = 1;
  238.         display(h_part.pos, hptr);
  239.     }
  240.     /* delete help window */
  241.     delete_w();
  242.  
  243. # ifdef MOUSE
  244.     mouse_delete_level( mouse_level-- );
  245. # endif
  246. }
  247.