diff src/redisplay-tty.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 11054d720c21
line wrap: on
line diff
--- a/src/redisplay-tty.c	Mon Aug 13 11:19:22 2007 +0200
+++ b/src/redisplay-tty.c	Mon Aug 13 11:20:41 2007 +0200
@@ -53,12 +53,17 @@
    invoking them correctly. */
 /* # include <curses.h> */
 /* # include <term.h> */
-EXTERN_C int tgetent (const char *, const char *);
-EXTERN_C int tgetflag (const char *);
-EXTERN_C int tgetnum (const char *);
-EXTERN_C char *tgetstr (const char *, char **);
-EXTERN_C void tputs (const char *, int, void (*)(int));
-
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int tgetent (CONST char *, CONST char *);
+extern int tgetflag (CONST char *);
+extern int tgetnum (CONST char *);
+extern char *tgetstr (CONST char *, char **);
+extern void tputs (CONST char *, int, void (*)(int));
+#ifdef __cplusplus
+}
+#endif
 #define FORCE_CURSOR_UPDATE(c) send_string_to_tty_console (c, 0, 0)
 #define OUTPUTN(c, a, n)			\
   do {						\
@@ -102,7 +107,7 @@
  column, so we use emchar_string_displayed_columns().
  ****************************************************************************/
 static int
-tty_text_width (struct frame *f, struct face_cachel *cachel, const Emchar *str,
+tty_text_width (struct frame *f, struct face_cachel *cachel, CONST Emchar *str,
 		Charcount len)
 {
   return emchar_string_displayed_columns (str, len);
@@ -133,40 +138,39 @@
 }
 
 /*****************************************************************************
- tty_frame_output_begin
+ tty_output_begin
 
  Perform any necessary initialization prior to an update.
  ****************************************************************************/
 #ifdef DEBUG_XEMACS
-void tty_frame_output_begin (struct frame *f);
+void tty_output_begin (struct device *d);
 void
 #else
 static void
 #endif
-tty_frame_output_begin (struct frame *f)
+tty_output_begin (struct device *d)
 {
 #ifndef HAVE_TERMIOS
   /* Termcap requires `ospeed' to be a global variable so we have to
      always set it for whatever tty console we are actually currently
      working with. */
-  ospeed = DEVICE_TTY_DATA (XDEVICE (FRAME_DEVICE (f)))->ospeed;
+  ospeed = DEVICE_TTY_DATA (d)->ospeed;
 #endif
 }
 
 /*****************************************************************************
- tty_frame_output_end
+ tty_output_end
 
  Perform any necessary flushing of queues when an update has completed.
  ****************************************************************************/
 #ifdef DEBUG_XEMACS
-void tty_frame_output_end (struct frame *f);
+void tty_output_end (struct device *d);
 void
 #else
 static void
 #endif
-tty_frame_output_end (struct frame *f)
+tty_output_end (struct device *d)
 {
-  struct device *d = XDEVICE (FRAME_DEVICE (f));
   struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
 
   CONSOLE_TTY_CURSOR_X (c) = CONSOLE_TTY_FINAL_CURSOR_X (c);
@@ -329,28 +333,78 @@
 					       window, ERROR_ME_NOT, 1);
 
 	      if (IMAGE_INSTANCEP (instance))
-		{
-		  switch (XIMAGE_INSTANCE_TYPE (instance))
+		switch (XIMAGE_INSTANCE_TYPE (instance))
+		  {
+		  case IMAGE_TEXT:
 		    {
-		    case IMAGE_MONO_PIXMAP:
-		    case IMAGE_COLOR_PIXMAP:
-		    case IMAGE_SUBWINDOW:
-		    case IMAGE_WIDGET:
-		      /* just do nothing here */
-		      break;
+		      Bufbyte *temptemp;
+		      Lisp_Object string =
+			XIMAGE_INSTANCE_TEXT_STRING (instance);
+		      Bytecount len = XSTRING_LENGTH (string);
+
+		      /* In the unlikely instance that a garbage-collect
+			 occurs during encoding, we at least need to
+			 copy the string.
+			 */
+		      temptemp = (Bufbyte *) alloca (len);
+		      memcpy (temptemp, XSTRING_DATA (string), len);
+		      {
+			int i;
+
+			/* Now truncate the first rb->object.dglyph.xoffset
+			   columns. */
+			for (i = 0; i < rb->object.dglyph.xoffset;)
+			  {
+#ifdef MULE
+			    Emchar ch = charptr_emchar (temptemp);
+			    i += XCHARSET_COLUMNS (CHAR_CHARSET (ch));
+#else
+			    i++; /* telescope this */
+#endif
+			    INC_CHARPTR (temptemp);
+			  }
 
-		    case IMAGE_NOTHING:
-		      /* nothing is as nothing does */
-		      break;
+			/* If we truncated one column too many, then
+			   add a space at the beginning. */
+			if (i > rb->object.dglyph.xoffset)
+			  {
+			    assert (i > 0);
+			    *--temptemp = ' ';
+			    i--;
+			  }
+			len -= i;
+		      }
+
+		      tty_output_bufbyte_string (w, dl, temptemp, len,
+						 xpos, findex, 0);
 
-		    case IMAGE_TEXT:
-		    case IMAGE_POINTER:
-		    default:
-		      abort ();
+		      if (xpos >= cursor_start
+			  && (cursor_start <
+			      xpos + (bufbyte_string_displayed_columns
+				      (temptemp, len))))
+			{
+			  cmgoto (f, dl->ypos - 1, cursor_start);
+			}
 		    }
-		  IMAGE_INSTANCE_OPTIMIZE_OUTPUT
-		    (XIMAGE_INSTANCE (instance)) = 0;
-		}
+		    break;
+
+		  case IMAGE_MONO_PIXMAP:
+		  case IMAGE_COLOR_PIXMAP:
+		  case IMAGE_SUBWINDOW:
+		  case IMAGE_WIDGET:
+		    /* just do nothing here */
+		    break;
+
+		  case IMAGE_POINTER:
+		    abort ();
+
+		  case IMAGE_NOTHING:
+		    /* nothing is as nothing does */
+		    break;
+
+		  default:
+		    abort ();
+		  }
 
 	      xpos += rb->width;
 	      elt++;
@@ -410,7 +464,7 @@
 static void
 tty_clear_region (Lisp_Object window, struct device* d, struct frame * f,
 		  face_index findex, int x, int y,
-		  int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
+		  int width, int height, Lisp_Object fcolor, Lisp_Object bcolor, 
 		  Lisp_Object background_pixmap)
 {
   struct console *c = XCONSOLE (FRAME_CONSOLE (f));
@@ -511,7 +565,7 @@
       clear_to_end (f);
 #else
       /* #### Not implemented. */
-      stderr_out ("Not yet.\n");
+      fprintf (stderr, "Not yet.\n");
 #endif
     }
   tty_turn_off_frame_face (f, Vdefault_face);
@@ -882,7 +936,7 @@
   OUTPUT1_IF (c, TTY_SD (c).keypad_off);
   OUTPUT1_IF (c, TTY_SD (c).cursor_normal);
   OUTPUT1_IF (c, TTY_SD (c).end_motion);
-  tty_frame_output_end (XFRAME (CONSOLE_SELECTED_FRAME (c)));
+  tty_output_end (XDEVICE (CONSOLE_SELECTED_DEVICE (c)));
 }
 
 /*****************************************************************************
@@ -895,11 +949,11 @@
 {
   Lisp_Object dev = CONSOLE_SELECTED_DEVICE (c);
 
-  if (!NILP (dev))
+  if (!GC_NILP (dev))
     {
       Lisp_Object frm = DEVICE_SELECTED_FRAME (XDEVICE (dev));
 
-      if (!NILP (frm))
+      if (!GC_NILP (frm))
 	{
 	  struct frame *f = XFRAME (frm);
 
@@ -909,7 +963,7 @@
 
 	  /* And then stick the cursor there. */
 	  tty_set_final_cursor_coords (f, f->height, 0);
-	  tty_frame_output_end (f);
+	  tty_output_end (XDEVICE (dev));
 	}
     }
 }
@@ -920,7 +974,7 @@
 
 
 /* FLAGS - these don't need to be console local since only one console
-	   can be being updated at a time. */
+ 	   can be being updated at a time. */
 static int insert_mode_on;		/* nonzero if in insert mode */
 static int standout_mode_on;		/* nonzero if in standout mode */
 static int underline_mode_on;		/* nonzero if in underline mode */
@@ -1054,12 +1108,12 @@
   CONSOLE_TTY_DATA (c)->term_entry_buffer = (char *) xmalloc (2044);
   bufptr = CONSOLE_TTY_DATA (c)->term_entry_buffer;
 
-#ifdef SIGTTOU
+#if !defined(WIN32)
   /* SIGTT* don't exist under win32 */
   EMACS_BLOCK_SIGNAL (SIGTTOU);
 #endif
   status = tgetent (entry_buffer, terminal_type);
-#ifdef SIGTTOU
+#if !defined(WIN32)
   EMACS_UNBLOCK_SIGNAL (SIGTTOU);
 #endif
 #if 0
@@ -1250,8 +1304,7 @@
 
 struct fkey_table
 {
-  const char *cap;
-  const char *name;
+  CONST char *cap, *name;
 };
 
   /* Termcap capability names that correspond directly to X keysyms.
@@ -1383,7 +1436,7 @@
       char *sequence = tgetstr (keys[i].cap, address);
       if (sequence)
 	Fdefine_key (function_key_map,
-		     build_ext_string (sequence, Qbinary),
+		     build_ext_string (sequence, FORMAT_BINARY),
 		     vector1 (intern (keys[i].name)));
     }
 
@@ -1391,18 +1444,22 @@
      describes F10, whereas othertimes it describes F0 and "k;" describes F10.
      We will attempt to politely accommodate both systems by testing for
      "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
-  */
+     */
   {
-    const char *k_semi  = tgetstr ("k;", address);
-    const char *k0      = tgetstr ("k0", address);
+    char *k_semi  = tgetstr ("k;", address);
+    char *k0      = tgetstr ("k0", address);
+    CONST char *k0_name = "f10";
 
     if (k_semi)
-      Fdefine_key (function_key_map, build_ext_string (k_semi, Qbinary),
-		   vector1 (intern ("f10")));
+      {
+	Fdefine_key (function_key_map, build_ext_string (k_semi, FORMAT_BINARY),
+		     vector1 (intern ("f10")));
+	k0_name = "f0";
+      }
 
     if (k0)
-      Fdefine_key (function_key_map, build_ext_string (k0, Qbinary),
-		   vector1 (intern (k_semi ? "f0" : "f10")));
+      Fdefine_key (function_key_map, build_ext_string (k0, FORMAT_BINARY),
+		   vector1 (intern (k0_name)));
   }
 
   /* Set up cookies for numbered function keys above f10. */
@@ -1425,46 +1482,47 @@
 	    {
 	      sprintf (fkey, "f%d", i);
 	      Fdefine_key (function_key_map,
-			   build_ext_string (sequence, Qbinary),
+			   build_ext_string (sequence, FORMAT_BINARY),
 			   vector1 (intern (fkey)));
 	    }
 	}
       }
-  }
+   }
 
   /*
    * Various mappings to try and get a better fit.
    */
-#define CONDITIONAL_REASSIGN(cap1, cap2, keyname) do {		\
-    if (!tgetstr (cap1, address))				\
-      {								\
-	char *sequence = tgetstr (cap2, address);		\
-	if (sequence)						\
-	  Fdefine_key (function_key_map,			\
-		       build_ext_string (sequence, Qbinary),	\
-		       vector1 (intern (keyname)));		\
-      }								\
-  } while (0)
+  {
+#define CONDITIONAL_REASSIGN(cap1, cap2, sym)				\
+      if (!tgetstr (cap1, address))					\
+	{								\
+	  char *sequence = tgetstr (cap2, address);			\
+	  if (sequence)							\
+	    Fdefine_key (function_key_map,				\
+			 build_ext_string (sequence, FORMAT_BINARY),	\
+			 vector1 (intern (sym)));			\
+	}
 
-  /* if there's no key_next keycap, map key_npage to `next' keysym */
-  CONDITIONAL_REASSIGN ("%5", "kN", "next");
-  /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
-  CONDITIONAL_REASSIGN ("%8", "kP", "prior");
-  /* if there's no key_dc keycap, map key_ic to `insert' keysym */
-  CONDITIONAL_REASSIGN ("kD", "kI", "insert");
+      /* if there's no key_next keycap, map key_npage to `next' keysym */
+      CONDITIONAL_REASSIGN ("%5", "kN", "next");
+      /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
+      CONDITIONAL_REASSIGN ("%8", "kP", "prior");
+      /* if there's no key_dc keycap, map key_ic to `insert' keysym */
+      CONDITIONAL_REASSIGN ("kD", "kI", "insert");
 
-  /* IBM has their own non-standard dialect of terminfo.
-     If the standard name isn't found, try the IBM name.  */
-  CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
-  CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
-  CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
-  CONDITIONAL_REASSIGN ("%7", "ki", "menu");
-  CONDITIONAL_REASSIGN ("@7", "kw", "end");
-  CONDITIONAL_REASSIGN ("F1", "k<", "f11");
-  CONDITIONAL_REASSIGN ("F2", "k>", "f12");
-  CONDITIONAL_REASSIGN ("%1", "kq", "help");
-  CONDITIONAL_REASSIGN ("*6", "kU", "select");
+      /* IBM has their own non-standard dialect of terminfo.
+	 If the standard name isn't found, try the IBM name.  */
+      CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
+      CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
+      CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
+      CONDITIONAL_REASSIGN ("%7", "ki", "menu");
+      CONDITIONAL_REASSIGN ("@7", "kw", "end");
+      CONDITIONAL_REASSIGN ("F1", "k<", "f11");
+      CONDITIONAL_REASSIGN ("F2", "k>", "f12");
+      CONDITIONAL_REASSIGN ("%1", "kq", "help");
+      CONDITIONAL_REASSIGN ("*6", "kU", "select");
 #undef CONDITIONAL_REASSIGN
+  }
 
   return Qnil;
 }
@@ -1486,8 +1544,8 @@
   CONSOLE_HAS_METHOD (tty, clear_to_window_end);
   CONSOLE_HAS_METHOD (tty, clear_region);
   CONSOLE_HAS_METHOD (tty, clear_frame);
-  CONSOLE_HAS_METHOD (tty, frame_output_begin);
-  CONSOLE_HAS_METHOD (tty, frame_output_end);
+  CONSOLE_HAS_METHOD (tty, output_begin);
+  CONSOLE_HAS_METHOD (tty, output_end);
   CONSOLE_HAS_METHOD (tty, flash);
   CONSOLE_HAS_METHOD (tty, ring_bell);
   CONSOLE_HAS_METHOD (tty, set_final_cursor_coords);