1998-03-22 21:43:15 +01:00
|
|
|
/* variables.c -- How to manipulate user visible variables in Info.
|
1998-03-24 19:08:49 +01:00
|
|
|
$Id: variables.c,v 1.1.1.2 1998/03/22 20:43:01 law Exp $
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
This file is part of GNU Info, a program for reading online documentation
|
1997-08-22 00:57:35 +02:00
|
|
|
stored in Info format.
|
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
Copyright (C) 1993, 97 Free Software Foundation, Inc.
|
1997-08-22 00:57:35 +02:00
|
|
|
|
|
|
|
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 2, 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, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
Written by Brian Fox (bfox@ai.mit.edu). */
|
|
|
|
|
|
|
|
#include "info.h"
|
|
|
|
#include "variables.h"
|
|
|
|
|
|
|
|
/* **************************************************************** */
|
1998-03-22 21:43:15 +01:00
|
|
|
/* */
|
|
|
|
/* User Visible Variables in Info */
|
|
|
|
/* */
|
1997-08-22 00:57:35 +02:00
|
|
|
/* **************************************************************** */
|
|
|
|
|
|
|
|
/* Choices used by the completer when reading a zero/non-zero value for
|
|
|
|
a variable. */
|
|
|
|
static char *on_off_choices[] = { "Off", "On", (char *)NULL };
|
|
|
|
|
|
|
|
VARIABLE_ALIST info_variables[] = {
|
|
|
|
{ "automatic-footnotes",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", footnotes appear and disappear automatically"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&auto_footnotes_p, (char **)on_off_choices },
|
|
|
|
|
|
|
|
{ "automatic-tiling",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", creating or deleting a window resizes other windows"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&auto_tiling_p, (char **)on_off_choices },
|
|
|
|
|
|
|
|
{ "visible-bell",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", flash the screen instead of ringing the bell"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&terminal_use_visible_bell_p, (char **)on_off_choices },
|
|
|
|
|
|
|
|
{ "errors-ring-bell",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", errors cause the bell to ring"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&info_error_rings_bell_p, (char **)on_off_choices },
|
|
|
|
|
|
|
|
{ "gc-compressed-files",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", Info garbage collects files which had to be uncompressed"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&gc_compressed_files, (char **)on_off_choices },
|
|
|
|
{ "show-index-match",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", the portion of the matched search string is highlighted"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&show_index_match, (char **)on_off_choices },
|
|
|
|
|
|
|
|
{ "scroll-behaviour",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("Controls what happens when scrolling is requested at the end of a node"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&info_scroll_behaviour, (char **)info_scroll_choices },
|
|
|
|
|
|
|
|
{ "scroll-step",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("The number lines to scroll when the cursor moves out of the window"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&window_scroll_step, (char **)NULL },
|
|
|
|
|
|
|
|
{ "ISO-Latin",
|
1998-03-22 21:43:15 +01:00
|
|
|
N_("When \"On\", Info accepts and displays ISO Latin characters"),
|
1997-08-22 00:57:35 +02:00
|
|
|
&ISO_Latin_p, (char **)on_off_choices },
|
|
|
|
|
|
|
|
{ (char *)NULL, (char *)NULL, (int *)NULL, (char **)NULL }
|
|
|
|
};
|
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
DECLARE_INFO_COMMAND (describe_variable, _("Explain the use of a variable"))
|
1997-08-22 00:57:35 +02:00
|
|
|
{
|
|
|
|
VARIABLE_ALIST *var;
|
|
|
|
char *description;
|
|
|
|
|
|
|
|
/* Get the variable's name. */
|
1998-03-22 21:43:15 +01:00
|
|
|
var = read_variable_name (_("Describe variable: "), window);
|
1997-08-22 00:57:35 +02:00
|
|
|
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
description = (char *)xmalloc (20 + strlen (var->name)
|
|
|
|
+ strlen (_(var->doc)));
|
1997-08-22 00:57:35 +02:00
|
|
|
|
|
|
|
if (var->choices)
|
|
|
|
sprintf (description, "%s (%s): %s.",
|
1998-03-22 21:43:15 +01:00
|
|
|
var->name, var->choices[*(var->value)], _(var->doc));
|
1997-08-22 00:57:35 +02:00
|
|
|
else
|
1998-03-22 21:43:15 +01:00
|
|
|
sprintf (description, "%s (%d): %s.",
|
|
|
|
var->name, *(var->value), _(var->doc));
|
1997-08-22 00:57:35 +02:00
|
|
|
|
|
|
|
window_message_in_echo_area ("%s", description);
|
|
|
|
free (description);
|
|
|
|
}
|
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
DECLARE_INFO_COMMAND (set_variable, _("Set the value of an Info variable"))
|
1997-08-22 00:57:35 +02:00
|
|
|
{
|
|
|
|
VARIABLE_ALIST *var;
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
/* Get the variable's name and value. */
|
1998-03-22 21:43:15 +01:00
|
|
|
var = read_variable_name (_("Set variable: "), window);
|
1997-08-22 00:57:35 +02:00
|
|
|
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Read a new value for this variable. */
|
|
|
|
{
|
|
|
|
char prompt[100];
|
|
|
|
|
|
|
|
if (!var->choices)
|
|
|
|
{
|
1998-03-22 21:43:15 +01:00
|
|
|
int potential_value;
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
if (info_explicit_arg || count != 1)
|
|
|
|
potential_value = count;
|
|
|
|
else
|
|
|
|
potential_value = *(var->value);
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
sprintf (prompt, _("Set %s to value (%d): "),
|
|
|
|
var->name, potential_value);
|
|
|
|
line = info_read_in_echo_area (active_window, prompt);
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
/* If no error was printed, clear the echo area. */
|
|
|
|
if (!info_error_was_printed)
|
|
|
|
window_clear_echo_area ();
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
/* User aborted? */
|
|
|
|
if (!line)
|
|
|
|
return;
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
/* If the user specified a value, get that, otherwise, we are done. */
|
|
|
|
canonicalize_whitespace (line);
|
|
|
|
if (*line)
|
|
|
|
*(var->value) = atoi (line);
|
|
|
|
else
|
|
|
|
*(var->value) = potential_value;
|
1997-08-22 00:57:35 +02:00
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
free (line);
|
1997-08-22 00:57:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-03-22 21:43:15 +01:00
|
|
|
register int i;
|
|
|
|
REFERENCE **array = (REFERENCE **)NULL;
|
|
|
|
int array_index = 0;
|
|
|
|
int array_slots = 0;
|
|
|
|
|
|
|
|
for (i = 0; var->choices[i]; i++)
|
|
|
|
{
|
|
|
|
REFERENCE *entry;
|
|
|
|
|
|
|
|
entry = (REFERENCE *)xmalloc (sizeof (REFERENCE));
|
|
|
|
entry->label = xstrdup (var->choices[i]);
|
|
|
|
entry->nodename = (char *)NULL;
|
|
|
|
entry->filename = (char *)NULL;
|
|
|
|
|
|
|
|
add_pointer_to_array
|
|
|
|
(entry, array_index, array, array_slots, 10, REFERENCE *);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf (prompt, _("Set %s to value (%s): "),
|
|
|
|
var->name, var->choices[*(var->value)]);
|
|
|
|
|
|
|
|
/* Ask the completer to read a variable value for us. */
|
|
|
|
line = info_read_completing_in_echo_area (window, prompt, array);
|
|
|
|
|
|
|
|
info_free_references (array);
|
|
|
|
|
|
|
|
if (!echo_area_is_active)
|
|
|
|
window_clear_echo_area ();
|
|
|
|
|
|
|
|
/* User aborted? */
|
|
|
|
if (!line)
|
|
|
|
{
|
|
|
|
info_abort_key (active_window, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User accepted default choice? If so, no change. */
|
|
|
|
if (!*line)
|
|
|
|
{
|
|
|
|
free (line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the choice in our list of choices. */
|
|
|
|
for (i = 0; var->choices[i]; i++)
|
|
|
|
if (strcmp (var->choices[i], line) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (var->choices[i])
|
|
|
|
*(var->value) = i;
|
1997-08-22 00:57:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the name of an Info variable in the echo area and return the
|
|
|
|
address of a VARIABLE_ALIST member. A return value of NULL indicates
|
|
|
|
that no variable could be read. */
|
|
|
|
VARIABLE_ALIST *
|
|
|
|
read_variable_name (prompt, window)
|
|
|
|
char *prompt;
|
|
|
|
WINDOW *window;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
char *line;
|
|
|
|
REFERENCE **variables;
|
|
|
|
|
|
|
|
/* Get the completion array of variable names. */
|
|
|
|
variables = make_variable_completions_array ();
|
|
|
|
|
|
|
|
/* Ask the completer to read a variable for us. */
|
|
|
|
line =
|
|
|
|
info_read_completing_in_echo_area (window, prompt, variables);
|
|
|
|
|
|
|
|
info_free_references (variables);
|
|
|
|
|
|
|
|
if (!echo_area_is_active)
|
|
|
|
window_clear_echo_area ();
|
|
|
|
|
|
|
|
/* User aborted? */
|
|
|
|
if (!line)
|
|
|
|
{
|
|
|
|
info_abort_key (active_window, 0, 0);
|
|
|
|
return ((VARIABLE_ALIST *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User accepted "default"? (There is none.) */
|
|
|
|
if (!*line)
|
|
|
|
{
|
|
|
|
free (line);
|
|
|
|
return ((VARIABLE_ALIST *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the variable in our list of variables. */
|
|
|
|
for (i = 0; info_variables[i].name; i++)
|
|
|
|
if (strcmp (info_variables[i].name, line) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!info_variables[i].name)
|
|
|
|
return ((VARIABLE_ALIST *)NULL);
|
|
|
|
else
|
|
|
|
return (&(info_variables[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make an array of REFERENCE which actually contains the names of the
|
|
|
|
variables available in Info. */
|
|
|
|
REFERENCE **
|
|
|
|
make_variable_completions_array ()
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
REFERENCE **array = (REFERENCE **)NULL;
|
|
|
|
int array_index = 0, array_slots = 0;
|
|
|
|
|
|
|
|
for (i = 0; info_variables[i].name; i++)
|
|
|
|
{
|
|
|
|
REFERENCE *entry;
|
|
|
|
|
1998-03-22 21:43:15 +01:00
|
|
|
entry = (REFERENCE *) xmalloc (sizeof (REFERENCE));
|
|
|
|
entry->label = xstrdup (info_variables[i].name);
|
1997-08-22 00:57:35 +02:00
|
|
|
entry->nodename = (char *)NULL;
|
|
|
|
entry->filename = (char *)NULL;
|
|
|
|
|
|
|
|
add_pointer_to_array
|
1998-03-22 21:43:15 +01:00
|
|
|
(entry, array_index, array, array_slots, 200, REFERENCE *);
|
1997-08-22 00:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (array);
|
|
|
|
}
|