home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tc-book.zip / THELP.C < prev    next >
Text File  |  1987-08-20  |  2KB  |  111 lines

  1. /* --------- thelp.c ----------- */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "twindow.h"
  7. #include "keys.h"
  8.  
  9. #define MAXHELPS 25
  10. #define HBG WHITE
  11. #define HFG BLACK
  12. #define HINT DIM
  13.  
  14. #define TRUE 1
  15. #define FALSE 0
  16.  
  17. static struct helps {
  18.     char hname [9];
  19.     int h, w;
  20.     long hptr;
  21. } hps [MAXHELPS+1];
  22.  
  23. static int hp = 0;
  24. static int ch = 0;
  25. static int hx, hy;
  26. FILE *helpfp = NULL;
  27. long ftell();
  28. char *fgets();
  29. void help();
  30. char helpname[64];
  31. void getline(char *lineh);
  32. /*page*/
  33. /* ----------- load the HELP! definition file ------------ */
  34. void load_help(char *hn)
  35. {
  36.     extern void (*helpfunc)();
  37.     extern int helpkey;
  38.     char lineh [80];
  39.  
  40.     if (strcmp(helpname, hn) == 0)
  41.         return;
  42.     helpfunc = help;
  43.     helpkey = F1;
  44.     hp = 0;
  45.     strcpy(helpname, hn);
  46.     if ((helpfp = fopen(helpname, "r")) == NULL)
  47.         return;
  48.     getline(lineh);
  49.     while (1)    {
  50.         if (hp == MAXHELPS)
  51.             break;
  52.         if (strncmp(lineh, "<end>", 5) == 0)
  53.             break;
  54.         if (*lineh != '<')
  55.             continue;
  56.         hps[hp].h = 3;
  57.         hps[hp].w = 18;
  58.         strncpy(hps[hp].hname, lineh+1, 8);
  59.         hps[hp].hptr = ftell(helpfp);
  60.         getline(lineh);
  61.         while (*lineh != '<')    {
  62.             hps[hp].h++;
  63.             hps[hp].w = max(hps[hp].w, strlen(lineh)+2);
  64.             getline(lineh);
  65.         }
  66.         hp++;
  67.     }
  68. }
  69. /*page*/
  70. /* -------- get a line of text from the help file -------- */
  71. static void getline(char *lineh)
  72. {
  73.     if (fgets(lineh, 80, helpfp) == NULL)
  74.         strcpy(lineh, "<end>");
  75. }
  76. /* -------- set the current active help screen ----------- */
  77. void set_help(char *s, int x, int y)
  78. {
  79.     for (ch = 0; ch < hp; ch++)
  80.         if (strncmp(s, hps[ch].hname, 8) == 0)
  81.             break;
  82.     hx = x;
  83.     hy = y;
  84. }
  85. /* ---------- display the current help window ----------- */
  86. void help()
  87. {
  88.     char ln [80];
  89.     int i, xx, yy;
  90.     WINDOW *wnd;
  91.     extern int helpkey;
  92.     if (hp && ch != hp)    {
  93.         curr_cursor(&xx, &yy);
  94.         cursor(0, 25);
  95.         wnd = establish_window(hx, hy, hps[ch].h, hps[ch].w);
  96.         set_colors(wnd, ALL, HBG, HFG, HINT);
  97.         display_window(wnd);
  98.         fseek(helpfp, hps[ch].hptr, 0);
  99.         for (i = 0; i < hps[ch].h-3; i++)    {
  100.             getline(ln);
  101.             wprintf(wnd, ln);
  102.         }
  103.         wprintf(wnd, " [Help] to return");
  104.         while (get_char() != helpkey)
  105.             putchar(BELL);
  106.         delete_window(wnd);
  107.         cursor(xx, yy);
  108.     }
  109. }
  110.  
  111.