diff 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
line wrap: on
line diff
--- a/src/cm.c	Wed Dec 24 18:55:24 2003 +0000
+++ b/src/cm.c	Thu Dec 25 06:59:31 2003 +0000
@@ -22,8 +22,16 @@
 
 #include <config.h>
 #include <stdio.h>
+
+/* For CURTTY */
+#include "lisp.h"
+#include "frame.h"
+
 #include "cm.h"
 #include "termhooks.h"
+#include "systty.h" /* For emacs_tty in termchar.h */
+#include "termchar.h"
+
 
 /* For now, don't try to include termcap.h.  On some systems,
    configure finds a non-standard termcap.h that the main build
@@ -41,6 +49,7 @@
 
 extern char *BC, *UP;
 
+
 int cost;		/* sums up costs */
 
 /* ARGSUSED */
@@ -52,13 +61,16 @@
   return c;
 }
 
+/* The terminal to use for low-level output. */
+struct tty_output * current_tty;
+
 int
 cmputc (c)
      char c;
 {
-  if (termscript)
-    fputc (c & 0177, termscript);
-  putchar (c & 0177);
+  if (TTY_TERMSCRIPT (current_tty))
+    putc (c & 0177, TTY_TERMSCRIPT (current_tty));
+  putc (c & 0177, TTY_OUTPUT (current_tty));
   return c;
 }
 
@@ -122,18 +134,19 @@
  * after we reach the last column; this takes us to a known state.
  */
 void
-cmcheckmagic ()
+cmcheckmagic (tty)
+     struct tty_output *tty;
 {
   if (curX == FrameCols)
     {
       if (!MagicWrap || curY >= FrameRows - 1)
 	abort ();
-      if (termscript)
-	putc ('\r', termscript);
-      putchar ('\r');
-      if (termscript)
-	putc ('\n', termscript);
-      putchar ('\n');
+      if (TTY_TERMSCRIPT (tty))
+	putc ('\r', TTY_TERMSCRIPT (tty));
+      putc ('\r', TTY_OUTPUT (tty));
+      if (TTY_TERMSCRIPT (tty))
+	putc ('\n', TTY_TERMSCRIPT (tty));
+      putc ('\n', TTY_OUTPUT (tty));
       curX = 0;
       curY++;
     }
@@ -187,8 +200,7 @@
  */
 
 static int
-calccost (srcy, srcx, dsty, dstx, doit)
-     int srcy, srcx, dsty, dstx, doit;
+calccost (struct tty_output *tty, int srcy, int srcx, int dsty, int dstx, int doit)
 {
     register int    deltay,
                     deltax,
@@ -223,7 +235,7 @@
     totalcost = c * deltay;
     if (doit)
 	while (--deltay >= 0)
-	    tputs (p, 1, cmputc);
+          emacs_tputs (tty, p, 1, cmputc);
 x:
     if ((deltax = dstx - srcx) == 0)
 	goto done;
@@ -278,7 +290,7 @@
 	totalcost += tabcost;	/* use the tabs */
 	if (doit)
 	    while (--ntabs >= 0)
-		tputs (Wcm.cm_tab, 1, cmputc);
+              emacs_tputs (tty, Wcm.cm_tab, 1, cmputc);
 	srcx = tabx;
     }
 
@@ -305,7 +317,7 @@
     totalcost += c * deltax;
     if (doit)
 	while (--deltax >= 0)
-	    tputs (p, 1, cmputc);
+          emacs_tputs (tty, p, 1, cmputc);
 done:
     return totalcost;
 }
@@ -323,7 +335,8 @@
 #define	USECR	3
 
 void
-cmgoto (row, col)
+cmgoto (tty, row, col)
+     struct tty_output *tty;
      int row, col;
 {
     int     homecost,
@@ -346,24 +359,24 @@
        * start where we are.  Examine the options, and pick the cheapest.
        */
 
-      relcost = calccost (curY, curX, row, col, 0);
+      relcost = calccost (tty, curY, curX, row, col, 0);
       use = USEREL;
       if ((homecost = Wcm.cc_home) < BIG)
-	  homecost += calccost (0, 0, row, col, 0);
+          homecost += calccost (tty, 0, 0, row, col, 0);
       if (homecost < relcost)
-	  relcost = homecost, use = USEHOME;
+          relcost = homecost, use = USEHOME;
       if ((llcost = Wcm.cc_ll) < BIG)
-	  llcost += calccost (Wcm.cm_rows - 1, 0, row, col, 0);
+          llcost += calccost (tty, Wcm.cm_rows - 1, 0, row, col, 0);
       if (llcost < relcost)
-	  relcost = llcost, use = USELL;
+          relcost = llcost, use = USELL;
       if ((crcost = Wcm.cc_cr) < BIG) {
 	  if (Wcm.cm_autolf)
 	      if (curY + 1 >= Wcm.cm_rows)
 		  crcost = BIG;
 	      else
-		  crcost += calccost (curY + 1, 0, row, col, 0);
+                  crcost += calccost (tty, curY + 1, 0, row, col, 0);
 	  else
-	      crcost += calccost (curY, 0, row, col, 0);
+	      crcost += calccost (tty, curY, 0, row, col, 0);
       }
       if (crcost < relcost)
 	  relcost = crcost, use = USECR;
@@ -389,10 +402,10 @@
       cost = 0;
       p = dcm == Wcm.cm_habs ? tgoto (dcm, row, col) :
 			       tgoto (dcm, col, row);
-      tputs (p, 1, evalcost);
+      emacs_tputs (tty, p, 1, evalcost);
       if (cost <= relcost)
 	{	/* really is cheaper */
-	  tputs (p, 1, cmputc);
+	  emacs_tputs (tty, p, 1, cmputc);
 	  curY = row, curX = col;
 	  return;
 	}
@@ -401,24 +414,24 @@
   switch (use)
     {
     case USEHOME:
-      tputs (Wcm.cm_home, 1, cmputc);
+      emacs_tputs (tty, Wcm.cm_home, 1, cmputc);
       curY = 0, curX = 0;
       break;
 
     case USELL:
-      tputs (Wcm.cm_ll, 1, cmputc);
+      emacs_tputs (tty, Wcm.cm_ll, 1, cmputc);
       curY = Wcm.cm_rows - 1, curX = 0;
       break;
 
     case USECR:
-      tputs (Wcm.cm_cr, 1, cmputc);
+      emacs_tputs (tty, Wcm.cm_cr, 1, cmputc);
       if (Wcm.cm_autolf)
 	curY++;
       curX = 0;
       break;
     }
 
-  (void) calccost (curY, curX, row, col, 1);
+  (void) calccost (tty, curY, curX, row, col, 1);
   curY = row, curX = col;
 }