aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c234
1 files changed, 95 insertions, 139 deletions
diff --git a/src/term.c b/src/term.c
index fad6e3c80d7..d1279498060 100644
--- a/src/term.c
+++ b/src/term.c
@@ -31,8 +31,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#include <unistd.h> 31#include <unistd.h>
32#endif 32#endif
33 33
34#if HAVE_TERMIOS_H 34#ifdef HAVE_SYS_IOCTL_H
35#include <termios.h> /* For TIOCNOTTY. */ 35#include <sys/ioctl.h>
36#endif 36#endif
37 37
38#include <signal.h> 38#include <signal.h>
@@ -66,10 +66,10 @@ static int been_here = -1;
66/* For now, don't try to include termcap.h. On some systems, 66/* For now, don't try to include termcap.h. On some systems,
67 configure finds a non-standard termcap.h that the main build 67 configure finds a non-standard termcap.h that the main build
68 won't find. */ 68 won't find. */
69extern void tputs P_ ((const char *, int, int (*)(int))); 69extern void tputs (const char *, int, int (*)(int));
70extern int tgetent P_ ((char *, const char *)); 70extern int tgetent (char *, const char *);
71extern int tgetflag P_ ((char *id)); 71extern int tgetflag (char *id);
72extern int tgetnum P_ ((char *id)); 72extern int tgetnum (char *id);
73 73
74#include "cm.h" 74#include "cm.h"
75#ifdef HAVE_X_WINDOWS 75#ifdef HAVE_X_WINDOWS
@@ -91,16 +91,20 @@ extern int tgetnum P_ ((char *id));
91#define DEV_TTY "/dev/tty" 91#define DEV_TTY "/dev/tty"
92#endif 92#endif
93 93
94static void tty_set_scroll_region P_ ((struct frame *f, int start, int stop)); 94static void tty_set_scroll_region (struct frame *f, int start, int stop);
95static void turn_on_face P_ ((struct frame *, int face_id)); 95static void turn_on_face (struct frame *, int face_id);
96static void turn_off_face P_ ((struct frame *, int face_id)); 96static void turn_off_face (struct frame *, int face_id);
97static void tty_show_cursor P_ ((struct tty_display_info *)); 97static void tty_show_cursor (struct tty_display_info *);
98static void tty_hide_cursor P_ ((struct tty_display_info *)); 98static void tty_hide_cursor (struct tty_display_info *);
99static void tty_background_highlight P_ ((struct tty_display_info *tty)); 99static void tty_background_highlight (struct tty_display_info *tty);
100static void clear_tty_hooks P_ ((struct terminal *terminal)); 100static void clear_tty_hooks (struct terminal *terminal);
101static void set_tty_hooks P_ ((struct terminal *terminal)); 101static void set_tty_hooks (struct terminal *terminal);
102static void dissociate_if_controlling_tty P_ ((int fd)); 102static void dissociate_if_controlling_tty (int fd);
103static void delete_tty P_ ((struct terminal *)); 103static void delete_tty (struct terminal *);
104static void maybe_fatal (int must_succeed, struct terminal *terminal,
105 const char *str1, const char *str2, ...) NO_RETURN;
106static void vfatal (const char *str, va_list ap) NO_RETURN;
107
104 108
105#define OUTPUT(tty, a) \ 109#define OUTPUT(tty, a) \
106 emacs_tputs ((tty), a, \ 110 emacs_tputs ((tty), a, \
@@ -128,8 +132,6 @@ static int visible_cursor;
128 132
129/* Display space properties */ 133/* Display space properties */
130 134
131extern Lisp_Object Qspace, QCalign_to, QCwidth;
132
133/* Functions to call after suspending a tty. */ 135/* Functions to call after suspending a tty. */
134Lisp_Object Vsuspend_tty_functions; 136Lisp_Object Vsuspend_tty_functions;
135 137
@@ -179,15 +181,15 @@ static int no_controlling_tty;
179 181
180static int system_uses_terminfo; 182static int system_uses_terminfo;
181 183
182char *tparam (); 184char *tparam (char *, char *, int, int, ...);
183 185
184extern char *tgetstr (); 186extern char *tgetstr (char *, char **);
185 187
186 188
187#ifdef HAVE_GPM 189#ifdef HAVE_GPM
188#include <sys/fcntl.h> 190#include <sys/fcntl.h>
189 191
190static void term_clear_mouse_face (); 192static void term_clear_mouse_face (void);
191static void term_mouse_highlight (struct frame *f, int x, int y); 193static void term_mouse_highlight (struct frame *f, int x, int y);
192 194
193/* The device for which we have enabled gpm support (or NULL). */ 195/* The device for which we have enabled gpm support (or NULL). */
@@ -558,10 +560,7 @@ static int encode_terminal_dst_size;
558 sequence, and return a pointer to that byte sequence. */ 560 sequence, and return a pointer to that byte sequence. */
559 561
560unsigned char * 562unsigned char *
561encode_terminal_code (src, src_len, coding) 563encode_terminal_code (struct glyph *src, int src_len, struct coding_system *coding)
562 struct glyph *src;
563 int src_len;
564 struct coding_system *coding;
565{ 564{
566 struct glyph *src_end = src + src_len; 565 struct glyph *src_end = src + src_len;
567 unsigned char *buf; 566 unsigned char *buf;
@@ -711,7 +710,7 @@ encode_terminal_code (src, src_len, coding)
711 } 710 }
712 else 711 else
713 { 712 {
714 unsigned char *p = SDATA (string), *pend = p + SBYTES (string); 713 unsigned char *p = SDATA (string);
715 714
716 if (! STRING_MULTIBYTE (string)) 715 if (! STRING_MULTIBYTE (string))
717 string = string_to_multibyte (string); 716 string = string_to_multibyte (string);
@@ -723,7 +722,7 @@ encode_terminal_code (src, src_len, coding)
723 encode_terminal_src_size); 722 encode_terminal_src_size);
724 buf = encode_terminal_src + nbytes; 723 buf = encode_terminal_src + nbytes;
725 } 724 }
726 bcopy (SDATA (string), buf, SBYTES (string)); 725 memcpy (buf, SDATA (string), SBYTES (string));
727 buf += SBYTES (string); 726 buf += SBYTES (string);
728 nchars += SCHARS (string); 727 nchars += SCHARS (string);
729 } 728 }
@@ -836,10 +835,8 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
836#ifdef HAVE_GPM /* Only used by GPM code. */ 835#ifdef HAVE_GPM /* Only used by GPM code. */
837 836
838static void 837static void
839tty_write_glyphs_with_face (f, string, len, face_id) 838tty_write_glyphs_with_face (register struct frame *f, register struct glyph *string,
840 register struct frame *f; 839 register int len, register int face_id)
841 register struct glyph *string;
842 register int len, face_id;
843{ 840{
844 unsigned char *conversion_buffer; 841 unsigned char *conversion_buffer;
845 struct coding_system *coding; 842 struct coding_system *coding;
@@ -1087,7 +1084,7 @@ tty_ins_del_lines (struct frame *f, int vpos, int n)
1087 not counting any line-dependent padding. */ 1084 not counting any line-dependent padding. */
1088 1085
1089int 1086int
1090string_cost (char *str) 1087string_cost (const char *str)
1091{ 1088{
1092 cost = 0; 1089 cost = 0;
1093 if (str) 1090 if (str)
@@ -1099,7 +1096,7 @@ string_cost (char *str)
1099 counting any line-dependent padding at one line. */ 1096 counting any line-dependent padding at one line. */
1100 1097
1101static int 1098static int
1102string_cost_one_line (char *str) 1099string_cost_one_line (const char *str)
1103{ 1100{
1104 cost = 0; 1101 cost = 0;
1105 if (str) 1102 if (str)
@@ -1111,7 +1108,7 @@ string_cost_one_line (char *str)
1111 in tenths of characters. */ 1108 in tenths of characters. */
1112 1109
1113int 1110int
1114per_line_cost (char *str) 1111per_line_cost (const char *str)
1115{ 1112{
1116 cost = 0; 1113 cost = 0;
1117 if (str) 1114 if (str)
@@ -1122,7 +1119,6 @@ per_line_cost (char *str)
1122 return cost; 1119 return cost;
1123} 1120}
1124 1121
1125#ifndef old
1126/* char_ins_del_cost[n] is cost of inserting N characters. 1122/* char_ins_del_cost[n] is cost of inserting N characters.
1127 char_ins_del_cost[-n] is cost of deleting N characters. 1123 char_ins_del_cost[-n] is cost of deleting N characters.
1128 The length of this vector is based on max_frame_cols. */ 1124 The length of this vector is based on max_frame_cols. */
@@ -1130,7 +1126,6 @@ per_line_cost (char *str)
1130int *char_ins_del_vector; 1126int *char_ins_del_vector;
1131 1127
1132#define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))]) 1128#define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1133#endif
1134 1129
1135/* ARGSUSED */ 1130/* ARGSUSED */
1136static void 1131static void
@@ -1230,8 +1225,8 @@ calculate_costs (struct frame *frame)
1230 = (int *) xmalloc (sizeof (int) 1225 = (int *) xmalloc (sizeof (int)
1231 + 2 * max_frame_cols * sizeof (int)); 1226 + 2 * max_frame_cols * sizeof (int));
1232 1227
1233 bzero (char_ins_del_vector, (sizeof (int) 1228 memset (char_ins_del_vector, 0,
1234 + 2 * max_frame_cols * sizeof (int))); 1229 (sizeof (int) + 2 * max_frame_cols * sizeof (int)));
1235 1230
1236 1231
1237 if (f && (!tty->TS_ins_line && !tty->TS_del_line)) 1232 if (f && (!tty->TS_ins_line && !tty->TS_del_line))
@@ -1268,7 +1263,7 @@ struct fkey_table {
1268 other keys (as on the IBM PC keyboard) they get overridden. 1263 other keys (as on the IBM PC keyboard) they get overridden.
1269 */ 1264 */
1270 1265
1271static struct fkey_table keys[] = 1266static const struct fkey_table keys[] =
1272{ 1267{
1273 {"kh", "home"}, /* termcap */ 1268 {"kh", "home"}, /* termcap */
1274 {"kl", "left"}, /* termcap */ 1269 {"kl", "left"}, /* termcap */
@@ -1364,18 +1359,17 @@ static struct fkey_table keys[] =
1364 {"!3", "S-undo"} /*shifted undo key*/ 1359 {"!3", "S-undo"} /*shifted undo key*/
1365 }; 1360 };
1366 1361
1362#ifndef DOS_NT
1367static char **term_get_fkeys_address; 1363static char **term_get_fkeys_address;
1368static KBOARD *term_get_fkeys_kboard; 1364static KBOARD *term_get_fkeys_kboard;
1369static Lisp_Object term_get_fkeys_1 (); 1365static Lisp_Object term_get_fkeys_1 (void);
1370 1366
1371/* Find the escape codes sent by the function keys for Vinput_decode_map. 1367/* Find the escape codes sent by the function keys for Vinput_decode_map.
1372 This function scans the termcap function key sequence entries, and 1368 This function scans the termcap function key sequence entries, and
1373 adds entries to Vinput_decode_map for each function key it finds. */ 1369 adds entries to Vinput_decode_map for each function key it finds. */
1374 1370
1375static void 1371static void
1376term_get_fkeys (address, kboard) 1372term_get_fkeys (char **address, KBOARD *kboard)
1377 char **address;
1378 KBOARD *kboard;
1379{ 1373{
1380 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp 1374 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1381 errors during the call. The only errors should be from Fdefine_key 1375 errors during the call. The only errors should be from Fdefine_key
@@ -1385,14 +1379,13 @@ term_get_fkeys (address, kboard)
1385 function key specification, rather than giving the user an error and 1379 function key specification, rather than giving the user an error and
1386 refusing to run at all on such a terminal. */ 1380 refusing to run at all on such a terminal. */
1387 1381
1388 extern Lisp_Object Fidentity ();
1389 term_get_fkeys_address = address; 1382 term_get_fkeys_address = address;
1390 term_get_fkeys_kboard = kboard; 1383 term_get_fkeys_kboard = kboard;
1391 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity); 1384 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity);
1392} 1385}
1393 1386
1394static Lisp_Object 1387static Lisp_Object
1395term_get_fkeys_1 () 1388term_get_fkeys_1 (void)
1396{ 1389{
1397 int i; 1390 int i;
1398 1391
@@ -1503,24 +1496,16 @@ term_get_fkeys_1 ()
1503 1496
1504 return Qnil; 1497 return Qnil;
1505} 1498}
1499#endif /* not DOS_NT */
1506 1500
1507 1501
1508/*********************************************************************** 1502/***********************************************************************
1509 Character Display Information 1503 Character Display Information
1510 ***********************************************************************/ 1504 ***********************************************************************/
1511 1505static void append_glyph (struct it *);
1512/* Avoid name clash with functions defined in xterm.c */ 1506static void produce_stretch_glyph (struct it *);
1513#ifdef static 1507static void append_composite_glyph (struct it *);
1514#define append_glyph append_glyph_term 1508static void produce_composite_glyph (struct it *);
1515#define produce_stretch_glyph produce_stretch_glyph_term
1516#define append_composite_glyph append_composite_glyph_term
1517#define produce_composite_glyph produce_composite_glyph_term
1518#endif
1519
1520static void append_glyph P_ ((struct it *));
1521static void produce_stretch_glyph P_ ((struct it *));
1522static void append_composite_glyph P_ ((struct it *));
1523static void produce_composite_glyph P_ ((struct it *));
1524 1509
1525/* Append glyphs to IT's glyph_row. Called from produce_glyphs for 1510/* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1526 terminal frames if IT->glyph_row != NULL. IT->char_to_display is 1511 terminal frames if IT->glyph_row != NULL. IT->char_to_display is
@@ -1529,8 +1514,7 @@ static void produce_composite_glyph P_ ((struct it *));
1529 IT->pixel_width > 1. */ 1514 IT->pixel_width > 1. */
1530 1515
1531static void 1516static void
1532append_glyph (it) 1517append_glyph (struct it *it)
1533 struct it *it;
1534{ 1518{
1535 struct glyph *glyph, *end; 1519 struct glyph *glyph, *end;
1536 int i; 1520 int i;
@@ -1609,8 +1593,7 @@ append_glyph (it)
1609 instead they use the macro PRODUCE_GLYPHS. */ 1593 instead they use the macro PRODUCE_GLYPHS. */
1610 1594
1611void 1595void
1612produce_glyphs (it) 1596produce_glyphs (struct it *it)
1613 struct it *it;
1614{ 1597{
1615 /* If a hook is installed, let it do the work. */ 1598 /* If a hook is installed, let it do the work. */
1616 1599
@@ -1728,8 +1711,7 @@ produce_glyphs (it)
1728 to reach HPOS, a value in canonical character units. */ 1711 to reach HPOS, a value in canonical character units. */
1729 1712
1730static void 1713static void
1731produce_stretch_glyph (it) 1714produce_stretch_glyph (struct it *it)
1732 struct it *it;
1733{ 1715{
1734 /* (space :width WIDTH ...) */ 1716 /* (space :width WIDTH ...) */
1735 Lisp_Object prop, plist; 1717 Lisp_Object prop, plist;
@@ -1798,8 +1780,7 @@ produce_stretch_glyph (it)
1798 face. */ 1780 face. */
1799 1781
1800static void 1782static void
1801append_composite_glyph (it) 1783append_composite_glyph (struct it *it)
1802 struct it *it;
1803{ 1784{
1804 struct glyph *glyph; 1785 struct glyph *glyph;
1805 1786
@@ -1863,11 +1844,8 @@ append_composite_glyph (it)
1863 correctly. */ 1844 correctly. */
1864 1845
1865static void 1846static void
1866produce_composite_glyph (it) 1847produce_composite_glyph (struct it *it)
1867 struct it *it;
1868{ 1848{
1869 int c;
1870
1871 if (it->cmp_it.ch < 0) 1849 if (it->cmp_it.ch < 0)
1872 { 1850 {
1873 struct composition *cmp = composition_table[it->cmp_it.id]; 1851 struct composition *cmp = composition_table[it->cmp_it.id];
@@ -1894,9 +1872,7 @@ produce_composite_glyph (it)
1894 face_id, c, len of IT are left untouched. */ 1872 face_id, c, len of IT are left untouched. */
1895 1873
1896void 1874void
1897produce_special_glyphs (it, what) 1875produce_special_glyphs (struct it *it, enum display_element_type what)
1898 struct it *it;
1899 enum display_element_type what;
1900{ 1876{
1901 struct it temp_it; 1877 struct it temp_it;
1902 Lisp_Object gc; 1878 Lisp_Object gc;
@@ -1907,7 +1883,7 @@ produce_special_glyphs (it, what)
1907 temp_it.what = IT_CHARACTER; 1883 temp_it.what = IT_CHARACTER;
1908 temp_it.len = 1; 1884 temp_it.len = 1;
1909 temp_it.object = make_number (0); 1885 temp_it.object = make_number (0);
1910 bzero (&temp_it.current, sizeof temp_it.current); 1886 memset (&temp_it.current, 0, sizeof temp_it.current);
1911 1887
1912 if (what == IT_CONTINUATION) 1888 if (what == IT_CONTINUATION)
1913 { 1889 {
@@ -1970,9 +1946,7 @@ produce_special_glyphs (it, what)
1970 FACE_ID is a realized face ID number, in the face cache. */ 1946 FACE_ID is a realized face ID number, in the face cache. */
1971 1947
1972static void 1948static void
1973turn_on_face (f, face_id) 1949turn_on_face (struct frame *f, int face_id)
1974 struct frame *f;
1975 int face_id;
1976{ 1950{
1977 struct face *face = FACE_FROM_ID (f, face_id); 1951 struct face *face = FACE_FROM_ID (f, face_id);
1978 long fg = face->foreground; 1952 long fg = face->foreground;
@@ -2069,9 +2043,7 @@ turn_on_face (f, face_id)
2069/* Turn off appearances of face FACE_ID on tty frame F. */ 2043/* Turn off appearances of face FACE_ID on tty frame F. */
2070 2044
2071static void 2045static void
2072turn_off_face (f, face_id) 2046turn_off_face (struct frame *f, int face_id)
2073 struct frame *f;
2074 int face_id;
2075{ 2047{
2076 struct face *face = FACE_FROM_ID (f, face_id); 2048 struct face *face = FACE_FROM_ID (f, face_id);
2077 struct tty_display_info *tty = FRAME_TTY (f); 2049 struct tty_display_info *tty = FRAME_TTY (f);
@@ -2124,10 +2096,8 @@ turn_off_face (f, face_id)
2124 colors FG and BG. */ 2096 colors FG and BG. */
2125 2097
2126int 2098int
2127tty_capable_p (tty, caps, fg, bg) 2099tty_capable_p (struct tty_display_info *tty, unsigned int caps,
2128 struct tty_display_info *tty; 2100 unsigned long fg, unsigned long bg)
2129 unsigned caps;
2130 unsigned long fg, bg;
2131{ 2101{
2132#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \ 2102#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2133 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \ 2103 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
@@ -2153,8 +2123,7 @@ DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
2153TERMINAL can be a terminal object, a frame, or nil (meaning the 2123TERMINAL can be a terminal object, a frame, or nil (meaning the
2154selected frame's terminal). This function always returns nil if 2124selected frame's terminal). This function always returns nil if
2155TERMINAL does not refer to a text-only terminal. */) 2125TERMINAL does not refer to a text-only terminal. */)
2156 (terminal) 2126 (Lisp_Object terminal)
2157 Lisp_Object terminal;
2158{ 2127{
2159 struct terminal *t = get_tty_terminal (terminal, 0); 2128 struct terminal *t = get_tty_terminal (terminal, 0);
2160 if (!t) 2129 if (!t)
@@ -2171,8 +2140,7 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2171TERMINAL can be a terminal object, a frame, or nil (meaning the 2140TERMINAL can be a terminal object, a frame, or nil (meaning the
2172selected frame's terminal). This function always returns 0 if 2141selected frame's terminal). This function always returns 0 if
2173TERMINAL does not refer to a text-only terminal. */) 2142TERMINAL does not refer to a text-only terminal. */)
2174 (terminal) 2143 (Lisp_Object terminal)
2175 Lisp_Object terminal;
2176{ 2144{
2177 struct terminal *t = get_tty_terminal (terminal, 0); 2145 struct terminal *t = get_tty_terminal (terminal, 0);
2178 if (!t) 2146 if (!t)
@@ -2267,14 +2235,11 @@ tty_setup_colors (struct tty_display_info *tty, int mode)
2267} 2235}
2268 2236
2269void 2237void
2270set_tty_color_mode (tty, f) 2238set_tty_color_mode (struct tty_display_info *tty, struct frame *f)
2271 struct tty_display_info *tty;
2272 struct frame *f;
2273{ 2239{
2274 Lisp_Object tem, val; 2240 Lisp_Object tem, val;
2275 Lisp_Object color_mode; 2241 Lisp_Object color_mode;
2276 int mode; 2242 int mode;
2277 extern Lisp_Object Qtty_color_mode;
2278 Lisp_Object tty_color_mode_alist 2243 Lisp_Object tty_color_mode_alist
2279 = Fintern_soft (build_string ("tty-color-mode-alist"), Qnil); 2244 = Fintern_soft (build_string ("tty-color-mode-alist"), Qnil);
2280 2245
@@ -2333,8 +2298,7 @@ get_tty_terminal (Lisp_Object terminal, int throw)
2333 Returns NULL if the named terminal device is not opened. */ 2298 Returns NULL if the named terminal device is not opened. */
2334 2299
2335struct terminal * 2300struct terminal *
2336get_named_tty (name) 2301get_named_tty (const char *name)
2337 char *name;
2338{ 2302{
2339 struct terminal *t; 2303 struct terminal *t;
2340 2304
@@ -2359,8 +2323,7 @@ Returns nil if TERMINAL is not on a tty device.
2359 2323
2360TERMINAL can be a terminal object, a frame, or nil (meaning the 2324TERMINAL can be a terminal object, a frame, or nil (meaning the
2361selected frame's terminal). */) 2325selected frame's terminal). */)
2362 (terminal) 2326 (Lisp_Object terminal)
2363 Lisp_Object terminal;
2364{ 2327{
2365 struct terminal *t = get_terminal (terminal, 1); 2328 struct terminal *t = get_terminal (terminal, 1);
2366 2329
@@ -2379,8 +2342,7 @@ DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
2379TERMINAL can be a terminal object, a frame, or nil (meaning the 2342TERMINAL can be a terminal object, a frame, or nil (meaning the
2380selected frame's terminal). This function always returns nil if 2343selected frame's terminal). This function always returns nil if
2381TERMINAL is not on a tty device. */) 2344TERMINAL is not on a tty device. */)
2382 (terminal) 2345 (Lisp_Object terminal)
2383 Lisp_Object terminal;
2384{ 2346{
2385 struct terminal *t = get_terminal (terminal, 1); 2347 struct terminal *t = get_terminal (terminal, 1);
2386 2348
@@ -2400,8 +2362,7 @@ no effect if used on a non-tty terminal.
2400TERMINAL can be a terminal object, a frame or nil (meaning the 2362TERMINAL can be a terminal object, a frame or nil (meaning the
2401selected frame's terminal). This function always returns nil if 2363selected frame's terminal). This function always returns nil if
2402TERMINAL does not refer to a text-only terminal. */) 2364TERMINAL does not refer to a text-only terminal. */)
2403 (terminal) 2365 (Lisp_Object terminal)
2404 Lisp_Object terminal;
2405{ 2366{
2406 struct terminal *t = get_terminal (terminal, 1); 2367 struct terminal *t = get_terminal (terminal, 1);
2407 2368
@@ -2431,8 +2392,7 @@ terminal device.
2431suspended. 2392suspended.
2432 2393
2433A suspended tty may be resumed by calling `resume-tty' on it. */) 2394A suspended tty may be resumed by calling `resume-tty' on it. */)
2434 (tty) 2395 (Lisp_Object tty)
2435 Lisp_Object tty;
2436{ 2396{
2437 struct terminal *t = get_tty_terminal (tty, 1); 2397 struct terminal *t = get_tty_terminal (tty, 1);
2438 FILE *f; 2398 FILE *f;
@@ -2456,10 +2416,7 @@ A suspended tty may be resumed by calling `resume-tty' on it. */)
2456 } 2416 }
2457 2417
2458 reset_sys_modes (t->display_info.tty); 2418 reset_sys_modes (t->display_info.tty);
2459
2460#ifdef subprocesses
2461 delete_keyboard_wait_descriptor (fileno (f)); 2419 delete_keyboard_wait_descriptor (fileno (f));
2462#endif
2463 2420
2464#ifndef MSDOS 2421#ifndef MSDOS
2465 fclose (f); 2422 fclose (f);
@@ -2498,8 +2455,7 @@ suspended.
2498 2455
2499TTY may be a terminal object, a frame, or nil (meaning the selected 2456TTY may be a terminal object, a frame, or nil (meaning the selected
2500frame's terminal). */) 2457frame's terminal). */)
2501 (tty) 2458 (Lisp_Object tty)
2502 Lisp_Object tty;
2503{ 2459{
2504 struct terminal *t = get_tty_terminal (tty, 1); 2460 struct terminal *t = get_tty_terminal (tty, 1);
2505 int fd; 2461 int fd;
@@ -2528,9 +2484,7 @@ frame's terminal). */)
2528 t->display_info.tty->input = t->display_info.tty->output; 2484 t->display_info.tty->input = t->display_info.tty->output;
2529#endif 2485#endif
2530 2486
2531#ifdef subprocesses
2532 add_keyboard_wait_descriptor (fd); 2487 add_keyboard_wait_descriptor (fd);
2533#endif
2534 2488
2535 if (FRAMEP (t->display_info.tty->top_frame)) 2489 if (FRAMEP (t->display_info.tty->top_frame))
2536 { 2490 {
@@ -2664,7 +2618,7 @@ term_show_mouse_face (enum draw_glyphs_face draw)
2664} 2618}
2665 2619
2666static void 2620static void
2667term_clear_mouse_face () 2621term_clear_mouse_face (void)
2668{ 2622{
2669 if (!NILP (mouse_face_window)) 2623 if (!NILP (mouse_face_window))
2670 term_show_mouse_face (DRAW_NORMAL_TEXT); 2624 term_show_mouse_face (DRAW_NORMAL_TEXT);
@@ -2824,7 +2778,6 @@ term_mouse_highlight (struct frame *f, int x, int y)
2824 2778
2825 /* Check for mouse-face. */ 2779 /* Check for mouse-face. */
2826 { 2780 {
2827 extern Lisp_Object Qmouse_face;
2828 Lisp_Object mouse_face, overlay, position, *overlay_vec; 2781 Lisp_Object mouse_face, overlay, position, *overlay_vec;
2829 int noverlays, obegv, ozv; 2782 int noverlays, obegv, ozv;
2830 struct buffer *obuf; 2783 struct buffer *obuf;
@@ -2950,7 +2903,6 @@ term_mouse_highlight (struct frame *f, int x, int y)
2950 /* Look for a `help-echo' property. */ 2903 /* Look for a `help-echo' property. */
2951 { 2904 {
2952 Lisp_Object help; 2905 Lisp_Object help;
2953 extern Lisp_Object Qhelp_echo;
2954 2906
2955 /* Check overlays first. */ 2907 /* Check overlays first. */
2956 help = Qnil; 2908 help = Qnil;
@@ -3171,7 +3123,7 @@ DEFUN ("gpm-mouse-start", Fgpm_mouse_start, Sgpm_mouse_start,
3171 0, 0, 0, 3123 0, 0, 0,
3172 doc: /* Open a connection to Gpm. 3124 doc: /* Open a connection to Gpm.
3173Gpm-mouse can only be activated for one tty at a time. */) 3125Gpm-mouse can only be activated for one tty at a time. */)
3174 () 3126 (void)
3175{ 3127{
3176 struct frame *f = SELECTED_FRAME (); 3128 struct frame *f = SELECTED_FRAME ();
3177 struct tty_display_info *tty 3129 struct tty_display_info *tty
@@ -3219,7 +3171,7 @@ close_gpm (int fd)
3219DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop, 3171DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop,
3220 0, 0, 0, 3172 0, 0, 0,
3221 doc: /* Close a connection to Gpm. */) 3173 doc: /* Close a connection to Gpm. */)
3222 () 3174 (void)
3223{ 3175{
3224 struct frame *f = SELECTED_FRAME (); 3176 struct frame *f = SELECTED_FRAME ();
3225 struct tty_display_info *tty 3177 struct tty_display_info *tty
@@ -3252,7 +3204,7 @@ create_tty_output (struct frame *f)
3252 abort (); 3204 abort ();
3253 3205
3254 t = xmalloc (sizeof (struct tty_output)); 3206 t = xmalloc (sizeof (struct tty_output));
3255 bzero (t, sizeof (struct tty_output)); 3207 memset (t, 0, sizeof (struct tty_output));
3256 3208
3257 t->display_info = FRAME_TERMINAL (f)->display_info.tty; 3209 t->display_info = FRAME_TERMINAL (f)->display_info.tty;
3258 3210
@@ -3379,7 +3331,7 @@ dissociate_if_controlling_tty (int fd)
3379 EMACS_GET_TTY_PGRP (fd, &pgid); /* If tcgetpgrp succeeds, fd is the ctty. */ 3331 EMACS_GET_TTY_PGRP (fd, &pgid); /* If tcgetpgrp succeeds, fd is the ctty. */
3380 if (pgid != -1) 3332 if (pgid != -1)
3381 { 3333 {
3382#if defined (USG) 3334#if defined (USG5)
3383 setpgrp (); 3335 setpgrp ();
3384 no_controlling_tty = 1; 3336 no_controlling_tty = 1;
3385#elif defined (CYGWIN) 3337#elif defined (CYGWIN)
@@ -3405,8 +3357,6 @@ dissociate_if_controlling_tty (int fd)
3405#endif /* !DOS_NT */ 3357#endif /* !DOS_NT */
3406} 3358}
3407 3359
3408static void maybe_fatal();
3409
3410/* Create a termcap display on the tty device with the given name and 3360/* Create a termcap display on the tty device with the given name and
3411 type. 3361 type.
3412 3362
@@ -3419,7 +3369,7 @@ static void maybe_fatal();
3419 If MUST_SUCCEED is true, then all errors are fatal. */ 3369 If MUST_SUCCEED is true, then all errors are fatal. */
3420 3370
3421struct terminal * 3371struct terminal *
3422init_tty (char *name, char *terminal_type, int must_succeed) 3372init_tty (const char *name, const char *terminal_type, int must_succeed)
3423{ 3373{
3424 char *area = NULL; 3374 char *area = NULL;
3425 char **address = &area; 3375 char **address = &area;
@@ -3459,7 +3409,7 @@ init_tty (char *name, char *terminal_type, int must_succeed)
3459#else 3409#else
3460 tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info)); 3410 tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info));
3461#endif 3411#endif
3462 bzero (tty, sizeof (struct tty_display_info)); 3412 memset (tty, 0, sizeof (struct tty_display_info));
3463 tty->next = tty_list; 3413 tty->next = tty_list;
3464 tty_list = tty; 3414 tty_list = tty;
3465 3415
@@ -3551,9 +3501,7 @@ init_tty (char *name, char *terminal_type, int must_succeed)
3551 terminal->name = xstrdup (name); 3501 terminal->name = xstrdup (name);
3552 tty->type = xstrdup (terminal_type); 3502 tty->type = xstrdup (terminal_type);
3553 3503
3554#ifdef subprocesses
3555 add_keyboard_wait_descriptor (0); 3504 add_keyboard_wait_descriptor (0);
3556#endif
3557 3505
3558 Wcm_clear (tty); 3506 Wcm_clear (tty);
3559 3507
@@ -3778,7 +3726,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3778 3726
3779 if (FrameRows (tty) < 3 || FrameCols (tty) < 3) 3727 if (FrameRows (tty) < 3 || FrameCols (tty) < 3)
3780 maybe_fatal (must_succeed, terminal, 3728 maybe_fatal (must_succeed, terminal,
3781 "Screen size %dx%d is too small" 3729 "Screen size %dx%d is too small",
3782 "Screen size %dx%d is too small", 3730 "Screen size %dx%d is too small",
3783 FrameCols (tty), FrameRows (tty)); 3731 FrameCols (tty), FrameRows (tty));
3784 3732
@@ -3954,24 +3902,39 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3954 return terminal; 3902 return terminal;
3955} 3903}
3956 3904
3905
3906static void
3907vfatal (const char *str, va_list ap)
3908{
3909 fprintf (stderr, "emacs: ");
3910 vfprintf (stderr, str, ap);
3911 if (!(strlen (str) > 0 && str[strlen (str) - 1] == '\n'))
3912 fprintf (stderr, "\n");
3913 va_end (ap);
3914 fflush (stderr);
3915 exit (1);
3916}
3917
3918
3957/* Auxiliary error-handling function for init_tty. 3919/* Auxiliary error-handling function for init_tty.
3958 Delete TERMINAL, then call error or fatal with str1 or str2, 3920 Delete TERMINAL, then call error or fatal with str1 or str2,
3959 respectively, according to MUST_SUCCEED. */ 3921 respectively, according to MUST_SUCCEED. */
3960 3922
3961static void 3923static void
3962maybe_fatal (must_succeed, terminal, str1, str2, arg1, arg2) 3924maybe_fatal (int must_succeed, struct terminal *terminal,
3963 int must_succeed; 3925 const char *str1, const char *str2, ...)
3964 struct terminal *terminal;
3965 char *str1, *str2, *arg1, *arg2;
3966{ 3926{
3927 va_list ap;
3928 va_start (ap, str2);
3967 if (terminal) 3929 if (terminal)
3968 delete_tty (terminal); 3930 delete_tty (terminal);
3969 3931
3970 if (must_succeed) 3932 if (must_succeed)
3971 fatal (str2, arg1, arg2); 3933 vfatal (str2, ap);
3972 else 3934 else
3973 error (str1, arg1, arg2); 3935 verror (str1, ap);
3974 3936
3937 va_end (ap);
3975 abort (); 3938 abort ();
3976} 3939}
3977 3940
@@ -3980,13 +3943,8 @@ fatal (const char *str, ...)
3980{ 3943{
3981 va_list ap; 3944 va_list ap;
3982 va_start (ap, str); 3945 va_start (ap, str);
3983 fprintf (stderr, "emacs: "); 3946 vfatal (str, ap);
3984 vfprintf (stderr, str, ap);
3985 if (!(strlen (str) > 0 && str[strlen (str) - 1] == '\n'))
3986 fprintf (stderr, "\n");
3987 va_end (ap); 3947 va_end (ap);
3988 fflush (stderr);
3989 exit (1);
3990} 3948}
3991 3949
3992 3950
@@ -4035,9 +3993,7 @@ delete_tty (struct terminal *terminal)
4035 3993
4036 if (tty->input) 3994 if (tty->input)
4037 { 3995 {
4038#ifdef subprocesses
4039 delete_keyboard_wait_descriptor (fileno (tty->input)); 3996 delete_keyboard_wait_descriptor (fileno (tty->input));
4040#endif
4041 if (tty->input != stdin) 3997 if (tty->input != stdin)
4042 fclose (tty->input); 3998 fclose (tty->input);
4043 } 3999 }
@@ -4051,7 +4007,7 @@ delete_tty (struct terminal *terminal)
4051 xfree (tty->termcap_strings_buffer); 4007 xfree (tty->termcap_strings_buffer);
4052 xfree (tty->termcap_term_buffer); 4008 xfree (tty->termcap_term_buffer);
4053 4009
4054 bzero (tty, sizeof (struct tty_display_info)); 4010 memset (tty, 0, sizeof (struct tty_display_info));
4055 xfree (tty); 4011 xfree (tty);
4056} 4012}
4057 4013
@@ -4072,7 +4028,7 @@ mark_ttys (void)
4072 4028
4073 4029
4074void 4030void
4075syms_of_term () 4031syms_of_term (void)
4076{ 4032{
4077 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo, 4033 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo,
4078 doc: /* Non-nil means the system uses terminfo rather than termcap. 4034 doc: /* Non-nil means the system uses terminfo rather than termcap.