aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.multi-tty64
-rw-r--r--lib-src/emacsclient.c2
-rw-r--r--lisp/frame.el18
-rw-r--r--lisp/server.el15
-rw-r--r--src/cm.c22
-rw-r--r--src/dispextern.h14
-rw-r--r--src/dispnew.c3
-rw-r--r--src/frame.c22
-rw-r--r--src/keyboard.c37
-rw-r--r--src/sysdep.c20
-rw-r--r--src/term.c1118
-rw-r--r--src/termchar.h120
-rw-r--r--src/xfaces.c2
13 files changed, 817 insertions, 640 deletions
diff --git a/README.multi-tty b/README.multi-tty
index ed2fb17770f..5d3e5f4f014 100644
--- a/README.multi-tty
+++ b/README.multi-tty
@@ -27,8 +27,8 @@ STATUS
27Basic support is there; there are some rough edges, but it already 27Basic support is there; there are some rough edges, but it already
28seems to be usable. Input is read from all terminals (NOT via 28seems to be usable. Input is read from all terminals (NOT via
29MULTIKBOARD!). At the moment, the type of the new terminals must be 29MULTIKBOARD!). At the moment, the type of the new terminals must be
30the same as the initial terminal. Emacsclient was extended to support 30the same as the initial terminal. Emacsclient has been extended to
31opening a new terminal frame. 31support opening a new terminal frame.
32 32
33To try it out, start up the emacs server (M-x server-start), and then 33To try it out, start up the emacs server (M-x server-start), and then
34(from a shell prompt on another terminal) start emacsclient with 34(from a shell prompt on another terminal) start emacsclient with
@@ -147,38 +147,68 @@ DIARY OF CHANGES
147 (Done, emacsclient signals Emacs after writing to the proxy pseudo 147 (Done, emacsclient signals Emacs after writing to the proxy pseudo
148 terminal. This means that multi-tty does not work with raw ttys!) 148 terminal. This means that multi-tty does not work with raw ttys!)
149 149
150THINGS TO DO
151------------
152 150
153** Implement sane error handling after initialization. (Currently 151-- Make make-terminal-frame look up the `tty' and `tty-type' frame
152 parameters from the currently selected terminal before the global
153 default.
154
155 (Done.)
156
157-- Put all cached terminal escape sequences into struct tty_output.
158 Currently, they are still stored in global variables, so we don't
159 really support multiple terminal types.
160
161 (Done.)
162
163-- Implement sane error handling after initialization. (Currently
154 emacs exits if you specify a bad terminal type.) The helpful error 164 emacs exits if you specify a bad terminal type.) The helpful error
155 messages must still be provided when Emacs starts. 165 messages must still be provided when Emacs starts.
156 166
157** C-g should work on secondary terminals. 167 (Done.)
168
169-- Implement terminal deletion, i.e., deleting local frames, closing
170 the tty device and restoring its previous state without exiting
171 Emacs.
158 172
159** Make make-terminal-frame look up the tty and tty-type parameters 173 (Done, but at the moment only called when an error happens during
160 from the currently selected terminal before the global default. 174 initialization. There is a memory corruption error around this
175 somewhere.)
176
177
178THINGS TO DO
179------------
180
181** Fix mysterious memory corruption error with tty deletion. To
182 trigger it, try the following shell command:
183
184 while true; do TERM=no-such-terminal-definition emacsclient -h; done
185
186 Emacs usually dumps core after a few dozen iterations. (The bug
187 seems to be related to the xfree()ing or bzero()ing of
188 tty_output.Wcm. Maybe there are outside references to struct Wcm?
189 Sounds logical, otherwise these vars would not have been collected
190 into a struct. But where?)
191
192 This does not seem to happen if the error occurs before terminal
193 initialization or if I comment out all xfree()s in delete_frame.
194 Update: yes it does, although it is much rarer.
195
196** C-g should work on secondary terminals.
161 197
162** Move optimalization parameters (costs) from union output_data to 198** Move optimalization parameters (costs) from union output_data to
163 a backend-neutral per-device structure. 199 a backend-neutral per-device structure.
164 200
165** Implement terminal deletion, i.e., deleting local frames, closing
166 the tty device and restoring its previous state without exiting
167 Emacs. This should be exported to the Lisp environment.
168
169** Implement automatic deletion of terminals when the last frame on 201** Implement automatic deletion of terminals when the last frame on
170 that terminal is closed. 202 that terminal is closed.
171 203
172** Put all cached terminal escape sequences into struct tty_output.
173 Currently, they are still stored in global variables, so we don't
174 really support multiple terminal types.
175
176** Make parts of struct tty_output accessible from Lisp. The device 204** Make parts of struct tty_output accessible from Lisp. The device
177 name and the type is sufficient. 205 name and the type is sufficient.
178 206
207** Export delete_tty to the Lisp environment.
208
179** Implement support for starting an interactive Emacs session without 209** Implement support for starting an interactive Emacs session without
180 an initial frame. (The user would connect to it and open frames 210 an initial frame. (The user would connect to it and open frames
181 later, with emacsclient.) Not necessary a good idea. 211 later, with emacsclient.) Not necessarily a good idea.
182 212
183** Support raw secondary terminals. (This one is tricky, SIGIO works 213** Support raw secondary terminals. (This one is tricky, SIGIO works
184 only on the controlling terminal.) 214 only on the controlling terminal.)
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 14da37b1bb8..0ff8f2e6a3b 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1095,7 +1095,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1095 if (emacs_pid == 0) 1095 if (emacs_pid == 0)
1096 { 1096 {
1097 reset_tty (); 1097 reset_tty ();
1098 fprintf (stderr, "%s: Could not get process id of Emacs\n", argv[0]); 1098 fprintf (stderr, "%s: %s\n", argv[0], str);
1099 fail (argc, argv); 1099 fail (argc, argv);
1100 } 1100 }
1101 1101
diff --git a/lisp/frame.el b/lisp/frame.el
index 367f40d6f8e..1dbf8321bf3 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -558,6 +558,24 @@ The optional second argument PARAMETERS specifies additional frame parameters."
558 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN")) 558 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
559 (make-frame (cons (cons 'display display) parameters))) 559 (make-frame (cons (cons 'display display) parameters)))
560 560
561;;;###autoload
562(defun make-frame-on-tty (device type &optional parameters)
563 "Make a frame on terminal DEVICE which is of type TYPE (e.g., \"xterm\").
564The optional third argument PARAMETERS specifies additional frame parameters.
565
566DEVICE must be a proxy psudo terminal created by emacsclient,
567otherwise there will be problems with terminal input and window
568resizes. (The kernel notifies processes about pending input or
569terminal resizes only on the controlling terminal, so we need
570emacsclient to sit on the real terminal device, create SIGIO
571signals upon terminal input, and forward SIGWINCH signals to
572us.)"
573 (unless device
574 (error "Invalid terminal device"))
575 (unless type
576 (error "Invalid terminal type"))
577 (make-frame `((tty . ,device) (tty-type . ,type) . ,parameters)))
578
561(defun make-frame-command () 579(defun make-frame-command ()
562 "Make a new frame, and select it if the terminal displays only one frame." 580 "Make a new frame, and select it if the terminal displays only one frame."
563 (interactive) 581 (interactive)
diff --git a/lisp/server.el b/lisp/server.el
index f2c1fc9ce2a..9721dbc4a41 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -345,12 +345,15 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"."
345 (if coding-system 345 (if coding-system
346 (setq arg (decode-coding-string arg coding-system))) 346 (setq arg (decode-coding-string arg coding-system)))
347 (if eval 347 (if eval
348 (let ((v (eval (car (read-from-string arg))))) 348 (condition-case err
349 (when v 349 (let ((v (eval (car (read-from-string arg)))))
350 (with-temp-buffer 350 (when v
351 (let ((standard-output (current-buffer))) 351 (with-temp-buffer
352 (pp v) 352 (let ((standard-output (current-buffer)))
353 (process-send-region proc (point-min) (point-max)))))) 353 (pp v)
354 (process-send-region proc (point-min) (point-max))))))
355 (error (process-send-string proc (concat "*Error* " (error-message-string err)))))
356
354 ;; ARG is a file name. 357 ;; ARG is a file name.
355 ;; Collapse multiple slashes to single slashes. 358 ;; Collapse multiple slashes to single slashes.
356 (setq arg (command-line-normalize-file-name arg)) 359 (setq arg (command-line-normalize-file-name arg))
diff --git a/src/cm.c b/src/cm.c
index 31972b5d9f7..d1deb12f690 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -83,9 +83,9 @@ cmputc (c)
83 */ 83 */
84 84
85static 85static
86at (row, col) { 86at (tty, row, col) {
87 curY = row; 87 curY (tty) = row;
88 curX = col; 88 curX (tty) = col;
89} 89}
90 90
91/* 91/*
@@ -93,8 +93,8 @@ at (row, col) {
93 */ 93 */
94 94
95static 95static
96addcol (n) { 96addcol (tty, n) {
97 curX += n; 97 curX (tty) += n;
98 98
99 /* 99 /*
100 * If cursor hit edge of screen, what happened? 100 * If cursor hit edge of screen, what happened?
@@ -104,21 +104,21 @@ addcol (n) {
104 * of the last line. 104 * of the last line.
105 */ 105 */
106 106
107 if (curX == Wcm.cm_cols) { 107 if (curX (tty) == tty->Wcm->cm_cols) {
108 /* 108 /*
109 * Well, if magicwrap, still there, past the edge of the 109 * Well, if magicwrap, still there, past the edge of the
110 * screen (!). If autowrap, on the col 0 of the next line. 110 * screen (!). If autowrap, on the col 0 of the next line.
111 * Otherwise on last column. 111 * Otherwise on last column.
112 */ 112 */
113 113
114 if (Wcm.cm_magicwrap) 114 if (tty->Wcm->cm_magicwrap)
115 ; /* "limbo" */ 115 ; /* "limbo" */
116 else if (Wcm.cm_autowrap) { 116 else if (tty->Wcm->cm_autowrap) {
117 curX = 0; 117 curX (tty) = 0;
118 curY++; /* Beware end of screen! */ 118 curY (tty) ++; /* Beware end of screen! */
119 } 119 }
120 else 120 else
121 curX--; 121 curX (tty)--;
122 } 122 }
123} 123}
124#endif 124#endif
diff --git a/src/dispextern.h b/src/dispextern.h
index 195d080ca92..7148c68859c 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2724,15 +2724,15 @@ extern Lisp_Object Qredisplay_dont_pause;
2724/* Defined in term.c */ 2724/* Defined in term.c */
2725 2725
2726extern void ring_bell P_ ((void)); 2726extern void ring_bell P_ ((void));
2727extern void set_terminal_modes P_ (()); 2727extern void set_terminal_modes P_ ((void));
2728extern void reset_terminal_modes P_ (()); 2728extern void reset_terminal_modes P_ ((void));
2729extern void update_begin P_ ((struct frame *)); 2729extern void update_begin P_ ((struct frame *));
2730extern void update_end P_ ((struct frame *)); 2730extern void update_end P_ ((struct frame *));
2731extern void set_terminal_window P_ ((int)); 2731extern void set_terminal_window P_ ((int));
2732extern void set_scroll_region P_ ((int, int)); 2732extern void set_scroll_region P_ ((int, int));
2733extern void turn_off_insert P_ ((void)); 2733extern void turn_off_insert P_ ((struct tty_output *));
2734extern void turn_off_highlight P_ ((void)); 2734extern void turn_off_highlight P_ ((struct tty_output *));
2735extern void background_highlight P_ ((void)); 2735extern void background_highlight P_ ((struct tty_output *));
2736extern void clear_frame P_ ((void)); 2736extern void clear_frame P_ ((void));
2737extern void clear_end_of_line P_ ((int)); 2737extern void clear_end_of_line P_ ((int));
2738extern void clear_end_of_line_raw P_ ((int)); 2738extern void clear_end_of_line_raw P_ ((int));
@@ -2742,12 +2742,12 @@ extern int string_cost P_ ((char *));
2742extern int per_line_cost P_ ((char *)); 2742extern int per_line_cost P_ ((char *));
2743extern void calculate_costs P_ ((struct frame *)); 2743extern void calculate_costs P_ ((struct frame *));
2744extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object)); 2744extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object));
2745extern void tty_setup_colors P_ ((int)); 2745extern void tty_setup_colors P_ ((struct tty_output *, int));
2746extern struct tty_output *term_init P_ ((char *, char *)); 2746extern struct tty_output *term_init P_ ((char *, char *));
2747extern struct tty_output *term_dummy_init P_ ((void)); 2747extern struct tty_output *term_dummy_init P_ ((void));
2748extern void fatal P_ ((/* char *, ... */)); 2748extern void fatal P_ ((/* char *, ... */));
2749void cursor_to P_ ((int, int)); 2749void cursor_to P_ ((int, int));
2750extern int tty_capable_p P_ ((struct frame *, unsigned, unsigned long, unsigned long)); 2750extern int tty_capable_p P_ ((struct tty_output *, unsigned, unsigned long, unsigned long));
2751 2751
2752/* Defined in scroll.c */ 2752/* Defined in scroll.c */
2753 2753
diff --git a/src/dispnew.c b/src/dispnew.c
index 9d7281f32d4..b4aa9698937 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3313,7 +3313,7 @@ DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
3313 3313
3314 update_begin (f); 3314 update_begin (f);
3315 if (FRAME_MSDOS_P (f)) 3315 if (FRAME_MSDOS_P (f))
3316 set_terminal_modes (0); 3316 set_terminal_modes ();
3317 clear_frame (); 3317 clear_frame ();
3318 clear_current_matrices (f); 3318 clear_current_matrices (f);
3319 update_end (f); 3319 update_end (f);
@@ -6485,7 +6485,6 @@ init_display ()
6485 SET_CHAR_GLYPH_FROM_GLYPH (space_glyph, ' '); 6485 SET_CHAR_GLYPH_FROM_GLYPH (space_glyph, ' ');
6486 space_glyph.charpos = -1; 6486 space_glyph.charpos = -1;
6487 6487
6488 meta_key = 0;
6489 inverse_video = 0; 6488 inverse_video = 0;
6490 cursor_in_echo_area = 0; 6489 cursor_in_echo_area = 0;
6491 terminal_type = (char *) 0; 6490 terminal_type = (char *) 0;
diff --git a/src/frame.c b/src/frame.c
index 158aa1058fc..72d28c72b79 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -478,14 +478,21 @@ make_minibuffer_frame ()
478static int terminal_frame_count; 478static int terminal_frame_count;
479 479
480struct frame * 480struct frame *
481make_terminal_frame (tty, tty_type) 481make_terminal_frame (tty_name, tty_type)
482 char *tty; 482 char *tty_name;
483 char *tty_type; 483 char *tty_type;
484{ 484{
485 register struct frame *f; 485 register struct frame *f;
486 Lisp_Object frame; 486 Lisp_Object frame;
487 char name[20]; 487 char name[20];
488 struct tty_output *tty;
488 489
490 /* init_term may throw an error, so create the tty first. */
491 if (initialized)
492 tty = term_init (tty_name, tty_type);
493 else
494 tty = term_dummy_init ();
495
489#ifdef MULTI_KBOARD 496#ifdef MULTI_KBOARD
490 if (!initial_kboard) 497 if (!initial_kboard)
491 { 498 {
@@ -544,10 +551,7 @@ make_terminal_frame (tty, tty_type)
544 make_mac_terminal_frame (f); 551 make_mac_terminal_frame (f);
545#else 552#else
546 f->output_method = output_termcap; 553 f->output_method = output_termcap;
547 if (initialized) 554 f->output_data.tty = tty;
548 f->output_data.tty = term_init (tty, tty_type);
549 else
550 f->output_data.tty = term_dummy_init ();
551 f->output_data.tty->top_frame = frame; 555 f->output_data.tty->top_frame = frame;
552#ifdef CANNOT_DUMP 556#ifdef CANNOT_DUMP
553 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR; 557 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
@@ -608,6 +612,8 @@ Note that changing the size of one terminal frame automatically affects all. */
608 /* XXX Ugh, there must be a better way to do this. */ 612 /* XXX Ugh, there must be a better way to do this. */
609 tty = Fassq (Qtty, parms); 613 tty = Fassq (Qtty, parms);
610 if (EQ (tty, Qnil)) 614 if (EQ (tty, Qnil))
615 tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
616 if (EQ (tty, Qnil))
611 tty = Fassq (Qtty, Vdefault_frame_alist); 617 tty = Fassq (Qtty, Vdefault_frame_alist);
612 if (! EQ (tty, Qnil)) 618 if (! EQ (tty, Qnil))
613 tty = XCDR (tty); 619 tty = XCDR (tty);
@@ -617,6 +623,8 @@ Note that changing the size of one terminal frame automatically affects all. */
617 tty_type = Fassq (Qtty_type, parms); 623 tty_type = Fassq (Qtty_type, parms);
618 if (EQ (tty_type, Qnil)) 624 if (EQ (tty_type, Qnil))
619 tty_type = Fassq (Qtty_type, Vdefault_frame_alist); 625 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
626 if (EQ (tty_type, Qnil))
627 tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
620 if (! EQ (tty_type, Qnil)) 628 if (! EQ (tty_type, Qnil))
621 tty_type = XCDR (tty_type); 629 tty_type = XCDR (tty_type);
622 if (EQ (tty_type, Qnil) || !STRINGP (tty_type)) 630 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
@@ -1300,7 +1308,7 @@ The functions are run with one arg, the frame to be deleted. */)
1300 { 1308 {
1301 FOR_EACH_FRAME (tail, frame1) 1309 FOR_EACH_FRAME (tail, frame1)
1302 { 1310 {
1303 if (! EQ (frame, frame1)) 1311 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1304 break; 1312 break;
1305 } 1313 }
1306 } 1314 }
diff --git a/src/keyboard.c b/src/keyboard.c
index 810cf682b18..f1e19079733 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -461,11 +461,6 @@ FILE *dribble;
461/* Nonzero if input is available. */ 461/* Nonzero if input is available. */
462int input_pending; 462int input_pending;
463 463
464/* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
465 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
466
467int meta_key;
468
469/* Non-zero means force key bindings update in parse_menu_item. */ 464/* Non-zero means force key bindings update in parse_menu_item. */
470 465
471int update_menu_bindings; 466int update_menu_bindings;
@@ -6593,7 +6588,9 @@ read_avail_input (expected)
6593 of characters on some systems when input is stuffed at us. */ 6588 of characters on some systems when input is stuffed at us. */
6594 unsigned char cbuf[KBD_BUFFER_SIZE - 1]; 6589 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6595 int n_to_read; 6590 int n_to_read;
6596 6591 struct tty_output *tty;
6592 Lisp_Object frame;
6593
6597#ifdef WINDOWSNT 6594#ifdef WINDOWSNT
6598 return 0; 6595 return 0;
6599#else /* not WINDOWSNT */ 6596#else /* not WINDOWSNT */
@@ -6607,12 +6604,14 @@ read_avail_input (expected)
6607 6604
6608#else /* not MSDOS */ 6605#else /* not MSDOS */
6609 6606
6610 struct tty_output *tty;
6611 nread = 0; 6607 nread = 0;
6612 6608
6613 /* Try to read from each available tty, until one succeeds. */ 6609 /* Try to read from each available tty, until one succeeds. */
6614 for (tty = tty_list; tty; tty = tty->next) { 6610 for (tty = tty_list; tty; tty = tty->next) {
6615 6611
6612 if (! tty->term_initted)
6613 continue;
6614
6616 /* Determine how many characters we should *try* to read. */ 6615 /* Determine how many characters we should *try* to read. */
6617#ifdef FIONREAD 6616#ifdef FIONREAD
6618 /* Find out how much input is available. */ 6617 /* Find out how much input is available. */
@@ -6720,15 +6719,15 @@ read_avail_input (expected)
6720 /* Select frame corresponding to the active tty. Note that the 6719 /* Select frame corresponding to the active tty. Note that the
6721 value of selected_frame is not reliable here, redisplay tends 6720 value of selected_frame is not reliable here, redisplay tends
6722 to temporarily change it. But tty should always be non-NULL. */ 6721 to temporarily change it. But tty should always be non-NULL. */
6723 Lisp_Object frame = (tty ? tty->top_frame : selected_frame); 6722 frame = (tty ? tty->top_frame : selected_frame);
6724 6723
6725 for (i = 0; i < nread; i++) 6724 for (i = 0; i < nread; i++)
6726 { 6725 {
6727 buf[i].kind = ASCII_KEYSTROKE_EVENT; 6726 buf[i].kind = ASCII_KEYSTROKE_EVENT;
6728 buf[i].modifiers = 0; 6727 buf[i].modifiers = 0;
6729 if (meta_key == 1 && (cbuf[i] & 0x80)) 6728 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6730 buf[i].modifiers = meta_modifier; 6729 buf[i].modifiers = meta_modifier;
6731 if (meta_key != 2) 6730 if (tty->meta_key != 2)
6732 cbuf[i] &= ~0x80; 6731 cbuf[i] &= ~0x80;
6733 6732
6734 buf[i].code = cbuf[i]; 6733 buf[i].code = cbuf[i];
@@ -10109,7 +10108,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10109 /* sys_suspend can get an error if it tries to fork a subshell 10108 /* sys_suspend can get an error if it tries to fork a subshell
10110 and the system resources aren't available for that. */ 10109 and the system resources aren't available for that. */
10111 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, 10110 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes,
10112 Qnil); 10111 (Lisp_Object)CURTTY()); /* XXX */
10113 stuff_buffered_input (stuffstring); 10112 stuff_buffered_input (stuffstring);
10114 if (cannot_suspend) 10113 if (cannot_suspend)
10115 sys_subshell (); 10114 sys_subshell ();
@@ -10438,14 +10437,14 @@ See also `current-input-mode'. */)
10438 10437
10439 flow_control = !NILP (flow); 10438 flow_control = !NILP (flow);
10440 if (NILP (meta)) 10439 if (NILP (meta))
10441 meta_key = 0; 10440 FRAME_TTY (SELECTED_FRAME ())->meta_key = 0;
10442 else if (EQ (meta, Qt)) 10441 else if (EQ (meta, Qt))
10443 meta_key = 1; 10442 FRAME_TTY (SELECTED_FRAME ())->meta_key = 1;
10444 else 10443 else
10445 meta_key = 2; 10444 FRAME_TTY (SELECTED_FRAME ())->meta_key = 2;
10446 if (!NILP (quit)) 10445 if (!NILP (quit))
10447 /* Don't let this value be out of range. */ 10446 /* Don't let this value be out of range. */
10448 quit_char = XINT (quit) & (meta_key ? 0377 : 0177); 10447 quit_char = XINT (quit) & (FRAME_TTY (SELECTED_FRAME ())->meta_key ? 0377 : 0177);
10449 10448
10450#ifndef DOS_NT 10449#ifndef DOS_NT
10451 init_all_sys_modes (); 10450 init_all_sys_modes ();
@@ -10478,7 +10477,9 @@ The elements of this list correspond to the arguments of
10478 10477
10479 val[0] = interrupt_input ? Qt : Qnil; 10478 val[0] = interrupt_input ? Qt : Qnil;
10480 val[1] = flow_control ? Qt : Qnil; 10479 val[1] = flow_control ? Qt : Qnil;
10481 val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; 10480 val[2] = FRAME_TTY (SELECTED_FRAME ())->meta_key == 2
10481 ? make_number (0)
10482 : FRAME_TTY (SELECTED_FRAME ())->meta_key == 1 ? Qt : Qnil;
10482 XSETFASTINT (val[3], quit_char); 10483 XSETFASTINT (val[3], quit_char);
10483 10484
10484 return Flist (sizeof (val) / sizeof (val[0]), val); 10485 return Flist (sizeof (val) / sizeof (val[0]), val);
diff --git a/src/sysdep.c b/src/sysdep.c
index 946e2c1384a..ad8b5c518b1 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1362,14 +1362,15 @@ nil means don't delete them until `list-processes' is run. */);
1362 if (!read_socket_hook && EQ (Vwindow_system, Qnil)) 1362 if (!read_socket_hook && EQ (Vwindow_system, Qnil))
1363#endif 1363#endif
1364 { 1364 {
1365 EMACS_GET_TTY (fileno (TTY_INPUT (tty_out)), &tty_out->old_tty); 1365 if (! tty_out->old_tty)
1366 1366 tty_out->old_tty = (struct emacs_tty *) xmalloc (sizeof (struct emacs_tty));
1367 tty_out->old_tty_valid = 1; 1367
1368 EMACS_GET_TTY (fileno (TTY_INPUT (tty_out)), tty_out->old_tty);
1368 1369
1369 tty = tty_out->old_tty; 1370 tty = *tty_out->old_tty;
1370 1371
1371#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 1372#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1372 XSETINT (Vtty_erase_char, tty_out->old_tty.main.c_cc[VERASE]); 1373 XSETINT (Vtty_erase_char, tty.main.c_cc[VERASE]);
1373 1374
1374#ifdef DGUX 1375#ifdef DGUX
1375 /* This allows meta to be sent on 8th bit. */ 1376 /* This allows meta to be sent on 8th bit. */
@@ -1403,7 +1404,7 @@ nil means don't delete them until `list-processes' is run. */);
1403 on output */ 1404 on output */
1404 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */ 1405 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */
1405#ifdef CS8 1406#ifdef CS8
1406 if (meta_key) 1407 if (tty_out->meta_key)
1407 { 1408 {
1408 tty.main.c_cflag |= CS8; /* allow 8th bit on input */ 1409 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
1409 tty.main.c_cflag &= ~PARENB;/* Don't check parity */ 1410 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
@@ -1641,7 +1642,6 @@ nil means don't delete them until `list-processes' is run. */);
1641#endif 1642#endif
1642 ) 1643 )
1643#endif 1644#endif
1644 set_terminal_modes (tty_out);
1645 1645
1646 if (!tty_out->term_initted) 1646 if (!tty_out->term_initted)
1647 { 1647 {
@@ -1838,7 +1838,7 @@ reset_sys_modes (tty_out)
1838 } 1838 }
1839#endif 1839#endif
1840 1840
1841 reset_terminal_modes (tty_out); 1841 tty_reset_terminal_modes (tty_out);
1842 fflush (TTY_OUTPUT (tty_out)); 1842 fflush (TTY_OUTPUT (tty_out));
1843#ifdef BSD_SYSTEM 1843#ifdef BSD_SYSTEM
1844#ifndef BSD4_1 1844#ifndef BSD4_1
@@ -1867,9 +1867,9 @@ reset_sys_modes (tty_out)
1867 reset_sigio (); 1867 reset_sigio ();
1868#endif /* BSD4_1 */ 1868#endif /* BSD4_1 */
1869 1869
1870 if (tty_out->old_tty_valid) 1870 if (tty_out->old_tty)
1871 while (EMACS_SET_TTY (fileno (TTY_INPUT (tty_out)), 1871 while (EMACS_SET_TTY (fileno (TTY_INPUT (tty_out)),
1872 &tty_out->old_tty, 0) < 0 && errno == EINTR) 1872 tty_out->old_tty, 0) < 0 && errno == EINTR)
1873 ; 1873 ;
1874 1874
1875#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ 1875#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
diff --git a/src/term.c b/src/term.c
index 80e5e437e43..53171e92369 100644
--- a/src/term.c
+++ b/src/term.c
@@ -69,8 +69,12 @@ extern int tgetnum P_ ((char *id));
69 69
70static void turn_on_face P_ ((struct frame *, int face_id)); 70static void turn_on_face P_ ((struct frame *, int face_id));
71static void turn_off_face P_ ((struct frame *, int face_id)); 71static void turn_off_face P_ ((struct frame *, int face_id));
72static void tty_show_cursor P_ ((void)); 72static void tty_show_cursor P_ ((struct tty_output *));
73static void tty_hide_cursor P_ ((void)); 73static void tty_hide_cursor P_ ((struct tty_output *));
74
75void delete_tty P_ ((struct tty_output *));
76static void delete_tty_1 P_ ((struct tty_output *));
77
74 78
75#define OUTPUT(tty, a) \ 79#define OUTPUT(tty, a) \
76 emacs_tputs ((tty), a, \ 80 emacs_tputs ((tty), a, \
@@ -100,11 +104,12 @@ Lisp_Object Vring_bell_function;
100 104
101struct tty_output *tty_list; 105struct tty_output *tty_list;
102 106
103/* Nonzero means no need to redraw the entire frame on resuming 107/* Nonzero means no need to redraw the entire frame on resuming a
104 a suspended Emacs. This is useful on terminals with multiple pages, 108 suspended Emacs. This is useful on terminals with multiple
105 where one page is used for Emacs and another for all else. */ 109 pages, where one page is used for Emacs and another for all
110 else. */
106int no_redraw_on_reenter; 111int no_redraw_on_reenter;
107 112
108/* Hook functions that you can set to snap out the functions in this file. 113/* Hook functions that you can set to snap out the functions in this file.
109 These are all extern'd in termhooks.h */ 114 These are all extern'd in termhooks.h */
110 115
@@ -233,51 +238,6 @@ void (*redeem_scroll_bar_hook) P_ ((struct window *window));
233 238
234void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME)); 239void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME));
235 240
236/* Strings, numbers and flags taken from the termcap entry. */
237
238char *TS_ins_line; /* "al" */
239char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */
240char *TS_bell; /* "bl" */
241char *TS_clr_to_bottom; /* "cd" */
242char *TS_clr_line; /* "ce", clear to end of line */
243char *TS_clr_frame; /* "cl" */
244char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */
245char *TS_set_scroll_region_1; /* "cS" (4 params: total lines,
246 lines above scroll region, lines below it,
247 total lines again) */
248char *TS_del_char; /* "dc" */
249char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */
250char *TS_del_line; /* "dl" */
251char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */
252char *TS_delete_mode; /* "dm", enter character-delete mode */
253char *TS_end_delete_mode; /* "ed", leave character-delete mode */
254char *TS_end_insert_mode; /* "ei", leave character-insert mode */
255char *TS_ins_char; /* "ic" */
256char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */
257char *TS_insert_mode; /* "im", enter character-insert mode */
258char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */
259char *TS_end_keypad_mode; /* "ke" */
260char *TS_keypad_mode; /* "ks" */
261char *TS_pad_char; /* "pc", char to use as padding */
262char *TS_repeat; /* "rp" (2 params, # times to repeat
263 and character to be repeated) */
264char *TS_end_standout_mode; /* "se" */
265char *TS_fwd_scroll; /* "sf" */
266char *TS_standout_mode; /* "so" */
267char *TS_rev_scroll; /* "sr" */
268char *TS_end_termcap_modes; /* "te" */
269char *TS_termcap_modes; /* "ti" */
270char *TS_visible_bell; /* "vb" */
271char *TS_cursor_normal; /* "ve" */
272char *TS_cursor_visible; /* "vs" */
273char *TS_cursor_invisible; /* "vi" */
274char *TS_set_window; /* "wi" (4 params, start and end of window,
275 each as vpos and hpos) */
276
277/* Value of the "NC" (no_color_video) capability, or 0 if not
278 present. */
279
280static int TN_no_color_video;
281 241
282/* Meaning of bits in no_color_video. Each bit set means that the 242/* Meaning of bits in no_color_video. Each bit set means that the
283 corresponding attribute cannot be combined with colors. */ 243 corresponding attribute cannot be combined with colors. */
@@ -295,68 +255,6 @@ enum no_color_bit
295 NC_ALT_CHARSET = 1 << 8 255 NC_ALT_CHARSET = 1 << 8
296}; 256};
297 257
298/* "md" -- turn on bold (extra bright mode). */
299
300char *TS_enter_bold_mode;
301
302/* "mh" -- turn on half-bright mode. */
303
304char *TS_enter_dim_mode;
305
306/* "mb" -- enter blinking mode. */
307
308char *TS_enter_blink_mode;
309
310/* "mr" -- enter reverse video mode. */
311
312char *TS_enter_reverse_mode;
313
314/* "us"/"ue" -- start/end underlining. */
315
316char *TS_exit_underline_mode, *TS_enter_underline_mode;
317
318/* "as"/"ae" -- start/end alternate character set. Not really
319 supported, yet. */
320
321char *TS_enter_alt_charset_mode, *TS_exit_alt_charset_mode;
322
323/* "me" -- switch appearances off. */
324
325char *TS_exit_attribute_mode;
326
327/* "Co" -- number of colors. */
328
329int TN_max_colors;
330
331/* "pa" -- max. number of color pairs on screen. Not handled yet.
332 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
333
334int TN_max_pairs;
335
336/* "op" -- SVr4 set default pair to its original value. */
337
338char *TS_orig_pair;
339
340/* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
341 1 param, the color index. */
342
343char *TS_set_foreground, *TS_set_background;
344
345int TF_hazeltine; /* termcap hz flag. */
346int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */
347int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */
348int TF_underscore; /* termcap ul flag: _ underlines if over-struck on
349 non-blank position. Must clear before writing _. */
350int TF_teleray; /* termcap xt flag: many weird consequences.
351 For t1061. */
352
353static int RPov; /* # chars to start a TS_repeat */
354
355static int delete_in_insert_mode; /* delete mode == insert mode */
356
357static int se_is_so; /* 1 if same string both enters and leaves
358 standout mode */
359
360/* internal state */ 258/* internal state */
361 259
362/* The largest frame width in any call to calculate_costs. */ 260/* The largest frame width in any call to calculate_costs. */
@@ -367,20 +265,6 @@ int max_frame_cols;
367 265
368int max_frame_lines; 266int max_frame_lines;
369 267
370static int costs_set; /* Nonzero if costs have been calculated. */
371
372int insert_mode; /* Nonzero when in insert mode. */
373int standout_mode; /* Nonzero when in standout mode. */
374
375/* Size of window specified by higher levels.
376 This is the number of lines, from the top of frame downwards,
377 which can participate in insert-line/delete-line operations.
378
379 Effectively it excludes the bottom frame_lines - specified_window_size
380 lines from those operations. */
381
382int specified_window;
383
384/* Frame currently being redisplayed; 0 if not currently redisplaying. 268/* Frame currently being redisplayed; 0 if not currently redisplaying.
385 (Direct output does not count). */ 269 (Direct output does not count). */
386 270
@@ -390,10 +274,6 @@ FRAME_PTR updating_frame;
390 274
391static int system_uses_terminfo; 275static int system_uses_terminfo;
392 276
393/* Flag used in tty_show/hide_cursor. */
394
395static int tty_cursor_hidden;
396
397char *tparam (); 277char *tparam ();
398 278
399extern char *tgetstr (); 279extern char *tgetstr ();
@@ -438,43 +318,47 @@ ring_bell ()
438 (*ring_bell_hook) (); 318 (*ring_bell_hook) ();
439 else { 319 else {
440 struct tty_output *tty = FRAME_TTY (f); 320 struct tty_output *tty = FRAME_TTY (f);
441 OUTPUT (tty, TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell); 321 OUTPUT (tty, tty->TS_visible_bell && visible_bell ? tty->TS_visible_bell : tty->TS_bell);
442 } 322 }
443} 323}
444 324
325void tty_set_terminal_modes (struct tty_output *tty)
326{
327 OUTPUT_IF (tty, tty->TS_termcap_modes);
328 OUTPUT_IF (tty, tty->TS_cursor_visible);
329 OUTPUT_IF (tty, tty->TS_keypad_mode);
330 losecursor (tty);
331}
332
445void 333void
446set_terminal_modes () 334set_terminal_modes ()
447{ 335{
448 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 336 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
449 if (FRAME_TERMCAP_P (f)) 337 if (FRAME_TERMCAP_P (f))
450 { 338 tty_set_terminal_modes (FRAME_TTY (f));
451 struct tty_output *tty = FRAME_TTY (f);
452 OUTPUT_IF (tty, TS_termcap_modes);
453 OUTPUT_IF (tty, TS_cursor_visible);
454 OUTPUT_IF (tty, TS_keypad_mode);
455 losecursor (tty);
456 }
457 else 339 else
458 (*set_terminal_modes_hook) (); 340 (*set_terminal_modes_hook) ();
459} 341}
460 342
343void tty_reset_terminal_modes (struct tty_output *tty)
344{
345 turn_off_highlight (tty);
346 turn_off_insert (tty);
347 OUTPUT_IF (tty, tty->TS_end_keypad_mode);
348 OUTPUT_IF (tty, tty->TS_cursor_normal);
349 OUTPUT_IF (tty, tty->TS_end_termcap_modes);
350 OUTPUT_IF (tty, tty->TS_orig_pair);
351 /* Output raw CR so kernel can track the cursor hpos. */
352 current_tty = tty;
353 cmputc ('\r');
354}
355
461void 356void
462reset_terminal_modes () 357reset_terminal_modes ()
463{ 358{
464 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 359 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
465 if (FRAME_TERMCAP_P (f)) 360 if (FRAME_TERMCAP_P (f))
466 { 361 tty_reset_terminal_modes (FRAME_TTY (f));
467 struct tty_output *tty = FRAME_TTY (f);
468 turn_off_highlight ();
469 turn_off_insert ();
470 OUTPUT_IF (tty, TS_end_keypad_mode);
471 OUTPUT_IF (tty, TS_cursor_normal);
472 OUTPUT_IF (tty, TS_end_termcap_modes);
473 OUTPUT_IF (tty, TS_orig_pair);
474 /* Output raw CR so kernel can track the cursor hpos. */
475 current_tty = tty;
476 cmputc ('\r');
477 }
478 else if (reset_terminal_modes_hook) 362 else if (reset_terminal_modes_hook)
479 (*reset_terminal_modes_hook) (); 363 (*reset_terminal_modes_hook) ();
480} 364}
@@ -494,10 +378,11 @@ update_end (f)
494{ 378{
495 if (FRAME_TERMCAP_P (f)) 379 if (FRAME_TERMCAP_P (f))
496 { 380 {
381 struct tty_output *tty = FRAME_TTY (f);
497 if (!XWINDOW (selected_window)->cursor_off_p) 382 if (!XWINDOW (selected_window)->cursor_off_p)
498 tty_show_cursor (); 383 tty_show_cursor (tty);
499 turn_off_insert (); 384 turn_off_insert (tty);
500 background_highlight (); 385 background_highlight (tty);
501 } 386 }
502 else 387 else
503 update_end_hook (f); 388 update_end_hook (f);
@@ -513,9 +398,9 @@ set_terminal_window (size)
513 if (FRAME_TERMCAP_P (f)) 398 if (FRAME_TERMCAP_P (f))
514 { 399 {
515 struct tty_output *tty = FRAME_TTY (f); 400 struct tty_output *tty = FRAME_TTY (f);
516 specified_window = size ? size : FRAME_LINES (f); 401 tty->specified_window = size ? size : FRAME_LINES (f);
517 if (TTY_SCROLL_REGION_OK (tty)) 402 if (TTY_SCROLL_REGION_OK (tty))
518 set_scroll_region (0, specified_window); 403 set_scroll_region (0, tty->specified_window);
519 } 404 }
520 else 405 else
521 set_terminal_window_hook (size); 406 set_terminal_window_hook (size);
@@ -529,15 +414,15 @@ set_scroll_region (start, stop)
529 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 414 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
530 struct tty_output *tty = FRAME_TTY (f); 415 struct tty_output *tty = FRAME_TTY (f);
531 416
532 if (TS_set_scroll_region) 417 if (tty->TS_set_scroll_region)
533 buf = tparam (TS_set_scroll_region, 0, 0, start, stop - 1); 418 buf = tparam (tty->TS_set_scroll_region, 0, 0, start, stop - 1);
534 else if (TS_set_scroll_region_1) 419 else if (tty->TS_set_scroll_region_1)
535 buf = tparam (TS_set_scroll_region_1, 0, 0, 420 buf = tparam (tty->TS_set_scroll_region_1, 0, 0,
536 FRAME_LINES (f), start, 421 FRAME_LINES (f), start,
537 FRAME_LINES (f) - stop, 422 FRAME_LINES (f) - stop,
538 FRAME_LINES (f)); 423 FRAME_LINES (f));
539 else 424 else
540 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (f)); 425 buf = tparam (tty->TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (f));
541 426
542 OUTPUT (tty, buf); 427 OUTPUT (tty, buf);
543 xfree (buf); 428 xfree (buf);
@@ -546,68 +431,58 @@ set_scroll_region (start, stop)
546 431
547 432
548static void 433static void
549turn_on_insert () 434turn_on_insert (struct tty_output *tty)
550{ 435{
551 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 436 if (!tty->insert_mode)
552 struct tty_output *tty = FRAME_TTY (f); 437 OUTPUT (tty, tty->TS_insert_mode);
553 if (!insert_mode) 438 tty->insert_mode = 1;
554 OUTPUT (tty, TS_insert_mode);
555 insert_mode = 1;
556} 439}
557 440
558void 441void
559turn_off_insert () 442turn_off_insert (struct tty_output *tty)
560{ 443{
561 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 444 if (tty->insert_mode)
562 struct tty_output *tty = FRAME_TTY (f); 445 OUTPUT (tty, tty->TS_end_insert_mode);
563 if (insert_mode) 446 tty->insert_mode = 0;
564 OUTPUT (tty, TS_end_insert_mode);
565 insert_mode = 0;
566} 447}
567 448
568/* Handle highlighting. */ 449/* Handle highlighting. */
569 450
570void 451void
571turn_off_highlight () 452turn_off_highlight (struct tty_output *tty)
572{ 453{
573 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 454 if (tty->standout_mode)
574 struct tty_output *tty = FRAME_TTY (f); 455 OUTPUT_IF (tty, tty->TS_end_standout_mode);
575 if (standout_mode) 456 tty->standout_mode = 0;
576 OUTPUT_IF (tty, TS_end_standout_mode);
577 standout_mode = 0;
578} 457}
579 458
580static void 459static void
581turn_on_highlight () 460turn_on_highlight (struct tty_output *tty)
582{ 461{
583 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 462 if (!tty->standout_mode)
584 struct tty_output *tty = FRAME_TTY (f); 463 OUTPUT_IF (tty, tty->TS_standout_mode);
585 if (!standout_mode) 464 tty->standout_mode = 1;
586 OUTPUT_IF (tty, TS_standout_mode);
587 standout_mode = 1;
588} 465}
589 466
590static void 467static void
591toggle_highlight () 468toggle_highlight (struct tty_output *tty)
592{ 469{
593 if (standout_mode) 470 if (tty->standout_mode)
594 turn_off_highlight (); 471 turn_off_highlight (tty);
595 else 472 else
596 turn_on_highlight (); 473 turn_on_highlight (tty);
597} 474}
598 475
599 476
600/* Make cursor invisible. */ 477/* Make cursor invisible. */
601 478
602static void 479static void
603tty_hide_cursor () 480tty_hide_cursor (struct tty_output *tty)
604{ 481{
605 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 482 if (tty->cursor_hidden == 0)
606 struct tty_output *tty = FRAME_TTY (f);
607 if (tty_cursor_hidden == 0)
608 { 483 {
609 tty_cursor_hidden = 1; 484 tty->cursor_hidden = 1;
610 OUTPUT_IF (tty, TS_cursor_invisible); 485 OUTPUT_IF (tty, tty->TS_cursor_invisible);
611 } 486 }
612} 487}
613 488
@@ -615,16 +490,13 @@ tty_hide_cursor ()
615/* Ensure that cursor is visible. */ 490/* Ensure that cursor is visible. */
616 491
617static void 492static void
618tty_show_cursor () 493tty_show_cursor (struct tty_output *tty)
619{ 494{
620 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 495 if (tty->cursor_hidden)
621 struct tty_output *tty = FRAME_TTY (f);
622
623 if (tty_cursor_hidden)
624 { 496 {
625 tty_cursor_hidden = 0; 497 tty->cursor_hidden = 0;
626 OUTPUT_IF (tty, TS_cursor_normal); 498 OUTPUT_IF (tty, tty->TS_cursor_normal);
627 OUTPUT_IF (tty, TS_cursor_visible); 499 OUTPUT_IF (tty, tty->TS_cursor_visible);
628 } 500 }
629} 501}
630 502
@@ -634,23 +506,23 @@ tty_show_cursor ()
634 depends on the user option inverse-video. */ 506 depends on the user option inverse-video. */
635 507
636void 508void
637background_highlight () 509background_highlight (struct tty_output *tty)
638{ 510{
639 if (inverse_video) 511 if (inverse_video)
640 turn_on_highlight (); 512 turn_on_highlight (tty);
641 else 513 else
642 turn_off_highlight (); 514 turn_off_highlight (tty);
643} 515}
644 516
645/* Set standout mode to the mode specified for the text to be output. */ 517/* Set standout mode to the mode specified for the text to be output. */
646 518
647static void 519static void
648highlight_if_desired () 520highlight_if_desired (struct tty_output *tty)
649{ 521{
650 if (inverse_video) 522 if (inverse_video)
651 turn_on_highlight (); 523 turn_on_highlight (tty);
652 else 524 else
653 turn_off_highlight (); 525 turn_off_highlight (tty);
654} 526}
655 527
656 528
@@ -662,27 +534,28 @@ cursor_to (vpos, hpos)
662 int vpos, hpos; 534 int vpos, hpos;
663{ 535{
664 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 536 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
665 537 struct tty_output *tty;
538
666 if (! FRAME_TERMCAP_P (f) && cursor_to_hook) 539 if (! FRAME_TERMCAP_P (f) && cursor_to_hook)
667 { 540 {
668 (*cursor_to_hook) (vpos, hpos); 541 (*cursor_to_hook) (vpos, hpos);
669 return; 542 return;
670 } 543 }
671 544
672 struct tty_output *tty = FRAME_TTY (f); 545 tty = FRAME_TTY (f);
673 546
674 /* Detect the case where we are called from reset_sys_modes 547 /* Detect the case where we are called from reset_sys_modes
675 and the costs have never been calculated. Do nothing. */ 548 and the costs have never been calculated. Do nothing. */
676 if (! costs_set) 549 if (! tty->costs_set)
677 return; 550 return;
678 551
679 if (curY (tty) == vpos 552 if (curY (tty) == vpos
680 && curX (tty) == hpos) 553 && curX (tty) == hpos)
681 return; 554 return;
682 if (!TF_standout_motion) 555 if (!tty->TF_standout_motion)
683 background_highlight (); 556 background_highlight (tty);
684 if (!TF_insmode_motion) 557 if (!tty->TF_insmode_motion)
685 turn_off_insert (); 558 turn_off_insert (tty);
686 cmgoto (tty, vpos, hpos); 559 cmgoto (tty, vpos, hpos);
687} 560}
688 561
@@ -693,19 +566,20 @@ raw_cursor_to (row, col)
693 int row, col; 566 int row, col;
694{ 567{
695 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); 568 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame);
569 struct tty_output *tty;
696 if (! FRAME_TERMCAP_P (f)) 570 if (! FRAME_TERMCAP_P (f))
697 { 571 {
698 (*raw_cursor_to_hook) (row, col); 572 (*raw_cursor_to_hook) (row, col);
699 return; 573 return;
700 } 574 }
701 struct tty_output *tty = FRAME_TTY (f); 575 tty = FRAME_TTY (f);
702 if (curY (tty) == row 576 if (curY (tty) == row
703 && curX (tty) == col) 577 && curX (tty) == col)
704 return; 578 return;
705 if (!TF_standout_motion) 579 if (!tty->TF_standout_motion)
706 background_highlight (); 580 background_highlight (tty);
707 if (!TF_insmode_motion) 581 if (!tty->TF_insmode_motion)
708 turn_off_insert (); 582 turn_off_insert (tty);
709 cmgoto (tty, row, col); 583 cmgoto (tty, row, col);
710} 584}
711 585
@@ -718,17 +592,18 @@ clear_to_end ()
718 register int i; 592 register int i;
719 593
720 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 594 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
595 struct tty_output *tty;
721 596
722 if (clear_to_end_hook && ! FRAME_TERMCAP_P (f)) 597 if (clear_to_end_hook && ! FRAME_TERMCAP_P (f))
723 { 598 {
724 (*clear_to_end_hook) (); 599 (*clear_to_end_hook) ();
725 return; 600 return;
726 } 601 }
727 struct tty_output *tty = FRAME_TTY (f); 602 tty = FRAME_TTY (f);
728 if (TS_clr_to_bottom) 603 if (tty->TS_clr_to_bottom)
729 { 604 {
730 background_highlight (); 605 background_highlight (tty);
731 OUTPUT (tty, TS_clr_to_bottom); 606 OUTPUT (tty, tty->TS_clr_to_bottom);
732 } 607 }
733 else 608 else
734 { 609 {
@@ -746,17 +621,18 @@ void
746clear_frame () 621clear_frame ()
747{ 622{
748 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 623 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
749 624 struct tty_output *tty;
625
750 if (clear_frame_hook && ! FRAME_TERMCAP_P (f)) 626 if (clear_frame_hook && ! FRAME_TERMCAP_P (f))
751 { 627 {
752 (*clear_frame_hook) (); 628 (*clear_frame_hook) ();
753 return; 629 return;
754 } 630 }
755 struct tty_output *tty = FRAME_TTY (f); 631 tty = FRAME_TTY (f);
756 if (TS_clr_frame) 632 if (tty->TS_clr_frame)
757 { 633 {
758 background_highlight (); 634 background_highlight (tty);
759 OUTPUT (tty, TS_clr_frame); 635 OUTPUT (tty, tty->TS_clr_frame);
760 cmat (tty, 0, 0); 636 cmat (tty, 0, 0);
761 } 637 }
762 else 638 else
@@ -778,6 +654,7 @@ clear_end_of_line (first_unused_hpos)
778 register int i; 654 register int i;
779 655
780 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 656 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
657 struct tty_output *tty;
781 658
782 if (clear_end_of_line_hook 659 if (clear_end_of_line_hook
783 && ! FRAME_TERMCAP_P (f)) 660 && ! FRAME_TERMCAP_P (f))
@@ -786,23 +663,23 @@ clear_end_of_line (first_unused_hpos)
786 return; 663 return;
787 } 664 }
788 665
789 struct tty_output *tty = FRAME_TTY (f); 666 tty = FRAME_TTY (f);
790 667
791 /* Detect the case where we are called from reset_sys_modes 668 /* Detect the case where we are called from reset_sys_modes
792 and the costs have never been calculated. Do nothing. */ 669 and the costs have never been calculated. Do nothing. */
793 if (! costs_set) 670 if (! tty->costs_set)
794 return; 671 return;
795 672
796 if (curX (tty) >= first_unused_hpos) 673 if (curX (tty) >= first_unused_hpos)
797 return; 674 return;
798 background_highlight (); 675 background_highlight (tty);
799 if (TS_clr_line) 676 if (tty->TS_clr_line)
800 { 677 {
801 OUTPUT1 (tty, TS_clr_line); 678 OUTPUT1 (tty, tty->TS_clr_line);
802 } 679 }
803 else 680 else
804 { /* have to do it the hard way */ 681 { /* have to do it the hard way */
805 turn_off_insert (); 682 turn_off_insert (tty);
806 683
807 /* Do not write in last row last col with Auto-wrap on. */ 684 /* Do not write in last row last col with Auto-wrap on. */
808 if (AutoWrap (tty) 685 if (AutoWrap (tty)
@@ -936,6 +813,7 @@ write_glyphs (string, len)
936{ 813{
937 int produced, consumed; 814 int produced, consumed;
938 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); 815 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame);
816 struct tty_output *tty;
939 unsigned char conversion_buffer[1024]; 817 unsigned char conversion_buffer[1024];
940 int conversion_buffer_size = sizeof conversion_buffer; 818 int conversion_buffer_size = sizeof conversion_buffer;
941 819
@@ -946,10 +824,10 @@ write_glyphs (string, len)
946 return; 824 return;
947 } 825 }
948 826
949 struct tty_output *tty = FRAME_TTY (f); 827 tty = FRAME_TTY (f);
950 828
951 turn_off_insert (); 829 turn_off_insert (tty);
952 tty_hide_cursor (); 830 tty_hide_cursor (tty);
953 831
954 /* Don't dare write in last column of bottom line, if Auto-Wrap, 832 /* Don't dare write in last column of bottom line, if Auto-Wrap,
955 since that would scroll the whole frame on some terminals. */ 833 since that would scroll the whole frame on some terminals. */
@@ -978,7 +856,7 @@ write_glyphs (string, len)
978 break; 856 break;
979 857
980 /* Turn appearance modes of the face of the run on. */ 858 /* Turn appearance modes of the face of the run on. */
981 highlight_if_desired (); 859 highlight_if_desired (tty);
982 turn_on_face (f, face_id); 860 turn_on_face (f, face_id);
983 861
984 while (n > 0) 862 while (n > 0)
@@ -1006,7 +884,7 @@ write_glyphs (string, len)
1006 884
1007 /* Turn appearance modes off. */ 885 /* Turn appearance modes off. */
1008 turn_off_face (f, face_id); 886 turn_off_face (f, face_id);
1009 turn_off_highlight (); 887 turn_off_highlight (tty);
1010 } 888 }
1011 889
1012 /* We may have to output some codes to terminate the writing. */ 890 /* We may have to output some codes to terminate the writing. */
@@ -1040,7 +918,8 @@ insert_glyphs (start, len)
1040 char *buf; 918 char *buf;
1041 struct glyph *glyph = NULL; 919 struct glyph *glyph = NULL;
1042 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 920 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
1043 921 struct tty_output *tty;
922
1044 if (len <= 0) 923 if (len <= 0)
1045 return; 924 return;
1046 925
@@ -1050,11 +929,11 @@ insert_glyphs (start, len)
1050 return; 929 return;
1051 } 930 }
1052 931
1053 struct tty_output *tty = FRAME_TTY (f); 932 tty = FRAME_TTY (f);
1054 933
1055 if (TS_ins_multi_chars) 934 if (tty->TS_ins_multi_chars)
1056 { 935 {
1057 buf = tparam (TS_ins_multi_chars, 0, 0, len); 936 buf = tparam (tty->TS_ins_multi_chars, 0, 0, len);
1058 OUTPUT1 (tty, buf); 937 OUTPUT1 (tty, buf);
1059 xfree (buf); 938 xfree (buf);
1060 if (start) 939 if (start)
@@ -1062,7 +941,7 @@ insert_glyphs (start, len)
1062 return; 941 return;
1063 } 942 }
1064 943
1065 turn_on_insert (); 944 turn_on_insert (tty);
1066 cmplus (tty, len); 945 cmplus (tty, len);
1067 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */ 946 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
1068 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; 947 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
@@ -1072,7 +951,7 @@ insert_glyphs (start, len)
1072 unsigned char conversion_buffer[1024]; 951 unsigned char conversion_buffer[1024];
1073 int conversion_buffer_size = sizeof conversion_buffer; 952 int conversion_buffer_size = sizeof conversion_buffer;
1074 953
1075 OUTPUT1_IF (tty, TS_ins_char); 954 OUTPUT1_IF (tty, tty->TS_ins_char);
1076 if (!start) 955 if (!start)
1077 { 956 {
1078 conversion_buffer[0] = SPACEGLYPH; 957 conversion_buffer[0] = SPACEGLYPH;
@@ -1080,7 +959,7 @@ insert_glyphs (start, len)
1080 } 959 }
1081 else 960 else
1082 { 961 {
1083 highlight_if_desired (); 962 highlight_if_desired (tty);
1084 turn_on_face (f, start->face_id); 963 turn_on_face (f, start->face_id);
1085 glyph = start; 964 glyph = start;
1086 ++start; 965 ++start;
@@ -1088,7 +967,7 @@ insert_glyphs (start, len)
1088 occupies more than one column. */ 967 occupies more than one column. */
1089 while (len && CHAR_GLYPH_PADDING_P (*start)) 968 while (len && CHAR_GLYPH_PADDING_P (*start))
1090 { 969 {
1091 OUTPUT1_IF (tty, TS_ins_char); 970 OUTPUT1_IF (tty, tty->TS_ins_char);
1092 start++, len--; 971 start++, len--;
1093 } 972 }
1094 973
@@ -1113,11 +992,11 @@ insert_glyphs (start, len)
1113 TTY_TERMSCRIPT (tty)); 992 TTY_TERMSCRIPT (tty));
1114 } 993 }
1115 994
1116 OUTPUT1_IF (tty, TS_pad_inserted_char); 995 OUTPUT1_IF (tty, tty->TS_pad_inserted_char);
1117 if (start) 996 if (start)
1118 { 997 {
1119 turn_off_face (f, glyph->face_id); 998 turn_off_face (f, glyph->face_id);
1120 turn_off_highlight (); 999 turn_off_highlight (tty);
1121 } 1000 }
1122 } 1001 }
1123 1002
@@ -1140,27 +1019,27 @@ delete_glyphs (n)
1140 } 1019 }
1141 1020
1142 1021
1143 if (delete_in_insert_mode) 1022 if (tty->delete_in_insert_mode)
1144 { 1023 {
1145 turn_on_insert (); 1024 turn_on_insert (tty);
1146 } 1025 }
1147 else 1026 else
1148 { 1027 {
1149 turn_off_insert (); 1028 turn_off_insert (tty);
1150 OUTPUT_IF (tty, TS_delete_mode); 1029 OUTPUT_IF (tty, tty->TS_delete_mode);
1151 } 1030 }
1152 1031
1153 if (TS_del_multi_chars) 1032 if (tty->TS_del_multi_chars)
1154 { 1033 {
1155 buf = tparam (TS_del_multi_chars, 0, 0, n); 1034 buf = tparam (tty->TS_del_multi_chars, 0, 0, n);
1156 OUTPUT1 (tty, buf); 1035 OUTPUT1 (tty, buf);
1157 xfree (buf); 1036 xfree (buf);
1158 } 1037 }
1159 else 1038 else
1160 for (i = 0; i < n; i++) 1039 for (i = 0; i < n; i++)
1161 OUTPUT1 (tty, TS_del_char); 1040 OUTPUT1 (tty, tty->TS_del_char);
1162 if (!delete_in_insert_mode) 1041 if (!tty->delete_in_insert_mode)
1163 OUTPUT_IF (tty, TS_end_delete_mode); 1042 OUTPUT_IF (tty, tty->TS_end_delete_mode);
1164} 1043}
1165 1044
1166/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */ 1045/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
@@ -1169,72 +1048,73 @@ void
1169ins_del_lines (vpos, n) 1048ins_del_lines (vpos, n)
1170 int vpos, n; 1049 int vpos, n;
1171{ 1050{
1172 char *multi = n > 0 ? TS_ins_multi_lines : TS_del_multi_lines;
1173 char *single = n > 0 ? TS_ins_line : TS_del_line;
1174 char *scroll = n > 0 ? TS_rev_scroll : TS_fwd_scroll;
1175 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); 1051 struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame));
1176
1177 register int i = n > 0 ? n : -n;
1178 register char *buf;
1179
1180 if (ins_del_lines_hook && ! FRAME_TERMCAP_P (f)) 1052 if (ins_del_lines_hook && ! FRAME_TERMCAP_P (f))
1181 { 1053 {
1182 (*ins_del_lines_hook) (vpos, n); 1054 (*ins_del_lines_hook) (vpos, n);
1183 return; 1055 return;
1184 } 1056 }
1185
1186 struct tty_output *tty = FRAME_TTY (f);
1187
1188 /* If the lines below the insertion are being pushed
1189 into the end of the window, this is the same as clearing;
1190 and we know the lines are already clear, since the matching
1191 deletion has already been done. So can ignore this. */
1192 /* If the lines below the deletion are blank lines coming
1193 out of the end of the window, don't bother,
1194 as there will be a matching inslines later that will flush them. */
1195 if (TTY_SCROLL_REGION_OK (tty)
1196 && vpos + i >= specified_window)
1197 return;
1198 if (!TTY_MEMORY_BELOW_FRAME (tty)
1199 && vpos + i >= FRAME_LINES (f))
1200 return;
1201
1202 if (multi)
1203 {
1204 raw_cursor_to (vpos, 0);
1205 background_highlight ();
1206 buf = tparam (multi, 0, 0, i);
1207 OUTPUT (tty, buf);
1208 xfree (buf);
1209 }
1210 else if (single)
1211 {
1212 raw_cursor_to (vpos, 0);
1213 background_highlight ();
1214 while (--i >= 0)
1215 OUTPUT (tty, single);
1216 if (TF_teleray)
1217 curX (tty) = 0;
1218 }
1219 else 1057 else
1220 { 1058 {
1221 set_scroll_region (vpos, specified_window); 1059 struct tty_output *tty = FRAME_TTY (f);
1222 if (n < 0) 1060 char *multi = n > 0 ? tty->TS_ins_multi_lines : tty->TS_del_multi_lines;
1223 raw_cursor_to (specified_window - 1, 0); 1061 char *single = n > 0 ? tty->TS_ins_line : tty->TS_del_line;
1062 char *scroll = n > 0 ? tty->TS_rev_scroll : tty->TS_fwd_scroll;
1063
1064 register int i = n > 0 ? n : -n;
1065 register char *buf;
1066
1067 /* If the lines below the insertion are being pushed
1068 into the end of the window, this is the same as clearing;
1069 and we know the lines are already clear, since the matching
1070 deletion has already been done. So can ignore this. */
1071 /* If the lines below the deletion are blank lines coming
1072 out of the end of the window, don't bother,
1073 as there will be a matching inslines later that will flush them. */
1074 if (TTY_SCROLL_REGION_OK (tty)
1075 && vpos + i >= tty->specified_window)
1076 return;
1077 if (!TTY_MEMORY_BELOW_FRAME (tty)
1078 && vpos + i >= FRAME_LINES (f))
1079 return;
1080
1081 if (multi)
1082 {
1083 raw_cursor_to (vpos, 0);
1084 background_highlight (tty);
1085 buf = tparam (multi, 0, 0, i);
1086 OUTPUT (tty, buf);
1087 xfree (buf);
1088 }
1089 else if (single)
1090 {
1091 raw_cursor_to (vpos, 0);
1092 background_highlight (tty);
1093 while (--i >= 0)
1094 OUTPUT (tty, single);
1095 if (tty->TF_teleray)
1096 curX (tty) = 0;
1097 }
1224 else 1098 else
1225 raw_cursor_to (vpos, 0); 1099 {
1226 background_highlight (); 1100 set_scroll_region (vpos, tty->specified_window);
1227 while (--i >= 0) 1101 if (n < 0)
1228 OUTPUTL (tty, scroll, specified_window - vpos); 1102 raw_cursor_to (tty->specified_window - 1, 0);
1229 set_scroll_region (0, specified_window); 1103 else
1230 } 1104 raw_cursor_to (vpos, 0);
1231 1105 background_highlight (tty);
1232 if (!TTY_SCROLL_REGION_OK (tty) 1106 while (--i >= 0)
1233 && TTY_MEMORY_BELOW_FRAME (tty) 1107 OUTPUTL (tty, scroll, tty->specified_window - vpos);
1234 && n < 0) 1108 set_scroll_region (0, tty->specified_window);
1235 { 1109 }
1236 cursor_to (FRAME_LINES (f) + n, 0); 1110
1237 clear_to_end (); 1111 if (!TTY_SCROLL_REGION_OK (tty)
1112 && TTY_MEMORY_BELOW_FRAME (tty)
1113 && n < 0)
1114 {
1115 cursor_to (FRAME_LINES (f) + n, 0);
1116 clear_to_end ();
1117 }
1238 } 1118 }
1239} 1119}
1240 1120
@@ -1292,26 +1172,27 @@ int *char_ins_del_vector;
1292 1172
1293/* ARGSUSED */ 1173/* ARGSUSED */
1294static void 1174static void
1295calculate_ins_del_char_costs (frame) 1175calculate_ins_del_char_costs (f)
1296 FRAME_PTR frame; 1176 FRAME_PTR f;
1297{ 1177{
1178 struct tty_output *tty = FRAME_TTY (f);
1298 int ins_startup_cost, del_startup_cost; 1179 int ins_startup_cost, del_startup_cost;
1299 int ins_cost_per_char, del_cost_per_char; 1180 int ins_cost_per_char, del_cost_per_char;
1300 register int i; 1181 register int i;
1301 register int *p; 1182 register int *p;
1302 1183
1303 if (TS_ins_multi_chars) 1184 if (tty->TS_ins_multi_chars)
1304 { 1185 {
1305 ins_cost_per_char = 0; 1186 ins_cost_per_char = 0;
1306 ins_startup_cost = string_cost_one_line (TS_ins_multi_chars); 1187 ins_startup_cost = string_cost_one_line (tty->TS_ins_multi_chars);
1307 } 1188 }
1308 else if (TS_ins_char || TS_pad_inserted_char 1189 else if (tty->TS_ins_char || tty->TS_pad_inserted_char
1309 || (TS_insert_mode && TS_end_insert_mode)) 1190 || (tty->TS_insert_mode && tty->TS_end_insert_mode))
1310 { 1191 {
1311 ins_startup_cost = (30 * (string_cost (TS_insert_mode) 1192 ins_startup_cost = (30 * (string_cost (tty->TS_insert_mode)
1312 + string_cost (TS_end_insert_mode))) / 100; 1193 + string_cost (tty->TS_end_insert_mode))) / 100;
1313 ins_cost_per_char = (string_cost_one_line (TS_ins_char) 1194 ins_cost_per_char = (string_cost_one_line (tty->TS_ins_char)
1314 + string_cost_one_line (TS_pad_inserted_char)); 1195 + string_cost_one_line (tty->TS_pad_inserted_char));
1315 } 1196 }
1316 else 1197 else
1317 { 1198 {
@@ -1319,18 +1200,18 @@ calculate_ins_del_char_costs (frame)
1319 ins_cost_per_char = 0; 1200 ins_cost_per_char = 0;
1320 } 1201 }
1321 1202
1322 if (TS_del_multi_chars) 1203 if (tty->TS_del_multi_chars)
1323 { 1204 {
1324 del_cost_per_char = 0; 1205 del_cost_per_char = 0;
1325 del_startup_cost = string_cost_one_line (TS_del_multi_chars); 1206 del_startup_cost = string_cost_one_line (tty->TS_del_multi_chars);
1326 } 1207 }
1327 else if (TS_del_char) 1208 else if (tty->TS_del_char)
1328 { 1209 {
1329 del_startup_cost = (string_cost (TS_delete_mode) 1210 del_startup_cost = (string_cost (tty->TS_delete_mode)
1330 + string_cost (TS_end_delete_mode)); 1211 + string_cost (tty->TS_end_delete_mode));
1331 if (delete_in_insert_mode) 1212 if (tty->delete_in_insert_mode)
1332 del_startup_cost /= 2; 1213 del_startup_cost /= 2;
1333 del_cost_per_char = string_cost_one_line (TS_del_char); 1214 del_cost_per_char = string_cost_one_line (tty->TS_del_char);
1334 } 1215 }
1335 else 1216 else
1336 { 1217 {
@@ -1339,16 +1220,16 @@ calculate_ins_del_char_costs (frame)
1339 } 1220 }
1340 1221
1341 /* Delete costs are at negative offsets */ 1222 /* Delete costs are at negative offsets */
1342 p = &char_ins_del_cost (frame)[0]; 1223 p = &char_ins_del_cost (f)[0];
1343 for (i = FRAME_COLS (frame); --i >= 0;) 1224 for (i = FRAME_COLS (f); --i >= 0;)
1344 *--p = (del_startup_cost += del_cost_per_char); 1225 *--p = (del_startup_cost += del_cost_per_char);
1345 1226
1346 /* Doing nothing is free */ 1227 /* Doing nothing is free */
1347 p = &char_ins_del_cost (frame)[0]; 1228 p = &char_ins_del_cost (f)[0];
1348 *p++ = 0; 1229 *p++ = 0;
1349 1230
1350 /* Insert costs are at positive offsets */ 1231 /* Insert costs are at positive offsets */
1351 for (i = FRAME_COLS (frame); --i >= 0;) 1232 for (i = FRAME_COLS (f); --i >= 0;)
1352 *p++ = (ins_startup_cost += ins_cost_per_char); 1233 *p++ = (ins_startup_cost += ins_cost_per_char);
1353} 1234}
1354 1235
@@ -1356,9 +1237,10 @@ void
1356calculate_costs (frame) 1237calculate_costs (frame)
1357 FRAME_PTR frame; 1238 FRAME_PTR frame;
1358{ 1239{
1359 register char *f = (TS_set_scroll_region 1240 struct tty_output *tty = FRAME_TTY (frame);
1360 ? TS_set_scroll_region 1241 register char *f = (tty->TS_set_scroll_region
1361 : TS_set_scroll_region_1); 1242 ? tty->TS_set_scroll_region
1243 : tty->TS_set_scroll_region_1);
1362 1244
1363 FRAME_COST_BAUD_RATE (frame) = baud_rate; 1245 FRAME_COST_BAUD_RATE (frame) = baud_rate;
1364 1246
@@ -1374,7 +1256,7 @@ calculate_costs (frame)
1374 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame)); 1256 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
1375 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); 1257 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
1376 1258
1377 costs_set = 1; 1259 tty->costs_set = 1;
1378 1260
1379 if (char_ins_del_vector != 0) 1261 if (char_ins_del_vector != 0)
1380 char_ins_del_vector 1262 char_ins_del_vector
@@ -1389,24 +1271,24 @@ calculate_costs (frame)
1389 bzero (char_ins_del_vector, (sizeof (int) 1271 bzero (char_ins_del_vector, (sizeof (int)
1390 + 2 * max_frame_cols * sizeof (int))); 1272 + 2 * max_frame_cols * sizeof (int)));
1391 1273
1392 if (f && (!TS_ins_line && !TS_del_line)) 1274 if (f && (!tty->TS_ins_line && !tty->TS_del_line))
1393 do_line_insertion_deletion_costs (frame, 1275 do_line_insertion_deletion_costs (frame,
1394 TS_rev_scroll, TS_ins_multi_lines, 1276 tty->TS_rev_scroll, tty->TS_ins_multi_lines,
1395 TS_fwd_scroll, TS_del_multi_lines, 1277 tty->TS_fwd_scroll, tty->TS_del_multi_lines,
1396 f, f, 1); 1278 f, f, 1);
1397 else 1279 else
1398 do_line_insertion_deletion_costs (frame, 1280 do_line_insertion_deletion_costs (frame,
1399 TS_ins_line, TS_ins_multi_lines, 1281 tty->TS_ins_line, tty->TS_ins_multi_lines,
1400 TS_del_line, TS_del_multi_lines, 1282 tty->TS_del_line, tty->TS_del_multi_lines,
1401 0, 0, 1); 1283 0, 0, 1);
1402 1284
1403 calculate_ins_del_char_costs (frame); 1285 calculate_ins_del_char_costs (frame);
1404 1286
1405 /* Don't use TS_repeat if its padding is worse than sending the chars */ 1287 /* Don't use TS_repeat if its padding is worse than sending the chars */
1406 if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000) 1288 if (tty->TS_repeat && per_line_cost (tty->TS_repeat) * baud_rate < 9000)
1407 RPov = string_cost (TS_repeat); 1289 tty->RPov = string_cost (tty->TS_repeat);
1408 else 1290 else
1409 RPov = FRAME_COLS (frame) * 2; 1291 tty->RPov = FRAME_COLS (frame) * 2;
1410 1292
1411 cmcostinit (FRAME_TTY (frame)); /* set up cursor motion costs */ 1293 cmcostinit (FRAME_TTY (frame)); /* set up cursor motion costs */
1412} 1294}
@@ -1858,10 +1740,10 @@ produce_special_glyphs (it, what)
1858 from them. Some display attributes may not be used together with 1740 from them. Some display attributes may not be used together with
1859 color; the termcap capability `NC' specifies which ones. */ 1741 color; the termcap capability `NC' specifies which ones. */
1860 1742
1861#define MAY_USE_WITH_COLORS_P(ATTR) \ 1743#define MAY_USE_WITH_COLORS_P(tty, ATTR) \
1862 (TN_max_colors > 0 \ 1744 (tty->TN_max_colors > 0 \
1863 ? (TN_no_color_video & (ATTR)) == 0 \ 1745 ? (tty->TN_no_color_video & (ATTR)) == 0 \
1864 : 1) 1746 : 1)
1865 1747
1866/* Turn appearances of face FACE_ID on tty frame F on. */ 1748/* Turn appearances of face FACE_ID on tty frame F on. */
1867 1749
@@ -1877,9 +1759,9 @@ turn_on_face (f, face_id)
1877 1759
1878 /* Do this first because TS_end_standout_mode may be the same 1760 /* Do this first because TS_end_standout_mode may be the same
1879 as TS_exit_attribute_mode, which turns all appearances off. */ 1761 as TS_exit_attribute_mode, which turns all appearances off. */
1880 if (MAY_USE_WITH_COLORS_P (NC_REVERSE)) 1762 if (MAY_USE_WITH_COLORS_P (tty, NC_REVERSE))
1881 { 1763 {
1882 if (TN_max_colors > 0) 1764 if (tty->TN_max_colors > 0)
1883 { 1765 {
1884 if (fg >= 0 && bg >= 0) 1766 if (fg >= 0 && bg >= 0)
1885 { 1767 {
@@ -1893,13 +1775,13 @@ turn_on_face (f, face_id)
1893 { 1775 {
1894 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1776 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1895 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1777 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1896 toggle_highlight (); 1778 toggle_highlight (tty);
1897 } 1779 }
1898 else 1780 else
1899 { 1781 {
1900 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1782 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1901 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1783 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1902 toggle_highlight (); 1784 toggle_highlight (tty);
1903 } 1785 }
1904 } 1786 }
1905 else 1787 else
@@ -1910,52 +1792,52 @@ turn_on_face (f, face_id)
1910 { 1792 {
1911 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1793 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1912 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1794 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1913 toggle_highlight (); 1795 toggle_highlight (tty);
1914 } 1796 }
1915 else 1797 else
1916 { 1798 {
1917 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1799 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1918 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1800 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1919 toggle_highlight (); 1801 toggle_highlight (tty);
1920 } 1802 }
1921 } 1803 }
1922 } 1804 }
1923 1805
1924 if (face->tty_bold_p) 1806 if (face->tty_bold_p)
1925 { 1807 {
1926 if (MAY_USE_WITH_COLORS_P (NC_BOLD)) 1808 if (MAY_USE_WITH_COLORS_P (tty, NC_BOLD))
1927 OUTPUT1_IF (tty, TS_enter_bold_mode); 1809 OUTPUT1_IF (tty, tty->TS_enter_bold_mode);
1928 } 1810 }
1929 else if (face->tty_dim_p) 1811 else if (face->tty_dim_p)
1930 if (MAY_USE_WITH_COLORS_P (NC_DIM)) 1812 if (MAY_USE_WITH_COLORS_P (tty, NC_DIM))
1931 OUTPUT1_IF (tty, TS_enter_dim_mode); 1813 OUTPUT1_IF (tty, tty->TS_enter_dim_mode);
1932 1814
1933 /* Alternate charset and blinking not yet used. */ 1815 /* Alternate charset and blinking not yet used. */
1934 if (face->tty_alt_charset_p 1816 if (face->tty_alt_charset_p
1935 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET)) 1817 && MAY_USE_WITH_COLORS_P (tty, NC_ALT_CHARSET))
1936 OUTPUT1_IF (tty, TS_enter_alt_charset_mode); 1818 OUTPUT1_IF (tty, tty->TS_enter_alt_charset_mode);
1937 1819
1938 if (face->tty_blinking_p 1820 if (face->tty_blinking_p
1939 && MAY_USE_WITH_COLORS_P (NC_BLINK)) 1821 && MAY_USE_WITH_COLORS_P (tty, NC_BLINK))
1940 OUTPUT1_IF (tty, TS_enter_blink_mode); 1822 OUTPUT1_IF (tty, tty->TS_enter_blink_mode);
1941 1823
1942 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE)) 1824 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (tty, NC_UNDERLINE))
1943 OUTPUT1_IF (tty, TS_enter_underline_mode); 1825 OUTPUT1_IF (tty, tty->TS_enter_underline_mode);
1944 1826
1945 if (TN_max_colors > 0) 1827 if (tty->TN_max_colors > 0)
1946 { 1828 {
1947 char *p; 1829 char *p;
1948 1830
1949 if (fg >= 0 && TS_set_foreground) 1831 if (fg >= 0 && tty->TS_set_foreground)
1950 { 1832 {
1951 p = tparam (TS_set_foreground, NULL, 0, (int) fg); 1833 p = tparam (tty->TS_set_foreground, NULL, 0, (int) fg);
1952 OUTPUT (tty, p); 1834 OUTPUT (tty, p);
1953 xfree (p); 1835 xfree (p);
1954 } 1836 }
1955 1837
1956 if (bg >= 0 && TS_set_background) 1838 if (bg >= 0 && tty->TS_set_background)
1957 { 1839 {
1958 p = tparam (TS_set_background, NULL, 0, (int) bg); 1840 p = tparam (tty->TS_set_background, NULL, 0, (int) bg);
1959 OUTPUT (tty, p); 1841 OUTPUT (tty, p);
1960 xfree (p); 1842 xfree (p);
1961 } 1843 }
@@ -1975,7 +1857,7 @@ turn_off_face (f, face_id)
1975 1857
1976 xassert (face != NULL); 1858 xassert (face != NULL);
1977 1859
1978 if (TS_exit_attribute_mode) 1860 if (tty->TS_exit_attribute_mode)
1979 { 1861 {
1980 /* Capability "me" will turn off appearance modes double-bright, 1862 /* Capability "me" will turn off appearance modes double-bright,
1981 half-bright, reverse-video, standout, underline. It may or 1863 half-bright, reverse-video, standout, underline. It may or
@@ -1987,32 +1869,32 @@ turn_off_face (f, face_id)
1987 || face->tty_blinking_p 1869 || face->tty_blinking_p
1988 || face->tty_underline_p) 1870 || face->tty_underline_p)
1989 { 1871 {
1990 OUTPUT1_IF (tty, TS_exit_attribute_mode); 1872 OUTPUT1_IF (tty, tty->TS_exit_attribute_mode);
1991 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0) 1873 if (strcmp (tty->TS_exit_attribute_mode, tty->TS_end_standout_mode) == 0)
1992 standout_mode = 0; 1874 tty->standout_mode = 0;
1993 } 1875 }
1994 1876
1995 if (face->tty_alt_charset_p) 1877 if (face->tty_alt_charset_p)
1996 OUTPUT_IF (tty, TS_exit_alt_charset_mode); 1878 OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode);
1997 } 1879 }
1998 else 1880 else
1999 { 1881 {
2000 /* If we don't have "me" we can only have those appearances 1882 /* If we don't have "me" we can only have those appearances
2001 that have exit sequences defined. */ 1883 that have exit sequences defined. */
2002 if (face->tty_alt_charset_p) 1884 if (face->tty_alt_charset_p)
2003 OUTPUT_IF (tty, TS_exit_alt_charset_mode); 1885 OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode);
2004 1886
2005 if (face->tty_underline_p) 1887 if (face->tty_underline_p)
2006 OUTPUT_IF (tty, TS_exit_underline_mode); 1888 OUTPUT_IF (tty, tty->TS_exit_underline_mode);
2007 } 1889 }
2008 1890
2009 /* Switch back to default colors. */ 1891 /* Switch back to default colors. */
2010 if (TN_max_colors > 0 1892 if (tty->TN_max_colors > 0
2011 && ((face->foreground != FACE_TTY_DEFAULT_COLOR 1893 && ((face->foreground != FACE_TTY_DEFAULT_COLOR
2012 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR) 1894 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
2013 || (face->background != FACE_TTY_DEFAULT_COLOR 1895 || (face->background != FACE_TTY_DEFAULT_COLOR
2014 && face->background != FACE_TTY_DEFAULT_BG_COLOR))) 1896 && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
2015 OUTPUT1_IF (tty, TS_orig_pair); 1897 OUTPUT1_IF (tty, tty->TS_orig_pair);
2016} 1898}
2017 1899
2018 1900
@@ -2021,21 +1903,21 @@ turn_off_face (f, face_id)
2021 colors FG and BG. */ 1903 colors FG and BG. */
2022 1904
2023int 1905int
2024tty_capable_p (f, caps, fg, bg) 1906tty_capable_p (tty, caps, fg, bg)
2025 struct frame *f; 1907 struct tty_output *tty;
2026 unsigned caps; 1908 unsigned caps;
2027 unsigned long fg, bg; 1909 unsigned long fg, bg;
2028{ 1910{
2029#define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \ 1911#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2030 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \ 1912 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
2031 return 0; 1913 return 0;
2032 1914
2033 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE); 1915 TTY_CAPABLE_P_TRY (tty, TTY_CAP_INVERSE, tty->TS_standout_mode, NC_REVERSE);
2034 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE); 1916 TTY_CAPABLE_P_TRY (tty, TTY_CAP_UNDERLINE, tty->TS_enter_underline_mode, NC_UNDERLINE);
2035 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD); 1917 TTY_CAPABLE_P_TRY (tty, TTY_CAP_BOLD, tty->TS_enter_bold_mode, NC_BOLD);
2036 TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM); 1918 TTY_CAPABLE_P_TRY (tty, TTY_CAP_DIM, tty->TS_enter_dim_mode, NC_DIM);
2037 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK); 1919 TTY_CAPABLE_P_TRY (tty, TTY_CAP_BLINK, tty->TS_enter_blink_mode, NC_BLINK);
2038 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET); 1920 TTY_CAPABLE_P_TRY (tty, TTY_CAP_ALT_CHARSET, tty->TS_enter_alt_charset_mode, NC_ALT_CHARSET);
2039 1921
2040 /* We can do it! */ 1922 /* We can do it! */
2041 return 1; 1923 return 1;
@@ -2050,7 +1932,8 @@ DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
2050 (display) 1932 (display)
2051 Lisp_Object display; 1933 Lisp_Object display;
2052{ 1934{
2053 return TN_max_colors > 0 ? Qt : Qnil; 1935 struct tty_output *tty = FRAME_TTY (SELECTED_FRAME ());
1936 return tty->TN_max_colors > 0 ? Qt : Qnil;
2054} 1937}
2055 1938
2056/* Return the number of supported colors. */ 1939/* Return the number of supported colors. */
@@ -2060,7 +1943,8 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2060 (display) 1943 (display)
2061 Lisp_Object display; 1944 Lisp_Object display;
2062{ 1945{
2063 return make_number (TN_max_colors); 1946 struct tty_output *tty = FRAME_TTY (SELECTED_FRAME ());
1947 return make_number (tty->TN_max_colors);
2064} 1948}
2065 1949
2066#ifndef WINDOWSNT 1950#ifndef WINDOWSNT
@@ -2068,8 +1952,7 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2068/* Save or restore the default color-related capabilities of this 1952/* Save or restore the default color-related capabilities of this
2069 terminal. */ 1953 terminal. */
2070static void 1954static void
2071tty_default_color_capabilities (save) 1955tty_default_color_capabilities (struct tty_output *tty, int save)
2072 int save;
2073{ 1956{
2074 static char 1957 static char
2075 *default_orig_pair, *default_set_foreground, *default_set_background; 1958 *default_orig_pair, *default_set_foreground, *default_set_background;
@@ -2079,30 +1962,30 @@ tty_default_color_capabilities (save)
2079 { 1962 {
2080 if (default_orig_pair) 1963 if (default_orig_pair)
2081 xfree (default_orig_pair); 1964 xfree (default_orig_pair);
2082 default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL; 1965 default_orig_pair = tty->TS_orig_pair ? xstrdup (tty->TS_orig_pair) : NULL;
2083 1966
2084 if (default_set_foreground) 1967 if (default_set_foreground)
2085 xfree (default_set_foreground); 1968 xfree (default_set_foreground);
2086 default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground) 1969 default_set_foreground = tty->TS_set_foreground ? xstrdup (tty->TS_set_foreground)
2087 : NULL; 1970 : NULL;
2088 1971
2089 if (default_set_background) 1972 if (default_set_background)
2090 xfree (default_set_background); 1973 xfree (default_set_background);
2091 default_set_background = TS_set_background ? xstrdup (TS_set_background) 1974 default_set_background = tty->TS_set_background ? xstrdup (tty->TS_set_background)
2092 : NULL; 1975 : NULL;
2093 1976
2094 default_max_colors = TN_max_colors; 1977 default_max_colors = tty->TN_max_colors;
2095 default_max_pairs = TN_max_pairs; 1978 default_max_pairs = tty->TN_max_pairs;
2096 default_no_color_video = TN_no_color_video; 1979 default_no_color_video = tty->TN_no_color_video;
2097 } 1980 }
2098 else 1981 else
2099 { 1982 {
2100 TS_orig_pair = default_orig_pair; 1983 tty->TS_orig_pair = default_orig_pair;
2101 TS_set_foreground = default_set_foreground; 1984 tty->TS_set_foreground = default_set_foreground;
2102 TS_set_background = default_set_background; 1985 tty->TS_set_background = default_set_background;
2103 TN_max_colors = default_max_colors; 1986 tty->TN_max_colors = default_max_colors;
2104 TN_max_pairs = default_max_pairs; 1987 tty->TN_max_pairs = default_max_pairs;
2105 TN_no_color_video = default_no_color_video; 1988 tty->TN_no_color_video = default_no_color_video;
2106 } 1989 }
2107} 1990}
2108 1991
@@ -2111,8 +1994,7 @@ tty_default_color_capabilities (save)
2111 support; zero means set up for the default capabilities, the ones 1994 support; zero means set up for the default capabilities, the ones
2112 we saw at term_init time; -1 means turn off color support. */ 1995 we saw at term_init time; -1 means turn off color support. */
2113void 1996void
2114tty_setup_colors (mode) 1997tty_setup_colors (struct tty_output *tty, int mode)
2115 int mode;
2116{ 1998{
2117 /* Canonicalize all negative values of MODE. */ 1999 /* Canonicalize all negative values of MODE. */
2118 if (mode < -1) 2000 if (mode < -1)
@@ -2121,27 +2003,27 @@ tty_setup_colors (mode)
2121 switch (mode) 2003 switch (mode)
2122 { 2004 {
2123 case -1: /* no colors at all */ 2005 case -1: /* no colors at all */
2124 TN_max_colors = 0; 2006 tty->TN_max_colors = 0;
2125 TN_max_pairs = 0; 2007 tty->TN_max_pairs = 0;
2126 TN_no_color_video = 0; 2008 tty->TN_no_color_video = 0;
2127 TS_set_foreground = TS_set_background = TS_orig_pair = NULL; 2009 tty->TS_set_foreground = tty->TS_set_background = tty->TS_orig_pair = NULL;
2128 break; 2010 break;
2129 case 0: /* default colors, if any */ 2011 case 0: /* default colors, if any */
2130 default: 2012 default:
2131 tty_default_color_capabilities (0); 2013 tty_default_color_capabilities (tty, 0);
2132 break; 2014 break;
2133 case 8: /* 8 standard ANSI colors */ 2015 case 8: /* 8 standard ANSI colors */
2134 TS_orig_pair = "\033[0m"; 2016 tty->TS_orig_pair = "\033[0m";
2135#ifdef TERMINFO 2017#ifdef TERMINFO
2136 TS_set_foreground = "\033[3%p1%dm"; 2018 tty->TS_set_foreground = "\033[3%p1%dm";
2137 TS_set_background = "\033[4%p1%dm"; 2019 tty->TS_set_background = "\033[4%p1%dm";
2138#else 2020#else
2139 TS_set_foreground = "\033[3%dm"; 2021 tty->TS_set_foreground = "\033[3%dm";
2140 TS_set_background = "\033[4%dm"; 2022 tty->TS_set_background = "\033[4%dm";
2141#endif 2023#endif
2142 TN_max_colors = 8; 2024 tty->TN_max_colors = 8;
2143 TN_max_pairs = 64; 2025 tty->TN_max_pairs = 64;
2144 TN_no_color_video = 0; 2026 tty->TN_no_color_video = 0;
2145 break; 2027 break;
2146 } 2028 }
2147} 2029}
@@ -2192,7 +2074,7 @@ set_tty_color_mode (f, val)
2192 2074
2193 if (mode != old_mode) 2075 if (mode != old_mode)
2194 { 2076 {
2195 tty_setup_colors (mode); 2077 tty_setup_colors (FRAME_TTY (f), mode);
2196 /* This recomputes all the faces given the new color 2078 /* This recomputes all the faces given the new color
2197 definitions. */ 2079 definitions. */
2198 call0 (intern ("tty-set-up-initial-frame-faces")); 2080 call0 (intern ("tty-set-up-initial-frame-faces"));
@@ -2262,12 +2144,12 @@ term_init (name, terminal_type)
2262 terminal created for the initial frame. */ 2144 terminal created for the initial frame. */
2263 if (tty->type) 2145 if (tty->type)
2264 return tty; 2146 return tty;
2147
2148 /* In the latter case, initialize top_frame to the current terminal. */
2149 tty->top_frame = selected_frame;
2265 } 2150 }
2266 else 2151 else
2267 { 2152 {
2268 if (!terminal_type)
2269 error ("Unknown terminal type");
2270
2271 tty = (struct tty_output *) xmalloc (sizeof (struct tty_output)); 2153 tty = (struct tty_output *) xmalloc (sizeof (struct tty_output));
2272 bzero (tty, sizeof (struct tty_output)); 2154 bzero (tty, sizeof (struct tty_output));
2273 tty->next = tty_list; 2155 tty->next = tty_list;
@@ -2275,8 +2157,9 @@ term_init (name, terminal_type)
2275 } 2157 }
2276 2158
2277 if (tty->Wcm) 2159 if (tty->Wcm)
2278 xfree (tty->Wcm); 2160 Wcm_clear (tty);
2279 tty->Wcm = (struct cm *) xmalloc (sizeof (struct cm)); 2161 else
2162 tty->Wcm = (struct cm *) xmalloc (sizeof (struct cm));
2280 2163
2281 if (name) 2164 if (name)
2282 { 2165 {
@@ -2287,7 +2170,7 @@ term_init (name, terminal_type)
2287 { 2170 {
2288 tty_list = tty->next; 2171 tty_list = tty->next;
2289 xfree (tty); 2172 xfree (tty);
2290 error ("could not open file: %s", name); 2173 error ("Could not open file: %s", name);
2291 } 2174 }
2292 f = fdopen (fd, "w+"); 2175 f = fdopen (fd, "w+");
2293 TTY_NAME (tty) = xstrdup (name); 2176 TTY_NAME (tty) = xstrdup (name);
@@ -2301,12 +2184,14 @@ term_init (name, terminal_type)
2301 TTY_OUTPUT (tty) = stdout; 2184 TTY_OUTPUT (tty) = stdout;
2302 } 2185 }
2303 2186
2304 init_sys_modes (tty); 2187 TTY_TYPE (tty) = xstrdup (terminal_type);
2305 2188
2189 init_sys_modes (tty);
2190
2306#ifdef WINDOWSNT 2191#ifdef WINDOWSNT
2307 initialize_w32_display (); 2192 initialize_w32_display ();
2308 2193
2309 Wcm_clear (); 2194 Wcm_clear (tty);
2310 2195
2311 area = (char *) xmalloc (2044); 2196 area = (char *) xmalloc (2044);
2312 2197
@@ -2338,34 +2223,56 @@ term_init (name, terminal_type)
2338 2223
2339 Wcm_clear (tty); 2224 Wcm_clear (tty);
2340 2225
2341 TTY_TYPE (tty) = xstrdup (terminal_type);
2342
2343 buffer = (char *) xmalloc (buffer_size); 2226 buffer = (char *) xmalloc (buffer_size);
2344 status = tgetent (buffer, terminal_type); 2227 status = tgetent (buffer, terminal_type);
2345 if (status < 0) 2228 if (status < 0)
2346 { 2229 {
2347#ifdef TERMINFO 2230#ifdef TERMINFO
2348 fatal ("Cannot open terminfo database file"); 2231 if (name)
2232 {
2233 delete_tty (tty);
2234 error ("Cannot open terminfo database file");
2235 }
2236 else
2237 fatal ("Cannot open terminfo database file");
2349#else 2238#else
2350 fatal ("Cannot open termcap database file"); 2239 if (name)
2240 {
2241 delete_tty (tty);
2242 error ("Cannot open termcap database file");
2243 }
2244 else
2245 fatal ("Cannot open termcap database file");
2351#endif 2246#endif
2352 } 2247 }
2353 if (status == 0) 2248 if (status == 0)
2354 { 2249 {
2355#ifdef TERMINFO 2250#ifdef TERMINFO
2356 fatal ("Terminal type %s is not defined.\n\ 2251 if (name)
2357If that is not the actual type of terminal you have,\n\ 2252 {
2253 delete_tty (tty);
2254 error ("Terminal type %s is not defined", terminal_type);
2255 }
2256 else
2257 fatal ("Terminal type %s is not defined.\n\
2258If that is not the actual type of terminal you have,\n \
2358use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2259use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2359`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2260`setenv TERM ...') to specify the correct type. It may be necessary\n\
2360to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 2261to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2361 terminal_type); 2262 terminal_type);
2362#else 2263#else
2363 fatal ("Terminal type %s is not defined.\n\ 2264 if (name)
2364If that is not the actual type of terminal you have,\n\ 2265 {
2266 delete_tty (tty);
2267 error ("Terminal type %s is not defined", terminal_type);
2268 }
2269 else
2270 fatal ("Terminal type %s is not defined.\n\
2271If that is not the actual type of terminal you have,\n \
2365use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2272use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2366`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2273`setenv TERM ...') to specify the correct type. It may be necessary\n\
2367to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 2274to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2368 terminal_type); 2275 terminal_type);
2369#endif 2276#endif
2370 } 2277 }
2371 2278
@@ -2376,33 +2283,33 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2376#endif 2283#endif
2377 area = (char *) xmalloc (buffer_size); 2284 area = (char *) xmalloc (buffer_size);
2378 2285
2379 TS_ins_line = tgetstr ("al", address); 2286 tty->TS_ins_line = tgetstr ("al", address);
2380 TS_ins_multi_lines = tgetstr ("AL", address); 2287 tty->TS_ins_multi_lines = tgetstr ("AL", address);
2381 TS_bell = tgetstr ("bl", address); 2288 tty->TS_bell = tgetstr ("bl", address);
2382 BackTab (tty) = tgetstr ("bt", address); 2289 BackTab (tty) = tgetstr ("bt", address);
2383 TS_clr_to_bottom = tgetstr ("cd", address); 2290 tty->TS_clr_to_bottom = tgetstr ("cd", address);
2384 TS_clr_line = tgetstr ("ce", address); 2291 tty->TS_clr_line = tgetstr ("ce", address);
2385 TS_clr_frame = tgetstr ("cl", address); 2292 tty->TS_clr_frame = tgetstr ("cl", address);
2386 ColPosition (tty) = NULL; /* tgetstr ("ch", address); */ 2293 ColPosition (tty) = NULL; /* tgetstr ("ch", address); */
2387 AbsPosition (tty) = tgetstr ("cm", address); 2294 AbsPosition (tty) = tgetstr ("cm", address);
2388 CR (tty) = tgetstr ("cr", address); 2295 CR (tty) = tgetstr ("cr", address);
2389 TS_set_scroll_region = tgetstr ("cs", address); 2296 tty->TS_set_scroll_region = tgetstr ("cs", address);
2390 TS_set_scroll_region_1 = tgetstr ("cS", address); 2297 tty->TS_set_scroll_region_1 = tgetstr ("cS", address);
2391 RowPosition (tty) = tgetstr ("cv", address); 2298 RowPosition (tty) = tgetstr ("cv", address);
2392 TS_del_char = tgetstr ("dc", address); 2299 tty->TS_del_char = tgetstr ("dc", address);
2393 TS_del_multi_chars = tgetstr ("DC", address); 2300 tty->TS_del_multi_chars = tgetstr ("DC", address);
2394 TS_del_line = tgetstr ("dl", address); 2301 tty->TS_del_line = tgetstr ("dl", address);
2395 TS_del_multi_lines = tgetstr ("DL", address); 2302 tty->TS_del_multi_lines = tgetstr ("DL", address);
2396 TS_delete_mode = tgetstr ("dm", address); 2303 tty->TS_delete_mode = tgetstr ("dm", address);
2397 TS_end_delete_mode = tgetstr ("ed", address); 2304 tty->TS_end_delete_mode = tgetstr ("ed", address);
2398 TS_end_insert_mode = tgetstr ("ei", address); 2305 tty->TS_end_insert_mode = tgetstr ("ei", address);
2399 Home (tty) = tgetstr ("ho", address); 2306 Home (tty) = tgetstr ("ho", address);
2400 TS_ins_char = tgetstr ("ic", address); 2307 tty->TS_ins_char = tgetstr ("ic", address);
2401 TS_ins_multi_chars = tgetstr ("IC", address); 2308 tty->TS_ins_multi_chars = tgetstr ("IC", address);
2402 TS_insert_mode = tgetstr ("im", address); 2309 tty->TS_insert_mode = tgetstr ("im", address);
2403 TS_pad_inserted_char = tgetstr ("ip", address); 2310 tty->TS_pad_inserted_char = tgetstr ("ip", address);
2404 TS_end_keypad_mode = tgetstr ("ke", address); 2311 tty->TS_end_keypad_mode = tgetstr ("ke", address);
2405 TS_keypad_mode = tgetstr ("ks", address); 2312 tty->TS_keypad_mode = tgetstr ("ks", address);
2406 LastLine (tty) = tgetstr ("ll", address); 2313 LastLine (tty) = tgetstr ("ll", address);
2407 Right (tty) = tgetstr ("nd", address); 2314 Right (tty) = tgetstr ("nd", address);
2408 Down (tty) = tgetstr ("do", address); 2315 Down (tty) = tgetstr ("do", address);
@@ -2420,31 +2327,31 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2420 Left (tty) = tgetstr ("le", address); 2327 Left (tty) = tgetstr ("le", address);
2421 if (!Left (tty)) 2328 if (!Left (tty))
2422 Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le" */ 2329 Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le" */
2423 TS_pad_char = tgetstr ("pc", address); 2330 tty->TS_pad_char = tgetstr ("pc", address);
2424 TS_repeat = tgetstr ("rp", address); 2331 tty->TS_repeat = tgetstr ("rp", address);
2425 TS_end_standout_mode = tgetstr ("se", address); 2332 tty->TS_end_standout_mode = tgetstr ("se", address);
2426 TS_fwd_scroll = tgetstr ("sf", address); 2333 tty->TS_fwd_scroll = tgetstr ("sf", address);
2427 TS_standout_mode = tgetstr ("so", address); 2334 tty->TS_standout_mode = tgetstr ("so", address);
2428 TS_rev_scroll = tgetstr ("sr", address); 2335 tty->TS_rev_scroll = tgetstr ("sr", address);
2429 tty->Wcm->cm_tab = tgetstr ("ta", address); 2336 tty->Wcm->cm_tab = tgetstr ("ta", address);
2430 TS_end_termcap_modes = tgetstr ("te", address); 2337 tty->TS_end_termcap_modes = tgetstr ("te", address);
2431 TS_termcap_modes = tgetstr ("ti", address); 2338 tty->TS_termcap_modes = tgetstr ("ti", address);
2432 Up (tty) = tgetstr ("up", address); 2339 Up (tty) = tgetstr ("up", address);
2433 TS_visible_bell = tgetstr ("vb", address); 2340 tty->TS_visible_bell = tgetstr ("vb", address);
2434 TS_cursor_normal = tgetstr ("ve", address); 2341 tty->TS_cursor_normal = tgetstr ("ve", address);
2435 TS_cursor_visible = tgetstr ("vs", address); 2342 tty->TS_cursor_visible = tgetstr ("vs", address);
2436 TS_cursor_invisible = tgetstr ("vi", address); 2343 tty->TS_cursor_invisible = tgetstr ("vi", address);
2437 TS_set_window = tgetstr ("wi", address); 2344 tty->TS_set_window = tgetstr ("wi", address);
2438 2345
2439 TS_enter_underline_mode = tgetstr ("us", address); 2346 tty->TS_enter_underline_mode = tgetstr ("us", address);
2440 TS_exit_underline_mode = tgetstr ("ue", address); 2347 tty->TS_exit_underline_mode = tgetstr ("ue", address);
2441 TS_enter_bold_mode = tgetstr ("md", address); 2348 tty->TS_enter_bold_mode = tgetstr ("md", address);
2442 TS_enter_dim_mode = tgetstr ("mh", address); 2349 tty->TS_enter_dim_mode = tgetstr ("mh", address);
2443 TS_enter_blink_mode = tgetstr ("mb", address); 2350 tty->TS_enter_blink_mode = tgetstr ("mb", address);
2444 TS_enter_reverse_mode = tgetstr ("mr", address); 2351 tty->TS_enter_reverse_mode = tgetstr ("mr", address);
2445 TS_enter_alt_charset_mode = tgetstr ("as", address); 2352 tty->TS_enter_alt_charset_mode = tgetstr ("as", address);
2446 TS_exit_alt_charset_mode = tgetstr ("ae", address); 2353 tty->TS_exit_alt_charset_mode = tgetstr ("ae", address);
2447 TS_exit_attribute_mode = tgetstr ("me", address); 2354 tty->TS_exit_attribute_mode = tgetstr ("me", address);
2448 2355
2449 MultiUp (tty) = tgetstr ("UP", address); 2356 MultiUp (tty) = tgetstr ("UP", address);
2450 MultiDown (tty) = tgetstr ("DO", address); 2357 MultiDown (tty) = tgetstr ("DO", address);
@@ -2454,40 +2361,40 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2454 /* SVr4/ANSI color suppert. If "op" isn't available, don't support 2361 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2455 color because we can't switch back to the default foreground and 2362 color because we can't switch back to the default foreground and
2456 background. */ 2363 background. */
2457 TS_orig_pair = tgetstr ("op", address); 2364 tty->TS_orig_pair = tgetstr ("op", address);
2458 if (TS_orig_pair) 2365 if (tty->TS_orig_pair)
2459 { 2366 {
2460 TS_set_foreground = tgetstr ("AF", address); 2367 tty->TS_set_foreground = tgetstr ("AF", address);
2461 TS_set_background = tgetstr ("AB", address); 2368 tty->TS_set_background = tgetstr ("AB", address);
2462 if (!TS_set_foreground) 2369 if (!tty->TS_set_foreground)
2463 { 2370 {
2464 /* SVr4. */ 2371 /* SVr4. */
2465 TS_set_foreground = tgetstr ("Sf", address); 2372 tty->TS_set_foreground = tgetstr ("Sf", address);
2466 TS_set_background = tgetstr ("Sb", address); 2373 tty->TS_set_background = tgetstr ("Sb", address);
2467 } 2374 }
2468 2375
2469 TN_max_colors = tgetnum ("Co"); 2376 tty->TN_max_colors = tgetnum ("Co");
2470 TN_max_pairs = tgetnum ("pa"); 2377 tty->TN_max_pairs = tgetnum ("pa");
2471 2378
2472 TN_no_color_video = tgetnum ("NC"); 2379 tty->TN_no_color_video = tgetnum ("NC");
2473 if (TN_no_color_video == -1) 2380 if (tty->TN_no_color_video == -1)
2474 TN_no_color_video = 0; 2381 tty->TN_no_color_video = 0;
2475 } 2382 }
2476 2383
2477 tty_default_color_capabilities (1); 2384 tty_default_color_capabilities (tty, 1);
2478 2385
2479 MagicWrap (tty) = tgetflag ("xn"); 2386 MagicWrap (tty) = tgetflag ("xn");
2480 /* Since we make MagicWrap terminals look like AutoWrap, we need to have 2387 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2481 the former flag imply the latter. */ 2388 the former flag imply the latter. */
2482 AutoWrap (tty) = MagicWrap (tty) || tgetflag ("am"); 2389 AutoWrap (tty) = MagicWrap (tty) || tgetflag ("am");
2483 TTY_MEMORY_BELOW_FRAME (tty) = tgetflag ("db"); 2390 TTY_MEMORY_BELOW_FRAME (tty) = tgetflag ("db");
2484 TF_hazeltine = tgetflag ("hz"); 2391 tty->TF_hazeltine = tgetflag ("hz");
2485 TTY_MUST_WRITE_SPACES (tty) = tgetflag ("in"); 2392 TTY_MUST_WRITE_SPACES (tty) = tgetflag ("in");
2486 meta_key = tgetflag ("km") || tgetflag ("MT"); 2393 tty->meta_key = tgetflag ("km") || tgetflag ("MT");
2487 TF_insmode_motion = tgetflag ("mi"); 2394 tty->TF_insmode_motion = tgetflag ("mi");
2488 TF_standout_motion = tgetflag ("ms"); 2395 tty->TF_standout_motion = tgetflag ("ms");
2489 TF_underscore = tgetflag ("ul"); 2396 tty->TF_underscore = tgetflag ("ul");
2490 TF_teleray = tgetflag ("xt"); 2397 tty->TF_teleray = tgetflag ("xt");
2491 2398
2492 term_get_fkeys (address); 2399 term_get_fkeys (address);
2493 2400
@@ -2526,13 +2433,13 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2526 Down (tty) = 0; 2433 Down (tty) = 0;
2527#endif /* VMS */ 2434#endif /* VMS */
2528 2435
2529 if (!TS_bell) 2436 if (!tty->TS_bell)
2530 TS_bell = "\07"; 2437 tty->TS_bell = "\07";
2531 2438
2532 if (!TS_fwd_scroll) 2439 if (!tty->TS_fwd_scroll)
2533 TS_fwd_scroll = Down (tty); 2440 tty->TS_fwd_scroll = Down (tty);
2534 2441
2535 PC = TS_pad_char ? *TS_pad_char : 0; 2442 PC = tty->TS_pad_char ? *tty->TS_pad_char : 0;
2536 2443
2537 if (TabWidth (tty) < 0) 2444 if (TabWidth (tty) < 0)
2538 TabWidth (tty) = 8; 2445 TabWidth (tty) = 8;
@@ -2545,40 +2452,40 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2545 2452
2546 /* We don't support standout modes that use `magic cookies', so 2453 /* We don't support standout modes that use `magic cookies', so
2547 turn off any that do. */ 2454 turn off any that do. */
2548 if (TS_standout_mode && tgetnum ("sg") >= 0) 2455 if (tty->TS_standout_mode && tgetnum ("sg") >= 0)
2549 { 2456 {
2550 TS_standout_mode = 0; 2457 tty->TS_standout_mode = 0;
2551 TS_end_standout_mode = 0; 2458 tty->TS_end_standout_mode = 0;
2552 } 2459 }
2553 if (TS_enter_underline_mode && tgetnum ("ug") >= 0) 2460 if (tty->TS_enter_underline_mode && tgetnum ("ug") >= 0)
2554 { 2461 {
2555 TS_enter_underline_mode = 0; 2462 tty->TS_enter_underline_mode = 0;
2556 TS_exit_underline_mode = 0; 2463 tty->TS_exit_underline_mode = 0;
2557 } 2464 }
2558 2465
2559 /* If there's no standout mode, try to use underlining instead. */ 2466 /* If there's no standout mode, try to use underlining instead. */
2560 if (TS_standout_mode == 0) 2467 if (tty->TS_standout_mode == 0)
2561 { 2468 {
2562 TS_standout_mode = TS_enter_underline_mode; 2469 tty->TS_standout_mode = tty->TS_enter_underline_mode;
2563 TS_end_standout_mode = TS_exit_underline_mode; 2470 tty->TS_end_standout_mode = tty->TS_exit_underline_mode;
2564 } 2471 }
2565 2472
2566 /* If no `se' string, try using a `me' string instead. 2473 /* If no `se' string, try using a `me' string instead.
2567 If that fails, we can't use standout mode at all. */ 2474 If that fails, we can't use standout mode at all. */
2568 if (TS_end_standout_mode == 0) 2475 if (tty->TS_end_standout_mode == 0)
2569 { 2476 {
2570 char *s = tgetstr ("me", address); 2477 char *s = tgetstr ("me", address);
2571 if (s != 0) 2478 if (s != 0)
2572 TS_end_standout_mode = s; 2479 tty->TS_end_standout_mode = s;
2573 else 2480 else
2574 TS_standout_mode = 0; 2481 tty->TS_standout_mode = 0;
2575 } 2482 }
2576 2483
2577 if (TF_teleray) 2484 if (tty->TF_teleray)
2578 { 2485 {
2579 tty->Wcm->cm_tab = 0; 2486 tty->Wcm->cm_tab = 0;
2580 /* We can't support standout mode, because it uses magic cookies. */ 2487 /* We can't support standout mode, because it uses magic cookies. */
2581 TS_standout_mode = 0; 2488 tty->TS_standout_mode = 0;
2582 /* But that means we cannot rely on ^M to go to column zero! */ 2489 /* But that means we cannot rely on ^M to go to column zero! */
2583 CR (tty) = 0; 2490 CR (tty) = 0;
2584 /* LF can't be trusted either -- can alter hpos */ 2491 /* LF can't be trusted either -- can alter hpos */
@@ -2608,21 +2515,21 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2608 It would be simpler if the :wi string could go in the termcap 2515 It would be simpler if the :wi string could go in the termcap
2609 entry, but it can't because it is not fully valid. 2516 entry, but it can't because it is not fully valid.
2610 If it were in the termcap entry, it would confuse other programs. */ 2517 If it were in the termcap entry, it would confuse other programs. */
2611 if (!TS_set_window) 2518 if (!tty->TS_set_window)
2612 { 2519 {
2613 p = TS_termcap_modes; 2520 p = tty->TS_termcap_modes;
2614 while (*p && strcmp (p, "\033v ")) 2521 while (*p && strcmp (p, "\033v "))
2615 p++; 2522 p++;
2616 if (*p) 2523 if (*p)
2617 TS_set_window = "\033v%C %C %C %C "; 2524 tty->TS_set_window = "\033v%C %C %C %C ";
2618 } 2525 }
2619 /* Termcap entry often fails to have :in: flag */ 2526 /* Termcap entry often fails to have :in: flag */
2620 TTY_MUST_WRITE_SPACES (tty) = 1; 2527 TTY_MUST_WRITE_SPACES (tty) = 1;
2621 /* :ti string typically fails to have \E^G! in it */ 2528 /* :ti string typically fails to have \E^G! in it */
2622 /* This limits scope of insert-char to one line. */ 2529 /* This limits scope of insert-char to one line. */
2623 strcpy (area, TS_termcap_modes); 2530 strcpy (area, tty->TS_termcap_modes);
2624 strcat (area, "\033\007!"); 2531 strcat (area, "\033\007!");
2625 TS_termcap_modes = area; 2532 tty->TS_termcap_modes = area;
2626 area += strlen (area) + 1; 2533 area += strlen (area) + 1;
2627 p = AbsPosition (tty); 2534 p = AbsPosition (tty);
2628 /* Change all %+ parameters to %C, to handle 2535 /* Change all %+ parameters to %C, to handle
@@ -2637,65 +2544,81 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2637 2544
2638 FrameRows (tty) = FRAME_LINES (sf); 2545 FrameRows (tty) = FRAME_LINES (sf);
2639 FrameCols (tty) = FRAME_COLS (sf); 2546 FrameCols (tty) = FRAME_COLS (sf);
2640 specified_window = FRAME_LINES (sf); 2547 tty->specified_window = FRAME_LINES (sf);
2641 2548
2642 if (Wcm_init (tty) == -1) /* can't do cursor motion */ 2549 if (Wcm_init (tty) == -1) /* can't do cursor motion */
2550 if (name)
2551 {
2552 delete_tty (tty);
2553 error ("Terminal type \"%s\" is not powerful enough to run Emacs");
2554 }
2555 else {
2643#ifdef VMS 2556#ifdef VMS
2644 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2557 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2645It lacks the ability to position the cursor.\n\ 2558It lacks the ability to position the cursor.\n\
2646If that is not the actual type of terminal you have, use either the\n\ 2559If that is not the actual type of terminal you have, use either the\n\
2647DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\ 2560DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2648or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.", 2561or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2649 terminal_type); 2562 terminal_type);
2650#else /* not VMS */ 2563#else /* not VMS */
2651# ifdef TERMINFO 2564# ifdef TERMINFO
2652 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2565 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2653It lacks the ability to position the cursor.\n\ 2566It lacks the ability to position the cursor.\n \
2654If that is not the actual type of terminal you have,\n\ 2567If that is not the actual type of terminal you have,\n \
2655use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2568use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2656`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2569`setenv TERM ...') to specify the correct type. It may be necessary\n\
2657to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 2570to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2658 terminal_type); 2571 terminal_type);
2659# else /* TERMCAP */ 2572# else /* TERMCAP */
2660 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2573 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2661It lacks the ability to position the cursor.\n\ 2574It lacks the ability to position the cursor.\n \
2662If that is not the actual type of terminal you have,\n\ 2575If that is not the actual type of terminal you have,\n\
2663use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2576use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2664`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2577`setenv TERM ...') to specify the correct type. It may be necessary\n\
2665to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 2578to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2666 terminal_type); 2579 terminal_type);
2667# endif /* TERMINFO */ 2580# endif /* TERMINFO */
2668#endif /*VMS */ 2581#endif /*VMS */
2582 }
2583
2669 if (FRAME_LINES (sf) <= 0 2584 if (FRAME_LINES (sf) <= 0
2670 || FRAME_COLS (sf) <= 0) 2585 || FRAME_COLS (sf) <= 0)
2671 fatal ("The frame size has not been specified"); 2586 {
2587 if (name)
2588 {
2589 delete_tty (tty);
2590 error ("The frame size has not been specified");
2591 }
2592 else
2593 fatal ("The frame size has not been specified");
2594 }
2672 2595
2673 delete_in_insert_mode 2596 tty->delete_in_insert_mode
2674 = TS_delete_mode && TS_insert_mode 2597 = tty->TS_delete_mode && tty->TS_insert_mode
2675 && !strcmp (TS_delete_mode, TS_insert_mode); 2598 && !strcmp (tty->TS_delete_mode, tty->TS_insert_mode);
2676 2599
2677 se_is_so = (TS_standout_mode 2600 tty->se_is_so = (tty->TS_standout_mode
2678 && TS_end_standout_mode 2601 && tty->TS_end_standout_mode
2679 && !strcmp (TS_standout_mode, TS_end_standout_mode)); 2602 && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode));
2680 2603
2681 UseTabs (tty) = tabs_safe_p (tty) && TabWidth (tty) == 8; 2604 UseTabs (tty) = tabs_safe_p (tty) && TabWidth (tty) == 8;
2682 2605
2683 TTY_SCROLL_REGION_OK (tty) 2606 TTY_SCROLL_REGION_OK (tty)
2684 = (tty->Wcm->cm_abs 2607 = (tty->Wcm->cm_abs
2685 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1)); 2608 && (tty->TS_set_window || tty->TS_set_scroll_region || tty->TS_set_scroll_region_1));
2686 2609
2687 TTY_LINE_INS_DEL_OK (tty) 2610 TTY_LINE_INS_DEL_OK (tty)
2688 = (((TS_ins_line || TS_ins_multi_lines) 2611 = (((tty->TS_ins_line || tty->TS_ins_multi_lines)
2689 && (TS_del_line || TS_del_multi_lines)) 2612 && (tty->TS_del_line || tty->TS_del_multi_lines))
2690 || (TTY_SCROLL_REGION_OK (tty) 2613 || (TTY_SCROLL_REGION_OK (tty)
2691 && TS_fwd_scroll && TS_rev_scroll)); 2614 && tty->TS_fwd_scroll && tty->TS_rev_scroll));
2692 2615
2693 TTY_CHAR_INS_DEL_OK (tty) 2616 TTY_CHAR_INS_DEL_OK (tty)
2694 = ((TS_ins_char || TS_insert_mode 2617 = ((tty->TS_ins_char || tty->TS_insert_mode
2695 || TS_pad_inserted_char || TS_ins_multi_chars) 2618 || tty->TS_pad_inserted_char || tty->TS_ins_multi_chars)
2696 && (TS_del_char || TS_del_multi_chars)); 2619 && (tty->TS_del_char || tty->TS_del_multi_chars));
2697 2620
2698 TTY_FAST_CLEAR_END_OF_LINE (tty) = TS_clr_line != 0; 2621 TTY_FAST_CLEAR_END_OF_LINE (tty) = tty->TS_clr_line != 0;
2699 2622
2700 init_baud_rate (); 2623 init_baud_rate ();
2701 if (read_socket_hook) /* Baudrate is somewhat 2624 if (read_socket_hook) /* Baudrate is somewhat
@@ -2708,6 +2631,8 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2708 2631
2709 xfree (buffer); 2632 xfree (buffer);
2710 2633
2634 tty_set_terminal_modes (tty);
2635
2711 return tty; 2636 return tty;
2712} 2637}
2713 2638
@@ -2746,12 +2671,93 @@ The function should accept no arguments. */);
2746 Fprovide (intern ("multi-tty"), Qnil); 2671 Fprovide (intern ("multi-tty"), Qnil);
2747} 2672}
2748 2673
2674void
2675delete_tty (struct tty_output *tty)
2676{
2677 Lisp_Object tail, frame;
2678
2679 FOR_EACH_FRAME (tail, frame)
2680 {
2681 struct frame *f = XFRAME (frame);
2682 if (FRAME_LIVE_P (f) && FRAME_TTY (f) == tty)
2683 {
2684 Fdelete_frame (frame, Qt);
2685 f->output_data.tty = 0;
2686 }
2687 }
2688
2689 /* Close the terminal and free memory. */
2690 delete_tty_1 (tty);
2691}
2692
2693static void
2694delete_tty_1 (struct tty_output *tty)
2695{
2696
2697 if (tty == tty_list)
2698 tty_list = tty->next;
2699 else
2700 {
2701 struct tty_output *p;
2702 for (p = tty_list; p && p->next != tty; p = p->next)
2703 ;
2704
2705 if (! p)
2706 /* This should not happen. */
2707 abort ();
2708
2709 p->next = p->next->next;
2710 }
2711
2712 /* This hangs. */
2713 /* reset_sys_modes (tty); */
2714
2715 if (tty->name)
2716 xfree (tty->name);
2717 if (tty->type)
2718 xfree (tty->type);
2719 if (tty->input)
2720 fclose (tty->input);
2721 if (tty->output)
2722 fclose (tty->output);
2723 if (tty->termscript)
2724 fclose (tty->termscript);
2725
2726 /*
2727 if (tty->old_tty)
2728 xfree (tty->old_tty);
2729
2730 if (tty->Wcm)
2731 {
2732 bzero (tty->Wcm, sizeof (struct cm));
2733 }
2734 xfree (tty->Wcm);
2735
2736 bzero (tty, sizeof (struct tty_output));
2737
2738 xfree (tty);
2739 */
2740}
2741
2742
2749struct tty_output * 2743struct tty_output *
2750get_current_tty () 2744get_current_tty ()
2751{ 2745{
2752 return CURTTY(); 2746 return CURTTY();
2753} 2747}
2754 2748
2749void
2750print_all_frames ()
2751{
2752 /* XXX Debug function. */
2753 Lisp_Object frame, tail;
2754 FOR_EACH_FRAME (tail, frame)
2755 {
2756 fprintf (stderr, "Frame: %x\n", XFRAME (frame));
2757 fflush (stderr);
2758 }
2759}
2760
2755 2761
2756/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 2762/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2757 (do not change this comment) */ 2763 (do not change this comment) */
diff --git a/src/termchar.h b/src/termchar.h
index 33170d5a78e..a9a74dd5b05 100644
--- a/src/termchar.h
+++ b/src/termchar.h
@@ -1,5 +1,5 @@
1/* Flags and parameters describing terminal's characteristics. 1/* Flags and parameters describing terminal's characteristics.
2 Copyright (C) 1985, 1986 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1986, 2003 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -35,10 +35,9 @@ struct tty_output
35 FILE *termscript; /* If nonzero, send all terminal output 35 FILE *termscript; /* If nonzero, send all terminal output
36 characters to this stream also. */ 36 characters to this stream also. */
37 37
38 struct emacs_tty old_tty; /* The initial tty mode bits */ 38 struct emacs_tty *old_tty; /* The initial tty mode bits */
39 39
40 int term_initted; /* 1 if we have been through init_sys_modes. */ 40 int term_initted; /* 1 if we have been through init_sys_modes. */
41 int old_tty_valid; /* 1 if outer tty status has been recorded. */
42 41
43 42
44 /* Structure for info on cursor positioning. */ 43 /* Structure for info on cursor positioning. */
@@ -47,7 +46,7 @@ struct tty_output
47 46
48 /* Redisplay. */ 47 /* Redisplay. */
49 48
50 /* XXX This may cause problems with GC. */ 49 /* XXX GC does not know about this; is this a problem? */
51 Lisp_Object top_frame; /* The topmost frame on this tty. */ 50 Lisp_Object top_frame; /* The topmost frame on this tty. */
52 51
53 /* The previous terminal frame we displayed on this tty. */ 52 /* The previous terminal frame we displayed on this tty. */
@@ -82,6 +81,119 @@ struct tty_output
82 various cost tables; we won't use them. */ 81 various cost tables; we won't use them. */
83#endif 82#endif
84 83
84 /* Strings, numbers and flags taken from the termcap entry. */
85
86 char *TS_ins_line; /* "al" */
87 char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */
88 char *TS_bell; /* "bl" */
89 char *TS_clr_to_bottom; /* "cd" */
90 char *TS_clr_line; /* "ce", clear to end of line */
91 char *TS_clr_frame; /* "cl" */
92 char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */
93 char *TS_set_scroll_region_1; /* "cS" (4 params: total lines,
94 lines above scroll region, lines below it,
95 total lines again) */
96 char *TS_del_char; /* "dc" */
97 char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */
98 char *TS_del_line; /* "dl" */
99 char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */
100 char *TS_delete_mode; /* "dm", enter character-delete mode */
101 char *TS_end_delete_mode; /* "ed", leave character-delete mode */
102 char *TS_end_insert_mode; /* "ei", leave character-insert mode */
103 char *TS_ins_char; /* "ic" */
104 char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */
105 char *TS_insert_mode; /* "im", enter character-insert mode */
106 char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */
107 char *TS_end_keypad_mode; /* "ke" */
108 char *TS_keypad_mode; /* "ks" */
109 char *TS_pad_char; /* "pc", char to use as padding */
110 char *TS_repeat; /* "rp" (2 params, # times to repeat
111 and character to be repeated) */
112 char *TS_end_standout_mode; /* "se" */
113 char *TS_fwd_scroll; /* "sf" */
114 char *TS_standout_mode; /* "so" */
115 char *TS_rev_scroll; /* "sr" */
116 char *TS_end_termcap_modes; /* "te" */
117 char *TS_termcap_modes; /* "ti" */
118 char *TS_visible_bell; /* "vb" */
119 char *TS_cursor_normal; /* "ve" */
120 char *TS_cursor_visible; /* "vs" */
121 char *TS_cursor_invisible; /* "vi" */
122 char *TS_set_window; /* "wi" (4 params, start and end of window,
123 each as vpos and hpos) */
124
125 char *TS_enter_bold_mode; /* "md" -- turn on bold (extra bright mode). */
126 char *TS_enter_dim_mode; /* "mh" -- turn on half-bright mode. */
127 char *TS_enter_blink_mode; /* "mb" -- enter blinking mode. */
128 char *TS_enter_reverse_mode; /* "mr" -- enter reverse video mode. */
129 char *TS_exit_underline_mode; /* "us" -- start underlining. */
130 char *TS_enter_underline_mode; /* "ue" -- end underlining. */
131
132 /* "as"/"ae" -- start/end alternate character set. Not really
133 supported, yet. */
134 char *TS_enter_alt_charset_mode;
135 char *TS_exit_alt_charset_mode;
136
137 char *TS_exit_attribute_mode; /* "me" -- switch appearances off. */
138
139 /* Value of the "NC" (no_color_video) capability, or 0 if not present. */
140 int TN_no_color_video;
141
142 int TN_max_colors; /* "Co" -- number of colors. */
143
144 /* "pa" -- max. number of color pairs on screen. Not handled yet.
145 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
146 int TN_max_pairs;
147
148 /* "op" -- SVr4 set default pair to its original value. */
149 char *TS_orig_pair;
150
151 /* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
152 1 param, the color index. */
153 char *TS_set_foreground;
154 char *TS_set_background;
155
156 int TF_hazeltine; /* termcap hz flag. */
157 int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */
158 int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */
159 int TF_underscore; /* termcap ul flag: _ underlines if over-struck on
160 non-blank position. Must clear before writing _. */
161 int TF_teleray; /* termcap xt flag: many weird consequences.
162 For t1061. */
163
164 int RPov; /* # chars to start a TS_repeat */
165
166 int delete_in_insert_mode; /* delete mode == insert mode */
167
168 int se_is_so; /* 1 if same string both enters and leaves
169 standout mode */
170
171 int costs_set; /* Nonzero if costs have been calculated. */
172
173 int insert_mode; /* Nonzero when in insert mode. */
174 int standout_mode; /* Nonzero when in standout mode. */
175
176
177
178 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
179 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
180
181 int meta_key;
182
183 /* Size of window specified by higher levels.
184 This is the number of lines, from the top of frame downwards,
185 which can participate in insert-line/delete-line operations.
186
187 Effectively it excludes the bottom frame_lines - specified_window_size
188 lines from those operations. */
189
190 int specified_window;
191
192 /* Flag used in tty_show/hide_cursor. */
193
194 int cursor_hidden;
195
196
85 struct tty_output *next; 197 struct tty_output *next;
86}; 198};
87 199
diff --git a/src/xfaces.c b/src/xfaces.c
index faae8352cb3..b3eba748720 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -5333,7 +5333,7 @@ substitution of a `dim' face for italic. */)
5333 /* See if the capabilities we selected above are supported, with the 5333 /* See if the capabilities we selected above are supported, with the
5334 given colors. */ 5334 given colors. */
5335 if (test_caps != 0 && 5335 if (test_caps != 0 &&
5336 ! tty_capable_p (f, test_caps, fg_tty_color.pixel, bg_tty_color.pixel)) 5336 ! tty_capable_p (FRAME_TTY (SELECTED_FRAME ()), test_caps, fg_tty_color.pixel, bg_tty_color.pixel))
5337 return Qnil; 5337 return Qnil;
5338 5338
5339 5339