annotate src/console-tty.c @ 359:8e84bee8ddd0 r21-1-9

Import from CVS: tag r21-1-9
author cvs
date Mon, 13 Aug 2007 10:57:55 +0200
parents 7df0dd720c89
children 8626e4521993
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* TTY console functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /* Authors: Ben Wing and Chuck Thompson. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "console-tty.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "console-stream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "faces.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "redisplay.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "sysdep.h"
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
37 #include "sysfile.h"
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 255
diff changeset
38 #ifdef FILE_CODING
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 255
diff changeset
39 #include "file-coding.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #endif
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
41 #ifdef HAVE_GPM
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
42 #include "gpmevent.h"
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
43 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 DEFINE_CONSOLE_TYPE (tty);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 Lisp_Object Qterminal_type;
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
48 Lisp_Object Qcontrolling_process;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 allocate_tty_console_struct (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 163
diff changeset
54 /* zero out all slots except the lisp ones ... */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
55 CONSOLE_TTY_DATA (con) = xnew_and_zero (struct tty_console);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 CONSOLE_TTY_DATA (con)->terminal_type = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 CONSOLE_TTY_DATA (con)->instream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 CONSOLE_TTY_DATA (con)->outstream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 tty_init_console (struct console *con, Lisp_Object props)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 {
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
64 Lisp_Object tty = CONSOLE_CONNECTION (con);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
65 Lisp_Object terminal_type = Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
66 Lisp_Object controlling_process = Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
67 struct tty_console *tty_con;
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
68 struct gcpro gcpro1, gcpro2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
70 GCPRO2 (terminal_type, controlling_process);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 terminal_type = Fplist_get (props, Qterminal_type, Qnil);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
73 controlling_process = Fplist_get (props, Qcontrolling_process, Qnil);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 163
diff changeset
74
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 /* Determine the terminal type */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 if (!NILP (terminal_type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 CHECK_STRING (terminal_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
81 char *temp_type = getenv ("TERM");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 if (!temp_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 error ("Cannot determine terminal type");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 terminal_type = build_string (temp_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
91 /* Determine the controlling process */
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
92 if (!NILP (controlling_process))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
93 CHECK_INT (controlling_process);
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
94
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 /* Open the specified console */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 allocate_tty_console_struct (con);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
98 tty_con = CONSOLE_TTY_DATA (con);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
99
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
100 if (internal_equal (tty, Vstdio_str, 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
102 tty_con->infd = fileno (stdin);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
103 tty_con->outfd = fileno (stdout);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
104 tty_con->is_stdio = 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
108 tty_con->infd = tty_con->outfd =
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
109 open ((char *) XSTRING_DATA (tty), O_RDWR);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
110 if (tty_con->infd < 0)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
111 error ("Unable to open tty %s", XSTRING_DATA (tty));
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
112 tty_con->is_stdio = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 163
diff changeset
114
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
115 tty_con->instream = make_filedesc_input_stream (tty_con->infd, 0, -1, 0);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
116 tty_con->outstream = make_filedesc_output_stream (tty_con->outfd, 0, -1, 0);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
117 #ifdef MULE
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
118 tty_con->instream =
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
119 make_decoding_input_stream (XLSTREAM (tty_con->instream),
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
120 Fget_coding_system (Vkeyboard_coding_system));
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
121 Lstream_set_character_mode (XLSTREAM (tty_con->instream));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
122 tty_con->outstream =
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
123 make_encoding_output_stream (XLSTREAM (tty_con->outstream),
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
124 Fget_coding_system (Vterminal_coding_system));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
125 #endif /* MULE */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
126 tty_con->terminal_type = terminal_type;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
127 tty_con->controlling_process = controlling_process;
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 108
diff changeset
128
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 108
diff changeset
129 #ifdef HAVE_GPM
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
130 connect_to_gpm (con);
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 108
diff changeset
131 #endif
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 108
diff changeset
132
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 if (NILP (CONSOLE_NAME (con)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 int tty_pg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 int controlling_tty_pg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 int cfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 /* OK, the only sure-fire way I can think of to determine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 whether a particular TTY is our controlling TTY is to check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 if it has the same foreground process group as our controlling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 TTY. This is OK because a process group can never simultaneously
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 be the foreground process group of two TTY's (in that case it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 would have two controlling TTY's, which is not allowed). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
147 EMACS_GET_TTY_PROCESS_GROUP (tty_con->infd, &tty_pg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 cfd = open ("/dev/tty", O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 EMACS_GET_TTY_PROCESS_GROUP (cfd, &controlling_tty_pg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 close (cfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 if (tty_pg == controlling_tty_pg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
153 tty_con->controlling_terminal = 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 XSETCONSOLE (Vcontrolling_terminal, con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 munge_tty_process_group ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
158 tty_con->controlling_terminal = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 tty_mark_console (struct console *con, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
167 struct tty_console *tty_con = CONSOLE_TTY_DATA (con);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
168 ((markobj) (tty_con->terminal_type));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
169 ((markobj) (tty_con->instream));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
170 ((markobj) (tty_con->outstream));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 tty_initially_selected_for_input (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 free_tty_console_struct (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
182 struct tty_console *tty_con = CONSOLE_TTY_DATA (con);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
183 if (tty_con)
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
184 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
185 if (tty_con->term_entry_buffer) /* allocated in term_init () */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
186 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
187 xfree (tty_con->term_entry_buffer);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
188 tty_con->term_entry_buffer = NULL;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
189 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
190 xfree (tty_con);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
191 CONSOLE_TTY_DATA (con) = NULL;
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
192 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 tty_delete_console (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->instream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 if (!CONSOLE_TTY_DATA (con)->is_stdio)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 close (CONSOLE_TTY_DATA (con)->infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 Vcontrolling_terminal = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 unmunge_tty_process_group ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 free_tty_console_struct (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 static struct console *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 decode_tty_console (Lisp_Object console)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 XSETCONSOLE (console, decode_console (console));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 CHECK_TTY_CONSOLE (console);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 return XCONSOLE (console);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
219 DEFUN ("console-tty-terminal-type", Fconsole_tty_terminal_type,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
220 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Return the terminal type of TTY console CONSOLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
222 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
223 (console))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 return CONSOLE_TTY_DATA (decode_tty_console (console))->terminal_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
228 DEFUN ("console-tty-controlling-process", Fconsole_tty_controlling_process,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
229 0, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
230 Return the controlling process of tty console CONSOLE.
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
231 */
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
232 (console))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
233 {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
234 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
235 }
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
236
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
237 #ifdef MULE
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
238
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
239 DEFUN ("console-tty-input-coding-system", Fconsole_tty_input_coding_system,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
240 0, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
241 Return the input coding system of tty console CONSOLE.
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
242 */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
243 (console))
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
244 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
245 return decoding_stream_coding_system
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
246 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream));
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
247 }
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
248
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
249 DEFUN ("set-console-tty-input-coding-system", Fset_console_tty_input_coding_system,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
250 0, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
251 Set the input coding system of tty console CONSOLE to CODESYS.
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
252 CONSOLE defaults to the selected console.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
253 CODESYS defaults to the value of `keyboard-coding-system'.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
254 */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
255 (console, codesys))
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
256 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
257 set_decoding_stream_coding_system
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
258 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
259 Fget_coding_system (NILP (codesys) ? Vkeyboard_coding_system : codesys));
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
260 return Qnil;
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
261 }
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
262
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
263 DEFUN ("console-tty-output-coding-system", Fconsole_tty_output_coding_system,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
264 0, 1, 0, /*
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
265 Return TTY CONSOLE's output coding system.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
266 */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
267 (console))
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
268 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
269 return encoding_stream_coding_system
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
270 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream));
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
271 }
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
272
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
273 DEFUN ("set-console-tty-output-coding-system", Fset_console_tty_output_coding_system,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
274 0, 2, 0, /*
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
275 Set the coding system of tty output of console CONSOLE to CODESYS.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
276 CONSOLE defaults to the selected console.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
277 CODESYS defaults to the value of `terminal-coding-system'.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
278 */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
279 (console, codesys))
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
280 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
281 set_encoding_stream_coding_system
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
282 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
283 Fget_coding_system (NILP (codesys) ? Vterminal_coding_system : codesys));
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
284 return Qnil;
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
285 }
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
286
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
287 /* ### Move this function to lisp */
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
288 DEFUN ("set-console-tty-coding-system", Fset_console_tty_coding_system,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
289 0, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
290 Set the input and output coding systems of tty console CONSOLE to CODESYS.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
291 CONSOLE defaults to the selected console.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
292 If CODESYS is nil, the values of `keyboard-coding-system' and
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
293 `terminal-coding-system' will be used for the input and
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
294 output coding systems of CONSOLE.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
295 */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
296 (console, codesys))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
297 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
298 Fset_console_tty_input_coding_system (console, codesys);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
299 Fset_console_tty_output_coding_system (console, codesys);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
300 return Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
301 }
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
302 #endif /* MULE */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
303
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
304
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 tty_semi_canonicalize_console_connection (Lisp_Object connection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 {
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
309 return stream_semi_canonicalize_console_connection (connection, errb);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 tty_canonicalize_console_connection (Lisp_Object connection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 {
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
316 return stream_canonicalize_console_connection (connection, errb);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 tty_semi_canonicalize_device_connection (Lisp_Object connection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 {
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
323 return stream_semi_canonicalize_console_connection (connection, errb);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 tty_canonicalize_device_connection (Lisp_Object connection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 {
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
330 return stream_canonicalize_console_connection (connection, errb);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 syms_of_console_tty (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
341 DEFSUBR (Fconsole_tty_terminal_type);
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
342 DEFSUBR (Fconsole_tty_controlling_process);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 defsymbol (&Qterminal_type, "terminal-type");
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 80
diff changeset
344 defsymbol (&Qcontrolling_process, "controlling-process");
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
345 #ifdef MULE
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
346 DEFSUBR (Fconsole_tty_output_coding_system);
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
347 DEFSUBR (Fset_console_tty_output_coding_system);
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
348 DEFSUBR (Fconsole_tty_input_coding_system);
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
349 DEFSUBR (Fset_console_tty_input_coding_system);
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 207
diff changeset
350 DEFSUBR (Fset_console_tty_coding_system);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
351 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 console_type_create_tty (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 INITIALIZE_CONSOLE_TYPE (tty, "tty", "console-tty-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 /* console methods */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 CONSOLE_HAS_METHOD (tty, init_console);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 CONSOLE_HAS_METHOD (tty, mark_console);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 CONSOLE_HAS_METHOD (tty, initially_selected_for_input);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 CONSOLE_HAS_METHOD (tty, delete_console);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 CONSOLE_HAS_METHOD (tty, canonicalize_console_connection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 CONSOLE_HAS_METHOD (tty, canonicalize_device_connection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 CONSOLE_HAS_METHOD (tty, semi_canonicalize_console_connection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 CONSOLE_HAS_METHOD (tty, semi_canonicalize_device_connection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 vars_of_console_tty (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 Fprovide (Qtty);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 }