Mercurial > emacs
annotate lisp/net/ange-ftp.el @ 93068:3ca0c43ea37d
(run_funs): New fun.
(run_window_configuration_change_hook): Use it to run the buffer-local
and the global part of the hook.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 19 Mar 2008 15:18:30 +0000 |
parents | f991f10f15ec |
children | 91e5880a36c1 |
rev | line source |
---|---|
28210 | 1 ;;; ange-ftp.el --- transparent FTP support for GNU Emacs |
2 | |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64667
diff
changeset
|
3 ;; Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, |
79714 | 4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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 | |
78230
84cf1e2214c5
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
76407
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
28210 | 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 | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
28210 | 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 ;; | |
80044
b62f4b92bc13
*** empty log message ***
Juanma Barranquero <lekktu@gmail.com>
parents:
79714
diff
changeset
|
300 ;; A valid VMS filename is of the form: FILE.TYPE;## |
28210 | 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 | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
689 '("\\`/\\(\\([^/:]*\\)@\\)?\\([^@/:]*[^@/:.]\\):\\(.*\\)" . (3 2 4)) |
28210 | 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 | |
53388
29c86aab2fa2
(ange-ftp-name-format): Allow USER to contain
Eli Zaretskii <eliz@is.elta.co.il>
parents:
53351
diff
changeset
|
697 :type '(list (regexp :tag "Name 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 | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
746 (defcustom ange-ftp-potential-error-msgs |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
747 ;; On Mac OS X we sometimes get things like: |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64667
diff
changeset
|
748 ;; |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
749 ;; ftp> open ftp.nluug.nl |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
750 ;; Trying 2001:610:1:80aa:192:87:102:36... |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
751 ;; ftp: connect to address 2001:610:1:80aa:192:87:102:36: No route to host |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
752 ;; Trying 192.87.102.36... |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
753 ;; Connected to ftp.nluug.nl. |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
754 "^ftp: connect to address .*: No route to host" |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
755 "*Regular expression matching ftp messages that can indicate serious errors. |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
756 These mean that something went wrong, but they may be followed by more |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
757 messages indicating that the error was somehow corrected." |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
758 :group 'ange-ftp |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
759 :type 'regexp) |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
760 |
28210 | 761 (defcustom ange-ftp-gateway-fatal-msgs |
762 "No route to host\\|Connection closed\\|No such host\\|Login incorrect" | |
763 "*Regular expression matching login failure messages from rlogin/telnet." | |
764 :group 'ange-ftp | |
765 :type 'regexp) | |
766 | |
767 (defcustom ange-ftp-xfer-size-msgs | |
768 "^150 .* connection for .* (\\([0-9]+\\) bytes)" | |
769 "*Regular expression used to determine the number of bytes in a FTP transfer." | |
770 :group 'ange-ftp | |
771 :type 'regexp) | |
772 | |
30459 | 773 (defcustom ange-ftp-tmp-name-template |
28210 | 774 (expand-file-name "ange-ftp" temporary-file-directory) |
775 "*Template used to create temporary files." | |
776 :group 'ange-ftp | |
777 :type 'directory) | |
778 | |
779 (defcustom ange-ftp-gateway-tmp-name-template "/tmp/ange-ftp" | |
780 "*Template used to create temporary files when ftp-ing through a gateway. | |
781 | |
782 Files starting with this prefix need to be accessible from BOTH the local | |
783 machine and the gateway machine, and need to have the SAME name on both | |
784 machines, that is, /tmp is probably NOT what you want, since that is rarely | |
785 cross-mounted." | |
786 :group 'ange-ftp | |
787 :type 'directory) | |
788 | |
789 (defcustom ange-ftp-netrc-filename "~/.netrc" | |
790 "*File in .netrc format to search for passwords." | |
791 :group 'ange-ftp | |
792 :type 'file) | |
793 | |
794 (defcustom ange-ftp-disable-netrc-security-check (eq system-type 'windows-nt) | |
795 "*If non-nil avoid checking permissions on the .netrc file." | |
796 :group 'ange-ftp | |
797 :type 'boolean) | |
798 | |
799 (defcustom ange-ftp-default-user nil | |
800 "*User name to use when none is specified in a file name. | |
801 | |
802 If non-nil but not a string, you are prompted for the name. | |
803 If nil, the value of `ange-ftp-netrc-default-user' is used. | |
804 If that is nil too, then your login name is used. | |
805 | |
806 Once a connection to a given host has been initiated, the user name | |
807 and password information for that host are cached and re-used by | |
808 ange-ftp. Use \\[ange-ftp-set-user] to change the cached values, | |
809 since setting `ange-ftp-default-user' directly does not affect | |
810 the cached information." | |
811 :group 'ange-ftp | |
812 :type '(choice (const :tag "Default" nil) | |
813 string | |
814 (other :tag "Prompt" t))) | |
815 | |
816 (defcustom ange-ftp-netrc-default-user nil | |
817 "Alternate default user name to use when none is specified. | |
818 | |
819 This variable is set from the `default' command in your `.netrc' file, | |
820 if there is one." | |
821 :group 'ange-ftp | |
822 :type '(choice (const :tag "Default" nil) | |
823 string)) | |
824 | |
825 (defcustom ange-ftp-default-password nil | |
826 "*Password to use when the user name equals `ange-ftp-default-user'." | |
827 :group 'ange-ftp | |
828 :type '(choice (const :tag "Default" nil) | |
829 string)) | |
830 | |
831 (defcustom ange-ftp-default-account nil | |
832 "*Account to use when the user name equals `ange-ftp-default-user'." | |
833 :group 'ange-ftp | |
834 :type '(choice (const :tag "Default" nil) | |
835 string)) | |
836 | |
837 (defcustom ange-ftp-netrc-default-password nil | |
838 "*Password to use when the user name equals `ange-ftp-netrc-default-user'." | |
839 :group 'ange-ftp | |
840 :type '(choice (const :tag "Default" nil) | |
841 string)) | |
842 | |
843 (defcustom ange-ftp-netrc-default-account nil | |
844 "*Account to use when the user name equals `ange-ftp-netrc-default-user'." | |
845 :group 'ange-ftp | |
846 :type '(choice (const :tag "Default" nil) | |
847 string)) | |
848 | |
849 (defcustom ange-ftp-generate-anonymous-password t | |
850 "*If t, use value of `user-mail-address' as password for anonymous ftp. | |
851 | |
852 If a string, then use that string as the password. | |
853 If nil, prompt the user for a password." | |
854 :group 'ange-ftp | |
855 :type '(choice (const :tag "Prompt" nil) | |
856 string | |
857 (other :tag "User address" t))) | |
858 | |
859 (defcustom ange-ftp-dumb-unix-host-regexp nil | |
860 "*If non-nil, regexp matching hosts on which `dir' command lists directory." | |
861 :group 'ange-ftp | |
862 :type '(choice (const :tag "Default" nil) | |
863 string)) | |
864 | |
865 (defcustom ange-ftp-binary-file-name-regexp | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
866 (concat "TAGS\\'\\|\\.\\(?:" |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
867 (eval-when-compile |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
868 (regexp-opt '("z" "Z" "lzh" "arc" "zip" "zoo" "tar" "dvi" |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
869 "ps" "elc" "gif" "gz" "taz" "tgz"))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
870 "\\|EXE\\(;[0-9]+\\)?\\|[zZ]-part-..\\)\\'") |
28210 | 871 "*If a file matches this regexp then it is transferred in binary mode." |
872 :group 'ange-ftp | |
873 :type 'regexp) | |
874 | |
875 (defcustom ange-ftp-gateway-host nil | |
876 "*Name of host to use as gateway machine when local FTP isn't possible." | |
877 :group 'ange-ftp | |
878 :type '(choice (const :tag "Default" nil) | |
879 string)) | |
880 | |
881 (defcustom ange-ftp-local-host-regexp ".*" | |
882 "*Regexp selecting hosts which can be reached directly with ftp. | |
883 | |
884 For other hosts the FTP process is started on \`ange-ftp-gateway-host\' | |
885 instead, and/or reached via \`ange-ftp-gateway-ftp-program-name\'." | |
886 :group 'ange-ftp | |
887 :type 'regexp) | |
888 | |
889 (defcustom ange-ftp-gateway-program-interactive nil | |
890 "*If non-nil then the gateway program should give a shell prompt. | |
891 | |
892 Both telnet and rlogin do something like this." | |
893 :group 'ange-ftp | |
894 :type 'boolean) | |
895 | |
896 (defcustom ange-ftp-gateway-program remote-shell-program | |
897 "*Name of program to spawn a shell on the gateway machine. | |
898 | |
899 Valid candidates are rsh (remsh on some systems), telnet and rlogin. See | |
900 also the gateway variable above." | |
901 :group 'ange-ftp | |
902 :type '(choice (const "rsh") | |
903 (const "telnet") | |
904 (const "rlogin") | |
905 string)) | |
906 | |
907 (defcustom ange-ftp-gateway-prompt-pattern "^[^#$%>;\n]*[#$%>;] *" | |
908 "*Regexp matching prompt after complete login sequence on gateway machine. | |
909 | |
910 A match for this means the shell is now awaiting input. Make this regexp as | |
911 strict as possible; it shouldn't match *anything* at all except the user's | |
912 initial prompt. The above string will fail under most SUN-3's since it | |
913 matches the login banner." | |
914 :group 'ange-ftp | |
915 :type 'regexp) | |
916 | |
917 (defvar ange-ftp-gateway-setup-term-command | |
918 (if (eq system-type 'hpux) | |
919 "stty -onlcr -echo\n" | |
920 "stty -echo nl\n") | |
921 "*Set up terminal after logging in to the gateway machine. | |
922 This command should stop the terminal from echoing each command, and | |
923 arrange to strip out trailing ^M characters.") | |
924 | |
925 (defcustom ange-ftp-smart-gateway nil | |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
926 "*Non-nil says the ftp gateway (proxy) or gateway ftp program is smart. |
28210 | 927 |
928 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
|
929 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
|
930 See also `ange-ftp-smart-gateway-port'." |
28210 | 931 :group 'ange-ftp |
932 :type 'boolean) | |
933 | |
934 (defcustom ange-ftp-smart-gateway-port "21" | |
935 "*Port on gateway machine to use when smart gateway is in operation." | |
936 :group 'ange-ftp | |
937 :type 'string) | |
938 | |
939 (defcustom ange-ftp-send-hash t | |
940 "*If non-nil, send the HASH command to the FTP client." | |
941 :group 'ange-ftp | |
942 :type 'boolean) | |
943 | |
944 (defcustom ange-ftp-binary-hash-mark-size nil | |
945 "*Default size, in bytes, between hash-marks when transferring a binary file. | |
946 If nil, this variable will be locally overridden if the FTP client outputs a | |
947 suitable response to the HASH command. If non-nil, this value takes | |
948 precedence over the local value." | |
949 :group 'ange-ftp | |
950 :type '(choice (const :tag "Overridden" nil) | |
951 integer)) | |
952 | |
953 (defcustom ange-ftp-ascii-hash-mark-size 1024 | |
954 "*Default size, in bytes, between hash-marks when transferring an ASCII file. | |
955 This variable is buffer-local and will be locally overridden if the FTP client | |
956 outputs a suitable response to the HASH command." | |
957 :group 'ange-ftp | |
958 :type 'integer) | |
959 | |
960 (defcustom ange-ftp-process-verbose t | |
961 "*If non-nil then be chatty about interaction with the FTP process." | |
962 :group 'ange-ftp | |
963 :type 'boolean) | |
964 | |
965 (defcustom ange-ftp-ftp-program-name "ftp" | |
966 "*Name of FTP program to run." | |
967 :group 'ange-ftp | |
968 :type 'string) | |
969 | |
970 (defcustom ange-ftp-gateway-ftp-program-name "ftp" | |
971 "*Name of FTP program to run when accessing non-local hosts. | |
972 | |
973 Some AT&T folks claim to use something called `pftp' here." | |
974 :group 'ange-ftp | |
975 :type 'string) | |
976 | |
977 (defcustom ange-ftp-ftp-program-args '("-i" "-n" "-g" "-v") | |
978 "*A list of arguments passed to the FTP program when started." | |
979 :group 'ange-ftp | |
980 :type '(repeat string)) | |
981 | |
982 (defcustom ange-ftp-nslookup-program nil | |
30459 | 983 "*If non-nil, this is a string naming the nslookup program." |
28210 | 984 :group 'ange-ftp |
985 :type '(choice (const :tag "None" nil) | |
986 string)) | |
987 | |
988 (defcustom ange-ftp-make-backup-files () | |
989 "*Non-nil means make backup files for \"magic\" remote files." | |
990 :group 'ange-ftp | |
991 :type 'boolean) | |
992 | |
993 (defcustom ange-ftp-retry-time 5 | |
994 "*Number of seconds to wait before retry if file or listing doesn't arrive. | |
995 This might need to be increased for very slow connections." | |
996 :group 'ange-ftp | |
997 :type 'integer) | |
998 | |
999 (defcustom ange-ftp-auto-save 0 | |
1000 "If 1, allow ange-ftp files to be auto-saved. | |
1001 If 0, inhibit auto-saving of ange-ftp files. | |
1002 Don't use any other value." | |
1003 :group 'ange-ftp | |
1004 :type '(choice (const :tag "Suppress" 0) | |
1005 (const :tag "Allow" 1))) | |
1006 | |
1007 (defcustom ange-ftp-try-passive-mode nil | |
76407
635d8b158d85
(ange-ftp-try-passive-mode): Doc fix.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
75552
diff
changeset
|
1008 "If t, try to use passive mode in ftp, if the client program supports it." |
28210 | 1009 :group 'ange-ftp |
1010 :type 'boolean | |
45260 | 1011 :version "21.1") |
28210 | 1012 |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1013 (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
|
1014 "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
|
1015 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
|
1016 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
|
1017 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
|
1018 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
|
1019 :group 'ange-ftp |
44953
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1020 :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
|
1021 (const :tag "Off" "off") |
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1022 (const :tag "Don't change" nil)))) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
57426
diff
changeset
|
1023 :version "22.1") |
28210 | 1024 |
1025 ;;;; ------------------------------------------------------------ | |
1026 ;;;; Hash table support. | |
1027 ;;;; ------------------------------------------------------------ | |
1028 | |
1029 (require 'backquote) | |
1030 | |
1031 (defun ange-ftp-hash-entry-exists-p (key tbl) | |
1032 "Return whether there is an association for KEY in TABLE." | |
56742
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
1033 (and tbl (not (eq (gethash key tbl 'unknown) 'unknown)))) |
28210 | 1034 |
1035 (defun ange-ftp-hash-table-keys (tbl) | |
1036 "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
|
1037 ;; (let ((keys nil)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1038 ;; (maphash (lambda (k v) (push k keys)) tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1039 ;; (sort keys 'string-lessp)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1040 (sort (all-completions "" tbl) 'string-lessp)) |
28210 | 1041 |
1042 ;;;; ------------------------------------------------------------ | |
1043 ;;;; Internal variables. | |
1044 ;;;; ------------------------------------------------------------ | |
1045 | |
1046 (defvar ange-ftp-data-buffer-name " *ftp data*" | |
1047 "Buffer name to hold directory listing data received from ftp process.") | |
1048 | |
1049 (defvar ange-ftp-netrc-modtime nil | |
1050 "Last modified time of the netrc file from file-attributes.") | |
1051 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1052 (defvar ange-ftp-user-hashtable (make-hash-table :test 'equal) |
28210 | 1053 "Hash table holding associations between HOST, USER pairs.") |
1054 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1055 (defvar ange-ftp-passwd-hashtable (make-hash-table :test 'equal) |
28210 | 1056 "Mapping between a HOST, USER pair and a PASSWORD for them. |
1057 All HOST values should be in lower case.") | |
1058 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1059 (defvar ange-ftp-account-hashtable (make-hash-table :test 'equal) |
28210 | 1060 "Mapping between a HOST, USER pair and a ACCOUNT password for them.") |
1061 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1062 (defvar ange-ftp-files-hashtable (make-hash-table :test 'equal :size 97) |
28210 | 1063 "Hash table for storing directories and their respective files.") |
1064 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1065 (defvar ange-ftp-inodes-hashtable (make-hash-table :test 'equal :size 97) |
28210 | 1066 "Hash table for storing file names and their \"inode numbers\".") |
1067 | |
1068 (defvar ange-ftp-next-inode-number 1 | |
1069 "Next \"inode number\" value. We give each file name a unique number.") | |
1070 | |
1071 (defvar ange-ftp-ls-cache-lsargs nil | |
1072 "Last set of args used by ange-ftp-ls.") | |
1073 | |
1074 (defvar ange-ftp-ls-cache-file nil | |
1075 "Last file passed to ange-ftp-ls.") | |
1076 | |
1077 (defvar ange-ftp-ls-cache-res nil | |
1078 "Last result returned from ange-ftp-ls.") | |
1079 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1080 (defconst ange-ftp-expand-dir-hashtable (make-hash-table :test 'equal)) |
28210 | 1081 |
1082 (defconst ange-ftp-expand-dir-regexp "^5.0 \\([^: ]+\\):") | |
1083 | |
1084 ;; These are local variables in each FTP process buffer. | |
1085 (defvar ange-ftp-hash-mark-unit nil) | |
1086 (defvar ange-ftp-hash-mark-count nil) | |
1087 (defvar ange-ftp-xfer-size nil) | |
1088 (defvar ange-ftp-process-string nil) | |
1089 (defvar ange-ftp-process-result-line nil) | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1090 (defvar ange-ftp-pending-error-line nil) |
28210 | 1091 (defvar ange-ftp-process-busy nil) |
1092 (defvar ange-ftp-process-result nil) | |
1093 (defvar ange-ftp-process-multi-skip nil) | |
1094 (defvar ange-ftp-process-msg nil) | |
1095 (defvar ange-ftp-process-continue nil) | |
1096 (defvar ange-ftp-last-percent nil) | |
1097 | |
1098 ;; These variables are bound by one function and examined by another. | |
1099 ;; Leave them void globally for error checking. | |
1100 (defvar ange-ftp-this-file) | |
1101 (defvar ange-ftp-this-dir) | |
1102 (defvar ange-ftp-this-user) | |
1103 (defvar ange-ftp-this-host) | |
1104 (defvar ange-ftp-this-msg) | |
1105 (defvar ange-ftp-completion-ignored-pattern) | |
1106 (defvar ange-ftp-trample-marker) | |
1107 | |
1108 ;; New error symbols. | |
1109 (put 'ftp-error 'error-conditions '(ftp-error file-error error)) | |
1110 ;; (put 'ftp-error 'error-message "FTP error") | |
1111 | |
1112 ;;; ------------------------------------------------------------ | |
1113 ;;; Enhanced message support. | |
1114 ;;; ------------------------------------------------------------ | |
1115 | |
1116 (defun ange-ftp-message (fmt &rest args) | |
1117 "Display message in echo area, but indicate if truncated. | |
1118 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
|
1119 (let ((msg (apply 'format fmt args)) |
28210 | 1120 (max (window-width (minibuffer-window)))) |
1121 (if noninteractive | |
1122 msg | |
1123 (if (>= (length msg) max) | |
1124 ;; Take just the last MAX - 3 chars of the string. | |
1125 (setq msg (concat "> " (substring msg (- 3 max))))) | |
1126 (message "%s" msg)))) | |
1127 | |
1128 (defun ange-ftp-abbreviate-filename (file &optional new) | |
30459 | 1129 "Abbreviate the file name FILE relative to the `default-directory'. |
28210 | 1130 If the optional parameter NEW is given and the non-directory parts match, |
1131 only return the directory part of FILE." | |
1132 (save-match-data | |
1133 (if (and default-directory | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1134 (string-match (concat "\\`" |
28210 | 1135 (regexp-quote default-directory) |
1136 ".") file)) | |
1137 (setq file (substring file (1- (match-end 0))))) | |
1138 (if (and new | |
1139 (string-equal (file-name-nondirectory file) | |
1140 (file-name-nondirectory new))) | |
1141 (setq file (file-name-directory file))) | |
1142 (or file "./"))) | |
1143 | |
1144 ;;;; ------------------------------------------------------------ | |
1145 ;;;; User / Host mapping support. | |
1146 ;;;; ------------------------------------------------------------ | |
1147 | |
1148 (defun ange-ftp-set-user (host user) | |
1149 "For a given HOST, set or change the default USER." | |
1150 (interactive "sHost: \nsUser: ") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1151 (puthash host user ange-ftp-user-hashtable)) |
28210 | 1152 |
1153 (defun ange-ftp-get-user (host) | |
1154 "Given a HOST, return the default USER." | |
1155 (ange-ftp-parse-netrc) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1156 (let ((user (gethash host ange-ftp-user-hashtable))) |
28210 | 1157 (or user |
1158 (prog1 | |
1159 (setq user | |
1160 (cond ((stringp ange-ftp-default-user) | |
1161 ;; We have a default name. Use it. | |
1162 ange-ftp-default-user) | |
1163 (ange-ftp-default-user | |
1164 ;; Ask the user. | |
1165 (let ((enable-recursive-minibuffers t)) | |
1166 (read-string (format "User for %s: " host) | |
1167 (user-login-name)))) | |
1168 (ange-ftp-netrc-default-user) | |
1169 ;; Default to the user's login name. | |
1170 (t | |
1171 (user-login-name)))) | |
1172 (ange-ftp-set-user host user))))) | |
1173 | |
1174 ;;;; ------------------------------------------------------------ | |
1175 ;;;; Password support. | |
1176 ;;;; ------------------------------------------------------------ | |
1177 | |
1178 (defmacro ange-ftp-generate-passwd-key (host user) | |
30459 | 1179 `(concat (downcase ,host) "/" ,user)) |
28210 | 1180 |
1181 (defmacro ange-ftp-lookup-passwd (host user) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1182 `(gethash (ange-ftp-generate-passwd-key ,host ,user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1183 ange-ftp-passwd-hashtable)) |
28210 | 1184 |
1185 (defun ange-ftp-set-passwd (host user passwd) | |
1186 "For a given HOST and USER, set or change the associated PASSWORD." | |
1187 (interactive (list (read-string "Host: ") | |
1188 (read-string "User: ") | |
1189 (read-passwd "Password: "))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1190 (puthash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1191 passwd ange-ftp-passwd-hashtable)) |
28210 | 1192 |
1193 (defun ange-ftp-get-host-with-passwd (user) | |
1194 "Given a USER, return a host we know the password for." | |
1195 (ange-ftp-parse-netrc) | |
1196 (catch 'found-one | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1197 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1198 (lambda (host val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1199 (if (ange-ftp-lookup-passwd host user) (throw 'found-one host))) |
28210 | 1200 ange-ftp-user-hashtable) |
1201 (save-match-data | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1202 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1203 (lambda (key value) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1204 (if (string-match "\\`[^/]*\\(/\\).*\\'" key) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1205 (let ((host (substring key 0 (match-beginning 1)))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1206 (if (and (string-equal user (substring key (match-end 1))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1207 value) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1208 (throw 'found-one host))))) |
28210 | 1209 ange-ftp-passwd-hashtable)) |
1210 nil)) | |
1211 | |
1212 (defun ange-ftp-get-passwd (host user) | |
1213 "Return the password for specified HOST and USER, asking user if necessary." | |
1214 (ange-ftp-parse-netrc) | |
1215 | |
1216 ;; look up password in the hash table first; user might have overridden the | |
1217 ;; defaults. | |
1218 (cond ((ange-ftp-lookup-passwd host user)) | |
30459 | 1219 |
28210 | 1220 ;; See if default user and password set. |
1221 ((and (stringp ange-ftp-default-user) | |
1222 ange-ftp-default-password | |
1223 (string-equal user ange-ftp-default-user)) | |
1224 ange-ftp-default-password) | |
30459 | 1225 |
28210 | 1226 ;; See if default user and password set from .netrc file. |
1227 ((and (stringp ange-ftp-netrc-default-user) | |
1228 ange-ftp-netrc-default-password | |
1229 (string-equal user ange-ftp-netrc-default-user)) | |
1230 ange-ftp-netrc-default-password) | |
30459 | 1231 |
28210 | 1232 ;; anonymous ftp password is handled specially since there is an |
1233 ;; unwritten rule about how that is used on the Internet. | |
1234 ((and (or (string-equal user "anonymous") | |
1235 (string-equal user "ftp")) | |
1236 ange-ftp-generate-anonymous-password) | |
1237 (if (stringp ange-ftp-generate-anonymous-password) | |
1238 ange-ftp-generate-anonymous-password | |
1239 user-mail-address)) | |
30459 | 1240 |
28210 | 1241 ;; see if same user has logged in to other hosts; if so then prompt |
1242 ;; with the password that was used there. | |
1243 (t | |
1244 (let* ((other (ange-ftp-get-host-with-passwd user)) | |
1245 (passwd (if other | |
30459 | 1246 |
28210 | 1247 ;; found another machine with the same user. |
1248 ;; Try that account. | |
1249 (read-passwd | |
1250 (format "passwd for %s@%s (default same as %s@%s): " | |
1251 user host user other) | |
1252 nil | |
1253 (ange-ftp-lookup-passwd other user)) | |
30459 | 1254 |
28210 | 1255 ;; I give up. Ask the user for the password. |
1256 (read-passwd | |
1257 (format "Password for %s@%s: " user host))))) | |
1258 (ange-ftp-set-passwd host user passwd) | |
1259 passwd)))) | |
1260 | |
1261 ;;;; ------------------------------------------------------------ | |
1262 ;;;; Account support | |
1263 ;;;; ------------------------------------------------------------ | |
1264 | |
1265 ;; Account passwords must be either specified in the .netrc file, or set | |
1266 ;; manually by calling ange-ftp-set-account. For the moment, ange-ftp doesn't | |
1267 ;; check to see whether the FTP process is actually prompting for an account | |
1268 ;; password. | |
30459 | 1269 |
28210 | 1270 (defun ange-ftp-set-account (host user account) |
1271 "For a given HOST and USER, set or change the associated ACCOUNT password." | |
1272 (interactive (list (read-string "Host: ") | |
1273 (read-string "User: ") | |
1274 (read-passwd "Account password: "))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1275 (puthash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1276 account ange-ftp-account-hashtable)) |
28210 | 1277 |
1278 (defun ange-ftp-get-account (host user) | |
1279 "Given a HOST and USER, return the FTP account." | |
1280 (ange-ftp-parse-netrc) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1281 (or (gethash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1282 ange-ftp-account-hashtable) |
28210 | 1283 (and (stringp ange-ftp-default-user) |
1284 (string-equal user ange-ftp-default-user) | |
1285 ange-ftp-default-account) | |
1286 (and (stringp ange-ftp-netrc-default-user) | |
1287 (string-equal user ange-ftp-netrc-default-user) | |
1288 ange-ftp-netrc-default-account))) | |
1289 | |
1290 ;;;; ------------------------------------------------------------ | |
1291 ;;;; ~/.netrc support | |
1292 ;;;; ------------------------------------------------------------ | |
1293 | |
1294 (defun ange-ftp-chase-symlinks (file) | |
1295 "Return the filename that FILE references, following all symbolic links." | |
1296 (let (temp) | |
1297 (while (setq temp (ange-ftp-real-file-symlink-p file)) | |
1298 (setq file | |
1299 (if (file-name-absolute-p temp) | |
1300 temp | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
1301 ;; Wouldn't `expand-file-name' be better than `concat' ? |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
1302 ;; It would fail when `a/b/..' != `a', tho. --Stef |
28210 | 1303 (concat (file-name-directory file) temp))))) |
1304 file) | |
1305 | |
1306 ;; Move along current line looking for the value of the TOKEN. | |
1307 ;; Valid separators between TOKEN and its value are commas and | |
1308 ;; whitespace. Second arg LIMIT is a limit for the search. | |
1309 | |
1310 (defun ange-ftp-parse-netrc-token (token limit) | |
1311 (if (search-forward token limit t) | |
1312 (let (beg) | |
1313 (skip-chars-forward ", \t\r\n" limit) | |
1314 (if (eq (following-char) ?\") ;quoted token value | |
1315 (progn (forward-char 1) | |
1316 (setq beg (point)) | |
1317 (skip-chars-forward "^\"" limit) | |
1318 (forward-char 1) | |
1319 (buffer-substring beg (1- (point)))) | |
1320 (setq beg (point)) | |
1321 (skip-chars-forward "^, \t\r\n" limit) | |
1322 (buffer-substring beg (point)))))) | |
1323 | |
1324 ;; Extract the values for the tokens `machine', `login', | |
1325 ;; `password' and `account' in the current buffer. If successful, | |
1326 ;; record the information found. | |
1327 | |
1328 (defun ange-ftp-parse-netrc-group () | |
1329 (let ((start (point)) | |
1330 (end (save-excursion | |
1331 (if (looking-at "machine\\>") | |
1332 ;; Skip `machine' and the machine name that follows. | |
1333 (progn | |
1334 (skip-chars-forward "^ \t\r\n") | |
1335 (skip-chars-forward " \t\r\n") | |
1336 (skip-chars-forward "^ \t\r\n")) | |
1337 ;; Skip `default'. | |
1338 (skip-chars-forward "^ \t\r\n")) | |
1339 ;; Find start of the next `machine' or `default' | |
1340 ;; or the end of the buffer. | |
1341 (if (re-search-forward "machine\\>\\|default\\>" nil t) | |
1342 (match-beginning 0) | |
1343 (point-max)))) | |
1344 machine login password account) | |
1345 (setq machine (ange-ftp-parse-netrc-token "machine" end) | |
1346 login (ange-ftp-parse-netrc-token "login" end) | |
1347 password (ange-ftp-parse-netrc-token "password" end) | |
1348 account (ange-ftp-parse-netrc-token "account" end)) | |
1349 (if (and machine login) | |
1350 ;; found a `machine` token. | |
1351 (progn | |
1352 (ange-ftp-set-user machine login) | |
1353 (ange-ftp-set-passwd machine login password) | |
1354 (and account | |
1355 (ange-ftp-set-account machine login account))) | |
1356 (goto-char start) | |
1357 (if (search-forward "default" end t) | |
1358 ;; found a `default' token | |
1359 (progn | |
1360 (setq login (ange-ftp-parse-netrc-token "login" end) | |
1361 password (ange-ftp-parse-netrc-token "password" end) | |
1362 account (ange-ftp-parse-netrc-token "account" end)) | |
1363 (and login | |
1364 (setq ange-ftp-netrc-default-user login)) | |
1365 (and password | |
1366 (setq ange-ftp-netrc-default-password password)) | |
1367 (and account | |
1368 (setq ange-ftp-netrc-default-account account))))) | |
1369 (goto-char end))) | |
1370 | |
1371 ;; Read in ~/.netrc, if one exists. If ~/.netrc file exists and has | |
1372 ;; the correct permissions then extract the \`machine\', \`login\', | |
1373 ;; \`password\' and \`account\' information from within. | |
1374 | |
1375 (defun ange-ftp-parse-netrc () | |
1376 ;; We set this before actually doing it to avoid the possibility | |
1377 ;; of an infinite loop if ange-ftp-netrc-filename is an FTP file. | |
1378 (interactive) | |
1379 (let (file attr) | |
1380 (let ((default-directory "/")) | |
1381 (setq file (ange-ftp-chase-symlinks | |
1382 (ange-ftp-real-expand-file-name ange-ftp-netrc-filename))) | |
1383 (setq attr (ange-ftp-real-file-attributes file))) | |
1384 (if (and attr ; file exists. | |
1385 (not (equal (nth 5 attr) ange-ftp-netrc-modtime))) ; file changed | |
1386 (save-match-data | |
1387 (if (or ange-ftp-disable-netrc-security-check | |
1388 (and (eq (nth 2 attr) (user-uid)) ; Same uids. | |
1389 (string-match ".r..------" (nth 8 attr)))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1390 (with-current-buffer |
28210 | 1391 ;; we are cheating a bit here. I'm trying to do the equivalent |
1392 ;; of find-file on the .netrc file, but then nuke it afterwards. | |
1393 ;; with the bit of logic below we should be able to have | |
1394 ;; encrypted .netrc files. | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1395 (generate-new-buffer "*ftp-.netrc*") |
28210 | 1396 (ange-ftp-real-insert-file-contents file) |
1397 (setq buffer-file-name file) | |
1398 (setq default-directory (file-name-directory file)) | |
1399 (normal-mode t) | |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
1400 (run-hooks 'find-file-hook) |
28210 | 1401 (setq buffer-file-name nil) |
1402 (goto-char (point-min)) | |
1403 (skip-chars-forward " \t\r\n") | |
1404 (while (not (eobp)) | |
1405 (ange-ftp-parse-netrc-group)) | |
1406 (kill-buffer (current-buffer))) | |
1407 (ange-ftp-message "%s either not owned by you or badly protected." | |
1408 ange-ftp-netrc-filename) | |
1409 (sit-for 1)) | |
1410 (setq ange-ftp-netrc-modtime (nth 5 attr)))))) | |
1411 | |
1412 ;; Return a list of prefixes of the form 'user@host:' to be used when | |
1413 ;; completion is done in the root directory. | |
1414 | |
1415 (defun ange-ftp-generate-root-prefixes () | |
1416 (ange-ftp-parse-netrc) | |
1417 (save-match-data | |
1418 (let (res) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1419 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1420 (lambda (key value) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1421 (if (string-match "\\`[^/]*\\(/\\).*\\'" key) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1422 (let ((host (substring key 0 (match-beginning 1))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1423 (user (substring key (match-end 1)))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1424 (push (concat user "@" host ":") res)))) |
28210 | 1425 ange-ftp-passwd-hashtable) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1426 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1427 (lambda (host user) (push (concat host ":") res)) |
28210 | 1428 ange-ftp-user-hashtable) |
1429 (or res (list nil))))) | |
1430 | |
1431 ;;;; ------------------------------------------------------------ | |
1432 ;;;; Remote file name syntax support. | |
1433 ;;;; ------------------------------------------------------------ | |
1434 | |
1435 (defmacro ange-ftp-ftp-name-component (n ns name) | |
1436 "Extract the Nth ftp file name component from NS." | |
30459 | 1437 `(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
|
1438 (match-string elt ,name))) |
28210 | 1439 |
1440 (defvar ange-ftp-ftp-name-arg "") | |
1441 (defvar ange-ftp-ftp-name-res nil) | |
1442 | |
1443 ;; Parse NAME according to `ange-ftp-name-format' (which see). | |
1444 ;; Returns a list (HOST USER NAME), or nil if NAME does not match the format. | |
1445 (defun ange-ftp-ftp-name (name) | |
1446 (if (string-equal name ange-ftp-ftp-name-arg) | |
1447 ange-ftp-ftp-name-res | |
1448 (setq ange-ftp-ftp-name-arg name | |
1449 ange-ftp-ftp-name-res | |
1450 (save-match-data | |
1451 (if (posix-string-match (car ange-ftp-name-format) name) | |
1452 (let* ((ns (cdr ange-ftp-name-format)) | |
1453 (host (ange-ftp-ftp-name-component 0 ns name)) | |
1454 (user (ange-ftp-ftp-name-component 1 ns name)) | |
1455 (name (ange-ftp-ftp-name-component 2 ns name))) | |
1456 (if (zerop (length user)) | |
1457 (setq user (ange-ftp-get-user host))) | |
1458 (list host user name)) | |
1459 nil))))) | |
1460 | |
1461 ;; Take a FULLNAME that matches according to ange-ftp-name-format and | |
1462 ;; replace the name component with NAME. | |
1463 (defun ange-ftp-replace-name-component (fullname name) | |
1464 (save-match-data | |
1465 (if (posix-string-match (car ange-ftp-name-format) fullname) | |
1466 (let* ((ns (cdr ange-ftp-name-format)) | |
1467 (elt (nth 2 ns))) | |
1468 (concat (substring fullname 0 (match-beginning elt)) | |
1469 name | |
1470 (substring fullname (match-end elt))))))) | |
1471 | |
1472 ;;;; ------------------------------------------------------------ | |
1473 ;;;; Miscellaneous utils. | |
1474 ;;;; ------------------------------------------------------------ | |
1475 | |
1476 ;; (setq ange-ftp-tmp-keymap (make-sparse-keymap)) | |
1477 ;; (define-key ange-ftp-tmp-keymap "\C-m" 'exit-minibuffer) | |
1478 | |
1479 (defun ange-ftp-repaint-minibuffer () | |
1480 "Clear any existing minibuffer message; let the minibuffer contents show." | |
1481 (message nil)) | |
1482 | |
1483 ;; Return the name of the buffer that collects output from the ftp process | |
1484 ;; connected to the given HOST and USER pair. | |
1485 (defun ange-ftp-ftp-process-buffer (host user) | |
1486 (concat "*ftp " user "@" host "*")) | |
1487 | |
1488 ;; Display the last chunk of output from the ftp process for the given HOST | |
1489 ;; USER pair, and signal an error including MSG in the text. | |
1490 (defun ange-ftp-error (host user msg) | |
52209
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1491 (save-excursion ;; Prevent pop-to-buffer from changing current buffer. |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1492 (let ((cur (selected-window)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1493 (pop-up-windows t)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1494 (pop-to-buffer |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1495 (get-buffer-create |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1496 (ange-ftp-ftp-process-buffer host user))) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1497 (goto-char (point-max)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1498 (select-window cur)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1499 (signal 'ftp-error (list (format "FTP Error: %s" msg))))) |
28210 | 1500 |
1501 (defun ange-ftp-set-buffer-mode () | |
1502 "Set correct modes for the current buffer if visiting a remote file." | |
1503 (if (and (stringp buffer-file-name) | |
1504 (ange-ftp-ftp-name buffer-file-name)) | |
1505 (auto-save-mode ange-ftp-auto-save))) | |
1506 | |
1507 (defun ange-ftp-kill-ftp-process (&optional buffer) | |
1508 "Kill the FTP process associated with BUFFER (the current buffer, if nil). | |
1509 If the BUFFER's visited filename or default-directory is an ftp filename | |
1510 then kill the related ftp process." | |
1511 (interactive "bKill FTP process associated with buffer: ") | |
1512 (if (null buffer) | |
1513 (setq buffer (current-buffer)) | |
1514 (setq buffer (get-buffer buffer))) | |
1515 (let ((file (or (buffer-file-name buffer) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1516 (with-current-buffer buffer default-directory)))) |
28210 | 1517 (if file |
1518 (let ((parsed (ange-ftp-ftp-name (expand-file-name file)))) | |
1519 (if parsed | |
1520 (let ((host (nth 0 parsed)) | |
1521 (user (nth 1 parsed))) | |
1522 (kill-buffer (get-buffer (ange-ftp-ftp-process-buffer host user))))))))) | |
1523 | |
1524 (defun ange-ftp-quote-string (string) | |
1525 "Quote any characters in STRING that may confuse the ftp process." | |
91814
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1526 ;; This is said to be wrong; ftp is said to need quoting only for ", |
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1527 ;; and that by doubling it. But experiment says UNIX-style kind of |
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1528 ;; quoting is correct when talking to ftp on GNU/Linux systems, and |
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1529 ;; W32-style kind of quoting on, yes, W32 systems. |
91961
93cf29ed1d24
* net/ange-ftp.el (ange-ftp-quote-string): Return the null string
Michael Albinus <michael.albinus@gmx.de>
parents:
91814
diff
changeset
|
1530 (if (stringp string) |
93cf29ed1d24
* net/ange-ftp.el (ange-ftp-quote-string): Return the null string
Michael Albinus <michael.albinus@gmx.de>
parents:
91814
diff
changeset
|
1531 (shell-quote-argument string) |
93cf29ed1d24
* net/ange-ftp.el (ange-ftp-quote-string): Return the null string
Michael Albinus <michael.albinus@gmx.de>
parents:
91814
diff
changeset
|
1532 "")) |
28210 | 1533 |
1534 (defun ange-ftp-barf-if-not-directory (directory) | |
1535 (or (file-directory-p directory) | |
1536 (signal 'file-error | |
1537 (list "Opening directory" | |
1538 (if (file-exists-p directory) | |
1539 "not a directory" | |
1540 "no such file or directory") | |
1541 directory)))) | |
1542 | |
1543 ;;;; ------------------------------------------------------------ | |
1544 ;;;; FTP process filter support. | |
1545 ;;;; ------------------------------------------------------------ | |
1546 | |
1547 (defun ange-ftp-process-handle-line (line proc) | |
1548 "Look at the given LINE from the ftp process PROC. | |
1549 Try to categorize it into one of four categories: | |
1550 good, skip, fatal, or unknown." | |
1551 (cond ((string-match ange-ftp-xfer-size-msgs line) | |
1552 (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
|
1553 (/ (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
|
1554 1024))) |
28210 | 1555 ((string-match ange-ftp-skip-msgs line) |
1556 t) | |
1557 ((string-match ange-ftp-good-msgs line) | |
1558 (setq ange-ftp-process-busy nil | |
1559 ange-ftp-process-result t | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1560 ange-ftp-pending-error-line nil |
28210 | 1561 ange-ftp-process-result-line line)) |
1562 ;; Check this before checking for errors. | |
1563 ;; Otherwise the last line of these three seems to be an error: | |
1564 ;; 230-see a significant impact from the move. For those of you who can't | |
1565 ;; 230-use DNS to resolve hostnames and get an error message like | |
1566 ;; 230-"ftp.stsci.edu: unknown host", the new IP address will be... | |
1567 ((string-match ange-ftp-multi-msgs line) | |
1568 (setq ange-ftp-process-multi-skip t)) | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1569 ((string-match ange-ftp-potential-error-msgs line) |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1570 ;; This looks like an error, but we have to keep reading the output |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1571 ;; to see if it was fixed or not. E.g. it may indicate that IPv6 |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1572 ;; failed, but maybe a subsequent IPv4 fallback succeeded. |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1573 (set (make-local-variable 'ange-ftp-pending-error-line) line) |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1574 t) |
28210 | 1575 ((string-match ange-ftp-fatal-msgs line) |
1576 (delete-process proc) | |
1577 (setq ange-ftp-process-busy nil | |
1578 ange-ftp-process-result-line line)) | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1579 (ange-ftp-process-multi-skip |
28210 | 1580 t) |
1581 (t | |
1582 (setq ange-ftp-process-busy nil | |
1583 ange-ftp-process-result-line line)))) | |
1584 | |
1585 (defun ange-ftp-set-xfer-size (host user bytes) | |
1586 "Set the size of the next FTP transfer in bytes." | |
1587 (let ((proc (ange-ftp-get-process host user))) | |
1588 (if proc | |
1589 (let ((buf (process-buffer proc))) | |
1590 (if buf | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1591 (with-current-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
|
1592 (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
|
1593 ;; 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
|
1594 (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
|
1595 (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
|
1596 (/ bytes 1024))))))))) |
28210 | 1597 |
1598 (defun ange-ftp-process-handle-hash (str) | |
1599 "Remove hash marks from STRING and display count so far." | |
1600 (setq str (concat (substring str 0 (match-beginning 0)) | |
1601 (substring str (match-end 0))) | |
1602 ange-ftp-hash-mark-count (+ (- (match-end 0) | |
1603 (match-beginning 0)) | |
1604 ange-ftp-hash-mark-count)) | |
1605 (and ange-ftp-hash-mark-unit | |
1606 ange-ftp-process-msg | |
1607 ange-ftp-process-verbose | |
1608 (not (eq (selected-window) (minibuffer-window))) | |
1609 (not (boundp 'search-message)) ;screws up isearch otherwise | |
1610 (not cursor-in-echo-area) ;screws up y-or-n-p otherwise | |
1611 (let ((kbytes (ash (* ange-ftp-hash-mark-unit | |
1612 ange-ftp-hash-mark-count) | |
1613 -6))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1614 (if (zerop ange-ftp-xfer-size) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1615 (ange-ftp-message "%s...%dk" ange-ftp-process-msg kbytes) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1616 (let ((percent (/ (* 100 kbytes) ange-ftp-xfer-size))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1617 ;; cut out the redisplay of identical %-age messages. |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1618 (unless (eq percent ange-ftp-last-percent) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1619 (setq ange-ftp-last-percent percent) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1620 (ange-ftp-message "%s...%d%%" ange-ftp-process-msg percent)))))) |
28210 | 1621 str) |
1622 | |
1623 ;; Call the function specified by CONT. CONT can be either a function | |
1624 ;; or a list of a function and some args. The first two parameters | |
1625 ;; passed to the function will be RESULT and LINE. The remaining args | |
1626 ;; will be taken from CONT if a list was passed. | |
1627 | |
1628 (defun ange-ftp-call-cont (cont result line) | |
1629 (if cont | |
1630 (if (and (listp cont) | |
1631 (not (eq (car cont) 'lambda))) | |
1632 (apply (car cont) result line (cdr cont)) | |
1633 (funcall cont result line)))) | |
1634 | |
1635 ;; Build up a complete line of output from the ftp PROCESS and pass it | |
1636 ;; on to ange-ftp-process-handle-line to deal with. | |
1637 | |
1638 (defun ange-ftp-process-filter (proc str) | |
65516
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1639 ;; Eliminate nulls. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1640 (while (string-match "\000+" str) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1641 (setq str (replace-match "" nil nil str))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1642 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1643 ;; see if the buffer is still around... it could have been deleted. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1644 (when (buffer-live-p (process-buffer proc)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1645 (with-current-buffer (process-buffer proc) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1646 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1647 ;; handle hash mark printing |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1648 (and ange-ftp-process-busy |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1649 (string-match "^#+$" str) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1650 (setq str (ange-ftp-process-handle-hash str))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1651 (comint-output-filter proc str) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1652 ;; Replace STR by the result of the comint processing. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1653 (setq str (buffer-substring comint-last-output-start |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1654 (process-mark proc))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1655 (if ange-ftp-process-busy |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1656 (progn |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1657 (setq ange-ftp-process-string (concat ange-ftp-process-string |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1658 str)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1659 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1660 ;; if we gave an empty password to the USER command earlier |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1661 ;; then we should send a null password now. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1662 (if (string-match "Password: *$" ange-ftp-process-string) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1663 (process-send-string proc "\n")))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1664 (while (and ange-ftp-process-busy |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1665 (string-match "\n" ange-ftp-process-string)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1666 (let ((line (substring ange-ftp-process-string |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1667 0 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1668 (match-beginning 0))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1669 (seen-prompt nil)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1670 (setq ange-ftp-process-string (substring ange-ftp-process-string |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1671 (match-end 0))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1672 (while (string-match "\\`ftp> *" line) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1673 (setq seen-prompt t) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1674 (setq line (substring line (match-end 0)))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1675 (if (not (and seen-prompt ange-ftp-pending-error-line)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1676 (ange-ftp-process-handle-line line proc) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1677 ;; If we've seen a potential error message and it |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1678 ;; hasn't been cancelled by a good message before |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1679 ;; seeing a propt, then the error was real. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1680 (delete-process proc) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1681 (setq ange-ftp-process-busy nil |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1682 ange-ftp-process-result-line ange-ftp-pending-error-line)))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1683 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1684 ;; has the ftp client finished? if so then do some clean-up |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1685 ;; actions. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1686 (if (not ange-ftp-process-busy) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1687 (progn |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1688 ;; reset the xfer size |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1689 (setq ange-ftp-xfer-size 0) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1690 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1691 ;; issue the "done" message since we've finished. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1692 (if (and ange-ftp-process-msg |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1693 ange-ftp-process-verbose |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1694 ange-ftp-process-result) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1695 (progn |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1696 (ange-ftp-message "%s...done" ange-ftp-process-msg) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1697 (ange-ftp-repaint-minibuffer) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1698 (setq ange-ftp-process-msg nil))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1699 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1700 ;; is there a continuation we should be calling? if so, |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1701 ;; we'd better call it, making sure we only call it once. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1702 (if ange-ftp-process-continue |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1703 (let ((cont ange-ftp-process-continue)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1704 (setq ange-ftp-process-continue nil) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1705 (ange-ftp-call-cont cont |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1706 ange-ftp-process-result |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1707 ange-ftp-process-result-line)))))))) |
28210 | 1708 |
1709 (defun ange-ftp-process-sentinel (proc str) | |
1710 "When ftp process changes state, nuke all file-entries in cache." | |
1711 (let ((name (process-name proc))) | |
1712 (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
|
1713 (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
|
1714 (host (match-string 2 name))) |
28210 | 1715 (ange-ftp-wipe-file-entries host user)))) |
1716 (setq ange-ftp-ls-cache-file nil)) | |
1717 | |
1718 ;;;; ------------------------------------------------------------ | |
1719 ;;;; Gateway support. | |
1720 ;;;; ------------------------------------------------------------ | |
1721 | |
1722 (defun ange-ftp-use-gateway-p (host) | |
1723 "Returns whether to access this host via a normal (non-smart) gateway." | |
1724 ;; yes, I know that I could simplify the following expression, but it is | |
1725 ;; clearer (to me at least) this way. | |
1726 (and (not ange-ftp-smart-gateway) | |
1727 (save-match-data | |
1728 (not (string-match ange-ftp-local-host-regexp host))))) | |
1729 | |
1730 (defun ange-ftp-use-smart-gateway-p (host) | |
1731 "Returns whether to access this host via a smart gateway." | |
1732 (and ange-ftp-smart-gateway | |
1733 (save-match-data | |
1734 (not (string-match ange-ftp-local-host-regexp host))))) | |
1735 | |
1736 | |
1737 ;;; ------------------------------------------------------------ | |
1738 ;;; Temporary file location and deletion... | |
1739 ;;; ------------------------------------------------------------ | |
1740 | |
1741 (defun ange-ftp-make-tmp-name (host) | |
1742 "This routine will return the name of a new file." | |
1743 (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
|
1744 ange-ftp-gateway-tmp-name-template |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1745 ange-ftp-tmp-name-template))) |
28210 | 1746 |
1747 (defalias 'ange-ftp-del-tmp-name 'delete-file) | |
1748 | |
1749 ;;;; ------------------------------------------------------------ | |
1750 ;;;; Interactive gateway program support. | |
1751 ;;;; ------------------------------------------------------------ | |
1752 | |
1753 (defvar ange-ftp-gwp-running t) | |
1754 (defvar ange-ftp-gwp-status nil) | |
1755 | |
1756 (defun ange-ftp-gwp-sentinel (proc str) | |
1757 (setq ange-ftp-gwp-running nil)) | |
1758 | |
1759 (defun ange-ftp-gwp-filter (proc str) | |
1760 (comint-output-filter proc str) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1761 (with-current-buffer (process-buffer proc) |
28210 | 1762 ;; Replace STR by the result of the comint processing. |
1763 (setq str (buffer-substring comint-last-output-start (process-mark proc)))) | |
1764 (cond ((string-match "login: *$" str) | |
62460
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1765 (process-send-string proc |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1766 (concat |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1767 (let ((ange-ftp-default-user t)) |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1768 (ange-ftp-get-user ange-ftp-gateway-host)) |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1769 "\n"))) |
28210 | 1770 ((string-match "Password: *$" str) |
62460
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1771 (process-send-string proc |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1772 (concat |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1773 (ange-ftp-get-passwd ange-ftp-gateway-host |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1774 (ange-ftp-get-user |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1775 ange-ftp-gateway-host)) |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1776 "\n"))) |
28210 | 1777 ((string-match ange-ftp-gateway-fatal-msgs str) |
1778 (delete-process proc) | |
1779 (setq ange-ftp-gwp-running nil)) | |
1780 ((string-match ange-ftp-gateway-prompt-pattern str) | |
1781 (setq ange-ftp-gwp-running nil | |
1782 ange-ftp-gwp-status t)))) | |
1783 | |
1784 (defun ange-ftp-gwp-start (host user name args) | |
1785 "Login to the gateway machine and fire up an ftp process." | |
65516
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1786 (let* (;; It would be nice to make process-connection-type nil, |
28210 | 1787 ;; but that doesn't work: ftp never responds. |
1788 ;; Can anyone find a fix for that? | |
1789 (proc (let ((process-connection-type t)) | |
1790 (start-process name name | |
1791 ange-ftp-gateway-program | |
1792 ange-ftp-gateway-host))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1793 (ftp (mapconcat 'identity args " "))) |
56765
3c6aa215e03f
(ange-ftp-gwp-start, ange-ftp-nslookup-host)
Richard M. Stallman <rms@gnu.org>
parents:
56742
diff
changeset
|
1794 (set-process-query-on-exit-flag proc nil) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1795 (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
|
1796 (set-process-filter proc 'ange-ftp-gwp-filter) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
1797 (with-current-buffer (process-buffer proc) |
28210 | 1798 (goto-char (point-max)) |
1799 (set-marker (process-mark proc) (point))) | |
1800 (setq ange-ftp-gwp-running t | |
1801 ange-ftp-gwp-status nil) | |
1802 (ange-ftp-message "Connecting to gateway %s..." ange-ftp-gateway-host) | |
1803 (while ange-ftp-gwp-running ;perform login sequence | |
1804 (accept-process-output proc)) | |
1805 (if (not ange-ftp-gwp-status) | |
1806 (ange-ftp-error host user "unable to login to gateway")) | |
1807 (ange-ftp-message "Connecting to gateway %s...done" ange-ftp-gateway-host) | |
1808 (setq ange-ftp-gwp-running t | |
1809 ange-ftp-gwp-status nil) | |
1810 (process-send-string proc ange-ftp-gateway-setup-term-command) | |
1811 (while ange-ftp-gwp-running ;zap ^M's and double echoing. | |
1812 (accept-process-output proc)) | |
1813 (if (not ange-ftp-gwp-status) | |
1814 (ange-ftp-error host user "unable to set terminal modes on gateway")) | |
1815 (setq ange-ftp-gwp-running t | |
1816 ange-ftp-gwp-status nil) | |
1817 (process-send-string proc (concat "exec " ftp "\n")) ;spawn ftp process | |
1818 proc)) | |
1819 | |
1820 ;;;; ------------------------------------------------------------ | |
1821 ;;;; Support for sending commands to the ftp process. | |
1822 ;;;; ------------------------------------------------------------ | |
1823 | |
1824 (defun ange-ftp-raw-send-cmd (proc cmd &optional msg cont nowait) | |
1825 "Low-level routine to send the given ftp CMD to the ftp PROCESS. | |
1826 MSG is an optional message to output before and after the command. | |
30459 | 1827 If CONT is non-nil then it is either a function or a list of function |
1828 and some arguments. The function will be called when the ftp command | |
1829 has completed. | |
1830 If CONT is nil then this routine will return \(RESULT . LINE\) where RESULT | |
28210 | 1831 is whether the command was successful, and LINE is the line from the FTP |
1832 process that caused the command to complete. | |
1833 If NOWAIT is given then the routine will return immediately the command has | |
1834 been queued with no result. CONT will still be called, however." | |
1835 (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
|
1836 (with-current-buffer (process-buffer proc) |
28210 | 1837 (ange-ftp-wait-not-busy proc) |
1838 (setq ange-ftp-process-string "" | |
1839 ange-ftp-process-result-line "" | |
1840 ange-ftp-process-busy t | |
1841 ange-ftp-process-result nil | |
1842 ange-ftp-process-multi-skip nil | |
1843 ange-ftp-process-msg msg | |
1844 ange-ftp-process-continue cont | |
1845 ange-ftp-hash-mark-count 0 | |
1846 ange-ftp-last-percent -1 | |
1847 cmd (concat cmd "\n")) | |
1848 (and msg ange-ftp-process-verbose (ange-ftp-message "%s..." msg)) | |
1849 (goto-char (point-max)) | |
1850 (move-marker comint-last-input-start (point)) | |
1851 ;; don't insert the password into the buffer on the USER command. | |
1852 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1853 (if (string-match "\\`user \"[^\"]*\"" cmd) |
28210 | 1854 (insert (substring cmd 0 (match-end 0)) " Turtle Power!\n") |
1855 (insert cmd))) | |
1856 (move-marker comint-last-input-end (point)) | |
62460
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1857 (process-send-string proc cmd) |
28210 | 1858 (set-marker (process-mark proc) (point)) |
1859 (if nowait | |
1860 nil | |
1861 (ange-ftp-wait-not-busy proc) | |
1862 (if cont | |
1863 nil ;cont has already been called | |
1864 (cons ange-ftp-process-result ange-ftp-process-result-line)))))) | |
1865 | |
1866 ;; Wait for the ange-ftp process PROC not to be busy. | |
1867 (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
|
1868 (with-current-buffer (process-buffer proc) |
28210 | 1869 (condition-case nil |
1870 ;; This is a kludge to let user quit in case ftp gets hung. | |
1871 ;; It matters because this function can be called from the filter. | |
1872 ;; It is bad to allow quitting in a filter, but getting hung | |
1873 ;; is worse. By binding quit-flag to nil, we might avoid | |
1874 ;; most of the probability of getting screwed because the user | |
1875 ;; wants to quit some command. | |
1876 (let ((quit-flag nil) | |
1877 (inhibit-quit nil)) | |
1878 (while ange-ftp-process-busy | |
1879 (accept-process-output proc))) | |
1880 (quit | |
1881 ;; If the user does quit out of this, | |
1882 ;; kill the process. That stops any transfer in progress. | |
1883 ;; The next operation will open a new ftp connection. | |
1884 (delete-process proc) | |
1885 (signal 'quit nil))))) | |
1886 | |
1887 (defun ange-ftp-nslookup-host (host) | |
1888 "Attempt to resolve the given HOSTNAME using nslookup if possible." | |
1889 (interactive "sHost: ") | |
1890 (if ange-ftp-nslookup-program | |
1891 (let ((default-directory | |
1892 (if (file-accessible-directory-p default-directory) | |
1893 default-directory | |
1894 exec-directory)) | |
1895 ;; It would be nice to make process-connection-type nil, | |
1896 ;; but that doesn't work: ftp never responds. | |
1897 ;; Can anyone find a fix for that? | |
1898 (proc (let ((process-connection-type t)) | |
1899 (start-process " *nslookup*" " *nslookup*" | |
1900 ange-ftp-nslookup-program host))) | |
1901 (res host)) | |
56765
3c6aa215e03f
(ange-ftp-gwp-start, ange-ftp-nslookup-host)
Richard M. Stallman <rms@gnu.org>
parents:
56742
diff
changeset
|
1902 (set-process-query-on-exit-flag proc nil) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1903 (with-current-buffer (process-buffer proc) |
28210 | 1904 (while (memq (process-status proc) '(run open)) |
1905 (accept-process-output proc)) | |
1906 (goto-char (point-min)) | |
1907 (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
|
1908 (setq res (match-string 1))) |
28210 | 1909 (kill-buffer (current-buffer))) |
1910 res) | |
1911 host)) | |
1912 | |
1913 (defun ange-ftp-start-process (host user name) | |
1914 "Spawn a new ftp process ready to connect to machine HOST and give it NAME. | |
1915 If HOST is only ftp-able through a gateway machine then spawn a shell | |
1916 on the gateway machine to do the ftp instead." | |
1917 (let* ((use-gateway (ange-ftp-use-gateway-p host)) | |
1918 (use-smart-ftp (and (not ange-ftp-gateway-host) | |
1919 (ange-ftp-use-smart-gateway-p host))) | |
1920 (ftp-prog (if (or use-gateway | |
30459 | 1921 use-smart-ftp) |
28210 | 1922 ange-ftp-gateway-ftp-program-name |
1923 ange-ftp-ftp-program-name)) | |
1924 (args (append (list ftp-prog) ange-ftp-ftp-program-args)) | |
1925 ;; Without the following binding, ange-ftp-start-process | |
1926 ;; recurses on file-accessible-directory-p, since it needs to | |
1927 ;; restart its process in order to determine anything about | |
1928 ;; default-directory. | |
1929 (file-name-handler-alist) | |
1930 (default-directory | |
1931 (if (file-accessible-directory-p default-directory) | |
1932 default-directory | |
1933 exec-directory)) | |
1934 proc) | |
1935 ;; It would be nice to make process-connection-type nil, | |
1936 ;; but that doesn't work: ftp never responds. | |
1937 ;; Can anyone find a fix for that? | |
1938 (let ((process-connection-type t) | |
53415
d2a77d389b0e
(ange-ftp-start-process): Copy the environment.
Richard M. Stallman <rms@gnu.org>
parents:
53388
diff
changeset
|
1939 ;; Copy this so we don't alter it permanently. |
d2a77d389b0e
(ange-ftp-start-process): Copy the environment.
Richard M. Stallman <rms@gnu.org>
parents:
53388
diff
changeset
|
1940 (process-environment (copy-tree process-environment)) |
28210 | 1941 (buffer (get-buffer-create name))) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1942 (with-current-buffer buffer |
28210 | 1943 (internal-ange-ftp-mode)) |
1944 ;; This tells GNU ftp not to output any fancy escape sequences. | |
1945 (setenv "TERM" "dumb") | |
1946 (if use-gateway | |
1947 (if ange-ftp-gateway-program-interactive | |
1948 (setq proc (ange-ftp-gwp-start host user name args)) | |
1949 (setq proc (apply 'start-process name name | |
1950 (append (list ange-ftp-gateway-program | |
1951 ange-ftp-gateway-host) | |
1952 args)))) | |
1953 (setq proc (apply 'start-process name name args)))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1954 (with-current-buffer (process-buffer proc) |
28210 | 1955 (goto-char (point-max)) |
1956 (set-marker (process-mark proc) (point))) | |
56765
3c6aa215e03f
(ange-ftp-gwp-start, ange-ftp-nslookup-host)
Richard M. Stallman <rms@gnu.org>
parents:
56742
diff
changeset
|
1957 (set-process-query-on-exit-flag proc nil) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1958 (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
|
1959 (set-process-filter proc 'ange-ftp-process-filter) |
28210 | 1960 ;; On Windows, the standard ftp client buffers its output (because |
1961 ;; stdout is a pipe handle) so the startup message may never appear: | |
1962 ;; `accept-process-output' at this point would hang indefinitely. | |
1963 ;; However, sending an innocuous command ("help foo") forces some | |
1964 ;; output that will be ignored, which is just as good. Once we | |
1965 ;; start sending normal commands, the output no longer appears to be | |
1966 ;; buffered, and everything works correctly. My guess is that the | |
1967 ;; output of interest is being sent to stderr which is not buffered. | |
1968 (when (eq system-type 'windows-nt) | |
1969 ;; force ftp output to be treated as DOS text, otherwise the | |
1970 ;; output of "help foo" confuses the EOL detection logic. | |
1971 (set-process-coding-system proc 'raw-text-dos) | |
1972 (process-send-string proc "help foo\n")) | |
1973 (accept-process-output proc) ;wait for ftp startup message | |
1974 proc)) | |
1975 | |
1976 (put 'internal-ange-ftp-mode 'mode-class 'special) | |
1977 | |
1978 (defun internal-ange-ftp-mode () | |
1979 "Major mode for interacting with the FTP process. | |
1980 | |
1981 \\{comint-mode-map}" | |
1982 (interactive) | |
63413
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1983 (delay-mode-hooks (comint-mode)) |
28210 | 1984 (setq major-mode 'internal-ange-ftp-mode) |
1985 (setq mode-name "Internal Ange-ftp") | |
63413
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1986 (make-local-variable 'ange-ftp-process-string) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1987 (setq ange-ftp-process-string "") |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1988 (make-local-variable 'ange-ftp-process-busy) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1989 (make-local-variable 'ange-ftp-process-result) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1990 (make-local-variable 'ange-ftp-process-msg) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1991 (make-local-variable 'ange-ftp-process-multi-skip) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1992 (make-local-variable 'ange-ftp-process-result-line) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1993 (make-local-variable 'ange-ftp-process-continue) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1994 (make-local-variable 'ange-ftp-hash-mark-count) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1995 (make-local-variable 'ange-ftp-binary-hash-mark-size) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1996 (make-local-variable 'ange-ftp-ascii-hash-mark-size) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1997 (make-local-variable 'ange-ftp-hash-mark-unit) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1998 (make-local-variable 'ange-ftp-xfer-size) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1999 (make-local-variable 'ange-ftp-last-percent) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2000 (setq ange-ftp-hash-mark-count 0) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2001 (setq ange-ftp-xfer-size 0) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2002 (setq ange-ftp-process-result-line "") |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2003 (setq comint-prompt-regexp "^ftp> ") |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2004 (make-local-variable 'comint-password-prompt-regexp) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2005 ;; This is a regexp that can't match anything. |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2006 ;; ange-ftp has its own ways of handling passwords. |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
2007 (setq comint-password-prompt-regexp "\\`a\\`") |
63413
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2008 (make-local-variable 'paragraph-start) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2009 (setq paragraph-start comint-prompt-regexp) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
2010 (run-mode-hooks 'internal-ange-ftp-mode-hook)) |
28210 | 2011 |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2012 (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
|
2013 "*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
|
2014 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
|
2015 :group 'ange-ftp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2016 :version "21.3" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2017 :type 'boolean) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2018 |
28210 | 2019 (defun ange-ftp-smart-login (host user pass account proc) |
2020 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT. | |
2021 PROC is the FTP-client's process. This routine uses the smart-gateway | |
30459 | 2022 host specified in `ange-ftp-gateway-host'." |
28210 | 2023 (let ((result (ange-ftp-raw-send-cmd |
2024 proc | |
2025 (format "open %s %s" | |
2026 (ange-ftp-nslookup-host ange-ftp-gateway-host) | |
2027 ange-ftp-smart-gateway-port) | |
2028 (format "Opening FTP connection to %s via %s" | |
2029 host | |
2030 ange-ftp-gateway-host)))) | |
2031 (or (car result) | |
30459 | 2032 (ange-ftp-error host user |
28210 | 2033 (concat "OPEN request failed: " |
2034 (cdr result)))) | |
2035 (setq result (ange-ftp-raw-send-cmd | |
2036 proc (format "user \"%s\"@%s %s %s" | |
2037 user | |
2038 (ange-ftp-nslookup-host host) | |
2039 pass | |
2040 account) | |
2041 (format "Logging in as user %s@%s" | |
2042 user host))) | |
2043 (or (car result) | |
2044 (progn | |
2045 (ange-ftp-set-passwd host user nil) ; reset password | |
2046 (ange-ftp-set-account host user nil) ; reset account | |
2047 (ange-ftp-error host user | |
2048 (concat "USER request failed: " | |
2049 (cdr result))))))) | |
2050 | |
2051 (defun ange-ftp-normal-login (host user pass account proc) | |
2052 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT. | |
2053 PROC is the process to the FTP-client. HOST may have an optional | |
2054 suffix of the form #PORT to specify a non-default port" | |
2055 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2056 (string-match "\\`\\([^#]+\\)\\(#\\([0-9]+\\)\\)?\\'" host) |
28210 | 2057 (let* ((nshost (ange-ftp-nslookup-host (match-string 1 host))) |
2058 (port (match-string 3 host)) | |
2059 (result (ange-ftp-raw-send-cmd | |
2060 proc | |
2061 (if port | |
2062 (format "open %s %s" nshost port) | |
2063 (format "open %s" nshost)) | |
2064 (format "Opening FTP connection to %s" host)))) | |
2065 (or (car result) | |
2066 (ange-ftp-error host user | |
2067 (concat "OPEN request failed: " | |
2068 (cdr result)))) | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2069 (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
|
2070 (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
|
2071 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2072 (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
|
2073 ange-ftp-gateway-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2074 (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
|
2075 user nshost pass account) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2076 (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
|
2077 (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
|
2078 (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
|
2079 (skip ange-ftp-skip-msgs)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2080 (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
|
2081 "\\|^331 \\|^332 ")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2082 (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
|
2083 (setq ange-ftp-skip-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2084 (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
|
2085 (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
|
2086 (setq ange-ftp-skip-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2087 (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
|
2088 (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
|
2089 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2090 (format "quote \"USER %s\"" user) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2091 (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
|
2092 (and (car result) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2093 (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
|
2094 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2095 (format "quote \"PASS %s\"" pass) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2096 (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
|
2097 (and (car result) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2098 (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
|
2099 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2100 (format "quote \"ACCT %s\"" account) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2101 (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
|
2102 )) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2103 (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
|
2104 ange-ftp-skip-msgs skip))) |
28210 | 2105 (or (car result) |
2106 (progn | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2107 (ange-ftp-set-passwd host user nil) ;reset password. |
28210 | 2108 (ange-ftp-set-account host user nil) ;reset account. |
2109 (ange-ftp-error host user | |
2110 (concat "USER request failed: " | |
2111 (cdr result)))))))) | |
2112 | |
2113 ;; ange@hplb.hpl.hp.com says this should not be changed. | |
2114 (defvar ange-ftp-hash-mark-msgs | |
2115 "[hH]ash mark [^0-9]*\\([0-9]+\\)" | |
2116 "*Regexp matching the FTP client's output upon doing a HASH command.") | |
2117 | |
2118 (defun ange-ftp-guess-hash-mark-size (proc) | |
2119 (if ange-ftp-send-hash | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2120 (with-current-buffer (process-buffer proc) |
28210 | 2121 (let* ((status (ange-ftp-raw-send-cmd proc "hash")) |
2122 (line (cdr status))) | |
2123 (save-match-data | |
2124 (if (string-match ange-ftp-hash-mark-msgs line) | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
59996
diff
changeset
|
2125 (let ((size (string-to-number (match-string 1 line)))) |
28210 | 2126 (setq ange-ftp-ascii-hash-mark-size size |
2127 ange-ftp-hash-mark-unit (ash size -4)) | |
2128 | |
2129 ;; if a default value for this is set, use that value. | |
2130 (or ange-ftp-binary-hash-mark-size | |
2131 (setq ange-ftp-binary-hash-mark-size size))))))))) | |
2132 | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2133 (defvar ange-ftp-process-startup-hook nil) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2134 |
28210 | 2135 (defun ange-ftp-get-process (host user) |
2136 "Return an FTP subprocess connected to HOST and logged in as USER. | |
2137 Create a new process if needed." | |
2138 (let* ((name (ange-ftp-ftp-process-buffer host user)) | |
2139 (proc (get-process name))) | |
2140 (if (and proc (memq (process-status proc) '(run open))) | |
2141 proc | |
2142 ;; Must delete dead process so that new process can reuse the name. | |
2143 (if proc (delete-process proc)) | |
2144 (let ((pass (ange-ftp-quote-string | |
2145 (ange-ftp-get-passwd host user))) | |
2146 (account (ange-ftp-quote-string | |
2147 (ange-ftp-get-account host user)))) | |
2148 ;; grab a suitable process. | |
2149 (setq proc (ange-ftp-start-process host user name)) | |
30459 | 2150 |
28210 | 2151 ;; login to FTP server. |
2152 (if (and (ange-ftp-use-smart-gateway-p host) | |
2153 ange-ftp-gateway-host) | |
2154 (ange-ftp-smart-login host user pass account proc) | |
2155 (ange-ftp-normal-login host user pass account proc)) | |
30459 | 2156 |
28210 | 2157 ;; Tell client to send back hash-marks as progress. It isn't usually |
2158 ;; fatal if this command fails. | |
2159 (ange-ftp-guess-hash-mark-size proc) | |
2160 | |
2161 ;; Guess at the host type. | |
2162 (ange-ftp-guess-host-type host user) | |
2163 | |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2164 ;; 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
|
2165 (let* ((case-fold-search t) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2166 (passive |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2167 (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
|
2168 'string-match) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2169 (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
|
2170 (if passive |
42801
b719a1276b31
(ange-ftp-passive-mode): New arg PROC.
Richard M. Stallman <rms@gnu.org>
parents:
42740
diff
changeset
|
2171 (ange-ftp-passive-mode proc passive))) |
28210 | 2172 |
2173 ;; Run any user-specified hooks. Note that proc, host and user are | |
2174 ;; 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
|
2175 (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
|
2176 (ange-ftp-this-host host)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2177 (run-hooks 'ange-ftp-process-startup-hook))) |
28210 | 2178 proc))) |
2179 | |
42801
b719a1276b31
(ange-ftp-passive-mode): New arg PROC.
Richard M. Stallman <rms@gnu.org>
parents:
42740
diff
changeset
|
2180 (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
|
2181 (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
|
2182 (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
|
2183 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
|
2184 "Trying passive mode..." nil))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2185 (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
|
2186 (error "Trying passive mode...failed"))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2187 |
28210 | 2188 ;; Variables for caching host and host-type |
2189 (defvar ange-ftp-host-cache nil) | |
2190 (defvar ange-ftp-host-type-cache nil) | |
2191 | |
2192 ;; If ange-ftp-host-type is called with the optional user | |
2193 ;; argument, it will attempt to guess the host type by connecting | |
2194 ;; as user, if necessary. For efficiency, I have tried to give this | |
2195 ;; optional second argument only when necessary. Have I missed any calls | |
2196 ;; to ange-ftp-host-type where it should have been supplied? | |
2197 | |
2198 (defun ange-ftp-host-type (host &optional user) | |
2199 "Return a symbol which represents the type of the HOST given. | |
2200 If the optional argument USER is given, attempts to guess the | |
2201 host-type by logging in as USER." | |
2202 (cond ((null host) 'unix) | |
2203 ;; Return `unix' if HOST is nil, since that's the most vanilla | |
2204 ;; possible return value. | |
2205 ((eq host ange-ftp-host-cache) | |
2206 ange-ftp-host-type-cache) | |
2207 ;; Trigger an ftp connection, in case we need to guess at the host type. | |
2208 ((and user (ange-ftp-get-process host user) (eq host ange-ftp-host-cache)) | |
2209 ange-ftp-host-type-cache) | |
2210 (t | |
2211 (setq ange-ftp-host-cache host | |
2212 ange-ftp-host-type-cache | |
2213 (cond ((ange-ftp-dumb-unix-host host) | |
2214 'dumb-unix) | |
2215 ;; ((and (fboundp 'ange-ftp-vos-host) | |
2216 ;; (ange-ftp-vos-host host)) | |
2217 ;; 'vos) | |
2218 ((and (fboundp 'ange-ftp-vms-host) | |
2219 (ange-ftp-vms-host host)) | |
2220 'vms) | |
2221 ((and (fboundp 'ange-ftp-mts-host) | |
2222 (ange-ftp-mts-host host)) | |
2223 'mts) | |
2224 ((and (fboundp 'ange-ftp-cms-host) | |
2225 (ange-ftp-cms-host host)) | |
2226 'cms) | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2227 ((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
|
2228 (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
|
2229 '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
|
2230 ((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
|
2231 (ange-ftp-bs2000-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2232 'bs2000) |
28210 | 2233 (t |
2234 'unix)))))) | |
2235 | |
2236 ;; It would be nice to abstract the functions ange-ftp-TYPE-host and | |
2237 ;; ange-ftp-add-TYPE-host. The trick is to abstract these functions | |
2238 ;; without sacrificing speed. Also, having separate variables | |
2239 ;; ange-ftp-TYPE-regexp is more user friendly then requiring the user to | |
2240 ;; set an alist to indicate that a host is of a given type. Even with | |
2241 ;; automatic host type recognition, setting a regexp is still a good idea | |
2242 ;; (for efficiency) if you log into a particular non-UNIX host frequently. | |
2243 | |
2244 (defvar ange-ftp-fix-name-func-alist nil | |
2245 "Alist saying how to convert file name to the host's syntax. | |
2246 Association list of \( TYPE \. FUNC \) pairs, where FUNC is a routine | |
2247 which can change a UNIX file name into a name more suitable for a host of type | |
2248 TYPE.") | |
2249 | |
2250 (defvar ange-ftp-fix-dir-name-func-alist nil | |
2251 "Alist saying how to convert directory name to the host's syntax. | |
2252 Association list of \( TYPE \. FUNC \) pairs, where FUNC is a routine | |
2253 which can change UNIX directory name into a directory name more suitable | |
2254 for a host of type TYPE.") | |
2255 | |
2256 ;; *** Perhaps the sense of this variable should be inverted, since there | |
2257 ;; *** is only 1 host type that can take ls-style listing options. | |
2258 (defvar ange-ftp-dumb-host-types '(dumb-unix) | |
2259 "List of host types that can't take UNIX ls-style listing options.") | |
2260 | |
2261 (defun ange-ftp-send-cmd (host user cmd &optional msg cont nowait) | |
2262 "Find an ftp process connected to HOST logged in as USER and send it CMD. | |
2263 MSG is an optional status message to be output before and after issuing the | |
2264 command. | |
30459 | 2265 See the documentation for `ange-ftp-raw-send-cmd' for a description of CONT |
28210 | 2266 and NOWAIT." |
2267 ;; Handle conversion to remote file name syntax and remote ls option | |
2268 ;; capability. | |
2269 (let ((cmd0 (car cmd)) | |
2270 (cmd1 (nth 1 cmd)) | |
2271 (ange-ftp-this-user user) | |
2272 (ange-ftp-this-host host) | |
2273 (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
|
2274 cmd2 cmd3 host-type fix-name-func result) |
28210 | 2275 |
2276 (cond | |
30459 | 2277 |
28210 | 2278 ;; pwd case (We don't care what host-type.) |
2279 ((null cmd1)) | |
30459 | 2280 |
28210 | 2281 ;; cmd == 'dir "remote-name" "local-name" "ls-switches" |
2282 ((progn | |
2283 (setq cmd2 (nth 2 cmd) | |
2284 host-type (ange-ftp-host-type host user)) | |
2285 ;; This will trigger an FTP login, if one doesn't exist | |
2286 (eq cmd0 'dir)) | |
2287 (setq cmd1 (funcall | |
2288 (or (cdr (assq host-type ange-ftp-fix-dir-name-func-alist)) | |
2289 'identity) | |
2290 cmd1) | |
2291 cmd3 (nth 3 cmd)) | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
2292 ;; 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
|
2293 ;; resolve symlinks to directories on SysV machines. (Sebastian will |
28210 | 2294 ;; be happy.) |
2295 (and (eq host-type 'unix) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2296 (string-match "/\\'" cmd1) |
28210 | 2297 (not (string-match "R" cmd3)) |
2298 (setq cmd1 (concat cmd1 "."))) | |
2299 | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2300 ;; Using "ls -flags foo" has several problems: |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2301 ;; - if foo is a symlink, we may get a single line showing the symlink |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2302 ;; rather than the listing of the directory it points to. |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2303 ;; - if "foo" has spaces, the parsing of the command may be done wrong. |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2304 ;; - some version of netbsd's ftpd only accept a single argument after |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2305 ;; `ls', which can either be the directory or the flags. |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2306 ;; So to work around those problems, we use "cd foo; ls -flags". |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2307 |
28210 | 2308 ;; If the dir name contains a space, some ftp servers will |
2309 ;; refuse to list it. We instead change directory to the | |
2310 ;; directory in question and ls ".". | |
2311 (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
|
2312 ;; 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
|
2313 ;; 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
|
2314 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror)) |
28210 | 2315 (setq cmd1 ".")) |
2316 | |
2317 ;; 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
|
2318 (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
|
2319 (setq cmd0 'ls) |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2320 ;; We cd and then use `ls' with no directory argument. |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2321 ;; This works around a misfeature of some versions of netbsd ftpd |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2322 ;; where `ls' can only take one argument: either one set of flags |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2323 ;; or a file/directory name. |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2324 ;; If we're trying to `ls' a single file, this fails since we |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2325 ;; can't cd to a file. We can't fix this problem here, tho, because |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2326 ;; at this point we don't know whether the argument is a file or |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2327 ;; a directory. Such an `ls' is only ever used (apparently) from |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2328 ;; `insert-directory' when the `full-directory-p' argument is nil |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2329 ;; (which seems to only be used by dired when updating its display |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2330 ;; after operating on a set of files). So we've changed |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2331 ;; `ange-ftp-insert-directory' such that in this case it gets |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2332 ;; a full listing of the directory and extracting the line |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2333 ;; corresponding to the requested file. |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2334 (unless (equal cmd1 ".") |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2335 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2336 (setq cmd1 cmd3))) |
30459 | 2337 |
28210 | 2338 ;; First argument is the remote name |
2339 ((progn | |
2340 (setq fix-name-func (or (cdr (assq host-type | |
2341 ange-ftp-fix-name-func-alist)) | |
2342 'identity)) | |
2343 (memq cmd0 '(get delete mkdir rmdir cd))) | |
2344 (setq cmd1 (funcall fix-name-func cmd1))) | |
2345 | |
2346 ;; 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
|
2347 ((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
|
2348 (and (eq cmd0 'quote) (string= cmd1 "mdtm"))) |
28210 | 2349 (setq cmd2 (funcall fix-name-func cmd2))) |
2350 ;; Both arguments are remote names | |
2351 ((eq cmd0 'rename) | |
2352 (setq cmd1 (funcall fix-name-func cmd1) | |
2353 cmd2 (funcall fix-name-func cmd2)))) | |
30459 | 2354 |
2355 ;; Turn the command into one long string | |
28210 | 2356 (setq cmd0 (symbol-name cmd0)) |
2357 (setq cmd (concat cmd0 | |
2358 (and cmd1 (concat " " cmd1)) | |
2359 (and cmd2 (concat " " cmd2)))) | |
2360 | |
2361 ;; 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
|
2362 (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
|
2363 ;; `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
|
2364 result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2365 (let (afsc-result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2366 afsc-line) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2367 (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
|
2368 (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
|
2369 cmd |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2370 msg |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2371 (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
|
2372 (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
|
2373 afsc-line line)) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2374 (if result (ange-ftp-call-cont cont result line) |
30459 | 2375 (ange-ftp-raw-send-cmd |
2376 (ange-ftp-get-process host user) | |
2377 cmd | |
2378 msg | |
2379 (list (lambda (result line cont) | |
2380 (or cont (setq afsc-result result | |
2381 afsc-line line)) | |
2382 (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
|
2383 cont) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2384 nowait))) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2385 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
|
2386 nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2387 |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2388 (if nowait |
28210 | 2389 nil |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2390 (if cont |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2391 nil |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2392 (cons afsc-result afsc-line))))))) |
28210 | 2393 |
2394 ;; It might be nice to message users about the host type identified, | |
2395 ;; but there is so much other messaging going on, it would not be | |
2396 ;; seen. No point in slowing things down just so users can read | |
2397 ;; a host type message. | |
2398 | |
2399 (defconst ange-ftp-cms-name-template | |
2400 (concat | |
2401 "^[-A-Z0-9$*][-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?" | |
2402 "[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?\\.[0-9][0-9][0-9A-Z]$")) | |
2403 (defconst ange-ftp-vms-name-template | |
2404 "^[-A-Z0-9_$]+:\\[[-A-Z0-9_$]+\\(\\.[-A-Z0-9_$]+\\)*\\]$") | |
2405 (defconst ange-ftp-mts-name-template | |
2406 "^[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
|
2407 (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
|
2408 ":[A-Z0-9]+:" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2409 "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
|
2410 (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
|
2411 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2412 "\\$[A-Z0-9]*\\.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2413 "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
|
2414 (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
|
2415 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2416 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
|
2417 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
|
2418 "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
|
2419 (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
|
2420 (concat "^" ange-ftp-bs2000-filename-prefix-regexp "$")) |
28210 | 2421 |
2422 (defun ange-ftp-guess-host-type (host user) | |
42706 | 2423 "Guess the host type of HOST. |
28210 | 2424 Works by doing a pwd and examining the directory syntax." |
2425 (let ((host-type (ange-ftp-host-type host)) | |
2426 (key (concat host "/" user "/~"))) | |
2427 (if (eq host-type 'unix) | |
2428 ;; Note that ange-ftp-host-type returns unix as the default value. | |
2429 (save-match-data | |
2430 (let* ((result (ange-ftp-get-pwd host user)) | |
2431 (dir (car result)) | |
2432 fix-name-func) | |
2433 (cond ((null dir) | |
2434 (message "Warning! Unable to get home directory") | |
2435 (sit-for 1) | |
2436 (if (string-match | |
2437 "^450 No current working directory defined$" | |
2438 (cdr result)) | |
30459 | 2439 |
28210 | 2440 ;; We'll assume that if pwd bombs with this |
2441 ;; error message, then it's CMS. | |
2442 (progn | |
2443 (ange-ftp-add-cms-host host) | |
2444 (setq ange-ftp-host-cache host | |
2445 ange-ftp-host-type-cache 'cms)))) | |
2446 | |
2447 ;; try for VMS | |
2448 ((string-match ange-ftp-vms-name-template dir) | |
2449 (ange-ftp-add-vms-host host) | |
2450 ;; The add-host functions clear the host type cache. | |
2451 ;; Therefore, need to set the cache afterwards. | |
2452 (setq ange-ftp-host-cache host | |
2453 ange-ftp-host-type-cache 'vms)) | |
2454 | |
2455 ;; try for MTS | |
2456 ((string-match ange-ftp-mts-name-template dir) | |
2457 (ange-ftp-add-mts-host host) | |
2458 (setq ange-ftp-host-cache host | |
2459 ange-ftp-host-type-cache 'mts)) | |
30459 | 2460 |
28210 | 2461 ;; try for CMS |
2462 ((string-match ange-ftp-cms-name-template dir) | |
2463 (ange-ftp-add-cms-host host) | |
2464 (setq ange-ftp-host-cache host | |
2465 ange-ftp-host-type-cache 'cms)) | |
2466 | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2467 ;; try for BS2000-POSIX |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2468 ((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
|
2469 (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
|
2470 (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
|
2471 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
|
2472 ;; try for BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2473 ((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
|
2474 (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
|
2475 (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
|
2476 (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
|
2477 ange-ftp-host-type-cache 'bs2000)) |
28210 | 2478 ;; assume UN*X |
2479 (t | |
2480 (setq ange-ftp-host-cache host | |
2481 ange-ftp-host-type-cache 'unix))) | |
2482 | |
2483 ;; Now that we have done a pwd, might as well put it in | |
2484 ;; the expand-dir hashtable. | |
2485 (let ((ange-ftp-this-user user) | |
2486 (ange-ftp-this-host host)) | |
2487 (setq fix-name-func (cdr (assq ange-ftp-host-type-cache | |
2488 ange-ftp-fix-name-func-alist))) | |
2489 (if fix-name-func | |
2490 (setq dir (funcall fix-name-func dir 'reverse)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2491 (puthash key dir ange-ftp-expand-dir-hashtable)))) |
28210 | 2492 |
2493 ;; In the special case of CMS make sure that know the | |
2494 ;; expansion of the home minidisk now, because we will | |
2495 ;; be doing a lot of cd's. | |
2496 (if (and (eq host-type 'cms) | |
2497 (not (ange-ftp-hash-entry-exists-p | |
2498 key ange-ftp-expand-dir-hashtable))) | |
2499 (let ((dir (car (ange-ftp-get-pwd host user)))) | |
2500 (if dir | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2501 (puthash key (concat "/" dir) ange-ftp-expand-dir-hashtable) |
28210 | 2502 (message "Warning! Unable to get home directory") |
2503 (sit-for 1)))))) | |
2504 | |
2505 | |
2506 ;;;; ------------------------------------------------------------ | |
2507 ;;;; Remote file and directory listing support. | |
2508 ;;;; ------------------------------------------------------------ | |
2509 | |
2510 ;; Returns whether HOST's FTP server doesn't like \'ls\' or \'dir\' commands | |
2511 ;; to take switch arguments. | |
2512 (defun ange-ftp-dumb-unix-host (host) | |
2513 (and host ange-ftp-dumb-unix-host-regexp | |
2514 (save-match-data | |
2515 (string-match ange-ftp-dumb-unix-host-regexp host)))) | |
2516 | |
2517 (defun ange-ftp-add-dumb-unix-host (host) | |
2518 "Interactively adds a given HOST to ange-ftp-dumb-unix-host-regexp." | |
2519 (interactive | |
2520 (list (read-string "Host: " | |
2521 (let ((name (or (buffer-file-name) default-directory))) | |
2522 (and name (car (ange-ftp-ftp-name name))))))) | |
2523 (if (not (ange-ftp-dumb-unix-host host)) | |
2524 (setq ange-ftp-dumb-unix-host-regexp | |
2525 (concat "^" (regexp-quote host) "$" | |
2526 (and ange-ftp-dumb-unix-host-regexp "\\|") | |
2527 ange-ftp-dumb-unix-host-regexp) | |
2528 ange-ftp-host-cache nil))) | |
2529 | |
2530 (defvar ange-ftp-parse-list-func-alist nil | |
2531 "Alist saying how to parse directory listings for certain OS types. | |
2532 Association list of \( TYPE \. FUNC \) pairs. The FUNC is a routine | |
2533 which can parse the output from a DIR listing for a host of type TYPE.") | |
2534 | |
2535 ;; With no-error nil, this function returns: | |
2536 ;; an error if file is not an ange-ftp-name | |
30459 | 2537 ;; (This should never happen.) |
28210 | 2538 ;; an error if either the listing is unreadable or there is an ftp error. |
2539 ;; the listing (a string), if everything works. | |
30459 | 2540 ;; |
28210 | 2541 ;; With no-error t, it returns: |
2542 ;; an error if not an ange-ftp-name | |
2543 ;; error if listing is unreadable (most likely caused by a slow connection) | |
2544 ;; nil if ftp error (this is because although asking to list a nonexistent | |
2545 ;; directory on a remote unix machine usually (except | |
2546 ;; maybe for dumb hosts) returns an ls error, but no | |
2547 ;; ftp error, if the same is done on a VMS machine, | |
2548 ;; an ftp error is returned. Need to trap the error | |
2549 ;; so we can go on and try to list the parent.) | |
2550 ;; the listing, if everything works. | |
2551 | |
2552 ;; If WILDCARD is non-nil, then this implements the guts of insert-directory | |
2553 ;; in the wildcard case. Then we make a relative directory listing | |
2554 ;; of FILE within the directory specified by `default-directory'. | |
2555 | |
2556 (defvar ange-ftp-before-parse-ls-hook nil | |
2557 "Normal hook run before parsing the text of an ftp directory listing.") | |
2558 | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2559 (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
|
2560 "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
|
2561 |
28210 | 2562 (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
|
2563 "Return the output of a `DIR' or `ls' command done over ftp. |
28210 | 2564 FILE is the full name of the remote file, LSARGS is any args to pass to the |
2565 `ls' command, and PARSE specifies that the output should be parsed and stored | |
2566 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
|
2567 (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
|
2568 (setq lsargs (replace-match "" nil t lsargs))) |
28210 | 2569 ;; If parse is t, we assume that file is a directory. i.e. we only parse |
2570 ;; full directory listings. | |
2571 (let* ((ange-ftp-this-file (ange-ftp-expand-file-name file)) | |
2572 (parsed (ange-ftp-ftp-name ange-ftp-this-file))) | |
2573 (if parsed | |
2574 (let* ((host (nth 0 parsed)) | |
2575 (user (nth 1 parsed)) | |
2576 (name (ange-ftp-quote-string (nth 2 parsed))) | |
2577 (key (directory-file-name ange-ftp-this-file)) | |
2578 (host-type (ange-ftp-host-type host user)) | |
2579 (dumb (memq host-type ange-ftp-dumb-host-types)) | |
2580 result | |
2581 temp | |
2582 lscmd parse-func) | |
2583 (if (string-equal name "") | |
2584 (setq name | |
2585 (ange-ftp-real-file-name-as-directory | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2586 (ange-ftp-expand-dir host user "~")))) |
28210 | 2587 (if (and ange-ftp-ls-cache-file |
2588 (string-equal key ange-ftp-ls-cache-file) | |
2589 ;; Don't care about lsargs for dumb hosts. | |
2590 (or dumb (string-equal lsargs ange-ftp-ls-cache-lsargs))) | |
2591 ange-ftp-ls-cache-res | |
2592 (setq temp (ange-ftp-make-tmp-name host)) | |
2593 (if wildcard | |
2594 (progn | |
2595 (ange-ftp-cd host user (file-name-directory name)) | |
75552
4144cd078a1d
* files.el (get-free-disk-space): Return nil for remote
Michael Albinus <michael.albinus@gmx.de>
parents:
75347
diff
changeset
|
2596 (setq lscmd (list 'ls file temp lsargs))) |
28210 | 2597 (setq lscmd (list 'dir name temp lsargs))) |
2598 (unwind-protect | |
2599 (if (car (setq result (ange-ftp-send-cmd | |
2600 host | |
2601 user | |
2602 lscmd | |
2603 (format "Listing %s" | |
2604 (ange-ftp-abbreviate-filename | |
2605 ange-ftp-this-file))))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2606 (with-current-buffer (get-buffer-create |
65814
967a91879fee
(ange-ftp-ls): Fix typo introduced in last change.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65810
diff
changeset
|
2607 ange-ftp-data-buffer-name) |
28210 | 2608 (erase-buffer) |
2609 (if (ange-ftp-real-file-readable-p temp) | |
2610 (ange-ftp-real-insert-file-contents temp) | |
2611 (sleep-for ange-ftp-retry-time) | |
2612 ;wait for file to possibly appear | |
2613 (if (ange-ftp-real-file-readable-p temp) | |
2614 ;; Try again. | |
2615 (ange-ftp-real-insert-file-contents temp) | |
2616 (ange-ftp-error host user | |
2617 (format | |
2618 "list data file %s not readable" | |
2619 temp)))) | |
30518
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2620 ;; 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
|
2621 (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
|
2622 (replace-match "")) |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2623 (goto-char 1) |
28210 | 2624 (run-hooks 'ange-ftp-before-parse-ls-hook) |
2625 (if parse | |
2626 (ange-ftp-set-files | |
2627 ange-ftp-this-file | |
2628 (if (setq | |
2629 parse-func | |
2630 (cdr (assq host-type | |
2631 ange-ftp-parse-list-func-alist))) | |
2632 (funcall parse-func) | |
2633 (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
|
2634 ;; 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
|
2635 ;; 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
|
2636 ;; 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
|
2637 ;; 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
|
2638 (run-hooks 'ange-ftp-after-parse-ls-hook) |
28210 | 2639 (setq ange-ftp-ls-cache-file key |
2640 ange-ftp-ls-cache-lsargs lsargs | |
2641 ; For dumb hosts-types this is | |
2642 ; meaningless but harmless. | |
2643 ange-ftp-ls-cache-res (buffer-string)) | |
2644 ;; (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
|
2645 (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
|
2646 ;; 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
|
2647 ;; 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
|
2648 ;; `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
|
2649 ;; 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
|
2650 nil |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2651 ange-ftp-ls-cache-res)) |
28210 | 2652 (if no-error |
2653 nil | |
2654 (ange-ftp-error host user | |
2655 (concat "DIR failed: " (cdr result))))) | |
2656 (ange-ftp-del-tmp-name temp)))) | |
2657 (error "Should never happen. Please report. Bug ref. no.: 1")))) | |
2658 | |
2659 ;;;; ------------------------------------------------------------ | |
2660 ;;;; Directory information caching support. | |
2661 ;;;; ------------------------------------------------------------ | |
2662 | |
2663 (defvar ange-ftp-add-file-entry-alist nil | |
2664 "Alist saying how to add file entries on certain OS types. | |
2665 Association list of pairs \( TYPE \. FUNC \), where FUNC | |
2666 is a function to be used to add a file entry for the OS TYPE. The | |
2667 main reason for this alist is to deal with file versions in VMS.") | |
2668 | |
2669 (defvar ange-ftp-delete-file-entry-alist nil | |
2670 "Alist saying how to delete files on certain OS types. | |
2671 Association list of pairs \( TYPE \. FUNC \), where FUNC | |
2672 is a function to be used to delete a file entry for the OS TYPE. | |
2673 The main reason for this alist is to deal with file versions in VMS.") | |
2674 | |
2675 (defun ange-ftp-add-file-entry (name &optional dir-p) | |
2676 "Add a file entry for file NAME, if its directory info exists." | |
2677 (funcall (or (cdr (assq (ange-ftp-host-type | |
2678 (car (ange-ftp-ftp-name name))) | |
2679 ange-ftp-add-file-entry-alist)) | |
2680 'ange-ftp-internal-add-file-entry) | |
2681 name dir-p) | |
2682 (setq ange-ftp-ls-cache-file nil)) | |
2683 | |
2684 (defun ange-ftp-delete-file-entry (name &optional dir-p) | |
2685 "Delete the file entry for file NAME, if its directory info exists." | |
2686 (funcall (or (cdr (assq (ange-ftp-host-type | |
2687 (car (ange-ftp-ftp-name name))) | |
2688 ange-ftp-delete-file-entry-alist)) | |
2689 'ange-ftp-internal-delete-file-entry) | |
2690 name dir-p) | |
2691 (setq ange-ftp-ls-cache-file nil)) | |
2692 | |
2693 (defmacro ange-ftp-parse-filename () | |
2694 ;;Extract the filename from the current line of a dired-like listing. | |
30459 | 2695 `(let ((eol (progn (end-of-line) (point)))) |
2696 (beginning-of-line) | |
66325
fda96ff4c7e5
* files.el (directory-listing-before-filename-regexp): New
Michael Albinus <michael.albinus@gmx.de>
parents:
66256
diff
changeset
|
2697 (if (re-search-forward directory-listing-before-filename-regexp eol t) |
fda96ff4c7e5
* files.el (directory-listing-before-filename-regexp): New
Michael Albinus <michael.albinus@gmx.de>
parents:
66256
diff
changeset
|
2698 (buffer-substring (point) eol)))) |
30459 | 2699 |
28210 | 2700 ;; This deals with the F switch. Should also do something about |
2701 ;; unquoting names obtained with the SysV b switch and the GNU Q | |
2702 ;; switch. See Sebastian's dired-get-filename. | |
2703 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2704 (defun ange-ftp-ls-parser (switches) |
28210 | 2705 ;; 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
|
2706 (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
|
2707 (used-F (and (stringp switches) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2708 (string-match "F" switches))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2709 file-type symlink directory file) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2710 (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
|
2711 (beginning-of-line) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2712 (skip-chars-forward "\t 0-9") |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2713 (setq file-type (following-char) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2714 directory (eq file-type ?d)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2715 (if (eq file-type ?l) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2716 (let ((end (string-match " -> " file))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2717 (if end |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2718 ;; 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
|
2719 (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
|
2720 (string-match "@\\'" file)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2721 file (substring file 0 end)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2722 ;; Shouldn't happen |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2723 (setq symlink ""))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2724 (setq symlink nil)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2725 ;; 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
|
2726 (if (and used-F |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2727 (not (string-equal file "")) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2728 (looking-at |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2729 ".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)")) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2730 (let ((socket (eq file-type ?s)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2731 (executable |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2732 (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
|
2733 (string-match |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2734 "[xst]" |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2735 (concat (match-string 1) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2736 (match-string 2) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2737 (match-string 3)))))) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2738 ;; 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
|
2739 ;; 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
|
2740 ;; seem to believe in the F-switch |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2741 (if (or (and symlink (string-match "@\\'" file)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2742 (and directory (string-match "/\\'" file)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2743 (and executable (string-match "*\\'" file)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2744 (and socket (string-match "=\\'" file))) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2745 (setq file (substring file 0 -1))))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2746 (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
|
2747 (forward-line 1)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2748 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2749 (puthash ".." t tbl) |
30459 | 2750 tbl)) |
28210 | 2751 |
2752 ;;; The dl stuff for descriptive listings | |
2753 | |
2754 (defvar ange-ftp-dl-dir-regexp nil | |
2755 "Regexp matching directories which are listed in dl format. | |
2756 This regexp should not be anchored with a trailing `$', because it should | |
2757 match subdirectories as well.") | |
2758 | |
2759 (defun ange-ftp-add-dl-dir (dir) | |
2760 "Interactively adds a DIR to ange-ftp-dl-dir-regexp." | |
2761 (interactive | |
2762 (list (read-string "Directory: " | |
2763 (let ((name (or (buffer-file-name) default-directory))) | |
2764 (and name (ange-ftp-ftp-name name) | |
2765 (file-name-directory name)))))) | |
2766 (if (not (and ange-ftp-dl-dir-regexp | |
2767 (string-match ange-ftp-dl-dir-regexp dir))) | |
2768 (setq ange-ftp-dl-dir-regexp | |
2769 (concat "^" (regexp-quote dir) | |
2770 (and ange-ftp-dl-dir-regexp "\\|") | |
2771 ange-ftp-dl-dir-regexp)))) | |
2772 | |
2773 (defmacro ange-ftp-dl-parser () | |
2774 ;; Parse the current buffer, which is assumed to be a descriptive | |
2775 ;; listing, and return a hashtable. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2776 `(let ((tbl (make-hash-table :test 'equal))) |
30459 | 2777 (while (not (eobp)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2778 (puthash |
30459 | 2779 (buffer-substring (point) |
2780 (progn | |
2781 (skip-chars-forward "^ /\n") | |
2782 (point))) | |
2783 (eq (following-char) ?/) | |
2784 tbl) | |
2785 (forward-line 1)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2786 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2787 (puthash ".." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2788 tbl)) |
28210 | 2789 |
2790 ;; Parse the current buffer which is assumed to be in a dired-like listing | |
2791 ;; format, and return a hashtable as the result. If the listing is not really | |
2792 ;; a listing, then return nil. | |
2793 | |
2794 (defun ange-ftp-parse-dired-listing (&optional switches) | |
2795 (save-match-data | |
2796 (cond | |
2797 ((looking-at "^total [0-9]+$") | |
2798 (forward-line 1) | |
2799 ;; Some systems put in a blank line here. | |
2800 (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
|
2801 (ange-ftp-ls-parser switches)) |
28210 | 2802 ((looking-at "[^\n]+\\( not found\\|: Not a directory\\)\n\\'") |
2803 ;; It's an ls error message. | |
2804 nil) | |
2805 ((eobp) ; i.e. (zerop (buffer-size)) | |
2806 ;; This could be one of: | |
2807 ;; (1) An Ultrix ls error message | |
2808 ;; (2) A listing with the A switch of an empty directory | |
2809 ;; on a machine which doesn't give a total line. | |
2810 ;; (3) The twilight zone. | |
2811 ;; We'll assume (1) for now. | |
2812 nil) | |
66325
fda96ff4c7e5
* files.el (directory-listing-before-filename-regexp): New
Michael Albinus <michael.albinus@gmx.de>
parents:
66256
diff
changeset
|
2813 ((re-search-forward directory-listing-before-filename-regexp nil t) |
28210 | 2814 (beginning-of-line) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2815 (ange-ftp-ls-parser switches)) |
28210 | 2816 ((re-search-forward "^[^ \n\t]+ +\\([0-9]+\\|-\\|=\\) " nil t) |
2817 ;; It's a dl listing (I hope). | |
2818 ;; file is bound by the call to ange-ftp-ls | |
2819 (ange-ftp-add-dl-dir ange-ftp-this-file) | |
2820 (beginning-of-line) | |
2821 (ange-ftp-dl-parser)) | |
2822 (t nil)))) | |
2823 | |
2824 (defun ange-ftp-set-files (directory files) | |
2825 "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
|
2826 (and files (puthash (file-name-as-directory directory) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2827 files ange-ftp-files-hashtable))) |
28210 | 2828 |
2829 (defun ange-ftp-get-files (directory &optional no-error) | |
2830 "Given a given DIRECTORY, return a hashtable of file entries. | |
2831 This will give an error or return nil, depending on the value of | |
2832 NO-ERROR, if a listing for DIRECTORY cannot be obtained." | |
2833 (setq directory (file-name-as-directory directory)) ;normalize | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2834 (or (gethash directory ange-ftp-files-hashtable) |
28210 | 2835 (save-match-data |
2836 (and (ange-ftp-ls directory | |
2837 ;; This is an efficiency hack. We try to | |
2838 ;; anticipate what sort of listing dired | |
2839 ;; might want, and cache just such a listing. | |
2840 (if (and (boundp 'dired-actual-switches) | |
2841 (stringp dired-actual-switches) | |
2842 ;; We allow the A switch, which lists | |
2843 ;; all files except "." and "..". | |
2844 ;; This is OK because we manually | |
2845 ;; insert these entries | |
2846 ;; in the hash table. | |
2847 (string-match | |
2848 "[aA]" dired-actual-switches) | |
2849 (string-match | |
2850 "l" dired-actual-switches) | |
2851 (not (string-match | |
2852 "R" dired-actual-switches))) | |
2853 dired-actual-switches | |
2854 (if (and (boundp 'dired-listing-switches) | |
2855 (stringp dired-listing-switches) | |
2856 (string-match | |
2857 "[aA]" dired-listing-switches) | |
2858 (string-match | |
2859 "l" dired-listing-switches) | |
2860 (not (string-match | |
2861 "R" dired-listing-switches))) | |
2862 dired-listing-switches | |
2863 "-al")) | |
2864 t no-error) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2865 (gethash directory ange-ftp-files-hashtable))))) |
28210 | 2866 |
2867 ;; Given NAME, return the file part that can be used for looking up the | |
2868 ;; file's entry in a hashtable. | |
2869 (defmacro ange-ftp-get-file-part (name) | |
30459 | 2870 `(let ((file (file-name-nondirectory ,name))) |
2871 (if (string-equal file "") | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2872 "." |
30459 | 2873 file))) |
28210 | 2874 |
2875 ;; Return whether ange-ftp-file-entry-p and ange-ftp-get-file-entry are | |
2876 ;; allowed to determine if NAME is a sub-directory by listing it directly, | |
2877 ;; rather than listing its parent directory. This is used for efficiency so | |
2878 ;; that a wasted listing is not done: | |
2879 ;; 1. When looking for a .dired file in dired-x.el. | |
2880 ;; 2. The syntax of FILE and DIR make it impossible that FILE could be a valid | |
2881 ;; subdirectory. This is of course an OS dependent judgement. | |
2882 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2883 (defvar dired-local-variables-file) |
28210 | 2884 (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
|
2885 `(not |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2886 (let* ((efile ,file) ; expand once. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2887 (edir ,dir) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2888 (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
|
2889 (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
|
2890 (car parsed)))) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2891 (or |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2892 ;; Deal with dired |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2893 (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
|
2894 (stringp dired-local-variables-file) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2895 (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
|
2896 ;; 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
|
2897 (and (eq host-type 'vms) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2898 (string-match "\\." efile)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2899 ;; 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
|
2900 (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
|
2901 (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
|
2902 ;; 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
|
2903 (and (eq host-type 'bs2000) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2904 (string-match "\\." efile)))))) |
28210 | 2905 |
2906 (defun ange-ftp-file-entry-p (name) | |
2907 "Given NAME, return whether there is a file entry for it." | |
2908 (let* ((name (directory-file-name name)) | |
2909 (dir (file-name-directory name)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2910 (ent (gethash dir ange-ftp-files-hashtable)) |
28210 | 2911 (file (ange-ftp-get-file-part name))) |
2912 (if ent | |
2913 (ange-ftp-hash-entry-exists-p file ent) | |
2914 (or (and (ange-ftp-allow-child-lookup dir file) | |
2915 (setq ent (ange-ftp-get-files name t)) | |
2916 ;; Try a child lookup. i.e. try to list file as a | |
2917 ;; subdirectory of dir. This is a good idea because | |
2918 ;; we may not have read permission for file's parent. Also, | |
2919 ;; people tend to work down directory trees anyway. We use | |
2920 ;; no-error ;; because if file does not exist as a subdir., | |
2921 ;; then dumb hosts will give an ftp error. Smart unix hosts | |
2922 ;; will simply send back the ls | |
2923 ;; error message. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2924 (gethash "." ent)) |
28210 | 2925 ;; Child lookup failed, so try the parent. |
56742
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
2926 (ange-ftp-hash-entry-exists-p |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
2927 file (ange-ftp-get-files dir 'no-error)))))) |
28210 | 2928 |
2929 (defun ange-ftp-get-file-entry (name) | |
2930 "Given NAME, return the given file entry. | |
2931 The entry will be either t for a directory, nil for a normal file, | |
2932 or a string for a symlink. If the file isn't in the hashtable, | |
2933 this also returns nil." | |
2934 (let* ((name (directory-file-name name)) | |
2935 (dir (file-name-directory name)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2936 (ent (gethash dir ange-ftp-files-hashtable)) |
28210 | 2937 (file (ange-ftp-get-file-part name))) |
2938 (if ent | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2939 (gethash file ent) |
28210 | 2940 (or (and (ange-ftp-allow-child-lookup dir file) |
2941 (setq ent (ange-ftp-get-files name t)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2942 (gethash "." ent)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2943 ;; 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
|
2944 (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
|
2945 (gethash file ent)))))) |
28210 | 2946 |
2947 (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
|
2948 (when dir-p |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2949 (setq name (file-name-as-directory name)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2950 (remhash name ange-ftp-files-hashtable) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2951 (setq name (directory-file-name name))) |
28210 | 2952 ;; Note that file-name-as-directory followed by directory-file-name |
2953 ;; serves to canonicalize directory file names to their unix form. | |
2954 ;; i.e. in VMS, FOO.DIR -> FOO/ -> FOO | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2955 (let ((files (gethash (file-name-directory name) ange-ftp-files-hashtable))) |
28210 | 2956 (if files |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2957 (remhash (ange-ftp-get-file-part name) files)))) |
28210 | 2958 |
2959 (defun ange-ftp-internal-add-file-entry (name &optional dir-p) | |
2960 (and dir-p | |
2961 (setq name (directory-file-name name))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2962 (let ((files (gethash (file-name-directory name) ange-ftp-files-hashtable))) |
28210 | 2963 (if files |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2964 (puthash (ange-ftp-get-file-part name) dir-p files)))) |
28210 | 2965 |
2966 (defun ange-ftp-wipe-file-entries (host user) | |
2967 "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
|
2968 (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
|
2969 :size (hash-table-size |
6e8123be5cab
(ange-ftp-wipe-file-entries): Fix type mismatch;
David Kastrup <dak@gnu.org>
parents:
46811
diff
changeset
|
2970 ange-ftp-files-hashtable)))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2971 (maphash |
30459 | 2972 (lambda (key val) |
2973 (let ((parsed (ange-ftp-ftp-name key))) | |
2974 (if parsed | |
2975 (let ((h (nth 0 parsed)) | |
2976 (u (nth 1 parsed))) | |
2977 (or (and (equal host h) (equal user u)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2978 (puthash key val new-tbl)))))) |
28210 | 2979 ange-ftp-files-hashtable) |
2980 (setq ange-ftp-files-hashtable new-tbl))) | |
2981 | |
2982 ;;;; ------------------------------------------------------------ | |
2983 ;;;; File transfer mode support. | |
2984 ;;;; ------------------------------------------------------------ | |
2985 | |
2986 (defun ange-ftp-set-binary-mode (host user) | |
2987 "Tell the ftp process for the given HOST & USER to switch to binary mode." | |
2988 (let ((result (ange-ftp-send-cmd host user '(type "binary")))) | |
2989 (if (not (car result)) | |
2990 (ange-ftp-error host user (concat "BINARY failed: " (cdr result))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2991 (with-current-buffer (process-buffer (ange-ftp-get-process host user)) |
28210 | 2992 (and ange-ftp-binary-hash-mark-size |
2993 (setq ange-ftp-hash-mark-unit | |
2994 (ash ange-ftp-binary-hash-mark-size -4))))))) | |
2995 | |
2996 (defun ange-ftp-set-ascii-mode (host user) | |
2997 "Tell the ftp process for the given HOST & USER to switch to ascii mode." | |
2998 (let ((result (ange-ftp-send-cmd host user '(type "ascii")))) | |
2999 (if (not (car result)) | |
3000 (ange-ftp-error host user (concat "ASCII failed: " (cdr result))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
3001 (with-current-buffer (process-buffer (ange-ftp-get-process host user)) |
28210 | 3002 (and ange-ftp-ascii-hash-mark-size |
3003 (setq ange-ftp-hash-mark-unit | |
3004 (ash ange-ftp-ascii-hash-mark-size -4))))))) | |
3005 | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3006 (defun ange-ftp-cd (host user dir &optional noerror) |
28210 | 3007 (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
|
3008 (if noerror result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3009 (or (car result) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3010 (ange-ftp-error host user (concat "CD failed: " (cdr result))))))) |
28210 | 3011 |
3012 (defun ange-ftp-get-pwd (host user) | |
3013 "Attempts to get the current working directory for the given HOST/USER pair. | |
3014 Returns \( DIR . LINE \) where DIR is either the directory or nil if not found, | |
3015 and LINE is the relevant success or fail line from the FTP-client." | |
3016 (let* ((result (ange-ftp-send-cmd host user '(pwd) "Getting PWD")) | |
3017 (line (cdr result)) | |
3018 dir) | |
3019 (if (car result) | |
3020 (save-match-data | |
3021 (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
|
3022 (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
|
3023 (setq dir (match-string 1 line))))) |
28210 | 3024 (cons dir line))) |
3025 | |
3026 ;;; ------------------------------------------------------------ | |
3027 ;;; expand-file-name and friends...which currently don't work | |
3028 ;;; ------------------------------------------------------------ | |
3029 | |
3030 (defun ange-ftp-expand-dir (host user dir) | |
3031 "Return the result of doing a PWD in the current FTP session. | |
3032 Use the connection to machine HOST | |
3033 logged in as user USER and cd'd to directory DIR." | |
3034 (let* ((host-type (ange-ftp-host-type host user)) | |
3035 ;; It is more efficient to call ange-ftp-host-type | |
3036 ;; before binding res, because ange-ftp-host-type sometimes | |
3037 ;; adds to the info in the expand-dir-hashtable. | |
3038 (fix-name-func | |
3039 (cdr (assq host-type ange-ftp-fix-name-func-alist))) | |
3040 (key (concat host "/" user "/" dir)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3041 (res (gethash key ange-ftp-expand-dir-hashtable))) |
28210 | 3042 (or res |
3043 (progn | |
3044 (or | |
3045 (string-equal user "anonymous") | |
3046 (string-equal user "ftp") | |
3047 (not (eq host-type 'unix)) | |
3048 (let* ((ange-ftp-good-msgs (concat ange-ftp-expand-dir-regexp | |
3049 "\\|" | |
3050 ange-ftp-good-msgs)) | |
3051 (result (ange-ftp-send-cmd host user | |
3052 (list 'get dir null-device) | |
3053 (format "expanding %s" dir))) | |
3054 (line (cdr result))) | |
3055 (setq res | |
3056 (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
|
3057 (match-string 1 line))))) |
28210 | 3058 (or res |
3059 (if (string-equal dir "~") | |
3060 (setq res (car (ange-ftp-get-pwd host user))) | |
3061 (let ((home (ange-ftp-expand-dir host user "~"))) | |
3062 (unwind-protect | |
3063 (and (ange-ftp-cd host user dir) | |
3064 (setq res (car (ange-ftp-get-pwd host user)))) | |
3065 (ange-ftp-cd host user home))))) | |
3066 (if res | |
3067 (let ((ange-ftp-this-user user) | |
3068 (ange-ftp-this-host host)) | |
3069 (if fix-name-func | |
3070 (setq res (funcall fix-name-func res 'reverse))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3071 (puthash key res ange-ftp-expand-dir-hashtable))) |
28210 | 3072 res)))) |
3073 | |
3074 (defun ange-ftp-canonize-filename (n) | |
3075 "Take a string and short-circuit //, /. and /.." | |
3076 (if (string-match "[^:]+//" n) ;don't upset Apollo users | |
3077 (setq n (substring n (1- (match-end 0))))) | |
3078 (let ((parsed (ange-ftp-ftp-name n))) | |
3079 (if parsed | |
3080 (let ((host (car parsed)) | |
3081 (user (nth 1 parsed)) | |
3082 (name (nth 2 parsed))) | |
30459 | 3083 |
28210 | 3084 ;; See if remote name is absolute. If so then just expand it and |
3085 ;; replace the name component of the overall name. | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3086 (cond ((string-match "\\`/" name) |
28210 | 3087 name) |
30459 | 3088 |
28210 | 3089 ;; Name starts with ~ or ~user. Resolve that part of the name |
3090 ;; making it absolute then re-expand it. | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3091 ((string-match "\\`~[^/]*" name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3092 (let* ((tilda (match-string 0 name)) |
28210 | 3093 (rest (substring name (match-end 0))) |
3094 (dir (ange-ftp-expand-dir host user tilda))) | |
3095 (if dir | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3096 ;; C-x d /ftp:anonymous@ftp.gnu.org:~/ RET |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3097 ;; seems to cause `rest' to sometimes be empty. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3098 ;; Maybe it's an error for `rest' to be empty here, |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3099 ;; but until we figure this out, this quick fix |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3100 ;; seems to do the trick. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3101 (setq name (cond ((string-equal rest "") dir) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3102 ((string-equal dir "/") rest) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3103 (t (concat dir rest)))) |
30459 | 3104 (error "User \"%s\" is not known" |
28210 | 3105 (substring tilda 1))))) |
30459 | 3106 |
28210 | 3107 ;; relative name. Tack on homedir and re-expand. |
3108 (t | |
3109 (let ((dir (ange-ftp-expand-dir host user "~"))) | |
3110 (if dir | |
3111 (setq name (concat | |
3112 (ange-ftp-real-file-name-as-directory dir) | |
3113 name)) | |
3114 (error "Unable to obtain CWD"))))) | |
30459 | 3115 |
28210 | 3116 ;; If name starts with //, preserve that, for apollo system. |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3117 (unless (string-match "\\`//" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3118 (if (not (eq system-type 'windows-nt)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3119 (setq name (ange-ftp-real-expand-file-name name)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3120 ;; Windows UNC default dirs do not make sense for ftp. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3121 (setq name (if (string-match "\\`//" default-directory) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3122 (ange-ftp-real-expand-file-name name "c:/") |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3123 (ange-ftp-real-expand-file-name name))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3124 ;; Strip off possible drive specifier. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3125 (if (string-match "\\`[a-zA-Z]:" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3126 (setq name (substring name 2)))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3127 (if (string-match "\\`//" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3128 (setq name (substring name 1)))) |
30459 | 3129 |
28210 | 3130 ;; Now substitute the expanded name back into the overall filename. |
3131 (ange-ftp-replace-name-component n name)) | |
30459 | 3132 |
28210 | 3133 ;; non-ange-ftp name. Just expand normally. |
3134 (if (eq (string-to-char n) ?/) | |
3135 (ange-ftp-real-expand-file-name n) | |
3136 (ange-ftp-real-expand-file-name | |
3137 (ange-ftp-real-file-name-nondirectory n) | |
3138 (ange-ftp-real-file-name-directory n)))))) | |
3139 | |
3140 (defun ange-ftp-expand-file-name (name &optional default) | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3141 "Documented as `expand-file-name'." |
28210 | 3142 (save-match-data |
3143 (setq default (or default default-directory)) | |
3144 (cond ((eq (string-to-char name) ?~) | |
3145 (ange-ftp-real-expand-file-name name)) | |
3146 ((eq (string-to-char name) ?/) | |
3147 (ange-ftp-canonize-filename name)) | |
3148 ((and (eq system-type 'windows-nt) | |
3149 (eq (string-to-char name) ?\\)) | |
3150 (ange-ftp-canonize-filename name)) | |
3151 ((and (eq system-type 'windows-nt) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3152 (or (string-match "\\`[a-zA-Z]:" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3153 (string-match "\\`[a-zA-Z]:" default))) |
28210 | 3154 (ange-ftp-real-expand-file-name name default)) |
3155 ((zerop (length name)) | |
3156 (ange-ftp-canonize-filename default)) | |
3157 ((ange-ftp-canonize-filename | |
3158 (concat (file-name-as-directory default) name)))))) | |
3159 | |
3160 ;;; These are problems--they are currently not enabled. | |
3161 | |
3162 (defvar ange-ftp-file-name-as-directory-alist nil | |
3163 "Association list of \( TYPE \. FUNC \) pairs. | |
3164 FUNC converts a filename to a directory name for the operating | |
3165 system TYPE.") | |
3166 | |
3167 (defun ange-ftp-file-name-as-directory (name) | |
3168 "Documented as original." | |
3169 (let ((parsed (ange-ftp-ftp-name name))) | |
3170 (if parsed | |
3171 (if (string-equal (nth 2 parsed) "") | |
3172 name | |
3173 (funcall (or (cdr (assq | |
3174 (ange-ftp-host-type (car parsed)) | |
3175 ange-ftp-file-name-as-directory-alist)) | |
3176 'ange-ftp-real-file-name-as-directory) | |
3177 name)) | |
3178 (ange-ftp-real-file-name-as-directory name)))) | |
30459 | 3179 |
28210 | 3180 (defun ange-ftp-file-name-directory (name) |
3181 "Documented as original." | |
3182 (let ((parsed (ange-ftp-ftp-name name))) | |
3183 (if parsed | |
3184 (let ((filename (nth 2 parsed))) | |
3185 (if (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3186 (string-match "\\`~[^/]*\\'" filename)) |
28210 | 3187 name |
3188 (ange-ftp-replace-name-component | |
3189 name | |
3190 (ange-ftp-real-file-name-directory filename)))) | |
3191 (ange-ftp-real-file-name-directory name)))) | |
3192 | |
3193 (defun ange-ftp-file-name-nondirectory (name) | |
3194 "Documented as original." | |
3195 (let ((parsed (ange-ftp-ftp-name name))) | |
3196 (if parsed | |
3197 (let ((filename (nth 2 parsed))) | |
3198 (if (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3199 (string-match "\\`~[^/]*\\'" filename)) |
28210 | 3200 "" |
3201 (ange-ftp-real-file-name-nondirectory filename))) | |
3202 (ange-ftp-real-file-name-nondirectory name)))) | |
3203 | |
3204 (defun ange-ftp-directory-file-name (dir) | |
3205 "Documented as original." | |
3206 (let ((parsed (ange-ftp-ftp-name dir))) | |
3207 (if parsed | |
3208 (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
|
3209 dir |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3210 (ange-ftp-real-directory-file-name (nth 2 parsed))) |
28210 | 3211 (ange-ftp-real-directory-file-name dir)))) |
3212 | |
3213 | |
3214 ;;; Hooks that handle Emacs primitives. | |
3215 | |
3216 ;; Returns non-nil if should transfer FILE in binary mode. | |
3217 (defun ange-ftp-binary-file (file) | |
3218 (save-match-data | |
3219 (string-match ange-ftp-binary-file-name-regexp file))) | |
3220 | |
3221 (defun ange-ftp-write-region (start end filename &optional append visit) | |
3222 (setq filename (expand-file-name filename)) | |
3223 (let ((parsed (ange-ftp-ftp-name filename))) | |
3224 (if parsed | |
3225 (let* ((host (nth 0 parsed)) | |
3226 (user (nth 1 parsed)) | |
3227 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3228 (temp (ange-ftp-make-tmp-name host)) | |
3229 ;; What we REALLY need here is a way to determine if the mode | |
3230 ;; of the transfer is irrelevant, i.e. we can use binary mode | |
3231 ;; regardless. Maybe a system-type to host-type lookup? | |
3232 (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
|
3233 (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
|
3234 '(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
|
3235 (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
|
3236 '(unix dumb-unix))))) |
28210 | 3237 (cmd (if append 'append 'put)) |
3238 (abbr (ange-ftp-abbreviate-filename filename)) | |
3239 ;; we need to reset `last-coding-system-used' to its | |
3240 ;; value immediately after calling the real write-region, | |
3241 ;; so that `basic-save-buffer' doesn't see whatever value | |
3242 ;; might be used when communicating with the ftp process. | |
3243 (coding-system-used last-coding-system-used)) | |
3244 (unwind-protect | |
3245 (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
|
3246 (let ((filename (buffer-file-name)) |
28210 | 3247 (mod-p (buffer-modified-p))) |
3248 (unwind-protect | |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3249 (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
|
3250 (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
|
3251 (or visit 'quiet)) |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3252 (setq coding-system-used last-coding-system-used)) |
28210 | 3253 ;; cleanup forms |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3254 (setq coding-system-used last-coding-system-used) |
28210 | 3255 (setq buffer-file-name filename) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
3256 (restore-buffer-modified-p mod-p))) |
28210 | 3257 (if binary |
3258 (ange-ftp-set-binary-mode host user)) | |
3259 | |
3260 ;; tell the process filter what size the transfer will be. | |
3261 (let ((attr (file-attributes temp))) | |
3262 (if attr | |
3263 (ange-ftp-set-xfer-size host user (nth 7 attr)))) | |
3264 | |
3265 ;; put or append the file. | |
3266 (let ((result (ange-ftp-send-cmd host user | |
3267 (list cmd temp name) | |
3268 (format "Writing %s" abbr)))) | |
3269 (or (car result) | |
3270 (signal 'ftp-error | |
3271 (list | |
3272 "Opening output file" | |
3273 (format "FTP Error: \"%s\"" (cdr result)) | |
3274 filename))))) | |
3275 (ange-ftp-del-tmp-name temp) | |
30459 | 3276 (if binary |
28210 | 3277 (ange-ftp-set-ascii-mode host user))) |
3278 (if (eq visit t) | |
3279 (progn | |
30459 | 3280 (set-visited-file-modtime (ange-ftp-file-modtime filename)) |
28210 | 3281 (ange-ftp-set-buffer-mode) |
3282 (setq buffer-file-name filename) | |
3283 (set-buffer-modified-p nil))) | |
3284 ;; ensure `last-coding-system-used' has an appropriate value | |
3285 (setq last-coding-system-used coding-system-used) | |
3286 (ange-ftp-message "Wrote %s" abbr) | |
3287 (ange-ftp-add-file-entry filename)) | |
3288 (ange-ftp-real-write-region start end filename append visit)))) | |
3289 | |
3290 (defun ange-ftp-insert-file-contents (filename &optional visit beg end replace) | |
3291 (barf-if-buffer-read-only) | |
3292 (setq filename (expand-file-name filename)) | |
3293 (let ((parsed (ange-ftp-ftp-name filename))) | |
3294 (if parsed | |
3295 (progn | |
3296 (if visit | |
3297 (setq buffer-file-name filename)) | |
3298 (if (or (file-exists-p filename) | |
3299 (progn | |
3300 (setq ange-ftp-ls-cache-file nil) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3301 (remhash (file-name-directory filename) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3302 ange-ftp-files-hashtable) |
28210 | 3303 (file-exists-p filename))) |
3304 (let* ((host (nth 0 parsed)) | |
3305 (user (nth 1 parsed)) | |
3306 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3307 (temp (ange-ftp-make-tmp-name host)) | |
3308 (binary (or (ange-ftp-binary-file filename) | |
3309 (memq (ange-ftp-host-type host user) | |
3310 '(unix dumb-unix)))) | |
3311 (abbr (ange-ftp-abbreviate-filename filename)) | |
3312 (coding-system-used last-coding-system-used) | |
3313 size) | |
3314 (unwind-protect | |
3315 (progn | |
3316 (if binary | |
3317 (ange-ftp-set-binary-mode host user)) | |
3318 (let ((result (ange-ftp-send-cmd host user | |
3319 (list 'get name temp) | |
3320 (format "Retrieving %s" abbr)))) | |
3321 (or (car result) | |
3322 (signal 'ftp-error | |
3323 (list | |
3324 "Opening input file" | |
3325 (format "FTP Error: \"%s\"" (cdr result)) | |
3326 filename)))) | |
3327 (if (or (ange-ftp-real-file-readable-p temp) | |
3328 (sleep-for ange-ftp-retry-time) | |
3329 ;; Wait for file to hopefully appear. | |
3330 (ange-ftp-real-file-readable-p temp)) | |
3331 (setq | |
3332 size | |
3333 (nth 1 (ange-ftp-real-insert-file-contents | |
3334 temp visit beg end replace)) | |
3335 coding-system-used last-coding-system-used | |
3336 ;; override autodetection of buffer file type | |
3337 ;; to ensure buffer is saved in DOS format | |
3338 buffer-file-type binary) | |
3339 (signal 'ftp-error | |
3340 (list | |
3341 "Opening input file:" | |
3342 (format | |
3343 "FTP Error: %s not arrived or readable" | |
3344 filename))))) | |
3345 (if binary | |
3346 ;; We must keep `last-coding-system-used' | |
3347 ;; unchanged. | |
3348 (let (last-coding-system-used) | |
3349 (ange-ftp-set-ascii-mode host user))) | |
3350 (ange-ftp-del-tmp-name temp)) | |
3351 (if visit | |
3352 (progn | |
30459 | 3353 (set-visited-file-modtime |
3354 (ange-ftp-file-modtime filename)) | |
28210 | 3355 (setq buffer-file-name filename))) |
3356 (setq last-coding-system-used coding-system-used) | |
3357 (list filename size)) | |
3358 (signal 'file-error | |
30459 | 3359 (list |
28210 | 3360 "Opening input file" |
3361 filename)))) | |
3362 (ange-ftp-real-insert-file-contents filename visit beg end replace)))) | |
30459 | 3363 |
28210 | 3364 (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
|
3365 (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
|
3366 (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
|
3367 (expand-file-name file dir)))) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3368 (if (file-symlink-p res) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3369 (ange-ftp-expand-symlink |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3370 (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
|
3371 (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
|
3372 res))) |
28210 | 3373 |
3374 (defun ange-ftp-file-symlink-p (file) | |
3375 ;; call ange-ftp-expand-file-name rather than the normal | |
3376 ;; expand-file-name to stop loops when using a package that | |
3377 ;; redefines both file-symlink-p and expand-file-name. | |
3378 (setq file (ange-ftp-expand-file-name file)) | |
3379 (if (ange-ftp-ftp-name file) | |
51799
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3380 (condition-case nil |
56742
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3381 (let ((ent (ange-ftp-get-files (file-name-directory file)))) |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3382 (and ent |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3383 (stringp (setq ent |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3384 (gethash (ange-ftp-get-file-part file) ent))) |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3385 ent)) |
51799
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3386 ;; 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
|
3387 ;; this file is not a symlink. |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3388 ;; 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
|
3389 ;; whose parent is not readable. |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3390 (file-error nil)) |
28210 | 3391 (ange-ftp-real-file-symlink-p file))) |
3392 | |
3393 (defun ange-ftp-file-exists-p (name) | |
3394 (setq name (expand-file-name name)) | |
3395 (if (ange-ftp-ftp-name name) | |
3396 (if (ange-ftp-file-entry-p name) | |
3397 (let ((file-ent (ange-ftp-get-file-entry name))) | |
3398 (if (stringp file-ent) | |
3399 (file-exists-p | |
3400 (ange-ftp-expand-symlink file-ent | |
3401 (file-name-directory | |
3402 (directory-file-name name)))) | |
3403 t))) | |
3404 (ange-ftp-real-file-exists-p name))) | |
3405 | |
3406 (defun ange-ftp-file-directory-p (name) | |
3407 (setq name (expand-file-name name)) | |
3408 (if (ange-ftp-ftp-name name) | |
3409 ;; We do a file-name-as-directory on name here because some | |
3410 ;; machines (VMS) use a .DIR to indicate the filename associated | |
3411 ;; with a directory. This needs to be canonicalized. | |
3412 (let ((file-ent (ange-ftp-get-file-entry | |
3413 (ange-ftp-file-name-as-directory name)))) | |
3414 (if (stringp file-ent) | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3415 ;; Calling file-directory-p doesn't work because ange-ftp |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3416 ;; is temporarily disabled for this operation. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3417 (ange-ftp-file-directory-p |
28210 | 3418 (ange-ftp-expand-symlink file-ent |
3419 (file-name-directory | |
3420 (directory-file-name name)))) | |
3421 file-ent)) | |
3422 (ange-ftp-real-file-directory-p name))) | |
3423 | |
3424 (defun ange-ftp-directory-files (directory &optional full match | |
3425 &rest v19-args) | |
3426 (setq directory (expand-file-name directory)) | |
3427 (if (ange-ftp-ftp-name directory) | |
3428 (progn | |
3429 (ange-ftp-barf-if-not-directory directory) | |
3430 (let ((tail (ange-ftp-hash-table-keys | |
3431 (ange-ftp-get-files directory))) | |
3432 files f) | |
3433 (setq directory (file-name-as-directory directory)) | |
3434 (save-match-data | |
3435 (while tail | |
3436 (setq f (car tail) | |
3437 tail (cdr tail)) | |
3438 (if (or (not match) (string-match match f)) | |
3439 (setq files | |
3440 (cons (if full (concat directory f) f) files))))) | |
3441 (nreverse files))) | |
3442 (apply 'ange-ftp-real-directory-files directory full match v19-args))) | |
3443 | |
53351
d3b9902eacfe
(ange-ftp-file-attributes): Add new optional parameter ID-FORMAT.
Sam Steingold <sds@gnu.org>
parents:
52401
diff
changeset
|
3444 (defun ange-ftp-file-attributes (file &optional id-format) |
28210 | 3445 (setq file (expand-file-name file)) |
3446 (let ((parsed (ange-ftp-ftp-name file))) | |
3447 (if parsed | |
3448 (let ((part (ange-ftp-get-file-part file)) | |
3449 (files (ange-ftp-get-files (file-name-directory file)))) | |
3450 (if (ange-ftp-hash-entry-exists-p part files) | |
3451 (let ((host (nth 0 parsed)) | |
3452 (user (nth 1 parsed)) | |
3453 (name (nth 2 parsed)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3454 (dirp (gethash part files)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3455 (inode (gethash file ange-ftp-inodes-hashtable))) |
28210 | 3456 (unless inode |
3457 (setq inode ange-ftp-next-inode-number | |
3458 ange-ftp-next-inode-number (1+ inode)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3459 (puthash file inode ange-ftp-inodes-hashtable)) |
28210 | 3460 (list (if (and (stringp dirp) (file-name-absolute-p dirp)) |
3461 (ange-ftp-expand-symlink dirp | |
3462 (file-name-directory file)) | |
3463 dirp) ;0 file type | |
3464 -1 ;1 link count | |
3465 -1 ;2 uid | |
3466 -1 ;3 gid | |
3467 '(0 0) ;4 atime | |
30459 | 3468 (ange-ftp-file-modtime file) ;5 mtime |
28210 | 3469 '(0 0) ;6 ctime |
3470 -1 ;7 size | |
3471 (concat (if (stringp dirp) "l" (if dirp "d" "-")) | |
3472 "?????????") ;8 mode | |
3473 nil ;9 gid weird | |
3474 inode ;10 "inode number". | |
3475 -1 ;11 device number [v19 only] | |
3476 )))) | |
53500
530a52a3971b
(ange-ftp-file-attributes):
Richard M. Stallman <rms@gnu.org>
parents:
53415
diff
changeset
|
3477 (if id-format |
530a52a3971b
(ange-ftp-file-attributes):
Richard M. Stallman <rms@gnu.org>
parents:
53415
diff
changeset
|
3478 (ange-ftp-real-file-attributes file id-format) |
530a52a3971b
(ange-ftp-file-attributes):
Richard M. Stallman <rms@gnu.org>
parents:
53415
diff
changeset
|
3479 (ange-ftp-real-file-attributes file))))) |
28210 | 3480 |
30481 | 3481 (defun ange-ftp-file-newer-than-file-p (f1 f2) |
3482 (let ((f1-parsed (ange-ftp-ftp-name f1)) | |
3483 (f2-parsed (ange-ftp-ftp-name f2))) | |
3484 (if (or f1-parsed f2-parsed) | |
3485 (let ((f1-mt (nth 5 (file-attributes f1))) | |
3486 (f2-mt (nth 5 (file-attributes f2)))) | |
3487 (cond ((null f1-mt) nil) | |
3488 ((null f2-mt) t) | |
3489 (t (> (float-time f1-mt) (float-time f2-mt))))) | |
3490 (ange-ftp-real-file-newer-than-file-p f1 f2)))) | |
3491 | |
28210 | 3492 (defun ange-ftp-file-writable-p (file) |
33533 | 3493 (let ((ange-ftp-process-verbose nil)) |
3494 (setq file (expand-file-name file)) | |
3495 (if (ange-ftp-ftp-name file) | |
3496 (or (file-exists-p file) ;guess here for speed | |
3497 (file-directory-p (file-name-directory file))) | |
3498 (ange-ftp-real-file-writable-p file)))) | |
28210 | 3499 |
3500 (defun ange-ftp-file-readable-p (file) | |
33533 | 3501 (let ((ange-ftp-process-verbose nil)) |
3502 (setq file (expand-file-name file)) | |
3503 (if (ange-ftp-ftp-name file) | |
3504 (file-exists-p file) | |
3505 (ange-ftp-real-file-readable-p file)))) | |
28210 | 3506 |
3507 (defun ange-ftp-file-executable-p (file) | |
33533 | 3508 (let ((ange-ftp-process-verbose nil)) |
3509 (setq file (expand-file-name file)) | |
3510 (if (ange-ftp-ftp-name file) | |
3511 (file-exists-p file) | |
3512 (ange-ftp-real-file-executable-p file)))) | |
28210 | 3513 |
3514 (defun ange-ftp-delete-file (file) | |
3515 (interactive "fDelete file: ") | |
3516 (setq file (expand-file-name file)) | |
3517 (let ((parsed (ange-ftp-ftp-name file))) | |
3518 (if parsed | |
3519 (let* ((host (nth 0 parsed)) | |
3520 (user (nth 1 parsed)) | |
3521 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3522 (abbr (ange-ftp-abbreviate-filename file)) | |
3523 (result (ange-ftp-send-cmd host user | |
3524 (list 'delete name) | |
3525 (format "Deleting %s" abbr)))) | |
3526 (or (car result) | |
3527 (signal 'ftp-error | |
3528 (list | |
3529 "Removing old name" | |
3530 (format "FTP Error: \"%s\"" (cdr result)) | |
3531 file))) | |
3532 (ange-ftp-delete-file-entry file)) | |
3533 (ange-ftp-real-delete-file file)))) | |
3534 | |
30459 | 3535 (defun ange-ftp-file-modtime (file) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3536 "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
|
3537 Value is (0 0) if the modification time cannot be determined." |
30459 | 3538 (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
|
3539 ;; 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
|
3540 ;; 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
|
3541 ;; that. |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3542 (ange-ftp-skip-msgs (concat ange-ftp-skip-msgs "\\|^226")) |
30459 | 3543 (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
|
3544 (list 'quote "mdtm" (cadr (cdr parsed))))) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3545 (line (cdr res)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3546 (modtime '(0 0))) |
38328
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3547 ;; 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
|
3548 ;; 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
|
3549 ;; 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
|
3550 ;; 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
|
3551 ;; 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
|
3552 (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
|
3553 (setq modtime |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3554 (encode-time |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3555 (string-to-number (substring line 16 18)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3556 (string-to-number (substring line 14 16)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3557 (string-to-number (substring line 12 14)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3558 (string-to-number (substring line 10 12)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3559 (string-to-number (substring line 8 10)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3560 (string-to-number (substring line 4 8)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3561 0))) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3562 modtime)) |
30459 | 3563 |
28210 | 3564 (defun ange-ftp-verify-visited-file-modtime (buf) |
3565 (let ((name (buffer-file-name buf))) | |
3566 (if (and (stringp name) (ange-ftp-ftp-name name)) | |
30459 | 3567 (let ((file-mdtm (ange-ftp-file-modtime name)) |
3568 (buf-mdtm (with-current-buffer buf (visited-file-modtime)))) | |
3569 (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
|
3570 (<= (float-time file-mdtm) (float-time buf-mdtm)))) |
28210 | 3571 (ange-ftp-real-verify-visited-file-modtime buf)))) |
3572 | |
3573 ;;;; ------------------------------------------------------------ | |
3574 ;;;; File copying support... totally re-written 6/24/92. | |
3575 ;;;; ------------------------------------------------------------ | |
3576 | |
3577 (defun ange-ftp-barf-or-query-if-file-exists (absname querystring interactive) | |
3578 (if (file-exists-p absname) | |
3579 (if (not interactive) | |
3580 (signal 'file-already-exists (list absname)) | |
3581 (if (not (yes-or-no-p (format "File %s already exists; %s anyway? " | |
3582 absname querystring))) | |
3583 (signal 'file-already-exists (list absname)))))) | |
3584 | |
3585 ;; async local copy commented out for now since I don't seem to get | |
3586 ;; the process sentinel called for some processes. | |
3587 ;; | |
3588 ;; (defun ange-ftp-copy-file-locally (filename newname ok-if-already-exists | |
3589 ;; keep-date cont) | |
3590 ;; "Kludge to copy a local file and call a continuation when the copy | |
3591 ;; finishes." | |
3592 ;; ;; check to see if we can overwrite | |
3593 ;; (if (or (not ok-if-already-exists) | |
3594 ;; (numberp ok-if-already-exists)) | |
30459 | 3595 ;; (ange-ftp-barf-or-query-if-file-exists newname "copy to it" |
28210 | 3596 ;; (numberp ok-if-already-exists))) |
3597 ;; (let ((proc (start-process " *copy*" | |
3598 ;; (generate-new-buffer "*copy*") | |
3599 ;; "cp" | |
3600 ;; filename | |
3601 ;; newname)) | |
3602 ;; res) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3603 ;; (set-process-sentinel proc 'ange-ftp-copy-file-locally-sentinel) |
28210 | 3604 ;; (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
|
3605 ;; (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
|
3606 ;; (set (make-local-variable 'copy-cont) cont)))) |
30459 | 3607 ;; |
28210 | 3608 ;; (defun ange-ftp-copy-file-locally-sentinel (proc status) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
3609 ;; (with-current-buffer (process-buffer proc) |
28210 | 3610 ;; (let ((cont copy-cont) |
3611 ;; (result (buffer-string))) | |
3612 ;; (unwind-protect | |
3613 ;; (if (and (string-equal status "finished\n") | |
3614 ;; (zerop (length result))) | |
3615 ;; (ange-ftp-call-cont cont t nil) | |
3616 ;; (ange-ftp-call-cont cont | |
3617 ;; nil | |
3618 ;; (if (zerop (length result)) | |
3619 ;; (substring status 0 -1) | |
3620 ;; (substring result 0 -1)))) | |
3621 ;; (kill-buffer (current-buffer)))))) | |
3622 | |
3623 ;; this is the extended version of ange-ftp-copy-file-internal that works | |
3624 ;; asynchronously if asked nicely. | |
3625 (defun ange-ftp-copy-file-internal (filename newname ok-if-already-exists | |
3626 keep-date &optional msg cont nowait) | |
3627 (setq filename (expand-file-name filename) | |
3628 newname (expand-file-name newname)) | |
3629 | |
3630 ;; canonicalize newname if a directory. | |
3631 (if (file-directory-p newname) | |
3632 (setq newname (expand-file-name (file-name-nondirectory filename) newname))) | |
3633 | |
3634 (let ((f-parsed (ange-ftp-ftp-name filename)) | |
3635 (t-parsed (ange-ftp-ftp-name newname))) | |
3636 | |
3637 ;; local file to local file copy? | |
3638 (if (and (not f-parsed) (not t-parsed)) | |
3639 (progn | |
3640 (ange-ftp-real-copy-file filename newname ok-if-already-exists | |
3641 keep-date) | |
3642 (if cont | |
3643 (ange-ftp-call-cont cont t "Copied locally"))) | |
3644 ;; one or both files are remote. | |
3645 (let* ((f-host (and f-parsed (nth 0 f-parsed))) | |
3646 (f-user (and f-parsed (nth 1 f-parsed))) | |
3647 (f-name (and f-parsed (ange-ftp-quote-string (nth 2 f-parsed)))) | |
3648 (f-abbr (ange-ftp-abbreviate-filename filename)) | |
3649 (t-host (and t-parsed (nth 0 t-parsed))) | |
3650 (t-user (and t-parsed (nth 1 t-parsed))) | |
3651 (t-name (and t-parsed (ange-ftp-quote-string (nth 2 t-parsed)))) | |
3652 (t-abbr (ange-ftp-abbreviate-filename newname filename)) | |
3653 (binary (or (ange-ftp-binary-file filename) | |
3654 (ange-ftp-binary-file newname) | |
3655 (and (memq (ange-ftp-host-type f-host f-user) | |
3656 '(unix dumb-unix)) | |
3657 (memq (ange-ftp-host-type t-host t-user) | |
3658 '(unix dumb-unix))))) | |
3659 temp1 | |
3660 temp2) | |
3661 | |
3662 ;; check to see if we can overwrite | |
3663 (if (or (not ok-if-already-exists) | |
3664 (numberp ok-if-already-exists)) | |
30459 | 3665 (ange-ftp-barf-or-query-if-file-exists newname "copy to it" |
28210 | 3666 (numberp ok-if-already-exists))) |
3667 | |
3668 ;; do the copying. | |
3669 (if f-parsed | |
30459 | 3670 |
28210 | 3671 ;; filename was remote. |
3672 (progn | |
3673 (if (or (ange-ftp-use-gateway-p f-host) | |
3674 t-parsed) | |
3675 ;; have to use intermediate file if we are getting via | |
3676 ;; gateway machine or we are doing a remote to remote copy. | |
3677 (setq temp1 (ange-ftp-make-tmp-name f-host))) | |
30459 | 3678 |
28210 | 3679 (if binary |
3680 (ange-ftp-set-binary-mode f-host f-user)) | |
3681 | |
3682 (ange-ftp-send-cmd | |
3683 f-host | |
3684 f-user | |
3685 (list 'get f-name (or temp1 (ange-ftp-quote-string newname))) | |
3686 (or msg | |
3687 (if (and temp1 t-parsed) | |
3688 (format "Getting %s" f-abbr) | |
3689 (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
|
3690 (list 'ange-ftp-cf1 |
28210 | 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 temp1 temp2 cont nowait) | |
3695 nowait)) | |
3696 | |
3697 ;; filename wasn't remote. newname must be remote. call the | |
3698 ;; function which does the remainder of the copying work. | |
3699 (ange-ftp-cf1 t nil | |
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 nil nil cont nowait)))))) | |
3704 | |
3705 (defvar ange-ftp-waiting-flag nil) | |
3706 | |
3707 ;; next part of copying routine. | |
3708 (defun ange-ftp-cf1 (result line | |
3709 filename newname binary msg | |
3710 f-parsed f-host f-user f-name f-abbr | |
3711 t-parsed t-host t-user t-name t-abbr | |
3712 temp1 temp2 cont nowait) | |
3713 (if line | |
3714 ;; filename must have been remote, and we must have just done a GET. | |
3715 (unwind-protect | |
3716 (or result | |
3717 ;; GET failed for some reason. Clean up and get out. | |
3718 (progn | |
3719 (and temp1 (ange-ftp-del-tmp-name temp1)) | |
3720 (or cont | |
3721 (if ange-ftp-waiting-flag | |
3722 (throw 'ftp-error t) | |
3723 (signal 'ftp-error | |
3724 (list "Opening input file" | |
3725 (format "FTP Error: \"%s\"" line) | |
3726 filename)))))) | |
3727 ;; cleanup | |
3728 (if binary | |
3729 (ange-ftp-set-ascii-mode f-host f-user)))) | |
3730 | |
3731 (if result | |
3732 ;; We now have to copy either temp1 or filename to newname. | |
3733 (if t-parsed | |
30459 | 3734 |
28210 | 3735 ;; newname was remote. |
3736 (progn | |
3737 (if (ange-ftp-use-gateway-p t-host) | |
3738 (setq temp2 (ange-ftp-make-tmp-name t-host))) | |
30459 | 3739 |
28210 | 3740 ;; make sure data is moved into the right place for the |
3741 ;; outgoing transfer. gateway temporary files complicate | |
3742 ;; things nicely. | |
3743 (if temp1 | |
3744 (if temp2 | |
3745 (if (string-equal temp1 temp2) | |
3746 (setq temp1 nil) | |
3747 (ange-ftp-real-copy-file temp1 temp2 t)) | |
3748 (setq temp2 temp1 temp1 nil)) | |
3749 (if temp2 | |
3750 (ange-ftp-real-copy-file filename temp2 t))) | |
30459 | 3751 |
28210 | 3752 (if binary |
3753 (ange-ftp-set-binary-mode t-host t-user)) | |
3754 | |
3755 ;; tell the process filter what size the file is. | |
3756 (let ((attr (file-attributes (or temp2 filename)))) | |
3757 (if attr | |
3758 (ange-ftp-set-xfer-size t-host t-user (nth 7 attr)))) | |
3759 | |
3760 (ange-ftp-send-cmd | |
3761 t-host | |
3762 t-user | |
80116
91513d7aa412
* net/ange-ftp.el (ange-ftp-cf1): Quote FILENAME.
Michael Albinus <michael.albinus@gmx.de>
parents:
80044
diff
changeset
|
3763 (list 'put (or temp2 (ange-ftp-quote-string filename)) t-name) |
28210 | 3764 (or msg |
3765 (if (and temp2 f-parsed) | |
3766 (format "Putting %s" newname) | |
3767 (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
|
3768 (list 'ange-ftp-cf2 |
28210 | 3769 newname t-host t-user binary temp1 temp2 cont) |
3770 nowait)) | |
30459 | 3771 |
28210 | 3772 ;; newname wasn't remote. |
3773 (ange-ftp-cf2 t nil newname t-host t-user binary temp1 temp2 cont)) | |
3774 | |
3775 ;; first copy failed, tell caller | |
3776 (ange-ftp-call-cont cont result line))) | |
3777 | |
3778 ;; last part of copying routine. | |
3779 (defun ange-ftp-cf2 (result line newname t-host t-user binary temp1 temp2 cont) | |
3780 (unwind-protect | |
3781 (if line | |
3782 ;; result from doing a local to remote copy. | |
3783 (unwind-protect | |
3784 (progn | |
3785 (or result | |
3786 (or cont | |
3787 (if ange-ftp-waiting-flag | |
3788 (throw 'ftp-error t) | |
3789 (signal 'ftp-error | |
3790 (list "Opening output file" | |
3791 (format "FTP Error: \"%s\"" line) | |
3792 newname))))) | |
30459 | 3793 |
28210 | 3794 (ange-ftp-add-file-entry newname)) |
30459 | 3795 |
28210 | 3796 ;; cleanup. |
3797 (if binary | |
3798 (ange-ftp-set-ascii-mode t-host t-user))) | |
30459 | 3799 |
28210 | 3800 ;; newname was local. |
3801 (if temp1 | |
3802 (ange-ftp-real-copy-file temp1 newname t))) | |
30459 | 3803 |
28210 | 3804 ;; clean up |
3805 (and temp1 (ange-ftp-del-tmp-name temp1)) | |
3806 (and temp2 (ange-ftp-del-tmp-name temp2)) | |
3807 (ange-ftp-call-cont cont result line))) | |
3808 | |
3809 (defun ange-ftp-copy-file (filename newname &optional ok-if-already-exists | |
85505
bc97f31b2cf1
* files.el (backup-buffer-copy): Call `copy-file' with non-nil
Michael Albinus <michael.albinus@gmx.de>
parents:
84913
diff
changeset
|
3810 keep-date preserve-uid-gid) |
28210 | 3811 (interactive "fCopy file: \nFCopy %s to file: \np") |
3812 (ange-ftp-copy-file-internal filename | |
3813 newname | |
3814 ok-if-already-exists | |
3815 keep-date | |
3816 nil | |
3817 nil | |
3818 (interactive-p))) | |
39839
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3819 |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3820 (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
|
3821 "Copy some files in the background. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3822 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
|
3823 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
|
3824 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
|
3825 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
|
3826 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
|
3827 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
|
3828 (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
|
3829 E.g., |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3830 (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
|
3831 (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
|
3832 (if files |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3833 (let* ((ff (car files)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3834 (from-file (nth 0 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3835 (to-file (nth 1 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3836 (ok-if-exists (nth 2 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3837 (keep-date (nth 3 ff))) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3838 (ange-ftp-copy-file-internal |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3839 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
|
3840 (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
|
3841 (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
|
3842 t)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3843 (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
|
3844 |
28210 | 3845 |
3846 ;;;; ------------------------------------------------------------ | |
3847 ;;;; File renaming support. | |
3848 ;;;; ------------------------------------------------------------ | |
3849 | |
3850 (defun ange-ftp-rename-remote-to-remote (filename newname f-parsed t-parsed) | |
3851 "Rename remote file FILE to remote file NEWNAME." | |
3852 (let ((f-host (nth 0 f-parsed)) | |
3853 (f-user (nth 1 f-parsed)) | |
3854 (t-host (nth 0 t-parsed)) | |
3855 (t-user (nth 1 t-parsed))) | |
3856 (if (and (string-equal f-host t-host) | |
3857 (string-equal f-user t-user)) | |
3858 (let* ((f-name (ange-ftp-quote-string (nth 2 f-parsed))) | |
3859 (t-name (ange-ftp-quote-string (nth 2 t-parsed))) | |
3860 (cmd (list 'rename f-name t-name)) | |
3861 (fabbr (ange-ftp-abbreviate-filename filename)) | |
3862 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3863 (result (ange-ftp-send-cmd f-host f-user cmd | |
3864 (format "Renaming %s to %s" | |
3865 fabbr | |
3866 nabbr)))) | |
3867 (or (car result) | |
3868 (signal 'ftp-error | |
3869 (list | |
3870 "Renaming" | |
3871 (format "FTP Error: \"%s\"" (cdr result)) | |
3872 filename | |
3873 newname))) | |
3874 (ange-ftp-add-file-entry newname) | |
3875 (ange-ftp-delete-file-entry filename)) | |
3876 (ange-ftp-copy-file-internal filename newname t nil) | |
3877 (delete-file filename)))) | |
3878 | |
3879 (defun ange-ftp-rename-local-to-remote (filename newname) | |
3880 "Rename local FILENAME to remote 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-remote-to-local (filename newname) | |
3889 "Rename remote file FILENAME to local file NEWNAME." | |
3890 (let* ((fabbr (ange-ftp-abbreviate-filename filename)) | |
3891 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3892 (msg (format "Renaming %s to %s" fabbr nabbr))) | |
3893 (ange-ftp-copy-file-internal filename newname t nil msg) | |
3894 (let (ange-ftp-process-verbose) | |
3895 (delete-file filename)))) | |
3896 | |
3897 (defun ange-ftp-rename-file (filename newname &optional ok-if-already-exists) | |
3898 (interactive "fRename file: \nFRename %s to file: \np") | |
3899 (setq filename (expand-file-name filename)) | |
3900 (setq newname (expand-file-name newname)) | |
3901 (let* ((f-parsed (ange-ftp-ftp-name filename)) | |
3902 (t-parsed (ange-ftp-ftp-name newname))) | |
3903 (if (and (or f-parsed t-parsed) | |
3904 (or (not ok-if-already-exists) | |
3905 (numberp ok-if-already-exists))) | |
3906 (ange-ftp-barf-or-query-if-file-exists | |
3907 newname | |
3908 "rename to it" | |
3909 (numberp ok-if-already-exists))) | |
3910 (if f-parsed | |
3911 (if t-parsed | |
3912 (ange-ftp-rename-remote-to-remote filename newname f-parsed | |
3913 t-parsed) | |
3914 (ange-ftp-rename-remote-to-local filename newname)) | |
3915 (if t-parsed | |
3916 (ange-ftp-rename-local-to-remote filename newname) | |
3917 (ange-ftp-real-rename-file filename newname ok-if-already-exists))))) | |
3918 | |
3919 ;;;; ------------------------------------------------------------ | |
3920 ;;;; File name completion support. | |
3921 ;;;; ------------------------------------------------------------ | |
3922 | |
3923 ;; If the file entry is not a directory (nor a symlink pointing to a directory) | |
3924 ;; returns whether the file (or file pointed to by the symlink) is ignored | |
3925 ;; by completion-ignored-extensions. | |
3926 ;; Note that `ange-ftp-this-dir' and `ange-ftp-completion-ignored-pattern' | |
3927 ;; are used as free variables. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3928 (defun ange-ftp-file-entry-not-ignored-p (symname val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3929 (if (stringp val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3930 (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
|
3931 (or (file-directory-p file) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3932 (and (file-exists-p file) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3933 (not (string-match ange-ftp-completion-ignored-pattern |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3934 symname))))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3935 (or val ; is a directory name |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3936 (not (string-match ange-ftp-completion-ignored-pattern symname))))) |
28210 | 3937 |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3938 (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
|
3939 ;; 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
|
3940 ;; (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
|
3941 (or (and (eq system-type 'windows-nt) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3942 (string-match "\\`[a-zA-Z]:[/\\]\\'" dir)) |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3943 (string-equal "/" dir))) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3944 |
28210 | 3945 (defun ange-ftp-file-name-all-completions (file dir) |
3946 (let ((ange-ftp-this-dir (expand-file-name dir))) | |
3947 (if (ange-ftp-ftp-name ange-ftp-this-dir) | |
3948 (progn | |
3949 (ange-ftp-barf-if-not-directory ange-ftp-this-dir) | |
3950 (setq ange-ftp-this-dir | |
3951 (ange-ftp-real-file-name-as-directory ange-ftp-this-dir)) | |
3952 (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
|
3953 (completions (all-completions file tbl))) |
28210 | 3954 |
3955 ;; see whether each matching file is a directory or not... | |
3956 (mapcar | |
30459 | 3957 (lambda (file) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3958 (let ((ent (gethash file tbl))) |
30459 | 3959 (if (and ent |
3960 (or (not (stringp ent)) | |
3961 (file-directory-p | |
3962 (ange-ftp-expand-symlink ent | |
3963 ange-ftp-this-dir)))) | |
3964 (concat file "/") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3965 file))) |
28210 | 3966 completions))) |
3967 | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3968 (if (ange-ftp-root-dir-p ange-ftp-this-dir) |
28210 | 3969 (nconc (all-completions file (ange-ftp-generate-root-prefixes)) |
3970 (ange-ftp-real-file-name-all-completions file | |
3971 ange-ftp-this-dir)) | |
3972 (ange-ftp-real-file-name-all-completions file ange-ftp-this-dir))))) | |
3973 | |
74766
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
3974 (defun ange-ftp-file-name-completion (file dir &optional predicate) |
28210 | 3975 (let ((ange-ftp-this-dir (expand-file-name dir))) |
3976 (if (ange-ftp-ftp-name ange-ftp-this-dir) | |
3977 (progn | |
3978 (ange-ftp-barf-if-not-directory ange-ftp-this-dir) | |
3979 (if (equal file "") | |
3980 "" | |
3981 (setq ange-ftp-this-dir | |
3982 (ange-ftp-real-file-name-as-directory ange-ftp-this-dir)) ;real? | |
3983 (let* ((tbl (ange-ftp-get-files ange-ftp-this-dir)) | |
3984 (ange-ftp-completion-ignored-pattern | |
30459 | 3985 (mapconcat (lambda (s) (if (stringp s) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3986 (concat (regexp-quote s) "$") |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3987 "/")) ; / never in filename |
28210 | 3988 completion-ignored-extensions |
3989 "\\|"))) | |
3990 (save-match-data | |
3991 (or (ange-ftp-file-name-completion-1 | |
3992 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
|
3993 'ange-ftp-file-entry-not-ignored-p) |
28210 | 3994 (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
|
3995 file tbl ange-ftp-this-dir)))))) |
28210 | 3996 |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3997 (if (ange-ftp-root-dir-p ange-ftp-this-dir) |
28210 | 3998 (try-completion |
3999 file | |
4000 (nconc (ange-ftp-generate-root-prefixes) | |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
4001 (ange-ftp-real-file-name-all-completions |
74766
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4002 file ange-ftp-this-dir)) |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4003 predicate) |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4004 (if predicate |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4005 (ange-ftp-real-file-name-completion |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4006 file ange-ftp-this-dir predicate) |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4007 (ange-ftp-real-file-name-completion |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4008 file ange-ftp-this-dir)))))) |
28210 | 4009 |
4010 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4011 (defun ange-ftp-file-name-completion-1 (file tbl dir &optional predicate) |
28210 | 4012 (let ((bestmatch (try-completion file tbl predicate))) |
4013 (if bestmatch | |
4014 (if (eq bestmatch t) | |
4015 (if (file-directory-p (expand-file-name file dir)) | |
4016 (concat file "/") | |
4017 t) | |
4018 (if (and (eq (try-completion bestmatch tbl predicate) t) | |
4019 (file-directory-p | |
4020 (expand-file-name bestmatch dir))) | |
4021 (concat bestmatch "/") | |
4022 bestmatch))))) | |
4023 | |
4024 ;; Put these lines uncommmented in your .emacs if you want C-r to refresh | |
4025 ;; ange-ftp's cache whilst doing filename completion. | |
4026 ;; | |
4027 ;;(define-key minibuffer-local-completion-map "\C-r" 'ange-ftp-re-read-dir) | |
4028 ;;(define-key minibuffer-local-must-match-map "\C-r" 'ange-ftp-re-read-dir) | |
4029 | |
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
|
4030 ;;;###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
|
4031 (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
|
4032 |
28210 | 4033 ;;;###autoload |
4034 (defun ange-ftp-reread-dir (&optional dir) | |
4035 "Reread remote directory DIR to update the directory cache. | |
4036 The implementation of remote ftp file names caches directory contents | |
4037 for speed. Therefore, when new remote files are created, Emacs | |
4038 may not know they exist. You can use this command to reread a specific | |
4039 directory, so that Emacs will know its current contents." | |
4040 (interactive) | |
4041 (if dir | |
4042 (setq dir (expand-file-name dir)) | |
4043 (setq dir (file-name-directory (expand-file-name (buffer-string))))) | |
4044 (if (ange-ftp-ftp-name dir) | |
4045 (progn | |
4046 (setq ange-ftp-ls-cache-file nil) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4047 (remhash dir ange-ftp-files-hashtable) |
28210 | 4048 (ange-ftp-get-files dir t)))) |
4049 | |
4050 (defun ange-ftp-make-directory (dir &optional parents) | |
4051 (interactive (list (expand-file-name (read-file-name "Make directory: ")))) | |
4052 (if parents | |
4053 (let ((parent (file-name-directory (directory-file-name dir)))) | |
4054 (or (file-exists-p parent) | |
4055 (ange-ftp-make-directory parent parents)))) | |
4056 (if (file-exists-p dir) | |
4057 (error "Cannot make directory %s: file already exists" dir) | |
4058 (let ((parsed (ange-ftp-ftp-name dir))) | |
4059 (if parsed | |
4060 (let* ((host (nth 0 parsed)) | |
4061 (user (nth 1 parsed)) | |
4062 ;; Some ftp's on unix machines (at least on Suns) | |
4063 ;; insist that mkdir take a filename, and not a | |
4064 ;; directory-name name as an arg. Argh!! This is a bug. | |
4065 ;; Non-unix machines will probably always insist | |
4066 ;; that mkdir takes a directory-name as an arg | |
4067 ;; (as the ftp man page says it should). | |
4068 (name (ange-ftp-quote-string | |
4069 (if (eq (ange-ftp-host-type host) 'unix) | |
4070 (ange-ftp-real-directory-file-name (nth 2 parsed)) | |
4071 (ange-ftp-real-file-name-as-directory | |
4072 (nth 2 parsed))))) | |
4073 (abbr (ange-ftp-abbreviate-filename dir)) | |
4074 (result (ange-ftp-send-cmd host user | |
4075 (list 'mkdir name) | |
4076 (format "Making directory %s" | |
4077 abbr)))) | |
4078 (or (car result) | |
4079 (ange-ftp-error host user | |
4080 (format "Could not make directory %s: %s" | |
4081 dir | |
4082 (cdr result)))) | |
4083 (ange-ftp-add-file-entry dir t)) | |
4084 (ange-ftp-real-make-directory dir))))) | |
4085 | |
4086 (defun ange-ftp-delete-directory (dir) | |
4087 (if (file-directory-p dir) | |
4088 (let ((parsed (ange-ftp-ftp-name dir))) | |
4089 (if parsed | |
4090 (let* ((host (nth 0 parsed)) | |
4091 (user (nth 1 parsed)) | |
4092 ;; Some ftp's on unix machines (at least on Suns) | |
4093 ;; insist that rmdir take a filename, and not a | |
4094 ;; directory-name name as an arg. Argh!! This is a bug. | |
4095 ;; Non-unix machines will probably always insist | |
4096 ;; that rmdir takes a directory-name as an arg | |
4097 ;; (as the ftp man page says it should). | |
4098 (name (ange-ftp-quote-string | |
4099 (if (eq (ange-ftp-host-type host) 'unix) | |
4100 (ange-ftp-real-directory-file-name | |
4101 (nth 2 parsed)) | |
4102 (ange-ftp-real-file-name-as-directory | |
4103 (nth 2 parsed))))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4104 (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
|
4105 (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
|
4106 (list 'rmdir name) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4107 (format "Removing directory %s" |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4108 abbr)))) |
28210 | 4109 (or (car result) |
4110 (ange-ftp-error host user | |
4111 (format "Could not remove directory %s: %s" | |
4112 dir | |
4113 (cdr result)))) | |
4114 (ange-ftp-delete-file-entry dir t)) | |
4115 (ange-ftp-real-delete-directory dir))) | |
4116 (error "Not a directory: %s" dir))) | |
4117 | |
4118 ;; Make a local copy of FILE and return its name. | |
4119 | |
4120 (defun ange-ftp-file-local-copy (file) | |
4121 (let* ((fn1 (expand-file-name file)) | |
4122 (pa1 (ange-ftp-ftp-name fn1))) | |
4123 (if pa1 | |
4124 (let ((tmp1 (ange-ftp-make-tmp-name (car pa1)))) | |
4125 (ange-ftp-copy-file-internal fn1 tmp1 t nil | |
4126 (format "Getting %s" fn1)) | |
4127 tmp1)))) | |
4128 | |
81937
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4129 (defun ange-ftp-file-remote-p (file &optional identification connected) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4130 (let* ((parsed (ange-ftp-ftp-name file)) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4131 (host (nth 0 parsed)) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4132 (user (nth 1 parsed))) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4133 (and (or (not connected) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4134 (let ((proc (get-process (ange-ftp-ftp-process-buffer host user)))) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4135 (and proc (processp proc) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4136 (memq (process-status proc) '(run open))))) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4137 (cond |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4138 ((eq identification 'method) (and parsed "ftp")) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4139 ((eq identification 'user) user) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4140 ((eq identification 'host) host) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4141 (t (ange-ftp-replace-name-component file "")))))) |
55846
aed680fa845d
(ange-ftp-file-remote-p): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
53500
diff
changeset
|
4142 |
28210 | 4143 (defun ange-ftp-load (file &optional noerror nomessage nosuffix) |
4144 (if (ange-ftp-ftp-name file) | |
4145 (let ((tryfiles (if nosuffix | |
4146 (list file) | |
4147 (list (concat file ".elc") (concat file ".el") file))) | |
4148 ;; make sure there are no references to temp files | |
4149 (load-force-doc-strings t) | |
4150 copy) | |
4151 (while (and tryfiles (not copy)) | |
4152 (catch 'ftp-error | |
4153 (let ((ange-ftp-waiting-flag t)) | |
4154 (condition-case error | |
4155 (setq copy (ange-ftp-file-local-copy (car tryfiles))) | |
4156 (ftp-error nil)))) | |
4157 (setq tryfiles (cdr tryfiles))) | |
4158 (if copy | |
4159 (unwind-protect | |
4160 (funcall 'load copy noerror nomessage nosuffix) | |
4161 (delete-file copy)) | |
4162 (or noerror | |
4163 (signal 'file-error (list "Cannot open load file" file))) | |
4164 nil)) | |
4165 (ange-ftp-real-load file noerror nomessage nosuffix))) | |
4166 | |
4167 ;; Calculate default-unhandled-directory for a given ange-ftp buffer. | |
4168 (defun ange-ftp-unhandled-file-name-directory (filename) | |
91583
846fe57f9c57
(ange-ftp-unhandled-file-name-directory):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
4169 nil) |
28210 | 4170 |
4171 | |
4172 ;; Need the following functions for making filenames of compressed | |
4173 ;; files, because some OS's (unlike UNIX) do not allow a filename to | |
4174 ;; have two extensions. | |
4175 | |
4176 (defvar ange-ftp-make-compressed-filename-alist nil | |
4177 "Alist of host-type-specific functions to process file names for compression. | |
4178 Each element has the form (TYPE . FUNC). | |
4179 FUNC should take one argument, a file name, and return a list | |
4180 of the form (COMPRESSING NEWNAME). | |
30459 | 4181 COMPRESSING should be t if the specified file should be compressed, |
28210 | 4182 and nil if it should be uncompressed (that is, if it is a compressed file). |
4183 NEWNAME should be the name to give the new compressed or uncompressed file.") | |
4184 | |
4185 (defun ange-ftp-dired-compress-file (name) | |
4186 (let ((parsed (ange-ftp-ftp-name name)) | |
4187 conversion-func) | |
4188 (if (and parsed | |
4189 (setq conversion-func | |
4190 (cdr (assq (ange-ftp-host-type (car parsed)) | |
4191 ange-ftp-make-compressed-filename-alist)))) | |
4192 (let* ((decision | |
4193 (save-match-data (funcall conversion-func name))) | |
4194 (compressing (car decision)) | |
4195 (newfile (nth 1 decision))) | |
4196 (if compressing | |
4197 (ange-ftp-compress name newfile) | |
4198 (ange-ftp-uncompress name newfile))) | |
4199 (let (file-name-handler-alist) | |
4200 (dired-compress-file name))))) | |
4201 | |
4202 ;; Copy FILE to this machine, compress it, and copy out to NFILE. | |
4203 (defun ange-ftp-compress (file nfile) | |
4204 (let* ((parsed (ange-ftp-ftp-name file)) | |
4205 (tmp1 (ange-ftp-make-tmp-name (car parsed))) | |
4206 (tmp2 (ange-ftp-make-tmp-name (car parsed))) | |
4207 (abbr (ange-ftp-abbreviate-filename file)) | |
4208 (nabbr (ange-ftp-abbreviate-filename nfile)) | |
4209 (msg1 (format "Getting %s" abbr)) | |
4210 (msg2 (format "Putting %s" nabbr))) | |
4211 (unwind-protect | |
4212 (progn | |
4213 (ange-ftp-copy-file-internal file tmp1 t nil msg1) | |
4214 (and ange-ftp-process-verbose | |
4215 (ange-ftp-message "Compressing %s..." abbr)) | |
4216 (call-process-region (point) | |
4217 (point) | |
4218 shell-file-name | |
4219 nil | |
4220 t | |
4221 nil | |
4222 "-c" | |
4223 (format "compress -f -c < %s > %s" tmp1 tmp2)) | |
4224 (and ange-ftp-process-verbose | |
4225 (ange-ftp-message "Compressing %s...done" abbr)) | |
4226 (if (zerop (buffer-size)) | |
4227 (progn | |
4228 (let (ange-ftp-process-verbose) | |
4229 (delete-file file)) | |
4230 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2)))) | |
4231 (ange-ftp-del-tmp-name tmp1) | |
4232 (ange-ftp-del-tmp-name tmp2)))) | |
30459 | 4233 |
28210 | 4234 ;; Copy FILE to this machine, uncompress it, and copy out to NFILE. |
4235 (defun ange-ftp-uncompress (file nfile) | |
4236 (let* ((parsed (ange-ftp-ftp-name file)) | |
4237 (tmp1 (ange-ftp-make-tmp-name (car parsed))) | |
4238 (tmp2 (ange-ftp-make-tmp-name (car parsed))) | |
4239 (abbr (ange-ftp-abbreviate-filename file)) | |
4240 (nabbr (ange-ftp-abbreviate-filename nfile)) | |
4241 (msg1 (format "Getting %s" abbr)) | |
4242 (msg2 (format "Putting %s" nabbr)) | |
4243 ;; ;; Cheap hack because of problems with binary file transfers from | |
4244 ;; ;; VMS hosts. | |
4245 ;; (gbinary (not (eq 'vms (ange-ftp-host-type (car parsed))))) | |
4246 ) | |
4247 (unwind-protect | |
4248 (progn | |
4249 (ange-ftp-copy-file-internal file tmp1 t nil msg1) | |
4250 (and ange-ftp-process-verbose | |
4251 (ange-ftp-message "Uncompressing %s..." abbr)) | |
4252 (call-process-region (point) | |
4253 (point) | |
4254 shell-file-name | |
4255 nil | |
4256 t | |
4257 nil | |
4258 "-c" | |
4259 (format "uncompress -c < %s > %s" tmp1 tmp2)) | |
4260 (and ange-ftp-process-verbose | |
4261 (ange-ftp-message "Uncompressing %s...done" abbr)) | |
4262 (if (zerop (buffer-size)) | |
4263 (progn | |
4264 (let (ange-ftp-process-verbose) | |
4265 (delete-file file)) | |
4266 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2)))) | |
4267 (ange-ftp-del-tmp-name tmp1) | |
4268 (ange-ftp-del-tmp-name tmp2)))) | |
4269 | |
4270 (defun ange-ftp-find-backup-file-name (fn) | |
4271 ;; Either return the ordinary backup name, etc., | |
4272 ;; or return nil meaning don't make a backup. | |
4273 (if ange-ftp-make-backup-files | |
4274 (ange-ftp-real-find-backup-file-name fn))) | |
4275 | |
4276 ;;; Define the handler for special file names | |
4277 ;;; that causes ange-ftp to be invoked. | |
4278 | |
4279 ;;;###autoload | |
4280 (defun ange-ftp-hook-function (operation &rest args) | |
4281 (let ((fn (get operation 'ange-ftp))) | |
78422
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4282 (if fn |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4283 ;; Catch also errors in process-filter. |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4284 (condition-case err |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4285 (let ((debug-on-error t)) |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4286 (save-match-data (apply fn args))) |
78423
ca1e15221b34
*** empty log message ***
Michael Albinus <michael.albinus@gmx.de>
parents:
78422
diff
changeset
|
4287 (error (signal (car err) (cdr err)))) |
28210 | 4288 (ange-ftp-run-real-handler operation args)))) |
4289 | |
46349
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4290 ;; 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
|
4291 ;; 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
|
4292 |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4293 ;;-;;; 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
|
4294 ;;-;;; and colon). |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4295 ;;-;;; 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
|
4296 ;;-;;;###autoload |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4297 ;;-(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
|
4298 ;;- (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
|
4299 ;;- (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
|
4300 ;;- 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
|
4301 ;;- |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4302 ;;-;;; 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
|
4303 ;;-;;; 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
|
4304 ;;-;;;###autoload |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4305 ;;-(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
|
4306 ;;- (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
|
4307 ;;- (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
|
4308 ;;- 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
|
4309 ;;- |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4310 ;;-;;; 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
|
4311 ;;-;;; 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
|
4312 ;;-;;; 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
|
4313 ;;-;;; 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
|
4314 ;;-(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
|
4315 ;;- (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
|
4316 ;;- (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
|
4317 ;;- (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
|
4318 ;;- 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
|
4319 ;;- file-name-handler-alist)))) |
28210 | 4320 |
4321 ;;; The above two forms are sufficient to cause this file to be loaded | |
4322 ;;; if the user ever uses a file name with a colon in it. | |
4323 | |
30459 | 4324 ;;; This sets the mode |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
4325 (add-hook 'find-file-hook 'ange-ftp-set-buffer-mode) |
28210 | 4326 |
4327 ;;; Now say where to find the handlers for particular operations. | |
4328 | |
4329 (put 'file-name-directory 'ange-ftp 'ange-ftp-file-name-directory) | |
4330 (put 'file-name-nondirectory 'ange-ftp 'ange-ftp-file-name-nondirectory) | |
4331 (put 'file-name-as-directory 'ange-ftp 'ange-ftp-file-name-as-directory) | |
4332 (put 'directory-file-name 'ange-ftp 'ange-ftp-directory-file-name) | |
4333 (put 'expand-file-name 'ange-ftp 'ange-ftp-expand-file-name) | |
4334 (put 'make-directory 'ange-ftp 'ange-ftp-make-directory) | |
4335 (put 'delete-directory 'ange-ftp 'ange-ftp-delete-directory) | |
4336 (put 'insert-file-contents 'ange-ftp 'ange-ftp-insert-file-contents) | |
4337 (put 'directory-files 'ange-ftp 'ange-ftp-directory-files) | |
4338 (put 'file-directory-p 'ange-ftp 'ange-ftp-file-directory-p) | |
4339 (put 'file-writable-p 'ange-ftp 'ange-ftp-file-writable-p) | |
4340 (put 'file-readable-p 'ange-ftp 'ange-ftp-file-readable-p) | |
4341 (put 'file-executable-p 'ange-ftp 'ange-ftp-file-executable-p) | |
4342 (put 'file-symlink-p 'ange-ftp 'ange-ftp-file-symlink-p) | |
4343 (put 'delete-file 'ange-ftp 'ange-ftp-delete-file) | |
4344 (put 'verify-visited-file-modtime 'ange-ftp | |
4345 'ange-ftp-verify-visited-file-modtime) | |
4346 (put 'file-exists-p 'ange-ftp 'ange-ftp-file-exists-p) | |
4347 (put 'write-region 'ange-ftp 'ange-ftp-write-region) | |
4348 (put 'copy-file 'ange-ftp 'ange-ftp-copy-file) | |
4349 (put 'rename-file 'ange-ftp 'ange-ftp-rename-file) | |
4350 (put 'file-attributes 'ange-ftp 'ange-ftp-file-attributes) | |
30481 | 4351 (put 'file-newer-than-file-p 'ange-ftp 'ange-ftp-file-newer-than-file-p) |
28210 | 4352 (put 'file-name-all-completions 'ange-ftp 'ange-ftp-file-name-all-completions) |
4353 (put 'file-name-completion 'ange-ftp 'ange-ftp-file-name-completion) | |
4354 (put 'insert-directory 'ange-ftp 'ange-ftp-insert-directory) | |
4355 (put 'file-local-copy 'ange-ftp 'ange-ftp-file-local-copy) | |
55846
aed680fa845d
(ange-ftp-file-remote-p): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
53500
diff
changeset
|
4356 (put 'file-remote-p 'ange-ftp 'ange-ftp-file-remote-p) |
28210 | 4357 (put 'unhandled-file-name-directory 'ange-ftp |
4358 'ange-ftp-unhandled-file-name-directory) | |
4359 (put 'file-name-sans-versions 'ange-ftp 'ange-ftp-file-name-sans-versions) | |
4360 (put 'dired-uncache 'ange-ftp 'ange-ftp-dired-uncache) | |
4361 (put 'dired-compress-file 'ange-ftp 'ange-ftp-dired-compress-file) | |
4362 (put 'load 'ange-ftp 'ange-ftp-load) | |
4363 (put 'find-backup-file-name 'ange-ftp 'ange-ftp-find-backup-file-name) | |
4364 | |
4365 ;; Turn off truename processing to save time. | |
4366 ;; Treat each name as its own truename. | |
4367 (put 'file-truename 'ange-ftp 'identity) | |
4368 | |
83791
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4369 ;; We must return non-nil in order to mask our inability to do the job. |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4370 ;; Otherwise there are errors when applied to the target file during |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4371 ;; copying from a (localhost) Tramp file. |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4372 (put 'set-file-modes 'ange-ftp 'ignore) |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4373 (put 'set-file-times 'ange-ftp 'ignore) |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4374 |
28210 | 4375 ;; Turn off RCS/SCCS processing to save time. |
4376 ;; This returns nil for any file name as argument. | |
4377 (put 'vc-registered 'ange-ftp 'null) | |
4378 | |
81758
f03856eb136b
* files.el (file-remote-p): Introduce optional parameter CONNECTED.
Michael Albinus <michael.albinus@gmx.de>
parents:
81639
diff
changeset
|
4379 ;; We can handle process-file in a restricted way (just for chown). |
83791
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4380 ;; Nothing possible for `start-file-process'. |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4381 (put 'process-file 'ange-ftp 'ange-ftp-process-file) |
81758
f03856eb136b
* files.el (file-remote-p): Introduce optional parameter CONNECTED.
Michael Albinus <michael.albinus@gmx.de>
parents:
81639
diff
changeset
|
4382 (put 'start-file-process 'ange-ftp 'ignore) |
28210 | 4383 (put 'shell-command 'ange-ftp 'ange-ftp-shell-command) |
4384 | |
4385 ;;; Define ways of getting at unmodified Emacs primitives, | |
4386 ;;; turning off our handler. | |
4387 | |
4388 (defun ange-ftp-run-real-handler (operation args) | |
4389 (let ((inhibit-file-name-handlers | |
4390 (cons 'ange-ftp-hook-function | |
4391 (cons 'ange-ftp-completion-hook-function | |
4392 (and (eq inhibit-file-name-operation operation) | |
4393 inhibit-file-name-handlers)))) | |
4394 (inhibit-file-name-operation operation)) | |
4395 (apply operation args))) | |
4396 | |
4397 (defun ange-ftp-real-file-name-directory (&rest args) | |
4398 (ange-ftp-run-real-handler 'file-name-directory args)) | |
4399 (defun ange-ftp-real-file-name-nondirectory (&rest args) | |
4400 (ange-ftp-run-real-handler 'file-name-nondirectory args)) | |
4401 (defun ange-ftp-real-file-name-as-directory (&rest args) | |
4402 (ange-ftp-run-real-handler 'file-name-as-directory args)) | |
4403 (defun ange-ftp-real-directory-file-name (&rest args) | |
4404 (ange-ftp-run-real-handler 'directory-file-name args)) | |
4405 (defun ange-ftp-real-expand-file-name (&rest args) | |
4406 (ange-ftp-run-real-handler 'expand-file-name args)) | |
4407 (defun ange-ftp-real-make-directory (&rest args) | |
4408 (ange-ftp-run-real-handler 'make-directory args)) | |
4409 (defun ange-ftp-real-delete-directory (&rest args) | |
4410 (ange-ftp-run-real-handler 'delete-directory args)) | |
4411 (defun ange-ftp-real-insert-file-contents (&rest args) | |
4412 (ange-ftp-run-real-handler 'insert-file-contents args)) | |
4413 (defun ange-ftp-real-directory-files (&rest args) | |
4414 (ange-ftp-run-real-handler 'directory-files args)) | |
4415 (defun ange-ftp-real-file-directory-p (&rest args) | |
4416 (ange-ftp-run-real-handler 'file-directory-p args)) | |
4417 (defun ange-ftp-real-file-writable-p (&rest args) | |
4418 (ange-ftp-run-real-handler 'file-writable-p args)) | |
4419 (defun ange-ftp-real-file-readable-p (&rest args) | |
4420 (ange-ftp-run-real-handler 'file-readable-p args)) | |
4421 (defun ange-ftp-real-file-executable-p (&rest args) | |
4422 (ange-ftp-run-real-handler 'file-executable-p args)) | |
4423 (defun ange-ftp-real-file-symlink-p (&rest args) | |
4424 (ange-ftp-run-real-handler 'file-symlink-p args)) | |
4425 (defun ange-ftp-real-delete-file (&rest args) | |
4426 (ange-ftp-run-real-handler 'delete-file args)) | |
4427 (defun ange-ftp-real-verify-visited-file-modtime (&rest args) | |
4428 (ange-ftp-run-real-handler 'verify-visited-file-modtime args)) | |
4429 (defun ange-ftp-real-file-exists-p (&rest args) | |
4430 (ange-ftp-run-real-handler 'file-exists-p args)) | |
4431 (defun ange-ftp-real-write-region (&rest args) | |
4432 (ange-ftp-run-real-handler 'write-region args)) | |
4433 (defun ange-ftp-real-backup-buffer (&rest args) | |
4434 (ange-ftp-run-real-handler 'backup-buffer args)) | |
4435 (defun ange-ftp-real-copy-file (&rest args) | |
4436 (ange-ftp-run-real-handler 'copy-file args)) | |
4437 (defun ange-ftp-real-rename-file (&rest args) | |
4438 (ange-ftp-run-real-handler 'rename-file args)) | |
4439 (defun ange-ftp-real-file-attributes (&rest args) | |
4440 (ange-ftp-run-real-handler 'file-attributes args)) | |
30481 | 4441 (defun ange-ftp-real-file-newer-than-file-p (&rest args) |
4442 (ange-ftp-run-real-handler 'file-newer-than-file-p args)) | |
28210 | 4443 (defun ange-ftp-real-file-name-all-completions (&rest args) |
4444 (ange-ftp-run-real-handler 'file-name-all-completions args)) | |
4445 (defun ange-ftp-real-file-name-completion (&rest args) | |
4446 (ange-ftp-run-real-handler 'file-name-completion args)) | |
4447 (defun ange-ftp-real-insert-directory (&rest args) | |
4448 (ange-ftp-run-real-handler 'insert-directory args)) | |
4449 (defun ange-ftp-real-file-name-sans-versions (&rest args) | |
4450 (ange-ftp-run-real-handler 'file-name-sans-versions args)) | |
4451 (defun ange-ftp-real-shell-command (&rest args) | |
4452 (ange-ftp-run-real-handler 'shell-command args)) | |
4453 (defun ange-ftp-real-load (&rest args) | |
4454 (ange-ftp-run-real-handler 'load args)) | |
4455 (defun ange-ftp-real-find-backup-file-name (&rest args) | |
4456 (ange-ftp-run-real-handler 'find-backup-file-name args)) | |
4457 | |
4458 ;; Here we support using dired on remote hosts. | |
4459 ;; I have turned off the support for using dired on foreign directory formats. | |
4460 ;; That involves too many unclean hooks. | |
30459 | 4461 ;; It would be cleaner to support such operations by |
28210 | 4462 ;; converting the foreign directory format to something dired can understand; |
4463 ;; something close to ls -l output. | |
4464 ;; The logical place to do this is in the functions ange-ftp-parse-...-listing. | |
4465 | |
4466 ;; Some of the old dired hooks would still be needed even if this is done. | |
4467 ;; I have preserved (and modernized) those hooks. | |
4468 ;; So the format conversion should be all that is needed. | |
4469 | |
47575
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4470 ;; 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
|
4471 ;; `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
|
4472 |
28210 | 4473 (defun ange-ftp-insert-directory (file switches &optional wildcard full) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4474 (if (not (ange-ftp-ftp-name (expand-file-name file))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4475 (ange-ftp-real-insert-directory file switches wildcard full) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4476 ;; We used to follow symlinks on `file' here. Apparently it was done |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4477 ;; because some FTP servers react to "ls foo" by listing the symlink foo |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4478 ;; rather than the directory it points to. Now that ange-ftp-ls uses |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4479 ;; "cd foo; ls" instead, this is not necesssary any more. |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4480 (insert |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4481 (cond |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4482 (wildcard |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4483 (let ((default-directory (file-name-directory file))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4484 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4485 (full |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4486 (ange-ftp-ls file switches 'parse)) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4487 (t |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4488 ;; If `full' is nil we're going to do `ls' for a single file. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4489 ;; Problem is that for various reasons, ange-ftp-ls needs to cd and |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4490 ;; then do an ls of current dir, which obviously won't work if we |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4491 ;; want to ls a file. So instead, we get a full listing of the |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4492 ;; parent directory and extract the line corresponding to `file'. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4493 (when (string-match "d\\'" switches) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4494 ;; Remove "d" which dired added to `switches'. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4495 (setq switches (substring switches 0 (match-beginning 0)))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4496 (let* ((dirlist (ange-ftp-ls (or (file-name-directory file) ".") |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4497 switches nil)) |
65791
5121212db622
(ange-ftp-insert-directory): Fix up the search when `file' is absolute.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65790
diff
changeset
|
4498 (filename (file-name-nondirectory (directory-file-name file))) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4499 (case-fold-search nil)) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4500 ;; FIXME: This presumes a particular output format, which is |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4501 ;; basically Unix. |
65791
5121212db622
(ange-ftp-insert-directory): Fix up the search when `file' is absolute.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65790
diff
changeset
|
4502 (if (string-match (concat "^.+[^ ] " (regexp-quote filename) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4503 "\\( -> .*\\)?[@/*=]?\n") dirlist) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4504 (match-string 0 dirlist) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4505 ""))))))) |
28210 | 4506 |
4507 (defun ange-ftp-dired-uncache (dir) | |
4508 (if (ange-ftp-ftp-name (expand-file-name dir)) | |
4509 (setq ange-ftp-ls-cache-file nil))) | |
4510 | |
4511 (defvar ange-ftp-sans-version-alist nil | |
4512 "Alist of mapping host type into function to remove file version numbers.") | |
4513 | |
4514 (defun ange-ftp-file-name-sans-versions (file keep-backup-version) | |
4515 (let* ((short (ange-ftp-abbreviate-filename file)) | |
4516 (parsed (ange-ftp-ftp-name short)) | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4517 (func (if parsed (cdr (assq (ange-ftp-host-type (car parsed)) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4518 ange-ftp-sans-version-alist))))) |
28210 | 4519 (if func (funcall func file keep-backup-version) |
4520 (ange-ftp-real-file-name-sans-versions file keep-backup-version)))) | |
4521 | |
4522 ;; This is the handler for shell-command. | |
4523 (defun ange-ftp-shell-command (command &optional output-buffer error-buffer) | |
4524 (let* ((parsed (ange-ftp-ftp-name default-directory)) | |
4525 (host (nth 0 parsed)) | |
4526 (user (nth 1 parsed)) | |
4527 (name (nth 2 parsed))) | |
4528 (if (not parsed) | |
4529 (ange-ftp-real-shell-command command output-buffer error-buffer) | |
4530 (if (> (length name) 0) ; else it's $HOME | |
4531 (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
|
4532 ;; Remove port from the hostname |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4533 (when (string-match "\\(.*\\)#" host) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4534 (setq host (match-string 1 host))) |
28210 | 4535 (setq command |
4536 (format "%s %s \"%s\"" ; remsh -l USER does not work well | |
4537 ; on a hp-ux machine I tried | |
4538 remote-shell-program host command)) | |
4539 (ange-ftp-message "Remote command '%s' ..." command) | |
4540 ;; Cannot call ange-ftp-real-dired-run-shell-command here as it | |
4541 ;; would prepend "cd default-directory" --- which bombs because | |
4542 ;; default-directory is in ange-ftp syntax for remote file names. | |
4543 (ange-ftp-real-shell-command command output-buffer error-buffer)))) | |
4544 | |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4545 ;;; This is the handler for process-file. |
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4546 (defun ange-ftp-process-file (program infile buffer display &rest arguments) |
28210 | 4547 ;; PROGRAM is always one of those below in the cond in dired.el. |
4548 ;; The ARGUMENTS are (nearly) always files. | |
4549 (if (ange-ftp-ftp-name default-directory) | |
4550 ;; Can't use ange-ftp-dired-host-type here because the current | |
4551 ;; buffer is *dired-check-process output* | |
4552 (condition-case oops | |
4553 (cond ((equal dired-chmod-program program) | |
4554 (ange-ftp-call-chmod arguments)) | |
4555 ;; ((equal "chgrp" program)) | |
4556 ;; ((equal dired-chown-program program)) | |
4557 (t (error "Unknown remote command: %s" program))) | |
4558 (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
|
4559 (nth 1 oops) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4560 (nth 2 oops) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4561 (nth 3 oops))) |
28210 | 4562 ;; Caller expects nonzero value to mean failure. |
4563 1) | |
4564 (error (insert (format "%s\n" (nth 1 oops))) | |
4565 1)) | |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4566 (apply 'call-process program infile buffer display arguments))) |
28210 | 4567 |
4568 ;; Handle an attempt to run chmod on a remote file | |
4569 ;; by using the ftp chmod command. | |
4570 (defun ange-ftp-call-chmod (args) | |
4571 (if (< (length args) 2) | |
4572 (error "ange-ftp-call-chmod: missing mode and/or filename: %s" args)) | |
4573 (let ((mode (car args)) | |
4574 (rest (cdr args))) | |
4575 (if (equal "--" (car rest)) | |
4576 (setq rest (cdr rest))) | |
84913
db1179979d6b
(ange-ftp-call-chmod, ange-ftp-parse-bs2000-listing):
Juanma Barranquero <lekktu@gmail.com>
parents:
83791
diff
changeset
|
4577 (mapc |
30459 | 4578 (lambda (file) |
4579 (setq file (expand-file-name file)) | |
4580 (let ((parsed (ange-ftp-ftp-name file))) | |
4581 (if parsed | |
4582 (let* ((host (nth 0 parsed)) | |
4583 (user (nth 1 parsed)) | |
4584 (name (ange-ftp-quote-string (nth 2 parsed))) | |
4585 (abbr (ange-ftp-abbreviate-filename file)) | |
4586 (result (ange-ftp-send-cmd host user | |
4587 (list 'chmod mode name) | |
4588 (format "doing chmod %s" | |
4589 abbr)))) | |
4590 (or (car result) | |
4591 (call-process | |
57426
4f0c0062f974
(ange-ftp-remote-shell): Remove variable.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
56765
diff
changeset
|
4592 remote-shell-program |
30459 | 4593 nil t nil host dired-chmod-program mode name)))))) |
28210 | 4594 rest)) |
4595 (setq ange-ftp-ls-cache-file nil) ;Stop confusing Dired. | |
4596 0) | |
4597 | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
4598 ;; This is turned off because it has nothing properly to do |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
4599 ;; with dired. It could be reasonable to adapt this to |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
4600 ;; replace ange-ftp-copy-file. |
28210 | 4601 |
4602 ;;;;; ------------------------------------------------------------ | |
4603 ;;;;; Noddy support for async copy-file within dired. | |
4604 ;;;;; ------------------------------------------------------------ | |
4605 | |
4606 ;;(defun ange-ftp-dired-copy-file (from to ok-flag &optional cont nowait) | |
4607 ;; "Documented as original." | |
4608 ;; (dired-handle-overwrite to) | |
4609 ;; (ange-ftp-copy-file-internal from to ok-flag dired-copy-preserve-time nil | |
4610 ;; cont nowait)) | |
4611 | |
4612 ;;(defun ange-ftp-dired-do-create-files (op-symbol file-creator operation arg | |
4613 ;; &optional marker-char op1 | |
4614 ;; how-to) | |
4615 ;; "Documented as original." | |
4616 ;; ;; we need to let ange-ftp-dired-create-files know that we indirectly | |
4617 ;; ;; called it rather than somebody else. | |
4618 ;; (let ((ange-ftp-dired-do-create-files t)) ; tell who caller is | |
4619 ;; (ange-ftp-real-dired-do-create-files op-symbol file-creator operation | |
4620 ;; arg marker-char op1 how-to))) | |
4621 | |
4622 ;;(defun ange-ftp-dired-create-files (file-creator operation fn-list name-constructor | |
4623 ;; &optional marker-char) | |
4624 ;; "Documented as original." | |
4625 ;; (if (and (boundp 'ange-ftp-dired-do-create-files) | |
4626 ;; ;; called from ange-ftp-dired-do-create-files? | |
4627 ;; ange-ftp-dired-do-create-files | |
4628 ;; ;; any files worth copying? | |
4629 ;; fn-list | |
4630 ;; ;; we only support async copy-file at the mo. | |
4631 ;; (eq file-creator 'dired-copy-file) | |
4632 ;; ;; it is only worth calling the alternative function for remote files | |
4633 ;; ;; as we tie ourself in recursive knots otherwise. | |
4634 ;; (or (ange-ftp-ftp-name (car fn-list)) | |
4635 ;; ;; we can only call the name constructor for dired-do-create-files | |
4636 ;; ;; since the one for regexps starts prompting here, there and | |
4637 ;; ;; everywhere. | |
4638 ;; (ange-ftp-ftp-name (funcall name-constructor (car fn-list))))) | |
4639 ;; ;; use the process-filter driven routine rather than the iterative one. | |
4640 ;; (ange-ftp-dcf-1 file-creator | |
4641 ;; operation | |
4642 ;; fn-list | |
4643 ;; name-constructor | |
4644 ;; (and (boundp 'target) target) ;dynamically bound | |
4645 ;; marker-char | |
4646 ;; (current-buffer) | |
4647 ;; nil ;overwrite-query | |
4648 ;; nil ;overwrite-backup-query | |
4649 ;; nil ;failures | |
4650 ;; nil ;skipped | |
4651 ;; 0 ;success-count | |
4652 ;; (length fn-list) ;total | |
4653 ;; ) | |
4654 ;; ;; normal case... use the interactive routine... much cheaper. | |
4655 ;; (ange-ftp-real-dired-create-files file-creator operation fn-list | |
4656 ;; name-constructor marker-char))) | |
4657 | |
4658 ;;(defun ange-ftp-dcf-1 (file-creator operation fn-list name-constructor | |
30459 | 4659 ;; target marker-char buffer overwrite-query |
28210 | 4660 ;; overwrite-backup-query failures skipped |
4661 ;; success-count total) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4662 ;; (with-current-buffer buffer |
28210 | 4663 ;; (if (null fn-list) |
4664 ;; (ange-ftp-dcf-3 failures operation total skipped | |
4665 ;; success-count buffer) | |
30459 | 4666 |
28210 | 4667 ;; (let* ((from (car fn-list)) |
4668 ;; (to (funcall name-constructor from))) | |
4669 ;; (if (equal to from) | |
4670 ;; (progn | |
4671 ;; (setq to nil) | |
4672 ;; (dired-log "Cannot %s to same file: %s\n" | |
4673 ;; (downcase operation) from))) | |
4674 ;; (if (not to) | |
4675 ;; (ange-ftp-dcf-1 file-creator | |
4676 ;; operation | |
4677 ;; (cdr fn-list) | |
4678 ;; name-constructor | |
4679 ;; target | |
4680 ;; marker-char | |
4681 ;; buffer | |
4682 ;; overwrite-query | |
4683 ;; overwrite-backup-query | |
4684 ;; failures | |
4685 ;; (cons (dired-make-relative from) skipped) | |
4686 ;; success-count | |
4687 ;; total) | |
4688 ;; (let* ((overwrite (file-exists-p to)) | |
4689 ;; (overwrite-confirmed ; for dired-handle-overwrite | |
4690 ;; (and overwrite | |
4691 ;; (let ((help-form '(format "\ | |
4692 ;;Type SPC or `y' to overwrite file `%s', | |
4693 ;;DEL or `n' to skip to next, | |
4694 ;;ESC or `q' to not overwrite any of the remaining files, | |
4695 ;;`!' to overwrite all remaining files with no more questions." to))) | |
4696 ;; (dired-query 'overwrite-query | |
4697 ;; "Overwrite `%s'?" to)))) | |
4698 ;; ;; must determine if FROM is marked before file-creator | |
4699 ;; ;; gets a chance to delete it (in case of a move). | |
4700 ;; (actual-marker-char | |
4701 ;; (cond ((integerp marker-char) marker-char) | |
4702 ;; (marker-char (dired-file-marker from)) ; slow | |
4703 ;; (t nil)))) | |
4704 ;; (condition-case err | |
4705 ;; (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
|
4706 ;; (list 'ange-ftp-dcf-2 |
28210 | 4707 ;; nil ;err |
4708 ;; file-creator operation fn-list | |
4709 ;; name-constructor | |
4710 ;; target | |
4711 ;; marker-char actual-marker-char | |
4712 ;; buffer to from | |
4713 ;; overwrite | |
4714 ;; overwrite-confirmed | |
30459 | 4715 ;; overwrite-query |
28210 | 4716 ;; overwrite-backup-query |
4717 ;; failures skipped success-count | |
4718 ;; total) | |
4719 ;; t) | |
4720 ;; (file-error ; FILE-CREATOR aborted | |
4721 ;; (ange-ftp-dcf-2 nil ;result | |
4722 ;; nil ;line | |
4723 ;; err | |
4724 ;; file-creator operation fn-list | |
4725 ;; name-constructor | |
4726 ;; target | |
4727 ;; marker-char actual-marker-char | |
4728 ;; buffer to from | |
4729 ;; overwrite | |
4730 ;; overwrite-confirmed | |
30459 | 4731 ;; overwrite-query |
28210 | 4732 ;; overwrite-backup-query |
4733 ;; failures skipped success-count | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4734 ;; total))))))))) |
28210 | 4735 |
4736 ;;(defun ange-ftp-dcf-2 (result line err | |
4737 ;; file-creator operation fn-list | |
4738 ;; name-constructor | |
4739 ;; target | |
4740 ;; marker-char actual-marker-char | |
4741 ;; buffer to from | |
4742 ;; overwrite | |
4743 ;; overwrite-confirmed | |
30459 | 4744 ;; overwrite-query |
28210 | 4745 ;; overwrite-backup-query |
4746 ;; failures skipped success-count | |
4747 ;; total) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4748 ;; (with-current-buffer buffer |
28210 | 4749 ;; (if (or err (not result)) |
4750 ;; (progn | |
4751 ;; (setq failures (cons (dired-make-relative from) failures)) | |
4752 ;; (dired-log "%s `%s' to `%s' failed:\n%s\n" | |
4753 ;; operation from to (or err line))) | |
4754 ;; (if overwrite | |
4755 ;; ;; If we get here, file-creator hasn't been aborted | |
4756 ;; ;; and the old entry (if any) has to be deleted | |
4757 ;; ;; before adding the new entry. | |
4758 ;; (dired-remove-file to)) | |
4759 ;; (setq success-count (1+ success-count)) | |
4760 ;; (message "%s: %d of %d" operation success-count total) | |
4761 ;; (dired-add-file to actual-marker-char)) | |
30459 | 4762 |
28210 | 4763 ;; (ange-ftp-dcf-1 file-creator operation (cdr fn-list) |
4764 ;; name-constructor | |
4765 ;; target | |
4766 ;; marker-char | |
4767 ;; buffer | |
30459 | 4768 ;; overwrite-query |
28210 | 4769 ;; overwrite-backup-query |
4770 ;; failures skipped success-count | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4771 ;; total))) |
28210 | 4772 |
4773 ;;(defun ange-ftp-dcf-3 (failures operation total skipped success-count | |
4774 ;; buffer) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4775 ;; (with-current-buffer buffer |
28210 | 4776 ;; (cond |
4777 ;; (failures | |
4778 ;; (dired-log-summary | |
4779 ;; (message "%s failed for %d of %d file%s %s" | |
4780 ;; operation (length failures) total | |
4781 ;; (dired-plural-s total) failures))) | |
4782 ;; (skipped | |
4783 ;; (dired-log-summary | |
4784 ;; (message "%s: %d of %d file%s skipped %s" | |
4785 ;; operation (length skipped) total | |
4786 ;; (dired-plural-s total) skipped))) | |
4787 ;; (t | |
4788 ;; (message "%s: %s file%s." | |
4789 ;; operation success-count (dired-plural-s success-count)))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4790 ;; (dired-move-to-filename))) |
28210 | 4791 |
4792 ;;;; ----------------------------------------------- | |
4793 ;;;; Unix Descriptive Listing (dl) Support | |
4794 ;;;; ----------------------------------------------- | |
4795 | |
4796 ;; This is turned off because nothing uses it currently | |
4797 ;; and because I don't understand what it's supposed to be for. --rms. | |
4798 | |
4799 ;;(defconst ange-ftp-dired-dl-re-dir | |
4800 ;; "^. [^ /]+/[ \n]" | |
4801 ;; "Regular expression to use to search for dl directories.") | |
4802 | |
4803 ;;(or (assq 'unix:dl ange-ftp-dired-re-dir-alist) | |
4804 ;; (setq ange-ftp-dired-re-dir-alist | |
4805 ;; (cons (cons 'unix:dl ange-ftp-dired-dl-re-dir) | |
4806 ;; ange-ftp-dired-re-dir-alist))) | |
4807 | |
4808 ;;(defun ange-ftp-dired-dl-move-to-filename (&optional raise-error eol) | |
4809 ;; "In dired, move to the first character of the filename on this line." | |
4810 ;; ;; This is the Unix dl version. | |
4811 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
4812 ;; (let (case-fold-search) | |
4813 ;; (beginning-of-line) | |
4814 ;; (if (looking-at ". [^ ]+ +\\([0-9]+\\|-\\|=\\) ") | |
4815 ;; (goto-char (+ (point) 2)) | |
4816 ;; (if raise-error | |
4817 ;; (error "No file on this line") | |
4818 ;; nil)))) | |
4819 | |
4820 ;;(or (assq 'unix:dl ange-ftp-dired-move-to-filename-alist) | |
4821 ;; (setq ange-ftp-dired-move-to-filename-alist | |
4822 ;; (cons '(unix:dl . ange-ftp-dired-dl-move-to-filename) | |
4823 ;; ange-ftp-dired-move-to-filename-alist))) | |
4824 | |
4825 ;;(defun ange-ftp-dired-dl-move-to-end-of-filename (&optional no-error eol) | |
4826 ;; ;; Assumes point is at beginning of filename. | |
4827 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
4828 ;; ;; On failure, signals an error or returns nil. | |
4829 ;; ;; This is the Unix dl version. | |
4830 ;; (let ((opoint (point)) | |
4831 ;; case-fold-search hidden) | |
4832 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
4833 ;; (setq hidden (and selective-display | |
4834 ;; (save-excursion | |
4835 ;; (search-forward "\r" eol t)))) | |
4836 ;; (if hidden | |
4837 ;; (if no-error | |
4838 ;; nil | |
4839 ;; (error | |
4840 ;; (substitute-command-keys | |
4841 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide"))) | |
4842 ;; (skip-chars-forward "^ /" eol) | |
4843 ;; (if (eq opoint (point)) | |
4844 ;; (if no-error | |
4845 ;; nil | |
4846 ;; (error "No file on this line")) | |
4847 ;; (point))))) | |
4848 | |
4849 ;;(or (assq 'unix:dl ange-ftp-dired-move-to-end-of-filename-alist) | |
4850 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
4851 ;; (cons '(unix:dl . ange-ftp-dired-dl-move-to-end-of-filename) | |
4852 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
4853 | |
4854 ;;;; ------------------------------------------------------------ | |
4855 ;;;; VOS support (VOS support is probably broken, | |
4856 ;;;; but I don't know anything about VOS.) | |
4857 ;;;; ------------------------------------------------------------ | |
4858 ; | |
4859 ;(defun ange-ftp-fix-name-for-vos (name &optional reverse) | |
4860 ; (setq name (copy-sequence name)) | |
4861 ; (let ((from (if reverse ?\> ?\/)) | |
4862 ; (to (if reverse ?\/ ?\>)) | |
4863 ; (i (1- (length name)))) | |
4864 ; (while (>= i 0) | |
4865 ; (if (= (aref name i) from) | |
4866 ; (aset name i to)) | |
4867 ; (setq i (1- i))) | |
4868 ; name)) | |
4869 ; | |
4870 ;(or (assq 'vos ange-ftp-fix-name-func-alist) | |
4871 ; (setq ange-ftp-fix-name-func-alist | |
4872 ; (cons '(vos . ange-ftp-fix-name-for-vos) | |
4873 ; ange-ftp-fix-name-func-alist))) | |
4874 ; | |
4875 ;(or (memq 'vos ange-ftp-dumb-host-types) | |
4876 ; (setq ange-ftp-dumb-host-types | |
4877 ; (cons 'vos ange-ftp-dumb-host-types))) | |
4878 ; | |
4879 ;(defun ange-ftp-fix-dir-name-for-vos (dir-name) | |
4880 ; (ange-ftp-fix-name-for-vos | |
4881 ; (concat dir-name | |
4882 ; (if (eq ?/ (aref dir-name (1- (length dir-name)))) | |
4883 ; "" "/") | |
4884 ; "*"))) | |
4885 ; | |
4886 ;(or (assq 'vos ange-ftp-fix-dir-name-func-alist) | |
4887 ; (setq ange-ftp-fix-dir-name-func-alist | |
4888 ; (cons '(vos . ange-ftp-fix-dir-name-for-vos) | |
4889 ; ange-ftp-fix-dir-name-func-alist))) | |
4890 ; | |
4891 ;(defvar ange-ftp-vos-host-regexp nil | |
4892 ; "If a host matches this regexp then it is assumed to be running VOS.") | |
4893 ; | |
4894 ;(defun ange-ftp-vos-host (host) | |
4895 ; (and ange-ftp-vos-host-regexp | |
4896 ; (save-match-data | |
4897 ; (string-match ange-ftp-vos-host-regexp host)))) | |
4898 ; | |
4899 ;(defun ange-ftp-parse-vos-listing () | |
4900 ; "Parse the current buffer which is assumed to be in VOS list -all | |
4901 ;format, and return a hashtable as the result." | |
4902 ; (let ((tbl (ange-ftp-make-hashtable)) | |
4903 ; (type-list | |
4904 ; '(("^Files: [0-9]+ +Blocks: [0-9]+\n+" nil 40) | |
4905 ; ("^Dirs: [0-9]+\n+" t 30))) | |
4906 ; type-regexp type-is-dir type-col file) | |
4907 ; (goto-char (point-min)) | |
4908 ; (save-match-data | |
4909 ; (while type-list | |
4910 ; (setq type-regexp (car (car type-list)) | |
4911 ; type-is-dir (nth 1 (car type-list)) | |
4912 ; type-col (nth 2 (car type-list)) | |
4913 ; type-list (cdr type-list)) | |
4914 ; (if (re-search-forward type-regexp nil t) | |
4915 ; (while (eq (char-after (point)) ? ) | |
4916 ; (move-to-column type-col) | |
4917 ; (setq file (buffer-substring (point) | |
4918 ; (progn | |
4919 ; (end-of-line 1) | |
4920 ; (point)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4921 ; (puthash file type-is-dir tbl) |
28210 | 4922 ; (forward-line 1)))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4923 ; (puthash "." 'vosdir tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4924 ; (puthash ".." 'vosdir tbl)) |
28210 | 4925 ; tbl)) |
4926 ; | |
4927 ;(or (assq 'vos ange-ftp-parse-list-func-alist) | |
4928 ; (setq ange-ftp-parse-list-func-alist | |
4929 ; (cons '(vos . ange-ftp-parse-vos-listing) | |
4930 ; ange-ftp-parse-list-func-alist))) | |
4931 | |
4932 ;;;; ------------------------------------------------------------ | |
4933 ;;;; VMS support. | |
4934 ;;;; ------------------------------------------------------------ | |
4935 | |
4936 ;; Convert NAME from UNIX-ish to VMS. If REVERSE given then convert from VMS | |
4937 ;; to UNIX-ish. | |
4938 (defun ange-ftp-fix-name-for-vms (name &optional reverse) | |
4939 (save-match-data | |
4940 (if reverse | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
4941 (if (string-match "\\`\\([^:]+:\\)?\\(\\[.*\\]\\)?\\([^][]*\\)\\'" name) |
28210 | 4942 (let (drive dir file) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4943 (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
|
4944 (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
|
4945 (setq file (match-string 3 name)) |
28210 | 4946 (and dir |
30481 | 4947 (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
|
4948 ?/ ?. (substring dir 1 -1) t))) |
28210 | 4949 (concat (and drive |
4950 (concat "/" drive "/")) | |
4951 dir (and dir "/") | |
4952 file)) | |
4953 (error "name %s didn't match" name)) | |
4954 (let (drive dir file tmp) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
4955 (if (string-match "\\`/[^:]+:/" name) |
28210 | 4956 (setq drive (substring name 1 |
4957 (1- (match-end 0))) | |
4958 name (substring name (match-end 0)))) | |
4959 (setq tmp (file-name-directory name)) | |
4960 (if tmp | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
4961 (setq dir (subst-char-in-string ?/ ?. (substring tmp 0 -1) t))) |
28210 | 4962 (setq file (file-name-nondirectory name)) |
4963 (concat drive | |
4964 (and dir (concat "[" (if drive nil ".") dir "]")) | |
4965 file))))) | |
4966 | |
4967 ;; (ange-ftp-fix-name-for-vms "/PUB$:/ANONYMOUS/SDSCPUB/NEXT/Readme.txt;1") | |
4968 ;; (ange-ftp-fix-name-for-vms "/PUB$:[ANONYMOUS.SDSCPUB.NEXT]Readme.txt;1" t) | |
4969 | |
4970 (or (assq 'vms ange-ftp-fix-name-func-alist) | |
4971 (setq ange-ftp-fix-name-func-alist | |
4972 (cons '(vms . ange-ftp-fix-name-for-vms) | |
4973 ange-ftp-fix-name-func-alist))) | |
4974 | |
4975 (or (memq 'vms ange-ftp-dumb-host-types) | |
4976 (setq ange-ftp-dumb-host-types | |
4977 (cons 'vms ange-ftp-dumb-host-types))) | |
4978 | |
4979 ;; It is important that this function barf for directories for which we know | |
4980 ;; that we cannot possibly get a directory listing, such as "/" and "/DEV:/". | |
4981 ;; This is because it saves an unnecessary FTP error, or possibly the listing | |
4982 ;; might succeed, but give erroneous info. This last case is particularly | |
4983 ;; likely for OS's (like MTS) for which we need to use a wildcard in order | |
4984 ;; to list a directory. | |
4985 | |
4986 ;; Convert name from UNIX-ish to VMS ready for a DIRectory listing. | |
4987 (defun ange-ftp-fix-dir-name-for-vms (dir-name) | |
4988 ;; Should there be entries for .. -> [-] and . -> [] below. Don't | |
4989 ;; think so, because expand-filename should have already short-circuited | |
4990 ;; them. | |
4991 (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
|
4992 (error "Cannot get listing for fictitious \"/\" directory")) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
4993 ((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
|
4994 (error "Cannot get listing for device")) |
28210 | 4995 ((ange-ftp-fix-name-for-vms dir-name)))) |
30459 | 4996 |
28210 | 4997 (or (assq 'vms ange-ftp-fix-dir-name-func-alist) |
4998 (setq ange-ftp-fix-dir-name-func-alist | |
4999 (cons '(vms . ange-ftp-fix-dir-name-for-vms) | |
5000 ange-ftp-fix-dir-name-func-alist))) | |
5001 | |
5002 (defvar ange-ftp-vms-host-regexp nil) | |
5003 | |
5004 ;; Return non-nil if HOST is running VMS. | |
5005 (defun ange-ftp-vms-host (host) | |
5006 (and ange-ftp-vms-host-regexp | |
5007 (save-match-data | |
5008 (string-match ange-ftp-vms-host-regexp host)))) | |
5009 | |
5010 ;; Because some VMS ftp servers convert filenames to lower case | |
5011 ;; we allow a-z in the filename regexp. I'm not too happy about this. | |
5012 | |
5013 (defconst ange-ftp-vms-filename-regexp | |
5014 (concat | |
5015 "\\(\\([_A-Za-z0-9$]?\\|[_A-Za-z0-9$][-_A-Za-z0-9$]*\\)\\." | |
5016 "[-_A-Za-z0-9$]*;+[0-9]*\\)") | |
5017 "Regular expression to match for a valid VMS file name in Dired buffer. | |
5018 Stupid freaking bug! Position of _ and $ shouldn't matter but they do. | |
5019 Having [A-Z0-9$_] bombs on filename _$$CHANGE_LOG$.TXT$ and $CHANGE_LOG$.TX | |
5020 Other orders of $ and _ seem to all work just fine.") | |
5021 | |
5022 ;; These parsing functions are as general as possible because the syntax | |
5023 ;; of ftp listings from VMS hosts is a bit erratic. What saves us is that | |
5024 ;; the VMS filename syntax is so rigid. If they bomb on a listing in the | |
5025 ;; standard VMS Multinet format, then this is a bug. If they bomb on a listing | |
5026 ;; from vms.weird.net, then too bad. | |
5027 | |
5028 ;; Extract the next filename from a VMS dired-like listing. | |
5029 (defun ange-ftp-parse-vms-filename () | |
5030 (if (re-search-forward | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5031 ange-ftp-vms-filename-regexp |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5032 nil t) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5033 (match-string 0))) |
28210 | 5034 |
5035 ;; Parse the current buffer which is assumed to be in MultiNet FTP dir | |
5036 ;; format, and return a hashtable as the result. | |
5037 (defun ange-ftp-parse-vms-listing () | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5038 (let ((tbl (make-hash-table :test 'equal)) |
28210 | 5039 file) |
5040 (goto-char (point-min)) | |
5041 (save-match-data | |
5042 (while (setq file (ange-ftp-parse-vms-filename)) | |
5043 (if (string-match "\\.\\(DIR\\|dir\\);[0-9]+" file) | |
5044 ;; deal with directories | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5045 (puthash (substring file 0 (match-beginning 0)) t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5046 (puthash file nil tbl) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5047 (if (string-match ";[0-9]+\\'" file) ; deal with extension |
28210 | 5048 ;; sans extension |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5049 (puthash (substring file 0 (match-beginning 0)) nil tbl))) |
28210 | 5050 (forward-line 1)) |
5051 ;; Would like to look for a "Total" line, or a "Directory" line to | |
5052 ;; make sure that the listing isn't complete garbage before putting | |
5053 ;; in "." and "..", but we can't even count on all VAX's giving us | |
5054 ;; either of these. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5055 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5056 (puthash ".." t tbl)) |
28210 | 5057 tbl)) |
5058 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5059 (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
|
5060 '(vms . ange-ftp-parse-vms-listing)) |
28210 | 5061 |
5062 ;; This version only deletes file entries which have | |
5063 ;; explicit version numbers, because that is all VMS allows. | |
5064 | |
5065 ;; Can the following two functions be speeded up using file | |
5066 ;; completion functions? | |
5067 | |
5068 (defun ange-ftp-vms-delete-file-entry (name &optional dir-p) | |
5069 (if dir-p | |
5070 (ange-ftp-internal-delete-file-entry name t) | |
5071 (save-match-data | |
5072 (let ((file (ange-ftp-get-file-part name))) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5073 (if (string-match ";[0-9]+\\'" file) |
30459 | 5074 ;; In VMS you can't delete a file without an explicit |
28210 | 5075 ;; version number, or wild-card (e.g. FOO;*) |
5076 ;; For now, we give up on wildcards. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5077 (let ((files (gethash (file-name-directory name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5078 ange-ftp-files-hashtable))) |
28210 | 5079 (if files |
5080 (let* ((root (substring file 0 | |
5081 (match-beginning 0))) | |
5082 (regexp (concat "^" | |
5083 (regexp-quote root) | |
5084 ";[0-9]+$")) | |
5085 versions) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5086 (remhash file files) |
28210 | 5087 ;; Now we need to check if there are any |
5088 ;; versions left. If not, then delete the | |
5089 ;; root entry. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5090 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5091 (lambda (key val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5092 (and (string-match regexp key) |
29587
bcdfb27c5ea4
(ange-ftp-vms-delete-file-entry)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28892
diff
changeset
|
5093 (setq versions t))) |
28210 | 5094 files) |
5095 (or versions | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5096 (remhash root files)))))))))) |
28210 | 5097 |
5098 (or (assq 'vms ange-ftp-delete-file-entry-alist) | |
5099 (setq ange-ftp-delete-file-entry-alist | |
5100 (cons '(vms . ange-ftp-vms-delete-file-entry) | |
5101 ange-ftp-delete-file-entry-alist))) | |
5102 | |
5103 (defun ange-ftp-vms-add-file-entry (name &optional dir-p) | |
5104 (if dir-p | |
5105 (ange-ftp-internal-add-file-entry name t) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5106 (let ((files (gethash (file-name-directory name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5107 ange-ftp-files-hashtable))) |
28210 | 5108 (if files |
5109 (let ((file (ange-ftp-get-file-part name))) | |
5110 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5111 (if (string-match ";[0-9]+\\'" file) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5112 (puthash (substring file 0 (match-beginning 0)) nil files) |
28210 | 5113 ;; Need to figure out what version of the file |
5114 ;; is being added. | |
5115 (let ((regexp (concat "^" | |
5116 (regexp-quote file) | |
5117 ";\\([0-9]+\\)$")) | |
5118 (version 0)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5119 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5120 (lambda (name val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5121 (and (string-match regexp name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5122 (setq version |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5123 (max version |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
59996
diff
changeset
|
5124 (string-to-number (match-string 1 name)))))) |
28210 | 5125 files) |
5126 (setq version (1+ version)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5127 (puthash |
28210 | 5128 (concat file ";" (int-to-string version)) |
5129 nil files)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5130 (puthash file nil files)))))) |
28210 | 5131 |
5132 (or (assq 'vms ange-ftp-add-file-entry-alist) | |
5133 (setq ange-ftp-add-file-entry-alist | |
5134 (cons '(vms . ange-ftp-vms-add-file-entry) | |
5135 ange-ftp-add-file-entry-alist))) | |
5136 | |
5137 | |
5138 (defun ange-ftp-add-vms-host (host) | |
5139 "Mark HOST as the name of a machine running VMS." | |
5140 (interactive | |
5141 (list (read-string "Host: " | |
5142 (let ((name (or (buffer-file-name) default-directory))) | |
5143 (and name (car (ange-ftp-ftp-name name))))))) | |
5144 (if (not (ange-ftp-vms-host host)) | |
5145 (setq ange-ftp-vms-host-regexp | |
5146 (concat "^" (regexp-quote host) "$" | |
5147 (and ange-ftp-vms-host-regexp "\\|") | |
5148 ange-ftp-vms-host-regexp) | |
5149 ange-ftp-host-cache nil))) | |
5150 | |
5151 | |
5152 (defun ange-ftp-vms-file-name-as-directory (name) | |
5153 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5154 (if (string-match "\\.\\(DIR\\|dir\\)\\(;[0-9]+\\)?\\'" name) |
28210 | 5155 (setq name (substring name 0 (match-beginning 0)))) |
5156 (ange-ftp-real-file-name-as-directory name))) | |
5157 | |
5158 (or (assq 'vms ange-ftp-file-name-as-directory-alist) | |
5159 (setq ange-ftp-file-name-as-directory-alist | |
5160 (cons '(vms . ange-ftp-vms-file-name-as-directory) | |
5161 ange-ftp-file-name-as-directory-alist))) | |
5162 | |
5163 ;;; Tree dired support: | |
5164 | |
5165 ;; For this code I have borrowed liberally from Sebastian Kremer's | |
5166 ;; dired-vms.el | |
5167 | |
5168 | |
5169 ;;;; These regexps must be anchored to beginning of line. | |
5170 ;;;; Beware that the ftpd may put the device in front of the filename. | |
5171 | |
5172 ;;(defconst ange-ftp-dired-vms-re-exe "^. [^ \t.]+\\.\\(EXE\\|exe\\)[; ]" | |
5173 ;; "Regular expression to use to search for VMS executable files.") | |
5174 | |
5175 ;;(defconst ange-ftp-dired-vms-re-dir "^. [^ \t.]+\\.\\(DIR\\|dir\\)[; ]" | |
5176 ;; "Regular expression to use to search for VMS directories.") | |
5177 | |
5178 ;;(or (assq 'vms ange-ftp-dired-re-exe-alist) | |
5179 ;; (setq ange-ftp-dired-re-exe-alist | |
5180 ;; (cons (cons 'vms ange-ftp-dired-vms-re-exe) | |
5181 ;; ange-ftp-dired-re-exe-alist))) | |
5182 | |
5183 ;;(or (assq 'vms ange-ftp-dired-re-dir-alist) | |
5184 ;; (setq ange-ftp-dired-re-dir-alist | |
5185 ;; (cons (cons 'vms ange-ftp-dired-vms-re-dir) | |
5186 ;; ange-ftp-dired-re-dir-alist))) | |
5187 | |
5188 ;;(defun ange-ftp-dired-vms-insert-headerline (dir) | |
5189 ;; ;; VMS inserts a headerline. I would prefer the headerline | |
5190 ;; ;; to be in ange-ftp format. This version tries to | |
5191 ;; ;; be careful, because we can't count on a headerline | |
5192 ;; ;; over ftp, and we wouldn't want to delete anything | |
5193 ;; ;; important. | |
5194 ;; (save-excursion | |
5195 ;; (if (looking-at "^ wildcard ") | |
5196 ;; (forward-line 1)) | |
5197 ;; (if (looking-at "^[ \n\t]*[^\n]+\\][ \t]*\n") | |
5198 ;; (delete-region (point) (match-end 0)))) | |
5199 ;; (ange-ftp-real-dired-insert-headerline dir)) | |
5200 | |
5201 ;;(or (assq 'vms ange-ftp-dired-insert-headerline-alist) | |
5202 ;; (setq ange-ftp-dired-insert-headerline-alist | |
5203 ;; (cons '(vms . ange-ftp-dired-vms-insert-headerline) | |
5204 ;; ange-ftp-dired-insert-headerline-alist))) | |
5205 | |
5206 ;;(defun ange-ftp-dired-vms-move-to-filename (&optional raise-error eol) | |
5207 ;; "In dired, move to first char of filename on this line. | |
5208 ;;Returns position (point) or nil if no filename on this line." | |
5209 ;; ;; This is the VMS version. | |
5210 ;; (let (case-fold-search) | |
5211 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5212 ;; (beginning-of-line) | |
5213 ;; (if (re-search-forward ange-ftp-vms-filename-regexp eol t) | |
5214 ;; (goto-char (match-beginning 1)) | |
5215 ;; (if raise-error | |
5216 ;; (error "No file on this line") | |
5217 ;; nil)))) | |
5218 | |
5219 ;;(or (assq 'vms ange-ftp-dired-move-to-filename-alist) | |
5220 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5221 ;; (cons '(vms . ange-ftp-dired-vms-move-to-filename) | |
5222 ;; ange-ftp-dired-move-to-filename-alist))) | |
5223 | |
5224 ;;(defun ange-ftp-dired-vms-move-to-end-of-filename (&optional no-error eol) | |
5225 ;; ;; Assumes point is at beginning of filename. | |
5226 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5227 ;; ;; case-fold-search must be nil, at least for VMS. | |
5228 ;; ;; On failure, signals an error or returns nil. | |
5229 ;; ;; This is the VMS version. | |
5230 ;; (let (opoint hidden case-fold-search) | |
5231 ;; (setq opoint (point)) | |
5232 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
5233 ;; (setq hidden (and selective-display | |
5234 ;; (save-excursion (search-forward "\r" eol t)))) | |
5235 ;; (if hidden | |
5236 ;; nil | |
5237 ;; (re-search-forward ange-ftp-vms-filename-regexp eol t)) | |
5238 ;; (or no-error | |
5239 ;; (not (eq opoint (point))) | |
5240 ;; (error | |
5241 ;; (if hidden | |
5242 ;; (substitute-command-keys | |
5243 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide") | |
5244 ;; "No file on this line"))) | |
5245 ;; (if (eq opoint (point)) | |
5246 ;; nil | |
5247 ;; (point)))) | |
5248 | |
5249 ;;(or (assq 'vms ange-ftp-dired-move-to-end-of-filename-alist) | |
5250 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5251 ;; (cons '(vms . ange-ftp-dired-vms-move-to-end-of-filename) | |
5252 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5253 | |
5254 ;;(defun ange-ftp-dired-vms-between-files () | |
5255 ;; (save-excursion | |
5256 ;; (beginning-of-line) | |
5257 ;; (or (equal (following-char) 10) ; newline | |
5258 ;; (equal (following-char) 9) ; tab | |
5259 ;; (progn (forward-char 2) | |
5260 ;; (or (looking-at "Total of") | |
5261 ;; (equal (following-char) 32)))))) | |
5262 | |
5263 ;;(or (assq 'vms ange-ftp-dired-between-files-alist) | |
5264 ;; (setq ange-ftp-dired-between-files-alist | |
5265 ;; (cons '(vms . ange-ftp-dired-vms-between-files) | |
5266 ;; ange-ftp-dired-between-files-alist))) | |
5267 | |
5268 ;; Beware! In VMS filenames must be of the form "FILE.TYPE". | |
5269 ;; Therefore, we cannot just append a ".Z" to filenames for | |
5270 ;; compressed files. Instead, we turn "FILE.TYPE" into | |
5271 ;; "FILE.TYPE-Z". Hope that this is a reasonable thing to do. | |
5272 | |
5273 (defun ange-ftp-vms-make-compressed-filename (name &optional reverse) | |
5274 (cond | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5275 ((string-match "-Z;[0-9]+\\'" name) |
28210 | 5276 (list nil (substring name 0 (match-beginning 0)))) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5277 ((string-match ";[0-9]+\\'" name) |
28210 | 5278 (list nil (substring name 0 (match-beginning 0)))) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5279 ((string-match "-Z\\'" name) |
28210 | 5280 (list nil (substring name 0 -2))) |
5281 (t | |
5282 (list t | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5283 (if (string-match ";[0-9]+\\'" name) |
28210 | 5284 (concat (substring name 0 (match-beginning 0)) |
5285 "-Z") | |
5286 (concat name "-Z")))))) | |
5287 | |
5288 (or (assq 'vms ange-ftp-make-compressed-filename-alist) | |
5289 (setq ange-ftp-make-compressed-filename-alist | |
5290 (cons '(vms . ange-ftp-vms-make-compressed-filename) | |
5291 ange-ftp-make-compressed-filename-alist))) | |
5292 | |
5293 ;;;; When the filename is too long, VMS will use two lines to list a file | |
5294 ;;;; (damn them!) This will confuse dired. To solve this, need to convince | |
5295 ;;;; Sebastian to use a function dired-go-to-end-of-file-line, instead of | |
5296 ;;;; (forward-line 1). This would require a number of changes to dired.el. | |
5297 ;;;; If dired gets confused, revert-buffer will fix it. | |
5298 | |
5299 ;;(defun ange-ftp-dired-vms-ls-trim () | |
5300 ;; (goto-char (point-min)) | |
5301 ;; (let ((case-fold-search nil)) | |
5302 ;; (re-search-forward ange-ftp-vms-filename-regexp)) | |
5303 ;; (beginning-of-line) | |
5304 ;; (delete-region (point-min) (point)) | |
5305 ;; (forward-line 1) | |
5306 ;; (delete-region (point) (point-max))) | |
5307 | |
5308 | |
5309 ;;(or (assq 'vms ange-ftp-dired-ls-trim-alist) | |
5310 ;; (setq ange-ftp-dired-ls-trim-alist | |
5311 ;; (cons '(vms . ange-ftp-dired-vms-ls-trim) | |
30459 | 5312 ;; ange-ftp-dired-ls-trim-alist))) |
28210 | 5313 |
5314 (defun ange-ftp-vms-sans-version (name &rest args) | |
5315 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5316 (if (string-match ";[0-9]+\\'" name) |
28210 | 5317 (substring name 0 (match-beginning 0)) |
5318 name))) | |
5319 | |
5320 (or (assq 'vms ange-ftp-sans-version-alist) | |
5321 (setq ange-ftp-sans-version-alist | |
5322 (cons '(vms . ange-ftp-vms-sans-version) | |
5323 ange-ftp-sans-version-alist))) | |
5324 | |
5325 ;;(defvar ange-ftp-file-version-alist) | |
5326 | |
5327 ;;;;; The vms version of clean-directory has 2 more optional args | |
5328 ;;;;; than the usual dired version. This is so that it can be used by | |
5329 ;;;;; ange-ftp-dired-vms-flag-backup-files. | |
5330 | |
5331 ;;(defun ange-ftp-dired-vms-clean-directory (keep &optional marker msg) | |
5332 ;; "Flag numerical backups for deletion. | |
5333 ;;Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. | |
5334 ;;Positive prefix arg KEEP overrides `dired-kept-versions'; | |
5335 ;;Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive. | |
5336 | |
5337 ;;To clear the flags on these files, you can use \\[dired-flag-backup-files] | |
5338 ;;with a prefix argument." | |
5339 ;;; (interactive "P") ; Never actually called interactively. | |
5340 ;; (setq keep (max 1 (if keep (prefix-numeric-value keep) dired-kept-versions))) | |
5341 ;; (let ((early-retention (if (< keep 0) (- keep) kept-old-versions)) | |
5342 ;; ;; late-retention must NEVER be allowed to be less than 1 in VMS! | |
5343 ;; ;; This could wipe ALL copies of the file. | |
5344 ;; (late-retention (max 1 (if (<= keep 0) dired-kept-versions keep))) | |
5345 ;; (action (or msg "Cleaning")) | |
5346 ;; (ange-ftp-trample-marker (or marker dired-del-marker)) | |
5347 ;; (ange-ftp-file-version-alist ())) | |
5348 ;; (message (concat action | |
5349 ;; " numerical backups (keeping %d late, %d old)...") | |
5350 ;; late-retention early-retention) | |
5351 ;; ;; Look at each file. | |
5352 ;; ;; If the file has numeric backup versions, | |
5353 ;; ;; put on ange-ftp-file-version-alist an element of the form | |
5354 ;; ;; (FILENAME . VERSION-NUMBER-LIST) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5355 ;; (dired-map-dired-file-lines 'ange-ftp-dired-vms-collect-file-versions) |
28210 | 5356 ;; ;; Sort each VERSION-NUMBER-LIST, |
5357 ;; ;; and remove the versions not to be deleted. | |
5358 ;; (let ((fval ange-ftp-file-version-alist)) | |
5359 ;; (while fval | |
5360 ;; (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<))) | |
5361 ;; (v-count (length sorted-v-list))) | |
5362 ;; (if (> v-count (+ early-retention late-retention)) | |
5363 ;; (rplacd (nthcdr early-retention sorted-v-list) | |
5364 ;; (nthcdr (- v-count late-retention) | |
5365 ;; sorted-v-list))) | |
5366 ;; (rplacd (car fval) | |
5367 ;; (cdr sorted-v-list))) | |
5368 ;; (setq fval (cdr fval)))) | |
5369 ;; ;; Look at each file. If it is a numeric backup file, | |
5370 ;; ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion. | |
5371 ;; (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
|
5372 ;; 'ange-ftp-dired-vms-trample-file-versions mark) |
28210 | 5373 ;; (message (concat action " numerical backups...done")))) |
5374 | |
5375 ;;(or (assq 'vms ange-ftp-dired-clean-directory-alist) | |
5376 ;; (setq ange-ftp-dired-clean-directory-alist | |
5377 ;; (cons '(vms . ange-ftp-dired-vms-clean-directory) | |
5378 ;; ange-ftp-dired-clean-directory-alist))) | |
5379 | |
5380 ;;(defun ange-ftp-dired-vms-collect-file-versions (fn) | |
5381 ;; ;; "If it looks like file FN has versions, return a list of the versions. | |
5382 ;; ;;That is a list of strings which are file names. | |
5383 ;; ;;The caller may want to flag some of these files for deletion." | |
5384 ;;(let ((name (nth 2 (ange-ftp-ftp-name fn)))) | |
5385 ;; (if (string-match ";[0-9]+$" name) | |
5386 ;; (let* ((name (substring name 0 (match-beginning 0))) | |
5387 ;; (fn (ange-ftp-replace-name-component fn name))) | |
5388 ;; (if (not (assq fn ange-ftp-file-version-alist)) | |
5389 ;; (let* ((base-versions | |
5390 ;; (concat (file-name-nondirectory name) ";")) | |
5391 ;; (bv-length (length base-versions)) | |
5392 ;; (possibilities (file-name-all-completions | |
5393 ;; base-versions | |
5394 ;; (file-name-directory fn))) | |
5395 ;; (versions (mapcar | |
5396 ;; '(lambda (arg) | |
5397 ;; (if (and (string-match | |
5398 ;; "[0-9]+$" arg bv-length) | |
5399 ;; (= (match-beginning 0) bv-length)) | |
5400 ;; (string-to-int (substring arg bv-length)) | |
5401 ;; 0)) | |
5402 ;; possibilities))) | |
5403 ;; (if versions | |
5404 ;; (setq | |
5405 ;; ange-ftp-file-version-alist | |
5406 ;; (cons (cons fn versions) | |
5407 ;; ange-ftp-file-version-alist))))))))) | |
5408 | |
5409 ;;(defun ange-ftp-dired-vms-trample-file-versions (fn) | |
5410 ;; (let* ((start-vn (string-match ";[0-9]+$" fn)) | |
5411 ;; base-version-list) | |
5412 ;; (and start-vn | |
5413 ;; (setq base-version-list ; there was a base version to which | |
5414 ;; (assoc (substring fn 0 start-vn) ; this looks like a | |
5415 ;; ange-ftp-file-version-alist)) ; subversion | |
5416 ;; (not (memq (string-to-int (substring fn (1+ start-vn))) | |
5417 ;; base-version-list)) ; this one doesn't make the cut | |
5418 ;; (progn (beginning-of-line) | |
5419 ;; (delete-char 1) | |
5420 ;; (insert ange-ftp-trample-marker))))) | |
5421 | |
5422 ;;(defun ange-ftp-dired-vms-flag-backup-files (&optional unflag-p) | |
5423 ;; (let ((dired-kept-versions 1) | |
5424 ;; (kept-old-versions 0) | |
5425 ;; marker msg) | |
5426 ;; (if unflag-p | |
5427 ;; (setq marker ?\040 msg "Unflagging") | |
5428 ;; (setq marker dired-del-marker msg "Cleaning")) | |
5429 ;; (ange-ftp-dired-vms-clean-directory nil marker msg))) | |
5430 | |
5431 ;;(or (assq 'vms ange-ftp-dired-flag-backup-files-alist) | |
5432 ;; (setq ange-ftp-dired-flag-backup-files-alist | |
5433 ;; (cons '(vms . ange-ftp-dired-vms-flag-backup-files) | |
5434 ;; ange-ftp-dired-flag-backup-files-alist))) | |
5435 | |
5436 ;;(defun ange-ftp-dired-vms-backup-diff (&optional switches) | |
5437 ;; (let ((file (dired-get-filename 'no-dir)) | |
5438 ;; bak) | |
5439 ;; (if (and (string-match ";[0-9]+$" file) | |
5440 ;; ;; Find most recent previous version. | |
5441 ;; (let ((root (substring file 0 (match-beginning 0))) | |
5442 ;; (ver | |
5443 ;; (string-to-int (substring file (1+ (match-beginning 0))))) | |
5444 ;; found) | |
5445 ;; (setq ver (1- ver)) | |
5446 ;; (while (and (> ver 0) (not found)) | |
5447 ;; (setq bak (concat root ";" (int-to-string ver))) | |
5448 ;; (and (file-exists-p bak) (setq found t)) | |
5449 ;; (setq ver (1- ver))) | |
5450 ;; found)) | |
5451 ;; (if switches | |
5452 ;; (diff (expand-file-name bak) (expand-file-name file) switches) | |
5453 ;; (diff (expand-file-name bak) (expand-file-name file))) | |
5454 ;; (error "No previous version found for %s" file)))) | |
5455 | |
5456 ;;(or (assq 'vms ange-ftp-dired-backup-diff-alist) | |
5457 ;; (setq ange-ftp-dired-backup-diff-alist | |
5458 ;; (cons '(vms . ange-ftp-dired-vms-backup-diff) | |
5459 ;; ange-ftp-dired-backup-diff-alist))) | |
5460 | |
5461 | |
5462 ;;;; ------------------------------------------------------------ | |
5463 ;;;; MTS support | |
5464 ;;;; ------------------------------------------------------------ | |
5465 | |
5466 | |
5467 ;; Convert NAME from UNIX-ish to MTS. If REVERSE given then convert from | |
5468 ;; MTS to UNIX-ish. | |
5469 (defun ange-ftp-fix-name-for-mts (name &optional reverse) | |
5470 (save-match-data | |
5471 (if reverse | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5472 (if (string-match "\\`\\([^:]+:\\)?\\(.*\\)\\'" name) |
28210 | 5473 (let (acct file) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5474 (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
|
5475 (setq file (match-string 2 name)) |
28210 | 5476 (concat (and acct (concat "/" acct "/")) |
5477 file)) | |
5478 (error "name %s didn't match" name)) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5479 (if (string-match "\\`/\\([^:]+:\\)/\\(.*\\)\\'" name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5480 (concat (match-string 1 name) (match-string 2 name)) |
28210 | 5481 ;; Let's hope that mts will recognize it anyway. |
5482 name)))) | |
5483 | |
5484 (or (assq 'mts ange-ftp-fix-name-func-alist) | |
5485 (setq ange-ftp-fix-name-func-alist | |
5486 (cons '(mts . ange-ftp-fix-name-for-mts) | |
5487 ange-ftp-fix-name-func-alist))) | |
5488 | |
5489 ;; Convert name from UNIX-ish to MTS ready for a DIRectory listing. | |
5490 ;; Remember that there are no directories in MTS. | |
5491 (defun ange-ftp-fix-dir-name-for-mts (dir-name) | |
5492 (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
|
5493 (error "Cannot get listing for fictitious \"/\" directory") |
28210 | 5494 (let ((dir-name (ange-ftp-fix-name-for-mts dir-name))) |
5495 (cond | |
5496 ((string-equal dir-name "") | |
5497 "?") | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5498 ((string-match ":\\'" dir-name) |
28210 | 5499 (concat dir-name "?")) |
5500 (dir-name))))) ; It's just a single file. | |
5501 | |
5502 (or (assq 'mts ange-ftp-fix-dir-name-func-alist) | |
5503 (setq ange-ftp-fix-dir-name-func-alist | |
5504 (cons '(mts . ange-ftp-fix-dir-name-for-mts) | |
5505 ange-ftp-fix-dir-name-func-alist))) | |
5506 | |
5507 (or (memq 'mts ange-ftp-dumb-host-types) | |
5508 (setq ange-ftp-dumb-host-types | |
5509 (cons 'mts ange-ftp-dumb-host-types))) | |
5510 | |
5511 (defvar ange-ftp-mts-host-regexp nil) | |
5512 | |
5513 ;; Return non-nil if HOST is running MTS. | |
5514 (defun ange-ftp-mts-host (host) | |
5515 (and ange-ftp-mts-host-regexp | |
5516 (save-match-data | |
5517 (string-match ange-ftp-mts-host-regexp host)))) | |
5518 | |
5519 ;; Parse the current buffer which is assumed to be in mts ftp dir format. | |
5520 (defun ange-ftp-parse-mts-listing () | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5521 (let ((tbl (make-hash-table :test 'equal))) |
28210 | 5522 (goto-char (point-min)) |
5523 (save-match-data | |
66325
fda96ff4c7e5
* files.el (directory-listing-before-filename-regexp): New
Michael Albinus <michael.albinus@gmx.de>
parents:
66256
diff
changeset
|
5524 (while (re-search-forward directory-listing-before-filename-regexp nil t) |
28210 | 5525 (end-of-line) |
5526 (skip-chars-backward " ") | |
5527 (let ((end (point))) | |
5528 (skip-chars-backward "-A-Z0-9_.!") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5529 (puthash (buffer-substring (point) end) nil tbl)) |
28210 | 5530 (forward-line 1))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5531 ;; Don't need to bother with .. |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5532 (puthash "." t tbl) |
28210 | 5533 tbl)) |
5534 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5535 (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
|
5536 '(mts . ange-ftp-parse-mts-listing)) |
28210 | 5537 |
5538 (defun ange-ftp-add-mts-host (host) | |
5539 "Mark HOST as the name of a machine running MTS." | |
5540 (interactive | |
5541 (list (read-string "Host: " | |
5542 (let ((name (or (buffer-file-name) default-directory))) | |
5543 (and name (car (ange-ftp-ftp-name name))))))) | |
5544 (if (not (ange-ftp-mts-host host)) | |
5545 (setq ange-ftp-mts-host-regexp | |
5546 (concat "^" (regexp-quote host) "$" | |
5547 (and ange-ftp-mts-host-regexp "\\|") | |
5548 ange-ftp-mts-host-regexp) | |
5549 ange-ftp-host-cache nil))) | |
5550 | |
5551 ;;; Tree dired support: | |
5552 | |
5553 ;;;; There aren't too many systems left that use MTS. This dired support will | |
5554 ;;;; work for the implementation of ftp on mtsg.ubc.ca. I hope other mts systems | |
5555 ;;;; implement ftp in the same way. If not, it might be necessary to make the | |
5556 ;;;; following more flexible. | |
5557 | |
5558 ;;(defun ange-ftp-dired-mts-move-to-filename (&optional raise-error eol) | |
5559 ;; "In dired, move to first char of filename on this line. | |
5560 ;;Returns position (point) or nil if no filename on this line." | |
5561 ;; ;; This is the MTS version. | |
5562 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5563 ;; (beginning-of-line) | |
5564 ;; (if (re-search-forward | |
5565 ;; ange-ftp-date-regexp eol t) | |
5566 ;; (progn | |
5567 ;; (skip-chars-forward " ") ; Eat blanks after date | |
5568 ;; (skip-chars-forward "0-9:" eol) ; Eat time or year | |
5569 ;; (skip-chars-forward " " eol) ; one space before filename | |
5570 ;; ;; When listing an account other than the users own account it appends | |
5571 ;; ;; ACCT: to the beginning of the filename. Skip over this. | |
5572 ;; (and (looking-at "[A-Z0-9_.]+:") | |
5573 ;; (goto-char (match-end 0))) | |
5574 ;; (point)) | |
5575 ;; (if raise-error | |
5576 ;; (error "No file on this line") | |
5577 ;; nil))) | |
5578 | |
5579 ;;(or (assq 'mts ange-ftp-dired-move-to-filename-alist) | |
5580 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5581 ;; (cons '(mts . ange-ftp-dired-mts-move-to-filename) | |
5582 ;; ange-ftp-dired-move-to-filename-alist))) | |
5583 | |
5584 ;;(defun ange-ftp-dired-mts-move-to-end-of-filename (&optional no-error eol) | |
5585 ;; ;; Assumes point is at beginning of filename. | |
5586 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5587 ;; ;; On failure, signals an error or returns nil. | |
5588 ;; ;; This is the MTS version. | |
5589 ;; (let (opoint hidden case-fold-search) | |
5590 ;; (setq opoint (point) | |
5591 ;; eol (save-excursion (end-of-line) (point)) | |
5592 ;; hidden (and selective-display | |
5593 ;; (save-excursion (search-forward "\r" eol t)))) | |
5594 ;; (if hidden | |
5595 ;; nil | |
5596 ;; (skip-chars-forward "-A-Z0-9._!" eol)) | |
5597 ;; (or no-error | |
5598 ;; (not (eq opoint (point))) | |
5599 ;; (error | |
5600 ;; (if hidden | |
5601 ;; (substitute-command-keys | |
5602 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide") | |
5603 ;; "No file on this line"))) | |
5604 ;; (if (eq opoint (point)) | |
5605 ;; nil | |
5606 ;; (point)))) | |
5607 | |
5608 ;;(or (assq 'mts ange-ftp-dired-move-to-end-of-filename-alist) | |
5609 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5610 ;; (cons '(mts . ange-ftp-dired-mts-move-to-end-of-filename) | |
5611 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5612 | |
5613 ;;;; ------------------------------------------------------------ | |
5614 ;;;; CMS support | |
5615 ;;;; ------------------------------------------------------------ | |
5616 | |
5617 ;; Since CMS doesn't have any full file name syntax, we have to fudge | |
5618 ;; things with cd's. We actually send too many cd's, but it's dangerous | |
5619 ;; to try to remember the current minidisk, because if the connection | |
5620 ;; is closed and needs to be reopened, we will find ourselves back in | |
5621 ;; the default minidisk. This is fairly likely since CMS ftp servers | |
5622 ;; usually close the connection after 5 minutes of inactivity. | |
5623 | |
5624 ;; Have I got the filename character set right? | |
5625 | |
5626 (defun ange-ftp-fix-name-for-cms (name &optional reverse) | |
5627 (save-match-data | |
5628 (if reverse | |
5629 ;; Since we only convert output from a pwd in this direction, | |
5630 ;; we'll assume that it's a minidisk, and make it into a | |
5631 ;; directory file name. Note that the expand-dir-hashtable | |
5632 ;; stores directories without the trailing /. Is this | |
5633 ;; consistent? | |
5634 (concat "/" name) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5635 (if (string-match "\\`/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?\\'" |
28210 | 5636 name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5637 (let ((minidisk (match-string 1 name))) |
28210 | 5638 (if (match-beginning 2) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5639 (let ((file (match-string 2 name)) |
28210 | 5640 (cmd (concat "cd " minidisk)) |
5641 | |
5642 ;; Note that host and user are bound in the call | |
5643 ;; to ange-ftp-send-cmd | |
5644 (proc (ange-ftp-get-process ange-ftp-this-host | |
5645 ange-ftp-this-user))) | |
5646 | |
5647 ;; Must use ange-ftp-raw-send-cmd here to avoid | |
5648 ;; an infinite loop. | |
5649 (if (car (ange-ftp-raw-send-cmd proc cmd ange-ftp-this-msg)) | |
5650 file | |
5651 ;; failed... try ONCE more. | |
5652 (setq proc (ange-ftp-get-process ange-ftp-this-host | |
5653 ange-ftp-this-user)) | |
5654 (let ((result (ange-ftp-raw-send-cmd proc cmd | |
5655 ange-ftp-this-msg))) | |
5656 (if (car result) | |
5657 file | |
5658 ;; failed. give up. | |
5659 (ange-ftp-error ange-ftp-this-host ange-ftp-this-user | |
5660 (format "cd to minidisk %s failed: %s" | |
5661 minidisk (cdr result))))))) | |
5662 ;; return the minidisk | |
5663 minidisk)) | |
5664 (error "Invalid CMS filename"))))) | |
5665 | |
5666 (or (assq 'cms ange-ftp-fix-name-func-alist) | |
5667 (setq ange-ftp-fix-name-func-alist | |
5668 (cons '(cms . ange-ftp-fix-name-for-cms) | |
5669 ange-ftp-fix-name-func-alist))) | |
5670 | |
5671 (or (memq 'cms ange-ftp-dumb-host-types) | |
5672 (setq ange-ftp-dumb-host-types | |
5673 (cons 'cms ange-ftp-dumb-host-types))) | |
5674 | |
5675 ;; Convert name from UNIX-ish to CMS ready for a DIRectory listing. | |
5676 (defun ange-ftp-fix-dir-name-for-cms (dir-name) | |
5677 (cond | |
5678 ((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
|
5679 (error "Cannot get listing for fictitious \"/\" directory")) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5680 ((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
|
5681 (let* ((minidisk (match-string 1 dir-name)) |
28210 | 5682 ;; host and user are bound in the call to ange-ftp-send-cmd |
5683 (proc (ange-ftp-get-process ange-ftp-this-host ange-ftp-this-user)) | |
5684 (cmd (concat "cd " minidisk)) | |
5685 (file (if (match-beginning 2) | |
5686 ;; 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
|
5687 (match-string 2 dir-name) |
28210 | 5688 ;; use the wild-card |
5689 "*"))) | |
5690 (if (car (ange-ftp-raw-send-cmd proc cmd)) | |
5691 file | |
5692 ;; try again... | |
5693 (setq proc (ange-ftp-get-process ange-ftp-this-host | |
5694 ange-ftp-this-user)) | |
5695 (let ((result (ange-ftp-raw-send-cmd proc cmd))) | |
5696 (if (car result) | |
5697 file | |
5698 ;; give up | |
5699 (ange-ftp-error ange-ftp-this-host ange-ftp-this-user | |
5700 (format "cd to minidisk %s failed: %s" | |
5701 minidisk (cdr result)))))))) | |
5702 (t (error "Invalid CMS file name")))) | |
5703 | |
5704 (or (assq 'cms ange-ftp-fix-dir-name-func-alist) | |
5705 (setq ange-ftp-fix-dir-name-func-alist | |
5706 (cons '(cms . ange-ftp-fix-dir-name-for-cms) | |
5707 ange-ftp-fix-dir-name-func-alist))) | |
5708 | |
5709 (defvar ange-ftp-cms-host-regexp nil | |
5710 "Regular expression to match hosts running the CMS operating system.") | |
5711 | |
5712 ;; Return non-nil if HOST is running CMS. | |
5713 (defun ange-ftp-cms-host (host) | |
5714 (and ange-ftp-cms-host-regexp | |
5715 (save-match-data | |
5716 (string-match ange-ftp-cms-host-regexp host)))) | |
5717 | |
5718 (defun ange-ftp-add-cms-host (host) | |
5719 "Mark HOST as the name of a CMS host." | |
5720 (interactive | |
5721 (list (read-string "Host: " | |
5722 (let ((name (or (buffer-file-name) default-directory))) | |
5723 (and name (car (ange-ftp-ftp-name name))))))) | |
5724 (if (not (ange-ftp-cms-host host)) | |
5725 (setq ange-ftp-cms-host-regexp | |
5726 (concat "^" (regexp-quote host) "$" | |
5727 (and ange-ftp-cms-host-regexp "\\|") | |
5728 ange-ftp-cms-host-regexp) | |
5729 ange-ftp-host-cache nil))) | |
5730 | |
5731 (defun ange-ftp-parse-cms-listing () | |
5732 ;; Parse the current buffer which is assumed to be a CMS directory listing. | |
5733 ;; If we succeed in getting a listing, then we will assume that the minidisk | |
5734 ;; exists. file is bound by the call to ange-ftp-ls. This doesn't work | |
5735 ;; because ange-ftp doesn't know that the root hashtable has only part of | |
5736 ;; the info. It will assume that if a minidisk isn't in it, then it doesn't | |
5737 ;; exist. It would be nice if completion worked for minidisks, as we | |
5738 ;; discover them. | |
5739 ; (let* ((dir-file (directory-file-name file)) | |
5740 ; (root (file-name-directory dir-file)) | |
5741 ; (minidisk (ange-ftp-get-file-part dir-file)) | |
5742 ; (root-tbl (ange-ftp-get-hash-entry root ange-ftp-files-hashtable))) | |
5743 ; (if root-tbl | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5744 ; (puthash minidisk t root-tbl) |
28210 | 5745 ; (setq root-tbl (ange-ftp-make-hashtable)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5746 ; (puthash minidisk t root-tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5747 ; (puthash "." t root-tbl) |
28210 | 5748 ; (ange-ftp-set-files root root-tbl))) |
5749 ;; Now do the usual parsing | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5750 (let ((tbl (make-hash-table :test 'equal))) |
28210 | 5751 (goto-char (point-min)) |
5752 (save-match-data | |
5753 (while | |
5754 (re-search-forward | |
5755 "^\\([-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
|
5756 (puthash (concat (match-string 1) "." (match-string 2)) nil tbl) |
28210 | 5757 (forward-line 1)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5758 (puthash "." t tbl)) |
28210 | 5759 tbl)) |
5760 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5761 (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
|
5762 '(cms . ange-ftp-parse-cms-listing)) |
30459 | 5763 |
28210 | 5764 ;;;;; Tree dired support: |
5765 | |
5766 ;;(defconst ange-ftp-dired-cms-re-exe | |
5767 ;; "^. [-A-Z0-9$_]+ +EXEC " | |
5768 ;; "Regular expression to use to search for CMS executables.") | |
5769 | |
5770 ;;(or (assq 'cms ange-ftp-dired-re-exe-alist) | |
5771 ;; (setq ange-ftp-dired-re-exe-alist | |
5772 ;; (cons (cons 'cms ange-ftp-dired-cms-re-exe) | |
5773 ;; ange-ftp-dired-re-exe-alist))) | |
5774 | |
5775 | |
5776 ;;(defun ange-ftp-dired-cms-insert-headerline (dir) | |
5777 ;; ;; CMS has no total line, so we insert a blank line for | |
5778 ;; ;; aesthetics. | |
5779 ;; (insert "\n") | |
5780 ;; (forward-char -1) | |
5781 ;; (ange-ftp-real-dired-insert-headerline dir)) | |
5782 | |
5783 ;;(or (assq 'cms ange-ftp-dired-insert-headerline-alist) | |
5784 ;; (setq ange-ftp-dired-insert-headerline-alist | |
5785 ;; (cons '(cms . ange-ftp-dired-cms-insert-headerline) | |
5786 ;; ange-ftp-dired-insert-headerline-alist))) | |
5787 | |
5788 ;;(defun ange-ftp-dired-cms-move-to-filename (&optional raise-error eol) | |
5789 ;; "In dired, move to the first char of filename on this line." | |
5790 ;; ;; This is the CMS version. | |
5791 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5792 ;; (let (case-fold-search) | |
5793 ;; (beginning-of-line) | |
5794 ;; (if (re-search-forward " [-A-Z0-9$_]+ +[-A-Z0-9$_]+ +[VF] +[0-9]+ " eol t) | |
5795 ;; (goto-char (1+ (match-beginning 0))) | |
5796 ;; (if raise-error | |
5797 ;; (error "No file on this line") | |
5798 ;; nil)))) | |
5799 | |
5800 ;;(or (assq 'cms ange-ftp-dired-move-to-filename-alist) | |
5801 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5802 ;; (cons '(cms . ange-ftp-dired-cms-move-to-filename) | |
5803 ;; ange-ftp-dired-move-to-filename-alist))) | |
5804 | |
5805 ;;(defun ange-ftp-dired-cms-move-to-end-of-filename (&optional no-error eol) | |
5806 ;; ;; Assumes point is at beginning of filename. | |
5807 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5808 ;; ;; case-fold-search must be nil, at least for VMS. | |
5809 ;; ;; On failure, signals an error or returns nil. | |
5810 ;; ;; This is the CMS version. | |
5811 ;; (let ((opoint (point)) | |
5812 ;; case-fold-search hidden) | |
5813 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
5814 ;; (setq hidden (and selective-display | |
5815 ;; (save-excursion | |
5816 ;; (search-forward "\r" eol t)))) | |
5817 ;; (if hidden | |
5818 ;; (if no-error | |
5819 ;; nil | |
5820 ;; (error | |
5821 ;; (substitute-command-keys | |
5822 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide"))) | |
5823 ;; (skip-chars-forward "-A-Z0-9$_" eol) | |
5824 ;; (skip-chars-forward " " eol) | |
5825 ;; (skip-chars-forward "-A-Z0-9$_" eol) | |
5826 ;; (if (eq opoint (point)) | |
5827 ;; (if no-error | |
5828 ;; nil | |
5829 ;; (error "No file on this line")) | |
5830 ;; (point))))) | |
5831 | |
5832 ;;(or (assq 'cms ange-ftp-dired-move-to-end-of-filename-alist) | |
5833 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5834 ;; (cons '(cms . ange-ftp-dired-cms-move-to-end-of-filename) | |
5835 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5836 | |
5837 (defun ange-ftp-cms-make-compressed-filename (name &optional reverse) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5838 (if (string-match "-Z\\'" name) |
28210 | 5839 (list nil (substring name 0 -2)) |
5840 (list t (concat name "-Z")))) | |
5841 | |
5842 (or (assq 'cms ange-ftp-make-compressed-filename-alist) | |
5843 (setq ange-ftp-make-compressed-filename-alist | |
5844 (cons '(cms . ange-ftp-cms-make-compressed-filename) | |
5845 ange-ftp-make-compressed-filename-alist))) | |
5846 | |
5847 ;;(defun ange-ftp-dired-cms-get-filename (&optional localp no-error-if-not-filep) | |
5848 ;; (let ((name (ange-ftp-real-dired-get-filename localp no-error-if-not-filep))) | |
5849 ;; (and name | |
5850 ;; (if (string-match "^\\([^ ]+\\) +\\([^ ]+\\)$" name) | |
5851 ;; (concat (substring name 0 (match-end 1)) | |
5852 ;; "." | |
5853 ;; (substring name (match-beginning 2) (match-end 2))) | |
5854 ;; name)))) | |
5855 | |
5856 ;;(or (assq 'cms ange-ftp-dired-get-filename-alist) | |
5857 ;; (setq ange-ftp-dired-get-filename-alist | |
5858 ;; (cons '(cms . ange-ftp-dired-cms-get-filename) | |
5859 ;; ange-ftp-dired-get-filename-alist))) | |
5860 | |
5861 ;;;; ------------------------------------------------------------ | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5862 ;;;; BS2000 support |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5863 ;;;; ------------------------------------------------------------ |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5864 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5865 ;; 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
|
5866 ;; 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
|
5867 (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
|
5868 "[-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
|
5869 "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
|
5870 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5871 (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
|
5872 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5873 "^\\(" 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
|
5874 "\\(" 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
|
5875 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)?") |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5876 "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
|
5877 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5878 (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
|
5879 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5880 "/?\\(" 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
|
5881 "\\(\\$[A-Z0-9]*/\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5882 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)?") |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5883 "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
|
5884 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5885 (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
|
5886 "X" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5887 "*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
|
5888 :group 'ange-ftp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5889 :type 'string) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5890 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5891 ;; 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
|
5892 ;; BS2000 to UNIX-ish. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5893 (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
|
5894 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5895 (if reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5896 (if (string-match |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5897 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
|
5898 name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5899 (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
|
5900 (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
|
5901 (userid (if (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5902 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5903 (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5904 (1- (match-end 2))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5905 (filename (if (match-beginning 3) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5906 (substring name (match-beginning 3))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5907 (concat |
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 ;; 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
|
5910 ;; 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
|
5911 (and pubset (concat "_/" pubset "/")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5912 (and userid (concat userid "/")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5913 filename)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5914 (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
|
5915 ;; 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
|
5916 ;; 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
|
5917 (if (string-match (concat "^/_/") name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5918 (setq name (substring name 2))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5919 (if (string-match |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5920 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
|
5921 name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5922 (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
|
5923 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5924 (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5925 (1- (match-end 1))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5926 (userid (if (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5927 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5928 (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5929 (1- (match-end 2))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5930 (filename (if (match-beginning 3) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5931 (substring name (match-beginning 3))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5932 (if (and (boundp 'filename) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5933 (stringp filename) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5934 (string-match "[#@].+" filename)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5935 (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
|
5936 (substring filename 1)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5937 (upcase |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5938 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5939 pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5940 (and userid (concat userid ".")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5941 ;; 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
|
5942 (and filename |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5943 (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
|
5944 ;; 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
|
5945 name)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5946 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5947 (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
|
5948 (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
|
5949 (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
|
5950 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
|
5951 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5952 ;; 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
|
5953 ;; 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
|
5954 (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
|
5955 (if (string-equal dir-name "/") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5956 "*" ;; 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
|
5957 (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
|
5958 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5959 (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
|
5960 (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
|
5961 (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
|
5962 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
|
5963 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5964 (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
|
5965 (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
|
5966 (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
|
5967 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5968 (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
|
5969 (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
|
5970 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5971 ;; 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
|
5972 (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
|
5973 (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
|
5974 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5975 (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
|
5976 ;; 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
|
5977 (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
|
5978 (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
|
5979 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5980 (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
|
5981 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5982 (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
|
5983 "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
|
5984 (interactive |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5985 (list (read-string "Host: " |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5986 (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
|
5987 (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
|
5988 (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
|
5989 (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
|
5990 (concat "^" (regexp-quote host) "$" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5991 (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
|
5992 ange-ftp-bs2000-host-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5993 ange-ftp-host-cache nil))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5994 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5995 (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
|
5996 "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
|
5997 (interactive |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5998 (list (read-string "Host: " |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5999 (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
|
6000 (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
|
6001 (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
|
6002 (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
|
6003 (concat "^" (regexp-quote host) "$" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6004 (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
|
6005 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
|
6006 ange-ftp-host-cache nil)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6007 ;; 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
|
6008 (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
|
6009 host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6010 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6011 (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
|
6012 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6013 "\\(" 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
|
6014 "\\(" 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
|
6015 "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
|
6016 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6017 (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
|
6018 nil |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6019 "*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
|
6020 :group 'ange-ftp |
44953
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
6021 :type '(repeat string)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6022 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6023 ;; 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
|
6024 ;; 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
|
6025 ;; 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
|
6026 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6027 ;; 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
|
6028 (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
|
6029 (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
|
6030 (match-string 2))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6031 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6032 ;; 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
|
6033 ;; 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
|
6034 (defun ange-ftp-parse-bs2000-listing () |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6035 (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
|
6036 pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6037 file) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6038 ;; get current pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6039 (goto-char (point-min)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6040 (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
|
6041 (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
|
6042 ;; add files to hashtable |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6043 (goto-char (point-min)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6044 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6045 (while (setq file (ange-ftp-parse-bs2000-filename)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6046 (puthash file nil tbl))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6047 ;; add . and .. |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6048 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6049 (puthash ".." t tbl) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6050 ;; 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
|
6051 (if (not (member pubset ange-ftp-bs2000-additional-pubsets)) |
84913
db1179979d6b
(ange-ftp-call-chmod, ange-ftp-parse-bs2000-listing):
Juanma Barranquero <lekktu@gmail.com>
parents:
83791
diff
changeset
|
6052 (mapc (lambda (pubset) (puthash pubset t tbl)) |
db1179979d6b
(ange-ftp-call-chmod, ange-ftp-parse-bs2000-listing):
Juanma Barranquero <lekktu@gmail.com>
parents:
83791
diff
changeset
|
6053 ange-ftp-bs2000-additional-pubsets)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6054 tbl)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6055 |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6056 (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
|
6057 '(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
|
6058 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6059 (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
|
6060 "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
|
6061 `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
|
6062 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
|
6063 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
|
6064 (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
|
6065 (progn |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6066 ;; change to POSIX: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6067 ; (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
|
6068 (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
|
6069 ;; 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
|
6070 ;; `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
|
6071 ;; ange-ftp-get-process. |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6072 (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
|
6073 (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
|
6074 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
|
6075 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6076 ;; Not available yet: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6077 ;; 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
|
6078 ;; 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
|
6079 ;; 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
|
6080 ;; 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
|
6081 ;; 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
|
6082 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6083 ;;;; ------------------------------------------------------------ |
28210 | 6084 ;;;; Finally provide package. |
6085 ;;;; ------------------------------------------------------------ | |
6086 | |
6087 (provide 'ange-ftp) | |
6088 | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
6089 ;; arch-tag: 2987ef88-cb56-4ec1-87a9-79132572e316 |
28210 | 6090 ;;; ange-ftp.el ends here |