home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume8 / gnuplot1.10A / part07 / help / input_choice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-09  |  2.6 KB  |  122 lines

  1. /*
  2.  * Program    : help
  3.  * Module    : input_choice.c
  4.  * Programmer    : R. Stolfa
  5.  *
  6.  * Purpose :    To selectively change the current help subject
  7.  *        based on what topic the user chooses to learn
  8.  *        about next.
  9.  *
  10.  * Modification History:
  11.  *   08/26/87    Created
  12.  */
  13.  
  14. #include    "global.h"
  15.  
  16. input_choice ()
  17. {
  18.     int    done,            /* need to parse DIRFILE again */
  19.         i,            /* temp */
  20.         j,            /* temp */
  21.         count,            /* num. of acronym topics that mached */
  22.         topics;            /* num. of topics at this level */
  23.     char    buff[BSIZE],        /* input buffer */
  24.         tmp_path[BSIZE];    /* holding place for cur_path */
  25.     struct    LIST    *p;        /* temp */
  26.  
  27.     done = FALSE;
  28.     do {
  29.         present ("HELP ", " > ");
  30.  
  31.         if (fgets (buff, BSIZE, stdin) == NULL)
  32.             /*
  33.              * End help on EOF
  34.              */
  35.             return (TRUE);
  36.  
  37.         /*
  38.          * Strip junk out of line
  39.          */
  40.         for (i = 0, j = 0; i < strlen(buff); i ++) {
  41.             if (buff[i] == '\n')
  42.                 buff[i] = '\0';
  43.             if (!isspace(buff[i]))
  44.                 buff[j++] = toupper(buff[i]);
  45.         }
  46.  
  47.         if (strlen(buff) == 0) {
  48.             /*
  49.              * At this point, we have a request to recurse
  50.              * back out of the help tree by one level.
  51.              */
  52.             for (i = strlen (cur_path); cur_path[i] != '/'; --i)
  53.                 ;
  54.             cur_path[i] = '\0';
  55.             return (UP);
  56.             /* NOT REACHED */
  57.         }
  58.  
  59.         /*
  60.          * OK.  We have the topic that the user has requested.
  61.          * Now let's try to find some reference to it
  62.          */
  63.         count = 0;
  64.         topics = 0;
  65.         free_list (TOPIC);
  66.         for (p = acr_list; p != NULL ; p = p->prev) {
  67.             if (strncmp (buff, p->topic, strlen(buff)) == 0) {
  68.                 insert (TOPIC,
  69.                     p->base, p->topic, p->cmd);
  70.                 count ++;
  71.             }
  72.             topics ++;
  73.         }
  74.  
  75.         if (count == 0) {
  76.             if (strcmp (buff, "?") != 0) {
  77.                 present ("Sorry, no documentation on ", " ");
  78.                 printf ("%s\n", buff);
  79.             }
  80.             if (topics > 0) {
  81.                 printf ("Additional information available:\n");
  82.                 lines = 2;
  83.                 format_help();
  84.             }
  85.             done = FALSE;
  86.         } else if (count == 1) {
  87.             if (top_list->cmd[0] == '\0') {
  88.                /*
  89.                 * We have only one help subtopic, so traverse
  90.                 * the tree down that link.
  91.                 */
  92.                sprintf (cur_path, "%s/%s", cur_path,
  93.                    top_list->base);
  94.                done = TRUE;
  95.                            }
  96.             else {
  97.                            system(top_list->cmd);
  98.                            return (UP);
  99.                            }
  100.         } else {
  101.             /*
  102.              * We have several matches.  Therefore, page the
  103.              * HELPFILE for each to the screen and stay where
  104.              * we are.
  105.              */
  106.             lines = 0;
  107.             strcpy (tmp_path, cur_path);
  108.             for (p = top_list; p != NULL ; p = p->prev) {
  109.                 if (p->cmd[0] == '\0') {
  110.                    sprintf (cur_path, "%s/%s", tmp_path,
  111.                        p->base);
  112.                    gen_path(HELPFILE);
  113.                    help();
  114.                    strcpy (cur_path, tmp_path);
  115.                    }
  116.             }
  117.         }
  118.  
  119.     } while (done != TRUE);
  120.     return (FALSE);
  121. }
  122.