Mercurial > emacs
comparison lisp/arc-mode.el @ 70388:000b130bfb7d
(archive-l-e): New optional argument `float' means generate a float value.
(archive-arc-summarize, archive-lzh-summarize)
(archive-zip-summarize, archive-zoo-summarize): Invoke archive-l-e with 3rd
argument non-nil when file's size is being computed. Format the file sizes
with %8.0f instead of %8d.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 05 May 2006 10:54:55 +0000 |
parents | 619b0c2000a6 |
children | 2400f78c17e8 |
comparison
equal
deleted
inserted
replaced
70387:a995a8745b40 | 70388:000b130bfb7d |
---|---|
462 ;; Section: Support functions. | 462 ;; Section: Support functions. |
463 | 463 |
464 (defsubst archive-name (suffix) | 464 (defsubst archive-name (suffix) |
465 (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) | 465 (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) |
466 | 466 |
467 (defun archive-l-e (str &optional len) | 467 (defun archive-l-e (str &optional len float) |
468 "Convert little endian string/vector STR to integer. | 468 "Convert little endian string/vector STR to integer. |
469 Alternatively, STR may be a buffer position in the current buffer | 469 Alternatively, STR may be a buffer position in the current buffer |
470 in which case a second argument, length LEN, should be supplied." | 470 in which case a second argument, length LEN, should be supplied. |
471 FLOAT, if non-nil, means generate and return a float instead of an integer | |
472 \(use this for numbers that can overflow the Emacs integer)." | |
471 (if (stringp str) | 473 (if (stringp str) |
472 (setq len (length str)) | 474 (setq len (length str)) |
473 (setq str (buffer-substring str (+ str len)))) | 475 (setq str (buffer-substring str (+ str len)))) |
474 (let ((result 0) | 476 (let ((result 0) |
475 (i 0)) | 477 (i 0)) |
476 (while (< i len) | 478 (while (< i len) |
477 (setq i (1+ i) | 479 (setq i (1+ i) |
478 result (+ (ash result 8) (aref str (- len i))))) | 480 result (+ (if float (* result 256.0) (ash result 8)) |
481 (aref str (- len i))))) | |
479 result)) | 482 result)) |
480 | 483 |
481 (defun archive-int-to-mode (mode) | 484 (defun archive-int-to-mode (mode) |
482 "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------." | 485 "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------." |
483 ;; FIXME: merge with tar-grind-file-mode. | 486 ;; FIXME: merge with tar-grind-file-mode. |
1329 (= (char-after p) ?\C-z) | 1332 (= (char-after p) ?\C-z) |
1330 (> (char-after (1+ p)) 0)) | 1333 (> (char-after (1+ p)) 0)) |
1331 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13))) | 1334 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13))) |
1332 (fnlen (or (string-match "\0" namefld) 13)) | 1335 (fnlen (or (string-match "\0" namefld) 13)) |
1333 (efnname (substring namefld 0 fnlen)) | 1336 (efnname (substring namefld 0 fnlen)) |
1334 (csize (archive-l-e (+ p 15) 4)) | 1337 ;; Convert to float to avoid overflow for very large files. |
1338 (csize (archive-l-e (+ p 15) 4 'float)) | |
1335 (moddate (archive-l-e (+ p 19) 2)) | 1339 (moddate (archive-l-e (+ p 19) 2)) |
1336 (modtime (archive-l-e (+ p 21) 2)) | 1340 (modtime (archive-l-e (+ p 21) 2)) |
1337 (ucsize (archive-l-e (+ p 25) 4)) | 1341 (ucsize (archive-l-e (+ p 25) 4 'float)) |
1338 (fiddle (string= efnname (upcase efnname))) | 1342 (fiddle (string= efnname (upcase efnname))) |
1339 (ifnname (if fiddle (downcase efnname) efnname)) | 1343 (ifnname (if fiddle (downcase efnname) efnname)) |
1340 (text (format " %8d %-11s %-8s %s" | 1344 (text (format " %8.0f %-11s %-8s %s" |
1341 ucsize | 1345 ucsize |
1342 (archive-dosdate moddate) | 1346 (archive-dosdate moddate) |
1343 (archive-dostime modtime) | 1347 (archive-dostime modtime) |
1344 ifnname))) | 1348 ifnname))) |
1345 (setq maxlen (max maxlen fnlen) | 1349 (setq maxlen (max maxlen fnlen) |
1357 "\n"))) | 1361 "\n"))) |
1358 (insert "M Length Date Time File\n" | 1362 (insert "M Length Date Time File\n" |
1359 dash) | 1363 dash) |
1360 (archive-summarize-files (nreverse visual)) | 1364 (archive-summarize-files (nreverse visual)) |
1361 (insert dash | 1365 (insert dash |
1362 (format " %8d %d file%s" | 1366 (format " %8.0f %d file%s" |
1363 totalsize | 1367 totalsize |
1364 (length files) | 1368 (length files) |
1365 (if (= 1 (length files)) "" "s")) | 1369 (if (= 1 (length files)) "" "s")) |
1366 "\n")) | 1370 "\n")) |
1367 (apply 'vector (nreverse files)))) | 1371 (apply 'vector (nreverse files)))) |
1391 files | 1395 files |
1392 visual) | 1396 visual) |
1393 (while (progn (goto-char p) ;beginning of a base header. | 1397 (while (progn (goto-char p) ;beginning of a base header. |
1394 (looking-at "\\(.\\|\n\\)\\(.\\|\n\\)-l[hz][0-9ds]-")) | 1398 (looking-at "\\(.\\|\n\\)\\(.\\|\n\\)-l[hz][0-9ds]-")) |
1395 (let* ((hsize (char-after p)) ;size of the base header (level 0 and 1) | 1399 (let* ((hsize (char-after p)) ;size of the base header (level 0 and 1) |
1396 (csize (archive-l-e (+ p 7) 4)) ;size of a compressed file to follow (level 0 and 2), | 1400 ;; Convert to float to avoid overflow for very large files. |
1401 (csize (archive-l-e (+ p 7) 4 'float)) ;size of a compressed file to follow (level 0 and 2), | |
1397 ;size of extended headers + the compressed file to follow (level 1). | 1402 ;size of extended headers + the compressed file to follow (level 1). |
1398 (ucsize (archive-l-e (+ p 11) 4)) ;size of an uncompressed file. | 1403 (ucsize (archive-l-e (+ p 11) 4 'float)) ;size of an uncompressed file. |
1399 (time1 (archive-l-e (+ p 15) 2)) ;date/time (MSDOS format in level 0, 1 headers | 1404 (time1 (archive-l-e (+ p 15) 2)) ;date/time (MSDOS format in level 0, 1 headers |
1400 (time2 (archive-l-e (+ p 17) 2)) ;and UNIX format in level 2 header.) | 1405 (time2 (archive-l-e (+ p 17) 2)) ;and UNIX format in level 2 header.) |
1401 (hdrlvl (char-after (+ p 20))) ;header level | 1406 (hdrlvl (char-after (+ p 20))) ;header level |
1402 thsize ;total header size (base + extensions) | 1407 thsize ;total header size (base + extensions) |
1403 fnlen efnname fiddle ifnname width p2 | 1408 fnlen efnname fiddle ifnname width p2 |
1469 (archive-dosdate time2))) ;level 0 and 1 header in DOS format | 1474 (archive-dosdate time2))) ;level 0 and 1 header in DOS format |
1470 (setq modtime (if (= hdrlvl 2) | 1475 (setq modtime (if (= hdrlvl 2) |
1471 (archive-unixtime time1 time2) | 1476 (archive-unixtime time1 time2) |
1472 (archive-dostime time1))) | 1477 (archive-dostime time1))) |
1473 (setq text (if archive-alternate-display | 1478 (setq text (if archive-alternate-display |
1474 (format " %8d %5S %5S %s" | 1479 (format " %8.0f %5S %5S %s" |
1475 ucsize | 1480 ucsize |
1476 (or uid "?") | 1481 (or uid "?") |
1477 (or gid "?") | 1482 (or gid "?") |
1478 ifnname) | 1483 ifnname) |
1479 (format " %10s %8d %-11s %-8s %s" | 1484 (format " %10s %8.0f %-11s %-8s %s" |
1480 modestr | 1485 modestr |
1481 ucsize | 1486 ucsize |
1482 moddate | 1487 moddate |
1483 modtime | 1488 modtime |
1484 prname))) | 1489 prname))) |
1504 "\n")) | 1509 "\n")) |
1505 (header (if archive-alternate-display | 1510 (header (if archive-alternate-display |
1506 "M Length Uid Gid File\n" | 1511 "M Length Uid Gid File\n" |
1507 "M Filemode Length Date Time File\n")) | 1512 "M Filemode Length Date Time File\n")) |
1508 (sumline (if archive-alternate-display | 1513 (sumline (if archive-alternate-display |
1509 " %8d %d file%s" | 1514 " %8.0f %d file%s" |
1510 " %8d %d file%s"))) | 1515 " %8.0f %d file%s"))) |
1511 (insert header dash) | 1516 (insert header dash) |
1512 (archive-summarize-files (nreverse visual)) | 1517 (archive-summarize-files (nreverse visual)) |
1513 (insert dash | 1518 (insert dash |
1514 (format sumline | 1519 (format sumline |
1515 totalsize | 1520 totalsize |
1601 (while (string= "PK\001\002" (buffer-substring p (+ p 4))) | 1606 (while (string= "PK\001\002" (buffer-substring p (+ p 4))) |
1602 (let* ((creator (char-after (+ p 5))) | 1607 (let* ((creator (char-after (+ p 5))) |
1603 ;; (method (archive-l-e (+ p 10) 2)) | 1608 ;; (method (archive-l-e (+ p 10) 2)) |
1604 (modtime (archive-l-e (+ p 12) 2)) | 1609 (modtime (archive-l-e (+ p 12) 2)) |
1605 (moddate (archive-l-e (+ p 14) 2)) | 1610 (moddate (archive-l-e (+ p 14) 2)) |
1606 (ucsize (archive-l-e (+ p 24) 4)) | 1611 ;; Convert to float to avoid overflow for very large files. |
1612 (ucsize (archive-l-e (+ p 24) 4 'float)) | |
1607 (fnlen (archive-l-e (+ p 28) 2)) | 1613 (fnlen (archive-l-e (+ p 28) 2)) |
1608 (exlen (archive-l-e (+ p 30) 2)) | 1614 (exlen (archive-l-e (+ p 30) 2)) |
1609 (fclen (archive-l-e (+ p 32) 2)) | 1615 (fclen (archive-l-e (+ p 32) 2)) |
1610 (lheader (archive-l-e (+ p 42) 4)) | 1616 (lheader (archive-l-e (+ p 42) 4)) |
1611 (efnname (let ((str (buffer-substring (+ p 46) (+ p 46 fnlen)))) | 1617 (efnname (let ((str (buffer-substring (+ p 46) (+ p 46 fnlen)))) |
1627 (fiddle (and archive-zip-case-fiddle | 1633 (fiddle (and archive-zip-case-fiddle |
1628 (not (not (memq creator '(0 2 4 5 9)))) | 1634 (not (not (memq creator '(0 2 4 5 9)))) |
1629 (string= (upcase efnname) efnname))) | 1635 (string= (upcase efnname) efnname))) |
1630 (ifnname (if fiddle (downcase efnname) efnname)) | 1636 (ifnname (if fiddle (downcase efnname) efnname)) |
1631 (width (string-width ifnname)) | 1637 (width (string-width ifnname)) |
1632 (text (format " %10s %8d %-11s %-8s %s" | 1638 (text (format " %10s %8.0f %-11s %-8s %s" |
1633 modestr | 1639 modestr |
1634 ucsize | 1640 ucsize |
1635 (archive-dosdate moddate) | 1641 (archive-dosdate moddate) |
1636 (archive-dostime modtime) | 1642 (archive-dostime modtime) |
1637 ifnname))) | 1643 ifnname))) |
1653 "\n"))) | 1659 "\n"))) |
1654 (insert "M Filemode Length Date Time File\n" | 1660 (insert "M Filemode Length Date Time File\n" |
1655 dash) | 1661 dash) |
1656 (archive-summarize-files (nreverse visual)) | 1662 (archive-summarize-files (nreverse visual)) |
1657 (insert dash | 1663 (insert dash |
1658 (format " %8d %d file%s" | 1664 (format " %8.0f %d file%s" |
1659 totalsize | 1665 totalsize |
1660 (length files) | 1666 (length files) |
1661 (if (= 1 (length files)) "" "s")) | 1667 (if (= 1 (length files)) "" "s")) |
1662 "\n")) | 1668 "\n")) |
1663 (apply 'vector (nreverse files)))) | 1669 (apply 'vector (nreverse files)))) |
1707 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4))) | 1713 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4))) |
1708 (> (archive-l-e (+ p 6) 4) 0)) | 1714 (> (archive-l-e (+ p 6) 4) 0)) |
1709 (let* ((next (1+ (archive-l-e (+ p 6) 4))) | 1715 (let* ((next (1+ (archive-l-e (+ p 6) 4))) |
1710 (moddate (archive-l-e (+ p 14) 2)) | 1716 (moddate (archive-l-e (+ p 14) 2)) |
1711 (modtime (archive-l-e (+ p 16) 2)) | 1717 (modtime (archive-l-e (+ p 16) 2)) |
1712 (ucsize (archive-l-e (+ p 20) 4)) | 1718 ;; Convert to float to avoid overflow for very large files. |
1719 (ucsize (archive-l-e (+ p 20) 4 'float)) | |
1713 (namefld (buffer-substring (+ p 38) (+ p 38 13))) | 1720 (namefld (buffer-substring (+ p 38) (+ p 38 13))) |
1714 (dirtype (char-after (+ p 4))) | 1721 (dirtype (char-after (+ p 4))) |
1715 (lfnlen (if (= dirtype 2) (char-after (+ p 56)) 0)) | 1722 (lfnlen (if (= dirtype 2) (char-after (+ p 56)) 0)) |
1716 (ldirlen (if (= dirtype 2) (char-after (+ p 57)) 0)) | 1723 (ldirlen (if (= dirtype 2) (char-after (+ p 57)) 0)) |
1717 (fnlen (or (string-match "\0" namefld) 13)) | 1724 (fnlen (or (string-match "\0" namefld) 13)) |
1731 (decode-coding-string str file-name-coding-system) | 1738 (decode-coding-string str file-name-coding-system) |
1732 (string-as-multibyte str)))) | 1739 (string-as-multibyte str)))) |
1733 (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname)))) | 1740 (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname)))) |
1734 (ifnname (if fiddle (downcase efnname) efnname)) | 1741 (ifnname (if fiddle (downcase efnname) efnname)) |
1735 (width (string-width ifnname)) | 1742 (width (string-width ifnname)) |
1736 (text (format " %8d %-11s %-8s %s" | 1743 (text (format " %8.0f %-11s %-8s %s" |
1737 ucsize | 1744 ucsize |
1738 (archive-dosdate moddate) | 1745 (archive-dosdate moddate) |
1739 (archive-dostime modtime) | 1746 (archive-dostime modtime) |
1740 ifnname))) | 1747 ifnname))) |
1741 (setq maxlen (max maxlen width) | 1748 (setq maxlen (max maxlen width) |
1753 "\n"))) | 1760 "\n"))) |
1754 (insert "M Length Date Time File\n" | 1761 (insert "M Length Date Time File\n" |
1755 dash) | 1762 dash) |
1756 (archive-summarize-files (nreverse visual)) | 1763 (archive-summarize-files (nreverse visual)) |
1757 (insert dash | 1764 (insert dash |
1758 (format " %8d %d file%s" | 1765 (format " %8.0f %d file%s" |
1759 totalsize | 1766 totalsize |
1760 (length files) | 1767 (length files) |
1761 (if (= 1 (length files)) "" "s")) | 1768 (if (= 1 (length files)) "" "s")) |
1762 "\n")) | 1769 "\n")) |
1763 (apply 'vector (nreverse files)))) | 1770 (apply 'vector (nreverse files)))) |