Cleanup terminal handling code.

* dispextern.h (get_named_tty): Remove prototype but...
* termhooks.h (get_named_terminal): ...resurrect it under
more meaningful name.
(get_terminal): Likewise, but with...
(decode_live_terminal): ...this name.
(decode_tty_terminal): Add prototype.
* term.c (get_tty_terminal): Remove.
(get_named_tty): Remove.
(Ftty_display_color_p, Ftty_display_color_cells, Ftty_type)
(Fcontrolling_tty_p, Fsuspend_tty, Fresume_tty):
Use decode_tty_terminal.
(Ftty_no_underline, Ftty_top_frame): Use decode_live_terminal.
* terminal.c (get_terminal): Refactor to...
(decode_terminal, decode_live_terminal): ...new functions.
(decode_tty_terminal): Replacement for get_tty_terminal.
(get_named_terminal): Likewise for get_named_tty.
* coding.c (Fset_terminal_coding_system_internal)
(Fterminal_coding_system, Fset_keyboard_coding_system_internal):
(Fkeyboard_coding_system):
* composite.c (Fcomposition_get_gstring):
* dispnew.c (Fsend_string_to_terminal):
* frame.c (Fmake_terminal_frame):
* nsfns.m (check_ns_display_info):
* w32fns.c, xfns.c (check_x_display_info):
* xselect.c (frame_for_x_selection): Use decode_live_terminal.
* keyboard.c (handle_interrupt_signal, handle_interrupt)
(Fset_quit_char): Use get_named_terminal.
(Fset_output_flow_control, Fset_input_meta_mode):
Use decode_tty_terminal.
This commit is contained in:
Dmitry Antipov 2014-10-14 16:45:41 +04:00
parent 5fa75d8eba
commit bb75cdf9c7
14 changed files with 135 additions and 141 deletions

View file

@ -1,3 +1,36 @@
2014-10-14 Dmitry Antipov <dmantipov@yandex.ru>
Cleanup terminal handling code.
* dispextern.h (get_named_tty): Remove prototype but...
* termhooks.h (get_named_terminal): ...resurrect it under
more meaningful name.
(get_terminal): Likewise, but with...
(decode_live_terminal): ...this name.
(decode_tty_terminal): Add prototype.
* term.c (get_tty_terminal): Remove.
(get_named_tty): Remove.
(Ftty_display_color_p, Ftty_display_color_cells, Ftty_type)
(Fcontrolling_tty_p, Fsuspend_tty, Fresume_tty):
Use decode_tty_terminal.
(Ftty_no_underline, Ftty_top_frame): Use decode_live_terminal.
* terminal.c (get_terminal): Refactor to...
(decode_terminal, decode_live_terminal): ...new functions.
(decode_tty_terminal): Replacement for get_tty_terminal.
(get_named_terminal): Likewise for get_named_tty.
* coding.c (Fset_terminal_coding_system_internal)
(Fterminal_coding_system, Fset_keyboard_coding_system_internal):
(Fkeyboard_coding_system):
* composite.c (Fcomposition_get_gstring):
* dispnew.c (Fsend_string_to_terminal):
* frame.c (Fmake_terminal_frame):
* nsfns.m (check_ns_display_info):
* w32fns.c, xfns.c (check_x_display_info):
* xselect.c (frame_for_x_selection): Use decode_live_terminal.
* keyboard.c (handle_interrupt_signal, handle_interrupt)
(Fset_quit_char): Use get_named_terminal.
(Fset_output_flow_control, Fset_input_meta_mode):
Use decode_tty_terminal.
2014-10-13 Eli Zaretskii <eliz@gnu.org>
* w32term.h (ALIGN_STACK): Use _WIN64, not _W64, to distinguish

View file

@ -9759,7 +9759,7 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern
doc: /* Internal use only. */)
(Lisp_Object coding_system, Lisp_Object terminal)
{
struct terminal *term = get_terminal (terminal, 1);
struct terminal *term = decode_live_terminal (terminal);
struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (term);
CHECK_SYMBOL (coding_system);
setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
@ -9800,7 +9800,7 @@ frame's terminal device. */)
(Lisp_Object terminal)
{
struct coding_system *terminal_coding
= TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1));
= TERMINAL_TERMINAL_CODING (decode_live_terminal (terminal));
Lisp_Object coding_system = CODING_ID_NAME (terminal_coding->id);
/* For backward compatibility, return nil if it is `undecided'. */
@ -9812,7 +9812,7 @@ DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_intern
doc: /* Internal use only. */)
(Lisp_Object coding_system, Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_live_terminal (terminal);
CHECK_SYMBOL (coding_system);
if (NILP (coding_system))
coding_system = Qno_conversion;
@ -9831,7 +9831,7 @@ DEFUN ("keyboard-coding-system",
(Lisp_Object terminal)
{
return CODING_ID_NAME (TERMINAL_KEYBOARD_CODING
(get_terminal (terminal, 1))->id);
(decode_live_terminal (terminal))->id);
}

View file

@ -1719,7 +1719,7 @@ should be ignored. */)
if (! FONT_OBJECT_P (font_object))
{
struct coding_system *coding;
struct terminal *terminal = get_terminal (font_object, 1);
struct terminal *terminal = decode_live_terminal (font_object);
coding = ((TERMINAL_TERMINAL_CODING (terminal)->common_flags
& CODING_REQUIRE_ENCODING_MASK)

View file

@ -3500,7 +3500,6 @@ extern void calculate_costs (struct frame *);
extern void produce_glyphs (struct it *);
extern bool tty_capable_p (struct tty_display_info *, unsigned);
extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
extern struct terminal *get_named_tty (const char *);
extern void create_tty_output (struct frame *);
extern struct terminal *init_tty (const char *, const char *, bool);
extern void tty_append_glyph (struct it *);

View file

@ -5611,16 +5611,13 @@ the currently selected frame. In batch mode, STRING is sent to stdout
when TERMINAL is nil. */)
(Lisp_Object string, Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_live_terminal (terminal);
FILE *out;
/* ??? Perhaps we should do something special for multibyte strings here. */
CHECK_STRING (string);
block_input ();
if (!t)
error ("Unknown terminal device");
if (t->type == output_initial)
out = stdout;
else if (t->type != output_termcap && t->type != output_msdos_raw)

View file

@ -964,7 +964,7 @@ affects all frames on the same terminal device. */)
if (CONSP (terminal))
{
terminal = XCDR (terminal);
t = get_terminal (terminal, 1);
t = decode_live_terminal (terminal);
}
#ifdef MSDOS
if (t && t != the_only_display_info.terminal)

View file

@ -10349,7 +10349,7 @@ static void
handle_interrupt_signal (int sig)
{
/* See if we have an active terminal on our controlling tty. */
struct terminal *terminal = get_named_tty ("/dev/tty");
struct terminal *terminal = get_named_terminal ("/dev/tty");
if (!terminal)
{
/* If there are no frames there, let's pretend that we are a
@ -10403,7 +10403,7 @@ handle_interrupt (bool in_signal_handler)
cancel_echoing ();
/* XXX This code needs to be revised for multi-tty support. */
if (!NILP (Vquit_flag) && get_named_tty ("/dev/tty"))
if (!NILP (Vquit_flag) && get_named_terminal ("/dev/tty"))
{
if (! in_signal_handler)
{
@ -10615,9 +10615,10 @@ Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
See also `current-input-mode'. */)
(Lisp_Object flow, Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_tty_terminal (terminal);
struct tty_display_info *tty;
if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw))
if (!t)
return Qnil;
tty = t->display_info.tty;
@ -10657,11 +10658,11 @@ the currently selected frame.
See also `current-input-mode'. */)
(Lisp_Object meta, Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_tty_terminal (terminal);
struct tty_display_info *tty;
int new_meta;
if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw))
if (!t)
return Qnil;
tty = t->display_info.tty;
@ -10698,9 +10699,10 @@ process.
See also `current-input-mode'. */)
(Lisp_Object quit)
{
struct terminal *t = get_named_tty ("/dev/tty");
struct terminal *t = get_named_terminal ("/dev/tty");
struct tty_display_info *tty;
if (t == NULL || (t->type != output_termcap && t->type != output_msdos_raw))
if (!t)
return Qnil;
tty = t->display_info.tty;

View file

@ -133,7 +133,7 @@ Updated by Christian Limpach (chris@nice.ch)
}
else if (TERMINALP (object))
{
struct terminal *t = get_terminal (object, 1);
struct terminal *t = decode_live_terminal (object);
if (t->type != output_ns)
error ("Terminal %d is not a Nextstep display", t->id);
@ -2541,7 +2541,7 @@ and GNUstep implementations ("distributor-specific release
Internal use only, use `display-monitor-attributes-list' instead. */)
(Lisp_Object terminal)
{
struct terminal *term = get_terminal (terminal, 1);
struct terminal *term = decode_live_terminal (terminal);
NSArray *screens;
NSUInteger i, n_monitors;
struct MonitorInfo *monitors;

View file

@ -77,7 +77,6 @@ static void tty_turn_off_highlight (struct tty_display_info *);
static void tty_show_cursor (struct tty_display_info *);
static void tty_hide_cursor (struct tty_display_info *);
static void tty_background_highlight (struct tty_display_info *tty);
static struct terminal *get_tty_terminal (Lisp_Object, bool);
static void clear_tty_hooks (struct terminal *terminal);
static void set_tty_hooks (struct terminal *terminal);
static void dissociate_if_controlling_tty (int fd);
@ -2032,11 +2031,9 @@ selected frame's terminal). This function always returns nil if
TERMINAL does not refer to a text terminal. */)
(Lisp_Object terminal)
{
struct terminal *t = get_tty_terminal (terminal, 0);
if (!t)
return Qnil;
else
return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
struct terminal *t = decode_tty_terminal (terminal);
return (t && t->display_info.tty->TN_max_colors > 0) ? Qt : Qnil;
}
/* Return the number of supported colors. */
@ -2049,11 +2046,9 @@ selected frame's terminal). This function always returns 0 if
TERMINAL does not refer to a text terminal. */)
(Lisp_Object terminal)
{
struct terminal *t = get_tty_terminal (terminal, 0);
if (!t)
return make_number (0);
else
return make_number (t->display_info.tty->TN_max_colors);
struct terminal *t = decode_tty_terminal (terminal);
return make_number (t ? t->display_info.tty->TN_max_colors : 0);
}
#ifndef DOS_NT
@ -2168,52 +2163,6 @@ set_tty_color_mode (struct tty_display_info *tty, struct frame *f)
#endif /* !DOS_NT */
/* Return the tty display object specified by TERMINAL. */
static struct terminal *
get_tty_terminal (Lisp_Object terminal, bool throw)
{
struct terminal *t = get_terminal (terminal, throw);
if (t && t->type != output_termcap && t->type != output_msdos_raw)
{
if (throw)
error ("Device %d is not a termcap terminal device", t->id);
else
return NULL;
}
return t;
}
/* Return an active termcap device that uses the tty device with the
given name.
This function ignores suspended devices.
Returns NULL if the named terminal device is not opened. */
struct terminal *
get_named_tty (const char *name)
{
struct terminal *t;
eassert (name);
for (t = terminal_list; t; t = t->next_terminal)
{
if ((t->type == output_termcap || t->type == output_msdos_raw)
&& !strcmp (t->display_info.tty->name, name)
&& TERMINAL_ACTIVE_P (t))
return t;
}
return 0;
}
DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
doc: /* Return the type of the tty device that TERMINAL uses.
Returns nil if TERMINAL is not on a tty device.
@ -2222,15 +2171,10 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
selected frame's terminal). */)
(Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_tty_terminal (terminal);
if (t->type != output_termcap && t->type != output_msdos_raw)
return Qnil;
if (t->display_info.tty->type)
return build_string (t->display_info.tty->type);
else
return Qnil;
return (t && t->display_info.tty->type
? build_string (t->display_info.tty->type) : Qnil);
}
DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
@ -2241,13 +2185,9 @@ selected frame's terminal). This function always returns nil if
TERMINAL is not on a tty device. */)
(Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_tty_terminal (terminal);
if ((t->type != output_termcap && t->type != output_msdos_raw)
|| strcmp (t->display_info.tty->name, DEV_TTY) != 0)
return Qnil;
else
return Qt;
return (t && !strcmp (t->display_info.tty->name, DEV_TTY) ? Qt : Qnil);
}
DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
@ -2261,7 +2201,7 @@ selected frame's terminal). This function always returns nil if
TERMINAL does not refer to a text terminal. */)
(Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_live_terminal (terminal);
if (t->type == output_termcap)
t->display_info.tty->TS_enter_underline_mode = 0;
@ -2276,7 +2216,7 @@ does not refer to a text terminal. Otherwise, it returns the
top-most frame on the text terminal. */)
(Lisp_Object terminal)
{
struct terminal *t = get_terminal (terminal, 1);
struct terminal *t = decode_live_terminal (terminal);
if (t->type == output_termcap)
return t->display_info.tty->top_frame;
@ -2306,11 +2246,11 @@ suspended.
A suspended tty may be resumed by calling `resume-tty' on it. */)
(Lisp_Object tty)
{
struct terminal *t = get_tty_terminal (tty, 1);
struct terminal *t = decode_tty_terminal (tty);
FILE *f;
if (!t)
error ("Unknown tty device");
error ("Attempt to suspend a non-text terminal device");
f = t->display_info.tty->input;
@ -2366,15 +2306,15 @@ TTY may be a terminal object, a frame, or nil (meaning the selected
frame's terminal). */)
(Lisp_Object tty)
{
struct terminal *t = get_tty_terminal (tty, 1);
struct terminal *t = decode_tty_terminal (tty);
int fd;
if (!t)
error ("Unknown tty device");
error ("Attempt to resume a non-text terminal device");
if (!t->display_info.tty->input)
{
if (get_named_tty (t->display_info.tty->name))
if (get_named_terminal (t->display_info.tty->name))
error ("Cannot resume display while another display is active on the same device");
#ifdef MSDOS
@ -4007,7 +3947,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
/* XXX Perhaps this should be made explicit by having init_tty
always create a new terminal and separating terminal and frame
creation on Lisp level. */
terminal = get_named_tty (name);
terminal = get_named_terminal (name);
if (terminal)
return terminal;

View file

@ -681,7 +681,9 @@ extern struct terminal *terminal_list;
(t->type == output_ns ? t->display_info.ns->name_list_element : Qnil)
#endif
extern struct terminal *get_terminal (Lisp_Object terminal, bool);
extern struct terminal *decode_live_terminal (Lisp_Object);
extern struct terminal *decode_tty_terminal (Lisp_Object);
extern struct terminal *get_named_terminal (const char *);
extern struct terminal *create_terminal (enum output_method,
struct redisplay_interface *);
extern void delete_terminal (struct terminal *);

View file

@ -37,7 +37,9 @@ 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 *);
@ -194,34 +196,66 @@ ins_del_lines (struct frame *f, int vpos, int n)
(*FRAME_TERMINAL (f)->ins_del_lines_hook) (f, vpos, n);
}
/* Return the terminal object specified by TERMINAL. TERMINAL may
be a terminal object, a frame, or nil for the terminal device of
the current frame. If TERMINAL is neither from the above or the
resulting terminal object is deleted, return NULL. */
/* Return the terminal object specified by TERMINAL. TERMINAL may be
a terminal object, a frame, or nil for the terminal device of the
current frame. If THROW is false, return NULL for failure,
otherwise throw an error. */
struct terminal *
get_terminal (Lisp_Object terminal, bool throw)
static struct terminal *
decode_terminal (Lisp_Object terminal)
{
struct terminal *result = NULL;
struct terminal *t;
if (NILP (terminal))
terminal = selected_frame;
t = (TERMINALP (terminal)
? XTERMINAL (terminal)
: FRAMEP (terminal) ? FRAME_TERMINAL (XFRAME (terminal)) : NULL);
return t && t->name ? t : NULL;
}
if (TERMINALP (terminal))
result = XTERMINAL (terminal);
else if (FRAMEP (terminal))
result = FRAME_TERMINAL (XFRAME (terminal));
/* Like above, but throw an error if TERMINAL is not valid or deleted. */
if (result && !result->name)
result = NULL;
struct terminal *
decode_live_terminal (Lisp_Object terminal)
{
struct terminal *t = decode_terminal (terminal);
if (result == NULL && throw)
if (!t)
wrong_type_argument (Qterminal_live_p, terminal);
return t;
}
return result;
/* Like decode_terminal, but ensure that the resulting terminal object refers
to a text-based terminal device. */
struct terminal *
decode_tty_terminal (Lisp_Object terminal)
{
struct terminal *t = decode_live_terminal (terminal);
return (t->type == output_termcap || t->type == output_msdos_raw) ? t : NULL;
}
/* Return an active (not suspended) text-based terminal device that uses
the tty device with the given NAME, or NULL if the named terminal device
is not opened. */
struct terminal *
get_named_terminal (const char *name)
{
struct terminal *t;
eassert (name);
for (t = terminal_list; t; t = t->next_terminal)
{
if ((t->type == output_termcap || t->type == output_msdos_raw)
&& !strcmp (t->display_info.tty->name, name)
&& TERMINAL_ACTIVE_P (t))
return t;
}
return NULL;
}
/* Create a new terminal object of TYPE and add it to the terminal list. RIF
@ -308,8 +342,6 @@ delete_terminal (struct terminal *terminal)
}
}
Lisp_Object Qrun_hook_with_args;
static Lisp_Object Qdelete_terminal_functions;
DEFUN ("delete-terminal", Fdelete_terminal, Sdelete_terminal, 0, 2, 0,
doc: /* Delete TERMINAL by deleting all frames on it and closing the terminal.
TERMINAL may be a terminal object, a frame, or nil (meaning the
@ -319,7 +351,7 @@ Normally, you may not delete a display if all other displays are suspended,
but if the second argument FORCE is non-nil, you may do so. */)
(Lisp_Object terminal, Lisp_Object force)
{
struct terminal *t = get_terminal (terminal, 0);
struct terminal *t = decode_terminal (terminal);
if (!t)
return Qnil;
@ -380,9 +412,7 @@ sort of output terminal it uses. See the documentation of `framep' for
possible return values. */)
(Lisp_Object object)
{
struct terminal *t;
t = get_terminal (object, 0);
struct terminal *t = decode_terminal (object);
if (!t)
return Qnil;
@ -429,8 +459,7 @@ TERMINAL may be a terminal object, a frame, or nil (meaning the
selected frame's terminal). */)
(Lisp_Object terminal)
{
struct terminal *t
= TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
struct terminal *t = decode_live_terminal (terminal);
return t->name ? build_string (t->name) : Qnil;
}
@ -467,9 +496,7 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
selected frame's terminal). */)
(Lisp_Object terminal)
{
struct terminal *t
= TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
return Fcopy_alist (t->param_alist);
return Fcopy_alist (decode_live_terminal (terminal)->param_alist);
}
DEFUN ("terminal-parameter", Fterminal_parameter, Sterminal_parameter, 2, 2, 0,
@ -478,12 +505,8 @@ TERMINAL can be a terminal object, a frame, or nil (meaning the
selected frame's terminal). */)
(Lisp_Object terminal, Lisp_Object parameter)
{
Lisp_Object value;
struct terminal *t
= TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
CHECK_SYMBOL (parameter);
value = Fcdr (Fassq (parameter, t->param_alist));
return value;
return Fcdr (Fassq (parameter, decode_live_terminal (terminal)->param_alist));
}
DEFUN ("set-terminal-parameter", Fset_terminal_parameter,
@ -495,9 +518,7 @@ TERMINAL can be a terminal object, a frame or nil (meaning the
selected frame's terminal). */)
(Lisp_Object terminal, Lisp_Object parameter, Lisp_Object value)
{
struct terminal *t
= TERMINALP (terminal) ? XTERMINAL (terminal) : get_terminal (terminal, 1);
return store_terminal_param (t, parameter, value);
return store_terminal_param (decode_live_terminal (terminal), parameter, value);
}
/* Initial frame has no device-dependent output data, but has

View file

@ -276,7 +276,7 @@ check_x_display_info (Lisp_Object object)
}
else if (TERMINALP (object))
{
struct terminal *t = get_terminal (object, 1);
struct terminal *t = decode_live_terminal (object);
if (t->type != output_w32)
error ("Terminal %d is not a W32 display", t->id);

View file

@ -159,7 +159,7 @@ check_x_display_info (Lisp_Object object)
}
else if (TERMINALP (object))
{
struct terminal *t = get_terminal (object, 1);
struct terminal *t = decode_live_terminal (object);
if (t->type != output_x_window)
error ("Terminal %d is not an X display", t->id);

View file

@ -1901,7 +1901,7 @@ frame_for_x_selection (Lisp_Object object)
}
else if (TERMINALP (object))
{
struct terminal *t = get_terminal (object, 1);
struct terminal *t = decode_live_terminal (object);
if (t->type == output_x_window)
FOR_EACH_FRAME (tail, frame)