annotate lisp/packages/tar-mode.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 441bb1e64a06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; tar-mode.el --- simple editing of tar files from GNU emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Keywords: unix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; File: tar-mode.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; Description: simple editing of tar files from GNU emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Author: Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; Created: 4 Apr 1990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Version: 1.31, 15 Dec 93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; Copyright (C) 1990-1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
25 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
27 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Synched up with: Not synched with FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; This package attempts to make dealing with Unix 'tar' archives easier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; When this code is loaded, visiting a file whose name ends in '.tar' will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; cause the contents of that archive file to be displayed in a Dired-like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; listing. It is then possible to use the customary Dired keybindings to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; extract sub-files from that archive, either by reading them into their own
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; editor buffers, or by copying them directly to arbitrary files on disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; It is also possible to delete sub-files from within the tar file and write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; the modified archive back to disk, or to edit sub-files within the archive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; and re-insert the modified files into the archive. See the documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; string of tar-mode for more info.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; To autoload, add this to your .emacs file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; (setq auto-mode-alist (cons '("\\.tar$" . tar-mode) auto-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; (autoload 'tar-mode "tar-mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; But beware: for certain tar files - those whose very first file has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; a -*- property line - autoloading won't work. See the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; "tar-normal-mode" to understand why.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; This code now understands the extra fields that GNU tar adds to tar files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; This interacts correctly with "uncompress.el" in the Emacs library,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; and with sufficiently recent versions of "crypt.el" by Kyle Jones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; *************** TO DO ***************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; o There should be a command to extract the whole current buffer into files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; on disk (right now you have to do the subfiles one at a time.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; o chmod should understand "a+x,og-w".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; o It's not possible to add a NEW file to a tar archive; not that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; important, but still...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; o The code is less efficient that it could be - in a lot of places, I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; pull a 512-character string out of the buffer and parse it, when I could
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; be parsing it in place, not garbaging a string. Should redo that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; o I'd like a command that searches for a string/regexp in every subfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; of an archive, where <esc> would leave you in a subfile-edit buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; (Like M-s in VM and M-r in the Zmacs mail reader.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; o Sometimes (but not always) reverting the tar-file buffer does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; re-grind the listing, and you are staring at the binary tar data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; Typing 'g' again immediately after that will always revert and re-grind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; it, though. I have no idea why this happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; o If you edit a subfile, and selective-display gets set to t, then when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; we save the subfile, we should map ^M -> ^J.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; o Block files, sparse files, continuation files, and the various header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; types aren't editable. Actually I don't know that they work at all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; If you know that they work, or know that they don't, please let me know.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; o Tar files inside of tar files don't work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; o When using crypt-mode, you can't save a compressed or encrypted subfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; of a tar file back into the tar file: it is saved uncompressed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar tar-anal-blocksize 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "*The blocksize of tar files written by Emacs, or nil, meaning don't care.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 The blocksize of a tar file is not really the size of the blocks; rather, it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 the number of blocks written with one system call. When tarring to a tape,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 this is the size of the *tape* blocks, but when writing to a file, it doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 matter much. The only noticeable difference is that if a tar file does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 have a blocksize of 20, the tar program will issue a warning; all this really
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 controls is how many null padding bytes go on the end of the tar file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar tar-update-datestamp (or (fboundp 'current-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (fboundp 'current-time-seconds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "*Whether tar-mode should play fast and loose with sub-file datestamps;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 if this is true, then editing and saving a tar file entry back into its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 tar file will update its datestamp. If false, the datestamp is unchanged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 You may or may not want this - it is good in that you can tell when a file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 in a tar archive has been changed, but it is bad for the same reason that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 editing a file in the tar archive at all is bad - the changed version of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 the file never exists on disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 This does not work in Emacs 18, because there's no way to get the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 time as an integer - if this var is true, then editing a file sets its date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 to midnight, Jan 1 1970 GMT, which happens to be what 0 encodes.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; First, duplicate some Common Lisp functions; I used to just (require 'cl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; but "cl.el" was messing some people up (also it's really big).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defmacro tar-setf (form val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "A mind-numbingly simple implementation of setf."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((mform (macroexpand form (and (boundp 'byte-compile-macro-environment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 byte-compile-macro-environment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (cond ((symbolp mform) (list 'setq mform val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ((not (consp mform)) (error "can't setf %s" form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ((eq (car mform) 'aref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (list 'aset (nth 1 mform) (nth 2 mform) val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ((eq (car mform) 'car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (list 'setcar (nth 1 mform) val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ((eq (car mform) 'cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (list 'setcdr (nth 1 mform) val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (t (error "don't know how to setf %s" form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defmacro tar-dolist (control &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "syntax: (dolist (var-name list-expr &optional return-value) &body body)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (let ((var (car control))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (init (car (cdr control)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (val (car (cdr (cdr control)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (list 'let (list (list '_dolist_iterator_ init))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (list 'while '_dolist_iterator_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (cons 'let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (cons (list (list var '(car _dolist_iterator_)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (append body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (list (list 'setq '_dolist_iterator_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (list 'cdr '_dolist_iterator_)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defmacro tar-dotimes (control &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "syntax: (dotimes (var-name count-expr &optional return-value) &body body)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (let ((var (car control))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (n (car (cdr control)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (val (car (cdr (cdr control)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (list 'let (list (list '_dotimes_end_ n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (list var 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (cons 'while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (cons (list '< var '_dotimes_end_)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (append body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (list (list 'setq var (list '1+ var))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;; down to business.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defmacro make-tar-header (name mode uid git size date ck lt ln
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 magic uname gname devmaj devmin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (list 'vector name mode uid git size date ck lt ln
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 magic uname gname devmaj devmin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defmacro tar-header-name (x) (list 'aref x 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defmacro tar-header-mode (x) (list 'aref x 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defmacro tar-header-uid (x) (list 'aref x 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defmacro tar-header-gid (x) (list 'aref x 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defmacro tar-header-size (x) (list 'aref x 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (defmacro tar-header-date (x) (list 'aref x 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defmacro tar-header-checksum (x) (list 'aref x 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defmacro tar-header-link-type (x) (list 'aref x 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defmacro tar-header-link-name (x) (list 'aref x 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defmacro tar-header-magic (x) (list 'aref x 9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defmacro tar-header-uname (x) (list 'aref x 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defmacro tar-header-gname (x) (list 'aref x 11))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defmacro tar-header-dmaj (x) (list 'aref x 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defmacro tar-header-dmin (x) (list 'aref x 13))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defmacro make-tar-desc (data-start tokens)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (list 'cons data-start tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (defmacro tar-desc-data-start (x) (list 'car x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defmacro tar-desc-tokens (x) (list 'cdr x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defconst tar-name-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (defconst tar-mode-offset (+ tar-name-offset 100))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defconst tar-uid-offset (+ tar-mode-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defconst tar-gid-offset (+ tar-uid-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (defconst tar-size-offset (+ tar-gid-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defconst tar-time-offset (+ tar-size-offset 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (defconst tar-chk-offset (+ tar-time-offset 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defconst tar-linkp-offset (+ tar-chk-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defconst tar-link-offset (+ tar-linkp-offset 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;;; GNU-tar specific slots.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defconst tar-magic-offset (+ tar-link-offset 100))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (defconst tar-uname-offset (+ tar-magic-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defconst tar-gname-offset (+ tar-uname-offset 32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defconst tar-dmaj-offset (+ tar-gname-offset 32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defconst tar-dmin-offset (+ tar-dmaj-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defconst tar-end-offset (+ tar-dmin-offset 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun tokenize-tar-header-block (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "Returns a 'tar-header' structure (a list of name, mode, uid, gid, size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 write-date, checksum, link-type, and link-name)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (cond ((< (length string) 512) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (;(some 'plusp string) ; <-- oops, massive cycle hog!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (or (not (= 0 (aref string 0))) ; This will do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (not (= 0 (aref string 101))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (let* ((name-end (1- tar-mode-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (link-end (1- tar-magic-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (uname-end (1- tar-gname-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (gname-end (1- tar-dmaj-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (link-p (aref string tar-linkp-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (magic-str (substring string tar-magic-offset (1- tar-uname-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (uname-valid-p (or (string= "ustar " magic-str) (string= "GNUtar " magic-str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (nulsexp "[^\000]*\000"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (and (string-match nulsexp string tar-name-offset) (setq name-end (min name-end (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (and (string-match nulsexp string tar-link-offset) (setq link-end (min link-end (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (and (string-match nulsexp string tar-uname-offset) (setq uname-end (min uname-end (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (and (string-match nulsexp string tar-gname-offset) (setq gname-end (min gname-end (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (setq name (substring string tar-name-offset name-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 link-p (if (or (= link-p 0) (= link-p ?0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (- link-p ?0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (and (null link-p) (string-match "/$" name)) (setq link-p 5)) ; directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (make-tar-header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (tar-parse-octal-integer string tar-mode-offset (1- tar-uid-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (tar-parse-octal-integer string tar-uid-offset (1- tar-gid-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (tar-parse-octal-integer string tar-gid-offset (1- tar-size-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (tar-parse-octal-integer string tar-size-offset (1- tar-time-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (tar-parse-octal-integer-32 string tar-time-offset (1- tar-chk-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (tar-parse-octal-integer string tar-chk-offset (1- tar-linkp-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 link-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (substring string tar-link-offset link-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 uname-valid-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (and uname-valid-p (substring string tar-uname-offset uname-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (and uname-valid-p (substring string tar-gname-offset gname-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (tar-parse-octal-integer string tar-dmaj-offset (1- tar-dmin-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (tar-parse-octal-integer string tar-dmin-offset (1- tar-end-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (t 'empty-tar-block)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defun tar-parse-octal-integer (string &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "deletes all your files, and then reboots."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (if (null start) (setq start 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (if (null end) (setq end (length string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (if (= (aref string start) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (let ((n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (while (< start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq n (if (< (aref string start) ?0) n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (+ (* n 8) (- (aref string start) 48)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 start (1+ start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (defun tar-parse-octal-integer-32 (string &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; like tar-parse-octal-integer, but returns a cons of two 16-bit numbers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; since elisp can't handle integers of that magnitude.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (or start (setq start 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (or end (setq end (length string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (let ((top (tar-parse-octal-integer string start (- end 6)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (bot (tar-parse-octal-integer string (- end 6) end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (setq top (logior (ash top 2) (ash bot -16)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq bot (logand bot 65535))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (cons top bot)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defun tar-parse-octal-integer-safe (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (let ((L (length string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if (= L 0) (error "empty string"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (tar-dotimes (i L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (or (< (aref string i) ?0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (> (aref string i) ?7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (error "'%c' is not an octal digit."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (tar-parse-octal-integer string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (defun checksum-tar-header-block (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 "Computes and returns a tar-acceptable checksum for this block."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (let* ((chk-field-start tar-chk-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (chk-field-end (+ chk-field-start 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (sum 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;; Add up all of the characters except the ones in the checksum field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; Add that field as if it were filled with spaces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (while (< i chk-field-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq sum (+ sum (aref string i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (setq i chk-field-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (while (< i 512)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setq sum (+ sum (aref string i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (+ sum (* 32 8))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (defun check-tar-header-block-checksum (hblock desired-checksum file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 "Beep and print a warning if the checksum doesn't match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (not (= desired-checksum (checksum-tar-header-block hblock)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (progn (beep) (message "Invalid checksum for file %s!" file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defun recompute-tar-header-block-checksum (hblock)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "Modifies the given string to have a valid checksum field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (let* ((chk (checksum-tar-header-block hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (chk-string (format "%6o" chk))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (l (length chk-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (aset hblock 154 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (aset hblock 155 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (tar-dotimes (i l) (aset hblock (- 153 i) (aref chk-string (- l i 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 hblock)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defun tar-grind-file-mode (mode string start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "Write a \"-rw--r--r-\" representing MODE into STRING beginning at START."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (aset string start (if (zerop (logand 256 mode)) ?- ?r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (aset string (+ start 1) (if (zerop (logand 128 mode)) ?- ?w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (aset string (+ start 2) (if (zerop (logand 64 mode)) ?- ?x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (aset string (+ start 3) (if (zerop (logand 32 mode)) ?- ?r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (aset string (+ start 4) (if (zerop (logand 16 mode)) ?- ?w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (aset string (+ start 5) (if (zerop (logand 8 mode)) ?- ?x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (aset string (+ start 6) (if (zerop (logand 4 mode)) ?- ?r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (aset string (+ start 7) (if (zerop (logand 2 mode)) ?- ?w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (aset string (+ start 8) (if (zerop (logand 1 mode)) ?- ?x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (if (zerop (logand 1024 mode)) nil (aset string (+ start 2) ?s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (if (zerop (logand 2048 mode)) nil (aset string (+ start 5) ?s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (defconst tar-can-print-dates (or (fboundp 'current-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (fboundp 'current-time-seconds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 "true if this emacs has been built with time-printing support")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (defun summarize-tar-header-block (tar-hblock &optional mod-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 "Returns a line similar to the output of 'tar -vtf'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (let ((name (tar-header-name tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (mode (tar-header-mode tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (uid (tar-header-uid tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (gid (tar-header-gid tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (uname (tar-header-uname tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (gname (tar-header-gname tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (size (tar-header-size tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (time (tar-header-date tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (ck (tar-header-checksum tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (link-p (tar-header-link-type tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (link-name (tar-header-link-name tar-hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (let* ((left 11)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (namew 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (groupw 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (sizew 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (datew (if tar-can-print-dates 15 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (slash (1- (+ left namew)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (lastdigit (+ slash groupw sizew))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (namestart (+ lastdigit datew))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (string (make-string (+ namestart (length name) (if link-p (+ 5 (length link-name)) 0)) 32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (type (tar-header-link-type tar-hblock)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (aset string 0 (if mod-p ?* ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (aset string 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (cond ((or (eq type nil) (eq type 0)) ?-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ((eq type 1) ?l) ; link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ((eq type 2) ?s) ; symlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ((eq type 3) ?c) ; char special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ((eq type 4) ?b) ; block special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ((eq type 5) ?d) ; directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ((eq type 6) ?p) ; FIFO/pipe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ((eq type 20) ?*) ; directory listing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ((eq type 29) ?M) ; multivolume continuation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ((eq type 35) ?S) ; sparse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ((eq type 38) ?V) ; volume header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (tar-grind-file-mode mode string 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (setq uid (if (= 0 (length uname)) (int-to-string uid) uname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq gid (if (= 0 (length gname)) (int-to-string gid) gname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (setq size (int-to-string size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (tar-dotimes (i (min (1- namew) (length uid))) (aset string (- slash i) (aref uid (- (length uid) i 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (aset string (1+ slash) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (tar-dotimes (i (min (1- groupw) (length gid))) (aset string (+ (+ slash 2) i) (aref gid i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (tar-dotimes (i (min sizew (length size))) (aset string (- lastdigit i) (aref size (- (length size) i 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (if tar-can-print-dates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (let* ((year (substring (current-time-string) -4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;; in v18, current-time-string doesn't take an argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (file (current-time-string time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (file-year (substring file -4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (str (if (equal year file-year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (substring file 4 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (concat (substring file 4 11) " " file-year))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (tar-dotimes (i 12) (aset string (- namestart (- 13 i)) (aref str i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (tar-dotimes (i (length name)) (aset string (+ namestart i) (aref name i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if (or (eq link-p 1) (eq link-p 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (tar-dotimes (i 3) (aset string (+ namestart 1 (length name) i) (aref (if (= link-p 1) "==>" "-->") i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (tar-dotimes (i (length link-name)) (aset string (+ namestart 5 (length name) i) (aref link-name i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 ;; buffer-local variables in the tar file's buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (defvar tar-parse-info) ; the header structures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (defvar tar-header-offset) ; the end of the "pretty" data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (defun tar-summarize-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 "Parse the contents of the tar file in the current buffer, and place a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 dired-like listing on the front; then narrow to it, so that only that listing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 is visible (and the real data of the buffer is hidden)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (message "parsing tar file...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (let* ((result '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (pos 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (bs (max 1 (- (buffer-size) 1024))) ; always 2+ empty blocks at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (bs100 (max 1 (/ bs 100)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (tokens nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (while (not (eq tokens 'empty-tar-block))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if (> (+ pos 512) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (error "truncated tar file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (let* ((hblock (buffer-substring pos (+ pos 512))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (setq tokens (tokenize-tar-header-block hblock))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq pos (+ pos 512))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (message "parsing tar file...%s%%"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;(/ (* pos 100) bs) ; this gets round-off lossage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (/ pos bs100) ; this doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (if (eq tokens 'empty-tar-block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if (null tokens) (error "premature EOF parsing tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (if (eq (tar-header-link-type tokens) 20)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;; Foo. There's an extra empty block after these.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (setq pos (+ pos 512)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let ((size (tar-header-size tokens)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if (< size 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (error "%s has size %s - corrupted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (tar-header-name tokens) size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ; This is just too slow. Don't really need it anyway....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;(check-tar-header-block-checksum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ; hblock (checksum-tar-header-block hblock)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ; (tar-header-name tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq result (cons (make-tar-desc pos tokens) result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (if (and (null (tar-header-link-type tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (> size 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (setq pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (+ pos 512 (ash (ash (1- size) -9) 9)) ; this works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;(+ pos (+ size (- 512 (rem (1- size) 512)))) ; this doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (make-local-variable 'tar-parse-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (setq tar-parse-info (nreverse result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (message "parsing tar file...formatting...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (tar-dolist (tar-desc tar-parse-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (summarize-tar-header-block (tar-desc-tokens tar-desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (make-local-variable 'tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (setq tar-header-offset (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (narrow-to-region 1 tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (set-buffer-modified-p nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (message "parsing tar file...done."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (defvar tar-mode-map nil "*Local keymap for tar-mode listings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (if tar-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (setq tar-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (suppress-keymap tar-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (define-key tar-mode-map " " 'tar-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (define-key tar-mode-map "c" 'tar-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (define-key tar-mode-map "d" 'tar-flag-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (define-key tar-mode-map "\^D" 'tar-flag-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (define-key tar-mode-map "e" 'tar-extract)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (define-key tar-mode-map "f" 'tar-extract)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (define-key tar-mode-map "g" 'revert-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (define-key tar-mode-map "h" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (define-key tar-mode-map "n" 'tar-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (define-key tar-mode-map "\^N" 'tar-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (define-key tar-mode-map "o" 'tar-extract-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (define-key tar-mode-map "\^C" 'tar-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (define-key tar-mode-map "p" 'tar-previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (define-key tar-mode-map "\^P" 'tar-previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (define-key tar-mode-map "r" 'tar-rename-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (define-key tar-mode-map "u" 'tar-unflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (define-key tar-mode-map "v" 'tar-view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (define-key tar-mode-map "x" 'tar-expunge)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (define-key tar-mode-map "\177" 'tar-unflag-backwards)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (define-key tar-mode-map "E" 'tar-extract-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (define-key tar-mode-map "M" 'tar-chmod-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (define-key tar-mode-map "G" 'tar-chgrp-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (define-key tar-mode-map "O" 'tar-chown-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (cond ((string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (define-key tar-mode-map 'button2 'tar-track-mouse-and-extract-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (define-key tar-mode-map 'button3 'tar-popup-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; XEmacs menu mouse/support added by Heiko Muenkel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ;; muenkel@tnt.uni-hannover.de
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (autoload 'dired-mark-region "dired-xemacs-menu")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (defvar tar-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 '("Tar Mode Commands"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ["Copy Subfile to Disk" tar-copy t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ["Rename Subfile" tar-rename-entry t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ["Delete Flaged Subfiles" tar-expunge t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ["Flag Subfile for Deletion" tar-flag-deleted t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ["Flag Subfiles in Region for Deletion"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (dired-mark-region '(tar-flag-deleted 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ["Unflag Subfile" tar-unflag t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ["Unflag Subfiles in Region"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (dired-mark-region '(tar-flag-deleted 1 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ["Change Permissions of Subfile..." tar-chmod-entry t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ["Change Group of Subfile..." tar-chgrp-entry t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ["Change Owner of Subfile..." tar-chown-entry t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 "----"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ["Edit Subfile Other Window" tar-extract-other-window t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ["Edit Subfile" tar-extract t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ["View Subfile" tar-view t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (defun tar-track-mouse-and-extract-file (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 "Visit the tar-file-entry upon which the mouse is clicked."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (tar-next-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (let (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (tar-extract)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (switch-to-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (defun tar-popup-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 "Display the tar-mode menu."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (tar-next-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (popup-menu tar-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; tar mode is suitable only for specially formatted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (put 'tar-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (put 'tar-subfile-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defun tar-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 "Major mode for viewing a tar file as a dired-like listing of its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 You can move around using the usual cursor motion commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 Letters no longer insert themselves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 Type 'e' to pull a file out of the tar file and into its own buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 Type 'c' to copy an entry from the tar file into another file on disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 If you edit a sub-file of this archive (as with the 'e' command) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 save it with Control-X Control-S, the contents of that buffer will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 saved back into the tar-file buffer; in this way you can edit a file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 inside of a tar archive without extracting it and re-archiving it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 See also: variables tar-update-datestamp and tar-anal-blocksize.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 \\{tar-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ;; this is not interactive because you shouldn't be turning this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;; mode on and off. You can corrupt things that way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (make-local-variable 'tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (make-local-variable 'tar-parse-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (make-local-variable 'require-final-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (setq require-final-newline nil) ; binary data, dude...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (make-local-variable 'revert-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (setq revert-buffer-function 'tar-mode-revert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq major-mode 'tar-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (setq mode-name "Tar")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (use-local-map tar-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (auto-save-mode 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (if (and (boundp 'tar-header-offset) tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (narrow-to-region 1 tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (tar-summarize-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (cond ((string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (require 'mode-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (setq mode-motion-hook 'mode-motion-highlight-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (if (and current-menubar (not (assoc "Tar" current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (set-buffer-menubar (copy-sequence current-menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (add-menu nil "Tar" (cdr tar-menu))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (run-hooks 'tar-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 ;; buffer-local variables in subfile mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (defvar tar-subfile-mode nil) ; whether the minor-mode is on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (defvar superior-tar-buffer) ; parent buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (defvar superior-tar-descriptor) ; header object of this file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (defvar tar-subfile-buffer-id) ; pretty name-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (defvar subfile-orig-mlbid) ; orig mode-line-buffer-identification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (defun tar-subfile-mode (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 "Minor mode for editing an element of a tar-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 This mode redefines ^X^S to save the current buffer back into its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 associated tar-file buffer. You must save that buffer to actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 save your changes to disk."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (or (and (boundp 'superior-tar-buffer) superior-tar-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (error "This buffer is not an element of a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (or (assq 'tar-subfile-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (setq minor-mode-alist (append minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (list '(tar-subfile-mode " TarFile")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (make-local-variable 'tar-subfile-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (setq tar-subfile-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (if (null p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (not tar-subfile-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (> (prefix-numeric-value p) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (cond (tar-subfile-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 ;; copy the local keymap so that we don't accidentally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ;; alter a keymap like 'lisp-mode-map' which is shared
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ;; by all buffers in that mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (let ((m (current-local-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (if m (use-local-map (copy-keymap m))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (local-set-key "\^X\^S" 'tar-subfile-save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ;; turn off auto-save.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (auto-save-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (setq buffer-auto-save-file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (run-hooks 'tar-subfile-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; remove the local binding for C-x C-s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (local-unset-key "\^X\^S")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (if subfile-orig-mlbid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (set (make-local-variable 'mode-line-buffer-identification)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 subfile-orig-mlbid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (setq superior-tar-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 superior-tar-descriptor nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 subfile-orig-mlbid nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (defun tar-subfile-after-write-file-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 ;; if the buffer has a filename, then it is no longer associated with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 ;; the tar file. Turn off subfile mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (if (and buffer-file-name tar-subfile-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (tar-subfile-mode -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (defun tar-mode-revert (&optional no-autosave no-confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 "Revert this buffer and turn on tar mode again, to re-compute the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 directory listing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (setq tar-header-offset nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (let ((revert-buffer-function nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (revert-buffer t no-confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (widen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (tar-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (defun tar-next-line (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (forward-line p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (if (eobp) nil (forward-char (if tar-can-print-dates 48 36))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (defun tar-previous-line (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (tar-next-line (- p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defun tar-current-descriptor (&optional noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 "Returns the tar-descriptor of the current line, or signals an error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 ;; I wish lines had plists, like in ZMACS...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (or (nth (count-lines (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (save-excursion (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 tar-parse-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (if noerror
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (error "This line does not describe a tar-file entry."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (defun tar-extract (&optional other-window-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 "*In tar-mode, extract this entry of the tar file into its own buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (let* ((view-p (eq other-window-p 'view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (descriptor (tar-current-descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (tokens (tar-desc-tokens descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (name (tar-header-name tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (size (tar-header-size tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (link-p (tar-header-link-type tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (start (+ (tar-desc-data-start descriptor) tar-header-offset -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (end (+ start size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (if link-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (error "This is a %s, not a real file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (cond ((eq link-p 5) "directory")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ((eq link-p 20) "tar directory header")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 ((eq link-p 29) "multivolume-continuation")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ((eq link-p 35) "sparse entry")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ((eq link-p 38) "volume header")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (t "link"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (if (zerop size) (error "This is a zero-length file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (let* ((tar-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (bufname (file-name-nondirectory name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (bufid (concat ;" (" name " in "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 " (in "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (file-name-nondirectory (buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ")"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (read-only-p (or buffer-read-only view-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (buffers (buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (just-created nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;; find a buffer visiting this subfile from this tar file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (while (and buffers (not buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (set-buffer (car buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (if (and (null (buffer-file-name (car buffers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (boundp 'superior-tar-descriptor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (eq superior-tar-descriptor descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (setq buffer (car buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (setq buffers (cdr buffers))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (set-buffer tar-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (if buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (setq buffer (generate-new-buffer bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (setq just-created t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (insert-buffer-substring tar-buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (goto-char 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (let ((lock-directory nil)) ; disable locking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (set-visited-file-name name) ; give it a name to decide mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; (normal-mode) ; pick a mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; (after-find-file nil nil) ; pick a mode; works with crypt.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; Ok, instead of running after-find-file, just invoke the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;; find-file-hooks instead. This does everything we want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;; from after-find-file, without losing when visiting .tar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;; files via ange-ftp: doesn't probe the ftp site for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ;; name of the subfile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (normal-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (run-hooks 'find-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (set-visited-file-name nil) ; nuke the name - not meaningful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (make-local-variable 'superior-tar-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (make-local-variable 'superior-tar-descriptor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (make-local-variable 'mode-line-buffer-identification)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (make-local-variable 'tar-subfile-buffer-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (make-local-variable 'subfile-orig-mlbid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (setq superior-tar-buffer tar-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (setq superior-tar-descriptor descriptor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (setq tar-subfile-buffer-id bufid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (setq subfile-orig-mlbid mode-line-buffer-identification)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (cond ((stringp mode-line-buffer-identification)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (setq mode-line-buffer-identification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (list mode-line-buffer-identification))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (let ((ms (car mode-line-buffer-identification))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (cond ((and (stringp ms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (string-match "%\\([0-9]+\\)b\\'" ms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (setq mode-line-buffer-identification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (concat (substring ms 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (1- (match-beginning 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (substring ms (1+ (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (list (car (read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (substring ms (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (concat "%b" tar-subfile-buffer-id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (cdr mode-line-buffer-identification)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (setq mode-line-buffer-identification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (list "Emacs: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (list 17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (concat "%b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 tar-subfile-buffer-id)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (tar-subfile-mode 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (setq buffer-read-only read-only-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (set-buffer-modified-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (set-buffer tar-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (narrow-to-region 1 tar-header-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (if view-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (view-buffer-other-window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 ;; for view-less.el; view.el can't do this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (set (make-local-variable 'view-kill-on-exit) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (if other-window-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (switch-to-buffer-other-window buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (switch-to-buffer buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (defun tar-extract-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 "*In tar-mode, extract this entry of the tar file into its own buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (tar-extract t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (defun tar-view ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 "*In tar-mode, view the tar file entry on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (tar-extract 'view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (defun tar-read-file-name (&optional prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 "Calls read-file-name, with the default being the file of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 tar-file descriptor."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (or prompt (setq prompt "Copy to: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (let* ((default-file (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (tar-header-name (tar-desc-tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (tar-current-descriptor)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (target (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (read-file-name prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (file-name-directory default-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 default-file nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (if (or (string= "" (file-name-nondirectory target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (file-directory-p target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (setq target (concat (if (string-match "/$" target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (substring target 0 (1- (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 "/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (file-name-nondirectory default-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (defun tar-copy (&optional to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 "*In tar-mode, extract this entry of the tar file into a file on disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 If TO-FILE is not supplied, it is prompted for, defaulting to the name of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 the current tar-entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (interactive (list (tar-read-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (let* ((descriptor (tar-current-descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (tokens (tar-desc-tokens descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (name (tar-header-name tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (size (tar-header-size tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (link-p (tar-header-link-type tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (start (+ (tar-desc-data-start descriptor) tar-header-offset -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (end (+ start size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (if link-p (error "This is a link, not a real file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (if (zerop size) (error "This is a zero-length file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (let* ((tar-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (setq buffer (generate-new-buffer "*tar-copy-tmp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (insert-buffer-substring tar-buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (set-buffer-modified-p nil) ; in case we abort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (write-file to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (message "Copied tar entry %s to %s" name to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (set-buffer tar-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (narrow-to-region 1 tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (if buffer (kill-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (defun tar-flag-deleted (p &optional unflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 "*In tar mode, mark this sub-file to be deleted from the tar file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 With a prefix argument, mark that many files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (tar-dotimes (i (if (< p 0) (- p) p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (if (tar-current-descriptor unflag) ; barf if we're not on an entry-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (insert (if unflag " " "D"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (forward-line (if (< p 0) -1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (if (eobp) nil (forward-char 36)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (defun tar-unflag (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 "*In tar mode, un-mark this sub-file if it is marked to be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 With a prefix argument, un-mark that many files forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (tar-flag-deleted p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (defun tar-unflag-backwards (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 "*In tar mode, un-mark this sub-file if it is marked to be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 With a prefix argument, un-mark that many files backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (tar-flag-deleted (- p) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (defun tar-expunge-internal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 "Expunge the tar-entry specified by the current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (let* ((descriptor (tar-current-descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (tokens (tar-desc-tokens descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (line (tar-desc-data-start descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (name (tar-header-name tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (size (tar-header-size tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (link-p (tar-header-link-type tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (start (tar-desc-data-start descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (following-descs (cdr (memq descriptor tar-parse-info))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (if link-p (setq size 0)) ; size lies for hard-links.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 ;; delete the current line...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (let ((line-start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (end-of-line) (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (let ((line-len (- (point) line-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (delete-region line-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ;; decrement the header-pointer to be in synch...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (setq tar-header-offset (- tar-header-offset line-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;; delete the data pointer...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (setq tar-parse-info (delq descriptor tar-parse-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ;; delete the data from inside the file...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (let* ((data-start (+ start tar-header-offset -513))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (data-end (+ data-start 512 (ash (ash (+ size 511) -9) 9))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (delete-region data-start data-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 ;; and finally, decrement the start-pointers of all following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;; entries in the archive. This is a pig when deleting a bunch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;; of files at once - we could optimize this to only do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; iteration over the files that remain, or only iterate up to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 ;; the next file to be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (let ((data-length (- data-end data-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (tar-dolist (desc following-descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (tar-setf (tar-desc-data-start desc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (- (tar-desc-data-start desc) data-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (narrow-to-region 1 tar-header-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (defun tar-expunge (&optional noconfirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 "*In tar-mode, delete all the archived files flagged for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 This does not modify the disk image; you must save the tar file itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 for this to be permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (if (or noconfirm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (y-or-n-p "expunge files marked for deletion? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (let ((n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (goto-char 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (if (looking-at "D")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (progn (tar-expunge-internal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (setq n (1+ n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;; after doing the deletions, add any padding that may be necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (tar-pad-to-blocksize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (narrow-to-region 1 tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (if (zerop n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (message "nothing to expunge.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (message "%s expunged. Be sure to save this buffer." n)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (defun tar-clear-modification-flags ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 "remove the stars at the beginning of each line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (goto-char 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (while (< (point) tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (if (looking-at "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (progn (delete-char 1) (insert " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (defun tar-chown-entry (new-uid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 "*Change the user-id associated with this entry in the tar file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 If this tar file was written by GNU tar, then you will be able to edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 the user id as a string; otherwise, you must edit it as a number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 You can force editing as a number by calling this with a prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 This does not modify the disk image; you must save the tar file itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 for this to be permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (interactive (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (let ((tokens (tar-desc-tokens (tar-current-descriptor))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (if (or current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (not (tar-header-magic tokens)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (let (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (while (not (numberp (setq n (read-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 "New UID number: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (format "%s" (tar-header-uid tokens)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (read-string "New UID string: " (tar-header-uname tokens))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (cond ((stringp new-uid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (tar-setf (tar-header-uname (tar-desc-tokens (tar-current-descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 new-uid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (tar-alter-one-field tar-uname-offset (concat new-uid "\000")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (tar-setf (tar-header-uid (tar-desc-tokens (tar-current-descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 new-uid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (tar-alter-one-field tar-uid-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (concat (substring (format "%6o" new-uid) 0 6) "\000 ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (defun tar-chgrp-entry (new-gid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 "*Change the group-id associated with this entry in the tar file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 If this tar file was written by GNU tar, then you will be able to edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 the group id as a string; otherwise, you must edit it as a number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 You can force editing as a number by calling this with a prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 This does not modify the disk image; you must save the tar file itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 for this to be permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (interactive (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (let ((tokens (tar-desc-tokens (tar-current-descriptor))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (if (or current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (not (tar-header-magic tokens)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (let (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (while (not (numberp (setq n (read-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 "New GID number: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (format "%s" (tar-header-gid tokens)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (read-string "New GID string: " (tar-header-gname tokens))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (cond ((stringp new-gid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (tar-setf (tar-header-gname (tar-desc-tokens (tar-current-descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 new-gid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (tar-alter-one-field tar-gname-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (concat new-gid "\000")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (tar-setf (tar-header-gid (tar-desc-tokens (tar-current-descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 new-gid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (tar-alter-one-field tar-gid-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (concat (substring (format "%6o" new-gid) 0 6) "\000 ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (defun tar-rename-entry (new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 "*Change the name associated with this entry in the tar file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 This does not modify the disk image; you must save the tar file itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 for this to be permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (list (read-string "New name: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (tar-header-name (tar-desc-tokens (tar-current-descriptor))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (if (string= "" new-name) (error "zero length name."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (if (> (length new-name) 98) (error "name too long."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (tar-setf (tar-header-name (tar-desc-tokens (tar-current-descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (tar-alter-one-field 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (substring (concat new-name (make-string 99 0)) 0 99)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (defun tar-chmod-entry (new-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 "*Change the protection bits associated with this entry in the tar file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 This does not modify the disk image; you must save the tar file itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 for this to be permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (interactive (list (tar-parse-octal-integer-safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (read-string "New protection (octal): "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (tar-setf (tar-header-mode (tar-desc-tokens (tar-current-descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 new-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (tar-alter-one-field tar-mode-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (concat (substring (format "%6o" new-mode) 0 6) "\000 ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (defun tar-alter-one-field (data-position new-data-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (let* ((descriptor (tar-current-descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (tokens (tar-desc-tokens descriptor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; update the header-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (let ((p (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (delete-region p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (insert (summarize-tar-header-block tokens) "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (setq tar-header-offset (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (let* ((start (+ (tar-desc-data-start descriptor) tar-header-offset -513)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ;; delete the old field and insert a new one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (goto-char (+ start data-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (delete-region (point) (+ (point) (length new-data-string))) ; <--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (insert new-data-string) ; <--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 ;; compute a new checksum and insert it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (let ((chk (checksum-tar-header-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (buffer-substring start (+ start 512)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (goto-char (+ start tar-chk-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (delete-region (point) (+ (point) 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (insert (format "%6o" chk))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (insert 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (insert ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (tar-setf (tar-header-checksum tokens) chk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 ;; ok, make sure we didn't botch it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (check-tar-header-block-checksum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (buffer-substring start (+ start 512))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 chk (tar-header-name tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (narrow-to-region 1 tar-header-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (defun tar-subfile-save-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 "In tar subfile mode, write this buffer back into its parent tar-file buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 This doesn't write anything to disk - you must save the parent tar-file buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 to make your changes permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (cond (buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ;; tar-subfile buffers should have nil as buffer-file-name. If they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 ;; ever gain a buffer-file-name, that means they have been written to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 ;; a real disk file, as with ^X^W. If this happens, behave just like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 ;; `save-buffer.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (call-interactively 'save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (tar-subfile-save-buffer-internal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (defun tar-subfile-save-buffer-internal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (if (not (and (boundp 'superior-tar-buffer) superior-tar-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (error "this buffer has no superior tar file buffer."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (or (buffer-name superior-tar-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (error "the superior tar file's buffer has been killed."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (if (not (and (boundp 'superior-tar-descriptor) superior-tar-descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (error "this buffer doesn't have an index into its superior tar file!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 ;; Notice when crypt.el has uncompressed while reading the subfile, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 ;; signal an error if the user tries to save back into the parent file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;; (because it won't work - the .Z subfile it writes won't really be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ;; compressed.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 ; ;; These are for the old crypt.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ; (if (and (boundp 'buffer-save-encrypted) buffer-save-encrypted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ; (error "Don't know how to encrypt back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 ; (if (and (boundp 'buffer-save-compacted) buffer-save-compacted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 ; (error "Don't know how to compact back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ; (if (and (boundp 'buffer-save-compressed) buffer-save-compressed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ; (error "Don't know how to compress back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 ; (if (and (boundp 'buffer-save-gzipped) buffer-save-gzipped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ; (error "Don't know how to gzip back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;; These are for the new crypt++.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (if (and (boundp 'crypt-buffer-save-encrypted) crypt-buffer-save-encrypted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (error "Don't know how to encrypt back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (if (and (boundp 'crypt-buffer-save-compact) crypt-buffer-save-compact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (error "Don't know how to compact back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (if (and (boundp 'crypt-buffer-save-compress) crypt-buffer-save-compress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (error "Don't know how to compress back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (if (and (boundp 'crypt-buffer-save-gzip) crypt-buffer-save-gzip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (error "Don't know how to gzip back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (if (and (boundp 'crypt-buffer-save-freeze) crypt-buffer-save-freeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (error "Don't know how to freeze back into a tar file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (let ((subfile (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (subfile-size (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (descriptor superior-tar-descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (set-buffer superior-tar-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (let* ((tokens (tar-desc-tokens descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (start (tar-desc-data-start descriptor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (name (tar-header-name tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (size (tar-header-size tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (size-pad (ash (ash (+ size 511) -9) 9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (head (memq descriptor tar-parse-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (following-descs (cdr head)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (if (not head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (error "Can't find this tar file entry in its parent tar file!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 ;; delete the old data...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (let* ((data-start (+ start tar-header-offset -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (data-end (+ data-start (ash (ash (+ size 511) -9) 9))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (delete-region data-start data-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 ;; insert the new data...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (goto-char data-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (insert-buffer subfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 ;; pad the new data out to a multiple of 512...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (let ((subfile-size-pad (ash (ash (+ subfile-size 511) -9) 9)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (goto-char (+ data-start subfile-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (insert (make-string (- subfile-size-pad subfile-size) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; update the data pointer of this and all following files...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (tar-setf (tar-header-size tokens) subfile-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (let ((difference (- subfile-size-pad size-pad)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (tar-dolist (desc following-descs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (tar-setf (tar-desc-data-start desc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (+ (tar-desc-data-start desc) difference))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;; Update the size field in the header block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (let ((header-start (- data-start 512)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (goto-char (+ header-start tar-size-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (delete-region (point) (+ (point) 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (insert (format "%11o" subfile-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (insert ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 ;; Maybe update the datestamp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (if (not tar-update-datestamp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (goto-char (+ header-start tar-time-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (delete-region (point) (+ (point) 12))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (let (now top bot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (cond ((fboundp 'current-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (setq now (current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (setcdr now (car (cdr now))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ; ((fboundp 'current-time-seconds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ; (setq now (current-time-seconds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (setq top (car now)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 bot (cdr now))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (tar-setf (tar-header-date tokens) now)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 ;; hair to print two 16-bit numbers as one octal number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (setq bot (logior (ash (logand top 3) 16) bot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (setq top (ash top -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (insert (format "%5o" top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (insert (format "%06o " bot)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ;; otherwise, set it to the epoch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (insert (format "%11o " 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (tar-setf (tar-header-date tokens) (cons 0 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ;; compute a new checksum and insert it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (let ((chk (checksum-tar-header-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (buffer-substring header-start data-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (goto-char (+ header-start tar-chk-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (delete-region (point) (+ (point) 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (insert (format "%6o" chk))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (insert 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (insert ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (tar-setf (tar-header-checksum tokens) chk)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ;; alter the descriptor-line...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (let ((position (- (length tar-parse-info) (length head))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (next-line position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (let ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (m (set-marker (make-marker) tar-header-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (delete-region p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (insert-before-markers (summarize-tar-header-block tokens t) "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (setq tar-header-offset (marker-position m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 ;; after doing the insertion, add any final padding that may be necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (tar-pad-to-blocksize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (narrow-to-region 1 tar-header-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (set-buffer-modified-p t) ; mark the tar file as modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (set-buffer subfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (set-buffer-modified-p nil) ; mark the tar subfile as unmodified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (message "saved into tar-buffer \"%s\" - remember to save that buffer!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (buffer-name superior-tar-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (defun tar-pad-to-blocksize ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 "If we are being anal about tar file blocksizes, fix up the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 Leaves the region wide."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (if (null tar-anal-blocksize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (let* ((last-desc (nth (1- (length tar-parse-info)) tar-parse-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (start (tar-desc-data-start last-desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (tokens (tar-desc-tokens last-desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (link-p (tar-header-link-type tokens))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (size (if link-p 0 (tar-header-size tokens)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (data-end (+ start size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (bbytes (ash tar-anal-blocksize 9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (pad-to (+ bbytes (* bbytes (/ (1- data-end) bbytes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (buffer-read-only nil) ; ##
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 ;; If the padding after the last data is too long, delete some;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 ;; else insert some until we are padded out to the right number of blocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (goto-char (+ (or tar-header-offset 0) data-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (if (> (1+ (buffer-size)) (+ (or tar-header-offset 0) pad-to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (delete-region (+ (or tar-header-offset 0) pad-to) (1+ (buffer-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (insert (make-string (- (+ (or tar-header-offset 0) pad-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (1+ (buffer-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (defun maybe-write-tar-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 "Used as a write-file-hook to write tar-files out correctly."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 ;; If the current buffer is in tar-mode and has its header-offset set,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ;; remove the header from the file, call the remaining write-file hooks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 ;; and then write out the buffer (if and only if one of the write-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 ;; hooks didn't write it already). Then put the header back on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 ;; buffer. Many thanks to Piet van Oostrum for this code, which causes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 ;; correct interaction with crypt.el (and probably anything like it.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 ;; Kludge: in XEmacs Emacs, write-file-hooks is bound to nil before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 ;; write-file-hooks are run, to prevent them from being run recursively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 ;; (this is more of a danger in v19-vintage emacses, which have both
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 ;; write-file-hooks and write-contents-hooks.) So, we need to reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 ;; an internal variable of basic-save-buffer to get the list of hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 ;; remaining to be run.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (and (eq major-mode 'tar-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (and (boundp 'tar-header-offset) tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (let* ((hooks (cond ((string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 ;; Internal to basic-save-buffer in XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (symbol-value 'hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ((string-lessp "19" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ;; I think this is what we need to do in fsfmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (append write-contents-hooks write-file-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 write-file-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (remaining-hooks (cdr (memq 'maybe-write-tar-file hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 header-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (tar-clear-modification-flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (setq header-string (buffer-substring 1 tar-header-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (delete-region 1 tar-header-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (while (and remaining-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (not (setq done (funcall (car remaining-hooks)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (setq remaining-hooks (cdr remaining-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (cond ((not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (write-region 1 (1+ (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 buffer-file-name nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (setq done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (insert header-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (set-buffer-modified-p nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 done)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 ;;; Patch it in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (defvar tar-regexp "\\.\\(tar\\|tgz\\)$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 "The regular expression used to identify tar file names.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (cons (cons tar-regexp 'tar-mode) auto-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 ;; Note: the tar write-file-hook should go on the list *before* any other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 ;; hooks which might write the file. Since things like crypt-mode add things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 ;; to the end of the write-file-hooks, this will normally be the case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 ;(or (boundp 'write-file-hooks) (setq write-file-hooks nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 ;(or (listp write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 ; (setq write-file-hooks (list write-file-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 ;(or (memq 'maybe-write-tar-file write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 ; (setq write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 ; (cons 'maybe-write-tar-file write-file-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (add-hook 'write-file-hooks 'maybe-write-tar-file); ####write-contents-hooks??
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (cond ((boundp 'after-save-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (add-hook 'after-save-hook 'tar-subfile-after-write-file-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 ((boundp 'after-write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (add-hook 'after-write-file-hooks 'tar-subfile-after-write-file-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (t (error "neither after-save-hook nor after-write-file-hooks?")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 ;;; This is a hack. For files ending in .tar, we want -*- lines to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;;; completely ignored - if there is one, it applies to the first file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ;;; in the archive, and not the archive itself! Similarly for local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 ;;; variables specifications in the last file of the archive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (defun tar-normal-mode (&optional find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 "Choose the major mode for this buffer automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 Also sets up any specified local variables of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 Uses the visited file name, the -*- line, and the local variables spec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 This function is called automatically from `find-file'. In that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 if `inhibit-local-variables' is non-`nil' we require confirmation before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 processing a local variables spec. If you run `normal-mode' explicitly,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 confirmation is never required.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 Note that this version of this function has been hacked to interact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 correctly with tar files - when visiting a file which matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 'tar-regexp', the -*- line and local-variables are not examined,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 as they would apply to a file within the archive rather than the archive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 itself."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (if (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (string-match tar-regexp buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (tar-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (tar-real-normal-mode find-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ;; We have to shadow this as well to get along with crypt.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 ;; Shadowing this alone isn't enough, though; we need to shadow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 ;; tar-normal-mode in order to inhibit the local variables of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 ;; last file in the tar archive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (defun tar-set-auto-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 "Select major mode appropriate for current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 May base decision on visited file name (See variable auto-mode-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 or on buffer contents (-*- line or local variables spec), but does not look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 for the \"mode:\" local variable. For that, use hack-local-variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 Note that this version of this function has been hacked to interact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 correctly with tar files - when visiting a file which matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 'tar-regexp', the -*- line and local-variables are not examined,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 as they would apply to a file within the archive rather than the archive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 itself."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (if (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (string-match tar-regexp buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (tar-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (tar-real-set-auto-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (if (not (fboundp 'tar-real-normal-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (fset 'tar-real-normal-mode (symbol-function 'normal-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (fset 'normal-mode 'tar-normal-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (if (not (fboundp 'tar-real-set-auto-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (fset 'tar-real-set-auto-mode (symbol-function 'set-auto-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (fset 'set-auto-mode 'tar-set-auto-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (provide 'tar-mode)