diff options
| author | Kenichi Handa | 2002-07-31 07:14:35 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2002-07-31 07:14:35 +0000 |
| commit | d26e6665bf487689a0e44c0b601effe25d8b71f3 (patch) | |
| tree | f428454c5e5a0b0a699b07647aaa30168260c89e | |
| parent | ad38511a70fc9cca5c705bb333d9c202aa94cca5 (diff) | |
| download | emacs-d26e6665bf487689a0e44c0b601effe25d8b71f3.tar.gz emacs-d26e6665bf487689a0e44c0b601effe25d8b71f3.zip | |
(tar-file-name-coding-system): New variable. Make
it permanent-local.p
(tar-header-block-tokenize): Decode filename and linkname by
tar-file-name-coding-system.
(tar-header-block-checksum): Call multibyte-char-to-unibyte to get
the byte value of eight-bit chars.
(tar-summarize-buffer): Call set-buffer-multibyte with METHOD
`to'. Delete unnecessary call of position-bytes.
(tar-mode): Set tar-file-name-coding-system. Delete unnecessary
call of position-bytes.
(tar-extract): Simplified by calling decode-coding-region with
DESTINATION argument. Don't toggle multibyteness of tar buffer.
(tar-copy): Don't toggle multibyteness of tar buffer.
(tar-expunge): Likewise.
(tar-clear-modification-flags): Delete unnecessary call of
position-bytes.
(tar-rename-entry): Call tar-alter-one-field with encoded new
name.
(tar-alter-one-field): Don't toggle multibyteness of tar buffer.
Convert new-data-string by string-to-multibyte before inserting
it.
(tar-subfile-save-buffer): Don't toggle multibyteness of tar
buffer. Simplified by calling encoding-coding-region with
DESTINATION argument.
(tar-mode-write-file): Delete unnecessary call of
byte-to-position.
| -rw-r--r-- | lisp/tar-mode.el | 182 |
1 files changed, 75 insertions, 107 deletions
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index 2bfd75c7630..bd10737b548 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el | |||
| @@ -129,16 +129,17 @@ This information is useful, but it takes screen space away from file names." | |||
| 129 | :group 'tar) | 129 | :group 'tar) |
| 130 | 130 | ||
| 131 | (defvar tar-parse-info nil) | 131 | (defvar tar-parse-info nil) |
| 132 | ;; Be sure that this variable holds byte position, not char position. | ||
| 133 | (defvar tar-header-offset nil) | 132 | (defvar tar-header-offset nil) |
| 134 | (defvar tar-superior-buffer nil) | 133 | (defvar tar-superior-buffer nil) |
| 135 | (defvar tar-superior-descriptor nil) | 134 | (defvar tar-superior-descriptor nil) |
| 136 | (defvar tar-subfile-mode nil) | 135 | (defvar tar-subfile-mode nil) |
| 136 | (defvar tar-file-name-coding-system nil) | ||
| 137 | 137 | ||
| 138 | (put 'tar-parse-info 'permanent-local t) | 138 | (put 'tar-parse-info 'permanent-local t) |
| 139 | (put 'tar-header-offset 'permanent-local t) | 139 | (put 'tar-header-offset 'permanent-local t) |
| 140 | (put 'tar-superior-buffer 'permanent-local t) | 140 | (put 'tar-superior-buffer 'permanent-local t) |
| 141 | (put 'tar-superior-descriptor 'permanent-local t) | 141 | (put 'tar-superior-descriptor 'permanent-local t) |
| 142 | (put 'tar-file-name-coding-system 'permanent-local t) | ||
| 142 | 143 | ||
| 143 | (defmacro tar-setf (form val) | 144 | (defmacro tar-setf (form val) |
| 144 | "A mind-numbingly simple implementation of setf." | 145 | "A mind-numbingly simple implementation of setf." |
| @@ -231,11 +232,10 @@ write-date, checksum, link-type, and link-name." | |||
| 231 | (setq linkname (substring string tar-link-offset link-end)) | 232 | (setq linkname (substring string tar-link-offset link-end)) |
| 232 | (if default-enable-multibyte-characters | 233 | (if default-enable-multibyte-characters |
| 233 | (setq name | 234 | (setq name |
| 234 | (decode-coding-string name (or file-name-coding-system | 235 | (decode-coding-string name tar-file-name-coding-system) |
| 235 | 'undecided)) | ||
| 236 | linkname | 236 | linkname |
| 237 | (decode-coding-string linkname (or file-name-coding-system | 237 | (decode-coding-string linkname |
| 238 | 'undecided)))) | 238 | tar-file-name-coding-system))) |
| 239 | (if (and (null link-p) (string-match "/$" name)) (setq link-p 5)) ; directory | 239 | (if (and (null link-p) (string-match "/$" name)) (setq link-p 5)) ; directory |
| 240 | (make-tar-header | 240 | (make-tar-header |
| 241 | name | 241 | name |
| @@ -302,11 +302,11 @@ write-date, checksum, link-type, and link-name." | |||
| 302 | ;; Add up all of the characters except the ones in the checksum field. | 302 | ;; Add up all of the characters except the ones in the checksum field. |
| 303 | ;; Add that field as if it were filled with spaces. | 303 | ;; Add that field as if it were filled with spaces. |
| 304 | (while (< i chk-field-start) | 304 | (while (< i chk-field-start) |
| 305 | (setq sum (+ sum (aref string i)) | 305 | (setq sum (+ sum (multibyte-char-to-unibyte (aref string i))) |
| 306 | i (1+ i))) | 306 | i (1+ i))) |
| 307 | (setq i chk-field-end) | 307 | (setq i chk-field-end) |
| 308 | (while (< i 512) | 308 | (while (< i 512) |
| 309 | (setq sum (+ sum (aref string i)) | 309 | (setq sum (+ sum (multibyte-char-to-unibyte (aref string i))) |
| 310 | i (1+ i))) | 310 | i (1+ i))) |
| 311 | (+ sum (* 32 8)))) | 311 | (+ sum (* 32 8)))) |
| 312 | 312 | ||
| @@ -434,15 +434,13 @@ is visible (and the real data of the buffer is hidden)." | |||
| 434 | (cons (tar-header-block-summarize (tar-desc-tokens tar-desc)) | 434 | (cons (tar-header-block-summarize (tar-desc-tokens tar-desc)) |
| 435 | (cons "\n" | 435 | (cons "\n" |
| 436 | summaries)))) | 436 | summaries)))) |
| 437 | (if default-enable-multibyte-characters | ||
| 438 | (set-buffer-multibyte t 'to)) | ||
| 437 | (let ((total-summaries (apply 'concat summaries))) | 439 | (let ((total-summaries (apply 'concat summaries))) |
| 438 | (if (multibyte-string-p total-summaries) | ||
| 439 | (set-buffer-multibyte t)) | ||
| 440 | (insert total-summaries)) | 440 | (insert total-summaries)) |
| 441 | (make-local-variable 'tar-header-offset) | 441 | (make-local-variable 'tar-header-offset) |
| 442 | (setq tar-header-offset (point)) | 442 | (setq tar-header-offset (point)) |
| 443 | (narrow-to-region 1 tar-header-offset) | 443 | (narrow-to-region 1 tar-header-offset) |
| 444 | (if enable-multibyte-characters | ||
| 445 | (setq tar-header-offset (position-bytes tar-header-offset))) | ||
| 446 | (set-buffer-modified-p nil)))) | 444 | (set-buffer-modified-p nil)))) |
| 447 | 445 | ||
| 448 | (defvar tar-mode-map nil "*Local keymap for Tar mode listings.") | 446 | (defvar tar-mode-map nil "*Local keymap for Tar mode listings.") |
| @@ -553,13 +551,17 @@ See also: variables `tar-update-datestamp' and `tar-anal-blocksize'. | |||
| 553 | (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert) | 551 | (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert) |
| 554 | (set (make-local-variable 'local-enable-local-variables) nil) | 552 | (set (make-local-variable 'local-enable-local-variables) nil) |
| 555 | (set (make-local-variable 'next-line-add-newlines) nil) | 553 | (set (make-local-variable 'next-line-add-newlines) nil) |
| 554 | (set (make-local-variable 'tar-file-name-coding-system) | ||
| 555 | (or file-name-coding-system | ||
| 556 | default-file-name-coding-system | ||
| 557 | locale-coding-system)) | ||
| 556 | ;; Prevent loss of data when saving the file. | 558 | ;; Prevent loss of data when saving the file. |
| 557 | (set (make-local-variable 'file-precious-flag) t) | 559 | (set (make-local-variable 'file-precious-flag) t) |
| 558 | (auto-save-mode 0) | 560 | (auto-save-mode 0) |
| 559 | (set (make-local-variable 'write-contents-hooks) '(tar-mode-write-file)) | 561 | (set (make-local-variable 'write-contents-hooks) '(tar-mode-write-file)) |
| 560 | (widen) | 562 | (widen) |
| 561 | (if (and (boundp 'tar-header-offset) tar-header-offset) | 563 | (if (and (boundp 'tar-header-offset) tar-header-offset) |
| 562 | (narrow-to-region 1 (byte-to-position tar-header-offset)) | 564 | (narrow-to-region 1 tar-header-offset) |
| 563 | (tar-summarize-buffer) | 565 | (tar-summarize-buffer) |
| 564 | (tar-next-line 0))) | 566 | (tar-next-line 0))) |
| 565 | 567 | ||
| @@ -681,61 +683,40 @@ appear on disk when you save the tar-file's buffer." | |||
| 681 | ;; `:' is not allowed on Windows | 683 | ;; `:' is not allowed on Windows |
| 682 | (concat tarname "!" name))) | 684 | (concat tarname "!" name))) |
| 683 | (buffer (get-file-buffer new-buffer-file-name)) | 685 | (buffer (get-file-buffer new-buffer-file-name)) |
| 684 | (just-created nil)) | 686 | (just-created nil) |
| 687 | (pos (point))) | ||
| 685 | (unless buffer | 688 | (unless buffer |
| 686 | (setq buffer (generate-new-buffer bufname)) | 689 | (setq buffer (generate-new-buffer bufname)) |
| 687 | (setq bufname (buffer-name buffer)) | 690 | (setq bufname (buffer-name buffer)) |
| 688 | (setq just-created t) | 691 | (setq just-created t) |
| 689 | (unwind-protect | 692 | (unwind-protect |
| 690 | (progn | 693 | (let (coding) |
| 691 | (widen) | 694 | (narrow-to-region start end) |
| 692 | (set-buffer-multibyte nil) | 695 | (goto-char start) |
| 696 | (setq coding (or coding-system-for-read | ||
| 697 | (and set-auto-coding-function | ||
| 698 | (funcall set-auto-coding-function | ||
| 699 | name (point-max))))) | ||
| 700 | (if (or (not coding) | ||
| 701 | (eq (coding-system-type coding) 'undecided)) | ||
| 702 | (setq coding (detect-coding-region start end t))) | ||
| 703 | (if (eq (coding-system-type coding) 'undecided) | ||
| 704 | (setq coding | ||
| 705 | (coding-system-change-text-conversion coding | ||
| 706 | 'us-ascii))) | ||
| 693 | (save-excursion | 707 | (save-excursion |
| 694 | (set-buffer buffer) | 708 | (set-buffer buffer) |
| 695 | (if enable-multibyte-characters | 709 | (if (and enable-multibyte-characters |
| 696 | (progn | 710 | (eq (coding-system-type 'raw-text) coding)) |
| 697 | ;; We must avoid unibyte->multibyte conversion. | 711 | (set-buffer-multibyte nil)) |
| 698 | (set-buffer-multibyte nil) | ||
| 699 | (insert-buffer-substring tar-buffer start end) | ||
| 700 | (set-buffer-multibyte t)) | ||
| 701 | (insert-buffer-substring tar-buffer start end)) | ||
| 702 | (goto-char (point-min)) | 712 | (goto-char (point-min)) |
| 703 | (setq buffer-file-name new-buffer-file-name) | 713 | (setq buffer-file-name new-buffer-file-name) |
| 704 | (setq buffer-file-truename | 714 | (setq buffer-file-truename |
| 705 | (abbreviate-file-name buffer-file-name)) | 715 | (abbreviate-file-name buffer-file-name))) |
| 706 | ;; We need to mimic the parts of insert-file-contents | 716 | (decode-coding-region start end coding buffer) |
| 707 | ;; which determine the coding-system and decode the text. | 717 | (save-excursion |
| 708 | (let ((coding | 718 | (set-buffer buffer) |
| 709 | (or coding-system-for-read | 719 | (goto-char (point-min)) |
| 710 | (and set-auto-coding-function | ||
| 711 | (save-excursion | ||
| 712 | (funcall set-auto-coding-function | ||
| 713 | name (- (point-max) (point))))))) | ||
| 714 | (multibyte enable-multibyte-characters) | ||
| 715 | (detected (detect-coding-region | ||
| 716 | 1 (min 16384 (point-max)) t))) | ||
| 717 | (if coding | ||
| 718 | (or (numberp (coding-system-eol-type coding)) | ||
| 719 | (setq coding (coding-system-change-eol-conversion | ||
| 720 | coding | ||
| 721 | (coding-system-eol-type detected)))) | ||
| 722 | (setq coding | ||
| 723 | (or (find-new-buffer-file-coding-system detected) | ||
| 724 | (let ((file-coding | ||
| 725 | (find-operation-coding-system | ||
| 726 | 'insert-file-contents buffer-file-name))) | ||
| 727 | (if (consp file-coding) | ||
| 728 | (setq file-coding (car file-coding)) | ||
| 729 | file-coding))))) | ||
| 730 | (if (or (eq coding 'no-conversion) | ||
| 731 | (eq (coding-system-type coding) 5)) | ||
| 732 | (setq multibyte (set-buffer-multibyte nil))) | ||
| 733 | (or multibyte | ||
| 734 | (setq coding | ||
| 735 | (coding-system-change-text-conversion | ||
| 736 | coding 'raw-text))) | ||
| 737 | (decode-coding-region 1 (point-max) coding) | ||
| 738 | (set-buffer-file-coding-system coding)) | ||
| 739 | ;; Set the default-directory to the dir of the | 720 | ;; Set the default-directory to the dir of the |
| 740 | ;; superior buffer. | 721 | ;; superior buffer. |
| 741 | (setq default-directory | 722 | (setq default-directory |
| @@ -753,7 +734,7 @@ appear on disk when you save the tar-file's buffer." | |||
| 753 | (tar-subfile-mode 1)) | 734 | (tar-subfile-mode 1)) |
| 754 | (set-buffer tar-buffer)) | 735 | (set-buffer tar-buffer)) |
| 755 | (narrow-to-region 1 tar-header-offset) | 736 | (narrow-to-region 1 tar-header-offset) |
| 756 | (set-buffer-multibyte tar-buffer-multibyte))) | 737 | (goto-char pos))) |
| 757 | (if view-p | 738 | (if view-p |
| 758 | (view-buffer buffer (and just-created 'kill-buffer)) | 739 | (view-buffer buffer (and just-created 'kill-buffer)) |
| 759 | (if (eq other-window-p 'display) | 740 | (if (eq other-window-p 'display) |
| @@ -810,7 +791,6 @@ the current tar-entry." | |||
| 810 | (size (tar-header-size tokens)) | 791 | (size (tar-header-size tokens)) |
| 811 | (start (+ (tar-desc-data-start descriptor) tar-header-offset -1)) | 792 | (start (+ (tar-desc-data-start descriptor) tar-header-offset -1)) |
| 812 | (end (+ start size)) | 793 | (end (+ start size)) |
| 813 | (multibyte enable-multibyte-characters) | ||
| 814 | (inhibit-file-name-handlers inhibit-file-name-handlers) | 794 | (inhibit-file-name-handlers inhibit-file-name-handlers) |
| 815 | (inhibit-file-name-operation inhibit-file-name-operation)) | 795 | (inhibit-file-name-operation inhibit-file-name-operation)) |
| 816 | (save-restriction | 796 | (save-restriction |
| @@ -824,11 +804,8 @@ the current tar-entry." | |||
| 824 | (and (eq inhibit-file-name-operation 'write-region) | 804 | (and (eq inhibit-file-name-operation 'write-region) |
| 825 | inhibit-file-name-handlers)) | 805 | inhibit-file-name-handlers)) |
| 826 | inhibit-file-name-operation 'write-region)) | 806 | inhibit-file-name-operation 'write-region)) |
| 827 | (unwind-protect | 807 | (let ((coding-system-for-write 'no-conversion)) |
| 828 | (let ((coding-system-for-write 'no-conversion)) | 808 | (write-region start end to-file nil nil nil t))) |
| 829 | (set-buffer-multibyte nil) | ||
| 830 | (write-region start end to-file nil nil nil t)) | ||
| 831 | (set-buffer-multibyte multibyte))) | ||
| 832 | (message "Copied tar entry %s to %s" name to-file))) | 809 | (message "Copied tar entry %s to %s" name to-file))) |
| 833 | 810 | ||
| 834 | (defun tar-flag-deleted (p &optional unflag) | 811 | (defun tar-flag-deleted (p &optional unflag) |
| @@ -857,7 +834,6 @@ With a prefix argument, un-mark that many files backward." | |||
| 857 | (tar-flag-deleted (- p) t)) | 834 | (tar-flag-deleted (- p) t)) |
| 858 | 835 | ||
| 859 | 836 | ||
| 860 | ;; When this function is called, it is sure that the buffer is unibyte. | ||
| 861 | (defun tar-expunge-internal () | 837 | (defun tar-expunge-internal () |
| 862 | "Expunge the tar-entry specified by the current line." | 838 | "Expunge the tar-entry specified by the current line." |
| 863 | (let* ((descriptor (tar-current-descriptor)) | 839 | (let* ((descriptor (tar-current-descriptor)) |
| @@ -909,9 +885,7 @@ for this to be permanent." | |||
| 909 | (interactive) | 885 | (interactive) |
| 910 | (if (or noconfirm | 886 | (if (or noconfirm |
| 911 | (y-or-n-p "Expunge files marked for deletion? ")) | 887 | (y-or-n-p "Expunge files marked for deletion? ")) |
| 912 | (let ((n 0) | 888 | (let ((n 0)) |
| 913 | (multibyte enable-multibyte-characters)) | ||
| 914 | (set-buffer-multibyte nil) | ||
| 915 | (save-excursion | 889 | (save-excursion |
| 916 | (goto-char (point-min)) | 890 | (goto-char (point-min)) |
| 917 | (while (not (eobp)) | 891 | (while (not (eobp)) |
| @@ -922,7 +896,6 @@ for this to be permanent." | |||
| 922 | ;; after doing the deletions, add any padding that may be necessary. | 896 | ;; after doing the deletions, add any padding that may be necessary. |
| 923 | (tar-pad-to-blocksize) | 897 | (tar-pad-to-blocksize) |
| 924 | (narrow-to-region 1 tar-header-offset)) | 898 | (narrow-to-region 1 tar-header-offset)) |
| 925 | (set-buffer-multibyte multibyte) | ||
| 926 | (if (zerop n) | 899 | (if (zerop n) |
| 927 | (message "Nothing to expunge.") | 900 | (message "Nothing to expunge.") |
| 928 | (message "%s files expunged. Be sure to save this buffer." n))))) | 901 | (message "%s files expunged. Be sure to save this buffer." n))))) |
| @@ -933,7 +906,7 @@ for this to be permanent." | |||
| 933 | (interactive) | 906 | (interactive) |
| 934 | (save-excursion | 907 | (save-excursion |
| 935 | (goto-char (point-min)) | 908 | (goto-char (point-min)) |
| 936 | (while (< (position-bytes (point)) tar-header-offset) | 909 | (while (< (point) tar-header-offset) |
| 937 | (if (not (eq (following-char) ?\ )) | 910 | (if (not (eq (following-char) ?\ )) |
| 938 | (progn (delete-char 1) (insert " "))) | 911 | (progn (delete-char 1) (insert " "))) |
| 939 | (forward-line 1)))) | 912 | (forward-line 1)))) |
| @@ -1003,11 +976,13 @@ for this to be permanent." | |||
| 1003 | (list (read-string "New name: " | 976 | (list (read-string "New name: " |
| 1004 | (tar-header-name (tar-desc-tokens (tar-current-descriptor)))))) | 977 | (tar-header-name (tar-desc-tokens (tar-current-descriptor)))))) |
| 1005 | (if (string= "" new-name) (error "zero length name")) | 978 | (if (string= "" new-name) (error "zero length name")) |
| 1006 | (if (> (length new-name) 98) (error "name too long")) | 979 | (let ((encoded-new-name (encode-coding-string new-name |
| 1007 | (tar-setf (tar-header-name (tar-desc-tokens (tar-current-descriptor))) | 980 | tar-file-name-coding-system))) |
| 1008 | new-name) | 981 | (if (> (length encoded-new-name) 98) (error "name too long")) |
| 1009 | (tar-alter-one-field 0 | 982 | (tar-setf (tar-header-name (tar-desc-tokens (tar-current-descriptor))) |
| 1010 | (substring (concat new-name (make-string 99 0)) 0 99))) | 983 | new-name) |
| 984 | (tar-alter-one-field 0 | ||
| 985 | (substring (concat encoded-new-name (make-string 99 0)) 0 99)))) | ||
| 1011 | 986 | ||
| 1012 | 987 | ||
| 1013 | (defun tar-chmod-entry (new-mode) | 988 | (defun tar-chmod-entry (new-mode) |
| @@ -1024,8 +999,7 @@ for this to be permanent." | |||
| 1024 | 999 | ||
| 1025 | (defun tar-alter-one-field (data-position new-data-string) | 1000 | (defun tar-alter-one-field (data-position new-data-string) |
| 1026 | (let* ((descriptor (tar-current-descriptor)) | 1001 | (let* ((descriptor (tar-current-descriptor)) |
| 1027 | (tokens (tar-desc-tokens descriptor)) | 1002 | (tokens (tar-desc-tokens descriptor))) |
| 1028 | (multibyte enable-multibyte-characters)) | ||
| 1029 | (unwind-protect | 1003 | (unwind-protect |
| 1030 | (save-excursion | 1004 | (save-excursion |
| 1031 | ;; | 1005 | ;; |
| @@ -1035,16 +1009,21 @@ for this to be permanent." | |||
| 1035 | (forward-line 1) | 1009 | (forward-line 1) |
| 1036 | (delete-region p (point)) | 1010 | (delete-region p (point)) |
| 1037 | (insert (tar-header-block-summarize tokens) "\n") | 1011 | (insert (tar-header-block-summarize tokens) "\n") |
| 1038 | (setq tar-header-offset (position-bytes (point-max)))) | 1012 | (setq tar-header-offset (point-max))) |
| 1039 | 1013 | ||
| 1040 | (widen) | 1014 | (widen) |
| 1041 | (set-buffer-multibyte nil) | ||
| 1042 | (let* ((start (+ (tar-desc-data-start descriptor) tar-header-offset -513))) | 1015 | (let* ((start (+ (tar-desc-data-start descriptor) tar-header-offset -513))) |
| 1043 | ;; | 1016 | ;; |
| 1044 | ;; delete the old field and insert a new one. | 1017 | ;; delete the old field and insert a new one. |
| 1045 | (goto-char (+ start data-position)) | 1018 | (goto-char (+ start data-position)) |
| 1046 | (delete-region (point) (+ (point) (length new-data-string))) ; <-- | 1019 | (delete-region (point) (+ (point) (length new-data-string))) ; <-- |
| 1047 | (insert new-data-string) ; <-- | 1020 | |
| 1021 | ;; As new-data-string is unibyte, just inserting it will | ||
| 1022 | ;; make eight-bit chars to the corresponding multibyte | ||
| 1023 | ;; chars. This avoid that conversion, i.e., eight-bit | ||
| 1024 | ;; chars are converted to multibyte form of eight-bit | ||
| 1025 | ;; chars. | ||
| 1026 | (insert (string-to-multibyte new-data-string)) | ||
| 1048 | ;; | 1027 | ;; |
| 1049 | ;; compute a new checksum and insert it. | 1028 | ;; compute a new checksum and insert it. |
| 1050 | (let ((chk (tar-header-block-checksum | 1029 | (let ((chk (tar-header-block-checksum |
| @@ -1062,7 +1041,6 @@ for this to be permanent." | |||
| 1062 | chk (tar-header-name tokens)) | 1041 | chk (tar-header-name tokens)) |
| 1063 | ))) | 1042 | ))) |
| 1064 | (narrow-to-region 1 tar-header-offset) | 1043 | (narrow-to-region 1 tar-header-offset) |
| 1065 | (set-buffer-multibyte multibyte) | ||
| 1066 | (tar-next-line 0)))) | 1044 | (tar-next-line 0)))) |
| 1067 | 1045 | ||
| 1068 | 1046 | ||
| @@ -1086,14 +1064,9 @@ to make your changes permanent." | |||
| 1086 | (error "This buffer doesn't have an index into its superior tar file!")) | 1064 | (error "This buffer doesn't have an index into its superior tar file!")) |
| 1087 | (save-excursion | 1065 | (save-excursion |
| 1088 | (let ((subfile (current-buffer)) | 1066 | (let ((subfile (current-buffer)) |
| 1089 | (subfile-multibyte enable-multibyte-characters) | ||
| 1090 | (coding buffer-file-coding-system) | 1067 | (coding buffer-file-coding-system) |
| 1091 | (descriptor tar-superior-descriptor) | 1068 | (descriptor tar-superior-descriptor) |
| 1092 | subfile-size) | 1069 | subfile-size) |
| 1093 | ;; We must make the current buffer unibyte temporarily to avoid | ||
| 1094 | ;; multibyte->unibyte conversion in `insert-buffer'. | ||
| 1095 | (set-buffer-multibyte nil) | ||
| 1096 | (setq subfile-size (buffer-size)) | ||
| 1097 | (set-buffer tar-superior-buffer) | 1070 | (set-buffer tar-superior-buffer) |
| 1098 | (let* ((tokens (tar-desc-tokens descriptor)) | 1071 | (let* ((tokens (tar-desc-tokens descriptor)) |
| 1099 | (start (tar-desc-data-start descriptor)) | 1072 | (start (tar-desc-data-start descriptor)) |
| @@ -1101,28 +1074,28 @@ to make your changes permanent." | |||
| 1101 | (size (tar-header-size tokens)) | 1074 | (size (tar-header-size tokens)) |
| 1102 | (size-pad (ash (ash (+ size 511) -9) 9)) | 1075 | (size-pad (ash (ash (+ size 511) -9) 9)) |
| 1103 | (head (memq descriptor tar-parse-info)) | 1076 | (head (memq descriptor tar-parse-info)) |
| 1104 | (following-descs (cdr head)) | 1077 | (following-descs (cdr head))) |
| 1105 | (tar-buffer-multibyte enable-multibyte-characters)) | ||
| 1106 | (if (not head) | 1078 | (if (not head) |
| 1107 | (error "Can't find this tar file entry in its parent tar file!")) | 1079 | (error "Can't find this tar file entry in its parent tar file!")) |
| 1108 | (unwind-protect | 1080 | (unwind-protect |
| 1109 | (save-excursion | 1081 | (save-excursion |
| 1110 | (widen) | ||
| 1111 | (set-buffer-multibyte nil) | ||
| 1112 | ;; delete the old data... | 1082 | ;; delete the old data... |
| 1113 | (let* ((data-start (+ start tar-header-offset -1)) | 1083 | (let* ((data-start (+ start tar-header-offset -1)) |
| 1114 | (data-end (+ data-start (ash (ash (+ size 511) -9) 9)))) | 1084 | (data-end (+ data-start (ash (ash (+ size 511) -9) 9)))) |
| 1115 | (delete-region data-start data-end) | 1085 | (narrow-to-region data-start data-end) |
| 1086 | (delete-region (point-min) (point-max)) | ||
| 1116 | ;; insert the new data... | 1087 | ;; insert the new data... |
| 1117 | (goto-char data-start) | 1088 | (goto-char data-start) |
| 1118 | (insert-buffer subfile) | 1089 | (save-excursion |
| 1119 | (setq subfile-size | 1090 | (set-buffer subfile) |
| 1120 | (encode-coding-region | 1091 | (save-restriction |
| 1121 | data-start (+ data-start subfile-size) coding)) | 1092 | (widen) |
| 1093 | (encode-coding-region 1 (point-max) coding tar-superior-buffer))) | ||
| 1094 | (setq subfile-size (- (point-max) (point-min))) | ||
| 1122 | ;; | 1095 | ;; |
| 1123 | ;; pad the new data out to a multiple of 512... | 1096 | ;; pad the new data out to a multiple of 512... |
| 1124 | (let ((subfile-size-pad (ash (ash (+ subfile-size 511) -9) 9))) | 1097 | (let ((subfile-size-pad (ash (ash (+ subfile-size 511) -9) 9))) |
| 1125 | (goto-char (+ data-start subfile-size)) | 1098 | (goto-char (point-max)) |
| 1126 | (insert (make-string (- subfile-size-pad subfile-size) 0)) | 1099 | (insert (make-string (- subfile-size-pad subfile-size) 0)) |
| 1127 | ;; | 1100 | ;; |
| 1128 | ;; update the data pointer of this and all following files... | 1101 | ;; update the data pointer of this and all following files... |
| @@ -1133,6 +1106,7 @@ to make your changes permanent." | |||
| 1133 | (+ (tar-desc-data-start desc) difference)))) | 1106 | (+ (tar-desc-data-start desc) difference)))) |
| 1134 | ;; | 1107 | ;; |
| 1135 | ;; Update the size field in the header block. | 1108 | ;; Update the size field in the header block. |
| 1109 | (widen) | ||
| 1136 | (let ((header-start (- data-start 512))) | 1110 | (let ((header-start (- data-start 512))) |
| 1137 | (goto-char (+ header-start tar-size-offset)) | 1111 | (goto-char (+ header-start tar-size-offset)) |
| 1138 | (delete-region (point) (+ (point) 12)) | 1112 | (delete-region (point) (+ (point) 12)) |
| @@ -1171,21 +1145,16 @@ to make your changes permanent." | |||
| 1171 | ;; Insert the new text after the old, before deleting, | 1145 | ;; Insert the new text after the old, before deleting, |
| 1172 | ;; to preserve the window start. | 1146 | ;; to preserve the window start. |
| 1173 | (let ((line (tar-header-block-summarize tokens t))) | 1147 | (let ((line (tar-header-block-summarize tokens t))) |
| 1174 | (if (multibyte-string-p line) | 1148 | (insert-before-markers line "\n")) |
| 1175 | (insert-before-markers (string-as-unibyte line) "\n") | ||
| 1176 | (insert-before-markers line "\n"))) | ||
| 1177 | (delete-region p after) | 1149 | (delete-region p after) |
| 1178 | (setq tar-header-offset (marker-position m))) | 1150 | (setq tar-header-offset (marker-position m))) |
| 1179 | ))) | 1151 | ))) |
| 1180 | ;; after doing the insertion, add any final padding that may be necessary. | 1152 | ;; after doing the insertion, add any final padding that may be necessary. |
| 1181 | (tar-pad-to-blocksize)) | 1153 | (tar-pad-to-blocksize)) |
| 1182 | (narrow-to-region 1 tar-header-offset) | 1154 | (narrow-to-region 1 tar-header-offset))) |
| 1183 | (set-buffer-multibyte tar-buffer-multibyte))) | ||
| 1184 | (set-buffer-modified-p t) ; mark the tar file as modified | 1155 | (set-buffer-modified-p t) ; mark the tar file as modified |
| 1185 | (tar-next-line 0) | 1156 | (tar-next-line 0) |
| 1186 | (set-buffer subfile) | 1157 | (set-buffer subfile) |
| 1187 | ;; Restore the buffer multibyteness. | ||
| 1188 | (set-buffer-multibyte subfile-multibyte) | ||
| 1189 | (set-buffer-modified-p nil) ; mark the tar subfile as unmodified | 1158 | (set-buffer-modified-p nil) ; mark the tar subfile as unmodified |
| 1190 | (message "Saved into tar-buffer `%s'. Be sure to save that buffer!" | 1159 | (message "Saved into tar-buffer `%s'. Be sure to save that buffer!" |
| 1191 | (buffer-name tar-superior-buffer)) | 1160 | (buffer-name tar-superior-buffer)) |
| @@ -1235,14 +1204,13 @@ Leaves the region wide." | |||
| 1235 | ;; tar-header-offset turns out to be null for files fetched with W3, | 1204 | ;; tar-header-offset turns out to be null for files fetched with W3, |
| 1236 | ;; at least. | 1205 | ;; at least. |
| 1237 | (let ((coding-system-for-write 'no-conversion)) | 1206 | (let ((coding-system-for-write 'no-conversion)) |
| 1238 | (write-region (if tar-header-offset | 1207 | (write-region (or tar-header-offset |
| 1239 | (byte-to-position tar-header-offset) | 1208 | (point-min)) |
| 1240 | (point-min)) | ||
| 1241 | (point-max) | 1209 | (point-max) |
| 1242 | buffer-file-name nil t)) | 1210 | buffer-file-name nil t)) |
| 1243 | (tar-clear-modification-flags) | 1211 | (tar-clear-modification-flags) |
| 1244 | (set-buffer-modified-p nil)) | 1212 | (set-buffer-modified-p nil)) |
| 1245 | (narrow-to-region 1 (byte-to-position tar-header-offset))) | 1213 | (narrow-to-region 1 tar-header-offset)) |
| 1246 | ;; Return t because we've written the file. | 1214 | ;; Return t because we've written the file. |
| 1247 | t) | 1215 | t) |
| 1248 | 1216 | ||