aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKaroly Lorentey2003-12-25 06:59:31 +0000
committerKaroly Lorentey2003-12-25 06:59:31 +0000
commit28d440abfe46139dff7278a444e0a35896038ff8 (patch)
tree89805f4ff23e9d9b8c73dc0fdb43669d4f142d2f /src
parent8a56675df17bbd27cf45bd60a2d6e94c8f2c2281 (diff)
downloademacs-28d440abfe46139dff7278a444e0a35896038ff8.tar.gz
emacs-28d440abfe46139dff7278a444e0a35896038ff8.zip
Implemented multiple tty support.
README.multi-tty: New file. src/termchar.h (struct terminal): Renamed to struct tty_output. Added name, type, input, output, termscript, old_tty, term_initted, old_tty_valid, background_pixel, foreground_pixel, next fields. (TERMINAL_*): Renamed to TTY_* for brevity. (CURRENT_TERMINAL): Renamed to CURTTY for brevity. (tty_list): New variable. (TERMINAL_PTR): Removed. (FRAME_TTY): New function. (TTY_NAME, TTY_TYPE): New macros. src/term.c (current_terminal): Removed. (_current_terminal): Removed. (tty_list): New variable. (OUTPUT, OUTPUT1, OUTPUTL, OUTPUT_IF, OUTPUT1_IF): Added tty parameter. (set_terminal_modes): Added tty parameter. (reset_terminal_modes): Added tty parameter. (cursor_to, raw_cursor_to): Updated cmgoto() calls. (clear_end_of_line, write_glyphs): Add indirection to terminal output, updated cmcheckmagic() calls. (get_named_tty): New function. (term_dummy_init): New function. (term_init): Added name parameter, added tty_output return value. Changed algorithm to update tty_list. Call init_sys_modes() to set up tty mode on the newly opened terminal device. (get_current_tty): New function, intended for debugging. src/termhooks.h (termscript): Removed. src/w32term.h (FRAME_FOREGROUND_PIXEL, FRAME_BACKGROUND_PIXEL): Removed redundant definition. src/macterm.h (FRAME_FOREGROUND_PIXEL, FRAME_BACKGROUND_PIXEL): Ditto. src/window.c (init_window_once): Call make_terminal_frame with two zero parameters. src/cm.h (emacs_tputs): New macro to set current_tty, and then call tputs(). (current_tty): New variable, for cmputc(). (cmcheckmagic, cmputc, cmgoto): Added prototypes. src/cm.c (current_tty): New variable, for cmputc(). (cmputc): Use it. (cmcheckmagic): Added tty parameter, look up terminal streams there. (calccost): Added tty parameter. Use emacs_tputs() instead of tputs(). (cmgoto): Added tty parameter. Pass it on to calccost(). Use emacs_tputs() instead of tputs(). src/dispextern.h (set_terminal_modes, reset_terminal_modes): Added tty parameter. (term_init): Added name parameter (the filename of the terminal device). Added return value (struct tty_output). src/dispnew.c: Replace CURTTY() with local variables throughout the file (where applicable). (termscript): Moved to struct tty_output. (terminal_type): Removed. src/emacs.c (main): Don't call init_sys_modes(), the new term_init() already does that during init_display(). (shut_down_emacs): Call reset_all_sys_modes() instead of reset_sys_modes(). src/frame.c (Qtty, Qtty_type): New variables. (syms_of_frame): Initialize them. (tty_display): Removed. (make_terminal_frame): New parameters (tty filename and type). Initialize output_data.tty field instead of output_data.x. Use term_init() to find the right tty_output. (Use term_dummy_init() during bootstrap.) (Fmake_terminal_frame): Get device filename and type from frame parameters. src/frame.h (FRAME_FOREGROUND_PIXEL, FRAME_BACKGROUND_PIXEL): Do the right thing if the frame is a tty. (struct frame): New member in output_data: tty. (make_terminal_frame): Updated of prototype. src/keyboard.c (Fset_input_mode): Call reset_all_sys_modes(), not reset_sys_modes(). Ditto with init_sys_modes(). src/lisp.h (tty_output): Added forward declaration. (init_sys_modes, reset_sys_modes): Updated prototype. (init_all_sys_modes, reset_all_sys_modes): New prototypes. src/scroll.c: Replace CURTTY() with local variables throughout the file (where applicable). src/sysdep.c (old_tty, term_initted, old_tty_valid): Moved to struct tty_output.( (init_all_sys_modes): New function. (init_sys_modes): Added tty_output parameter. Use it. (reset_all_sys_modes): New function. (reset_sys_modes): Added tty_output parameter. Use it. src/Makefile.in: Update dependencies. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-2
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in23
-rw-r--r--src/cm.c71
-rw-r--r--src/cm.h9
-rw-r--r--src/dispextern.h7
-rw-r--r--src/dispnew.c69
-rw-r--r--src/emacs.c6
-rw-r--r--src/frame.c78
-rw-r--r--src/frame.h17
-rw-r--r--src/indent.c1
-rw-r--r--src/keyboard.c12
-rw-r--r--src/lisp.h10
-rw-r--r--src/macterm.c10
-rw-r--r--src/macterm.h3
-rw-r--r--src/msdos.c2
-rw-r--r--src/print.c1
-rw-r--r--src/scroll.c9
-rw-r--r--src/sysdep.c72
-rw-r--r--src/term.c352
-rw-r--r--src/termchar.h69
-rw-r--r--src/termhooks.h3
-rw-r--r--src/w32term.c10
-rw-r--r--src/w32term.h2
-rw-r--r--src/window.c3
-rw-r--r--src/xdisp.c7
-rw-r--r--src/xfaces.c2
-rw-r--r--src/xfns.c2
26 files changed, 548 insertions, 302 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 07b3c828650..c3b7541e7df 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1047,7 +1047,7 @@ ccl.o: ccl.c ccl.h charset.h coding.h $(config_h)
1047charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \ 1047charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \
1048 $(config_h) 1048 $(config_h)
1049coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h window.h $(config_h) 1049coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h window.h $(config_h)
1050cm.o: cm.c cm.h termhooks.h $(config_h) 1050cm.o: cm.c frame.h cm.h termhooks.h systty.h termchar.h $(config_h)
1051cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \ 1051cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \
1052 msdos.h dispextern.h 1052 msdos.h dispextern.h
1053pre-crt0.o: pre-crt0.c 1053pre-crt0.o: pre-crt0.c
@@ -1055,7 +1055,7 @@ ecrt0.o: ecrt0.c $(config_h)
1055 CRT0_COMPILE ${srcdir}/ecrt0.c 1055 CRT0_COMPILE ${srcdir}/ecrt0.c
1056dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \ 1056dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \
1057 systime.h 1057 systime.h
1058dispnew.o: dispnew.c systty.h systime.h commands.h process.h frame.h \ 1058dispnew.o: dispnew.c systty.h systime.h commands.h process.h frame.h \
1059 window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \ 1059 window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \
1060 disptab.h \ 1060 disptab.h \
1061 xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \ 1061 xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \
@@ -1073,12 +1073,12 @@ fileio.o: fileio.c window.h buffer.h systime.h $(INTERVAL_SRC) charset.h \
1073filelock.o: filelock.c buffer.h systime.h epaths.h $(config_h) 1073filelock.o: filelock.c buffer.h systime.h epaths.h $(config_h)
1074filemode.o: filemode.c $(config_h) 1074filemode.o: filemode.c $(config_h)
1075frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \ 1075frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \
1076 blockinput.h atimer.h systime.h buffer.h charset.h fontset.h \ 1076 blockinput.h systty.h atimer.h systime.h buffer.h charset.h fontset.h \
1077 msdos.h dosfns.h dispextern.h $(config_h) 1077 msdos.h dosfns.h dispextern.h $(config_h)
1078fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \ 1078fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \
1079 keyboard.h $(config_h) 1079 keyboard.h $(config_h)
1080getloadavg.o: getloadavg.c $(config_h) 1080getloadavg.o: getloadavg.c $(config_h)
1081indent.o: indent.c frame.h window.h indent.h buffer.h $(config_h) termchar.h \ 1081indent.o: indent.c frame.h window.h systty.h indent.h buffer.h $(config_h) termchar.h \
1082 termopts.h disptab.h region-cache.h charset.h composite.h dispextern.h \ 1082 termopts.h disptab.h region-cache.h charset.h composite.h dispextern.h \
1083 keyboard.h 1083 keyboard.h
1084insdel.o: insdel.c window.h buffer.h $(INTERVAL_SRC) blockinput.h charset.h \ 1084insdel.o: insdel.c window.h buffer.h $(INTERVAL_SRC) blockinput.h charset.h \
@@ -1110,7 +1110,7 @@ process.o: process.c process.h buffer.h window.h termhooks.h termopts.h \
1110 keyboard.h $(config_h) 1110 keyboard.h $(config_h)
1111regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h 1111regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h
1112region-cache.o: region-cache.c buffer.h region-cache.h 1112region-cache.o: region-cache.c buffer.h region-cache.h
1113scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \ 1113scroll.o: scroll.c systty.h termchar.h dispextern.h frame.h msdos.h keyboard.h \
1114 $(config_h) 1114 $(config_h)
1115search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \ 1115search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \
1116 blockinput.h atimer.h systime.h category.h charset.h composite.h $(config_h) 1116 blockinput.h atimer.h systime.h category.h charset.h composite.h $(config_h)
@@ -1120,7 +1120,7 @@ syntax.o: syntax.c syntax.h buffer.h commands.h category.h charset.h \
1120sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \ 1120sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \
1121 process.h dispextern.h termhooks.h termchar.h termopts.h \ 1121 process.h dispextern.h termhooks.h termchar.h termopts.h \
1122 frame.h atimer.h window.h msdos.h dosfns.h keyboard.h $(config_h) 1122 frame.h atimer.h window.h msdos.h dosfns.h keyboard.h $(config_h)
1123term.o: term.c termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \ 1123term.o: term.c systty.h termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \
1124 disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h 1124 disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h
1125termcap.o: termcap.c $(config_h) 1125termcap.o: termcap.c $(config_h)
1126terminfo.o: terminfo.c $(config_h) 1126terminfo.o: terminfo.c $(config_h)
@@ -1134,17 +1134,18 @@ w16select.o: w16select.c dispextern.h frame.h blockinput.h atimer.h systime.h \
1134 msdos.h $(config_h) 1134 msdos.h $(config_h)
1135widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \ 1135widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \
1136 $(srcdir)/../lwlib/lwlib.h $(config_h) 1136 $(srcdir)/../lwlib/lwlib.h $(config_h)
1137window.o: window.c indent.h commands.h frame.h window.h buffer.h termchar.h \ 1137window.o: window.c indent.h commands.h frame.h window.h buffer.h systty.h termchar.h \
1138 termhooks.h disptab.h keyboard.h dispextern.h msdos.h composite.h \ 1138 termhooks.h disptab.h keyboard.h dispextern.h msdos.h composite.h \
1139 $(config_h) 1139 $(config_h)
1140xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \ 1140xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \
1141 termchar.h frame.h window.h disptab.h termhooks.h charset.h $(config_h) \ 1141 systty.h termchar.h frame.h window.h disptab.h termhooks.h charset.h $(config_h) \
1142 msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h 1142 msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h
1143xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \ 1143xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \
1144 window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h $(config_h) 1144 window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \
1145 systty.h termchar.h $(config_h)
1145xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \ 1146xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \
1146 $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \ 1147 $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \
1147 charset.h gtkutil.h $(config_h) 1148 charset.h gtkutil.h systty.h termchar.h $(config_h)
1148xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \ 1149xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \
1149 keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \ 1150 keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \
1150 gtkutil.h msdos.h coding.h $(config_h) 1151 gtkutil.h msdos.h coding.h $(config_h)
@@ -1176,7 +1177,7 @@ floatfns.o: floatfns.c $(config_h)
1176fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \ 1177fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \
1177 frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h 1178 frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h
1178print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \ 1179print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \
1179 $(config_h) dispextern.h msdos.h composite.h 1180 $(config_h) dispextern.h msdos.h composite.h systty.h termchar.h intervals.h
1180lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h $(config_h) \ 1181lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h $(config_h) \
1181 termhooks.h coding.h msdos.h 1182 termhooks.h coding.h msdos.h
1182 1183
diff --git a/src/cm.c b/src/cm.c
index dcff5048460..508729eeadb 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -22,8 +22,16 @@ Boston, MA 02111-1307, USA. */
22 22
23#include <config.h> 23#include <config.h>
24#include <stdio.h> 24#include <stdio.h>
25
26/* For CURTTY */
27#include "lisp.h"
28#include "frame.h"
29
25#include "cm.h" 30#include "cm.h"
26#include "termhooks.h" 31#include "termhooks.h"
32#include "systty.h" /* For emacs_tty in termchar.h */
33#include "termchar.h"
34
27 35
28/* For now, don't try to include termcap.h. On some systems, 36/* For now, don't try to include termcap.h. On some systems,
29 configure finds a non-standard termcap.h that the main build 37 configure finds a non-standard termcap.h that the main build
@@ -41,6 +49,7 @@ extern char *tgoto P_ ((const char *, int, int));
41 49
42extern char *BC, *UP; 50extern char *BC, *UP;
43 51
52
44int cost; /* sums up costs */ 53int cost; /* sums up costs */
45 54
46/* ARGSUSED */ 55/* ARGSUSED */
@@ -52,13 +61,16 @@ evalcost (c)
52 return c; 61 return c;
53} 62}
54 63
64/* The terminal to use for low-level output. */
65struct tty_output * current_tty;
66
55int 67int
56cmputc (c) 68cmputc (c)
57 char c; 69 char c;
58{ 70{
59 if (termscript) 71 if (TTY_TERMSCRIPT (current_tty))
60 fputc (c & 0177, termscript); 72 putc (c & 0177, TTY_TERMSCRIPT (current_tty));
61 putchar (c & 0177); 73 putc (c & 0177, TTY_OUTPUT (current_tty));
62 return c; 74 return c;
63} 75}
64 76
@@ -122,18 +134,19 @@ addcol (n) {
122 * after we reach the last column; this takes us to a known state. 134 * after we reach the last column; this takes us to a known state.
123 */ 135 */
124void 136void
125cmcheckmagic () 137cmcheckmagic (tty)
138 struct tty_output *tty;
126{ 139{
127 if (curX == FrameCols) 140 if (curX == FrameCols)
128 { 141 {
129 if (!MagicWrap || curY >= FrameRows - 1) 142 if (!MagicWrap || curY >= FrameRows - 1)
130 abort (); 143 abort ();
131 if (termscript) 144 if (TTY_TERMSCRIPT (tty))
132 putc ('\r', termscript); 145 putc ('\r', TTY_TERMSCRIPT (tty));
133 putchar ('\r'); 146 putc ('\r', TTY_OUTPUT (tty));
134 if (termscript) 147 if (TTY_TERMSCRIPT (tty))
135 putc ('\n', termscript); 148 putc ('\n', TTY_TERMSCRIPT (tty));
136 putchar ('\n'); 149 putc ('\n', TTY_OUTPUT (tty));
137 curX = 0; 150 curX = 0;
138 curY++; 151 curY++;
139 } 152 }
@@ -187,8 +200,7 @@ cmcostinit ()
187 */ 200 */
188 201
189static int 202static int
190calccost (srcy, srcx, dsty, dstx, doit) 203calccost (struct tty_output *tty, int srcy, int srcx, int dsty, int dstx, int doit)
191 int srcy, srcx, dsty, dstx, doit;
192{ 204{
193 register int deltay, 205 register int deltay,
194 deltax, 206 deltax,
@@ -223,7 +235,7 @@ calccost (srcy, srcx, dsty, dstx, doit)
223 totalcost = c * deltay; 235 totalcost = c * deltay;
224 if (doit) 236 if (doit)
225 while (--deltay >= 0) 237 while (--deltay >= 0)
226 tputs (p, 1, cmputc); 238 emacs_tputs (tty, p, 1, cmputc);
227x: 239x:
228 if ((deltax = dstx - srcx) == 0) 240 if ((deltax = dstx - srcx) == 0)
229 goto done; 241 goto done;
@@ -278,7 +290,7 @@ x:
278 totalcost += tabcost; /* use the tabs */ 290 totalcost += tabcost; /* use the tabs */
279 if (doit) 291 if (doit)
280 while (--ntabs >= 0) 292 while (--ntabs >= 0)
281 tputs (Wcm.cm_tab, 1, cmputc); 293 emacs_tputs (tty, Wcm.cm_tab, 1, cmputc);
282 srcx = tabx; 294 srcx = tabx;
283 } 295 }
284 296
@@ -305,7 +317,7 @@ fail:
305 totalcost += c * deltax; 317 totalcost += c * deltax;
306 if (doit) 318 if (doit)
307 while (--deltax >= 0) 319 while (--deltax >= 0)
308 tputs (p, 1, cmputc); 320 emacs_tputs (tty, p, 1, cmputc);
309done: 321done:
310 return totalcost; 322 return totalcost;
311} 323}
@@ -323,7 +335,8 @@ losecursor ()
323#define USECR 3 335#define USECR 3
324 336
325void 337void
326cmgoto (row, col) 338cmgoto (tty, row, col)
339 struct tty_output *tty;
327 int row, col; 340 int row, col;
328{ 341{
329 int homecost, 342 int homecost,
@@ -346,24 +359,24 @@ cmgoto (row, col)
346 * start where we are. Examine the options, and pick the cheapest. 359 * start where we are. Examine the options, and pick the cheapest.
347 */ 360 */
348 361
349 relcost = calccost (curY, curX, row, col, 0); 362 relcost = calccost (tty, curY, curX, row, col, 0);
350 use = USEREL; 363 use = USEREL;
351 if ((homecost = Wcm.cc_home) < BIG) 364 if ((homecost = Wcm.cc_home) < BIG)
352 homecost += calccost (0, 0, row, col, 0); 365 homecost += calccost (tty, 0, 0, row, col, 0);
353 if (homecost < relcost) 366 if (homecost < relcost)
354 relcost = homecost, use = USEHOME; 367 relcost = homecost, use = USEHOME;
355 if ((llcost = Wcm.cc_ll) < BIG) 368 if ((llcost = Wcm.cc_ll) < BIG)
356 llcost += calccost (Wcm.cm_rows - 1, 0, row, col, 0); 369 llcost += calccost (tty, Wcm.cm_rows - 1, 0, row, col, 0);
357 if (llcost < relcost) 370 if (llcost < relcost)
358 relcost = llcost, use = USELL; 371 relcost = llcost, use = USELL;
359 if ((crcost = Wcm.cc_cr) < BIG) { 372 if ((crcost = Wcm.cc_cr) < BIG) {
360 if (Wcm.cm_autolf) 373 if (Wcm.cm_autolf)
361 if (curY + 1 >= Wcm.cm_rows) 374 if (curY + 1 >= Wcm.cm_rows)
362 crcost = BIG; 375 crcost = BIG;
363 else 376 else
364 crcost += calccost (curY + 1, 0, row, col, 0); 377 crcost += calccost (tty, curY + 1, 0, row, col, 0);
365 else 378 else
366 crcost += calccost (curY, 0, row, col, 0); 379 crcost += calccost (tty, curY, 0, row, col, 0);
367 } 380 }
368 if (crcost < relcost) 381 if (crcost < relcost)
369 relcost = crcost, use = USECR; 382 relcost = crcost, use = USECR;
@@ -389,10 +402,10 @@ cmgoto (row, col)
389 cost = 0; 402 cost = 0;
390 p = dcm == Wcm.cm_habs ? tgoto (dcm, row, col) : 403 p = dcm == Wcm.cm_habs ? tgoto (dcm, row, col) :
391 tgoto (dcm, col, row); 404 tgoto (dcm, col, row);
392 tputs (p, 1, evalcost); 405 emacs_tputs (tty, p, 1, evalcost);
393 if (cost <= relcost) 406 if (cost <= relcost)
394 { /* really is cheaper */ 407 { /* really is cheaper */
395 tputs (p, 1, cmputc); 408 emacs_tputs (tty, p, 1, cmputc);
396 curY = row, curX = col; 409 curY = row, curX = col;
397 return; 410 return;
398 } 411 }
@@ -401,24 +414,24 @@ cmgoto (row, col)
401 switch (use) 414 switch (use)
402 { 415 {
403 case USEHOME: 416 case USEHOME:
404 tputs (Wcm.cm_home, 1, cmputc); 417 emacs_tputs (tty, Wcm.cm_home, 1, cmputc);
405 curY = 0, curX = 0; 418 curY = 0, curX = 0;
406 break; 419 break;
407 420
408 case USELL: 421 case USELL:
409 tputs (Wcm.cm_ll, 1, cmputc); 422 emacs_tputs (tty, Wcm.cm_ll, 1, cmputc);
410 curY = Wcm.cm_rows - 1, curX = 0; 423 curY = Wcm.cm_rows - 1, curX = 0;
411 break; 424 break;
412 425
413 case USECR: 426 case USECR:
414 tputs (Wcm.cm_cr, 1, cmputc); 427 emacs_tputs (tty, Wcm.cm_cr, 1, cmputc);
415 if (Wcm.cm_autolf) 428 if (Wcm.cm_autolf)
416 curY++; 429 curY++;
417 curX = 0; 430 curX = 0;
418 break; 431 break;
419 } 432 }
420 433
421 (void) calccost (curY, curX, row, col, 1); 434 (void) calccost (tty, curY, curX, row, col, 1);
422 curY = row, curX = col; 435 curY = row, curX = col;
423} 436}
424 437
diff --git a/src/cm.h b/src/cm.h
index 5500c5ce58e..18d82c3748a 100644
--- a/src/cm.h
+++ b/src/cm.h
@@ -162,10 +162,13 @@ extern char PC; /* Pad character */
162extern int cost; 162extern int cost;
163extern int evalcost (); 163extern int evalcost ();
164 164
165extern void cmcheckmagic (); 165#define emacs_tputs(tty, str, affcnt, putc) (current_tty = (tty), tputs (str, affcnt, putc))
166extern int cmputc (); 166
167extern struct tty_output *current_tty;
168extern void cmcheckmagic P_ ((struct tty_output *));
169extern int cmputc P_ ((int));
167extern void cmcostinit (); 170extern void cmcostinit ();
168extern void cmgoto (); 171extern void cmgoto P_ ((struct tty_output *, int, int));
169extern void Wcm_clear (); 172extern void Wcm_clear ();
170extern int Wcm_init (); 173extern int Wcm_init ();
171 174
diff --git a/src/dispextern.h b/src/dispextern.h
index f306a939db2..2538460dee2 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2724,8 +2724,8 @@ 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_ ((void)); 2727extern void set_terminal_modes P_ ((struct tty_output *));
2728extern void reset_terminal_modes P_ ((void)); 2728extern void reset_terminal_modes P_ ((struct tty_output *));
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));
@@ -2743,7 +2743,8 @@ extern 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_ ((int));
2746extern void term_init P_ ((char *)); 2746extern struct tty_output *term_init P_ ((char *, char *));
2747extern struct tty_output *term_dummy_init P_ ((void));
2747extern void fatal P_ ((/* char *, ... */)); 2748extern void fatal P_ ((/* char *, ... */));
2748void cursor_to P_ ((int, int)); 2749void cursor_to P_ ((int, int));
2749extern int tty_capable_p P_ ((struct frame *, unsigned, unsigned long, unsigned long)); 2750extern int tty_capable_p P_ ((struct frame *, unsigned, unsigned long, unsigned long));
diff --git a/src/dispnew.c b/src/dispnew.c
index 9eb69ebf79d..cf335cfeed6 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -29,6 +29,7 @@ Boston, MA 02111-1307, USA. */
29#endif 29#endif
30 30
31#include "lisp.h" 31#include "lisp.h"
32#include "systty.h" /* For emacs_tty in termchar.h */
32#include "termchar.h" 33#include "termchar.h"
33#include "termopts.h" 34#include "termopts.h"
34#include "termhooks.h" 35#include "termhooks.h"
@@ -258,10 +259,6 @@ Lisp_Object selected_frame;
258 259
259struct frame *last_nonminibuf_frame; 260struct frame *last_nonminibuf_frame;
260 261
261/* Stdio stream being used for copy of all output. */
262
263FILE *termscript;
264
265/* Structure for info on cursor positioning. */ 262/* Structure for info on cursor positioning. */
266 263
267struct cm Wcm; 264struct cm Wcm;
@@ -1397,7 +1394,7 @@ line_hash_code (row)
1397 { 1394 {
1398 int c = glyph->u.ch; 1395 int c = glyph->u.ch;
1399 int face_id = glyph->face_id; 1396 int face_id = glyph->face_id;
1400 if (TERMINAL_MUST_WRITE_SPACES (CURRENT_TERMINAL ())) 1397 if (TTY_MUST_WRITE_SPACES (CURTTY ()))
1401 c -= SPACEGLYPH; 1398 c -= SPACEGLYPH;
1402 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c; 1399 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c;
1403 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + face_id; 1400 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + face_id;
@@ -1429,7 +1426,7 @@ line_draw_cost (matrix, vpos)
1429 int glyph_table_len = GLYPH_TABLE_LENGTH; 1426 int glyph_table_len = GLYPH_TABLE_LENGTH;
1430 1427
1431 /* Ignore trailing and leading spaces if we can. */ 1428 /* Ignore trailing and leading spaces if we can. */
1432 if (!TERMINAL_MUST_WRITE_SPACES (CURRENT_TERMINAL ())) 1429 if (!TTY_MUST_WRITE_SPACES (CURTTY ()))
1433 { 1430 {
1434 /* Skip from the end over trailing spaces. */ 1431 /* Skip from the end over trailing spaces. */
1435 while (end > beg && CHAR_GLYPH_SPACE_P (*(end - 1))) 1432 while (end > beg && CHAR_GLYPH_SPACE_P (*(end - 1)))
@@ -1643,8 +1640,10 @@ realloc_glyph_pool (pool, matrix_dim)
1643#if GLYPH_DEBUG 1640#if GLYPH_DEBUG
1644 1641
1645 1642
1646/* Flush standard output. This is sometimes useful to call from 1643/* Flush standard output. This is sometimes useful to call from the debugger.
1647 the debugger. */ 1644 XXX Maybe this should be changed to flush the current terminal instead of
1645 stdout.
1646*/
1648 1647
1649void 1648void
1650flush_stdout () 1649flush_stdout ()
@@ -3318,7 +3317,7 @@ DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
3318 3317
3319 update_begin (f); 3318 update_begin (f);
3320 if (FRAME_MSDOS_P (f)) 3319 if (FRAME_MSDOS_P (f))
3321 set_terminal_modes (); 3320 set_terminal_modes (0);
3322 clear_frame (); 3321 clear_frame ();
3323 clear_current_matrices (f); 3322 clear_current_matrices (f);
3324 update_end (f); 3323 update_end (f);
@@ -3462,7 +3461,7 @@ direct_output_for_insert (g)
3462 3461
3463 /* If we can't insert glyphs, we can use this method only 3462 /* If we can't insert glyphs, we can use this method only
3464 at the end of a line. */ 3463 at the end of a line. */
3465 if (!TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ())) 3464 if (!TTY_CHAR_INS_DEL_OK (CURTTY ()))
3466 if (PT != ZV && FETCH_BYTE (PT_BYTE) != '\n') 3465 if (PT != ZV && FETCH_BYTE (PT_BYTE) != '\n')
3467 return 0; 3466 return 0;
3468 3467
@@ -3841,9 +3840,9 @@ update_frame (f, force_p, inhibit_hairy_id_p)
3841 paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p); 3840 paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p);
3842 update_end (f); 3841 update_end (f);
3843 3842
3844 if (termscript) 3843 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
3845 fflush (termscript); 3844 fflush (TTY_TERMSCRIPT (FRAME_TTY (f)));
3846 fflush (stdout); 3845 fflush (TTY_OUTPUT (FRAME_TTY (f)));
3847 3846
3848 /* Check window matrices for lost pointers. */ 3847 /* Check window matrices for lost pointers. */
3849#if GLYPH_DEBUG 3848#if GLYPH_DEBUG
@@ -5075,7 +5074,7 @@ update_frame_1 (f, force_p, inhibit_id_p)
5075 } 5074 }
5076 5075
5077 /* If we cannot insert/delete lines, it's no use trying it. */ 5076 /* If we cannot insert/delete lines, it's no use trying it. */
5078 if (!TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ())) 5077 if (!TTY_LINE_INS_DEL_OK (FRAME_TTY (f)))
5079 inhibit_id_p = 1; 5078 inhibit_id_p = 1;
5080 5079
5081 /* See if any of the desired lines are enabled; don't compute for 5080 /* See if any of the desired lines are enabled; don't compute for
@@ -5293,7 +5292,7 @@ scrolling (frame)
5293 } 5292 }
5294 5293
5295 /* If changed lines are few, don't allow preemption, don't scroll. */ 5294 /* If changed lines are few, don't allow preemption, don't scroll. */
5296 if ((!TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) 5295 if ((!TTY_SCROLL_REGION_OK (FRAME_TTY (frame))
5297 && changed_lines < baud_rate / 2400) 5296 && changed_lines < baud_rate / 2400)
5298 || unchanged_at_bottom == FRAME_LINES (frame)) 5297 || unchanged_at_bottom == FRAME_LINES (frame))
5299 return 1; 5298 return 1;
@@ -5301,14 +5300,14 @@ scrolling (frame)
5301 window_size = (FRAME_LINES (frame) - unchanged_at_top 5300 window_size = (FRAME_LINES (frame) - unchanged_at_top
5302 - unchanged_at_bottom); 5301 - unchanged_at_bottom);
5303 5302
5304 if (TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ())) 5303 if (TTY_SCROLL_REGION_OK (FRAME_TTY (frame)))
5305 free_at_end_vpos -= unchanged_at_bottom; 5304 free_at_end_vpos -= unchanged_at_bottom;
5306 else if (TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ())) 5305 else if (TTY_MEMORY_BELOW_FRAME (FRAME_TTY (frame)))
5307 free_at_end_vpos = -1; 5306 free_at_end_vpos = -1;
5308 5307
5309 /* If large window, fast terminal and few lines in common between 5308 /* If large window, fast terminal and few lines in common between
5310 current frame and desired frame, don't bother with i/d calc. */ 5309 current frame and desired frame, don't bother with i/d calc. */
5311 if (!TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) 5310 if (!TTY_SCROLL_REGION_OK (FRAME_TTY (frame))
5312 && window_size >= 18 && baud_rate > 2400 5311 && window_size >= 18 && baud_rate > 2400
5313 && (window_size >= 5312 && (window_size >=
5314 10 * scrolling_max_lines_saved (unchanged_at_top, 5313 10 * scrolling_max_lines_saved (unchanged_at_top,
@@ -5389,7 +5388,7 @@ update_frame_line (f, vpos)
5389 struct glyph_row *current_row = MATRIX_ROW (current_matrix, vpos); 5388 struct glyph_row *current_row = MATRIX_ROW (current_matrix, vpos);
5390 struct glyph_row *desired_row = MATRIX_ROW (desired_matrix, vpos); 5389 struct glyph_row *desired_row = MATRIX_ROW (desired_matrix, vpos);
5391 int must_write_whole_line_p; 5390 int must_write_whole_line_p;
5392 int write_spaces_p = TERMINAL_MUST_WRITE_SPACES (CURRENT_TERMINAL ()); 5391 int write_spaces_p = TTY_MUST_WRITE_SPACES (FRAME_TTY (f));
5393 int colored_spaces_p = (FACE_FROM_ID (f, DEFAULT_FACE_ID)->background 5392 int colored_spaces_p = (FACE_FROM_ID (f, DEFAULT_FACE_ID)->background
5394 != FACE_TTY_DEFAULT_BG_COLOR); 5393 != FACE_TTY_DEFAULT_BG_COLOR);
5395 5394
@@ -5468,7 +5467,7 @@ update_frame_line (f, vpos)
5468 nlen--; 5467 nlen--;
5469 5468
5470 /* If there's no i/d char, quickly do the best we can without it. */ 5469 /* If there's no i/d char, quickly do the best we can without it. */
5471 if (!TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ())) 5470 if (!TTY_CHAR_INS_DEL_OK (FRAME_TTY (f)))
5472 { 5471 {
5473 int i, j; 5472 int i, j;
5474 5473
@@ -5571,7 +5570,7 @@ update_frame_line (f, vpos)
5571 5570
5572 tem = (nlen - nsp) - (olen - osp); 5571 tem = (nlen - nsp) - (olen - osp);
5573 if (endmatch && tem 5572 if (endmatch && tem
5574 && (!TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) 5573 && (!TTY_CHAR_INS_DEL_OK (FRAME_TTY (f))
5575 || endmatch <= char_ins_del_cost (f)[tem])) 5574 || endmatch <= char_ins_del_cost (f)[tem]))
5576 endmatch = 0; 5575 endmatch = 0;
5577 5576
@@ -5581,7 +5580,7 @@ update_frame_line (f, vpos)
5581 Is it worth it? */ 5580 Is it worth it? */
5582 5581
5583 if (nsp != osp 5582 if (nsp != osp
5584 && (!TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) 5583 && (!TTY_CHAR_INS_DEL_OK (FRAME_TTY (f))
5585 || begmatch + endmatch <= char_ins_del_cost (f)[nsp - osp])) 5584 || begmatch + endmatch <= char_ins_del_cost (f)[nsp - osp]))
5586 { 5585 {
5587 begmatch = 0; 5586 begmatch = 0;
@@ -6113,14 +6112,15 @@ FILE = nil means just close any termscript file currently open. */)
6113 (file) 6112 (file)
6114 Lisp_Object file; 6113 Lisp_Object file;
6115{ 6114{
6116 if (termscript != 0) fclose (termscript); 6115 if (TTY_TERMSCRIPT (CURTTY ()) != 0)
6117 termscript = 0; 6116 fclose (TTY_TERMSCRIPT (CURTTY ()));
6117 TTY_TERMSCRIPT (CURTTY ()) = 0;
6118 6118
6119 if (! NILP (file)) 6119 if (! NILP (file))
6120 { 6120 {
6121 file = Fexpand_file_name (file, Qnil); 6121 file = Fexpand_file_name (file, Qnil);
6122 termscript = fopen (SDATA (file), "w"); 6122 TTY_TERMSCRIPT (CURTTY ()) = fopen (SDATA (file), "w");
6123 if (termscript == 0) 6123 if (TTY_TERMSCRIPT (CURTTY ()) == 0)
6124 report_file_error ("Opening termscript", Fcons (file, Qnil)); 6124 report_file_error ("Opening termscript", Fcons (file, Qnil));
6125 } 6125 }
6126 return Qnil; 6126 return Qnil;
@@ -6136,14 +6136,15 @@ Control characters in STRING will have terminal-dependent effects. */)
6136{ 6136{
6137 /* ??? Perhaps we should do something special for multibyte strings here. */ 6137 /* ??? Perhaps we should do something special for multibyte strings here. */
6138 CHECK_STRING (string); 6138 CHECK_STRING (string);
6139 fwrite (SDATA (string), 1, SBYTES (string), stdout); 6139 if (TTY_TERMSCRIPT (CURTTY ()))
6140 fflush (stdout);
6141 if (termscript)
6142 { 6140 {
6143 fwrite (SDATA (string), 1, SBYTES (string), 6141 fwrite (SDATA (string), 1, SBYTES (string),
6144 termscript); 6142 TTY_TERMSCRIPT (CURTTY ()));
6145 fflush (termscript); 6143 fflush (TTY_TERMSCRIPT (CURTTY ()));
6146 } 6144 }
6145 fwrite (SDATA (string), 1, SBYTES (string),
6146 TTY_OUTPUT (CURTTY ()));
6147 fflush (TTY_OUTPUT (CURTTY ()));
6147 return Qnil; 6148 return Qnil;
6148} 6149}
6149 6150
@@ -6463,8 +6464,6 @@ the current state. */)
6463 Initialization 6464 Initialization
6464***********************************************************************/ 6465***********************************************************************/
6465 6466
6466char *terminal_type;
6467
6468/* Initialization done when Emacs fork is started, before doing stty. 6467/* Initialization done when Emacs fork is started, before doing stty.
6469 Determine terminal type and set terminal_driver. Then invoke its 6468 Determine terminal type and set terminal_driver. Then invoke its
6470 decoding routine to set up variables in the terminal package. */ 6469 decoding routine to set up variables in the terminal package. */
@@ -6472,6 +6471,8 @@ char *terminal_type;
6472void 6471void
6473init_display () 6472init_display ()
6474{ 6473{
6474 char *terminal_type;
6475
6475#ifdef HAVE_X_WINDOWS 6476#ifdef HAVE_X_WINDOWS
6476 extern int display_arg; 6477 extern int display_arg;
6477#endif 6478#endif
@@ -6593,7 +6594,7 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\
6593 } 6594 }
6594#endif /* VMS */ 6595#endif /* VMS */
6595 6596
6596 term_init (terminal_type); 6597 term_init (0, terminal_type);
6597 6598
6598 { 6599 {
6599 struct frame *sf = SELECTED_FRAME (); 6600 struct frame *sf = SELECTED_FRAME ();
diff --git a/src/emacs.c b/src/emacs.c
index 0b2e678329c..9b07b5a17b2 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1566,7 +1566,7 @@ main (argc, argv
1566#ifdef VMS 1566#ifdef VMS
1567 init_vms_input ();/* init_display calls get_frame_size, that needs this. */ 1567 init_vms_input ();/* init_display calls get_frame_size, that needs this. */
1568#endif /* VMS */ 1568#endif /* VMS */
1569 init_display (); /* Determine terminal type. init_sys_modes uses results. */ 1569 init_display (); /* Determine terminal type. Calls init_sys_modes. */
1570 } 1570 }
1571#ifndef MAC_OS8 1571#ifndef MAC_OS8
1572 /* Called before init_window_once for Mac OS Classic. */ 1572 /* Called before init_window_once for Mac OS Classic. */
@@ -1575,7 +1575,7 @@ main (argc, argv
1575#ifdef VMS 1575#ifdef VMS
1576 init_vmsproc (); /* And this too. */ 1576 init_vmsproc (); /* And this too. */
1577#endif /* VMS */ 1577#endif /* VMS */
1578 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.). */ 1578 /* init_sys_modes (); */ /* Init system terminal modes (RAW or CBREAK, etc.). */
1579#if defined (HAVE_X_WINDOWS) || defined (WINDOWSNT) 1579#if defined (HAVE_X_WINDOWS) || defined (WINDOWSNT)
1580 init_xfns (); 1580 init_xfns ();
1581#endif /* HAVE_X_WINDOWS */ 1581#endif /* HAVE_X_WINDOWS */
@@ -1992,7 +1992,7 @@ shut_down_emacs (sig, no_x, stuff)
1992 && tpgrp == pgrp) 1992 && tpgrp == pgrp)
1993 { 1993 {
1994 fflush (stdout); 1994 fflush (stdout);
1995 reset_sys_modes (); 1995 reset_all_sys_modes ();
1996 if (sig && sig != SIGTERM) 1996 if (sig && sig != SIGTERM)
1997 fprintf (stderr, "Fatal error (%d)", sig); 1997 fprintf (stderr, "Fatal error (%d)", sig);
1998 } 1998 }
diff --git a/src/frame.c b/src/frame.c
index 934c11d98bc..4a97befaf0e 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -42,6 +42,8 @@ Boston, MA 02111-1307, USA. */
42#include "fontset.h" 42#include "fontset.h"
43#endif 43#endif
44#include "blockinput.h" 44#include "blockinput.h"
45#include "systty.h" /* For emacs_tty in termchar.h */
46#include "termchar.h"
45#include "termhooks.h" 47#include "termhooks.h"
46#include "dispextern.h" 48#include "dispextern.h"
47#include "window.h" 49#include "window.h"
@@ -106,6 +108,7 @@ Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
106Lisp_Object Qleft_fringe, Qright_fringe; 108Lisp_Object Qleft_fringe, Qright_fringe;
107Lisp_Object Qbuffer_predicate, Qbuffer_list; 109Lisp_Object Qbuffer_predicate, Qbuffer_list;
108Lisp_Object Qtty_color_mode; 110Lisp_Object Qtty_color_mode;
111Lisp_Object Qtty, Qtty_type;
109 112
110Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth; 113Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
111 114
@@ -180,8 +183,6 @@ set_menu_bar_lines (f, value, oldval)
180Lisp_Object Vemacs_iconified; 183Lisp_Object Vemacs_iconified;
181Lisp_Object Vframe_list; 184Lisp_Object Vframe_list;
182 185
183struct x_output tty_display;
184
185extern Lisp_Object Vminibuffer_list; 186extern Lisp_Object Vminibuffer_list;
186extern Lisp_Object get_minibuffer (); 187extern Lisp_Object get_minibuffer ();
187extern Lisp_Object Fhandle_switch_frame (); 188extern Lisp_Object Fhandle_switch_frame ();
@@ -474,12 +475,14 @@ make_minibuffer_frame ()
474} 475}
475#endif /* HAVE_WINDOW_SYSTEM */ 476#endif /* HAVE_WINDOW_SYSTEM */
476 477
477/* Construct a frame that refers to the terminal (stdin and stdout). */ 478/* Construct a frame that refers to a terminal. */
478 479
479static int terminal_frame_count; 480static int terminal_frame_count;
480 481
481struct frame * 482struct frame *
482make_terminal_frame () 483make_terminal_frame (tty, tty_type)
484 char *tty;
485 char *tty_type;
483{ 486{
484 register struct frame *f; 487 register struct frame *f;
485 Lisp_Object frame; 488 Lisp_Object frame;
@@ -537,12 +540,16 @@ make_terminal_frame ()
537#else 540#else
538#ifdef WINDOWSNT 541#ifdef WINDOWSNT
539 f->output_method = output_termcap; 542 f->output_method = output_termcap;
540 f->output_data.x = &tty_display; 543 f->output_data.x = &tty_display; /* XXX */
541#else 544#else
542#ifdef MAC_OS8 545#ifdef MAC_OS8
543 make_mac_terminal_frame (f); 546 make_mac_terminal_frame (f);
544#else 547#else
545 f->output_data.x = &tty_display; 548 f->output_method = output_termcap;
549 if (initialized)
550 f->output_data.tty = term_init (tty, tty_type);
551 else
552 f->output_data.tty = term_dummy_init ();
546#ifdef CANNOT_DUMP 553#ifdef CANNOT_DUMP
547 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR; 554 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
548 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR; 555 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
@@ -559,11 +566,19 @@ make_terminal_frame ()
559 566
560DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame, 567DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
561 1, 1, 0, 568 1, 1, 0,
562 doc: /* Create an additional terminal frame. 569 doc: /* Create an additional terminal frame, possibly on another terminal.
563You can create multiple frames on a text-only terminal in this way.
564Only the selected terminal frame is actually displayed.
565This function takes one argument, an alist specifying frame parameters. 570This function takes one argument, an alist specifying frame parameters.
566In practice, generally you don't need to specify any parameters. 571
572You can create multiple frames on a single text-only terminal, but
573only one of them (the selected terminal frame) is actually displayed.
574
575In practice, generally you don't need to specify any parameters,
576except when you want to create a new frame on another terminal.
577In that case, the `tty' parameter specifies the device file to open,
578and the `tty-type' parameter specifies the terminal type. Example:
579
580 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
581
567Note that changing the size of one terminal frame automatically affects all. */) 582Note that changing the size of one terminal frame automatically affects all. */)
568 (parms) 583 (parms)
569 Lisp_Object parms; 584 Lisp_Object parms;
@@ -587,7 +602,44 @@ Note that changing the size of one terminal frame automatically affects all. */
587#endif 602#endif
588#endif /* not MSDOS */ 603#endif /* not MSDOS */
589 604
590 f = make_terminal_frame (); 605 {
606 Lisp_Object tty, tty_type;
607 char *name = 0, *type = 0;
608
609 /* XXX Ugh, there must be a better way to do this. */
610 tty = Fassq (Qtty, parms);
611 if (EQ (tty, Qnil))
612 tty = Fassq (Qtty, Vdefault_frame_alist);
613 if (! EQ (tty, Qnil))
614 tty = XCDR (tty);
615 if (EQ (tty, Qnil) || !STRINGP (tty))
616 tty = Qnil;
617
618 tty_type = Fassq (Qtty_type, parms);
619 if (EQ (tty_type, Qnil))
620 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
621 if (! EQ (tty_type, Qnil))
622 tty_type = XCDR (tty_type);
623 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
624 tty_type = Qnil;
625
626 if (! EQ (tty, Qnil))
627 {
628 name = (char *) alloca (SBYTES (tty) + 1);
629 strncpy (name, SDATA (tty), SBYTES (tty));
630 name[SBYTES (tty)] = 0;
631 }
632
633 if (! EQ (tty_type, Qnil))
634 {
635 type = (char *) alloca (SBYTES (tty_type) + 1);
636 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
637 type[SBYTES (tty_type)] = 0;
638 }
639
640
641 f = make_terminal_frame (name, type);
642 }
591 643
592 change_frame_size (f, FRAME_LINES (sf), 644 change_frame_size (f, FRAME_LINES (sf),
593 FRAME_COLS (sf), 0, 0, 0); 645 FRAME_COLS (sf), 0, 0, 0);
@@ -3937,6 +3989,10 @@ syms_of_frame ()
3937 staticpro (&Qbackground_mode); 3989 staticpro (&Qbackground_mode);
3938 Qtty_color_mode = intern ("tty-color-mode"); 3990 Qtty_color_mode = intern ("tty-color-mode");
3939 staticpro (&Qtty_color_mode); 3991 staticpro (&Qtty_color_mode);
3992 Qtty = intern ("tty");
3993 staticpro (&Qtty);
3994 Qtty_type = intern ("tty-type");
3995 staticpro (&Qtty_type);
3940 3996
3941 Qface_set_after_frame_default = intern ("face-set-after-frame-default"); 3997 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
3942 staticpro (&Qface_set_after_frame_default); 3998 staticpro (&Qface_set_after_frame_default);
diff --git a/src/frame.h b/src/frame.h
index 30d3f4348e9..6d7f1fffa80 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -84,11 +84,15 @@ struct x_output
84#endif /* ! HAVE_X_WINDOWS */ 84#endif /* ! HAVE_X_WINDOWS */
85 85
86 86
87#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) 87#define FRAME_FOREGROUND_PIXEL(f) \
88#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel) 88 (((f)->output_method == output_termcap) \
89 ? ((f)->output_data.tty->foreground_pixel) \
90 : ((f)->output_data.x->foreground_pixel))
89 91
90/* A structure describing a termcap frame display. */ 92#define FRAME_BACKGROUND_PIXEL(f) \
91extern struct x_output tty_display; 93 (((f)->output_method == output_termcap) \
94 ? ((f)->output_data.tty->background_pixel) \
95 : ((f)->output_data.x->background_pixel))
92 96
93#endif /* ! MSDOS && ! WINDOWSNT && ! MAC_OS */ 97#endif /* ! MSDOS && ! WINDOWSNT && ! MAC_OS */
94 98
@@ -283,12 +287,15 @@ struct frame
283 enum output_method output_method; 287 enum output_method output_method;
284 288
285 /* A structure of auxiliary data used for displaying the contents. 289 /* A structure of auxiliary data used for displaying the contents.
290 struct tty_output is used for terminal frames;
291 it is defined in term.h.
286 struct x_output is used for X window frames; 292 struct x_output is used for X window frames;
287 it is defined in xterm.h. 293 it is defined in xterm.h.
288 struct w32_output is used for W32 window frames; 294 struct w32_output is used for W32 window frames;
289 it is defined in w32term.h. */ 295 it is defined in w32term.h. */
290 union output_data 296 union output_data
291 { 297 {
298 struct tty_output *tty;
292 struct x_output *x; 299 struct x_output *x;
293 struct w32_output *w32; 300 struct w32_output *w32;
294 struct mac_output *mac; 301 struct mac_output *mac;
@@ -779,7 +786,7 @@ extern Lisp_Object Qframep, Qframe_live_p;
779 786
780extern struct frame *last_nonminibuf_frame; 787extern struct frame *last_nonminibuf_frame;
781 788
782extern struct frame *make_terminal_frame P_ ((void)); 789extern struct frame *make_terminal_frame P_ ((char *tty, char *tty_type));
783extern struct frame *make_frame P_ ((int)); 790extern struct frame *make_frame P_ ((int));
784#ifdef HAVE_WINDOW_SYSTEM 791#ifdef HAVE_WINDOW_SYSTEM
785extern struct frame *make_minibuffer_frame P_ ((void)); 792extern struct frame *make_minibuffer_frame P_ ((void));
diff --git a/src/indent.c b/src/indent.c
index 0d9fe9aaf9c..bc32aa1f407 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -28,6 +28,7 @@ Boston, MA 02111-1307, USA. */
28#include "keyboard.h" 28#include "keyboard.h"
29#include "frame.h" 29#include "frame.h"
30#include "window.h" 30#include "window.h"
31#include "systty.h" /* For emacs_tty in termchar.h */
31#include "termchar.h" 32#include "termchar.h"
32#include "termopts.h" 33#include "termopts.h"
33#include "disptab.h" 34#include "disptab.h"
diff --git a/src/keyboard.c b/src/keyboard.c
index 6148a2510b8..dd4619d7967 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -22,6 +22,7 @@ Boston, MA 02111-1307, USA. */
22#include <config.h> 22#include <config.h>
23#include <signal.h> 23#include <signal.h>
24#include <stdio.h> 24#include <stdio.h>
25#include "systty.h" /* This must be included befor termchar.h. */
25#include "termchar.h" 26#include "termchar.h"
26#include "termopts.h" 27#include "termopts.h"
27#include "lisp.h" 28#include "lisp.h"
@@ -55,7 +56,6 @@ Boston, MA 02111-1307, USA. */
55#endif /* not MSDOS */ 56#endif /* not MSDOS */
56 57
57#include "syssignal.h" 58#include "syssignal.h"
58#include "systty.h"
59 59
60#include <sys/types.h> 60#include <sys/types.h>
61#ifdef HAVE_UNISTD_H 61#ifdef HAVE_UNISTD_H
@@ -10067,7 +10067,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10067 10067
10068 GCPRO1 (stuffstring); 10068 GCPRO1 (stuffstring);
10069 get_frame_size (&old_width, &old_height); 10069 get_frame_size (&old_width, &old_height);
10070 reset_sys_modes (); 10070 reset_all_sys_modes ();
10071 /* sys_suspend can get an error if it tries to fork a subshell 10071 /* sys_suspend can get an error if it tries to fork a subshell
10072 and the system resources aren't available for that. */ 10072 and the system resources aren't available for that. */
10073 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, 10073 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes,
@@ -10206,7 +10206,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10206 sigblock (sigmask (SIGINT)); 10206 sigblock (sigmask (SIGINT));
10207 10207
10208 fflush (stdout); 10208 fflush (stdout);
10209 reset_sys_modes (); 10209 reset_all_sys_modes ();
10210 10210
10211#ifdef SIGTSTP /* Support possible in later USG versions */ 10211#ifdef SIGTSTP /* Support possible in later USG versions */
10212/* 10212/*
@@ -10285,7 +10285,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10285 printf ("Continuing...\n"); 10285 printf ("Continuing...\n");
10286#endif /* not MSDOS */ 10286#endif /* not MSDOS */
10287 fflush (stdout); 10287 fflush (stdout);
10288 init_sys_modes (); 10288 init_all_sys_modes ();
10289 sigfree (); 10289 sigfree ();
10290 } 10290 }
10291 else 10291 else
@@ -10372,7 +10372,7 @@ See also `current-input-mode'. */)
10372 10372
10373#ifndef DOS_NT 10373#ifndef DOS_NT
10374 /* this causes startup screen to be restored and messes with the mouse */ 10374 /* this causes startup screen to be restored and messes with the mouse */
10375 reset_sys_modes (); 10375 reset_all_sys_modes ();
10376#endif 10376#endif
10377 10377
10378#ifdef SIGIO 10378#ifdef SIGIO
@@ -10410,7 +10410,7 @@ See also `current-input-mode'. */)
10410 quit_char = XINT (quit) & (meta_key ? 0377 : 0177); 10410 quit_char = XINT (quit) & (meta_key ? 0377 : 0177);
10411 10411
10412#ifndef DOS_NT 10412#ifndef DOS_NT
10413 init_sys_modes (); 10413 init_all_sys_modes ();
10414#endif 10414#endif
10415 10415
10416#ifdef POLL_FOR_INPUT 10416#ifdef POLL_FOR_INPUT
diff --git a/src/lisp.h b/src/lisp.h
index 94de2c2960f..2c30549d53b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2931,17 +2931,21 @@ EXFUN (Fx_popup_menu, 2);
2931EXFUN (Fx_popup_dialog, 2); 2931EXFUN (Fx_popup_dialog, 2);
2932extern void syms_of_xmenu P_ ((void)); 2932extern void syms_of_xmenu P_ ((void));
2933 2933
2934/* defined in termchar.h */
2935struct tty_output;
2936
2934/* defined in sysdep.c */ 2937/* defined in sysdep.c */
2935extern void stuff_char P_ ((char c)); 2938extern void stuff_char P_ ((char c));
2936extern void init_sigio P_ ((int)); 2939extern void init_sigio P_ ((int));
2937extern void request_sigio P_ ((void)); 2940extern void request_sigio P_ ((void));
2938extern void unrequest_sigio P_ ((void)); 2941extern void unrequest_sigio P_ ((void));
2939extern void reset_sys_modes P_ ((void));
2940extern void sys_subshell P_ ((void)); 2942extern void sys_subshell P_ ((void));
2941extern void sys_suspend P_ ((void)); 2943extern void sys_suspend P_ ((void));
2942extern void discard_tty_input P_ ((void)); 2944extern void discard_tty_input P_ ((void));
2943extern void init_sys_modes P_ ((void)); 2945extern void init_sys_modes P_ ((struct tty_output *));
2944extern void reset_sys_modes P_ ((void)); 2946extern void reset_sys_modes P_ ((struct tty_output *));
2947extern void init_all_sys_modes P_ ((void));
2948extern void reset_all_sys_modes P_ ((void));
2945extern void get_frame_size P_ ((int *, int *)); 2949extern void get_frame_size P_ ((int *, int *));
2946extern void wait_for_termination P_ ((int)); 2950extern void wait_for_termination P_ ((int));
2947extern void flush_pending_output P_ ((int)); 2951extern void flush_pending_output P_ ((int));
diff --git a/src/macterm.c b/src/macterm.c
index 7d27e5430eb..dd031919a1f 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -8674,11 +8674,11 @@ mac_initialize ()
8674 redeem_scroll_bar_hook = XTredeem_scroll_bar; 8674 redeem_scroll_bar_hook = XTredeem_scroll_bar;
8675 judge_scroll_bars_hook = XTjudge_scroll_bars; 8675 judge_scroll_bars_hook = XTjudge_scroll_bars;
8676 8676
8677 TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) = 1; /* we'll scroll partial frames */ 8677 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
8678 TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) = 1; 8678 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
8679 TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ()) = 1; /* we'll just blt 'em */ 8679 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
8680 TERMINAL_FAST_CLEAR_END_OF_LINE (CURRENT_TERMINAL ()) = 1; /* X does this well */ 8680 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
8681 TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ()) = 0; /* we don't remember what 8681 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
8682 scrolls off the 8682 scrolls off the
8683 bottom */ 8683 bottom */
8684 baud_rate = 19200; 8684 baud_rate = 19200;
diff --git a/src/macterm.h b/src/macterm.h
index b3fe53c86ea..212119e08b2 100644
--- a/src/macterm.h
+++ b/src/macterm.h
@@ -406,9 +406,6 @@ typedef struct mac_output mac_output;
406#define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->mWP) 406#define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->mWP)
407#define FRAME_X_WINDOW(f) ((f)->output_data.mac->mWP) 407#define FRAME_X_WINDOW(f) ((f)->output_data.mac->mWP)
408 408
409#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
410#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
411
412#define FRAME_FONT(f) ((f)->output_data.mac->font) 409#define FRAME_FONT(f) ((f)->output_data.mac->font)
413#define FRAME_FONTSET(f) ((f)->output_data.mac->fontset) 410#define FRAME_FONTSET(f) ((f)->output_data.mac->fontset)
414 411
diff --git a/src/msdos.c b/src/msdos.c
index 103094141bf..da6bfef0659 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -2580,7 +2580,7 @@ internal_terminal_init ()
2580 set_terminal_modes_hook = IT_set_terminal_modes; 2580 set_terminal_modes_hook = IT_set_terminal_modes;
2581 reset_terminal_modes_hook = IT_reset_terminal_modes; 2581 reset_terminal_modes_hook = IT_reset_terminal_modes;
2582 set_terminal_window_hook = IT_set_terminal_window; 2582 set_terminal_window_hook = IT_set_terminal_window;
2583 TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) = 0; 2583 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 0;
2584#endif 2584#endif
2585} 2585}
2586 2586
diff --git a/src/print.c b/src/print.c
index 441894471a7..af76616e42b 100644
--- a/src/print.c
+++ b/src/print.c
@@ -30,6 +30,7 @@ Boston, MA 02111-1307, USA. */
30#include "window.h" 30#include "window.h"
31#include "process.h" 31#include "process.h"
32#include "dispextern.h" 32#include "dispextern.h"
33#include "systty.h" /* For emacs_tty in termchar.h */
33#include "termchar.h" 34#include "termchar.h"
34#include "intervals.h" 35#include "intervals.h"
35 36
diff --git a/src/scroll.c b/src/scroll.c
index a786d3c2cf4..f4faca2fad8 100644
--- a/src/scroll.c
+++ b/src/scroll.c
@@ -22,6 +22,7 @@ Boston, MA 02111-1307, USA. */
22#include <config.h> 22#include <config.h>
23#include <stdio.h> 23#include <stdio.h>
24#include <string.h> 24#include <string.h>
25#include "systty.h" /* For emacs_tty in termchar.h */
25#include "termchar.h" 26#include "termchar.h"
26#include "lisp.h" 27#include "lisp.h"
27#include "dispextern.h" 28#include "dispextern.h"
@@ -101,7 +102,7 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
101 register int cost, cost1; 102 register int cost, cost1;
102 103
103 int lines_moved = window_size 104 int lines_moved = window_size
104 + (TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) ? 0 : lines_below); 105 + (TTY_SCROLL_REGION_OK (FRAME_TTY (frame)) ? 0 : lines_below);
105 /* first_insert_cost[I] is the cost of doing the first insert-line 106 /* first_insert_cost[I] is the cost of doing the first insert-line
106 at the i'th line of the lines we are considering, 107 at the i'th line of the lines we are considering,
107 where I is origin 1 (as it is below). */ 108 where I is origin 1 (as it is below). */
@@ -468,7 +469,7 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
468 cost of scrolling by a distance of one. The extra cost is 469 cost of scrolling by a distance of one. The extra cost is
469 added once for consistency with the cost vectors */ 470 added once for consistency with the cost vectors */
470 scroll_overhead 471 scroll_overhead
471 = TERMINAL_SCROLL_REGION_COST (CURRENT_TERMINAL ()) + extra_cost; 472 = TTY_SCROLL_REGION_COST (FRAME_TTY (frame)) + extra_cost;
472 473
473 /* initialize the top left corner of the matrix */ 474 /* initialize the top left corner of the matrix */
474 matrix->writecost = 0; 475 matrix->writecost = 0;
@@ -820,7 +821,7 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
820 matrix = ((struct matrix_elt *) 821 matrix = ((struct matrix_elt *)
821 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix)); 822 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
822 823
823 if (TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ())) 824 if (TTY_SCROLL_REGION_OK (FRAME_TTY (frame)))
824 { 825 {
825 calculate_direct_scrolling (frame, matrix, window_size, 826 calculate_direct_scrolling (frame, matrix, window_size,
826 unchanged_at_bottom, 827 unchanged_at_bottom,
@@ -916,7 +917,7 @@ scroll_cost (frame, from, to, amount)
916 if (amount == 0) 917 if (amount == 0)
917 return 0; 918 return 0;
918 919
919 if (! TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ())) 920 if (! TTY_SCROLL_REGION_OK (FRAME_TTY (frame)))
920 limit = height; 921 limit = height;
921 else if (amount > 0) 922 else if (amount > 0)
922 limit += amount; 923 limit += amount;
diff --git a/src/sysdep.c b/src/sysdep.c
index b83e01635cc..7573cc4b9de 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1255,14 +1255,6 @@ emacs_set_tty (fd, settings, flushp)
1255} 1255}
1256 1256
1257 1257
1258/* The initial tty mode bits */
1259struct emacs_tty old_tty;
1260
1261/* 1 if we have been through init_sys_modes. */
1262int term_initted;
1263
1264/* 1 if outer tty status has been recorded. */
1265int old_tty_valid;
1266 1258
1267#ifdef BSD4_1 1259#ifdef BSD4_1
1268/* BSD 4.1 needs to keep track of the lmode bits in order to start 1260/* BSD 4.1 needs to keep track of the lmode bits in order to start
@@ -1298,7 +1290,18 @@ static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
1298#endif 1290#endif
1299 1291
1300void 1292void
1301init_sys_modes () 1293init_all_sys_modes (void)
1294{
1295 struct tty_output *tty = tty_list;
1296 while (tty) {
1297 init_sys_modes (tty);
1298 tty = tty->next;
1299 }
1300}
1301
1302void
1303init_sys_modes (otty)
1304 struct tty_output *otty;
1302{ 1305{
1303 struct emacs_tty tty; 1306 struct emacs_tty tty;
1304 1307
@@ -1367,14 +1370,14 @@ nil means don't delete them until `list-processes' is run. */);
1367 if (!read_socket_hook && EQ (Vwindow_system, Qnil)) 1370 if (!read_socket_hook && EQ (Vwindow_system, Qnil))
1368#endif 1371#endif
1369 { 1372 {
1370 EMACS_GET_TTY (input_fd, &old_tty); 1373 EMACS_GET_TTY (input_fd, &otty->old_tty);
1371 1374
1372 old_tty_valid = 1; 1375 otty->old_tty_valid = 1;
1373 1376
1374 tty = old_tty; 1377 tty = otty->old_tty;
1375 1378
1376#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 1379#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1377 XSETINT (Vtty_erase_char, old_tty.main.c_cc[VERASE]); 1380 XSETINT (Vtty_erase_char, otty->old_tty.main.c_cc[VERASE]);
1378 1381
1379#ifdef DGUX 1382#ifdef DGUX
1380 /* This allows meta to be sent on 8th bit. */ 1383 /* This allows meta to be sent on 8th bit. */
@@ -1539,7 +1542,7 @@ nil means don't delete them until `list-processes' is run. */);
1539 tty.tchars.t_stopc = '\023'; 1542 tty.tchars.t_stopc = '\023';
1540 } 1543 }
1541 1544
1542 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | old_tty.lmode; 1545 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | otty->old_tty.lmode;
1543#ifdef ultrix 1546#ifdef ultrix
1544 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt 1547 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1545 anything, and leaving it in breaks the meta key. Go figure. */ 1548 anything, and leaving it in breaks the meta key. Go figure. */
@@ -1557,7 +1560,7 @@ nil means don't delete them until `list-processes' is run. */);
1557 tty.ltchars = new_ltchars; 1560 tty.ltchars = new_ltchars;
1558#endif /* HAVE_LTCHARS */ 1561#endif /* HAVE_LTCHARS */
1559#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */ 1562#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1560 if (!term_initted) 1563 if (!otty->term_initted)
1561 internal_terminal_init (); 1564 internal_terminal_init ();
1562 dos_ttraw (); 1565 dos_ttraw ();
1563#endif 1566#endif
@@ -1646,14 +1649,14 @@ nil means don't delete them until `list-processes' is run. */);
1646#endif 1649#endif
1647 ) 1650 )
1648#endif 1651#endif
1649 set_terminal_modes (); 1652 set_terminal_modes (otty);
1650 1653
1651 if (!term_initted 1654 if (!otty->term_initted
1652 && FRAMEP (Vterminal_frame) 1655 && FRAMEP (Vterminal_frame)
1653 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame))) 1656 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame)))
1654 init_frame_faces (XFRAME (Vterminal_frame)); 1657 init_frame_faces (XFRAME (Vterminal_frame));
1655 1658
1656 if (term_initted && no_redraw_on_reenter) 1659 if (otty->term_initted && no_redraw_on_reenter)
1657 { 1660 {
1658 if (display_completed) 1661 if (display_completed)
1659 direct_output_forward_char (0); 1662 direct_output_forward_char (0);
@@ -1665,7 +1668,7 @@ nil means don't delete them until `list-processes' is run. */);
1665 FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1; 1668 FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1;
1666 } 1669 }
1667 1670
1668 term_initted = 1; 1671 otty->term_initted = 1;
1669} 1672}
1670 1673
1671/* Return nonzero if safe to use tabs in output. 1674/* Return nonzero if safe to use tabs in output.
@@ -1778,10 +1781,21 @@ set_window_size (fd, height, width)
1778} 1781}
1779 1782
1780 1783
1784void
1785reset_all_sys_modes (void)
1786{
1787 struct tty_output *tty = tty_list;
1788 while (tty) {
1789 reset_sys_modes (tty);
1790 tty = tty->next;
1791 }
1792}
1793
1781/* Prepare the terminal for exiting Emacs; move the cursor to the 1794/* Prepare the terminal for exiting Emacs; move the cursor to the
1782 bottom of the frame, turn off interrupt-driven I/O, etc. */ 1795 bottom of the frame, turn off interrupt-driven I/O, etc. */
1783void 1796void
1784reset_sys_modes () 1797reset_sys_modes (otty)
1798 struct tty_output *otty;
1785{ 1799{
1786 struct frame *sf; 1800 struct frame *sf;
1787 1801
@@ -1790,7 +1804,7 @@ reset_sys_modes ()
1790 fflush (stdout); 1804 fflush (stdout);
1791 return; 1805 return;
1792 } 1806 }
1793 if (!term_initted) 1807 if (!otty->term_initted)
1794 return; 1808 return;
1795#ifdef HAVE_WINDOW_SYSTEM 1809#ifdef HAVE_WINDOW_SYSTEM
1796 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore 1810 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
@@ -1820,7 +1834,7 @@ reset_sys_modes ()
1820 } 1834 }
1821#endif 1835#endif
1822 1836
1823 reset_terminal_modes (); 1837 reset_terminal_modes (otty);
1824 fflush (stdout); 1838 fflush (stdout);
1825#ifdef BSD_SYSTEM 1839#ifdef BSD_SYSTEM
1826#ifndef BSD4_1 1840#ifndef BSD4_1
@@ -1848,8 +1862,8 @@ reset_sys_modes ()
1848 reset_sigio (); 1862 reset_sigio ();
1849#endif /* BSD4_1 */ 1863#endif /* BSD4_1 */
1850 1864
1851 if (old_tty_valid) 1865 if (otty->old_tty_valid)
1852 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) 1866 while (EMACS_SET_TTY (input_fd, &otty->old_tty, 0) < 0 && errno == EINTR)
1853 ; 1867 ;
1854 1868
1855#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ 1869#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
@@ -1860,7 +1874,7 @@ reset_sys_modes ()
1860 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. 1874 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1861 A different old line discipline is therefore not restored, yet. 1875 A different old line discipline is therefore not restored, yet.
1862 Restore the old line discipline by hand. */ 1876 Restore the old line discipline by hand. */
1863 ioctl (0, TIOCSETD, &old_tty.main.c_line); 1877 ioctl (0, TIOCSETD, &otty->old_tty.main.c_line);
1864#endif 1878#endif
1865 1879
1866#ifdef AIXHFT 1880#ifdef AIXHFT
@@ -3470,7 +3484,7 @@ croak (badfunc)
3470 char *badfunc; 3484 char *badfunc;
3471{ 3485{
3472 printf ("%s not yet implemented\r\n", badfunc); 3486 printf ("%s not yet implemented\r\n", badfunc);
3473 reset_sys_modes (); 3487 reset_all_sys_modes ();
3474 exit (1); 3488 exit (1);
3475} 3489}
3476 3490
@@ -5056,7 +5070,7 @@ croak (badfunc)
5056 char *badfunc; 5070 char *badfunc;
5057{ 5071{
5058 printf ("%s not yet implemented\r\n", badfunc); 5072 printf ("%s not yet implemented\r\n", badfunc);
5059 reset_sys_modes (); 5073 reset_all_sys_modes ();
5060 exit (1); 5074 exit (1);
5061} 5075}
5062 5076
@@ -5126,8 +5140,8 @@ hft_init ()
5126 } 5140 }
5127 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly 5141 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5128 at times. */ 5142 at times. */
5129 TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ()) = 0; 5143 TTY_LINE_INS_DEL_OK (CURTTY ()) = 0;
5130 TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) = 0; 5144 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 0;
5131} 5145}
5132 5146
5133/* Reset the rubout key to backspace. */ 5147/* Reset the rubout key to backspace. */
diff --git a/src/term.c b/src/term.c
index 50d47a1dac1..5739cd0d19a 100644
--- a/src/term.c
+++ b/src/term.c
@@ -26,6 +26,9 @@ Boston, MA 02111-1307, USA. */
26#include <ctype.h> 26#include <ctype.h>
27#include <string.h> 27#include <string.h>
28 28
29#include <sys/file.h>
30
31#include "systty.h" /* For emacs_tty in termchar.h */
29#include "termchar.h" 32#include "termchar.h"
30#include "termopts.h" 33#include "termopts.h"
31#include "lisp.h" 34#include "lisp.h"
@@ -60,32 +63,36 @@ extern int tgetnum P_ ((char *id));
60#include "macterm.h" 63#include "macterm.h"
61#endif 64#endif
62 65
66#ifndef O_RDWR
67#define O_RDWR 2
68#endif
69
63static void turn_on_face P_ ((struct frame *, int face_id)); 70static void turn_on_face P_ ((struct frame *, int face_id));
64static void turn_off_face P_ ((struct frame *, int face_id)); 71static void turn_off_face P_ ((struct frame *, int face_id));
65static void tty_show_cursor P_ ((void)); 72static void tty_show_cursor P_ ((void));
66static void tty_hide_cursor P_ ((void)); 73static void tty_hide_cursor P_ ((void));
67 74
68#define OUTPUT(a) \ 75#define OUTPUT(tty, a) \
69 tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc) 76 emacs_tputs ((tty), a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc)
70#define OUTPUT1(a) tputs (a, 1, cmputc) 77#define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
71#define OUTPUTL(a, lines) tputs (a, lines, cmputc) 78#define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
72 79
73#define OUTPUT_IF(a) \ 80#define OUTPUT_IF(tty, a) \
74 do { \ 81 do { \
75 if (a) \ 82 if (a) \
76 tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) \ 83 emacs_tputs ((tty), a, (int) (FRAME_LINES (XFRAME (selected_frame)) \
77 - curY), cmputc); \ 84 - curY), cmputc); \
78 } while (0) 85 } while (0)
79 86
80#define OUTPUT1_IF(a) do { if (a) tputs (a, 1, cmputc); } while (0) 87#define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
81 88
82/* Function to use to ring the bell. */ 89/* Function to use to ring the bell. */
83 90
84Lisp_Object Vring_bell_function; 91Lisp_Object Vring_bell_function;
85 92
86/* Terminal characteristics that higher levels want to look at. */ 93/* Terminal characteristics that higher levels want to look at. */
87static struct terminal _current_terminal; 94
88TERMINAL_PTR current_terminal = &_current_terminal; 95struct tty_output *tty_list;
89 96
90/* Nonzero means no need to redraw the entire frame on resuming 97/* Nonzero means no need to redraw the entire frame on resuming
91 a suspended Emacs. This is useful on terminals with multiple pages, 98 a suspended Emacs. This is useful on terminals with multiple pages,
@@ -421,18 +428,19 @@ ring_bell ()
421 } 428 }
422 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame))) 429 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame)))
423 (*ring_bell_hook) (); 430 (*ring_bell_hook) ();
424 else 431 else {
425 OUTPUT (TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell); 432 OUTPUT (CURTTY (), TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell);
433 }
426} 434}
427 435
428void 436void
429set_terminal_modes () 437set_terminal_modes (struct tty_output *tty)
430{ 438{
431 if (FRAME_TERMCAP_P (XFRAME (selected_frame))) 439 if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
432 { 440 {
433 OUTPUT_IF (TS_termcap_modes); 441 OUTPUT_IF (tty, TS_termcap_modes);
434 OUTPUT_IF (TS_cursor_visible); 442 OUTPUT_IF (tty, TS_cursor_visible);
435 OUTPUT_IF (TS_keypad_mode); 443 OUTPUT_IF (tty, TS_keypad_mode);
436 losecursor (); 444 losecursor ();
437 } 445 }
438 else 446 else
@@ -440,17 +448,18 @@ set_terminal_modes ()
440} 448}
441 449
442void 450void
443reset_terminal_modes () 451reset_terminal_modes (struct tty_output *tty)
444{ 452{
445 if (FRAME_TERMCAP_P (XFRAME (selected_frame))) 453 if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
446 { 454 {
447 turn_off_highlight (); 455 turn_off_highlight ();
448 turn_off_insert (); 456 turn_off_insert ();
449 OUTPUT_IF (TS_end_keypad_mode); 457 OUTPUT_IF (tty, TS_end_keypad_mode);
450 OUTPUT_IF (TS_cursor_normal); 458 OUTPUT_IF (tty, TS_cursor_normal);
451 OUTPUT_IF (TS_end_termcap_modes); 459 OUTPUT_IF (tty, TS_end_termcap_modes);
452 OUTPUT_IF (TS_orig_pair); 460 OUTPUT_IF (tty, TS_orig_pair);
453 /* Output raw CR so kernel can track the cursor hpos. */ 461 /* Output raw CR so kernel can track the cursor hpos. */
462 current_tty = tty;
454 cmputc ('\r'); 463 cmputc ('\r');
455 } 464 }
456 else if (reset_terminal_modes_hook) 465 else if (reset_terminal_modes_hook)
@@ -490,7 +499,7 @@ set_terminal_window (size)
490 if (FRAME_TERMCAP_P (updating_frame)) 499 if (FRAME_TERMCAP_P (updating_frame))
491 { 500 {
492 specified_window = size ? size : FRAME_LINES (updating_frame); 501 specified_window = size ? size : FRAME_LINES (updating_frame);
493 if (TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ())) 502 if (TTY_SCROLL_REGION_OK (FRAME_TTY (updating_frame)))
494 set_scroll_region (0, specified_window); 503 set_scroll_region (0, specified_window);
495 } 504 }
496 else 505 else
@@ -514,7 +523,7 @@ set_scroll_region (start, stop)
514 else 523 else
515 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (sf)); 524 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (sf));
516 525
517 OUTPUT (buf); 526 OUTPUT (CURTTY (), buf);
518 xfree (buf); 527 xfree (buf);
519 losecursor (); 528 losecursor ();
520} 529}
@@ -524,7 +533,7 @@ static void
524turn_on_insert () 533turn_on_insert ()
525{ 534{
526 if (!insert_mode) 535 if (!insert_mode)
527 OUTPUT (TS_insert_mode); 536 OUTPUT (CURTTY (), TS_insert_mode);
528 insert_mode = 1; 537 insert_mode = 1;
529} 538}
530 539
@@ -532,7 +541,7 @@ void
532turn_off_insert () 541turn_off_insert ()
533{ 542{
534 if (insert_mode) 543 if (insert_mode)
535 OUTPUT (TS_end_insert_mode); 544 OUTPUT (CURTTY (), TS_end_insert_mode);
536 insert_mode = 0; 545 insert_mode = 0;
537} 546}
538 547
@@ -542,7 +551,7 @@ void
542turn_off_highlight () 551turn_off_highlight ()
543{ 552{
544 if (standout_mode) 553 if (standout_mode)
545 OUTPUT_IF (TS_end_standout_mode); 554 OUTPUT_IF (CURTTY (), TS_end_standout_mode);
546 standout_mode = 0; 555 standout_mode = 0;
547} 556}
548 557
@@ -550,7 +559,7 @@ static void
550turn_on_highlight () 559turn_on_highlight ()
551{ 560{
552 if (!standout_mode) 561 if (!standout_mode)
553 OUTPUT_IF (TS_standout_mode); 562 OUTPUT_IF (CURTTY(), TS_standout_mode);
554 standout_mode = 1; 563 standout_mode = 1;
555} 564}
556 565
@@ -572,7 +581,7 @@ tty_hide_cursor ()
572 if (tty_cursor_hidden == 0) 581 if (tty_cursor_hidden == 0)
573 { 582 {
574 tty_cursor_hidden = 1; 583 tty_cursor_hidden = 1;
575 OUTPUT_IF (TS_cursor_invisible); 584 OUTPUT_IF (CURTTY (), TS_cursor_invisible);
576 } 585 }
577} 586}
578 587
@@ -585,8 +594,8 @@ tty_show_cursor ()
585 if (tty_cursor_hidden) 594 if (tty_cursor_hidden)
586 { 595 {
587 tty_cursor_hidden = 0; 596 tty_cursor_hidden = 0;
588 OUTPUT_IF (TS_cursor_normal); 597 OUTPUT_IF (CURTTY (), TS_cursor_normal);
589 OUTPUT_IF (TS_cursor_visible); 598 OUTPUT_IF (CURTTY (), TS_cursor_visible);
590 } 599 }
591} 600}
592 601
@@ -642,7 +651,7 @@ cursor_to (vpos, hpos)
642 background_highlight (); 651 background_highlight ();
643 if (!TF_insmode_motion) 652 if (!TF_insmode_motion)
644 turn_off_insert (); 653 turn_off_insert ();
645 cmgoto (vpos, hpos); 654 cmgoto (FRAME_TTY (f), vpos, hpos);
646} 655}
647 656
648/* Similar but don't take any account of the wasted characters. */ 657/* Similar but don't take any account of the wasted characters. */
@@ -663,7 +672,7 @@ raw_cursor_to (row, col)
663 background_highlight (); 672 background_highlight ();
664 if (!TF_insmode_motion) 673 if (!TF_insmode_motion)
665 turn_off_insert (); 674 turn_off_insert ();
666 cmgoto (row, col); 675 cmgoto (FRAME_TTY (f), row, col);
667} 676}
668 677
669/* Erase operations */ 678/* Erase operations */
@@ -682,7 +691,7 @@ clear_to_end ()
682 if (TS_clr_to_bottom) 691 if (TS_clr_to_bottom)
683 { 692 {
684 background_highlight (); 693 background_highlight ();
685 OUTPUT (TS_clr_to_bottom); 694 OUTPUT (CURTTY (), TS_clr_to_bottom);
686 } 695 }
687 else 696 else
688 { 697 {
@@ -710,7 +719,7 @@ clear_frame ()
710 if (TS_clr_frame) 719 if (TS_clr_frame)
711 { 720 {
712 background_highlight (); 721 background_highlight ();
713 OUTPUT (TS_clr_frame); 722 OUTPUT (FRAME_TTY (updating_frame ? updating_frame : sf), TS_clr_frame);
714 cmat (0, 0); 723 cmat (0, 0);
715 } 724 }
716 else 725 else
@@ -750,7 +759,7 @@ clear_end_of_line (first_unused_hpos)
750 background_highlight (); 759 background_highlight ();
751 if (TS_clr_line) 760 if (TS_clr_line)
752 { 761 {
753 OUTPUT1 (TS_clr_line); 762 OUTPUT1 (CURTTY (), TS_clr_line);
754 } 763 }
755 else 764 else
756 { /* have to do it the hard way */ 765 { /* have to do it the hard way */
@@ -764,9 +773,9 @@ clear_end_of_line (first_unused_hpos)
764 773
765 for (i = curX; i < first_unused_hpos; i++) 774 for (i = curX; i < first_unused_hpos; i++)
766 { 775 {
767 if (termscript) 776 if (TTY_TERMSCRIPT (CURTTY ()))
768 fputc (' ', termscript); 777 fputc (' ', TTY_TERMSCRIPT (CURTTY ()));
769 putchar (' '); 778 fputc (' ', TTY_OUTPUT (CURTTY ()));
770 } 779 }
771 cmplus (first_unused_hpos - curX); 780 cmplus (first_unused_hpos - curX);
772 } 781 }
@@ -942,11 +951,13 @@ write_glyphs (string, len)
942 &consumed); 951 &consumed);
943 if (produced > 0) 952 if (produced > 0)
944 { 953 {
945 fwrite (conversion_buffer, 1, produced, stdout); 954 fwrite (conversion_buffer, 1, produced,
946 if (ferror (stdout)) 955 TTY_OUTPUT (FRAME_TTY (f)));
947 clearerr (stdout); 956 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
948 if (termscript) 957 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
949 fwrite (conversion_buffer, 1, produced, termscript); 958 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
959 fwrite (conversion_buffer, 1, produced,
960 TTY_TERMSCRIPT (FRAME_TTY (f)));
950 } 961 }
951 len -= consumed; 962 len -= consumed;
952 n -= consumed; 963 n -= consumed;
@@ -966,16 +977,17 @@ write_glyphs (string, len)
966 0, conversion_buffer_size); 977 0, conversion_buffer_size);
967 if (terminal_coding.produced > 0) 978 if (terminal_coding.produced > 0)
968 { 979 {
969 fwrite (conversion_buffer, 1, terminal_coding.produced, stdout); 980 fwrite (conversion_buffer, 1, terminal_coding.produced,
970 if (ferror (stdout)) 981 TTY_OUTPUT (FRAME_TTY (f)));
971 clearerr (stdout); 982 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
972 if (termscript) 983 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
984 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
973 fwrite (conversion_buffer, 1, terminal_coding.produced, 985 fwrite (conversion_buffer, 1, terminal_coding.produced,
974 termscript); 986 TTY_TERMSCRIPT (FRAME_TTY (f)));
975 } 987 }
976 } 988 }
977 989
978 cmcheckmagic (); 990 cmcheckmagic (FRAME_TTY (f));
979} 991}
980 992
981/* If start is zero, insert blanks instead of a string at start */ 993/* If start is zero, insert blanks instead of a string at start */
@@ -1004,7 +1016,7 @@ insert_glyphs (start, len)
1004 if (TS_ins_multi_chars) 1016 if (TS_ins_multi_chars)
1005 { 1017 {
1006 buf = tparam (TS_ins_multi_chars, 0, 0, len); 1018 buf = tparam (TS_ins_multi_chars, 0, 0, len);
1007 OUTPUT1 (buf); 1019 OUTPUT1 (FRAME_TTY (f), buf);
1008 xfree (buf); 1020 xfree (buf);
1009 if (start) 1021 if (start)
1010 write_glyphs (start, len); 1022 write_glyphs (start, len);
@@ -1021,7 +1033,7 @@ insert_glyphs (start, len)
1021 unsigned char conversion_buffer[1024]; 1033 unsigned char conversion_buffer[1024];
1022 int conversion_buffer_size = sizeof conversion_buffer; 1034 int conversion_buffer_size = sizeof conversion_buffer;
1023 1035
1024 OUTPUT1_IF (TS_ins_char); 1036 OUTPUT1_IF (FRAME_TTY (f), TS_ins_char);
1025 if (!start) 1037 if (!start)
1026 { 1038 {
1027 conversion_buffer[0] = SPACEGLYPH; 1039 conversion_buffer[0] = SPACEGLYPH;
@@ -1037,7 +1049,7 @@ insert_glyphs (start, len)
1037 occupies more than one column. */ 1049 occupies more than one column. */
1038 while (len && CHAR_GLYPH_PADDING_P (*start)) 1050 while (len && CHAR_GLYPH_PADDING_P (*start))
1039 { 1051 {
1040 OUTPUT1_IF (TS_ins_char); 1052 OUTPUT1_IF (FRAME_TTY (f), TS_ins_char);
1041 start++, len--; 1053 start++, len--;
1042 } 1054 }
1043 1055
@@ -1053,14 +1065,16 @@ insert_glyphs (start, len)
1053 1065
1054 if (produced > 0) 1066 if (produced > 0)
1055 { 1067 {
1056 fwrite (conversion_buffer, 1, produced, stdout); 1068 fwrite (conversion_buffer, 1, produced,
1057 if (ferror (stdout)) 1069 TTY_OUTPUT (FRAME_TTY (f)));
1058 clearerr (stdout); 1070 if (ferror (TTY_OUTPUT (FRAME_TTY (f))))
1059 if (termscript) 1071 clearerr (TTY_OUTPUT (FRAME_TTY (f)));
1060 fwrite (conversion_buffer, 1, produced, termscript); 1072 if (TTY_TERMSCRIPT (FRAME_TTY (f)))
1073 fwrite (conversion_buffer, 1, produced,
1074 TTY_TERMSCRIPT (FRAME_TTY (f)));
1061 } 1075 }
1062 1076
1063 OUTPUT1_IF (TS_pad_inserted_char); 1077 OUTPUT1_IF (FRAME_TTY (f), TS_pad_inserted_char);
1064 if (start) 1078 if (start)
1065 { 1079 {
1066 turn_off_face (f, glyph->face_id); 1080 turn_off_face (f, glyph->face_id);
@@ -1068,7 +1082,7 @@ insert_glyphs (start, len)
1068 } 1082 }
1069 } 1083 }
1070 1084
1071 cmcheckmagic (); 1085 cmcheckmagic (FRAME_TTY (f));
1072} 1086}
1073 1087
1074void 1088void
@@ -1091,20 +1105,20 @@ delete_glyphs (n)
1091 else 1105 else
1092 { 1106 {
1093 turn_off_insert (); 1107 turn_off_insert ();
1094 OUTPUT_IF (TS_delete_mode); 1108 OUTPUT_IF (FRAME_TTY (updating_frame), TS_delete_mode);
1095 } 1109 }
1096 1110
1097 if (TS_del_multi_chars) 1111 if (TS_del_multi_chars)
1098 { 1112 {
1099 buf = tparam (TS_del_multi_chars, 0, 0, n); 1113 buf = tparam (TS_del_multi_chars, 0, 0, n);
1100 OUTPUT1 (buf); 1114 OUTPUT1 (FRAME_TTY (updating_frame), buf);
1101 xfree (buf); 1115 xfree (buf);
1102 } 1116 }
1103 else 1117 else
1104 for (i = 0; i < n; i++) 1118 for (i = 0; i < n; i++)
1105 OUTPUT1 (TS_del_char); 1119 OUTPUT1 (FRAME_TTY (updating_frame), TS_del_char);
1106 if (!delete_in_insert_mode) 1120 if (!delete_in_insert_mode)
1107 OUTPUT_IF (TS_end_delete_mode); 1121 OUTPUT_IF (FRAME_TTY (updating_frame), TS_end_delete_mode);
1108} 1122}
1109 1123
1110/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */ 1124/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
@@ -1136,10 +1150,10 @@ ins_del_lines (vpos, n)
1136 /* If the lines below the deletion are blank lines coming 1150 /* If the lines below the deletion are blank lines coming
1137 out of the end of the window, don't bother, 1151 out of the end of the window, don't bother,
1138 as there will be a matching inslines later that will flush them. */ 1152 as there will be a matching inslines later that will flush them. */
1139 if (TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) 1153 if (TTY_SCROLL_REGION_OK (FRAME_TTY (sf))
1140 && vpos + i >= specified_window) 1154 && vpos + i >= specified_window)
1141 return; 1155 return;
1142 if (!TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ()) 1156 if (!TTY_MEMORY_BELOW_FRAME (FRAME_TTY (sf))
1143 && vpos + i >= FRAME_LINES (sf)) 1157 && vpos + i >= FRAME_LINES (sf))
1144 return; 1158 return;
1145 1159
@@ -1148,7 +1162,7 @@ ins_del_lines (vpos, n)
1148 raw_cursor_to (vpos, 0); 1162 raw_cursor_to (vpos, 0);
1149 background_highlight (); 1163 background_highlight ();
1150 buf = tparam (multi, 0, 0, i); 1164 buf = tparam (multi, 0, 0, i);
1151 OUTPUT (buf); 1165 OUTPUT (FRAME_TTY (sf), buf);
1152 xfree (buf); 1166 xfree (buf);
1153 } 1167 }
1154 else if (single) 1168 else if (single)
@@ -1156,7 +1170,7 @@ ins_del_lines (vpos, n)
1156 raw_cursor_to (vpos, 0); 1170 raw_cursor_to (vpos, 0);
1157 background_highlight (); 1171 background_highlight ();
1158 while (--i >= 0) 1172 while (--i >= 0)
1159 OUTPUT (single); 1173 OUTPUT (FRAME_TTY (sf), single);
1160 if (TF_teleray) 1174 if (TF_teleray)
1161 curX = 0; 1175 curX = 0;
1162 } 1176 }
@@ -1169,12 +1183,12 @@ ins_del_lines (vpos, n)
1169 raw_cursor_to (vpos, 0); 1183 raw_cursor_to (vpos, 0);
1170 background_highlight (); 1184 background_highlight ();
1171 while (--i >= 0) 1185 while (--i >= 0)
1172 OUTPUTL (scroll, specified_window - vpos); 1186 OUTPUTL (FRAME_TTY (sf), scroll, specified_window - vpos);
1173 set_scroll_region (0, specified_window); 1187 set_scroll_region (0, specified_window);
1174 } 1188 }
1175 1189
1176 if (!TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) 1190 if (!TTY_SCROLL_REGION_OK (FRAME_TTY (sf))
1177 && TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ()) 1191 && TTY_MEMORY_BELOW_FRAME (FRAME_TTY (sf))
1178 && n < 0) 1192 && n < 0)
1179 { 1193 {
1180 cursor_to (FRAME_LINES (sf) + n, 0); 1194 cursor_to (FRAME_LINES (sf) + n, 0);
@@ -1306,7 +1320,8 @@ calculate_costs (frame)
1306 1320
1307 FRAME_COST_BAUD_RATE (frame) = baud_rate; 1321 FRAME_COST_BAUD_RATE (frame) = baud_rate;
1308 1322
1309 TERMINAL_SCROLL_REGION_COST (CURRENT_TERMINAL ()) = string_cost (f); 1323 if (FRAME_TERMCAP_P (frame))
1324 TTY_SCROLL_REGION_COST (frame->output_data.tty) = string_cost (f);
1310 1325
1311 /* These variables are only used for terminal stuff. They are allocated 1326 /* These variables are only used for terminal stuff. They are allocated
1312 once for the terminal frame of X-windows emacs, but not used afterwards. 1327 once for the terminal frame of X-windows emacs, but not used afterwards.
@@ -1866,23 +1881,23 @@ turn_on_face (f, face_id)
1866 if (face->tty_bold_p) 1881 if (face->tty_bold_p)
1867 { 1882 {
1868 if (MAY_USE_WITH_COLORS_P (NC_BOLD)) 1883 if (MAY_USE_WITH_COLORS_P (NC_BOLD))
1869 OUTPUT1_IF (TS_enter_bold_mode); 1884 OUTPUT1_IF (FRAME_TTY (f), TS_enter_bold_mode);
1870 } 1885 }
1871 else if (face->tty_dim_p) 1886 else if (face->tty_dim_p)
1872 if (MAY_USE_WITH_COLORS_P (NC_DIM)) 1887 if (MAY_USE_WITH_COLORS_P (NC_DIM))
1873 OUTPUT1_IF (TS_enter_dim_mode); 1888 OUTPUT1_IF (FRAME_TTY (f), TS_enter_dim_mode);
1874 1889
1875 /* Alternate charset and blinking not yet used. */ 1890 /* Alternate charset and blinking not yet used. */
1876 if (face->tty_alt_charset_p 1891 if (face->tty_alt_charset_p
1877 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET)) 1892 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET))
1878 OUTPUT1_IF (TS_enter_alt_charset_mode); 1893 OUTPUT1_IF (FRAME_TTY (f), TS_enter_alt_charset_mode);
1879 1894
1880 if (face->tty_blinking_p 1895 if (face->tty_blinking_p
1881 && MAY_USE_WITH_COLORS_P (NC_BLINK)) 1896 && MAY_USE_WITH_COLORS_P (NC_BLINK))
1882 OUTPUT1_IF (TS_enter_blink_mode); 1897 OUTPUT1_IF (FRAME_TTY (f), TS_enter_blink_mode);
1883 1898
1884 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE)) 1899 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE))
1885 OUTPUT1_IF (TS_enter_underline_mode); 1900 OUTPUT1_IF (FRAME_TTY (f), TS_enter_underline_mode);
1886 1901
1887 if (TN_max_colors > 0) 1902 if (TN_max_colors > 0)
1888 { 1903 {
@@ -1891,14 +1906,14 @@ turn_on_face (f, face_id)
1891 if (fg >= 0 && TS_set_foreground) 1906 if (fg >= 0 && TS_set_foreground)
1892 { 1907 {
1893 p = tparam (TS_set_foreground, NULL, 0, (int) fg); 1908 p = tparam (TS_set_foreground, NULL, 0, (int) fg);
1894 OUTPUT (p); 1909 OUTPUT (FRAME_TTY (f), p);
1895 xfree (p); 1910 xfree (p);
1896 } 1911 }
1897 1912
1898 if (bg >= 0 && TS_set_background) 1913 if (bg >= 0 && TS_set_background)
1899 { 1914 {
1900 p = tparam (TS_set_background, NULL, 0, (int) bg); 1915 p = tparam (TS_set_background, NULL, 0, (int) bg);
1901 OUTPUT (p); 1916 OUTPUT (FRAME_TTY (f), p);
1902 xfree (p); 1917 xfree (p);
1903 } 1918 }
1904 } 1919 }
@@ -1928,23 +1943,23 @@ turn_off_face (f, face_id)
1928 || face->tty_blinking_p 1943 || face->tty_blinking_p
1929 || face->tty_underline_p) 1944 || face->tty_underline_p)
1930 { 1945 {
1931 OUTPUT1_IF (TS_exit_attribute_mode); 1946 OUTPUT1_IF (FRAME_TTY (f), TS_exit_attribute_mode);
1932 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0) 1947 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0)
1933 standout_mode = 0; 1948 standout_mode = 0;
1934 } 1949 }
1935 1950
1936 if (face->tty_alt_charset_p) 1951 if (face->tty_alt_charset_p)
1937 OUTPUT_IF (TS_exit_alt_charset_mode); 1952 OUTPUT_IF (FRAME_TTY (f), TS_exit_alt_charset_mode);
1938 } 1953 }
1939 else 1954 else
1940 { 1955 {
1941 /* If we don't have "me" we can only have those appearances 1956 /* If we don't have "me" we can only have those appearances
1942 that have exit sequences defined. */ 1957 that have exit sequences defined. */
1943 if (face->tty_alt_charset_p) 1958 if (face->tty_alt_charset_p)
1944 OUTPUT_IF (TS_exit_alt_charset_mode); 1959 OUTPUT_IF (FRAME_TTY (f), TS_exit_alt_charset_mode);
1945 1960
1946 if (face->tty_underline_p) 1961 if (face->tty_underline_p)
1947 OUTPUT_IF (TS_exit_underline_mode); 1962 OUTPUT_IF (FRAME_TTY (f), TS_exit_underline_mode);
1948 } 1963 }
1949 1964
1950 /* Switch back to default colors. */ 1965 /* Switch back to default colors. */
@@ -1953,7 +1968,7 @@ turn_off_face (f, face_id)
1953 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR) 1968 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
1954 || (face->background != FACE_TTY_DEFAULT_COLOR 1969 || (face->background != FACE_TTY_DEFAULT_COLOR
1955 && face->background != FACE_TTY_DEFAULT_BG_COLOR))) 1970 && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
1956 OUTPUT1_IF (TS_orig_pair); 1971 OUTPUT1_IF (FRAME_TTY (f), TS_orig_pair);
1957} 1972}
1958 1973
1959 1974
@@ -2144,12 +2159,46 @@ set_tty_color_mode (f, val)
2144#endif /* !WINDOWSNT */ 2159#endif /* !WINDOWSNT */
2145 2160
2146 2161
2162
2163struct tty_output *
2164get_named_tty (name)
2165 char *name;
2166{
2167 struct tty_output *tty = tty_list;
2168
2169 while (tty) {
2170 if ((tty->name == 0 && name == 0)
2171 || (name && tty->name && !strcmp (tty->name, name)))
2172 return tty;
2173 tty = tty->next;
2174 };
2175
2176 return 0;
2177}
2178
2179
2147/*********************************************************************** 2180/***********************************************************************
2148 Initialization 2181 Initialization
2149 ***********************************************************************/ 2182 ***********************************************************************/
2150 2183
2151void 2184struct tty_output *
2152term_init (terminal_type) 2185term_dummy_init (void)
2186{
2187 if (initialized || tty_list)
2188 error ("tty already initialized");
2189
2190 tty_list = xmalloc (sizeof (struct tty_output));
2191 bzero (tty_list, sizeof (struct tty_output));
2192 TTY_NAME (tty_list) = 0;
2193 TTY_INPUT (tty_list) = stdin;
2194 TTY_OUTPUT (tty_list) = stdout;
2195 return tty_list;
2196}
2197
2198
2199struct tty_output *
2200term_init (name, terminal_type)
2201 char *name;
2153 char *terminal_type; 2202 char *terminal_type;
2154{ 2203{
2155 char *area; 2204 char *area;
@@ -2160,6 +2209,52 @@ term_init (terminal_type)
2160 int status; 2209 int status;
2161 struct frame *sf = XFRAME (selected_frame); 2210 struct frame *sf = XFRAME (selected_frame);
2162 2211
2212 struct tty_output *tty;
2213
2214 tty = get_named_tty (name);
2215 if (tty)
2216 {
2217 /* Return the previously initialized terminal, except if it is the dummy
2218 terminal created for the initial frame. */
2219 if (tty->type)
2220 return tty;
2221 }
2222 else
2223 {
2224 if (!terminal_type)
2225 error ("Unknown terminal type");
2226
2227 tty = (struct tty_output *) xmalloc (sizeof (struct tty_output));
2228 bzero (tty, sizeof (struct tty_output));
2229 tty->next = tty_list;
2230 tty_list = tty;
2231 }
2232
2233 if (name)
2234 {
2235 int fd;
2236 FILE *f;
2237 fd = emacs_open (name, O_RDWR, 0);
2238 if (fd < 0)
2239 {
2240 tty_list = tty->next;
2241 xfree (tty);
2242 error ("could not open file: %s", name);
2243 }
2244 f = fdopen (fd, "w+");
2245 TTY_NAME (tty) = xstrdup (name);
2246 TTY_INPUT (tty) = f;
2247 TTY_OUTPUT (tty) = f;
2248 }
2249 else
2250 {
2251 TTY_NAME (tty) = 0;
2252 TTY_INPUT (tty) = stdin;
2253 TTY_OUTPUT (tty) = stdout;
2254 }
2255
2256 init_sys_modes (tty);
2257
2163#ifdef WINDOWSNT 2258#ifdef WINDOWSNT
2164 initialize_w32_display (); 2259 initialize_w32_display ();
2165 2260
@@ -2174,15 +2269,15 @@ term_init (terminal_type)
2174 delete_in_insert_mode = 1; 2269 delete_in_insert_mode = 1;
2175 2270
2176 UseTabs = 0; 2271 UseTabs = 0;
2177 TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) = 0; 2272 TTY_SCROLL_REGION_OK (tty) = 0;
2178 2273
2179 /* Seems to insert lines when it's not supposed to, messing 2274 /* Seems to insert lines when it's not supposed to, messing
2180 up the display. In doing a trace, it didn't seem to be 2275 up the display. In doing a trace, it didn't seem to be
2181 called much, so I don't think we're losing anything by 2276 called much, so I don't think we're losing anything by
2182 turning it off. */ 2277 turning it off. */
2278 TTY_LINE_INS_DEL_OK (tty) = 0;
2183 2279
2184 TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ()) = 0; 2280 TTY_CHAR_INS_DEL_OK (tty) = 1;
2185 TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) = 1;
2186 2281
2187 baud_rate = 19200; 2282 baud_rate = 19200;
2188 2283
@@ -2190,11 +2285,13 @@ term_init (terminal_type)
2190 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; 2285 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
2191 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ 2286 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
2192 2287
2193 return; 2288 return tty;
2194#else /* not WINDOWSNT */ 2289#else /* not WINDOWSNT */
2195 2290
2196 Wcm_clear (); 2291 Wcm_clear ();
2197 2292
2293 TTY_TYPE (tty) = xstrdup (terminal_type);
2294
2198 buffer = (char *) xmalloc (buffer_size); 2295 buffer = (char *) xmalloc (buffer_size);
2199 status = tgetent (buffer, terminal_type); 2296 status = tgetent (buffer, terminal_type);
2200 if (status < 0) 2297 if (status < 0)
@@ -2213,14 +2310,14 @@ If that is not the actual type of terminal you have,\n\
2213use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2310use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2214`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2311`setenv TERM ...') to specify the correct type. It may be necessary\n\
2215to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 2312to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2216 terminal_type); 2313 terminal_type);
2217#else 2314#else
2218 fatal ("Terminal type %s is not defined.\n\ 2315 fatal ("Terminal type %s is not defined.\n\
2219If that is not the actual type of terminal you have,\n\ 2316If that is not the actual type of terminal you have,\n\
2220use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2317use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2221`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2318`setenv TERM ...') to specify the correct type. It may be necessary\n\
2222to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 2319to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2223 terminal_type); 2320 terminal_type);
2224#endif 2321#endif
2225 } 2322 }
2226 2323
@@ -2326,7 +2423,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2326 2423
2327 TN_no_color_video = tgetnum ("NC"); 2424 TN_no_color_video = tgetnum ("NC");
2328 if (TN_no_color_video == -1) 2425 if (TN_no_color_video == -1)
2329 TN_no_color_video = 0; 2426 TN_no_color_video = 0;
2330 } 2427 }
2331 2428
2332 tty_default_color_capabilities (1); 2429 tty_default_color_capabilities (1);
@@ -2335,9 +2432,9 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2335 /* Since we make MagicWrap terminals look like AutoWrap, we need to have 2432 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2336 the former flag imply the latter. */ 2433 the former flag imply the latter. */
2337 AutoWrap = MagicWrap || tgetflag ("am"); 2434 AutoWrap = MagicWrap || tgetflag ("am");
2338 TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ()) = tgetflag ("db"); 2435 TTY_MEMORY_BELOW_FRAME (tty) = tgetflag ("db");
2339 TF_hazeltine = tgetflag ("hz"); 2436 TF_hazeltine = tgetflag ("hz");
2340 TERMINAL_MUST_WRITE_SPACES (CURRENT_TERMINAL ()) = tgetflag ("in"); 2437 TTY_MUST_WRITE_SPACES (tty) = tgetflag ("in");
2341 meta_key = tgetflag ("km") || tgetflag ("MT"); 2438 meta_key = tgetflag ("km") || tgetflag ("MT");
2342 TF_insmode_motion = tgetflag ("mi"); 2439 TF_insmode_motion = tgetflag ("mi");
2343 TF_standout_motion = tgetflag ("ms"); 2440 TF_standout_motion = tgetflag ("ms");
@@ -2364,12 +2461,12 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2364 2461
2365 if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3) 2462 if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3)
2366 fatal ("Screen size %dx%d is too small", 2463 fatal ("Screen size %dx%d is too small",
2367 FRAME_LINES (sf), FRAME_COLS (sf)); 2464 FRAME_LINES (sf), FRAME_COLS (sf));
2368 2465
2369#if 0 /* This is not used anywhere. */ 2466#if 0 /* This is not used anywhere. */
2370 TERMINAL_MIN_PADDING_SPEED (CURRENT_TERMINAL ()) = tgetnum ("pb"); 2467 TTY_MIN_PADDING_SPEED (tty) = tgetnum ("pb");
2371#endif 2468#endif
2372 2469
2373 TabWidth = tgetnum ("tw"); 2470 TabWidth = tgetnum ("tw");
2374 2471
2375#ifdef VMS 2472#ifdef VMS
@@ -2424,9 +2521,9 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2424 { 2521 {
2425 char *s = tgetstr ("me", address); 2522 char *s = tgetstr ("me", address);
2426 if (s != 0) 2523 if (s != 0)
2427 TS_end_standout_mode = s; 2524 TS_end_standout_mode = s;
2428 else 2525 else
2429 TS_standout_mode = 0; 2526 TS_standout_mode = 0;
2430 } 2527 }
2431 2528
2432 if (TF_teleray) 2529 if (TF_teleray)
@@ -2445,7 +2542,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2445 2542
2446 if (!strcmp (terminal_type, "supdup")) 2543 if (!strcmp (terminal_type, "supdup"))
2447 { 2544 {
2448 TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ()) = 1; 2545 TTY_MEMORY_BELOW_FRAME (tty) = 1;
2449 Wcm.cm_losewrap = 1; 2546 Wcm.cm_losewrap = 1;
2450 } 2547 }
2451 if (!strncmp (terminal_type, "c10", 3) 2548 if (!strncmp (terminal_type, "c10", 3)
@@ -2455,7 +2552,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2455 This string is not valid in general since it works only 2552 This string is not valid in general since it works only
2456 for windows starting at the upper left corner; 2553 for windows starting at the upper left corner;
2457 but that is all Emacs uses. 2554 but that is all Emacs uses.
2458 2555
2459 This string works only if the frame is using 2556 This string works only if the frame is using
2460 the top of the video memory, because addressing is memory-relative. 2557 the top of the video memory, because addressing is memory-relative.
2461 So first check the :ti string to see if that is true. 2558 So first check the :ti string to see if that is true.
@@ -2472,7 +2569,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2472 TS_set_window = "\033v%C %C %C %C "; 2569 TS_set_window = "\033v%C %C %C %C ";
2473 } 2570 }
2474 /* Termcap entry often fails to have :in: flag */ 2571 /* Termcap entry often fails to have :in: flag */
2475 TERMINAL_MUST_WRITE_SPACES (CURRENT_TERMINAL ()) = 1; 2572 TTY_MUST_WRITE_SPACES (tty) = 1;
2476 /* :ti string typically fails to have \E^G! in it */ 2573 /* :ti string typically fails to have \E^G! in it */
2477 /* This limits scope of insert-char to one line. */ 2574 /* This limits scope of insert-char to one line. */
2478 strcpy (area, TS_termcap_modes); 2575 strcpy (area, TS_termcap_modes);
@@ -2481,13 +2578,13 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2481 area += strlen (area) + 1; 2578 area += strlen (area) + 1;
2482 p = AbsPosition; 2579 p = AbsPosition;
2483 /* Change all %+ parameters to %C, to handle 2580 /* Change all %+ parameters to %C, to handle
2484 values above 96 correctly for the C100. */ 2581 values above 96 correctly for the C100. */
2485 while (*p) 2582 while (*p)
2486 { 2583 {
2487 if (p[0] == '%' && p[1] == '+') 2584 if (p[0] == '%' && p[1] == '+')
2488 p[1] = 'C'; 2585 p[1] = 'C';
2489 p++; 2586 p++;
2490 } 2587 }
2491 } 2588 }
2492 2589
2493 FrameRows = FRAME_LINES (sf); 2590 FrameRows = FRAME_LINES (sf);
@@ -2504,21 +2601,21 @@ or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2504 terminal_type); 2601 terminal_type);
2505#else /* not VMS */ 2602#else /* not VMS */
2506# ifdef TERMINFO 2603# ifdef TERMINFO
2507 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2604 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2508It lacks the ability to position the cursor.\n\ 2605It lacks the ability to position the cursor.\n\
2509If that is not the actual type of terminal you have,\n\ 2606If that is not the actual type of terminal you have,\n\
2510use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2607use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2511`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2608`setenv TERM ...') to specify the correct type. It may be necessary\n\
2512to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 2609to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2513 terminal_type); 2610 terminal_type);
2514# else /* TERMCAP */ 2611# else /* TERMCAP */
2515 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2612 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2516It lacks the ability to position the cursor.\n\ 2613It lacks the ability to position the cursor.\n\
2517If that is not the actual type of terminal you have,\n\ 2614If that is not the actual type of terminal you have,\n\
2518use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2615use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2519`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2616`setenv TERM ...') to specify the correct type. It may be necessary\n\
2520to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 2617to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2521 terminal_type); 2618 terminal_type);
2522# endif /* TERMINFO */ 2619# endif /* TERMINFO */
2523#endif /*VMS */ 2620#endif /*VMS */
2524 if (FRAME_LINES (sf) <= 0 2621 if (FRAME_LINES (sf) <= 0
@@ -2527,34 +2624,34 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2527 2624
2528 delete_in_insert_mode 2625 delete_in_insert_mode
2529 = TS_delete_mode && TS_insert_mode 2626 = TS_delete_mode && TS_insert_mode
2530 && !strcmp (TS_delete_mode, TS_insert_mode); 2627 && !strcmp (TS_delete_mode, TS_insert_mode);
2531 2628
2532 se_is_so = (TS_standout_mode 2629 se_is_so = (TS_standout_mode
2533 && TS_end_standout_mode 2630 && TS_end_standout_mode
2534 && !strcmp (TS_standout_mode, TS_end_standout_mode)); 2631 && !strcmp (TS_standout_mode, TS_end_standout_mode));
2535 2632
2536 UseTabs = tabs_safe_p () && TabWidth == 8; 2633 UseTabs = tabs_safe_p () && TabWidth == 8;
2537 2634
2538 TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) 2635 TTY_SCROLL_REGION_OK (tty)
2539 = (Wcm.cm_abs 2636 = (Wcm.cm_abs
2540 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1)); 2637 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1));
2541 2638
2542 TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ()) 2639 TTY_LINE_INS_DEL_OK (tty)
2543 = (((TS_ins_line || TS_ins_multi_lines) 2640 = (((TS_ins_line || TS_ins_multi_lines)
2544 && (TS_del_line || TS_del_multi_lines)) 2641 && (TS_del_line || TS_del_multi_lines))
2545 || (TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) 2642 || (TTY_SCROLL_REGION_OK (tty)
2546 && TS_fwd_scroll && TS_rev_scroll)); 2643 && TS_fwd_scroll && TS_rev_scroll));
2547 2644
2548 TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) 2645 TTY_CHAR_INS_DEL_OK (tty)
2549 = ((TS_ins_char || TS_insert_mode 2646 = ((TS_ins_char || TS_insert_mode
2550 || TS_pad_inserted_char || TS_ins_multi_chars) 2647 || TS_pad_inserted_char || TS_ins_multi_chars)
2551 && (TS_del_char || TS_del_multi_chars)); 2648 && (TS_del_char || TS_del_multi_chars));
2552 2649
2553 TERMINAL_FAST_CLEAR_END_OF_LINE (CURRENT_TERMINAL ()) = TS_clr_line != 0; 2650 TTY_FAST_CLEAR_END_OF_LINE (tty) = TS_clr_line != 0;
2554 2651
2555 init_baud_rate (); 2652 init_baud_rate ();
2556 if (read_socket_hook) /* Baudrate is somewhat */ 2653 if (read_socket_hook) /* Baudrate is somewhat
2557 /* meaningless in this case */ 2654 meaningless in this case */
2558 baud_rate = 9600; 2655 baud_rate = 9600;
2559 2656
2560 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; 2657 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0;
@@ -2562,6 +2659,8 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2562#endif /* WINDOWSNT */ 2659#endif /* WINDOWSNT */
2563 2660
2564 xfree (buffer); 2661 xfree (buffer);
2662
2663 return tty;
2565} 2664}
2566 2665
2567/* VARARGS 1 */ 2666/* VARARGS 1 */
@@ -2597,5 +2696,12 @@ The function should accept no arguments. */);
2597 defsubr (&Stty_display_color_cells); 2696 defsubr (&Stty_display_color_cells);
2598} 2697}
2599 2698
2699struct tty_output *
2700get_current_tty ()
2701{
2702 return CURTTY();
2703}
2704
2705
2600/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 2706/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2601 (do not change this comment) */ 2707 (do not change this comment) */
diff --git a/src/termchar.h b/src/termchar.h
index b7c82d04936..9d7399e80d9 100644
--- a/src/termchar.h
+++ b/src/termchar.h
@@ -18,10 +18,37 @@ along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21struct terminal 21/* Each termcap frame points to its own struct tty_output object in the
22 output_data.tty field. The tty_output structure contains the information
23 that is specific to terminals. */
24struct tty_output
22{ 25{
26 char *name; /* The name of the device file or 0 if
27 stdin/stdout. */
28 char *type; /* The type of the tty. */
29
30 /* Input/output */
31
32 FILE *input; /* The stream to be used for terminal input. */
33 FILE *output; /* The stream to be used for terminal output. */
34
35 FILE *termscript; /* If nonzero, send all terminal output
36 characters to this stream also. */
37
38 struct emacs_tty old_tty; /* The initial tty mode bits */
39
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
43
44 /* Pixel values.
45 XXX What are these used for? */
46
47 unsigned long background_pixel;
48 unsigned long foreground_pixel;
49
50 /* Terminal characteristics. */
23 51
24 /* EMACS_INT baud_rate; */ /* Output speed in baud */
25 int must_write_spaces; /* Nonzero means spaces in the text must 52 int must_write_spaces; /* Nonzero means spaces in the text must
26 actually be output; can't just skip over 53 actually be output; can't just skip over
27 some columns to leave them blank. */ 54 some columns to leave them blank. */
@@ -37,31 +64,43 @@ struct terminal
37 off bottom */ 64 off bottom */
38 65
39#if 0 /* These are not used anywhere. */ 66#if 0 /* These are not used anywhere. */
67 /* EMACS_INT baud_rate; */ /* Output speed in baud */
40 int min_padding_speed; /* Speed below which no padding necessary. */ 68 int min_padding_speed; /* Speed below which no padding necessary. */
41 int dont_calculate_costs; /* Nonzero means don't bother computing 69 int dont_calculate_costs; /* Nonzero means don't bother computing
42 various cost tables; we won't use them. */ 70 various cost tables; we won't use them. */
43#endif 71#endif
72
73 struct tty_output *next;
44}; 74};
45 75
46typedef struct terminal *TERMINAL_PTR; 76extern struct tty_output *tty_list;
77
78
79#define FRAME_TTY(f) \
80 ((f)->output_method == output_termcap \
81 ? (f)->output_data.tty : (abort(), (struct tty_output *) 0))
82
83#define CURTTY() FRAME_TTY (SELECTED_FRAME())
47 84
48extern TERMINAL_PTR current_terminal; 85#define TTY_NAME(t) ((t)->name)
86#define TTY_TYPE(t) ((t)->type)
49 87
50#define CURRENT_TERMINAL() \ 88#define TTY_INPUT(t) ((t)->input)
51 (current_terminal ? current_terminal : (abort(), (TERMINAL_PTR) 0)) 89#define TTY_OUTPUT(t) ((t)->output)
90#define TTY_TERMSCRIPT(t) ((t)->termscript)
52 91
53#define TERMINAL_MUST_WRITE_SPACES(t) ((t)->must_write_spaces) 92#define TTY_MUST_WRITE_SPACES(t) ((t)->must_write_spaces)
54#define TERMINAL_FAST_CLEAR_END_OF_LINE(t) ((t)->fast_clear_end_of_line) 93#define TTY_FAST_CLEAR_END_OF_LINE(t) ((t)->fast_clear_end_of_line)
55#define TERMINAL_LINE_INS_DEL_OK(t) ((t)->line_ins_del_ok) 94#define TTY_LINE_INS_DEL_OK(t) ((t)->line_ins_del_ok)
56#define TERMINAL_CHAR_INS_DEL_OK(t) ((t)->char_ins_del_ok) 95#define TTY_CHAR_INS_DEL_OK(t) ((t)->char_ins_del_ok)
57#define TERMINAL_SCROLL_REGION_OK(t) ((t)->scroll_region_ok) 96#define TTY_SCROLL_REGION_OK(t) ((t)->scroll_region_ok)
58#define TERMINAL_SCROLL_REGION_COST(t) ((t)->scroll_region_cost) 97#define TTY_SCROLL_REGION_COST(t) ((t)->scroll_region_cost)
59#define TERMINAL_MEMORY_BELOW_FRAME(t) ((t)->memory_below_frame) 98#define TTY_MEMORY_BELOW_FRAME(t) ((t)->memory_below_frame)
60 99
61#if 0 100#if 0
62/* These are not used anywhere. */ 101/* These are not used anywhere. */
63#define TERMINAL_MIN_PADDING_SPEED(t) ((t)->min_padding_speed) 102#define TTY_MIN_PADDING_SPEED(t) ((t)->min_padding_speed)
64#define TERMINAL_DONT_CALCULATE_COSTS(t) ((t)->dont_calculate_costs) 103#define TTY_DONT_CALCULATE_COSTS(t) ((t)->dont_calculate_costs)
65#endif 104#endif
66 105
67/* arch-tag: bf9f0d49-842b-42fb-9348-ec8759b27193 106/* arch-tag: bf9f0d49-842b-42fb-9348-ec8759b27193
diff --git a/src/termhooks.h b/src/termhooks.h
index d76d06671ef..c1ada7b851f 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -25,9 +25,6 @@ Boston, MA 02111-1307, USA. */
25struct glyph; 25struct glyph;
26struct frame; 26struct frame;
27 27
28/* If nonzero, send all terminal output characters to this stream also. */
29extern FILE *termscript;
30
31/* Only use prototypes when lisp.h has been included. */ 28/* Only use prototypes when lisp.h has been included. */
32#ifndef P_ 29#ifndef P_
33#define P_(X) () 30#define P_(X) ()
diff --git a/src/w32term.c b/src/w32term.c
index cf8d07a18ff..06d82a7bee3 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -6366,11 +6366,11 @@ w32_initialize ()
6366 redeem_scroll_bar_hook = w32_redeem_scroll_bar; 6366 redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6367 judge_scroll_bars_hook = w32_judge_scroll_bars; 6367 judge_scroll_bars_hook = w32_judge_scroll_bars;
6368 6368
6369 TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ()) = 1; /* we'll scroll partial frames */ 6369 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
6370 TERMINAL_CHAR_INS_DEL_OK (CURRENT_TERMINAL ()) = 1; 6370 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
6371 TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ()) = 1; /* we'll just blt 'em */ 6371 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
6372 TERMINAL_FAST_CLEAR_END_OF_LINE (CURRENT_TERMINAL ()) = 1; /* X does this well */ 6372 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
6373 TERMINAL_MEMORY_BELOW_FRAME (CURRENT_TERMINAL ()) = 0; /* we don't remember what 6373 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
6374 scrolls off the 6374 scrolls off the
6375 bottom */ 6375 bottom */
6376 baud_rate = 19200; 6376 baud_rate = 19200;
diff --git a/src/w32term.h b/src/w32term.h
index de28620c7b9..68967ad7d24 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -389,8 +389,6 @@ extern struct w32_output w32term_display;
389#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc) 389#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc)
390#define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc) 390#define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc)
391 391
392#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
393#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
394#define FRAME_FONT(f) ((f)->output_data.w32->font) 392#define FRAME_FONT(f) ((f)->output_data.w32->font)
395#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset) 393#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset)
396#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset) 394#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset)
diff --git a/src/window.c b/src/window.c
index 3c0f3a17439..48e517a68f7 100644
--- a/src/window.c
+++ b/src/window.c
@@ -29,6 +29,7 @@ Boston, MA 02111-1307, USA. */
29#include "window.h" 29#include "window.h"
30#include "commands.h" 30#include "commands.h"
31#include "indent.h" 31#include "indent.h"
32#include "systty.h" /* For emacs_tty in termchar.h */
32#include "termchar.h" 33#include "termchar.h"
33#include "disptab.h" 34#include "disptab.h"
34#include "dispextern.h" 35#include "dispextern.h"
@@ -6381,7 +6382,7 @@ and scrolling positions. */)
6381void 6382void
6382init_window_once () 6383init_window_once ()
6383{ 6384{
6384 struct frame *f = make_terminal_frame (); 6385 struct frame *f = make_terminal_frame (0, 0);
6385 XSETFRAME (selected_frame, f); 6386 XSETFRAME (selected_frame, f);
6386 Vterminal_frame = selected_frame; 6387 Vterminal_frame = selected_frame;
6387 minibuf_window = f->minibuffer_window; 6388 minibuf_window = f->minibuffer_window;
diff --git a/src/xdisp.c b/src/xdisp.c
index 252c6c824b3..cedfa9a72d5 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -173,6 +173,7 @@ Boston, MA 02111-1307, USA. */
173#include "keyboard.h" 173#include "keyboard.h"
174#include "frame.h" 174#include "frame.h"
175#include "window.h" 175#include "window.h"
176#include "systty.h" /* For emacs_tty in termchar.h */
176#include "termchar.h" 177#include "termchar.h"
177#include "dispextern.h" 178#include "dispextern.h"
178#include "buffer.h" 179#include "buffer.h"
@@ -12889,7 +12890,7 @@ try_window_id (w)
12889 12890
12890 /* Window must either use window-based redisplay or be full width. */ 12891 /* Window must either use window-based redisplay or be full width. */
12891 if (!FRAME_WINDOW_P (f) 12892 if (!FRAME_WINDOW_P (f)
12892 && (!TERMINAL_LINE_INS_DEL_OK (CURRENT_TERMINAL ()) 12893 && (!TTY_LINE_INS_DEL_OK (CURTTY ())
12893 || !WINDOW_FULL_WIDTH_P (w))) 12894 || !WINDOW_FULL_WIDTH_P (w)))
12894 GIVE_UP (4); 12895 GIVE_UP (4);
12895 12896
@@ -13322,7 +13323,7 @@ try_window_id (w)
13322 13323
13323 /* On dumb terminals delete dvpos lines at the end 13324 /* On dumb terminals delete dvpos lines at the end
13324 before inserting dvpos empty lines. */ 13325 before inserting dvpos empty lines. */
13325 if (!TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ())) 13326 if (!TTY_SCROLL_REGION_OK (CURTTY ()))
13326 ins_del_lines (end - dvpos, -dvpos); 13327 ins_del_lines (end - dvpos, -dvpos);
13327 13328
13328 /* Insert dvpos empty lines in front of 13329 /* Insert dvpos empty lines in front of
@@ -13343,7 +13344,7 @@ try_window_id (w)
13343 13344
13344 /* On a dumb terminal insert dvpos empty lines at the 13345 /* On a dumb terminal insert dvpos empty lines at the
13345 end. */ 13346 end. */
13346 if (!TERMINAL_SCROLL_REGION_OK (CURRENT_TERMINAL ())) 13347 if (!TTY_SCROLL_REGION_OK (CURTTY ()))
13347 ins_del_lines (end + dvpos, -dvpos); 13348 ins_del_lines (end + dvpos, -dvpos);
13348 } 13349 }
13349 13350
diff --git a/src/xfaces.c b/src/xfaces.c
index 96a1d52b3c2..faae8352cb3 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -241,6 +241,8 @@ Boston, MA 02111-1307, USA. */
241#include "blockinput.h" 241#include "blockinput.h"
242#include "window.h" 242#include "window.h"
243#include "intervals.h" 243#include "intervals.h"
244#include "systty.h" /* For emacs_tty in termchar.h */
245#include "termchar.h"
244 246
245#ifdef HAVE_X_WINDOWS 247#ifdef HAVE_X_WINDOWS
246 248
diff --git a/src/xfns.c b/src/xfns.c
index cd50cbbc919..94a74417983 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -48,6 +48,8 @@ Boston, MA 02111-1307, USA. */
48#include "systime.h" 48#include "systime.h"
49#include "termhooks.h" 49#include "termhooks.h"
50#include "atimer.h" 50#include "atimer.h"
51#include "systty.h"
52#include "termchar.h"
51 53
52#ifdef HAVE_X_WINDOWS 54#ifdef HAVE_X_WINDOWS
53 55