home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / imdisp79.zip / HELP.C < prev    next >
C/C++ Source or Header  |  1993-02-15  |  3KB  |  131 lines

  1. /***  IMDISP module HELP.C
  2.  
  3.     HELP.C contains the command which services help requests from
  4.     the IMDISP main menu.  All help text for new commands goes here.
  5.     Adapted from the original HELP.C to use external help file
  6.     IMDISP.HLP ala Lee Brotzman's FTB program/
  7.  
  8. ***/
  9.  
  10. #define __MSC
  11.  
  12.  
  13. /* * * * INCLUDE files * * * */
  14.  
  15. #include <stdio.h>
  16. #include <conio.h>
  17. #include <string.h>
  18. #include "imdef.h"
  19. #include "imdisp.h"
  20. #include "imdutil.h"
  21. #include "dispio.h"
  22. #include "labutil.h"
  23. #include "textutil.h"
  24.  
  25.  
  26. /*
  27.    External data
  28. */
  29.  
  30. void Help(void)
  31. /*
  32.    Print help information on given topic.  The help is gotten from a text
  33.    file called pointed to by the FILE structure helpfile.  Each topic is
  34.    delimited by a record beginning with a period, '.', followed by the name
  35.    of the topic.  All records up to the next topic heading are listed to
  36.    the screen.
  37. */
  38. {
  39.    char  inrec[81];
  40.    int   linecnt;
  41.    int   length;
  42.    char  ch;
  43.    char  *command, temp[81];
  44.    char  *string;
  45.  
  46.    strcpy(temp, CommandString);
  47.  
  48.    command = strtok( temp, " ");
  49.    command = strtok( NULL, " ");
  50.  
  51.    if (command == NULL)     /* Default help command is "HELP HELP" */
  52.    {
  53.       strcpy(temp, "HELP");
  54.       command = strtok(temp," ");
  55.    }
  56.  
  57.    if(helpfile == NULL)
  58.    {
  59.       sprintf( inrec, "Warning: help file %s not open.", helpfilename);
  60.       StatusLine(1, inrec);
  61.       return;
  62.    }
  63.  
  64.    rewind(helpfile);
  65.  
  66.    linecnt = 0;
  67.    while( !feof(helpfile) )
  68.    {
  69.       fgets(inrec, 80, helpfile);
  70.       if (inrec[0] == '.')
  71.       {
  72.  
  73.          string = strrtrim( inrec );
  74.          strcpy( inrec, string);
  75.  
  76.          if (match(command, &inrec[1]))
  77.          {
  78.             if (OneScreen)
  79.             {
  80.                 ClearDisplay (0);
  81.                 TextLine = TextHeight + 5;
  82.                 TextSample = 1;
  83.             }
  84.  
  85.             fgets(inrec, 80, helpfile);
  86.             while ((inrec[0] != '.') && !feof(helpfile))
  87.             {
  88.  
  89.                string = strrtrim( inrec );
  90.                strcpy( inrec, string);
  91.  
  92.                length = strlen(inrec);
  93.                if (length == 0)
  94.                {
  95.                   TextLine += TextHeight+5;
  96.                   TextSample = 1;
  97.                }
  98.                else
  99.                   WriteText(inrec);
  100.                fgets(inrec, 80, helpfile);
  101.  
  102.                if ( (TextLine + 2*TextHeight) >= dispnl)
  103.                {
  104.                   WriteText("Press RETURN to continue, any key to quit: ");
  105.                   while(!kbhit);
  106.                   if ((ch = getch()) == 0)
  107.                      ch = 0x80 | getch();
  108.  
  109.                   if (ch != 13) /* don't abort if <CR> */
  110.                   {
  111.                           return;
  112.                   }
  113.  
  114.                   ClearDisplay (0);
  115.                   TextLine = TextHeight + 5;
  116.                   TextSample = 1;
  117.                }
  118.             }
  119.             return;
  120.          }
  121.       }
  122.    }
  123.  
  124.    /*
  125.       No match was found, list HELP topics
  126.    */
  127.    strcpy(CommandString, "HELP");
  128.    Help();
  129. }
  130.  
  131.