Mercurial > emacs
annotate lisp/telnet.el @ 2437:290a7be0d392
Initial revision
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 31 Mar 1993 08:13:16 +0000 |
parents | a52da8d63ff3 |
children | 2715e893d220 |
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 | |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
24 ;;; Code: |
48 | 25 |
26 ;;to do fix software types for lispm: | |
27 ;;to eval current expression. Also to try to send escape keys correctly. | |
28 ;;essentially we'll want the rubout-handler off. | |
29 | |
30 ;; filter is simplistic but should be okay for typical shell usage. | |
31 ;; needs hacking if it is going to deal with asynchronous output in a sane | |
32 ;; manner | |
33 | |
34 (require 'comint) | |
707 | 35 |
48 | 36 (defvar telnet-new-line "\r") |
37 (defvar telnet-mode-map nil) | |
38 (defvar telnet-prompt-pattern "^[^#$%>]*[#$%>] *") | |
39 (defvar telnet-replace-c-g nil) | |
40 (make-variable-buffer-local | |
41 (defvar telnet-remote-echoes t | |
42 "True if the telnet process will echo input.")) | |
43 (make-variable-buffer-local | |
44 (defvar telnet-interrupt-string "\C-c" "String sent by C-c.")) | |
45 | |
46 (defvar telnet-count 0 | |
47 "Number of output strings read from the telnet process | |
48 while looking for the initial password.") | |
49 | |
50 (defvar telnet-initial-count -50 | |
1577 | 51 "Initial value of `telnet-count'. Should be set to the negative of the |
48 | 52 number of terminal writes telnet will make setting up the host connection.") |
53 | |
54 (defvar telnet-maximum-count 4 | |
1577 | 55 "Maximum value `telnet-count' can have. |
48 | 56 After this many passes, we stop looking for initial setup data. |
57 Should be set to the number of terminal writes telnet will make | |
58 rejecting one login and prompting for the again for a username and password.") | |
59 | |
60 (defun telnet-interrupt-subjob () | |
61 (interactive) | |
62 "Interrupt the program running through telnet on the remote host." | |
63 (send-string nil telnet-interrupt-string)) | |
64 | |
65 (defun telnet-c-z () | |
66 (interactive) | |
67 (send-string nil "\C-z")) | |
68 | |
69 (defun send-process-next-char () | |
70 (interactive) | |
71 (send-string nil | |
72 (char-to-string | |
73 (let ((inhibit-quit t)) | |
74 (prog1 (read-char) | |
75 (setq quit-flag nil)))))) | |
76 | |
77 ; initialization on first load. | |
78 (if telnet-mode-map | |
79 nil | |
80 (setq telnet-mode-map (copy-keymap comint-mode-map)) | |
81 (define-key telnet-mode-map "\C-m" 'telnet-send-input) | |
82 ; (define-key telnet-mode-map "\C-j" 'telnet-send-input) | |
83 (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char) | |
84 (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob) | |
85 (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z)) | |
86 | |
87 ;;maybe should have a flag for when have found type | |
88 (defun telnet-check-software-type-initialize (string) | |
89 "Tries to put correct initializations in. Needs work." | |
90 (let ((case-fold-search t)) | |
91 (cond ((string-match "unix" string) | |
92 (setq telnet-prompt-pattern comint-prompt-regexp) | |
93 (setq telnet-new-line "\n")) | |
94 ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g | |
95 (setq telnet-prompt-pattern "[@>]*")) | |
96 ((string-match "its" string) | |
97 (setq telnet-prompt-pattern "^[^*>]*[*>] *")) | |
98 ((string-match "explorer" string) ;;explorer telnet needs work | |
99 (setq telnet-replace-c-g ?\n)))) | |
100 (setq comint-prompt-regexp telnet-prompt-pattern)) | |
101 | |
102 (defun telnet-initial-filter (proc string) | |
103 ;For reading up to and including password; also will get machine type. | |
104 (cond ((string-match "No such host" string) | |
105 (kill-buffer (process-buffer proc)) | |
106 (error "No such host.")) | |
107 ((string-match "passw" string) | |
108 (telnet-filter proc string) | |
109 (let* ((echo-keystrokes 0) | |
110 (password (read-password))) | |
111 (setq telnet-count 0) | |
112 (send-string proc (concat password telnet-new-line)))) | |
113 (t (telnet-check-software-type-initialize string) | |
114 (telnet-filter proc string) | |
115 (cond ((> telnet-count telnet-maximum-count) | |
116 (set-process-filter proc 'telnet-filter)) | |
117 (t (setq telnet-count (1+ telnet-count))))))) | |
118 | |
119 (defun telnet-filter (proc string) | |
120 (let ((at-end | |
121 (and (eq (process-buffer proc) (current-buffer)) | |
122 (= (point) (point-max))))) | |
123 (save-excursion | |
124 (set-buffer (process-buffer proc)) | |
125 (goto-char (process-mark proc)) | |
126 (let ((now (point))) | |
707 | 127 ;; Insert STRING, omitting all C-m characters. |
48 | 128 (let ((index 0) c-m) |
129 (while (setq c-m (string-match "\C-m" string index)) | |
130 (insert-before-markers (substring string index c-m)) | |
131 (setq index (1+ c-m))) | |
132 (insert-before-markers (substring string index))) | |
133 (and telnet-replace-c-g | |
134 (subst-char-in-region now (point) ?\C-g telnet-replace-c-g))) | |
135 ; (if (and (integer-or-marker-p last-input-start) | |
136 ; (marker-position last-input-start) | |
137 ; telnet-remote-echoes) | |
138 ; (delete-region last-input-start last-input-end)) | |
139 ) | |
140 (if at-end | |
141 (goto-char (point-max))))) | |
142 | |
143 (defun telnet-send-input () | |
144 (interactive) | |
707 | 145 ; (comint-send-input telnet-new-line telnet-remote-echoes) |
146 (comint-send-input) | |
147 (if telnet-remote-echoes | |
148 (delete-region comint-last-input-start | |
149 comint-last-input-end))) | |
48 | 150 |
258 | 151 ;;;###autoload |
48 | 152 (defun telnet (arg) |
153 "Open a network login connection to host named HOST (a string). | |
154 Communication with HOST is recorded in a buffer *HOST-telnet*. | |
155 Normally input is edited in Emacs and sent a line at a time." | |
156 (interactive "sOpen telnet connection to host: ") | |
157 (let ((name (concat arg "-telnet" ))) | |
158 (switch-to-buffer (make-comint name "telnet")) | |
159 (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
|
160 ;; 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
|
161 (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
|
162 (erase-buffer) |
48 | 163 (send-string name (concat "open " arg "\n")) |
164 (telnet-mode) | |
165 (setq telnet-count telnet-initial-count))) | |
166 | |
167 (defun telnet-mode () | |
1577 | 168 "This mode is for telnetting from a buffer to another host. |
169 It has most of the same commands as comint-mode. | |
48 | 170 There is a variable ``telnet-interrupt-string'' which is the character |
171 sent to try to stop execution of a job on the remote host. | |
172 Data is sent to the remote host when RET is typed. | |
173 | |
174 \\{telnet-mode-map} | |
175 | |
176 Bugs: | |
177 --Replaces by a space, really should remove." | |
178 (interactive) | |
179 (comint-mode) | |
180 (setq major-mode 'telnet-mode | |
181 mode-name "Telnet" | |
182 comint-prompt-regexp telnet-prompt-pattern) | |
183 (use-local-map telnet-mode-map) | |
184 (run-hooks 'telnet-mode-hook)) | |
185 | |
186 (defun read-password () | |
187 (let ((answ "") tem) | |
188 (message "Reading password...") | |
557 | 189 (while (prog1 (not (memq (setq tem (read-char)) '(?\C-m ?\n ?\C-g))) |
190 (setq quit-flag nil)) | |
48 | 191 (setq answ (concat answ (char-to-string tem)))) |
192 answ)) | |
584 | 193 |
194 (provide 'telnet) | |
195 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
196 ;;; telnet.el ends here |