Remove spurious test of XScale and HARD_FLOAT floags
[official-gcc.git] / texinfo / info / variables.c
blobe1c2ac4d2bd694cb59a50da9f3290ee24b49a010
1 /* variables.c -- How to manipulate user visible variables in Info.
2 $Id: variables.c,v 1.1.1.2 1998/03/22 20:43:01 law Exp $
4 This file is part of GNU Info, a program for reading online documentation
5 stored in Info format.
7 Copyright (C) 1993, 97 Free Software 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 Written by Brian Fox (bfox@ai.mit.edu). */
25 #include "info.h"
26 #include "variables.h"
28 /* **************************************************************** */
29 /* */
30 /* User Visible Variables in Info */
31 /* */
32 /* **************************************************************** */
34 /* Choices used by the completer when reading a zero/non-zero value for
35 a variable. */
36 static char *on_off_choices[] = { "Off", "On", (char *)NULL };
38 VARIABLE_ALIST info_variables[] = {
39 { "automatic-footnotes",
40 N_("When \"On\", footnotes appear and disappear automatically"),
41 &auto_footnotes_p, (char **)on_off_choices },
43 { "automatic-tiling",
44 N_("When \"On\", creating or deleting a window resizes other windows"),
45 &auto_tiling_p, (char **)on_off_choices },
47 { "visible-bell",
48 N_("When \"On\", flash the screen instead of ringing the bell"),
49 &terminal_use_visible_bell_p, (char **)on_off_choices },
51 { "errors-ring-bell",
52 N_("When \"On\", errors cause the bell to ring"),
53 &info_error_rings_bell_p, (char **)on_off_choices },
55 { "gc-compressed-files",
56 N_("When \"On\", Info garbage collects files which had to be uncompressed"),
57 &gc_compressed_files, (char **)on_off_choices },
58 { "show-index-match",
59 N_("When \"On\", the portion of the matched search string is highlighted"),
60 &show_index_match, (char **)on_off_choices },
62 { "scroll-behaviour",
63 N_("Controls what happens when scrolling is requested at the end of a node"),
64 &info_scroll_behaviour, (char **)info_scroll_choices },
66 { "scroll-step",
67 N_("The number lines to scroll when the cursor moves out of the window"),
68 &window_scroll_step, (char **)NULL },
70 { "ISO-Latin",
71 N_("When \"On\", Info accepts and displays ISO Latin characters"),
72 &ISO_Latin_p, (char **)on_off_choices },
74 { (char *)NULL, (char *)NULL, (int *)NULL, (char **)NULL }
77 DECLARE_INFO_COMMAND (describe_variable, _("Explain the use of a variable"))
79 VARIABLE_ALIST *var;
80 char *description;
82 /* Get the variable's name. */
83 var = read_variable_name (_("Describe variable: "), window);
85 if (!var)
86 return;
88 description = (char *)xmalloc (20 + strlen (var->name)
89 + strlen (_(var->doc)));
91 if (var->choices)
92 sprintf (description, "%s (%s): %s.",
93 var->name, var->choices[*(var->value)], _(var->doc));
94 else
95 sprintf (description, "%s (%d): %s.",
96 var->name, *(var->value), _(var->doc));
98 window_message_in_echo_area ("%s", description);
99 free (description);
102 DECLARE_INFO_COMMAND (set_variable, _("Set the value of an Info variable"))
104 VARIABLE_ALIST *var;
105 char *line;
107 /* Get the variable's name and value. */
108 var = read_variable_name (_("Set variable: "), window);
110 if (!var)
111 return;
113 /* Read a new value for this variable. */
115 char prompt[100];
117 if (!var->choices)
119 int potential_value;
121 if (info_explicit_arg || count != 1)
122 potential_value = count;
123 else
124 potential_value = *(var->value);
126 sprintf (prompt, _("Set %s to value (%d): "),
127 var->name, potential_value);
128 line = info_read_in_echo_area (active_window, prompt);
130 /* If no error was printed, clear the echo area. */
131 if (!info_error_was_printed)
132 window_clear_echo_area ();
134 /* User aborted? */
135 if (!line)
136 return;
138 /* If the user specified a value, get that, otherwise, we are done. */
139 canonicalize_whitespace (line);
140 if (*line)
141 *(var->value) = atoi (line);
142 else
143 *(var->value) = potential_value;
145 free (line);
147 else
149 register int i;
150 REFERENCE **array = (REFERENCE **)NULL;
151 int array_index = 0;
152 int array_slots = 0;
154 for (i = 0; var->choices[i]; i++)
156 REFERENCE *entry;
158 entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
159 entry->label = xstrdup (var->choices[i]);
160 entry->nodename = (char *)NULL;
161 entry->filename = (char *)NULL;
163 add_pointer_to_array
164 (entry, array_index, array, array_slots, 10, REFERENCE *);
167 sprintf (prompt, _("Set %s to value (%s): "),
168 var->name, var->choices[*(var->value)]);
170 /* Ask the completer to read a variable value for us. */
171 line = info_read_completing_in_echo_area (window, prompt, array);
173 info_free_references (array);
175 if (!echo_area_is_active)
176 window_clear_echo_area ();
178 /* User aborted? */
179 if (!line)
181 info_abort_key (active_window, 0, 0);
182 return;
185 /* User accepted default choice? If so, no change. */
186 if (!*line)
188 free (line);
189 return;
192 /* Find the choice in our list of choices. */
193 for (i = 0; var->choices[i]; i++)
194 if (strcmp (var->choices[i], line) == 0)
195 break;
197 if (var->choices[i])
198 *(var->value) = i;
203 /* Read the name of an Info variable in the echo area and return the
204 address of a VARIABLE_ALIST member. A return value of NULL indicates
205 that no variable could be read. */
206 VARIABLE_ALIST *
207 read_variable_name (prompt, window)
208 char *prompt;
209 WINDOW *window;
211 register int i;
212 char *line;
213 REFERENCE **variables;
215 /* Get the completion array of variable names. */
216 variables = make_variable_completions_array ();
218 /* Ask the completer to read a variable for us. */
219 line =
220 info_read_completing_in_echo_area (window, prompt, variables);
222 info_free_references (variables);
224 if (!echo_area_is_active)
225 window_clear_echo_area ();
227 /* User aborted? */
228 if (!line)
230 info_abort_key (active_window, 0, 0);
231 return ((VARIABLE_ALIST *)NULL);
234 /* User accepted "default"? (There is none.) */
235 if (!*line)
237 free (line);
238 return ((VARIABLE_ALIST *)NULL);
241 /* Find the variable in our list of variables. */
242 for (i = 0; info_variables[i].name; i++)
243 if (strcmp (info_variables[i].name, line) == 0)
244 break;
246 if (!info_variables[i].name)
247 return ((VARIABLE_ALIST *)NULL);
248 else
249 return (&(info_variables[i]));
252 /* Make an array of REFERENCE which actually contains the names of the
253 variables available in Info. */
254 REFERENCE **
255 make_variable_completions_array ()
257 register int i;
258 REFERENCE **array = (REFERENCE **)NULL;
259 int array_index = 0, array_slots = 0;
261 for (i = 0; info_variables[i].name; i++)
263 REFERENCE *entry;
265 entry = (REFERENCE *) xmalloc (sizeof (REFERENCE));
266 entry->label = xstrdup (info_variables[i].name);
267 entry->nodename = (char *)NULL;
268 entry->filename = (char *)NULL;
270 add_pointer_to_array
271 (entry, array_index, array, array_slots, 200, REFERENCE *);
274 return (array);