diff options
| author | Stefan Monnier | 2000-06-05 07:44:59 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-06-05 07:44:59 +0000 |
| commit | 139f2b7cdc65aa91fba6c022aa3625a50fae3ee5 (patch) | |
| tree | 9cfe3e63eae8d2b3acb9d3836c05f8b1608d30c4 | |
| parent | c0078a045cd752c619a9d7739b5a56a4ada10590 (diff) | |
| download | emacs-139f2b7cdc65aa91fba6c022aa3625a50fae3ee5.tar.gz emacs-139f2b7cdc65aa91fba6c022aa3625a50fae3ee5.zip | |
(tar-header-block-recompute-checksum): Remove.
(tar-clip-time-string): Prepend a space.
(tar-grind-file-mode): Construct a string rather than modifying one.
(tar-header-block-summarize): Fix docstring.
Use `format' rather than an error-prone set of copy-loops.
| -rw-r--r-- | lisp/tar-mode.el | 126 |
1 files changed, 39 insertions, 87 deletions
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index 46d595ffeaa..bbf4774fd72 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el | |||
| @@ -314,38 +314,26 @@ write-date, checksum, link-type, and link-name." | |||
| 314 | (if (not (= desired-checksum (tar-header-block-checksum hblock))) | 314 | (if (not (= desired-checksum (tar-header-block-checksum hblock))) |
| 315 | (progn (beep) (message "Invalid checksum for file %s!" file-name)))) | 315 | (progn (beep) (message "Invalid checksum for file %s!" file-name)))) |
| 316 | 316 | ||
| 317 | (defun tar-header-block-recompute-checksum (hblock) | ||
| 318 | "Modifies the given string to have a valid checksum field." | ||
| 319 | (let* ((chk (tar-header-block-checksum hblock)) | ||
| 320 | (chk-string (format "%6o" chk)) | ||
| 321 | (l (length chk-string))) | ||
| 322 | (aset hblock 154 0) | ||
| 323 | (aset hblock 155 32) | ||
| 324 | (dotimes (i l) (aset hblock (- 153 i) (aref chk-string (- l i 1))))) | ||
| 325 | hblock) | ||
| 326 | |||
| 327 | (defun tar-clip-time-string (time) | 317 | (defun tar-clip-time-string (time) |
| 328 | (let ((str (current-time-string time))) | 318 | (let ((str (current-time-string time))) |
| 329 | (concat (substring str 4 16) (substring str 19 24)))) | 319 | (concat " " (substring str 4 16) (substring str 19 24)))) |
| 330 | 320 | ||
| 331 | (defun tar-grind-file-mode (mode string start) | 321 | (defun tar-grind-file-mode (mode) |
| 332 | "Store `-rw--r--r--' indicating MODE into STRING beginning at START. | 322 | "Construct a `-rw--r--r--' string indicating MODE. |
| 333 | MODE should be an integer which is a file mode value." | 323 | MODE should be an integer which is a file mode value." |
| 334 | (aset string start (if (zerop (logand 256 mode)) ?- ?r)) | 324 | (string |
| 335 | (aset string (+ start 1) (if (zerop (logand 128 mode)) ?- ?w)) | 325 | (if (zerop (logand 256 mode)) ?- ?r) |
| 336 | (aset string (+ start 2) (if (zerop (logand 64 mode)) ?- ?x)) | 326 | (if (zerop (logand 128 mode)) ?- ?w) |
| 337 | (aset string (+ start 3) (if (zerop (logand 32 mode)) ?- ?r)) | 327 | (if (zerop (logand 1024 mode)) (if (zerop (logand 64 mode)) ?- ?x) ?s) |
| 338 | (aset string (+ start 4) (if (zerop (logand 16 mode)) ?- ?w)) | 328 | (if (zerop (logand 32 mode)) ?- ?r) |
| 339 | (aset string (+ start 5) (if (zerop (logand 8 mode)) ?- ?x)) | 329 | (if (zerop (logand 16 mode)) ?- ?w) |
| 340 | (aset string (+ start 6) (if (zerop (logand 4 mode)) ?- ?r)) | 330 | (if (zerop (logand 2048 mode)) (if (zerop (logand 8 mode)) ?- ?x) ?s) |
| 341 | (aset string (+ start 7) (if (zerop (logand 2 mode)) ?- ?w)) | 331 | (if (zerop (logand 4 mode)) ?- ?r) |
| 342 | (aset string (+ start 8) (if (zerop (logand 1 mode)) ?- ?x)) | 332 | (if (zerop (logand 2 mode)) ?- ?w) |
| 343 | (if (zerop (logand 1024 mode)) nil (aset string (+ start 2) ?s)) | 333 | (if (zerop (logand 1 mode)) ?- ?x))) |
| 344 | (if (zerop (logand 2048 mode)) nil (aset string (+ start 5) ?s)) | ||
| 345 | string) | ||
| 346 | 334 | ||
| 347 | (defun tar-header-block-summarize (tar-hblock &optional mod-p) | 335 | (defun tar-header-block-summarize (tar-hblock &optional mod-p) |
| 348 | "Returns a line similar to the output of `tar -vtf'." | 336 | "Return a line similar to the output of `tar -vtf'." |
| 349 | (let ((name (tar-header-name tar-hblock)) | 337 | (let ((name (tar-header-name tar-hblock)) |
| 350 | (mode (tar-header-mode tar-hblock)) | 338 | (mode (tar-header-mode tar-hblock)) |
| 351 | (uid (tar-header-uid tar-hblock)) | 339 | (uid (tar-header-uid tar-hblock)) |
| @@ -355,68 +343,32 @@ MODE should be an integer which is a file mode value." | |||
| 355 | (size (tar-header-size tar-hblock)) | 343 | (size (tar-header-size tar-hblock)) |
| 356 | (time (tar-header-date tar-hblock)) | 344 | (time (tar-header-date tar-hblock)) |
| 357 | (ck (tar-header-checksum tar-hblock)) | 345 | (ck (tar-header-checksum tar-hblock)) |
| 358 | (link-p (tar-header-link-type tar-hblock)) | 346 | (type (tar-header-link-type tar-hblock)) |
| 359 | (link-name (tar-header-link-name tar-hblock)) | 347 | (link-name (tar-header-link-name tar-hblock))) |
| 360 | ) | 348 | (format "%c%c%s%8s/%-8s%7s%s %s%s" |
| 361 | (let* ((left 11) | 349 | (if mod-p ?* ? ) |
| 362 | (namew 8) | ||
| 363 | (groupw 8) | ||
| 364 | (sizew 8) | ||
| 365 | (datew (if tar-mode-show-date 18 0)) | ||
| 366 | (slash (1- (+ left namew))) | ||
| 367 | (lastdigit (+ slash groupw sizew)) | ||
| 368 | (datestart (+ lastdigit 2)) | ||
| 369 | (namestart (+ datestart datew)) | ||
| 370 | (multibyte (or (multibyte-string-p name) | ||
| 371 | (multibyte-string-p link-name))) | ||
| 372 | ;; If multibyte, we can't use optimized method of aset, | ||
| 373 | ;; instead we must use concat. | ||
| 374 | (string (make-string (if multibyte | ||
| 375 | namestart | ||
| 376 | (+ namestart | ||
| 377 | (length name) | ||
| 378 | (if link-p (+ 5 (length link-name)) 0))) | ||
| 379 | 32)) | ||
| 380 | (type (tar-header-link-type tar-hblock))) | ||
| 381 | (aset string 0 (if mod-p ?* ? )) | ||
| 382 | (aset string 1 | ||
| 383 | (cond ((or (eq type nil) (eq type 0)) ?-) | 350 | (cond ((or (eq type nil) (eq type 0)) ?-) |
| 384 | ((eq type 1) ?l) ; link | 351 | ((eq type 1) ?l) ; link |
| 385 | ((eq type 2) ?s) ; symlink | 352 | ((eq type 2) ?s) ; symlink |
| 386 | ((eq type 3) ?c) ; char special | 353 | ((eq type 3) ?c) ; char special |
| 387 | ((eq type 4) ?b) ; block special | 354 | ((eq type 4) ?b) ; block special |
| 388 | ((eq type 5) ?d) ; directory | 355 | ((eq type 5) ?d) ; directory |
| 389 | ((eq type 6) ?p) ; FIFO/pipe | 356 | ((eq type 6) ?p) ; FIFO/pipe |
| 390 | ((eq type 20) ?*) ; directory listing | 357 | ((eq type 20) ?*) ; directory listing |
| 391 | ((eq type 29) ?M) ; multivolume continuation | 358 | ((eq type 29) ?M) ; multivolume continuation |
| 392 | ((eq type 35) ?S) ; sparse | 359 | ((eq type 35) ?S) ; sparse |
| 393 | ((eq type 38) ?V) ; volume header | 360 | ((eq type 38) ?V) ; volume header |
| 394 | )) | 361 | (t ?\ ) |
| 395 | (tar-grind-file-mode mode string 2) | 362 | ) |
| 396 | (setq uid (if (= 0 (length uname)) (int-to-string uid) uname)) | 363 | (tar-grind-file-mode mode) |
| 397 | (setq gid (if (= 0 (length gname)) (int-to-string gid) gname)) | 364 | (if (= 0 (length uname)) uid uname) |
| 398 | (setq size (int-to-string size)) | 365 | (if (= 0 (length gname)) gid gname) |
| 399 | (setq time (tar-clip-time-string time)) | 366 | size |
| 400 | (dotimes (i (min (1- namew) (length uid))) (aset string (- slash i) (aref uid (- (length uid) i 1)))) | 367 | (if tar-mode-show-date (tar-clip-time-string time) "") |
| 401 | (aset string (1+ slash) ?/) | 368 | (propertize name 'mouse-face 'highlight) |
| 402 | (dotimes (i (min (1- groupw) (length gid))) (aset string (+ (+ slash 2) i) (aref gid i))) | 369 | (if (or (eq type 1) (eq type 2)) |
| 403 | (dotimes (i (min sizew (length size))) (aset string (- lastdigit i) (aref size (- (length size) i 1)))) | 370 | (concat (if (= type 1) " ==> " " --> ") link-name) |
| 404 | (if tar-mode-show-date | 371 | "")))) |
| 405 | (dotimes (i (length time)) (aset string (+ datestart i) (aref time i)))) | ||
| 406 | (if multibyte | ||
| 407 | (setq string (concat string name)) | ||
| 408 | (dotimes (i (length name)) (aset string (+ namestart i) (aref name i)))) | ||
| 409 | (if (or (eq link-p 1) (eq link-p 2)) | ||
| 410 | (if multibyte | ||
| 411 | (setq string (concat string | ||
| 412 | (if (= link-p 1) " ==> " " --> ") | ||
| 413 | link-name)) | ||
| 414 | (dotimes (i 3) (aset string (+ namestart 1 (length name) i) (aref (if (= link-p 1) "==>" "-->") i))) | ||
| 415 | (dotimes (i (length link-name)) (aset string (+ namestart 5 (length name) i) (aref link-name i))))) | ||
| 416 | (put-text-property namestart (length string) | ||
| 417 | 'mouse-face 'highlight string) | ||
| 418 | string))) | ||
| 419 | |||
| 420 | 372 | ||
| 421 | (defun tar-summarize-buffer () | 373 | (defun tar-summarize-buffer () |
| 422 | "Parse the contents of the tar file in the current buffer. | 374 | "Parse the contents of the tar file in the current buffer. |