annotate lisp/packages/tar-mode.el @ 175:2d532a89d707 r20-3b14

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