|
|
1.1 root 1: ;; Copyright (C) 1985 Free Software Foundation
2:
3: ;; This file is part of GNU Emacs.
4:
5: ;; GNU Emacs is distributed in the hope that it will be useful,
6: ;; but WITHOUT ANY WARRANTY. No author or distributor
7: ;; accepts responsibility to anyone for the consequences of using it
8: ;; or for whether it serves any particular purpose or works at all,
9: ;; unless he says so in writing. Refer to the GNU Emacs General Public
10: ;; License for full details.
11:
12: ;; Everyone is granted permission to copy, modify and redistribute
13: ;; GNU Emacs, but only under the conditions described in the
14: ;; GNU Emacs General Public License. A copy of this license is
15: ;; supposed to have been given to you along with GNU Emacs so you
16: ;; can know your rights and responsibilities. It should be in a
17: ;; file named COPYING. Among other things, the copyright notice
18: ;; and this notice must be preserved on all copies.
19:
20:
21: ;; Author William F. Schelter
22:
23: ;;to do fix software types for lispm:
24: ;;to eval current expression. Also to try to send escape keys correctly.
25: ;;essentially we'll want the rubout-handler off.
26:
27: (defvar telnet-new-line "\r")
28: (defvar telnet-mode-map nil)
29: (defvar telnet-prompt-pattern "^[^#$%>]*[#$%>] *")
30: (defvar telnet-interrupt-string "\^c" "String sent by C-c.")
31: (defvar telnet-count 0)
32: (defvar telnet-replace-c-g nil)
33: (defvar telnet-remote-echoes nil)
34:
35: (defun telnet-interrupt-subjob ()
36: (interactive)
37: "Interrupt the program running through telnet on the remote host."
38: (send-string nil telnet-interrupt-string))
39:
40: (defun telnet-c-z ()
41: (interactive)
42: (send-string nil ""))
43:
44: (defun send-process-next-char ()
45: (interactive)
46: (send-string nil
47: (char-to-string
48: (let ((inhibit-quit t))
49: (prog1 (read-char)
50: (setq quit-flag nil))))))
51:
52: (setq telnet-mode-map (make-sparse-keymap))
53:
54: (progn
55: (define-key telnet-mode-map "\C-m" 'telnet-send-input)
56: (define-key telnet-mode-map "\C-j" 'telnet-send-input)
57: (define-key telnet-mode-map "\C-c\C-d" 'shell-send-eof)
58: (define-key telnet-mode-map "\C-c\C-q" 'send-process-next-char)
59: (define-key telnet-mode-map "\C-c\C-c" 'telnet-interrupt-subjob)
60: (define-key telnet-mode-map "\C-c\C-z" 'telnet-c-z)
61: (define-key telnet-mode-map "\C-c\C-u" 'kill-shell-input)
62: (define-key telnet-mode-map "\C-c\C-w" 'backward-kill-word)
63: (define-key telnet-mode-map "\C-c\C-o" 'kill-output-from-shell)
64: (define-key telnet-mode-map "\C-c\C-r" 'show-output-from-shell)
65: (define-key telnet-mode-map "\C-c\C-y" 'copy-last-shell-input))
66:
67: ;;maybe should have a flag for when have found type
68: (defun telnet-check-software-type-initialize (string)
69: "Tries to put correct initializations in. Needs work."
70: (cond ((string-match "unix" string)
71: (setq telnet-prompt-pattern shell-prompt-pattern)
72: (setq telnet-new-line "\n"))
73: ((string-match "tops-20" string) ;;maybe add telnet-replace-c-g
74: (setq telnet-prompt-pattern "[@>]*"))
75: ((string-match "its" string)
76: (setq telnet-prompt-pattern "^[^*>]*[*>] *"))
77: ((string-match "explorer" string) ;;explorer telnet needs work
78: (setq telnet-replace-c-g ?\n))
79: ))
80:
81: (defun telnet-initial-filter (proc string)
82: ;For reading up to and including password; also will get machine type.
83: (cond ((string-match "No such host" string)
84: (kill-buffer (process-buffer proc))
85: (error "No such host."))
86: ((string-match "passw" string)
87: (telnet-filter proc string)
88: (let ((echo-keystrokes 0))
89: (setq password (read-password)))
90: (setq telnet-count 0)
91: (send-string proc (concat password telnet-new-line)))
92: (t (telnet-check-software-type-initialize string)
93: (telnet-filter proc string)
94: (cond ((> telnet-count 4)
95: (set-process-filter proc 'telnet-filter))
96: (t (setq telnet-count (1+ telnet-count)))))))
97:
98: (defun telnet-filter (proc string)
99: (save-excursion
100: (set-buffer (process-buffer proc))
101: (goto-char (point-max))
102: (let ((now (point)))
103: (insert string)
104: (subst-char-in-region now (point) ?\^m ?\ )
105: (and telnet-replace-c-g (subst-char-in-region now (point) ?\^g telnet-replace-c-g)))
106: (if (process-mark proc)
107: (set-marker (process-mark proc) (point)))
108: (if (and (integer-or-marker-p last-input-start)
109: (marker-position last-input-start)
110: telnet-remote-echoes)
111: (delete-region last-input-start last-input-end)))
112: (if (eq (process-buffer proc)
113: (current-buffer))
114: (goto-char (point-max))))
115:
116: (defun delete-char-or-send-eof (arg killp)
117: "At end of buffer, send eof to subshell. Otherwise delete character."
118: (interactive "p\nP")
119: (if (and (eobp) (not killp))
120: (process-send-eof)
121: (delete-char arg killp)))
122:
123: (defun telnet-send-input ()
124: "Send input to remote host
125: At end of buffer, sends all text after last output
126: as input to the telnet, including a telnet-new-line inserted at the end.
127: Not at end, copies current line to the end of the buffer and sends it,
128: after first attempting to discard any prompt at the beginning of the line
129: by matching the regexp that is the value of telnet-prompt-pattern if possible."
130: (interactive)
131: (let (copied)
132: (end-of-line)
133: (if (eobp)
134: (progn
135: (move-marker last-input-start
136: (process-mark (get-buffer-process (current-buffer))))
137: (move-marker last-input-end (point)))
138: (beginning-of-line)
139: (re-search-forward telnet-prompt-pattern nil t)
140: (let ((copy (buffer-substring (point)
141: (progn (forward-line 1) (point)))))
142: (goto-char (point-max))
143: (move-marker last-input-start (point))
144: (insert copy) (setq copied t)
145: (move-marker last-input-end (point))))
146: (save-excursion
147: (goto-char last-input-start)
148: (let ((process (get-buffer-process (current-buffer))))
149: (send-region process last-input-start last-input-end)
150: (if (not copied) (send-string process telnet-new-line))
151: (set-marker (process-mark process) (point))))))
152:
153: (defun telnet (arg)
154: "Open a network login connection to host named HOST (a string).
155: Communication with HOST is recorded in a buffer *HOST-telnet*.
156: Normally input is edited in Emacs and sent a line at a time."
157: (interactive "sOpen telnet connection to host: ")
158: (require 'shell)
159: (let ((name (concat arg "-telnet" )))
160: (switch-to-buffer (make-shell name "telnet"))
161: (set-process-filter (get-process name) 'telnet-initial-filter)
162: (erase-buffer)
163: (send-string name (concat "open " arg "\n"))
164: (telnet-mode)
165: (setq telnet-count -16)))
166:
167: (defun read-password ()
168: (let ((answ "") tem)
169: (while (not(or (= (setq tem (read-char)) ?\^m)
170: (= tem ?\n)))
171: (setq answ (concat answ (char-to-string tem))))
172: answ))
173:
174: (defun telnet-mode ()
175: "This mode is for use during telnet from a buffer to another
176: host. It has most of the same commands as shell mode.
177: There is a variable `telnet-interrupt-string' which is the character
178: sent to try to stop execution of a job on the remote host.
179: Data is sent to the remote host when `return' is typed.
180: Thus if you may need to edit the data before sending you
181: should use c-n to move down a line. Then you can return
182: to alter a previous line. Of course you should not use this
183: mode of telnet if you want to run emacs like programs on the
184: remote host (at least not yet!).
185:
186: The following commands imitate the usual Unix interrupt and
187: editing control characters:
188: \\{telnet-mode-map}
189:
190: Bugs:
191: --Replace
by a space, really should remove.
192: --For Unix interacts poorly with tcsh although csh,sh,ksh are ok."
193: (interactive)
194: (kill-all-local-variables)
195: (setq major-mode 'telnet-mode)
196: (setq mode-name "Telnet")
197: (setq mode-line-process '(": %s"))
198: (make-local-variable 'last-input-start)
199: (use-local-map telnet-mode-map)
200: (let ((tem telnet-prompt-pattern))
201: (make-local-variable 'telnet-prompt-pattern)
202: (setq telnet-prompt-pattern tem))
203: (make-local-variable 'telnet-interrupt-string)
204: (setq telnet-interrupt-string "")
205: (make-local-variable 'telnet-new-line)
206: (setq telnet-new-line "\r")
207: (make-local-variable 'last-input-start)
208: (setq last-input-start (make-marker))
209: (make-local-variable 'last-input-end)
210: (setq last-input-end (make-marker))
211: (make-local-variable 'telnet-remote-echoes)
212: (setq telnet-remote-echoes t)
213: (make-local-variable 'telnet-replace-c-g)
214: (setq telnet-replace-c-g nil))
215:
216:
217:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.