annotate lisp/w3/url-file.el @ 144:318232e2a3f0 r20-2b6

Import from CVS: tag r20-2b6
author cvs
date Mon, 13 Aug 2007 09:34:14 +0200
parents cca96a509cfe
children 5a88923fcbfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; url-file.el --- File retrieval code
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
3 ;; Created: 1997/05/09 04:39:15
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
4 ;; Version: 1.19
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1993-1996 by William M. Perry (wmperry@cs.indiana.edu)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 (require 'url-vars)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30 (require 'mule-sysdp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31 (require 'url-parse)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 (defun url-insert-possibly-compressed-file (fname &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34 ;; Insert a file into a buffer, checking for compressed versions.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35 (let ((compressed nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37 ;; F*** *U** **C* ***K!!!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 ;; We cannot just use insert-file-contents-literally here, because
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 ;; then we would lose big time with ange-ftp. *sigh*
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 (crypt-encoding-alist nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 (jka-compr-compression-info-list nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 (jam-zcat-filename-list nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 (file-coding-system-for-read mule-no-coding-system)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 (coding-system-for-read mule-no-coding-system))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45 (setq compressed
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (cond
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
47 ((file-exists-p fname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
48 (if (string-match "\\.\\(z\\|gz\\|Z\\)$" fname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
49 (case (intern (match-string 1 fname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
50 ((z gz)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
51 (setq url-current-mime-headers (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
52 (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
53 "content-transfer-encoding"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
54 "gzip")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
55 url-current-mime-headers)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
56 (Z
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
57 (setq url-current-mime-headers (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
58 (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
59 "content-transfer-encoding"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
60 "compress")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
61 url-current-mime-headers))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
62 nil))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 ((file-exists-p (concat fname ".Z"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
64 (setq fname (concat fname ".Z")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
65 url-current-mime-headers (cons (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
66 "content-transfer-encoding"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
67 "compress")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
68 url-current-mime-headers)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 ((file-exists-p (concat fname ".gz"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
70 (setq fname (concat fname ".gz")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
71 url-current-mime-headers (cons (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
72 "content-transfer-encoding"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
73 "gzip")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
74 url-current-mime-headers)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 ((file-exists-p (concat fname ".z"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
76 (setq fname (concat fname ".z")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
77 url-current-mime-headers (cons (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
78 "content-transfer-encoding"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
79 "gzip")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
80 url-current-mime-headers)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 (error "File not found %s" fname))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
83 (apply 'insert-file-contents fname args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
84 (set-buffer-modified-p nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
85
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
86 (defvar url-dired-minor-mode-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
87 (let ((map (make-sparse-keymap)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
88 (define-key map "\C-m" 'url-dired-find-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
89 (if url-running-xemacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
90 (define-key map [button2] 'url-dired-find-file-mouse)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
91 (define-key map [mouse-2] 'url-dired-find-file-mouse))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
92 map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
93 "Keymap used when browsing directories.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
94
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
95 (defvar url-dired-minor-mode nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
96 "Whether we are in url-dired-minor-mode")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
97
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
98 (make-variable-buffer-local 'url-dired-minor-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
99
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
100 (defun url-dired-find-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
101 "In dired, visit the file or directory named on this line, using Emacs-W3."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
102 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
103 (w3-open-local (dired-get-filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
104
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
105 (defun url-dired-find-file-mouse (event)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
106 "In dired, visit the file or directory name you click on, using Emacs-W3."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
107 (interactive "@e")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
108 (if (event-point event)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
109 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
110 (goto-char (event-point event))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
111 (url-dired-find-file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
112
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
113 (defun url-dired-minor-mode (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
114 "Minor mode for directory browsing with Emacs-W3."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
115 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
116 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
117 ((null arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
118 (setq url-dired-minor-mode (not url-dired-minor-mode)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
119 ((equal 0 arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
120 (setq url-dired-minor-mode nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
121 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
122 (setq url-dired-minor-mode t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
123
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
124 (add-minor-mode 'url-dired-minor-mode " URL" url-dired-minor-mode-map)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
126 (defun url-format-directory (dir)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
127 ;; Format the files in DIR into hypertext
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
128 (if (and url-directory-index-file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
129 (file-exists-p (expand-file-name url-directory-index-file dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
130 (file-readable-p (expand-file-name url-directory-index-file dir)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 (erase-buffer)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 102
diff changeset
134 (insert-file-contents
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
135 (expand-file-name url-directory-index-file dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
136 (kill-buffer (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
137 (find-file dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
138 (url-dired-minor-mode t)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 (defun url-host-is-local-p (host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141 "Return t iff HOST references our local machine."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 (let ((case-fold-search t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 (or
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 (null host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (string= "" host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 (equal (downcase host) (downcase (system-name)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 (and (string-match "^localhost$" host) t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 (and (not (string-match (regexp-quote ".") host))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 (equal (downcase host) (if (string-match (regexp-quote ".")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 (system-name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 (substring (system-name) 0
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 (system-name)))))))
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
154
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
155 (defun url-file-build-continuation (name)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
156 (list 'url-file-asynch-callback
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
157 name (current-buffer)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
158 url-current-callback-func url-current-callback-data))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
159
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
160 (defun url-file-asynch-callback (x y name buff func args &optional efs)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
161 (if (featurep 'efs)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
162 ;; EFS passes us an extra argument
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
163 (setq name buff
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
164 buff func
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
165 func args
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
166 args efs))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
167 (cond
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
168 ((not name) nil)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
169 ((not (file-exists-p name)) nil)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
170 (t
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
171 (if (not buff)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
172 (setq buff (generate-new-buffer " *url-asynch-file*")))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
173 (set-buffer buff)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
174 (insert-file-contents-literally name)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
175 (condition-case ()
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
176 (delete-file name)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
177 (error nil))))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
178 (if func
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
179 (apply func args)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
180 (url-sentinel (current-buffer) nil)))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
181
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 (defun url-file (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 ;; Find a file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 (user (url-user urlobj))
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
186 (pass (url-password urlobj))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 (site (url-host urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 (file (url-unhex-string (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 (dest (url-target urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 (filename (if (or user (not (url-host-is-local-p site)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 (concat "/" (or user "anonymous") "@" site ":" file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 file)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 (url-clear-tmp-buffer)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
195 (and user pass
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
196 (cond
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
197 ((featurep 'ange-ftp)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
198 (ange-ftp-set-passwd site user pass))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
199 ((or (featurep 'efs) (featurep 'efs-auto))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
200 (efs-set-passwd site user pass))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
201 (t
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
202 nil)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 ((file-directory-p filename)
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
205 (if (not (string-match "/$" filename))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
206 (setq filename (concat filename "/")))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
207 (if (not (string-match "/$" file))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
208 (setq file (concat file "/")))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
209 (url-set-filename urlobj file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 86
diff changeset
210 (url-format-directory filename))
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
211 (url-be-asynchronous
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 ((file-exists-p filename) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 ((file-exists-p (concat filename ".Z"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 (setq filename (concat filename ".Z")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 ((file-exists-p (concat filename ".gz"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (setq filename (concat filename ".gz")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 ((file-exists-p (concat filename ".z"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 (setq filename (concat filename ".z")))
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
220 (t nil))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
221 (let ((new (mm-generate-unique-filename)))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
222 (cond
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
223 ((url-host-is-local-p site)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
224 (insert-file-contents-literally filename)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
225 (if (featurep 'efs)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
226 (url-file-asynch-callback nil nil nil nil nil
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
227 url-current-callback-func
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
228 url-current-callback-data)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
229 (url-file-asynch-callback nil nil nil nil
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
230 url-current-callback-func
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
231 url-current-callback-data)))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
232 ((featurep 'ange-ftp)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
233 (ange-ftp-copy-file-internal filename (expand-file-name new) t
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
234 nil t
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
235 (url-file-build-continuation new)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
236 t))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
237 ((or (featurep 'efs) (featurep 'efs-auto))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 (efs-copy-file-internal filename (efs-ftp-path filename)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 new (efs-ftp-path new)
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
240 t nil 0
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
241 (url-file-build-continuation new)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
242 0 nil)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (let ((viewer (mm-mime-info
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 (mm-extension-to-mime (url-file-extension file))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 (errobj nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 (if (or url-source ; Need it in a buffer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 (and (symbolp viewer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (not (eq viewer 'w3-default-local-file)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 (stringp viewer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 (condition-case errobj
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 (url-insert-possibly-compressed-file filename t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 (error
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 (url-save-error errobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 (url-retrieve (concat "www://error/nofile/" file))))))))
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 98
diff changeset
256 (setq url-current-mime-type (mm-extension-to-mime
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 98
diff changeset
257 (url-file-extension file)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (fset 'url-ftp 'url-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 (provide 'url-file)