1 ;;; arc-mode.el --- simple editing of archives
3 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;; Author: Morten Welinder (terra@diku.dk)
6 ;; Keywords: archives msdog editing major-mode
7 ;; Favourite-brand-of-beer: None, I hate beer.
9 ;;; This file is part of GNU Emacs.
11 ;;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;;; it under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 2, or (at your option)
14 ;;; any later version.
16 ;;; GNU Emacs is distributed in the hope that it will be useful,
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;; NAMING: "arc" is short for "archive" and does not refer specifically
28 ;; to files whose name end in ".arc"
30 ;; This code does not decode any files internally, although it does
31 ;; understand the directory level of the archives. For this reason,
32 ;; you should expect this code to need more fiddling than tar-mode.el
33 ;; (although it at present has fewer bugs :-) In particular, I have
34 ;; not tested this under Ms-Dog myself.
35 ;; -------------------------------------
36 ;; INTERACTION: arc-mode.el should play together with
38 ;; * ange-ftp.el: Remote archives (i.e., ones that ange-ftp has brought
39 ;; to you) are handled by doing all updates on a local
40 ;; copy. When you make changes to a remote file the
41 ;; changes will first take effect when the archive buffer
42 ;; is saved. You will be warned about this.
44 ;; * dos-fns.el: (Part of Emacs 19). You get automatic ^M^J <--> ^J
47 ;; arc-mode.el does not work well with crypt++.el; for the archives as
48 ;; such this could be fixed (but wouldn't be useful) by declaring such
49 ;; archives to be "remote". For the members this is a general Emacs
50 ;; problem that 19.29's file formats may fix.
51 ;; -------------------------------------
52 ;; ARCHIVE TYPES: Currently only the archives below are handled, but the
53 ;; structure for handling just about anything is in place.
56 ;; --------------------------------
57 ;; View listing Intern Intern Intern Intern
58 ;; Extract member Y Y Y Y
59 ;; Save changed member Y Y Y Y
60 ;; Add new member N N N N
61 ;; Delete member Y Y Y Y
62 ;; Rename member Y Y N N
67 ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips
68 ;; on the first released version of this package.
70 ;; This code is partly based on tar-mode.el from Emacs.
71 ;; -------------------------------------
72 ;; ARCHIVE STRUCTURES:
73 ;; (This is mostly for myself.)
75 ;; ARC A series of (header,file). No interactions among members.
77 ;; LZH A series of (header,file). Headers are checksummed. No
78 ;; interaction among members.
80 ;; ZIP A series of (lheader,fil) followed by a "central directory"
81 ;; which is a series of (cheader) followed by an end-of-
82 ;; central-dir record possibly followed by junk. The e-o-c-d
83 ;; links to c-d. cheaders link to lheaders which are basically
84 ;; cut-down versions of the cheaders.
86 ;; ZOO An archive header followed by a series of (header,file).
87 ;; Each member header points to the next. The archive is
88 ;; terminated by a bogus header with a zero next link.
89 ;; -------------------------------------
90 ;; HOOKS: `foo' means one the the supported archive types.
93 ;; archive-foo-mode-hook
94 ;; archive-extract-hooks
98 ;; -------------------------------------------------------------------------
99 ;; Section: Configuration.
101 (defvar archive-dos-members t
102 "*If non-nil then recognize member files using ^M^J as line terminator
103 and do The Right Thing.")
105 (defvar archive-tmpdir
107 (make-temp-name (if (eq system-type
'ms-dos
) "ar" "archive.tmp"))
108 (or (getenv "TMPDIR") (getenv "TMP") "/tmp"))
109 "*Directory for temporary files made by arc-mode.el")
111 (defvar archive-remote-regexp
"^/[^/:]*[^/:]:"
112 "*Regexp recognizing archive files names that are not local (i.e., are
113 not proper file names outside Emacs). A local copy a the archive will
114 be used when updating.")
116 (defvar archive-extract-hooks nil
117 "*Hooks to run when an archive member has been extracted.")
118 ;; ------------------------------
119 ;; Arc archive configuration
121 ;; We always go via a local file since there seems to be no reliable way
122 ;; to extract to stdout without junk getting added.
123 (defvar archive-arc-extract
125 "*Program and its options to run in order to extract an arc file member
126 to the current directory. Archive and member name will be added.")
128 (defvar archive-arc-expunge
130 "*Program and its options to run in order to delete arc file members.
131 Archive and member names will be added.")
133 (defvar archive-arc-write-file-member
135 "*Program and its options to run in order to update an arc file member.
136 Archive and member name will be added.")
137 ;; ------------------------------
138 ;; Lzh archive configuration
140 (defvar archive-lzh-extract
142 "*Program and its options to run in order to extract an lzh file member
143 to standard output. Archive and member name will be added.")
145 (defvar archive-lzh-expunge
147 "*Program and its options to run in order to delete lzh file members.
148 Archive and member names will be added.")
150 (defvar archive-lzh-write-file-member
152 "*Program and its options to run in order to update an lzh file member.
153 Archive and member name will be added.")
154 ;; ------------------------------
155 ;; Zip archive configuration
157 (defvar archive-zip-use-pkzip
(memq system-type
'(ms-dos windows-nt
))
158 "*If non-nil then all zip options default to values suitable when using
159 pkzip and pkunzip. Only set to true for msdog systems!")
161 (defvar archive-zip-extract
162 (if archive-zip-use-pkzip
'("pkunzip" "-e") '("unzip" "-qq" "-c"))
163 "*Program and its options to run in order to extract a zip file member
164 to standard output. Archive and member name will be added.\n
165 If `archive-zip-use-pkzip' is non-nil then this program is expected to
166 extract to a file junking the directory part of the name.")
168 ;; For several reasons the latter behaviour is not desireable in general.
169 ;; (1) It uses more disk space. (2) Error checking is worse or non-
170 ;; existent. (3) It tends to do funny things with other systems' file
173 (defvar archive-zip-expunge
174 (if archive-zip-use-pkzip
'("pkzip" "-d") '("zip" "-d" "-q"))
175 "*Program and its options to run in order to delete zip file members.
176 Archive and member names will be added.")
178 (defvar archive-zip-update
179 (if archive-zip-use-pkzip
'("pkzip" "-u") '("zip" "-q"))
180 "*Program and its options to run in order to update a zip file member.
181 Options should ensure that specified directory will be put into the zip
182 file. Archive and member name will be added.")
184 (defvar archive-zip-update-case
185 (if archive-zip-use-pkzip archive-zip-update
'("zip" "-q" "-k"))
186 "*Program and its options to run in order to update a case fiddled
187 zip file member. Options should ensure that specified directory will
188 be put into the zip file. Archive and member name will be added.")
190 (defvar archive-zip-case-fiddle t
191 "*If non-nil then zip file members are mapped to lower case if created
192 by a system that under single case file names.")
193 ;; ------------------------------
194 ;; Zoo archive configuration
196 (defvar archive-zoo-extract
198 "*Program and its options to run in order to extract a zoo file member
199 to standard output. Archive and member name will be added.")
201 (defvar archive-zoo-expunge
203 "*Program and its options to run in order to delete zoo file members.
204 Archive and member names will be added.")
206 (defvar archive-zoo-write-file-member
208 "*Program and its options to run in order to update a zoo file member.
209 Archive and member name will be added.")
210 ;; -------------------------------------------------------------------------
211 ;; Section: Variables
213 (defvar archive-subtype nil
"*Symbol describing archive type.")
214 (defvar archive-file-list-start nil
"*Position of first contents line.")
215 (defvar archive-file-list-end nil
"*Position just after last contents line.")
216 (defvar archive-proper-file-start nil
"*Position of real archive's start.")
217 (defvar archive-read-only nil
"*Non-nil if the archive is read-only on disk.")
218 (defvar archive-remote nil
"*Non-nil if the archive is outside file system.")
219 (defvar archive-local-name nil
"*Name of local copy of remote archive.")
220 (defvar archive-mode-map nil
"*Local keymap for archive mode listings.")
221 (defvar archive-file-name-indent nil
"*Column where file names start.")
223 (defvar archive-alternate-display nil
224 "*Non-nil when alternate information is shown.")
225 (make-variable-buffer-local 'archive-alternate-display
)
226 (put 'archive-alternate-display
'permanent-local t
)
228 (defvar archive-superior-buffer nil
"*In archive members, points to archive.")
229 (put 'archive-superior-buffer
'permanent-local t
)
231 (defvar archive-subfile-mode nil
"*Non-nil in archive member buffers.")
232 (make-variable-buffer-local 'archive-subfile-mode
)
233 (put 'archive-subfile-mode
'permanent-local t
)
235 ;; buffer-file-type is a per-buffer variable in the msdog configuration
236 (if (boundp 'buffer-file-type
) nil
237 (defvar buffer-file-type nil
238 "*Nil for dos-style text file, non-nil otherwise.")
239 (make-variable-buffer-local 'buffer-file-type
)
240 (put 'buffer-file-type
'permanent-local t
)
241 (setq-default buffer-file-type nil
))
243 (defvar archive-subfile-dos nil
244 "Negation of `buffer-file-type' which see.")
245 (make-variable-buffer-local 'archive-subfile-dos
)
246 (put 'archive-subfile-dos
'permanent-local t
)
248 (defvar archive-files nil
"Vector of file descriptors. Each descriptor is
249 a vector of [ext-file-name int-file-name case-fiddled mode ...]")
250 (make-variable-buffer-local 'archive-files
)
252 (defvar archive-lemacs
253 (string-match "\\(Lucid\\|Xemacs\\)" emacs-version
)
254 "*Non-nil when running under under Lucid Emacs or Xemacs.")
255 ;; -------------------------------------------------------------------------
256 ;; Section: Support functions.
258 (defsubst archive-name
(suffix)
259 (intern (concat "archive-" (symbol-name archive-subtype
) "-" suffix
)))
261 (defun archive-l-e (str &optional len
)
262 "Convert little endian string/vector to integer. Alternatively, first
263 argument may be a buffer position in the current buffer in which case a
264 second arguemnt, length, should be supplied."
266 (setq len
(length str
))
267 (setq str
(buffer-substring str
(+ str len
))))
272 result
(+ (ash result
8) (aref str
(- len i
)))))
275 (defun archive-int-to-mode (mode)
276 "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------"
277 (let ((str (make-string 10 ?-
)))
278 (or (zerop (logand 16384 mode
)) (aset str
0 ?d
))
279 (or (zerop (logand 8192 mode
)) (aset str
0 ?c
)) ; completeness
280 (or (zerop (logand 256 mode
)) (aset str
1 ?r
))
281 (or (zerop (logand 128 mode
)) (aset str
2 ?w
))
282 (or (zerop (logand 64 mode
)) (aset str
3 ?x
))
283 (or (zerop (logand 32 mode
)) (aset str
4 ?r
))
284 (or (zerop (logand 16 mode
)) (aset str
5 ?w
))
285 (or (zerop (logand 8 mode
)) (aset str
6 ?x
))
286 (or (zerop (logand 4 mode
)) (aset str
7 ?r
))
287 (or (zerop (logand 2 mode
)) (aset str
8 ?w
))
288 (or (zerop (logand 1 mode
)) (aset str
9 ?x
))
289 (or (zerop (logand 1024 mode
)) (aset str
3 (if (zerop (logand 64 mode
))
291 (or (zerop (logand 2048 mode
)) (aset str
6 (if (zerop (logand 8 mode
))
295 (defun archive-calc-mode (oldmode newmode
&optional error
)
296 "From the integer OLDMODE and the string NEWMODE calculate a new file
298 NEWMODE may be an octal number including a leading zero in which case it
299 will become the new mode.\n
300 NEWMODE may also be a relative specification like \"og-rwx\" in which case
301 OLDMODE will be modified accordingly just like chmod(2) would have done.\n
302 If optional third argument ERROR is non-nil an error will be signaled if
303 the mode is invalid. If ERROR is nil then nil will be returned."
304 (cond ((string-match "^0[0-7]*$" newmode
)
306 (len (length newmode
))
309 (setq result
(+ (lsh result
3) (aref newmode i
) (- ?
0))
311 (logior (logand oldmode
65024) result
)))
312 ((string-match "^\\([agou]+\\)\\([---+=]\\)\\([rwxst]+\\)$" newmode
)
315 (op (aref newmode
(match-beginning 2)))
317 (i (match-beginning 3)))
318 (while (< i
(match-end 3))
319 (let ((rwx (aref newmode i
)))
320 (setq bits
(logior bits
(cond ((= rwx ?r
) 292)
326 (while (< who
(match-end 1))
327 (let* ((whoc (aref newmode who
))
328 (whomask (cond ((= whoc ?a
) 4095)
333 (setq result
(logand result
(lognot whomask
))))
335 (setq result
(logand result
(lognot (logand whomask bits
))))
336 (setq result
(logior result
(logand whomask bits
)))))
341 (error "Invalid mode specification: %s" newmode
)))))
343 (defun archive-dosdate (date)
344 "Stringify dos packed DATE record."
345 (let ((year (+ 1980 (logand (ash date -
9) 127)))
346 (month (logand (ash date -
5) 15))
347 (day (logand date
31)))
348 (if (or (> month
12) (< month
1))
352 (aref ["Jan" "Feb" "Mar" "Apr" "May" "Jun"
353 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"] (1- month
))
356 (defun archive-dostime (time)
357 "Stringify dos packed TIME record."
358 (let ((hour (logand (ash time -
11) 31))
359 (minute (logand (ash time -
5) 53))
360 (second (* 2 (logand time
31)))) ; 2 seconds resolution
361 (format "%02d:%02d:%02d" hour minute second
)))
363 ;;(defun archive-unixdate (low high)
364 ;; "Stringify unix (LOW HIGH) date."
365 ;; (let ((str (current-time-string (cons high low))))
366 ;; (format "%s-%s-%s"
367 ;; (substring str 8 9)
368 ;; (substring str 4 7)
369 ;; (substring str 20 24))))
371 ;;(defun archive-unixtime (low high)
372 ;; "Stringify unix (LOW HIGH) time."
373 ;; (let ((str (current-time-string (cons high low))))
374 ;; (substring str 11 19)))
376 (defun archive-get-lineno ()
377 (if (>= (point) archive-file-list-start
)
378 (count-lines archive-file-list-start
379 (save-excursion (beginning-of-line) (point)))
382 (defun archive-get-descr (&optional noerror
)
383 "Return the descriptor vector for file at point. Do not signal an error
384 if optional second argument NOERROR is non-nil."
385 (let ((no (archive-get-lineno)))
386 (if (and (>= (point) archive-file-list-start
)
387 (< no
(length archive-files
)))
388 (let ((item (aref archive-files no
)))
392 (error "Entry is not a regular member of the archive"))))
394 (error "Line does not describe a member of the archive")))))
395 ;; -------------------------------------------------------------------------
396 ;; Section: the mode definition
399 (defun archive-mode (&optional force
)
400 "Major mode for viewing an archive file as a dired-like listing of its
401 contents. You can move around using the usual cursor motion commands.
402 Letters no longer insert themselves.
403 Type `e' to pull a file out of the archive and into its own buffer;
404 or click mouse-2 on the file's line in the archive mode buffer.
406 If you edit a sub-file of this archive (as with the `e' command) and
407 save it, the contents of that buffer will be saved back into the
410 \\{archive-mode-map}"
411 ;; This is not interactive because you shouldn't be turning this
412 ;; mode on and off. You can corrupt things that way.
413 (if (zerop (buffer-size))
414 ;; At present we cannot create archives from scratch
415 (funcall default-major-mode
)
416 (if (and (not force
) archive-files
) nil
417 (let* ((type (archive-find-type))
418 (typename (copy-sequence (symbol-name type
))))
419 (aset typename
0 (upcase (aref typename
0)))
420 (kill-all-local-variables)
421 (make-local-variable 'archive-subtype
)
422 (setq archive-subtype type
)
424 ;; Buffer contains treated image of file before the file contents
425 (make-local-variable 'revert-buffer-function
)
426 (setq revert-buffer-function
'archive-mode-revert
)
428 (make-local-variable 'local-write-file-hooks
)
429 (add-hook 'local-write-file-hooks
'archive-write-file
)
431 ;; Real file contents is binary
432 (make-local-variable 'require-final-newline
)
433 (setq require-final-newline nil
)
434 (make-local-variable 'enable-local-variables
)
435 (setq enable-local-variables nil
)
436 (setq buffer-file-type t
)
438 (make-local-variable 'archive-read-only
)
439 (setq archive-read-only
(not (file-writable-p (buffer-file-name))))
441 ;; Should we use a local copy when accessing from outside Emacs?
442 (make-local-variable 'archive-local-name
)
443 (make-local-variable 'archive-remote
)
444 (setq archive-remote
(string-match archive-remote-regexp
447 (setq major-mode
'archive-mode
)
448 (setq mode-name
(concat typename
"-Archive"))
449 ;; Run archive-foo-mode-hook and archive-mode-hook
450 (run-hooks (archive-name "mode-hook") 'archive-mode-hook
)
451 (use-local-map archive-mode-map
))
453 (make-local-variable 'archive-proper-file-start
)
454 (make-local-variable 'archive-file-list-start
)
455 (make-local-variable 'archive-file-list-end
)
456 (make-local-variable 'archive-file-name-indent
)
458 (setq buffer-read-only t
))))
460 ;; Archive mode is suitable only for specially formatted data.
461 (put 'archive-mode
'mode-class
'special
)
462 ;; -------------------------------------------------------------------------
465 (if archive-mode-map nil
466 (setq archive-mode-map
(make-keymap))
467 (suppress-keymap archive-mode-map
)
468 (define-key archive-mode-map
" " 'archive-next-line
)
469 (define-key archive-mode-map
"a" 'archive-alternate-display
)
470 ;;(define-key archive-mode-map "c" 'archive-copy)
471 (define-key archive-mode-map
"d" 'archive-flag-deleted
)
472 (define-key archive-mode-map
"\C-d" 'archive-flag-deleted
)
473 (define-key archive-mode-map
"e" 'archive-extract
)
474 (define-key archive-mode-map
"f" 'archive-extract
)
475 (define-key archive-mode-map
"\C-m" 'archive-extract
)
476 (define-key archive-mode-map
"g" 'revert-buffer
)
477 (define-key archive-mode-map
"h" 'describe-mode
)
478 (define-key archive-mode-map
"m" 'archive-mark
)
479 (define-key archive-mode-map
"n" 'archive-next-line
)
480 (define-key archive-mode-map
"\C-n" 'archive-next-line
)
481 (define-key archive-mode-map
[down] 'archive-next-line)
482 (define-key archive-mode-map "o" 'archive-extract-other-window)
483 (define-key archive-mode-map "p" 'archive-previous-line)
484 (define-key archive-mode-map "\C-p" 'archive-previous-line)
485 (define-key archive-mode-map [up] 'archive-previous-line)
486 (define-key archive-mode-map "r" 'archive-rename-entry)
487 (define-key archive-mode-map "u" 'archive-unflag)
488 (define-key archive-mode-map "\M-\C-?" 'archive-unmark-all-files)
489 (define-key archive-mode-map "v" 'archive-view)
490 (define-key archive-mode-map "x" 'archive-expunge)
491 (define-key archive-mode-map "\177" 'archive-unflag-backwards)
492 (define-key archive-mode-map "E" 'archive-extract-other-window)
493 (define-key archive-mode-map "M" 'archive-chmod-entry)
494 (define-key archive-mode-map "G" 'archive-chgrp-entry)
495 (define-key archive-mode-map "O" 'archive-chown-entry)
499 ;; Not a nice "solution" but it'll have to do
500 (define-key archive-mode-map "\C-xu" 'archive-undo)
501 (define-key archive-mode-map "\C-_" 'archive-undo))
502 (substitute-key-definition 'undo 'archive-undo
503 archive-mode-map global-map))
505 (define-key archive-mode-map
506 (if archive-lemacs 'button2 [mouse-2]) 'archive-mouse-extract)
510 ;; Get rid of the Edit menu bar item to save space.
511 (define-key archive-mode-map [menu-bar edit] 'undefined)
513 (define-key archive-mode-map [menu-bar immediate]
514 (cons "Immediate" (make-sparse-keymap "Immediate")))
515 (define-key archive-mode-map [menu-bar immediate alternate]
516 '("Alternate Display" . archive-alternate-display))
517 (put 'archive-alternate-display 'menu-enable
518 '(boundp (archive-name "alternate-display")))
519 (define-key archive-mode-map [menu-bar immediate view]
520 '("View This File" . archive-view))
521 (define-key archive-mode-map [menu-bar immediate display]
522 '("Display in Other Window" . archive-display-other-window))
523 (define-key archive-mode-map [menu-bar immediate find-file-other-window]
524 '("Find in Other Window" . archive-extract-other-window))
525 (define-key archive-mode-map [menu-bar immediate find-file]
526 '("Find This File" . archive-extract))
528 (define-key archive-mode-map [menu-bar mark]
529 (cons "Mark" (make-sparse-keymap "Mark")))
530 (define-key archive-mode-map [menu-bar mark unmark-all]
531 '("Unmark All" . archive-unmark-all-files))
532 (define-key archive-mode-map [menu-bar mark deletion]
533 '("Flag" . archive-flag-deleted))
534 (define-key archive-mode-map [menu-bar mark unmark]
535 '("Unflag" . archive-unflag))
536 (define-key archive-mode-map [menu-bar mark mark]
537 '("Mark" . archive-mark))
539 (define-key archive-mode-map [menu-bar operate]
540 (cons "Operate" (make-sparse-keymap "Operate")))
541 (define-key archive-mode-map [menu-bar operate chown]
542 '("Change Owner..." . archive-chown-entry))
543 (put 'archive-chown-entry 'menu-enable
544 '(fboundp (archive-name "chown-entry")))
545 (define-key archive-mode-map [menu-bar operate chgrp]
546 '("Change Group..." . archive-chgrp-entry))
547 (put 'archive-chgrp-entry 'menu-enable
548 '(fboundp (archive-name "chgrp-entry")))
549 (define-key archive-mode-map [menu-bar operate chmod]
550 '("Change Mode..." . archive-chmod-entry))
551 (put 'archive-chmod-entry 'menu-enable
552 '(fboundp (archive-name "chmod-entry")))
553 (define-key archive-mode-map [menu-bar operate rename]
554 '("Rename to..." . archive-rename-entry))
555 (put 'archive-rename-entry 'menu-enable
556 '(fboundp (archive-name "rename-entry")))
557 ;;(define-key archive-mode-map [menu-bar operate copy]
558 ;; '("Copy to..." . archive-copy))
559 (define-key archive-mode-map [menu-bar operate expunge]
560 '("Expunge Marked Files" . archive-expunge))
563 (let* ((item1 '(archive-subfile-mode " Archive"))
564 (item2 '(archive-subfile-dos " Dos"))
565 (items (if (memq system-type '(ms-dos windows-nt))
566 (list item1) ; msdog has its own indicator
567 (list item1 item2))))
568 (or (member item1 minor-mode-alist)
569 (setq minor-mode-alist (append items minor-mode-alist))))
570 ;; -------------------------------------------------------------------------
571 (defun archive-find-type ()
573 (goto-char (point-min))
574 ;; The funny [] here make it unlikely that the .elc file will be treated
575 ;; as an archive by other software.
576 (let (case-fold-search)
577 (cond ((looking-at "[P]K\003\004") 'zip)
578 ((looking-at "..-l[hz][0-9]-") 'lzh)
579 ((looking-at "....................[\334]\247\304\375") 'zoo)
580 ((and (looking-at "\C-z") ; signature too simple, IMHO
581 (string-match "\\.[aA][rR][cC]$"
582 (or buffer-file-name (buffer-name))))
584 (t (error "Buffer format not recognized.")))))
585 ;; -------------------------------------------------------------------------
586 (defun archive-summarize ()
587 "Parse the contents of the archive file in the current buffer.
588 Place a dired-like listing on the front;
589 then narrow to it, so that only that listing
590 is visible (and the real data of the buffer is hidden)."
592 (let (buffer-read-only)
593 (message "Parsing archive file...")
594 (buffer-disable-undo (current-buffer))
595 (setq archive-files (funcall (archive-name "summarize")))
596 (message "Parsing archive file...done.")
597 (setq archive-proper-file-start (point-marker))
598 (narrow-to-region (point-min) (point))
599 (set-buffer-modified-p nil)
600 (buffer-enable-undo))
601 (goto-char archive-file-list-start)
602 (archive-next-line 0))
604 (defun archive-resummarize ()
605 "Recreate the contents listing of an archive."
606 (let ((modified (buffer-modified-p))
607 (no (archive-get-lineno))
610 (delete-region (point-min) archive-proper-file-start)
612 (set-buffer-modified-p modified)
613 (goto-char archive-file-list-start)
614 (archive-next-line no)))
616 (defun archive-summarize-files (files)
617 "Insert a desciption of a list of files annotated with proper mouse face"
618 (setq archive-file-list-start (point-marker))
619 (setq archive-file-name-indent (if files (aref (car files) 1) 0))
620 ;; We don't want to do an insert for each element since that takes too
621 ;; long when the archive -- which has to be moved in memory -- is large.
628 ;; Using `concat' here copies the text also, so we can add
629 ;; properties without problems.
630 (let ((text (concat (aref fil 0) "\n")))
633 (put-text-property (aref fil 1) (aref fil 2)
634 'mouse-face 'highlight
638 (setq archive-file-list-end (point-marker)))
640 (defun archive-alternate-display ()
641 "Toggle alternative display. To avoid very long lines some archive mode
642 don't show all information. This function changes the set of information
643 shown for each files."
645 (setq archive-alternate-display (not archive-alternate-display))
646 (archive-resummarize))
647 ;; -------------------------------------------------------------------------
648 ;; Section: Local archive copy handling
650 (defun archive-maybe-copy (archive)
652 (let ((start (point-max)))
653 (setq archive-local-name (expand-file-name
654 (file-name-nondirectory archive)
656 (make-directory archive-tmpdir t)
659 (write-region start (point-max) archive-local-name nil 'nomessage))
661 (if (buffer-modified-p) (save-buffer))
664 (defun archive-maybe-update (unchanged)
666 (let ((name archive-local-name)
667 (modified (buffer-modified-p))
671 (insert-file-contents name)
673 (archive-delete-local name)
675 (message "Archive file must be saved for changes to take effect"))
676 (set-buffer-modified-p (or modified (not unchanged))))))
678 (defun archive-delete-local (name)
679 "Delete (robust) the file NAME and its parents up to and including the
680 value of `archive-tmpdir'."
682 (top (directory-file-name (file-name-as-directory archive-tmpdir))))
687 (setq name (directory-file-name (file-name-directory name)))
689 (delete-directory name)
691 (if (string= name top) (setq again nil)))))
692 ;; -------------------------------------------------------------------------
693 ;; Section: Member extraction
695 (defun archive-mouse-extract (event)
696 "Extract a file whose name you click on."
698 (mouse-set-point event)
704 (defun archive-extract (&optional other-window-p)
705 "In archive mode, extract this entry of the archive into its own buffer."
707 (let* ((view-p (eq other-window-p 'view))
708 (descr (archive-get-descr))
709 (ename (aref descr 0))
710 (iname (aref descr 1))
711 (archive-buffer (current-buffer))
712 (arcdir default-directory)
713 (archive (buffer-file-name))
714 (arcname (file-name-nondirectory archive))
715 (bufname (concat (file-name-nondirectory iname) " (" arcname ")"))
716 (extractor (archive-name "extract"))
717 (read-only-p (or archive-read-only view-p))
718 (buffer (get-buffer bufname))
722 (setq archive (archive-maybe-copy archive))
723 (setq buffer (get-buffer-create bufname))
724 (setq just-created t)
727 (setq buffer-file-name
728 (expand-file-name (concat arcname ":" iname)))
729 (setq buffer-file-truename
730 (abbreviate-file-name buffer-file-name))
731 ;; Set the default-directory to the dir of the superior buffer.
732 (setq default-directory arcdir)
733 (make-local-variable 'archive-superior-buffer)
734 (setq archive-superior-buffer archive-buffer)
735 (make-local-variable 'local-write-file-hooks)
736 (add-hook 'local-write-file-hooks 'archive-write-file-member)
737 (setq archive-subfile-mode descr)
738 (setq archive-subfile-dos nil
740 (if (fboundp extractor)
741 (funcall extractor archive ename)
742 (archive-*-extract archive ename (symbol-value extractor)))
743 (if archive-dos-members (archive-check-dos))
744 (goto-char (point-min))
745 (rename-buffer bufname)
746 (setq buffer-read-only read-only-p)
747 (setq buffer-undo-list nil)
748 (set-buffer-modified-p nil)
749 (setq buffer-saved-size (buffer-size))
751 ;; Just in case an archive occurs inside another archive.
752 (if (eq major-mode 'archive-mode)
753 (setq archive-remote t))
754 (run-hooks 'archive-extract-hooks))
755 (archive-maybe-update t))
759 (and just-created (setq view-exit-action 'kill-buffer)))
760 (if (eq other-window-p 'display)
761 (display-buffer buffer)
763 (switch-to-buffer-other-window buffer)
764 (switch-to-buffer buffer))))))
766 (defun archive-*-extract (archive name command)
767 (let* ((default-directory (file-name-as-directory archive-tmpdir))
768 (tmpfile (expand-file-name (file-name-nondirectory name)
770 (make-directory (directory-file-name default-directory) t)
776 (append (cdr command) (list archive name)))
777 (insert-file-contents tmpfile)
778 (archive-delete-local tmpfile)))
780 (defun archive-extract-by-stdout (archive name command)
781 (let ((binary-process-output t)) ; for Ms-Dos
787 (append (cdr command) (list archive name)))))
789 (defun archive-extract-other-window ()
790 "In archive mode, find this member in another window."
794 (defun archive-display-other-window ()
795 "In archive mode, display this member in another window."
797 (archive-extract 'display))
799 (defun archive-view ()
800 "In archive mode, view the member on this line."
802 (archive-extract 'view))
804 (defun archive-add-new-member (arcbuf name)
805 "Add the file in the current buffer to the archive in ARCBUF naming it
809 (read-buffer "Buffer containing archive: "
810 ;; Find first archive buffer and suggest that
811 (let ((bufs (buffer-list)))
812 (while (and bufs (not (eq (save-excursion
813 (set-buffer (car bufs))
816 (setq bufs (cdr bufs)))
819 (error "There are no archive buffers")))
821 (read-string "File name in archive: "
823 (file-name-nondirectory buffer-file-name)
827 (or (eq major-mode 'archive-mode)
828 (error "Buffer is not an archive buffer"))
829 (if archive-read-only
830 (error "Archive is read-only")))
831 (if (eq arcbuf (current-buffer))
832 (error "An archive buffer cannot be added to itself"))
833 (if (string= name "")
834 (error "Archive members may not be given empty names"))
835 (let ((func (save-excursion (set-buffer arcbuf)
836 (archive-name "add-new-member")))
837 (membuf (current-buffer)))
841 (funcall func buffer-file-name membuf name))
842 (error "Adding a new member is not supported for this archive type"))))
843 ;; -------------------------------------------------------------------------
846 (defun archive-check-dos (&optional force)
847 "*If this looks like a buffer with ^M^J as line terminator then remove
848 those ^Ms and set archive-subfile-dos."
852 (goto-char (point-min))
853 (setq archive-subfile-dos
854 (or force (not (search-forward-regexp "[^\r]\n" nil t))))
855 (setq buffer-file-type (not archive-subfile-dos))
856 (if archive-subfile-dos
857 (let ((modified (buffer-modified-p)))
858 (buffer-disable-undo (current-buffer))
859 (goto-char (point-min))
860 (while (search-forward "\r\n" nil t)
861 (replace-match "\n"))
863 (set-buffer-modified-p modified))))))
865 (defun archive-write-file-member ()
866 (if archive-subfile-dos
870 (goto-char (point-min))
871 ;; We don't want our ^M^J <--> ^J changes to show in the undo list
872 (let ((undo-list buffer-undo-list))
875 (setq buffer-undo-list t)
876 (while (search-forward "\n" nil t)
877 (replace-match "\r\n"))
878 (setq archive-subfile-dos nil)
879 (setq buffer-file-type t)
880 ;; OK, we're now have explicit ^M^Js -- save and re-unixfy
881 (archive-write-file-member))
883 (archive-check-dos t)
884 (setq buffer-undo-list undo-list))))
888 (message "Updating archive...")
890 (let ((writer (save-excursion (set-buffer archive-superior-buffer)
891 (archive-name "write-file-member")))
892 (archive (save-excursion (set-buffer archive-superior-buffer)
893 (buffer-file-name))))
895 (funcall writer archive archive-subfile-mode)
896 (archive-*-write-file-member archive
898 (symbol-value writer))))
899 (set-buffer-modified-p nil)
900 (message "Updating archive...done")
901 (set-buffer archive-superior-buffer)
905 (defun archive-*-write-file-member (archive descr command)
906 (let* ((ename (aref descr 0))
907 (tmpfile (expand-file-name ename archive-tmpdir))
908 (top (directory-file-name (file-name-as-directory archive-tmpdir)))
909 (default-directory (file-name-as-directory top)))
912 (make-directory (file-name-directory tmpfile) t)
913 (write-region (point-min) (point-max) tmpfile nil 'nomessage)
915 ;; Set the file modes, but make sure we can read it.
916 (set-file-modes tmpfile (logior ?\400 (aref descr 3))))
917 (let ((exitcode (apply 'call-process
922 (append (cdr command) (list archive ename)))))
923 (if (equal exitcode 0)
925 (error "Updating was unsuccessful (%S)" exitcode))))
926 (archive-delete-local tmpfile))))
928 (defun archive-write-file ()
930 (write-region archive-proper-file-start (point-max) buffer-file-name nil t)
931 (set-buffer-modified-p nil)
933 ;; -------------------------------------------------------------------------
934 ;; Section: Marking and unmarking.
936 (defun archive-flag-deleted (p &optional type)
937 "In archive mode, mark this member to be deleted from the archive.
938 With a prefix argument, mark that many files."
940 (or type (setq type ?D))
942 (let ((sign (if (>= p 0) +1 -1))
943 (modified (buffer-modified-p))
945 (while (not (zerop p))
946 (if (archive-get-descr t)
952 (set-buffer-modified-p modified))
953 (archive-next-line 0))
955 (defun archive-unflag (p)
956 "In archive mode, un-mark this member if it is marked to be deleted.
957 With a prefix argument, un-mark that many files forward."
959 (archive-flag-deleted p ? ))
961 (defun archive-unflag-backwards (p)
962 "In archive mode, un-mark this member if it is marked to be deleted.
963 With a prefix argument, un-mark that many members backward."
965 (archive-flag-deleted (- p) ? ))
967 (defun archive-unmark-all-files ()
970 (let ((modified (buffer-modified-p))
973 (goto-char archive-file-list-start)
974 (while (< (point) archive-file-list-end)
975 (or (= (following-char) ? )
976 (progn (delete-char 1) (insert ? )))
978 (set-buffer-modified-p modified)))
980 (defun archive-mark (p)
981 "In archive mode, mark this member for group operations.
982 With a prefix argument, mark that many members.
983 Use \\[archive-unmark-all-files] to remove all marks."
985 (archive-flag-deleted p ?*))
987 (defun archive-get-marked (mark &optional default)
990 (goto-char archive-file-list-start)
991 (while (< (point) archive-file-list-end)
992 (if (= (following-char) mark)
993 (setq files (cons (archive-get-descr) files)))
997 (list (archive-get-descr))))))
998 ;; -------------------------------------------------------------------------
1001 (defun archive-next-line (p)
1005 (forward-char archive-file-name-indent)))
1007 (defun archive-previous-line (p)
1009 (archive-next-line (- p)))
1011 (defun archive-chmod-entry (new-mode)
1012 "Change the protection bits associated with all marked or this member
1014 The new protection bits can either be specified as an octal number or
1015 as a relative change like \"g+rw\" as for chmod(2)"
1016 (interactive "sNew mode (octal or relative): ")
1017 (if archive-read-only (error "Archive is read-only"))
1018 (let ((func (archive-name "chmod-entry")))
1021 (funcall func new-mode (archive-get-marked ?* t))
1022 (archive-resummarize))
1023 (error "Setting mode bits is not supported for this archive type"))))
1025 (defun archive-chown-entry (new-uid)
1026 "Change the owner of all marked or this member."
1027 (interactive "nNew uid: ")
1028 (if archive-read-only (error "Archive is read-only"))
1029 (let ((func (archive-name "chown-entry")))
1032 (funcall func new-uid (archive-get-marked ?* t))
1033 (archive-resummarize))
1034 (error "Setting owner is not supported for this archive type"))))
1036 (defun archive-chgrp-entry (new-gid)
1037 "Change the group of all marked or this member."
1038 (interactive "nNew gid: ")
1039 (if archive-read-only (error "Archive is read-only"))
1040 (let ((func (archive-name "chgrp-entry")))
1043 (funcall func new-gid (archive-get-marked ?* t))
1044 (archive-resummarize))
1045 (error "Setting group is not supported for this archive type"))))
1047 (defun archive-expunge ()
1048 "Do the flagged deletions."
1052 (goto-char archive-file-list-start)
1053 (while (< (point) archive-file-list-end)
1054 (if (= (following-char) ?D)
1055 (setq files (cons (aref (archive-get-descr) 0) files)))
1057 (setq files (nreverse files))
1059 (or (not archive-read-only)
1060 (error "Archive is read-only"))
1061 (or (yes-or-no-p (format "Really delete %d member%s? "
1063 (if (null (cdr files)) "" "s")))
1064 (error "Operation aborted"))
1065 (let ((archive (archive-maybe-copy (buffer-file-name)))
1066 (expunger (archive-name "expunge")))
1067 (if (fboundp expunger)
1068 (funcall expunger archive files)
1069 (archive-*-expunge archive files (symbol-value expunger)))
1070 (archive-maybe-update nil)
1072 (archive-resummarize)
1073 (revert-buffer))))))
1075 (defun archive-*-expunge (archive files command)
1076 (apply 'call-process
1081 (append (cdr command) (cons archive files))))
1083 (defun archive-rename-entry (newname)
1084 "Change the name associated with this entry in the tar file."
1085 (interactive "sNew name: ")
1086 (if archive-read-only (error "Archive is read-only"))
1087 (if (string= newname "")
1088 (error "Archive members may not be given empty names"))
1089 (let ((func (archive-name "rename-entry"))
1090 (descr (archive-get-descr)))
1093 (funcall func (buffer-file-name) newname descr)
1094 (archive-resummarize))
1095 (error "Renaming is not supported for this archive type"))))
1097 ;; Revert the buffer and recompute the dired-like listing.
1098 (defun archive-mode-revert (&optional no-autosave no-confirm)
1099 (let ((no (archive-get-lineno)))
1100 (setq archive-files nil)
1101 (let ((revert-buffer-function nil))
1102 (revert-buffer t t))
1104 (goto-char archive-file-list-start)
1105 (archive-next-line no)))
1107 (defun archive-undo ()
1108 "Undo in an archive buffer.
1109 This doesn't recover lost files, it just undoes changes in the buffer itself."
1111 (let (buffer-read-only)
1113 ;; -------------------------------------------------------------------------
1114 ;; Section: Arc Archives
1116 (defun archive-arc-summarize ()
1122 (while (and (< (+ p 29) (point-max))
1123 (= (char-after p) ?\C-z)
1124 (> (char-after (1+ p)) 0))
1125 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13)))
1126 (fnlen (or (string-match "\0" namefld) 13))
1127 (efnname (substring namefld 0 fnlen))
1128 (csize (archive-l-e (+ p 15) 4))
1129 (moddate (archive-l-e (+ p 19) 2))
1130 (modtime (archive-l-e (+ p 21) 2))
1131 (ucsize (archive-l-e (+ p 25) 4))
1132 (fiddle (string= efnname (upcase efnname)))
1133 (ifnname (if fiddle (downcase efnname) efnname))
1134 (text (format " %8d %-11s %-8s %s"
1136 (archive-dosdate moddate)
1137 (archive-dostime modtime)
1139 (setq maxlen (max maxlen fnlen)
1140 totalsize (+ totalsize ucsize)
1141 visual (cons (vector text
1142 (- (length text) (length ifnname))
1145 files (cons (vector efnname ifnname fiddle nil (1- p))
1148 (goto-char (point-min))
1149 (let ((dash (concat "- -------- ----------- -------- "
1150 (make-string maxlen ?-)
1152 (insert "M Length Date Time File\n"
1154 (archive-summarize-files (nreverse visual))
1156 (format " %8d %d file%s"
1159 (if (= 1 (length files)) "" "s"))
1161 (apply 'vector (nreverse files))))
1163 (defun archive-arc-rename-entry (archive newname descr)
1164 (if (string-match "[:\\\\/]" newname)
1165 (error "File names in arc files may not contain a path"))
1166 (if (> (length newname) 12)
1167 (error "File names in arc files are limited to 12 characters"))
1168 (let ((name (concat newname (substring "\0\0\0\0\0\0\0\0\0\0\0\0\0"
1174 (goto-char (+ archive-proper-file-start (aref descr 4) 2))
1177 ;; -------------------------------------------------------------------------
1178 ;; Section: Lzh Archives
1180 (defun archive-lzh-summarize ()
1186 (while (progn (goto-char p) (looking-at "..-l[hz][0-9]-"))
1187 (let* ((hsize (char-after p))
1188 (csize (archive-l-e (+ p 7) 4))
1189 (ucsize (archive-l-e (+ p 11) 4))
1190 (modtime (archive-l-e (+ p 15) 2))
1191 (moddate (archive-l-e (+ p 17) 2))
1192 (fnlen (char-after (+ p 21)))
1193 (efnname (buffer-substring (+ p 22) (+ p 22 fnlen)))
1194 (fiddle (string= efnname (upcase efnname)))
1195 (ifnname (if fiddle (downcase efnname) efnname))
1197 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0))
1198 (mode (if (= creator ?U) (archive-l-e (+ p2 8) 2) ?\666))
1199 (modestr (if mode (archive-int-to-mode mode) "??????????"))
1200 (uid (if (= creator ?U) (archive-l-e (+ p2 10) 2)))
1201 (gid (if (= creator ?U) (archive-l-e (+ p2 12) 2)))
1202 (text (if archive-alternate-display
1203 (format " %8d %5S %5S %s"
1208 (format " %10s %8d %-11s %-8s %s"
1211 (archive-dosdate moddate)
1212 (archive-dostime modtime)
1214 (setq maxlen (max maxlen fnlen)
1215 totalsize (+ totalsize ucsize)
1216 visual (cons (vector text
1217 (- (length text) (length ifnname))
1220 files (cons (vector efnname ifnname fiddle mode (1- p))
1222 p (+ p hsize 2 csize))))
1223 (goto-char (point-min))
1224 (let ((dash (concat (if archive-alternate-display
1225 "- -------- ----- ----- "
1226 "- ---------- -------- ----------- -------- ")
1227 (make-string maxlen ?-)
1229 (header (if archive-alternate-display
1230 "M Length Uid Gid File\n"
1231 "M Filemode Length Date Time File\n"))
1232 (sumline (if archive-alternate-display
1235 (insert header dash)
1236 (archive-summarize-files (nreverse visual))
1241 (if (= 1 (length files)) "" "s"))
1243 (apply 'vector (nreverse files))))
1245 (defconst archive-lzh-alternate-display t)
1247 (defun archive-lzh-extract (archive name)
1248 (archive-extract-by-stdout archive name archive-lzh-extract))
1250 (defun archive-lzh-resum (p count)
1253 (setq count (1- count)
1254 sum (+ sum (char-after p))
1258 (defun archive-lzh-rename-entry (archive newname descr)
1262 (let* ((p (+ archive-proper-file-start (aref descr 4)))
1263 (oldhsize (char-after p))
1264 (oldfnlen (char-after (+ p 21)))
1265 (newfnlen (length newname))
1266 (newhsize (+ oldhsize newfnlen (- oldfnlen)))
1268 (if (> newhsize 255)
1269 (error "The file name is too long"))
1270 (goto-char (+ p 21))
1271 (delete-char (1+ oldfnlen))
1272 (insert newfnlen newname)
1275 (insert newhsize (archive-lzh-resum p newhsize))))))
1277 (defun archive-lzh-ogm (newval files errtxt ofs)
1282 (let* ((fil (car files))
1283 (p (+ archive-proper-file-start (aref fil 4)))
1284 (hsize (char-after p))
1285 (fnlen (char-after (+ p 21)))
1287 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0))
1291 (or (numberp newval)
1292 (setq newval (funcall newval (archive-l-e (+ p2 ofs) 2))))
1293 (goto-char (+ p2 ofs))
1295 (insert (logand newval 255) (lsh newval -8))
1298 (insert (archive-lzh-resum (1+ p) hsize)))
1299 (message "Member %s does not have %s field"
1300 (aref fil 1) errtxt)))
1301 (setq files (cdr files))))))
1303 (defun archive-lzh-chown-entry (newuid files)
1304 (archive-lzh-ogm newuid files "an uid" 10))
1306 (defun archive-lzh-chgrp-entry (newgid files)
1307 (archive-lzh-ogm newgid files "a gid" 12))
1309 (defun archive-lzh-chmod-entry (newmode files)
1311 ;; This should work even though newmode will be dynamically accessed.
1312 (function (lambda (old) (archive-calc-mode old newmode t)))
1313 files "a unix-style mode" 8))
1314 ;; -------------------------------------------------------------------------
1315 ;; Section: Zip Archives
1317 (defun archive-zip-summarize ()
1318 (goto-char (- (point-max) (- 22 18)))
1319 (search-backward-regexp "[P]K\005\006")
1320 (let ((p (1+ (archive-l-e (+ (point) 16) 4)))
1325 (while (string= "PK\001\002" (buffer-substring p (+ p 4)))
1326 (let* ((creator (char-after (+ p 5)))
1327 (method (archive-l-e (+ p 10) 2))
1328 (modtime (archive-l-e (+ p 12) 2))
1329 (moddate (archive-l-e (+ p 14) 2))
1330 (ucsize (archive-l-e (+ p 24) 4))
1331 (fnlen (archive-l-e (+ p 28) 2))
1332 (exlen (archive-l-e (+ p 30) 2))
1333 (fclen (archive-l-e (+ p 32) 2))
1334 (lheader (archive-l-e (+ p 42) 4))
1335 (efnname (buffer-substring (+ p 46) (+ p 46 fnlen)))
1336 (isdir (and (= ucsize 0)
1337 (string= (file-name-nondirectory efnname) "")))
1338 (mode (cond ((memq creator '(2 3)) ; Unix + VMS
1339 (archive-l-e (+ p 40) 2))
1340 ((memq creator '(0 5 6 7 10 11)) ; Dos etc.
1342 (if isdir (logior 16384 ?\111) 0)
1344 (logand 1 (char-after (+ p 38))))
1347 (modestr (if mode (archive-int-to-mode mode) "??????????"))
1348 (fiddle (and archive-zip-case-fiddle
1349 (not (not (memq creator '(0 2 4 5 9))))))
1350 (ifnname (if fiddle (downcase efnname) efnname))
1351 (text (format " %10s %8d %-11s %-8s %s"
1354 (archive-dosdate moddate)
1355 (archive-dostime modtime)
1357 (setq maxlen (max maxlen fnlen)
1358 totalsize (+ totalsize ucsize)
1359 visual (cons (vector text
1360 (- (length text) (length ifnname))
1363 files (cons (if isdir
1365 (vector efnname ifnname fiddle mode
1366 (list (1- p) lheader)))
1368 p (+ p 46 fnlen exlen fclen))))
1369 (goto-char (point-min))
1370 (let ((dash (concat "- ---------- -------- ----------- -------- "
1371 (make-string maxlen ?-)
1373 (insert "M Filemode Length Date Time File\n"
1375 (archive-summarize-files (nreverse visual))
1377 (format " %8d %d file%s"
1380 (if (= 1 (length files)) "" "s"))
1382 (apply 'vector (nreverse files))))
1384 (defun archive-zip-extract (archive name)
1385 (if archive-zip-use-pkzip
1386 (archive-*-extract archive name archive-zip-extract)
1387 (archive-extract-by-stdout archive name archive-zip-extract)))
1389 (defun archive-zip-write-file-member (archive descr)
1390 (archive-*-write-file-member
1393 (if (aref descr 2) archive-zip-update-case archive-zip-update)))
1395 (defun archive-zip-chmod-entry (newmode files)
1400 (let* ((fil (car files))
1401 (p (+ archive-proper-file-start (car (aref fil 4))))
1402 (creator (char-after (+ p 5)))
1403 (oldmode (aref fil 3))
1404 (newval (archive-calc-mode oldmode newmode t))
1406 (cond ((memq creator '(2 3)) ; Unix + VMS
1407 (goto-char (+ p 40))
1409 (insert (logand newval 255) (lsh newval -8)))
1410 ((memq creator '(0 5 6 7 10 11)) ; Dos etc.
1411 (goto-char (+ p 38))
1412 (insert (logior (logand (char-after (point)) 254)
1413 (logand (logxor 1 (lsh newval -7)) 1)))
1415 (t (message "Don't know how to change mode for this member"))))
1416 (setq files (cdr files))))))
1417 ;; -------------------------------------------------------------------------
1418 ;; Section: Zoo Archives
1420 (defun archive-zoo-summarize ()
1421 (let ((p (1+ (archive-l-e 25 4)))
1426 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4)))
1427 (> (archive-l-e (+ p 6) 4) 0))
1428 (let* ((next (1+ (archive-l-e (+ p 6) 4)))
1429 (moddate (archive-l-e (+ p 14) 2))
1430 (modtime (archive-l-e (+ p 16) 2))
1431 (ucsize (archive-l-e (+ p 20) 4))
1432 (namefld (buffer-substring (+ p 38) (+ p 38 13)))
1433 (fnlen (or (string-match "\0" namefld) 13))
1434 (efnname (substring namefld 0 fnlen))
1435 (fiddle (string= efnname (upcase efnname)))
1436 (ifnname (if fiddle (downcase efnname) efnname))
1437 (text (format " %8d %-11s %-8s %s"
1439 (archive-dosdate moddate)
1440 (archive-dostime modtime)
1442 (setq maxlen (max maxlen fnlen)
1443 totalsize (+ totalsize ucsize)
1444 visual (cons (vector text
1445 (- (length text) (length ifnname))
1448 files (cons (vector efnname ifnname fiddle nil (1- p))
1451 (goto-char (point-min))
1452 (let ((dash (concat "- -------- ----------- -------- "
1453 (make-string maxlen ?-)
1455 (insert "M Length Date Time File\n"
1457 (archive-summarize-files (nreverse visual))
1459 (format " %8d %d file%s"
1462 (if (= 1 (length files)) "" "s"))
1464 (apply 'vector (nreverse files))))
1466 (defun archive-zoo-extract (archive name)
1467 (archive-extract-by-stdout archive name archive-zoo-extract))
1468 ;; -------------------------------------------------------------------------
1469 (provide 'archive-mode)
1471 ;; arc-mode.el ends here.