aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
diff options
context:
space:
mode:
authorDmitry Antipov2014-10-14 16:45:41 +0400
committerDmitry Antipov2014-10-14 16:45:41 +0400
commitbb75cdf9c74ab19b75532da1f953233a47eedab4 (patch)
treeb8b4d07acaf36cdce7485fb459e7376975ebd5f7 /src/term.c
parent5fa75d8eba2d43408fd7831dcfd69c21e31c21f3 (diff)
downloademacs-bb75cdf9c74ab19b75532da1f953233a47eedab4.tar.gz
emacs-bb75cdf9c74ab19b75532da1f953233a47eedab4.zip
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.
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c98
1 files changed, 19 insertions, 79 deletions
diff --git a/src/term.c b/src/term.c
index 572435bdd1a..0c36469f655 100644
--- a/src/term.c
+++ b/src/term.c
@@ -77,7 +77,6 @@ static void tty_turn_off_highlight (struct tty_display_info *);
77static void tty_show_cursor (struct tty_display_info *); 77static void tty_show_cursor (struct tty_display_info *);
78static void tty_hide_cursor (struct tty_display_info *); 78static void tty_hide_cursor (struct tty_display_info *);
79static void tty_background_highlight (struct tty_display_info *tty); 79static void tty_background_highlight (struct tty_display_info *tty);
80static struct terminal *get_tty_terminal (Lisp_Object, bool);
81static void clear_tty_hooks (struct terminal *terminal); 80static void clear_tty_hooks (struct terminal *terminal);
82static void set_tty_hooks (struct terminal *terminal); 81static void set_tty_hooks (struct terminal *terminal);
83static void dissociate_if_controlling_tty (int fd); 82static void dissociate_if_controlling_tty (int fd);
@@ -2032,11 +2031,9 @@ selected frame's terminal). This function always returns nil if
2032TERMINAL does not refer to a text terminal. */) 2031TERMINAL does not refer to a text terminal. */)
2033 (Lisp_Object terminal) 2032 (Lisp_Object terminal)
2034{ 2033{
2035 struct terminal *t = get_tty_terminal (terminal, 0); 2034 struct terminal *t = decode_tty_terminal (terminal);
2036 if (!t) 2035
2037 return Qnil; 2036 return (t && t->display_info.tty->TN_max_colors > 0) ? Qt : Qnil;
2038 else
2039 return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
2040} 2037}
2041 2038
2042/* Return the number of supported colors. */ 2039/* Return the number of supported colors. */
@@ -2049,11 +2046,9 @@ selected frame's terminal). This function always returns 0 if
2049TERMINAL does not refer to a text terminal. */) 2046TERMINAL does not refer to a text terminal. */)
2050 (Lisp_Object terminal) 2047 (Lisp_Object terminal)
2051{ 2048{
2052 struct terminal *t = get_tty_terminal (terminal, 0); 2049 struct terminal *t = decode_tty_terminal (terminal);
2053 if (!t) 2050
2054 return make_number (0); 2051 return make_number (t ? t->display_info.tty->TN_max_colors : 0);
2055 else
2056 return make_number (t->display_info.tty->TN_max_colors);
2057} 2052}
2058 2053
2059#ifndef DOS_NT 2054#ifndef DOS_NT
@@ -2168,52 +2163,6 @@ set_tty_color_mode (struct tty_display_info *tty, struct frame *f)
2168 2163
2169#endif /* !DOS_NT */ 2164#endif /* !DOS_NT */
2170 2165
2171
2172
2173/* Return the tty display object specified by TERMINAL. */
2174
2175static struct terminal *
2176get_tty_terminal (Lisp_Object terminal, bool throw)
2177{
2178 struct terminal *t = get_terminal (terminal, throw);
2179
2180 if (t && t->type != output_termcap && t->type != output_msdos_raw)
2181 {
2182 if (throw)
2183 error ("Device %d is not a termcap terminal device", t->id);
2184 else
2185 return NULL;
2186 }
2187
2188 return t;
2189}
2190
2191/* Return an active termcap device that uses the tty device with the
2192 given name.
2193
2194 This function ignores suspended devices.
2195
2196 Returns NULL if the named terminal device is not opened. */
2197
2198struct terminal *
2199get_named_tty (const char *name)
2200{
2201 struct terminal *t;
2202
2203 eassert (name);
2204
2205 for (t = terminal_list; t; t = t->next_terminal)
2206 {
2207 if ((t->type == output_termcap || t->type == output_msdos_raw)
2208 && !strcmp (t->display_info.tty->name, name)
2209 && TERMINAL_ACTIVE_P (t))
2210 return t;
2211 }
2212
2213 return 0;
2214}
2215
2216
2217DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0, 2166DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
2218 doc: /* Return the type of the tty device that TERMINAL uses. 2167 doc: /* Return the type of the tty device that TERMINAL uses.
2219Returns nil if TERMINAL is not on a tty device. 2168Returns 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
2222selected frame's terminal). */) 2171selected frame's terminal). */)
2223 (Lisp_Object terminal) 2172 (Lisp_Object terminal)
2224{ 2173{
2225 struct terminal *t = get_terminal (terminal, 1); 2174 struct terminal *t = decode_tty_terminal (terminal);
2226
2227 if (t->type != output_termcap && t->type != output_msdos_raw)
2228 return Qnil;
2229 2175
2230 if (t->display_info.tty->type) 2176 return (t && t->display_info.tty->type
2231 return build_string (t->display_info.tty->type); 2177 ? build_string (t->display_info.tty->type) : Qnil);
2232 else
2233 return Qnil;
2234} 2178}
2235 2179
2236DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0, 2180DEFUN ("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
2241TERMINAL is not on a tty device. */) 2185TERMINAL is not on a tty device. */)
2242 (Lisp_Object terminal) 2186 (Lisp_Object terminal)
2243{ 2187{
2244 struct terminal *t = get_terminal (terminal, 1); 2188 struct terminal *t = decode_tty_terminal (terminal);
2245 2189
2246 if ((t->type != output_termcap && t->type != output_msdos_raw) 2190 return (t && !strcmp (t->display_info.tty->name, DEV_TTY) ? Qt : Qnil);
2247 || strcmp (t->display_info.tty->name, DEV_TTY) != 0)
2248 return Qnil;
2249 else
2250 return Qt;
2251} 2191}
2252 2192
2253DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0, 2193DEFUN ("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
2261TERMINAL does not refer to a text terminal. */) 2201TERMINAL does not refer to a text terminal. */)
2262 (Lisp_Object terminal) 2202 (Lisp_Object terminal)
2263{ 2203{
2264 struct terminal *t = get_terminal (terminal, 1); 2204 struct terminal *t = decode_live_terminal (terminal);
2265 2205
2266 if (t->type == output_termcap) 2206 if (t->type == output_termcap)
2267 t->display_info.tty->TS_enter_underline_mode = 0; 2207 t->display_info.tty->TS_enter_underline_mode = 0;
@@ -2276,7 +2216,7 @@ does not refer to a text terminal. Otherwise, it returns the
2276top-most frame on the text terminal. */) 2216top-most frame on the text terminal. */)
2277 (Lisp_Object terminal) 2217 (Lisp_Object terminal)
2278{ 2218{
2279 struct terminal *t = get_terminal (terminal, 1); 2219 struct terminal *t = decode_live_terminal (terminal);
2280 2220
2281 if (t->type == output_termcap) 2221 if (t->type == output_termcap)
2282 return t->display_info.tty->top_frame; 2222 return t->display_info.tty->top_frame;
@@ -2306,11 +2246,11 @@ suspended.
2306A suspended tty may be resumed by calling `resume-tty' on it. */) 2246A suspended tty may be resumed by calling `resume-tty' on it. */)
2307 (Lisp_Object tty) 2247 (Lisp_Object tty)
2308{ 2248{
2309 struct terminal *t = get_tty_terminal (tty, 1); 2249 struct terminal *t = decode_tty_terminal (tty);
2310 FILE *f; 2250 FILE *f;
2311 2251
2312 if (!t) 2252 if (!t)
2313 error ("Unknown tty device"); 2253 error ("Attempt to suspend a non-text terminal device");
2314 2254
2315 f = t->display_info.tty->input; 2255 f = t->display_info.tty->input;
2316 2256
@@ -2366,15 +2306,15 @@ TTY may be a terminal object, a frame, or nil (meaning the selected
2366frame's terminal). */) 2306frame's terminal). */)
2367 (Lisp_Object tty) 2307 (Lisp_Object tty)
2368{ 2308{
2369 struct terminal *t = get_tty_terminal (tty, 1); 2309 struct terminal *t = decode_tty_terminal (tty);
2370 int fd; 2310 int fd;
2371 2311
2372 if (!t) 2312 if (!t)
2373 error ("Unknown tty device"); 2313 error ("Attempt to resume a non-text terminal device");
2374 2314
2375 if (!t->display_info.tty->input) 2315 if (!t->display_info.tty->input)
2376 { 2316 {
2377 if (get_named_tty (t->display_info.tty->name)) 2317 if (get_named_terminal (t->display_info.tty->name))
2378 error ("Cannot resume display while another display is active on the same device"); 2318 error ("Cannot resume display while another display is active on the same device");
2379 2319
2380#ifdef MSDOS 2320#ifdef MSDOS
@@ -4007,7 +3947,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
4007 /* XXX Perhaps this should be made explicit by having init_tty 3947 /* XXX Perhaps this should be made explicit by having init_tty
4008 always create a new terminal and separating terminal and frame 3948 always create a new terminal and separating terminal and frame
4009 creation on Lisp level. */ 3949 creation on Lisp level. */
4010 terminal = get_named_tty (name); 3950 terminal = get_named_terminal (name);
4011 if (terminal) 3951 if (terminal)
4012 return terminal; 3952 return terminal;
4013 3953