home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / gnuinfo / Source / c / m-x < prev    next >
Encoding:
Text File  |  1994-10-01  |  4.7 KB  |  197 lines

  1. #include "defines.h"
  2. /* m-x.c -- Meta-X minibuffer reader. */
  3.  
  4. /* This file is part of GNU Info, a program for reading online documentation
  5.    stored in Info format.
  6.  
  7.    Copyright (C) 1993 Free Software Foundation, Inc.
  8.  
  9.    This program is free software; you can redistribute it and/or modify
  10.    it under the terms of the GNU General Public License as published by
  11.    the Free Software Foundation; either version 2, or (at your option)
  12.    any later version.
  13.  
  14.    This program is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU General Public License
  20.    along with this program; if not, write to the Free Software
  21.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23.    Written by Brian Fox (bfox@ai.mit.edu). */
  24.  
  25. #include "info.h"
  26.  
  27. /* **************************************************************** */
  28. /*                                    */
  29. /*               Reading Named Commands                */
  30. /*                                    */
  31. /* **************************************************************** */
  32.  
  33. /* Read the name of an Info function in the echo area and return the
  34.    name.  A return value of NULL indicates that no function name could
  35.    be read. */
  36. char *
  37. read_function_name (prompt, window)
  38.      char *prompt;
  39.      WINDOW *window;
  40. {
  41.   register int i;
  42.   char *line;
  43.   REFERENCE **array = (REFERENCE **)NULL;
  44.   int array_index = 0, array_slots = 0;
  45.  
  46.   /* Make an array of REFERENCE which actually contains the names of
  47.      the functions available in Info. */
  48.   for (i = 0; function_doc_array[i].func; i++)
  49.     {
  50.       REFERENCE *entry;
  51.  
  52.       entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
  53.       entry->label = savestring (function_doc_array[i].func_name);
  54.       entry->nodename = (char *)NULL;
  55.       entry->filename = (char *)NULL;
  56.  
  57.       add_pointer_to_array
  58.     (entry, array_index, array, array_slots, 200, REFERENCE *);
  59.     }
  60.  
  61.   line = info_read_completing_in_echo_area (window, prompt, array);
  62.  
  63.   info_free_references (array);
  64.  
  65.   if (!echo_area_is_active)
  66.     window_clear_echo_area ();
  67.  
  68.   return (line);
  69. }
  70.  
  71. DECLARE_INFO_COMMAND (describe_command,
  72.    "Read the name of an Info command and describe it")
  73. {
  74.   char *line;
  75.  
  76.   line = read_function_name ("Describe command: ", window);
  77.  
  78.   if (!line)
  79.     {
  80.       info_abort_key (active_window, count, key);
  81.       return;
  82.     }
  83.  
  84.   /* Describe the function named in "LINE". */
  85.   if (*line)
  86.     {
  87.       char *fundoc;
  88.       VFunction *fun;
  89.  
  90.       fun = named_function (line);
  91.  
  92.       if (!fun)
  93.     return;
  94.  
  95.       window_message_in_echo_area ("%s: %s.",
  96.                    line, function_documentation (fun));
  97.     }
  98.   free (line);
  99. }
  100.  
  101. DECLARE_INFO_COMMAND (info_execute_command,
  102.    "Read a command name in the echo area and execute it")
  103. {
  104.   char *line;
  105.  
  106.   /* Ask the completer to read a reference for us. */
  107.   if (info_explicit_arg || count != 1)
  108.     {
  109.       char *prompt;
  110.  
  111.       prompt = (char *)xmalloc (20);
  112.       sprintf (prompt, "%d M-x ", count);
  113.       line = read_function_name (prompt, window);
  114.     }
  115.   else
  116.     line = read_function_name ("M-x ", window);
  117.  
  118.   /* User aborted? */
  119.   if (!line)
  120.     {
  121.       info_abort_key (active_window, count, key);
  122.       return;
  123.     }
  124.  
  125.   /* User accepted "default"?  (There is none.) */
  126.   if (!*line)
  127.     {
  128.       free (line);
  129.       return;
  130.     }
  131.  
  132.   /* User wants to execute a named command.  Do it. */
  133.   {
  134.     VFunction *function;
  135.  
  136.     if ((active_window != the_echo_area) &&
  137.     (strncmp (line, "echo-area-", 10) == 0))
  138.       {
  139.     free (line);
  140.     info_error ("Cannot execute an `echo-area' command here.");
  141.     return;
  142.       }
  143.  
  144.     function = named_function (line);
  145.     free (line);
  146.  
  147.     if (!function)
  148.       return;
  149.  
  150.     (*function) (active_window, count, 0);
  151.   }
  152. }
  153.  
  154. /* Okay, now that we have M-x, let the user set the screen height. */
  155. DECLARE_INFO_COMMAND (set_screen_height,
  156.   "Set the height of the displayed window")
  157. {
  158.   int new_height;
  159.  
  160.   if (info_explicit_arg || count != 1)
  161.     new_height = count;
  162.   else
  163.     {
  164.       char prompt[80];
  165.       char *line;
  166.  
  167.       new_height = screenheight;
  168.  
  169.       sprintf (prompt, "Set screen height to (%d): ", new_height);
  170.  
  171.       line = info_read_in_echo_area (window, prompt);
  172.  
  173.       /* If the user aborted, do that now. */
  174.       if (!line)
  175.     {
  176.       info_abort_key (active_window, count, 0);
  177.       return;
  178.     }
  179.  
  180.       /* Find out what the new height is supposed to be. */
  181.       if (*line)
  182.     new_height = atoi (line);
  183.  
  184.       /* Clear the echo area if it isn't active. */
  185.       if (!echo_area_is_active)
  186.     window_clear_echo_area ();
  187.  
  188.       free (line);
  189.     }
  190.  
  191.   terminal_clear_screen ();
  192.   display_clear_display (the_display);
  193.   screenheight = new_height;
  194.   display_initialize_display (screenwidth, screenheight);
  195.   window_new_screen_size (screenwidth, screenheight);
  196. }
  197.