171
|
1 /* variables.c -- How to manipulate user visible variables in Info. */ |
|
2 |
|
3 /* This file is part of GNU Info, a program for reading online documentation |
|
4 stored in Info format. |
|
5 |
|
6 Copyright (C) 1993 Free Software Foundation, Inc. |
|
7 |
|
8 This program is free software; you can redistribute it and/or modify |
|
9 it under the terms of the GNU General Public License as published by |
|
10 the Free Software Foundation; either version 2, or (at your option) |
|
11 any later version. |
|
12 |
|
13 This program is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with this program; if not, write to the Free Software |
|
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 Written by Brian Fox (bfox@ai.mit.edu). */ |
|
23 |
1242
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
171
|
28 #include "info.h" |
|
29 #include "variables.h" |
|
30 |
|
31 /* **************************************************************** */ |
|
32 /* */ |
|
33 /* User Visible Variables in Info */ |
|
34 /* */ |
|
35 /* **************************************************************** */ |
|
36 |
|
37 /* Choices used by the completer when reading a zero/non-zero value for |
|
38 a variable. */ |
|
39 static char *on_off_choices[] = { "Off", "On", (char *)NULL }; |
|
40 |
|
41 VARIABLE_ALIST info_variables[] = { |
|
42 { "automatic-footnotes", |
|
43 "When \"On\", footnotes appear and disappear automatically", |
|
44 &auto_footnotes_p, (char **)on_off_choices }, |
|
45 |
|
46 { "automatic-tiling", |
|
47 "When \"On\", creating or deleting a window resizes other windows", |
|
48 &auto_tiling_p, (char **)on_off_choices }, |
|
49 |
|
50 { "visible-bell", |
|
51 "When \"On\", flash the screen instead of ringing the bell", |
|
52 &terminal_use_visible_bell_p, (char **)on_off_choices }, |
|
53 |
|
54 { "errors-ring-bell", |
|
55 "When \"On\", errors cause the bell to ring", |
|
56 &info_error_rings_bell_p, (char **)on_off_choices }, |
|
57 |
|
58 { "gc-compressed-files", |
|
59 "When \"On\", Info garbage collects files which had to be uncompressed", |
|
60 &gc_compressed_files, (char **)on_off_choices }, |
|
61 { "show-index-match", |
|
62 "When \"On\", the portion of the matched search string is highlighted", |
|
63 &show_index_match, (char **)on_off_choices }, |
|
64 |
|
65 { "scroll-behaviour", |
|
66 "Controls what happens when scrolling is requested at the end of a node", |
|
67 &info_scroll_behaviour, (char **)info_scroll_choices }, |
|
68 |
|
69 { "scroll-step", |
|
70 "The number lines to scroll when the cursor moves out of the window", |
|
71 &window_scroll_step, (char **)NULL }, |
|
72 |
|
73 { "ISO-Latin", |
|
74 "When \"On\", Info accepts and displays ISO Latin characters", |
|
75 &ISO_Latin_p, (char **)on_off_choices }, |
|
76 |
|
77 { (char *)NULL, (char *)NULL, (int *)NULL, (char **)NULL } |
|
78 }; |
|
79 |
|
80 DECLARE_INFO_COMMAND (describe_variable, "Explain the use of a variable") |
|
81 { |
|
82 VARIABLE_ALIST *var; |
|
83 char *description; |
|
84 |
|
85 /* Get the variable's name. */ |
|
86 var = read_variable_name ("Describe variable: ", window); |
|
87 |
|
88 if (!var) |
|
89 return; |
|
90 |
|
91 description = (char *)xmalloc (20 + strlen (var->name) + strlen (var->doc)); |
|
92 |
|
93 if (var->choices) |
|
94 sprintf (description, "%s (%s): %s.", |
|
95 var->name, var->choices[*(var->value)], var->doc); |
|
96 else |
|
97 sprintf (description, "%s (%d): %s.", var->name, *(var->value), var->doc); |
|
98 |
|
99 window_message_in_echo_area ("%s", description); |
|
100 free (description); |
|
101 } |
|
102 |
|
103 DECLARE_INFO_COMMAND (set_variable, "Set the value of an Info variable") |
|
104 { |
|
105 VARIABLE_ALIST *var; |
|
106 char *line; |
|
107 |
|
108 /* Get the variable's name and value. */ |
|
109 var = read_variable_name ("Set variable: ", window); |
|
110 |
|
111 if (!var) |
|
112 return; |
|
113 |
|
114 /* Read a new value for this variable. */ |
|
115 { |
|
116 char prompt[100]; |
|
117 |
|
118 if (!var->choices) |
|
119 { |
|
120 int potential_value; |
|
121 |
|
122 if (info_explicit_arg || count != 1) |
|
123 potential_value = count; |
|
124 else |
|
125 potential_value = *(var->value); |
|
126 |
|
127 sprintf (prompt, "Set %s to value (%d): ", |
|
128 var->name, potential_value); |
|
129 line = info_read_in_echo_area (active_window, prompt); |
|
130 |
|
131 /* If no error was printed, clear the echo area. */ |
|
132 if (!info_error_was_printed) |
|
133 window_clear_echo_area (); |
|
134 |
|
135 /* User aborted? */ |
|
136 if (!line) |
|
137 return; |
|
138 |
|
139 /* If the user specified a value, get that, otherwise, we are done. */ |
|
140 canonicalize_whitespace (line); |
|
141 if (*line) |
|
142 *(var->value) = atoi (line); |
|
143 else |
|
144 *(var->value) = potential_value; |
|
145 |
|
146 free (line); |
|
147 } |
|
148 else |
|
149 { |
|
150 register int i; |
|
151 REFERENCE **array = (REFERENCE **)NULL; |
|
152 int array_index = 0; |
|
153 int array_slots = 0; |
|
154 |
|
155 for (i = 0; var->choices[i]; i++) |
|
156 { |
|
157 REFERENCE *entry; |
|
158 |
|
159 entry = (REFERENCE *)xmalloc (sizeof (REFERENCE)); |
|
160 entry->label = savestring (var->choices[i]); |
|
161 entry->nodename = (char *)NULL; |
|
162 entry->filename = (char *)NULL; |
|
163 |
|
164 add_pointer_to_array |
|
165 (entry, array_index, array, array_slots, 10, REFERENCE *); |
|
166 } |
|
167 |
|
168 sprintf (prompt, "Set %s to value (%s): ", |
|
169 var->name, var->choices[*(var->value)]); |
|
170 |
|
171 /* Ask the completer to read a variable value for us. */ |
|
172 line = info_read_completing_in_echo_area (window, prompt, array); |
|
173 |
|
174 info_free_references (array); |
|
175 |
|
176 if (!echo_area_is_active) |
|
177 window_clear_echo_area (); |
|
178 |
|
179 /* User aborted? */ |
|
180 if (!line) |
|
181 { |
|
182 info_abort_key (active_window, 0, 0); |
|
183 return; |
|
184 } |
|
185 |
|
186 /* User accepted default choice? If so, no change. */ |
|
187 if (!*line) |
|
188 { |
|
189 free (line); |
|
190 return; |
|
191 } |
|
192 |
|
193 /* Find the choice in our list of choices. */ |
|
194 for (i = 0; var->choices[i]; i++) |
|
195 if (strcmp (var->choices[i], line) == 0) |
|
196 break; |
|
197 |
|
198 if (var->choices[i]) |
|
199 *(var->value) = i; |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 /* Read the name of an Info variable in the echo area and return the |
|
205 address of a VARIABLE_ALIST member. A return value of NULL indicates |
|
206 that no variable could be read. */ |
|
207 VARIABLE_ALIST * |
|
208 read_variable_name (prompt, window) |
|
209 char *prompt; |
|
210 WINDOW *window; |
|
211 { |
|
212 register int i; |
|
213 char *line; |
|
214 REFERENCE **variables; |
|
215 |
|
216 /* Get the completion array of variable names. */ |
|
217 variables = make_variable_completions_array (); |
|
218 |
|
219 /* Ask the completer to read a variable for us. */ |
|
220 line = |
|
221 info_read_completing_in_echo_area (window, prompt, variables); |
|
222 |
|
223 info_free_references (variables); |
|
224 |
|
225 if (!echo_area_is_active) |
|
226 window_clear_echo_area (); |
|
227 |
|
228 /* User aborted? */ |
|
229 if (!line) |
|
230 { |
|
231 info_abort_key (active_window, 0, 0); |
|
232 return ((VARIABLE_ALIST *)NULL); |
|
233 } |
|
234 |
|
235 /* User accepted "default"? (There is none.) */ |
|
236 if (!*line) |
|
237 { |
|
238 free (line); |
|
239 return ((VARIABLE_ALIST *)NULL); |
|
240 } |
|
241 |
|
242 /* Find the variable in our list of variables. */ |
|
243 for (i = 0; info_variables[i].name; i++) |
|
244 if (strcmp (info_variables[i].name, line) == 0) |
|
245 break; |
|
246 |
|
247 if (!info_variables[i].name) |
|
248 return ((VARIABLE_ALIST *)NULL); |
|
249 else |
|
250 return (&(info_variables[i])); |
|
251 } |
|
252 |
|
253 /* Make an array of REFERENCE which actually contains the names of the |
|
254 variables available in Info. */ |
|
255 REFERENCE ** |
|
256 make_variable_completions_array () |
|
257 { |
|
258 register int i; |
|
259 REFERENCE **array = (REFERENCE **)NULL; |
|
260 int array_index = 0, array_slots = 0; |
|
261 |
|
262 for (i = 0; info_variables[i].name; i++) |
|
263 { |
|
264 REFERENCE *entry; |
|
265 |
|
266 entry = (REFERENCE *)xmalloc (sizeof (REFERENCE)); |
|
267 entry->label = savestring (info_variables[i].name); |
|
268 entry->nodename = (char *)NULL; |
|
269 entry->filename = (char *)NULL; |
|
270 |
|
271 add_pointer_to_array |
|
272 (entry, array_index, array, array_slots, 200, REFERENCE *); |
|
273 } |
|
274 |
|
275 return (array); |
|
276 } |