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