1 ;;; rlogin.el --- remote login interface
3 ;; Author: Noah Friedman
4 ;; Maintainer: Noah Friedman <friedman@prep.ai.mit.edu>
5 ;; Keywords: unix, comm
7 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program; if not, write to: The Free Software Foundation,
21 ;; Inc.; 675 Massachusetts Avenue.; Cambridge, MA 02139, USA.
25 ;; Support for remote logins using `rlogin'.
26 ;; $Id: rlogin.el,v 1.18 1994/06/16 08:09:34 friedman Exp pot $
28 ;; If you wish for rlogin mode to prompt you in the minibuffer for
29 ;; passwords when a password prompt appears, just enter m-x send-invisible
30 ;; and type in your line, or add `comint-watch-for-password-prompt' to
31 ;; `comint-output-filter-functions'.
39 (defvar rlogin-program
"rlogin"
40 "*Name of program to invoke rlogin")
43 (defvar rlogin-explicit-args nil
44 "*List of arguments to pass to rlogin on the command line.")
47 (defvar rlogin-mode-hook nil
48 "*Hooks to run after setting current buffer to rlogin-mode.")
51 (defvar rlogin-process-connection-type nil
52 "*If non-`nil', use a pty for the local rlogin process.
53 If `nil', use a pipe (if pipes are supported on the local system).
55 Generally it is better not to waste ptys on systems which have a static
56 number of them. On the other hand, some implementations of `rlogin' assume
57 a pty is being used, and errors will result from using a pipe instead.")
60 (defvar rlogin-initially-track-cwd t
61 "*If non-`nil', do remote directory tracking via ange-ftp right away.
62 If `nil', you can still enable directory tracking by doing
63 `M-x dirtrack-toggle'.")
65 ;; Initialize rlogin mode map.
66 (defvar rlogin-mode-map
'())
67 (cond ((not rlogin-mode-map
)
68 (setq rlogin-mode-map
(cons 'keymap shell-mode-map
))
69 (define-key rlogin-mode-map
"\C-c\C-c" 'rlogin-send-Ctrl-C
)
70 (define-key rlogin-mode-map
"\C-c\C-d" 'rlogin-send-Ctrl-D
)
71 (define-key rlogin-mode-map
"\C-c\C-z" 'rlogin-send-Ctrl-Z
)
72 (define-key rlogin-mode-map
"\C-c\C-\\" 'rlogin-send-Ctrl-backslash
)
73 (define-key rlogin-mode-map
"\C-d" 'rlogin-delchar-or-send-Ctrl-D
)))
76 (defun rlogin (input-args &optional prefix
)
77 "Open a network login connection to HOST via the `rlogin' program.
78 Input is sent line-at-a-time to the remote connection.
80 Communication with the remote host is recorded in a buffer *rlogin-HOST*,
81 where HOST is the first word in the string ARGS. If a prefix argument is
82 given and the buffer *rlogin-HOST* already exists, a new buffer with a
83 different connection will be made.
85 The variable `rlogin-program' contains the name of the actual program to
86 run. It can be a relative or absolute path.
88 The variable `rlogin-explicit-args' is a list of arguments to give to
89 the rlogin when starting. They are added after any arguments given in ARGS."
91 (read-from-minibuffer "rlogin arguments (hostname first): ")
93 (let* ((process-connection-type rlogin-process-connection-type
)
94 (buffer-name (format "*rlogin-%s*" input-args
))
99 (old-match-data (match-data)))
100 (while (string-match "[ \t]*\\([^ \t]+\\)$" input-args
)
101 (setq args
(cons (substring input-args
102 (match-beginning 1) (match-end 1))
104 input-args
(substring input-args
0 (match-beginning 0))))
105 (store-match-data old-match-data
)
106 (setq args
(append args rlogin-explicit-args
))
107 (setq host
(car args
))
108 (let ((tmpargs (cdr args
)))
110 (not (string= (car tmpargs
) "-l")))
111 (setq tmpargs
(cdr tmpargs
)))
112 (setq user
(car (cdr tmpargs
))))
113 (setq buffer-name
(format "*rlogin-%s*" host
))
114 (and prefix
(setq buffer-name
115 (buffer-name (generate-new-buffer buffer-name
))))
116 (switch-to-buffer buffer-name
)
117 (or (comint-check-proc buffer-name
)
120 (comint-exec (current-buffer) buffer-name rlogin-program nil args
)
121 (setq proc
(get-process buffer-name
))
122 ;; Set process-mark to point-max in case there is text in the
123 ;; buffer from a previous exited process.
124 (set-marker (process-mark proc
) (point-max))
126 ;; Set the prefix for filename completion and directory tracking
127 ;; to find the remote machine's files by ftp.
128 (setq comint-file-name-prefix
(concat "/"
129 (and user
(concat user
"@"))
131 (and rlogin-initially-track-cwd
132 ;; Presume the user will start in his remote home directory.
133 ;; If this is wrong, M-x dirs will fix it.
134 (cd-absolute (concat "/"
135 (and user
(concat user
"@"))
137 (defun rlogin-mode ()
138 "Set major-mode for rlogin sessions.
139 If `rlogin-mode-hook' is set, run it."
141 (kill-all-local-variables)
143 (setq major-mode
'rlogin-mode
)
144 (setq mode-name
"rlogin")
145 (use-local-map rlogin-mode-map
)
146 (setq shell-dirtrackp rlogin-initially-track-cwd
)
147 (make-local-variable 'comint-file-name-prefix
)
148 (run-hooks 'rlogin-mode-hook
))
151 (defun rlogin-send-Ctrl-C ()
153 (send-string nil
"\C-c"))
155 (defun rlogin-send-Ctrl-D ()
157 (send-string nil
"\C-d"))
159 (defun rlogin-send-Ctrl-Z ()
161 (send-string nil
"\C-z"))
163 (defun rlogin-send-Ctrl-backslash ()
165 (send-string nil
"\C-\\"))
167 (defun rlogin-delchar-or-send-Ctrl-D (arg)
169 Delete ARG characters forward, or send a C-d to process if at end of buffer."
175 ;;; rlogin.el ends here