]> code.delx.au - gnu-emacs/blobdiff - src/terminal.c
Remove now-inaccurate bytecode comments
[gnu-emacs] / src / terminal.c
index 65b68955dbfcbb80fd6741bd1ed23fbfbf56a820..5dd9975a6f44125cb39e916d6414b585bd1c9b9e 100644 (file)
@@ -1,12 +1,12 @@
 /* Functions related to terminal devices.
-   Copyright (C) 2005-2015 Free Software Foundation, Inc.
+   Copyright (C) 2005-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
@@ -21,13 +21,18 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdio.h>
 
 #include "lisp.h"
+#include "character.h"
 #include "frame.h"
 #include "termchar.h"
 #include "termhooks.h"
-#include "charset.h"
-#include "coding.h"
 #include "keyboard.h"
 
+#if HAVE_STRUCT_UNIPAIR_UNICODE
+# include <errno.h>
+# include <linux/kd.h>
+# include <sys/ioctl.h>
+#endif
+
 /* Chain of all terminals currently in use.  */
 struct terminal *terminal_list;
 
@@ -37,10 +42,6 @@ static int next_terminal_id;
 /* The initial terminal device, created by initial_term_init.  */
 struct terminal *initial_terminal;
 
-Lisp_Object Qrun_hook_with_args;
-static Lisp_Object Qterminal_live_p;
-static Lisp_Object Qdelete_terminal_functions;
-
 static void delete_initial_terminal (struct terminal *);
 
 /* This setter is used only in this file, so it can be private.  */
@@ -258,6 +259,15 @@ get_named_terminal (const char *name)
   return NULL;
 }
 
+/* Allocate basically initialized terminal.  */
+
+static struct terminal *
+allocate_terminal (void)
+{
+  return ALLOCATE_ZEROED_PSEUDOVECTOR
+    (struct terminal, next_terminal, PVEC_TERMINAL);
+}
+
 /* Create a new terminal object of TYPE and add it to the terminal list.  RIF
    may be NULL if this terminal type doesn't support window-based redisplay.  */
 
@@ -521,6 +531,65 @@ selected frame's terminal).  */)
   return store_terminal_param (decode_live_terminal (terminal), parameter, value);
 }
 
+#if HAVE_STRUCT_UNIPAIR_UNICODE
+
+/* Compute the glyph code table for T.  */
+
+static void
+calculate_glyph_code_table (struct terminal *t)
+{
+  Lisp_Object glyphtab = Qt;
+  enum { initial_unipairs = 1000 };
+  int entry_ct = initial_unipairs;
+  struct unipair unipair_buffer[initial_unipairs];
+  struct unipair *entries = unipair_buffer;
+  struct unipair *alloced = 0;
+
+  while (true)
+    {
+      int fd = fileno (t->display_info.tty->output);
+      struct unimapdesc unimapdesc = { entry_ct, entries };
+      if (ioctl (fd, GIO_UNIMAP, &unimapdesc) == 0)
+       {
+         glyphtab = Fmake_char_table (Qnil, make_number (-1));
+         for (int i = 0; i < unimapdesc.entry_ct; i++)
+           char_table_set (glyphtab, entries[i].unicode,
+                           make_number (entries[i].fontpos));
+         break;
+       }
+      if (errno != ENOMEM)
+       break;
+      entry_ct = unimapdesc.entry_ct;
+      entries = alloced = xrealloc (alloced, entry_ct * sizeof *alloced);
+    }
+
+  xfree (alloced);
+  t->glyph_code_table = glyphtab;
+}
+#endif
+
+/* Return the glyph code in T of character CH, or -1 if CH does not
+   have a font position in T, or nil if T does not report glyph codes.  */
+
+Lisp_Object
+terminal_glyph_code (struct terminal *t, int ch)
+{
+#if HAVE_STRUCT_UNIPAIR_UNICODE
+  if (t->type == output_termcap)
+    {
+      /* As a hack, recompute the table when CH is the maximum
+        character.  */
+      if (NILP (t->glyph_code_table) || ch == MAX_CHAR)
+       calculate_glyph_code_table (t);
+
+      if (! EQ (t->glyph_code_table, Qt))
+       return char_table_ref (t->glyph_code_table, ch);
+    }
+#endif
+
+  return Qnil;
+}
+
 /* Initial frame has no device-dependent output data, but has
    face cache which should be freed when the frame is deleted.  */