comparison src/cm.c @ 53226:dd3018b4785b

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
author Karoly Lorentey <lorentey@elte.hu>
date Thu, 25 Dec 2003 06:59:31 +0000
parents 695cf19ef79e
children 22aaf1e5fbe6
comparison
equal deleted inserted replaced
53225:4250e7e26247 53226:dd3018b4785b
20 Boston, MA 02111-1307, USA. */ 20 Boston, MA 02111-1307, USA. */
21 21
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
30 won't find. */ 38 won't find. */
31 39
39 #define BIG 9999 /* 9999 good on VAXen. For 16 bit machines 47 #define BIG 9999 /* 9999 good on VAXen. For 16 bit machines
40 use about 2000.... */ 48 use about 2000.... */
41 49
42 extern char *BC, *UP; 50 extern char *BC, *UP;
43 51
52
44 int cost; /* sums up costs */ 53 int cost; /* sums up costs */
45 54
46 /* ARGSUSED */ 55 /* ARGSUSED */
47 int 56 int
48 evalcost (c) 57 evalcost (c)
50 { 59 {
51 cost++; 60 cost++;
52 return c; 61 return c;
53 } 62 }
54 63
64 /* The terminal to use for low-level output. */
65 struct tty_output * current_tty;
66
55 int 67 int
56 cmputc (c) 68 cmputc (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
65 /* NEXT TWO ARE DONE WITH MACROS */ 77 /* NEXT TWO ARE DONE WITH MACROS */
66 #if 0 78 #if 0
120 * in limbo if we use direct cursor addressing from the phantom column. 132 * in limbo if we use direct cursor addressing from the phantom column.
121 * The only guaranteed safe thing to do is to emit a CRLF immediately 133 * The only guaranteed safe thing to do is to emit a CRLF immediately
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 */
124 void 136 void
125 cmcheckmagic () 137 cmcheckmagic (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 }
140 } 153 }
141 154
185 * up and down, and left and right, motions, and tabs. If doit is set 198 * up and down, and left and right, motions, and tabs. If doit is set
186 * actually perform the motion. 199 * actually perform the motion.
187 */ 200 */
188 201
189 static int 202 static int
190 calccost (srcy, srcx, dsty, dstx, doit) 203 calccost (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,
195 c, 207 c,
196 totalcost; 208 totalcost;
221 return c; 233 return c;
222 } 234 }
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);
227 x: 239 x:
228 if ((deltax = dstx - srcx) == 0) 240 if ((deltax = dstx - srcx) == 0)
229 goto done; 241 goto done;
230 if (deltax < 0) { 242 if (deltax < 0) {
231 p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax; 243 p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax;
276 288
277 if (tabcost < (deltax * Wcm.cc_right)) { 289 if (tabcost < (deltax * Wcm.cc_right)) {
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
285 /* 297 /*
286 * Now might as well just recompute the delta. 298 * Now might as well just recompute the delta.
303 return BIG; 315 return BIG;
304 } 316 }
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);
309 done: 321 done:
310 return totalcost; 322 return totalcost;
311 } 323 }
312 324
313 #if 0 325 #if 0
321 #define USEHOME 1 333 #define USEHOME 1
322 #define USELL 2 334 #define USELL 2
323 #define USECR 3 335 #define USECR 3
324 336
325 void 337 void
326 cmgoto (row, col) 338 cmgoto (tty, row, col)
339 struct tty_output *tty;
327 int row, col; 340 int row, col;
328 { 341 {
329 int homecost, 342 int homecost,
330 crcost, 343 crcost,
331 llcost, 344 llcost,
344 /* We may have quick ways to go to the upper-left, bottom-left, 357 /* We may have quick ways to go to the upper-left, bottom-left,
345 * start-of-line, or start-of-next-line. Or it might be best to 358 * start-of-line, or start-of-next-line. Or it might be best to
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;
370 directcost = Wcm.cc_abs, dcm = Wcm.cm_abs; 383 directcost = Wcm.cc_abs, dcm = Wcm.cm_abs;
371 if (row == curY && Wcm.cc_habs < BIG) 384 if (row == curY && Wcm.cc_habs < BIG)
387 { 400 {
388 /* compute REAL direct cost */ 401 /* compute REAL direct cost */
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 }
399 } 412 }
400 413
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
425 /* Clear out all terminal info. 438 /* Clear out all terminal info.
426 Used before copying into it the info on the actual terminal. 439 Used before copying into it the info on the actual terminal.