home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games (Alt) / INFESPGAMES.iso / os2 / backgam / source / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-10  |  3.0 KB  |  89 lines

  1. /*************************************************************
  2.  *    ______                                                 *
  3.  *   /     /\  TinyFugue was derived from a client initially *
  4.  *  /   __/  \ written by Anton Rang (Tarrant) and later     *
  5.  *  |  / /\  | modified by Leo Plotkin (Grod).  The early    *
  6.  *  |  |/    | versions of TinyFugue written by Greg Hudson  *
  7.  *  |  X__/  | (Explorer_Bob).  The current version is       *
  8.  *  \ /      / written and maintained by Ken Keys (Hawkeye), *
  9.  *   \______/  who can be reached at kkeys@ucsd.edu.         *
  10.  *                                                           *
  11.  *             No copyright 1992, no rights reserved.        *
  12.  *             Fugue is in the public domain.                *
  13.  *************************************************************/
  14.  
  15. /****************************************************************
  16.  * Fugue help handling                                          *
  17.  *                                                              *
  18.  * Uses the help index to search the helpfile for a topic.      *
  19.  *                                                              *
  20.  * Algorithm developed by Leo Plotkin.  Code rewritten by Greg  *
  21.  * Hudson and Ken Keys to work with rest of program.            *
  22.  ****************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include "tf.h"
  26. #include "dstring.h"
  27. #include "util.h"
  28. #include "output.h"
  29.  
  30. void FDECL(do_help,(char *what));
  31.  
  32. void do_help(what) 
  33.     char *what;
  34. {
  35.     static Stringp indexfname, input;
  36.     static int strings_inited = FALSE;
  37.     FILE *indexfile;
  38.     TFILE *helpfile;
  39.     long offset = -1;
  40.     char *place;
  41.  
  42.     if (!strings_inited) {
  43.         Stringinit(indexfname);
  44.         Stringinit(input);
  45.         strings_inited = TRUE;
  46.     }
  47.     if (!*what) what = "summary";
  48.  
  49.     if ((helpfile = tfopen("", "HELPFILE", "r")) == NULL) return;
  50.     Sprintf(indexfname, "tf.idx");
  51.     if ((indexfile = fopen(indexfname->s, "r")) == NULL) {
  52.         oputs("% Could not open help index.");
  53.         tfclose(helpfile);
  54.         return;
  55.     }
  56.  
  57.     while (fgetS(input, indexfile) != NULL) {
  58.         newline_package(input, 0);
  59.         place = strchr(input->s, ':');
  60.         if (place == NULL) {
  61.             oputs("% Error in indexfile");
  62.             return;
  63.         } else place++;
  64.         if (!cstrcmp(place, what)) {
  65.             offset = atol(input->s);
  66.             break;
  67.         }
  68.     }
  69.     fclose(indexfile);
  70.     if (offset == -1) {
  71.         oprintf("%% Help on subject %s not found.", what);
  72.         tfclose(helpfile);
  73.         return;
  74.     }
  75.  
  76.     /* find offset and skip lines starting with "@@@@" */
  77.     tfjump(helpfile, offset);
  78.     while (tfgetS(input, helpfile) != NULL)
  79.         if (strncmp(input->s, "@@@@", 4) != 0) break;
  80.  
  81.     oprintf("Help on topic %s:", what);
  82.     do {
  83.         if (strncmp(input->s, "@@@@", 4) == 0) break;
  84.         newline_package(input, 0);
  85.         oputs(input->s);
  86.     } while (tfgetS(input, helpfile) != NULL);
  87.     tfclose(helpfile);
  88. }
  89.