]> code.delx.au - gnu-emacs/blobdiff - src/term.c
Fix an error in Tramp for rsync
[gnu-emacs] / src / term.c
index 15d33b4e3ee48986c664902ba06f35102024af0c..81908b370a5dc8a53af9626a461a1f09eed7657f 100644 (file)
@@ -1,13 +1,13 @@
 /* Terminal control module for terminals described by TERMCAP
-   Copyright (C) 1985-1987, 1993-1995, 1998, 2000-2015 Free Software
+   Copyright (C) 1985-1987, 1993-1995, 1998, 2000-2016 Free Software
    Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs 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 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -44,8 +44,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "keymap.h"
 #include "blockinput.h"
 #include "syssignal.h"
-#include "systty.h"
-#include "intervals.h"
 #ifdef MSDOS
 #include "msdos.h"
 static int been_here = -1;
@@ -56,10 +54,6 @@ static int been_here = -1;
 #endif
 
 #include "cm.h"
-#ifdef HAVE_X_WINDOWS
-#include "xterm.h"
-#endif
-
 #include "menu.h"
 
 /* The name of the default console device.  */
@@ -538,15 +532,13 @@ encode_terminal_code (struct glyph *src, int src_len,
      multibyte-form.  But, it may be enlarged on demand if
      Vglyph_table contains a string or a composite glyph is
      encountered.  */
-  if (min (PTRDIFF_MAX, SIZE_MAX) / MAX_MULTIBYTE_LENGTH < src_len)
+  if (INT_MULTIPLY_WRAPV (src_len, MAX_MULTIBYTE_LENGTH, &required))
     memory_full (SIZE_MAX);
-  required = src_len;
-  required *= MAX_MULTIBYTE_LENGTH;
   if (encode_terminal_src_size < required)
-    {
-      encode_terminal_src = xrealloc (encode_terminal_src, required);
-      encode_terminal_src_size = required;
-    }
+    encode_terminal_src = xpalloc (encode_terminal_src,
+                                  &encode_terminal_src_size,
+                                  required - encode_terminal_src_size,
+                                  -1, sizeof *encode_terminal_src);
 
   charset_list = coding_charset_list (coding);
 
@@ -556,8 +548,8 @@ encode_terminal_code (struct glyph *src, int src_len,
     {
       if (src->type == COMPOSITE_GLYPH)
        {
-         struct composition *cmp IF_LINT (= NULL);
-         Lisp_Object gstring IF_LINT (= Qnil);
+         struct composition *cmp UNINIT;
+         Lisp_Object gstring UNINIT;
          int i;
 
          nbytes = buf - encode_terminal_src;
@@ -622,7 +614,7 @@ encode_terminal_code (struct glyph *src, int src_len,
       else if (! CHAR_GLYPH_PADDING_P (*src))
        {
          GLYPH g;
-         int c IF_LINT (= 0);
+         int c UNINIT;
          Lisp_Object string;
 
          string = Qnil;
@@ -1504,6 +1496,8 @@ append_glyph (struct it *it)
       glyph->pixel_width = 1;
       glyph->u.ch = it->char_to_display;
       glyph->face_id = it->face_id;
+      glyph->avoid_cursor_p = it->avoid_cursor_p;
+      glyph->multibyte_p = it->multibyte_p;
       glyph->padding_p = i > 0;
       glyph->charpos = CHARPOS (it->position);
       glyph->object = it->object;
@@ -1684,6 +1678,7 @@ append_composite_glyph (struct it *it)
          glyph = it->glyph_row->glyphs[it->area];
        }
       glyph->type = COMPOSITE_GLYPH;
+      eassert (it->pixel_width <= SHRT_MAX);
       glyph->pixel_width = it->pixel_width;
       glyph->u.cmp.id = it->cmp_it.id;
       if (it->cmp_it.ch < 0)
@@ -1699,8 +1694,10 @@ append_composite_glyph (struct it *it)
          glyph->slice.cmp.to = it->cmp_it.to - 1;
        }
 
+      glyph->avoid_cursor_p = it->avoid_cursor_p;
+      glyph->multibyte_p = it->multibyte_p;
       glyph->face_id = it->face_id;
-      glyph->padding_p = 0;
+      glyph->padding_p = false;
       glyph->charpos = CHARPOS (it->position);
       glyph->object = it->object;
       if (it->bidi_p)
@@ -1783,8 +1780,10 @@ append_glyphless_glyph (struct it *it, int face_id, const char *str)
     return;
   glyph->type = CHAR_GLYPH;
   glyph->pixel_width = 1;
+  glyph->avoid_cursor_p = it->avoid_cursor_p;
+  glyph->multibyte_p = it->multibyte_p;
   glyph->face_id = face_id;
-  glyph->padding_p = 0;
+  glyph->padding_p = false;
   glyph->charpos = CHARPOS (it->position);
   glyph->object = it->object;
   if (it->bidi_p)
@@ -1862,9 +1861,11 @@ produce_glyphless_glyph (struct it *it, Lisp_Object acronym)
       else
        {
          eassert (it->glyphless_method == GLYPHLESS_DISPLAY_HEX_CODE);
-         len = (it->c < 0x10000 ? sprintf (buf, "\\u%04X", it->c)
-                : it->c <= MAX_UNICODE_CHAR ? sprintf (buf, "\\U%06X", it->c)
-                : sprintf (buf, "\\x%06X", it->c));
+         len = sprintf (buf,
+                        (it->c < 0x10000 ? "\\u%04X"
+                         : it->c <= MAX_UNICODE_CHAR ? "\\U%06X"
+                         : "\\x%06X"),
+                        it->c + 0u);
        }
       str = buf;
     }
@@ -1959,8 +1960,6 @@ turn_off_face (struct frame *f, int face_id)
   struct face *face = FACE_FROM_ID (f, face_id);
   struct tty_display_info *tty = FRAME_TTY (f);
 
-  eassert (face != NULL);
-
   if (tty->TS_exit_attribute_mode)
     {
       /* Capability "me" will turn off appearance modes double-bright,
@@ -3106,7 +3105,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
   struct tty_menu_state *state;
   int statecount, x, y, i;
   bool leave, onepane;
-  int result IF_LINT (= 0);
+  int result UNINIT;
   int title_faces[4];          /* Face to display the menu title.  */
   int faces[4], buffers_num_deleted = 0;
   struct frame *sf = SELECTED_FRAME ();
@@ -3115,6 +3114,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
   Lisp_Object selectface;
   int first_item = 0;
   int col, row;
+  Lisp_Object prev_inhibit_redisplay = Vinhibit_redisplay;
   USE_SAFE_ALLOCA;
 
   /* Don't allow non-positive x0 and y0, lest the menu will wrap
@@ -3157,6 +3157,11 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
       buffers_num_deleted = 1;
     }
 
+  /* Inhibit redisplay for as long as the menu is active, to avoid
+     messing the screen if some timer calls sit-for or a similar
+     function.  */
+  Vinhibit_redisplay = Qt;
+
   /* Force update of the current frame, so that the desired and the
      current matrices are identical.  */
   update_frame_with_menu (sf, -1, -1);
@@ -3347,6 +3352,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
   if (!kbd_buffer_events_waiting ())
     clear_input_pending ();
   SAFE_FREE ();
+  Vinhibit_redisplay = prev_inhibit_redisplay;
   return result;
 }
 
@@ -3401,9 +3407,11 @@ static void
 tty_pop_down_menu (Lisp_Object arg)
 {
   tty_menu *menu = XSAVE_POINTER (arg, 0);
+  struct buffer *orig_buffer = XSAVE_POINTER (arg, 1);
 
   block_input ();
   tty_menu_destroy (menu);
+  set_buffer_internal (orig_buffer);
   unblock_input ();
 }
 
@@ -3682,7 +3690,10 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags,
 
   pane = selidx = 0;
 
-  record_unwind_protect (tty_pop_down_menu, make_save_ptr (menu));
+  /* We save and restore the current buffer because tty_menu_activate
+     triggers redisplay, which switches buffers at will.  */
+  record_unwind_protect (tty_pop_down_menu,
+                        make_save_ptr_ptr (menu, current_buffer));
 
   specbind (Qoverriding_terminal_local_map,
            Fsymbol_value (Qtty_menu_navigation_map));
@@ -3908,13 +3919,15 @@ dissociate_if_controlling_tty (int fd)
 struct terminal *
 init_tty (const char *name, const char *terminal_type, bool must_succeed)
 {
+  struct tty_display_info *tty = NULL;
+  struct terminal *terminal = NULL;
+#ifndef DOS_NT
   char *area;
   char **address = &area;
   int status;
-  struct tty_display_info *tty = NULL;
-  struct terminal *terminal = NULL;
   sigset_t oldset;
   bool ctty = false;  /* True if asked to open controlling tty.  */
+#endif
 
   if (!terminal_type)
     maybe_fatal (must_succeed, 0,
@@ -3923,8 +3936,10 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
 
   if (name == NULL)
     name = DEV_TTY;
+#ifndef DOS_NT
   if (!strcmp (name, DEV_TTY))
     ctty = 1;
+#endif
 
   /* If we already have a terminal on the given device, use that.  If
      all such terminals are suspended, create a new one instead.  */
@@ -4026,12 +4041,12 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
                    "Terminal type %s is not defined",
                    "Terminal type %s is not defined.\n\
 If that is not the actual type of terminal you have,\n\
-use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
-`setenv TERM ...') to specify the correct type.  It may be necessary\n"
+use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\
+'setenv TERM ...') to specify the correct type.  It may be necessary\n"
 #ifdef TERMINFO
-"to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
+"to do 'unset TERMINFO' (C-shell: 'unsetenv TERMINFO') as well.",
 #else
-"to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
+"to do 'unset TERMCAP' (C-shell: 'unsetenv TERMCAP') as well.",
 #endif
                    terminal_type);
     }
@@ -4305,12 +4320,12 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
                    "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
 It lacks the ability to position the cursor.\n\
 If that is not the actual type of terminal you have,\n\
-use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
-`setenv TERM ...') to specify the correct type.  It may be necessary\n"
+use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\
+'setenv TERM ...') to specify the correct type.  It may be necessary\n"
 # ifdef TERMINFO
-"to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
+"to do 'unset TERMINFO' (C-shell: 'unsetenv TERMINFO') as well.",
 # else /* TERMCAP */
-"to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
+"to do 'unset TERMCAP' (C-shell: 'unsetenv TERMCAP') as well.",
 # endif /* TERMINFO */
                    terminal_type);
     }