diff options
| author | Stefan Monnier | 2005-11-10 18:00:37 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-11-10 18:00:37 +0000 |
| commit | 8560523d636a107cc030f7b12d1896afe8081220 (patch) | |
| tree | 9bf8a3a88c4bcbd6b33a4e99671f6a3e2f101d95 | |
| parent | d730a9fcf4aa7e4e1f8bd8255b50ce1b831d5ec8 (diff) | |
| download | emacs-8560523d636a107cc030f7b12d1896afe8081220.tar.gz emacs-8560523d636a107cc030f7b12d1896afe8081220.zip | |
Remove spurious or unnecessary leading stars in docstrings.
(tar-header-block-tokenize): Also obey default-file-name-coding-system.
(tar-parse-octal-integer-safe): Use mapc.
(tar-header-block-summarize): Remove unused var `ck'.
(tar-summarize-buffer): Don't clear the modified-p bit if it wasn't
cleared before. Obey default-enable-multibyte-characters.
Use mapconcat. Simplify setting of tar-header-offset.
(tar-mode-map): Move initialization inside delcaration.
(tar-flag-deleted): Use `abs'.
(tar-expunge-internal): Remove unused var `line'.
(tar-expunge-internal): Don't hardcode point-min==1.
(tar-expunge): Widen while doing set-buffer-multibyte.
(tar-rename-entry): Use file-name-coding-system.
(tar-alter-one-field): Don't hardcode point-min==1.
(tar-subfile-save-buffer): string-as-unibyte works on unibyte strings.
(tar-pad-to-blocksize): Don't hardcode point-min==1. Clarify the code.
| -rw-r--r-- | lisp/tar-mode.el | 377 |
1 files changed, 189 insertions, 188 deletions
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index 0e57d541dfe..5a400ffbec4 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el | |||
| @@ -101,7 +101,7 @@ | |||
| 101 | :group 'data) | 101 | :group 'data) |
| 102 | 102 | ||
| 103 | (defcustom tar-anal-blocksize 20 | 103 | (defcustom tar-anal-blocksize 20 |
| 104 | "*The blocksize of tar files written by Emacs, or nil, meaning don't care. | 104 | "The blocksize of tar files written by Emacs, or nil, meaning don't care. |
| 105 | The blocksize of a tar file is not really the size of the blocks; rather, it is | 105 | The blocksize of a tar file is not really the size of the blocks; rather, it is |
| 106 | the number of blocks written with one system call. When tarring to a tape, | 106 | the number of blocks written with one system call. When tarring to a tape, |
| 107 | this is the size of the *tape* blocks, but when writing to a file, it doesn't | 107 | this is the size of the *tape* blocks, but when writing to a file, it doesn't |
| @@ -112,7 +112,7 @@ how many null padding bytes go on the end of the tar file." | |||
| 112 | :group 'tar) | 112 | :group 'tar) |
| 113 | 113 | ||
| 114 | (defcustom tar-update-datestamp nil | 114 | (defcustom tar-update-datestamp nil |
| 115 | "*Non-nil means Tar mode should play fast and loose with sub-file datestamps. | 115 | "Non-nil means Tar mode should play fast and loose with sub-file datestamps. |
| 116 | If this is true, then editing and saving a tar file entry back into its | 116 | If this is true, then editing and saving a tar file entry back into its |
| 117 | tar file will update its datestamp. If false, the datestamp is unchanged. | 117 | tar file will update its datestamp. If false, the datestamp is unchanged. |
| 118 | You may or may not want this - it is good in that you can tell when a file | 118 | You may or may not want this - it is good in that you can tell when a file |
| @@ -123,7 +123,7 @@ the file never exists on disk." | |||
| 123 | :group 'tar) | 123 | :group 'tar) |
| 124 | 124 | ||
| 125 | (defcustom tar-mode-show-date nil | 125 | (defcustom tar-mode-show-date nil |
| 126 | "*Non-nil means Tar mode should show the date/time of each subfile. | 126 | "Non-nil means Tar mode should show the date/time of each subfile. |
| 127 | This information is useful, but it takes screen space away from file names." | 127 | This information is useful, but it takes screen space away from file names." |
| 128 | :type 'boolean | 128 | :type 'boolean |
| 129 | :group 'tar) | 129 | :group 'tar) |
| @@ -231,12 +231,16 @@ write-date, checksum, link-type, and link-name." | |||
| 231 | (setq linkname (substring string tar-link-offset link-end)) | 231 | (setq linkname (substring string tar-link-offset link-end)) |
| 232 | (if default-enable-multibyte-characters | 232 | (if default-enable-multibyte-characters |
| 233 | (setq name | 233 | (setq name |
| 234 | (decode-coding-string name (or file-name-coding-system | 234 | (decode-coding-string name |
| 235 | 'undecided)) | 235 | (or file-name-coding-system |
| 236 | default-file-name-coding-system | ||
| 237 | 'undecided)) | ||
| 236 | linkname | 238 | linkname |
| 237 | (decode-coding-string linkname (or file-name-coding-system | 239 | (decode-coding-string linkname |
| 238 | 'undecided)))) | 240 | (or file-name-coding-system |
| 239 | (if (and (null link-p) (string-match "/$" name)) (setq link-p 5)) ; directory | 241 | default-file-name-coding-system |
| 242 | 'undecided)))) | ||
| 243 | (if (and (null link-p) (string-match "/\\'" name)) (setq link-p 5)) ; directory | ||
| 240 | (make-tar-header | 244 | (make-tar-header |
| 241 | name | 245 | name |
| 242 | (tar-parse-octal-integer string tar-mode-offset tar-uid-offset) | 246 | (tar-parse-octal-integer string tar-mode-offset tar-uid-offset) |
| @@ -284,12 +288,11 @@ write-date, checksum, link-type, and link-name." | |||
| 284 | (list hi lo)))) | 288 | (list hi lo)))) |
| 285 | 289 | ||
| 286 | (defun tar-parse-octal-integer-safe (string) | 290 | (defun tar-parse-octal-integer-safe (string) |
| 287 | (let ((L (length string))) | 291 | (if (zerop (length string)) (error "empty string")) |
| 288 | (if (= L 0) (error "empty string")) | 292 | (mapc (lambda (c) |
| 289 | (dotimes (i L) | 293 | (if (or (< c ?0) (> c ?7)) |
| 290 | (if (or (< (aref string i) ?0) | 294 | (error "`%c' is not an octal digit" c))) |
| 291 | (> (aref string i) ?7)) | 295 | string) |
| 292 | (error "`%c' is not an octal digit" (aref string i))))) | ||
| 293 | (tar-parse-octal-integer string)) | 296 | (tar-parse-octal-integer string)) |
| 294 | 297 | ||
| 295 | 298 | ||
| @@ -343,7 +346,7 @@ MODE should be an integer which is a file mode value." | |||
| 343 | (gname (tar-header-gname tar-hblock)) | 346 | (gname (tar-header-gname tar-hblock)) |
| 344 | (size (tar-header-size tar-hblock)) | 347 | (size (tar-header-size tar-hblock)) |
| 345 | (time (tar-header-date tar-hblock)) | 348 | (time (tar-header-date tar-hblock)) |
| 346 | (ck (tar-header-checksum tar-hblock)) | 349 | ;; (ck (tar-header-checksum tar-hblock)) |
| 347 | (type (tar-header-link-type tar-hblock)) | 350 | (type (tar-header-link-type tar-hblock)) |
| 348 | (link-name (tar-header-link-name tar-hblock))) | 351 | (link-name (tar-header-link-name tar-hblock))) |
| 349 | (format "%c%c%s%8s/%-8s%7s%s %s%s" | 352 | (format "%c%c%s%8s/%-8s%7s%s %s%s" |
| @@ -403,147 +406,143 @@ MODE should be an integer which is a file mode value." | |||
| 403 | Place a dired-like listing on the front; | 406 | Place a dired-like listing on the front; |
| 404 | then narrow to it, so that only that listing | 407 | then narrow to it, so that only that listing |
| 405 | is visible (and the real data of the buffer is hidden)." | 408 | is visible (and the real data of the buffer is hidden)." |
| 406 | (set-buffer-multibyte nil) | 409 | (let ((modified (buffer-modified-p))) |
| 407 | (let* ((result '()) | 410 | (set-buffer-multibyte nil) |
| 408 | (pos (point-min)) | 411 | (let* ((result '()) |
| 409 | (progress-reporter | 412 | (pos (point-min)) |
| 410 | (make-progress-reporter "Parsing tar file..." | 413 | (progress-reporter |
| 411 | (point-min) (max 1 (- (buffer-size) 1024)))) | 414 | (make-progress-reporter "Parsing tar file..." |
| 412 | tokens) | 415 | (point-min) (max 1 (- (buffer-size) 1024)))) |
| 413 | (while (and (<= (+ pos 512) (point-max)) | 416 | tokens) |
| 414 | (not (eq 'empty-tar-block | 417 | (while (and (<= (+ pos 512) (point-max)) |
| 415 | (setq tokens | 418 | (not (eq 'empty-tar-block |
| 416 | (tar-header-block-tokenize | 419 | (setq tokens |
| 417 | (buffer-substring pos (+ pos 512))))))) | 420 | (tar-header-block-tokenize |
| 418 | (setq pos (+ pos 512)) | 421 | (buffer-substring pos (+ pos 512))))))) |
| 419 | (progress-reporter-update progress-reporter pos) | 422 | (setq pos (+ pos 512)) |
| 420 | (if (eq (tar-header-link-type tokens) 20) | 423 | (progress-reporter-update progress-reporter pos) |
| 421 | ;; Foo. There's an extra empty block after these. | 424 | (if (eq (tar-header-link-type tokens) 20) |
| 422 | (setq pos (+ pos 512))) | 425 | ;; Foo. There's an extra empty block after these. |
| 423 | (let ((size (tar-header-size tokens))) | 426 | (setq pos (+ pos 512))) |
| 424 | (if (< size 0) | 427 | (let ((size (tar-header-size tokens))) |
| 425 | (error "%s has size %s - corrupted" | 428 | (if (< size 0) |
| 426 | (tar-header-name tokens) size)) | 429 | (error "%s has size %s - corrupted" |
| 427 | ; | 430 | (tar-header-name tokens) size)) |
| 428 | ; This is just too slow. Don't really need it anyway.... | 431 | ; |
| 429 | ;(tar-header-block-check-checksum | 432 | ; This is just too slow. Don't really need it anyway.... |
| 430 | ; hblock (tar-header-block-checksum hblock) | 433 | ;(tar-header-block-check-checksum |
| 431 | ; (tar-header-name tokens)) | 434 | ; hblock (tar-header-block-checksum hblock) |
| 432 | 435 | ; (tar-header-name tokens)) | |
| 433 | (setq result (cons (make-tar-desc pos tokens) result)) | 436 | |
| 434 | 437 | (push (make-tar-desc pos tokens) result) | |
| 435 | (and (null (tar-header-link-type tokens)) | 438 | |
| 436 | (> size 0) | 439 | (and (null (tar-header-link-type tokens)) |
| 437 | (setq pos | 440 | (> size 0) |
| 438 | (+ pos 512 (ash (ash (1- size) -9) 9)) ; this works | 441 | (setq pos |
| 439 | ;(+ pos (+ size (- 512 (rem (1- size) 512)))) ; this doesn't | 442 | (+ pos 512 (ash (ash (1- size) -9) 9)) ; this works |
| 440 | )))) | 443 | ;(+ pos (+ size (- 512 (rem (1- size) 512)))) ; this doesn't |
| 441 | (make-local-variable 'tar-parse-info) | 444 | )))) |
| 442 | (setq tar-parse-info (nreverse result)) | 445 | (make-local-variable 'tar-parse-info) |
| 443 | ;; A tar file should end with a block or two of nulls, | 446 | (setq tar-parse-info (nreverse result)) |
| 444 | ;; but let's not get a fatal error if it doesn't. | 447 | ;; A tar file should end with a block or two of nulls, |
| 445 | (if (eq tokens 'empty-tar-block) | 448 | ;; but let's not get a fatal error if it doesn't. |
| 446 | (progress-reporter-done progress-reporter) | 449 | (if (eq tokens 'empty-tar-block) |
| 447 | (message "Warning: premature EOF parsing tar file"))) | 450 | (progress-reporter-done progress-reporter) |
| 448 | (save-excursion | 451 | (message "Warning: premature EOF parsing tar file"))) |
| 452 | (set-buffer-multibyte default-enable-multibyte-characters) | ||
| 449 | (goto-char (point-min)) | 453 | (goto-char (point-min)) |
| 450 | (let ((buffer-read-only nil) | 454 | (let ((inhibit-read-only t)) |
| 451 | (summaries nil)) | ||
| 452 | ;; Collect summary lines and insert them all at once since tar files | 455 | ;; Collect summary lines and insert them all at once since tar files |
| 453 | ;; can be pretty big. | 456 | ;; can be pretty big. |
| 454 | (dolist (tar-desc (reverse tar-parse-info)) | 457 | (let ((total-summaries |
| 455 | (setq summaries | 458 | (mapconcat |
| 456 | (cons (tar-header-block-summarize (tar-desc-tokens tar-desc)) | 459 | (lambda (tar-desc) |
| 457 | (cons "\n" | 460 | (tar-header-block-summarize (tar-desc-tokens tar-desc))) |
| 458 | summaries)))) | 461 | tar-parse-info |
| 459 | (let ((total-summaries (apply 'concat summaries))) | 462 | "\n"))) |
| 460 | (if (multibyte-string-p total-summaries) | 463 | (insert total-summaries "\n")) |
| 461 | (set-buffer-multibyte t)) | 464 | (narrow-to-region (point-min) (point)) |
| 462 | (insert total-summaries)) | 465 | (set (make-local-variable 'tar-header-offset) (position-bytes (point))) |
| 463 | (make-local-variable 'tar-header-offset) | 466 | (goto-char (point-min)) |
| 464 | (setq tar-header-offset (point)) | 467 | (restore-buffer-modified-p modified)))) |
| 465 | (narrow-to-region (point-min) tar-header-offset) | ||
| 466 | (if enable-multibyte-characters | ||
| 467 | (setq tar-header-offset (position-bytes tar-header-offset))) | ||
| 468 | (set-buffer-modified-p nil)))) | ||
| 469 | 468 | ||
| 470 | (defvar tar-mode-map nil "*Local keymap for Tar mode listings.") | 469 | (defvar tar-mode-map |
| 471 | 470 | (let ((map (make-keymap))) | |
| 472 | (if tar-mode-map | 471 | (suppress-keymap map) |
| 473 | nil | 472 | (define-key map " " 'tar-next-line) |
| 474 | (setq tar-mode-map (make-keymap)) | 473 | (define-key map "C" 'tar-copy) |
| 475 | (suppress-keymap tar-mode-map) | 474 | (define-key map "d" 'tar-flag-deleted) |
| 476 | (define-key tar-mode-map " " 'tar-next-line) | 475 | (define-key map "\^D" 'tar-flag-deleted) |
| 477 | (define-key tar-mode-map "C" 'tar-copy) | 476 | (define-key map "e" 'tar-extract) |
| 478 | (define-key tar-mode-map "d" 'tar-flag-deleted) | 477 | (define-key map "f" 'tar-extract) |
| 479 | (define-key tar-mode-map "\^D" 'tar-flag-deleted) | 478 | (define-key map "\C-m" 'tar-extract) |
| 480 | (define-key tar-mode-map "e" 'tar-extract) | 479 | (define-key map [mouse-2] 'tar-mouse-extract) |
| 481 | (define-key tar-mode-map "f" 'tar-extract) | 480 | (define-key map "g" 'revert-buffer) |
| 482 | (define-key tar-mode-map "\C-m" 'tar-extract) | 481 | (define-key map "h" 'describe-mode) |
| 483 | (define-key tar-mode-map [mouse-2] 'tar-mouse-extract) | 482 | (define-key map "n" 'tar-next-line) |
| 484 | (define-key tar-mode-map "g" 'revert-buffer) | 483 | (define-key map "\^N" 'tar-next-line) |
| 485 | (define-key tar-mode-map "h" 'describe-mode) | 484 | (define-key map [down] 'tar-next-line) |
| 486 | (define-key tar-mode-map "n" 'tar-next-line) | 485 | (define-key map "o" 'tar-extract-other-window) |
| 487 | (define-key tar-mode-map "\^N" 'tar-next-line) | 486 | (define-key map "p" 'tar-previous-line) |
| 488 | (define-key tar-mode-map [down] 'tar-next-line) | 487 | (define-key map "q" 'quit-window) |
| 489 | (define-key tar-mode-map "o" 'tar-extract-other-window) | 488 | (define-key map "\^P" 'tar-previous-line) |
| 490 | (define-key tar-mode-map "p" 'tar-previous-line) | 489 | (define-key map [up] 'tar-previous-line) |
| 491 | (define-key tar-mode-map "q" 'quit-window) | 490 | (define-key map "R" 'tar-rename-entry) |
| 492 | (define-key tar-mode-map "\^P" 'tar-previous-line) | 491 | (define-key map "u" 'tar-unflag) |
| 493 | (define-key tar-mode-map [up] 'tar-previous-line) | 492 | (define-key map "v" 'tar-view) |
| 494 | (define-key tar-mode-map "R" 'tar-rename-entry) | 493 | (define-key map "x" 'tar-expunge) |
| 495 | (define-key tar-mode-map "u" 'tar-unflag) | 494 | (define-key map "\177" 'tar-unflag-backwards) |
| 496 | (define-key tar-mode-map "v" 'tar-view) | 495 | (define-key map "E" 'tar-extract-other-window) |
| 497 | (define-key tar-mode-map "x" 'tar-expunge) | 496 | (define-key map "M" 'tar-chmod-entry) |
| 498 | (define-key tar-mode-map "\177" 'tar-unflag-backwards) | 497 | (define-key map "G" 'tar-chgrp-entry) |
| 499 | (define-key tar-mode-map "E" 'tar-extract-other-window) | 498 | (define-key map "O" 'tar-chown-entry) |
| 500 | (define-key tar-mode-map "M" 'tar-chmod-entry) | 499 | |
| 501 | (define-key tar-mode-map "G" 'tar-chgrp-entry) | 500 | ;; Make menu bar items. |
| 502 | (define-key tar-mode-map "O" 'tar-chown-entry) | 501 | |
| 503 | ) | 502 | ;; Get rid of the Edit menu bar item to save space. |
| 504 | 503 | (define-key map [menu-bar edit] 'undefined) | |
| 505 | ;; Make menu bar items. | 504 | |
| 506 | 505 | (define-key map [menu-bar immediate] | |
| 507 | ;; Get rid of the Edit menu bar item to save space. | 506 | (cons "Immediate" (make-sparse-keymap "Immediate"))) |
| 508 | (define-key tar-mode-map [menu-bar edit] 'undefined) | 507 | |
| 509 | 508 | (define-key map [menu-bar immediate view] | |
| 510 | (define-key tar-mode-map [menu-bar immediate] | 509 | '("View This File" . tar-view)) |
| 511 | (cons "Immediate" (make-sparse-keymap "Immediate"))) | 510 | (define-key map [menu-bar immediate display] |
| 512 | 511 | '("Display in Other Window" . tar-display-other-window)) | |
| 513 | (define-key tar-mode-map [menu-bar immediate view] | 512 | (define-key map [menu-bar immediate find-file-other-window] |
| 514 | '("View This File" . tar-view)) | 513 | '("Find in Other Window" . tar-extract-other-window)) |
| 515 | (define-key tar-mode-map [menu-bar immediate display] | 514 | (define-key map [menu-bar immediate find-file] |
| 516 | '("Display in Other Window" . tar-display-other-window)) | 515 | '("Find This File" . tar-extract)) |
| 517 | (define-key tar-mode-map [menu-bar immediate find-file-other-window] | 516 | |
| 518 | '("Find in Other Window" . tar-extract-other-window)) | 517 | (define-key map [menu-bar mark] |
| 519 | (define-key tar-mode-map [menu-bar immediate find-file] | 518 | (cons "Mark" (make-sparse-keymap "Mark"))) |
| 520 | '("Find This File" . tar-extract)) | 519 | |
| 521 | 520 | (define-key map [menu-bar mark unmark-all] | |
| 522 | (define-key tar-mode-map [menu-bar mark] | 521 | '("Unmark All" . tar-clear-modification-flags)) |
| 523 | (cons "Mark" (make-sparse-keymap "Mark"))) | 522 | (define-key map [menu-bar mark deletion] |
| 524 | 523 | '("Flag" . tar-flag-deleted)) | |
| 525 | (define-key tar-mode-map [menu-bar mark unmark-all] | 524 | (define-key map [menu-bar mark unmark] |
| 526 | '("Unmark All" . tar-clear-modification-flags)) | 525 | '("Unflag" . tar-unflag)) |
| 527 | (define-key tar-mode-map [menu-bar mark deletion] | 526 | |
| 528 | '("Flag" . tar-flag-deleted)) | 527 | (define-key map [menu-bar operate] |
| 529 | (define-key tar-mode-map [menu-bar mark unmark] | 528 | (cons "Operate" (make-sparse-keymap "Operate"))) |
| 530 | '("Unflag" . tar-unflag)) | 529 | |
| 531 | 530 | (define-key map [menu-bar operate chown] | |
| 532 | (define-key tar-mode-map [menu-bar operate] | 531 | '("Change Owner..." . tar-chown-entry)) |
| 533 | (cons "Operate" (make-sparse-keymap "Operate"))) | 532 | (define-key map [menu-bar operate chgrp] |
| 534 | 533 | '("Change Group..." . tar-chgrp-entry)) | |
| 535 | (define-key tar-mode-map [menu-bar operate chown] | 534 | (define-key map [menu-bar operate chmod] |
| 536 | '("Change Owner..." . tar-chown-entry)) | 535 | '("Change Mode..." . tar-chmod-entry)) |
| 537 | (define-key tar-mode-map [menu-bar operate chgrp] | 536 | (define-key map [menu-bar operate rename] |
| 538 | '("Change Group..." . tar-chgrp-entry)) | 537 | '("Rename to..." . tar-rename-entry)) |
| 539 | (define-key tar-mode-map [menu-bar operate chmod] | 538 | (define-key map [menu-bar operate copy] |
| 540 | '("Change Mode..." . tar-chmod-entry)) | 539 | '("Copy to..." . tar-copy)) |
| 541 | (define-key tar-mode-map [menu-bar operate rename] | 540 | (define-key map [menu-bar operate expunge] |
| 542 | '("Rename to..." . tar-rename-entry)) | 541 | '("Expunge Marked Files" . tar-expunge)) |
| 543 | (define-key tar-mode-map [menu-bar operate copy] | 542 | |
| 544 | '("Copy to..." . tar-copy)) | 543 | map) |
| 545 | (define-key tar-mode-map [menu-bar operate expunge] | 544 | "Local keymap for Tar mode listings.") |
| 546 | '("Expunge Marked Files" . tar-expunge)) | 545 | |
| 547 | 546 | ||
| 548 | ;; tar mode is suitable only for specially formatted data. | 547 | ;; tar mode is suitable only for specially formatted data. |
| 549 | (put 'tar-mode 'mode-class 'special) | 548 | (put 'tar-mode 'mode-class 'special) |
| @@ -559,7 +558,7 @@ or click mouse-2 on the file's line in the Tar mode buffer. | |||
| 559 | Type `c' to copy an entry from the tar file into another file on disk. | 558 | Type `c' to copy an entry from the tar file into another file on disk. |
| 560 | 559 | ||
| 561 | If you edit a sub-file of this archive (as with the `e' command) and | 560 | If you edit a sub-file of this archive (as with the `e' command) and |
| 562 | save it with Control-x Control-s, the contents of that buffer will be | 561 | save it with \\[save-buffer], the contents of that buffer will be |
| 563 | saved back into the tar-file buffer; in this way you can edit a file | 562 | saved back into the tar-file buffer; in this way you can edit a file |
| 564 | inside of a tar archive without extracting it and re-archiving it. | 563 | inside of a tar archive without extracting it and re-archiving it. |
| 565 | 564 | ||
| @@ -787,17 +786,17 @@ appear on disk when you save the tar-file's buffer." | |||
| 787 | 786 | ||
| 788 | 787 | ||
| 789 | (defun tar-extract-other-window () | 788 | (defun tar-extract-other-window () |
| 790 | "*In Tar mode, find this entry of the tar file in another window." | 789 | "In Tar mode, find this entry of the tar file in another window." |
| 791 | (interactive) | 790 | (interactive) |
| 792 | (tar-extract t)) | 791 | (tar-extract t)) |
| 793 | 792 | ||
| 794 | (defun tar-display-other-window () | 793 | (defun tar-display-other-window () |
| 795 | "*In Tar mode, display this entry of the tar file in another window." | 794 | "In Tar mode, display this entry of the tar file in another window." |
| 796 | (interactive) | 795 | (interactive) |
| 797 | (tar-extract 'display)) | 796 | (tar-extract 'display)) |
| 798 | 797 | ||
| 799 | (defun tar-view () | 798 | (defun tar-view () |
| 800 | "*In Tar mode, view the tar file entry on this line." | 799 | "In Tar mode, view the tar file entry on this line." |
| 801 | (interactive) | 800 | (interactive) |
| 802 | (tar-extract 'view)) | 801 | (tar-extract 'view)) |
| 803 | 802 | ||
| @@ -823,7 +822,7 @@ appear on disk when you save the tar-file's buffer." | |||
| 823 | 822 | ||
| 824 | 823 | ||
| 825 | (defun tar-copy (&optional to-file) | 824 | (defun tar-copy (&optional to-file) |
| 826 | "*In Tar mode, extract this entry of the tar file into a file on disk. | 825 | "In Tar mode, extract this entry of the tar file into a file on disk. |
| 827 | If TO-FILE is not supplied, it is prompted for, defaulting to the name of | 826 | If TO-FILE is not supplied, it is prompted for, defaulting to the name of |
| 828 | the current tar-entry." | 827 | the current tar-entry." |
| 829 | (interactive (list (tar-read-file-name))) | 828 | (interactive (list (tar-read-file-name))) |
| @@ -856,11 +855,11 @@ the current tar-entry." | |||
| 856 | (message "Copied tar entry %s to %s" name to-file))) | 855 | (message "Copied tar entry %s to %s" name to-file))) |
| 857 | 856 | ||
| 858 | (defun tar-flag-deleted (p &optional unflag) | 857 | (defun tar-flag-deleted (p &optional unflag) |
| 859 | "*In Tar mode, mark this sub-file to be deleted from the tar file. | 858 | "In Tar mode, mark this sub-file to be deleted from the tar file. |
| 860 | With a prefix argument, mark that many files." | 859 | With a prefix argument, mark that many files." |
| 861 | (interactive "p") | 860 | (interactive "p") |
| 862 | (beginning-of-line) | 861 | (beginning-of-line) |
| 863 | (dotimes (i (if (< p 0) (- p) p)) | 862 | (dotimes (i (abs p)) |
| 864 | (if (tar-current-descriptor unflag) ; barf if we're not on an entry-line. | 863 | (if (tar-current-descriptor unflag) ; barf if we're not on an entry-line. |
| 865 | (progn | 864 | (progn |
| 866 | (delete-char 1) | 865 | (delete-char 1) |
| @@ -869,13 +868,13 @@ With a prefix argument, mark that many files." | |||
| 869 | (if (eobp) nil (forward-char 36))) | 868 | (if (eobp) nil (forward-char 36))) |
| 870 | 869 | ||
| 871 | (defun tar-unflag (p) | 870 | (defun tar-unflag (p) |
| 872 | "*In Tar mode, un-mark this sub-file if it is marked to be deleted. | 871 | "In Tar mode, un-mark this sub-file if it is marked to be deleted. |
| 873 | With a prefix argument, un-mark that many files forward." | 872 | With a prefix argument, un-mark that many files forward." |
| 874 | (interactive "p") | 873 | (interactive "p") |
| 875 | (tar-flag-deleted p t)) | 874 | (tar-flag-deleted p t)) |
| 876 | 875 | ||
| 877 | (defun tar-unflag-backwards (p) | 876 | (defun tar-unflag-backwards (p) |
| 878 | "*In Tar mode, un-mark this sub-file if it is marked to be deleted. | 877 | "In Tar mode, un-mark this sub-file if it is marked to be deleted. |
| 879 | With a prefix argument, un-mark that many files backward." | 878 | With a prefix argument, un-mark that many files backward." |
| 880 | (interactive "p") | 879 | (interactive "p") |
| 881 | (tar-flag-deleted (- p) t)) | 880 | (tar-flag-deleted (- p) t)) |
| @@ -886,7 +885,7 @@ With a prefix argument, un-mark that many files backward." | |||
| 886 | "Expunge the tar-entry specified by the current line." | 885 | "Expunge the tar-entry specified by the current line." |
| 887 | (let* ((descriptor (tar-current-descriptor)) | 886 | (let* ((descriptor (tar-current-descriptor)) |
| 888 | (tokens (tar-desc-tokens descriptor)) | 887 | (tokens (tar-desc-tokens descriptor)) |
| 889 | (line (tar-desc-data-start descriptor)) | 888 | ;; (line (tar-desc-data-start descriptor)) |
| 890 | (name (tar-header-name tokens)) | 889 | (name (tar-header-name tokens)) |
| 891 | (size (tar-header-size tokens)) | 890 | (size (tar-header-size tokens)) |
| 892 | (link-p (tar-header-link-type tokens)) | 891 | (link-p (tar-header-link-type tokens)) |
| @@ -898,18 +897,16 @@ With a prefix argument, un-mark that many files backward." | |||
| 898 | (beginning-of-line) | 897 | (beginning-of-line) |
| 899 | (let ((line-start (point))) | 898 | (let ((line-start (point))) |
| 900 | (end-of-line) (forward-char) | 899 | (end-of-line) (forward-char) |
| 901 | (let ((line-len (- (point) line-start))) | 900 | ;; decrement the header-pointer to be in sync... |
| 902 | (delete-region line-start (point)) | 901 | (setq tar-header-offset (- tar-header-offset (- (point) line-start))) |
| 903 | ;; | 902 | (delete-region line-start (point))) |
| 904 | ;; decrement the header-pointer to be in sync... | ||
| 905 | (setq tar-header-offset (- tar-header-offset line-len)))) | ||
| 906 | ;; | 903 | ;; |
| 907 | ;; delete the data pointer... | 904 | ;; delete the data pointer... |
| 908 | (setq tar-parse-info (delq descriptor tar-parse-info)) | 905 | (setq tar-parse-info (delq descriptor tar-parse-info)) |
| 909 | ;; | 906 | ;; |
| 910 | ;; delete the data from inside the file... | 907 | ;; delete the data from inside the file... |
| 911 | (widen) | 908 | (widen) |
| 912 | (let* ((data-start (+ start tar-header-offset -513)) | 909 | (let* ((data-start (+ start (- tar-header-offset (point-min)) -512)) |
| 913 | (data-end (+ data-start 512 (ash (ash (+ size 511) -9) 9)))) | 910 | (data-end (+ data-start 512 (ash (ash (+ size 511) -9) 9)))) |
| 914 | (delete-region data-start data-end) | 911 | (delete-region data-start data-end) |
| 915 | ;; | 912 | ;; |
| @@ -927,7 +924,7 @@ With a prefix argument, un-mark that many files backward." | |||
| 927 | 924 | ||
| 928 | 925 | ||
| 929 | (defun tar-expunge (&optional noconfirm) | 926 | (defun tar-expunge (&optional noconfirm) |
| 930 | "*In Tar mode, delete all the archived files flagged for deletion. | 927 | "In Tar mode, delete all the archived files flagged for deletion. |
| 931 | This does not modify the disk image; you must save the tar file itself | 928 | This does not modify the disk image; you must save the tar file itself |
| 932 | for this to be permanent." | 929 | for this to be permanent." |
| 933 | (interactive) | 930 | (interactive) |
| @@ -935,8 +932,9 @@ for this to be permanent." | |||
| 935 | (y-or-n-p "Expunge files marked for deletion? ")) | 932 | (y-or-n-p "Expunge files marked for deletion? ")) |
| 936 | (let ((n 0) | 933 | (let ((n 0) |
| 937 | (multibyte enable-multibyte-characters)) | 934 | (multibyte enable-multibyte-characters)) |
| 938 | (set-buffer-multibyte nil) | ||
| 939 | (save-excursion | 935 | (save-excursion |
| 936 | (widen) | ||
| 937 | (set-buffer-multibyte nil) | ||
| 940 | (goto-char (point-min)) | 938 | (goto-char (point-min)) |
| 941 | (while (not (eobp)) | 939 | (while (not (eobp)) |
| 942 | (if (looking-at "D") | 940 | (if (looking-at "D") |
| @@ -945,8 +943,9 @@ for this to be permanent." | |||
| 945 | (forward-line 1))) | 943 | (forward-line 1))) |
| 946 | ;; after doing the deletions, add any padding that may be necessary. | 944 | ;; after doing the deletions, add any padding that may be necessary. |
| 947 | (tar-pad-to-blocksize) | 945 | (tar-pad-to-blocksize) |
| 946 | (widen) | ||
| 947 | (set-buffer-multibyte multibyte) | ||
| 948 | (narrow-to-region (point-min) tar-header-offset)) | 948 | (narrow-to-region (point-min) tar-header-offset)) |
| 949 | (set-buffer-multibyte multibyte) | ||
| 950 | (if (zerop n) | 949 | (if (zerop n) |
| 951 | (message "Nothing to expunge.") | 950 | (message "Nothing to expunge.") |
| 952 | (message "%s files expunged. Be sure to save this buffer." n))))) | 951 | (message "%s files expunged. Be sure to save this buffer." n))))) |
| @@ -964,7 +963,7 @@ for this to be permanent." | |||
| 964 | 963 | ||
| 965 | 964 | ||
| 966 | (defun tar-chown-entry (new-uid) | 965 | (defun tar-chown-entry (new-uid) |
| 967 | "*Change the user-id associated with this entry in the tar file. | 966 | "Change the user-id associated with this entry in the tar file. |
| 968 | If this tar file was written by GNU tar, then you will be able to edit | 967 | If this tar file was written by GNU tar, then you will be able to edit |
| 969 | the user id as a string; otherwise, you must edit it as a number. | 968 | the user id as a string; otherwise, you must edit it as a number. |
| 970 | You can force editing as a number by calling this with a prefix arg. | 969 | You can force editing as a number by calling this with a prefix arg. |
| @@ -992,7 +991,7 @@ for this to be permanent." | |||
| 992 | 991 | ||
| 993 | 992 | ||
| 994 | (defun tar-chgrp-entry (new-gid) | 993 | (defun tar-chgrp-entry (new-gid) |
| 995 | "*Change the group-id associated with this entry in the tar file. | 994 | "Change the group-id associated with this entry in the tar file. |
| 996 | If this tar file was written by GNU tar, then you will be able to edit | 995 | If this tar file was written by GNU tar, then you will be able to edit |
| 997 | the group id as a string; otherwise, you must edit it as a number. | 996 | the group id as a string; otherwise, you must edit it as a number. |
| 998 | You can force editing as a number by calling this with a prefix arg. | 997 | You can force editing as a number by calling this with a prefix arg. |
| @@ -1020,7 +1019,7 @@ for this to be permanent." | |||
| 1020 | (concat (substring (format "%6o" new-gid) 0 6) "\000 "))))) | 1019 | (concat (substring (format "%6o" new-gid) 0 6) "\000 "))))) |
| 1021 | 1020 | ||
| 1022 | (defun tar-rename-entry (new-name) | 1021 | (defun tar-rename-entry (new-name) |
| 1023 | "*Change the name associated with this entry in the tar file. | 1022 | "Change the name associated with this entry in the tar file. |
| 1024 | This does not modify the disk image; you must save the tar file itself | 1023 | This does not modify the disk image; you must save the tar file itself |
| 1025 | for this to be permanent." | 1024 | for this to be permanent." |
| 1026 | (interactive | 1025 | (interactive |
| @@ -1030,12 +1029,16 @@ for this to be permanent." | |||
| 1030 | (if (> (length new-name) 98) (error "name too long")) | 1029 | (if (> (length new-name) 98) (error "name too long")) |
| 1031 | (tar-setf (tar-header-name (tar-desc-tokens (tar-current-descriptor))) | 1030 | (tar-setf (tar-header-name (tar-desc-tokens (tar-current-descriptor))) |
| 1032 | new-name) | 1031 | new-name) |
| 1032 | (if (multibyte-string-p new-name) | ||
| 1033 | (setq new-name (encode-coding-string new-name | ||
| 1034 | (or file-name-coding-system | ||
| 1035 | default-file-name-coding-system)))) | ||
| 1033 | (tar-alter-one-field 0 | 1036 | (tar-alter-one-field 0 |
| 1034 | (substring (concat new-name (make-string 99 0)) 0 99))) | 1037 | (substring (concat new-name (make-string 99 0)) 0 99))) |
| 1035 | 1038 | ||
| 1036 | 1039 | ||
| 1037 | (defun tar-chmod-entry (new-mode) | 1040 | (defun tar-chmod-entry (new-mode) |
| 1038 | "*Change the protection bits associated with this entry in the tar file. | 1041 | "Change the protection bits associated with this entry in the tar file. |
| 1039 | This does not modify the disk image; you must save the tar file itself | 1042 | This does not modify the disk image; you must save the tar file itself |
| 1040 | for this to be permanent." | 1043 | for this to be permanent." |
| 1041 | (interactive (list (tar-parse-octal-integer-safe | 1044 | (interactive (list (tar-parse-octal-integer-safe |
| @@ -1063,7 +1066,9 @@ for this to be permanent." | |||
| 1063 | 1066 | ||
| 1064 | (widen) | 1067 | (widen) |
| 1065 | (set-buffer-multibyte nil) | 1068 | (set-buffer-multibyte nil) |
| 1066 | (let* ((start (+ (tar-desc-data-start descriptor) tar-header-offset -513))) | 1069 | (let* ((start (+ (tar-desc-data-start descriptor) |
| 1070 | (- tar-header-offset (point-min)) | ||
| 1071 | -512))) | ||
| 1067 | ;; | 1072 | ;; |
| 1068 | ;; delete the old field and insert a new one. | 1073 | ;; delete the old field and insert a new one. |
| 1069 | (goto-char (+ start data-position)) | 1074 | (goto-char (+ start data-position)) |
| @@ -1196,9 +1201,7 @@ to make your changes permanent." | |||
| 1196 | ;; Insert the new text after the old, before deleting, | 1201 | ;; Insert the new text after the old, before deleting, |
| 1197 | ;; to preserve the window start. | 1202 | ;; to preserve the window start. |
| 1198 | (let ((line (tar-header-block-summarize tokens t))) | 1203 | (let ((line (tar-header-block-summarize tokens t))) |
| 1199 | (if (multibyte-string-p line) | 1204 | (insert-before-markers (string-as-unibyte line) "\n")) |
| 1200 | (insert-before-markers (string-as-unibyte line) "\n") | ||
| 1201 | (insert-before-markers line "\n"))) | ||
| 1202 | (delete-region p after) | 1205 | (delete-region p after) |
| 1203 | (setq tar-header-offset (marker-position m))) | 1206 | (setq tar-header-offset (marker-position m))) |
| 1204 | ))) | 1207 | ))) |
| @@ -1234,19 +1237,17 @@ Leaves the region wide." | |||
| 1234 | (size (if link-p 0 (tar-header-size tokens))) | 1237 | (size (if link-p 0 (tar-header-size tokens))) |
| 1235 | (data-end (+ start size)) | 1238 | (data-end (+ start size)) |
| 1236 | (bbytes (ash tar-anal-blocksize 9)) | 1239 | (bbytes (ash tar-anal-blocksize 9)) |
| 1237 | (pad-to (+ bbytes (* bbytes (/ (1- data-end) bbytes)))) | 1240 | (pad-to (+ bbytes (* bbytes (/ (- data-end (point-min)) bbytes)))) |
| 1238 | (inhibit-read-only t) ; ## | 1241 | (inhibit-read-only t) ; ## |
| 1239 | ) | 1242 | ) |
| 1240 | ;; If the padding after the last data is too long, delete some; | 1243 | ;; If the padding after the last data is too long, delete some; |
| 1241 | ;; else insert some until we are padded out to the right number of blocks. | 1244 | ;; else insert some until we are padded out to the right number of blocks. |
| 1242 | ;; | 1245 | ;; |
| 1243 | (goto-char (+ (or tar-header-offset 0) data-end)) | 1246 | (let ((goal-end (+ (or tar-header-offset 0) pad-to))) |
| 1244 | (if (> (1+ (buffer-size)) (+ (or tar-header-offset 0) pad-to)) | 1247 | (if (> (point-max) goal-end) |
| 1245 | (delete-region (+ (or tar-header-offset 0) pad-to) (1+ (buffer-size))) | 1248 | (delete-region goal-end (point-max)) |
| 1246 | (insert (make-string (- (+ (or tar-header-offset 0) pad-to) | 1249 | (goto-char (point-max)) |
| 1247 | (1+ (buffer-size))) | 1250 | (insert (make-string (- goal-end (point-max)) ?\0))))))) |
| 1248 | 0))) | ||
| 1249 | ))) | ||
| 1250 | 1251 | ||
| 1251 | 1252 | ||
| 1252 | ;; Used in write-file-hook to write tar-files out correctly. | 1253 | ;; Used in write-file-hook to write tar-files out correctly. |
| @@ -1273,5 +1274,5 @@ Leaves the region wide." | |||
| 1273 | 1274 | ||
| 1274 | (provide 'tar-mode) | 1275 | (provide 'tar-mode) |
| 1275 | 1276 | ||
| 1276 | ;;; arch-tag: 8a585a4a-340e-42c2-89e7-d3b1013a4b78 | 1277 | ;; arch-tag: 8a585a4a-340e-42c2-89e7-d3b1013a4b78 |
| 1277 | ;;; tar-mode.el ends here | 1278 | ;;; tar-mode.el ends here |