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
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)
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). */
26 #include "variables.h"
28 /* **************************************************************** */
30 /* User Visible Variables in Info */
32 /* **************************************************************** */
34 /* Choices used by the completer when reading a zero/non-zero value for
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
},
44 N_("When \"On\", creating or deleting a window resizes other windows"),
45 &auto_tiling_p
, (char **)on_off_choices
},
48 N_("When \"On\", flash the screen instead of ringing the bell"),
49 &terminal_use_visible_bell_p
, (char **)on_off_choices
},
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
},
59 N_("When \"On\", the portion of the matched search string is highlighted"),
60 &show_index_match
, (char **)on_off_choices
},
63 N_("Controls what happens when scrolling is requested at the end of a node"),
64 &info_scroll_behaviour
, (char **)info_scroll_choices
},
67 N_("The number lines to scroll when the cursor moves out of the window"),
68 &window_scroll_step
, (char **)NULL
},
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"))
82 /* Get the variable's name. */
83 var
= read_variable_name (_("Describe variable: "), window
);
88 description
= (char *)xmalloc (20 + strlen (var
->name
)
89 + strlen (_(var
->doc
)));
92 sprintf (description
, "%s (%s): %s.",
93 var
->name
, var
->choices
[*(var
->value
)], _(var
->doc
));
95 sprintf (description
, "%s (%d): %s.",
96 var
->name
, *(var
->value
), _(var
->doc
));
98 window_message_in_echo_area ("%s", description
);
102 DECLARE_INFO_COMMAND (set_variable
, _("Set the value of an Info variable"))
107 /* Get the variable's name and value. */
108 var
= read_variable_name (_("Set variable: "), window
);
113 /* Read a new value for this variable. */
121 if (info_explicit_arg
|| count
!= 1)
122 potential_value
= count
;
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 ();
138 /* If the user specified a value, get that, otherwise, we are done. */
139 canonicalize_whitespace (line
);
141 *(var
->value
) = atoi (line
);
143 *(var
->value
) = potential_value
;
150 REFERENCE
**array
= (REFERENCE
**)NULL
;
154 for (i
= 0; var
->choices
[i
]; i
++)
158 entry
= (REFERENCE
*)xmalloc (sizeof (REFERENCE
));
159 entry
->label
= xstrdup (var
->choices
[i
]);
160 entry
->nodename
= (char *)NULL
;
161 entry
->filename
= (char *)NULL
;
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 ();
181 info_abort_key (active_window
, 0, 0);
185 /* User accepted default choice? If so, no change. */
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)
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. */
207 read_variable_name (prompt
, window
)
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. */
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 ();
230 info_abort_key (active_window
, 0, 0);
231 return ((VARIABLE_ALIST
*)NULL
);
234 /* User accepted "default"? (There is none.) */
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)
246 if (!info_variables
[i
].name
)
247 return ((VARIABLE_ALIST
*)NULL
);
249 return (&(info_variables
[i
]));
252 /* Make an array of REFERENCE which actually contains the names of the
253 variables available in Info. */
255 make_variable_completions_array ()
258 REFERENCE
**array
= (REFERENCE
**)NULL
;
259 int array_index
= 0, array_slots
= 0;
261 for (i
= 0; info_variables
[i
].name
; i
++)
265 entry
= (REFERENCE
*) xmalloc (sizeof (REFERENCE
));
266 entry
->label
= xstrdup (info_variables
[i
].name
);
267 entry
->nodename
= (char *)NULL
;
268 entry
->filename
= (char *)NULL
;
271 (entry
, array_index
, array
, array_slots
, 200, REFERENCE
*);