m-x.c revision 21495
121495Sjmacd/* m-x.c -- Meta-X minibuffer reader. */ 221495Sjmacd 321495Sjmacd/* This file is part of GNU Info, a program for reading online documentation 421495Sjmacd stored in Info format. 521495Sjmacd 621495Sjmacd Copyright (C) 1993 Free Software Foundation, Inc. 721495Sjmacd 821495Sjmacd This program is free software; you can redistribute it and/or modify 921495Sjmacd it under the terms of the GNU General Public License as published by 1021495Sjmacd the Free Software Foundation; either version 2, or (at your option) 1121495Sjmacd any later version. 1221495Sjmacd 1321495Sjmacd This program is distributed in the hope that it will be useful, 1421495Sjmacd but WITHOUT ANY WARRANTY; without even the implied warranty of 1521495Sjmacd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1621495Sjmacd GNU General Public License for more details. 1721495Sjmacd 1821495Sjmacd You should have received a copy of the GNU General Public License 1921495Sjmacd along with this program; if not, write to the Free Software 2021495Sjmacd Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 2121495Sjmacd 2221495Sjmacd Written by Brian Fox (bfox@ai.mit.edu). */ 2321495Sjmacd 2421495Sjmacd#include "info.h" 2521495Sjmacd 2621495Sjmacd/* **************************************************************** */ 2721495Sjmacd/* */ 2821495Sjmacd/* Reading Named Commands */ 2921495Sjmacd/* */ 3021495Sjmacd/* **************************************************************** */ 3121495Sjmacd 3221495Sjmacd/* Read the name of an Info function in the echo area and return the 3321495Sjmacd name. A return value of NULL indicates that no function name could 3421495Sjmacd be read. */ 3521495Sjmacdchar * 3621495Sjmacdread_function_name (prompt, window) 3721495Sjmacd char *prompt; 3821495Sjmacd WINDOW *window; 3921495Sjmacd{ 4021495Sjmacd register int i; 4121495Sjmacd char *line; 4221495Sjmacd REFERENCE **array = (REFERENCE **)NULL; 4321495Sjmacd int array_index = 0, array_slots = 0; 4421495Sjmacd 4521495Sjmacd /* Make an array of REFERENCE which actually contains the names of 4621495Sjmacd the functions available in Info. */ 4721495Sjmacd for (i = 0; function_doc_array[i].func; i++) 4821495Sjmacd { 4921495Sjmacd REFERENCE *entry; 5021495Sjmacd 5121495Sjmacd entry = (REFERENCE *)xmalloc (sizeof (REFERENCE)); 5221495Sjmacd entry->label = strdup (function_doc_array[i].func_name); 5321495Sjmacd entry->nodename = (char *)NULL; 5421495Sjmacd entry->filename = (char *)NULL; 5521495Sjmacd 5621495Sjmacd add_pointer_to_array 5721495Sjmacd (entry, array_index, array, array_slots, 200, REFERENCE *); 5821495Sjmacd } 5921495Sjmacd 6021495Sjmacd line = info_read_completing_in_echo_area (window, prompt, array); 6121495Sjmacd 6221495Sjmacd info_free_references (array); 6321495Sjmacd 6421495Sjmacd if (!echo_area_is_active) 6521495Sjmacd window_clear_echo_area (); 6621495Sjmacd 6721495Sjmacd return (line); 6821495Sjmacd} 6921495Sjmacd 7021495SjmacdDECLARE_INFO_COMMAND (describe_command, 7121495Sjmacd "Read the name of an Info command and describe it") 7221495Sjmacd{ 7321495Sjmacd char *line; 7421495Sjmacd 7521495Sjmacd line = read_function_name ("Describe command: ", window); 7621495Sjmacd 7721495Sjmacd if (!line) 7821495Sjmacd { 7921495Sjmacd info_abort_key (active_window, count, key); 8021495Sjmacd return; 8121495Sjmacd } 8221495Sjmacd 8321495Sjmacd /* Describe the function named in "LINE". */ 8421495Sjmacd if (*line) 8521495Sjmacd { 8621495Sjmacd char *fundoc; 8721495Sjmacd VFunction *fun; 8821495Sjmacd 8921495Sjmacd fun = named_function (line); 9021495Sjmacd 9121495Sjmacd if (!fun) 9221495Sjmacd return; 9321495Sjmacd 9421495Sjmacd window_message_in_echo_area ("%s: %s.", 9521495Sjmacd line, function_documentation (fun)); 9621495Sjmacd } 9721495Sjmacd free (line); 9821495Sjmacd} 9921495Sjmacd 10021495SjmacdDECLARE_INFO_COMMAND (info_execute_command, 10121495Sjmacd "Read a command name in the echo area and execute it") 10221495Sjmacd{ 10321495Sjmacd char *line; 10421495Sjmacd 10521495Sjmacd /* Ask the completer to read a reference for us. */ 10621495Sjmacd if (info_explicit_arg || count != 1) 10721495Sjmacd { 10821495Sjmacd char *prompt; 10921495Sjmacd 11021495Sjmacd prompt = (char *)xmalloc (20); 11121495Sjmacd sprintf (prompt, "%d M-x ", count); 11221495Sjmacd line = read_function_name (prompt, window); 11321495Sjmacd } 11421495Sjmacd else 11521495Sjmacd line = read_function_name ("M-x ", window); 11621495Sjmacd 11721495Sjmacd /* User aborted? */ 11821495Sjmacd if (!line) 11921495Sjmacd { 12021495Sjmacd info_abort_key (active_window, count, key); 12121495Sjmacd return; 12221495Sjmacd } 12321495Sjmacd 12421495Sjmacd /* User accepted "default"? (There is none.) */ 12521495Sjmacd if (!*line) 12621495Sjmacd { 12721495Sjmacd free (line); 12821495Sjmacd return; 12921495Sjmacd } 13021495Sjmacd 13121495Sjmacd /* User wants to execute a named command. Do it. */ 13221495Sjmacd { 13321495Sjmacd VFunction *function; 13421495Sjmacd 13521495Sjmacd if ((active_window != the_echo_area) && 13621495Sjmacd (strncmp (line, "echo-area-", 10) == 0)) 13721495Sjmacd { 13821495Sjmacd free (line); 13921495Sjmacd info_error ("Cannot execute an `echo-area' command here."); 14021495Sjmacd return; 14121495Sjmacd } 14221495Sjmacd 14321495Sjmacd function = named_function (line); 14421495Sjmacd free (line); 14521495Sjmacd 14621495Sjmacd if (!function) 14721495Sjmacd return; 14821495Sjmacd 14921495Sjmacd (*function) (active_window, count, 0); 15021495Sjmacd } 15121495Sjmacd} 15221495Sjmacd 15321495Sjmacd/* Okay, now that we have M-x, let the user set the screen height. */ 15421495SjmacdDECLARE_INFO_COMMAND (set_screen_height, 15521495Sjmacd "Set the height of the displayed window") 15621495Sjmacd{ 15721495Sjmacd int new_height; 15821495Sjmacd 15921495Sjmacd if (info_explicit_arg || count != 1) 16021495Sjmacd new_height = count; 16121495Sjmacd else 16221495Sjmacd { 16321495Sjmacd char prompt[80]; 16421495Sjmacd char *line; 16521495Sjmacd 16621495Sjmacd new_height = screenheight; 16721495Sjmacd 16821495Sjmacd sprintf (prompt, "Set screen height to (%d): ", new_height); 16921495Sjmacd 17021495Sjmacd line = info_read_in_echo_area (window, prompt); 17121495Sjmacd 17221495Sjmacd /* If the user aborted, do that now. */ 17321495Sjmacd if (!line) 17421495Sjmacd { 17521495Sjmacd info_abort_key (active_window, count, 0); 17621495Sjmacd return; 17721495Sjmacd } 17821495Sjmacd 17921495Sjmacd /* Find out what the new height is supposed to be. */ 18021495Sjmacd if (*line) 18121495Sjmacd new_height = atoi (line); 18221495Sjmacd 18321495Sjmacd /* Clear the echo area if it isn't active. */ 18421495Sjmacd if (!echo_area_is_active) 18521495Sjmacd window_clear_echo_area (); 18621495Sjmacd 18721495Sjmacd free (line); 18821495Sjmacd } 18921495Sjmacd 19021495Sjmacd terminal_clear_screen (); 19121495Sjmacd display_clear_display (the_display); 19221495Sjmacd screenheight = new_height; 19321495Sjmacd display_initialize_display (screenwidth, screenheight); 19421495Sjmacd window_new_screen_size (screenwidth, screenheight); 19521495Sjmacd} 196