home *** CD-ROM | disk | FTP | other *** search
- /* ==( help/display.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written JPK 26-Sep-88 */
- /* Modified Geo 12-Dec-89 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 12-Dec-89 Geo - V2 version with variable lines
- * 25-Oct-89 Geo - 1.32 Merge
- *
- *
- */
-
- /*
- * Routines in this file:
- *
- * int getline(char *, int, int)
- * gets the next line of help from the help text file
- *
- * static void tbdisp_w(int, int, int, int, int, char *, int)
- * displays the line in the window
- *
- * void display(int, struct help_hdr)
- * uses getline and tbdisp_w to display a window full of help
- *
- * void display_help(struct help_hdr)
- * gets input for help and controls the display of help
- *
- */
-
- # include <stdio.h>
- # include <bench.h>
- # include "help.h"
-
- # ifdef ANSI
- static int getline(char *, int, int);
- static void tbdisp_w(int, int, int, int, int, char *, int);
- # else
- static int getline();
- static void tbdisp_w();
- # endif
-
- static int right;
- static int end_reached = 0;
- static char eoh[] = "*** End of Help ***";
-
- static int getline(line, lmax, num)
- char * line;
- int lmax;
- int num;
- {
- if (read_help_index(num) == TRUE)
- {
- if (read_help(line, (h_tdx.size>lmax ?lmax :h_tdx.size), &h_tdx)
- != FALSE)
- {
- return(TRUE);
- }
- }
- return(-1);
- }
-
- static void tbdisp_w(row, col, attr, battr, n, buf, tab)
- int row, col;
- int attr;
- int battr;
- int n;
- char * buf;
- int tab;
- {
- int i, k;
- int a = 0;
-
- for (i = 0; i < n; i++)
- {
- if (*buf == '\0')
- break;
-
- if (*buf == '^')
- a = 1 - a;
- else if (*buf == '\t')
- {
- for (k = (i % tab); k < tab && i < n; k++, i++)
- poke_w(row, col++, a ? battr : attr, ' ');
- i--;
- }
- else
- poke_w(row, col++, a ? battr : attr, *buf);
- buf++;
- }
- if (i < n)
- rephoriz_w(row, col, a ? battr : attr, n - i, ' ');
- }
-
-
- void display(first, hptr)
- int first;
- struct help_hdr * hptr;
- {
- char *line;
- int i, j;
- int col;
-
- line = (char *)alloc(w_ncols);
-
- for (i=2; i < hptr->height; i++)
- {
- j = 0;
- col = 2;
- if (getline(line, w_ncols, first) != -1)
- {
- while (j < right && line[j] != '\0')
- j++;
- line[hptr->width-2+j] = '\0';
- }
- else
- line[0] = '\0';
-
- tbdisp_w(i, col, hptr->disp_attr, hptr->box_attr, hptr->width-2,
- line+j, hptr->tabs);
- first++;
- }
- if (end_reached)
- {
- /* put out a end of help message */
- tbdisp_w(hptr->height-1, 2, hptr->disp_attr, hptr->box_attr,
- hptr->width-2, eoh, hptr->tabs);
- end_reached = 0;
- }
- free(line);
- }
-
- void display_help(hptr)
- struct help_hdr *hptr;
- {
- int ch;
- int last_col;
- int page;
- int max_first;
-
- /* set buffer display parameters */
- last_col = w_ncols - hptr->width;
- page = hptr->height - 2;
- max_first = (h_part.len > page ? h_part.len-page+1 : 1);
-
- /* initialize the help window */
- setup_w(hptr);
- h_part.pos = 1;
- right = 0;
-
- # ifdef MOUSE
- mouse_level++;
- # endif
-
- /* display a user prompt line */
- keys_w(K_PGUP, ",", K_PGDN, scroll_prompt, K_F2, choice_prompt, K_ESC, exit_prompt, 0);
-
- /* display the buffer and allow user to scroll thru it */
- display(h_part.pos, hptr);
- while ((ch = inchar()) != K_ESC)
- {
- switch(ch)
- {
- # ifdef MOUSE
- case M_PRESS:
- case M_RELEASE:
- { /* Start forced local block */
- int dummy;
-
- mouse_click( &dummy , ch );
-
- } /* End forced local block */
- break;
- # endif
- case K_UP:
- h_part.pos--;
- h_part.pos = (h_part.pos < 1 ? 1 : h_part.pos);
- break;
-
- case K_CR:
- case K_DOWN:
- h_part.pos++;
- h_part.pos = (h_part.pos > max_first ? max_first : h_part.pos);
- break;
-
- case K_PGUP:
- h_part.pos -= (page - 1);
- if(h_part.pos < 1)
- h_part.pos = 1;
- break;
-
- case K_PGDN:
- h_part.pos += (page - 1);
- h_part.pos = (h_part.pos > max_first ? max_first : h_part.pos);
- break;
-
- case K_LEFT:
- if(right > 0)
- right--;
- break;
-
- case K_RIGHT:
- if(right < last_col)
- right++;
- break;
-
- case K_HOME:
- h_part.pos = 1;
- right = 0;
- break;
-
- case K_END:
- h_part.pos = max_first;
- right = 0;
- break;
-
- case K_F2:
- popup_menu(hptr);
- /* Due to resizing and moving */
- keys_w(K_PGUP, ",", K_PGDN, scroll_prompt, K_F2, choice_prompt, K_ESC, exit_prompt, 0);
- last_col = w_ncols - hptr->width;
- page = hptr->height - 2;
- if (h_part.len > page)
- max_first = h_part.len - page + 1;
- else
- max_first = 1;
- border_w(hptr->box_style, hptr->box_attr);
- break;
-
- default:
- continue;
- }
- if (h_part.pos == max_first)
- end_reached = 1;
- display(h_part.pos, hptr);
- }
- /* delete help window */
- delete_w();
-
- # ifdef MOUSE
- mouse_delete_level( mouse_level-- );
- # endif
- }
-