Mercurial > emacs
annotate lisp/net/ange-ftp.el @ 89588:3a34407a4019
(w32_encode_char): New charset parameter. font_info.encoding becomes
encoding_type.
(x_get_font_repertory): New function. Warning: stub only!
(x_new_font): Return quickly if font already set.
(x_new_fontset): fontsetname parameter is Lisp_Object. Use new
fs_query_fontset. Try new_fontset_from_font_name. Use fontset_name for
return value.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Sat, 11 Oct 2003 23:01:55 +0000 |
parents | 375f2633d815 |
children | 68c22ea6027c |
rev | line source |
---|---|
28210 | 1 ;;; ange-ftp.el --- transparent FTP support for GNU Emacs |
2 | |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3 ;; Copyright (C) 1989,90,91,92,93,94,95,96,98, 2000, 2001 |
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
28210 | 5 |
6 ;; Author: Andy Norman (ange@hplb.hpl.hp.com) | |
7 ;; Maintainer: FSF | |
8 ;; Keywords: comm | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This package attempts to make accessing files and directories using FTP | |
30 ;; from within GNU Emacs as simple and transparent as possible. A subset of | |
31 ;; the common file-handling routines are extended to interact with FTP. | |
32 | |
33 ;; Usage: | |
34 ;; | |
35 ;; Some of the common GNU Emacs file-handling operations have been made | |
36 ;; FTP-smart. If one of these routines is given a filename that matches | |
37 ;; '/user@host:name' then it will spawn an FTP process connecting to machine | |
38 ;; 'host' as account 'user' and perform its operation on the file 'name'. | |
39 ;; | |
40 ;; For example: if find-file is given a filename of: | |
41 ;; | |
42 ;; /ange@anorman:/tmp/notes | |
43 ;; | |
44 ;; then ange-ftp spawns an FTP process, connect to the host 'anorman' as | |
45 ;; user 'ange', get the file '/tmp/notes' and pop up a buffer containing the | |
46 ;; contents of that file as if it were on the local filesystem. If ange-ftp | |
47 ;; needs a password to connect then it reads one in the echo area. | |
48 | |
49 ;; Extended filename syntax: | |
50 ;; | |
51 ;; The default extended filename syntax is '/user@host:name', where the | |
52 ;; 'user@' part may be omitted. This syntax can be customised to a certain | |
53 ;; extent by changing ange-ftp-name-format. There are limitations. | |
54 ;; The `host' part has an optional suffix `#port' which may be used to | |
55 ;; specify a non-default port number for the connexion. | |
56 ;; | |
57 ;; If the user part is omitted then ange-ftp generates a default user | |
58 ;; instead whose value depends on the variable ange-ftp-default-user. | |
59 | |
60 ;; Passwords: | |
61 ;; | |
62 ;; A password is required for each host/user pair. Ange-ftp reads passwords | |
63 ;; as needed. You can also specify a password with ange-ftp-set-passwd, or | |
64 ;; in a *valid* ~/.netrc file. | |
65 | |
66 ;; Passwords for user "anonymous": | |
67 ;; | |
68 ;; Passwords for the user "anonymous" (or "ftp") are handled | |
69 ;; specially. The variable `ange-ftp-generate-anonymous-password' | |
70 ;; controls what happens: if the value of this variable is a string, | |
71 ;; then this is used as the password; if non-nil (the default), then | |
72 ;; the value of `user-mail-address' is used; if nil then the user | |
73 ;; is prompted for a password as normal. | |
74 | |
75 ;; "Dumb" UNIX hosts: | |
76 ;; | |
77 ;; The FTP servers on some UNIX machines have problems if the 'ls' command is | |
78 ;; used. | |
79 ;; | |
80 ;; The routine ange-ftp-add-dumb-unix-host can be called to tell ange-ftp to | |
81 ;; limit itself to the DIR command and not 'ls' for a given UNIX host. Note | |
82 ;; that this change will take effect for the current GNU Emacs session only. | |
83 ;; See below for a discussion of non-UNIX hosts. If a large number of | |
84 ;; machines with similar hostnames have this problem then it is easier to set | |
85 ;; the value of ange-ftp-dumb-unix-host-regexp in your .emacs file. ange-ftp | |
86 ;; is unable to automatically recognize dumb unix hosts. | |
87 | |
88 ;; File name completion: | |
89 ;; | |
90 ;; Full file-name completion is supported on UNIX, VMS, CMS, and MTS hosts. | |
91 ;; To do filename completion, ange-ftp needs a listing from the remote host. | |
92 ;; Therefore, for very slow connections, it might not save any time. | |
93 | |
94 ;; FTP processes: | |
95 ;; | |
96 ;; When ange-ftp starts up an FTP process, it leaves it running for speed | |
97 ;; purposes. Some FTP servers will close the connection after a period of | |
98 ;; time, but ange-ftp should be able to quietly reconnect the next time that | |
99 ;; the process is needed. | |
100 ;; | |
101 ;; Killing the "*ftp user@host*" buffer also kills the ftp process. | |
102 ;; This should not cause ange-ftp any grief. | |
103 | |
104 ;; Binary file transfers: | |
105 ;; | |
106 ;; By default ange-ftp transfers files in ASCII mode. If a file being | |
107 ;; transferred matches the value of ange-ftp-binary-file-name-regexp then | |
108 ;; binary mode is used for that transfer. | |
109 | |
110 ;; Account passwords: | |
111 ;; | |
112 ;; Some FTP servers require an additional password which is sent by the | |
113 ;; ACCOUNT command. ange-ftp partially supports this by allowing the user to | |
114 ;; specify an account password by either calling ange-ftp-set-account, or by | |
115 ;; specifying an account token in the .netrc file. If the account password | |
116 ;; is set by either of these methods then ange-ftp will issue an ACCOUNT | |
117 ;; command upon starting the FTP process. | |
118 | |
119 ;; Preloading: | |
120 ;; | |
121 ;; ange-ftp can be preloaded, but must be put in the site-init.el file and | |
122 ;; not the site-load.el file in order for the documentation strings for the | |
123 ;; functions being overloaded to be available. | |
124 | |
125 ;; Status reports: | |
126 ;; | |
127 ;; Most ange-ftp commands that talk to the FTP process output a status | |
128 ;; message on what they are doing. In addition, ange-ftp can take advantage | |
129 ;; of the FTP client's HASH command to display the status of transferring | |
130 ;; files and listing directories. See the documentation for the variables | |
131 ;; ange-ftp-{ascii,binary}-hash-mark-size, ange-ftp-send-hash and | |
132 ;; ange-ftp-process-verbose for more details. | |
133 | |
134 ;; Gateways: | |
135 ;; | |
136 ;; Sometimes it is necessary for the FTP process to be run on a different | |
137 ;; machine than the machine running GNU Emacs. This can happen when the | |
138 ;; local machine has restrictions on what hosts it can access. | |
139 ;; | |
140 ;; ange-ftp has support for running the ftp process on a different (gateway) | |
141 ;; machine. The way it works is as follows: | |
142 ;; | |
143 ;; 1) Set the variable 'ange-ftp-gateway-host' to the name of a machine | |
144 ;; that doesn't have the access restrictions. | |
145 ;; | |
146 ;; 2) Set the variable 'ange-ftp-local-host-regexp' to a regular expression | |
147 ;; that matches hosts that can be contacted from running a local ftp | |
148 ;; process, but fails to match hosts that can't be accessed locally. For | |
149 ;; example: | |
150 ;; | |
151 ;; "\\.hp\\.com$\\|^[^.]*$" | |
152 ;; | |
153 ;; will match all hosts that are in the .hp.com domain, or don't have an | |
154 ;; explicit domain in their name, but will fail to match hosts with | |
155 ;; explicit domains or that are specified by their ip address. | |
156 ;; | |
157 ;; 3) Using NFS and symlinks, make sure that there is a shared directory with | |
158 ;; the *same* name between the local machine and the gateway machine. | |
159 ;; This directory is necessary for temporary files created by ange-ftp. | |
160 ;; | |
161 ;; 4) Set the variable 'ange-ftp-gateway-tmp-name-template' to the name of | |
162 ;; this directory plus an identifying filename prefix. For example: | |
163 ;; | |
164 ;; "/nfs/hplose/ange/ange-ftp" | |
165 ;; | |
166 ;; where /nfs/hplose/ange is a directory that is shared between the | |
167 ;; gateway machine and the local machine. | |
168 ;; | |
169 ;; The simplest way of getting a ftp process running on the gateway machine | |
170 ;; is if you can spawn a remote shell using either 'rsh' or 'remsh'. If you | |
171 ;; can't do this for some reason such as security then points 7 onwards will | |
172 ;; discuss an alternative approach. | |
173 ;; | |
174 ;; 5) Set the variable ange-ftp-gateway-program to the name of the remote | |
175 ;; shell process such as 'remsh' or 'rsh' if the default isn't correct. | |
176 ;; | |
177 ;; 6) Set the variable ange-ftp-gateway-program-interactive to nil if it | |
178 ;; isn't already. This tells ange-ftp that you are using a remote shell | |
179 ;; rather than logging in using telnet or rlogin. | |
180 ;; | |
181 ;; That should be all you need to allow ange-ftp to spawn a ftp process on | |
182 ;; the gateway machine. If you have to use telnet or rlogin to get to the | |
183 ;; gateway machine then follow the instructions below. | |
184 ;; | |
185 ;; 7) Set the variable ange-ftp-gateway-program to the name of the program | |
186 ;; that lets you log onto the gateway machine. This may be something like | |
187 ;; telnet or rlogin. | |
188 ;; | |
189 ;; 8) Set the variable ange-ftp-gateway-prompt-pattern to a regular | |
190 ;; expression that matches the prompt you get when you login to the | |
191 ;; gateway machine. Be very specific here; this regexp must not match | |
192 ;; *anything* in your login banner except this prompt. | |
193 ;; shell-prompt-pattern is far too general as it appears to match some | |
194 ;; login banners from Sun machines. For example: | |
195 ;; | |
196 ;; "^$*$ *" | |
197 ;; | |
198 ;; 9) Set the variable ange-ftp-gateway-program-interactive to 't' to let | |
199 ;; ange-ftp know that it has to "hand-hold" the login to the gateway | |
200 ;; machine. | |
201 ;; | |
202 ;; 10) Set the variable ange-ftp-gateway-setup-term-command to a UNIX command | |
203 ;; that will put the pty connected to the gateway machine into a | |
204 ;; no-echoing mode, and will strip off carriage-returns from output from | |
205 ;; the gateway machine. For example: | |
206 ;; | |
207 ;; "stty -onlcr -echo" | |
208 ;; | |
209 ;; will work on HP-UX machines, whereas: | |
210 ;; | |
211 ;; "stty -echo nl" | |
212 ;; | |
213 ;; appears to work for some Sun machines. | |
214 ;; | |
215 ;; That's all there is to it. | |
216 | |
217 ;; Smart gateways: | |
218 ;; | |
219 ;; If you have a "smart" ftp program that allows you to issue commands like | |
220 ;; "USER foo@bar" which do nice proxy things, then look at the variables | |
221 ;; ange-ftp-smart-gateway and ange-ftp-smart-gateway-port. | |
222 ;; | |
223 ;; Otherwise, if there is an alternate ftp program that implements proxy in | |
224 ;; a transparent way (i.e. w/o specifying the proxy host), that will | |
225 ;; connect you directly to the desired destination host: | |
226 ;; Set ange-ftp-gateway-ftp-program-name to that program's name. | |
227 ;; Set ange-ftp-local-host-regexp to a value as stated earlier on. | |
228 ;; Leave ange-ftp-gateway-host set to nil. | |
229 ;; Set ange-ftp-smart-gateway to t. | |
230 | |
231 ;; Tips for using ange-ftp: | |
232 ;; | |
233 ;; 1. For dired to work on a host which marks symlinks with a trailing @ in | |
234 ;; an ls -alF listing, you need to (setq dired-ls-F-marks-symlinks t). | |
235 ;; Most UNIX systems do not do this, but ULTRIX does. If you think that | |
236 ;; there is a chance you might connect to an ULTRIX machine (such as | |
237 ;; prep.ai.mit.edu), then set this variable accordingly. This will have | |
238 ;; the side effect that dired will have problems with symlinks whose names | |
239 ;; end in an @. If you get yourself into this situation then editing | |
240 ;; dired's ls-switches to remove "F", will temporarily fix things. | |
241 ;; | |
242 ;; 2. If you know that you are connecting to a certain non-UNIX machine | |
243 ;; frequently, and ange-ftp seems to be unable to guess its host-type, | |
244 ;; then setting the appropriate host-type regexp | |
245 ;; (ange-ftp-vms-host-regexp, ange-ftp-mts-host-regexp, or | |
246 ;; ange-ftp-cms-host-regexp) accordingly should help. Also, please report | |
247 ;; ange-ftp's inability to recognize the host-type as a bug. | |
248 ;; | |
249 ;; 3. For slow connections, you might get "listing unreadable" error | |
250 ;; messages, or get an empty buffer for a file that you know has something | |
251 ;; in it. The solution is to increase the value of ange-ftp-retry-time. | |
252 ;; Its default value is 5 which is plenty for reasonable connections. | |
253 ;; However, for some transatlantic connections I set this to 20. | |
254 ;; | |
255 ;; 4. Beware of compressing files on non-UNIX hosts. Ange-ftp will do it by | |
256 ;; copying the file to the local machine, compressing it there, and then | |
257 ;; sending it back. Binary file transfers between machines of different | |
258 ;; architectures can be a risky business. Test things out first on some | |
259 ;; test files. See "Bugs" below. Also, note that ange-ftp copies files by | |
260 ;; moving them through the local machine. Again, be careful when doing | |
261 ;; this with binary files on non-Unix machines. | |
262 ;; | |
263 ;; 5. Beware that dired over ftp will use your setting of dired-no-confirm | |
264 ;; (list of dired commands for which confirmation is not asked). You | |
265 ;; might want to reconsider your setting of this variable, because you | |
266 ;; might want confirmation for more commands on remote direds than on | |
267 ;; local direds. For example, I strongly recommend that you not include | |
268 ;; compress and uncompress in this list. If there is enough demand it | |
269 ;; might be a good idea to have an alist ange-ftp-dired-no-confirm of | |
270 ;; pairs ( TYPE . LIST ), where TYPE is an operating system type and LIST | |
271 ;; is a list of commands for which confirmation would be suppressed. Then | |
272 ;; remote dired listings would take their (buffer-local) value of | |
273 ;; dired-no-confirm from this alist. Who votes for this? | |
274 | |
275 ;; --------------------------------------------------------------------- | |
276 ;; Non-UNIX support: | |
277 ;; --------------------------------------------------------------------- | |
278 | |
279 ;; VMS support: | |
280 ;; | |
281 ;; Ange-ftp has full support for VMS hosts. It | |
282 ;; should be able to automatically recognize any VMS machine. However, if it | |
283 ;; fails to do this, you can use the command ange-ftp-add-vms-host. As well, | |
284 ;; you can set the variable ange-ftp-vms-host-regexp in your .emacs file. We | |
285 ;; would be grateful if you would report any failures to automatically | |
286 ;; recognize a VMS host as a bug. | |
287 ;; | |
288 ;; Filename Syntax: | |
289 ;; | |
290 ;; For ease of *implementation*, the user enters the VMS filename syntax in a | |
291 ;; UNIX-y way. For example: | |
292 ;; PUB$:[ANONYMOUS.SDSCPUB.NEXT]README.TXT;1 | |
293 ;; would be entered as: | |
294 ;; /PUB$$:/ANONYMOUS/SDSCPUB/NEXT/README.TXT;1 | |
295 ;; i.e. to log in as anonymous on ymir.claremont.edu and grab the file: | |
296 ;; [.CSV.POLICY]RULES.MEM | |
297 ;; you would type: | |
298 ;; C-x C-f /anonymous@ymir.claremont.edu:CSV/POLICY/RULES.MEM | |
299 ;; | |
300 ;; A legal VMS filename is of the form: FILE.TYPE;## | |
301 ;; where FILE can be up to 39 characters | |
302 ;; TYPE can be up to 39 characters | |
303 ;; ## is a version number (an integer between 1 and 32,767) | |
304 ;; Valid characters in FILE and TYPE are A-Z 0-9 _ - $ | |
305 ;; $ cannot begin a filename, and - cannot be used as the first or last | |
306 ;; character. | |
307 ;; | |
308 ;; Tips: | |
309 ;; 1. Although VMS is not case sensitive, EMACS running under UNIX is. | |
310 ;; Therefore, to access a VMS file, you must enter the filename with upper | |
311 ;; case letters. | |
312 ;; 2. To access the latest version of file under VMS, you use the filename | |
313 ;; without the ";" and version number. You should always edit the latest | |
314 ;; version of a file. If you want to edit an earlier version, copy it to a | |
315 ;; new file first. This has nothing to do with ange-ftp, but is simply | |
316 ;; good VMS operating practice. Therefore, to edit FILE.TXT;3 (say 3 is | |
317 ;; latest version), do C-x C-f /ymir.claremont.edu:FILE.TXT. If you | |
318 ;; inadvertently do C-x C-f /ymir.claremont.edu:FILE.TXT;3, you will find | |
319 ;; that VMS will not allow you to save the file because it will refuse to | |
320 ;; overwrite FILE.TXT;3, but instead will want to create FILE.TXT;4, and | |
321 ;; attach the buffer to this file. To get out of this situation, M-x | |
322 ;; write-file /ymir.claremont.edu:FILE.TXT will attach the buffer to | |
323 ;; latest version of the file. For this reason, in dired "f" | |
324 ;; (dired-find-file), always loads the file sans version, whereas "v", | |
325 ;; (dired-view-file), always loads the explicit version number. The | |
326 ;; reasoning being that it reasonable to view old versions of a file, but | |
327 ;; not to edit them. | |
328 ;; 3. EMACS has a feature in which it does environment variable substitution | |
329 ;; in filenames. Therefore, to enter a $ in a filename, you must quote it | |
330 ;; by typing $$. | |
331 | |
332 ;; MTS support: | |
333 ;; | |
334 ;; Ange-ftp has full support for hosts running | |
335 ;; the Michigan terminal system. It should be able to automatically | |
336 ;; recognize any MTS machine. However, if it fails to do this, you can use | |
337 ;; the command ange-ftp-add-mts-host. As well, you can set the variable | |
338 ;; ange-ftp-mts-host-regexp in your .emacs file. We would be grateful if you | |
339 ;; would report any failures to automatically recognize a MTS host as a bug. | |
340 ;; | |
341 ;; Filename syntax: | |
30459 | 342 ;; |
28210 | 343 ;; MTS filenames are entered in a UNIX-y way. For example, if your account |
344 ;; was YYYY, the file FILE in the account XXXX: on mtsg.ubc.ca would be | |
345 ;; entered as | |
346 ;; /YYYY@mtsg.ubc.ca:/XXXX:/FILE | |
347 ;; In other words, MTS accounts are treated as UNIX directories. Of course, | |
348 ;; to access a file in another account, you must have access permission for | |
349 ;; it. If FILE were in your own account, then you could enter it in a | |
350 ;; relative name fashion as | |
351 ;; /YYYY@mtsg.ubc.ca:FILE | |
352 ;; MTS filenames can be up to 12 characters. Like UNIX, the structure of the | |
353 ;; filename does not contain a TYPE (i.e. it can have as many "."'s as you | |
354 ;; like.) MTS filenames are always in upper case, and hence be sure to enter | |
355 ;; them as such! MTS is not case sensitive, but an EMACS running under UNIX | |
356 ;; is. | |
357 | |
358 ;; CMS support: | |
30459 | 359 ;; |
28210 | 360 ;; Ange-ftp has full support for hosts running |
361 ;; CMS. It should be able to automatically recognize any CMS machine. | |
362 ;; However, if it fails to do this, you can use the command | |
363 ;; ange-ftp-add-cms-host. As well, you can set the variable | |
364 ;; ange-ftp-cms-host-regexp in your .emacs file. We would be grateful if you | |
365 ;; would report any failures to automatically recognize a CMS host as a bug. | |
30459 | 366 ;; |
28210 | 367 ;; Filename syntax: |
368 ;; | |
369 ;; CMS filenames are entered in a UNIX-y way. In otherwords, minidisks are | |
370 ;; treated as UNIX directories. For example to access the file READ.ME in | |
371 ;; minidisk *.311 on cuvmb.cc.columbia.edu, you would enter | |
372 ;; /anonymous@cuvmb.cc.columbia.edu:/*.311/READ.ME | |
373 ;; If *.301 is the default minidisk for this account, you could access | |
374 ;; FOO.BAR on this minidisk as | |
375 ;; /anonymous@cuvmb.cc.columbia.edu:FOO.BAR | |
376 ;; CMS filenames are of the form FILE.TYPE, where both FILE and TYPE can be | |
377 ;; up to 8 characters. Again, beware that CMS filenames are always upper | |
378 ;; case, and hence must be entered as such. | |
379 ;; | |
380 ;; Tips: | |
381 ;; 1. CMS machines, with the exception of anonymous accounts, nearly always | |
382 ;; need an account password. To have ange-ftp send an account password, | |
383 ;; you can either include it in your .netrc file, or use | |
384 ;; ange-ftp-set-account. | |
385 ;; 2. Ange-ftp cannot send "write passwords" for a minidisk. Hopefully, we | |
386 ;; can fix this. | |
387 ;; | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
388 ;; BS2000 support: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
389 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
390 ;; Ange-ftp has full support for BS2000 hosts. It should be able to |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
391 ;; automatically recognize any BS2000 machine. However, if it fails to |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
392 ;; do this, you can use the command ange-ftp-add-bs2000-host. As well, |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
393 ;; you can set the variable ange-ftp-bs2000-host-regexp in your .emacs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
394 ;; file. We would be grateful if you would report any failures to auto- |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
395 ;; matically recognize a BS2000 host as a bug. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
396 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
397 ;; If you want to access the POSIX subsystem on BS2000 you MUST use |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
398 ;; command ange-ftp-add-bs2000-posix-host for that particular |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
399 ;; hostname. ange-ftp can't decide if you want to access the native |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
400 ;; filesystem or the POSIX filesystem, so it accesses the native |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
401 ;; filesystem by default. And if you have an ASCII filesystem in |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
402 ;; your BS2000 POSIX subsystem you must use |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
403 ;; ange-ftp-binary-file-name-regexp to access its files. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
404 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
405 ;; Filename Syntax: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
406 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
407 ;; For ease of *implementation*, the user enters the BS2000 filename |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
408 ;; syntax in a UNIX-y way. For example: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
409 ;; :PUB:$PUBLIC.ANONYMOUS.SDSCPUB.NEXT.README.TXT |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
410 ;; would be entered as: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
411 ;; /:PUB:/$$PUBLIC/ANONYMOUS.SDSCPUB.NEXT.README.TXT |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
412 ;; You dont't have to type pubset and account, if they have default values, |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
413 ;; i.e. to log in as anonymous on bs2000.anywhere.com and grab the file |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
414 ;; IMPORTANT.TEXT.ON.BS2000 on the default pubset X on userid PUBLIC |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
415 ;; (there are only 8 characters in a valid username), you could type: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
416 ;; C-x C-f /public@bs2000.anywhere.com:/IMPORTANT.TEXT.ON.BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
417 ;; or |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
418 ;; C-x C-f /anonym@bs2000.anywhere.com:/:X:/$$PUBLIC/IMPORTANT.TEXT.ON.BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
419 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
420 ;; If X is not your default pubset, you could add it as 'subdirectory' (BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
421 ;; has a flat architecture) with the command |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
422 ;; (setq ange-ftp-bs2000-additional-pubsets '(":X:")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
423 ;; and then you could type: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
424 ;; C-x C-f /anonym@bs2000.anywhere.com:/:X:/IMPORTANT.TEXT.ON.BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
425 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
426 ;; Valid characters in an BS2000 filename are A-Z 0-9 $ # @ . - |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
427 ;; If the first character in a filename is # or @, this is replaced with |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
428 ;; ange-ftp-bs2000-special-prefix because names starting with # or @ |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
429 ;; are reserved for temporary files. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
430 ;; This is especially important for auto-save files. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47575
diff
changeset
|
431 ;; Valid file generations are ending with ([+|-|*]0-9...) . |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
432 ;; File generations are not supported yet! |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
433 ;; A filename must at least contain one character (A-Z) and cannot be longer |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
434 ;; than 41 characters. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
435 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
436 ;; Tips: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
437 ;; 1. Although BS2000 is not case sensitive, EMACS running under UNIX is. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
438 ;; Therefore, to access a BS2000 file, you must enter the filename with |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
439 ;; upper case letters. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
440 ;; 2. EMACS has a feature in which it does environment variable substitution |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
441 ;; in filenames. Therefore, to enter a $ in a filename, you must quote it |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
442 ;; by typing $$. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
443 ;; 3. BS2000 machines, with the exception of anonymous accounts, nearly |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
444 ;; always need an account password. To have ange-ftp send an account |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
445 ;; password, you can either include it in your .netrc file, or use |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
446 ;; ange-ftp-set-account. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
447 ;; |
28210 | 448 ;; ------------------------------------------------------------------ |
449 ;; Bugs: | |
450 ;; ------------------------------------------------------------------ | |
30459 | 451 ;; |
28210 | 452 ;; 1. Umask problems: |
453 ;; Be warned that files created by using ange-ftp will take account of the | |
454 ;; umask of the ftp daemon process rather than the umask of the creating | |
455 ;; user. This is particularly important when logging in as the root user. | |
456 ;; The way that I tighten up the ftp daemon's umask under HP-UX is to make | |
457 ;; sure that the umask is changed to 027 before I spawn /etc/inetd. I | |
458 ;; suspect that there is something similar on other systems. | |
459 ;; | |
460 ;; 2. Some combinations of FTP clients and servers break and get out of sync | |
461 ;; when asked to list a non-existent directory. Some of the ai.mit.edu | |
462 ;; machines cause this problem for some FTP clients. Using | |
463 ;; ange-ftp-kill-ftp-process can restart the ftp process, which | |
464 ;; should get things back in sync. | |
465 ;; | |
466 ;; 3. Ange-ftp does not check to make sure that when creating a new file, | |
467 ;; you provide a valid filename for the remote operating system. | |
468 ;; If you do not, then the remote FTP server will most likely | |
469 ;; translate your filename in some way. This may cause ange-ftp to | |
470 ;; get confused about what exactly is the name of the file. The | |
471 ;; most common causes of this are using lower case filenames on systems | |
472 ;; which support only upper case, and using filenames which are too | |
473 ;; long. | |
474 ;; | |
475 ;; 4. Null (blank) passwords confuse both ange-ftp and some FTP daemons. | |
476 ;; | |
477 ;; 5. Ange-ftp likes to use pty's to talk to its FTP processes. If GNU Emacs | |
478 ;; for some reason creates a FTP process that only talks via pipes then | |
479 ;; ange-ftp won't be getting the information it requires at the time that | |
480 ;; it wants it since pipes flush at different times to pty's. One | |
481 ;; disgusting way around this problem is to talk to the FTP process via | |
482 ;; rlogin which does the 'right' things with pty's. | |
483 ;; | |
484 ;; 6. For CMS support, we send too many cd's. Since cd's are cheap, I haven't | |
485 ;; worried about this too much. Eventually, we should have some caching | |
486 ;; of the current minidisk. | |
30459 | 487 ;; |
28210 | 488 ;; 7. Some CMS machines do not assign a default minidisk when you ftp them as |
489 ;; anonymous. It is then necessary to guess a valid minidisk name, and cd | |
490 ;; to it. This is (understandably) beyond ange-ftp. | |
491 ;; | |
492 ;; 8. Remote to remote copying of files on non-Unix machines can be risky. | |
493 ;; Depending on the variable ange-ftp-binary-file-name-regexp, ange-ftp | |
494 ;; will use binary mode for the copy. Between systems of different | |
495 ;; architecture, this still may not be enough to guarantee the integrity | |
496 ;; of binary files. Binary file transfers from VMS machines are | |
497 ;; particularly problematical. Should ange-ftp-binary-file-name-regexp be | |
498 ;; an alist of OS type, regexp pairs? | |
499 ;; | |
500 ;; 9. The code to do compression of files over ftp is not as careful as it | |
501 ;; should be. It deletes the old remote version of the file, before | |
502 ;; actually checking if the local to remote transfer of the compressed | |
503 ;; file succeeds. Of course to delete the original version of the file | |
504 ;; after transferring the compressed version back is also dangerous, | |
505 ;; because some OS's have severe restrictions on the length of filenames, | |
506 ;; and when the compressed version is copied back the "-Z" or ".Z" may be | |
507 ;; truncated. Then, ange-ftp would delete the only remaining version of | |
508 ;; the file. Maybe ange-ftp should make backups when it compresses files | |
509 ;; (of course, the backup "~" could also be truncated off, sigh...). | |
510 ;; Suggestions? | |
511 ;; | |
512 ;; 10. If a dir listing is attempted for an empty directory on (at least | |
513 ;; some) VMS hosts, an ftp error is given. This is really an ftp bug, and | |
514 ;; I don't know how to get ange-ftp work to around it. | |
515 ;; | |
516 ;; 11. Bombs on filenames that start with a space. Deals well with filenames | |
517 ;; containing spaces, but beware that the remote ftpd may not like them | |
518 ;; much. | |
519 ;; | |
520 ;; 12. The dired support for non-Unix-like systems does not currently work. | |
521 ;; It needs to be reimplemented by modifying the parse-...-listing | |
522 ;; functions to convert the directory listing to ls -l format. | |
30459 | 523 ;; |
28210 | 524 ;; 13. The famous @ bug. As mentioned above in TIPS, ULTRIX marks symlinks |
525 ;; with a trailing @ in a ls -alF listing. In order to account for this | |
526 ;; ange-ftp looks to chop trailing @'s off of symlink names when it is | |
527 ;; parsing a listing with the F switch. This will cause ange-ftp to | |
528 ;; incorrectly get the name of a symlink on a non-ULTRIX host if its name | |
529 ;; ends in an @. ange-ftp will correct itself if you take F out of the | |
530 ;; dired ls switches (C-u s will allow you to edit the switches). The | |
531 ;; dired buffer will be automatically reverted, which will allow ange-ftp | |
532 ;; to fix its files hashtable. A cookie to anyone who can think of a | |
533 ;; fast, sure-fire way to recognize ULTRIX over ftp. | |
534 | |
535 ;; If you find any bugs or problems with this package, PLEASE either e-mail | |
536 ;; the above author, or send a message to the ange-ftp-lovers mailing list | |
537 ;; below. Ideas and constructive comments are especially welcome. | |
538 | |
539 ;; ange-ftp-lovers: | |
540 ;; | |
541 ;; ange-ftp has its own mailing list modestly called ange-ftp-lovers. All | |
542 ;; users of ange-ftp are welcome to subscribe (see below) and to discuss | |
543 ;; aspects of ange-ftp. New versions of ange-ftp are posted periodically to | |
544 ;; the mailing list. | |
545 | |
546 ;; To [un]subscribe to ange-ftp-lovers, or to report mailer problems with the | |
547 ;; list, please mail one of the following addresses: | |
548 ;; | |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
549 ;; ange-ftp-lovers-request@hplb.hpl.hp.com |
28210 | 550 ;; |
551 ;; Please don't forget the -request part. | |
552 ;; | |
553 ;; For mail to be posted directly to ange-ftp-lovers, send to one of the | |
554 ;; following addresses: | |
30459 | 555 ;; |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
556 ;; ange-ftp-lovers@hplb.hpl.hp.com |
28210 | 557 ;; |
558 ;; Alternatively, there is a mailing list that only gets announcements of new | |
559 ;; ange-ftp releases. This is called ange-ftp-lovers-announce, and can be | |
560 ;; subscribed to by e-mailing to the -request address as above. Please make | |
561 ;; it clear in the request which mailing list you wish to join. | |
562 | |
563 ;; ----------------------------------------------------------- | |
564 ;; Technical information on this package: | |
565 ;; ----------------------------------------------------------- | |
566 | |
567 ;; ange-ftp works by putting a handler on file-name-handler-alist | |
568 ;; which is called by many primitives, and a few non-primitives, | |
569 ;; whenever they see a file name of the appropriate sort. | |
570 | |
571 ;; Checklist for adding non-UNIX support for TYPE | |
30459 | 572 ;; |
28210 | 573 ;; The following functions may need TYPE versions: |
574 ;; (not all functions will be needed for every OS) | |
575 ;; | |
576 ;; ange-ftp-fix-name-for-TYPE | |
577 ;; ange-ftp-fix-dir-name-for-TYPE | |
578 ;; ange-ftp-TYPE-host | |
579 ;; ange-ftp-TYPE-add-host | |
580 ;; ange-ftp-parse-TYPE-listing | |
581 ;; ange-ftp-TYPE-delete-file-entry | |
582 ;; ange-ftp-TYPE-add-file-entry | |
583 ;; ange-ftp-TYPE-file-name-as-directory | |
584 ;; ange-ftp-TYPE-make-compressed-filename | |
585 ;; ange-ftp-TYPE-file-name-sans-versions | |
586 ;; | |
587 ;; Variables: | |
588 ;; | |
589 ;; ange-ftp-TYPE-host-regexp | |
590 ;; May need to add TYPE to ange-ftp-dumb-host-types | |
591 ;; | |
592 ;; Check the following functions for OS dependent coding: | |
593 ;; | |
594 ;; ange-ftp-host-type | |
595 ;; ange-ftp-guess-host-type | |
596 ;; ange-ftp-allow-child-lookup | |
597 | |
598 ;; Host type conventions: | |
599 ;; | |
600 ;; The function ange-ftp-host-type and the variable ange-ftp-dired-host-type | |
601 ;; (mostly) follow the following conventions for remote host types. At | |
602 ;; least, I think that future code should try to follow these conventions, | |
603 ;; and the current code should eventually be made compliant. | |
604 ;; | |
605 ;; nil = local host type, whatever that is (probably unix). | |
606 ;; Think nil as in "not a remote host". This value is used by | |
607 ;; ange-ftp-dired-host-type for local buffers. | |
608 ;; | |
609 ;; t = a remote host of unknown type. Think t as in true, it's remote. | |
610 ;; Currently, `unix' is used as the default remote host type. | |
611 ;; Maybe we should use t. | |
612 ;; | |
613 ;; TYPE = a remote host of TYPE type. | |
614 ;; | |
615 ;; TYPE:LIST = a remote host of TYPE type, using a specialized ftp listing | |
616 ;; program called list. This is currently only used for Unix | |
617 ;; dl (descriptive listings), when ange-ftp-dired-host-type | |
618 ;; is set to `unix:dl'. | |
619 | |
620 ;; Bug report codes: | |
621 ;; | |
622 ;; Because of their naive faith in this code, there are certain situations | |
623 ;; which the writers of this program believe could never happen. However, | |
624 ;; being realists they have put calls to `error' in the program at these | |
625 ;; points. These errors provide a code, which is an integer, greater than 1. | |
626 ;; To aid debugging. the error codes, and the functions in which they reside | |
627 ;; are listed below. | |
30459 | 628 ;; |
28210 | 629 ;; 1: See ange-ftp-ls |
630 ;; | |
631 | |
632 ;; ----------------------------------------------------------- | |
633 ;; Hall of fame: | |
634 ;; ----------------------------------------------------------- | |
30459 | 635 ;; |
28210 | 636 ;; Thanks to Roland McGrath for improving the filename syntax handling, |
637 ;; for suggesting many enhancements and for numerous cleanups to the code. | |
638 ;; | |
639 ;; Thanks to Jamie Zawinski for bugfixes and for ideas such as gateways. | |
640 ;; | |
641 ;; Thanks to Ken Laprade for improved .netrc parsing, password reading, and | |
642 ;; dired / shell auto-loading. | |
643 ;; | |
644 ;; Thanks to Sebastian Kremer for dired support and for many ideas and | |
645 ;; bugfixes. | |
646 ;; | |
647 ;; Thanks to Joe Wells for bugfixes, the original non-UNIX system support, | |
648 ;; VOS support, and hostname completion. | |
649 ;; | |
650 ;; Thanks to Nakagawa Takayuki for many good ideas, filename-completion, help | |
651 ;; with file-name expansion, efficiency worries, stylistic concerns and many | |
652 ;; bugfixes. | |
653 ;; | |
654 ;; Thanks to Sandy Rutherford who re-wrote most of ange-ftp to support VMS, | |
655 ;; MTS, CMS and UNIX-dls. Sandy also added dired-support for non-UNIX OS and | |
656 ;; auto-recognition of the host type. | |
657 ;; | |
658 ;; Thanks to Dave Smith who wrote the info file for ange-ftp. | |
659 ;; | |
660 ;; Finally, thanks to Keith Waclena, Mark D. Baushke, Terence Kelleher, Ping | |
661 ;; Zhou, Edward Vielmetti, Jack Repenning, Mike Balenger, Todd Kaufmann, | |
662 ;; Kjetil Svarstad, Tom Wurgler, Linus Tolke, Niko Makila, Carl Edman, Bill | |
663 ;; Trost, Dave Brennan, Dan Jacobson, Andy Scott, Steve Anderson, Sanjay | |
664 ;; Mathur, the folks on the ange-ftp-lovers mailing list and many others | |
665 ;; whose names I've forgotten who have helped to debug and fix problems with | |
666 ;; ange-ftp.el. | |
667 | |
668 ;;; Code: | |
669 | |
670 (require 'comint) | |
671 ;; Silence compiler: | |
672 (eval-when-compile | |
673 (require 'dired) | |
674 (defvar comint-last-output-start nil) | |
675 (defvar comint-last-input-start nil) | |
676 (defvar comint-last-input-end nil)) | |
677 | |
678 ;;;; ------------------------------------------------------------ | |
679 ;;;; User customization variables. | |
680 ;;;; ------------------------------------------------------------ | |
681 | |
682 (defgroup ange-ftp nil | |
30459 | 683 "Accessing remote files and directories using FTP |
28210 | 684 made as simple and transparent as possible." |
685 :group 'files | |
686 :prefix "ange-ftp-") | |
687 | |
688 (defcustom ange-ftp-name-format | |
689 '("^/\\(\\([^@/:]*\\)@\\)?\\([^@/:]*[^@/:.]\\):\\(.*\\)" . (3 2 4)) | |
690 "*Format of a fully expanded remote file name. | |
691 | |
692 This is a list of the form \(REGEXP HOST USER NAME\), | |
693 where REGEXP is a regular expression matching | |
694 the full remote name, and HOST, USER, and NAME are the numbers of | |
695 parenthesized expressions in REGEXP for the components (in that order)." | |
696 :group 'ange-ftp | |
30459 | 697 :type '(list regexp |
28210 | 698 (integer :tag "Host group") |
699 (integer :tag "User group") | |
700 (integer :tag "Name group"))) | |
701 | |
702 ;; ange-ftp-multi-skip-msgs should only match ###-, where ### is one of | |
703 ;; the number codes corresponding to ange-ftp-good-msgs or ange-ftp-fatal-msgs. | |
704 ;; Otherwise, ange-ftp will go into multi-skip mode, and never come out. | |
705 | |
706 (defvar ange-ftp-multi-msgs | |
707 "^220-\\|^230-\\|^226\\|^25.-\\|^221-\\|^200-\\|^331-\\|^4[25]1-\\|^530-" | |
708 "*Regular expression matching the start of a multiline ftp reply.") | |
709 | |
710 (defvar ange-ftp-good-msgs | |
711 "^220 \\|^230 \\|^226 \\|^25. \\|^221 \\|^200 \\|^[Hh]ash mark" | |
712 "*Regular expression matching ftp \"success\" messages.") | |
713 | |
714 ;; CMS and the odd VMS machine say 200 Port rather than 200 PORT. | |
715 ;; Also CMS machines use a multiline 550- reply to say that you | |
716 ;; don't have write permission. ange-ftp gets into multi-line skip | |
717 ;; mode and hangs. Have it ignore 550- instead. It will then barf | |
718 ;; when it gets the 550 line, as it should. | |
719 | |
28892
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
720 ;; RFC2228 "FTP Security Extensions" defines extensions to the FTP |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
721 ;; protocol which involve the client requesting particular |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
722 ;; authentication methods (typically) at connection establishment. Non |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
723 ;; security-aware FTP servers should respond to this with a 500 code, |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
724 ;; which we ignore. |
28210 | 725 (defcustom ange-ftp-skip-msgs |
726 (concat "^200 \\(PORT\\|Port\\) \\|^331 \\|^150 \\|^350 \\|^[0-9]+ bytes \\|" | |
727 "^Connected \\|^$\\|^Remote system\\|^Using\\|^ \\|Password:\\|" | |
728 "^Data connection \\|" | |
729 "^local:\\|^Trying\\|^125 \\|^550-\\|^221 .*oodbye\\|" | |
28892
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
730 "^500 .*AUTH \\(KERBEROS\\|GSSAPI\\)\\|^KERBEROS\\|" |
47068
9026b0749c9e
(ange-ftp-skip-msgs): Skip the 530 response
Richard M. Stallman <rms@gnu.org>
parents:
46892
diff
changeset
|
731 "^530 Please login with USER and PASS\\|" ; non kerberised vsFTPd |
39533
75cd77e6f1d5
(ange-ftp-skip-msgs): Add 227 and 228 for Long
Andreas Schwab <schwab@suse.de>
parents:
38412
diff
changeset
|
732 "^22[789] .*[Pp]assive\\|^200 EPRT\\|^500 .*EPRT") |
28210 | 733 "*Regular expression matching ftp messages that can be ignored." |
734 :group 'ange-ftp | |
735 :type 'regexp) | |
736 | |
737 (defcustom ange-ftp-fatal-msgs | |
738 (concat "^ftp: \\|^Not connected\\|^530 \\|^4[25]1 \\|rcmd: \\|" | |
739 "^No control connection\\|unknown host\\|^lost connection") | |
740 "*Regular expression matching ftp messages that indicate serious errors. | |
741 | |
742 These mean that the FTP process should (or already has) been killed." | |
743 :group 'ange-ftp | |
744 :type 'regexp) | |
745 | |
746 (defcustom ange-ftp-gateway-fatal-msgs | |
747 "No route to host\\|Connection closed\\|No such host\\|Login incorrect" | |
748 "*Regular expression matching login failure messages from rlogin/telnet." | |
749 :group 'ange-ftp | |
750 :type 'regexp) | |
751 | |
752 (defcustom ange-ftp-xfer-size-msgs | |
753 "^150 .* connection for .* (\\([0-9]+\\) bytes)" | |
754 "*Regular expression used to determine the number of bytes in a FTP transfer." | |
755 :group 'ange-ftp | |
756 :type 'regexp) | |
757 | |
30459 | 758 (defcustom ange-ftp-tmp-name-template |
28210 | 759 (expand-file-name "ange-ftp" temporary-file-directory) |
760 "*Template used to create temporary files." | |
761 :group 'ange-ftp | |
762 :type 'directory) | |
763 | |
764 (defcustom ange-ftp-gateway-tmp-name-template "/tmp/ange-ftp" | |
765 "*Template used to create temporary files when ftp-ing through a gateway. | |
766 | |
767 Files starting with this prefix need to be accessible from BOTH the local | |
768 machine and the gateway machine, and need to have the SAME name on both | |
769 machines, that is, /tmp is probably NOT what you want, since that is rarely | |
770 cross-mounted." | |
771 :group 'ange-ftp | |
772 :type 'directory) | |
773 | |
774 (defcustom ange-ftp-netrc-filename "~/.netrc" | |
775 "*File in .netrc format to search for passwords." | |
776 :group 'ange-ftp | |
777 :type 'file) | |
778 | |
779 (defcustom ange-ftp-disable-netrc-security-check (eq system-type 'windows-nt) | |
780 "*If non-nil avoid checking permissions on the .netrc file." | |
781 :group 'ange-ftp | |
782 :type 'boolean) | |
783 | |
784 (defcustom ange-ftp-default-user nil | |
785 "*User name to use when none is specified in a file name. | |
786 | |
787 If non-nil but not a string, you are prompted for the name. | |
788 If nil, the value of `ange-ftp-netrc-default-user' is used. | |
789 If that is nil too, then your login name is used. | |
790 | |
791 Once a connection to a given host has been initiated, the user name | |
792 and password information for that host are cached and re-used by | |
793 ange-ftp. Use \\[ange-ftp-set-user] to change the cached values, | |
794 since setting `ange-ftp-default-user' directly does not affect | |
795 the cached information." | |
796 :group 'ange-ftp | |
797 :type '(choice (const :tag "Default" nil) | |
798 string | |
799 (other :tag "Prompt" t))) | |
800 | |
801 (defcustom ange-ftp-netrc-default-user nil | |
802 "Alternate default user name to use when none is specified. | |
803 | |
804 This variable is set from the `default' command in your `.netrc' file, | |
805 if there is one." | |
806 :group 'ange-ftp | |
807 :type '(choice (const :tag "Default" nil) | |
808 string)) | |
809 | |
810 (defcustom ange-ftp-default-password nil | |
811 "*Password to use when the user name equals `ange-ftp-default-user'." | |
812 :group 'ange-ftp | |
813 :type '(choice (const :tag "Default" nil) | |
814 string)) | |
815 | |
816 (defcustom ange-ftp-default-account nil | |
817 "*Account to use when the user name equals `ange-ftp-default-user'." | |
818 :group 'ange-ftp | |
819 :type '(choice (const :tag "Default" nil) | |
820 string)) | |
821 | |
822 (defcustom ange-ftp-netrc-default-password nil | |
823 "*Password to use when the user name equals `ange-ftp-netrc-default-user'." | |
824 :group 'ange-ftp | |
825 :type '(choice (const :tag "Default" nil) | |
826 string)) | |
827 | |
828 (defcustom ange-ftp-netrc-default-account nil | |
829 "*Account to use when the user name equals `ange-ftp-netrc-default-user'." | |
830 :group 'ange-ftp | |
831 :type '(choice (const :tag "Default" nil) | |
832 string)) | |
833 | |
834 (defcustom ange-ftp-generate-anonymous-password t | |
835 "*If t, use value of `user-mail-address' as password for anonymous ftp. | |
836 | |
837 If a string, then use that string as the password. | |
838 If nil, prompt the user for a password." | |
839 :group 'ange-ftp | |
840 :type '(choice (const :tag "Prompt" nil) | |
841 string | |
842 (other :tag "User address" t))) | |
843 | |
844 (defcustom ange-ftp-dumb-unix-host-regexp nil | |
845 "*If non-nil, regexp matching hosts on which `dir' command lists directory." | |
846 :group 'ange-ftp | |
847 :type '(choice (const :tag "Default" nil) | |
848 string)) | |
849 | |
850 (defcustom ange-ftp-binary-file-name-regexp | |
851 (concat "\\.[zZ]$\\|\\.lzh$\\|\\.arc$\\|\\.zip$\\|\\.zoo$\\|\\.tar$\\|" | |
852 "\\.dvi$\\|\\.ps$\\|\\.elc$\\|TAGS$\\|\\.gif$\\|" | |
853 "\\.EXE\\(;[0-9]+\\)?$\\|\\.[zZ]-part-..$\\|\\.gz$\\|" | |
854 "\\.taz$\\|\\.tgz$") | |
855 "*If a file matches this regexp then it is transferred in binary mode." | |
856 :group 'ange-ftp | |
857 :type 'regexp) | |
858 | |
859 (defcustom ange-ftp-gateway-host nil | |
860 "*Name of host to use as gateway machine when local FTP isn't possible." | |
861 :group 'ange-ftp | |
862 :type '(choice (const :tag "Default" nil) | |
863 string)) | |
864 | |
865 (defcustom ange-ftp-local-host-regexp ".*" | |
866 "*Regexp selecting hosts which can be reached directly with ftp. | |
867 | |
868 For other hosts the FTP process is started on \`ange-ftp-gateway-host\' | |
869 instead, and/or reached via \`ange-ftp-gateway-ftp-program-name\'." | |
870 :group 'ange-ftp | |
871 :type 'regexp) | |
872 | |
873 (defcustom ange-ftp-gateway-program-interactive nil | |
874 "*If non-nil then the gateway program should give a shell prompt. | |
875 | |
876 Both telnet and rlogin do something like this." | |
877 :group 'ange-ftp | |
878 :type 'boolean) | |
879 | |
880 (defcustom ange-ftp-gateway-program remote-shell-program | |
881 "*Name of program to spawn a shell on the gateway machine. | |
882 | |
883 Valid candidates are rsh (remsh on some systems), telnet and rlogin. See | |
884 also the gateway variable above." | |
885 :group 'ange-ftp | |
886 :type '(choice (const "rsh") | |
887 (const "telnet") | |
888 (const "rlogin") | |
889 string)) | |
890 | |
891 (defcustom ange-ftp-gateway-prompt-pattern "^[^#$%>;\n]*[#$%>;] *" | |
892 "*Regexp matching prompt after complete login sequence on gateway machine. | |
893 | |
894 A match for this means the shell is now awaiting input. Make this regexp as | |
895 strict as possible; it shouldn't match *anything* at all except the user's | |
896 initial prompt. The above string will fail under most SUN-3's since it | |
897 matches the login banner." | |
898 :group 'ange-ftp | |
899 :type 'regexp) | |
900 | |
901 (defvar ange-ftp-gateway-setup-term-command | |
902 (if (eq system-type 'hpux) | |
903 "stty -onlcr -echo\n" | |
904 "stty -echo nl\n") | |
905 "*Set up terminal after logging in to the gateway machine. | |
906 This command should stop the terminal from echoing each command, and | |
907 arrange to strip out trailing ^M characters.") | |
908 | |
909 (defcustom ange-ftp-smart-gateway nil | |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
910 "*Non-nil says the ftp gateway (proxy) or gateway ftp program is smart. |
28210 | 911 |
912 Don't bother telnetting, etc., already connected to desired host transparently, | |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
913 or just issue a user@host command in case \`ange-ftp-gateway-host\' is non-nil. |
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
914 See also `ange-ftp-smart-gateway-port'." |
28210 | 915 :group 'ange-ftp |
916 :type 'boolean) | |
917 | |
918 (defcustom ange-ftp-smart-gateway-port "21" | |
919 "*Port on gateway machine to use when smart gateway is in operation." | |
920 :group 'ange-ftp | |
921 :type 'string) | |
922 | |
923 (defcustom ange-ftp-send-hash t | |
924 "*If non-nil, send the HASH command to the FTP client." | |
925 :group 'ange-ftp | |
926 :type 'boolean) | |
927 | |
928 (defcustom ange-ftp-binary-hash-mark-size nil | |
929 "*Default size, in bytes, between hash-marks when transferring a binary file. | |
930 If nil, this variable will be locally overridden if the FTP client outputs a | |
931 suitable response to the HASH command. If non-nil, this value takes | |
932 precedence over the local value." | |
933 :group 'ange-ftp | |
934 :type '(choice (const :tag "Overridden" nil) | |
935 integer)) | |
936 | |
937 (defcustom ange-ftp-ascii-hash-mark-size 1024 | |
938 "*Default size, in bytes, between hash-marks when transferring an ASCII file. | |
939 This variable is buffer-local and will be locally overridden if the FTP client | |
940 outputs a suitable response to the HASH command." | |
941 :group 'ange-ftp | |
942 :type 'integer) | |
943 | |
944 (defcustom ange-ftp-process-verbose t | |
945 "*If non-nil then be chatty about interaction with the FTP process." | |
946 :group 'ange-ftp | |
947 :type 'boolean) | |
948 | |
949 (defcustom ange-ftp-ftp-program-name "ftp" | |
950 "*Name of FTP program to run." | |
951 :group 'ange-ftp | |
952 :type 'string) | |
953 | |
954 (defcustom ange-ftp-gateway-ftp-program-name "ftp" | |
955 "*Name of FTP program to run when accessing non-local hosts. | |
956 | |
957 Some AT&T folks claim to use something called `pftp' here." | |
958 :group 'ange-ftp | |
959 :type 'string) | |
960 | |
961 (defcustom ange-ftp-ftp-program-args '("-i" "-n" "-g" "-v") | |
962 "*A list of arguments passed to the FTP program when started." | |
963 :group 'ange-ftp | |
964 :type '(repeat string)) | |
965 | |
966 (defcustom ange-ftp-nslookup-program nil | |
30459 | 967 "*If non-nil, this is a string naming the nslookup program." |
28210 | 968 :group 'ange-ftp |
969 :type '(choice (const :tag "None" nil) | |
970 string)) | |
971 | |
972 (defcustom ange-ftp-make-backup-files () | |
973 "*Non-nil means make backup files for \"magic\" remote files." | |
974 :group 'ange-ftp | |
975 :type 'boolean) | |
976 | |
977 (defcustom ange-ftp-retry-time 5 | |
978 "*Number of seconds to wait before retry if file or listing doesn't arrive. | |
979 This might need to be increased for very slow connections." | |
980 :group 'ange-ftp | |
981 :type 'integer) | |
982 | |
983 (defcustom ange-ftp-auto-save 0 | |
984 "If 1, allow ange-ftp files to be auto-saved. | |
985 If 0, inhibit auto-saving of ange-ftp files. | |
986 Don't use any other value." | |
987 :group 'ange-ftp | |
988 :type '(choice (const :tag "Suppress" 0) | |
989 (const :tag "Allow" 1))) | |
990 | |
991 (defcustom ange-ftp-try-passive-mode nil | |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
992 "It t, try to use passive mode in ftp, if the client program supports it." |
28210 | 993 :group 'ange-ftp |
994 :type 'boolean | |
45260 | 995 :version "21.1") |
28210 | 996 |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
997 (defcustom ange-ftp-passive-host-alist nil |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
998 "Alist of FTP servers that need \"passive\" mode. |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
999 Each element is of the form (HOSTNAME . SETTING). |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1000 HOSTNAME is a regular expression to match the FTP server host name(s). |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1001 SETTING is \"on\" to turn passive mode on, \"off\" to turn it off, |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1002 or nil meaning don't change it." |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1003 :group 'ange-ftp |
44953
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1004 :type '(repeat (cons regexp (choice (const :tag "On" "on") |
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1005 (const :tag "Off" "off") |
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1006 (const :tag "Don't change" nil)))) |
45260 | 1007 :version "21.4") |
28210 | 1008 |
1009 ;;;; ------------------------------------------------------------ | |
1010 ;;;; Hash table support. | |
1011 ;;;; ------------------------------------------------------------ | |
1012 | |
1013 (require 'backquote) | |
1014 | |
1015 (defun ange-ftp-hash-entry-exists-p (key tbl) | |
1016 "Return whether there is an association for KEY in TABLE." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1017 (not (eq (gethash key tbl 'unknown) 'unknown))) |
28210 | 1018 |
1019 (defun ange-ftp-hash-table-keys (tbl) | |
1020 "Return a sorted list of all the active keys in TABLE, as strings." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1021 ;; (let ((keys nil)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1022 ;; (maphash (lambda (k v) (push k keys)) tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1023 ;; (sort keys 'string-lessp)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1024 (sort (all-completions "" tbl) 'string-lessp)) |
28210 | 1025 |
1026 ;;;; ------------------------------------------------------------ | |
1027 ;;;; Internal variables. | |
1028 ;;;; ------------------------------------------------------------ | |
1029 | |
1030 (defvar ange-ftp-data-buffer-name " *ftp data*" | |
1031 "Buffer name to hold directory listing data received from ftp process.") | |
1032 | |
1033 (defvar ange-ftp-netrc-modtime nil | |
1034 "Last modified time of the netrc file from file-attributes.") | |
1035 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1036 (defvar ange-ftp-user-hashtable (make-hash-table :test 'equal) |
28210 | 1037 "Hash table holding associations between HOST, USER pairs.") |
1038 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1039 (defvar ange-ftp-passwd-hashtable (make-hash-table :test 'equal) |
28210 | 1040 "Mapping between a HOST, USER pair and a PASSWORD for them. |
1041 All HOST values should be in lower case.") | |
1042 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1043 (defvar ange-ftp-account-hashtable (make-hash-table :test 'equal) |
28210 | 1044 "Mapping between a HOST, USER pair and a ACCOUNT password for them.") |
1045 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1046 (defvar ange-ftp-files-hashtable (make-hash-table :test 'equal :size 97) |
28210 | 1047 "Hash table for storing directories and their respective files.") |
1048 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1049 (defvar ange-ftp-inodes-hashtable (make-hash-table :test 'equal :size 97) |
28210 | 1050 "Hash table for storing file names and their \"inode numbers\".") |
1051 | |
1052 (defvar ange-ftp-next-inode-number 1 | |
1053 "Next \"inode number\" value. We give each file name a unique number.") | |
1054 | |
1055 (defvar ange-ftp-ls-cache-lsargs nil | |
1056 "Last set of args used by ange-ftp-ls.") | |
1057 | |
1058 (defvar ange-ftp-ls-cache-file nil | |
1059 "Last file passed to ange-ftp-ls.") | |
1060 | |
1061 (defvar ange-ftp-ls-cache-res nil | |
1062 "Last result returned from ange-ftp-ls.") | |
1063 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1064 (defconst ange-ftp-expand-dir-hashtable (make-hash-table :test 'equal)) |
28210 | 1065 |
1066 (defconst ange-ftp-expand-dir-regexp "^5.0 \\([^: ]+\\):") | |
1067 | |
1068 ;; These are local variables in each FTP process buffer. | |
1069 (defvar ange-ftp-hash-mark-unit nil) | |
1070 (defvar ange-ftp-hash-mark-count nil) | |
1071 (defvar ange-ftp-xfer-size nil) | |
1072 (defvar ange-ftp-process-string nil) | |
1073 (defvar ange-ftp-process-result-line nil) | |
1074 (defvar ange-ftp-process-busy nil) | |
1075 (defvar ange-ftp-process-result nil) | |
1076 (defvar ange-ftp-process-multi-skip nil) | |
1077 (defvar ange-ftp-process-msg nil) | |
1078 (defvar ange-ftp-process-continue nil) | |
1079 (defvar ange-ftp-last-percent nil) | |
1080 | |
1081 ;; These variables are bound by one function and examined by another. | |
1082 ;; Leave them void globally for error checking. | |
1083 (defvar ange-ftp-this-file) | |
1084 (defvar ange-ftp-this-dir) | |
1085 (defvar ange-ftp-this-user) | |
1086 (defvar ange-ftp-this-host) | |
1087 (defvar ange-ftp-this-msg) | |
1088 (defvar ange-ftp-completion-ignored-pattern) | |
1089 (defvar ange-ftp-trample-marker) | |
1090 | |
1091 ;; New error symbols. | |
1092 (put 'ftp-error 'error-conditions '(ftp-error file-error error)) | |
1093 ;; (put 'ftp-error 'error-message "FTP error") | |
1094 | |
1095 ;;; ------------------------------------------------------------ | |
1096 ;;; Enhanced message support. | |
1097 ;;; ------------------------------------------------------------ | |
1098 | |
1099 (defun ange-ftp-message (fmt &rest args) | |
1100 "Display message in echo area, but indicate if truncated. | |
1101 Args are as in `message': a format string, plus arguments to be formatted." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1102 (let ((msg (apply 'format fmt args)) |
28210 | 1103 (max (window-width (minibuffer-window)))) |
1104 (if noninteractive | |
1105 msg | |
1106 (if (>= (length msg) max) | |
1107 ;; Take just the last MAX - 3 chars of the string. | |
1108 (setq msg (concat "> " (substring msg (- 3 max))))) | |
1109 (message "%s" msg)))) | |
1110 | |
1111 (defun ange-ftp-abbreviate-filename (file &optional new) | |
30459 | 1112 "Abbreviate the file name FILE relative to the `default-directory'. |
28210 | 1113 If the optional parameter NEW is given and the non-directory parts match, |
1114 only return the directory part of FILE." | |
1115 (save-match-data | |
1116 (if (and default-directory | |
1117 (string-match (concat "^" | |
1118 (regexp-quote default-directory) | |
1119 ".") file)) | |
1120 (setq file (substring file (1- (match-end 0))))) | |
1121 (if (and new | |
1122 (string-equal (file-name-nondirectory file) | |
1123 (file-name-nondirectory new))) | |
1124 (setq file (file-name-directory file))) | |
1125 (or file "./"))) | |
1126 | |
1127 ;;;; ------------------------------------------------------------ | |
1128 ;;;; User / Host mapping support. | |
1129 ;;;; ------------------------------------------------------------ | |
1130 | |
1131 (defun ange-ftp-set-user (host user) | |
1132 "For a given HOST, set or change the default USER." | |
1133 (interactive "sHost: \nsUser: ") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1134 (puthash host user ange-ftp-user-hashtable)) |
28210 | 1135 |
1136 (defun ange-ftp-get-user (host) | |
1137 "Given a HOST, return the default USER." | |
1138 (ange-ftp-parse-netrc) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1139 (let ((user (gethash host ange-ftp-user-hashtable))) |
28210 | 1140 (or user |
1141 (prog1 | |
1142 (setq user | |
1143 (cond ((stringp ange-ftp-default-user) | |
1144 ;; We have a default name. Use it. | |
1145 ange-ftp-default-user) | |
1146 (ange-ftp-default-user | |
1147 ;; Ask the user. | |
1148 (let ((enable-recursive-minibuffers t)) | |
1149 (read-string (format "User for %s: " host) | |
1150 (user-login-name)))) | |
1151 (ange-ftp-netrc-default-user) | |
1152 ;; Default to the user's login name. | |
1153 (t | |
1154 (user-login-name)))) | |
1155 (ange-ftp-set-user host user))))) | |
1156 | |
1157 ;;;; ------------------------------------------------------------ | |
1158 ;;;; Password support. | |
1159 ;;;; ------------------------------------------------------------ | |
1160 | |
1161 (defmacro ange-ftp-generate-passwd-key (host user) | |
30459 | 1162 `(concat (downcase ,host) "/" ,user)) |
28210 | 1163 |
1164 (defmacro ange-ftp-lookup-passwd (host user) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1165 `(gethash (ange-ftp-generate-passwd-key ,host ,user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1166 ange-ftp-passwd-hashtable)) |
28210 | 1167 |
1168 (defun ange-ftp-set-passwd (host user passwd) | |
1169 "For a given HOST and USER, set or change the associated PASSWORD." | |
1170 (interactive (list (read-string "Host: ") | |
1171 (read-string "User: ") | |
1172 (read-passwd "Password: "))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1173 (puthash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1174 passwd ange-ftp-passwd-hashtable)) |
28210 | 1175 |
1176 (defun ange-ftp-get-host-with-passwd (user) | |
1177 "Given a USER, return a host we know the password for." | |
1178 (ange-ftp-parse-netrc) | |
1179 (catch 'found-one | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1180 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1181 (lambda (host val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1182 (if (ange-ftp-lookup-passwd host user) (throw 'found-one host))) |
28210 | 1183 ange-ftp-user-hashtable) |
1184 (save-match-data | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1185 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1186 (lambda (key value) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1187 (if (string-match "^[^/]*\\(/\\).*$" key) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1188 (let ((host (substring key 0 (match-beginning 1)))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1189 (if (and (string-equal user (substring key (match-end 1))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1190 value) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1191 (throw 'found-one host))))) |
28210 | 1192 ange-ftp-passwd-hashtable)) |
1193 nil)) | |
1194 | |
1195 (defun ange-ftp-get-passwd (host user) | |
1196 "Return the password for specified HOST and USER, asking user if necessary." | |
1197 (ange-ftp-parse-netrc) | |
1198 | |
1199 ;; look up password in the hash table first; user might have overridden the | |
1200 ;; defaults. | |
1201 (cond ((ange-ftp-lookup-passwd host user)) | |
30459 | 1202 |
28210 | 1203 ;; See if default user and password set. |
1204 ((and (stringp ange-ftp-default-user) | |
1205 ange-ftp-default-password | |
1206 (string-equal user ange-ftp-default-user)) | |
1207 ange-ftp-default-password) | |
30459 | 1208 |
28210 | 1209 ;; See if default user and password set from .netrc file. |
1210 ((and (stringp ange-ftp-netrc-default-user) | |
1211 ange-ftp-netrc-default-password | |
1212 (string-equal user ange-ftp-netrc-default-user)) | |
1213 ange-ftp-netrc-default-password) | |
30459 | 1214 |
28210 | 1215 ;; anonymous ftp password is handled specially since there is an |
1216 ;; unwritten rule about how that is used on the Internet. | |
1217 ((and (or (string-equal user "anonymous") | |
1218 (string-equal user "ftp")) | |
1219 ange-ftp-generate-anonymous-password) | |
1220 (if (stringp ange-ftp-generate-anonymous-password) | |
1221 ange-ftp-generate-anonymous-password | |
1222 user-mail-address)) | |
30459 | 1223 |
28210 | 1224 ;; see if same user has logged in to other hosts; if so then prompt |
1225 ;; with the password that was used there. | |
1226 (t | |
1227 (let* ((other (ange-ftp-get-host-with-passwd user)) | |
1228 (passwd (if other | |
30459 | 1229 |
28210 | 1230 ;; found another machine with the same user. |
1231 ;; Try that account. | |
1232 (read-passwd | |
1233 (format "passwd for %s@%s (default same as %s@%s): " | |
1234 user host user other) | |
1235 nil | |
1236 (ange-ftp-lookup-passwd other user)) | |
30459 | 1237 |
28210 | 1238 ;; I give up. Ask the user for the password. |
1239 (read-passwd | |
1240 (format "Password for %s@%s: " user host))))) | |
1241 (ange-ftp-set-passwd host user passwd) | |
1242 passwd)))) | |
1243 | |
1244 ;;;; ------------------------------------------------------------ | |
1245 ;;;; Account support | |
1246 ;;;; ------------------------------------------------------------ | |
1247 | |
1248 ;; Account passwords must be either specified in the .netrc file, or set | |
1249 ;; manually by calling ange-ftp-set-account. For the moment, ange-ftp doesn't | |
1250 ;; check to see whether the FTP process is actually prompting for an account | |
1251 ;; password. | |
30459 | 1252 |
28210 | 1253 (defun ange-ftp-set-account (host user account) |
1254 "For a given HOST and USER, set or change the associated ACCOUNT password." | |
1255 (interactive (list (read-string "Host: ") | |
1256 (read-string "User: ") | |
1257 (read-passwd "Account password: "))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1258 (puthash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1259 account ange-ftp-account-hashtable)) |
28210 | 1260 |
1261 (defun ange-ftp-get-account (host user) | |
1262 "Given a HOST and USER, return the FTP account." | |
1263 (ange-ftp-parse-netrc) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1264 (or (gethash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1265 ange-ftp-account-hashtable) |
28210 | 1266 (and (stringp ange-ftp-default-user) |
1267 (string-equal user ange-ftp-default-user) | |
1268 ange-ftp-default-account) | |
1269 (and (stringp ange-ftp-netrc-default-user) | |
1270 (string-equal user ange-ftp-netrc-default-user) | |
1271 ange-ftp-netrc-default-account))) | |
1272 | |
1273 ;;;; ------------------------------------------------------------ | |
1274 ;;;; ~/.netrc support | |
1275 ;;;; ------------------------------------------------------------ | |
1276 | |
1277 (defun ange-ftp-chase-symlinks (file) | |
1278 "Return the filename that FILE references, following all symbolic links." | |
1279 (let (temp) | |
1280 (while (setq temp (ange-ftp-real-file-symlink-p file)) | |
1281 (setq file | |
1282 (if (file-name-absolute-p temp) | |
1283 temp | |
1284 (concat (file-name-directory file) temp))))) | |
1285 file) | |
1286 | |
1287 ;; Move along current line looking for the value of the TOKEN. | |
1288 ;; Valid separators between TOKEN and its value are commas and | |
1289 ;; whitespace. Second arg LIMIT is a limit for the search. | |
1290 | |
1291 (defun ange-ftp-parse-netrc-token (token limit) | |
1292 (if (search-forward token limit t) | |
1293 (let (beg) | |
1294 (skip-chars-forward ", \t\r\n" limit) | |
1295 (if (eq (following-char) ?\") ;quoted token value | |
1296 (progn (forward-char 1) | |
1297 (setq beg (point)) | |
1298 (skip-chars-forward "^\"" limit) | |
1299 (forward-char 1) | |
1300 (buffer-substring beg (1- (point)))) | |
1301 (setq beg (point)) | |
1302 (skip-chars-forward "^, \t\r\n" limit) | |
1303 (buffer-substring beg (point)))))) | |
1304 | |
1305 ;; Extract the values for the tokens `machine', `login', | |
1306 ;; `password' and `account' in the current buffer. If successful, | |
1307 ;; record the information found. | |
1308 | |
1309 (defun ange-ftp-parse-netrc-group () | |
1310 (let ((start (point)) | |
1311 (end (save-excursion | |
1312 (if (looking-at "machine\\>") | |
1313 ;; Skip `machine' and the machine name that follows. | |
1314 (progn | |
1315 (skip-chars-forward "^ \t\r\n") | |
1316 (skip-chars-forward " \t\r\n") | |
1317 (skip-chars-forward "^ \t\r\n")) | |
1318 ;; Skip `default'. | |
1319 (skip-chars-forward "^ \t\r\n")) | |
1320 ;; Find start of the next `machine' or `default' | |
1321 ;; or the end of the buffer. | |
1322 (if (re-search-forward "machine\\>\\|default\\>" nil t) | |
1323 (match-beginning 0) | |
1324 (point-max)))) | |
1325 machine login password account) | |
1326 (setq machine (ange-ftp-parse-netrc-token "machine" end) | |
1327 login (ange-ftp-parse-netrc-token "login" end) | |
1328 password (ange-ftp-parse-netrc-token "password" end) | |
1329 account (ange-ftp-parse-netrc-token "account" end)) | |
1330 (if (and machine login) | |
1331 ;; found a `machine` token. | |
1332 (progn | |
1333 (ange-ftp-set-user machine login) | |
1334 (ange-ftp-set-passwd machine login password) | |
1335 (and account | |
1336 (ange-ftp-set-account machine login account))) | |
1337 (goto-char start) | |
1338 (if (search-forward "default" end t) | |
1339 ;; found a `default' token | |
1340 (progn | |
1341 (setq login (ange-ftp-parse-netrc-token "login" end) | |
1342 password (ange-ftp-parse-netrc-token "password" end) | |
1343 account (ange-ftp-parse-netrc-token "account" end)) | |
1344 (and login | |
1345 (setq ange-ftp-netrc-default-user login)) | |
1346 (and password | |
1347 (setq ange-ftp-netrc-default-password password)) | |
1348 (and account | |
1349 (setq ange-ftp-netrc-default-account account))))) | |
1350 (goto-char end))) | |
1351 | |
1352 ;; Read in ~/.netrc, if one exists. If ~/.netrc file exists and has | |
1353 ;; the correct permissions then extract the \`machine\', \`login\', | |
1354 ;; \`password\' and \`account\' information from within. | |
1355 | |
1356 (defun ange-ftp-parse-netrc () | |
1357 ;; We set this before actually doing it to avoid the possibility | |
1358 ;; of an infinite loop if ange-ftp-netrc-filename is an FTP file. | |
1359 (interactive) | |
1360 (let (file attr) | |
1361 (let ((default-directory "/")) | |
1362 (setq file (ange-ftp-chase-symlinks | |
1363 (ange-ftp-real-expand-file-name ange-ftp-netrc-filename))) | |
1364 (setq attr (ange-ftp-real-file-attributes file))) | |
1365 (if (and attr ; file exists. | |
1366 (not (equal (nth 5 attr) ange-ftp-netrc-modtime))) ; file changed | |
1367 (save-match-data | |
1368 (if (or ange-ftp-disable-netrc-security-check | |
1369 (and (eq (nth 2 attr) (user-uid)) ; Same uids. | |
1370 (string-match ".r..------" (nth 8 attr)))) | |
1371 (save-excursion | |
1372 ;; we are cheating a bit here. I'm trying to do the equivalent | |
1373 ;; of find-file on the .netrc file, but then nuke it afterwards. | |
1374 ;; with the bit of logic below we should be able to have | |
1375 ;; encrypted .netrc files. | |
1376 (set-buffer (generate-new-buffer "*ftp-.netrc*")) | |
1377 (ange-ftp-real-insert-file-contents file) | |
1378 (setq buffer-file-name file) | |
1379 (setq default-directory (file-name-directory file)) | |
1380 (normal-mode t) | |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
1381 (run-hooks 'find-file-hook) |
28210 | 1382 (setq buffer-file-name nil) |
1383 (goto-char (point-min)) | |
1384 (skip-chars-forward " \t\r\n") | |
1385 (while (not (eobp)) | |
1386 (ange-ftp-parse-netrc-group)) | |
1387 (kill-buffer (current-buffer))) | |
1388 (ange-ftp-message "%s either not owned by you or badly protected." | |
1389 ange-ftp-netrc-filename) | |
1390 (sit-for 1)) | |
1391 (setq ange-ftp-netrc-modtime (nth 5 attr)))))) | |
1392 | |
1393 ;; Return a list of prefixes of the form 'user@host:' to be used when | |
1394 ;; completion is done in the root directory. | |
1395 | |
1396 (defun ange-ftp-generate-root-prefixes () | |
1397 (ange-ftp-parse-netrc) | |
1398 (save-match-data | |
1399 (let (res) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1400 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1401 (lambda (key value) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1402 (if (string-match "^[^/]*\\(/\\).*$" key) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1403 (let ((host (substring key 0 (match-beginning 1))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1404 (user (substring key (match-end 1)))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1405 (push (concat user "@" host ":") res)))) |
28210 | 1406 ange-ftp-passwd-hashtable) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1407 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1408 (lambda (host user) (push (concat host ":") res)) |
28210 | 1409 ange-ftp-user-hashtable) |
1410 (or res (list nil))))) | |
1411 | |
1412 ;;;; ------------------------------------------------------------ | |
1413 ;;;; Remote file name syntax support. | |
1414 ;;;; ------------------------------------------------------------ | |
1415 | |
1416 (defmacro ange-ftp-ftp-name-component (n ns name) | |
1417 "Extract the Nth ftp file name component from NS." | |
30459 | 1418 `(let ((elt (nth ,n ,ns))) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1419 (match-string elt ,name))) |
28210 | 1420 |
1421 (defvar ange-ftp-ftp-name-arg "") | |
1422 (defvar ange-ftp-ftp-name-res nil) | |
1423 | |
1424 ;; Parse NAME according to `ange-ftp-name-format' (which see). | |
1425 ;; Returns a list (HOST USER NAME), or nil if NAME does not match the format. | |
1426 (defun ange-ftp-ftp-name (name) | |
1427 (if (string-equal name ange-ftp-ftp-name-arg) | |
1428 ange-ftp-ftp-name-res | |
1429 (setq ange-ftp-ftp-name-arg name | |
1430 ange-ftp-ftp-name-res | |
1431 (save-match-data | |
1432 (if (posix-string-match (car ange-ftp-name-format) name) | |
1433 (let* ((ns (cdr ange-ftp-name-format)) | |
1434 (host (ange-ftp-ftp-name-component 0 ns name)) | |
1435 (user (ange-ftp-ftp-name-component 1 ns name)) | |
1436 (name (ange-ftp-ftp-name-component 2 ns name))) | |
1437 (if (zerop (length user)) | |
1438 (setq user (ange-ftp-get-user host))) | |
1439 (list host user name)) | |
1440 nil))))) | |
1441 | |
1442 ;; Take a FULLNAME that matches according to ange-ftp-name-format and | |
1443 ;; replace the name component with NAME. | |
1444 (defun ange-ftp-replace-name-component (fullname name) | |
1445 (save-match-data | |
1446 (if (posix-string-match (car ange-ftp-name-format) fullname) | |
1447 (let* ((ns (cdr ange-ftp-name-format)) | |
1448 (elt (nth 2 ns))) | |
1449 (concat (substring fullname 0 (match-beginning elt)) | |
1450 name | |
1451 (substring fullname (match-end elt))))))) | |
1452 | |
1453 ;;;; ------------------------------------------------------------ | |
1454 ;;;; Miscellaneous utils. | |
1455 ;;;; ------------------------------------------------------------ | |
1456 | |
1457 ;; (setq ange-ftp-tmp-keymap (make-sparse-keymap)) | |
1458 ;; (define-key ange-ftp-tmp-keymap "\C-m" 'exit-minibuffer) | |
1459 | |
1460 (defun ange-ftp-repaint-minibuffer () | |
1461 "Clear any existing minibuffer message; let the minibuffer contents show." | |
1462 (message nil)) | |
1463 | |
1464 ;; Return the name of the buffer that collects output from the ftp process | |
1465 ;; connected to the given HOST and USER pair. | |
1466 (defun ange-ftp-ftp-process-buffer (host user) | |
1467 (concat "*ftp " user "@" host "*")) | |
1468 | |
1469 ;; Display the last chunk of output from the ftp process for the given HOST | |
1470 ;; USER pair, and signal an error including MSG in the text. | |
1471 (defun ange-ftp-error (host user msg) | |
88123 | 1472 (let ((cur (selected-window)) |
1473 (pop-up-windows t)) | |
1474 (pop-to-buffer | |
1475 (get-buffer-create | |
1476 (ange-ftp-ftp-process-buffer host user))) | |
1477 (goto-char (point-max)) | |
1478 (select-window cur)) | |
1479 (signal 'ftp-error (list (format "FTP Error: %s" msg)))) | |
28210 | 1480 |
1481 (defun ange-ftp-set-buffer-mode () | |
1482 "Set correct modes for the current buffer if visiting a remote file." | |
1483 (if (and (stringp buffer-file-name) | |
1484 (ange-ftp-ftp-name buffer-file-name)) | |
1485 (auto-save-mode ange-ftp-auto-save))) | |
1486 | |
1487 (defun ange-ftp-kill-ftp-process (&optional buffer) | |
1488 "Kill the FTP process associated with BUFFER (the current buffer, if nil). | |
1489 If the BUFFER's visited filename or default-directory is an ftp filename | |
1490 then kill the related ftp process." | |
1491 (interactive "bKill FTP process associated with buffer: ") | |
1492 (if (null buffer) | |
1493 (setq buffer (current-buffer)) | |
1494 (setq buffer (get-buffer buffer))) | |
1495 (let ((file (or (buffer-file-name buffer) | |
1496 (save-excursion (set-buffer buffer) default-directory)))) | |
1497 (if file | |
1498 (let ((parsed (ange-ftp-ftp-name (expand-file-name file)))) | |
1499 (if parsed | |
1500 (let ((host (nth 0 parsed)) | |
1501 (user (nth 1 parsed))) | |
1502 (kill-buffer (get-buffer (ange-ftp-ftp-process-buffer host user))))))))) | |
1503 | |
1504 (defun ange-ftp-quote-string (string) | |
1505 "Quote any characters in STRING that may confuse the ftp process." | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1506 (apply 'concat |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1507 (mapcar (lambda (char) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1508 ;; This is said to be wrong; ftp is said to |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1509 ;; need quoting only for ", and that by doubling it. |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1510 ;; But experiment says this kind of quoting is correct |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1511 ;; when talking to ftp on GNU/Linux systems. |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1512 (if (or (<= char ? ) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1513 (> char ?\~) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1514 (= char ?\") |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1515 (= char ?\\)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1516 (vector ?\\ char) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1517 (vector char))) |
28210 | 1518 string))) |
1519 | |
1520 (defun ange-ftp-barf-if-not-directory (directory) | |
1521 (or (file-directory-p directory) | |
1522 (signal 'file-error | |
1523 (list "Opening directory" | |
1524 (if (file-exists-p directory) | |
1525 "not a directory" | |
1526 "no such file or directory") | |
1527 directory)))) | |
1528 | |
1529 ;;;; ------------------------------------------------------------ | |
1530 ;;;; FTP process filter support. | |
1531 ;;;; ------------------------------------------------------------ | |
1532 | |
1533 (defun ange-ftp-process-handle-line (line proc) | |
1534 "Look at the given LINE from the ftp process PROC. | |
1535 Try to categorize it into one of four categories: | |
1536 good, skip, fatal, or unknown." | |
1537 (cond ((string-match ange-ftp-xfer-size-msgs line) | |
1538 (setq ange-ftp-xfer-size | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1539 (/ (string-to-number (match-string 1 line)) |
43187
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1540 1024))) |
28210 | 1541 ((string-match ange-ftp-skip-msgs line) |
1542 t) | |
1543 ((string-match ange-ftp-good-msgs line) | |
1544 (setq ange-ftp-process-busy nil | |
1545 ange-ftp-process-result t | |
1546 ange-ftp-process-result-line line)) | |
1547 ;; Check this before checking for errors. | |
1548 ;; Otherwise the last line of these three seems to be an error: | |
1549 ;; 230-see a significant impact from the move. For those of you who can't | |
1550 ;; 230-use DNS to resolve hostnames and get an error message like | |
1551 ;; 230-"ftp.stsci.edu: unknown host", the new IP address will be... | |
1552 ((string-match ange-ftp-multi-msgs line) | |
1553 (setq ange-ftp-process-multi-skip t)) | |
1554 ((string-match ange-ftp-fatal-msgs line) | |
1555 (delete-process proc) | |
1556 (setq ange-ftp-process-busy nil | |
1557 ange-ftp-process-result-line line)) | |
1558 (ange-ftp-process-multi-skip | |
1559 t) | |
1560 (t | |
1561 (setq ange-ftp-process-busy nil | |
1562 ange-ftp-process-result-line line)))) | |
1563 | |
1564 (defun ange-ftp-set-xfer-size (host user bytes) | |
1565 "Set the size of the next FTP transfer in bytes." | |
1566 (let ((proc (ange-ftp-get-process host user))) | |
1567 (if proc | |
1568 (let ((buf (process-buffer proc))) | |
1569 (if buf | |
1570 (save-excursion | |
1571 (set-buffer buf) | |
43187
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1572 (setq ange-ftp-xfer-size |
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1573 ;; For very large files, BYTES can be a float. |
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1574 (if (integerp bytes) |
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1575 (ash bytes -10) |
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1576 (/ bytes 1024))))))))) |
28210 | 1577 |
1578 (defun ange-ftp-process-handle-hash (str) | |
1579 "Remove hash marks from STRING and display count so far." | |
1580 (setq str (concat (substring str 0 (match-beginning 0)) | |
1581 (substring str (match-end 0))) | |
1582 ange-ftp-hash-mark-count (+ (- (match-end 0) | |
1583 (match-beginning 0)) | |
1584 ange-ftp-hash-mark-count)) | |
1585 (and ange-ftp-hash-mark-unit | |
1586 ange-ftp-process-msg | |
1587 ange-ftp-process-verbose | |
1588 (not (eq (selected-window) (minibuffer-window))) | |
1589 (not (boundp 'search-message)) ;screws up isearch otherwise | |
1590 (not cursor-in-echo-area) ;screws up y-or-n-p otherwise | |
1591 (let ((kbytes (ash (* ange-ftp-hash-mark-unit | |
1592 ange-ftp-hash-mark-count) | |
1593 -6))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1594 (if (zerop ange-ftp-xfer-size) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1595 (ange-ftp-message "%s...%dk" ange-ftp-process-msg kbytes) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1596 (let ((percent (/ (* 100 kbytes) ange-ftp-xfer-size))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1597 ;; cut out the redisplay of identical %-age messages. |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1598 (unless (eq percent ange-ftp-last-percent) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1599 (setq ange-ftp-last-percent percent) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1600 (ange-ftp-message "%s...%d%%" ange-ftp-process-msg percent)))))) |
28210 | 1601 str) |
1602 | |
1603 ;; Call the function specified by CONT. CONT can be either a function | |
1604 ;; or a list of a function and some args. The first two parameters | |
1605 ;; passed to the function will be RESULT and LINE. The remaining args | |
1606 ;; will be taken from CONT if a list was passed. | |
1607 | |
1608 (defun ange-ftp-call-cont (cont result line) | |
1609 (if cont | |
1610 (if (and (listp cont) | |
1611 (not (eq (car cont) 'lambda))) | |
1612 (apply (car cont) result line (cdr cont)) | |
1613 (funcall cont result line)))) | |
1614 | |
1615 ;; Build up a complete line of output from the ftp PROCESS and pass it | |
1616 ;; on to ange-ftp-process-handle-line to deal with. | |
1617 | |
1618 (defun ange-ftp-process-filter (proc str) | |
1619 (let ((buffer (process-buffer proc)) | |
1620 (old-buffer (current-buffer))) | |
1621 | |
1622 ;; Eliminate nulls. | |
1623 (while (string-match "\000+" str) | |
30459 | 1624 (setq str (replace-match "" nil nil str))) |
28210 | 1625 |
1626 ;; see if the buffer is still around... it could have been deleted. | |
1627 (if (buffer-name buffer) | |
1628 (unwind-protect | |
1629 (progn | |
1630 (set-buffer (process-buffer proc)) | |
30459 | 1631 |
28210 | 1632 ;; handle hash mark printing |
1633 (and ange-ftp-process-busy | |
1634 (string-match "^#+$" str) | |
1635 (setq str (ange-ftp-process-handle-hash str))) | |
1636 (comint-output-filter proc str) | |
1637 ;; Replace STR by the result of the comint processing. | |
1638 (setq str (buffer-substring comint-last-output-start | |
1639 (process-mark proc))) | |
1640 (if ange-ftp-process-busy | |
1641 (progn | |
1642 (setq ange-ftp-process-string (concat ange-ftp-process-string | |
1643 str)) | |
30459 | 1644 |
28210 | 1645 ;; if we gave an empty password to the USER command earlier |
1646 ;; then we should send a null password now. | |
1647 (if (string-match "Password: *$" ange-ftp-process-string) | |
1648 (send-string proc "\n")))) | |
1649 (while (and ange-ftp-process-busy | |
1650 (string-match "\n" ange-ftp-process-string)) | |
1651 (let ((line (substring ange-ftp-process-string | |
1652 0 | |
1653 (match-beginning 0)))) | |
1654 (setq ange-ftp-process-string (substring ange-ftp-process-string | |
1655 (match-end 0))) | |
1656 (while (string-match "^ftp> *" line) | |
1657 (setq line (substring line (match-end 0)))) | |
1658 (ange-ftp-process-handle-line line proc))) | |
1659 | |
1660 ;; has the ftp client finished? if so then do some clean-up | |
1661 ;; actions. | |
1662 (if (not ange-ftp-process-busy) | |
1663 (progn | |
1664 ;; reset the xfer size | |
1665 (setq ange-ftp-xfer-size 0) | |
1666 | |
1667 ;; issue the "done" message since we've finished. | |
1668 (if (and ange-ftp-process-msg | |
1669 ange-ftp-process-verbose | |
1670 ange-ftp-process-result) | |
1671 (progn | |
1672 (ange-ftp-message "%s...done" ange-ftp-process-msg) | |
1673 (ange-ftp-repaint-minibuffer) | |
1674 (setq ange-ftp-process-msg nil))) | |
30459 | 1675 |
28210 | 1676 ;; is there a continuation we should be calling? if so, |
1677 ;; we'd better call it, making sure we only call it once. | |
1678 (if ange-ftp-process-continue | |
1679 (let ((cont ange-ftp-process-continue)) | |
1680 (setq ange-ftp-process-continue nil) | |
1681 (ange-ftp-call-cont cont | |
1682 ange-ftp-process-result | |
1683 ange-ftp-process-result-line)))))) | |
1684 (set-buffer old-buffer))))) | |
1685 | |
1686 (defun ange-ftp-process-sentinel (proc str) | |
1687 "When ftp process changes state, nuke all file-entries in cache." | |
1688 (let ((name (process-name proc))) | |
1689 (if (string-match "\\*ftp \\([^@]+\\)@\\([^*]+\\)\\*" name) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1690 (let ((user (match-string 1 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1691 (host (match-string 2 name))) |
28210 | 1692 (ange-ftp-wipe-file-entries host user)))) |
1693 (setq ange-ftp-ls-cache-file nil)) | |
1694 | |
1695 ;;;; ------------------------------------------------------------ | |
1696 ;;;; Gateway support. | |
1697 ;;;; ------------------------------------------------------------ | |
1698 | |
1699 (defun ange-ftp-use-gateway-p (host) | |
1700 "Returns whether to access this host via a normal (non-smart) gateway." | |
1701 ;; yes, I know that I could simplify the following expression, but it is | |
1702 ;; clearer (to me at least) this way. | |
1703 (and (not ange-ftp-smart-gateway) | |
1704 (save-match-data | |
1705 (not (string-match ange-ftp-local-host-regexp host))))) | |
1706 | |
1707 (defun ange-ftp-use-smart-gateway-p (host) | |
1708 "Returns whether to access this host via a smart gateway." | |
1709 (and ange-ftp-smart-gateway | |
1710 (save-match-data | |
1711 (not (string-match ange-ftp-local-host-regexp host))))) | |
1712 | |
1713 | |
1714 ;;; ------------------------------------------------------------ | |
1715 ;;; Temporary file location and deletion... | |
1716 ;;; ------------------------------------------------------------ | |
1717 | |
1718 (defun ange-ftp-make-tmp-name (host) | |
1719 "This routine will return the name of a new file." | |
1720 (make-temp-file (if (ange-ftp-use-gateway-p host) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1721 ange-ftp-gateway-tmp-name-template |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1722 ange-ftp-tmp-name-template))) |
28210 | 1723 |
1724 (defalias 'ange-ftp-del-tmp-name 'delete-file) | |
1725 | |
1726 ;;;; ------------------------------------------------------------ | |
1727 ;;;; Interactive gateway program support. | |
1728 ;;;; ------------------------------------------------------------ | |
1729 | |
1730 (defvar ange-ftp-gwp-running t) | |
1731 (defvar ange-ftp-gwp-status nil) | |
1732 | |
1733 (defun ange-ftp-gwp-sentinel (proc str) | |
1734 (setq ange-ftp-gwp-running nil)) | |
1735 | |
1736 (defun ange-ftp-gwp-filter (proc str) | |
1737 (comint-output-filter proc str) | |
1738 (save-excursion | |
1739 (set-buffer (process-buffer proc)) | |
1740 ;; Replace STR by the result of the comint processing. | |
1741 (setq str (buffer-substring comint-last-output-start (process-mark proc)))) | |
1742 (cond ((string-match "login: *$" str) | |
1743 (send-string proc | |
1744 (concat | |
1745 (let ((ange-ftp-default-user t)) | |
1746 (ange-ftp-get-user ange-ftp-gateway-host)) | |
1747 "\n"))) | |
1748 ((string-match "Password: *$" str) | |
1749 (send-string proc | |
1750 (concat | |
1751 (ange-ftp-get-passwd ange-ftp-gateway-host | |
1752 (ange-ftp-get-user | |
1753 ange-ftp-gateway-host)) | |
1754 "\n"))) | |
1755 ((string-match ange-ftp-gateway-fatal-msgs str) | |
1756 (delete-process proc) | |
1757 (setq ange-ftp-gwp-running nil)) | |
1758 ((string-match ange-ftp-gateway-prompt-pattern str) | |
1759 (setq ange-ftp-gwp-running nil | |
1760 ange-ftp-gwp-status t)))) | |
1761 | |
1762 (defun ange-ftp-gwp-start (host user name args) | |
1763 "Login to the gateway machine and fire up an ftp process." | |
1764 (let* ((gw-user (ange-ftp-get-user ange-ftp-gateway-host)) | |
1765 ;; It would be nice to make process-connection-type nil, | |
1766 ;; but that doesn't work: ftp never responds. | |
1767 ;; Can anyone find a fix for that? | |
1768 (proc (let ((process-connection-type t)) | |
1769 (start-process name name | |
1770 ange-ftp-gateway-program | |
1771 ange-ftp-gateway-host))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1772 (ftp (mapconcat 'identity args " "))) |
28210 | 1773 (process-kill-without-query proc) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1774 (set-process-sentinel proc 'ange-ftp-gwp-sentinel) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1775 (set-process-filter proc 'ange-ftp-gwp-filter) |
28210 | 1776 (save-excursion |
1777 (set-buffer (process-buffer proc)) | |
1778 (goto-char (point-max)) | |
1779 (set-marker (process-mark proc) (point))) | |
1780 (setq ange-ftp-gwp-running t | |
1781 ange-ftp-gwp-status nil) | |
1782 (ange-ftp-message "Connecting to gateway %s..." ange-ftp-gateway-host) | |
1783 (while ange-ftp-gwp-running ;perform login sequence | |
1784 (accept-process-output proc)) | |
1785 (if (not ange-ftp-gwp-status) | |
1786 (ange-ftp-error host user "unable to login to gateway")) | |
1787 (ange-ftp-message "Connecting to gateway %s...done" ange-ftp-gateway-host) | |
1788 (setq ange-ftp-gwp-running t | |
1789 ange-ftp-gwp-status nil) | |
1790 (process-send-string proc ange-ftp-gateway-setup-term-command) | |
1791 (while ange-ftp-gwp-running ;zap ^M's and double echoing. | |
1792 (accept-process-output proc)) | |
1793 (if (not ange-ftp-gwp-status) | |
1794 (ange-ftp-error host user "unable to set terminal modes on gateway")) | |
1795 (setq ange-ftp-gwp-running t | |
1796 ange-ftp-gwp-status nil) | |
1797 (process-send-string proc (concat "exec " ftp "\n")) ;spawn ftp process | |
1798 proc)) | |
1799 | |
1800 ;;;; ------------------------------------------------------------ | |
1801 ;;;; Support for sending commands to the ftp process. | |
1802 ;;;; ------------------------------------------------------------ | |
1803 | |
1804 (defun ange-ftp-raw-send-cmd (proc cmd &optional msg cont nowait) | |
1805 "Low-level routine to send the given ftp CMD to the ftp PROCESS. | |
1806 MSG is an optional message to output before and after the command. | |
30459 | 1807 If CONT is non-nil then it is either a function or a list of function |
1808 and some arguments. The function will be called when the ftp command | |
1809 has completed. | |
1810 If CONT is nil then this routine will return \(RESULT . LINE\) where RESULT | |
28210 | 1811 is whether the command was successful, and LINE is the line from the FTP |
1812 process that caused the command to complete. | |
1813 If NOWAIT is given then the routine will return immediately the command has | |
1814 been queued with no result. CONT will still be called, however." | |
1815 (if (memq (process-status proc) '(run open)) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
1816 (with-current-buffer (process-buffer proc) |
28210 | 1817 (ange-ftp-wait-not-busy proc) |
1818 (setq ange-ftp-process-string "" | |
1819 ange-ftp-process-result-line "" | |
1820 ange-ftp-process-busy t | |
1821 ange-ftp-process-result nil | |
1822 ange-ftp-process-multi-skip nil | |
1823 ange-ftp-process-msg msg | |
1824 ange-ftp-process-continue cont | |
1825 ange-ftp-hash-mark-count 0 | |
1826 ange-ftp-last-percent -1 | |
1827 cmd (concat cmd "\n")) | |
1828 (and msg ange-ftp-process-verbose (ange-ftp-message "%s..." msg)) | |
1829 (goto-char (point-max)) | |
1830 (move-marker comint-last-input-start (point)) | |
1831 ;; don't insert the password into the buffer on the USER command. | |
1832 (save-match-data | |
1833 (if (string-match "^user \"[^\"]*\"" cmd) | |
1834 (insert (substring cmd 0 (match-end 0)) " Turtle Power!\n") | |
1835 (insert cmd))) | |
1836 (move-marker comint-last-input-end (point)) | |
1837 (send-string proc cmd) | |
1838 (set-marker (process-mark proc) (point)) | |
1839 (if nowait | |
1840 nil | |
1841 (ange-ftp-wait-not-busy proc) | |
1842 (if cont | |
1843 nil ;cont has already been called | |
1844 (cons ange-ftp-process-result ange-ftp-process-result-line)))))) | |
1845 | |
1846 ;; Wait for the ange-ftp process PROC not to be busy. | |
1847 (defun ange-ftp-wait-not-busy (proc) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
1848 (with-current-buffer (process-buffer proc) |
28210 | 1849 (condition-case nil |
1850 ;; This is a kludge to let user quit in case ftp gets hung. | |
1851 ;; It matters because this function can be called from the filter. | |
1852 ;; It is bad to allow quitting in a filter, but getting hung | |
1853 ;; is worse. By binding quit-flag to nil, we might avoid | |
1854 ;; most of the probability of getting screwed because the user | |
1855 ;; wants to quit some command. | |
1856 (let ((quit-flag nil) | |
1857 (inhibit-quit nil)) | |
1858 (while ange-ftp-process-busy | |
1859 (accept-process-output proc))) | |
1860 (quit | |
1861 ;; If the user does quit out of this, | |
1862 ;; kill the process. That stops any transfer in progress. | |
1863 ;; The next operation will open a new ftp connection. | |
1864 (delete-process proc) | |
1865 (signal 'quit nil))))) | |
1866 | |
1867 (defun ange-ftp-nslookup-host (host) | |
1868 "Attempt to resolve the given HOSTNAME using nslookup if possible." | |
1869 (interactive "sHost: ") | |
1870 (if ange-ftp-nslookup-program | |
1871 (let ((default-directory | |
1872 (if (file-accessible-directory-p default-directory) | |
1873 default-directory | |
1874 exec-directory)) | |
1875 ;; It would be nice to make process-connection-type nil, | |
1876 ;; but that doesn't work: ftp never responds. | |
1877 ;; Can anyone find a fix for that? | |
1878 (proc (let ((process-connection-type t)) | |
1879 (start-process " *nslookup*" " *nslookup*" | |
1880 ange-ftp-nslookup-program host))) | |
1881 (res host)) | |
1882 (process-kill-without-query proc) | |
1883 (save-excursion | |
1884 (set-buffer (process-buffer proc)) | |
1885 (while (memq (process-status proc) '(run open)) | |
1886 (accept-process-output proc)) | |
1887 (goto-char (point-min)) | |
1888 (if (re-search-forward "Name:.*\nAddress: *\\(.*\\)$" nil t) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1889 (setq res (match-string 1))) |
28210 | 1890 (kill-buffer (current-buffer))) |
1891 res) | |
1892 host)) | |
1893 | |
1894 (defun ange-ftp-start-process (host user name) | |
1895 "Spawn a new ftp process ready to connect to machine HOST and give it NAME. | |
1896 If HOST is only ftp-able through a gateway machine then spawn a shell | |
1897 on the gateway machine to do the ftp instead." | |
1898 (let* ((use-gateway (ange-ftp-use-gateway-p host)) | |
1899 (use-smart-ftp (and (not ange-ftp-gateway-host) | |
1900 (ange-ftp-use-smart-gateway-p host))) | |
1901 (ftp-prog (if (or use-gateway | |
30459 | 1902 use-smart-ftp) |
28210 | 1903 ange-ftp-gateway-ftp-program-name |
1904 ange-ftp-ftp-program-name)) | |
1905 (args (append (list ftp-prog) ange-ftp-ftp-program-args)) | |
1906 ;; Without the following binding, ange-ftp-start-process | |
1907 ;; recurses on file-accessible-directory-p, since it needs to | |
1908 ;; restart its process in order to determine anything about | |
1909 ;; default-directory. | |
1910 (file-name-handler-alist) | |
1911 (default-directory | |
1912 (if (file-accessible-directory-p default-directory) | |
1913 default-directory | |
1914 exec-directory)) | |
1915 proc) | |
1916 ;; It would be nice to make process-connection-type nil, | |
1917 ;; but that doesn't work: ftp never responds. | |
1918 ;; Can anyone find a fix for that? | |
1919 (let ((process-connection-type t) | |
1920 (process-environment process-environment) | |
1921 (buffer (get-buffer-create name))) | |
1922 (save-excursion | |
1923 (set-buffer buffer) | |
1924 (internal-ange-ftp-mode)) | |
1925 ;; This tells GNU ftp not to output any fancy escape sequences. | |
1926 (setenv "TERM" "dumb") | |
1927 (if use-gateway | |
1928 (if ange-ftp-gateway-program-interactive | |
1929 (setq proc (ange-ftp-gwp-start host user name args)) | |
1930 (setq proc (apply 'start-process name name | |
1931 (append (list ange-ftp-gateway-program | |
1932 ange-ftp-gateway-host) | |
1933 args)))) | |
1934 (setq proc (apply 'start-process name name args)))) | |
1935 (save-excursion | |
1936 (set-buffer (process-buffer proc)) | |
1937 (goto-char (point-max)) | |
1938 (set-marker (process-mark proc) (point))) | |
1939 (process-kill-without-query proc) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1940 (set-process-sentinel proc 'ange-ftp-process-sentinel) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1941 (set-process-filter proc 'ange-ftp-process-filter) |
28210 | 1942 ;; On Windows, the standard ftp client buffers its output (because |
1943 ;; stdout is a pipe handle) so the startup message may never appear: | |
1944 ;; `accept-process-output' at this point would hang indefinitely. | |
1945 ;; However, sending an innocuous command ("help foo") forces some | |
1946 ;; output that will be ignored, which is just as good. Once we | |
1947 ;; start sending normal commands, the output no longer appears to be | |
1948 ;; buffered, and everything works correctly. My guess is that the | |
1949 ;; output of interest is being sent to stderr which is not buffered. | |
1950 (when (eq system-type 'windows-nt) | |
1951 ;; force ftp output to be treated as DOS text, otherwise the | |
1952 ;; output of "help foo" confuses the EOL detection logic. | |
1953 (set-process-coding-system proc 'raw-text-dos) | |
1954 (process-send-string proc "help foo\n")) | |
1955 (accept-process-output proc) ;wait for ftp startup message | |
1956 proc)) | |
1957 | |
1958 (put 'internal-ange-ftp-mode 'mode-class 'special) | |
1959 | |
1960 (defun internal-ange-ftp-mode () | |
1961 "Major mode for interacting with the FTP process. | |
1962 | |
1963 \\{comint-mode-map}" | |
1964 (interactive) | |
1965 (comint-mode) | |
1966 (setq major-mode 'internal-ange-ftp-mode) | |
1967 (setq mode-name "Internal Ange-ftp") | |
1968 (let ((proc (get-buffer-process (current-buffer)))) | |
1969 (make-local-variable 'ange-ftp-process-string) | |
1970 (setq ange-ftp-process-string "") | |
1971 (make-local-variable 'ange-ftp-process-busy) | |
1972 (make-local-variable 'ange-ftp-process-result) | |
1973 (make-local-variable 'ange-ftp-process-msg) | |
1974 (make-local-variable 'ange-ftp-process-multi-skip) | |
1975 (make-local-variable 'ange-ftp-process-result-line) | |
1976 (make-local-variable 'ange-ftp-process-continue) | |
1977 (make-local-variable 'ange-ftp-hash-mark-count) | |
1978 (make-local-variable 'ange-ftp-binary-hash-mark-size) | |
1979 (make-local-variable 'ange-ftp-ascii-hash-mark-size) | |
1980 (make-local-variable 'ange-ftp-hash-mark-unit) | |
1981 (make-local-variable 'ange-ftp-xfer-size) | |
1982 (make-local-variable 'ange-ftp-last-percent) | |
1983 (setq ange-ftp-hash-mark-count 0) | |
1984 (setq ange-ftp-xfer-size 0) | |
1985 (setq ange-ftp-process-result-line "") | |
1986 | |
1987 (setq comint-prompt-regexp "^ftp> ") | |
1988 (make-local-variable 'comint-password-prompt-regexp) | |
1989 ;; This is a regexp that can't match anything. | |
1990 ;; ange-ftp has its own ways of handling passwords. | |
1991 (setq comint-password-prompt-regexp "^a\\'z") | |
1992 (make-local-variable 'paragraph-start) | |
1993 (setq paragraph-start comint-prompt-regexp))) | |
1994 | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1995 (defcustom ange-ftp-raw-login nil |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1996 "*Use raw ftp commands for login, if account password is not nil. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1997 Some ftp implementations need this, e.g. ftp in NT 4.0." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1998 :group 'ange-ftp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1999 :version "21.3" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2000 :type 'boolean) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2001 |
28210 | 2002 (defun ange-ftp-smart-login (host user pass account proc) |
2003 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT. | |
2004 PROC is the FTP-client's process. This routine uses the smart-gateway | |
30459 | 2005 host specified in `ange-ftp-gateway-host'." |
28210 | 2006 (let ((result (ange-ftp-raw-send-cmd |
2007 proc | |
2008 (format "open %s %s" | |
2009 (ange-ftp-nslookup-host ange-ftp-gateway-host) | |
2010 ange-ftp-smart-gateway-port) | |
2011 (format "Opening FTP connection to %s via %s" | |
2012 host | |
2013 ange-ftp-gateway-host)))) | |
2014 (or (car result) | |
30459 | 2015 (ange-ftp-error host user |
28210 | 2016 (concat "OPEN request failed: " |
2017 (cdr result)))) | |
2018 (setq result (ange-ftp-raw-send-cmd | |
2019 proc (format "user \"%s\"@%s %s %s" | |
2020 user | |
2021 (ange-ftp-nslookup-host host) | |
2022 pass | |
2023 account) | |
2024 (format "Logging in as user %s@%s" | |
2025 user host))) | |
2026 (or (car result) | |
2027 (progn | |
2028 (ange-ftp-set-passwd host user nil) ; reset password | |
2029 (ange-ftp-set-account host user nil) ; reset account | |
2030 (ange-ftp-error host user | |
2031 (concat "USER request failed: " | |
2032 (cdr result))))))) | |
2033 | |
2034 (defun ange-ftp-normal-login (host user pass account proc) | |
2035 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT. | |
2036 PROC is the process to the FTP-client. HOST may have an optional | |
2037 suffix of the form #PORT to specify a non-default port" | |
2038 (save-match-data | |
2039 (string-match "^\\([^#]+\\)\\(#\\([0-9]+\\)\\)?\\'" host) | |
2040 (let* ((nshost (ange-ftp-nslookup-host (match-string 1 host))) | |
2041 (port (match-string 3 host)) | |
2042 (result (ange-ftp-raw-send-cmd | |
2043 proc | |
2044 (if port | |
2045 (format "open %s %s" nshost port) | |
2046 (format "open %s" nshost)) | |
2047 (format "Opening FTP connection to %s" host)))) | |
2048 (or (car result) | |
2049 (ange-ftp-error host user | |
2050 (concat "OPEN request failed: " | |
2051 (cdr result)))) | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2052 (if (not (and ange-ftp-raw-login (string< "" account))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2053 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2054 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2055 (if (and (ange-ftp-use-smart-gateway-p host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2056 ange-ftp-gateway-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2057 (format "user \"%s\"@%s %s %s" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2058 user nshost pass account) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2059 (format "user \"%s\" %s %s" user pass account)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2060 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2061 (let ((good ange-ftp-good-msgs) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2062 (skip ange-ftp-skip-msgs)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2063 (setq ange-ftp-good-msgs (concat ange-ftp-good-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2064 "\\|^331 \\|^332 ")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2065 (if (string-match (regexp-quote "\\|^331 ") ange-ftp-skip-msgs) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2066 (setq ange-ftp-skip-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2067 (replace-match "" t t ange-ftp-skip-msgs))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2068 (if (string-match (regexp-quote "\\|^332 ") ange-ftp-skip-msgs) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2069 (setq ange-ftp-skip-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2070 (replace-match "" t t ange-ftp-skip-msgs))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2071 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2072 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2073 (format "quote \"USER %s\"" user) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2074 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2075 (and (car result) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2076 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2077 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2078 (format "quote \"PASS %s\"" pass) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2079 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2080 (and (car result) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2081 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2082 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2083 (format "quote \"ACCT %s\"" account) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2084 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2085 )) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2086 (setq ange-ftp-good-msgs good |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2087 ange-ftp-skip-msgs skip))) |
28210 | 2088 (or (car result) |
2089 (progn | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2090 (ange-ftp-set-passwd host user nil) ;reset password. |
28210 | 2091 (ange-ftp-set-account host user nil) ;reset account. |
2092 (ange-ftp-error host user | |
2093 (concat "USER request failed: " | |
2094 (cdr result)))))))) | |
2095 | |
2096 ;; ange@hplb.hpl.hp.com says this should not be changed. | |
2097 (defvar ange-ftp-hash-mark-msgs | |
2098 "[hH]ash mark [^0-9]*\\([0-9]+\\)" | |
2099 "*Regexp matching the FTP client's output upon doing a HASH command.") | |
2100 | |
2101 (defun ange-ftp-guess-hash-mark-size (proc) | |
2102 (if ange-ftp-send-hash | |
2103 (save-excursion | |
2104 (set-buffer (process-buffer proc)) | |
2105 (let* ((status (ange-ftp-raw-send-cmd proc "hash")) | |
2106 (result (car status)) | |
2107 (line (cdr status))) | |
2108 (save-match-data | |
2109 (if (string-match ange-ftp-hash-mark-msgs line) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2110 (let ((size (string-to-int (match-string 1 line)))) |
28210 | 2111 (setq ange-ftp-ascii-hash-mark-size size |
2112 ange-ftp-hash-mark-unit (ash size -4)) | |
2113 | |
2114 ;; if a default value for this is set, use that value. | |
2115 (or ange-ftp-binary-hash-mark-size | |
2116 (setq ange-ftp-binary-hash-mark-size size))))))))) | |
2117 | |
2118 (defun ange-ftp-get-process (host user) | |
2119 "Return an FTP subprocess connected to HOST and logged in as USER. | |
2120 Create a new process if needed." | |
2121 (let* ((name (ange-ftp-ftp-process-buffer host user)) | |
2122 (proc (get-process name))) | |
2123 (if (and proc (memq (process-status proc) '(run open))) | |
2124 proc | |
2125 ;; Must delete dead process so that new process can reuse the name. | |
2126 (if proc (delete-process proc)) | |
2127 (let ((pass (ange-ftp-quote-string | |
2128 (ange-ftp-get-passwd host user))) | |
2129 (account (ange-ftp-quote-string | |
2130 (ange-ftp-get-account host user)))) | |
2131 ;; grab a suitable process. | |
2132 (setq proc (ange-ftp-start-process host user name)) | |
30459 | 2133 |
28210 | 2134 ;; login to FTP server. |
2135 (if (and (ange-ftp-use-smart-gateway-p host) | |
2136 ange-ftp-gateway-host) | |
2137 (ange-ftp-smart-login host user pass account proc) | |
2138 (ange-ftp-normal-login host user pass account proc)) | |
30459 | 2139 |
28210 | 2140 ;; Tell client to send back hash-marks as progress. It isn't usually |
2141 ;; fatal if this command fails. | |
2142 (ange-ftp-guess-hash-mark-size proc) | |
2143 | |
2144 ;; Guess at the host type. | |
2145 (ange-ftp-guess-host-type host user) | |
2146 | |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2147 ;; Turn passive mode on or off as requested. |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2148 (let* ((case-fold-search t) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2149 (passive |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2150 (or (assoc-default host ange-ftp-passive-host-alist |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2151 'string-match) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2152 (if ange-ftp-try-passive-mode "on")))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2153 (if passive |
42801
b719a1276b31
(ange-ftp-passive-mode): New arg PROC.
Richard M. Stallman <rms@gnu.org>
parents:
42740
diff
changeset
|
2154 (ange-ftp-passive-mode proc passive))) |
28210 | 2155 |
2156 ;; Run any user-specified hooks. Note that proc, host and user are | |
2157 ;; dynamically bound at this point. | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2158 (let ((ange-ftp-this-user user) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2159 (ange-ftp-this-host host)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2160 (run-hooks 'ange-ftp-process-startup-hook))) |
28210 | 2161 proc))) |
2162 | |
42801
b719a1276b31
(ange-ftp-passive-mode): New arg PROC.
Richard M. Stallman <rms@gnu.org>
parents:
42740
diff
changeset
|
2163 (defun ange-ftp-passive-mode (proc on-or-off) |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2164 (if (string-match (concat "Passive mode " on-or-off) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2165 (cdr (ange-ftp-raw-send-cmd |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2166 proc (concat "passive " on-or-off) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2167 "Trying passive mode..." nil))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2168 (ange-ftp-message (concat "Trying passive mode..." on-or-off)) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2169 (error "Trying passive mode...failed"))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2170 |
28210 | 2171 ;; Variables for caching host and host-type |
2172 (defvar ange-ftp-host-cache nil) | |
2173 (defvar ange-ftp-host-type-cache nil) | |
2174 | |
2175 ;; If ange-ftp-host-type is called with the optional user | |
2176 ;; argument, it will attempt to guess the host type by connecting | |
2177 ;; as user, if necessary. For efficiency, I have tried to give this | |
2178 ;; optional second argument only when necessary. Have I missed any calls | |
2179 ;; to ange-ftp-host-type where it should have been supplied? | |
2180 | |
2181 (defun ange-ftp-host-type (host &optional user) | |
2182 "Return a symbol which represents the type of the HOST given. | |
2183 If the optional argument USER is given, attempts to guess the | |
2184 host-type by logging in as USER." | |
2185 (cond ((null host) 'unix) | |
2186 ;; Return `unix' if HOST is nil, since that's the most vanilla | |
2187 ;; possible return value. | |
2188 ((eq host ange-ftp-host-cache) | |
2189 ange-ftp-host-type-cache) | |
2190 ;; Trigger an ftp connection, in case we need to guess at the host type. | |
2191 ((and user (ange-ftp-get-process host user) (eq host ange-ftp-host-cache)) | |
2192 ange-ftp-host-type-cache) | |
2193 (t | |
2194 (setq ange-ftp-host-cache host | |
2195 ange-ftp-host-type-cache | |
2196 (cond ((ange-ftp-dumb-unix-host host) | |
2197 'dumb-unix) | |
2198 ;; ((and (fboundp 'ange-ftp-vos-host) | |
2199 ;; (ange-ftp-vos-host host)) | |
2200 ;; 'vos) | |
2201 ((and (fboundp 'ange-ftp-vms-host) | |
2202 (ange-ftp-vms-host host)) | |
2203 'vms) | |
2204 ((and (fboundp 'ange-ftp-mts-host) | |
2205 (ange-ftp-mts-host host)) | |
2206 'mts) | |
2207 ((and (fboundp 'ange-ftp-cms-host) | |
2208 (ange-ftp-cms-host host)) | |
2209 'cms) | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2210 ((and (fboundp 'ange-ftp-bs2000-posix-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2211 (ange-ftp-bs2000-posix-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2212 'text-unix) ; POSIX is a non-ASCII Unix |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2213 ((and (fboundp 'ange-ftp-bs2000-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2214 (ange-ftp-bs2000-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2215 'bs2000) |
28210 | 2216 (t |
2217 'unix)))))) | |
2218 | |
2219 ;; It would be nice to abstract the functions ange-ftp-TYPE-host and | |
2220 ;; ange-ftp-add-TYPE-host. The trick is to abstract these functions | |
2221 ;; without sacrificing speed. Also, having separate variables | |
2222 ;; ange-ftp-TYPE-regexp is more user friendly then requiring the user to | |
2223 ;; set an alist to indicate that a host is of a given type. Even with | |
2224 ;; automatic host type recognition, setting a regexp is still a good idea | |
2225 ;; (for efficiency) if you log into a particular non-UNIX host frequently. | |
2226 | |
2227 (defvar ange-ftp-fix-name-func-alist nil | |
2228 "Alist saying how to convert file name to the host's syntax. | |
2229 Association list of \( TYPE \. FUNC \) pairs, where FUNC is a routine | |
2230 which can change a UNIX file name into a name more suitable for a host of type | |
2231 TYPE.") | |
2232 | |
2233 (defvar ange-ftp-fix-dir-name-func-alist nil | |
2234 "Alist saying how to convert directory name to the host's syntax. | |
2235 Association list of \( TYPE \. FUNC \) pairs, where FUNC is a routine | |
2236 which can change UNIX directory name into a directory name more suitable | |
2237 for a host of type TYPE.") | |
2238 | |
2239 ;; *** Perhaps the sense of this variable should be inverted, since there | |
2240 ;; *** is only 1 host type that can take ls-style listing options. | |
2241 (defvar ange-ftp-dumb-host-types '(dumb-unix) | |
2242 "List of host types that can't take UNIX ls-style listing options.") | |
2243 | |
2244 (defun ange-ftp-send-cmd (host user cmd &optional msg cont nowait) | |
2245 "Find an ftp process connected to HOST logged in as USER and send it CMD. | |
2246 MSG is an optional status message to be output before and after issuing the | |
2247 command. | |
30459 | 2248 See the documentation for `ange-ftp-raw-send-cmd' for a description of CONT |
28210 | 2249 and NOWAIT." |
2250 ;; Handle conversion to remote file name syntax and remote ls option | |
2251 ;; capability. | |
2252 (let ((cmd0 (car cmd)) | |
2253 (cmd1 (nth 1 cmd)) | |
2254 (ange-ftp-this-user user) | |
2255 (ange-ftp-this-host host) | |
2256 (ange-ftp-this-msg msg) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2257 cmd2 cmd3 host-type fix-name-func result) |
28210 | 2258 |
2259 (cond | |
30459 | 2260 |
28210 | 2261 ;; pwd case (We don't care what host-type.) |
2262 ((null cmd1)) | |
30459 | 2263 |
28210 | 2264 ;; cmd == 'dir "remote-name" "local-name" "ls-switches" |
2265 ((progn | |
2266 (setq cmd2 (nth 2 cmd) | |
2267 host-type (ange-ftp-host-type host user)) | |
2268 ;; This will trigger an FTP login, if one doesn't exist | |
2269 (eq cmd0 'dir)) | |
2270 (setq cmd1 (funcall | |
2271 (or (cdr (assq host-type ange-ftp-fix-dir-name-func-alist)) | |
2272 'identity) | |
2273 cmd1) | |
2274 cmd3 (nth 3 cmd)) | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
2275 ;; Need to deal with the HP-UX ftp bug. This should also allow us to |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
2276 ;; resolve symlinks to directories on SysV machines. (Sebastian will |
28210 | 2277 ;; be happy.) |
2278 (and (eq host-type 'unix) | |
2279 (string-match "/$" cmd1) | |
2280 (not (string-match "R" cmd3)) | |
2281 (setq cmd1 (concat cmd1 "."))) | |
2282 | |
2283 ;; If the dir name contains a space, some ftp servers will | |
2284 ;; refuse to list it. We instead change directory to the | |
2285 ;; directory in question and ls ".". | |
2286 (when (string-match " " cmd1) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2287 ;; Keep the result. In case of failure, we will (see below) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2288 ;; short-circuit CMD and return this result directly. |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2289 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror)) |
28210 | 2290 (setq cmd1 ".")) |
2291 | |
2292 ;; If the remote ls can take switches, put them in | |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2293 (unless (memq host-type ange-ftp-dumb-host-types) |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2294 (setq cmd0 'ls) |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2295 ;; We cd and then use `ls' with no directory argument. |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2296 ;; This works around a misfeature of some versions of netbsd ftpd. |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2297 (unless (equal cmd1 ".") |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2298 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror))) |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2299 (setq cmd1 cmd3))) |
30459 | 2300 |
28210 | 2301 ;; First argument is the remote name |
2302 ((progn | |
2303 (setq fix-name-func (or (cdr (assq host-type | |
2304 ange-ftp-fix-name-func-alist)) | |
2305 'identity)) | |
2306 (memq cmd0 '(get delete mkdir rmdir cd))) | |
2307 (setq cmd1 (funcall fix-name-func cmd1))) | |
2308 | |
2309 ;; Second argument is the remote name | |
40361
8c6df631e62d
(ange-ftp-send-cmd): Call fix-name-func for
Gerd Moellmann <gerd@gnu.org>
parents:
39888
diff
changeset
|
2310 ((or (memq cmd0 '(append put chmod)) |
8c6df631e62d
(ange-ftp-send-cmd): Call fix-name-func for
Gerd Moellmann <gerd@gnu.org>
parents:
39888
diff
changeset
|
2311 (and (eq cmd0 'quote) (string= cmd1 "mdtm"))) |
28210 | 2312 (setq cmd2 (funcall fix-name-func cmd2))) |
2313 ;; Both arguments are remote names | |
2314 ((eq cmd0 'rename) | |
2315 (setq cmd1 (funcall fix-name-func cmd1) | |
2316 cmd2 (funcall fix-name-func cmd2)))) | |
30459 | 2317 |
2318 ;; Turn the command into one long string | |
28210 | 2319 (setq cmd0 (symbol-name cmd0)) |
2320 (setq cmd (concat cmd0 | |
2321 (and cmd1 (concat " " cmd1)) | |
2322 (and cmd2 (concat " " cmd2)))) | |
2323 | |
2324 ;; Actually send the resulting command. | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2325 (if (and (consp result) (null (car result))) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2326 ;; `ange-ftp-cd' has failed, so there's no point sending `cmd'. |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2327 result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2328 (let (afsc-result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2329 afsc-line) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2330 (ange-ftp-raw-send-cmd |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2331 (ange-ftp-get-process host user) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2332 cmd |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2333 msg |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2334 (list (lambda (result line host user cmd msg cont nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2335 (or cont (setq afsc-result result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2336 afsc-line line)) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2337 (if result (ange-ftp-call-cont cont result line) |
30459 | 2338 (ange-ftp-raw-send-cmd |
2339 (ange-ftp-get-process host user) | |
2340 cmd | |
2341 msg | |
2342 (list (lambda (result line cont) | |
2343 (or cont (setq afsc-result result | |
2344 afsc-line line)) | |
2345 (ange-ftp-call-cont cont result line)) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2346 cont) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2347 nowait))) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2348 host user cmd msg cont nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2349 nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2350 |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2351 (if nowait |
28210 | 2352 nil |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2353 (if cont |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2354 nil |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2355 (cons afsc-result afsc-line))))))) |
28210 | 2356 |
2357 ;; It might be nice to message users about the host type identified, | |
2358 ;; but there is so much other messaging going on, it would not be | |
2359 ;; seen. No point in slowing things down just so users can read | |
2360 ;; a host type message. | |
2361 | |
2362 (defconst ange-ftp-cms-name-template | |
2363 (concat | |
2364 "^[-A-Z0-9$*][-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?" | |
2365 "[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?\\.[0-9][0-9][0-9A-Z]$")) | |
2366 (defconst ange-ftp-vms-name-template | |
2367 "^[-A-Z0-9_$]+:\\[[-A-Z0-9_$]+\\(\\.[-A-Z0-9_$]+\\)*\\]$") | |
2368 (defconst ange-ftp-mts-name-template | |
2369 "^[A-Z0-9._][A-Z0-9._][A-Z0-9._][A-Z0-9._]:$") | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2370 (defconst ange-ftp-bs2000-filename-pubset-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2371 ":[A-Z0-9]+:" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2372 "Valid pubset for an BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2373 (defconst ange-ftp-bs2000-filename-username-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2374 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2375 "\\$[A-Z0-9]*\\.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2376 "Valid username for an BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2377 (defconst ange-ftp-bs2000-filename-prefix-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2378 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2379 ange-ftp-bs2000-filename-pubset-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2380 ange-ftp-bs2000-filename-username-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2381 "Valid prefix for an BS2000 file name (pubset and user).") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2382 (defconst ange-ftp-bs2000-name-template |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2383 (concat "^" ange-ftp-bs2000-filename-prefix-regexp "$")) |
28210 | 2384 |
2385 (defun ange-ftp-guess-host-type (host user) | |
42706 | 2386 "Guess the host type of HOST. |
28210 | 2387 Works by doing a pwd and examining the directory syntax." |
2388 (let ((host-type (ange-ftp-host-type host)) | |
2389 (key (concat host "/" user "/~"))) | |
2390 (if (eq host-type 'unix) | |
2391 ;; Note that ange-ftp-host-type returns unix as the default value. | |
2392 (save-match-data | |
2393 (let* ((result (ange-ftp-get-pwd host user)) | |
2394 (dir (car result)) | |
2395 fix-name-func) | |
2396 (cond ((null dir) | |
2397 (message "Warning! Unable to get home directory") | |
2398 (sit-for 1) | |
2399 (if (string-match | |
2400 "^450 No current working directory defined$" | |
2401 (cdr result)) | |
30459 | 2402 |
28210 | 2403 ;; We'll assume that if pwd bombs with this |
2404 ;; error message, then it's CMS. | |
2405 (progn | |
2406 (ange-ftp-add-cms-host host) | |
2407 (setq ange-ftp-host-cache host | |
2408 ange-ftp-host-type-cache 'cms)))) | |
2409 | |
2410 ;; try for VMS | |
2411 ((string-match ange-ftp-vms-name-template dir) | |
2412 (ange-ftp-add-vms-host host) | |
2413 ;; The add-host functions clear the host type cache. | |
2414 ;; Therefore, need to set the cache afterwards. | |
2415 (setq ange-ftp-host-cache host | |
2416 ange-ftp-host-type-cache 'vms)) | |
2417 | |
2418 ;; try for MTS | |
2419 ((string-match ange-ftp-mts-name-template dir) | |
2420 (ange-ftp-add-mts-host host) | |
2421 (setq ange-ftp-host-cache host | |
2422 ange-ftp-host-type-cache 'mts)) | |
30459 | 2423 |
28210 | 2424 ;; try for CMS |
2425 ((string-match ange-ftp-cms-name-template dir) | |
2426 (ange-ftp-add-cms-host host) | |
2427 (setq ange-ftp-host-cache host | |
2428 ange-ftp-host-type-cache 'cms)) | |
2429 | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2430 ;; try for BS2000-POSIX |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2431 ((ange-ftp-bs2000-posix-host host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2432 (ange-ftp-add-bs2000-host host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2433 (setq ange-ftp-host-cache host |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2434 ange-ftp-host-type-cache 'text-unix)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2435 ;; try for BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2436 ((and (string-match ange-ftp-bs2000-name-template dir) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2437 (not (ange-ftp-bs2000-posix-host host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2438 (ange-ftp-add-bs2000-host host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2439 (setq ange-ftp-host-cache host |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2440 ange-ftp-host-type-cache 'bs2000)) |
28210 | 2441 ;; assume UN*X |
2442 (t | |
2443 (setq ange-ftp-host-cache host | |
2444 ange-ftp-host-type-cache 'unix))) | |
2445 | |
2446 ;; Now that we have done a pwd, might as well put it in | |
2447 ;; the expand-dir hashtable. | |
2448 (let ((ange-ftp-this-user user) | |
2449 (ange-ftp-this-host host)) | |
2450 (setq fix-name-func (cdr (assq ange-ftp-host-type-cache | |
2451 ange-ftp-fix-name-func-alist))) | |
2452 (if fix-name-func | |
2453 (setq dir (funcall fix-name-func dir 'reverse)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2454 (puthash key dir ange-ftp-expand-dir-hashtable)))) |
28210 | 2455 |
2456 ;; In the special case of CMS make sure that know the | |
2457 ;; expansion of the home minidisk now, because we will | |
2458 ;; be doing a lot of cd's. | |
2459 (if (and (eq host-type 'cms) | |
2460 (not (ange-ftp-hash-entry-exists-p | |
2461 key ange-ftp-expand-dir-hashtable))) | |
2462 (let ((dir (car (ange-ftp-get-pwd host user)))) | |
2463 (if dir | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2464 (puthash key (concat "/" dir) ange-ftp-expand-dir-hashtable) |
28210 | 2465 (message "Warning! Unable to get home directory") |
2466 (sit-for 1)))))) | |
2467 | |
2468 | |
2469 ;;;; ------------------------------------------------------------ | |
2470 ;;;; Remote file and directory listing support. | |
2471 ;;;; ------------------------------------------------------------ | |
2472 | |
2473 ;; Returns whether HOST's FTP server doesn't like \'ls\' or \'dir\' commands | |
2474 ;; to take switch arguments. | |
2475 (defun ange-ftp-dumb-unix-host (host) | |
2476 (and host ange-ftp-dumb-unix-host-regexp | |
2477 (save-match-data | |
2478 (string-match ange-ftp-dumb-unix-host-regexp host)))) | |
2479 | |
2480 (defun ange-ftp-add-dumb-unix-host (host) | |
2481 "Interactively adds a given HOST to ange-ftp-dumb-unix-host-regexp." | |
2482 (interactive | |
2483 (list (read-string "Host: " | |
2484 (let ((name (or (buffer-file-name) default-directory))) | |
2485 (and name (car (ange-ftp-ftp-name name))))))) | |
2486 (if (not (ange-ftp-dumb-unix-host host)) | |
2487 (setq ange-ftp-dumb-unix-host-regexp | |
2488 (concat "^" (regexp-quote host) "$" | |
2489 (and ange-ftp-dumb-unix-host-regexp "\\|") | |
2490 ange-ftp-dumb-unix-host-regexp) | |
2491 ange-ftp-host-cache nil))) | |
2492 | |
2493 (defvar ange-ftp-parse-list-func-alist nil | |
2494 "Alist saying how to parse directory listings for certain OS types. | |
2495 Association list of \( TYPE \. FUNC \) pairs. The FUNC is a routine | |
2496 which can parse the output from a DIR listing for a host of type TYPE.") | |
2497 | |
2498 ;; With no-error nil, this function returns: | |
2499 ;; an error if file is not an ange-ftp-name | |
30459 | 2500 ;; (This should never happen.) |
28210 | 2501 ;; an error if either the listing is unreadable or there is an ftp error. |
2502 ;; the listing (a string), if everything works. | |
30459 | 2503 ;; |
28210 | 2504 ;; With no-error t, it returns: |
2505 ;; an error if not an ange-ftp-name | |
2506 ;; error if listing is unreadable (most likely caused by a slow connection) | |
2507 ;; nil if ftp error (this is because although asking to list a nonexistent | |
2508 ;; directory on a remote unix machine usually (except | |
2509 ;; maybe for dumb hosts) returns an ls error, but no | |
2510 ;; ftp error, if the same is done on a VMS machine, | |
2511 ;; an ftp error is returned. Need to trap the error | |
2512 ;; so we can go on and try to list the parent.) | |
2513 ;; the listing, if everything works. | |
2514 | |
2515 ;; If WILDCARD is non-nil, then this implements the guts of insert-directory | |
2516 ;; in the wildcard case. Then we make a relative directory listing | |
2517 ;; of FILE within the directory specified by `default-directory'. | |
2518 | |
2519 (defvar ange-ftp-before-parse-ls-hook nil | |
2520 "Normal hook run before parsing the text of an ftp directory listing.") | |
2521 | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2522 (defvar ange-ftp-after-parse-ls-hook nil |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2523 "Normal hook run after parsing the text of an ftp directory listing.") |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2524 |
28210 | 2525 (defun ange-ftp-ls (file lsargs parse &optional no-error wildcard) |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2526 "Return the output of a `DIR' or `ls' command done over ftp. |
28210 | 2527 FILE is the full name of the remote file, LSARGS is any args to pass to the |
2528 `ls' command, and PARSE specifies that the output should be parsed and stored | |
2529 away in the internal cache." | |
47575
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
2530 (when (string-match "^--dired\\s-+" lsargs) |
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
2531 (setq lsargs (replace-match "" nil t lsargs))) |
28210 | 2532 ;; If parse is t, we assume that file is a directory. i.e. we only parse |
2533 ;; full directory listings. | |
2534 (let* ((ange-ftp-this-file (ange-ftp-expand-file-name file)) | |
2535 (parsed (ange-ftp-ftp-name ange-ftp-this-file))) | |
2536 (if parsed | |
2537 (let* ((host (nth 0 parsed)) | |
2538 (user (nth 1 parsed)) | |
2539 (name (ange-ftp-quote-string (nth 2 parsed))) | |
2540 (key (directory-file-name ange-ftp-this-file)) | |
2541 (host-type (ange-ftp-host-type host user)) | |
2542 (dumb (memq host-type ange-ftp-dumb-host-types)) | |
2543 result | |
2544 temp | |
2545 lscmd parse-func) | |
2546 (if (string-equal name "") | |
2547 (setq name | |
2548 (ange-ftp-real-file-name-as-directory | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2549 (ange-ftp-expand-dir host user "~")))) |
28210 | 2550 (if (and ange-ftp-ls-cache-file |
2551 (string-equal key ange-ftp-ls-cache-file) | |
2552 ;; Don't care about lsargs for dumb hosts. | |
2553 (or dumb (string-equal lsargs ange-ftp-ls-cache-lsargs))) | |
2554 ange-ftp-ls-cache-res | |
2555 (setq temp (ange-ftp-make-tmp-name host)) | |
2556 (if wildcard | |
2557 (progn | |
2558 (ange-ftp-cd host user (file-name-directory name)) | |
2559 (setq lscmd (list 'dir file temp lsargs))) | |
2560 (setq lscmd (list 'dir name temp lsargs))) | |
2561 (unwind-protect | |
2562 (if (car (setq result (ange-ftp-send-cmd | |
2563 host | |
2564 user | |
2565 lscmd | |
2566 (format "Listing %s" | |
2567 (ange-ftp-abbreviate-filename | |
2568 ange-ftp-this-file))))) | |
2569 (save-excursion | |
2570 (set-buffer (get-buffer-create | |
2571 ange-ftp-data-buffer-name)) | |
2572 (erase-buffer) | |
2573 (if (ange-ftp-real-file-readable-p temp) | |
2574 (ange-ftp-real-insert-file-contents temp) | |
2575 (sleep-for ange-ftp-retry-time) | |
2576 ;wait for file to possibly appear | |
2577 (if (ange-ftp-real-file-readable-p temp) | |
2578 ;; Try again. | |
2579 (ange-ftp-real-insert-file-contents temp) | |
2580 (ange-ftp-error host user | |
2581 (format | |
2582 "list data file %s not readable" | |
2583 temp)))) | |
30518
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2584 ;; remove ^M inserted by the win32 ftp client |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2585 (while (re-search-forward "\r$" nil t) |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2586 (replace-match "")) |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2587 (goto-char 1) |
28210 | 2588 (run-hooks 'ange-ftp-before-parse-ls-hook) |
2589 (if parse | |
2590 (ange-ftp-set-files | |
2591 ange-ftp-this-file | |
2592 (if (setq | |
2593 parse-func | |
2594 (cdr (assq host-type | |
2595 ange-ftp-parse-list-func-alist))) | |
2596 (funcall parse-func) | |
2597 (ange-ftp-parse-dired-listing lsargs)))) | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2598 ;; Place this hook here to convert the contents of the |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2599 ;; buffer to a ls compatible format if the host system |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2600 ;; that is being queried is other than Unix i.e. VMS |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2601 ;; returns an ls format that really sucks. |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2602 (run-hooks 'ange-ftp-after-parse-ls-hook) |
28210 | 2603 (setq ange-ftp-ls-cache-file key |
2604 ange-ftp-ls-cache-lsargs lsargs | |
2605 ; For dumb hosts-types this is | |
2606 ; meaningless but harmless. | |
2607 ange-ftp-ls-cache-res (buffer-string)) | |
2608 ;; (kill-buffer (current-buffer)) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2609 (if (equal ange-ftp-ls-cache-res "total 0\n") |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2610 ;; wu-ftpd seems to return a successful result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2611 ;; with an empty file-listing when doing a |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2612 ;; `DIR /some/file/.' which leads ange-ftp to |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2613 ;; believe that /some/file is a directory ;-( |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2614 nil |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2615 ange-ftp-ls-cache-res)) |
28210 | 2616 (if no-error |
2617 nil | |
2618 (ange-ftp-error host user | |
2619 (concat "DIR failed: " (cdr result))))) | |
2620 (ange-ftp-del-tmp-name temp)))) | |
2621 (error "Should never happen. Please report. Bug ref. no.: 1")))) | |
2622 | |
2623 ;;;; ------------------------------------------------------------ | |
2624 ;;;; Directory information caching support. | |
2625 ;;;; ------------------------------------------------------------ | |
2626 | |
2627 (defconst ange-ftp-date-regexp | |
2628 (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)") | |
2629 ;; In some locales, month abbreviations are as short as 2 letters, | |
2630 ;; and they can be padded on the right with spaces. | |
2631 ;; weiand: changed: month ends with . or , or ., | |
2632 ;;old (month (concat l l "+ *")) | |
2633 (month (concat l l "+[.]?,? *")) | |
30459 | 2634 ;; Recognize any non-ASCII character. |
28210 | 2635 ;; The purpose is to match a Kanji character. |
2636 (k "[^\0-\177]") | |
2637 (s " ") | |
2638 (mm "[ 0-1][0-9]") | |
2639 ;; weiand: changed: day ends with . | |
2640 ;;old (dd "[ 0-3][0-9]") | |
2641 (dd "[ 0-3][0-9][.]?") | |
2642 (western (concat "\\(" month s dd "\\|" dd s month "\\)")) | |
2643 (japanese (concat mm k s dd k))) | |
2644 ;; Require the previous column to end in a digit. | |
2645 ;; This avoids recognizing `1 may 1997' as a date in the line: | |
2646 ;; -r--r--r-- 1 may 1997 1168 Oct 19 16:49 README | |
2647 (concat "[0-9]" s "\\(" western "\\|" japanese "\\)" s)) | |
2648 "Regular expression to match up to the column before the file name in a | |
2649 directory listing. This regular expression is designed to recognize dates | |
2650 regardless of the language.") | |
2651 | |
2652 (defvar ange-ftp-add-file-entry-alist nil | |
2653 "Alist saying how to add file entries on certain OS types. | |
2654 Association list of pairs \( TYPE \. FUNC \), where FUNC | |
2655 is a function to be used to add a file entry for the OS TYPE. The | |
2656 main reason for this alist is to deal with file versions in VMS.") | |
2657 | |
2658 (defvar ange-ftp-delete-file-entry-alist nil | |
2659 "Alist saying how to delete files on certain OS types. | |
2660 Association list of pairs \( TYPE \. FUNC \), where FUNC | |
2661 is a function to be used to delete a file entry for the OS TYPE. | |
2662 The main reason for this alist is to deal with file versions in VMS.") | |
2663 | |
2664 (defun ange-ftp-add-file-entry (name &optional dir-p) | |
2665 "Add a file entry for file NAME, if its directory info exists." | |
2666 (funcall (or (cdr (assq (ange-ftp-host-type | |
2667 (car (ange-ftp-ftp-name name))) | |
2668 ange-ftp-add-file-entry-alist)) | |
2669 'ange-ftp-internal-add-file-entry) | |
2670 name dir-p) | |
2671 (setq ange-ftp-ls-cache-file nil)) | |
2672 | |
2673 (defun ange-ftp-delete-file-entry (name &optional dir-p) | |
2674 "Delete the file entry for file NAME, if its directory info exists." | |
2675 (funcall (or (cdr (assq (ange-ftp-host-type | |
2676 (car (ange-ftp-ftp-name name))) | |
2677 ange-ftp-delete-file-entry-alist)) | |
2678 'ange-ftp-internal-delete-file-entry) | |
2679 name dir-p) | |
2680 (setq ange-ftp-ls-cache-file nil)) | |
2681 | |
2682 (defmacro ange-ftp-parse-filename () | |
2683 ;;Extract the filename from the current line of a dired-like listing. | |
30459 | 2684 `(let ((eol (progn (end-of-line) (point)))) |
2685 (beginning-of-line) | |
2686 (if (re-search-forward ange-ftp-date-regexp eol t) | |
2687 (progn | |
2688 (skip-chars-forward " ") | |
2689 (skip-chars-forward "^ " eol) | |
2690 (skip-chars-forward " " eol) | |
2691 ;; We bomb on filenames starting with a space. | |
2692 (buffer-substring (point) eol))))) | |
2693 | |
28210 | 2694 ;; This deals with the F switch. Should also do something about |
2695 ;; unquoting names obtained with the SysV b switch and the GNU Q | |
2696 ;; switch. See Sebastian's dired-get-filename. | |
2697 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2698 (defun ange-ftp-ls-parser (switches) |
28210 | 2699 ;; Meant to be called by ange-ftp-parse-dired-listing |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2700 (let ((tbl (make-hash-table :test 'equal)) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2701 (used-F (and (stringp switches) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2702 (string-match "F" switches))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2703 file-type symlink directory file) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2704 (while (setq file (ange-ftp-parse-filename)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2705 (beginning-of-line) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2706 (skip-chars-forward "\t 0-9") |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2707 (setq file-type (following-char) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2708 directory (eq file-type ?d)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2709 (if (eq file-type ?l) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2710 (let ((end (string-match " -> " file))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2711 (if end |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2712 ;; Sometimes `ls' appends a @ at the end of the target. |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2713 (setq symlink (substring file (match-end 0) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2714 (string-match "@\\'" file)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2715 file (substring file 0 end)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2716 ;; Shouldn't happen |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2717 (setq symlink ""))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2718 (setq symlink nil)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2719 ;; Only do a costly regexp search if the F switch was used. |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2720 (if (and used-F |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2721 (not (string-equal file "")) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2722 (looking-at |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2723 ".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)")) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2724 (let ((socket (eq file-type ?s)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2725 (executable |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2726 (and (not symlink) ; x bits don't mean a thing for symlinks |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2727 (string-match |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2728 "[xst]" |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2729 (concat (match-string 1) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2730 (match-string 2) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2731 (match-string 3)))))) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2732 ;; Some ls's with the F switch mark symlinks with an @ (ULTRIX) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2733 ;; and others don't. (sigh...) Beware, that some Unix's don't |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2734 ;; seem to believe in the F-switch |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2735 (if (or (and symlink (string-match "@$" file)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2736 (and directory (string-match "/$" file)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2737 (and executable (string-match "*$" file)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2738 (and socket (string-match "=$" file))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2739 (setq file (substring file 0 -1))))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2740 (puthash file (or symlink directory) tbl) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2741 (forward-line 1)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2742 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2743 (puthash ".." t tbl) |
30459 | 2744 tbl)) |
28210 | 2745 |
2746 ;;; The dl stuff for descriptive listings | |
2747 | |
2748 (defvar ange-ftp-dl-dir-regexp nil | |
2749 "Regexp matching directories which are listed in dl format. | |
2750 This regexp should not be anchored with a trailing `$', because it should | |
2751 match subdirectories as well.") | |
2752 | |
2753 (defun ange-ftp-add-dl-dir (dir) | |
2754 "Interactively adds a DIR to ange-ftp-dl-dir-regexp." | |
2755 (interactive | |
2756 (list (read-string "Directory: " | |
2757 (let ((name (or (buffer-file-name) default-directory))) | |
2758 (and name (ange-ftp-ftp-name name) | |
2759 (file-name-directory name)))))) | |
2760 (if (not (and ange-ftp-dl-dir-regexp | |
2761 (string-match ange-ftp-dl-dir-regexp dir))) | |
2762 (setq ange-ftp-dl-dir-regexp | |
2763 (concat "^" (regexp-quote dir) | |
2764 (and ange-ftp-dl-dir-regexp "\\|") | |
2765 ange-ftp-dl-dir-regexp)))) | |
2766 | |
2767 (defmacro ange-ftp-dl-parser () | |
2768 ;; Parse the current buffer, which is assumed to be a descriptive | |
2769 ;; listing, and return a hashtable. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2770 `(let ((tbl (make-hash-table :test 'equal))) |
30459 | 2771 (while (not (eobp)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2772 (puthash |
30459 | 2773 (buffer-substring (point) |
2774 (progn | |
2775 (skip-chars-forward "^ /\n") | |
2776 (point))) | |
2777 (eq (following-char) ?/) | |
2778 tbl) | |
2779 (forward-line 1)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2780 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2781 (puthash ".." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2782 tbl)) |
28210 | 2783 |
2784 ;; Parse the current buffer which is assumed to be in a dired-like listing | |
2785 ;; format, and return a hashtable as the result. If the listing is not really | |
2786 ;; a listing, then return nil. | |
2787 | |
2788 (defun ange-ftp-parse-dired-listing (&optional switches) | |
2789 (save-match-data | |
2790 (cond | |
2791 ((looking-at "^total [0-9]+$") | |
2792 (forward-line 1) | |
2793 ;; Some systems put in a blank line here. | |
2794 (if (eolp) (forward-line 1)) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2795 (ange-ftp-ls-parser switches)) |
28210 | 2796 ((looking-at "[^\n]+\\( not found\\|: Not a directory\\)\n\\'") |
2797 ;; It's an ls error message. | |
2798 nil) | |
2799 ((eobp) ; i.e. (zerop (buffer-size)) | |
2800 ;; This could be one of: | |
2801 ;; (1) An Ultrix ls error message | |
2802 ;; (2) A listing with the A switch of an empty directory | |
2803 ;; on a machine which doesn't give a total line. | |
2804 ;; (3) The twilight zone. | |
2805 ;; We'll assume (1) for now. | |
2806 nil) | |
2807 ((re-search-forward ange-ftp-date-regexp nil t) | |
2808 (beginning-of-line) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2809 (ange-ftp-ls-parser switches)) |
28210 | 2810 ((re-search-forward "^[^ \n\t]+ +\\([0-9]+\\|-\\|=\\) " nil t) |
2811 ;; It's a dl listing (I hope). | |
2812 ;; file is bound by the call to ange-ftp-ls | |
2813 (ange-ftp-add-dl-dir ange-ftp-this-file) | |
2814 (beginning-of-line) | |
2815 (ange-ftp-dl-parser)) | |
2816 (t nil)))) | |
2817 | |
2818 (defun ange-ftp-set-files (directory files) | |
2819 "For a given DIRECTORY, set or change the associated FILES hashtable." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2820 (and files (puthash (file-name-as-directory directory) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2821 files ange-ftp-files-hashtable))) |
28210 | 2822 |
2823 (defun ange-ftp-get-files (directory &optional no-error) | |
2824 "Given a given DIRECTORY, return a hashtable of file entries. | |
2825 This will give an error or return nil, depending on the value of | |
2826 NO-ERROR, if a listing for DIRECTORY cannot be obtained." | |
2827 (setq directory (file-name-as-directory directory)) ;normalize | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2828 (or (gethash directory ange-ftp-files-hashtable) |
28210 | 2829 (save-match-data |
2830 (and (ange-ftp-ls directory | |
2831 ;; This is an efficiency hack. We try to | |
2832 ;; anticipate what sort of listing dired | |
2833 ;; might want, and cache just such a listing. | |
2834 (if (and (boundp 'dired-actual-switches) | |
2835 (stringp dired-actual-switches) | |
2836 ;; We allow the A switch, which lists | |
2837 ;; all files except "." and "..". | |
2838 ;; This is OK because we manually | |
2839 ;; insert these entries | |
2840 ;; in the hash table. | |
2841 (string-match | |
2842 "[aA]" dired-actual-switches) | |
2843 (string-match | |
2844 "l" dired-actual-switches) | |
2845 (not (string-match | |
2846 "R" dired-actual-switches))) | |
2847 dired-actual-switches | |
2848 (if (and (boundp 'dired-listing-switches) | |
2849 (stringp dired-listing-switches) | |
2850 (string-match | |
2851 "[aA]" dired-listing-switches) | |
2852 (string-match | |
2853 "l" dired-listing-switches) | |
2854 (not (string-match | |
2855 "R" dired-listing-switches))) | |
2856 dired-listing-switches | |
2857 "-al")) | |
2858 t no-error) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2859 (gethash directory ange-ftp-files-hashtable))))) |
28210 | 2860 |
2861 ;; Given NAME, return the file part that can be used for looking up the | |
2862 ;; file's entry in a hashtable. | |
2863 (defmacro ange-ftp-get-file-part (name) | |
30459 | 2864 `(let ((file (file-name-nondirectory ,name))) |
2865 (if (string-equal file "") | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2866 "." |
30459 | 2867 file))) |
28210 | 2868 |
2869 ;; Return whether ange-ftp-file-entry-p and ange-ftp-get-file-entry are | |
2870 ;; allowed to determine if NAME is a sub-directory by listing it directly, | |
2871 ;; rather than listing its parent directory. This is used for efficiency so | |
2872 ;; that a wasted listing is not done: | |
2873 ;; 1. When looking for a .dired file in dired-x.el. | |
2874 ;; 2. The syntax of FILE and DIR make it impossible that FILE could be a valid | |
2875 ;; subdirectory. This is of course an OS dependent judgement. | |
2876 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2877 (defvar dired-local-variables-file) |
28210 | 2878 (defmacro ange-ftp-allow-child-lookup (dir file) |
45459
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2879 `(not |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2880 (let* ((efile ,file) ; expand once. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2881 (edir ,dir) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2882 (parsed (ange-ftp-ftp-name edir)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2883 (host-type (ange-ftp-host-type |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2884 (car parsed)))) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2885 (or |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2886 ;; Deal with dired |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2887 (and (boundp 'dired-local-variables-file) ; in the dired-x package |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2888 (stringp dired-local-variables-file) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2889 (string-equal dired-local-variables-file efile)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2890 ;; No dots in dir names in vms. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2891 (and (eq host-type 'vms) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2892 (string-match "\\." efile)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2893 ;; No subdirs in mts of cms. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2894 (and (memq host-type '(mts cms)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2895 (not (string-equal "/" (nth 2 parsed)))) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2896 ;; No dots in pseudo-dir names in bs2000. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2897 (and (eq host-type 'bs2000) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2898 (string-match "\\." efile)))))) |
28210 | 2899 |
2900 (defun ange-ftp-file-entry-p (name) | |
2901 "Given NAME, return whether there is a file entry for it." | |
2902 (let* ((name (directory-file-name name)) | |
2903 (dir (file-name-directory name)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2904 (ent (gethash dir ange-ftp-files-hashtable)) |
28210 | 2905 (file (ange-ftp-get-file-part name))) |
2906 (if ent | |
2907 (ange-ftp-hash-entry-exists-p file ent) | |
2908 (or (and (ange-ftp-allow-child-lookup dir file) | |
2909 (setq ent (ange-ftp-get-files name t)) | |
2910 ;; Try a child lookup. i.e. try to list file as a | |
2911 ;; subdirectory of dir. This is a good idea because | |
2912 ;; we may not have read permission for file's parent. Also, | |
2913 ;; people tend to work down directory trees anyway. We use | |
2914 ;; no-error ;; because if file does not exist as a subdir., | |
2915 ;; then dumb hosts will give an ftp error. Smart unix hosts | |
2916 ;; will simply send back the ls | |
2917 ;; error message. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2918 (gethash "." ent)) |
28210 | 2919 ;; Child lookup failed, so try the parent. |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2920 (let ((table (ange-ftp-get-files dir 'no-error))) |
28210 | 2921 ;; If the dir doesn't exist, don't use it as a hash table. |
2922 (and table | |
2923 (ange-ftp-hash-entry-exists-p file | |
2924 table))))))) | |
2925 | |
2926 (defun ange-ftp-get-file-entry (name) | |
2927 "Given NAME, return the given file entry. | |
2928 The entry will be either t for a directory, nil for a normal file, | |
2929 or a string for a symlink. If the file isn't in the hashtable, | |
2930 this also returns nil." | |
2931 (let* ((name (directory-file-name name)) | |
2932 (dir (file-name-directory name)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2933 (ent (gethash dir ange-ftp-files-hashtable)) |
28210 | 2934 (file (ange-ftp-get-file-part name))) |
2935 (if ent | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2936 (gethash file ent) |
28210 | 2937 (or (and (ange-ftp-allow-child-lookup dir file) |
2938 (setq ent (ange-ftp-get-files name t)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2939 (gethash "." ent)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2940 ;; i.e. it's a directory by child lookup |
49805
6e4a6658cec0
(ange-ftp-get-file-entry): Allow for graceful
David Kastrup <dak@gnu.org>
parents:
49598
diff
changeset
|
2941 (and (setq ent (ange-ftp-get-files dir t)) |
6e4a6658cec0
(ange-ftp-get-file-entry): Allow for graceful
David Kastrup <dak@gnu.org>
parents:
49598
diff
changeset
|
2942 (gethash file ent)))))) |
28210 | 2943 |
2944 (defun ange-ftp-internal-delete-file-entry (name &optional dir-p) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2945 (when dir-p |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2946 (setq name (file-name-as-directory name)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2947 (remhash name ange-ftp-files-hashtable) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2948 (setq name (directory-file-name name))) |
28210 | 2949 ;; Note that file-name-as-directory followed by directory-file-name |
2950 ;; serves to canonicalize directory file names to their unix form. | |
2951 ;; i.e. in VMS, FOO.DIR -> FOO/ -> FOO | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2952 (let ((files (gethash (file-name-directory name) ange-ftp-files-hashtable))) |
28210 | 2953 (if files |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2954 (remhash (ange-ftp-get-file-part name) files)))) |
28210 | 2955 |
2956 (defun ange-ftp-internal-add-file-entry (name &optional dir-p) | |
2957 (and dir-p | |
2958 (setq name (directory-file-name name))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2959 (let ((files (gethash (file-name-directory name) ange-ftp-files-hashtable))) |
28210 | 2960 (if files |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2961 (puthash (ange-ftp-get-file-part name) dir-p files)))) |
28210 | 2962 |
2963 (defun ange-ftp-wipe-file-entries (host user) | |
2964 "Get rid of entry for HOST, USER pair from file entry information hashtable." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2965 (let ((new-tbl (make-hash-table :test 'equal |
46892
6e8123be5cab
(ange-ftp-wipe-file-entries): Fix type mismatch;
David Kastrup <dak@gnu.org>
parents:
46811
diff
changeset
|
2966 :size (hash-table-size |
6e8123be5cab
(ange-ftp-wipe-file-entries): Fix type mismatch;
David Kastrup <dak@gnu.org>
parents:
46811
diff
changeset
|
2967 ange-ftp-files-hashtable)))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2968 (maphash |
30459 | 2969 (lambda (key val) |
2970 (let ((parsed (ange-ftp-ftp-name key))) | |
2971 (if parsed | |
2972 (let ((h (nth 0 parsed)) | |
2973 (u (nth 1 parsed))) | |
2974 (or (and (equal host h) (equal user u)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2975 (puthash key val new-tbl)))))) |
28210 | 2976 ange-ftp-files-hashtable) |
2977 (setq ange-ftp-files-hashtable new-tbl))) | |
2978 | |
2979 ;;;; ------------------------------------------------------------ | |
2980 ;;;; File transfer mode support. | |
2981 ;;;; ------------------------------------------------------------ | |
2982 | |
2983 (defun ange-ftp-set-binary-mode (host user) | |
2984 "Tell the ftp process for the given HOST & USER to switch to binary mode." | |
2985 (let ((result (ange-ftp-send-cmd host user '(type "binary")))) | |
2986 (if (not (car result)) | |
2987 (ange-ftp-error host user (concat "BINARY failed: " (cdr result))) | |
2988 (save-excursion | |
2989 (set-buffer (process-buffer (ange-ftp-get-process host user))) | |
2990 (and ange-ftp-binary-hash-mark-size | |
2991 (setq ange-ftp-hash-mark-unit | |
2992 (ash ange-ftp-binary-hash-mark-size -4))))))) | |
2993 | |
2994 (defun ange-ftp-set-ascii-mode (host user) | |
2995 "Tell the ftp process for the given HOST & USER to switch to ascii mode." | |
2996 (let ((result (ange-ftp-send-cmd host user '(type "ascii")))) | |
2997 (if (not (car result)) | |
2998 (ange-ftp-error host user (concat "ASCII failed: " (cdr result))) | |
2999 (save-excursion | |
3000 (set-buffer (process-buffer (ange-ftp-get-process host user))) | |
3001 (and ange-ftp-ascii-hash-mark-size | |
3002 (setq ange-ftp-hash-mark-unit | |
3003 (ash ange-ftp-ascii-hash-mark-size -4))))))) | |
3004 | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3005 (defun ange-ftp-cd (host user dir &optional noerror) |
28210 | 3006 (let ((result (ange-ftp-send-cmd host user (list 'cd dir) "Doing CD"))) |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3007 (if noerror result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3008 (or (car result) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3009 (ange-ftp-error host user (concat "CD failed: " (cdr result))))))) |
28210 | 3010 |
3011 (defun ange-ftp-get-pwd (host user) | |
3012 "Attempts to get the current working directory for the given HOST/USER pair. | |
3013 Returns \( DIR . LINE \) where DIR is either the directory or nil if not found, | |
3014 and LINE is the relevant success or fail line from the FTP-client." | |
3015 (let* ((result (ange-ftp-send-cmd host user '(pwd) "Getting PWD")) | |
3016 (line (cdr result)) | |
3017 dir) | |
3018 (if (car result) | |
3019 (save-match-data | |
3020 (and (or (string-match "\"\\([^\"]*\\)\"" line) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3021 (string-match " \\([^ ]+\\) " line)) ; stone-age VMS servers! |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3022 (setq dir (match-string 1 line))))) |
28210 | 3023 (cons dir line))) |
3024 | |
3025 ;;; ------------------------------------------------------------ | |
3026 ;;; expand-file-name and friends...which currently don't work | |
3027 ;;; ------------------------------------------------------------ | |
3028 | |
3029 (defun ange-ftp-expand-dir (host user dir) | |
3030 "Return the result of doing a PWD in the current FTP session. | |
3031 Use the connection to machine HOST | |
3032 logged in as user USER and cd'd to directory DIR." | |
3033 (let* ((host-type (ange-ftp-host-type host user)) | |
3034 ;; It is more efficient to call ange-ftp-host-type | |
3035 ;; before binding res, because ange-ftp-host-type sometimes | |
3036 ;; adds to the info in the expand-dir-hashtable. | |
3037 (fix-name-func | |
3038 (cdr (assq host-type ange-ftp-fix-name-func-alist))) | |
3039 (key (concat host "/" user "/" dir)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3040 (res (gethash key ange-ftp-expand-dir-hashtable))) |
28210 | 3041 (or res |
3042 (progn | |
3043 (or | |
3044 (string-equal user "anonymous") | |
3045 (string-equal user "ftp") | |
3046 (not (eq host-type 'unix)) | |
3047 (let* ((ange-ftp-good-msgs (concat ange-ftp-expand-dir-regexp | |
3048 "\\|" | |
3049 ange-ftp-good-msgs)) | |
3050 (result (ange-ftp-send-cmd host user | |
3051 (list 'get dir null-device) | |
3052 (format "expanding %s" dir))) | |
3053 (line (cdr result))) | |
3054 (setq res | |
3055 (if (string-match ange-ftp-expand-dir-regexp line) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3056 (match-string 1 line))))) |
28210 | 3057 (or res |
3058 (if (string-equal dir "~") | |
3059 (setq res (car (ange-ftp-get-pwd host user))) | |
3060 (let ((home (ange-ftp-expand-dir host user "~"))) | |
3061 (unwind-protect | |
3062 (and (ange-ftp-cd host user dir) | |
3063 (setq res (car (ange-ftp-get-pwd host user)))) | |
3064 (ange-ftp-cd host user home))))) | |
3065 (if res | |
3066 (let ((ange-ftp-this-user user) | |
3067 (ange-ftp-this-host host)) | |
3068 (if fix-name-func | |
3069 (setq res (funcall fix-name-func res 'reverse))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3070 (puthash key res ange-ftp-expand-dir-hashtable))) |
28210 | 3071 res)))) |
3072 | |
3073 (defun ange-ftp-canonize-filename (n) | |
3074 "Take a string and short-circuit //, /. and /.." | |
3075 (if (string-match "[^:]+//" n) ;don't upset Apollo users | |
3076 (setq n (substring n (1- (match-end 0))))) | |
3077 (let ((parsed (ange-ftp-ftp-name n))) | |
3078 (if parsed | |
3079 (let ((host (car parsed)) | |
3080 (user (nth 1 parsed)) | |
3081 (name (nth 2 parsed))) | |
30459 | 3082 |
28210 | 3083 ;; See if remote name is absolute. If so then just expand it and |
3084 ;; replace the name component of the overall name. | |
3085 (cond ((string-match "^/" name) | |
3086 name) | |
30459 | 3087 |
28210 | 3088 ;; Name starts with ~ or ~user. Resolve that part of the name |
3089 ;; making it absolute then re-expand it. | |
3090 ((string-match "^~[^/]*" name) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3091 (let* ((tilda (match-string 0 name)) |
28210 | 3092 (rest (substring name (match-end 0))) |
3093 (dir (ange-ftp-expand-dir host user tilda))) | |
3094 (if dir | |
42898
79af049b102e
(ange-ftp-canonize-filename): Avoid duplicate slash if DIR is just slash.
Richard M. Stallman <rms@gnu.org>
parents:
42891
diff
changeset
|
3095 (setq name (if (string-equal dir "/") |
79af049b102e
(ange-ftp-canonize-filename): Avoid duplicate slash if DIR is just slash.
Richard M. Stallman <rms@gnu.org>
parents:
42891
diff
changeset
|
3096 rest (concat dir rest))) |
30459 | 3097 (error "User \"%s\" is not known" |
28210 | 3098 (substring tilda 1))))) |
30459 | 3099 |
28210 | 3100 ;; relative name. Tack on homedir and re-expand. |
3101 (t | |
3102 (let ((dir (ange-ftp-expand-dir host user "~"))) | |
3103 (if dir | |
3104 (setq name (concat | |
3105 (ange-ftp-real-file-name-as-directory dir) | |
3106 name)) | |
3107 (error "Unable to obtain CWD"))))) | |
30459 | 3108 |
28210 | 3109 ;; If name starts with //, preserve that, for apollo system. |
3110 (if (not (string-match "^//" name)) | |
3111 (progn | |
3112 (if (not (eq system-type 'windows-nt)) | |
3113 (setq name (ange-ftp-real-expand-file-name name)) | |
3114 ;; Windows UNC default dirs do not make sense for ftp. | |
3115 (if (string-match "^//" default-directory) | |
3116 (setq name (ange-ftp-real-expand-file-name name "c:/")) | |
3117 (setq name (ange-ftp-real-expand-file-name name))) | |
3118 ;; Strip off possible drive specifier. | |
3119 (if (string-match "^[a-zA-Z]:" name) | |
3120 (setq name (substring name 2)))) | |
3121 (if (string-match "^//" name) | |
3122 (setq name (substring name 1))))) | |
30459 | 3123 |
28210 | 3124 ;; Now substitute the expanded name back into the overall filename. |
3125 (ange-ftp-replace-name-component n name)) | |
30459 | 3126 |
28210 | 3127 ;; non-ange-ftp name. Just expand normally. |
3128 (if (eq (string-to-char n) ?/) | |
3129 (ange-ftp-real-expand-file-name n) | |
3130 (ange-ftp-real-expand-file-name | |
3131 (ange-ftp-real-file-name-nondirectory n) | |
3132 (ange-ftp-real-file-name-directory n)))))) | |
3133 | |
3134 (defun ange-ftp-expand-file-name (name &optional default) | |
3135 "Documented as original." | |
3136 (save-match-data | |
3137 (setq default (or default default-directory)) | |
3138 (cond ((eq (string-to-char name) ?~) | |
3139 (ange-ftp-real-expand-file-name name)) | |
3140 ((eq (string-to-char name) ?/) | |
3141 (ange-ftp-canonize-filename name)) | |
3142 ((and (eq system-type 'windows-nt) | |
3143 (eq (string-to-char name) ?\\)) | |
3144 (ange-ftp-canonize-filename name)) | |
3145 ((and (eq system-type 'windows-nt) | |
3146 (or (string-match "^[a-zA-Z]:" name) | |
3147 (string-match "^[a-zA-Z]:" default))) | |
3148 (ange-ftp-real-expand-file-name name default)) | |
3149 ((zerop (length name)) | |
3150 (ange-ftp-canonize-filename default)) | |
3151 ((ange-ftp-canonize-filename | |
3152 (concat (file-name-as-directory default) name)))))) | |
3153 | |
3154 ;;; These are problems--they are currently not enabled. | |
3155 | |
3156 (defvar ange-ftp-file-name-as-directory-alist nil | |
3157 "Association list of \( TYPE \. FUNC \) pairs. | |
3158 FUNC converts a filename to a directory name for the operating | |
3159 system TYPE.") | |
3160 | |
3161 (defun ange-ftp-file-name-as-directory (name) | |
3162 "Documented as original." | |
3163 (let ((parsed (ange-ftp-ftp-name name))) | |
3164 (if parsed | |
3165 (if (string-equal (nth 2 parsed) "") | |
3166 name | |
3167 (funcall (or (cdr (assq | |
3168 (ange-ftp-host-type (car parsed)) | |
3169 ange-ftp-file-name-as-directory-alist)) | |
3170 'ange-ftp-real-file-name-as-directory) | |
3171 name)) | |
3172 (ange-ftp-real-file-name-as-directory name)))) | |
30459 | 3173 |
28210 | 3174 (defun ange-ftp-file-name-directory (name) |
3175 "Documented as original." | |
3176 (let ((parsed (ange-ftp-ftp-name name))) | |
3177 (if parsed | |
3178 (let ((filename (nth 2 parsed))) | |
3179 (if (save-match-data | |
3180 (string-match "^~[^/]*$" filename)) | |
3181 name | |
3182 (ange-ftp-replace-name-component | |
3183 name | |
3184 (ange-ftp-real-file-name-directory filename)))) | |
3185 (ange-ftp-real-file-name-directory name)))) | |
3186 | |
3187 (defun ange-ftp-file-name-nondirectory (name) | |
3188 "Documented as original." | |
3189 (let ((parsed (ange-ftp-ftp-name name))) | |
3190 (if parsed | |
3191 (let ((filename (nth 2 parsed))) | |
3192 (if (save-match-data | |
3193 (string-match "^~[^/]*$" filename)) | |
3194 "" | |
3195 (ange-ftp-real-file-name-nondirectory filename))) | |
3196 (ange-ftp-real-file-name-nondirectory name)))) | |
3197 | |
3198 (defun ange-ftp-directory-file-name (dir) | |
3199 "Documented as original." | |
3200 (let ((parsed (ange-ftp-ftp-name dir))) | |
3201 (if parsed | |
3202 (ange-ftp-replace-name-component | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3203 dir |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3204 (ange-ftp-real-directory-file-name (nth 2 parsed))) |
28210 | 3205 (ange-ftp-real-directory-file-name dir)))) |
3206 | |
3207 | |
3208 ;;; Hooks that handle Emacs primitives. | |
3209 | |
3210 ;; Returns non-nil if should transfer FILE in binary mode. | |
3211 (defun ange-ftp-binary-file (file) | |
3212 (save-match-data | |
3213 (string-match ange-ftp-binary-file-name-regexp file))) | |
3214 | |
3215 (defun ange-ftp-write-region (start end filename &optional append visit) | |
3216 (setq filename (expand-file-name filename)) | |
3217 (let ((parsed (ange-ftp-ftp-name filename))) | |
3218 (if parsed | |
3219 (let* ((host (nth 0 parsed)) | |
3220 (user (nth 1 parsed)) | |
3221 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3222 (temp (ange-ftp-make-tmp-name host)) | |
3223 ;; What we REALLY need here is a way to determine if the mode | |
3224 ;; of the transfer is irrelevant, i.e. we can use binary mode | |
3225 ;; regardless. Maybe a system-type to host-type lookup? | |
3226 (binary (or (ange-ftp-binary-file filename) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3227 (and (not (memq system-type |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3228 '(ms-dos windows-nt macos vax-vms))) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3229 (memq (ange-ftp-host-type host user) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3230 '(unix dumb-unix))))) |
28210 | 3231 (cmd (if append 'append 'put)) |
3232 (abbr (ange-ftp-abbreviate-filename filename)) | |
3233 ;; we need to reset `last-coding-system-used' to its | |
3234 ;; value immediately after calling the real write-region, | |
3235 ;; so that `basic-save-buffer' doesn't see whatever value | |
3236 ;; might be used when communicating with the ftp process. | |
3237 (coding-system-used last-coding-system-used)) | |
3238 (unwind-protect | |
3239 (progn | |
46336
af464c20ffb2
(ange-ftp-write-region): Don't bind executing-kbd-macro; instead, pass
Richard M. Stallman <rms@gnu.org>
parents:
46178
diff
changeset
|
3240 (let ((filename (buffer-file-name)) |
28210 | 3241 (mod-p (buffer-modified-p))) |
3242 (unwind-protect | |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3243 (progn |
46336
af464c20ffb2
(ange-ftp-write-region): Don't bind executing-kbd-macro; instead, pass
Richard M. Stallman <rms@gnu.org>
parents:
46178
diff
changeset
|
3244 (ange-ftp-real-write-region start end temp nil |
af464c20ffb2
(ange-ftp-write-region): Don't bind executing-kbd-macro; instead, pass
Richard M. Stallman <rms@gnu.org>
parents:
46178
diff
changeset
|
3245 (or visit 'quiet)) |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3246 (setq coding-system-used last-coding-system-used)) |
28210 | 3247 ;; cleanup forms |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3248 (setq coding-system-used last-coding-system-used) |
28210 | 3249 (setq buffer-file-name filename) |
3250 (set-buffer-modified-p mod-p))) | |
3251 (if binary | |
3252 (ange-ftp-set-binary-mode host user)) | |
3253 | |
3254 ;; tell the process filter what size the transfer will be. | |
3255 (let ((attr (file-attributes temp))) | |
3256 (if attr | |
3257 (ange-ftp-set-xfer-size host user (nth 7 attr)))) | |
3258 | |
3259 ;; put or append the file. | |
3260 (let ((result (ange-ftp-send-cmd host user | |
3261 (list cmd temp name) | |
3262 (format "Writing %s" abbr)))) | |
3263 (or (car result) | |
3264 (signal 'ftp-error | |
3265 (list | |
3266 "Opening output file" | |
3267 (format "FTP Error: \"%s\"" (cdr result)) | |
3268 filename))))) | |
3269 (ange-ftp-del-tmp-name temp) | |
30459 | 3270 (if binary |
28210 | 3271 (ange-ftp-set-ascii-mode host user))) |
3272 (if (eq visit t) | |
3273 (progn | |
30459 | 3274 (set-visited-file-modtime (ange-ftp-file-modtime filename)) |
28210 | 3275 (ange-ftp-set-buffer-mode) |
3276 (setq buffer-file-name filename) | |
3277 (set-buffer-modified-p nil))) | |
3278 ;; ensure `last-coding-system-used' has an appropriate value | |
3279 (setq last-coding-system-used coding-system-used) | |
3280 (ange-ftp-message "Wrote %s" abbr) | |
3281 (ange-ftp-add-file-entry filename)) | |
3282 (ange-ftp-real-write-region start end filename append visit)))) | |
3283 | |
3284 (defun ange-ftp-insert-file-contents (filename &optional visit beg end replace) | |
3285 (barf-if-buffer-read-only) | |
3286 (setq filename (expand-file-name filename)) | |
3287 (let ((parsed (ange-ftp-ftp-name filename))) | |
3288 (if parsed | |
3289 (progn | |
3290 (if visit | |
3291 (setq buffer-file-name filename)) | |
3292 (if (or (file-exists-p filename) | |
3293 (progn | |
3294 (setq ange-ftp-ls-cache-file nil) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3295 (remhash (file-name-directory filename) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3296 ange-ftp-files-hashtable) |
28210 | 3297 (file-exists-p filename))) |
3298 (let* ((host (nth 0 parsed)) | |
3299 (user (nth 1 parsed)) | |
3300 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3301 (temp (ange-ftp-make-tmp-name host)) | |
3302 (binary (or (ange-ftp-binary-file filename) | |
3303 (memq (ange-ftp-host-type host user) | |
3304 '(unix dumb-unix)))) | |
3305 (abbr (ange-ftp-abbreviate-filename filename)) | |
3306 (coding-system-used last-coding-system-used) | |
3307 size) | |
3308 (unwind-protect | |
3309 (progn | |
3310 (if binary | |
3311 (ange-ftp-set-binary-mode host user)) | |
3312 (let ((result (ange-ftp-send-cmd host user | |
3313 (list 'get name temp) | |
3314 (format "Retrieving %s" abbr)))) | |
3315 (or (car result) | |
3316 (signal 'ftp-error | |
3317 (list | |
3318 "Opening input file" | |
3319 (format "FTP Error: \"%s\"" (cdr result)) | |
3320 filename)))) | |
3321 (if (or (ange-ftp-real-file-readable-p temp) | |
3322 (sleep-for ange-ftp-retry-time) | |
3323 ;; Wait for file to hopefully appear. | |
3324 (ange-ftp-real-file-readable-p temp)) | |
3325 (setq | |
3326 size | |
3327 (nth 1 (ange-ftp-real-insert-file-contents | |
3328 temp visit beg end replace)) | |
3329 coding-system-used last-coding-system-used | |
3330 ;; override autodetection of buffer file type | |
3331 ;; to ensure buffer is saved in DOS format | |
3332 buffer-file-type binary) | |
3333 (signal 'ftp-error | |
3334 (list | |
3335 "Opening input file:" | |
3336 (format | |
3337 "FTP Error: %s not arrived or readable" | |
3338 filename))))) | |
3339 (if binary | |
3340 ;; We must keep `last-coding-system-used' | |
3341 ;; unchanged. | |
3342 (let (last-coding-system-used) | |
3343 (ange-ftp-set-ascii-mode host user))) | |
3344 (ange-ftp-del-tmp-name temp)) | |
3345 (if visit | |
3346 (progn | |
30459 | 3347 (set-visited-file-modtime |
3348 (ange-ftp-file-modtime filename)) | |
28210 | 3349 (setq buffer-file-name filename))) |
3350 (setq last-coding-system-used coding-system-used) | |
3351 (list filename size)) | |
3352 (signal 'file-error | |
30459 | 3353 (list |
28210 | 3354 "Opening input file" |
3355 filename)))) | |
3356 (ange-ftp-real-insert-file-contents filename visit beg end replace)))) | |
30459 | 3357 |
28210 | 3358 (defun ange-ftp-expand-symlink (file dir) |
50578
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3359 (let ((res (if (file-name-absolute-p file) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3360 (ange-ftp-replace-name-component dir file) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3361 (expand-file-name file dir)))) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3362 (if (file-symlink-p res) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3363 (ange-ftp-expand-symlink |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3364 (ange-ftp-get-file-entry res) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3365 (file-name-directory (directory-file-name res))) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3366 res))) |
28210 | 3367 |
3368 (defun ange-ftp-file-symlink-p (file) | |
3369 ;; call ange-ftp-expand-file-name rather than the normal | |
3370 ;; expand-file-name to stop loops when using a package that | |
3371 ;; redefines both file-symlink-p and expand-file-name. | |
3372 (setq file (ange-ftp-expand-file-name file)) | |
3373 (if (ange-ftp-ftp-name file) | |
51799
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3374 (condition-case nil |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3375 (let ((file-ent |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3376 (gethash |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3377 (ange-ftp-get-file-part file) |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3378 (ange-ftp-get-files (file-name-directory file))))) |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3379 (and (stringp file-ent) file-ent)) |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3380 ;; If we can't read the parent directory, just assume |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3381 ;; this file is not a symlink. |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3382 ;; This makes it possible to access a directory that |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3383 ;; whose parent is not readable. |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3384 (file-error nil)) |
28210 | 3385 (ange-ftp-real-file-symlink-p file))) |
3386 | |
3387 (defun ange-ftp-file-exists-p (name) | |
3388 (setq name (expand-file-name name)) | |
3389 (if (ange-ftp-ftp-name name) | |
3390 (if (ange-ftp-file-entry-p name) | |
3391 (let ((file-ent (ange-ftp-get-file-entry name))) | |
3392 (if (stringp file-ent) | |
3393 (file-exists-p | |
3394 (ange-ftp-expand-symlink file-ent | |
3395 (file-name-directory | |
3396 (directory-file-name name)))) | |
3397 t))) | |
3398 (ange-ftp-real-file-exists-p name))) | |
3399 | |
3400 (defun ange-ftp-file-directory-p (name) | |
3401 (setq name (expand-file-name name)) | |
3402 (if (ange-ftp-ftp-name name) | |
3403 ;; We do a file-name-as-directory on name here because some | |
3404 ;; machines (VMS) use a .DIR to indicate the filename associated | |
3405 ;; with a directory. This needs to be canonicalized. | |
3406 (let ((file-ent (ange-ftp-get-file-entry | |
3407 (ange-ftp-file-name-as-directory name)))) | |
3408 (if (stringp file-ent) | |
3409 (file-directory-p | |
3410 (ange-ftp-expand-symlink file-ent | |
3411 (file-name-directory | |
3412 (directory-file-name name)))) | |
3413 file-ent)) | |
3414 (ange-ftp-real-file-directory-p name))) | |
3415 | |
3416 (defun ange-ftp-directory-files (directory &optional full match | |
3417 &rest v19-args) | |
3418 (setq directory (expand-file-name directory)) | |
3419 (if (ange-ftp-ftp-name directory) | |
3420 (progn | |
3421 (ange-ftp-barf-if-not-directory directory) | |
3422 (let ((tail (ange-ftp-hash-table-keys | |
3423 (ange-ftp-get-files directory))) | |
3424 files f) | |
3425 (setq directory (file-name-as-directory directory)) | |
3426 (save-match-data | |
3427 (while tail | |
3428 (setq f (car tail) | |
3429 tail (cdr tail)) | |
3430 (if (or (not match) (string-match match f)) | |
3431 (setq files | |
3432 (cons (if full (concat directory f) f) files))))) | |
3433 (nreverse files))) | |
3434 (apply 'ange-ftp-real-directory-files directory full match v19-args))) | |
3435 | |
3436 (defun ange-ftp-file-attributes (file) | |
3437 (setq file (expand-file-name file)) | |
3438 (let ((parsed (ange-ftp-ftp-name file))) | |
3439 (if parsed | |
3440 (let ((part (ange-ftp-get-file-part file)) | |
3441 (files (ange-ftp-get-files (file-name-directory file)))) | |
3442 (if (ange-ftp-hash-entry-exists-p part files) | |
3443 (let ((host (nth 0 parsed)) | |
3444 (user (nth 1 parsed)) | |
3445 (name (nth 2 parsed)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3446 (dirp (gethash part files)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3447 (inode (gethash file ange-ftp-inodes-hashtable))) |
28210 | 3448 (unless inode |
3449 (setq inode ange-ftp-next-inode-number | |
3450 ange-ftp-next-inode-number (1+ inode)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3451 (puthash file inode ange-ftp-inodes-hashtable)) |
28210 | 3452 (list (if (and (stringp dirp) (file-name-absolute-p dirp)) |
3453 (ange-ftp-expand-symlink dirp | |
3454 (file-name-directory file)) | |
3455 dirp) ;0 file type | |
3456 -1 ;1 link count | |
3457 -1 ;2 uid | |
3458 -1 ;3 gid | |
3459 '(0 0) ;4 atime | |
30459 | 3460 (ange-ftp-file-modtime file) ;5 mtime |
28210 | 3461 '(0 0) ;6 ctime |
3462 -1 ;7 size | |
3463 (concat (if (stringp dirp) "l" (if dirp "d" "-")) | |
3464 "?????????") ;8 mode | |
3465 nil ;9 gid weird | |
3466 inode ;10 "inode number". | |
3467 -1 ;11 device number [v19 only] | |
3468 )))) | |
3469 (ange-ftp-real-file-attributes file)))) | |
3470 | |
30481 | 3471 (defun ange-ftp-file-newer-than-file-p (f1 f2) |
3472 (let ((f1-parsed (ange-ftp-ftp-name f1)) | |
3473 (f2-parsed (ange-ftp-ftp-name f2))) | |
3474 (if (or f1-parsed f2-parsed) | |
3475 (let ((f1-mt (nth 5 (file-attributes f1))) | |
3476 (f2-mt (nth 5 (file-attributes f2)))) | |
3477 (cond ((null f1-mt) nil) | |
3478 ((null f2-mt) t) | |
3479 (t (> (float-time f1-mt) (float-time f2-mt))))) | |
3480 (ange-ftp-real-file-newer-than-file-p f1 f2)))) | |
3481 | |
28210 | 3482 (defun ange-ftp-file-writable-p (file) |
33533 | 3483 (let ((ange-ftp-process-verbose nil)) |
3484 (setq file (expand-file-name file)) | |
3485 (if (ange-ftp-ftp-name file) | |
3486 (or (file-exists-p file) ;guess here for speed | |
3487 (file-directory-p (file-name-directory file))) | |
3488 (ange-ftp-real-file-writable-p file)))) | |
28210 | 3489 |
3490 (defun ange-ftp-file-readable-p (file) | |
33533 | 3491 (let ((ange-ftp-process-verbose nil)) |
3492 (setq file (expand-file-name file)) | |
3493 (if (ange-ftp-ftp-name file) | |
3494 (file-exists-p file) | |
3495 (ange-ftp-real-file-readable-p file)))) | |
28210 | 3496 |
3497 (defun ange-ftp-file-executable-p (file) | |
33533 | 3498 (let ((ange-ftp-process-verbose nil)) |
3499 (setq file (expand-file-name file)) | |
3500 (if (ange-ftp-ftp-name file) | |
3501 (file-exists-p file) | |
3502 (ange-ftp-real-file-executable-p file)))) | |
28210 | 3503 |
3504 (defun ange-ftp-delete-file (file) | |
3505 (interactive "fDelete file: ") | |
3506 (setq file (expand-file-name file)) | |
3507 (let ((parsed (ange-ftp-ftp-name file))) | |
3508 (if parsed | |
3509 (let* ((host (nth 0 parsed)) | |
3510 (user (nth 1 parsed)) | |
3511 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3512 (abbr (ange-ftp-abbreviate-filename file)) | |
3513 (result (ange-ftp-send-cmd host user | |
3514 (list 'delete name) | |
3515 (format "Deleting %s" abbr)))) | |
3516 (or (car result) | |
3517 (signal 'ftp-error | |
3518 (list | |
3519 "Removing old name" | |
3520 (format "FTP Error: \"%s\"" (cdr result)) | |
3521 file))) | |
3522 (ange-ftp-delete-file-entry file)) | |
3523 (ange-ftp-real-delete-file file)))) | |
3524 | |
30459 | 3525 (defun ange-ftp-file-modtime (file) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3526 "Return the modification time of remote file FILE. |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3527 Value is (0 0) if the modification time cannot be determined." |
30459 | 3528 (let* ((parsed (ange-ftp-ftp-name file)) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3529 ;; At least one FTP server (wu-ftpd) can return a "226 |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3530 ;; Transfer complete" before the "213 MODTIME". Let's skip |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3531 ;; that. |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3532 (ange-ftp-skip-msgs (concat ange-ftp-skip-msgs "\\|^226")) |
30459 | 3533 (res (ange-ftp-send-cmd (car parsed) (cadr parsed) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3534 (list 'quote "mdtm" (cadr (cdr parsed))))) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3535 (line (cdr res)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3536 (modtime '(0 0))) |
38328
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3537 ;; MDTM should return "213 YYYYMMDDhhmmss" GMT on success |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3538 ;; following the Internet draft for FTP extensions. |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3539 ;; Bob@rattlesnake.com reports that is returns something different |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3540 ;; for at least one FTP server. So, let's use the response only |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3541 ;; if it matches the Internet draft. |
42251
d2e8e0db6666
(ange-ftp-file-modtime): Use save-match-data.
Richard M. Stallman <rms@gnu.org>
parents:
40361
diff
changeset
|
3542 (when (save-match-data (string-match "^213 [0-9]\\{14\\}$" line)) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3543 (setq modtime |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3544 (encode-time |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3545 (string-to-number (substring line 16 18)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3546 (string-to-number (substring line 14 16)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3547 (string-to-number (substring line 12 14)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3548 (string-to-number (substring line 10 12)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3549 (string-to-number (substring line 8 10)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3550 (string-to-number (substring line 4 8)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3551 0))) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3552 modtime)) |
30459 | 3553 |
28210 | 3554 (defun ange-ftp-verify-visited-file-modtime (buf) |
3555 (let ((name (buffer-file-name buf))) | |
3556 (if (and (stringp name) (ange-ftp-ftp-name name)) | |
30459 | 3557 (let ((file-mdtm (ange-ftp-file-modtime name)) |
3558 (buf-mdtm (with-current-buffer buf (visited-file-modtime)))) | |
3559 (or (zerop (car file-mdtm)) | |
30518
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
3560 (<= (float-time file-mdtm) (float-time buf-mdtm)))) |
28210 | 3561 (ange-ftp-real-verify-visited-file-modtime buf)))) |
3562 | |
3563 ;;;; ------------------------------------------------------------ | |
3564 ;;;; File copying support... totally re-written 6/24/92. | |
3565 ;;;; ------------------------------------------------------------ | |
3566 | |
3567 (defun ange-ftp-barf-or-query-if-file-exists (absname querystring interactive) | |
3568 (if (file-exists-p absname) | |
3569 (if (not interactive) | |
3570 (signal 'file-already-exists (list absname)) | |
3571 (if (not (yes-or-no-p (format "File %s already exists; %s anyway? " | |
3572 absname querystring))) | |
3573 (signal 'file-already-exists (list absname)))))) | |
3574 | |
3575 ;; async local copy commented out for now since I don't seem to get | |
3576 ;; the process sentinel called for some processes. | |
3577 ;; | |
3578 ;; (defun ange-ftp-copy-file-locally (filename newname ok-if-already-exists | |
3579 ;; keep-date cont) | |
3580 ;; "Kludge to copy a local file and call a continuation when the copy | |
3581 ;; finishes." | |
3582 ;; ;; check to see if we can overwrite | |
3583 ;; (if (or (not ok-if-already-exists) | |
3584 ;; (numberp ok-if-already-exists)) | |
30459 | 3585 ;; (ange-ftp-barf-or-query-if-file-exists newname "copy to it" |
28210 | 3586 ;; (numberp ok-if-already-exists))) |
3587 ;; (let ((proc (start-process " *copy*" | |
3588 ;; (generate-new-buffer "*copy*") | |
3589 ;; "cp" | |
3590 ;; filename | |
3591 ;; newname)) | |
3592 ;; res) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3593 ;; (set-process-sentinel proc 'ange-ftp-copy-file-locally-sentinel) |
28210 | 3594 ;; (process-kill-without-query proc) |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3595 ;; (with-current-buffer (process-buffer proc) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3596 ;; (set (make-local-variable 'copy-cont) cont)))) |
30459 | 3597 ;; |
28210 | 3598 ;; (defun ange-ftp-copy-file-locally-sentinel (proc status) |
3599 ;; (save-excursion | |
3600 ;; (set-buffer (process-buffer proc)) | |
3601 ;; (let ((cont copy-cont) | |
3602 ;; (result (buffer-string))) | |
3603 ;; (unwind-protect | |
3604 ;; (if (and (string-equal status "finished\n") | |
3605 ;; (zerop (length result))) | |
3606 ;; (ange-ftp-call-cont cont t nil) | |
3607 ;; (ange-ftp-call-cont cont | |
3608 ;; nil | |
3609 ;; (if (zerop (length result)) | |
3610 ;; (substring status 0 -1) | |
3611 ;; (substring result 0 -1)))) | |
3612 ;; (kill-buffer (current-buffer)))))) | |
3613 | |
3614 ;; this is the extended version of ange-ftp-copy-file-internal that works | |
3615 ;; asynchronously if asked nicely. | |
3616 (defun ange-ftp-copy-file-internal (filename newname ok-if-already-exists | |
3617 keep-date &optional msg cont nowait) | |
3618 (setq filename (expand-file-name filename) | |
3619 newname (expand-file-name newname)) | |
3620 | |
3621 ;; canonicalize newname if a directory. | |
3622 (if (file-directory-p newname) | |
3623 (setq newname (expand-file-name (file-name-nondirectory filename) newname))) | |
3624 | |
3625 (let ((f-parsed (ange-ftp-ftp-name filename)) | |
3626 (t-parsed (ange-ftp-ftp-name newname))) | |
3627 | |
3628 ;; local file to local file copy? | |
3629 (if (and (not f-parsed) (not t-parsed)) | |
3630 (progn | |
3631 (ange-ftp-real-copy-file filename newname ok-if-already-exists | |
3632 keep-date) | |
3633 (if cont | |
3634 (ange-ftp-call-cont cont t "Copied locally"))) | |
3635 ;; one or both files are remote. | |
3636 (let* ((f-host (and f-parsed (nth 0 f-parsed))) | |
3637 (f-user (and f-parsed (nth 1 f-parsed))) | |
3638 (f-name (and f-parsed (ange-ftp-quote-string (nth 2 f-parsed)))) | |
3639 (f-abbr (ange-ftp-abbreviate-filename filename)) | |
3640 (t-host (and t-parsed (nth 0 t-parsed))) | |
3641 (t-user (and t-parsed (nth 1 t-parsed))) | |
3642 (t-name (and t-parsed (ange-ftp-quote-string (nth 2 t-parsed)))) | |
3643 (t-abbr (ange-ftp-abbreviate-filename newname filename)) | |
3644 (binary (or (ange-ftp-binary-file filename) | |
3645 (ange-ftp-binary-file newname) | |
3646 (and (memq (ange-ftp-host-type f-host f-user) | |
3647 '(unix dumb-unix)) | |
3648 (memq (ange-ftp-host-type t-host t-user) | |
3649 '(unix dumb-unix))))) | |
3650 temp1 | |
3651 temp2) | |
3652 | |
3653 ;; check to see if we can overwrite | |
3654 (if (or (not ok-if-already-exists) | |
3655 (numberp ok-if-already-exists)) | |
30459 | 3656 (ange-ftp-barf-or-query-if-file-exists newname "copy to it" |
28210 | 3657 (numberp ok-if-already-exists))) |
3658 | |
3659 ;; do the copying. | |
3660 (if f-parsed | |
30459 | 3661 |
28210 | 3662 ;; filename was remote. |
3663 (progn | |
3664 (if (or (ange-ftp-use-gateway-p f-host) | |
3665 t-parsed) | |
3666 ;; have to use intermediate file if we are getting via | |
3667 ;; gateway machine or we are doing a remote to remote copy. | |
3668 (setq temp1 (ange-ftp-make-tmp-name f-host))) | |
30459 | 3669 |
28210 | 3670 (if binary |
3671 (ange-ftp-set-binary-mode f-host f-user)) | |
3672 | |
3673 (ange-ftp-send-cmd | |
3674 f-host | |
3675 f-user | |
3676 (list 'get f-name (or temp1 (ange-ftp-quote-string newname))) | |
3677 (or msg | |
3678 (if (and temp1 t-parsed) | |
3679 (format "Getting %s" f-abbr) | |
3680 (format "Copying %s to %s" f-abbr t-abbr))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3681 (list 'ange-ftp-cf1 |
28210 | 3682 filename newname binary msg |
3683 f-parsed f-host f-user f-name f-abbr | |
3684 t-parsed t-host t-user t-name t-abbr | |
3685 temp1 temp2 cont nowait) | |
3686 nowait)) | |
3687 | |
3688 ;; filename wasn't remote. newname must be remote. call the | |
3689 ;; function which does the remainder of the copying work. | |
3690 (ange-ftp-cf1 t nil | |
3691 filename newname binary msg | |
3692 f-parsed f-host f-user f-name f-abbr | |
3693 t-parsed t-host t-user t-name t-abbr | |
3694 nil nil cont nowait)))))) | |
3695 | |
3696 (defvar ange-ftp-waiting-flag nil) | |
3697 | |
3698 ;; next part of copying routine. | |
3699 (defun ange-ftp-cf1 (result line | |
3700 filename newname binary msg | |
3701 f-parsed f-host f-user f-name f-abbr | |
3702 t-parsed t-host t-user t-name t-abbr | |
3703 temp1 temp2 cont nowait) | |
3704 (if line | |
3705 ;; filename must have been remote, and we must have just done a GET. | |
3706 (unwind-protect | |
3707 (or result | |
3708 ;; GET failed for some reason. Clean up and get out. | |
3709 (progn | |
3710 (and temp1 (ange-ftp-del-tmp-name temp1)) | |
3711 (or cont | |
3712 (if ange-ftp-waiting-flag | |
3713 (throw 'ftp-error t) | |
3714 (signal 'ftp-error | |
3715 (list "Opening input file" | |
3716 (format "FTP Error: \"%s\"" line) | |
3717 filename)))))) | |
3718 ;; cleanup | |
3719 (if binary | |
3720 (ange-ftp-set-ascii-mode f-host f-user)))) | |
3721 | |
3722 (if result | |
3723 ;; We now have to copy either temp1 or filename to newname. | |
3724 (if t-parsed | |
30459 | 3725 |
28210 | 3726 ;; newname was remote. |
3727 (progn | |
3728 (if (ange-ftp-use-gateway-p t-host) | |
3729 (setq temp2 (ange-ftp-make-tmp-name t-host))) | |
30459 | 3730 |
28210 | 3731 ;; make sure data is moved into the right place for the |
3732 ;; outgoing transfer. gateway temporary files complicate | |
3733 ;; things nicely. | |
3734 (if temp1 | |
3735 (if temp2 | |
3736 (if (string-equal temp1 temp2) | |
3737 (setq temp1 nil) | |
3738 (ange-ftp-real-copy-file temp1 temp2 t)) | |
3739 (setq temp2 temp1 temp1 nil)) | |
3740 (if temp2 | |
3741 (ange-ftp-real-copy-file filename temp2 t))) | |
30459 | 3742 |
28210 | 3743 (if binary |
3744 (ange-ftp-set-binary-mode t-host t-user)) | |
3745 | |
3746 ;; tell the process filter what size the file is. | |
3747 (let ((attr (file-attributes (or temp2 filename)))) | |
3748 (if attr | |
3749 (ange-ftp-set-xfer-size t-host t-user (nth 7 attr)))) | |
3750 | |
3751 (ange-ftp-send-cmd | |
3752 t-host | |
3753 t-user | |
3754 (list 'put (or temp2 filename) t-name) | |
3755 (or msg | |
3756 (if (and temp2 f-parsed) | |
3757 (format "Putting %s" newname) | |
3758 (format "Copying %s to %s" f-abbr t-abbr))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3759 (list 'ange-ftp-cf2 |
28210 | 3760 newname t-host t-user binary temp1 temp2 cont) |
3761 nowait)) | |
30459 | 3762 |
28210 | 3763 ;; newname wasn't remote. |
3764 (ange-ftp-cf2 t nil newname t-host t-user binary temp1 temp2 cont)) | |
3765 | |
3766 ;; first copy failed, tell caller | |
3767 (ange-ftp-call-cont cont result line))) | |
3768 | |
3769 ;; last part of copying routine. | |
3770 (defun ange-ftp-cf2 (result line newname t-host t-user binary temp1 temp2 cont) | |
3771 (unwind-protect | |
3772 (if line | |
3773 ;; result from doing a local to remote copy. | |
3774 (unwind-protect | |
3775 (progn | |
3776 (or result | |
3777 (or cont | |
3778 (if ange-ftp-waiting-flag | |
3779 (throw 'ftp-error t) | |
3780 (signal 'ftp-error | |
3781 (list "Opening output file" | |
3782 (format "FTP Error: \"%s\"" line) | |
3783 newname))))) | |
30459 | 3784 |
28210 | 3785 (ange-ftp-add-file-entry newname)) |
30459 | 3786 |
28210 | 3787 ;; cleanup. |
3788 (if binary | |
3789 (ange-ftp-set-ascii-mode t-host t-user))) | |
30459 | 3790 |
28210 | 3791 ;; newname was local. |
3792 (if temp1 | |
3793 (ange-ftp-real-copy-file temp1 newname t))) | |
30459 | 3794 |
28210 | 3795 ;; clean up |
3796 (and temp1 (ange-ftp-del-tmp-name temp1)) | |
3797 (and temp2 (ange-ftp-del-tmp-name temp2)) | |
3798 (ange-ftp-call-cont cont result line))) | |
3799 | |
3800 (defun ange-ftp-copy-file (filename newname &optional ok-if-already-exists | |
3801 keep-date) | |
3802 (interactive "fCopy file: \nFCopy %s to file: \np") | |
3803 (ange-ftp-copy-file-internal filename | |
3804 newname | |
3805 ok-if-already-exists | |
3806 keep-date | |
3807 nil | |
3808 nil | |
3809 (interactive-p))) | |
39839
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3810 |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3811 (defun ange-ftp-copy-files-async (okay-p line verbose-p files) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3812 "Copy some files in the background. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3813 Arguments: (OKAY-P LINE VERBOSE-P FILES) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3814 OKAY-P must be T, and LINE does not matter. They are here to make this |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3815 function a valid CONT argument for `ange-ftp-raw-send-cmd'. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3816 If VERBOSE-P is non-nil, print progress report in the echo area. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3817 When all the files have been copied already, a message is shown anyway. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3818 FILES is a list of files to copy in the form |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3819 (from-file to-file ok-if-already-exists keep-date) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3820 E.g., |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3821 (ange-ftp-copy-files-async t nil t '((\"a\" \"b\" t t) (\"c\" \"d\" t t)))" |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3822 (unless okay-p (error "%s: %s" 'ange-ftp-copy-files-async line)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3823 (if files |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3824 (let* ((ff (car files)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3825 (from-file (nth 0 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3826 (to-file (nth 1 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3827 (ok-if-exists (nth 2 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3828 (keep-date (nth 3 ff))) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3829 (ange-ftp-copy-file-internal |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3830 from-file to-file ok-if-exists keep-date |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3831 (and verbose-p (format "%s --> %s" from-file to-file)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3832 (list 'ange-ftp-copy-files-async verbose-p (cdr files)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3833 t)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3834 (message "%s: done" 'ange-ftp-copy-files-async))) |
39839
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3835 |
28210 | 3836 |
3837 ;;;; ------------------------------------------------------------ | |
3838 ;;;; File renaming support. | |
3839 ;;;; ------------------------------------------------------------ | |
3840 | |
3841 (defun ange-ftp-rename-remote-to-remote (filename newname f-parsed t-parsed) | |
3842 "Rename remote file FILE to remote file NEWNAME." | |
3843 (let ((f-host (nth 0 f-parsed)) | |
3844 (f-user (nth 1 f-parsed)) | |
3845 (t-host (nth 0 t-parsed)) | |
3846 (t-user (nth 1 t-parsed))) | |
3847 (if (and (string-equal f-host t-host) | |
3848 (string-equal f-user t-user)) | |
3849 (let* ((f-name (ange-ftp-quote-string (nth 2 f-parsed))) | |
3850 (t-name (ange-ftp-quote-string (nth 2 t-parsed))) | |
3851 (cmd (list 'rename f-name t-name)) | |
3852 (fabbr (ange-ftp-abbreviate-filename filename)) | |
3853 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3854 (result (ange-ftp-send-cmd f-host f-user cmd | |
3855 (format "Renaming %s to %s" | |
3856 fabbr | |
3857 nabbr)))) | |
3858 (or (car result) | |
3859 (signal 'ftp-error | |
3860 (list | |
3861 "Renaming" | |
3862 (format "FTP Error: \"%s\"" (cdr result)) | |
3863 filename | |
3864 newname))) | |
3865 (ange-ftp-add-file-entry newname) | |
3866 (ange-ftp-delete-file-entry filename)) | |
3867 (ange-ftp-copy-file-internal filename newname t nil) | |
3868 (delete-file filename)))) | |
3869 | |
3870 (defun ange-ftp-rename-local-to-remote (filename newname) | |
3871 "Rename local FILENAME to remote file NEWNAME." | |
3872 (let* ((fabbr (ange-ftp-abbreviate-filename filename)) | |
3873 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3874 (msg (format "Renaming %s to %s" fabbr nabbr))) | |
3875 (ange-ftp-copy-file-internal filename newname t nil msg) | |
3876 (let (ange-ftp-process-verbose) | |
3877 (delete-file filename)))) | |
3878 | |
3879 (defun ange-ftp-rename-remote-to-local (filename newname) | |
3880 "Rename remote file FILENAME to local file NEWNAME." | |
3881 (let* ((fabbr (ange-ftp-abbreviate-filename filename)) | |
3882 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3883 (msg (format "Renaming %s to %s" fabbr nabbr))) | |
3884 (ange-ftp-copy-file-internal filename newname t nil msg) | |
3885 (let (ange-ftp-process-verbose) | |
3886 (delete-file filename)))) | |
3887 | |
3888 (defun ange-ftp-rename-file (filename newname &optional ok-if-already-exists) | |
3889 (interactive "fRename file: \nFRename %s to file: \np") | |
3890 (setq filename (expand-file-name filename)) | |
3891 (setq newname (expand-file-name newname)) | |
3892 (let* ((f-parsed (ange-ftp-ftp-name filename)) | |
3893 (t-parsed (ange-ftp-ftp-name newname))) | |
3894 (if (and (or f-parsed t-parsed) | |
3895 (or (not ok-if-already-exists) | |
3896 (numberp ok-if-already-exists))) | |
3897 (ange-ftp-barf-or-query-if-file-exists | |
3898 newname | |
3899 "rename to it" | |
3900 (numberp ok-if-already-exists))) | |
3901 (if f-parsed | |
3902 (if t-parsed | |
3903 (ange-ftp-rename-remote-to-remote filename newname f-parsed | |
3904 t-parsed) | |
3905 (ange-ftp-rename-remote-to-local filename newname)) | |
3906 (if t-parsed | |
3907 (ange-ftp-rename-local-to-remote filename newname) | |
3908 (ange-ftp-real-rename-file filename newname ok-if-already-exists))))) | |
3909 | |
3910 ;;;; ------------------------------------------------------------ | |
3911 ;;;; File name completion support. | |
3912 ;;;; ------------------------------------------------------------ | |
3913 | |
3914 ;; If the file entry is not a directory (nor a symlink pointing to a directory) | |
3915 ;; returns whether the file (or file pointed to by the symlink) is ignored | |
3916 ;; by completion-ignored-extensions. | |
3917 ;; Note that `ange-ftp-this-dir' and `ange-ftp-completion-ignored-pattern' | |
3918 ;; are used as free variables. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3919 (defun ange-ftp-file-entry-not-ignored-p (symname val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3920 (if (stringp val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3921 (let ((file (ange-ftp-expand-symlink val ange-ftp-this-dir))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3922 (or (file-directory-p file) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3923 (and (file-exists-p file) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3924 (not (string-match ange-ftp-completion-ignored-pattern |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3925 symname))))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3926 (or val ; is a directory name |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3927 (not (string-match ange-ftp-completion-ignored-pattern symname))))) |
28210 | 3928 |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3929 (defun ange-ftp-root-dir-p (dir) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3930 ;; Maybe we should use something more like |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3931 ;; (equal dir (file-name-directory (directory-file-name dir))) -stef |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3932 (or (and (eq system-type 'windows-nt) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3933 (string-match "^[a-zA-Z]:[/\\]$" dir)) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3934 (string-equal "/" dir))) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3935 |
28210 | 3936 (defun ange-ftp-file-name-all-completions (file dir) |
3937 (let ((ange-ftp-this-dir (expand-file-name dir))) | |
3938 (if (ange-ftp-ftp-name ange-ftp-this-dir) | |
3939 (progn | |
3940 (ange-ftp-barf-if-not-directory ange-ftp-this-dir) | |
3941 (setq ange-ftp-this-dir | |
3942 (ange-ftp-real-file-name-as-directory ange-ftp-this-dir)) | |
3943 (let* ((tbl (ange-ftp-get-files ange-ftp-this-dir)) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3944 (completions (all-completions file tbl))) |
28210 | 3945 |
3946 ;; see whether each matching file is a directory or not... | |
3947 (mapcar | |
30459 | 3948 (lambda (file) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3949 (let ((ent (gethash file tbl))) |
30459 | 3950 (if (and ent |
3951 (or (not (stringp ent)) | |
3952 (file-directory-p | |
3953 (ange-ftp-expand-symlink ent | |
3954 ange-ftp-this-dir)))) | |
3955 (concat file "/") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3956 file))) |
28210 | 3957 completions))) |
3958 | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3959 (if (ange-ftp-root-dir-p ange-ftp-this-dir) |
28210 | 3960 (nconc (all-completions file (ange-ftp-generate-root-prefixes)) |
3961 (ange-ftp-real-file-name-all-completions file | |
3962 ange-ftp-this-dir)) | |
3963 (ange-ftp-real-file-name-all-completions file ange-ftp-this-dir))))) | |
3964 | |
3965 (defun ange-ftp-file-name-completion (file dir) | |
3966 (let ((ange-ftp-this-dir (expand-file-name dir))) | |
3967 (if (ange-ftp-ftp-name ange-ftp-this-dir) | |
3968 (progn | |
3969 (ange-ftp-barf-if-not-directory ange-ftp-this-dir) | |
3970 (if (equal file "") | |
3971 "" | |
3972 (setq ange-ftp-this-dir | |
3973 (ange-ftp-real-file-name-as-directory ange-ftp-this-dir)) ;real? | |
3974 (let* ((tbl (ange-ftp-get-files ange-ftp-this-dir)) | |
3975 (ange-ftp-completion-ignored-pattern | |
30459 | 3976 (mapconcat (lambda (s) (if (stringp s) |
3977 (concat (regexp-quote s) "$") | |
3978 "/")) ; / never in filename | |
28210 | 3979 completion-ignored-extensions |
3980 "\\|"))) | |
3981 (save-match-data | |
3982 (or (ange-ftp-file-name-completion-1 | |
3983 file tbl ange-ftp-this-dir | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3984 'ange-ftp-file-entry-not-ignored-p) |
28210 | 3985 (ange-ftp-file-name-completion-1 |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3986 file tbl ange-ftp-this-dir)))))) |
28210 | 3987 |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3988 (if (ange-ftp-root-dir-p ange-ftp-this-dir) |
28210 | 3989 (try-completion |
3990 file | |
3991 (nconc (ange-ftp-generate-root-prefixes) | |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
3992 (ange-ftp-real-file-name-all-completions |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
3993 file ange-ftp-this-dir))) |
28210 | 3994 (ange-ftp-real-file-name-completion file ange-ftp-this-dir))))) |
3995 | |
3996 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3997 (defun ange-ftp-file-name-completion-1 (file tbl dir &optional predicate) |
28210 | 3998 (let ((bestmatch (try-completion file tbl predicate))) |
3999 (if bestmatch | |
4000 (if (eq bestmatch t) | |
4001 (if (file-directory-p (expand-file-name file dir)) | |
4002 (concat file "/") | |
4003 t) | |
4004 (if (and (eq (try-completion bestmatch tbl predicate) t) | |
4005 (file-directory-p | |
4006 (expand-file-name bestmatch dir))) | |
4007 (concat bestmatch "/") | |
4008 bestmatch))))) | |
4009 | |
4010 ;; Put these lines uncommmented in your .emacs if you want C-r to refresh | |
4011 ;; ange-ftp's cache whilst doing filename completion. | |
4012 ;; | |
4013 ;;(define-key minibuffer-local-completion-map "\C-r" 'ange-ftp-re-read-dir) | |
4014 ;;(define-key minibuffer-local-must-match-map "\C-r" 'ange-ftp-re-read-dir) | |
4015 | |
45170
1f468f3ca959
(ange-ftp-re-read-dir): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44953
diff
changeset
|
4016 ;;;###autoload |
1f468f3ca959
(ange-ftp-re-read-dir): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44953
diff
changeset
|
4017 (defalias 'ange-ftp-re-read-dir 'ange-ftp-reread-dir) |
1f468f3ca959
(ange-ftp-re-read-dir): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44953
diff
changeset
|
4018 |
28210 | 4019 ;;;###autoload |
4020 (defun ange-ftp-reread-dir (&optional dir) | |
4021 "Reread remote directory DIR to update the directory cache. | |
4022 The implementation of remote ftp file names caches directory contents | |
4023 for speed. Therefore, when new remote files are created, Emacs | |
4024 may not know they exist. You can use this command to reread a specific | |
4025 directory, so that Emacs will know its current contents." | |
4026 (interactive) | |
4027 (if dir | |
4028 (setq dir (expand-file-name dir)) | |
4029 (setq dir (file-name-directory (expand-file-name (buffer-string))))) | |
4030 (if (ange-ftp-ftp-name dir) | |
4031 (progn | |
4032 (setq ange-ftp-ls-cache-file nil) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4033 (remhash dir ange-ftp-files-hashtable) |
28210 | 4034 (ange-ftp-get-files dir t)))) |
4035 | |
4036 (defun ange-ftp-make-directory (dir &optional parents) | |
4037 (interactive (list (expand-file-name (read-file-name "Make directory: ")))) | |
4038 (if parents | |
4039 (let ((parent (file-name-directory (directory-file-name dir)))) | |
4040 (or (file-exists-p parent) | |
4041 (ange-ftp-make-directory parent parents)))) | |
4042 (if (file-exists-p dir) | |
4043 (error "Cannot make directory %s: file already exists" dir) | |
4044 (let ((parsed (ange-ftp-ftp-name dir))) | |
4045 (if parsed | |
4046 (let* ((host (nth 0 parsed)) | |
4047 (user (nth 1 parsed)) | |
4048 ;; Some ftp's on unix machines (at least on Suns) | |
4049 ;; insist that mkdir take a filename, and not a | |
4050 ;; directory-name name as an arg. Argh!! This is a bug. | |
4051 ;; Non-unix machines will probably always insist | |
4052 ;; that mkdir takes a directory-name as an arg | |
4053 ;; (as the ftp man page says it should). | |
4054 (name (ange-ftp-quote-string | |
4055 (if (eq (ange-ftp-host-type host) 'unix) | |
4056 (ange-ftp-real-directory-file-name (nth 2 parsed)) | |
4057 (ange-ftp-real-file-name-as-directory | |
4058 (nth 2 parsed))))) | |
4059 (abbr (ange-ftp-abbreviate-filename dir)) | |
4060 (result (ange-ftp-send-cmd host user | |
4061 (list 'mkdir name) | |
4062 (format "Making directory %s" | |
4063 abbr)))) | |
4064 (or (car result) | |
4065 (ange-ftp-error host user | |
4066 (format "Could not make directory %s: %s" | |
4067 dir | |
4068 (cdr result)))) | |
4069 (ange-ftp-add-file-entry dir t)) | |
4070 (ange-ftp-real-make-directory dir))))) | |
4071 | |
4072 (defun ange-ftp-delete-directory (dir) | |
4073 (if (file-directory-p dir) | |
4074 (let ((parsed (ange-ftp-ftp-name dir))) | |
4075 (if parsed | |
4076 (let* ((host (nth 0 parsed)) | |
4077 (user (nth 1 parsed)) | |
4078 ;; Some ftp's on unix machines (at least on Suns) | |
4079 ;; insist that rmdir take a filename, and not a | |
4080 ;; directory-name name as an arg. Argh!! This is a bug. | |
4081 ;; Non-unix machines will probably always insist | |
4082 ;; that rmdir takes a directory-name as an arg | |
4083 ;; (as the ftp man page says it should). | |
4084 (name (ange-ftp-quote-string | |
4085 (if (eq (ange-ftp-host-type host) 'unix) | |
4086 (ange-ftp-real-directory-file-name | |
4087 (nth 2 parsed)) | |
4088 (ange-ftp-real-file-name-as-directory | |
4089 (nth 2 parsed))))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4090 (abbr (ange-ftp-abbreviate-filename dir)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4091 (result (ange-ftp-send-cmd host user |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4092 (list 'rmdir name) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4093 (format "Removing directory %s" |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4094 abbr)))) |
28210 | 4095 (or (car result) |
4096 (ange-ftp-error host user | |
4097 (format "Could not remove directory %s: %s" | |
4098 dir | |
4099 (cdr result)))) | |
4100 (ange-ftp-delete-file-entry dir t)) | |
4101 (ange-ftp-real-delete-directory dir))) | |
4102 (error "Not a directory: %s" dir))) | |
4103 | |
4104 ;; Make a local copy of FILE and return its name. | |
4105 | |
4106 (defun ange-ftp-file-local-copy (file) | |
4107 (let* ((fn1 (expand-file-name file)) | |
4108 (pa1 (ange-ftp-ftp-name fn1))) | |
4109 (if pa1 | |
4110 (let ((tmp1 (ange-ftp-make-tmp-name (car pa1)))) | |
4111 (ange-ftp-copy-file-internal fn1 tmp1 t nil | |
4112 (format "Getting %s" fn1)) | |
4113 tmp1)))) | |
4114 | |
4115 (defun ange-ftp-load (file &optional noerror nomessage nosuffix) | |
4116 (if (ange-ftp-ftp-name file) | |
4117 (let ((tryfiles (if nosuffix | |
4118 (list file) | |
4119 (list (concat file ".elc") (concat file ".el") file))) | |
4120 ;; make sure there are no references to temp files | |
4121 (load-force-doc-strings t) | |
4122 copy) | |
4123 (while (and tryfiles (not copy)) | |
4124 (catch 'ftp-error | |
4125 (let ((ange-ftp-waiting-flag t)) | |
4126 (condition-case error | |
4127 (setq copy (ange-ftp-file-local-copy (car tryfiles))) | |
4128 (ftp-error nil)))) | |
4129 (setq tryfiles (cdr tryfiles))) | |
4130 (if copy | |
4131 (unwind-protect | |
4132 (funcall 'load copy noerror nomessage nosuffix) | |
4133 (delete-file copy)) | |
4134 (or noerror | |
4135 (signal 'file-error (list "Cannot open load file" file))) | |
4136 nil)) | |
4137 (ange-ftp-real-load file noerror nomessage nosuffix))) | |
4138 | |
4139 ;; Calculate default-unhandled-directory for a given ange-ftp buffer. | |
4140 (defun ange-ftp-unhandled-file-name-directory (filename) | |
4141 (file-name-directory ange-ftp-tmp-name-template)) | |
4142 | |
4143 | |
4144 ;; Need the following functions for making filenames of compressed | |
4145 ;; files, because some OS's (unlike UNIX) do not allow a filename to | |
4146 ;; have two extensions. | |
4147 | |
4148 (defvar ange-ftp-make-compressed-filename-alist nil | |
4149 "Alist of host-type-specific functions to process file names for compression. | |
4150 Each element has the form (TYPE . FUNC). | |
4151 FUNC should take one argument, a file name, and return a list | |
4152 of the form (COMPRESSING NEWNAME). | |
30459 | 4153 COMPRESSING should be t if the specified file should be compressed, |
28210 | 4154 and nil if it should be uncompressed (that is, if it is a compressed file). |
4155 NEWNAME should be the name to give the new compressed or uncompressed file.") | |
4156 | |
4157 (defun ange-ftp-dired-compress-file (name) | |
4158 (let ((parsed (ange-ftp-ftp-name name)) | |
4159 conversion-func) | |
4160 (if (and parsed | |
4161 (setq conversion-func | |
4162 (cdr (assq (ange-ftp-host-type (car parsed)) | |
4163 ange-ftp-make-compressed-filename-alist)))) | |
4164 (let* ((decision | |
4165 (save-match-data (funcall conversion-func name))) | |
4166 (compressing (car decision)) | |
4167 (newfile (nth 1 decision))) | |
4168 (if compressing | |
4169 (ange-ftp-compress name newfile) | |
4170 (ange-ftp-uncompress name newfile))) | |
4171 (let (file-name-handler-alist) | |
4172 (dired-compress-file name))))) | |
4173 | |
4174 ;; Copy FILE to this machine, compress it, and copy out to NFILE. | |
4175 (defun ange-ftp-compress (file nfile) | |
4176 (let* ((parsed (ange-ftp-ftp-name file)) | |
4177 (tmp1 (ange-ftp-make-tmp-name (car parsed))) | |
4178 (tmp2 (ange-ftp-make-tmp-name (car parsed))) | |
4179 (abbr (ange-ftp-abbreviate-filename file)) | |
4180 (nabbr (ange-ftp-abbreviate-filename nfile)) | |
4181 (msg1 (format "Getting %s" abbr)) | |
4182 (msg2 (format "Putting %s" nabbr))) | |
4183 (unwind-protect | |
4184 (progn | |
4185 (ange-ftp-copy-file-internal file tmp1 t nil msg1) | |
4186 (and ange-ftp-process-verbose | |
4187 (ange-ftp-message "Compressing %s..." abbr)) | |
4188 (call-process-region (point) | |
4189 (point) | |
4190 shell-file-name | |
4191 nil | |
4192 t | |
4193 nil | |
4194 "-c" | |
4195 (format "compress -f -c < %s > %s" tmp1 tmp2)) | |
4196 (and ange-ftp-process-verbose | |
4197 (ange-ftp-message "Compressing %s...done" abbr)) | |
4198 (if (zerop (buffer-size)) | |
4199 (progn | |
4200 (let (ange-ftp-process-verbose) | |
4201 (delete-file file)) | |
4202 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2)))) | |
4203 (ange-ftp-del-tmp-name tmp1) | |
4204 (ange-ftp-del-tmp-name tmp2)))) | |
30459 | 4205 |
28210 | 4206 ;; Copy FILE to this machine, uncompress it, and copy out to NFILE. |
4207 (defun ange-ftp-uncompress (file nfile) | |
4208 (let* ((parsed (ange-ftp-ftp-name file)) | |
4209 (tmp1 (ange-ftp-make-tmp-name (car parsed))) | |
4210 (tmp2 (ange-ftp-make-tmp-name (car parsed))) | |
4211 (abbr (ange-ftp-abbreviate-filename file)) | |
4212 (nabbr (ange-ftp-abbreviate-filename nfile)) | |
4213 (msg1 (format "Getting %s" abbr)) | |
4214 (msg2 (format "Putting %s" nabbr)) | |
4215 ;; ;; Cheap hack because of problems with binary file transfers from | |
4216 ;; ;; VMS hosts. | |
4217 ;; (gbinary (not (eq 'vms (ange-ftp-host-type (car parsed))))) | |
4218 ) | |
4219 (unwind-protect | |
4220 (progn | |
4221 (ange-ftp-copy-file-internal file tmp1 t nil msg1) | |
4222 (and ange-ftp-process-verbose | |
4223 (ange-ftp-message "Uncompressing %s..." abbr)) | |
4224 (call-process-region (point) | |
4225 (point) | |
4226 shell-file-name | |
4227 nil | |
4228 t | |
4229 nil | |
4230 "-c" | |
4231 (format "uncompress -c < %s > %s" tmp1 tmp2)) | |
4232 (and ange-ftp-process-verbose | |
4233 (ange-ftp-message "Uncompressing %s...done" abbr)) | |
4234 (if (zerop (buffer-size)) | |
4235 (progn | |
4236 (let (ange-ftp-process-verbose) | |
4237 (delete-file file)) | |
4238 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2)))) | |
4239 (ange-ftp-del-tmp-name tmp1) | |
4240 (ange-ftp-del-tmp-name tmp2)))) | |
4241 | |
4242 (defun ange-ftp-find-backup-file-name (fn) | |
4243 ;; Either return the ordinary backup name, etc., | |
4244 ;; or return nil meaning don't make a backup. | |
4245 (if ange-ftp-make-backup-files | |
4246 (ange-ftp-real-find-backup-file-name fn))) | |
4247 | |
4248 ;;; Define the handler for special file names | |
4249 ;;; that causes ange-ftp to be invoked. | |
4250 | |
4251 ;;;###autoload | |
4252 (defun ange-ftp-hook-function (operation &rest args) | |
4253 (let ((fn (get operation 'ange-ftp))) | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4254 (if fn (save-match-data (apply fn args)) |
28210 | 4255 (ange-ftp-run-real-handler operation args)))) |
46143
5023425b4a55
(ange-ftp-hook-function): Add file-remote-p prop.
Richard M. Stallman <rms@gnu.org>
parents:
45958
diff
changeset
|
4256 ;;;###autoload |
5023425b4a55
(ange-ftp-hook-function): Add file-remote-p prop.
Richard M. Stallman <rms@gnu.org>
parents:
45958
diff
changeset
|
4257 ;;; These file names are remote file names. |
5023425b4a55
(ange-ftp-hook-function): Add file-remote-p prop.
Richard M. Stallman <rms@gnu.org>
parents:
45958
diff
changeset
|
4258 (put 'ange-ftp-hook-function 'file-remote-p t) |
28210 | 4259 |
46349
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4260 ;; The following code is commented out because Tramp now deals with |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4261 ;; Ange-FTP filenames, too. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4262 |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4263 ;;-;;; This regexp takes care of real ange-ftp file names (with a slash |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4264 ;;-;;; and colon). |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4265 ;;-;;; Don't allow the host name to end in a period--some systems use /.: |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4266 ;;-;;;###autoload |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4267 ;;-(or (assoc "^/[^/:]*[^/:.]:" file-name-handler-alist) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4268 ;;- (setq file-name-handler-alist |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4269 ;;- (cons '("^/[^/:]*[^/:.]:" . ange-ftp-hook-function) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4270 ;;- file-name-handler-alist))) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4271 ;;- |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4272 ;;-;;; This regexp recognizes absolute filenames with only one component, |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4273 ;;-;;; for the sake of hostname completion. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4274 ;;-;;;###autoload |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4275 ;;-(or (assoc "^/[^/:]*\\'" file-name-handler-alist) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4276 ;;- (setq file-name-handler-alist |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4277 ;;- (cons '("^/[^/:]*\\'" . ange-ftp-completion-hook-function) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4278 ;;- file-name-handler-alist))) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4279 ;;- |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4280 ;;-;;; This regexp recognizes absolute filenames with only one component |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4281 ;;-;;; on Windows, for the sake of hostname completion. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4282 ;;-;;; NB. Do not mark this as autoload, because it is very common to |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4283 ;;-;;; do completions in the root directory of drives on Windows. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4284 ;;-(and (memq system-type '(ms-dos windows-nt)) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4285 ;;- (or (assoc "^[a-zA-Z]:/[^/:]*\\'" file-name-handler-alist) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4286 ;;- (setq file-name-handler-alist |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4287 ;;- (cons '("^[a-zA-Z]:/[^/:]*\\'" . |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4288 ;;- ange-ftp-completion-hook-function) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4289 ;;- file-name-handler-alist)))) |
28210 | 4290 |
4291 ;;; The above two forms are sufficient to cause this file to be loaded | |
4292 ;;; if the user ever uses a file name with a colon in it. | |
4293 | |
30459 | 4294 ;;; This sets the mode |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
4295 (add-hook 'find-file-hook 'ange-ftp-set-buffer-mode) |
28210 | 4296 |
4297 ;;; Now say where to find the handlers for particular operations. | |
4298 | |
4299 (put 'file-name-directory 'ange-ftp 'ange-ftp-file-name-directory) | |
4300 (put 'file-name-nondirectory 'ange-ftp 'ange-ftp-file-name-nondirectory) | |
4301 (put 'file-name-as-directory 'ange-ftp 'ange-ftp-file-name-as-directory) | |
4302 (put 'directory-file-name 'ange-ftp 'ange-ftp-directory-file-name) | |
4303 (put 'expand-file-name 'ange-ftp 'ange-ftp-expand-file-name) | |
4304 (put 'make-directory 'ange-ftp 'ange-ftp-make-directory) | |
4305 (put 'delete-directory 'ange-ftp 'ange-ftp-delete-directory) | |
4306 (put 'insert-file-contents 'ange-ftp 'ange-ftp-insert-file-contents) | |
4307 (put 'directory-files 'ange-ftp 'ange-ftp-directory-files) | |
4308 (put 'file-directory-p 'ange-ftp 'ange-ftp-file-directory-p) | |
4309 (put 'file-writable-p 'ange-ftp 'ange-ftp-file-writable-p) | |
4310 (put 'file-readable-p 'ange-ftp 'ange-ftp-file-readable-p) | |
4311 (put 'file-executable-p 'ange-ftp 'ange-ftp-file-executable-p) | |
4312 (put 'file-symlink-p 'ange-ftp 'ange-ftp-file-symlink-p) | |
4313 (put 'delete-file 'ange-ftp 'ange-ftp-delete-file) | |
4314 (put 'verify-visited-file-modtime 'ange-ftp | |
4315 'ange-ftp-verify-visited-file-modtime) | |
4316 (put 'file-exists-p 'ange-ftp 'ange-ftp-file-exists-p) | |
4317 (put 'write-region 'ange-ftp 'ange-ftp-write-region) | |
4318 (put 'copy-file 'ange-ftp 'ange-ftp-copy-file) | |
4319 (put 'rename-file 'ange-ftp 'ange-ftp-rename-file) | |
4320 (put 'file-attributes 'ange-ftp 'ange-ftp-file-attributes) | |
30481 | 4321 (put 'file-newer-than-file-p 'ange-ftp 'ange-ftp-file-newer-than-file-p) |
28210 | 4322 (put 'file-name-all-completions 'ange-ftp 'ange-ftp-file-name-all-completions) |
4323 (put 'file-name-completion 'ange-ftp 'ange-ftp-file-name-completion) | |
4324 (put 'insert-directory 'ange-ftp 'ange-ftp-insert-directory) | |
4325 (put 'file-local-copy 'ange-ftp 'ange-ftp-file-local-copy) | |
4326 (put 'unhandled-file-name-directory 'ange-ftp | |
4327 'ange-ftp-unhandled-file-name-directory) | |
4328 (put 'file-name-sans-versions 'ange-ftp 'ange-ftp-file-name-sans-versions) | |
4329 (put 'dired-uncache 'ange-ftp 'ange-ftp-dired-uncache) | |
4330 (put 'dired-compress-file 'ange-ftp 'ange-ftp-dired-compress-file) | |
4331 (put 'load 'ange-ftp 'ange-ftp-load) | |
4332 (put 'find-backup-file-name 'ange-ftp 'ange-ftp-find-backup-file-name) | |
4333 | |
4334 ;; Turn off truename processing to save time. | |
4335 ;; Treat each name as its own truename. | |
4336 (put 'file-truename 'ange-ftp 'identity) | |
4337 | |
4338 ;; Turn off RCS/SCCS processing to save time. | |
4339 ;; This returns nil for any file name as argument. | |
4340 (put 'vc-registered 'ange-ftp 'null) | |
4341 | |
4342 (put 'dired-call-process 'ange-ftp 'ange-ftp-dired-call-process) | |
4343 (put 'shell-command 'ange-ftp 'ange-ftp-shell-command) | |
4344 | |
4345 ;;; Define ways of getting at unmodified Emacs primitives, | |
4346 ;;; turning off our handler. | |
4347 | |
4348 (defun ange-ftp-run-real-handler (operation args) | |
4349 (let ((inhibit-file-name-handlers | |
4350 (cons 'ange-ftp-hook-function | |
4351 (cons 'ange-ftp-completion-hook-function | |
4352 (and (eq inhibit-file-name-operation operation) | |
4353 inhibit-file-name-handlers)))) | |
4354 (inhibit-file-name-operation operation)) | |
4355 (apply operation args))) | |
4356 | |
4357 (defun ange-ftp-real-file-name-directory (&rest args) | |
4358 (ange-ftp-run-real-handler 'file-name-directory args)) | |
4359 (defun ange-ftp-real-file-name-nondirectory (&rest args) | |
4360 (ange-ftp-run-real-handler 'file-name-nondirectory args)) | |
4361 (defun ange-ftp-real-file-name-as-directory (&rest args) | |
4362 (ange-ftp-run-real-handler 'file-name-as-directory args)) | |
4363 (defun ange-ftp-real-directory-file-name (&rest args) | |
4364 (ange-ftp-run-real-handler 'directory-file-name args)) | |
4365 (defun ange-ftp-real-expand-file-name (&rest args) | |
4366 (ange-ftp-run-real-handler 'expand-file-name args)) | |
4367 (defun ange-ftp-real-make-directory (&rest args) | |
4368 (ange-ftp-run-real-handler 'make-directory args)) | |
4369 (defun ange-ftp-real-delete-directory (&rest args) | |
4370 (ange-ftp-run-real-handler 'delete-directory args)) | |
4371 (defun ange-ftp-real-insert-file-contents (&rest args) | |
4372 (ange-ftp-run-real-handler 'insert-file-contents args)) | |
4373 (defun ange-ftp-real-directory-files (&rest args) | |
4374 (ange-ftp-run-real-handler 'directory-files args)) | |
4375 (defun ange-ftp-real-file-directory-p (&rest args) | |
4376 (ange-ftp-run-real-handler 'file-directory-p args)) | |
4377 (defun ange-ftp-real-file-writable-p (&rest args) | |
4378 (ange-ftp-run-real-handler 'file-writable-p args)) | |
4379 (defun ange-ftp-real-file-readable-p (&rest args) | |
4380 (ange-ftp-run-real-handler 'file-readable-p args)) | |
4381 (defun ange-ftp-real-file-executable-p (&rest args) | |
4382 (ange-ftp-run-real-handler 'file-executable-p args)) | |
4383 (defun ange-ftp-real-file-symlink-p (&rest args) | |
4384 (ange-ftp-run-real-handler 'file-symlink-p args)) | |
4385 (defun ange-ftp-real-delete-file (&rest args) | |
4386 (ange-ftp-run-real-handler 'delete-file args)) | |
4387 (defun ange-ftp-real-verify-visited-file-modtime (&rest args) | |
4388 (ange-ftp-run-real-handler 'verify-visited-file-modtime args)) | |
4389 (defun ange-ftp-real-file-exists-p (&rest args) | |
4390 (ange-ftp-run-real-handler 'file-exists-p args)) | |
4391 (defun ange-ftp-real-write-region (&rest args) | |
4392 (ange-ftp-run-real-handler 'write-region args)) | |
4393 (defun ange-ftp-real-backup-buffer (&rest args) | |
4394 (ange-ftp-run-real-handler 'backup-buffer args)) | |
4395 (defun ange-ftp-real-copy-file (&rest args) | |
4396 (ange-ftp-run-real-handler 'copy-file args)) | |
4397 (defun ange-ftp-real-rename-file (&rest args) | |
4398 (ange-ftp-run-real-handler 'rename-file args)) | |
4399 (defun ange-ftp-real-file-attributes (&rest args) | |
4400 (ange-ftp-run-real-handler 'file-attributes args)) | |
30481 | 4401 (defun ange-ftp-real-file-newer-than-file-p (&rest args) |
4402 (ange-ftp-run-real-handler 'file-newer-than-file-p args)) | |
28210 | 4403 (defun ange-ftp-real-file-name-all-completions (&rest args) |
4404 (ange-ftp-run-real-handler 'file-name-all-completions args)) | |
4405 (defun ange-ftp-real-file-name-completion (&rest args) | |
4406 (ange-ftp-run-real-handler 'file-name-completion args)) | |
4407 (defun ange-ftp-real-insert-directory (&rest args) | |
4408 (ange-ftp-run-real-handler 'insert-directory args)) | |
4409 (defun ange-ftp-real-file-name-sans-versions (&rest args) | |
4410 (ange-ftp-run-real-handler 'file-name-sans-versions args)) | |
4411 (defun ange-ftp-real-shell-command (&rest args) | |
4412 (ange-ftp-run-real-handler 'shell-command args)) | |
4413 (defun ange-ftp-real-load (&rest args) | |
4414 (ange-ftp-run-real-handler 'load args)) | |
4415 (defun ange-ftp-real-find-backup-file-name (&rest args) | |
4416 (ange-ftp-run-real-handler 'find-backup-file-name args)) | |
4417 | |
4418 ;; Here we support using dired on remote hosts. | |
4419 ;; I have turned off the support for using dired on foreign directory formats. | |
4420 ;; That involves too many unclean hooks. | |
30459 | 4421 ;; It would be cleaner to support such operations by |
28210 | 4422 ;; converting the foreign directory format to something dired can understand; |
4423 ;; something close to ls -l output. | |
4424 ;; The logical place to do this is in the functions ange-ftp-parse-...-listing. | |
4425 | |
4426 ;; Some of the old dired hooks would still be needed even if this is done. | |
4427 ;; I have preserved (and modernized) those hooks. | |
4428 ;; So the format conversion should be all that is needed. | |
4429 | |
47575
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4430 ;; When called from dired, SWITCHES may start with "--dired". |
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4431 ;; `ange-ftp-ls' handles this. |
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4432 |
28210 | 4433 (defun ange-ftp-insert-directory (file switches &optional wildcard full) |
4434 (let ((short (ange-ftp-abbreviate-filename file)) | |
42397
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4435 (parsed (ange-ftp-ftp-name (expand-file-name file))) |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4436 tem) |
28210 | 4437 (if parsed |
42397
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4438 (if (and (not wildcard) |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4439 (setq tem (file-symlink-p (directory-file-name file)))) |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4440 (ange-ftp-insert-directory |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
4441 (ange-ftp-expand-symlink |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
4442 tem (file-name-directory (directory-file-name file))) |
42397
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4443 switches wildcard full) |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4444 (insert |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4445 (if wildcard |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4446 (let ((default-directory (file-name-directory file))) |
47ec068f97d5
(ange-ftp-insert-directory): Explicitly follow symlinks.
Richard M. Stallman <rms@gnu.org>
parents:
42393
diff
changeset
|
4447 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t)) |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4448 (ange-ftp-ls file switches full)))) |
28210 | 4449 (ange-ftp-real-insert-directory file switches wildcard full)))) |
4450 | |
4451 (defun ange-ftp-dired-uncache (dir) | |
4452 (if (ange-ftp-ftp-name (expand-file-name dir)) | |
4453 (setq ange-ftp-ls-cache-file nil))) | |
4454 | |
4455 (defvar ange-ftp-sans-version-alist nil | |
4456 "Alist of mapping host type into function to remove file version numbers.") | |
4457 | |
4458 (defun ange-ftp-file-name-sans-versions (file keep-backup-version) | |
4459 (let* ((short (ange-ftp-abbreviate-filename file)) | |
4460 (parsed (ange-ftp-ftp-name short)) | |
4461 host-type func) | |
4462 (if parsed | |
4463 (setq host-type (ange-ftp-host-type (car parsed)) | |
4464 func (cdr (assq (ange-ftp-host-type (car parsed)) | |
4465 ange-ftp-sans-version-alist)))) | |
4466 (if func (funcall func file keep-backup-version) | |
4467 (ange-ftp-real-file-name-sans-versions file keep-backup-version)))) | |
4468 | |
4469 ;; This is the handler for shell-command. | |
4470 (defun ange-ftp-shell-command (command &optional output-buffer error-buffer) | |
4471 (let* ((parsed (ange-ftp-ftp-name default-directory)) | |
4472 (host (nth 0 parsed)) | |
4473 (user (nth 1 parsed)) | |
4474 (name (nth 2 parsed))) | |
4475 (if (not parsed) | |
4476 (ange-ftp-real-shell-command command output-buffer error-buffer) | |
4477 (if (> (length name) 0) ; else it's $HOME | |
4478 (setq command (concat "cd " name "; " command))) | |
42495
09f1b967d12e
(ange-ftp-shell-command): Remove port specification from the hostname.
Pavel Janík <Pavel@Janik.cz>
parents:
42397
diff
changeset
|
4479 ;; Remove port from the hostname |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4480 (when (string-match "\\(.*\\)#" host) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4481 (setq host (match-string 1 host))) |
28210 | 4482 (setq command |
4483 (format "%s %s \"%s\"" ; remsh -l USER does not work well | |
4484 ; on a hp-ux machine I tried | |
4485 remote-shell-program host command)) | |
4486 (ange-ftp-message "Remote command '%s' ..." command) | |
4487 ;; Cannot call ange-ftp-real-dired-run-shell-command here as it | |
4488 ;; would prepend "cd default-directory" --- which bombs because | |
4489 ;; default-directory is in ange-ftp syntax for remote file names. | |
4490 (ange-ftp-real-shell-command command output-buffer error-buffer)))) | |
4491 | |
4492 ;;; This is the handler for call-process. | |
4493 (defun ange-ftp-dired-call-process (program discard &rest arguments) | |
4494 ;; PROGRAM is always one of those below in the cond in dired.el. | |
4495 ;; The ARGUMENTS are (nearly) always files. | |
4496 (if (ange-ftp-ftp-name default-directory) | |
4497 ;; Can't use ange-ftp-dired-host-type here because the current | |
4498 ;; buffer is *dired-check-process output* | |
4499 (condition-case oops | |
4500 (cond ((equal dired-chmod-program program) | |
4501 (ange-ftp-call-chmod arguments)) | |
4502 ;; ((equal "chgrp" program)) | |
4503 ;; ((equal dired-chown-program program)) | |
4504 (t (error "Unknown remote command: %s" program))) | |
4505 (ftp-error (insert (format "%s: %s, %s\n" | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4506 (nth 1 oops) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4507 (nth 2 oops) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4508 (nth 3 oops))) |
28210 | 4509 ;; Caller expects nonzero value to mean failure. |
4510 1) | |
4511 (error (insert (format "%s\n" (nth 1 oops))) | |
4512 1)) | |
4513 (apply 'call-process program nil (not discard) nil arguments))) | |
4514 | |
30459 | 4515 (defvar ange-ftp-remote-shell "rsh" |
28210 | 4516 "Remote shell to use for chmod, if FTP server rejects the `chmod' command.") |
4517 | |
4518 ;; Handle an attempt to run chmod on a remote file | |
4519 ;; by using the ftp chmod command. | |
4520 (defun ange-ftp-call-chmod (args) | |
4521 (if (< (length args) 2) | |
4522 (error "ange-ftp-call-chmod: missing mode and/or filename: %s" args)) | |
4523 (let ((mode (car args)) | |
4524 (rest (cdr args))) | |
4525 (if (equal "--" (car rest)) | |
4526 (setq rest (cdr rest))) | |
4527 (mapcar | |
30459 | 4528 (lambda (file) |
4529 (setq file (expand-file-name file)) | |
4530 (let ((parsed (ange-ftp-ftp-name file))) | |
4531 (if parsed | |
4532 (let* ((host (nth 0 parsed)) | |
4533 (user (nth 1 parsed)) | |
4534 (name (ange-ftp-quote-string (nth 2 parsed))) | |
4535 (abbr (ange-ftp-abbreviate-filename file)) | |
4536 (result (ange-ftp-send-cmd host user | |
4537 (list 'chmod mode name) | |
4538 (format "doing chmod %s" | |
4539 abbr)))) | |
4540 (or (car result) | |
4541 (call-process | |
4542 ange-ftp-remote-shell | |
4543 nil t nil host dired-chmod-program mode name)))))) | |
28210 | 4544 rest)) |
4545 (setq ange-ftp-ls-cache-file nil) ;Stop confusing Dired. | |
4546 0) | |
4547 | |
4548 ;;; This is turned off because it has nothing properly to do | |
4549 ;;; with dired. It could be reasonable to adapt this to | |
4550 ;;; replace ange-ftp-copy-file. | |
4551 | |
4552 ;;;;; ------------------------------------------------------------ | |
4553 ;;;;; Noddy support for async copy-file within dired. | |
4554 ;;;;; ------------------------------------------------------------ | |
4555 | |
4556 ;;(defun ange-ftp-dired-copy-file (from to ok-flag &optional cont nowait) | |
4557 ;; "Documented as original." | |
4558 ;; (dired-handle-overwrite to) | |
4559 ;; (ange-ftp-copy-file-internal from to ok-flag dired-copy-preserve-time nil | |
4560 ;; cont nowait)) | |
4561 | |
4562 ;;(defun ange-ftp-dired-do-create-files (op-symbol file-creator operation arg | |
4563 ;; &optional marker-char op1 | |
4564 ;; how-to) | |
4565 ;; "Documented as original." | |
4566 ;; ;; we need to let ange-ftp-dired-create-files know that we indirectly | |
4567 ;; ;; called it rather than somebody else. | |
4568 ;; (let ((ange-ftp-dired-do-create-files t)) ; tell who caller is | |
4569 ;; (ange-ftp-real-dired-do-create-files op-symbol file-creator operation | |
4570 ;; arg marker-char op1 how-to))) | |
4571 | |
4572 ;;(defun ange-ftp-dired-create-files (file-creator operation fn-list name-constructor | |
4573 ;; &optional marker-char) | |
4574 ;; "Documented as original." | |
4575 ;; (if (and (boundp 'ange-ftp-dired-do-create-files) | |
4576 ;; ;; called from ange-ftp-dired-do-create-files? | |
4577 ;; ange-ftp-dired-do-create-files | |
4578 ;; ;; any files worth copying? | |
4579 ;; fn-list | |
4580 ;; ;; we only support async copy-file at the mo. | |
4581 ;; (eq file-creator 'dired-copy-file) | |
4582 ;; ;; it is only worth calling the alternative function for remote files | |
4583 ;; ;; as we tie ourself in recursive knots otherwise. | |
4584 ;; (or (ange-ftp-ftp-name (car fn-list)) | |
4585 ;; ;; we can only call the name constructor for dired-do-create-files | |
4586 ;; ;; since the one for regexps starts prompting here, there and | |
4587 ;; ;; everywhere. | |
4588 ;; (ange-ftp-ftp-name (funcall name-constructor (car fn-list))))) | |
4589 ;; ;; use the process-filter driven routine rather than the iterative one. | |
4590 ;; (ange-ftp-dcf-1 file-creator | |
4591 ;; operation | |
4592 ;; fn-list | |
4593 ;; name-constructor | |
4594 ;; (and (boundp 'target) target) ;dynamically bound | |
4595 ;; marker-char | |
4596 ;; (current-buffer) | |
4597 ;; nil ;overwrite-query | |
4598 ;; nil ;overwrite-backup-query | |
4599 ;; nil ;failures | |
4600 ;; nil ;skipped | |
4601 ;; 0 ;success-count | |
4602 ;; (length fn-list) ;total | |
4603 ;; ) | |
4604 ;; ;; normal case... use the interactive routine... much cheaper. | |
4605 ;; (ange-ftp-real-dired-create-files file-creator operation fn-list | |
4606 ;; name-constructor marker-char))) | |
4607 | |
4608 ;;(defun ange-ftp-dcf-1 (file-creator operation fn-list name-constructor | |
30459 | 4609 ;; target marker-char buffer overwrite-query |
28210 | 4610 ;; overwrite-backup-query failures skipped |
4611 ;; success-count total) | |
4612 ;; (let ((old-buf (current-buffer))) | |
4613 ;; (unwind-protect | |
4614 ;; (progn | |
4615 ;; (set-buffer buffer) | |
4616 ;; (if (null fn-list) | |
4617 ;; (ange-ftp-dcf-3 failures operation total skipped | |
4618 ;; success-count buffer) | |
30459 | 4619 |
28210 | 4620 ;; (let* ((from (car fn-list)) |
4621 ;; (to (funcall name-constructor from))) | |
4622 ;; (if (equal to from) | |
4623 ;; (progn | |
4624 ;; (setq to nil) | |
4625 ;; (dired-log "Cannot %s to same file: %s\n" | |
4626 ;; (downcase operation) from))) | |
4627 ;; (if (not to) | |
4628 ;; (ange-ftp-dcf-1 file-creator | |
4629 ;; operation | |
4630 ;; (cdr fn-list) | |
4631 ;; name-constructor | |
4632 ;; target | |
4633 ;; marker-char | |
4634 ;; buffer | |
4635 ;; overwrite-query | |
4636 ;; overwrite-backup-query | |
4637 ;; failures | |
4638 ;; (cons (dired-make-relative from) skipped) | |
4639 ;; success-count | |
4640 ;; total) | |
4641 ;; (let* ((overwrite (file-exists-p to)) | |
4642 ;; (overwrite-confirmed ; for dired-handle-overwrite | |
4643 ;; (and overwrite | |
4644 ;; (let ((help-form '(format "\ | |
4645 ;;Type SPC or `y' to overwrite file `%s', | |
4646 ;;DEL or `n' to skip to next, | |
4647 ;;ESC or `q' to not overwrite any of the remaining files, | |
4648 ;;`!' to overwrite all remaining files with no more questions." to))) | |
4649 ;; (dired-query 'overwrite-query | |
4650 ;; "Overwrite `%s'?" to)))) | |
4651 ;; ;; must determine if FROM is marked before file-creator | |
4652 ;; ;; gets a chance to delete it (in case of a move). | |
4653 ;; (actual-marker-char | |
4654 ;; (cond ((integerp marker-char) marker-char) | |
4655 ;; (marker-char (dired-file-marker from)) ; slow | |
4656 ;; (t nil)))) | |
4657 ;; (condition-case err | |
4658 ;; (funcall file-creator from to overwrite-confirmed | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4659 ;; (list 'ange-ftp-dcf-2 |
28210 | 4660 ;; nil ;err |
4661 ;; file-creator operation fn-list | |
4662 ;; name-constructor | |
4663 ;; target | |
4664 ;; marker-char actual-marker-char | |
4665 ;; buffer to from | |
4666 ;; overwrite | |
4667 ;; overwrite-confirmed | |
30459 | 4668 ;; overwrite-query |
28210 | 4669 ;; overwrite-backup-query |
4670 ;; failures skipped success-count | |
4671 ;; total) | |
4672 ;; t) | |
4673 ;; (file-error ; FILE-CREATOR aborted | |
4674 ;; (ange-ftp-dcf-2 nil ;result | |
4675 ;; nil ;line | |
4676 ;; err | |
4677 ;; file-creator operation fn-list | |
4678 ;; name-constructor | |
4679 ;; target | |
4680 ;; marker-char actual-marker-char | |
4681 ;; buffer to from | |
4682 ;; overwrite | |
4683 ;; overwrite-confirmed | |
30459 | 4684 ;; overwrite-query |
28210 | 4685 ;; overwrite-backup-query |
4686 ;; failures skipped success-count | |
4687 ;; total)))))))) | |
4688 ;; (set-buffer old-buf)))) | |
4689 | |
4690 ;;(defun ange-ftp-dcf-2 (result line err | |
4691 ;; file-creator operation fn-list | |
4692 ;; name-constructor | |
4693 ;; target | |
4694 ;; marker-char actual-marker-char | |
4695 ;; buffer to from | |
4696 ;; overwrite | |
4697 ;; overwrite-confirmed | |
30459 | 4698 ;; overwrite-query |
28210 | 4699 ;; overwrite-backup-query |
4700 ;; failures skipped success-count | |
4701 ;; total) | |
4702 ;; (let ((old-buf (current-buffer))) | |
4703 ;; (unwind-protect | |
4704 ;; (progn | |
4705 ;; (set-buffer buffer) | |
4706 ;; (if (or err (not result)) | |
4707 ;; (progn | |
4708 ;; (setq failures (cons (dired-make-relative from) failures)) | |
4709 ;; (dired-log "%s `%s' to `%s' failed:\n%s\n" | |
4710 ;; operation from to (or err line))) | |
4711 ;; (if overwrite | |
4712 ;; ;; If we get here, file-creator hasn't been aborted | |
4713 ;; ;; and the old entry (if any) has to be deleted | |
4714 ;; ;; before adding the new entry. | |
4715 ;; (dired-remove-file to)) | |
4716 ;; (setq success-count (1+ success-count)) | |
4717 ;; (message "%s: %d of %d" operation success-count total) | |
4718 ;; (dired-add-file to actual-marker-char)) | |
30459 | 4719 |
28210 | 4720 ;; (ange-ftp-dcf-1 file-creator operation (cdr fn-list) |
4721 ;; name-constructor | |
4722 ;; target | |
4723 ;; marker-char | |
4724 ;; buffer | |
30459 | 4725 ;; overwrite-query |
28210 | 4726 ;; overwrite-backup-query |
4727 ;; failures skipped success-count | |
4728 ;; total)) | |
4729 ;; (set-buffer old-buf)))) | |
4730 | |
4731 ;;(defun ange-ftp-dcf-3 (failures operation total skipped success-count | |
4732 ;; buffer) | |
4733 ;; (let ((old-buf (current-buffer))) | |
4734 ;; (unwind-protect | |
4735 ;; (progn | |
4736 ;; (set-buffer buffer) | |
4737 ;; (cond | |
4738 ;; (failures | |
4739 ;; (dired-log-summary | |
4740 ;; (message "%s failed for %d of %d file%s %s" | |
4741 ;; operation (length failures) total | |
4742 ;; (dired-plural-s total) failures))) | |
4743 ;; (skipped | |
4744 ;; (dired-log-summary | |
4745 ;; (message "%s: %d of %d file%s skipped %s" | |
4746 ;; operation (length skipped) total | |
4747 ;; (dired-plural-s total) skipped))) | |
4748 ;; (t | |
4749 ;; (message "%s: %s file%s." | |
4750 ;; operation success-count (dired-plural-s success-count)))) | |
4751 ;; (dired-move-to-filename)) | |
4752 ;; (set-buffer old-buf)))) | |
4753 | |
4754 ;;;; ----------------------------------------------- | |
4755 ;;;; Unix Descriptive Listing (dl) Support | |
4756 ;;;; ----------------------------------------------- | |
4757 | |
4758 ;; This is turned off because nothing uses it currently | |
4759 ;; and because I don't understand what it's supposed to be for. --rms. | |
4760 | |
4761 ;;(defconst ange-ftp-dired-dl-re-dir | |
4762 ;; "^. [^ /]+/[ \n]" | |
4763 ;; "Regular expression to use to search for dl directories.") | |
4764 | |
4765 ;;(or (assq 'unix:dl ange-ftp-dired-re-dir-alist) | |
4766 ;; (setq ange-ftp-dired-re-dir-alist | |
4767 ;; (cons (cons 'unix:dl ange-ftp-dired-dl-re-dir) | |
4768 ;; ange-ftp-dired-re-dir-alist))) | |
4769 | |
4770 ;;(defun ange-ftp-dired-dl-move-to-filename (&optional raise-error eol) | |
4771 ;; "In dired, move to the first character of the filename on this line." | |
4772 ;; ;; This is the Unix dl version. | |
4773 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
4774 ;; (let (case-fold-search) | |
4775 ;; (beginning-of-line) | |
4776 ;; (if (looking-at ". [^ ]+ +\\([0-9]+\\|-\\|=\\) ") | |
4777 ;; (goto-char (+ (point) 2)) | |
4778 ;; (if raise-error | |
4779 ;; (error "No file on this line") | |
4780 ;; nil)))) | |
4781 | |
4782 ;;(or (assq 'unix:dl ange-ftp-dired-move-to-filename-alist) | |
4783 ;; (setq ange-ftp-dired-move-to-filename-alist | |
4784 ;; (cons '(unix:dl . ange-ftp-dired-dl-move-to-filename) | |
4785 ;; ange-ftp-dired-move-to-filename-alist))) | |
4786 | |
4787 ;;(defun ange-ftp-dired-dl-move-to-end-of-filename (&optional no-error eol) | |
4788 ;; ;; Assumes point is at beginning of filename. | |
4789 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
4790 ;; ;; On failure, signals an error or returns nil. | |
4791 ;; ;; This is the Unix dl version. | |
4792 ;; (let ((opoint (point)) | |
4793 ;; case-fold-search hidden) | |
4794 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
4795 ;; (setq hidden (and selective-display | |
4796 ;; (save-excursion | |
4797 ;; (search-forward "\r" eol t)))) | |
4798 ;; (if hidden | |
4799 ;; (if no-error | |
4800 ;; nil | |
4801 ;; (error | |
4802 ;; (substitute-command-keys | |
4803 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide"))) | |
4804 ;; (skip-chars-forward "^ /" eol) | |
4805 ;; (if (eq opoint (point)) | |
4806 ;; (if no-error | |
4807 ;; nil | |
4808 ;; (error "No file on this line")) | |
4809 ;; (point))))) | |
4810 | |
4811 ;;(or (assq 'unix:dl ange-ftp-dired-move-to-end-of-filename-alist) | |
4812 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
4813 ;; (cons '(unix:dl . ange-ftp-dired-dl-move-to-end-of-filename) | |
4814 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
4815 | |
4816 ;;;; ------------------------------------------------------------ | |
4817 ;;;; VOS support (VOS support is probably broken, | |
4818 ;;;; but I don't know anything about VOS.) | |
4819 ;;;; ------------------------------------------------------------ | |
4820 ; | |
4821 ;(defun ange-ftp-fix-name-for-vos (name &optional reverse) | |
4822 ; (setq name (copy-sequence name)) | |
4823 ; (let ((from (if reverse ?\> ?\/)) | |
4824 ; (to (if reverse ?\/ ?\>)) | |
4825 ; (i (1- (length name)))) | |
4826 ; (while (>= i 0) | |
4827 ; (if (= (aref name i) from) | |
4828 ; (aset name i to)) | |
4829 ; (setq i (1- i))) | |
4830 ; name)) | |
4831 ; | |
4832 ;(or (assq 'vos ange-ftp-fix-name-func-alist) | |
4833 ; (setq ange-ftp-fix-name-func-alist | |
4834 ; (cons '(vos . ange-ftp-fix-name-for-vos) | |
4835 ; ange-ftp-fix-name-func-alist))) | |
4836 ; | |
4837 ;(or (memq 'vos ange-ftp-dumb-host-types) | |
4838 ; (setq ange-ftp-dumb-host-types | |
4839 ; (cons 'vos ange-ftp-dumb-host-types))) | |
4840 ; | |
4841 ;(defun ange-ftp-fix-dir-name-for-vos (dir-name) | |
4842 ; (ange-ftp-fix-name-for-vos | |
4843 ; (concat dir-name | |
4844 ; (if (eq ?/ (aref dir-name (1- (length dir-name)))) | |
4845 ; "" "/") | |
4846 ; "*"))) | |
4847 ; | |
4848 ;(or (assq 'vos ange-ftp-fix-dir-name-func-alist) | |
4849 ; (setq ange-ftp-fix-dir-name-func-alist | |
4850 ; (cons '(vos . ange-ftp-fix-dir-name-for-vos) | |
4851 ; ange-ftp-fix-dir-name-func-alist))) | |
4852 ; | |
4853 ;(defvar ange-ftp-vos-host-regexp nil | |
4854 ; "If a host matches this regexp then it is assumed to be running VOS.") | |
4855 ; | |
4856 ;(defun ange-ftp-vos-host (host) | |
4857 ; (and ange-ftp-vos-host-regexp | |
4858 ; (save-match-data | |
4859 ; (string-match ange-ftp-vos-host-regexp host)))) | |
4860 ; | |
4861 ;(defun ange-ftp-parse-vos-listing () | |
4862 ; "Parse the current buffer which is assumed to be in VOS list -all | |
4863 ;format, and return a hashtable as the result." | |
4864 ; (let ((tbl (ange-ftp-make-hashtable)) | |
4865 ; (type-list | |
4866 ; '(("^Files: [0-9]+ +Blocks: [0-9]+\n+" nil 40) | |
4867 ; ("^Dirs: [0-9]+\n+" t 30))) | |
4868 ; type-regexp type-is-dir type-col file) | |
4869 ; (goto-char (point-min)) | |
4870 ; (save-match-data | |
4871 ; (while type-list | |
4872 ; (setq type-regexp (car (car type-list)) | |
4873 ; type-is-dir (nth 1 (car type-list)) | |
4874 ; type-col (nth 2 (car type-list)) | |
4875 ; type-list (cdr type-list)) | |
4876 ; (if (re-search-forward type-regexp nil t) | |
4877 ; (while (eq (char-after (point)) ? ) | |
4878 ; (move-to-column type-col) | |
4879 ; (setq file (buffer-substring (point) | |
4880 ; (progn | |
4881 ; (end-of-line 1) | |
4882 ; (point)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4883 ; (puthash file type-is-dir tbl) |
28210 | 4884 ; (forward-line 1)))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4885 ; (puthash "." 'vosdir tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4886 ; (puthash ".." 'vosdir tbl)) |
28210 | 4887 ; tbl)) |
4888 ; | |
4889 ;(or (assq 'vos ange-ftp-parse-list-func-alist) | |
4890 ; (setq ange-ftp-parse-list-func-alist | |
4891 ; (cons '(vos . ange-ftp-parse-vos-listing) | |
4892 ; ange-ftp-parse-list-func-alist))) | |
4893 | |
4894 ;;;; ------------------------------------------------------------ | |
4895 ;;;; VMS support. | |
4896 ;;;; ------------------------------------------------------------ | |
4897 | |
4898 ;; Convert NAME from UNIX-ish to VMS. If REVERSE given then convert from VMS | |
4899 ;; to UNIX-ish. | |
4900 (defun ange-ftp-fix-name-for-vms (name &optional reverse) | |
4901 (save-match-data | |
4902 (if reverse | |
4903 (if (string-match "^\\([^:]+:\\)?\\(\\[.*\\]\\)?\\([^][]*\\)$" name) | |
4904 (let (drive dir file) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4905 (setq drive (match-string 1 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4906 (setq dir (match-string 2 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4907 (setq file (match-string 3 name)) |
28210 | 4908 (and dir |
30481 | 4909 (setq dir (subst-char-in-string |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
4910 ?/ ?. (substring dir 1 -1) t))) |
28210 | 4911 (concat (and drive |
4912 (concat "/" drive "/")) | |
4913 dir (and dir "/") | |
4914 file)) | |
4915 (error "name %s didn't match" name)) | |
4916 (let (drive dir file tmp) | |
4917 (if (string-match "^/[^:]+:/" name) | |
4918 (setq drive (substring name 1 | |
4919 (1- (match-end 0))) | |
4920 name (substring name (match-end 0)))) | |
4921 (setq tmp (file-name-directory name)) | |
4922 (if tmp | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
4923 (setq dir (subst-char-in-string ?/ ?. (substring tmp 0 -1) t))) |
28210 | 4924 (setq file (file-name-nondirectory name)) |
4925 (concat drive | |
4926 (and dir (concat "[" (if drive nil ".") dir "]")) | |
4927 file))))) | |
4928 | |
4929 ;; (ange-ftp-fix-name-for-vms "/PUB$:/ANONYMOUS/SDSCPUB/NEXT/Readme.txt;1") | |
4930 ;; (ange-ftp-fix-name-for-vms "/PUB$:[ANONYMOUS.SDSCPUB.NEXT]Readme.txt;1" t) | |
4931 | |
4932 (or (assq 'vms ange-ftp-fix-name-func-alist) | |
4933 (setq ange-ftp-fix-name-func-alist | |
4934 (cons '(vms . ange-ftp-fix-name-for-vms) | |
4935 ange-ftp-fix-name-func-alist))) | |
4936 | |
4937 (or (memq 'vms ange-ftp-dumb-host-types) | |
4938 (setq ange-ftp-dumb-host-types | |
4939 (cons 'vms ange-ftp-dumb-host-types))) | |
4940 | |
4941 ;; It is important that this function barf for directories for which we know | |
4942 ;; that we cannot possibly get a directory listing, such as "/" and "/DEV:/". | |
4943 ;; This is because it saves an unnecessary FTP error, or possibly the listing | |
4944 ;; might succeed, but give erroneous info. This last case is particularly | |
4945 ;; likely for OS's (like MTS) for which we need to use a wildcard in order | |
4946 ;; to list a directory. | |
4947 | |
4948 ;; Convert name from UNIX-ish to VMS ready for a DIRectory listing. | |
4949 (defun ange-ftp-fix-dir-name-for-vms (dir-name) | |
4950 ;; Should there be entries for .. -> [-] and . -> [] below. Don't | |
4951 ;; think so, because expand-filename should have already short-circuited | |
4952 ;; them. | |
4953 (cond ((string-equal dir-name "/") | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
4954 (error "Cannot get listing for fictitious \"/\" directory")) |
28210 | 4955 ((string-match "^/[-A-Z0-9_$]+:/$" dir-name) |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
4956 (error "Cannot get listing for device")) |
28210 | 4957 ((ange-ftp-fix-name-for-vms dir-name)))) |
30459 | 4958 |
28210 | 4959 (or (assq 'vms ange-ftp-fix-dir-name-func-alist) |
4960 (setq ange-ftp-fix-dir-name-func-alist | |
4961 (cons '(vms . ange-ftp-fix-dir-name-for-vms) | |
4962 ange-ftp-fix-dir-name-func-alist))) | |
4963 | |
4964 (defvar ange-ftp-vms-host-regexp nil) | |
4965 | |
4966 ;; Return non-nil if HOST is running VMS. | |
4967 (defun ange-ftp-vms-host (host) | |
4968 (and ange-ftp-vms-host-regexp | |
4969 (save-match-data | |
4970 (string-match ange-ftp-vms-host-regexp host)))) | |
4971 | |
4972 ;; Because some VMS ftp servers convert filenames to lower case | |
4973 ;; we allow a-z in the filename regexp. I'm not too happy about this. | |
4974 | |
4975 (defconst ange-ftp-vms-filename-regexp | |
4976 (concat | |
4977 "\\(\\([_A-Za-z0-9$]?\\|[_A-Za-z0-9$][-_A-Za-z0-9$]*\\)\\." | |
4978 "[-_A-Za-z0-9$]*;+[0-9]*\\)") | |
4979 "Regular expression to match for a valid VMS file name in Dired buffer. | |
4980 Stupid freaking bug! Position of _ and $ shouldn't matter but they do. | |
4981 Having [A-Z0-9$_] bombs on filename _$$CHANGE_LOG$.TXT$ and $CHANGE_LOG$.TX | |
4982 Other orders of $ and _ seem to all work just fine.") | |
4983 | |
4984 ;; These parsing functions are as general as possible because the syntax | |
4985 ;; of ftp listings from VMS hosts is a bit erratic. What saves us is that | |
4986 ;; the VMS filename syntax is so rigid. If they bomb on a listing in the | |
4987 ;; standard VMS Multinet format, then this is a bug. If they bomb on a listing | |
4988 ;; from vms.weird.net, then too bad. | |
4989 | |
4990 ;; Extract the next filename from a VMS dired-like listing. | |
4991 (defun ange-ftp-parse-vms-filename () | |
4992 (if (re-search-forward | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4993 ange-ftp-vms-filename-regexp |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4994 nil t) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4995 (match-string 0))) |
28210 | 4996 |
4997 ;; Parse the current buffer which is assumed to be in MultiNet FTP dir | |
4998 ;; format, and return a hashtable as the result. | |
4999 (defun ange-ftp-parse-vms-listing () | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5000 (let ((tbl (make-hash-table :test 'equal)) |
28210 | 5001 file) |
5002 (goto-char (point-min)) | |
5003 (save-match-data | |
5004 (while (setq file (ange-ftp-parse-vms-filename)) | |
5005 (if (string-match "\\.\\(DIR\\|dir\\);[0-9]+" file) | |
5006 ;; deal with directories | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5007 (puthash (substring file 0 (match-beginning 0)) t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5008 (puthash file nil tbl) |
28210 | 5009 (if (string-match ";[0-9]+$" file) ; deal with extension |
5010 ;; sans extension | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5011 (puthash (substring file 0 (match-beginning 0)) nil tbl))) |
28210 | 5012 (forward-line 1)) |
5013 ;; Would like to look for a "Total" line, or a "Directory" line to | |
5014 ;; make sure that the listing isn't complete garbage before putting | |
5015 ;; in "." and "..", but we can't even count on all VAX's giving us | |
5016 ;; either of these. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5017 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5018 (puthash ".." t tbl)) |
28210 | 5019 tbl)) |
5020 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5021 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5022 '(vms . ange-ftp-parse-vms-listing)) |
28210 | 5023 |
5024 ;; This version only deletes file entries which have | |
5025 ;; explicit version numbers, because that is all VMS allows. | |
5026 | |
5027 ;; Can the following two functions be speeded up using file | |
5028 ;; completion functions? | |
5029 | |
5030 (defun ange-ftp-vms-delete-file-entry (name &optional dir-p) | |
5031 (if dir-p | |
5032 (ange-ftp-internal-delete-file-entry name t) | |
5033 (save-match-data | |
5034 (let ((file (ange-ftp-get-file-part name))) | |
5035 (if (string-match ";[0-9]+$" file) | |
30459 | 5036 ;; In VMS you can't delete a file without an explicit |
28210 | 5037 ;; version number, or wild-card (e.g. FOO;*) |
5038 ;; For now, we give up on wildcards. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5039 (let ((files (gethash (file-name-directory name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5040 ange-ftp-files-hashtable))) |
28210 | 5041 (if files |
5042 (let* ((root (substring file 0 | |
5043 (match-beginning 0))) | |
5044 (regexp (concat "^" | |
5045 (regexp-quote root) | |
5046 ";[0-9]+$")) | |
5047 versions) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5048 (remhash file files) |
28210 | 5049 ;; Now we need to check if there are any |
5050 ;; versions left. If not, then delete the | |
5051 ;; root entry. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5052 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5053 (lambda (key val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5054 (and (string-match regexp key) |
29587
bcdfb27c5ea4
(ange-ftp-vms-delete-file-entry)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28892
diff
changeset
|
5055 (setq versions t))) |
28210 | 5056 files) |
5057 (or versions | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5058 (remhash root files)))))))))) |
28210 | 5059 |
5060 (or (assq 'vms ange-ftp-delete-file-entry-alist) | |
5061 (setq ange-ftp-delete-file-entry-alist | |
5062 (cons '(vms . ange-ftp-vms-delete-file-entry) | |
5063 ange-ftp-delete-file-entry-alist))) | |
5064 | |
5065 (defun ange-ftp-vms-add-file-entry (name &optional dir-p) | |
5066 (if dir-p | |
5067 (ange-ftp-internal-add-file-entry name t) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5068 (let ((files (gethash (file-name-directory name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5069 ange-ftp-files-hashtable))) |
28210 | 5070 (if files |
5071 (let ((file (ange-ftp-get-file-part name))) | |
5072 (save-match-data | |
5073 (if (string-match ";[0-9]+$" file) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5074 (puthash (substring file 0 (match-beginning 0)) nil files) |
28210 | 5075 ;; Need to figure out what version of the file |
5076 ;; is being added. | |
5077 (let ((regexp (concat "^" | |
5078 (regexp-quote file) | |
5079 ";\\([0-9]+\\)$")) | |
5080 (version 0)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5081 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5082 (lambda (name val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5083 (and (string-match regexp name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5084 (setq version |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5085 (max version |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5086 (string-to-int (match-string 1 name)))))) |
28210 | 5087 files) |
5088 (setq version (1+ version)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5089 (puthash |
28210 | 5090 (concat file ";" (int-to-string version)) |
5091 nil files)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5092 (puthash file nil files)))))) |
28210 | 5093 |
5094 (or (assq 'vms ange-ftp-add-file-entry-alist) | |
5095 (setq ange-ftp-add-file-entry-alist | |
5096 (cons '(vms . ange-ftp-vms-add-file-entry) | |
5097 ange-ftp-add-file-entry-alist))) | |
5098 | |
5099 | |
5100 (defun ange-ftp-add-vms-host (host) | |
5101 "Mark HOST as the name of a machine running VMS." | |
5102 (interactive | |
5103 (list (read-string "Host: " | |
5104 (let ((name (or (buffer-file-name) default-directory))) | |
5105 (and name (car (ange-ftp-ftp-name name))))))) | |
5106 (if (not (ange-ftp-vms-host host)) | |
5107 (setq ange-ftp-vms-host-regexp | |
5108 (concat "^" (regexp-quote host) "$" | |
5109 (and ange-ftp-vms-host-regexp "\\|") | |
5110 ange-ftp-vms-host-regexp) | |
5111 ange-ftp-host-cache nil))) | |
5112 | |
5113 | |
5114 (defun ange-ftp-vms-file-name-as-directory (name) | |
5115 (save-match-data | |
5116 (if (string-match "\\.\\(DIR\\|dir\\)\\(;[0-9]+\\)?$" name) | |
5117 (setq name (substring name 0 (match-beginning 0)))) | |
5118 (ange-ftp-real-file-name-as-directory name))) | |
5119 | |
5120 (or (assq 'vms ange-ftp-file-name-as-directory-alist) | |
5121 (setq ange-ftp-file-name-as-directory-alist | |
5122 (cons '(vms . ange-ftp-vms-file-name-as-directory) | |
5123 ange-ftp-file-name-as-directory-alist))) | |
5124 | |
5125 ;;; Tree dired support: | |
5126 | |
5127 ;; For this code I have borrowed liberally from Sebastian Kremer's | |
5128 ;; dired-vms.el | |
5129 | |
5130 | |
5131 ;;;; These regexps must be anchored to beginning of line. | |
5132 ;;;; Beware that the ftpd may put the device in front of the filename. | |
5133 | |
5134 ;;(defconst ange-ftp-dired-vms-re-exe "^. [^ \t.]+\\.\\(EXE\\|exe\\)[; ]" | |
5135 ;; "Regular expression to use to search for VMS executable files.") | |
5136 | |
5137 ;;(defconst ange-ftp-dired-vms-re-dir "^. [^ \t.]+\\.\\(DIR\\|dir\\)[; ]" | |
5138 ;; "Regular expression to use to search for VMS directories.") | |
5139 | |
5140 ;;(or (assq 'vms ange-ftp-dired-re-exe-alist) | |
5141 ;; (setq ange-ftp-dired-re-exe-alist | |
5142 ;; (cons (cons 'vms ange-ftp-dired-vms-re-exe) | |
5143 ;; ange-ftp-dired-re-exe-alist))) | |
5144 | |
5145 ;;(or (assq 'vms ange-ftp-dired-re-dir-alist) | |
5146 ;; (setq ange-ftp-dired-re-dir-alist | |
5147 ;; (cons (cons 'vms ange-ftp-dired-vms-re-dir) | |
5148 ;; ange-ftp-dired-re-dir-alist))) | |
5149 | |
5150 ;;(defun ange-ftp-dired-vms-insert-headerline (dir) | |
5151 ;; ;; VMS inserts a headerline. I would prefer the headerline | |
5152 ;; ;; to be in ange-ftp format. This version tries to | |
5153 ;; ;; be careful, because we can't count on a headerline | |
5154 ;; ;; over ftp, and we wouldn't want to delete anything | |
5155 ;; ;; important. | |
5156 ;; (save-excursion | |
5157 ;; (if (looking-at "^ wildcard ") | |
5158 ;; (forward-line 1)) | |
5159 ;; (if (looking-at "^[ \n\t]*[^\n]+\\][ \t]*\n") | |
5160 ;; (delete-region (point) (match-end 0)))) | |
5161 ;; (ange-ftp-real-dired-insert-headerline dir)) | |
5162 | |
5163 ;;(or (assq 'vms ange-ftp-dired-insert-headerline-alist) | |
5164 ;; (setq ange-ftp-dired-insert-headerline-alist | |
5165 ;; (cons '(vms . ange-ftp-dired-vms-insert-headerline) | |
5166 ;; ange-ftp-dired-insert-headerline-alist))) | |
5167 | |
5168 ;;(defun ange-ftp-dired-vms-move-to-filename (&optional raise-error eol) | |
5169 ;; "In dired, move to first char of filename on this line. | |
5170 ;;Returns position (point) or nil if no filename on this line." | |
5171 ;; ;; This is the VMS version. | |
5172 ;; (let (case-fold-search) | |
5173 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5174 ;; (beginning-of-line) | |
5175 ;; (if (re-search-forward ange-ftp-vms-filename-regexp eol t) | |
5176 ;; (goto-char (match-beginning 1)) | |
5177 ;; (if raise-error | |
5178 ;; (error "No file on this line") | |
5179 ;; nil)))) | |
5180 | |
5181 ;;(or (assq 'vms ange-ftp-dired-move-to-filename-alist) | |
5182 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5183 ;; (cons '(vms . ange-ftp-dired-vms-move-to-filename) | |
5184 ;; ange-ftp-dired-move-to-filename-alist))) | |
5185 | |
5186 ;;(defun ange-ftp-dired-vms-move-to-end-of-filename (&optional no-error eol) | |
5187 ;; ;; Assumes point is at beginning of filename. | |
5188 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5189 ;; ;; case-fold-search must be nil, at least for VMS. | |
5190 ;; ;; On failure, signals an error or returns nil. | |
5191 ;; ;; This is the VMS version. | |
5192 ;; (let (opoint hidden case-fold-search) | |
5193 ;; (setq opoint (point)) | |
5194 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
5195 ;; (setq hidden (and selective-display | |
5196 ;; (save-excursion (search-forward "\r" eol t)))) | |
5197 ;; (if hidden | |
5198 ;; nil | |
5199 ;; (re-search-forward ange-ftp-vms-filename-regexp eol t)) | |
5200 ;; (or no-error | |
5201 ;; (not (eq opoint (point))) | |
5202 ;; (error | |
5203 ;; (if hidden | |
5204 ;; (substitute-command-keys | |
5205 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide") | |
5206 ;; "No file on this line"))) | |
5207 ;; (if (eq opoint (point)) | |
5208 ;; nil | |
5209 ;; (point)))) | |
5210 | |
5211 ;;(or (assq 'vms ange-ftp-dired-move-to-end-of-filename-alist) | |
5212 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5213 ;; (cons '(vms . ange-ftp-dired-vms-move-to-end-of-filename) | |
5214 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5215 | |
5216 ;;(defun ange-ftp-dired-vms-between-files () | |
5217 ;; (save-excursion | |
5218 ;; (beginning-of-line) | |
5219 ;; (or (equal (following-char) 10) ; newline | |
5220 ;; (equal (following-char) 9) ; tab | |
5221 ;; (progn (forward-char 2) | |
5222 ;; (or (looking-at "Total of") | |
5223 ;; (equal (following-char) 32)))))) | |
5224 | |
5225 ;;(or (assq 'vms ange-ftp-dired-between-files-alist) | |
5226 ;; (setq ange-ftp-dired-between-files-alist | |
5227 ;; (cons '(vms . ange-ftp-dired-vms-between-files) | |
5228 ;; ange-ftp-dired-between-files-alist))) | |
5229 | |
5230 ;; Beware! In VMS filenames must be of the form "FILE.TYPE". | |
5231 ;; Therefore, we cannot just append a ".Z" to filenames for | |
5232 ;; compressed files. Instead, we turn "FILE.TYPE" into | |
5233 ;; "FILE.TYPE-Z". Hope that this is a reasonable thing to do. | |
5234 | |
5235 (defun ange-ftp-vms-make-compressed-filename (name &optional reverse) | |
5236 (cond | |
5237 ((string-match "-Z;[0-9]+$" name) | |
5238 (list nil (substring name 0 (match-beginning 0)))) | |
5239 ((string-match ";[0-9]+$" name) | |
5240 (list nil (substring name 0 (match-beginning 0)))) | |
5241 ((string-match "-Z$" name) | |
5242 (list nil (substring name 0 -2))) | |
5243 (t | |
5244 (list t | |
5245 (if (string-match ";[0-9]+$" name) | |
5246 (concat (substring name 0 (match-beginning 0)) | |
5247 "-Z") | |
5248 (concat name "-Z")))))) | |
5249 | |
5250 (or (assq 'vms ange-ftp-make-compressed-filename-alist) | |
5251 (setq ange-ftp-make-compressed-filename-alist | |
5252 (cons '(vms . ange-ftp-vms-make-compressed-filename) | |
5253 ange-ftp-make-compressed-filename-alist))) | |
5254 | |
5255 ;;;; When the filename is too long, VMS will use two lines to list a file | |
5256 ;;;; (damn them!) This will confuse dired. To solve this, need to convince | |
5257 ;;;; Sebastian to use a function dired-go-to-end-of-file-line, instead of | |
5258 ;;;; (forward-line 1). This would require a number of changes to dired.el. | |
5259 ;;;; If dired gets confused, revert-buffer will fix it. | |
5260 | |
5261 ;;(defun ange-ftp-dired-vms-ls-trim () | |
5262 ;; (goto-char (point-min)) | |
5263 ;; (let ((case-fold-search nil)) | |
5264 ;; (re-search-forward ange-ftp-vms-filename-regexp)) | |
5265 ;; (beginning-of-line) | |
5266 ;; (delete-region (point-min) (point)) | |
5267 ;; (forward-line 1) | |
5268 ;; (delete-region (point) (point-max))) | |
5269 | |
5270 | |
5271 ;;(or (assq 'vms ange-ftp-dired-ls-trim-alist) | |
5272 ;; (setq ange-ftp-dired-ls-trim-alist | |
5273 ;; (cons '(vms . ange-ftp-dired-vms-ls-trim) | |
30459 | 5274 ;; ange-ftp-dired-ls-trim-alist))) |
28210 | 5275 |
5276 (defun ange-ftp-vms-sans-version (name &rest args) | |
5277 (save-match-data | |
5278 (if (string-match ";[0-9]+$" name) | |
5279 (substring name 0 (match-beginning 0)) | |
5280 name))) | |
5281 | |
5282 (or (assq 'vms ange-ftp-sans-version-alist) | |
5283 (setq ange-ftp-sans-version-alist | |
5284 (cons '(vms . ange-ftp-vms-sans-version) | |
5285 ange-ftp-sans-version-alist))) | |
5286 | |
5287 ;;(defvar ange-ftp-file-version-alist) | |
5288 | |
5289 ;;;;; The vms version of clean-directory has 2 more optional args | |
5290 ;;;;; than the usual dired version. This is so that it can be used by | |
5291 ;;;;; ange-ftp-dired-vms-flag-backup-files. | |
5292 | |
5293 ;;(defun ange-ftp-dired-vms-clean-directory (keep &optional marker msg) | |
5294 ;; "Flag numerical backups for deletion. | |
5295 ;;Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. | |
5296 ;;Positive prefix arg KEEP overrides `dired-kept-versions'; | |
5297 ;;Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive. | |
5298 | |
5299 ;;To clear the flags on these files, you can use \\[dired-flag-backup-files] | |
5300 ;;with a prefix argument." | |
5301 ;;; (interactive "P") ; Never actually called interactively. | |
5302 ;; (setq keep (max 1 (if keep (prefix-numeric-value keep) dired-kept-versions))) | |
5303 ;; (let ((early-retention (if (< keep 0) (- keep) kept-old-versions)) | |
5304 ;; ;; late-retention must NEVER be allowed to be less than 1 in VMS! | |
5305 ;; ;; This could wipe ALL copies of the file. | |
5306 ;; (late-retention (max 1 (if (<= keep 0) dired-kept-versions keep))) | |
5307 ;; (action (or msg "Cleaning")) | |
5308 ;; (ange-ftp-trample-marker (or marker dired-del-marker)) | |
5309 ;; (ange-ftp-file-version-alist ())) | |
5310 ;; (message (concat action | |
5311 ;; " numerical backups (keeping %d late, %d old)...") | |
5312 ;; late-retention early-retention) | |
5313 ;; ;; Look at each file. | |
5314 ;; ;; If the file has numeric backup versions, | |
5315 ;; ;; put on ange-ftp-file-version-alist an element of the form | |
5316 ;; ;; (FILENAME . VERSION-NUMBER-LIST) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5317 ;; (dired-map-dired-file-lines 'ange-ftp-dired-vms-collect-file-versions) |
28210 | 5318 ;; ;; Sort each VERSION-NUMBER-LIST, |
5319 ;; ;; and remove the versions not to be deleted. | |
5320 ;; (let ((fval ange-ftp-file-version-alist)) | |
5321 ;; (while fval | |
5322 ;; (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<))) | |
5323 ;; (v-count (length sorted-v-list))) | |
5324 ;; (if (> v-count (+ early-retention late-retention)) | |
5325 ;; (rplacd (nthcdr early-retention sorted-v-list) | |
5326 ;; (nthcdr (- v-count late-retention) | |
5327 ;; sorted-v-list))) | |
5328 ;; (rplacd (car fval) | |
5329 ;; (cdr sorted-v-list))) | |
5330 ;; (setq fval (cdr fval)))) | |
5331 ;; ;; Look at each file. If it is a numeric backup file, | |
5332 ;; ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion. | |
5333 ;; (dired-map-dired-file-lines | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5334 ;; 'ange-ftp-dired-vms-trample-file-versions mark) |
28210 | 5335 ;; (message (concat action " numerical backups...done")))) |
5336 | |
5337 ;;(or (assq 'vms ange-ftp-dired-clean-directory-alist) | |
5338 ;; (setq ange-ftp-dired-clean-directory-alist | |
5339 ;; (cons '(vms . ange-ftp-dired-vms-clean-directory) | |
5340 ;; ange-ftp-dired-clean-directory-alist))) | |
5341 | |
5342 ;;(defun ange-ftp-dired-vms-collect-file-versions (fn) | |
5343 ;; ;; "If it looks like file FN has versions, return a list of the versions. | |
5344 ;; ;;That is a list of strings which are file names. | |
5345 ;; ;;The caller may want to flag some of these files for deletion." | |
5346 ;;(let ((name (nth 2 (ange-ftp-ftp-name fn)))) | |
5347 ;; (if (string-match ";[0-9]+$" name) | |
5348 ;; (let* ((name (substring name 0 (match-beginning 0))) | |
5349 ;; (fn (ange-ftp-replace-name-component fn name))) | |
5350 ;; (if (not (assq fn ange-ftp-file-version-alist)) | |
5351 ;; (let* ((base-versions | |
5352 ;; (concat (file-name-nondirectory name) ";")) | |
5353 ;; (bv-length (length base-versions)) | |
5354 ;; (possibilities (file-name-all-completions | |
5355 ;; base-versions | |
5356 ;; (file-name-directory fn))) | |
5357 ;; (versions (mapcar | |
5358 ;; '(lambda (arg) | |
5359 ;; (if (and (string-match | |
5360 ;; "[0-9]+$" arg bv-length) | |
5361 ;; (= (match-beginning 0) bv-length)) | |
5362 ;; (string-to-int (substring arg bv-length)) | |
5363 ;; 0)) | |
5364 ;; possibilities))) | |
5365 ;; (if versions | |
5366 ;; (setq | |
5367 ;; ange-ftp-file-version-alist | |
5368 ;; (cons (cons fn versions) | |
5369 ;; ange-ftp-file-version-alist))))))))) | |
5370 | |
5371 ;;(defun ange-ftp-dired-vms-trample-file-versions (fn) | |
5372 ;; (let* ((start-vn (string-match ";[0-9]+$" fn)) | |
5373 ;; base-version-list) | |
5374 ;; (and start-vn | |
5375 ;; (setq base-version-list ; there was a base version to which | |
5376 ;; (assoc (substring fn 0 start-vn) ; this looks like a | |
5377 ;; ange-ftp-file-version-alist)) ; subversion | |
5378 ;; (not (memq (string-to-int (substring fn (1+ start-vn))) | |
5379 ;; base-version-list)) ; this one doesn't make the cut | |
5380 ;; (progn (beginning-of-line) | |
5381 ;; (delete-char 1) | |
5382 ;; (insert ange-ftp-trample-marker))))) | |
5383 | |
5384 ;;(defun ange-ftp-dired-vms-flag-backup-files (&optional unflag-p) | |
5385 ;; (let ((dired-kept-versions 1) | |
5386 ;; (kept-old-versions 0) | |
5387 ;; marker msg) | |
5388 ;; (if unflag-p | |
5389 ;; (setq marker ?\040 msg "Unflagging") | |
5390 ;; (setq marker dired-del-marker msg "Cleaning")) | |
5391 ;; (ange-ftp-dired-vms-clean-directory nil marker msg))) | |
5392 | |
5393 ;;(or (assq 'vms ange-ftp-dired-flag-backup-files-alist) | |
5394 ;; (setq ange-ftp-dired-flag-backup-files-alist | |
5395 ;; (cons '(vms . ange-ftp-dired-vms-flag-backup-files) | |
5396 ;; ange-ftp-dired-flag-backup-files-alist))) | |
5397 | |
5398 ;;(defun ange-ftp-dired-vms-backup-diff (&optional switches) | |
5399 ;; (let ((file (dired-get-filename 'no-dir)) | |
5400 ;; bak) | |
5401 ;; (if (and (string-match ";[0-9]+$" file) | |
5402 ;; ;; Find most recent previous version. | |
5403 ;; (let ((root (substring file 0 (match-beginning 0))) | |
5404 ;; (ver | |
5405 ;; (string-to-int (substring file (1+ (match-beginning 0))))) | |
5406 ;; found) | |
5407 ;; (setq ver (1- ver)) | |
5408 ;; (while (and (> ver 0) (not found)) | |
5409 ;; (setq bak (concat root ";" (int-to-string ver))) | |
5410 ;; (and (file-exists-p bak) (setq found t)) | |
5411 ;; (setq ver (1- ver))) | |
5412 ;; found)) | |
5413 ;; (if switches | |
5414 ;; (diff (expand-file-name bak) (expand-file-name file) switches) | |
5415 ;; (diff (expand-file-name bak) (expand-file-name file))) | |
5416 ;; (error "No previous version found for %s" file)))) | |
5417 | |
5418 ;;(or (assq 'vms ange-ftp-dired-backup-diff-alist) | |
5419 ;; (setq ange-ftp-dired-backup-diff-alist | |
5420 ;; (cons '(vms . ange-ftp-dired-vms-backup-diff) | |
5421 ;; ange-ftp-dired-backup-diff-alist))) | |
5422 | |
5423 | |
5424 ;;;; ------------------------------------------------------------ | |
5425 ;;;; MTS support | |
5426 ;;;; ------------------------------------------------------------ | |
5427 | |
5428 | |
5429 ;; Convert NAME from UNIX-ish to MTS. If REVERSE given then convert from | |
5430 ;; MTS to UNIX-ish. | |
5431 (defun ange-ftp-fix-name-for-mts (name &optional reverse) | |
5432 (save-match-data | |
5433 (if reverse | |
5434 (if (string-match "^\\([^:]+:\\)?\\(.*\\)$" name) | |
5435 (let (acct file) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5436 (setq acct (match-string 1 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5437 (setq file (match-string 2 name)) |
28210 | 5438 (concat (and acct (concat "/" acct "/")) |
5439 file)) | |
5440 (error "name %s didn't match" name)) | |
5441 (if (string-match "^/\\([^:]+:\\)/\\(.*\\)$" name) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5442 (concat (match-string 1 name) (match-string 2 name)) |
28210 | 5443 ;; Let's hope that mts will recognize it anyway. |
5444 name)))) | |
5445 | |
5446 (or (assq 'mts ange-ftp-fix-name-func-alist) | |
5447 (setq ange-ftp-fix-name-func-alist | |
5448 (cons '(mts . ange-ftp-fix-name-for-mts) | |
5449 ange-ftp-fix-name-func-alist))) | |
5450 | |
5451 ;; Convert name from UNIX-ish to MTS ready for a DIRectory listing. | |
5452 ;; Remember that there are no directories in MTS. | |
5453 (defun ange-ftp-fix-dir-name-for-mts (dir-name) | |
5454 (if (string-equal dir-name "/") | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
5455 (error "Cannot get listing for fictitious \"/\" directory") |
28210 | 5456 (let ((dir-name (ange-ftp-fix-name-for-mts dir-name))) |
5457 (cond | |
5458 ((string-equal dir-name "") | |
5459 "?") | |
5460 ((string-match ":$" dir-name) | |
5461 (concat dir-name "?")) | |
5462 (dir-name))))) ; It's just a single file. | |
5463 | |
5464 (or (assq 'mts ange-ftp-fix-dir-name-func-alist) | |
5465 (setq ange-ftp-fix-dir-name-func-alist | |
5466 (cons '(mts . ange-ftp-fix-dir-name-for-mts) | |
5467 ange-ftp-fix-dir-name-func-alist))) | |
5468 | |
5469 (or (memq 'mts ange-ftp-dumb-host-types) | |
5470 (setq ange-ftp-dumb-host-types | |
5471 (cons 'mts ange-ftp-dumb-host-types))) | |
5472 | |
5473 (defvar ange-ftp-mts-host-regexp nil) | |
5474 | |
5475 ;; Return non-nil if HOST is running MTS. | |
5476 (defun ange-ftp-mts-host (host) | |
5477 (and ange-ftp-mts-host-regexp | |
5478 (save-match-data | |
5479 (string-match ange-ftp-mts-host-regexp host)))) | |
5480 | |
5481 ;; Parse the current buffer which is assumed to be in mts ftp dir format. | |
5482 (defun ange-ftp-parse-mts-listing () | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5483 (let ((tbl (make-hash-table :test 'equal))) |
28210 | 5484 (goto-char (point-min)) |
5485 (save-match-data | |
5486 (while (re-search-forward ange-ftp-date-regexp nil t) | |
5487 (end-of-line) | |
5488 (skip-chars-backward " ") | |
5489 (let ((end (point))) | |
5490 (skip-chars-backward "-A-Z0-9_.!") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5491 (puthash (buffer-substring (point) end) nil tbl)) |
28210 | 5492 (forward-line 1))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5493 ;; Don't need to bother with .. |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5494 (puthash "." t tbl) |
28210 | 5495 tbl)) |
5496 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5497 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5498 '(mts . ange-ftp-parse-mts-listing)) |
28210 | 5499 |
5500 (defun ange-ftp-add-mts-host (host) | |
5501 "Mark HOST as the name of a machine running MTS." | |
5502 (interactive | |
5503 (list (read-string "Host: " | |
5504 (let ((name (or (buffer-file-name) default-directory))) | |
5505 (and name (car (ange-ftp-ftp-name name))))))) | |
5506 (if (not (ange-ftp-mts-host host)) | |
5507 (setq ange-ftp-mts-host-regexp | |
5508 (concat "^" (regexp-quote host) "$" | |
5509 (and ange-ftp-mts-host-regexp "\\|") | |
5510 ange-ftp-mts-host-regexp) | |
5511 ange-ftp-host-cache nil))) | |
5512 | |
5513 ;;; Tree dired support: | |
5514 | |
5515 ;;;; There aren't too many systems left that use MTS. This dired support will | |
5516 ;;;; work for the implementation of ftp on mtsg.ubc.ca. I hope other mts systems | |
5517 ;;;; implement ftp in the same way. If not, it might be necessary to make the | |
5518 ;;;; following more flexible. | |
5519 | |
5520 ;;(defun ange-ftp-dired-mts-move-to-filename (&optional raise-error eol) | |
5521 ;; "In dired, move to first char of filename on this line. | |
5522 ;;Returns position (point) or nil if no filename on this line." | |
5523 ;; ;; This is the MTS version. | |
5524 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5525 ;; (beginning-of-line) | |
5526 ;; (if (re-search-forward | |
5527 ;; ange-ftp-date-regexp eol t) | |
5528 ;; (progn | |
5529 ;; (skip-chars-forward " ") ; Eat blanks after date | |
5530 ;; (skip-chars-forward "0-9:" eol) ; Eat time or year | |
5531 ;; (skip-chars-forward " " eol) ; one space before filename | |
5532 ;; ;; When listing an account other than the users own account it appends | |
5533 ;; ;; ACCT: to the beginning of the filename. Skip over this. | |
5534 ;; (and (looking-at "[A-Z0-9_.]+:") | |
5535 ;; (goto-char (match-end 0))) | |
5536 ;; (point)) | |
5537 ;; (if raise-error | |
5538 ;; (error "No file on this line") | |
5539 ;; nil))) | |
5540 | |
5541 ;;(or (assq 'mts ange-ftp-dired-move-to-filename-alist) | |
5542 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5543 ;; (cons '(mts . ange-ftp-dired-mts-move-to-filename) | |
5544 ;; ange-ftp-dired-move-to-filename-alist))) | |
5545 | |
5546 ;;(defun ange-ftp-dired-mts-move-to-end-of-filename (&optional no-error eol) | |
5547 ;; ;; Assumes point is at beginning of filename. | |
5548 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5549 ;; ;; On failure, signals an error or returns nil. | |
5550 ;; ;; This is the MTS version. | |
5551 ;; (let (opoint hidden case-fold-search) | |
5552 ;; (setq opoint (point) | |
5553 ;; eol (save-excursion (end-of-line) (point)) | |
5554 ;; hidden (and selective-display | |
5555 ;; (save-excursion (search-forward "\r" eol t)))) | |
5556 ;; (if hidden | |
5557 ;; nil | |
5558 ;; (skip-chars-forward "-A-Z0-9._!" eol)) | |
5559 ;; (or no-error | |
5560 ;; (not (eq opoint (point))) | |
5561 ;; (error | |
5562 ;; (if hidden | |
5563 ;; (substitute-command-keys | |
5564 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide") | |
5565 ;; "No file on this line"))) | |
5566 ;; (if (eq opoint (point)) | |
5567 ;; nil | |
5568 ;; (point)))) | |
5569 | |
5570 ;;(or (assq 'mts ange-ftp-dired-move-to-end-of-filename-alist) | |
5571 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5572 ;; (cons '(mts . ange-ftp-dired-mts-move-to-end-of-filename) | |
5573 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5574 | |
5575 ;;;; ------------------------------------------------------------ | |
5576 ;;;; CMS support | |
5577 ;;;; ------------------------------------------------------------ | |
5578 | |
5579 ;; Since CMS doesn't have any full file name syntax, we have to fudge | |
5580 ;; things with cd's. We actually send too many cd's, but it's dangerous | |
5581 ;; to try to remember the current minidisk, because if the connection | |
5582 ;; is closed and needs to be reopened, we will find ourselves back in | |
5583 ;; the default minidisk. This is fairly likely since CMS ftp servers | |
5584 ;; usually close the connection after 5 minutes of inactivity. | |
5585 | |
5586 ;; Have I got the filename character set right? | |
5587 | |
5588 (defun ange-ftp-fix-name-for-cms (name &optional reverse) | |
5589 (save-match-data | |
5590 (if reverse | |
5591 ;; Since we only convert output from a pwd in this direction, | |
5592 ;; we'll assume that it's a minidisk, and make it into a | |
5593 ;; directory file name. Note that the expand-dir-hashtable | |
5594 ;; stores directories without the trailing /. Is this | |
5595 ;; consistent? | |
5596 (concat "/" name) | |
5597 (if (string-match "^/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?$" | |
5598 name) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5599 (let ((minidisk (match-string 1 name))) |
28210 | 5600 (if (match-beginning 2) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5601 (let ((file (match-string 2 name)) |
28210 | 5602 (cmd (concat "cd " minidisk)) |
5603 | |
5604 ;; Note that host and user are bound in the call | |
5605 ;; to ange-ftp-send-cmd | |
5606 (proc (ange-ftp-get-process ange-ftp-this-host | |
5607 ange-ftp-this-user))) | |
5608 | |
5609 ;; Must use ange-ftp-raw-send-cmd here to avoid | |
5610 ;; an infinite loop. | |
5611 (if (car (ange-ftp-raw-send-cmd proc cmd ange-ftp-this-msg)) | |
5612 file | |
5613 ;; failed... try ONCE more. | |
5614 (setq proc (ange-ftp-get-process ange-ftp-this-host | |
5615 ange-ftp-this-user)) | |
5616 (let ((result (ange-ftp-raw-send-cmd proc cmd | |
5617 ange-ftp-this-msg))) | |
5618 (if (car result) | |
5619 file | |
5620 ;; failed. give up. | |
5621 (ange-ftp-error ange-ftp-this-host ange-ftp-this-user | |
5622 (format "cd to minidisk %s failed: %s" | |
5623 minidisk (cdr result))))))) | |
5624 ;; return the minidisk | |
5625 minidisk)) | |
5626 (error "Invalid CMS filename"))))) | |
5627 | |
5628 (or (assq 'cms ange-ftp-fix-name-func-alist) | |
5629 (setq ange-ftp-fix-name-func-alist | |
5630 (cons '(cms . ange-ftp-fix-name-for-cms) | |
5631 ange-ftp-fix-name-func-alist))) | |
5632 | |
5633 (or (memq 'cms ange-ftp-dumb-host-types) | |
5634 (setq ange-ftp-dumb-host-types | |
5635 (cons 'cms ange-ftp-dumb-host-types))) | |
5636 | |
5637 ;; Convert name from UNIX-ish to CMS ready for a DIRectory listing. | |
5638 (defun ange-ftp-fix-dir-name-for-cms (dir-name) | |
5639 (cond | |
5640 ((string-equal "/" dir-name) | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
5641 (error "Cannot get listing for fictitious \"/\" directory")) |
28210 | 5642 ((string-match "^/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?$" dir-name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5643 (let* ((minidisk (match-string 1 dir-name)) |
28210 | 5644 ;; host and user are bound in the call to ange-ftp-send-cmd |
5645 (proc (ange-ftp-get-process ange-ftp-this-host ange-ftp-this-user)) | |
5646 (cmd (concat "cd " minidisk)) | |
5647 (file (if (match-beginning 2) | |
5648 ;; it's a single file | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5649 (match-string 2 dir-name) |
28210 | 5650 ;; use the wild-card |
5651 "*"))) | |
5652 (if (car (ange-ftp-raw-send-cmd proc cmd)) | |
5653 file | |
5654 ;; try again... | |
5655 (setq proc (ange-ftp-get-process ange-ftp-this-host | |
5656 ange-ftp-this-user)) | |
5657 (let ((result (ange-ftp-raw-send-cmd proc cmd))) | |
5658 (if (car result) | |
5659 file | |
5660 ;; give up | |
5661 (ange-ftp-error ange-ftp-this-host ange-ftp-this-user | |
5662 (format "cd to minidisk %s failed: %s" | |
5663 minidisk (cdr result)))))))) | |
5664 (t (error "Invalid CMS file name")))) | |
5665 | |
5666 (or (assq 'cms ange-ftp-fix-dir-name-func-alist) | |
5667 (setq ange-ftp-fix-dir-name-func-alist | |
5668 (cons '(cms . ange-ftp-fix-dir-name-for-cms) | |
5669 ange-ftp-fix-dir-name-func-alist))) | |
5670 | |
5671 (defvar ange-ftp-cms-host-regexp nil | |
5672 "Regular expression to match hosts running the CMS operating system.") | |
5673 | |
5674 ;; Return non-nil if HOST is running CMS. | |
5675 (defun ange-ftp-cms-host (host) | |
5676 (and ange-ftp-cms-host-regexp | |
5677 (save-match-data | |
5678 (string-match ange-ftp-cms-host-regexp host)))) | |
5679 | |
5680 (defun ange-ftp-add-cms-host (host) | |
5681 "Mark HOST as the name of a CMS host." | |
5682 (interactive | |
5683 (list (read-string "Host: " | |
5684 (let ((name (or (buffer-file-name) default-directory))) | |
5685 (and name (car (ange-ftp-ftp-name name))))))) | |
5686 (if (not (ange-ftp-cms-host host)) | |
5687 (setq ange-ftp-cms-host-regexp | |
5688 (concat "^" (regexp-quote host) "$" | |
5689 (and ange-ftp-cms-host-regexp "\\|") | |
5690 ange-ftp-cms-host-regexp) | |
5691 ange-ftp-host-cache nil))) | |
5692 | |
5693 (defun ange-ftp-parse-cms-listing () | |
5694 ;; Parse the current buffer which is assumed to be a CMS directory listing. | |
5695 ;; If we succeed in getting a listing, then we will assume that the minidisk | |
5696 ;; exists. file is bound by the call to ange-ftp-ls. This doesn't work | |
5697 ;; because ange-ftp doesn't know that the root hashtable has only part of | |
5698 ;; the info. It will assume that if a minidisk isn't in it, then it doesn't | |
5699 ;; exist. It would be nice if completion worked for minidisks, as we | |
5700 ;; discover them. | |
5701 ; (let* ((dir-file (directory-file-name file)) | |
5702 ; (root (file-name-directory dir-file)) | |
5703 ; (minidisk (ange-ftp-get-file-part dir-file)) | |
5704 ; (root-tbl (ange-ftp-get-hash-entry root ange-ftp-files-hashtable))) | |
5705 ; (if root-tbl | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5706 ; (puthash minidisk t root-tbl) |
28210 | 5707 ; (setq root-tbl (ange-ftp-make-hashtable)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5708 ; (puthash minidisk t root-tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5709 ; (puthash "." t root-tbl) |
28210 | 5710 ; (ange-ftp-set-files root root-tbl))) |
5711 ;; Now do the usual parsing | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5712 (let ((tbl (make-hash-table :test 'equal))) |
28210 | 5713 (goto-char (point-min)) |
5714 (save-match-data | |
5715 (while | |
5716 (re-search-forward | |
5717 "^\\([-A-Z0-9$_]+\\) +\\([-A-Z0-9$_]+\\) +[VF] +[0-9]+ " nil t) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5718 (puthash (concat (match-string 1) "." (match-string 2)) nil tbl) |
28210 | 5719 (forward-line 1)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5720 (puthash "." t tbl)) |
28210 | 5721 tbl)) |
5722 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5723 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5724 '(cms . ange-ftp-parse-cms-listing)) |
30459 | 5725 |
28210 | 5726 ;;;;; Tree dired support: |
5727 | |
5728 ;;(defconst ange-ftp-dired-cms-re-exe | |
5729 ;; "^. [-A-Z0-9$_]+ +EXEC " | |
5730 ;; "Regular expression to use to search for CMS executables.") | |
5731 | |
5732 ;;(or (assq 'cms ange-ftp-dired-re-exe-alist) | |
5733 ;; (setq ange-ftp-dired-re-exe-alist | |
5734 ;; (cons (cons 'cms ange-ftp-dired-cms-re-exe) | |
5735 ;; ange-ftp-dired-re-exe-alist))) | |
5736 | |
5737 | |
5738 ;;(defun ange-ftp-dired-cms-insert-headerline (dir) | |
5739 ;; ;; CMS has no total line, so we insert a blank line for | |
5740 ;; ;; aesthetics. | |
5741 ;; (insert "\n") | |
5742 ;; (forward-char -1) | |
5743 ;; (ange-ftp-real-dired-insert-headerline dir)) | |
5744 | |
5745 ;;(or (assq 'cms ange-ftp-dired-insert-headerline-alist) | |
5746 ;; (setq ange-ftp-dired-insert-headerline-alist | |
5747 ;; (cons '(cms . ange-ftp-dired-cms-insert-headerline) | |
5748 ;; ange-ftp-dired-insert-headerline-alist))) | |
5749 | |
5750 ;;(defun ange-ftp-dired-cms-move-to-filename (&optional raise-error eol) | |
5751 ;; "In dired, move to the first char of filename on this line." | |
5752 ;; ;; This is the CMS version. | |
5753 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5754 ;; (let (case-fold-search) | |
5755 ;; (beginning-of-line) | |
5756 ;; (if (re-search-forward " [-A-Z0-9$_]+ +[-A-Z0-9$_]+ +[VF] +[0-9]+ " eol t) | |
5757 ;; (goto-char (1+ (match-beginning 0))) | |
5758 ;; (if raise-error | |
5759 ;; (error "No file on this line") | |
5760 ;; nil)))) | |
5761 | |
5762 ;;(or (assq 'cms ange-ftp-dired-move-to-filename-alist) | |
5763 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5764 ;; (cons '(cms . ange-ftp-dired-cms-move-to-filename) | |
5765 ;; ange-ftp-dired-move-to-filename-alist))) | |
5766 | |
5767 ;;(defun ange-ftp-dired-cms-move-to-end-of-filename (&optional no-error eol) | |
5768 ;; ;; Assumes point is at beginning of filename. | |
5769 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5770 ;; ;; case-fold-search must be nil, at least for VMS. | |
5771 ;; ;; On failure, signals an error or returns nil. | |
5772 ;; ;; This is the CMS version. | |
5773 ;; (let ((opoint (point)) | |
5774 ;; case-fold-search hidden) | |
5775 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
5776 ;; (setq hidden (and selective-display | |
5777 ;; (save-excursion | |
5778 ;; (search-forward "\r" eol t)))) | |
5779 ;; (if hidden | |
5780 ;; (if no-error | |
5781 ;; nil | |
5782 ;; (error | |
5783 ;; (substitute-command-keys | |
5784 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide"))) | |
5785 ;; (skip-chars-forward "-A-Z0-9$_" eol) | |
5786 ;; (skip-chars-forward " " eol) | |
5787 ;; (skip-chars-forward "-A-Z0-9$_" eol) | |
5788 ;; (if (eq opoint (point)) | |
5789 ;; (if no-error | |
5790 ;; nil | |
5791 ;; (error "No file on this line")) | |
5792 ;; (point))))) | |
5793 | |
5794 ;;(or (assq 'cms ange-ftp-dired-move-to-end-of-filename-alist) | |
5795 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5796 ;; (cons '(cms . ange-ftp-dired-cms-move-to-end-of-filename) | |
5797 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5798 | |
5799 (defun ange-ftp-cms-make-compressed-filename (name &optional reverse) | |
5800 (if (string-match "-Z$" name) | |
5801 (list nil (substring name 0 -2)) | |
5802 (list t (concat name "-Z")))) | |
5803 | |
5804 (or (assq 'cms ange-ftp-make-compressed-filename-alist) | |
5805 (setq ange-ftp-make-compressed-filename-alist | |
5806 (cons '(cms . ange-ftp-cms-make-compressed-filename) | |
5807 ange-ftp-make-compressed-filename-alist))) | |
5808 | |
5809 ;;(defun ange-ftp-dired-cms-get-filename (&optional localp no-error-if-not-filep) | |
5810 ;; (let ((name (ange-ftp-real-dired-get-filename localp no-error-if-not-filep))) | |
5811 ;; (and name | |
5812 ;; (if (string-match "^\\([^ ]+\\) +\\([^ ]+\\)$" name) | |
5813 ;; (concat (substring name 0 (match-end 1)) | |
5814 ;; "." | |
5815 ;; (substring name (match-beginning 2) (match-end 2))) | |
5816 ;; name)))) | |
5817 | |
5818 ;;(or (assq 'cms ange-ftp-dired-get-filename-alist) | |
5819 ;; (setq ange-ftp-dired-get-filename-alist | |
5820 ;; (cons '(cms . ange-ftp-dired-cms-get-filename) | |
5821 ;; ange-ftp-dired-get-filename-alist))) | |
5822 | |
5823 ;;;; ------------------------------------------------------------ | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5824 ;;;; BS2000 support |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5825 ;;;; ------------------------------------------------------------ |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5826 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5827 ;; There seems to be an error with regexps. '-' has to be the first |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5828 ;; character inside of the square brackets. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5829 (defconst ange-ftp-bs2000-short-filename-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5830 "[-A-Z0-9$#@.]*[A-Z][-A-Z0-9$#@.]*" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5831 "Regular expression to match for a valid short BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5832 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5833 (defconst ange-ftp-bs2000-fix-name-regexp-reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5834 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5835 "^\\(" ange-ftp-bs2000-filename-pubset-regexp "\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5836 "\\(" ange-ftp-bs2000-filename-username-regexp "\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5837 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)?") |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5838 "Regular expression used in ange-ftp-fix-name-for-bs2000.") |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5839 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5840 (defconst ange-ftp-bs2000-fix-name-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5841 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5842 "/?\\(" ange-ftp-bs2000-filename-pubset-regexp "/\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5843 "\\(\\$[A-Z0-9]*/\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5844 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)?") |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5845 "Regular expression used in ange-ftp-fix-name-for-bs2000.") |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5846 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5847 (defcustom ange-ftp-bs2000-special-prefix |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5848 "X" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5849 "*Prefix used for filenames starting with '#' or '@'." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5850 :group 'ange-ftp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5851 :type 'string) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5852 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5853 ;; Convert NAME from UNIX-ish to BS2000. If REVERSE given then convert from |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5854 ;; BS2000 to UNIX-ish. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5855 (defun ange-ftp-fix-name-for-bs2000 (name &optional reverse) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5856 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5857 (if reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5858 (if (string-match |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5859 ange-ftp-bs2000-fix-name-regexp-reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5860 name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5861 (let ((pubset (if (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5862 (substring name 0 (match-end 1)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5863 (userid (if (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5864 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5865 (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5866 (1- (match-end 2))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5867 (filename (if (match-beginning 3) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5868 (substring name (match-beginning 3))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5869 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5870 "/" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5871 ;; we have to insert "_/" here to prevent expand-file-name to |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5872 ;; interpret BS2000 pubsets as the special escape prefix: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5873 (and pubset (concat "_/" pubset "/")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5874 (and userid (concat userid "/")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5875 filename)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5876 (error "name %s didn't match" name)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5877 ;; and here we (maybe) have to remove the inserted "_/" 'cause |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5878 ;; of our prevention of the special escape prefix above: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5879 (if (string-match (concat "^/_/") name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5880 (setq name (substring name 2))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5881 (if (string-match |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5882 ange-ftp-bs2000-fix-name-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5883 name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5884 (let ((pubset (if (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5885 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5886 (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5887 (1- (match-end 1))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5888 (userid (if (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5889 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5890 (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5891 (1- (match-end 2))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5892 (filename (if (match-beginning 3) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5893 (substring name (match-beginning 3))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5894 (if (and (boundp 'filename) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5895 (stringp filename) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5896 (string-match "[#@].+" filename)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5897 (setq filename (concat ange-ftp-bs2000-special-prefix |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5898 (substring filename 1)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5899 (upcase |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5900 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5901 pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5902 (and userid (concat userid ".")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5903 ;; change every '/' in filename to a '.', normally not neccessary |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5904 (and filename |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5905 (subst-char-in-string ?/ ?. filename))))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5906 ;; Let's hope that BS2000 recognize this anyway: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5907 name)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5908 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5909 (or (assq 'bs2000 ange-ftp-fix-name-func-alist) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5910 (setq ange-ftp-fix-name-func-alist |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5911 (cons '(bs2000 . ange-ftp-fix-name-for-bs2000) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5912 ange-ftp-fix-name-func-alist))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5913 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5914 ;; Convert name from UNIX-ish to BS2000 ready for a DIRectory listing. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5915 ;; Remember that there are no directories in BS2000. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5916 (defun ange-ftp-fix-dir-name-for-bs2000 (dir-name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5917 (if (string-equal dir-name "/") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5918 "*" ;; Don't use an empty string here! |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5919 (ange-ftp-fix-name-for-bs2000 dir-name))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5920 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5921 (or (assq 'bs2000 ange-ftp-fix-dir-name-func-alist) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5922 (setq ange-ftp-fix-dir-name-func-alist |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5923 (cons '(bs2000 . ange-ftp-fix-dir-name-for-bs2000) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5924 ange-ftp-fix-dir-name-func-alist))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5925 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5926 (or (memq 'bs2000 ange-ftp-dumb-host-types) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5927 (setq ange-ftp-dumb-host-types |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5928 (cons 'bs2000 ange-ftp-dumb-host-types))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5929 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5930 (defvar ange-ftp-bs2000-host-regexp nil) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5931 (defvar ange-ftp-bs2000-posix-host-regexp nil) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5932 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5933 ;; Return non-nil if HOST is running BS2000. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5934 (defun ange-ftp-bs2000-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5935 (and ange-ftp-bs2000-host-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5936 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5937 (string-match ange-ftp-bs2000-host-regexp host)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5938 ;; Return non-nil if HOST is running BS2000 with POSIX subsystem. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5939 (defun ange-ftp-bs2000-posix-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5940 (and ange-ftp-bs2000-posix-host-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5941 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5942 (string-match ange-ftp-bs2000-posix-host-regexp host)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5943 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5944 (defun ange-ftp-add-bs2000-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5945 "Mark HOST as the name of a machine running BS2000." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5946 (interactive |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5947 (list (read-string "Host: " |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5948 (let ((name (or (buffer-file-name) default-directory))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5949 (and name (car (ange-ftp-ftp-name name))))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5950 (if (not (ange-ftp-bs2000-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5951 (setq ange-ftp-bs2000-host-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5952 (concat "^" (regexp-quote host) "$" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5953 (and ange-ftp-bs2000-host-regexp "\\|") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5954 ange-ftp-bs2000-host-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5955 ange-ftp-host-cache nil))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5956 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5957 (defun ange-ftp-add-bs2000-posix-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5958 "Mark HOST as the name of a machine running BS2000 with POSIX subsystem." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5959 (interactive |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5960 (list (read-string "Host: " |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5961 (let ((name (or (buffer-file-name) default-directory))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5962 (and name (car (ange-ftp-ftp-name name))))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5963 (if (not (ange-ftp-bs2000-posix-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5964 (setq ange-ftp-bs2000-posix-host-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5965 (concat "^" (regexp-quote host) "$" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5966 (and ange-ftp-bs2000-posix-host-regexp "\\|") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5967 ange-ftp-bs2000-posix-host-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5968 ange-ftp-host-cache nil)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5969 ;; Install CD hook to cd to posix on connecting: |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5970 (add-hook 'ange-ftp-process-startup-hook 'ange-ftp-bs2000-cd-to-posix) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5971 host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5972 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5973 (defconst ange-ftp-bs2000-filename-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5974 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5975 "\\(" ange-ftp-bs2000-filename-prefix-regexp "\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5976 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5977 "Regular expression to match for a valid BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5978 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5979 (defcustom ange-ftp-bs2000-additional-pubsets |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5980 nil |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5981 "*List of additional pubsets available to all users." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5982 :group 'ange-ftp |
44953
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
5983 :type '(repeat string)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5984 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5985 ;; These parsing functions are as general as possible because the syntax |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5986 ;; of ftp listings from BS2000 hosts is a bit erratic. What saves us is that |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5987 ;; the BS2000 filename syntax is so rigid. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5988 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5989 ;; Extract the next filename from a BS2000 dired-like listing. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5990 (defun ange-ftp-parse-bs2000-filename () |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5991 (if (re-search-forward ange-ftp-bs2000-filename-regexp nil t) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5992 (match-string 2))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5993 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5994 ;; Parse the current buffer which is assumed to be in (some) BS2000 FTP dir |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5995 ;; format, and return a hashtable as the result. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5996 (defun ange-ftp-parse-bs2000-listing () |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5997 (let ((tbl (make-hash-table :test 'equal)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5998 pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5999 file) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6000 ;; get current pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6001 (goto-char (point-min)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6002 (if (re-search-forward ange-ftp-bs2000-filename-pubset-regexp nil t) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6003 (setq pubset (match-string 0))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6004 ;; add files to hashtable |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6005 (goto-char (point-min)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6006 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6007 (while (setq file (ange-ftp-parse-bs2000-filename)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6008 (puthash file nil tbl))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6009 ;; add . and .. |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6010 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6011 (puthash ".." t tbl) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6012 ;; add all additional pubsets, if not listing one of them |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6013 (if (not (member pubset ange-ftp-bs2000-additional-pubsets)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6014 (mapcar (lambda (pubset) (puthash pubset t tbl)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6015 ange-ftp-bs2000-additional-pubsets)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6016 tbl)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6017 |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6018 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6019 '(bs2000 . ange-ftp-parse-bs2000-listing)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6020 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6021 (defun ange-ftp-bs2000-cd-to-posix () |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6022 "cd to POSIX subsystem if the current host matches |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6023 `ange-ftp-bs2000-posix-host-regexp'. All BS2000 hosts with POSIX subsystem |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6024 MUST BE EXPLICITLY SET with `ange-ftp-add-bs2000-posix-host' for they cannot |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6025 be recognized automatically (they are all valid BS2000 hosts too)." |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6026 (if (and ange-ftp-this-host (ange-ftp-bs2000-posix-host ange-ftp-this-host)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6027 (progn |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6028 ;; change to POSIX: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6029 ; (ange-ftp-raw-send-cmd proc "cd %POSIX") |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6030 (ange-ftp-cd ange-ftp-this-host ange-ftp-this-user "%POSIX") |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6031 ;; put new home directory in the expand-dir hashtable. |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6032 ;; `ange-ftp-this-host' and `ange-ftp-this-user' are bound in |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6033 ;; ange-ftp-get-process. |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6034 (puthash (concat ange-ftp-this-host "/" ange-ftp-this-user "/~") |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6035 (car (ange-ftp-get-pwd ange-ftp-this-host ange-ftp-this-user)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6036 ange-ftp-expand-dir-hashtable)))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6037 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6038 ;; Not available yet: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6039 ;; ange-ftp-bs2000-delete-file-entry |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6040 ;; ange-ftp-bs2000-add-file-entry |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6041 ;; ange-ftp-bs2000-file-name-as-directory |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6042 ;; ange-ftp-bs2000-make-compressed-filename |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6043 ;; ange-ftp-bs2000-file-name-sans-versions |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6044 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6045 ;;;; ------------------------------------------------------------ |
28210 | 6046 ;;;; Finally provide package. |
6047 ;;;; ------------------------------------------------------------ | |
6048 | |
6049 (provide 'ange-ftp) | |
6050 | |
6051 ;;; ange-ftp.el ends here |