Revert 2008-01-13 change: this is a generated file.
[bpt/emacs.git] / src / term.c
index ce3b49e..6993640 100644 (file)
@@ -1,6 +1,7 @@
 /* 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 Free Software Foundation, Inc.
+                 2002, 2003, 2004, 2005, 2006, 2007, 2008
+                 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -37,6 +38,7 @@ Boston, MA 02110-1301, USA.  */
 #endif
 
 #include <signal.h>
+#include <stdarg.h>
 
 #include "lisp.h"
 #include "termchar.h"
@@ -182,15 +184,15 @@ static int system_uses_terminfo;
 char *tparam ();
 
 extern char *tgetstr ();
-
-static void term_clear_mouse_face ();
-static void term_mouse_highlight (struct frame *f, int x, int y);
 \f
 
 #ifdef HAVE_GPM
 #include <sys/fcntl.h>
 #include "buffer.h"
 
+static void term_clear_mouse_face ();
+static void term_mouse_highlight (struct frame *f, int x, int y);
+
 /* The device for which we have enabled gpm support (or NULL).  */
 struct tty_display_info *gpm_tty = NULL;
 
@@ -202,7 +204,7 @@ struct tty_display_info *gpm_tty = NULL;
 static int mouse_face_beg_row, mouse_face_beg_col;
 static int mouse_face_end_row, mouse_face_end_col;
 static int mouse_face_past_end;
-static Lisp_Object Qmouse_face_window;
+static Lisp_Object mouse_face_window;
 static int mouse_face_face_id;
 
 static int pos_x, pos_y;
@@ -739,6 +741,8 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
   cmcheckmagic (tty);
 }
 
+#ifdef HAVE_GPM                        /* Only used by GPM code.  */
+
 static void
 tty_write_glyphs_with_face (f, string, len, face_id)
      register struct frame *f;
@@ -797,7 +801,7 @@ tty_write_glyphs_with_face (f, string, len, face_id)
 
   cmcheckmagic (tty);
 }
-
+#endif
 
 /* An implementation of insert_glyphs for termcap frames. */
 
@@ -1272,9 +1276,9 @@ static char **term_get_fkeys_address;
 static KBOARD *term_get_fkeys_kboard;
 static Lisp_Object term_get_fkeys_1 ();
 
-/* Find the escape codes sent by the function keys for Vfunction_key_map.
+/* Find the escape codes sent by the function keys for Vinput_decode_map.
    This function scans the termcap function key sequence entries, and
-   adds entries to Vfunction_key_map for each function key it finds.  */
+   adds entries to Vinput_decode_map for each function key it finds.  */
 
 static void
 term_get_fkeys (address, kboard)
@@ -1304,14 +1308,14 @@ term_get_fkeys_1 ()
   KBOARD *kboard = term_get_fkeys_kboard;
   
   /* This can happen if CANNOT_DUMP or with strange options.  */
-  if (!initialized)
-    kboard->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
+  if (!KEYMAPP (kboard->Vinput_decode_map))
+    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->Vlocal_function_key_map, build_string (sequence),
+       Fdefine_key (kboard->Vinput_decode_map, build_string (sequence),
                     Fmake_vector (make_number (1),
                                   intern (keys[i].name)));
     }
@@ -1331,13 +1335,13 @@ term_get_fkeys_1 ()
        if (k0)
          /* Define f0 first, so that f10 takes precedence in case the
             key sequences happens to be the same.  */
-         Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0),
+         Fdefine_key (kboard->Vinput_decode_map, build_string (k0),
                       Fmake_vector (make_number (1), intern ("f0")));
-       Fdefine_key (kboard->Vlocal_function_key_map, build_string (k_semi),
+       Fdefine_key (kboard->Vinput_decode_map, build_string (k_semi),
                     Fmake_vector (make_number (1), intern ("f10")));
       }
     else if (k0)
-      Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0),
+      Fdefine_key (kboard->Vinput_decode_map, build_string (k0),
                   Fmake_vector (make_number (1), intern (k0_name)));
   }
 
@@ -1360,7 +1364,7 @@ term_get_fkeys_1 ()
          if (sequence)
            {
              sprintf (fkey, "f%d", i);
-             Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence),
+             Fdefine_key (kboard->Vinput_decode_map, build_string (sequence),
                           Fmake_vector (make_number (1),
                                         intern (fkey)));
            }
@@ -1377,7 +1381,7 @@ term_get_fkeys_1 ()
        {                                                               \
          char *sequence = tgetstr (cap2, address);                     \
          if (sequence)                                                 \
-           Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), \
+           Fdefine_key (kboard->Vinput_decode_map, build_string (sequence), \
                         Fmake_vector (make_number (1),                 \
                                       intern (sym)));                  \
        }
@@ -2360,7 +2364,7 @@ term_mouse_moveto (int x, int y)
 static void
 term_show_mouse_face (enum draw_glyphs_face draw)
 {
-  struct window *w = XWINDOW (Qmouse_face_window);
+  struct window *w = XWINDOW (mouse_face_window);
   int save_x, save_y;
   int i;
 
@@ -2439,12 +2443,12 @@ term_show_mouse_face (enum draw_glyphs_face draw)
 static void
 term_clear_mouse_face ()
 {
-  if (!NILP (Qmouse_face_window))
+  if (!NILP (mouse_face_window))
     term_show_mouse_face (DRAW_NORMAL_TEXT);
 
   mouse_face_beg_row = mouse_face_beg_col = -1;
   mouse_face_end_row = mouse_face_end_col = -1;
-  Qmouse_face_window = Qnil;
+  mouse_face_window = Qnil;
 }
 
 /* Find the glyph matrix position of buffer position POS in window W.
@@ -2541,7 +2545,7 @@ term_mouse_highlight (struct frame *f, int x, int y)
   if (!WINDOWP (window))
     return;
 
-  if (!EQ (window, Qmouse_face_window))
+  if (!EQ (window, mouse_face_window))
     term_clear_mouse_face ();
 
   w = XWINDOW (window);
@@ -2624,7 +2628,7 @@ term_mouse_highlight (struct frame *f, int x, int y)
        noverlays = sort_overlays (overlay_vec, noverlays, w);
 
        /* Check mouse-face highlighting.  */
-       if (!(EQ (window, Qmouse_face_window)
+       if (!(EQ (window, mouse_face_window)
              && y >= mouse_face_beg_row
              && y <= mouse_face_end_row
              && (y > mouse_face_beg_row
@@ -2674,7 +2678,7 @@ term_mouse_highlight (struct frame *f, int x, int y)
                  = !fast_find_position (w, XFASTINT (after),
                                         &mouse_face_end_col,
                                         &mouse_face_end_row);
-               Qmouse_face_window = window;
+               mouse_face_window = window;
 
                mouse_face_face_id
                  = face_at_buffer_position (w, pos, 0, 0,
@@ -2709,7 +2713,7 @@ term_mouse_highlight (struct frame *f, int x, int y)
                  = !fast_find_position (w, XFASTINT (after),
                                         &mouse_face_end_col,
                                         &mouse_face_end_row);
-               Qmouse_face_window = window;
+               mouse_face_window = window;
 
                mouse_face_face_id
                  = face_at_buffer_position (w, pos, 0, 0,
@@ -2885,7 +2889,6 @@ int
 handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct input_event* hold_quit)
 {
   struct frame *f = XFRAME (tty->top_frame);
-  int fd;
   struct input_event ie;
   int do_help = 0;
   int count = 0;
@@ -2895,24 +2898,10 @@ handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct in
   ie.arg = Qnil;
 
   if (event->type & (GPM_MOVE | GPM_DRAG)) {
-    unsigned char buf[6 * sizeof (short)];
-    unsigned short *arg = (unsigned short *) buf + 1;
-    const char *name;
-
     previous_help_echo_string = help_echo_string;
     help_echo_string = Qnil;
 
-    /* Display mouse pointer */
-    buf[sizeof(short) - 1] = 2;  /* set selection */
-
-    arg[0] = arg[2] = (unsigned short) event->x + gpm_zerobased;
-    arg[1] = arg[3] = (unsigned short) event->y + gpm_zerobased;
-    arg[4] = (unsigned short) 3;
-    
-    name = ttyname (0);
-    fd = open (name, O_WRONLY);
-    ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1);
-    close (fd);
+    Gpm_DrawPointer (event->x, event->y, fileno (tty->output));
 
     if (!term_mouse_movement (f, event))
       help_echo_string = previous_help_echo_string;
@@ -2955,10 +2944,10 @@ handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct in
   return count;
 }
 
-DEFUN ("term-open-connection", Fterm_open_connection, Sterm_open_connection,
+DEFUN ("gpm-mouse-start", Fgpm_mouse_start, Sgpm_mouse_start,
        0, 0, 0,
        doc: /* Open a connection to Gpm.
-We only support Gpm on one tty at a time.  */)
+Gpm-mouse can only be activated for one tty at a time.  */)
      ()
 {
   struct frame *f = SELECTED_FRAME ();
@@ -2967,8 +2956,12 @@ We only support Gpm on one tty at a time.  */)
        ? (f)->terminal->display_info.tty : NULL);
   Gpm_Connect connection;
 
-  if (gpm_tty || !tty)         /* Already running, or not applicable.  */
-    return Qnil;
+  if (!tty)
+    error ("Gpm-mouse only works in the GNU/Linux console");
+  if (gpm_tty == tty)
+    return Qnil;               /* Already activated, nothing to do.  */
+  if (gpm_tty)
+    error ("Gpm-mouse can only be activated for one tty at a time");
 
   connection.eventMask = ~0;
   connection.defaultMask = ~GPM_HARD;
@@ -2977,26 +2970,38 @@ We only support Gpm on one tty at a time.  */)
   gpm_zerobased = 1;
 
   if (Gpm_Open (&connection, 0) < 0)
-    return Qnil;
+    error ("Gpm-mouse failed to connect to the gpm daemon");
   else
     {
       gpm_tty = tty;
+      /* `init_sys_modes' arranges for mouse movements sent through gpm_fd
+        to generate SIGIOs.  Apparently we need to call reset_sys_modes
+        before calling init_sys_modes.  */
       reset_sys_modes (tty);
       init_sys_modes (tty);
       add_gpm_wait_descriptor (gpm_fd);
-      return Qt;
+      return Qnil;
     }
 }
 
-DEFUN ("term-close-connection", Fterm_close_connection, Sterm_close_connection,
+DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop,
        0, 0, 0,
        doc: /* Close a connection to Gpm.  */)
      ()
 {
-   delete_gpm_wait_descriptor (gpm_fd);
-   while (Gpm_Close()); /* close all the stack */
-   gpm_tty = NULL;
-   return Qnil;
+  struct frame *f = SELECTED_FRAME ();
+  struct tty_display_info *tty
+    = ((f)->output_method == output_termcap
+       ? (f)->terminal->display_info.tty : NULL);
+
+  if (!tty || gpm_tty != tty)
+    return Qnil;       /* Not activated on this terminal, nothing to do.  */
+  
+  if (gpm_fd >= 0)
+    delete_gpm_wait_descriptor (gpm_fd);
+  while (Gpm_Close()); /* close all the stack */
+  gpm_tty = NULL;
+  return Qnil;
 }
 #endif /* HAVE_GPM */
 
@@ -3269,7 +3274,7 @@ init_tty (char *name, char *terminal_type, int must_succeed)
 
 #ifdef HAVE_GPM
   terminal->mouse_position_hook = term_mouse_position;
-  Qmouse_face_window = Qnil;
+  mouse_face_window = Qnil;
 #endif
 
 #ifdef WINDOWSNT
@@ -3484,6 +3489,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
 #ifdef MULTI_KBOARD
   terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
   init_kboard (terminal->kboard);
+  terminal->kboard->Vwindow_system = Qnil;
   terminal->kboard->next_kboard = all_kboards;
   all_kboards = terminal->kboard;
   terminal->kboard->reference_count++;
@@ -3750,14 +3756,14 @@ maybe_fatal (must_succeed, buffer, terminal, str1, str2, arg1, arg2)
   abort ();
 }
 
-/* VARARGS 1 */
 void
-fatal (str, arg1, arg2)
-     char *str, *arg1, *arg2;
+fatal (const char *str, ...)
 {
+  va_list ap;
+  va_start (ap, str);
   fprintf (stderr, "emacs: ");
-  fprintf (stderr, str, arg1, arg2);
-  fprintf (stderr, "\n");
+  vfprintf (stderr, str, ap);
+  va_end (ap);
   fflush (stderr);
   exit (1);
 }
@@ -3901,10 +3907,10 @@ bigger, or it may make it blink, or it may do nothing at all.  */);
   defsubr (&Ssuspend_tty);
   defsubr (&Sresume_tty);
 #ifdef HAVE_GPM
-  defsubr (&Sterm_open_connection);
-  defsubr (&Sterm_close_connection);
+  defsubr (&Sgpm_mouse_start);
+  defsubr (&Sgpm_mouse_stop);
 
-  staticpro (&Qmouse_face_window);
+  staticpro (&mouse_face_window);
 #endif /* HAVE_GPM */
 }