*** empty log message ***
[emacs.git] / lisp / rlogin.el
blobb3e2762bad57fbe34ae1ba6448621fa9579b89df
1 ;;; rlogin.el --- remote login interface
3 ;; Maintainer: Noah Friedman <friedman@prep.ai.mit.edu>
4 ;; Keywords: unix, comm
6 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
7 ;;
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to: The Free Software Foundation,
20 ;; Inc.; 675 Massachusetts Avenue.; Cambridge, MA 02139, USA.
22 ;;; Commentary:
24 ;; Support for remote logins using `rlogin'.
26 ;; Todo: add directory tracking using ange-ftp style patchnames for the cwd.
28 ;;; Code:
30 (require 'comint)
32 (defvar rlogin-program "rlogin"
33 "*Name of program to invoke rlogin")
35 (defvar rlogin-explicit-args nil
36 "*List of arguments to pass to rlogin on the command line.")
38 (defvar rlogin-mode-hook nil
39 "*Hooks to run after setting current buffer to rlogin-mode.")
41 ;; I think this is so obnoxious I refuse to enable it by default.
42 ;; In any case, there is a bug with regards to generating a quit while
43 ;; reading keyboard input in a process filter, so until that's fixed it's
44 ;; not safe to enable this anyway.
45 (defvar rlogin-password-paranoia nil
46 "*If non-`nil', query user for a password in the minibuffer when a
47 Password: prompt appears. Stars will echo as characters are type.
49 It's also possible to selectively enter passwords without echoing them in
50 the minibuffer using the function `rlogin-password'.")
52 (defvar rlogin-last-input-line nil nil)
54 ;; Initialize rlogin mode map.
55 (defvar rlogin-mode-map '())
56 (cond ((not rlogin-mode-map)
57 (setq rlogin-mode-map (full-copy-sparse-keymap comint-mode-map))
58 ;(define-key rlogin-mode-map "\M-\t" 'comint-dynamic-complete)
59 ;(define-key rlogin-mode-map "\M-?" 'comint-dynamic-list-completions)
60 (define-key rlogin-mode-map "\C-c\C-c" 'rlogin-send-Ctrl-C)
61 (define-key rlogin-mode-map "\C-c\C-z" 'rlogin-send-Ctrl-Z)
62 (define-key rlogin-mode-map "\C-c\C-\\" 'rlogin-send-Ctrl-backslash)
63 (define-key rlogin-mode-map "\C-d" 'rlogin-delchar-or-send-Ctrl-D)))
65 ;;;###autoload
66 (defun rlogin (&optional prefix host)
67 "Open a network login connection to HOST via the `rlogin' program.
68 Input is sent line-at-a-time to the remote connection.
70 Communication with HOST is recorded in a buffer *rlogin-HOST*.
71 If a prefix argument is given and the buffer *rlogin-HOST* already exists,
72 a new buffer with a different connection will be made.
74 The variable `rlogin-program' contains the name of the actual program to
75 run. It can be a relative or absolute path.
77 The variable `rlogin-explicit-args' is a list of arguments to give to
78 the rlogin when starting."
79 (interactive (list current-prefix-arg
80 (read-from-minibuffer "Open rlogin connection to host: ")))
81 (let* ((buffer-name (format "*rlogin-%s*" host))
82 (args (if (and rlogin-explicit-args (listp rlogin-explicit-args))
83 (cons host rlogin-explicit-args)
84 (list host)))
85 proc)
86 (and prefix (setq buffer-name
87 (buffer-name (generate-new-buffer buffer-name))))
88 (switch-to-buffer buffer-name)
89 (or (comint-check-proc buffer-name)
90 (progn
91 (comint-mode)
92 (comint-exec (current-buffer) buffer-name rlogin-program nil args)
93 (setq proc (get-process buffer-name))
94 (set-marker (process-mark proc) (point-min))
95 (set-process-filter proc 'rlogin-filter)
96 (rlogin-mode)))))
98 ;;;###autoload
99 (defun rlogin-with-args (host args)
100 "Open a new rlogin connection to HOST, even if one already exists.
101 String ARGS is given as arguments to the `rlogin' program, overriding the
102 value of `rlogin-explicit-args'."
103 (interactive (list (read-from-minibuffer "Open rlogin connection to host: ")
104 (read-from-minibuffer "with arguments: ")))
105 (let ((old-match-data (match-data))
106 (rlogin-explicit-args nil))
107 (unwind-protect
108 (progn
109 (while (string-match "[ \t]*\\([^ \t]\\)+$" args)
110 (setq rlogin-explicit-args
111 (cons (substring args
112 (match-beginning 1)
113 (match-end 1))
114 rlogin-explicit-args)
115 args (substring args 0 (match-beginning 0)))))
116 (store-match-data old-match-data))
117 (rlogin 1 host)))
119 ;;;###autoload
120 (defun rlogin-password ()
121 "Play the paranoia game by not echoing entered password in buffer
122 (stars will echo in the minibuffer instead."
123 (interactive)
124 (let ((input (comint-read-noecho "Enter password: " 'stars)))
125 (insert-before-markers "\n")
126 (comint-send-string (get-buffer-process (current-buffer))
127 (format "%s\n" input))))
129 ;;;###autoload
130 (defun rlogin-mode ()
131 (interactive)
132 (kill-all-local-variables)
133 (comint-mode)
134 (setq comint-prompt-regexp shell-prompt-pattern)
135 (setq major-mode 'rlogin-mode)
136 (setq mode-name "rlogin")
137 (use-local-map rlogin-mode-map)
138 (run-hooks 'rlogin-mode-hook))
140 (defun rlogin-filter (proc string)
141 (let ((old-buffer (current-buffer))
142 (old-match-data (match-data))
143 at-max-pos
144 moving)
145 (unwind-protect
146 (progn
147 (set-buffer (process-buffer proc))
148 (setq moving (= (point) (process-mark proc)))
149 (save-excursion
150 (goto-char (process-mark proc))
151 (save-restriction
152 (let ((beg (point)))
153 (insert-before-markers string)
154 (narrow-to-region beg (point))
155 (goto-char (point-min))
156 (while (search-forward "\C-m" nil t)
157 (delete-char -1))
158 (and rlogin-password-paranoia
159 (setq string (buffer-substring (point-min) (point-max))))
160 (goto-char (point-max))))
161 (set-marker (process-mark proc) (point)))
162 (and moving
163 (goto-char (process-mark proc))))
164 (set-buffer old-buffer)
165 (store-match-data old-match-data)))
166 (and rlogin-password-paranoia
167 (string= "Password:" string)
168 (let ((input (comint-read-noecho "Enter password: " 'stars)))
169 (and input
170 (progn
171 (insert-before-markers "\n")
172 (comint-send-string proc (format "%s\n" input)))))))
174 (defun rlogin-send-Ctrl-C ()
175 (interactive)
176 (send-string nil "\C-c"))
178 (defun rlogin-send-Ctrl-Z ()
179 (interactive)
180 (send-string nil "\C-z"))
182 (defun rlogin-send-Ctrl-backslash ()
183 (interactive)
184 (send-string nil "\C-\\"))
186 (defun rlogin-delchar-or-send-Ctrl-D (arg)
187 "Delete ARG characters forward, or send a C-d to process if at end of
188 buffer."
189 (interactive "p")
190 (if (eobp)
191 (send-string nil "\C-d")
192 (delete-char arg)))
194 ;;; rlogin.el ends here