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