aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaroly Lorentey2003-12-30 19:27:57 +0000
committerKaroly Lorentey2003-12-30 19:27:57 +0000
commit16c290d8c16fb0fdb574c837c6b1badbc655efe2 (patch)
tree26e7915477ebe5b8c3847e70b9230a6efa134e6c
parent9d9f18127ffc1bc26358a5d48917ef4e4bafbddc (diff)
downloademacs-16c290d8c16fb0fdb574c837c6b1badbc655efe2.tar.gz
emacs-16c290d8c16fb0fdb574c837c6b1badbc655efe2.zip
Major bugfixes and slight enhancements.
src/dispextern.h (get_tty_size, tabs_safe_p, init_baud_rate): Update prototypes. src/dispnew.c (window_change_signal): Update call to get_tty_size. src/frame.c (Fmake_terminal_frame): Ditto. src/keyboard.c (Fsuspend_emacs): Ditto. src/sysdep.c: Eliminate tty_outputs, wherever possible. (The exceptions are init_sys_modes and reset_sys_modes, which need access to tty-local parameters). (init_baud_rate): Change tty_output parameter to a simple file descriptor. (narrow_foreground_group, widen_foreground_group): Ditto. (tabs_safe_p, get_tty_size): Ditto. (init_sys_modes): Update narrow_foreground_group invocation. (reset_sys_modes): Update widen_foreground_group invocation. (request_sigio)[!FASYNC && STRIDE]: Fix function signature. src/term.c (delete_tty): Only close output file handle if it is different from input. Re-enable freeing of Wcm. (term_init): Update get_tty_size, tabs_safe_p and init_baud_rate invocations. lib-src/emacsclient.c (here): Renamed to frame. (longopts): Change --here to --frame. The -h short option may be confused with --help. (decode_options, print_help_and_exit): Update to reflect above changes. (main): Ditto. lisp/server.el (server-start): Fix frame-live-p call syntax. (server-process-filter): Handle 'emacsclient -f' without file arguments. Don't return any values to emacsclient when 'emacsclient -f -e'. (server-switch-buffer): Prevent infinite recursion when there are no files to edit. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-27
-rw-r--r--README.multi-tty44
-rw-r--r--lib-src/emacsclient.c22
-rw-r--r--lisp/server.el12
-rw-r--r--src/dispextern.h6
-rw-r--r--src/dispnew.c2
-rw-r--r--src/frame.c2
-rw-r--r--src/keyboard.c4
-rw-r--r--src/sysdep.c58
-rw-r--r--src/term.c10
9 files changed, 85 insertions, 75 deletions
diff --git a/README.multi-tty b/README.multi-tty
index 862a287fb9e..2ee943b6ed5 100644
--- a/README.multi-tty
+++ b/README.multi-tty
@@ -39,7 +39,7 @@ commands:
39then start up the emacs server (src/emacs, M-x server-start), and then 39then start up the emacs server (src/emacs, M-x server-start), and then
40(from a shell prompt on another terminal) start emacsclient with 40(from a shell prompt on another terminal) start emacsclient with
41 41
42 lib-src/emacsclient -h /optional/file/names... 42 lib-src/emacsclient -f /optional/file/names...
43 43
44You'll hopefully have two fully working, independent frames on 44You'll hopefully have two fully working, independent frames on
45separate terminals. (This seems to be very useful, emacsclient starts 45separate terminals. (This seems to be very useful, emacsclient starts
@@ -213,13 +213,7 @@ DIARY OF CHANGES
213 213
214 (Seems to be working OK.) 214 (Seems to be working OK.)
215 215
216THINGS TO DO 216-- Fix mysterious memory corruption error with tty deletion. To
217------------
218
219** Understand Emacs's low-level input system. It seems
220 complicated. :-)
221
222** Fix mysterious memory corruption error with tty deletion. To
223 trigger it, try the following shell command: 217 trigger it, try the following shell command:
224 218
225 while true; do TERM=no-such-terminal-definition emacsclient -h; done 219 while true; do TERM=no-such-terminal-definition emacsclient -h; done
@@ -230,17 +224,23 @@ THINGS TO DO
230 Why were these vars collected into a struct before multi-tty 224 Why were these vars collected into a struct before multi-tty
231 support?) 225 support?)
232 226
233 The bug does not seem to happen if the error occurs before terminal 227 (Done. Whew. It turned out that the problem had nothing to do
234 initialization or if I comment out all xfree()s in delete_frame. 228 with hypothetical external references to Wcm, or any other
235 Update: yes it does, although it is much rarer. Or maybe it's 229 tty_output component; it was simply that delete_tty closed the
236 another bug. 230 filehandles of secondary ttys twice, resulting in fclose doubly
231 free()ing memory. Utterly trivial matter. I love the C's memory
232 management, it puts hair on your chest.)
233
234THINGS TO DO
235------------
237 236
238 Idea: Some of these errors may have been caused by having more 237** Understand Emacs's low-level input system (it seems complicated) :-)
239 file handles than FD_SETSIZE. 238 and maybe rewrite multi-tty input in terms of MULTIKBOARD.
240 239
241** Find out why does Emacs abort when it wants to close its 240** Find out why does Emacs abort when it wants to close its
242 controlling tty. Hint: chan_process[] array. Hey, maybe 241 controlling tty. Hint: chan_process[] array. Hey, maybe
243 noninterrupt-IO would work, too? 242 noninterrupt-IO would work, too? Update: no, there is no process
243 for stdin/out.
244 244
245** Support raw secondary terminals. (Note that SIGIO works only on 245** Support raw secondary terminals. (Note that SIGIO works only on
246 the controlling terminal.) Hint: extend read_input_waiting() for 246 the controlling terminal.) Hint: extend read_input_waiting() for
@@ -252,9 +252,21 @@ THINGS TO DO
252** Issue with SIGIO: it needs to be disabled during redisplay. See if 252** Issue with SIGIO: it needs to be disabled during redisplay. See if
253 fcntl() kernel behaviour could be emulated by emacsclient. 253 fcntl() kernel behaviour could be emulated by emacsclient.
254 254
255** Get rid of the accessor macros in termchar.h, or define macros for
256 all members.
257
255** Make parts of struct tty_output accessible from Lisp. The device 258** Make parts of struct tty_output accessible from Lisp. The device
256 name and the type is sufficient. 259 name and the type is sufficient.
257 260
261** server.el: There are issues with saving files in buffers of closed
262 clients. Try editing a file with emacsclient -f, and (without
263 saving it) do a delete-frame. The frame is closed without
264 question, and a surprising confirmation prompt appears in another
265 frame.
266
267** emacsclient.el, server.el: Handle eval or file open errors when
268 doing -f.
269
258** Export delete_tty to the Lisp environment, for emacsclient. 270** Export delete_tty to the Lisp environment, for emacsclient.
259 271
260** Make sure C-g goes to the right frame. This is hard, as SIGINT 272** Make sure C-g goes to the right frame. This is hard, as SIGINT
@@ -283,6 +295,6 @@ THINGS TO DO
283 295
284** Fix DOS support (I can't do this myself). 296** Fix DOS support (I can't do this myself).
285 297
286 298** Do a grep on XXX and ?? for more issues.
287 299
288;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d 300;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 174923e2dc8..9f08e4dac37 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -118,7 +118,7 @@ int eval = 0;
118char *display = NULL; 118char *display = NULL;
119 119
120/* Nonzero means open a new Emacs frame on the current terminal. */ 120/* Nonzero means open a new Emacs frame on the current terminal. */
121int here = 0; 121int frame = 0;
122 122
123/* If non-NULL, the name of an editor to fallback to if the server 123/* If non-NULL, the name of an editor to fallback to if the server
124 is not running. --alternate-editor. */ 124 is not running. --alternate-editor. */
@@ -135,7 +135,7 @@ struct option longopts[] =
135 { "eval", no_argument, NULL, 'e' }, 135 { "eval", no_argument, NULL, 'e' },
136 { "help", no_argument, NULL, 'H' }, 136 { "help", no_argument, NULL, 'H' },
137 { "version", no_argument, NULL, 'V' }, 137 { "version", no_argument, NULL, 'V' },
138 { "here", no_argument, NULL, 'h' }, 138 { "frame", no_argument, NULL, 'f' },
139 { "alternate-editor", required_argument, NULL, 'a' }, 139 { "alternate-editor", required_argument, NULL, 'a' },
140 { "socket-name", required_argument, NULL, 's' }, 140 { "socket-name", required_argument, NULL, 's' },
141 { "display", required_argument, NULL, 'd' }, 141 { "display", required_argument, NULL, 'd' },
@@ -153,7 +153,7 @@ decode_options (argc, argv)
153 while (1) 153 while (1)
154 { 154 {
155 int opt = getopt_long (argc, argv, 155 int opt = getopt_long (argc, argv,
156 "VHnea:s:d:h", longopts, 0); 156 "VHnea:s:d:f", longopts, 0);
157 157
158 if (opt == EOF) 158 if (opt == EOF)
159 break; 159 break;
@@ -192,8 +192,8 @@ decode_options (argc, argv)
192 exit (0); 192 exit (0);
193 break; 193 break;
194 194
195 case 'h': 195 case 'f':
196 here = 1; 196 frame = 1;
197 break; 197 break;
198 198
199 case 'H': 199 case 'H':
@@ -207,7 +207,7 @@ decode_options (argc, argv)
207 } 207 }
208 } 208 }
209 209
210 if (here) { 210 if (frame) {
211 nowait = 0; 211 nowait = 0;
212 display = 0; 212 display = 0;
213 } 213 }
@@ -225,7 +225,7 @@ Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
225The following OPTIONS are accepted:\n\ 225The following OPTIONS are accepted:\n\
226-V, --version Just print a version info and return\n\ 226-V, --version Just print a version info and return\n\
227-H, --help Print this usage information message\n\ 227-H, --help Print this usage information message\n\
228-h, --here Open a new Emacs frame on the current terminal\n\ 228-f, --frame Open a new Emacs frame on the current terminal\n\
229-n, --no-wait Don't wait for the server to return\n\ 229-n, --no-wait Don't wait for the server to return\n\
230-e, --eval Evaluate the FILE arguments as ELisp expressions\n\ 230-e, --eval Evaluate the FILE arguments as ELisp expressions\n\
231-d, --display=DISPLAY Visit the file in the given display\n\ 231-d, --display=DISPLAY Visit the file in the given display\n\
@@ -876,7 +876,7 @@ main (argc, argv)
876 /* Process options. */ 876 /* Process options. */
877 decode_options (argc, argv); 877 decode_options (argc, argv);
878 878
879 if ((argc - optind < 1) && !eval && !here) 879 if ((argc - optind < 1) && !eval && !frame)
880 { 880 {
881 fprintf (stderr, "%s: file name or argument required\n", progname); 881 fprintf (stderr, "%s: file name or argument required\n", progname);
882 fprintf (stderr, "Try `%s --help' for more information\n", progname); 882 fprintf (stderr, "Try `%s --help' for more information\n", progname);
@@ -1048,7 +1048,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1048 fprintf (out, " "); 1048 fprintf (out, " ");
1049 } 1049 }
1050 1050
1051 if (here) 1051 if (frame)
1052 { 1052 {
1053 if (! init_signals ()) 1053 if (! init_signals ())
1054 { 1054 {
@@ -1108,7 +1108,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1108 } 1108 }
1109 else 1109 else
1110 { 1110 {
1111 if (!here) 1111 if (!frame)
1112 { 1112 {
1113 while ((str = fgets (string, BUFSIZ, stdin))) 1113 while ((str = fgets (string, BUFSIZ, stdin)))
1114 { 1114 {
@@ -1128,7 +1128,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1128 return 0; 1128 return 0;
1129 } 1129 }
1130 1130
1131 if (here) 1131 if (frame)
1132 { 1132 {
1133 if (! pty_conversation (out)) 1133 if (! pty_conversation (out))
1134 { 1134 {
diff --git a/lisp/server.el b/lisp/server.el
index 9c841071a99..bf7d4a5d358 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -271,7 +271,7 @@ Prefix arg means just kill any existing server communications subprocess."
271 (while server-frames 271 (while server-frames
272 (let ((frame (cadar server-frames))) 272 (let ((frame (cadar server-frames)))
273 (setq server-frames (cdr server-frames)) 273 (setq server-frames (cdr server-frames))
274 (when frame-live-p frame (delete-frame frame 'force)))) 274 (when (frame-live-p frame) (delete-frame frame 'force))))
275 (unless leave-dead 275 (unless leave-dead
276 (if server-process 276 (if server-process
277 (server-log (message "Restarting server"))) 277 (server-log (message "Restarting server")))
@@ -314,7 +314,7 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"."
314 (coding-system (and default-enable-multibyte-characters 314 (coding-system (and default-enable-multibyte-characters
315 (or file-name-coding-system 315 (or file-name-coding-system
316 default-file-name-coding-system))) 316 default-file-name-coding-system)))
317 client nowait eval 317 client nowait eval newframe
318 (files nil) 318 (files nil)
319 (lineno 1) 319 (lineno 1)
320 (columnno 0)) 320 (columnno 0))
@@ -336,6 +336,7 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"."
336 (setq request ""))))) 336 (setq request "")))))
337 ;; Open a new frame at the client. ARG is the name of the pseudo tty. 337 ;; Open a new frame at the client. ARG is the name of the pseudo tty.
338 ((and (equal "-pty" arg) (string-match "\\([^ ]*\\) \\([^ ]*\\) " request)) 338 ((and (equal "-pty" arg) (string-match "\\([^ ]*\\) \\([^ ]*\\) " request))
339 (setq newframe t)
339 (let ((pty (server-unquote-arg (match-string 1 request))) 340 (let ((pty (server-unquote-arg (match-string 1 request)))
340 (type (server-unquote-arg (match-string 2 request)))) 341 (type (server-unquote-arg (match-string 2 request))))
341 (setq request (substring request (match-end 0))) 342 (setq request (substring request (match-end 0)))
@@ -364,7 +365,7 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"."
364 (if eval 365 (if eval
365 (condition-case err 366 (condition-case err
366 (let ((v (eval (car (read-from-string arg))))) 367 (let ((v (eval (car (read-from-string arg)))))
367 (when v 368 (when (and (not newframe v))
368 (with-temp-buffer 369 (with-temp-buffer
369 (let ((standard-output (current-buffer))) 370 (let ((standard-output (current-buffer)))
370 (pp v) 371 (pp v)
@@ -382,7 +383,7 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"."
382 (server-visit-files files client nowait) 383 (server-visit-files files client nowait)
383 (run-hooks 'post-command-hook)) 384 (run-hooks 'post-command-hook))
384 ;; CLIENT is now a list (CLIENTNUM BUFFERS...) 385 ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
385 (if (null (cdr client)) 386 (if (and (not newframe) (null (cdr client)))
386 ;; This client is empty; get rid of it immediately. 387 ;; This client is empty; get rid of it immediately.
387 (progn 388 (progn
388 (let ((frame (assq (car client) server-frames))) 389 (let ((frame (assq (car client) server-frames)))
@@ -607,7 +608,8 @@ Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it."
607 ;; since we've already effectively done that. 608 ;; since we've already effectively done that.
608 (if (null next-buffer) 609 (if (null next-buffer)
609 (if server-clients 610 (if server-clients
610 (server-switch-buffer (nth 1 (car server-clients)) killed-one) 611 (let ((buffer (nth 1 (car server-clients))))
612 (and buffer (server-switch-buffer buffer killed-one)))
611 (unless (or killed-one (window-dedicated-p (selected-window))) 613 (unless (or killed-one (window-dedicated-p (selected-window)))
612 (switch-to-buffer (other-buffer)) 614 (switch-to-buffer (other-buffer))
613 (message "No server buffers remain to edit"))) 615 (message "No server buffers remain to edit")))
diff --git a/src/dispextern.h b/src/dispextern.h
index e53f36d4a01..a4864068eda 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2562,11 +2562,11 @@ extern int x_intersect_rectangles P_ ((XRectangle *, XRectangle *,
2562 2562
2563/* Defined in sysdep.c */ 2563/* Defined in sysdep.c */
2564 2564
2565void get_tty_size P_ ((struct tty_output *, int *, int *)); 2565void get_tty_size P_ ((int, int *, int *));
2566void request_sigio P_ ((void)); 2566void request_sigio P_ ((void));
2567void unrequest_sigio P_ ((void)); 2567void unrequest_sigio P_ ((void));
2568int tabs_safe_p P_ ((struct tty_output *)); 2568int tabs_safe_p P_ ((int));
2569void init_baud_rate P_ ((struct tty_output *)); 2569void init_baud_rate P_ ((int));
2570void init_sigio P_ ((int)); 2570void init_sigio P_ ((int));
2571 2571
2572/* Defined in xfaces.c */ 2572/* Defined in xfaces.c */
diff --git a/src/dispnew.c b/src/dispnew.c
index 3cf15deeab6..593067eae92 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5927,7 +5927,7 @@ window_change_signal (signalnum) /* If we don't have an argument, */
5927 if (! tty->term_initted) 5927 if (! tty->term_initted)
5928 continue; 5928 continue;
5929 5929
5930 get_tty_size (tty, &width, &height); 5930 get_tty_size (fileno (TTY_INPUT (tty)), &width, &height);
5931 5931
5932 { 5932 {
5933 Lisp_Object tail, frame; 5933 Lisp_Object tail, frame;
diff --git a/src/frame.c b/src/frame.c
index 9a532bfdd2d..f26bf9ae9ca 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -656,7 +656,7 @@ Note that changing the size of one terminal frame automatically affects all. */
656 656
657 { 657 {
658 int width, height; 658 int width, height;
659 get_tty_size (FRAME_TTY (f), &width, &height); 659 get_tty_size (fileno (TTY_INPUT (FRAME_TTY (f))), &width, &height);
660 change_frame_size (f, height, width, 0, 0, 0); 660 change_frame_size (f, height, width, 0, 0, 0);
661 } 661 }
662 662
diff --git a/src/keyboard.c b/src/keyboard.c
index 1bb9564060f..c9124f0f594 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -10127,7 +10127,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10127 call1 (Vrun_hooks, intern ("suspend-hook")); 10127 call1 (Vrun_hooks, intern ("suspend-hook"));
10128 10128
10129 GCPRO1 (stuffstring); 10129 GCPRO1 (stuffstring);
10130 get_tty_size (CURTTY (), &old_width, &old_height); 10130 get_tty_size (fileno (TTY_INPUT (CURTTY ())), &old_width, &old_height);
10131 reset_all_sys_modes (); 10131 reset_all_sys_modes ();
10132 /* sys_suspend can get an error if it tries to fork a subshell 10132 /* sys_suspend can get an error if it tries to fork a subshell
10133 and the system resources aren't available for that. */ 10133 and the system resources aren't available for that. */
@@ -10143,7 +10143,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10143 /* Check if terminal/window size has changed. 10143 /* Check if terminal/window size has changed.
10144 Note that this is not useful when we are running directly 10144 Note that this is not useful when we are running directly
10145 with a window system; but suspend should be disabled in that case. */ 10145 with a window system; but suspend should be disabled in that case. */
10146 get_tty_size (CURTTY (), &width, &height); 10146 get_tty_size (fileno (TTY_INPUT (CURTTY ())), &width, &height);
10147 if (width != old_width || height != old_height) 10147 if (width != old_width || height != old_height)
10148 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0); 10148 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0);
10149 10149
diff --git a/src/sysdep.c b/src/sysdep.c
index b3a46c77eb3..7453be6e3a7 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -309,10 +309,13 @@ discard_tty_input ()
309#endif /* not WINDOWSNT */ 309#endif /* not WINDOWSNT */
310} 310}
311 311
312
312#ifdef SIGTSTP 313#ifdef SIGTSTP
313 314
314/* Arrange for character C to be read as the next input from 315/* Arrange for character C to be read as the next input from
315 the terminal. */ 316 the terminal.
317 XXX What if we have multiple ttys?
318*/
316 319
317void 320void
318stuff_char (char c) 321stuff_char (char c)
@@ -331,7 +334,7 @@ stuff_char (char c)
331#endif /* SIGTSTP */ 334#endif /* SIGTSTP */
332 335
333void 336void
334init_baud_rate (struct tty_output *tty) 337init_baud_rate (int fd)
335{ 338{
336 if (noninteractive) 339 if (noninteractive)
337 emacs_ospeed = 0; 340 emacs_ospeed = 0;
@@ -346,7 +349,7 @@ init_baud_rate (struct tty_output *tty)
346#ifdef VMS 349#ifdef VMS
347 struct sensemode sg; 350 struct sensemode sg;
348 351
349 SYS$QIOW (0, fileno (TTY_INPUT (tty)), IO$_SENSEMODE, &sg, 0, 0, 352 SYS$QIOW (0, fd, IO$_SENSEMODE, &sg, 0, 0,
350 &sg.class, 12, 0, 0, 0, 0 ); 353 &sg.class, 12, 0, 0, 0, 0 );
351 emacs_ospeed = sg.xmit_baud; 354 emacs_ospeed = sg.xmit_baud;
352#else /* not VMS */ 355#else /* not VMS */
@@ -354,7 +357,7 @@ init_baud_rate (struct tty_output *tty)
354 struct termios sg; 357 struct termios sg;
355 358
356 sg.c_cflag = B9600; 359 sg.c_cflag = B9600;
357 tcgetattr (fileno (TTY_INPUT (tty)), &sg); 360 tcgetattr (fd, &sg);
358 emacs_ospeed = cfgetospeed (&sg); 361 emacs_ospeed = cfgetospeed (&sg);
359#if defined (USE_GETOBAUD) && defined (getobaud) 362#if defined (USE_GETOBAUD) && defined (getobaud)
360 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */ 363 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
@@ -367,16 +370,16 @@ init_baud_rate (struct tty_output *tty)
367 370
368 sg.c_cflag = B9600; 371 sg.c_cflag = B9600;
369#ifdef HAVE_TCATTR 372#ifdef HAVE_TCATTR
370 tcgetattr (fileno (TTY_INPUT (tty)), &sg); 373 tcgetattr (fd, &sg);
371#else 374#else
372 ioctl (fileno (TTY_INPUT (tty)), TCGETA, &sg); 375 ioctl (fd, TCGETA, &sg);
373#endif 376#endif
374 emacs_ospeed = sg.c_cflag & CBAUD; 377 emacs_ospeed = sg.c_cflag & CBAUD;
375#else /* neither VMS nor TERMIOS nor TERMIO */ 378#else /* neither VMS nor TERMIOS nor TERMIO */
376 struct sgttyb sg; 379 struct sgttyb sg;
377 380
378 sg.sg_ospeed = B9600; 381 sg.sg_ospeed = B9600;
379 if (ioctl (fileno (TTY_INPUT (tty)), TIOCGETP, &sg) < 0) 382 if (ioctl (fd, TIOCGETP, &sg) < 0)
380 abort (); 383 abort ();
381 emacs_ospeed = sg.sg_ospeed; 384 emacs_ospeed = sg.sg_ospeed;
382#endif /* not HAVE_TERMIO */ 385#endif /* not HAVE_TERMIO */
@@ -392,6 +395,7 @@ init_baud_rate (struct tty_output *tty)
392 baud_rate = 1200; 395 baud_rate = 1200;
393} 396}
394 397
398
395/*ARGSUSED*/ 399/*ARGSUSED*/
396void 400void
397set_exclusive_use (fd) 401set_exclusive_use (fd)
@@ -976,7 +980,7 @@ request_sigio ()
976} 980}
977 981
978void 982void
979unrequest_sigio (struct tty_output *tty) 983unrequest_sigio ()
980{ 984{
981 int off = 0; 985 int off = 0;
982 986
@@ -1078,23 +1082,23 @@ int inherited_pgroup;
1078 group, redirect the TTY to point to our own process group. We need 1082 group, redirect the TTY to point to our own process group. We need
1079 to be in our own process group to receive SIGIO properly. */ 1083 to be in our own process group to receive SIGIO properly. */
1080void 1084void
1081narrow_foreground_group (struct tty_output *tty) 1085narrow_foreground_group (int fd)
1082{ 1086{
1083 int me = getpid (); 1087 int me = getpid ();
1084 1088
1085 setpgrp (0, inherited_pgroup); 1089 setpgrp (0, inherited_pgroup);
1086 /* XXX This only works on the controlling tty. */ 1090 /* XXX This only works on the controlling tty. */
1087 if (inherited_pgroup != me) 1091 if (inherited_pgroup != me)
1088 EMACS_SET_TTY_PGRP (fileno (TTY_INPUT (tty)), &me); 1092 EMACS_SET_TTY_PGRP (fd, &me);
1089 setpgrp (0, me); 1093 setpgrp (0, me);
1090} 1094}
1091 1095
1092/* Set the tty to our original foreground group. */ 1096/* Set the tty to our original foreground group. */
1093void 1097void
1094widen_foreground_group (struct tty_output *tty) 1098widen_foreground_group (int fd)
1095{ 1099{
1096 if (inherited_pgroup != getpid ()) 1100 if (inherited_pgroup != getpid ())
1097 EMACS_SET_TTY_PGRP (fileno (TTY_INPUT (tty)), &inherited_pgroup); 1101 EMACS_SET_TTY_PGRP (fd, &inherited_pgroup);
1098 setpgrp (0, inherited_pgroup); 1102 setpgrp (0, inherited_pgroup);
1099} 1103}
1100 1104
@@ -1289,11 +1293,9 @@ static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
1289void 1293void
1290init_all_sys_modes (void) 1294init_all_sys_modes (void)
1291{ 1295{
1292 struct tty_output *tty = tty_list; 1296 struct tty_output *tty;
1293 while (tty) { 1297 for (tty = tty_list; tty; tty = tty->next)
1294 init_sys_modes (tty); 1298 init_sys_modes (tty);
1295 tty = tty->next;
1296 }
1297} 1299}
1298 1300
1299void 1301void
@@ -1358,7 +1360,7 @@ nil means don't delete them until `list-processes' is run. */);
1358 1360
1359#ifdef BSD_PGRPS 1361#ifdef BSD_PGRPS
1360 if (! read_socket_hook && EQ (Vwindow_system, Qnil)) 1362 if (! read_socket_hook && EQ (Vwindow_system, Qnil))
1361 narrow_foreground_group (tty_out); 1363 narrow_foreground_group (fileno (TTY_INPUT (tty_out)));
1362#endif 1364#endif
1363 1365
1364#ifdef HAVE_WINDOW_SYSTEM 1366#ifdef HAVE_WINDOW_SYSTEM
@@ -1683,11 +1685,11 @@ nil means don't delete them until `list-processes' is run. */);
1683 At the time this is called, init_sys_modes has not been done yet. */ 1685 At the time this is called, init_sys_modes has not been done yet. */
1684 1686
1685int 1687int
1686tabs_safe_p (struct tty_output *tty) 1688tabs_safe_p (int fd)
1687{ 1689{
1688 struct emacs_tty etty; 1690 struct emacs_tty etty;
1689 1691
1690 EMACS_GET_TTY (fileno (TTY_INPUT (tty)), &etty); 1692 EMACS_GET_TTY (fd, &etty);
1691 return EMACS_TTY_TABS_OK (&etty); 1693 return EMACS_TTY_TABS_OK (&etty);
1692} 1694}
1693 1695
@@ -1696,9 +1698,7 @@ tabs_safe_p (struct tty_output *tty)
1696 We store 0 if there's no valid information. */ 1698 We store 0 if there's no valid information. */
1697 1699
1698void 1700void
1699get_tty_size (tty_out, widthp, heightp) 1701get_tty_size (int fd, int *widthp, int *heightp)
1700 struct tty_output *tty_out;
1701 int *widthp, *heightp;
1702{ 1702{
1703 1703
1704#ifdef TIOCGWINSZ 1704#ifdef TIOCGWINSZ
@@ -1706,7 +1706,7 @@ get_tty_size (tty_out, widthp, heightp)
1706 /* BSD-style. */ 1706 /* BSD-style. */
1707 struct winsize size; 1707 struct winsize size;
1708 1708
1709 if (ioctl (fileno (TTY_INPUT (tty_out)), TIOCGWINSZ, &size) == -1) 1709 if (ioctl (fd, TIOCGWINSZ, &size) == -1)
1710 *widthp = *heightp = 0; 1710 *widthp = *heightp = 0;
1711 else 1711 else
1712 { 1712 {
@@ -1720,7 +1720,7 @@ get_tty_size (tty_out, widthp, heightp)
1720 /* SunOS - style. */ 1720 /* SunOS - style. */
1721 struct ttysize size; 1721 struct ttysize size;
1722 1722
1723 if (ioctl (fileno (TTY_INPUT (tty_out)), TIOCGSIZE, &size) == -1) 1723 if (ioctl (fd, TIOCGSIZE, &size) == -1)
1724 *widthp = *heightp = 0; 1724 *widthp = *heightp = 0;
1725 else 1725 else
1726 { 1726 {
@@ -1733,7 +1733,7 @@ get_tty_size (tty_out, widthp, heightp)
1733 1733
1734 struct sensemode tty; 1734 struct sensemode tty;
1735 1735
1736 SYS$QIOW (0, fileno (TTY_INPUT (tty_out)), IO$_SENSEMODE, &tty, 0, 0, 1736 SYS$QIOW (0, fd, IO$_SENSEMODE, &tty, 0, 0,
1737 &tty.class, 12, 0, 0, 0, 0); 1737 &tty.class, 12, 0, 0, 0, 0);
1738 *widthp = tty.scr_wid; 1738 *widthp = tty.scr_wid;
1739 *heightp = tty.scr_len; 1739 *heightp = tty.scr_len;
@@ -1793,11 +1793,9 @@ set_window_size (fd, height, width)
1793void 1793void
1794reset_all_sys_modes (void) 1794reset_all_sys_modes (void)
1795{ 1795{
1796 struct tty_output *tty = tty_list; 1796 struct tty_output *tty;
1797 while (tty) { 1797 for (tty = tty_list; tty; tty = tty->next)
1798 reset_sys_modes (tty); 1798 reset_sys_modes (tty);
1799 tty = tty->next;
1800 }
1801} 1799}
1802 1800
1803/* Prepare the terminal for closing it; move the cursor to the 1801/* Prepare the terminal for closing it; move the cursor to the
@@ -1889,7 +1887,7 @@ reset_sys_modes (tty_out)
1889#endif 1887#endif
1890 1888
1891#ifdef BSD_PGRPS 1889#ifdef BSD_PGRPS
1892 widen_foreground_group (tty_out); 1890 widen_foreground_group (fileno (TTY_INPUT (tty_out)));
1893#endif 1891#endif
1894} 1892}
1895 1893
diff --git a/src/term.c b/src/term.c
index 3b029da0b7f..72698ed3b2c 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2403,7 +2403,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2403 /* Get frame size from system, or else from termcap. */ 2403 /* Get frame size from system, or else from termcap. */
2404 { 2404 {
2405 int height, width; 2405 int height, width;
2406 get_tty_size (tty, &width, &height); 2406 get_tty_size (fileno (TTY_INPUT (tty)), &width, &height);
2407 FrameCols (tty) = width; 2407 FrameCols (tty) = width;
2408 FrameRows (tty) = height; 2408 FrameRows (tty) = height;
2409 } 2409 }
@@ -2609,7 +2609,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2609 && tty->TS_end_standout_mode 2609 && tty->TS_end_standout_mode
2610 && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode)); 2610 && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode));
2611 2611
2612 UseTabs (tty) = tabs_safe_p (tty) && TabWidth (tty) == 8; 2612 UseTabs (tty) = tabs_safe_p (fileno (TTY_INPUT (tty))) && TabWidth (tty) == 8;
2613 2613
2614 TTY_SCROLL_REGION_OK (tty) 2614 TTY_SCROLL_REGION_OK (tty)
2615 = (tty->Wcm->cm_abs 2615 = (tty->Wcm->cm_abs
@@ -2628,7 +2628,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2628 2628
2629 TTY_FAST_CLEAR_END_OF_LINE (tty) = tty->TS_clr_line != 0; 2629 TTY_FAST_CLEAR_END_OF_LINE (tty) = tty->TS_clr_line != 0;
2630 2630
2631 init_baud_rate (tty); 2631 init_baud_rate (fileno (TTY_INPUT (tty)));
2632 if (read_socket_hook) /* Baudrate is somewhat 2632 if (read_socket_hook) /* Baudrate is somewhat
2633 meaningless in this case */ 2633 meaningless in this case */
2634 baud_rate = 9600; 2634 baud_rate = 9600;
@@ -2737,7 +2737,7 @@ delete_tty (struct tty_output *tty)
2737 2737
2738 if (tty->input) 2738 if (tty->input)
2739 fclose (tty->input); 2739 fclose (tty->input);
2740 if (tty->output) 2740 if (tty->output && tty->output != tty->input)
2741 fclose (tty->output); 2741 fclose (tty->output);
2742 if (tty->termscript) 2742 if (tty->termscript)
2743 fclose (tty->termscript); 2743 fclose (tty->termscript);
@@ -2745,10 +2745,8 @@ delete_tty (struct tty_output *tty)
2745 if (tty->old_tty) 2745 if (tty->old_tty)
2746 xfree (tty->old_tty); 2746 xfree (tty->old_tty);
2747 2747
2748#if 0 /* XXX There is a dangling reference somewhere into this. */
2749 if (tty->Wcm) 2748 if (tty->Wcm)
2750 xfree (tty->Wcm); 2749 xfree (tty->Wcm);
2751#endif
2752 2750
2753 bzero (tty, sizeof (struct tty_output)); 2751 bzero (tty, sizeof (struct tty_output));
2754 xfree (tty); 2752 xfree (tty);