annotate lisp/telnet.el @ 496:dcdf0a92df40

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Wed, 15 Jan 1992 19:43:09 +0000
parents 1e0bc00dca7a
children 46b8522b8f89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
82ef7404837f Initial revision
root <root>
parents:
diff changeset
1 ;; Copyright (C) 1985, 1988 Free Software Foundation, Inc.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
2
82ef7404837f Initial revision
root <root>
parents:
diff changeset
3 ;; This file is part of GNU Emacs.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
4
82ef7404837f Initial revision
root <root>
parents:
diff changeset
5 ;; GNU Emacs is free software; you can redistribute it and/or modify
82ef7404837f Initial revision
root <root>
parents:
diff changeset
6 ;; it under the terms of the GNU General Public License as published by
82ef7404837f Initial revision
root <root>
parents:
diff changeset
7 ;; the Free Software Foundation; either version 1, or (at your option)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
8 ;; any later version.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
9
82ef7404837f Initial revision
root <root>
parents:
diff changeset
10 ;; GNU Emacs is distributed in the hope that it will be useful,
82ef7404837f Initial revision
root <root>
parents:
diff changeset
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
82ef7404837f Initial revision
root <root>
parents:
diff changeset
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82ef7404837f Initial revision
root <root>
parents:
diff changeset
13 ;; GNU General Public License for more details.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
14
82ef7404837f Initial revision
root <root>
parents:
diff changeset
15 ;; You should have received a copy of the GNU General Public License
82ef7404837f Initial revision
root <root>
parents:
diff changeset
16 ;; along with GNU Emacs; see the file COPYING. If not, write to
82ef7404837f Initial revision
root <root>
parents:
diff changeset
17 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
18
82ef7404837f Initial revision
root <root>
parents:
diff changeset
19 ;; Author William F. Schelter
82ef7404837f Initial revision
root <root>
parents:
diff changeset
20
82ef7404837f Initial revision
root <root>
parents:
diff changeset
21 ;;to do fix software types for lispm:
82ef7404837f Initial revision
root <root>
parents:
diff changeset
22 ;;to eval current expression. Also to try to send escape keys correctly.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
23 ;;essentially we'll want the rubout-handler off.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
24
82ef7404837f Initial revision
root <root>
parents:
diff changeset
25 ;; filter is simplistic but should be okay for typical shell usage.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
26 ;; needs hacking if it is going to deal with asynchronous output in a sane
82ef7404837f Initial revision
root <root>
parents:
diff changeset
27 ;; manner
82ef7404837f Initial revision
root <root>
parents:
diff changeset
28
82ef7404837f Initial revision
root <root>
parents:
diff changeset
29 (require 'comint)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
30 (provide 'telnet)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
31
82ef7404837f Initial revision
root <root>
parents:
diff changeset
32 (defvar telnet-new-line "\r")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
33 (defvar telnet-mode-map nil)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
34 (defvar telnet-prompt-pattern "^[^#$%>]*[#$%>] *")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
35 (defvar telnet-replace-c-g nil)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
36 (make-variable-buffer-local
82ef7404837f Initial revision
root <root>
parents:
diff changeset
37 (defvar telnet-remote-echoes t
82ef7404837f Initial revision
root <root>
parents:
diff changeset
38 "True if the telnet process will echo input."))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
39 (make-variable-buffer-local
82ef7404837f Initial revision
root <root>
parents:
diff changeset
40 (defvar telnet-interrupt-string "\C-c" "String sent by C-c."))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
41
82ef7404837f Initial revision
root <root>
parents:
diff changeset
42 (defvar telnet-count 0
82ef7404837f Initial revision
root <root>
parents:
diff changeset
43 "Number of output strings read from the telnet process
82ef7404837f Initial revision
root <root>
parents:
diff changeset
44 while looking for the initial password.")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
45
82ef7404837f Initial revision
root <root>
parents:
diff changeset
46 (defvar telnet-initial-count -50
82ef7404837f Initial revision
root <root>
parents:
diff changeset
47 "Initial value of telnet-count. Should be set to the negative of the
82ef7404837f Initial revision
root <root>
parents:
diff changeset
48 number of terminal writes telnet will make setting up the host connection.")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
49
82ef7404837f Initial revision
root <root>
parents:
diff changeset
50 (defvar telnet-maximum-count 4
82ef7404837f Initial revision
root <root>
parents:
diff changeset
51 "Maximum value telnet-count can have.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
52 After this many passes, we stop looking for initial setup data.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
53 Should be set to the number of terminal writes telnet will make
82ef7404837f Initial revision
root <root>
parents:
diff changeset
54 rejecting one login and prompting for the again for a username and password.")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
55
82ef7404837f Initial revision
root <root>
parents:
diff changeset
56 (defun telnet-interrupt-subjob ()
82ef7404837f Initial revision
root <root>
parents:
diff changeset
57 (interactive)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
58 "Interrupt the program running through telnet on the remote host."
82ef7404837f Initial revision
root <root>
parents:
diff changeset
59 (send-string nil telnet-interrupt-string))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
60
82ef7404837f Initial revision
root <root>
parents:
diff changeset
61 (defun telnet-c-z ()
82ef7404837f Initial revision
root <root>
parents:
diff changeset
62 (interactive)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
63 (send-string nil "\C-z"))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
64
82ef7404837f Initial revision
root <root>
parents:
diff changeset
65 (defun send-process-next-char ()
82ef7404837f Initial revision
root <root>
parents:
diff changeset
66 (interactive)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
67 (send-string nil
82ef7404837f Initial revision
root <root>
parents:
diff changeset
68 (char-to-string
82ef7404837f Initial revision
root <root>
parents:
diff changeset
69 (let ((inhibit-quit t))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
70 (prog1 (read-char)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
71 (setq quit-flag nil))))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
72
82ef7404837f Initial revision
root <root>
parents:
diff changeset
73 ; initialization on first load.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
74 (if telnet-mode-map
82ef7404837f Initial revision
root <root>
parents:
diff changeset
75 nil
82ef7404837f Initial revision
root <root>
parents:
diff changeset
76 (setq telnet-mode-map (copy-keymap comint-mode-map))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
77 (define-key telnet-mode-map "\C-m" 'telnet-send-input)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
78 ; (define-key telnet-mode-map "\C-j" 'telnet-send-input)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
79 (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
80 (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
81 (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
82
82ef7404837f Initial revision
root <root>
parents:
diff changeset
83 ;;maybe should have a flag for when have found type
82ef7404837f Initial revision
root <root>
parents:
diff changeset
84 (defun telnet-check-software-type-initialize (string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
85 "Tries to put correct initializations in. Needs work."
82ef7404837f Initial revision
root <root>
parents:
diff changeset
86 (let ((case-fold-search t))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
87 (cond ((string-match "unix" string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
88 (setq telnet-prompt-pattern comint-prompt-regexp)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
89 (setq telnet-new-line "\n"))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
90 ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g
82ef7404837f Initial revision
root <root>
parents:
diff changeset
91 (setq telnet-prompt-pattern "[@>]*"))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
92 ((string-match "its" string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
93 (setq telnet-prompt-pattern "^[^*>]*[*>] *"))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
94 ((string-match "explorer" string) ;;explorer telnet needs work
82ef7404837f Initial revision
root <root>
parents:
diff changeset
95 (setq telnet-replace-c-g ?\n))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
96 (setq comint-prompt-regexp telnet-prompt-pattern))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
97
82ef7404837f Initial revision
root <root>
parents:
diff changeset
98 (defun telnet-initial-filter (proc string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
99 ;For reading up to and including password; also will get machine type.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
100 (cond ((string-match "No such host" string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
101 (kill-buffer (process-buffer proc))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
102 (error "No such host."))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
103 ((string-match "passw" string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
104 (telnet-filter proc string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
105 (let* ((echo-keystrokes 0)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
106 (password (read-password)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
107 (setq telnet-count 0)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
108 (send-string proc (concat password telnet-new-line))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
109 (t (telnet-check-software-type-initialize string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
110 (telnet-filter proc string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
111 (cond ((> telnet-count telnet-maximum-count)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
112 (set-process-filter proc 'telnet-filter))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
113 (t (setq telnet-count (1+ telnet-count)))))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
114
82ef7404837f Initial revision
root <root>
parents:
diff changeset
115 (defun telnet-filter (proc string)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
116 (let ((at-end
82ef7404837f Initial revision
root <root>
parents:
diff changeset
117 (and (eq (process-buffer proc) (current-buffer))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
118 (= (point) (point-max)))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
119 (save-excursion
82ef7404837f Initial revision
root <root>
parents:
diff changeset
120 (set-buffer (process-buffer proc))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
121 (goto-char (process-mark proc))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
122 (let ((now (point)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
123 (let ((index 0) c-m)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
124 (while (setq c-m (string-match "\C-m" string index))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
125 (insert-before-markers (substring string index c-m))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
126 (setq index (1+ c-m)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
127 (insert-before-markers (substring string index)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
128 (and telnet-replace-c-g
82ef7404837f Initial revision
root <root>
parents:
diff changeset
129 (subst-char-in-region now (point) ?\C-g telnet-replace-c-g)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
130 ; (if (and (integer-or-marker-p last-input-start)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
131 ; (marker-position last-input-start)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
132 ; telnet-remote-echoes)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
133 ; (delete-region last-input-start last-input-end))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
134 )
82ef7404837f Initial revision
root <root>
parents:
diff changeset
135 (if at-end
82ef7404837f Initial revision
root <root>
parents:
diff changeset
136 (goto-char (point-max)))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
137
82ef7404837f Initial revision
root <root>
parents:
diff changeset
138 (defun telnet-send-input ()
82ef7404837f Initial revision
root <root>
parents:
diff changeset
139 (interactive)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
140 (comint-send-input telnet-new-line telnet-remote-echoes))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
141
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 48
diff changeset
142 ;;;###autoload
48
82ef7404837f Initial revision
root <root>
parents:
diff changeset
143 (defun telnet (arg)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
144 "Open a network login connection to host named HOST (a string).
82ef7404837f Initial revision
root <root>
parents:
diff changeset
145 Communication with HOST is recorded in a buffer *HOST-telnet*.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
146 Normally input is edited in Emacs and sent a line at a time."
82ef7404837f Initial revision
root <root>
parents:
diff changeset
147 (interactive "sOpen telnet connection to host: ")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
148 (let ((name (concat arg "-telnet" )))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
149 (switch-to-buffer (make-comint name "telnet"))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
150 (set-process-filter (get-process name) 'telnet-initial-filter)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
151 (erase-buffer)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
152 (send-string name (concat "open " arg "\n"))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
153 (telnet-mode)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
154 (setq telnet-count telnet-initial-count)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
155
82ef7404837f Initial revision
root <root>
parents:
diff changeset
156 (defun telnet-mode ()
82ef7404837f Initial revision
root <root>
parents:
diff changeset
157 "This mode is for use during telnet from a buffer to another
82ef7404837f Initial revision
root <root>
parents:
diff changeset
158 host. It has most of the same commands as comint-mode.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
159 There is a variable ``telnet-interrupt-string'' which is the character
82ef7404837f Initial revision
root <root>
parents:
diff changeset
160 sent to try to stop execution of a job on the remote host.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
161 Data is sent to the remote host when RET is typed.
82ef7404837f Initial revision
root <root>
parents:
diff changeset
162
82ef7404837f Initial revision
root <root>
parents:
diff changeset
163 \\{telnet-mode-map}
82ef7404837f Initial revision
root <root>
parents:
diff changeset
164
82ef7404837f Initial revision
root <root>
parents:
diff changeset
165 Bugs:
82ef7404837f Initial revision
root <root>
parents:
diff changeset
166 --Replaces by a space, really should remove."
82ef7404837f Initial revision
root <root>
parents:
diff changeset
167 (interactive)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
168 (comint-mode)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
169 (setq major-mode 'telnet-mode
82ef7404837f Initial revision
root <root>
parents:
diff changeset
170 mode-name "Telnet"
82ef7404837f Initial revision
root <root>
parents:
diff changeset
171 comint-prompt-regexp telnet-prompt-pattern)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
172 (use-local-map telnet-mode-map)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
173 (run-hooks 'telnet-mode-hook))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
174
82ef7404837f Initial revision
root <root>
parents:
diff changeset
175 (defun read-password ()
82ef7404837f Initial revision
root <root>
parents:
diff changeset
176 (let ((answ "") tem)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
177 (message "Reading password...")
82ef7404837f Initial revision
root <root>
parents:
diff changeset
178 (while (not (or (= (setq tem (read-char)) ?\^m)
82ef7404837f Initial revision
root <root>
parents:
diff changeset
179 (= tem ?\n)))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
180 (setq answ (concat answ (char-to-string tem))))
82ef7404837f Initial revision
root <root>
parents:
diff changeset
181 answ))