annotate src/console-tty.c @ 380:8626e4521993 r21-2-5

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