Use new form of calendar-read-date.
[emacs.git] / lisp / rlogin.el
bloba12144f665988ce6e2cd21c19cbcc2dabdf417cc
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.
8 ;;
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)
12 ;; any later version.
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.
23 ;;; Commentary:
25 ;; Support for remote logins using `rlogin'.
26 ;; $Id: rlogin.el,v 1.19 1994/09/19 11:47:05 pot Exp rms $
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'.
33 ;;; Code:
35 (require 'comint)
36 (require 'shell)
38 ;;;###autoload
39 (defvar rlogin-program "rlogin"
40 "*Name of program to invoke rlogin")
42 ;;;###autoload
43 (defvar rlogin-explicit-args nil
44 "*List of arguments to pass to rlogin on the command line.")
46 ;;;###autoload
47 (defvar rlogin-mode-hook nil
48 "*Hooks to run after setting current buffer to rlogin-mode.")
50 ;;;###autoload
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.")
59 ;;;###autoload
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)))
75 ;;;###autoload
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 If `rlogin-initially-track-cwd' is non-nil (which is true by default),
92 then the default directory in that buffer is set to a remote (FTP) file name
93 to access your home directory on the remote machine. Occasionally
94 this causes an error, if you cannot access the home directory on that
95 machine. This error is harmless as long as you don't try to use
96 that default directory."
97 (interactive (list
98 (read-from-minibuffer "rlogin arguments (hostname first): ")
99 current-prefix-arg))
100 (let* ((process-connection-type rlogin-process-connection-type)
101 (buffer-name (format "*rlogin-%s*" input-args))
102 args
103 host
104 user
105 proc
106 (old-match-data (match-data)))
107 (while (string-match "[ \t]*\\([^ \t]+\\)$" input-args)
108 (setq args (cons (substring input-args
109 (match-beginning 1) (match-end 1))
110 args)
111 input-args (substring input-args 0 (match-beginning 0))))
112 (store-match-data old-match-data)
113 (setq args (append args rlogin-explicit-args))
114 (setq host (car args))
115 (let ((tmpargs (cdr args)))
116 (while (and tmpargs
117 (not (string= (car tmpargs) "-l")))
118 (setq tmpargs (cdr tmpargs)))
119 (setq user (car (cdr tmpargs))))
120 (setq buffer-name (format "*rlogin-%s*" host))
121 (and prefix (setq buffer-name
122 (buffer-name (generate-new-buffer buffer-name))))
123 (switch-to-buffer buffer-name)
124 (or (comint-check-proc buffer-name)
125 (progn
126 (comint-mode)
127 (comint-exec (current-buffer) buffer-name rlogin-program nil args)
128 (setq proc (get-process buffer-name))
129 ;; Set process-mark to point-max in case there is text in the
130 ;; buffer from a previous exited process.
131 (set-marker (process-mark proc) (point-max))
132 (rlogin-mode)
133 ;; Set the prefix for filename completion and directory tracking
134 ;; to find the remote machine's files by ftp.
135 (setq comint-file-name-prefix (concat "/"
136 (and user (concat user "@"))
137 host ":"))
138 (and rlogin-initially-track-cwd
139 ;; Presume the user will start in his remote home directory.
140 ;; If this is wrong, M-x dirs will fix it.
141 (cd-absolute (concat "/"
142 (and user (concat user "@"))
143 host ":~/")))))))
144 (defun rlogin-mode ()
145 "Set major-mode for rlogin sessions.
146 If `rlogin-mode-hook' is set, run it."
147 (interactive)
148 (kill-all-local-variables)
149 (shell-mode)
150 (setq major-mode 'rlogin-mode)
151 (setq mode-name "rlogin")
152 (use-local-map rlogin-mode-map)
153 (setq shell-dirtrackp rlogin-initially-track-cwd)
154 (make-local-variable 'comint-file-name-prefix)
155 (run-hooks 'rlogin-mode-hook))
158 (defun rlogin-send-Ctrl-C ()
159 (interactive)
160 (send-string nil "\C-c"))
162 (defun rlogin-send-Ctrl-D ()
163 (interactive)
164 (send-string nil "\C-d"))
166 (defun rlogin-send-Ctrl-Z ()
167 (interactive)
168 (send-string nil "\C-z"))
170 (defun rlogin-send-Ctrl-backslash ()
171 (interactive)
172 (send-string nil "\C-\\"))
174 (defun rlogin-delchar-or-send-Ctrl-D (arg)
176 Delete ARG characters forward, or send a C-d to process if at end of buffer."
177 (interactive "p")
178 (if (eobp)
179 (rlogin-send-Ctrl-D)
180 (delete-char arg)))
182 ;;; rlogin.el ends here