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