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