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