]> Git Repo - binutils.git/blobdiff - readline/readline.c
keep new sun4 dir
[binutils.git] / readline / readline.c
index de1142f0950115d6c6f98ac7132a2261f15b1ca6..32ca4b7c575ec42c94ea6e5f503854daea27f1ea 100644 (file)
@@ -1,7 +1,7 @@
 /* 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
@@ -97,6 +97,72 @@ static char *xmalloc (), *xrealloc ();
 #    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;
@@ -163,7 +229,7 @@ extern char *tilde_expand ();
 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
@@ -305,6 +371,7 @@ static int defining_kbd_macro = 0;
 /* **************************************************************** */
 
 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. */
@@ -540,18 +607,7 @@ rl_signal_handler (sig)
 
       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 ();
@@ -1300,7 +1356,7 @@ rl_digit_loop ()
   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 &&
@@ -1968,6 +2024,11 @@ static char *term_string_buffer = (char *)NULL;
 /* 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;
 
@@ -2040,7 +2101,7 @@ init_terminal_io (terminal_name)
   if (!term)
     term = "dumb";
 
-  if (tgetent (term_buffer, term) < 0)
+  if (tgetent (term_buffer, term) <= 0)
     {
       dumb_term = 1;
       screenwidth = 79;
@@ -2166,7 +2227,7 @@ delete_chars (count)
 }
 
 /* Insert COUNT characters from STRING to the output stream. */
-static
+static void
 insert_some_chars (string, count)
      char *string;
      int count;
@@ -2241,6 +2302,7 @@ crlf ()
 
 /* 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;
 {
@@ -2299,14 +2361,12 @@ rl_prep_terminal ()
 {
 #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);
@@ -2396,9 +2456,7 @@ rl_prep_terminal ()
 
   terminal_prepped = 1;
 
-#if defined (HAVE_BSD_SIGNALS)
-  sigsetmask (oldmask);
-#endif
+  SIGNALS_RESTORE (saved_signals);
 #endif /* !__GO32__ */
 }
 
@@ -2408,14 +2466,12 @@ rl_deprep_terminal ()
 {
 #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);
@@ -2434,9 +2490,7 @@ rl_deprep_terminal ()
 #endif
   terminal_prepped = 0;
 
-#if defined (HAVE_BSD_SIGNALS)
-  sigsetmask (oldmask);
-#endif
+  SIGNALS_RESTORE (saved_signals);
 #endif /* !__GO32 */
 }
 
@@ -2469,28 +2523,14 @@ rl_prep_terminal ()
   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);
@@ -2557,13 +2597,7 @@ rl_prep_terminal ()
 
   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__ */
 }
 
@@ -2575,26 +2609,12 @@ rl_deprep_terminal ()
 
   /* 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);
@@ -2606,13 +2626,7 @@ rl_deprep_terminal ()
 
   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 */
@@ -3067,7 +3081,7 @@ rl_insert (count, c)
      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;
@@ -3081,7 +3095,7 @@ rl_insert (count, c)
     {
       int decreaser;
 
-      string = (char *)alloca (1024 + 1);
+      string = alloca (1024 + 1);
 
       for (i = 0; i < 1024; i++)
        string[i] = c;
@@ -3105,7 +3119,7 @@ rl_insert (count, 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)) &&
@@ -3123,7 +3137,7 @@ rl_insert (count, c)
   else
     {
       /* Inserting a single character. */
-      string = (char *)alloca (2);
+      string = alloca (2);
 
       string[1] = '\0';
       string[0] = c;
@@ -3870,7 +3884,7 @@ rl_complete_internal (what_to_do)
                      /* 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]);
@@ -4577,8 +4591,7 @@ rl_display_search (search_string, reverse_p, where)
 {
   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';
 
@@ -4611,7 +4624,7 @@ rl_search_history (direction, invoking_key)
      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;
@@ -4647,7 +4660,7 @@ rl_search_history (direction, invoking_key)
 
   /* 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;
 
@@ -4659,7 +4672,7 @@ rl_search_history (direction, invoking_key)
       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]);
     }
@@ -5509,6 +5522,8 @@ rl_macro_bind (keyseq, macro, map)
    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;
@@ -5526,7 +5541,7 @@ rl_generic_bind (type, keyseq, data, map)
       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
@@ -5644,7 +5659,7 @@ rl_named_function (string)
 /* 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. */
@@ -5991,7 +6006,7 @@ rl_parse_and_bind (string)
      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++)
This page took 0.036621 seconds and 4 git commands to generate.