Merge from emacs-23; up to 2010-06-01T01:49:15Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / src / term.c
index dbbdc03..f082bb4 100644 (file)
@@ -1,6 +1,5 @@
 /* Terminal control module for terminals described by TERMCAP
-   Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1998, 2000, 2001,
-                 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 1985-1987, 1993-1995, 1998, 2000-2011
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -25,11 +24,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <ctype.h>
 #include <errno.h>
 #include <sys/file.h>
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
-
 #include <signal.h>
 #include <stdarg.h>
 #include <setjmp.h>
@@ -66,6 +61,10 @@ extern int tgetent (char *, const char *);
 extern int tgetflag (char *id);
 extern int tgetnum (char *id);
 
+char *tparam (char *, char *, int, int, ...);
+
+extern char *tgetstr (char *, char **);
+
 #include "cm.h"
 #ifdef HAVE_X_WINDOWS
 #include "xterm.h"
@@ -113,35 +112,16 @@ static void vfatal (const char *str, va_list ap) NO_RETURN;
 #define OUTPUT_IF(tty, a)                                               \
   do {                                                                  \
     if (a)                                                              \
-      emacs_tputs ((tty), a,                                            \
-                   (int) (FRAME_LINES (XFRAME (selected_frame))         \
-                          - curY (tty) ),                               \
-                   cmputc);                                             \
+      OUTPUT (tty, a);                                                 \
   } while (0)
 
 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
 
-/* If true, use "vs", otherwise use "ve" to make the cursor visible.  */
-
-static int visible_cursor;
-
 /* Display space properties */
 
-/* Functions to call after suspending a tty. */
-Lisp_Object Vsuspend_tty_functions;
-
-/* Functions to call after resuming a tty. */
-Lisp_Object Vresume_tty_functions;
-
 /* Chain of all tty device parameters. */
 struct tty_display_info *tty_list;
 
-/* Nonzero means no need to redraw the entire frame on resuming a
-   suspended Emacs.  This is useful on terminals with multiple
-   pages, where one page is used for Emacs and another for all
-   else. */
-int no_redraw_on_reenter;
-
 /* Meaning of bits in no_color_video.  Each bit set means that the
    corresponding attribute cannot be combined with colors.  */
 
@@ -172,13 +152,6 @@ int max_frame_lines;
    should not open a frame on stdout. */
 static int no_controlling_tty;
 
-/* Provided for lisp packages.  */
-
-static int system_uses_terminfo;
-
-char *tparam (char *, char *, int, int, ...);
-
-extern char *tgetstr (char *, char **);
 \f
 
 #ifdef HAVE_GPM
@@ -1374,14 +1347,14 @@ term_get_fkeys_1 (void)
   KBOARD *kboard = term_get_fkeys_kboard;
 
   /* This can happen if CANNOT_DUMP or with strange options.  */
-  if (!KEYMAPP (kboard->Vinput_decode_map))
-    kboard->Vinput_decode_map = Fmake_sparse_keymap (Qnil);
+  if (!KEYMAPP (KVAR (kboard, Vinput_decode_map)))
+    KVAR (kboard, Vinput_decode_map) = Fmake_sparse_keymap (Qnil);
 
   for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++)
     {
       char *sequence = tgetstr (keys[i].cap, address);
       if (sequence)
-       Fdefine_key (kboard->Vinput_decode_map, build_string (sequence),
+       Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (sequence),
                     Fmake_vector (make_number (1),
                                   intern (keys[i].name)));
     }
@@ -1401,13 +1374,13 @@ term_get_fkeys_1 (void)
        if (k0)
          /* Define f0 first, so that f10 takes precedence in case the
             key sequences happens to be the same.  */
-         Fdefine_key (kboard->Vinput_decode_map, build_string (k0),
+         Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (k0),
                       Fmake_vector (make_number (1), intern ("f0")));
-       Fdefine_key (kboard->Vinput_decode_map, build_string (k_semi),
+       Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (k_semi),
                     Fmake_vector (make_number (1), intern ("f10")));
       }
     else if (k0)
-      Fdefine_key (kboard->Vinput_decode_map, build_string (k0),
+      Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (k0),
                   Fmake_vector (make_number (1), intern (k0_name)));
   }
 
@@ -1430,7 +1403,7 @@ term_get_fkeys_1 (void)
          if (sequence)
            {
              sprintf (fkey, "f%d", i);
-             Fdefine_key (kboard->Vinput_decode_map, build_string (sequence),
+             Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (sequence),
                           Fmake_vector (make_number (1),
                                         intern (fkey)));
            }
@@ -1447,7 +1420,7 @@ term_get_fkeys_1 (void)
        {                                                               \
          char *sequence = tgetstr (cap2, address);                     \
          if (sequence)                                                 \
-           Fdefine_key (kboard->Vinput_decode_map, build_string (sequence), \
+           Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (sequence), \
                         Fmake_vector (make_number (1),                 \
                                       intern (sym)));                  \
        }
@@ -1850,9 +1823,9 @@ produce_composite_glyph (struct it *it)
 
 
 /* Append a glyph for a glyphless character to IT->glyph_row.  FACE_ID
-   is a face ID to be used for the glyph.  What actually appended are
-   glyphs of type CHAR_GLYPH of which characters are in STR
-   (it->nglyphs bytes).  */
+   is a face ID to be used for the glyph.  What is actually appended
+   are glyphs of type CHAR_GLYPH whose characters are in STR (which
+   comes from it->nglyphs bytes).  */
 
 static void
 append_glyphless_glyph (struct it *it, int face_id, char *str)
@@ -1914,16 +1887,10 @@ append_glyphless_glyph (struct it *it, int face_id, char *str)
     }
 }
 
-/* Declared in xdisp.c */
-extern struct frame *last_glyphless_glyph_frame;
-extern unsigned last_glyphless_glyph_face_id;
-extern int last_glyphless_glyph_merged_face_id;
-extern Lisp_Object Qglyphless_char;
-
 /* Produce glyphs for a glyphless character for iterator IT.
    IT->glyphless_method specifies which method to use for displaying
    the character.  See the description of enum
-   glyphless_display_method in dispextern.h for the detail.
+   glyphless_display_method in dispextern.h for the details.
 
    FOR_NO_FONT is nonzero if and only if this is for a character that
    is not supproted by the coding system of the terminal.  ACRONYM, if
@@ -1935,11 +1902,11 @@ static void
 produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
 {
   int face_id;
-  int width, len;
+  int len;
   char buf[9], *str = "    ";
 
   /* Get a face ID for the glyph by utilizing a cache (the same way as
-     doen for `escape-glyph' in get_next_display_element).  */
+     done for `escape-glyph' in get_next_display_element).  */
   if (it->f == last_glyphless_glyph_frame
       && it->face_id == last_glyphless_glyph_face_id)
     {
@@ -1956,8 +1923,8 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
 
   if (it->glyphless_method == GLYPHLESS_DISPLAY_THIN_SPACE)
     {
-      /* As there's no way to produce a thin space, we produce
-        a space of canonical width..  */
+      /* As there's no way to produce a thin space, we produce a space
+        of canonical width.  */
       len = 1;
     }
   else if (it->glyphless_method == GLYPHLESS_DISPLAY_EMPTY_BOX)
@@ -1965,8 +1932,11 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
       len = CHAR_WIDTH (it->c);
       if (len == 0)
        len = 1;
-      else if (width > 4)
+      else if (len > 4)
        len = 4;
+      sprintf (buf, "[%.*s]", len, str);
+      len += 2;
+      str = buf;
     }
   else
     {
@@ -1975,7 +1945,7 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
          if (! STRINGP (acronym) && CHAR_TABLE_P (Vglyphless_char_display))
            acronym = CHAR_TABLE_REF (Vglyphless_char_display, it->c);
          buf[0] = '[';
-         str = STRINGP (acronym) ? (char *) SDATA (acronym) : "";
+         str = STRINGP (acronym) ? SSDATA (acronym) : "";
          for (len = 0; len < 6 && str[len] && ASCII_BYTE_P (str[len]); len++)
            buf[1 + len] = str[len];
          buf[1 + len] = ']';
@@ -1983,11 +1953,10 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
        }
       else
        {
-         xassert (it->glyphless_method == GLYPHLESS_DISPLAY_HEXA_CODE);
-         len = (it->c < 0x100 ? sprintf (buf, "U+%02X", it->c)
-                : it->c < 0x10000 ? sprintf (buf, "U+%04X", it->c)
-                : it->c <= MAX_UNICODE_CHAR ? sprintf (buf, "U+%06X", it->c)
-                : sprintf (buf, "E+%06X", it->c));
+         xassert (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));
        }
       str = buf;
     }
@@ -3084,8 +3053,7 @@ static void
 dissociate_if_controlling_tty (int fd)
 {
 #ifndef DOS_NT
-  int pgid;
-  EMACS_GET_TTY_PGRP (fd, &pgid); /* If tcgetpgrp succeeds, fd is the ctty. */
+  int pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */
   if (pgid != -1)
     {
 #if defined (USG5)
@@ -3185,7 +3153,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed)
   tty->mouse_highlight.mouse_face_window = Qnil;
 #endif
 
-  
+
 #ifndef DOS_NT
   set_tty_hooks (terminal);
 
@@ -3447,7 +3415,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
 
   terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
   init_kboard (terminal->kboard);
-  terminal->kboard->Vwindow_system = Qnil;
+  KVAR (terminal->kboard, Vwindow_system) = Qnil;
   terminal->kboard->next_kboard = all_kboards;
   all_kboards = terminal->kboard;
   terminal->kboard->reference_count++;
@@ -3778,7 +3746,7 @@ mark_ttys (void)
 void
 syms_of_term (void)
 {
-  DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo,
+  DEFVAR_BOOL ("system-uses-terminfo", system_uses_terminfo,
     doc: /* Non-nil means the system uses terminfo rather than termcap.
 This variable can be used by terminal emulator packages.  */);
 #ifdef TERMINFO
@@ -3787,20 +3755,20 @@ This variable can be used by terminal emulator packages.  */);
   system_uses_terminfo = 0;
 #endif
 
-  DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions,
+  DEFVAR_LISP ("suspend-tty-functions", Vsuspend_tty_functions,
     doc: /* Functions to be run after suspending a tty.
 The functions are run with one argument, the terminal object to be suspended.
 See `suspend-tty'.  */);
   Vsuspend_tty_functions = Qnil;
 
 
-  DEFVAR_LISP ("resume-tty-functions", &Vresume_tty_functions,
+  DEFVAR_LISP ("resume-tty-functions", Vresume_tty_functions,
     doc: /* Functions to be run after resuming a tty.
 The functions are run with one argument, the terminal object that was revived.
 See `resume-tty'.  */);
   Vresume_tty_functions = Qnil;
 
-  DEFVAR_BOOL ("visible-cursor", &visible_cursor,
+  DEFVAR_BOOL ("visible-cursor", visible_cursor,
               doc: /* Non-nil means to make the cursor very visible.
 This only has an effect when running in a text terminal.
 What means \"very visible\" is up to your terminal.  It may make the cursor
@@ -3828,8 +3796,3 @@ bigger, or it may make it blink, or it may do nothing at all.  */);
   encode_terminal_src = NULL;
   encode_terminal_dst = NULL;
 }
-
-
-
-/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
-   (do not change this comment) */