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)
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 the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; NAMING: "arc" is short for "archive" and does not refer specifically
29 ;; to files whose name end in ".arc"
31 ;; This code does not decode any files internally, although it does
32 ;; understand the directory level of the archives. For this reason,
33 ;; you should expect this code to need more fiddling than tar-mode.el
34 ;; (although it at present has fewer bugs :-) In particular, I have
35 ;; not tested this under Ms-Dog myself.
36 ;; -------------------------------------
37 ;; INTERACTION: arc-mode.el should play together with
39 ;; * ange-ftp.el: Remote archives (i.e., ones that ange-ftp has brought
40 ;; to you) are handled by doing all updates on a local
41 ;; copy. When you make changes to a remote file the
42 ;; changes will first take effect when the archive buffer
43 ;; is saved. You will be warned about this.
45 ;; * dos-fns.el: (Part of Emacs 19). You get automatic ^M^J <--> ^J
48 ;; arc-mode.el does not work well with crypt++.el; for the archives as
49 ;; such this could be fixed (but wouldn't be useful) by declaring such
50 ;; archives to be "remote". For the members this is a general Emacs
51 ;; problem that 19.29's file formats may fix.
52 ;; -------------------------------------
53 ;; ARCHIVE TYPES: Currently only the archives below are handled, but the
54 ;; structure for handling just about anything is in place.
57 ;; --------------------------------
58 ;; View listing Intern Intern Intern Intern
59 ;; Extract member Y Y Y Y
60 ;; Save changed member Y Y Y Y
61 ;; Add new member N N N N
62 ;; Delete member Y Y Y Y
63 ;; Rename member Y Y N N
68 ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips
69 ;; on the first released version of this package.
71 ;; This code is partly based on tar-mode.el from Emacs.
72 ;; -------------------------------------
73 ;; ARCHIVE STRUCTURES:
74 ;; (This is mostly for myself.)
76 ;; ARC A series of (header,file). No interactions among members.
78 ;; LZH A series of (header,file). Headers are checksummed. No
79 ;; interaction among members.
81 ;; ZIP A series of (lheader,fil) followed by a "central directory"
82 ;; which is a series of (cheader) followed by an end-of-
83 ;; central-dir record possibly followed by junk. The e-o-c-d
84 ;; links to c-d. cheaders link to lheaders which are basically
85 ;; cut-down versions of the cheaders.
87 ;; ZOO An archive header followed by a series of (header,file).
88 ;; Each member header points to the next. The archive is
89 ;; terminated by a bogus header with a zero next link.
90 ;; -------------------------------------
91 ;; HOOKS: `foo' means one the the supported archive types.
94 ;; archive-foo-mode-hook
95 ;; archive-extract-hooks
99 ;; -------------------------------------------------------------------------
100 ;; Section: Configuration.
102 (defvar archive-dos-members t
103 "*If non-nil then recognize member files using ^M^J as line terminator.")
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.
113 A non-local file is one whose file name is not proper outside Emacs.
114 A local copy of the archive will 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 Extraction should happen to the current directory. Archive and member
127 name will be added.")
129 (defvar archive-arc-expunge
131 "*Program and its options to run in order to delete arc file members.
132 Archive and member names will be added.")
134 (defvar archive-arc-write-file-member
136 "*Program and its options to run in order to update an arc file member.
137 Archive and member name will be added.")
138 ;; ------------------------------
139 ;; Lzh archive configuration
141 (defvar archive-lzh-extract
143 "*Program and its options to run in order to extract an lzh file member.
144 Extraction should happen to standard output. Archive and member name will
147 (defvar archive-lzh-expunge
149 "*Program and its options to run in order to delete lzh file members.
150 Archive and member names will be added.")
152 (defvar archive-lzh-write-file-member
154 "*Program and its options to run in order to update an lzh file member.
155 Archive and member name will be added.")
156 ;; ------------------------------
157 ;; Zip archive configuration
159 (defvar archive-zip-use-pkzip
(memq system-type
'(ms-dos windows-nt
))
160 "*If non-nil then pkzip option are used instead of zip options.
161 Only set to true for msdog systems!")
163 (defvar archive-zip-extract
164 (if archive-zip-use-pkzip
'("pkunzip" "-e") '("unzip" "-qq" "-c"))
165 "*Program and its options to run in order to extract a zip file member.
166 Extraction should happen to standard output. Archive and member name will
167 be added. If `archive-zip-use-pkzip' is non-nil then this program is
168 expected to extract to a file junking the directory part of the name.")
170 ;; For several reasons the latter behaviour is not desirable in general.
171 ;; (1) It uses more disk space. (2) Error checking is worse or non-
172 ;; existent. (3) It tends to do funny things with other systems' file
175 (defvar archive-zip-expunge
176 (if archive-zip-use-pkzip
'("pkzip" "-d") '("zip" "-d" "-q"))
177 "*Program and its options to run in order to delete zip file members.
178 Archive and member names will be added.")
180 (defvar archive-zip-update
181 (if archive-zip-use-pkzip
'("pkzip" "-u") '("zip" "-q"))
182 "*Program and its options to run in order to update a zip file member.
183 Options should ensure that specified directory will be put into the zip
184 file. Archive and member name will be added.")
186 (defvar archive-zip-update-case
187 (if archive-zip-use-pkzip archive-zip-update
'("zip" "-q" "-k"))
188 "*Program and its options to run in order to update a case fiddled zip member.
189 Options should ensure that specified directory will be put into the zip file.
190 Archive and member name will be added.")
192 (defvar archive-zip-case-fiddle t
193 "*If non-nil then zip file members are case fiddled.
194 Case fiddling will only happen for members created by a system that
195 uses caseless file names.")
196 ;; ------------------------------
197 ;; Zoo archive configuration
199 (defvar archive-zoo-extract
201 "*Program and its options to run in order to extract a zoo file member.
202 Extraction should happen to standard output. Archive and member name will
205 (defvar archive-zoo-expunge
207 "*Program and its options to run in order to delete zoo file members.
208 Archive and member names will be added.")
210 (defvar archive-zoo-write-file-member
212 "*Program and its options to run in order to update a zoo file member.
213 Archive and member name will be added.")
214 ;; -------------------------------------------------------------------------
215 ;; Section: Variables
217 (defvar archive-subtype nil
"*Symbol describing archive type.")
218 (defvar archive-file-list-start nil
"*Position of first contents line.")
219 (defvar archive-file-list-end nil
"*Position just after last contents line.")
220 (defvar archive-proper-file-start nil
"*Position of real archive's start.")
221 (defvar archive-read-only nil
"*Non-nil if the archive is read-only on disk.")
222 (defvar archive-remote nil
"*Non-nil if the archive is outside file system.")
223 (defvar archive-local-name nil
"*Name of local copy of remote archive.")
224 (defvar archive-mode-map nil
"*Local keymap for archive mode listings.")
225 (defvar archive-file-name-indent nil
"*Column where file names start.")
227 (defvar archive-alternate-display nil
228 "*Non-nil when alternate information is shown.")
229 (make-variable-buffer-local 'archive-alternate-display
)
230 (put 'archive-alternate-display
'permanent-local t
)
232 (defvar archive-superior-buffer nil
"*In archive members, points to archive.")
233 (put 'archive-superior-buffer
'permanent-local t
)
235 (defvar archive-subfile-mode nil
"*Non-nil in archive member buffers.")
236 (make-variable-buffer-local 'archive-subfile-mode
)
237 (put 'archive-subfile-mode
'permanent-local t
)
239 (defvar archive-subfile-dos nil
240 "Negation of `buffer-file-type', which see.")
241 (make-variable-buffer-local 'archive-subfile-dos
)
242 (put 'archive-subfile-dos
'permanent-local t
)
244 (defvar archive-files nil
245 "Vector of file descriptors.
246 Each descriptor is a vector of the form
247 [EXT-FILE-NAME INT-FILE-NAME CASE-FIDDLED MODE ...]")
248 (make-variable-buffer-local 'archive-files
)
250 (defvar archive-lemacs
251 (string-match "\\(Lucid\\|Xemacs\\)" emacs-version
)
252 "*Non-nil when running under under Lucid Emacs or Xemacs.")
253 ;; -------------------------------------------------------------------------
254 ;; Section: Support functions.
256 (defsubst archive-name
(suffix)
257 (intern (concat "archive-" (symbol-name archive-subtype
) "-" suffix
)))
259 (defun archive-l-e (str &optional len
)
260 "Convert little endian string/vector to integer.
261 Alternatively, first argument may be a buffer position in the current buffer
262 in which case a second argument, length, should be supplied."
264 (setq len
(length str
))
265 (setq str
(buffer-substring str
(+ str len
))))
270 result
(+ (ash result
8) (aref str
(- len i
)))))
273 (defun archive-int-to-mode (mode)
274 "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------"
275 (let ((str (make-string 10 ?-
)))
276 (or (zerop (logand 16384 mode
)) (aset str
0 ?d
))
277 (or (zerop (logand 8192 mode
)) (aset str
0 ?c
)) ; completeness
278 (or (zerop (logand 256 mode
)) (aset str
1 ?r
))
279 (or (zerop (logand 128 mode
)) (aset str
2 ?w
))
280 (or (zerop (logand 64 mode
)) (aset str
3 ?x
))
281 (or (zerop (logand 32 mode
)) (aset str
4 ?r
))
282 (or (zerop (logand 16 mode
)) (aset str
5 ?w
))
283 (or (zerop (logand 8 mode
)) (aset str
6 ?x
))
284 (or (zerop (logand 4 mode
)) (aset str
7 ?r
))
285 (or (zerop (logand 2 mode
)) (aset str
8 ?w
))
286 (or (zerop (logand 1 mode
)) (aset str
9 ?x
))
287 (or (zerop (logand 1024 mode
)) (aset str
3 (if (zerop (logand 64 mode
))
289 (or (zerop (logand 2048 mode
)) (aset str
6 (if (zerop (logand 8 mode
))
293 (defun archive-calc-mode (oldmode newmode
&optional error
)
294 "From the integer OLDMODE and the string NEWMODE calculate a new file mode.
295 NEWMODE may be an octal number including a leading zero in which case it
296 will become the new mode.\n
297 NEWMODE may also be a relative specification like \"og-rwx\" in which case
298 OLDMODE will be modified accordingly just like chmod(2) would have done.\n
299 If optional third argument ERROR is non-nil an error will be signaled if
300 the mode is invalid. If ERROR is nil then nil will be returned."
301 (cond ((string-match "^0[0-7]*$" newmode
)
303 (len (length newmode
))
306 (setq result
(+ (lsh result
3) (aref newmode i
) (- ?
0))
308 (logior (logand oldmode
65024) result
)))
309 ((string-match "^\\([agou]+\\)\\([---+=]\\)\\([rwxst]+\\)$" newmode
)
312 (op (aref newmode
(match-beginning 2)))
314 (i (match-beginning 3)))
315 (while (< i
(match-end 3))
316 (let ((rwx (aref newmode i
)))
317 (setq bits
(logior bits
(cond ((= rwx ?r
) 292)
323 (while (< who
(match-end 1))
324 (let* ((whoc (aref newmode who
))
325 (whomask (cond ((= whoc ?a
) 4095)
330 (setq result
(logand result
(lognot whomask
))))
332 (setq result
(logand result
(lognot (logand whomask bits
))))
333 (setq result
(logior result
(logand whomask bits
)))))
338 (error "Invalid mode specification: %s" newmode
)))))
340 (defun archive-dosdate (date)
341 "Stringify dos packed DATE record."
342 (let ((year (+ 1980 (logand (ash date -
9) 127)))
343 (month (logand (ash date -
5) 15))
344 (day (logand date
31)))
345 (if (or (> month
12) (< month
1))
349 (aref ["Jan" "Feb" "Mar" "Apr" "May" "Jun"
350 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"] (1- month
))
353 (defun archive-dostime (time)
354 "Stringify dos packed TIME record."
355 (let ((hour (logand (ash time -
11) 31))
356 (minute (logand (ash time -
5) 53))
357 (second (* 2 (logand time
31)))) ; 2 seconds resolution
358 (format "%02d:%02d:%02d" hour minute second
)))
360 ;;(defun archive-unixdate (low high)
361 ;; "Stringify unix (LOW HIGH) date."
362 ;; (let ((str (current-time-string (cons high low))))
363 ;; (format "%s-%s-%s"
364 ;; (substring str 8 9)
365 ;; (substring str 4 7)
366 ;; (substring str 20 24))))
368 ;;(defun archive-unixtime (low high)
369 ;; "Stringify unix (LOW HIGH) time."
370 ;; (let ((str (current-time-string (cons high low))))
371 ;; (substring str 11 19)))
373 (defun archive-get-lineno ()
374 (if (>= (point) archive-file-list-start
)
375 (count-lines archive-file-list-start
376 (save-excursion (beginning-of-line) (point)))
379 (defun archive-get-descr (&optional noerror
)
380 "Return the descriptor vector for file at point.
381 Does not signal an error if optional second argument NOERROR is non-nil."
382 (let ((no (archive-get-lineno)))
383 (if (and (>= (point) archive-file-list-start
)
384 (< no
(length archive-files
)))
385 (let ((item (aref archive-files no
)))
389 (error "Entry is not a regular member of the archive"))))
391 (error "Line does not describe a member of the archive")))))
392 ;; -------------------------------------------------------------------------
393 ;; Section: the mode definition
396 (defun archive-mode (&optional force
)
397 "Major mode for viewing an archive file in a dired-like way.
398 You can move around using the usual cursor motion commands.
399 Letters no longer insert themselves.
400 Type `e' to pull a file out of the archive and into its own buffer;
401 or click mouse-2 on the file's line in the archive mode buffer.
403 If you edit a sub-file of this archive (as with the `e' command) and
404 save it, the contents of that buffer will be saved back into the
407 \\{archive-mode-map}"
408 ;; This is not interactive because you shouldn't be turning this
409 ;; mode on and off. You can corrupt things that way.
410 (if (zerop (buffer-size))
411 ;; At present we cannot create archives from scratch
412 (funcall default-major-mode
)
413 (if (and (not force
) archive-files
) nil
414 (let* ((type (archive-find-type))
415 (typename (copy-sequence (symbol-name type
))))
416 (aset typename
0 (upcase (aref typename
0)))
417 (kill-all-local-variables)
418 (make-local-variable 'archive-subtype
)
419 (setq archive-subtype type
)
421 ;; Buffer contains treated image of file before the file contents
422 (make-local-variable 'revert-buffer-function
)
423 (setq revert-buffer-function
'archive-mode-revert
)
425 (make-local-variable 'local-write-file-hooks
)
426 (add-hook 'local-write-file-hooks
'archive-write-file
)
428 ;; Real file contents is binary
429 (make-local-variable 'require-final-newline
)
430 (setq require-final-newline nil
)
431 (make-local-variable 'enable-local-variables
)
432 (setq enable-local-variables nil
)
433 (if (boundp 'default-buffer-file-type
)
434 (setq buffer-file-type t
))
436 (make-local-variable 'archive-read-only
)
437 (setq archive-read-only
(not (file-writable-p (buffer-file-name))))
439 ;; Should we use a local copy when accessing from outside Emacs?
440 (make-local-variable 'archive-local-name
)
441 (make-local-variable 'archive-remote
)
442 (setq archive-remote
(string-match archive-remote-regexp
445 (setq major-mode
'archive-mode
)
446 (setq mode-name
(concat typename
"-Archive"))
447 ;; Run archive-foo-mode-hook and archive-mode-hook
448 (run-hooks (archive-name "mode-hook") 'archive-mode-hook
)
449 (use-local-map archive-mode-map
))
451 (make-local-variable 'archive-proper-file-start
)
452 (make-local-variable 'archive-file-list-start
)
453 (make-local-variable 'archive-file-list-end
)
454 (make-local-variable 'archive-file-name-indent
)
456 (setq buffer-read-only t
))))
458 ;; Archive mode is suitable only for specially formatted data.
459 (put 'archive-mode
'mode-class
'special
)
460 ;; -------------------------------------------------------------------------
463 (if archive-mode-map nil
464 (setq archive-mode-map
(make-keymap))
465 (suppress-keymap archive-mode-map
)
466 (define-key archive-mode-map
" " 'archive-next-line
)
467 (define-key archive-mode-map
"a" 'archive-alternate-display
)
468 ;;(define-key archive-mode-map "c" 'archive-copy)
469 (define-key archive-mode-map
"d" 'archive-flag-deleted
)
470 (define-key archive-mode-map
"\C-d" 'archive-flag-deleted
)
471 (define-key archive-mode-map
"e" 'archive-extract
)
472 (define-key archive-mode-map
"f" 'archive-extract
)
473 (define-key archive-mode-map
"\C-m" 'archive-extract
)
474 (define-key archive-mode-map
"g" 'revert-buffer
)
475 (define-key archive-mode-map
"h" 'describe-mode
)
476 (define-key archive-mode-map
"m" 'archive-mark
)
477 (define-key archive-mode-map
"n" 'archive-next-line
)
478 (define-key archive-mode-map
"\C-n" 'archive-next-line
)
479 (define-key archive-mode-map
[down] 'archive-next-line)
480 (define-key archive-mode-map "o" 'archive-extract-other-window)
481 (define-key archive-mode-map "p" 'archive-previous-line)
482 (define-key archive-mode-map "\C-p" 'archive-previous-line)
483 (define-key archive-mode-map [up] 'archive-previous-line)
484 (define-key archive-mode-map "r" 'archive-rename-entry)
485 (define-key archive-mode-map "u" 'archive-unflag)
486 (define-key archive-mode-map "\M-\C-?" 'archive-unmark-all-files)
487 (define-key archive-mode-map "v" 'archive-view)
488 (define-key archive-mode-map "x" 'archive-expunge)
489 (define-key archive-mode-map "\177" 'archive-unflag-backwards)
490 (define-key archive-mode-map "E" 'archive-extract-other-window)
491 (define-key archive-mode-map "M" 'archive-chmod-entry)
492 (define-key archive-mode-map "G" 'archive-chgrp-entry)
493 (define-key archive-mode-map "O" 'archive-chown-entry)
497 ;; Not a nice "solution" but it'll have to do
498 (define-key archive-mode-map "\C-xu" 'archive-undo)
499 (define-key archive-mode-map "\C-_" 'archive-undo))
500 (substitute-key-definition 'undo 'archive-undo
501 archive-mode-map global-map))
503 (define-key archive-mode-map
504 (if archive-lemacs 'button2 [mouse-2]) 'archive-mouse-extract)
508 ;; Get rid of the Edit menu bar item to save space.
509 (define-key archive-mode-map [menu-bar edit] 'undefined)
511 (define-key archive-mode-map [menu-bar immediate]
512 (cons "Immediate" (make-sparse-keymap "Immediate")))
513 (define-key archive-mode-map [menu-bar immediate alternate]
514 '("Alternate Display" . archive-alternate-display))
515 (put 'archive-alternate-display 'menu-enable
516 '(boundp (archive-name "alternate-display")))
517 (define-key archive-mode-map [menu-bar immediate view]
518 '("View This File" . archive-view))
519 (define-key archive-mode-map [menu-bar immediate display]
520 '("Display in Other Window" . archive-display-other-window))
521 (define-key archive-mode-map [menu-bar immediate find-file-other-window]
522 '("Find in Other Window" . archive-extract-other-window))
523 (define-key archive-mode-map [menu-bar immediate find-file]
524 '("Find This File" . archive-extract))
526 (define-key archive-mode-map [menu-bar mark]
527 (cons "Mark" (make-sparse-keymap "Mark")))
528 (define-key archive-mode-map [menu-bar mark unmark-all]
529 '("Unmark All" . archive-unmark-all-files))
530 (define-key archive-mode-map [menu-bar mark deletion]
531 '("Flag" . archive-flag-deleted))
532 (define-key archive-mode-map [menu-bar mark unmark]
533 '("Unflag" . archive-unflag))
534 (define-key archive-mode-map [menu-bar mark mark]
535 '("Mark" . archive-mark))
537 (define-key archive-mode-map [menu-bar operate]
538 (cons "Operate" (make-sparse-keymap "Operate")))
539 (define-key archive-mode-map [menu-bar operate chown]
540 '("Change Owner..." . archive-chown-entry))
541 (put 'archive-chown-entry 'menu-enable
542 '(fboundp (archive-name "chown-entry")))
543 (define-key archive-mode-map [menu-bar operate chgrp]
544 '("Change Group..." . archive-chgrp-entry))
545 (put 'archive-chgrp-entry 'menu-enable
546 '(fboundp (archive-name "chgrp-entry")))
547 (define-key archive-mode-map [menu-bar operate chmod]
548 '("Change Mode..." . archive-chmod-entry))
549 (put 'archive-chmod-entry 'menu-enable
550 '(fboundp (archive-name "chmod-entry")))
551 (define-key archive-mode-map [menu-bar operate rename]
552 '("Rename to..." . archive-rename-entry))
553 (put 'archive-rename-entry 'menu-enable
554 '(fboundp (archive-name "rename-entry")))
555 ;;(define-key archive-mode-map [menu-bar operate copy]
556 ;; '("Copy to..." . archive-copy))
557 (define-key archive-mode-map [menu-bar operate expunge]
558 '("Expunge Marked Files" . archive-expunge))
561 (let* ((item1 '(archive-subfile-mode " Archive"))
562 (item2 '(archive-subfile-dos " Dos"))
563 (items (if (memq system-type '(ms-dos windows-nt))
564 (list item1) ; msdog has its own indicator
565 (list item1 item2))))
566 (or (member item1 minor-mode-alist)
567 (setq minor-mode-alist (append items minor-mode-alist))))
568 ;; -------------------------------------------------------------------------
569 (defun archive-find-type ()
571 (goto-char (point-min))
572 ;; The funny [] here make it unlikely that the .elc file will be treated
573 ;; as an archive by other software.
574 (let (case-fold-search)
575 (cond ((looking-at "[P]K\003\004") 'zip)
576 ((looking-at "..-l[hz][0-9]-") 'lzh)
577 ((looking-at "....................[\334]\247\304\375") 'zoo)
578 ((and (looking-at "\C-z") ; signature too simple, IMHO
579 (string-match "\\.[aA][rR][cC]$"
580 (or buffer-file-name (buffer-name))))
582 (t (error "Buffer format not recognized.")))))
583 ;; -------------------------------------------------------------------------
584 (defun archive-summarize ()
585 "Parse the contents of the archive file in the current buffer.
586 Place a dired-like listing on the front;
587 then narrow to it, so that only that listing
588 is visible (and the real data of the buffer is hidden)."
590 (let (buffer-read-only)
591 (message "Parsing archive file...")
592 (buffer-disable-undo (current-buffer))
593 (setq archive-files (funcall (archive-name "summarize")))
594 (message "Parsing archive file...done.")
595 (setq archive-proper-file-start (point-marker))
596 (narrow-to-region (point-min) (point))
597 (set-buffer-modified-p nil)
598 (buffer-enable-undo))
599 (goto-char archive-file-list-start)
600 (archive-next-line 0))
602 (defun archive-resummarize ()
603 "Recreate the contents listing of an archive."
604 (let ((modified (buffer-modified-p))
605 (no (archive-get-lineno))
608 (delete-region (point-min) archive-proper-file-start)
610 (set-buffer-modified-p modified)
611 (goto-char archive-file-list-start)
612 (archive-next-line no)))
614 (defun archive-summarize-files (files)
615 "Insert a description of a list of files annotated with proper mouse face."
616 (setq archive-file-list-start (point-marker))
617 (setq archive-file-name-indent (if files (aref (car files) 1) 0))
618 ;; We don't want to do an insert for each element since that takes too
619 ;; long when the archive -- which has to be moved in memory -- is large.
626 ;; Using `concat' here copies the text also, so we can add
627 ;; properties without problems.
628 (let ((text (concat (aref fil 0) "\n")))
631 (put-text-property (aref fil 1) (aref fil 2)
632 'mouse-face 'highlight
636 (setq archive-file-list-end (point-marker)))
638 (defun archive-alternate-display ()
639 "Toggle alternative display.
640 To avoid very long lines some archive mode don't show all information.
641 This function changes the set of information shown for each files."
643 (setq archive-alternate-display (not archive-alternate-display))
644 (archive-resummarize))
645 ;; -------------------------------------------------------------------------
646 ;; Section: Local archive copy handling
648 (defun archive-maybe-copy (archive)
650 (let ((start (point-max)))
651 (setq archive-local-name (expand-file-name
652 (file-name-nondirectory archive)
654 (make-directory archive-tmpdir t)
657 (write-region start (point-max) archive-local-name nil 'nomessage))
659 (if (buffer-modified-p) (save-buffer))
662 (defun archive-maybe-update (unchanged)
664 (let ((name archive-local-name)
665 (modified (buffer-modified-p))
669 (insert-file-contents name)
671 (archive-delete-local name)
673 (message "Archive file must be saved for changes to take effect"))
674 (set-buffer-modified-p (or modified (not unchanged))))))
676 (defun archive-delete-local (name)
677 "Delete file NAME and its parents up to and including `archive-tmpdir'."
679 (top (directory-file-name (file-name-as-directory archive-tmpdir))))
684 (setq name (directory-file-name (file-name-directory name)))
686 (delete-directory name)
688 (if (string= name top) (setq again nil)))))
689 ;; -------------------------------------------------------------------------
690 ;; Section: Member extraction
692 (defun archive-mouse-extract (event)
693 "Extract a file whose name you click on."
695 (mouse-set-point event)
701 (defun archive-extract (&optional other-window-p)
702 "In archive mode, extract this entry of the archive into its own buffer."
704 (let* ((view-p (eq other-window-p 'view))
705 (descr (archive-get-descr))
706 (ename (aref descr 0))
707 (iname (aref descr 1))
708 (archive-buffer (current-buffer))
709 (arcdir default-directory)
710 (archive (buffer-file-name))
711 (arcname (file-name-nondirectory archive))
712 (bufname (concat (file-name-nondirectory iname) " (" arcname ")"))
713 (extractor (archive-name "extract"))
714 (read-only-p (or archive-read-only view-p))
715 (buffer (get-buffer bufname))
719 (setq archive (archive-maybe-copy archive))
720 (setq buffer (get-buffer-create bufname))
721 (setq just-created t)
724 (setq buffer-file-name
725 (expand-file-name (concat arcname ":" iname)))
726 (setq buffer-file-truename
727 (abbreviate-file-name buffer-file-name))
728 ;; Set the default-directory to the dir of the superior buffer.
729 (setq default-directory arcdir)
730 (make-local-variable 'archive-superior-buffer)
731 (setq archive-superior-buffer archive-buffer)
732 (make-local-variable 'local-write-file-hooks)
733 (add-hook 'local-write-file-hooks 'archive-write-file-member)
734 (setq archive-subfile-mode descr)
735 (setq archive-subfile-dos nil)
736 (if (boundp 'default-buffer-file-type)
737 (setq buffer-file-type t))
738 (if (fboundp extractor)
739 (funcall extractor archive ename)
740 (archive-*-extract archive ename (symbol-value extractor)))
741 (if archive-dos-members (archive-check-dos))
742 (goto-char (point-min))
743 (rename-buffer bufname)
744 (setq buffer-read-only read-only-p)
745 (setq buffer-undo-list nil)
746 (set-buffer-modified-p nil)
747 (setq buffer-saved-size (buffer-size))
749 ;; Just in case an archive occurs inside another archive.
750 (if (eq major-mode 'archive-mode)
751 (setq archive-remote t))
752 (run-hooks 'archive-extract-hooks))
753 (archive-maybe-update t))
755 (view-buffer buffer (and just-created 'kill-buffer))
756 (if (eq other-window-p 'display)
757 (display-buffer buffer)
759 (switch-to-buffer-other-window buffer)
760 (switch-to-buffer buffer))))))
762 (defun archive-*-extract (archive name command)
763 (let* ((default-directory (file-name-as-directory archive-tmpdir))
764 (tmpfile (expand-file-name (file-name-nondirectory name)
766 (make-directory (directory-file-name default-directory) t)
772 (append (cdr command) (list archive name)))
773 (insert-file-contents tmpfile)
774 (archive-delete-local tmpfile)))
776 (defun archive-extract-by-stdout (archive name command)
777 (let ((binary-process-output t)) ; for Ms-Dos
783 (append (cdr command) (list archive name)))))
785 (defun archive-extract-other-window ()
786 "In archive mode, find this member in another window."
790 (defun archive-display-other-window ()
791 "In archive mode, display this member in another window."
793 (archive-extract 'display))
795 (defun archive-view ()
796 "In archive mode, view the member on this line."
798 (archive-extract 'view))
800 (defun archive-add-new-member (arcbuf name)
801 "Add current buffer to the archive in ARCBUF naming it NAME."
804 (read-buffer "Buffer containing archive: "
805 ;; Find first archive buffer and suggest that
806 (let ((bufs (buffer-list)))
807 (while (and bufs (not (eq (save-excursion
808 (set-buffer (car bufs))
811 (setq bufs (cdr bufs)))
814 (error "There are no archive buffers")))
816 (read-string "File name in archive: "
818 (file-name-nondirectory buffer-file-name)
822 (or (eq major-mode 'archive-mode)
823 (error "Buffer is not an archive buffer"))
824 (if archive-read-only
825 (error "Archive is read-only")))
826 (if (eq arcbuf (current-buffer))
827 (error "An archive buffer cannot be added to itself"))
828 (if (string= name "")
829 (error "Archive members may not be given empty names"))
830 (let ((func (save-excursion (set-buffer arcbuf)
831 (archive-name "add-new-member")))
832 (membuf (current-buffer)))
836 (funcall func buffer-file-name membuf name))
837 (error "Adding a new member is not supported for this archive type"))))
838 ;; -------------------------------------------------------------------------
841 (defun archive-check-dos (&optional force)
842 "*Possibly handle a buffer with ^M^J terminated lines."
846 (goto-char (point-min))
847 (setq archive-subfile-dos
848 (or force (not (search-forward-regexp "[^\r]\n" nil t))))
849 (if (boundp 'default-buffer-file-type)
850 (setq buffer-file-type (not archive-subfile-dos)))
851 (if archive-subfile-dos
852 (let ((modified (buffer-modified-p)))
853 (buffer-disable-undo (current-buffer))
854 (goto-char (point-min))
855 (while (search-forward "\r\n" nil t)
856 (replace-match "\n"))
858 (set-buffer-modified-p modified))))))
860 (defun archive-write-file-member ()
861 (if archive-subfile-dos
865 (goto-char (point-min))
866 ;; We don't want our ^M^J <--> ^J changes to show in the undo list
867 (let ((undo-list buffer-undo-list))
870 (setq buffer-undo-list t)
871 (while (search-forward "\n" nil t)
872 (replace-match "\r\n"))
873 (setq archive-subfile-dos nil)
874 (if (boundp 'default-buffer-file-type)
875 (setq buffer-file-type t))
876 ;; OK, we're now have explicit ^M^Js -- save and re-unixfy
877 (archive-write-file-member))
879 (archive-check-dos t)
880 (setq buffer-undo-list undo-list))))
884 (message "Updating archive...")
886 (let ((writer (save-excursion (set-buffer archive-superior-buffer)
887 (archive-name "write-file-member")))
888 (archive (save-excursion (set-buffer archive-superior-buffer)
889 (buffer-file-name))))
891 (funcall writer archive archive-subfile-mode)
892 (archive-*-write-file-member archive
894 (symbol-value writer))))
895 (set-buffer-modified-p nil)
896 (message "Updating archive...done")
897 (set-buffer archive-superior-buffer)
901 (defun archive-*-write-file-member (archive descr command)
902 (let* ((ename (aref descr 0))
903 (tmpfile (expand-file-name ename archive-tmpdir))
904 (top (directory-file-name (file-name-as-directory archive-tmpdir)))
905 (default-directory (file-name-as-directory top)))
908 (make-directory (file-name-directory tmpfile) t)
909 (write-region (point-min) (point-max) tmpfile nil 'nomessage)
911 ;; Set the file modes, but make sure we can read it.
912 (set-file-modes tmpfile (logior ?\400 (aref descr 3))))
913 (let ((exitcode (apply 'call-process
918 (append (cdr command) (list archive ename)))))
919 (if (equal exitcode 0)
921 (error "Updating was unsuccessful (%S)" exitcode))))
922 (archive-delete-local tmpfile))))
924 (defun archive-write-file ()
926 (write-region archive-proper-file-start (point-max) buffer-file-name nil t)
927 (set-buffer-modified-p nil)
929 ;; -------------------------------------------------------------------------
930 ;; Section: Marking and unmarking.
932 (defun archive-flag-deleted (p &optional type)
933 "In archive mode, mark this member to be deleted from the archive.
934 With a prefix argument, mark that many files."
936 (or type (setq type ?D))
938 (let ((sign (if (>= p 0) +1 -1))
939 (modified (buffer-modified-p))
941 (while (not (zerop p))
942 (if (archive-get-descr t)
948 (set-buffer-modified-p modified))
949 (archive-next-line 0))
951 (defun archive-unflag (p)
952 "In archive mode, un-mark this member if it is marked to be deleted.
953 With a prefix argument, un-mark that many files forward."
955 (archive-flag-deleted p ? ))
957 (defun archive-unflag-backwards (p)
958 "In archive mode, un-mark this member if it is marked to be deleted.
959 With a prefix argument, un-mark that many members backward."
961 (archive-flag-deleted (- p) ? ))
963 (defun archive-unmark-all-files ()
966 (let ((modified (buffer-modified-p))
969 (goto-char archive-file-list-start)
970 (while (< (point) archive-file-list-end)
971 (or (= (following-char) ? )
972 (progn (delete-char 1) (insert ? )))
974 (set-buffer-modified-p modified)))
976 (defun archive-mark (p)
977 "In archive mode, mark this member for group operations.
978 With a prefix argument, mark that many members.
979 Use \\[archive-unmark-all-files] to remove all marks."
981 (archive-flag-deleted p ?*))
983 (defun archive-get-marked (mark &optional default)
986 (goto-char archive-file-list-start)
987 (while (< (point) archive-file-list-end)
988 (if (= (following-char) mark)
989 (setq files (cons (archive-get-descr) files)))
993 (list (archive-get-descr))))))
994 ;; -------------------------------------------------------------------------
997 (defun archive-next-line (p)
1001 (forward-char archive-file-name-indent)))
1003 (defun archive-previous-line (p)
1005 (archive-next-line (- p)))
1007 (defun archive-chmod-entry (new-mode)
1008 "Change the protection bits associated with all marked or this member.
1009 The new protection bits can either be specified as an octal number or
1010 as a relative change like \"g+rw\" as for chmod(2)"
1011 (interactive "sNew mode (octal or relative): ")
1012 (if archive-read-only (error "Archive is read-only"))
1013 (let ((func (archive-name "chmod-entry")))
1016 (funcall func new-mode (archive-get-marked ?* t))
1017 (archive-resummarize))
1018 (error "Setting mode bits is not supported for this archive type"))))
1020 (defun archive-chown-entry (new-uid)
1021 "Change the owner of all marked or this member."
1022 (interactive "nNew uid: ")
1023 (if archive-read-only (error "Archive is read-only"))
1024 (let ((func (archive-name "chown-entry")))
1027 (funcall func new-uid (archive-get-marked ?* t))
1028 (archive-resummarize))
1029 (error "Setting owner is not supported for this archive type"))))
1031 (defun archive-chgrp-entry (new-gid)
1032 "Change the group of all marked or this member."
1033 (interactive "nNew gid: ")
1034 (if archive-read-only (error "Archive is read-only"))
1035 (let ((func (archive-name "chgrp-entry")))
1038 (funcall func new-gid (archive-get-marked ?* t))
1039 (archive-resummarize))
1040 (error "Setting group is not supported for this archive type"))))
1042 (defun archive-expunge ()
1043 "Do the flagged deletions."
1047 (goto-char archive-file-list-start)
1048 (while (< (point) archive-file-list-end)
1049 (if (= (following-char) ?D)
1050 (setq files (cons (aref (archive-get-descr) 0) files)))
1052 (setq files (nreverse files))
1054 (or (not archive-read-only)
1055 (error "Archive is read-only"))
1056 (or (yes-or-no-p (format "Really delete %d member%s? "
1058 (if (null (cdr files)) "" "s")))
1059 (error "Operation aborted"))
1060 (let ((archive (archive-maybe-copy (buffer-file-name)))
1061 (expunger (archive-name "expunge")))
1062 (if (fboundp expunger)
1063 (funcall expunger archive files)
1064 (archive-*-expunge archive files (symbol-value expunger)))
1065 (archive-maybe-update nil)
1067 (archive-resummarize)
1068 (revert-buffer))))))
1070 (defun archive-*-expunge (archive files command)
1071 (apply 'call-process
1076 (append (cdr command) (cons archive files))))
1078 (defun archive-rename-entry (newname)
1079 "Change the name associated with this entry in the tar file."
1080 (interactive "sNew name: ")
1081 (if archive-read-only (error "Archive is read-only"))
1082 (if (string= newname "")
1083 (error "Archive members may not be given empty names"))
1084 (let ((func (archive-name "rename-entry"))
1085 (descr (archive-get-descr)))
1088 (funcall func (buffer-file-name) newname descr)
1089 (archive-resummarize))
1090 (error "Renaming is not supported for this archive type"))))
1092 ;; Revert the buffer and recompute the dired-like listing.
1093 (defun archive-mode-revert (&optional no-autosave no-confirm)
1094 (let ((no (archive-get-lineno)))
1095 (setq archive-files nil)
1096 (let ((revert-buffer-function nil))
1097 (revert-buffer t t))
1099 (goto-char archive-file-list-start)
1100 (archive-next-line no)))
1102 (defun archive-undo ()
1103 "Undo in an archive buffer.
1104 This doesn't recover lost files, it just undoes changes in the buffer itself."
1106 (let (buffer-read-only)
1108 ;; -------------------------------------------------------------------------
1109 ;; Section: Arc Archives
1111 (defun archive-arc-summarize ()
1117 (while (and (< (+ p 29) (point-max))
1118 (= (char-after p) ?\C-z)
1119 (> (char-after (1+ p)) 0))
1120 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13)))
1121 (fnlen (or (string-match "\0" namefld) 13))
1122 (efnname (substring namefld 0 fnlen))
1123 (csize (archive-l-e (+ p 15) 4))
1124 (moddate (archive-l-e (+ p 19) 2))
1125 (modtime (archive-l-e (+ p 21) 2))
1126 (ucsize (archive-l-e (+ p 25) 4))
1127 (fiddle (string= efnname (upcase efnname)))
1128 (ifnname (if fiddle (downcase efnname) efnname))
1129 (text (format " %8d %-11s %-8s %s"
1131 (archive-dosdate moddate)
1132 (archive-dostime modtime)
1134 (setq maxlen (max maxlen fnlen)
1135 totalsize (+ totalsize ucsize)
1136 visual (cons (vector text
1137 (- (length text) (length ifnname))
1140 files (cons (vector efnname ifnname fiddle nil (1- p))
1143 (goto-char (point-min))
1144 (let ((dash (concat "- -------- ----------- -------- "
1145 (make-string maxlen ?-)
1147 (insert "M Length Date Time File\n"
1149 (archive-summarize-files (nreverse visual))
1151 (format " %8d %d file%s"
1154 (if (= 1 (length files)) "" "s"))
1156 (apply 'vector (nreverse files))))
1158 (defun archive-arc-rename-entry (archive newname descr)
1159 (if (string-match "[:\\\\/]" newname)
1160 (error "File names in arc files may not contain a path"))
1161 (if (> (length newname) 12)
1162 (error "File names in arc files are limited to 12 characters"))
1163 (let ((name (concat newname (substring "\0\0\0\0\0\0\0\0\0\0\0\0\0"
1169 (goto-char (+ archive-proper-file-start (aref descr 4) 2))
1172 ;; -------------------------------------------------------------------------
1173 ;; Section: Lzh Archives
1175 (defun archive-lzh-summarize ()
1181 (while (progn (goto-char p) (looking-at "..-l[hz][0-9]-"))
1182 (let* ((hsize (char-after p))
1183 (csize (archive-l-e (+ p 7) 4))
1184 (ucsize (archive-l-e (+ p 11) 4))
1185 (modtime (archive-l-e (+ p 15) 2))
1186 (moddate (archive-l-e (+ p 17) 2))
1187 (fnlen (char-after (+ p 21)))
1188 (efnname (buffer-substring (+ p 22) (+ p 22 fnlen)))
1189 (fiddle (string= efnname (upcase efnname)))
1190 (ifnname (if fiddle (downcase efnname) efnname))
1192 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0))
1193 (mode (if (= creator ?U) (archive-l-e (+ p2 8) 2) ?\666))
1194 (modestr (if mode (archive-int-to-mode mode) "??????????"))
1195 (uid (if (= creator ?U) (archive-l-e (+ p2 10) 2)))
1196 (gid (if (= creator ?U) (archive-l-e (+ p2 12) 2)))
1197 (text (if archive-alternate-display
1198 (format " %8d %5S %5S %s"
1203 (format " %10s %8d %-11s %-8s %s"
1206 (archive-dosdate moddate)
1207 (archive-dostime modtime)
1209 (setq maxlen (max maxlen fnlen)
1210 totalsize (+ totalsize ucsize)
1211 visual (cons (vector text
1212 (- (length text) (length ifnname))
1215 files (cons (vector efnname ifnname fiddle mode (1- p))
1217 p (+ p hsize 2 csize))))
1218 (goto-char (point-min))
1219 (let ((dash (concat (if archive-alternate-display
1220 "- -------- ----- ----- "
1221 "- ---------- -------- ----------- -------- ")
1222 (make-string maxlen ?-)
1224 (header (if archive-alternate-display
1225 "M Length Uid Gid File\n"
1226 "M Filemode Length Date Time File\n"))
1227 (sumline (if archive-alternate-display
1230 (insert header dash)
1231 (archive-summarize-files (nreverse visual))
1236 (if (= 1 (length files)) "" "s"))
1238 (apply 'vector (nreverse files))))
1240 (defconst archive-lzh-alternate-display t)
1242 (defun archive-lzh-extract (archive name)
1243 (archive-extract-by-stdout archive name archive-lzh-extract))
1245 (defun archive-lzh-resum (p count)
1248 (setq count (1- count)
1249 sum (+ sum (char-after p))
1253 (defun archive-lzh-rename-entry (archive newname descr)
1257 (let* ((p (+ archive-proper-file-start (aref descr 4)))
1258 (oldhsize (char-after p))
1259 (oldfnlen (char-after (+ p 21)))
1260 (newfnlen (length newname))
1261 (newhsize (+ oldhsize newfnlen (- oldfnlen)))
1263 (if (> newhsize 255)
1264 (error "The file name is too long"))
1265 (goto-char (+ p 21))
1266 (delete-char (1+ oldfnlen))
1267 (insert newfnlen newname)
1270 (insert newhsize (archive-lzh-resum p newhsize))))))
1272 (defun archive-lzh-ogm (newval files errtxt ofs)
1277 (let* ((fil (car files))
1278 (p (+ archive-proper-file-start (aref fil 4)))
1279 (hsize (char-after p))
1280 (fnlen (char-after (+ p 21)))
1282 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0))
1286 (or (numberp newval)
1287 (setq newval (funcall newval (archive-l-e (+ p2 ofs) 2))))
1288 (goto-char (+ p2 ofs))
1290 (insert (logand newval 255) (lsh newval -8))
1293 (insert (archive-lzh-resum (1+ p) hsize)))
1294 (message "Member %s does not have %s field"
1295 (aref fil 1) errtxt)))
1296 (setq files (cdr files))))))
1298 (defun archive-lzh-chown-entry (newuid files)
1299 (archive-lzh-ogm newuid files "an uid" 10))
1301 (defun archive-lzh-chgrp-entry (newgid files)
1302 (archive-lzh-ogm newgid files "a gid" 12))
1304 (defun archive-lzh-chmod-entry (newmode files)
1306 ;; This should work even though newmode will be dynamically accessed.
1307 (function (lambda (old) (archive-calc-mode old newmode t)))
1308 files "a unix-style mode" 8))
1309 ;; -------------------------------------------------------------------------
1310 ;; Section: Zip Archives
1312 (defun archive-zip-summarize ()
1313 (goto-char (- (point-max) (- 22 18)))
1314 (search-backward-regexp "[P]K\005\006")
1315 (let ((p (1+ (archive-l-e (+ (point) 16) 4)))
1320 (while (string= "PK\001\002" (buffer-substring p (+ p 4)))
1321 (let* ((creator (char-after (+ p 5)))
1322 (method (archive-l-e (+ p 10) 2))
1323 (modtime (archive-l-e (+ p 12) 2))
1324 (moddate (archive-l-e (+ p 14) 2))
1325 (ucsize (archive-l-e (+ p 24) 4))
1326 (fnlen (archive-l-e (+ p 28) 2))
1327 (exlen (archive-l-e (+ p 30) 2))
1328 (fclen (archive-l-e (+ p 32) 2))
1329 (lheader (archive-l-e (+ p 42) 4))
1330 (efnname (buffer-substring (+ p 46) (+ p 46 fnlen)))
1331 (isdir (and (= ucsize 0)
1332 (string= (file-name-nondirectory efnname) "")))
1333 (mode (cond ((memq creator '(2 3)) ; Unix + VMS
1334 (archive-l-e (+ p 40) 2))
1335 ((memq creator '(0 5 6 7 10 11)) ; Dos etc.
1337 (if isdir (logior 16384 ?\111) 0)
1339 (logand 1 (char-after (+ p 38))))
1342 (modestr (if mode (archive-int-to-mode mode) "??????????"))
1343 (fiddle (and archive-zip-case-fiddle
1344 (not (not (memq creator '(0 2 4 5 9))))))
1345 (ifnname (if fiddle (downcase efnname) efnname))
1346 (text (format " %10s %8d %-11s %-8s %s"
1349 (archive-dosdate moddate)
1350 (archive-dostime modtime)
1352 (setq maxlen (max maxlen fnlen)
1353 totalsize (+ totalsize ucsize)
1354 visual (cons (vector text
1355 (- (length text) (length ifnname))
1358 files (cons (if isdir
1360 (vector efnname ifnname fiddle mode
1361 (list (1- p) lheader)))
1363 p (+ p 46 fnlen exlen fclen))))
1364 (goto-char (point-min))
1365 (let ((dash (concat "- ---------- -------- ----------- -------- "
1366 (make-string maxlen ?-)
1368 (insert "M Filemode Length Date Time File\n"
1370 (archive-summarize-files (nreverse visual))
1372 (format " %8d %d file%s"
1375 (if (= 1 (length files)) "" "s"))
1377 (apply 'vector (nreverse files))))
1379 (defun archive-zip-extract (archive name)
1380 (if archive-zip-use-pkzip
1381 (archive-*-extract archive name archive-zip-extract)
1382 (archive-extract-by-stdout archive name archive-zip-extract)))
1384 (defun archive-zip-write-file-member (archive descr)
1385 (archive-*-write-file-member
1388 (if (aref descr 2) archive-zip-update-case archive-zip-update)))
1390 (defun archive-zip-chmod-entry (newmode files)
1395 (let* ((fil (car files))
1396 (p (+ archive-proper-file-start (car (aref fil 4))))
1397 (creator (char-after (+ p 5)))
1398 (oldmode (aref fil 3))
1399 (newval (archive-calc-mode oldmode newmode t))
1401 (cond ((memq creator '(2 3)) ; Unix + VMS
1402 (goto-char (+ p 40))
1404 (insert (logand newval 255) (lsh newval -8)))
1405 ((memq creator '(0 5 6 7 10 11)) ; Dos etc.
1406 (goto-char (+ p 38))
1407 (insert (logior (logand (char-after (point)) 254)
1408 (logand (logxor 1 (lsh newval -7)) 1)))
1410 (t (message "Don't know how to change mode for this member"))))
1411 (setq files (cdr files))))))
1412 ;; -------------------------------------------------------------------------
1413 ;; Section: Zoo Archives
1415 (defun archive-zoo-summarize ()
1416 (let ((p (1+ (archive-l-e 25 4)))
1421 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4)))
1422 (> (archive-l-e (+ p 6) 4) 0))
1423 (let* ((next (1+ (archive-l-e (+ p 6) 4)))
1424 (moddate (archive-l-e (+ p 14) 2))
1425 (modtime (archive-l-e (+ p 16) 2))
1426 (ucsize (archive-l-e (+ p 20) 4))
1427 (namefld (buffer-substring (+ p 38) (+ p 38 13)))
1428 (dirtype (char-after (+ p 4)))
1429 (lfnlen (if (= dirtype 2) (char-after (+ p 56)) 0))
1430 (ldirlen (if (= dirtype 2) (char-after (+ p 57)) 0))
1434 (or (string-match "\0" namefld) 13))))
1437 (concat (buffer-substring
1438 (+ p 58 lfnlen) (+ p 58 lfnlen ldirlen -1))
1442 (buffer-substring (+ p 58) (+ p 58 lfnlen -1))
1443 (substring namefld 0 fnlen))))
1444 (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname))))
1445 (ifnname (if fiddle (downcase efnname) efnname))
1446 (text (format " %8d %-11s %-8s %s"
1448 (archive-dosdate moddate)
1449 (archive-dostime modtime)
1451 (setq maxlen (max maxlen fnlen)
1452 totalsize (+ totalsize ucsize)
1453 visual (cons (vector text
1454 (- (length text) (length ifnname))
1457 files (cons (vector efnname ifnname fiddle nil (1- p))
1460 (goto-char (point-min))
1461 (let ((dash (concat "- -------- ----------- -------- "
1462 (make-string maxlen ?-)
1464 (insert "M Length Date Time File\n"
1466 (archive-summarize-files (nreverse visual))
1468 (format " %8d %d file%s"
1471 (if (= 1 (length files)) "" "s"))
1473 (apply 'vector (nreverse files))))
1475 (defun archive-zoo-extract (archive name)
1476 (archive-extract-by-stdout archive name archive-zoo-extract))
1477 ;; -------------------------------------------------------------------------
1478 (provide 'archive-mode)
1480 ;; arc-mode.el ends here.