home *** CD-ROM | disk | FTP | other *** search
/ The Education Master 1994 (4th Edition) / EDUCATIONS_MASTER_4TH_EDITION.bin / files / progmisc / qparser2 / lib / help.c next >
Encoding:
C/C++ Source or Header  |  1993-03-15  |  1.9 KB  |  69 lines

  1. /*  help.c
  2.  
  3.     QCAD Systems, Inc.
  4.  
  5.     Provides help based on a helpfile and a topic.
  6.     The initial lines of a helpfile are ignored.
  7.  
  8.     The help itself starts with
  9.  
  10.      @TOPIC
  11.  
  12.     left-adjusted in a line, where TOPIC is some topic string.  That
  13.     help text ends on the EOF or the next @ line.
  14.  
  15.     The file name is found from the environment variable QPHELP if
  16.     it exists, otherwise from the current directory.
  17.     */
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include "help.h"
  22.  
  23. #ifdef MSDOS
  24. #  include <stdlib.h>
  25. #endif
  26.  
  27. /* .............. */
  28. void help(topic)
  29.   char *topic;
  30. { FILE *hfile;
  31.   char *helpfile, line[81], rch, *lp, *getenv();
  32.   int  more, lines, topic_found= 0;
  33.  
  34.   helpfile= getenv(QPHELP);
  35.   if (helpfile==NULL) helpfile= DEFAULT_HELP;
  36.  
  37.   more= 1;
  38.   if ((hfile= fopen(helpfile, "r"))) {
  39.     while ((more= (fgets(line, 80, hfile)!=NULL))) 
  40.       if (*line=='@') break;   /* get over the preamble */
  41.     while (more) {
  42.       if (*line=='@') {  /* here's a potential topic line */
  43.         if (strncmp(line+1, topic, strlen(topic))==0) {
  44.           topic_found= 1;
  45.           printf("\n- - - - - H E L P  on  %s - - - - - -\n", topic);
  46.           lines= 0;
  47.           while ((more= (fgets(line, 79, hfile)!=NULL))) {
  48.             if (*line=='@') break;  /* end of this topic */
  49.             lines++;
  50.             if (lines > SHOWLINES) {
  51.               rch= resp(" --- more? (SPACE to continue, ENTER to return) ---");
  52.               if (rch=='\n') break;
  53.               lines= 0;
  54.               }
  55.             printf("%s", line);
  56.             }
  57.           more= 0;
  58.           }
  59.         }
  60.       if (more) more= (fgets(line, 80, hfile)!=NULL);
  61.       if (!more &&
  62.           !topic_found) printf("Sorry, no help on %s\n", topic);
  63.       }
  64.     fclose(hfile);
  65.     }
  66.   else printf("Sorry, help file %s is not accessible\n", helpfile);
  67.   }
  68.  
  69.