/* readline.c -- a general facility for reading lines of input
- with emacs style editing and completion. */
+ with emacs style editing and completion. */
-/* Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+/* Copyright 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
This file contains the Readline Library (the Library), a set of
routines for providing Emacs style line input to programs that ask
# define _POSIX_VDISABLE -1
# endif /* !_POSIX_VERSION */
#endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */
+\f
+/* Define some macros for dealing with assorted signalling disciplines.
+
+ These macros provide a way to use signal blocking and disabling
+ without smothering your code in a pile of #ifdef's.
+
+ SIGNALS_UNBLOCK; Stop blocking all signals.
+
+ {
+ SIGNALS_DECLARE_SAVED (name); Declare a variable to save the
+ signal blocking state.
+ ...
+ SIGNALS_BLOCK (SIGSTOP, name); Block a signal, and save the previous
+ state for restoration later.
+ ...
+ SIGNALS_RESTORE (name); Restore previous signals.
+ }
+
+*/
+
+#ifdef HAVE_POSIX_SIGNALS
+ /* POSIX signals */
+
+#define SIGNALS_UNBLOCK \
+ do { sigset_t set; \
+ sigemptyset (&set); \
+ sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL); \
+ } while (0)
+
+#define SIGNALS_DECLARE_SAVED(name) sigset_t name
+
+#define SIGNALS_BLOCK(SIG, saved) \
+ do { sigset_t set; \
+ sigemptyset (&set); \
+ sigaddset (&set, SIG); \
+ sigprocmask (SIG_BLOCK, &set, &saved); \
+ } while (0)
+
+#define SIGNALS_RESTORE(saved) \
+ sigprocmask (SIG_SETMASK, &saved, (sigset_t *)NULL)
+
+
+#else /* HAVE_POSIX_SIGNALS */
+#ifdef HAVE_BSD_SIGNALS
+ /* BSD signals */
+
+#define SIGNALS_UNBLOCK sigsetmask (0)
+#define SIGNALS_DECLARE_SAVED(name) int name
+#define SIGNALS_BLOCK(SIG, saved) saved = sigblock (sigmask (SIG))
+#define SIGNALS_RESTORE(saved) sigsetmask (saved)
+
+
+#else /* HAVE_BSD_SIGNALS */
+ /* None of the Above */
+
+#define SIGNALS_UNBLOCK /* nothing */
+#define SIGNALS_DECLARE_SAVED(name) /* nothing */
+#define SIGNALS_BLOCK(SIG, saved) /* nothing */
+#define SIGNALS_RESTORE(saved) /* nothing */
+
+
+#endif /* HAVE_BSD_SIGNALS */
+#endif /* HAVE_POSIX_SIGNALS */
+
+/* End of signal handling definitions. */
+
#include <errno.h>
extern int errno;
static update_line ();
static void output_character_function ();
static delete_chars ();
-static insert_some_chars ();
+static void insert_some_chars ();
#if defined (VOID_SIGHANDLER)
# define sighandler void
/* **************************************************************** */
static void rl_prep_terminal (), rl_deprep_terminal ();
+static void clear_to_eol (), rl_generic_bind ();
/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means
none. A return value of NULL means that EOF was encountered. */
kill (getpid (), sig);
-#if defined (HAVE_POSIX_SIGNALS)
- {
- sigset_t set;
-
- sigemptyset (&set);
- sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL);
- }
-#else
-#if defined (HAVE_BSD_SIGNALS)
- sigsetmask (0);
-#endif /* HAVE_BSD_SIGNALS */
-#endif /* HAVE_POSIX_SIGNALS */
+ SIGNALS_UNBLOCK;
rl_prep_terminal ();
rl_set_signals ();
int key, c;
while (1)
{
- rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
+ rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg, 0);
key = c = rl_read_key ();
if (keymap[c].type == ISFUNC &&
/* Non-zero means this terminal can't really do anything. */
int dumb_term = 0;
+/* On Solaris2, sys/types.h brings in sys/reg.h,
+ which screws up the Termcap variable PC, used below. */
+
+#undef PC
+
char PC;
char *BC, *UP;
if (!term)
term = "dumb";
- if (tgetent (term_buffer, term) < 0)
+ if (tgetent (term_buffer, term) <= 0)
{
dumb_term = 1;
screenwidth = 79;
}
/* Insert COUNT characters from STRING to the output stream. */
-static
+static void
insert_some_chars (string, count)
char *string;
int count;
/* Clear to the end of the line. COUNT is the minimum
number of character spaces to clear, */
+static void
clear_to_eol (count)
int count;
{
{
#ifndef __GO32__
int tty = fileno (rl_instream);
-#if defined (HAVE_BSD_SIGNALS)
- int oldmask;
-#endif /* HAVE_BSD_SIGNALS */
+ SIGNALS_DECLARE_SAVED (saved_signals);
if (terminal_prepped)
return;
- oldmask = sigblock (sigmask (SIGINT));
+ SIGNALS_BLOCK (SIGINT, saved_signals);
/* We always get the latest tty values. Maybe stty changed them. */
ioctl (tty, TIOCGETP, &the_ttybuff);
terminal_prepped = 1;
-#if defined (HAVE_BSD_SIGNALS)
- sigsetmask (oldmask);
-#endif
+ SIGNALS_RESTORE (saved_signals);
#endif /* !__GO32__ */
}
{
#ifndef __GO32__
int tty = fileno (rl_instream);
-#if defined (HAVE_BSD_SIGNALS)
- int oldmask;
-#endif
+ SIGNALS_DECLARE_SAVED (saved_signals);
if (!terminal_prepped)
return;
- oldmask = sigblock (sigmask (SIGINT));
+ SIGNALS_BLOCK (SIGINT, saved_signals);
the_ttybuff.sg_flags = original_tty_flags;
ioctl (tty, TIOCSETN, &the_ttybuff);
#endif
terminal_prepped = 0;
-#if defined (HAVE_BSD_SIGNALS)
- sigsetmask (oldmask);
-#endif
+ SIGNALS_RESTORE (saved_signals);
#endif /* !__GO32 */
}
struct termio tio;
#endif /* !TERMIOS_TTY_DRIVER */
-#if defined (HAVE_POSIX_SIGNALS)
- sigset_t set, oset;
-#else
-# if defined (HAVE_BSD_SIGNALS)
- int oldmask;
-# endif /* HAVE_BSD_SIGNALS */
-#endif /* !HAVE_POSIX_SIGNALS */
+ SIGNALS_DECLARE_SAVED (saved_signals);
if (terminal_prepped)
return;
/* Try to keep this function from being INTerrupted. We can do it
on POSIX and systems with BSD-like signal handling. */
-#if defined (HAVE_POSIX_SIGNALS)
- sigemptyset (&set);
- sigaddset (&set, SIGINT);
- sigprocmask (SIG_BLOCK, &set, &oset);
-#else /* !HAVE_POSIX_SIGNALS */
-# if defined (HAVE_BSD_SIGNALS)
- oldmask = sigblock (sigmask (SIGINT));
-# endif /* HAVE_BSD_SIGNALS */
-#endif /* !HAVE_POSIX_SIGNALS */
+ SIGNALS_BLOCK (SIGINT, saved_signals);
#if defined (TERMIOS_TTY_DRIVER)
tcgetattr (tty, &tio);
terminal_prepped = 1;
-#if defined (HAVE_POSIX_SIGNALS)
- sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
-#else
-# if defined (HAVE_BSD_SIGNALS)
- sigsetmask (oldmask);
-# endif /* HAVE_BSD_SIGNALS */
-#endif /* !HAVE_POSIX_SIGNALS */
+ SIGNALS_RESTORE (saved_signals);
#endif /* !__GO32__ */
}
/* Try to keep this function from being INTerrupted. We can do it
on POSIX and systems with BSD-like signal handling. */
-#if defined (HAVE_POSIX_SIGNALS)
- sigset_t set, oset;
-#else /* !HAVE_POSIX_SIGNALS */
-# if defined (HAVE_BSD_SIGNALS)
- int oldmask;
-# endif /* HAVE_BSD_SIGNALS */
-#endif /* !HAVE_POSIX_SIGNALS */
+ SIGNALS_DECLARE_SAVED (saved_signals);
if (!terminal_prepped)
return;
-#if defined (HAVE_POSIX_SIGNALS)
- sigemptyset (&set);
- sigaddset (&set, SIGINT);
- sigprocmask (SIG_BLOCK, &set, &oset);
-#else /* !HAVE_POSIX_SIGNALS */
-# if defined (HAVE_BSD_SIGNALS)
- oldmask = sigblock (sigmask (SIGINT));
-# endif /* HAVE_BSD_SIGNALS */
-#endif /* !HAVE_POSIX_SIGNALS */
+ SIGNALS_BLOCK (SIGINT, saved_signals);
#if defined (TERMIOS_TTY_DRIVER)
tcsetattr (tty, TCSADRAIN, &otio);
terminal_prepped = 0;
-#if defined (HAVE_POSIX_SIGNALS)
- sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
-#else /* !HAVE_POSIX_SIGNALS */
-# if defined (HAVE_BSD_SIGNALS)
- sigsetmask (oldmask);
-# endif /* HAVE_BSD_SIGNALS */
-#endif /* !HAVE_POSIX_SIGNALS */
+ SIGNALS_RESTORE (saved_signals);
#endif /* !__GO32__ */
}
#endif /* NEW_TTY_DRIVER */
readline because of extra large arguments. */
if (count > 1 && count < 1024)
{
- string = (char *)alloca (1 + count);
+ string = alloca (1 + count);
for (i = 0; i < count; i++)
string[i] = c;
{
int decreaser;
- string = (char *)alloca (1024 + 1);
+ string = alloca (1024 + 1);
for (i = 0; i < 1024; i++)
string[i] = c;
int key = 0, t;
i = 0;
- string = (char *)alloca (ibuffer_len + 1);
+ string = alloca (ibuffer_len + 1);
string[i++] = c;
while ((t = rl_get_char (&key)) &&
else
{
/* Inserting a single character. */
- string = (char *)alloca (2);
+ string = alloca (2);
string[1] = '\0';
string[0] = c;
/* Found an embedded word break character in a potential
match, so need to prepend a quote character if we are
replacing the completion string. */
- replacement = alloca (strlen (matches[0]) + 2);
+ replacement = (char *)alloca (strlen (matches[0]) + 2);
quote_char = *rl_completer_quote_characters;
*replacement = quote_char;
strcpy (replacement + 1, matches[0]);
{
char *message = (char *)NULL;
- message =
- (char *)alloca (1 + (search_string ? strlen (search_string) : 0) + 30);
+ message = alloca (1 + (search_string ? strlen (search_string) : 0) + 30);
*message = '\0';
int invoking_key;
{
/* The string that the user types in to search for. */
- char *search_string = (char *)alloca (128);
+ char *search_string = alloca (128);
/* The current length of SEARCH_STRING. */
int search_string_index;
/* Allocate space for this many lines, +1 for the current input line,
and remember those lines. */
- lines = (char **)alloca ((1 + (hlen = i)) * sizeof (char *));
+ lines = alloca ((1 + (hlen = i)) * sizeof (char *));
for (i = 0; i < hlen; i++)
lines[i] = hlist[i]->line;
char *alloced_line;
/* Keep that mips alloca happy. */
- alloced_line = (char *)alloca (1 + strlen (the_line));
+ alloced_line = alloca (1 + strlen (the_line));
lines[i] = alloced_line;
strcpy (lines[i], &the_line[0]);
}
pointed to by DATA, right now this can be a function (ISFUNC),
a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps
as necessary. The initial place to do bindings is in MAP. */
+
+static void
rl_generic_bind (type, keyseq, data, map)
int type;
char *keyseq, *data;
return;
}
- keys = (char *)alloca (1 + (2 * strlen (keyseq)));
+ keys = alloca (1 + (2 * strlen (keyseq)));
/* Translate the ASCII representation of KEYSEQ into an array
of characters. Stuff the characters into ARRAY, and the
/* Don't know what to do, but this is a guess */
static char *last_readline_init_file = "/INPUTRC";
#else
-static char *last_readline_init_file = "~/inputrc";
+static char *last_readline_init_file = "~/.inputrc";
#endif
/* Re-read the current keybindings file. */
rl_set_key (). Otherwise, let the older code deal with it. */
if (*string == '"')
{
- char *seq = (char *)alloca (1 + strlen (string));
+ char *seq = alloca (1 + strlen (string));
register int j, k = 0;
for (j = 1; string[j]; j++)