home *** CD-ROM | disk | FTP | other *** search
- /* help.c
-
- QCAD Systems, Inc.
-
- Provides help based on a helpfile and a topic.
- The initial lines of a helpfile are ignored.
-
- The help itself starts with
-
- @TOPIC
-
- left-adjusted in a line, where TOPIC is some topic string. That
- help text ends on the EOF or the next @ line.
-
- The file name is found from the environment variable QPHELP if
- it exists, otherwise from the current directory.
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include "help.h"
-
- #ifdef MSDOS
- # include <stdlib.h>
- #endif
-
- /* .............. */
- void help(topic)
- char *topic;
- { FILE *hfile;
- char *helpfile, line[81], rch, *lp, *getenv();
- int more, lines, topic_found= 0;
-
- helpfile= getenv(QPHELP);
- if (helpfile==NULL) helpfile= DEFAULT_HELP;
-
- more= 1;
- if ((hfile= fopen(helpfile, "r"))) {
- while ((more= (fgets(line, 80, hfile)!=NULL)))
- if (*line=='@') break; /* get over the preamble */
- while (more) {
- if (*line=='@') { /* here's a potential topic line */
- if (strncmp(line+1, topic, strlen(topic))==0) {
- topic_found= 1;
- printf("\n- - - - - H E L P on %s - - - - - -\n", topic);
- lines= 0;
- while ((more= (fgets(line, 79, hfile)!=NULL))) {
- if (*line=='@') break; /* end of this topic */
- lines++;
- if (lines > SHOWLINES) {
- rch= resp(" --- more? (SPACE to continue, ENTER to return) ---");
- if (rch=='\n') break;
- lines= 0;
- }
- printf("%s", line);
- }
- more= 0;
- }
- }
- if (more) more= (fgets(line, 80, hfile)!=NULL);
- if (!more &&
- !topic_found) printf("Sorry, no help on %s\n", topic);
- }
- fclose(hfile);
- }
- else printf("Sorry, help file %s is not accessible\n", helpfile);
- }
-