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)
|
163
|
468
|
|
469 (defun archive-quit ()
|
|
470 "Bury the current archive buffer."
|
|
471 (interactive)
|
|
472 (bury-buffer))
|
|
473
|
0
|
474 ;; -------------------------------------------------------------------------
|
|
475 ;; Section: Key maps
|
|
476
|
|
477 (if archive-mode-map nil
|
|
478 (setq archive-mode-map (make-keymap))
|
|
479 (suppress-keymap archive-mode-map)
|
|
480 (define-key archive-mode-map " " 'archive-next-line)
|
|
481 (define-key archive-mode-map "a" 'archive-alternate-display)
|
|
482 ;;(define-key archive-mode-map "c" 'archive-copy)
|
|
483 (define-key archive-mode-map "d" 'archive-flag-deleted)
|
|
484 (define-key archive-mode-map "\C-d" 'archive-flag-deleted)
|
|
485 (define-key archive-mode-map "e" 'archive-extract)
|
|
486 (define-key archive-mode-map "f" 'archive-extract)
|
|
487 (define-key archive-mode-map "\C-m" 'archive-extract)
|
|
488 (define-key archive-mode-map "g" 'revert-buffer)
|
|
489 (define-key archive-mode-map "h" 'describe-mode)
|
|
490 (define-key archive-mode-map "m" 'archive-mark)
|
|
491 (define-key archive-mode-map "n" 'archive-next-line)
|
|
492 (define-key archive-mode-map "\C-n" 'archive-next-line)
|
|
493 (define-key archive-mode-map [down] 'archive-next-line)
|
|
494 (define-key archive-mode-map "o" 'archive-extract-other-window)
|
|
495 (define-key archive-mode-map "p" 'archive-previous-line)
|
|
496 (define-key archive-mode-map "\C-p" 'archive-previous-line)
|
|
497 (define-key archive-mode-map [up] 'archive-previous-line)
|
|
498 (define-key archive-mode-map "r" 'archive-rename-entry)
|
|
499 (define-key archive-mode-map "u" 'archive-unflag)
|
|
500 (define-key archive-mode-map "\M-\C-?" 'archive-unmark-all-files)
|
|
501 (define-key archive-mode-map "v" 'archive-view)
|
|
502 (define-key archive-mode-map "x" 'archive-expunge)
|
161
|
503 (define-key archive-mode-map 'backspace 'archive-unflag-backwards)
|
|
504 (define-key archive-mode-map 'delete 'archive-unflag-backwards)
|
0
|
505 (define-key archive-mode-map "E" 'archive-extract-other-window)
|
|
506 (define-key archive-mode-map "M" 'archive-chmod-entry)
|
|
507 (define-key archive-mode-map "G" 'archive-chgrp-entry)
|
|
508 (define-key archive-mode-map "O" 'archive-chown-entry)
|
|
509
|
2
|
510 (if archive-xemacs
|
0
|
511 (progn
|
|
512 ;; Not a nice "solution" but it'll have to do
|
163
|
513 (define-key archive-mode-map "q" 'archive-quit)
|
0
|
514 (define-key archive-mode-map "\C-xu" 'archive-undo)
|
|
515 (define-key archive-mode-map "\C-_" 'archive-undo))
|
|
516 (substitute-key-definition 'undo 'archive-undo
|
|
517 archive-mode-map global-map))
|
|
518
|
|
519 (define-key archive-mode-map
|
2
|
520 (if archive-xemacs 'button2 [mouse-2]) 'archive-mouse-extract)
|
0
|
521
|
2
|
522 (if archive-xemacs
|
0
|
523 () ; out of luck
|
|
524 ;; Get rid of the Edit menu bar item to save space.
|
|
525 (define-key archive-mode-map [menu-bar edit] 'undefined)
|
|
526
|
|
527 (define-key archive-mode-map [menu-bar immediate]
|
|
528 (cons "Immediate" (make-sparse-keymap "Immediate")))
|
|
529 (define-key archive-mode-map [menu-bar immediate alternate]
|
|
530 '("Alternate Display" . archive-alternate-display))
|
|
531 (put 'archive-alternate-display 'menu-enable
|
|
532 '(boundp (archive-name "alternate-display")))
|
|
533 (define-key archive-mode-map [menu-bar immediate view]
|
|
534 '("View This File" . archive-view))
|
|
535 (define-key archive-mode-map [menu-bar immediate display]
|
|
536 '("Display in Other Window" . archive-display-other-window))
|
|
537 (define-key archive-mode-map [menu-bar immediate find-file-other-window]
|
|
538 '("Find in Other Window" . archive-extract-other-window))
|
|
539 (define-key archive-mode-map [menu-bar immediate find-file]
|
|
540 '("Find This File" . archive-extract))
|
|
541
|
|
542 (define-key archive-mode-map [menu-bar mark]
|
|
543 (cons "Mark" (make-sparse-keymap "Mark")))
|
|
544 (define-key archive-mode-map [menu-bar mark unmark-all]
|
|
545 '("Unmark All" . archive-unmark-all-files))
|
|
546 (define-key archive-mode-map [menu-bar mark deletion]
|
|
547 '("Flag" . archive-flag-deleted))
|
|
548 (define-key archive-mode-map [menu-bar mark unmark]
|
|
549 '("Unflag" . archive-unflag))
|
|
550 (define-key archive-mode-map [menu-bar mark mark]
|
|
551 '("Mark" . archive-mark))
|
|
552
|
|
553 (define-key archive-mode-map [menu-bar operate]
|
|
554 (cons "Operate" (make-sparse-keymap "Operate")))
|
|
555 (define-key archive-mode-map [menu-bar operate chown]
|
|
556 '("Change Owner..." . archive-chown-entry))
|
|
557 (put 'archive-chown-entry 'menu-enable
|
|
558 '(fboundp (archive-name "chown-entry")))
|
|
559 (define-key archive-mode-map [menu-bar operate chgrp]
|
|
560 '("Change Group..." . archive-chgrp-entry))
|
|
561 (put 'archive-chgrp-entry 'menu-enable
|
|
562 '(fboundp (archive-name "chgrp-entry")))
|
|
563 (define-key archive-mode-map [menu-bar operate chmod]
|
|
564 '("Change Mode..." . archive-chmod-entry))
|
|
565 (put 'archive-chmod-entry 'menu-enable
|
|
566 '(fboundp (archive-name "chmod-entry")))
|
|
567 (define-key archive-mode-map [menu-bar operate rename]
|
|
568 '("Rename to..." . archive-rename-entry))
|
|
569 (put 'archive-rename-entry 'menu-enable
|
|
570 '(fboundp (archive-name "rename-entry")))
|
|
571 ;;(define-key archive-mode-map [menu-bar operate copy]
|
|
572 ;; '("Copy to..." . archive-copy))
|
|
573 (define-key archive-mode-map [menu-bar operate expunge]
|
|
574 '("Expunge Marked Files" . archive-expunge))
|
|
575 ))
|
|
576
|
|
577 (let* ((item1 '(archive-subfile-mode " Archive"))
|
|
578 (item2 '(archive-subfile-dos " Dos"))
|
|
579 (items (if (memq system-type '(ms-dos windows-nt))
|
|
580 (list item1) ; msdog has its own indicator
|
|
581 (list item1 item2))))
|
|
582 (or (member item1 minor-mode-alist)
|
|
583 (setq minor-mode-alist (append items minor-mode-alist))))
|
|
584 ;; -------------------------------------------------------------------------
|
|
585 (defun archive-find-type ()
|
|
586 (widen)
|
|
587 (goto-char (point-min))
|
|
588 ;; The funny [] here make it unlikely that the .elc file will be treated
|
|
589 ;; as an archive by other software.
|
|
590 (let (case-fold-search)
|
|
591 (cond ((looking-at "[P]K\003\004") 'zip)
|
|
592 ((looking-at "..-l[hz][0-9]-") 'lzh)
|
|
593 ((looking-at "....................[\334]\247\304\375") 'zoo)
|
|
594 ((and (looking-at "\C-z") ; signature too simple, IMHO
|
|
595 (string-match "\\.[aA][rR][cC]$"
|
|
596 (or buffer-file-name (buffer-name))))
|
|
597 'arc)
|
|
598 (t (error "Buffer format not recognized.")))))
|
|
599 ;; -------------------------------------------------------------------------
|
|
600 (defun archive-summarize ()
|
|
601 "Parse the contents of the archive file in the current buffer.
|
|
602 Place a dired-like listing on the front;
|
|
603 then narrow to it, so that only that listing
|
|
604 is visible (and the real data of the buffer is hidden)."
|
|
605 (widen)
|
|
606 (let (buffer-read-only)
|
|
607 (message "Parsing archive file...")
|
|
608 (buffer-disable-undo (current-buffer))
|
|
609 (setq archive-files (funcall (archive-name "summarize")))
|
|
610 (message "Parsing archive file...done.")
|
|
611 (setq archive-proper-file-start (point-marker))
|
|
612 (narrow-to-region (point-min) (point))
|
|
613 (set-buffer-modified-p nil)
|
|
614 (buffer-enable-undo))
|
|
615 (goto-char archive-file-list-start)
|
|
616 (archive-next-line 0))
|
|
617
|
|
618 (defun archive-resummarize ()
|
|
619 "Recreate the contents listing of an archive."
|
|
620 (let ((modified (buffer-modified-p))
|
|
621 (no (archive-get-lineno))
|
|
622 buffer-read-only)
|
|
623 (widen)
|
|
624 (delete-region (point-min) archive-proper-file-start)
|
|
625 (archive-summarize)
|
|
626 (set-buffer-modified-p modified)
|
|
627 (goto-char archive-file-list-start)
|
|
628 (archive-next-line no)))
|
|
629
|
|
630 (defun archive-summarize-files (files)
|
2
|
631 "Insert a description of a list of files annotated with proper mouse face"
|
0
|
632 (setq archive-file-list-start (point-marker))
|
|
633 (setq archive-file-name-indent (if files (aref (car files) 1) 0))
|
|
634 ;; We don't want to do an insert for each element since that takes too
|
|
635 ;; long when the archive -- which has to be moved in memory -- is large.
|
|
636 (insert
|
|
637 (apply
|
|
638 (function concat)
|
|
639 (mapcar
|
|
640 (function
|
|
641 (lambda (fil)
|
|
642 ;; Using `concat' here copies the text also, so we can add
|
|
643 ;; properties without problems.
|
|
644 (let ((text (concat (aref fil 0) "\n")))
|
2
|
645 (if archive-xemacs
|
0
|
646 () ; out of luck
|
|
647 (put-text-property (aref fil 1) (aref fil 2)
|
|
648 'mouse-face 'highlight
|
|
649 text))
|
|
650 text)))
|
|
651 files)))
|
|
652 (setq archive-file-list-end (point-marker)))
|
|
653
|
|
654 (defun archive-alternate-display ()
|
|
655 "Toggle alternative display.
|
|
656 To avoid very long lines some archive mode don't show all information.
|
|
657 This function changes the set of information shown for each files."
|
|
658 (interactive)
|
|
659 (setq archive-alternate-display (not archive-alternate-display))
|
|
660 (archive-resummarize))
|
|
661 ;; -------------------------------------------------------------------------
|
|
662 ;; Section: Local archive copy handling
|
|
663
|
|
664 (defun archive-maybe-copy (archive)
|
|
665 (if archive-remote
|
|
666 (let ((start (point-max)))
|
|
667 (setq archive-local-name (expand-file-name
|
|
668 (file-name-nondirectory archive)
|
|
669 archive-tmpdir))
|
|
670 (make-directory archive-tmpdir t)
|
|
671 (save-restriction
|
|
672 (widen)
|
|
673 (write-region start (point-max) archive-local-name nil 'nomessage))
|
|
674 archive-local-name)
|
|
675 (if (buffer-modified-p) (save-buffer))
|
|
676 archive))
|
|
677
|
|
678 (defun archive-maybe-update (unchanged)
|
|
679 (if archive-remote
|
|
680 (let ((name archive-local-name)
|
|
681 (modified (buffer-modified-p))
|
|
682 buffer-read-only)
|
|
683 (if unchanged nil
|
|
684 (erase-buffer)
|
|
685 (insert-file-contents name)
|
|
686 (archive-mode t))
|
|
687 (archive-delete-local name)
|
|
688 (if (not unchanged)
|
|
689 (message "Archive file must be saved for changes to take effect"))
|
|
690 (set-buffer-modified-p (or modified (not unchanged))))))
|
|
691
|
|
692 (defun archive-delete-local (name)
|
|
693 "Delete file NAME and its parents up to and including `archive-tmpdir'."
|
|
694 (let ((again t)
|
|
695 (top (directory-file-name (file-name-as-directory archive-tmpdir))))
|
|
696 (condition-case nil
|
|
697 (delete-file name)
|
|
698 (error nil))
|
|
699 (while again
|
|
700 (setq name (directory-file-name (file-name-directory name)))
|
|
701 (condition-case nil
|
|
702 (delete-directory name)
|
|
703 (error nil))
|
|
704 (if (string= name top) (setq again nil)))))
|
|
705 ;; -------------------------------------------------------------------------
|
|
706 ;; Section: Member extraction
|
|
707
|
|
708 (defun archive-mouse-extract (event)
|
|
709 "Extract a file whose name you click on."
|
|
710 (interactive "e")
|
|
711 (mouse-set-point event)
|
|
712 (switch-to-buffer
|
|
713 (save-excursion
|
|
714 (archive-extract)
|
|
715 (current-buffer))))
|
|
716
|
|
717 (defun archive-extract (&optional other-window-p)
|
|
718 "In archive mode, extract this entry of the archive into its own buffer."
|
|
719 (interactive)
|
|
720 (let* ((view-p (eq other-window-p 'view))
|
|
721 (descr (archive-get-descr))
|
|
722 (ename (aref descr 0))
|
|
723 (iname (aref descr 1))
|
|
724 (archive-buffer (current-buffer))
|
|
725 (arcdir default-directory)
|
|
726 (archive (buffer-file-name))
|
|
727 (arcname (file-name-nondirectory archive))
|
|
728 (bufname (concat (file-name-nondirectory iname) " (" arcname ")"))
|
|
729 (extractor (archive-name "extract"))
|
|
730 (read-only-p (or archive-read-only view-p))
|
|
731 (buffer (get-buffer bufname))
|
|
732 (just-created nil))
|
|
733 (if buffer
|
|
734 nil
|
|
735 (setq archive (archive-maybe-copy archive))
|
|
736 (setq buffer (get-buffer-create bufname))
|
|
737 (setq just-created t)
|
|
738 (save-excursion
|
|
739 (set-buffer buffer)
|
|
740 (setq buffer-file-name
|
|
741 (expand-file-name (concat arcname ":" iname)))
|
|
742 (setq buffer-file-truename
|
|
743 (abbreviate-file-name buffer-file-name))
|
|
744 ;; Set the default-directory to the dir of the superior buffer.
|
|
745 (setq default-directory arcdir)
|
|
746 (make-local-variable 'archive-superior-buffer)
|
|
747 (setq archive-superior-buffer archive-buffer)
|
|
748 (make-local-variable 'local-write-file-hooks)
|
|
749 (add-hook 'local-write-file-hooks 'archive-write-file-member)
|
|
750 (setq archive-subfile-mode descr)
|
|
751 (setq archive-subfile-dos nil
|
|
752 buffer-file-type t)
|
|
753 (if (fboundp extractor)
|
|
754 (funcall extractor archive ename)
|
|
755 (archive-*-extract archive ename (symbol-value extractor)))
|
|
756 (if archive-dos-members (archive-check-dos))
|
|
757 (goto-char (point-min))
|
|
758 (rename-buffer bufname)
|
|
759 (setq buffer-read-only read-only-p)
|
|
760 (setq buffer-undo-list nil)
|
|
761 (set-buffer-modified-p nil)
|
|
762 (setq buffer-saved-size (buffer-size))
|
|
763 (normal-mode)
|
|
764 ;; Just in case an archive occurs inside another archive.
|
|
765 (if (eq major-mode 'archive-mode)
|
|
766 (setq archive-remote t))
|
|
767 (run-hooks 'archive-extract-hooks))
|
|
768 (archive-maybe-update t))
|
|
769 (if view-p
|
|
770 (progn
|
|
771 (view-buffer buffer)
|
|
772 (and just-created (setq view-exit-action 'kill-buffer)))
|
|
773 (if (eq other-window-p 'display)
|
|
774 (display-buffer buffer)
|
|
775 (if other-window-p
|
|
776 (switch-to-buffer-other-window buffer)
|
|
777 (switch-to-buffer buffer))))))
|
|
778
|
|
779 (defun archive-*-extract (archive name command)
|
|
780 (let* ((default-directory (file-name-as-directory archive-tmpdir))
|
|
781 (tmpfile (expand-file-name (file-name-nondirectory name)
|
|
782 default-directory)))
|
|
783 (make-directory (directory-file-name default-directory) t)
|
|
784 (apply 'call-process
|
|
785 (car command)
|
|
786 nil
|
|
787 nil
|
|
788 nil
|
|
789 (append (cdr command) (list archive name)))
|
|
790 (insert-file-contents tmpfile)
|
|
791 (archive-delete-local tmpfile)))
|
|
792
|
|
793 (defun archive-extract-by-stdout (archive name command)
|
|
794 (let ((binary-process-output t)) ; for Ms-Dos
|
|
795 (apply 'call-process
|
|
796 (car command)
|
|
797 nil
|
|
798 t
|
|
799 nil
|
|
800 (append (cdr command) (list archive name)))))
|
|
801
|
|
802 (defun archive-extract-other-window ()
|
|
803 "In archive mode, find this member in another window."
|
|
804 (interactive)
|
|
805 (archive-extract t))
|
|
806
|
|
807 (defun archive-display-other-window ()
|
|
808 "In archive mode, display this member in another window."
|
|
809 (interactive)
|
|
810 (archive-extract 'display))
|
|
811
|
|
812 (defun archive-view ()
|
|
813 "In archive mode, view the member on this line."
|
|
814 (interactive)
|
|
815 (archive-extract 'view))
|
|
816
|
|
817 (defun archive-add-new-member (arcbuf name)
|
|
818 "Add current buffer to the archive in ARCBUF naming it NAME."
|
|
819 (interactive
|
|
820 (list (get-buffer
|
|
821 (read-buffer "Buffer containing archive: "
|
|
822 ;; Find first archive buffer and suggest that
|
|
823 (let ((bufs (buffer-list)))
|
|
824 (while (and bufs (not (eq (save-excursion
|
|
825 (set-buffer (car bufs))
|
|
826 major-mode)
|
|
827 'archive-mode)))
|
|
828 (setq bufs (cdr bufs)))
|
|
829 (if bufs
|
|
830 (car bufs)
|
|
831 (error "There are no archive buffers")))
|
|
832 t))
|
|
833 (read-string "File name in archive: "
|
|
834 (if buffer-file-name
|
|
835 (file-name-nondirectory buffer-file-name)
|
|
836 ""))))
|
|
837 (save-excursion
|
|
838 (set-buffer arcbuf)
|
|
839 (or (eq major-mode 'archive-mode)
|
|
840 (error "Buffer is not an archive buffer"))
|
|
841 (if archive-read-only
|
|
842 (error "Archive is read-only")))
|
|
843 (if (eq arcbuf (current-buffer))
|
|
844 (error "An archive buffer cannot be added to itself"))
|
|
845 (if (string= name "")
|
|
846 (error "Archive members may not be given empty names"))
|
|
847 (let ((func (save-excursion (set-buffer arcbuf)
|
|
848 (archive-name "add-new-member")))
|
|
849 (membuf (current-buffer)))
|
|
850 (if (fboundp func)
|
|
851 (save-excursion
|
|
852 (set-buffer arcbuf)
|
|
853 (funcall func buffer-file-name membuf name))
|
|
854 (error "Adding a new member is not supported for this archive type"))))
|
|
855 ;; -------------------------------------------------------------------------
|
|
856 ;; Section: IO stuff
|
|
857
|
|
858 (defun archive-check-dos (&optional force)
|
|
859 "*Possibly handle a buffer with ^M^J terminated lines."
|
|
860 (save-restriction
|
|
861 (widen)
|
|
862 (save-excursion
|
|
863 (goto-char (point-min))
|
|
864 (setq archive-subfile-dos
|
|
865 (or force (not (search-forward-regexp "[^\r]\n" nil t))))
|
|
866 (setq buffer-file-type (not archive-subfile-dos))
|
|
867 (if archive-subfile-dos
|
|
868 (let ((modified (buffer-modified-p)))
|
|
869 (buffer-disable-undo (current-buffer))
|
|
870 (goto-char (point-min))
|
|
871 (while (search-forward "\r\n" nil t)
|
|
872 (replace-match "\n"))
|
|
873 (buffer-enable-undo)
|
|
874 (set-buffer-modified-p modified))))))
|
|
875
|
|
876 (defun archive-write-file-member ()
|
|
877 (if archive-subfile-dos
|
|
878 (save-restriction
|
|
879 (widen)
|
|
880 (save-excursion
|
|
881 (goto-char (point-min))
|
|
882 ;; We don't want our ^M^J <--> ^J changes to show in the undo list
|
|
883 (let ((undo-list buffer-undo-list))
|
|
884 (unwind-protect
|
|
885 (progn
|
|
886 (setq buffer-undo-list t)
|
|
887 (while (search-forward "\n" nil t)
|
|
888 (replace-match "\r\n"))
|
|
889 (setq archive-subfile-dos nil)
|
|
890 (setq buffer-file-type t)
|
|
891 ;; OK, we're now have explicit ^M^Js -- save and re-unixfy
|
|
892 (archive-write-file-member))
|
|
893 (progn
|
|
894 (archive-check-dos t)
|
|
895 (setq buffer-undo-list undo-list))))
|
|
896 t))
|
|
897 (save-excursion
|
|
898 (save-restriction
|
|
899 (message "Updating archive...")
|
|
900 (widen)
|
|
901 (let ((writer (save-excursion (set-buffer archive-superior-buffer)
|
|
902 (archive-name "write-file-member")))
|
|
903 (archive (save-excursion (set-buffer archive-superior-buffer)
|
|
904 (buffer-file-name))))
|
|
905 (if (fboundp writer)
|
|
906 (funcall writer archive archive-subfile-mode)
|
|
907 (archive-*-write-file-member archive
|
|
908 archive-subfile-mode
|
|
909 (symbol-value writer))))
|
|
910 (set-buffer-modified-p nil)
|
|
911 (message "Updating archive...done")
|
|
912 (set-buffer archive-superior-buffer)
|
|
913 (revert-buffer)
|
|
914 t))))
|
|
915
|
|
916 (defun archive-*-write-file-member (archive descr command)
|
|
917 (let* ((ename (aref descr 0))
|
|
918 (tmpfile (expand-file-name ename archive-tmpdir))
|
|
919 (top (directory-file-name (file-name-as-directory archive-tmpdir)))
|
|
920 (default-directory (file-name-as-directory top)))
|
|
921 (unwind-protect
|
|
922 (progn
|
|
923 (make-directory (file-name-directory tmpfile) t)
|
|
924 (write-region (point-min) (point-max) tmpfile nil 'nomessage)
|
|
925 (if (aref descr 3)
|
|
926 ;; Set the file modes, but make sure we can read it.
|
|
927 (set-file-modes tmpfile (logior ?\400 (aref descr 3))))
|
|
928 (let ((exitcode (apply 'call-process
|
|
929 (car command)
|
|
930 nil
|
|
931 nil
|
|
932 nil
|
|
933 (append (cdr command) (list archive ename)))))
|
|
934 (if (equal exitcode 0)
|
|
935 nil
|
|
936 (error "Updating was unsuccessful (%S)" exitcode))))
|
|
937 (archive-delete-local tmpfile))))
|
|
938
|
|
939 (defun archive-write-file ()
|
|
940 (save-excursion
|
|
941 (write-region archive-proper-file-start (point-max) buffer-file-name nil t)
|
|
942 (set-buffer-modified-p nil)
|
|
943 t))
|
|
944 ;; -------------------------------------------------------------------------
|
|
945 ;; Section: Marking and unmarking.
|
|
946
|
|
947 (defun archive-flag-deleted (p &optional type)
|
|
948 "In archive mode, mark this member to be deleted from the archive.
|
|
949 With a prefix argument, mark that many files."
|
|
950 (interactive "p")
|
|
951 (or type (setq type ?D))
|
|
952 (beginning-of-line)
|
|
953 (let ((sign (if (>= p 0) +1 -1))
|
|
954 (modified (buffer-modified-p))
|
|
955 buffer-read-only)
|
|
956 (while (not (zerop p))
|
|
957 (if (archive-get-descr t)
|
|
958 (progn
|
|
959 (delete-char 1)
|
|
960 (insert type)))
|
|
961 (forward-line sign)
|
|
962 (setq p (- p sign)))
|
|
963 (set-buffer-modified-p modified))
|
|
964 (archive-next-line 0))
|
|
965
|
|
966 (defun archive-unflag (p)
|
|
967 "In archive mode, un-mark this member if it is marked to be deleted.
|
|
968 With a prefix argument, un-mark that many files forward."
|
|
969 (interactive "p")
|
|
970 (archive-flag-deleted p ? ))
|
|
971
|
|
972 (defun archive-unflag-backwards (p)
|
|
973 "In archive mode, un-mark this member if it is marked to be deleted.
|
|
974 With a prefix argument, un-mark that many members backward."
|
|
975 (interactive "p")
|
|
976 (archive-flag-deleted (- p) ? ))
|
|
977
|
|
978 (defun archive-unmark-all-files ()
|
|
979 "Remove all marks."
|
|
980 (interactive)
|
|
981 (let ((modified (buffer-modified-p))
|
|
982 buffer-read-only)
|
|
983 (save-excursion
|
|
984 (goto-char archive-file-list-start)
|
|
985 (while (< (point) archive-file-list-end)
|
|
986 (or (= (following-char) ? )
|
|
987 (progn (delete-char 1) (insert ? )))
|
|
988 (forward-line 1)))
|
|
989 (set-buffer-modified-p modified)))
|
|
990
|
|
991 (defun archive-mark (p)
|
|
992 "In archive mode, mark this member for group operations.
|
|
993 With a prefix argument, mark that many members.
|
|
994 Use \\[archive-unmark-all-files] to remove all marks."
|
|
995 (interactive "p")
|
|
996 (archive-flag-deleted p ?*))
|
|
997
|
|
998 (defun archive-get-marked (mark &optional default)
|
|
999 (let (files)
|
|
1000 (save-excursion
|
|
1001 (goto-char archive-file-list-start)
|
|
1002 (while (< (point) archive-file-list-end)
|
|
1003 (if (= (following-char) mark)
|
|
1004 (setq files (cons (archive-get-descr) files)))
|
|
1005 (forward-line 1)))
|
|
1006 (or (nreverse files)
|
|
1007 (and default
|
|
1008 (list (archive-get-descr))))))
|
|
1009 ;; -------------------------------------------------------------------------
|
|
1010 ;; Section: Operate
|
|
1011
|
|
1012 (defun archive-next-line (p)
|
|
1013 (interactive "p")
|
|
1014 (forward-line p)
|
|
1015 (or (eobp)
|
|
1016 (forward-char archive-file-name-indent)))
|
|
1017
|
|
1018 (defun archive-previous-line (p)
|
|
1019 (interactive "p")
|
|
1020 (archive-next-line (- p)))
|
|
1021
|
|
1022 (defun archive-chmod-entry (new-mode)
|
|
1023 "Change the protection bits associated with all marked or this member.
|
|
1024 The new protection bits can either be specified as an octal number or
|
|
1025 as a relative change like \"g+rw\" as for chmod(2)"
|
|
1026 (interactive "sNew mode (octal or relative): ")
|
|
1027 (if archive-read-only (error "Archive is read-only"))
|
|
1028 (let ((func (archive-name "chmod-entry")))
|
|
1029 (if (fboundp func)
|
|
1030 (progn
|
|
1031 (funcall func new-mode (archive-get-marked ?* t))
|
|
1032 (archive-resummarize))
|
|
1033 (error "Setting mode bits is not supported for this archive type"))))
|
|
1034
|
|
1035 (defun archive-chown-entry (new-uid)
|
|
1036 "Change the owner of all marked or this member."
|
|
1037 (interactive "nNew uid: ")
|
|
1038 (if archive-read-only (error "Archive is read-only"))
|
|
1039 (let ((func (archive-name "chown-entry")))
|
|
1040 (if (fboundp func)
|
|
1041 (progn
|
|
1042 (funcall func new-uid (archive-get-marked ?* t))
|
|
1043 (archive-resummarize))
|
|
1044 (error "Setting owner is not supported for this archive type"))))
|
|
1045
|
|
1046 (defun archive-chgrp-entry (new-gid)
|
|
1047 "Change the group of all marked or this member."
|
|
1048 (interactive "nNew gid: ")
|
|
1049 (if archive-read-only (error "Archive is read-only"))
|
|
1050 (let ((func (archive-name "chgrp-entry")))
|
|
1051 (if (fboundp func)
|
|
1052 (progn
|
|
1053 (funcall func new-gid (archive-get-marked ?* t))
|
|
1054 (archive-resummarize))
|
|
1055 (error "Setting group is not supported for this archive type"))))
|
|
1056
|
|
1057 (defun archive-expunge ()
|
|
1058 "Do the flagged deletions."
|
|
1059 (interactive)
|
|
1060 (let (files)
|
|
1061 (save-excursion
|
|
1062 (goto-char archive-file-list-start)
|
|
1063 (while (< (point) archive-file-list-end)
|
|
1064 (if (= (following-char) ?D)
|
|
1065 (setq files (cons (aref (archive-get-descr) 0) files)))
|
|
1066 (forward-line 1)))
|
|
1067 (setq files (nreverse files))
|
|
1068 (and files
|
|
1069 (or (not archive-read-only)
|
|
1070 (error "Archive is read-only"))
|
|
1071 (or (yes-or-no-p (format "Really delete %d member%s? "
|
|
1072 (length files)
|
|
1073 (if (null (cdr files)) "" "s")))
|
|
1074 (error "Operation aborted"))
|
|
1075 (let ((archive (archive-maybe-copy (buffer-file-name)))
|
|
1076 (expunger (archive-name "expunge")))
|
|
1077 (if (fboundp expunger)
|
|
1078 (funcall expunger archive files)
|
|
1079 (archive-*-expunge archive files (symbol-value expunger)))
|
|
1080 (archive-maybe-update nil)
|
|
1081 (if archive-remote
|
|
1082 (archive-resummarize)
|
|
1083 (revert-buffer))))))
|
|
1084
|
|
1085 (defun archive-*-expunge (archive files command)
|
|
1086 (apply 'call-process
|
|
1087 (car command)
|
|
1088 nil
|
|
1089 nil
|
|
1090 nil
|
|
1091 (append (cdr command) (cons archive files))))
|
|
1092
|
|
1093 (defun archive-rename-entry (newname)
|
|
1094 "Change the name associated with this entry in the tar file."
|
|
1095 (interactive "sNew name: ")
|
|
1096 (if archive-read-only (error "Archive is read-only"))
|
|
1097 (if (string= newname "")
|
|
1098 (error "Archive members may not be given empty names"))
|
|
1099 (let ((func (archive-name "rename-entry"))
|
|
1100 (descr (archive-get-descr)))
|
|
1101 (if (fboundp func)
|
|
1102 (progn
|
|
1103 (funcall func (buffer-file-name) newname descr)
|
|
1104 (archive-resummarize))
|
|
1105 (error "Renaming is not supported for this archive type"))))
|
|
1106
|
|
1107 ;; Revert the buffer and recompute the dired-like listing.
|
|
1108 (defun archive-mode-revert (&optional no-autosave no-confirm)
|
|
1109 (let ((no (archive-get-lineno)))
|
|
1110 (setq archive-files nil)
|
|
1111 (let ((revert-buffer-function nil))
|
|
1112 (revert-buffer t t))
|
|
1113 (archive-mode)
|
|
1114 (goto-char archive-file-list-start)
|
|
1115 (archive-next-line no)))
|
|
1116
|
|
1117 (defun archive-undo ()
|
|
1118 "Undo in an archive buffer.
|
|
1119 This doesn't recover lost files, it just undoes changes in the buffer itself."
|
|
1120 (interactive)
|
|
1121 (let (buffer-read-only)
|
|
1122 (undo)))
|
|
1123 ;; -------------------------------------------------------------------------
|
|
1124 ;; Section: Arc Archives
|
|
1125
|
|
1126 (defun archive-arc-summarize ()
|
|
1127 (let ((p 1)
|
|
1128 (totalsize 0)
|
|
1129 (maxlen 8)
|
|
1130 files
|
|
1131 visual)
|
|
1132 (while (and (< (+ p 29) (point-max))
|
163
|
1133 (eq (char-after p) ?\C-z)
|
0
|
1134 (> (char-after (1+ p)) 0))
|
|
1135 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13)))
|
|
1136 (fnlen (or (string-match "\0" namefld) 13))
|
|
1137 (efnname (substring namefld 0 fnlen))
|
|
1138 (csize (archive-l-e (+ p 15) 4))
|
|
1139 (moddate (archive-l-e (+ p 19) 2))
|
|
1140 (modtime (archive-l-e (+ p 21) 2))
|
|
1141 (ucsize (archive-l-e (+ p 25) 4))
|
|
1142 (fiddle (string= efnname (upcase efnname)))
|
|
1143 (ifnname (if fiddle (downcase efnname) efnname))
|
|
1144 (text (format " %8d %-11s %-8s %s"
|
|
1145 ucsize
|
|
1146 (archive-dosdate moddate)
|
|
1147 (archive-dostime modtime)
|
|
1148 ifnname)))
|
|
1149 (setq maxlen (max maxlen fnlen)
|
|
1150 totalsize (+ totalsize ucsize)
|
|
1151 visual (cons (vector text
|
|
1152 (- (length text) (length ifnname))
|
|
1153 (length text))
|
|
1154 visual)
|
|
1155 files (cons (vector efnname ifnname fiddle nil (1- p))
|
|
1156 files)
|
|
1157 p (+ p 29 csize))))
|
|
1158 (goto-char (point-min))
|
|
1159 (let ((dash (concat "- -------- ----------- -------- "
|
|
1160 (make-string maxlen ?-)
|
|
1161 "\n")))
|
|
1162 (insert "M Length Date Time File\n"
|
|
1163 dash)
|
|
1164 (archive-summarize-files (nreverse visual))
|
|
1165 (insert dash
|
|
1166 (format " %8d %d file%s"
|
|
1167 totalsize
|
|
1168 (length files)
|
|
1169 (if (= 1 (length files)) "" "s"))
|
|
1170 "\n"))
|
|
1171 (apply 'vector (nreverse files))))
|
|
1172
|
|
1173 (defun archive-arc-rename-entry (archive newname descr)
|
|
1174 (if (string-match "[:\\\\/]" newname)
|
|
1175 (error "File names in arc files may not contain a path"))
|
|
1176 (if (> (length newname) 12)
|
|
1177 (error "File names in arc files are limited to 12 characters"))
|
|
1178 (let ((name (concat newname (substring "\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|
1179 (length newname))))
|
|
1180 buffer-read-only)
|
|
1181 (save-restriction
|
|
1182 (save-excursion
|
|
1183 (widen)
|
|
1184 (goto-char (+ archive-proper-file-start (aref descr 4) 2))
|
|
1185 (delete-char 13)
|
|
1186 (insert name)))))
|
|
1187 ;; -------------------------------------------------------------------------
|
|
1188 ;; Section: Lzh Archives
|
|
1189
|
|
1190 (defun archive-lzh-summarize ()
|
|
1191 (let ((p 1)
|
|
1192 (totalsize 0)
|
|
1193 (maxlen 8)
|
|
1194 files
|
|
1195 visual)
|
|
1196 (while (progn (goto-char p) (looking-at "..-l[hz][0-9]-"))
|
|
1197 (let* ((hsize (char-after p))
|
|
1198 (csize (archive-l-e (+ p 7) 4))
|
|
1199 (ucsize (archive-l-e (+ p 11) 4))
|
|
1200 (modtime (archive-l-e (+ p 15) 2))
|
|
1201 (moddate (archive-l-e (+ p 17) 2))
|
|
1202 (fnlen (char-after (+ p 21)))
|
|
1203 (efnname (buffer-substring (+ p 22) (+ p 22 fnlen)))
|
|
1204 (fiddle (string= efnname (upcase efnname)))
|
|
1205 (ifnname (if fiddle (downcase efnname) efnname))
|
|
1206 (p2 (+ p 22 fnlen))
|
|
1207 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0))
|
163
|
1208 (mode (if (eq creator ?U) (archive-l-e (+ p2 8) 2) ?\666))
|
0
|
1209 (modestr (if mode (archive-int-to-mode mode) "??????????"))
|
163
|
1210 (uid (if (eq creator ?U) (archive-l-e (+ p2 10) 2)))
|
|
1211 (gid (if (eq creator ?U) (archive-l-e (+ p2 12) 2)))
|
0
|
1212 (text (if archive-alternate-display
|
|
1213 (format " %8d %5S %5S %s"
|
|
1214 ucsize
|
|
1215 (or uid "?")
|
|
1216 (or gid "?")
|
|
1217 ifnname)
|
|
1218 (format " %10s %8d %-11s %-8s %s"
|
|
1219 modestr
|
|
1220 ucsize
|
|
1221 (archive-dosdate moddate)
|
|
1222 (archive-dostime modtime)
|
|
1223 ifnname))))
|
|
1224 (setq maxlen (max maxlen fnlen)
|
|
1225 totalsize (+ totalsize ucsize)
|
|
1226 visual (cons (vector text
|
|
1227 (- (length text) (length ifnname))
|
|
1228 (length text))
|
|
1229 visual)
|
|
1230 files (cons (vector efnname ifnname fiddle mode (1- p))
|
|
1231 files)
|
|
1232 p (+ p hsize 2 csize))))
|
|
1233 (goto-char (point-min))
|
|
1234 (let ((dash (concat (if archive-alternate-display
|
|
1235 "- -------- ----- ----- "
|
|
1236 "- ---------- -------- ----------- -------- ")
|
|
1237 (make-string maxlen ?-)
|
|
1238 "\n"))
|
|
1239 (header (if archive-alternate-display
|
|
1240 "M Length Uid Gid File\n"
|
|
1241 "M Filemode Length Date Time File\n"))
|
|
1242 (sumline (if archive-alternate-display
|
|
1243 " %8d %d file%s"
|
|
1244 " %8d %d file%s")))
|
|
1245 (insert header dash)
|
|
1246 (archive-summarize-files (nreverse visual))
|
|
1247 (insert dash
|
|
1248 (format sumline
|
|
1249 totalsize
|
|
1250 (length files)
|
|
1251 (if (= 1 (length files)) "" "s"))
|
|
1252 "\n"))
|
|
1253 (apply 'vector (nreverse files))))
|
|
1254
|
|
1255 (defconst archive-lzh-alternate-display t)
|
|
1256
|
|
1257 (defun archive-lzh-extract (archive name)
|
|
1258 (archive-extract-by-stdout archive name archive-lzh-extract))
|
|
1259
|
|
1260 (defun archive-lzh-resum (p count)
|
|
1261 (let ((sum 0))
|
|
1262 (while (> count 0)
|
|
1263 (setq count (1- count)
|
|
1264 sum (+ sum (char-after p))
|
|
1265 p (1+ p)))
|
|
1266 (logand sum 255)))
|
|
1267
|
|
1268 (defun archive-lzh-rename-entry (archive newname descr)
|
|
1269 (save-restriction
|
|
1270 (save-excursion
|
|
1271 (widen)
|
|
1272 (let* ((p (+ archive-proper-file-start (aref descr 4)))
|
|
1273 (oldhsize (char-after p))
|
|
1274 (oldfnlen (char-after (+ p 21)))
|
|
1275 (newfnlen (length newname))
|
|
1276 (newhsize (+ oldhsize newfnlen (- oldfnlen)))
|
|
1277 buffer-read-only)
|
|
1278 (if (> newhsize 255)
|
|
1279 (error "The file name is too long"))
|
|
1280 (goto-char (+ p 21))
|
|
1281 (delete-char (1+ oldfnlen))
|
|
1282 (insert newfnlen newname)
|
|
1283 (goto-char p)
|
|
1284 (delete-char 2)
|
|
1285 (insert newhsize (archive-lzh-resum p newhsize))))))
|
|
1286
|
|
1287 (defun archive-lzh-ogm (newval files errtxt ofs)
|
|
1288 (save-restriction
|
|
1289 (save-excursion
|
|
1290 (widen)
|
|
1291 (while files
|
|
1292 (let* ((fil (car files))
|
|
1293 (p (+ archive-proper-file-start (aref fil 4)))
|
|
1294 (hsize (char-after p))
|
|
1295 (fnlen (char-after (+ p 21)))
|
|
1296 (p2 (+ p 22 fnlen))
|
|
1297 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0))
|
|
1298 buffer-read-only)
|
|
1299 (if (= creator ?U)
|
|
1300 (progn
|
|
1301 (or (numberp newval)
|
|
1302 (setq newval (funcall newval (archive-l-e (+ p2 ofs) 2))))
|
|
1303 (goto-char (+ p2 ofs))
|
|
1304 (delete-char 2)
|
|
1305 (insert (logand newval 255) (lsh newval -8))
|
|
1306 (goto-char (1+ p))
|
|
1307 (delete-char 1)
|
|
1308 (insert (archive-lzh-resum (1+ p) hsize)))
|
|
1309 (message "Member %s does not have %s field"
|
|
1310 (aref fil 1) errtxt)))
|
|
1311 (setq files (cdr files))))))
|
|
1312
|
|
1313 (defun archive-lzh-chown-entry (newuid files)
|
|
1314 (archive-lzh-ogm newuid files "an uid" 10))
|
|
1315
|
|
1316 (defun archive-lzh-chgrp-entry (newgid files)
|
|
1317 (archive-lzh-ogm newgid files "a gid" 12))
|
|
1318
|
|
1319 (defun archive-lzh-chmod-entry (newmode files)
|
|
1320 (archive-lzh-ogm
|
|
1321 ;; This should work even though newmode will be dynamically accessed.
|
|
1322 (function (lambda (old) (archive-calc-mode old newmode t)))
|
|
1323 files "a unix-style mode" 8))
|
|
1324 ;; -------------------------------------------------------------------------
|
|
1325 ;; Section: Zip Archives
|
|
1326
|
|
1327 (defun archive-zip-summarize ()
|
|
1328 (goto-char (- (point-max) (- 22 18)))
|
|
1329 (search-backward-regexp "[P]K\005\006")
|
|
1330 (let ((p (1+ (archive-l-e (+ (point) 16) 4)))
|
|
1331 (maxlen 8)
|
|
1332 (totalsize 0)
|
|
1333 files
|
|
1334 visual)
|
|
1335 (while (string= "PK\001\002" (buffer-substring p (+ p 4)))
|
|
1336 (let* ((creator (char-after (+ p 5)))
|
|
1337 (method (archive-l-e (+ p 10) 2))
|
|
1338 (modtime (archive-l-e (+ p 12) 2))
|
|
1339 (moddate (archive-l-e (+ p 14) 2))
|
|
1340 (ucsize (archive-l-e (+ p 24) 4))
|
|
1341 (fnlen (archive-l-e (+ p 28) 2))
|
|
1342 (exlen (archive-l-e (+ p 30) 2))
|
|
1343 (fclen (archive-l-e (+ p 32) 2))
|
|
1344 (lheader (archive-l-e (+ p 42) 4))
|
|
1345 (efnname (buffer-substring (+ p 46) (+ p 46 fnlen)))
|
|
1346 (isdir (and (= ucsize 0)
|
|
1347 (string= (file-name-nondirectory efnname) "")))
|
163
|
1348 (mode (cond ((memq (char-int creator) '(2 3)) ; Unix + VMS
|
0
|
1349 (archive-l-e (+ p 40) 2))
|
163
|
1350 ((memq (char-int creator)
|
|
1351 '(0 5 6 7 10 11)) ; Dos etc.
|
0
|
1352 (logior ?\444
|
|
1353 (if isdir (logior 16384 ?\111) 0)
|
|
1354 (if (zerop
|
|
1355 (logand 1 (char-after (+ p 38))))
|
|
1356 ?\222 0)))
|
|
1357 (t nil)))
|
|
1358 (modestr (if mode (archive-int-to-mode mode) "??????????"))
|
|
1359 (fiddle (and archive-zip-case-fiddle
|
163
|
1360 (not (not (memq (char-int creator) '(0 2 4 5 9))))))
|
0
|
1361 (ifnname (if fiddle (downcase efnname) efnname))
|
|
1362 (text (format " %10s %8d %-11s %-8s %s"
|
|
1363 modestr
|
|
1364 ucsize
|
|
1365 (archive-dosdate moddate)
|
|
1366 (archive-dostime modtime)
|
|
1367 ifnname)))
|
|
1368 (setq maxlen (max maxlen fnlen)
|
|
1369 totalsize (+ totalsize ucsize)
|
|
1370 visual (cons (vector text
|
|
1371 (- (length text) (length ifnname))
|
|
1372 (length text))
|
|
1373 visual)
|
|
1374 files (cons (if isdir
|
|
1375 nil
|
|
1376 (vector efnname ifnname fiddle mode
|
|
1377 (list (1- p) lheader)))
|
|
1378 files)
|
|
1379 p (+ p 46 fnlen exlen fclen))))
|
|
1380 (goto-char (point-min))
|
|
1381 (let ((dash (concat "- ---------- -------- ----------- -------- "
|
|
1382 (make-string maxlen ?-)
|
|
1383 "\n")))
|
|
1384 (insert "M Filemode Length Date Time File\n"
|
|
1385 dash)
|
|
1386 (archive-summarize-files (nreverse visual))
|
|
1387 (insert dash
|
|
1388 (format " %8d %d file%s"
|
|
1389 totalsize
|
|
1390 (length files)
|
|
1391 (if (= 1 (length files)) "" "s"))
|
|
1392 "\n"))
|
|
1393 (apply 'vector (nreverse files))))
|
|
1394
|
|
1395 (defun archive-zip-extract (archive name)
|
|
1396 (if archive-zip-use-pkzip
|
|
1397 (archive-*-extract archive name archive-zip-extract)
|
|
1398 (archive-extract-by-stdout archive name archive-zip-extract)))
|
|
1399
|
|
1400 (defun archive-zip-write-file-member (archive descr)
|
|
1401 (archive-*-write-file-member
|
|
1402 archive
|
|
1403 descr
|
|
1404 (if (aref descr 2) archive-zip-update-case archive-zip-update)))
|
|
1405
|
|
1406 (defun archive-zip-chmod-entry (newmode files)
|
|
1407 (save-restriction
|
|
1408 (save-excursion
|
|
1409 (widen)
|
|
1410 (while files
|
|
1411 (let* ((fil (car files))
|
|
1412 (p (+ archive-proper-file-start (car (aref fil 4))))
|
|
1413 (creator (char-after (+ p 5)))
|
|
1414 (oldmode (aref fil 3))
|
|
1415 (newval (archive-calc-mode oldmode newmode t))
|
|
1416 buffer-read-only)
|
163
|
1417 (cond ((memq (char-int creator) '(2 3)) ; Unix + VMS
|
0
|
1418 (goto-char (+ p 40))
|
|
1419 (delete-char 2)
|
|
1420 (insert (logand newval 255) (lsh newval -8)))
|
163
|
1421 ((memq (char-int creator) '(0 5 6 7 10 11)) ; Dos etc.
|
0
|
1422 (goto-char (+ p 38))
|
|
1423 (insert (logior (logand (char-after (point)) 254)
|
|
1424 (logand (logxor 1 (lsh newval -7)) 1)))
|
|
1425 (delete-char 1))
|
|
1426 (t (message "Don't know how to change mode for this member"))))
|
|
1427 (setq files (cdr files))))))
|
|
1428 ;; -------------------------------------------------------------------------
|
|
1429 ;; Section: Zoo Archives
|
|
1430
|
|
1431 (defun archive-zoo-summarize ()
|
|
1432 (let ((p (1+ (archive-l-e 25 4)))
|
|
1433 (maxlen 8)
|
|
1434 (totalsize 0)
|
|
1435 files
|
|
1436 visual)
|
|
1437 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4)))
|
|
1438 (> (archive-l-e (+ p 6) 4) 0))
|
|
1439 (let* ((next (1+ (archive-l-e (+ p 6) 4)))
|
|
1440 (moddate (archive-l-e (+ p 14) 2))
|
|
1441 (modtime (archive-l-e (+ p 16) 2))
|
|
1442 (ucsize (archive-l-e (+ p 20) 4))
|
|
1443 (namefld (buffer-substring (+ p 38) (+ p 38 13)))
|
|
1444 (dirtype (char-after (+ p 4)))
|
|
1445 (lfnlen (if (= dirtype 2) (char-after (+ p 56)) 0))
|
|
1446 (ldirlen (if (= dirtype 2) (char-after (+ p 57)) 0))
|
|
1447 (fnlen (+ ldirlen
|
|
1448 (if (> lfnlen 0)
|
|
1449 (1- lfnlen)
|
|
1450 (or (string-match "\0" namefld) 13))))
|
|
1451 (efnname (concat
|
|
1452 (if (> ldirlen 0)
|
|
1453 (concat (buffer-substring
|
|
1454 (+ p 58 lfnlen) (+ p 58 lfnlen ldirlen -1))
|
|
1455 "/")
|
|
1456 "")
|
|
1457 (if (> lfnlen 0)
|
|
1458 (buffer-substring (+ p 58) (+ p 58 lfnlen -1))
|
|
1459 (substring namefld 0 fnlen))))
|
|
1460 (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname))))
|
|
1461 (ifnname (if fiddle (downcase efnname) efnname))
|
|
1462 (text (format " %8d %-11s %-8s %s"
|
|
1463 ucsize
|
|
1464 (archive-dosdate moddate)
|
|
1465 (archive-dostime modtime)
|
|
1466 ifnname)))
|
|
1467 (setq maxlen (max maxlen fnlen)
|
|
1468 totalsize (+ totalsize ucsize)
|
|
1469 visual (cons (vector text
|
|
1470 (- (length text) (length ifnname))
|
|
1471 (length text))
|
|
1472 visual)
|
|
1473 files (cons (vector efnname ifnname fiddle nil (1- p))
|
|
1474 files)
|
|
1475 p next)))
|
|
1476 (goto-char (point-min))
|
|
1477 (let ((dash (concat "- -------- ----------- -------- "
|
|
1478 (make-string maxlen ?-)
|
|
1479 "\n")))
|
|
1480 (insert "M Length Date Time File\n"
|
|
1481 dash)
|
|
1482 (archive-summarize-files (nreverse visual))
|
|
1483 (insert dash
|
|
1484 (format " %8d %d file%s"
|
|
1485 totalsize
|
|
1486 (length files)
|
|
1487 (if (= 1 (length files)) "" "s"))
|
|
1488 "\n"))
|
|
1489 (apply 'vector (nreverse files))))
|
|
1490
|
|
1491 (defun archive-zoo-extract (archive name)
|
|
1492 (archive-extract-by-stdout archive name archive-zoo-extract))
|
|
1493 ;; -------------------------------------------------------------------------
|
|
1494 (provide 'archive-mode)
|
|
1495
|
|
1496 ;; arc-mode.el ends here.
|