Mercurial > emacs
annotate lisp/telnet.el @ 3860:70bdc91ef161
* subr.el (event-end): Modified to account for multi-click events.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Tue, 22 Jun 1993 02:02:00 +0000 |
parents | ec0c98304624 |
children | f00905dd8a41 |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; telnet.el --- run a telnet session from within an Emacs buffer |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
2 |
841 | 3 ;;; Copyright (C) 1985, 1988, 1992 Free Software Foundation, Inc. |
4 | |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
5 ;; Author: William F. Schelter |
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
6 ;; Maintainer: FSF |
48 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
707 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
48 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2562 | 24 ;;; Commentary: |
25 | |
26 ;; This mode is intended to be used for telnet or rsh to a remode host; | |
27 ;; `telnet' and `rsh' are the two entry points. Multiple telnet or rsh | |
28 ;; sessions are supported. | |
29 ;; | |
30 ;; Normally, input is sent to the remote telnet/rsh line-by-line, as you | |
31 ;; type RET or LFD. C-c C-c sends a C-c to the remote immediately; | |
32 ;; C-c C-z sends C-z immediately. C-c C-q followed by any character | |
33 ;; sends that character immediately. | |
34 ;; | |
35 ;; All RET characters are filtered out of the output coming back from the | |
36 ;; remote system. The mode tries to do other useful translations based | |
37 ;; on what it sees coming back from the other system before the password | |
38 ;; query. It knows about UNIX, ITS, TOPS-20 and Explorer systems. | |
39 | |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
40 ;;; Code: |
48 | 41 |
2562 | 42 ;; to do fix software types for lispm: |
43 ;; to eval current expression. Also to try to send escape keys correctly. | |
44 ;; essentially we'll want the rubout-handler off. | |
48 | 45 |
46 ;; filter is simplistic but should be okay for typical shell usage. | |
47 ;; needs hacking if it is going to deal with asynchronous output in a sane | |
48 ;; manner | |
49 | |
50 (require 'comint) | |
707 | 51 |
48 | 52 (defvar telnet-new-line "\r") |
53 (defvar telnet-mode-map nil) | |
54 (defvar telnet-prompt-pattern "^[^#$%>]*[#$%>] *") | |
55 (defvar telnet-replace-c-g nil) | |
56 (make-variable-buffer-local | |
57 (defvar telnet-remote-echoes t | |
58 "True if the telnet process will echo input.")) | |
59 (make-variable-buffer-local | |
60 (defvar telnet-interrupt-string "\C-c" "String sent by C-c.")) | |
61 | |
62 (defvar telnet-count 0 | |
63 "Number of output strings read from the telnet process | |
64 while looking for the initial password.") | |
65 | |
66 (defvar telnet-initial-count -50 | |
1577 | 67 "Initial value of `telnet-count'. Should be set to the negative of the |
48 | 68 number of terminal writes telnet will make setting up the host connection.") |
69 | |
70 (defvar telnet-maximum-count 4 | |
1577 | 71 "Maximum value `telnet-count' can have. |
48 | 72 After this many passes, we stop looking for initial setup data. |
73 Should be set to the number of terminal writes telnet will make | |
74 rejecting one login and prompting for the again for a username and password.") | |
75 | |
76 (defun telnet-interrupt-subjob () | |
77 (interactive) | |
78 "Interrupt the program running through telnet on the remote host." | |
79 (send-string nil telnet-interrupt-string)) | |
80 | |
81 (defun telnet-c-z () | |
82 (interactive) | |
83 (send-string nil "\C-z")) | |
84 | |
85 (defun send-process-next-char () | |
86 (interactive) | |
87 (send-string nil | |
88 (char-to-string | |
89 (let ((inhibit-quit t)) | |
90 (prog1 (read-char) | |
91 (setq quit-flag nil)))))) | |
92 | |
93 ; initialization on first load. | |
94 (if telnet-mode-map | |
95 nil | |
96 (setq telnet-mode-map (copy-keymap comint-mode-map)) | |
97 (define-key telnet-mode-map "\C-m" 'telnet-send-input) | |
98 ; (define-key telnet-mode-map "\C-j" 'telnet-send-input) | |
99 (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char) | |
100 (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob) | |
101 (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z)) | |
102 | |
103 ;;maybe should have a flag for when have found type | |
104 (defun telnet-check-software-type-initialize (string) | |
105 "Tries to put correct initializations in. Needs work." | |
106 (let ((case-fold-search t)) | |
107 (cond ((string-match "unix" string) | |
108 (setq telnet-prompt-pattern comint-prompt-regexp) | |
109 (setq telnet-new-line "\n")) | |
110 ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g | |
111 (setq telnet-prompt-pattern "[@>]*")) | |
112 ((string-match "its" string) | |
113 (setq telnet-prompt-pattern "^[^*>]*[*>] *")) | |
114 ((string-match "explorer" string) ;;explorer telnet needs work | |
115 (setq telnet-replace-c-g ?\n)))) | |
116 (setq comint-prompt-regexp telnet-prompt-pattern)) | |
117 | |
118 (defun telnet-initial-filter (proc string) | |
119 ;For reading up to and including password; also will get machine type. | |
120 (cond ((string-match "No such host" string) | |
121 (kill-buffer (process-buffer proc)) | |
122 (error "No such host.")) | |
123 ((string-match "passw" string) | |
124 (telnet-filter proc string) | |
125 (let* ((echo-keystrokes 0) | |
126 (password (read-password))) | |
127 (setq telnet-count 0) | |
128 (send-string proc (concat password telnet-new-line)))) | |
129 (t (telnet-check-software-type-initialize string) | |
130 (telnet-filter proc string) | |
131 (cond ((> telnet-count telnet-maximum-count) | |
132 (set-process-filter proc 'telnet-filter)) | |
133 (t (setq telnet-count (1+ telnet-count))))))) | |
134 | |
3562
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
135 ;; Identical to comint-simple-send, except that it sends telnet-new-line |
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
136 ;; instead of "\n". |
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
137 (defun telnet-simple-send (proc string) |
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
138 (comint-send-string proc string) |
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
139 (comint-send-string proc telnet-new-line)) |
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
140 |
48 | 141 (defun telnet-filter (proc string) |
142 (let ((at-end | |
143 (and (eq (process-buffer proc) (current-buffer)) | |
144 (= (point) (point-max))))) | |
145 (save-excursion | |
146 (set-buffer (process-buffer proc)) | |
147 (goto-char (process-mark proc)) | |
148 (let ((now (point))) | |
707 | 149 ;; Insert STRING, omitting all C-m characters. |
48 | 150 (let ((index 0) c-m) |
151 (while (setq c-m (string-match "\C-m" string index)) | |
152 (insert-before-markers (substring string index c-m)) | |
153 (setq index (1+ c-m))) | |
154 (insert-before-markers (substring string index))) | |
155 (and telnet-replace-c-g | |
156 (subst-char-in-region now (point) ?\C-g telnet-replace-c-g))) | |
157 ; (if (and (integer-or-marker-p last-input-start) | |
158 ; (marker-position last-input-start) | |
159 ; telnet-remote-echoes) | |
160 ; (delete-region last-input-start last-input-end)) | |
161 ) | |
162 (if at-end | |
163 (goto-char (point-max))))) | |
164 | |
165 (defun telnet-send-input () | |
166 (interactive) | |
707 | 167 ; (comint-send-input telnet-new-line telnet-remote-echoes) |
168 (comint-send-input) | |
169 (if telnet-remote-echoes | |
170 (delete-region comint-last-input-start | |
171 comint-last-input-end))) | |
48 | 172 |
258 | 173 ;;;###autoload |
48 | 174 (defun telnet (arg) |
175 "Open a network login connection to host named HOST (a string). | |
176 Communication with HOST is recorded in a buffer *HOST-telnet*. | |
177 Normally input is edited in Emacs and sent a line at a time." | |
178 (interactive "sOpen telnet connection to host: ") | |
179 (let ((name (concat arg "-telnet" ))) | |
180 (switch-to-buffer (make-comint name "telnet")) | |
181 (set-process-filter (get-process name) 'telnet-initial-filter) | |
1414
2ba9b06d4247
(telnet): Wait for telnet output before sending `open'.
Richard M. Stallman <rms@gnu.org>
parents:
841
diff
changeset
|
182 ;; Don't send the `open' cmd till telnet is ready for it. |
2ba9b06d4247
(telnet): Wait for telnet output before sending `open'.
Richard M. Stallman <rms@gnu.org>
parents:
841
diff
changeset
|
183 (accept-process-output (get-process name)) |
1418
d8dc740867ee
(telnet): Do erase-buffer after the initial output.
Richard M. Stallman <rms@gnu.org>
parents:
1414
diff
changeset
|
184 (erase-buffer) |
48 | 185 (send-string name (concat "open " arg "\n")) |
186 (telnet-mode) | |
3562
ec0c98304624
(telnet-simple-send): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2562
diff
changeset
|
187 (setq comint-input-sender 'telnet-simple-send) |
48 | 188 (setq telnet-count telnet-initial-count))) |
189 | |
190 (defun telnet-mode () | |
2562 | 191 "This mode is for using telnet (or rsh) from a buffer to another host. |
1577 | 192 It has most of the same commands as comint-mode. |
48 | 193 There is a variable ``telnet-interrupt-string'' which is the character |
194 sent to try to stop execution of a job on the remote host. | |
195 Data is sent to the remote host when RET is typed. | |
196 | |
197 \\{telnet-mode-map} | |
2562 | 198 " |
48 | 199 (interactive) |
200 (comint-mode) | |
201 (setq major-mode 'telnet-mode | |
202 mode-name "Telnet" | |
203 comint-prompt-regexp telnet-prompt-pattern) | |
204 (use-local-map telnet-mode-map) | |
205 (run-hooks 'telnet-mode-hook)) | |
206 | |
2562 | 207 ;;;###autoload |
208 (defun rsh (arg) | |
209 "Open a network login connection to host named HOST (a string). | |
210 Communication with HOST is recorded in a buffer *HOST-rsh*. | |
211 Normally input is edited in Emacs and sent a line at a time." | |
212 (interactive "sOpen rsh connection to host: ") | |
213 (require 'shell) | |
214 (let ((name (concat arg "-rsh" ))) | |
215 (switch-to-buffer (make-comint name "rsh")) | |
216 (set-process-filter (get-process name) 'telnet-initial-filter) | |
217 (telnet-mode) | |
218 (setq telnet-count -16))) | |
219 | |
48 | 220 (defun read-password () |
221 (let ((answ "") tem) | |
222 (message "Reading password...") | |
557 | 223 (while (prog1 (not (memq (setq tem (read-char)) '(?\C-m ?\n ?\C-g))) |
224 (setq quit-flag nil)) | |
48 | 225 (setq answ (concat answ (char-to-string tem)))) |
226 answ)) | |
584 | 227 |
228 (provide 'telnet) | |
229 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
230 ;;; telnet.el ends here |