annotate lisp/packages/tar-mode.el @ 0:376386a54a3c r19-14

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