MFC 1.45 for the 2.0 release: Properly set B_INVAL after failed read.
[dragonfly.git] / contrib / texinfo-4 / info / m-x.c
blob52365d1843ee15d3ed16752f82e18558bc3f213d
1 /* m-x.c -- Meta-x minibuffer reader.
2 $Id: m-x.c,v 1.3 2004/04/11 17:56:46 karl Exp $
4 Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004 Free Software
5 Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Originally written by Brian Fox (bfox@ai.mit.edu). */
23 #include "info.h"
24 #include "funs.h"
26 /* **************************************************************** */
27 /* */
28 /* Reading Named Commands */
29 /* */
30 /* **************************************************************** */
32 /* Read the name of an Info function in the echo area and return the
33 name. A return value of NULL indicates that no function name could
34 be read. */
35 char *
36 read_function_name (char *prompt, WINDOW *window)
38 register int i;
39 char *line;
40 REFERENCE **array = (REFERENCE **)NULL;
41 int array_index = 0, array_slots = 0;
43 /* Make an array of REFERENCE which actually contains the names of
44 the functions available in Info. */
45 for (i = 0; function_doc_array[i].func; i++)
47 REFERENCE *entry;
49 entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
50 entry->label = xstrdup (function_doc_array[i].func_name);
51 entry->nodename = (char *)NULL;
52 entry->filename = (char *)NULL;
54 add_pointer_to_array
55 (entry, array_index, array, array_slots, 200, REFERENCE *);
58 line = info_read_completing_in_echo_area (window, prompt, array);
60 info_free_references (array);
62 if (!echo_area_is_active)
63 window_clear_echo_area ();
65 return (line);
68 DECLARE_INFO_COMMAND (describe_command,
69 _("Read the name of an Info command and describe it"))
71 char *line;
73 line = read_function_name ((char *) _("Describe command: "), window);
75 if (!line)
77 info_abort_key (active_window, count, key);
78 return;
81 /* Describe the function named in "LINE". */
82 if (*line)
84 InfoCommand *cmd = named_function (line);
86 if (!cmd)
87 return;
89 window_message_in_echo_area ("%s: %s.",
90 line, function_documentation (cmd));
92 free (line);
95 DECLARE_INFO_COMMAND (info_execute_command,
96 _("Read a command name in the echo area and execute it"))
98 char *line;
99 char *keys;
100 char *prompt;
102 prompt = (char *)xmalloc (20);
104 keys = where_is (info_keymap, InfoCmd(info_execute_command));
105 /* If the where_is () function thinks that this command doesn't exist,
106 there's something very wrong! */
107 if (!keys)
108 abort();
110 if (info_explicit_arg || count != 1)
111 sprintf (prompt, "%d %s ", count, keys);
112 else
113 sprintf (prompt, "%s ", keys);
115 /* Ask the completer to read a reference for us. */
116 line = read_function_name (prompt, window);
118 /* User aborted? */
119 if (!line)
121 info_abort_key (active_window, count, key);
122 return;
125 /* User accepted "default"? (There is none.) */
126 if (!*line)
128 free (line);
129 return;
132 /* User wants to execute a named command. Do it. */
134 InfoCommand *command;
136 if ((active_window != the_echo_area) &&
137 (strncmp (line, "echo-area-", 10) == 0))
139 free (line);
140 info_error ((char *) _("Cannot execute an `echo-area' command here."),
141 NULL, NULL);
142 return;
145 command = named_function (line);
146 free (line);
148 if (!command)
149 return;
151 if (InfoFunction(command))
152 (*InfoFunction(command)) (active_window, count, 0);
153 else
154 info_error ((char *) _("Undefined command: %s"), line, NULL);
158 /* Okay, now that we have M-x, let the user set the screen height. */
159 DECLARE_INFO_COMMAND (set_screen_height,
160 _("Set the height of the displayed window"))
162 int new_height, old_height = screenheight;
164 if (info_explicit_arg || count != 1)
165 new_height = count;
166 else
168 char prompt[80];
169 char *line;
171 new_height = screenheight;
173 sprintf (prompt, _("Set screen height to (%d): "), new_height);
175 line = info_read_in_echo_area (window, prompt);
177 /* If the user aborted, do that now. */
178 if (!line)
180 info_abort_key (active_window, count, 0);
181 return;
184 /* Find out what the new height is supposed to be. */
185 if (*line)
186 new_height = atoi (line);
188 /* Clear the echo area if it isn't active. */
189 if (!echo_area_is_active)
190 window_clear_echo_area ();
192 free (line);
195 terminal_clear_screen ();
196 display_clear_display (the_display);
197 screenheight = new_height;
198 #ifdef SET_SCREEN_SIZE_HELPER
199 SET_SCREEN_SIZE_HELPER;
200 #endif
201 if (screenheight == old_height)
203 /* Display dimensions didn't actually change, so
204 window_new_screen_size won't do anything, but we've
205 already cleared the display above. Undo the damage. */
206 window_mark_chain (windows, W_UpdateWindow);
207 display_update_display (windows);
209 else
211 display_initialize_display (screenwidth, screenheight);
212 window_new_screen_size (screenwidth, screenheight);