aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-03-06 22:11:12 +0000
committerStefan Monnier2008-03-06 22:11:12 +0000
commit239bf18bf24e8e8afee41154d1f73345eab0cc3c (patch)
tree3d5b425ffae400836a346a9fa314045ef60197d4
parentb0a08954d512d8e70fdf3b49b7db281a98221c0a (diff)
downloademacs-239bf18bf24e8e8afee41154d1f73345eab0cc3c.tar.gz
emacs-239bf18bf24e8e8afee41154d1f73345eab0cc3c.zip
(archive-ar-file-header-re): New const.
(archive-ar-summarize, archive-ar-extract): New funs. (archive-find-type): Recognize ar archives.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/arc-mode.el122
2 files changed, 127 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b415c11303b..5a4c4e0a86f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12008-03-06 Stefan Monnier <monnier@iro.umontreal.ca> 12008-03-06 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * arc-mode.el (archive-ar-file-header-re): New const.
4 (archive-ar-summarize, archive-ar-extract): New funs.
5 (archive-find-type): Recognize ar archives.
6
3 * vc-bzr.el (vc-bzr-resolve-when-done, vc-bzr-find-file-hook): 7 * vc-bzr.el (vc-bzr-resolve-when-done, vc-bzr-find-file-hook):
4 New functions. 8 New functions.
5 9
@@ -7,8 +11,8 @@
7 11
82008-03-06 Lennart Borgman <lennart.borgman@gmail.com> (tiny change) 122008-03-06 Lennart Borgman <lennart.borgman@gmail.com> (tiny change)
9 13
10 * emacs-lisp/lisp-mode.el (emacs-lisp-mode-map): Bugfix: replaced 14 * emacs-lisp/lisp-mode.el (emacs-lisp-mode-map):
11 :enable (mark-active) with :enable mark-active. 15 Replace :enable (mark-active) with :enable mark-active.
12 16
132008-03-06 Juanma Barranquero <lekktu@gmail.com> 172008-03-06 Juanma Barranquero <lekktu@gmail.com>
14 18
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index 3e5cef9fec9..1bb4d2d477b 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -728,6 +728,7 @@ archive.
728 ;; Note this regexp is also in archive-exe-p. 728 ;; Note this regexp is also in archive-exe-p.
729 ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe) 729 ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe)
730 ((looking-at "Rar!") 'rar) 730 ((looking-at "Rar!") 'rar)
731 ((looking-at "!<arch>\n") 'ar)
731 ((and (looking-at "MZ") 732 ((and (looking-at "MZ")
732 (re-search-forward "Rar!" (+ (point) 100000) t)) 733 (re-search-forward "Rar!" (+ (point) 100000) t))
733 'rar-exe) 734 'rar-exe)
@@ -1971,10 +1972,129 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1971 (delete-file tmpfile)))) 1972 (delete-file tmpfile))))
1972 1973
1973 1974
1975;;; Section `ar' archives.
1976
1977;; TODO: we currently only handle the basic format of ar archives,
1978;; not the GNU nor the BSD extensions. As it turns out, this is sufficient
1979;; for .deb packages.
1980
1981(autoload 'tar-grind-file-mode "tar-mode")
1982
1983(defconst archive-ar-file-header-re
1984 "\\(.\\{16\\}\\)\\([ 0-9]\\{12\\}\\)\\([ 0-9]\\{6\\}\\)\\([ 0-9]\\{6\\}\\)\\([ 0-7]\\{8\\}\\)\\([ 0-9]\\{10\\}\\)`\n")
1985
1986(defun archive-ar-summarize ()
1987 ;; File is used internally for `archive-rar-exe-summarize'.
1988 (let* ((maxname 10)
1989 (maxtime 16)
1990 (maxuser 5)
1991 (maxgroup 5)
1992 (maxmode 8)
1993 (maxsize 5)
1994 (files ()))
1995 (goto-char (point-min))
1996 (search-forward "!<arch>\n")
1997 (while (looking-at archive-ar-file-header-re)
1998 (let ((name (match-string 1))
1999 ;; Emacs will automatically use float here because those
2000 ;; timestamps don't fit in our ints.
2001 (time (string-to-number (match-string 2)))
2002 (user (match-string 3))
2003 (group (match-string 4))
2004 (mode (string-to-number (match-string 5) 8))
2005 (size (string-to-number (match-string 6))))
2006 ;; Move to the beginning of the data.
2007 (goto-char (match-end 0))
2008 (cond
2009 ((equal name "// ")
2010 ;; FIXME: todo
2011 nil)
2012 ((equal name "/ ")
2013 ;; FIXME: todo
2014 nil)
2015 (t
2016 (setq time
2017 (format-time-string
2018 "%Y-%m-%d %H:%M"
2019 (let ((high (truncate (/ time 65536))))
2020 (list high (truncate (- time (* 65536.0 high)))))))
2021 (setq name (substring name 0 (string-match "/? *\\'" name)))
2022 (setq user (substring user 0 (string-match " +\\'" user)))
2023 (setq group (substring group 0 (string-match " +\\'" group)))
2024 (setq mode (tar-grind-file-mode mode))
2025 ;; Move to the end of the data.
2026 (forward-char size) (if (eq ?\n (char-after)) (forward-char 1))
2027 (setq size (number-to-string size))
2028 (if (> (length name) maxname) (setq maxname (length name)))
2029 (if (> (length time) maxtime) (setq maxtime (length time)))
2030 (if (> (length user) maxuser) (setq maxuser (length user)))
2031 (if (> (length group) maxgroup) (setq maxgroup (length group)))
2032 (if (> (length mode) maxmode) (setq maxmode (length mode)))
2033 (if (> (length size) maxsize) (setq maxsize (length size)))
2034 (push (vector name name nil mode
2035 time user group size)
2036 files)))))
2037 (setq files (nreverse files))
2038 (goto-char (point-min))
2039 (let* ((format (format "%%%ds %%%ds/%%-%ds %%%ds %%%ds %%s"
2040 maxmode maxuser maxgroup maxsize maxtime))
2041 (sep (format format (make-string maxmode ?-)
2042 (make-string maxuser ?-)
2043 (make-string maxgroup ?-)
2044 (make-string maxsize ?-)
2045 (make-string maxtime ?-) ""))
2046 (column (length sep)))
2047 (insert (format format " Mode " "User" "Group" " Size "
2048 " Date " "Filename")
2049 "\n")
2050 (insert sep (make-string maxname ?-) "\n")
2051 (archive-summarize-files (mapcar (lambda (desc)
2052 (let ((text
2053 (format format
2054 (aref desc 3)
2055 (aref desc 5)
2056 (aref desc 6)
2057 (aref desc 7)
2058 (aref desc 4)
2059 (aref desc 1))))
2060 (vector text
2061 column
2062 (length text))))
2063 files))
2064 (insert sep (make-string maxname ?-) "\n")
2065 (apply 'vector files))))
2066
2067(defun archive-ar-extract (archive name)
2068 (let ((destbuf (current-buffer))
2069 (archivebuf (find-file-noselect archive))
2070 (from nil) size)
2071 (with-current-buffer archivebuf
2072 (save-restriction
2073 ;; We may be in archive-mode or not, so either with or without
2074 ;; narrowing and with or without a prepended summary.
2075 (widen)
2076 (search-forward "!<arch>\n")
2077 (while (and (not from) (looking-at archive-ar-file-header-re))
2078 (let ((this (match-string 1)))
2079 (setq size (string-to-number (match-string 6)))
2080 (goto-char (match-end 0))
2081 (setq this (substring this 0 (string-match "/? *\\'" this)))
2082 (if (equal name this)
2083 (setq from (point))
2084 ;; Move to the end of the data.
2085 (forward-char size) (if (eq ?\n (char-after)) (forward-char 1)))))
2086 (when from
2087 (set-buffer-multibyte nil)
2088 (with-current-buffer destbuf
2089 ;; Do it within the `widen'.
2090 (insert-buffer-substring archivebuf from (+ from size)))
2091 (set-buffer-multibyte t)
2092 ;; Inform the caller that the call succeeded.
2093 t)))))
2094
1974;; ------------------------------------------------------------------------- 2095;; -------------------------------------------------------------------------
1975;; This line was a mistake; it is kept now for compatibility. 2096;; This line was a mistake; it is kept now for compatibility.
1976;; rms 15 Oct 98 2097;; rms 15 Oct 98
1977
1978(provide 'archive-mode) 2098(provide 'archive-mode)
1979 2099
1980(provide 'arc-mode) 2100(provide 'arc-mode)