From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.emacs.devel Subject: Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes Date: Thu, 19 Apr 2007 11:41:39 +1000 Message-ID: <87mz1516p8.fsf@zip.com.au> References: <87zm5etm0r.fsf@zip.com.au> <87tzvitz4z.fsf@zip.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1176946930 25817 80.91.229.12 (19 Apr 2007 01:42:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 19 Apr 2007 01:42:10 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 19 03:42:03 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HeLes-00010H-Uf for ged-emacs-devel@m.gmane.org; Thu, 19 Apr 2007 03:42:03 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HeLjm-0007cM-0x for ged-emacs-devel@m.gmane.org; Wed, 18 Apr 2007 21:47:06 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HeLjg-0007az-Ds for emacs-devel@gnu.org; Wed, 18 Apr 2007 21:47:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HeLje-0007Zj-Fj for emacs-devel@gnu.org; Wed, 18 Apr 2007 21:46:59 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HeLje-0007Zg-4M for emacs-devel@gnu.org; Wed, 18 Apr 2007 21:46:58 -0400 Original-Received: from mailout1-8.pacific.net.au ([61.8.2.215] helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HeLej-0000eR-LY for emacs-devel@gnu.org; Wed, 18 Apr 2007 21:41:54 -0400 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.2.162]) by mailout1.pacific.net.au (Postfix) with ESMTP id 9445B5A0635 for ; Thu, 19 Apr 2007 11:41:45 +1000 (EST) Original-Received: from localhost (ppp26DA.dyn.pacific.net.au [61.8.38.218]) by mailproxy1.pacific.net.au (Postfix) with ESMTP id 27FE68C0C for ; Thu, 19 Apr 2007 11:41:44 +1000 (EST) Original-Received: from gg by localhost with local (Exim 4.63) (envelope-from ) id 1HeLeV-0002Ig-5U for emacs-devel@gnu.org; Thu, 19 Apr 2007 11:41:39 +1000 In-Reply-To: <87tzvitz4z.fsf@zip.com.au> (Kevin Ryde's message of "Sun, 15 Apr 2007 07:38:36 +1000") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:69605 Archived-At: --=-=-= At Richard's request this is my lzh exe bits in the form of a patch for arc-mode.el. archive-exe-p is a combination content and filename test, because of course not all .exes are archives, and I don't think the content test alone would be tight enough. There's been several other self-extracting archives formats in the past (I can remember zip and pak), but lzh is the only one I've encountered for a long time. A sample to try it on (as per previous message), http://kanex.or.jp/history/BRO07.exe --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=arc-mode.el.lzh-exe.diff Index: arc-mode.el =================================================================== RCS file: /sources/emacs/emacs/lisp/arc-mode.el,v retrieving revision 1.80 diff -u -c -r1.80 arc-mode.el cvs diff: conflicting specifications of output style *** arc-mode.el 16 Apr 2007 19:40:14 -0000 1.80 --- arc-mode.el 19 Apr 2007 01:27:40 -0000 *************** *** 700,705 **** --- 700,709 ---- (string-match "\\.[aA][rR][cC]$" (or buffer-file-name (buffer-name)))) 'arc) + ;; This pattern modelled on the BSD/GNU+Linux `file' command. + ;; Have seen capital "LHA's", and file has lower case "LHa's" too. + ;; Note this regexp is also in archive-exe-p. + ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe) (t (error "Buffer format not recognized"))))) ;; ------------------------------------------------------------------------- (defun archive-summarize (&optional shut-up) *************** *** 1398,1405 **** ;; ------------------------------------------------------------------------- ;; Section: Lzh Archives ! (defun archive-lzh-summarize () ! (let ((p 1) (totalsize 0) (maxlen 8) files --- 1402,1409 ---- ;; ------------------------------------------------------------------------- ;; Section: Lzh Archives ! (defun archive-lzh-summarize (&optional start) ! (let ((p (or start 1)) ;; 1 for .lzh, something further on for .exe (totalsize 0) (maxlen 8) files *************** *** 1621,1626 **** --- 1625,1658 ---- ;; This should work even though newmode will be dynamically accessed. (lambda (old) (archive-calc-mode old newmode t)) files "a unix-style mode" 8)) + + ;; ------------------------------------------------------------------------- + ;; Section: Lzh Self-Extracting .exe Archives + ;; + ;; No support for modifying these files. It looks like the lha for unix + ;; program (as of version 1.14i) can't create or retain the DOS exe part. + ;; If you do an "lha a" on a .exe for instance it renames and writes to a + ;; plain .lzh. + + (defun archive-lzh-exe-summarize () + "Summarize the contents of an LZH self-extracting exe, for `archive-mode'." + + ;; Skip the initial executable code part and apply archive-lzh-summarize + ;; to the archive part proper. The "-lh5-" etc regexp here for the start + ;; is the same as in archive-find-type. + ;; + ;; The lha program (version 1.14i) does this in skip_msdos_sfx1_code() by + ;; a similar scan. It looks for "..-l..-" plus for level 0 or 1 a test of + ;; the header checksum, or level 2 a test of the "attribute" and size. + ;; + (re-search-forward "..-l[hz][0-9ds]-" nil) + (archive-lzh-summarize (match-beginning 0))) + + ;; `archive-lzh-extract' runs "lha pq", and that works for .exe as well as + ;; .lzh files + (defalias 'archive-lzh-exe-extract 'archive-lzh-extract + "Extract a member from an LZH self-extracting exe, for `archive-mode'.") + ;; ------------------------------------------------------------------------- ;; Section: Zip Archives --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=files.el.lzh-exe.diff Index: files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.893 diff -u -c -r1.893 files.el cvs diff: conflicting specifications of output style *** files.el 13 Apr 2007 15:09:32 -0000 1.893 --- files.el 19 Apr 2007 01:29:06 -0000 *************** *** 2138,2144 **** (concat "[ \t\n]*<" comment-re "*!DOCTYPE ")) . sgml-mode) ("%!PS" . ps-mode) ! ("# xmcd " . conf-unix-mode)) "Alist of buffer beginnings vs. corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (MATCH-FUNCTION . FUNCTION). After visiting a file, if REGEXP matches the text at the beginning of the --- 2138,2145 ---- (concat "[ \t\n]*<" comment-re "*!DOCTYPE ")) . sgml-mode) ("%!PS" . ps-mode) ! ("# xmcd " . conf-unix-mode) ! (archive-exe-p . archive-mode)) "Alist of buffer beginnings vs. corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (MATCH-FUNCTION . FUNCTION). After visiting a file, if REGEXP matches the text at the beginning of the *************** *** 2150,2155 **** --- 2151,2167 ---- \"allow `auto-mode-alist' to decide for these files.\")") (put 'magic-mode-alist 'risky-local-variable t) + ;; this is here to avoid loading the whole arc-mode.el from magic-mode-alist + (defun archive-exe-p () + "Return true if the current buffer is a self-extracting .exe archive. + This is designed for use as a test in `magic-mode-alist'." + (let (case-fold-search) + (and (string-match "\\.\\(exe\\|EXE\\)\\'" (buffer-name)) + (save-excursion + (goto-char (point-min)) + ;; same regexp as in archive-find-type for `lzh-exe' + (looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX "))))) + (defvar magic-mode-regexp-match-limit 4000 "Upper limit on `magic-mode-alist' regexp matches.") --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=mule.el.lzh-exe.diff Index: mule.el =================================================================== RCS file: /sources/emacs/emacs/lisp/international/mule.el,v retrieving revision 1.254 diff -u -c -r1.254 mule.el cvs diff: conflicting specifications of output style *** mule.el 4 Apr 2007 15:34:59 -0000 1.254 --- mule.el 19 Apr 2007 01:29:58 -0000 *************** *** 1582,1587 **** --- 1582,1591 ---- '(("\\.\\(arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\)\\'" . no-conversion) ("\\.\\(ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\)\\'" . no-conversion) ("\\.\\(sx[dmicw]\\|odt\\|tar\\|tgz\\)\\'" . no-conversion) + ;; .exe and .EXE no-conversion to support archive-mode looking at DOS + ;; self-extracting exe archives from magic-mode-alist; and in any case + ;; an executable is just bytes + ("\\.\\(exe\\|EXE\\)\\'" . no-conversion) ("\\.\\(gz\\|Z\\|bz\\|bz2\\|gpg\\)\\'" . no-conversion) ("\\.\\(jpe?g\\|png\\|gif\\|tiff?\\|p[bpgn]m\\)\\'" . no-conversion) ("/#[^/]+#\\'" . emacs-mule)) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--