Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / texinfo / info / m-x.c
blob9785955c13d80e88321dfbb175ceb9870483962b
1 /* $NetBSD$ */
3 /* m-x.c -- Meta-x minibuffer reader.
4 Id: m-x.c,v 1.3 2004/04/11 17:56:46 karl Exp
6 Copyright (C) 1993, 1997, 1998, 2001, 2002, 2004 Free Software
7 Foundation, Inc.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Originally written by Brian Fox (bfox@ai.mit.edu). */
25 #include "info.h"
26 #include "funs.h"
28 /* **************************************************************** */
29 /* */
30 /* Reading Named Commands */
31 /* */
32 /* **************************************************************** */
34 /* Read the name of an Info function in the echo area and return the
35 name. A return value of NULL indicates that no function name could
36 be read. */
37 char *
38 read_function_name (char *prompt, WINDOW *window)
40 register int i;
41 char *line;
42 REFERENCE **array = (REFERENCE **)NULL;
43 int array_index = 0, array_slots = 0;
45 /* Make an array of REFERENCE which actually contains the names of
46 the functions available in Info. */
47 for (i = 0; function_doc_array[i].func; i++)
49 REFERENCE *entry;
51 entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
52 entry->label = xstrdup (function_doc_array[i].func_name);
53 entry->nodename = (char *)NULL;
54 entry->filename = (char *)NULL;
56 add_pointer_to_array
57 (entry, array_index, array, array_slots, 200, REFERENCE *);
60 line = info_read_completing_in_echo_area (window, prompt, array);
62 info_free_references (array);
64 if (!echo_area_is_active)
65 window_clear_echo_area ();
67 return (line);
70 DECLARE_INFO_COMMAND (describe_command,
71 _("Read the name of an Info command and describe it"))
73 char *line;
75 line = read_function_name ((char *) _("Describe command: "), window);
77 if (!line)
79 info_abort_key (active_window, count, key);
80 return;
83 /* Describe the function named in "LINE". */
84 if (*line)
86 InfoCommand *cmd = named_function (line);
88 if (!cmd)
89 return;
91 window_message_in_echo_area ("%s: %s.",
92 line, function_documentation (cmd));
94 free (line);
97 DECLARE_INFO_COMMAND (info_execute_command,
98 _("Read a command name in the echo area and execute it"))
100 char *line;
101 char *keys;
102 char *prompt;
104 prompt = (char *)xmalloc (20);
106 keys = where_is (info_keymap, InfoCmd(info_execute_command));
107 /* If the where_is () function thinks that this command doesn't exist,
108 there's something very wrong! */
109 if (!keys)
110 abort();
112 if (info_explicit_arg || count != 1)
113 sprintf (prompt, "%d %s ", count, keys);
114 else
115 sprintf (prompt, "%s ", keys);
117 /* Ask the completer to read a reference for us. */
118 line = read_function_name (prompt, window);
120 /* User aborted? */
121 if (!line)
123 info_abort_key (active_window, count, key);
124 return;
127 /* User accepted "default"? (There is none.) */
128 if (!*line)
130 free (line);
131 return;
134 /* User wants to execute a named command. Do it. */
136 InfoCommand *command;
138 if ((active_window != the_echo_area) &&
139 (strncmp (line, "echo-area-", 10) == 0))
141 free (line);
142 info_error ((char *) _("Cannot execute an `echo-area' command here."),
143 NULL, NULL);
144 return;
147 command = named_function (line);
148 free (line);
150 if (!command)
151 return;
153 if (InfoFunction(command))
154 (*InfoFunction(command)) (active_window, count, 0);
155 else
156 info_error ((char *) _("Undefined command: %s"), line, NULL);
160 /* Okay, now that we have M-x, let the user set the screen height. */
161 DECLARE_INFO_COMMAND (set_screen_height,
162 _("Set the height of the displayed window"))
164 int new_height, old_height = screenheight;
166 if (info_explicit_arg || count != 1)
167 new_height = count;
168 else
170 char prompt[80];
171 char *line;
173 new_height = screenheight;
175 sprintf (prompt, _("Set screen height to (%d): "), new_height);
177 line = info_read_in_echo_area (window, prompt);
179 /* If the user aborted, do that now. */
180 if (!line)
182 info_abort_key (active_window, count, 0);
183 return;
186 /* Find out what the new height is supposed to be. */
187 if (*line)
188 new_height = atoi (line);
190 /* Clear the echo area if it isn't active. */
191 if (!echo_area_is_active)
192 window_clear_echo_area ();
194 free (line);
197 terminal_clear_screen ();
198 display_clear_display (the_display);
199 screenheight = new_height;
200 #ifdef SET_SCREEN_SIZE_HELPER
201 SET_SCREEN_SIZE_HELPER;
202 #endif
203 if (screenheight == old_height)
205 /* Display dimensions didn't actually change, so
206 window_new_screen_size won't do anything, but we've
207 already cleared the display above. Undo the damage. */
208 window_mark_chain (windows, W_UpdateWindow);
209 display_update_display (windows);
211 else
213 display_initialize_display (screenwidth, screenheight);
214 window_new_screen_size (screenwidth, screenheight);