Mercurial > emacs
annotate lisp/arc-mode.el @ 19161:248ec4d8a5e6
(mail-mode): Fix previous change.
Treat a supercite prefix not followed by text
as a paragraph separator.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 05 Aug 1997 06:41:51 +0000 |
parents | e526918bbae8 |
children | 09d355f9877e |
rev | line source |
---|---|
11880 | 1 ;;; arc-mode.el --- simple editing of archives |
2 | |
14169 | 3 ;; Copyright (C) 1995 Free Software Foundation, Inc. |
11880 | 4 |
17977 | 5 ;; Author: Morten Welinder <terra@diku.dk> |
11880 | 6 ;; Keywords: archives msdog editing major-mode |
7 ;; Favourite-brand-of-beer: None, I hate beer. | |
8 | |
14169 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
11880 | 25 |
26 ;;; Commentary: | |
14169 | 27 |
11880 | 28 ;; NAMING: "arc" is short for "archive" and does not refer specifically |
29 ;; to files whose name end in ".arc" | |
30 ;; | |
31 ;; This code does not decode any files internally, although it does | |
32 ;; understand the directory level of the archives. For this reason, | |
33 ;; you should expect this code to need more fiddling than tar-mode.el | |
34 ;; (although it at present has fewer bugs :-) In particular, I have | |
35 ;; not tested this under Ms-Dog myself. | |
36 ;; ------------------------------------- | |
37 ;; INTERACTION: arc-mode.el should play together with | |
38 ;; | |
39 ;; * ange-ftp.el: Remote archives (i.e., ones that ange-ftp has brought | |
40 ;; to you) are handled by doing all updates on a local | |
41 ;; copy. When you make changes to a remote file the | |
42 ;; changes will first take effect when the archive buffer | |
43 ;; is saved. You will be warned about this. | |
44 ;; | |
45 ;; * dos-fns.el: (Part of Emacs 19). You get automatic ^M^J <--> ^J | |
46 ;; conversion. | |
47 ;; | |
48 ;; arc-mode.el does not work well with crypt++.el; for the archives as | |
49 ;; such this could be fixed (but wouldn't be useful) by declaring such | |
50 ;; archives to be "remote". For the members this is a general Emacs | |
51 ;; problem that 19.29's file formats may fix. | |
52 ;; ------------------------------------- | |
53 ;; ARCHIVE TYPES: Currently only the archives below are handled, but the | |
54 ;; structure for handling just about anything is in place. | |
55 ;; | |
56 ;; Arc Lzh Zip Zoo | |
57 ;; -------------------------------- | |
58 ;; View listing Intern Intern Intern Intern | |
59 ;; Extract member Y Y Y Y | |
60 ;; Save changed member Y Y Y Y | |
61 ;; Add new member N N N N | |
62 ;; Delete member Y Y Y Y | |
63 ;; Rename member Y Y N N | |
64 ;; Chmod - Y Y - | |
65 ;; Chown - Y - - | |
66 ;; Chgrp - Y - - | |
67 ;; | |
68 ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips | |
69 ;; on the first released version of this package. | |
70 ;; | |
71 ;; This code is partly based on tar-mode.el from Emacs. | |
72 ;; ------------------------------------- | |
73 ;; ARCHIVE STRUCTURES: | |
74 ;; (This is mostly for myself.) | |
75 ;; | |
76 ;; ARC A series of (header,file). No interactions among members. | |
77 ;; | |
78 ;; LZH A series of (header,file). Headers are checksummed. No | |
79 ;; interaction among members. | |
80 ;; | |
81 ;; ZIP A series of (lheader,fil) followed by a "central directory" | |
82 ;; which is a series of (cheader) followed by an end-of- | |
83 ;; central-dir record possibly followed by junk. The e-o-c-d | |
84 ;; links to c-d. cheaders link to lheaders which are basically | |
85 ;; cut-down versions of the cheaders. | |
86 ;; | |
87 ;; ZOO An archive header followed by a series of (header,file). | |
88 ;; Each member header points to the next. The archive is | |
89 ;; terminated by a bogus header with a zero next link. | |
90 ;; ------------------------------------- | |
91 ;; HOOKS: `foo' means one the the supported archive types. | |
92 ;; | |
93 ;; archive-mode-hook | |
94 ;; archive-foo-mode-hook | |
95 ;; archive-extract-hooks | |
96 | |
97 ;;; Code: | |
98 | |
99 ;; ------------------------------------------------------------------------- | |
100 ;; Section: Configuration. | |
101 | |
102 (defvar archive-dos-members t | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
103 "*If non-nil then recognize member files using ^M^J as line terminator.") |
11880 | 104 |
105 (defvar archive-tmpdir | |
106 (expand-file-name | |
107 (make-temp-name (if (eq system-type 'ms-dos) "ar" "archive.tmp")) | |
108 (or (getenv "TMPDIR") (getenv "TMP") "/tmp")) | |
109 "*Directory for temporary files made by arc-mode.el") | |
110 | |
12756
0a2d094db7d8
(archive-remote-regexp): Don't accept hostnames
Richard M. Stallman <rms@gnu.org>
parents:
12437
diff
changeset
|
111 (defvar archive-remote-regexp "^/[^/:]*[^/:.]:" |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
112 "*Regexp recognizing archive files names that are not local. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
113 A non-local file is one whose file name is not proper outside Emacs. |
13539
4b42b497a96d
(archive-remote-regexp): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13339
diff
changeset
|
114 A local copy of the archive will be used when updating.") |
11880 | 115 |
116 (defvar archive-extract-hooks nil | |
117 "*Hooks to run when an archive member has been extracted.") | |
118 ;; ------------------------------ | |
119 ;; Arc archive configuration | |
120 | |
121 ;; We always go via a local file since there seems to be no reliable way | |
122 ;; to extract to stdout without junk getting added. | |
123 (defvar archive-arc-extract | |
124 '("arc" "x") | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
125 "*Program and its options to run in order to extract an arc file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
126 Extraction should happen to the current directory. Archive and member |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
127 name will be added.") |
11880 | 128 |
129 (defvar archive-arc-expunge | |
130 '("arc" "d") | |
131 "*Program and its options to run in order to delete arc file members. | |
132 Archive and member names will be added.") | |
133 | |
134 (defvar archive-arc-write-file-member | |
135 '("arc" "u") | |
136 "*Program and its options to run in order to update an arc file member. | |
137 Archive and member name will be added.") | |
138 ;; ------------------------------ | |
139 ;; Lzh archive configuration | |
140 | |
141 (defvar archive-lzh-extract | |
142 '("lha" "pq") | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
143 "*Program and its options to run in order to extract an lzh file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
144 Extraction should happen to standard output. Archive and member name will |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
145 be added.") |
11880 | 146 |
147 (defvar archive-lzh-expunge | |
148 '("lha" "d") | |
149 "*Program and its options to run in order to delete lzh file members. | |
150 Archive and member names will be added.") | |
151 | |
152 (defvar archive-lzh-write-file-member | |
153 '("lha" "a") | |
154 "*Program and its options to run in order to update an lzh file member. | |
155 Archive and member name will be added.") | |
156 ;; ------------------------------ | |
157 ;; Zip archive configuration | |
158 | |
159 (defvar archive-zip-use-pkzip (memq system-type '(ms-dos windows-nt)) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
160 "*If non-nil then pkzip option are used instead of zip options. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
161 Only set to true for msdog systems!") |
11880 | 162 |
163 (defvar archive-zip-extract | |
164 (if archive-zip-use-pkzip '("pkunzip" "-e") '("unzip" "-qq" "-c")) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
165 "*Program and its options to run in order to extract a zip file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
166 Extraction should happen to standard output. Archive and member name will |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
167 be added. If `archive-zip-use-pkzip' is non-nil then this program is |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
168 expected to extract to a file junking the directory part of the name.") |
11880 | 169 |
13966
82eeef849f8b
(archive-summarize-files): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
13539
diff
changeset
|
170 ;; For several reasons the latter behaviour is not desirable in general. |
11880 | 171 ;; (1) It uses more disk space. (2) Error checking is worse or non- |
172 ;; existent. (3) It tends to do funny things with other systems' file | |
173 ;; names. | |
174 | |
175 (defvar archive-zip-expunge | |
176 (if archive-zip-use-pkzip '("pkzip" "-d") '("zip" "-d" "-q")) | |
177 "*Program and its options to run in order to delete zip file members. | |
178 Archive and member names will be added.") | |
179 | |
180 (defvar archive-zip-update | |
181 (if archive-zip-use-pkzip '("pkzip" "-u") '("zip" "-q")) | |
182 "*Program and its options to run in order to update a zip file member. | |
183 Options should ensure that specified directory will be put into the zip | |
184 file. Archive and member name will be added.") | |
185 | |
186 (defvar archive-zip-update-case | |
187 (if archive-zip-use-pkzip archive-zip-update '("zip" "-q" "-k")) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
188 "*Program and its options to run in order to update a case fiddled zip member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
189 Options should ensure that specified directory will be put into the zip file. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
190 Archive and member name will be added.") |
11880 | 191 |
192 (defvar archive-zip-case-fiddle t | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
193 "*If non-nil then zip file members are case fiddled. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
194 Case fiddling will only happen for members created by a system that |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
195 uses caseless file names.") |
11880 | 196 ;; ------------------------------ |
197 ;; Zoo archive configuration | |
198 | |
199 (defvar archive-zoo-extract | |
200 '("zoo" "xpq") | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
201 "*Program and its options to run in order to extract a zoo file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
202 Extraction should happen to standard output. Archive and member name will |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
203 be added.") |
11880 | 204 |
205 (defvar archive-zoo-expunge | |
206 '("zoo" "DqPP") | |
207 "*Program and its options to run in order to delete zoo file members. | |
208 Archive and member names will be added.") | |
209 | |
210 (defvar archive-zoo-write-file-member | |
211 '("zoo" "a") | |
212 "*Program and its options to run in order to update a zoo file member. | |
213 Archive and member name will be added.") | |
214 ;; ------------------------------------------------------------------------- | |
215 ;; Section: Variables | |
216 | |
217 (defvar archive-subtype nil "*Symbol describing archive type.") | |
218 (defvar archive-file-list-start nil "*Position of first contents line.") | |
219 (defvar archive-file-list-end nil "*Position just after last contents line.") | |
220 (defvar archive-proper-file-start nil "*Position of real archive's start.") | |
221 (defvar archive-read-only nil "*Non-nil if the archive is read-only on disk.") | |
222 (defvar archive-remote nil "*Non-nil if the archive is outside file system.") | |
223 (defvar archive-local-name nil "*Name of local copy of remote archive.") | |
224 (defvar archive-mode-map nil "*Local keymap for archive mode listings.") | |
225 (defvar archive-file-name-indent nil "*Column where file names start.") | |
226 | |
227 (defvar archive-alternate-display nil | |
228 "*Non-nil when alternate information is shown.") | |
229 (make-variable-buffer-local 'archive-alternate-display) | |
230 (put 'archive-alternate-display 'permanent-local t) | |
231 | |
232 (defvar archive-superior-buffer nil "*In archive members, points to archive.") | |
233 (put 'archive-superior-buffer 'permanent-local t) | |
234 | |
235 (defvar archive-subfile-mode nil "*Non-nil in archive member buffers.") | |
236 (make-variable-buffer-local 'archive-subfile-mode) | |
237 (put 'archive-subfile-mode 'permanent-local t) | |
238 | |
239 (defvar archive-subfile-dos nil | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
240 "Negation of `buffer-file-type', which see.") |
11880 | 241 (make-variable-buffer-local 'archive-subfile-dos) |
242 (put 'archive-subfile-dos 'permanent-local t) | |
243 | |
16291 | 244 (defvar archive-files nil |
245 "Vector of file descriptors. | |
246 Each descriptor is a vector of the form | |
247 [EXT-FILE-NAME INT-FILE-NAME CASE-FIDDLED MODE ...]") | |
11880 | 248 (make-variable-buffer-local 'archive-files) |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
249 |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
250 (defvar archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
251 (string-match "\\(Lucid\\|Xemacs\\)" emacs-version) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
252 "*Non-nil when running under under Lucid Emacs or Xemacs.") |
11880 | 253 ;; ------------------------------------------------------------------------- |
254 ;; Section: Support functions. | |
255 | |
256 (defsubst archive-name (suffix) | |
257 (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) | |
258 | |
259 (defun archive-l-e (str &optional len) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
260 "Convert little endian string/vector to integer. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
261 Alternatively, first argument may be a buffer position in the current buffer |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
262 in which case a second argument, length, should be supplied." |
11880 | 263 (if (stringp str) |
264 (setq len (length str)) | |
265 (setq str (buffer-substring str (+ str len)))) | |
266 (let ((result 0) | |
267 (i 0)) | |
268 (while (< i len) | |
269 (setq i (1+ i) | |
270 result (+ (ash result 8) (aref str (- len i))))) | |
271 result)) | |
272 | |
273 (defun archive-int-to-mode (mode) | |
274 "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------" | |
275 (let ((str (make-string 10 ?-))) | |
276 (or (zerop (logand 16384 mode)) (aset str 0 ?d)) | |
277 (or (zerop (logand 8192 mode)) (aset str 0 ?c)) ; completeness | |
278 (or (zerop (logand 256 mode)) (aset str 1 ?r)) | |
279 (or (zerop (logand 128 mode)) (aset str 2 ?w)) | |
280 (or (zerop (logand 64 mode)) (aset str 3 ?x)) | |
281 (or (zerop (logand 32 mode)) (aset str 4 ?r)) | |
282 (or (zerop (logand 16 mode)) (aset str 5 ?w)) | |
283 (or (zerop (logand 8 mode)) (aset str 6 ?x)) | |
284 (or (zerop (logand 4 mode)) (aset str 7 ?r)) | |
285 (or (zerop (logand 2 mode)) (aset str 8 ?w)) | |
286 (or (zerop (logand 1 mode)) (aset str 9 ?x)) | |
287 (or (zerop (logand 1024 mode)) (aset str 3 (if (zerop (logand 64 mode)) | |
288 ?S ?s))) | |
289 (or (zerop (logand 2048 mode)) (aset str 6 (if (zerop (logand 8 mode)) | |
290 ?S ?s))) | |
291 str)) | |
292 | |
293 (defun archive-calc-mode (oldmode newmode &optional error) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
294 "From the integer OLDMODE and the string NEWMODE calculate a new file mode. |
11880 | 295 NEWMODE may be an octal number including a leading zero in which case it |
296 will become the new mode.\n | |
297 NEWMODE may also be a relative specification like \"og-rwx\" in which case | |
298 OLDMODE will be modified accordingly just like chmod(2) would have done.\n | |
299 If optional third argument ERROR is non-nil an error will be signaled if | |
300 the mode is invalid. If ERROR is nil then nil will be returned." | |
301 (cond ((string-match "^0[0-7]*$" newmode) | |
302 (let ((result 0) | |
303 (len (length newmode)) | |
304 (i 1)) | |
305 (while (< i len) | |
306 (setq result (+ (lsh result 3) (aref newmode i) (- ?0)) | |
307 i (1+ i))) | |
308 (logior (logand oldmode 65024) result))) | |
309 ((string-match "^\\([agou]+\\)\\([---+=]\\)\\([rwxst]+\\)$" newmode) | |
310 (let ((who 0) | |
311 (result oldmode) | |
312 (op (aref newmode (match-beginning 2))) | |
313 (bits 0) | |
314 (i (match-beginning 3))) | |
315 (while (< i (match-end 3)) | |
316 (let ((rwx (aref newmode i))) | |
317 (setq bits (logior bits (cond ((= rwx ?r) 292) | |
318 ((= rwx ?w) 146) | |
319 ((= rwx ?x) 73) | |
320 ((= rwx ?s) 3072) | |
321 ((= rwx ?t) 512))) | |
322 i (1+ i)))) | |
323 (while (< who (match-end 1)) | |
324 (let* ((whoc (aref newmode who)) | |
325 (whomask (cond ((= whoc ?a) 4095) | |
326 ((= whoc ?u) 1472) | |
327 ((= whoc ?g) 2104) | |
328 ((= whoc ?o) 7)))) | |
329 (if (= op ?=) | |
330 (setq result (logand result (lognot whomask)))) | |
331 (if (= op ?-) | |
332 (setq result (logand result (lognot (logand whomask bits)))) | |
333 (setq result (logior result (logand whomask bits))))) | |
334 (setq who (1+ who))) | |
335 result)) | |
336 (t | |
337 (if error | |
338 (error "Invalid mode specification: %s" newmode))))) | |
339 | |
340 (defun archive-dosdate (date) | |
341 "Stringify dos packed DATE record." | |
342 (let ((year (+ 1980 (logand (ash date -9) 127))) | |
343 (month (logand (ash date -5) 15)) | |
344 (day (logand date 31))) | |
345 (if (or (> month 12) (< month 1)) | |
346 "" | |
347 (format "%2d-%s-%d" | |
348 day | |
349 (aref ["Jan" "Feb" "Mar" "Apr" "May" "Jun" | |
350 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"] (1- month)) | |
351 year)))) | |
352 | |
353 (defun archive-dostime (time) | |
354 "Stringify dos packed TIME record." | |
355 (let ((hour (logand (ash time -11) 31)) | |
356 (minute (logand (ash time -5) 53)) | |
357 (second (* 2 (logand time 31)))) ; 2 seconds resolution | |
358 (format "%02d:%02d:%02d" hour minute second))) | |
359 | |
360 ;;(defun archive-unixdate (low high) | |
361 ;; "Stringify unix (LOW HIGH) date." | |
362 ;; (let ((str (current-time-string (cons high low)))) | |
363 ;; (format "%s-%s-%s" | |
364 ;; (substring str 8 9) | |
365 ;; (substring str 4 7) | |
366 ;; (substring str 20 24)))) | |
367 | |
368 ;;(defun archive-unixtime (low high) | |
369 ;; "Stringify unix (LOW HIGH) time." | |
370 ;; (let ((str (current-time-string (cons high low)))) | |
371 ;; (substring str 11 19))) | |
372 | |
373 (defun archive-get-lineno () | |
374 (if (>= (point) archive-file-list-start) | |
375 (count-lines archive-file-list-start | |
376 (save-excursion (beginning-of-line) (point))) | |
377 0)) | |
378 | |
379 (defun archive-get-descr (&optional noerror) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
380 "Return the descriptor vector for file at point. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
381 Does not signal an error if optional second argument NOERROR is non-nil." |
11880 | 382 (let ((no (archive-get-lineno))) |
383 (if (and (>= (point) archive-file-list-start) | |
384 (< no (length archive-files))) | |
385 (let ((item (aref archive-files no))) | |
386 (if (vectorp item) | |
387 item | |
388 (if (not noerror) | |
389 (error "Entry is not a regular member of the archive")))) | |
390 (if (not noerror) | |
391 (error "Line does not describe a member of the archive"))))) | |
392 ;; ------------------------------------------------------------------------- | |
393 ;; Section: the mode definition | |
394 | |
12437
c3597b66e4bf
(archive-mode): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
12304
diff
changeset
|
395 ;;;###autoload |
11880 | 396 (defun archive-mode (&optional force) |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
397 "Major mode for viewing an archive file in a dired-like way. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
398 You can move around using the usual cursor motion commands. |
11880 | 399 Letters no longer insert themselves. |
400 Type `e' to pull a file out of the archive and into its own buffer; | |
401 or click mouse-2 on the file's line in the archive mode buffer. | |
402 | |
403 If you edit a sub-file of this archive (as with the `e' command) and | |
404 save it, the contents of that buffer will be saved back into the | |
405 archive. | |
406 | |
407 \\{archive-mode-map}" | |
408 ;; This is not interactive because you shouldn't be turning this | |
409 ;; mode on and off. You can corrupt things that way. | |
410 (if (zerop (buffer-size)) | |
411 ;; At present we cannot create archives from scratch | |
412 (funcall default-major-mode) | |
413 (if (and (not force) archive-files) nil | |
414 (let* ((type (archive-find-type)) | |
415 (typename (copy-sequence (symbol-name type)))) | |
416 (aset typename 0 (upcase (aref typename 0))) | |
417 (kill-all-local-variables) | |
418 (make-local-variable 'archive-subtype) | |
419 (setq archive-subtype type) | |
420 | |
421 ;; Buffer contains treated image of file before the file contents | |
422 (make-local-variable 'revert-buffer-function) | |
423 (setq revert-buffer-function 'archive-mode-revert) | |
424 (auto-save-mode 0) | |
425 (make-local-variable 'local-write-file-hooks) | |
426 (add-hook 'local-write-file-hooks 'archive-write-file) | |
427 | |
428 ;; Real file contents is binary | |
429 (make-local-variable 'require-final-newline) | |
430 (setq require-final-newline nil) | |
431 (make-local-variable 'enable-local-variables) | |
432 (setq enable-local-variables nil) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
433 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
434 (setq buffer-file-type t)) |
11880 | 435 |
436 (make-local-variable 'archive-read-only) | |
437 (setq archive-read-only (not (file-writable-p (buffer-file-name)))) | |
438 | |
439 ;; Should we use a local copy when accessing from outside Emacs? | |
440 (make-local-variable 'archive-local-name) | |
441 (make-local-variable 'archive-remote) | |
442 (setq archive-remote (string-match archive-remote-regexp | |
443 (buffer-file-name))) | |
444 | |
445 (setq major-mode 'archive-mode) | |
446 (setq mode-name (concat typename "-Archive")) | |
447 ;; Run archive-foo-mode-hook and archive-mode-hook | |
448 (run-hooks (archive-name "mode-hook") 'archive-mode-hook) | |
449 (use-local-map archive-mode-map)) | |
450 | |
451 (make-local-variable 'archive-proper-file-start) | |
452 (make-local-variable 'archive-file-list-start) | |
453 (make-local-variable 'archive-file-list-end) | |
454 (make-local-variable 'archive-file-name-indent) | |
455 (archive-summarize) | |
456 (setq buffer-read-only t)))) | |
457 | |
458 ;; Archive mode is suitable only for specially formatted data. | |
459 (put 'archive-mode 'mode-class 'special) | |
460 ;; ------------------------------------------------------------------------- | |
461 ;; Section: Key maps | |
462 | |
463 (if archive-mode-map nil | |
464 (setq archive-mode-map (make-keymap)) | |
465 (suppress-keymap archive-mode-map) | |
466 (define-key archive-mode-map " " 'archive-next-line) | |
467 (define-key archive-mode-map "a" 'archive-alternate-display) | |
468 ;;(define-key archive-mode-map "c" 'archive-copy) | |
469 (define-key archive-mode-map "d" 'archive-flag-deleted) | |
470 (define-key archive-mode-map "\C-d" 'archive-flag-deleted) | |
471 (define-key archive-mode-map "e" 'archive-extract) | |
472 (define-key archive-mode-map "f" 'archive-extract) | |
473 (define-key archive-mode-map "\C-m" 'archive-extract) | |
474 (define-key archive-mode-map "g" 'revert-buffer) | |
475 (define-key archive-mode-map "h" 'describe-mode) | |
476 (define-key archive-mode-map "m" 'archive-mark) | |
477 (define-key archive-mode-map "n" 'archive-next-line) | |
478 (define-key archive-mode-map "\C-n" 'archive-next-line) | |
479 (define-key archive-mode-map [down] 'archive-next-line) | |
480 (define-key archive-mode-map "o" 'archive-extract-other-window) | |
481 (define-key archive-mode-map "p" 'archive-previous-line) | |
482 (define-key archive-mode-map "\C-p" 'archive-previous-line) | |
483 (define-key archive-mode-map [up] 'archive-previous-line) | |
484 (define-key archive-mode-map "r" 'archive-rename-entry) | |
485 (define-key archive-mode-map "u" 'archive-unflag) | |
486 (define-key archive-mode-map "\M-\C-?" 'archive-unmark-all-files) | |
487 (define-key archive-mode-map "v" 'archive-view) | |
488 (define-key archive-mode-map "x" 'archive-expunge) | |
489 (define-key archive-mode-map "\177" 'archive-unflag-backwards) | |
490 (define-key archive-mode-map "E" 'archive-extract-other-window) | |
491 (define-key archive-mode-map "M" 'archive-chmod-entry) | |
492 (define-key archive-mode-map "G" 'archive-chgrp-entry) | |
493 (define-key archive-mode-map "O" 'archive-chown-entry) | |
494 | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
495 (if archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
496 (progn |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
497 ;; Not a nice "solution" but it'll have to do |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
498 (define-key archive-mode-map "\C-xu" 'archive-undo) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
499 (define-key archive-mode-map "\C-_" 'archive-undo)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
500 (substitute-key-definition 'undo 'archive-undo |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
501 archive-mode-map global-map)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
502 |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
503 (define-key archive-mode-map |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
504 (if archive-lemacs 'button2 [mouse-2]) 'archive-mouse-extract) |
11880 | 505 |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
506 (if archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
507 () ; out of luck |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
508 ;; Get rid of the Edit menu bar item to save space. |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
509 (define-key archive-mode-map [menu-bar edit] 'undefined) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
510 |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
511 (define-key archive-mode-map [menu-bar immediate] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
512 (cons "Immediate" (make-sparse-keymap "Immediate"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
513 (define-key archive-mode-map [menu-bar immediate alternate] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
514 '("Alternate Display" . archive-alternate-display)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
515 (put 'archive-alternate-display 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
516 '(boundp (archive-name "alternate-display"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
517 (define-key archive-mode-map [menu-bar immediate view] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
518 '("View This File" . archive-view)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
519 (define-key archive-mode-map [menu-bar immediate display] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
520 '("Display in Other Window" . archive-display-other-window)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
521 (define-key archive-mode-map [menu-bar immediate find-file-other-window] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
522 '("Find in Other Window" . archive-extract-other-window)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
523 (define-key archive-mode-map [menu-bar immediate find-file] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
524 '("Find This File" . archive-extract)) |
11880 | 525 |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
526 (define-key archive-mode-map [menu-bar mark] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
527 (cons "Mark" (make-sparse-keymap "Mark"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
528 (define-key archive-mode-map [menu-bar mark unmark-all] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
529 '("Unmark All" . archive-unmark-all-files)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
530 (define-key archive-mode-map [menu-bar mark deletion] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
531 '("Flag" . archive-flag-deleted)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
532 (define-key archive-mode-map [menu-bar mark unmark] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
533 '("Unflag" . archive-unflag)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
534 (define-key archive-mode-map [menu-bar mark mark] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
535 '("Mark" . archive-mark)) |
11880 | 536 |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
537 (define-key archive-mode-map [menu-bar operate] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
538 (cons "Operate" (make-sparse-keymap "Operate"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
539 (define-key archive-mode-map [menu-bar operate chown] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
540 '("Change Owner..." . archive-chown-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
541 (put 'archive-chown-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
542 '(fboundp (archive-name "chown-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
543 (define-key archive-mode-map [menu-bar operate chgrp] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
544 '("Change Group..." . archive-chgrp-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
545 (put 'archive-chgrp-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
546 '(fboundp (archive-name "chgrp-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
547 (define-key archive-mode-map [menu-bar operate chmod] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
548 '("Change Mode..." . archive-chmod-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
549 (put 'archive-chmod-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
550 '(fboundp (archive-name "chmod-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
551 (define-key archive-mode-map [menu-bar operate rename] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
552 '("Rename to..." . archive-rename-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
553 (put 'archive-rename-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
554 '(fboundp (archive-name "rename-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
555 ;;(define-key archive-mode-map [menu-bar operate copy] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
556 ;; '("Copy to..." . archive-copy)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
557 (define-key archive-mode-map [menu-bar operate expunge] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
558 '("Expunge Marked Files" . archive-expunge)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
559 )) |
11880 | 560 |
561 (let* ((item1 '(archive-subfile-mode " Archive")) | |
562 (item2 '(archive-subfile-dos " Dos")) | |
563 (items (if (memq system-type '(ms-dos windows-nt)) | |
564 (list item1) ; msdog has its own indicator | |
565 (list item1 item2)))) | |
566 (or (member item1 minor-mode-alist) | |
567 (setq minor-mode-alist (append items minor-mode-alist)))) | |
568 ;; ------------------------------------------------------------------------- | |
569 (defun archive-find-type () | |
570 (widen) | |
571 (goto-char (point-min)) | |
572 ;; The funny [] here make it unlikely that the .elc file will be treated | |
573 ;; as an archive by other software. | |
574 (let (case-fold-search) | |
575 (cond ((looking-at "[P]K\003\004") 'zip) | |
576 ((looking-at "..-l[hz][0-9]-") 'lzh) | |
577 ((looking-at "....................[\334]\247\304\375") 'zoo) | |
578 ((and (looking-at "\C-z") ; signature too simple, IMHO | |
579 (string-match "\\.[aA][rR][cC]$" | |
580 (or buffer-file-name (buffer-name)))) | |
581 'arc) | |
582 (t (error "Buffer format not recognized."))))) | |
583 ;; ------------------------------------------------------------------------- | |
584 (defun archive-summarize () | |
585 "Parse the contents of the archive file in the current buffer. | |
586 Place a dired-like listing on the front; | |
587 then narrow to it, so that only that listing | |
588 is visible (and the real data of the buffer is hidden)." | |
589 (widen) | |
590 (let (buffer-read-only) | |
591 (message "Parsing archive file...") | |
592 (buffer-disable-undo (current-buffer)) | |
593 (setq archive-files (funcall (archive-name "summarize"))) | |
594 (message "Parsing archive file...done.") | |
595 (setq archive-proper-file-start (point-marker)) | |
596 (narrow-to-region (point-min) (point)) | |
597 (set-buffer-modified-p nil) | |
598 (buffer-enable-undo)) | |
599 (goto-char archive-file-list-start) | |
600 (archive-next-line 0)) | |
601 | |
602 (defun archive-resummarize () | |
603 "Recreate the contents listing of an archive." | |
604 (let ((modified (buffer-modified-p)) | |
605 (no (archive-get-lineno)) | |
606 buffer-read-only) | |
607 (widen) | |
608 (delete-region (point-min) archive-proper-file-start) | |
609 (archive-summarize) | |
610 (set-buffer-modified-p modified) | |
611 (goto-char archive-file-list-start) | |
612 (archive-next-line no))) | |
613 | |
614 (defun archive-summarize-files (files) | |
16291 | 615 "Insert a description of a list of files annotated with proper mouse face." |
11880 | 616 (setq archive-file-list-start (point-marker)) |
617 (setq archive-file-name-indent (if files (aref (car files) 1) 0)) | |
618 ;; We don't want to do an insert for each element since that takes too | |
619 ;; long when the archive -- which has to be moved in memory -- is large. | |
620 (insert | |
621 (apply | |
622 (function concat) | |
623 (mapcar | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
624 (function |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
625 (lambda (fil) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
626 ;; Using `concat' here copies the text also, so we can add |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
627 ;; properties without problems. |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
628 (let ((text (concat (aref fil 0) "\n"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
629 (if archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
630 () ; out of luck |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
631 (put-text-property (aref fil 1) (aref fil 2) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
632 'mouse-face 'highlight |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
633 text)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
634 text))) |
11880 | 635 files))) |
636 (setq archive-file-list-end (point-marker))) | |
637 | |
638 (defun archive-alternate-display () | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
639 "Toggle alternative display. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
640 To avoid very long lines some archive mode don't show all information. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
641 This function changes the set of information shown for each files." |
11880 | 642 (interactive) |
643 (setq archive-alternate-display (not archive-alternate-display)) | |
644 (archive-resummarize)) | |
645 ;; ------------------------------------------------------------------------- | |
646 ;; Section: Local archive copy handling | |
647 | |
648 (defun archive-maybe-copy (archive) | |
649 (if archive-remote | |
650 (let ((start (point-max))) | |
651 (setq archive-local-name (expand-file-name | |
652 (file-name-nondirectory archive) | |
653 archive-tmpdir)) | |
654 (make-directory archive-tmpdir t) | |
655 (save-restriction | |
656 (widen) | |
657 (write-region start (point-max) archive-local-name nil 'nomessage)) | |
658 archive-local-name) | |
659 (if (buffer-modified-p) (save-buffer)) | |
660 archive)) | |
661 | |
662 (defun archive-maybe-update (unchanged) | |
663 (if archive-remote | |
664 (let ((name archive-local-name) | |
665 (modified (buffer-modified-p)) | |
666 buffer-read-only) | |
667 (if unchanged nil | |
668 (erase-buffer) | |
669 (insert-file-contents name) | |
670 (archive-mode t)) | |
671 (archive-delete-local name) | |
672 (if (not unchanged) | |
673 (message "Archive file must be saved for changes to take effect")) | |
674 (set-buffer-modified-p (or modified (not unchanged)))))) | |
675 | |
676 (defun archive-delete-local (name) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
677 "Delete file NAME and its parents up to and including `archive-tmpdir'." |
11880 | 678 (let ((again t) |
679 (top (directory-file-name (file-name-as-directory archive-tmpdir)))) | |
680 (condition-case nil | |
681 (delete-file name) | |
682 (error nil)) | |
683 (while again | |
684 (setq name (directory-file-name (file-name-directory name))) | |
685 (condition-case nil | |
686 (delete-directory name) | |
687 (error nil)) | |
688 (if (string= name top) (setq again nil))))) | |
689 ;; ------------------------------------------------------------------------- | |
690 ;; Section: Member extraction | |
691 | |
692 (defun archive-mouse-extract (event) | |
693 "Extract a file whose name you click on." | |
694 (interactive "e") | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
695 (mouse-set-point event) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
696 (switch-to-buffer |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
697 (save-excursion |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
698 (archive-extract) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
699 (current-buffer)))) |
11880 | 700 |
701 (defun archive-extract (&optional other-window-p) | |
702 "In archive mode, extract this entry of the archive into its own buffer." | |
703 (interactive) | |
704 (let* ((view-p (eq other-window-p 'view)) | |
705 (descr (archive-get-descr)) | |
706 (ename (aref descr 0)) | |
707 (iname (aref descr 1)) | |
708 (archive-buffer (current-buffer)) | |
709 (arcdir default-directory) | |
710 (archive (buffer-file-name)) | |
711 (arcname (file-name-nondirectory archive)) | |
712 (bufname (concat (file-name-nondirectory iname) " (" arcname ")")) | |
713 (extractor (archive-name "extract")) | |
714 (read-only-p (or archive-read-only view-p)) | |
715 (buffer (get-buffer bufname)) | |
716 (just-created nil)) | |
717 (if buffer | |
718 nil | |
719 (setq archive (archive-maybe-copy archive)) | |
720 (setq buffer (get-buffer-create bufname)) | |
721 (setq just-created t) | |
722 (save-excursion | |
723 (set-buffer buffer) | |
724 (setq buffer-file-name | |
725 (expand-file-name (concat arcname ":" iname))) | |
726 (setq buffer-file-truename | |
727 (abbreviate-file-name buffer-file-name)) | |
728 ;; Set the default-directory to the dir of the superior buffer. | |
729 (setq default-directory arcdir) | |
730 (make-local-variable 'archive-superior-buffer) | |
731 (setq archive-superior-buffer archive-buffer) | |
732 (make-local-variable 'local-write-file-hooks) | |
733 (add-hook 'local-write-file-hooks 'archive-write-file-member) | |
734 (setq archive-subfile-mode descr) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
735 (setq archive-subfile-dos nil) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
736 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
737 (setq buffer-file-type t)) |
11880 | 738 (if (fboundp extractor) |
739 (funcall extractor archive ename) | |
740 (archive-*-extract archive ename (symbol-value extractor))) | |
741 (if archive-dos-members (archive-check-dos)) | |
742 (goto-char (point-min)) | |
743 (rename-buffer bufname) | |
744 (setq buffer-read-only read-only-p) | |
745 (setq buffer-undo-list nil) | |
746 (set-buffer-modified-p nil) | |
747 (setq buffer-saved-size (buffer-size)) | |
748 (normal-mode) | |
749 ;; Just in case an archive occurs inside another archive. | |
750 (if (eq major-mode 'archive-mode) | |
751 (setq archive-remote t)) | |
752 (run-hooks 'archive-extract-hooks)) | |
753 (archive-maybe-update t)) | |
754 (if view-p | |
18286
e526918bbae8
(archive-extract): Use second argument of
Richard M. Stallman <rms@gnu.org>
parents:
17977
diff
changeset
|
755 (view-buffer buffer (and just-created 'kill-buffer)) |
11880 | 756 (if (eq other-window-p 'display) |
757 (display-buffer buffer) | |
758 (if other-window-p | |
759 (switch-to-buffer-other-window buffer) | |
760 (switch-to-buffer buffer)))))) | |
761 | |
762 (defun archive-*-extract (archive name command) | |
763 (let* ((default-directory (file-name-as-directory archive-tmpdir)) | |
764 (tmpfile (expand-file-name (file-name-nondirectory name) | |
765 default-directory))) | |
766 (make-directory (directory-file-name default-directory) t) | |
767 (apply 'call-process | |
768 (car command) | |
769 nil | |
770 nil | |
771 nil | |
772 (append (cdr command) (list archive name))) | |
773 (insert-file-contents tmpfile) | |
774 (archive-delete-local tmpfile))) | |
775 | |
776 (defun archive-extract-by-stdout (archive name command) | |
777 (let ((binary-process-output t)) ; for Ms-Dos | |
778 (apply 'call-process | |
779 (car command) | |
780 nil | |
781 t | |
782 nil | |
783 (append (cdr command) (list archive name))))) | |
784 | |
785 (defun archive-extract-other-window () | |
786 "In archive mode, find this member in another window." | |
787 (interactive) | |
788 (archive-extract t)) | |
789 | |
790 (defun archive-display-other-window () | |
791 "In archive mode, display this member in another window." | |
792 (interactive) | |
793 (archive-extract 'display)) | |
794 | |
795 (defun archive-view () | |
796 "In archive mode, view the member on this line." | |
797 (interactive) | |
798 (archive-extract 'view)) | |
799 | |
800 (defun archive-add-new-member (arcbuf name) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
801 "Add current buffer to the archive in ARCBUF naming it NAME." |
11880 | 802 (interactive |
803 (list (get-buffer | |
804 (read-buffer "Buffer containing archive: " | |
805 ;; Find first archive buffer and suggest that | |
806 (let ((bufs (buffer-list))) | |
807 (while (and bufs (not (eq (save-excursion | |
808 (set-buffer (car bufs)) | |
809 major-mode) | |
810 'archive-mode))) | |
811 (setq bufs (cdr bufs))) | |
812 (if bufs | |
813 (car bufs) | |
814 (error "There are no archive buffers"))) | |
815 t)) | |
816 (read-string "File name in archive: " | |
817 (if buffer-file-name | |
818 (file-name-nondirectory buffer-file-name) | |
819 "")))) | |
820 (save-excursion | |
821 (set-buffer arcbuf) | |
822 (or (eq major-mode 'archive-mode) | |
823 (error "Buffer is not an archive buffer")) | |
824 (if archive-read-only | |
825 (error "Archive is read-only"))) | |
826 (if (eq arcbuf (current-buffer)) | |
827 (error "An archive buffer cannot be added to itself")) | |
828 (if (string= name "") | |
829 (error "Archive members may not be given empty names")) | |
830 (let ((func (save-excursion (set-buffer arcbuf) | |
831 (archive-name "add-new-member"))) | |
832 (membuf (current-buffer))) | |
833 (if (fboundp func) | |
834 (save-excursion | |
835 (set-buffer arcbuf) | |
836 (funcall func buffer-file-name membuf name)) | |
837 (error "Adding a new member is not supported for this archive type")))) | |
838 ;; ------------------------------------------------------------------------- | |
839 ;; Section: IO stuff | |
840 | |
841 (defun archive-check-dos (&optional force) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
842 "*Possibly handle a buffer with ^M^J terminated lines." |
11880 | 843 (save-restriction |
844 (widen) | |
845 (save-excursion | |
846 (goto-char (point-min)) | |
847 (setq archive-subfile-dos | |
848 (or force (not (search-forward-regexp "[^\r]\n" nil t)))) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
849 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
850 (setq buffer-file-type (not archive-subfile-dos))) |
11880 | 851 (if archive-subfile-dos |
852 (let ((modified (buffer-modified-p))) | |
853 (buffer-disable-undo (current-buffer)) | |
854 (goto-char (point-min)) | |
855 (while (search-forward "\r\n" nil t) | |
856 (replace-match "\n")) | |
857 (buffer-enable-undo) | |
858 (set-buffer-modified-p modified)))))) | |
859 | |
860 (defun archive-write-file-member () | |
861 (if archive-subfile-dos | |
862 (save-restriction | |
863 (widen) | |
864 (save-excursion | |
865 (goto-char (point-min)) | |
866 ;; We don't want our ^M^J <--> ^J changes to show in the undo list | |
867 (let ((undo-list buffer-undo-list)) | |
868 (unwind-protect | |
869 (progn | |
870 (setq buffer-undo-list t) | |
871 (while (search-forward "\n" nil t) | |
872 (replace-match "\r\n")) | |
873 (setq archive-subfile-dos nil) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
874 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
875 (setq buffer-file-type t)) |
11880 | 876 ;; OK, we're now have explicit ^M^Js -- save and re-unixfy |
877 (archive-write-file-member)) | |
878 (progn | |
879 (archive-check-dos t) | |
880 (setq buffer-undo-list undo-list)))) | |
881 t)) | |
882 (save-excursion | |
883 (save-restriction | |
884 (message "Updating archive...") | |
885 (widen) | |
886 (let ((writer (save-excursion (set-buffer archive-superior-buffer) | |
887 (archive-name "write-file-member"))) | |
888 (archive (save-excursion (set-buffer archive-superior-buffer) | |
889 (buffer-file-name)))) | |
890 (if (fboundp writer) | |
891 (funcall writer archive archive-subfile-mode) | |
892 (archive-*-write-file-member archive | |
893 archive-subfile-mode | |
894 (symbol-value writer)))) | |
895 (set-buffer-modified-p nil) | |
896 (message "Updating archive...done") | |
897 (set-buffer archive-superior-buffer) | |
898 (revert-buffer) | |
899 t)))) | |
900 | |
901 (defun archive-*-write-file-member (archive descr command) | |
902 (let* ((ename (aref descr 0)) | |
903 (tmpfile (expand-file-name ename archive-tmpdir)) | |
904 (top (directory-file-name (file-name-as-directory archive-tmpdir))) | |
905 (default-directory (file-name-as-directory top))) | |
906 (unwind-protect | |
907 (progn | |
908 (make-directory (file-name-directory tmpfile) t) | |
909 (write-region (point-min) (point-max) tmpfile nil 'nomessage) | |
910 (if (aref descr 3) | |
911 ;; Set the file modes, but make sure we can read it. | |
912 (set-file-modes tmpfile (logior ?\400 (aref descr 3)))) | |
913 (let ((exitcode (apply 'call-process | |
914 (car command) | |
915 nil | |
916 nil | |
917 nil | |
918 (append (cdr command) (list archive ename))))) | |
919 (if (equal exitcode 0) | |
920 nil | |
921 (error "Updating was unsuccessful (%S)" exitcode)))) | |
922 (archive-delete-local tmpfile)))) | |
923 | |
924 (defun archive-write-file () | |
925 (save-excursion | |
926 (write-region archive-proper-file-start (point-max) buffer-file-name nil t) | |
927 (set-buffer-modified-p nil) | |
928 t)) | |
929 ;; ------------------------------------------------------------------------- | |
930 ;; Section: Marking and unmarking. | |
931 | |
932 (defun archive-flag-deleted (p &optional type) | |
933 "In archive mode, mark this member to be deleted from the archive. | |
934 With a prefix argument, mark that many files." | |
935 (interactive "p") | |
936 (or type (setq type ?D)) | |
937 (beginning-of-line) | |
938 (let ((sign (if (>= p 0) +1 -1)) | |
939 (modified (buffer-modified-p)) | |
940 buffer-read-only) | |
941 (while (not (zerop p)) | |
942 (if (archive-get-descr t) | |
943 (progn | |
944 (delete-char 1) | |
945 (insert type))) | |
946 (forward-line sign) | |
947 (setq p (- p sign))) | |
948 (set-buffer-modified-p modified)) | |
949 (archive-next-line 0)) | |
950 | |
951 (defun archive-unflag (p) | |
952 "In archive mode, un-mark this member if it is marked to be deleted. | |
953 With a prefix argument, un-mark that many files forward." | |
954 (interactive "p") | |
955 (archive-flag-deleted p ? )) | |
956 | |
957 (defun archive-unflag-backwards (p) | |
958 "In archive mode, un-mark this member if it is marked to be deleted. | |
959 With a prefix argument, un-mark that many members backward." | |
960 (interactive "p") | |
961 (archive-flag-deleted (- p) ? )) | |
962 | |
963 (defun archive-unmark-all-files () | |
964 "Remove all marks." | |
965 (interactive) | |
966 (let ((modified (buffer-modified-p)) | |
967 buffer-read-only) | |
968 (save-excursion | |
969 (goto-char archive-file-list-start) | |
970 (while (< (point) archive-file-list-end) | |
971 (or (= (following-char) ? ) | |
972 (progn (delete-char 1) (insert ? ))) | |
973 (forward-line 1))) | |
974 (set-buffer-modified-p modified))) | |
975 | |
976 (defun archive-mark (p) | |
977 "In archive mode, mark this member for group operations. | |
978 With a prefix argument, mark that many members. | |
979 Use \\[archive-unmark-all-files] to remove all marks." | |
980 (interactive "p") | |
981 (archive-flag-deleted p ?*)) | |
982 | |
983 (defun archive-get-marked (mark &optional default) | |
984 (let (files) | |
985 (save-excursion | |
986 (goto-char archive-file-list-start) | |
987 (while (< (point) archive-file-list-end) | |
988 (if (= (following-char) mark) | |
989 (setq files (cons (archive-get-descr) files))) | |
990 (forward-line 1))) | |
991 (or (nreverse files) | |
992 (and default | |
993 (list (archive-get-descr)))))) | |
994 ;; ------------------------------------------------------------------------- | |
995 ;; Section: Operate | |
996 | |
997 (defun archive-next-line (p) | |
998 (interactive "p") | |
999 (forward-line p) | |
1000 (or (eobp) | |
1001 (forward-char archive-file-name-indent))) | |
1002 | |
1003 (defun archive-previous-line (p) | |
1004 (interactive "p") | |
1005 (archive-next-line (- p))) | |
1006 | |
1007 (defun archive-chmod-entry (new-mode) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
1008 "Change the protection bits associated with all marked or this member. |
11880 | 1009 The new protection bits can either be specified as an octal number or |
1010 as a relative change like \"g+rw\" as for chmod(2)" | |
1011 (interactive "sNew mode (octal or relative): ") | |
1012 (if archive-read-only (error "Archive is read-only")) | |
1013 (let ((func (archive-name "chmod-entry"))) | |
1014 (if (fboundp func) | |
1015 (progn | |
1016 (funcall func new-mode (archive-get-marked ?* t)) | |
1017 (archive-resummarize)) | |
1018 (error "Setting mode bits is not supported for this archive type")))) | |
1019 | |
1020 (defun archive-chown-entry (new-uid) | |
1021 "Change the owner of all marked or this member." | |
1022 (interactive "nNew uid: ") | |
1023 (if archive-read-only (error "Archive is read-only")) | |
1024 (let ((func (archive-name "chown-entry"))) | |
1025 (if (fboundp func) | |
1026 (progn | |
1027 (funcall func new-uid (archive-get-marked ?* t)) | |
1028 (archive-resummarize)) | |
1029 (error "Setting owner is not supported for this archive type")))) | |
1030 | |
1031 (defun archive-chgrp-entry (new-gid) | |
1032 "Change the group of all marked or this member." | |
1033 (interactive "nNew gid: ") | |
1034 (if archive-read-only (error "Archive is read-only")) | |
1035 (let ((func (archive-name "chgrp-entry"))) | |
1036 (if (fboundp func) | |
1037 (progn | |
1038 (funcall func new-gid (archive-get-marked ?* t)) | |
1039 (archive-resummarize)) | |
1040 (error "Setting group is not supported for this archive type")))) | |
1041 | |
1042 (defun archive-expunge () | |
1043 "Do the flagged deletions." | |
1044 (interactive) | |
1045 (let (files) | |
1046 (save-excursion | |
1047 (goto-char archive-file-list-start) | |
1048 (while (< (point) archive-file-list-end) | |
1049 (if (= (following-char) ?D) | |
1050 (setq files (cons (aref (archive-get-descr) 0) files))) | |
1051 (forward-line 1))) | |
1052 (setq files (nreverse files)) | |
1053 (and files | |
1054 (or (not archive-read-only) | |
1055 (error "Archive is read-only")) | |
1056 (or (yes-or-no-p (format "Really delete %d member%s? " | |
1057 (length files) | |
1058 (if (null (cdr files)) "" "s"))) | |
1059 (error "Operation aborted")) | |
1060 (let ((archive (archive-maybe-copy (buffer-file-name))) | |
1061 (expunger (archive-name "expunge"))) | |
1062 (if (fboundp expunger) | |
1063 (funcall expunger archive files) | |
1064 (archive-*-expunge archive files (symbol-value expunger))) | |
1065 (archive-maybe-update nil) | |
1066 (if archive-remote | |
1067 (archive-resummarize) | |
1068 (revert-buffer)))))) | |
1069 | |
1070 (defun archive-*-expunge (archive files command) | |
1071 (apply 'call-process | |
1072 (car command) | |
1073 nil | |
1074 nil | |
1075 nil | |
1076 (append (cdr command) (cons archive files)))) | |
1077 | |
1078 (defun archive-rename-entry (newname) | |
1079 "Change the name associated with this entry in the tar file." | |
1080 (interactive "sNew name: ") | |
1081 (if archive-read-only (error "Archive is read-only")) | |
1082 (if (string= newname "") | |
1083 (error "Archive members may not be given empty names")) | |
1084 (let ((func (archive-name "rename-entry")) | |
1085 (descr (archive-get-descr))) | |
1086 (if (fboundp func) | |
1087 (progn | |
1088 (funcall func (buffer-file-name) newname descr) | |
1089 (archive-resummarize)) | |
1090 (error "Renaming is not supported for this archive type")))) | |
1091 | |
1092 ;; Revert the buffer and recompute the dired-like listing. | |
1093 (defun archive-mode-revert (&optional no-autosave no-confirm) | |
1094 (let ((no (archive-get-lineno))) | |
1095 (setq archive-files nil) | |
1096 (let ((revert-buffer-function nil)) | |
1097 (revert-buffer t t)) | |
1098 (archive-mode) | |
1099 (goto-char archive-file-list-start) | |
1100 (archive-next-line no))) | |
1101 | |
1102 (defun archive-undo () | |
1103 "Undo in an archive buffer. | |
1104 This doesn't recover lost files, it just undoes changes in the buffer itself." | |
1105 (interactive) | |
1106 (let (buffer-read-only) | |
1107 (undo))) | |
1108 ;; ------------------------------------------------------------------------- | |
1109 ;; Section: Arc Archives | |
1110 | |
1111 (defun archive-arc-summarize () | |
1112 (let ((p 1) | |
1113 (totalsize 0) | |
1114 (maxlen 8) | |
1115 files | |
1116 visual) | |
1117 (while (and (< (+ p 29) (point-max)) | |
1118 (= (char-after p) ?\C-z) | |
1119 (> (char-after (1+ p)) 0)) | |
1120 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13))) | |
1121 (fnlen (or (string-match "\0" namefld) 13)) | |
1122 (efnname (substring namefld 0 fnlen)) | |
1123 (csize (archive-l-e (+ p 15) 4)) | |
1124 (moddate (archive-l-e (+ p 19) 2)) | |
1125 (modtime (archive-l-e (+ p 21) 2)) | |
1126 (ucsize (archive-l-e (+ p 25) 4)) | |
1127 (fiddle (string= efnname (upcase efnname))) | |
1128 (ifnname (if fiddle (downcase efnname) efnname)) | |
1129 (text (format " %8d %-11s %-8s %s" | |
1130 ucsize | |
1131 (archive-dosdate moddate) | |
1132 (archive-dostime modtime) | |
1133 ifnname))) | |
1134 (setq maxlen (max maxlen fnlen) | |
1135 totalsize (+ totalsize ucsize) | |
1136 visual (cons (vector text | |
1137 (- (length text) (length ifnname)) | |
1138 (length text)) | |
1139 visual) | |
1140 files (cons (vector efnname ifnname fiddle nil (1- p)) | |
1141 files) | |
1142 p (+ p 29 csize)))) | |
1143 (goto-char (point-min)) | |
1144 (let ((dash (concat "- -------- ----------- -------- " | |
1145 (make-string maxlen ?-) | |
1146 "\n"))) | |
1147 (insert "M Length Date Time File\n" | |
1148 dash) | |
1149 (archive-summarize-files (nreverse visual)) | |
1150 (insert dash | |
1151 (format " %8d %d file%s" | |
1152 totalsize | |
1153 (length files) | |
1154 (if (= 1 (length files)) "" "s")) | |
1155 "\n")) | |
1156 (apply 'vector (nreverse files)))) | |
1157 | |
1158 (defun archive-arc-rename-entry (archive newname descr) | |
1159 (if (string-match "[:\\\\/]" newname) | |
1160 (error "File names in arc files may not contain a path")) | |
1161 (if (> (length newname) 12) | |
1162 (error "File names in arc files are limited to 12 characters")) | |
1163 (let ((name (concat newname (substring "\0\0\0\0\0\0\0\0\0\0\0\0\0" | |
1164 (length newname)))) | |
1165 buffer-read-only) | |
1166 (save-restriction | |
1167 (save-excursion | |
1168 (widen) | |
1169 (goto-char (+ archive-proper-file-start (aref descr 4) 2)) | |
1170 (delete-char 13) | |
1171 (insert name))))) | |
1172 ;; ------------------------------------------------------------------------- | |
1173 ;; Section: Lzh Archives | |
1174 | |
1175 (defun archive-lzh-summarize () | |
1176 (let ((p 1) | |
1177 (totalsize 0) | |
1178 (maxlen 8) | |
1179 files | |
1180 visual) | |
1181 (while (progn (goto-char p) (looking-at "..-l[hz][0-9]-")) | |
1182 (let* ((hsize (char-after p)) | |
1183 (csize (archive-l-e (+ p 7) 4)) | |
1184 (ucsize (archive-l-e (+ p 11) 4)) | |
1185 (modtime (archive-l-e (+ p 15) 2)) | |
1186 (moddate (archive-l-e (+ p 17) 2)) | |
1187 (fnlen (char-after (+ p 21))) | |
1188 (efnname (buffer-substring (+ p 22) (+ p 22 fnlen))) | |
1189 (fiddle (string= efnname (upcase efnname))) | |
1190 (ifnname (if fiddle (downcase efnname) efnname)) | |
1191 (p2 (+ p 22 fnlen)) | |
1192 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0)) | |
1193 (mode (if (= creator ?U) (archive-l-e (+ p2 8) 2) ?\666)) | |
1194 (modestr (if mode (archive-int-to-mode mode) "??????????")) | |
1195 (uid (if (= creator ?U) (archive-l-e (+ p2 10) 2))) | |
1196 (gid (if (= creator ?U) (archive-l-e (+ p2 12) 2))) | |
1197 (text (if archive-alternate-display | |
1198 (format " %8d %5S %5S %s" | |
1199 ucsize | |
1200 (or uid "?") | |
1201 (or gid "?") | |
1202 ifnname) | |
1203 (format " %10s %8d %-11s %-8s %s" | |
1204 modestr | |
1205 ucsize | |
1206 (archive-dosdate moddate) | |
1207 (archive-dostime modtime) | |
1208 ifnname)))) | |
1209 (setq maxlen (max maxlen fnlen) | |
1210 totalsize (+ totalsize ucsize) | |
1211 visual (cons (vector text | |
1212 (- (length text) (length ifnname)) | |
1213 (length text)) | |
1214 visual) | |
1215 files (cons (vector efnname ifnname fiddle mode (1- p)) | |
1216 files) | |
1217 p (+ p hsize 2 csize)))) | |
1218 (goto-char (point-min)) | |
1219 (let ((dash (concat (if archive-alternate-display | |
1220 "- -------- ----- ----- " | |
1221 "- ---------- -------- ----------- -------- ") | |
1222 (make-string maxlen ?-) | |
1223 "\n")) | |
1224 (header (if archive-alternate-display | |
1225 "M Length Uid Gid File\n" | |
1226 "M Filemode Length Date Time File\n")) | |
1227 (sumline (if archive-alternate-display | |
1228 " %8d %d file%s" | |
1229 " %8d %d file%s"))) | |
1230 (insert header dash) | |
1231 (archive-summarize-files (nreverse visual)) | |
1232 (insert dash | |
1233 (format sumline | |
1234 totalsize | |
1235 (length files) | |
1236 (if (= 1 (length files)) "" "s")) | |
1237 "\n")) | |
1238 (apply 'vector (nreverse files)))) | |
1239 | |
1240 (defconst archive-lzh-alternate-display t) | |
1241 | |
1242 (defun archive-lzh-extract (archive name) | |
1243 (archive-extract-by-stdout archive name archive-lzh-extract)) | |
1244 | |
1245 (defun archive-lzh-resum (p count) | |
1246 (let ((sum 0)) | |
1247 (while (> count 0) | |
1248 (setq count (1- count) | |
1249 sum (+ sum (char-after p)) | |
1250 p (1+ p))) | |
1251 (logand sum 255))) | |
1252 | |
1253 (defun archive-lzh-rename-entry (archive newname descr) | |
1254 (save-restriction | |
1255 (save-excursion | |
1256 (widen) | |
1257 (let* ((p (+ archive-proper-file-start (aref descr 4))) | |
1258 (oldhsize (char-after p)) | |
1259 (oldfnlen (char-after (+ p 21))) | |
1260 (newfnlen (length newname)) | |
1261 (newhsize (+ oldhsize newfnlen (- oldfnlen))) | |
1262 buffer-read-only) | |
1263 (if (> newhsize 255) | |
1264 (error "The file name is too long")) | |
1265 (goto-char (+ p 21)) | |
1266 (delete-char (1+ oldfnlen)) | |
1267 (insert newfnlen newname) | |
1268 (goto-char p) | |
1269 (delete-char 2) | |
1270 (insert newhsize (archive-lzh-resum p newhsize)))))) | |
1271 | |
1272 (defun archive-lzh-ogm (newval files errtxt ofs) | |
1273 (save-restriction | |
1274 (save-excursion | |
1275 (widen) | |
1276 (while files | |
1277 (let* ((fil (car files)) | |
1278 (p (+ archive-proper-file-start (aref fil 4))) | |
1279 (hsize (char-after p)) | |
1280 (fnlen (char-after (+ p 21))) | |
1281 (p2 (+ p 22 fnlen)) | |
1282 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0)) | |
1283 buffer-read-only) | |
1284 (if (= creator ?U) | |
1285 (progn | |
1286 (or (numberp newval) | |
1287 (setq newval (funcall newval (archive-l-e (+ p2 ofs) 2)))) | |
1288 (goto-char (+ p2 ofs)) | |
1289 (delete-char 2) | |
1290 (insert (logand newval 255) (lsh newval -8)) | |
1291 (goto-char (1+ p)) | |
1292 (delete-char 1) | |
1293 (insert (archive-lzh-resum (1+ p) hsize))) | |
1294 (message "Member %s does not have %s field" | |
1295 (aref fil 1) errtxt))) | |
1296 (setq files (cdr files)))))) | |
1297 | |
1298 (defun archive-lzh-chown-entry (newuid files) | |
1299 (archive-lzh-ogm newuid files "an uid" 10)) | |
1300 | |
1301 (defun archive-lzh-chgrp-entry (newgid files) | |
1302 (archive-lzh-ogm newgid files "a gid" 12)) | |
1303 | |
1304 (defun archive-lzh-chmod-entry (newmode files) | |
1305 (archive-lzh-ogm | |
1306 ;; This should work even though newmode will be dynamically accessed. | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
1307 (function (lambda (old) (archive-calc-mode old newmode t))) |
11880 | 1308 files "a unix-style mode" 8)) |
1309 ;; ------------------------------------------------------------------------- | |
1310 ;; Section: Zip Archives | |
1311 | |
1312 (defun archive-zip-summarize () | |
1313 (goto-char (- (point-max) (- 22 18))) | |
1314 (search-backward-regexp "[P]K\005\006") | |
1315 (let ((p (1+ (archive-l-e (+ (point) 16) 4))) | |
1316 (maxlen 8) | |
1317 (totalsize 0) | |
1318 files | |
1319 visual) | |
1320 (while (string= "PK\001\002" (buffer-substring p (+ p 4))) | |
1321 (let* ((creator (char-after (+ p 5))) | |
1322 (method (archive-l-e (+ p 10) 2)) | |
1323 (modtime (archive-l-e (+ p 12) 2)) | |
1324 (moddate (archive-l-e (+ p 14) 2)) | |
1325 (ucsize (archive-l-e (+ p 24) 4)) | |
1326 (fnlen (archive-l-e (+ p 28) 2)) | |
1327 (exlen (archive-l-e (+ p 30) 2)) | |
12304
3cf4df625c3b
(archive-zip-summarize): Handle per-file comments in central directory.
Richard M. Stallman <rms@gnu.org>
parents:
12024
diff
changeset
|
1328 (fclen (archive-l-e (+ p 32) 2)) |
11880 | 1329 (lheader (archive-l-e (+ p 42) 4)) |
1330 (efnname (buffer-substring (+ p 46) (+ p 46 fnlen))) | |
1331 (isdir (and (= ucsize 0) | |
1332 (string= (file-name-nondirectory efnname) ""))) | |
1333 (mode (cond ((memq creator '(2 3)) ; Unix + VMS | |
1334 (archive-l-e (+ p 40) 2)) | |
1335 ((memq creator '(0 5 6 7 10 11)) ; Dos etc. | |
1336 (logior ?\444 | |
1337 (if isdir (logior 16384 ?\111) 0) | |
1338 (if (zerop | |
1339 (logand 1 (char-after (+ p 38)))) | |
1340 ?\222 0))) | |
1341 (t nil))) | |
1342 (modestr (if mode (archive-int-to-mode mode) "??????????")) | |
1343 (fiddle (and archive-zip-case-fiddle | |
1344 (not (not (memq creator '(0 2 4 5 9)))))) | |
1345 (ifnname (if fiddle (downcase efnname) efnname)) | |
1346 (text (format " %10s %8d %-11s %-8s %s" | |
1347 modestr | |
1348 ucsize | |
1349 (archive-dosdate moddate) | |
1350 (archive-dostime modtime) | |
1351 ifnname))) | |
1352 (setq maxlen (max maxlen fnlen) | |
1353 totalsize (+ totalsize ucsize) | |
1354 visual (cons (vector text | |
1355 (- (length text) (length ifnname)) | |
1356 (length text)) | |
1357 visual) | |
1358 files (cons (if isdir | |
1359 nil | |
1360 (vector efnname ifnname fiddle mode | |
1361 (list (1- p) lheader))) | |
1362 files) | |
12304
3cf4df625c3b
(archive-zip-summarize): Handle per-file comments in central directory.
Richard M. Stallman <rms@gnu.org>
parents:
12024
diff
changeset
|
1363 p (+ p 46 fnlen exlen fclen)))) |
11880 | 1364 (goto-char (point-min)) |
1365 (let ((dash (concat "- ---------- -------- ----------- -------- " | |
1366 (make-string maxlen ?-) | |
1367 "\n"))) | |
1368 (insert "M Filemode Length Date Time File\n" | |
1369 dash) | |
1370 (archive-summarize-files (nreverse visual)) | |
1371 (insert dash | |
1372 (format " %8d %d file%s" | |
1373 totalsize | |
1374 (length files) | |
1375 (if (= 1 (length files)) "" "s")) | |
1376 "\n")) | |
1377 (apply 'vector (nreverse files)))) | |
1378 | |
1379 (defun archive-zip-extract (archive name) | |
1380 (if archive-zip-use-pkzip | |
1381 (archive-*-extract archive name archive-zip-extract) | |
1382 (archive-extract-by-stdout archive name archive-zip-extract))) | |
1383 | |
1384 (defun archive-zip-write-file-member (archive descr) | |
1385 (archive-*-write-file-member | |
1386 archive | |
1387 descr | |
1388 (if (aref descr 2) archive-zip-update-case archive-zip-update))) | |
1389 | |
1390 (defun archive-zip-chmod-entry (newmode files) | |
1391 (save-restriction | |
1392 (save-excursion | |
1393 (widen) | |
1394 (while files | |
1395 (let* ((fil (car files)) | |
1396 (p (+ archive-proper-file-start (car (aref fil 4)))) | |
1397 (creator (char-after (+ p 5))) | |
1398 (oldmode (aref fil 3)) | |
1399 (newval (archive-calc-mode oldmode newmode t)) | |
1400 buffer-read-only) | |
1401 (cond ((memq creator '(2 3)) ; Unix + VMS | |
1402 (goto-char (+ p 40)) | |
1403 (delete-char 2) | |
1404 (insert (logand newval 255) (lsh newval -8))) | |
1405 ((memq creator '(0 5 6 7 10 11)) ; Dos etc. | |
1406 (goto-char (+ p 38)) | |
1407 (insert (logior (logand (char-after (point)) 254) | |
1408 (logand (logxor 1 (lsh newval -7)) 1))) | |
1409 (delete-char 1)) | |
1410 (t (message "Don't know how to change mode for this member")))) | |
1411 (setq files (cdr files)))))) | |
1412 ;; ------------------------------------------------------------------------- | |
1413 ;; Section: Zoo Archives | |
1414 | |
1415 (defun archive-zoo-summarize () | |
1416 (let ((p (1+ (archive-l-e 25 4))) | |
1417 (maxlen 8) | |
1418 (totalsize 0) | |
1419 files | |
1420 visual) | |
1421 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4))) | |
1422 (> (archive-l-e (+ p 6) 4) 0)) | |
1423 (let* ((next (1+ (archive-l-e (+ p 6) 4))) | |
1424 (moddate (archive-l-e (+ p 14) 2)) | |
1425 (modtime (archive-l-e (+ p 16) 2)) | |
1426 (ucsize (archive-l-e (+ p 20) 4)) | |
1427 (namefld (buffer-substring (+ p 38) (+ p 38 13))) | |
13339
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1428 (dirtype (char-after (+ p 4))) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1429 (lfnlen (if (= dirtype 2) (char-after (+ p 56)) 0)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1430 (ldirlen (if (= dirtype 2) (char-after (+ p 57)) 0)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1431 (fnlen (+ ldirlen |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1432 (if (> lfnlen 0) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1433 (1- lfnlen) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1434 (or (string-match "\0" namefld) 13)))) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1435 (efnname (concat |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1436 (if (> ldirlen 0) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1437 (concat (buffer-substring |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1438 (+ p 58 lfnlen) (+ p 58 lfnlen ldirlen -1)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1439 "/") |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1440 "") |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1441 (if (> lfnlen 0) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1442 (buffer-substring (+ p 58) (+ p 58 lfnlen -1)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1443 (substring namefld 0 fnlen)))) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1444 (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname)))) |
11880 | 1445 (ifnname (if fiddle (downcase efnname) efnname)) |
1446 (text (format " %8d %-11s %-8s %s" | |
1447 ucsize | |
1448 (archive-dosdate moddate) | |
1449 (archive-dostime modtime) | |
1450 ifnname))) | |
1451 (setq maxlen (max maxlen fnlen) | |
1452 totalsize (+ totalsize ucsize) | |
1453 visual (cons (vector text | |
1454 (- (length text) (length ifnname)) | |
1455 (length text)) | |
1456 visual) | |
1457 files (cons (vector efnname ifnname fiddle nil (1- p)) | |
1458 files) | |
1459 p next))) | |
1460 (goto-char (point-min)) | |
1461 (let ((dash (concat "- -------- ----------- -------- " | |
1462 (make-string maxlen ?-) | |
1463 "\n"))) | |
1464 (insert "M Length Date Time File\n" | |
1465 dash) | |
1466 (archive-summarize-files (nreverse visual)) | |
1467 (insert dash | |
1468 (format " %8d %d file%s" | |
1469 totalsize | |
1470 (length files) | |
1471 (if (= 1 (length files)) "" "s")) | |
1472 "\n")) | |
1473 (apply 'vector (nreverse files)))) | |
1474 | |
1475 (defun archive-zoo-extract (archive name) | |
1476 (archive-extract-by-stdout archive name archive-zoo-extract)) | |
1477 ;; ------------------------------------------------------------------------- | |
1478 (provide 'archive-mode) | |
1479 | |
1480 ;; arc-mode.el ends here. |