Mercurial > emacs
comparison lisp/arc-mode.el @ 86928:29dfee94a77f
(archive-find-type): Add recognition of rar-exe format.
(archive-rar-summarize): Allow the file name to be passed as argument.
Remove unused vars `header' and `footer'.
(archive-rar-exe-summarize, archive-rar-exe-extract): New functions.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 02 Dec 2007 02:05:48 +0000 |
parents | c85ffd1fab82 |
children | 107ccd98fa12 53108e6cea98 |
comparison
equal
deleted
inserted
replaced
86927:d4651506a112 | 86928:29dfee94a77f |
---|---|
703 ;; This pattern modelled on the BSD/GNU+Linux `file' command. | 703 ;; This pattern modelled on the BSD/GNU+Linux `file' command. |
704 ;; Have seen capital "LHA's", and file has lower case "LHa's" too. | 704 ;; Have seen capital "LHA's", and file has lower case "LHa's" too. |
705 ;; Note this regexp is also in archive-exe-p. | 705 ;; Note this regexp is also in archive-exe-p. |
706 ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe) | 706 ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe) |
707 ((looking-at "Rar!") 'rar) | 707 ((looking-at "Rar!") 'rar) |
708 ((and (looking-at "MZ") | |
709 (re-search-forward "Rar!" (+ (point) 100000) t)) | |
710 'rar-exe) | |
708 (t (error "Buffer format not recognized"))))) | 711 (t (error "Buffer format not recognized"))))) |
709 ;; ------------------------------------------------------------------------- | 712 ;; ------------------------------------------------------------------------- |
710 | 713 |
711 (defun archive-desummarize () | 714 (defun archive-desummarize () |
712 (let ((inhibit-read-only t) | 715 (let ((inhibit-read-only t) |
1842 (archive-extract-by-stdout archive name archive-zoo-extract)) | 1845 (archive-extract-by-stdout archive name archive-zoo-extract)) |
1843 | 1846 |
1844 ;; ------------------------------------------------------------------------- | 1847 ;; ------------------------------------------------------------------------- |
1845 ;;; Section: Rar Archives | 1848 ;;; Section: Rar Archives |
1846 | 1849 |
1847 (defun archive-rar-summarize () | 1850 (defun archive-rar-summarize (&optional file) |
1848 (let* ((file buffer-file-name) | 1851 ;; File is used internally for `archive-rar-exe-summarize'. |
1849 (copy (file-local-copy file)) | 1852 (unless file (setq file buffer-file-name)) |
1850 header footer | 1853 (let* ((copy (file-local-copy file)) |
1851 (maxname 10) | 1854 (maxname 10) |
1852 (maxsize 5) | 1855 (maxsize 5) |
1853 (files ())) | 1856 (files ())) |
1854 (with-temp-buffer | 1857 (with-temp-buffer |
1855 (call-process "unrar-free" nil t nil "--list" (or file copy)) | 1858 (call-process "unrar-free" nil t nil "--list" (or file copy)) |
1856 (if copy (delete-file copy)) | 1859 (if copy (delete-file copy)) |
1857 (goto-char (point-min)) | 1860 (goto-char (point-min)) |
1858 (re-search-forward "^-+\n") | 1861 (re-search-forward "^-+\n") |
1859 (setq header | |
1860 (buffer-substring (save-excursion (re-search-backward "^[^ ]")) | |
1861 (point))) | |
1862 (while (looking-at (concat " \\(.*\\)\n" ;Name. | 1862 (while (looking-at (concat " \\(.*\\)\n" ;Name. |
1863 ;; Size ; Packed. | 1863 ;; Size ; Packed. |
1864 " +\\([0-9]+\\) +[0-9]+" | 1864 " +\\([0-9]+\\) +[0-9]+" |
1865 ;; Ratio ; Date' | 1865 ;; Ratio ; Date' |
1866 " +\\([0-9%]+\\) +\\([-0-9]+\\)" | 1866 " +\\([0-9%]+\\) +\\([-0-9]+\\)" |
1876 (push (vector name name nil nil | 1876 (push (vector name name nil nil |
1877 ;; Size, Ratio. | 1877 ;; Size, Ratio. |
1878 size (match-string 3) | 1878 size (match-string 3) |
1879 ;; Date, Time. | 1879 ;; Date, Time. |
1880 (match-string 4) (match-string 5)) | 1880 (match-string 4) (match-string 5)) |
1881 files))) | 1881 files)))) |
1882 (setq footer (buffer-substring (point) (point-max)))) | |
1883 (setq files (nreverse files)) | 1882 (setq files (nreverse files)) |
1884 (goto-char (point-min)) | 1883 (goto-char (point-min)) |
1885 (let* ((format (format " %%s %%s %%%ds %%5s %%s" maxsize)) | 1884 (let* ((format (format " %%s %%s %%%ds %%5s %%s" maxsize)) |
1886 (sep (format format "--------" "-----" (make-string maxsize ?-) | 1885 (sep (format format "--------" "-----" (make-string maxsize ?-) |
1887 "-----" "")) | 1886 "-----" "")) |
1919 (while (file-name-directory name) | 1918 (while (file-name-directory name) |
1920 (setq name (directory-file-name (file-name-directory name))) | 1919 (setq name (directory-file-name (file-name-directory name))) |
1921 (delete-directory (expand-file-name name dest))) | 1920 (delete-directory (expand-file-name name dest))) |
1922 (delete-directory dest))))) | 1921 (delete-directory dest))))) |
1923 | 1922 |
1923 ;;; Section: Rar self-extracting .exe archives. | |
1924 | |
1925 (defun archive-rar-exe-summarize () | |
1926 (let ((tmpfile (make-temp-file "rarexe"))) | |
1927 (unwind-protect | |
1928 (progn | |
1929 (goto-char (point-min)) | |
1930 (re-search-forward "Rar!") | |
1931 (write-region (match-beginning 0) (point-max) tmpfile) | |
1932 (archive-rar-summarize tmpfile)) | |
1933 (delete-file tmpfile)))) | |
1934 | |
1935 (defun archive-rar-exe-extract (archive name) | |
1936 (let* ((tmpfile (make-temp-file "rarexe")) | |
1937 (buf (find-buffer-visiting archive)) | |
1938 (tmpbuf (unless buf (generate-new-buffer " *rar-exe*")))) | |
1939 (unwind-protect | |
1940 (progn | |
1941 (with-current-buffer (or buf tmpbuf) | |
1942 (save-excursion | |
1943 (save-restriction | |
1944 (if buf | |
1945 ;; point-max unwidened is assumed to be the end of the | |
1946 ;; summary text and the beginning of the actual file data. | |
1947 (progn (goto-char (point-max)) (widen)) | |
1948 (insert-file-contents-literally archive) | |
1949 (goto-char (point-min))) | |
1950 (re-search-forward "Rar!") | |
1951 (write-region (match-beginning 0) (point-max) tmpfile)))) | |
1952 (archive-rar-extract tmpfile name)) | |
1953 (if tmpbuf (kill-buffer tmpbuf)) | |
1954 (delete-file tmpfile)))) | |
1955 | |
1956 | |
1924 ;; ------------------------------------------------------------------------- | 1957 ;; ------------------------------------------------------------------------- |
1925 ;; This line was a mistake; it is kept now for compatibility. | 1958 ;; This line was a mistake; it is kept now for compatibility. |
1926 ;; rms 15 Oct 98 | 1959 ;; rms 15 Oct 98 |
1960 | |
1927 (provide 'archive-mode) | 1961 (provide 'archive-mode) |
1928 | 1962 |
1929 (provide 'arc-mode) | 1963 (provide 'arc-mode) |
1930 | 1964 |
1931 ;; arch-tag: e5966a01-35ec-4f27-8095-a043a79b457b | 1965 ;; arch-tag: e5966a01-35ec-4f27-8095-a043a79b457b |