all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: emacs-devel@gnu.org
Subject: Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
Date: Thu, 19 Apr 2007 11:41:39 +1000	[thread overview]
Message-ID: <87mz1516p8.fsf@zip.com.au> (raw)
In-Reply-To: <87tzvitz4z.fsf@zip.com.au> (Kevin Ryde's message of "Sun, 15 Apr 2007 07:38:36 +1000")

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: arc-mode.el.lzh-exe.diff --]
[-- Type: text/x-diff, Size: 3088 bytes --]

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
  

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: files.el.lzh-exe.diff --]
[-- Type: text/x-diff, Size: 1932 bytes --]

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.")
  

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: mule.el.lzh-exe.diff --]
[-- Type: text/x-diff, Size: 1027 bytes --]

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))

[-- Attachment #5: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

       reply	other threads:[~2007-04-19  1:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87zm5etm0r.fsf@zip.com.au>
     [not found] ` <E1HcAoA-0001sC-G4@fencepost.gnu.org>
     [not found]   ` <87tzvitz4z.fsf@zip.com.au>
2007-04-19  1:41     ` Kevin Ryde [this message]
2007-04-19  2:01       ` arc-lzh-exe.el -- archive-mode on lzh self-extracting exes Kevin Ryde
2007-04-19 23:17       ` Richard Stallman
2007-04-19 23:58         ` Chong Yidong
2007-04-20  1:05           ` Stefan Monnier
2007-04-20  1:42           ` Kevin Ryde
2007-04-20 10:40             ` Eli Zaretskii
2007-04-20 21:53           ` Richard Stallman
2007-04-20 22:44             ` Chong Yidong
2007-04-21  9:38             ` Eli Zaretskii
2007-04-21 18:25               ` Richard Stallman
2007-04-21 19:22                 ` Chong Yidong
2007-04-22 23:46                 ` Kevin Ryde
2007-04-23 14:25                   ` Chong Yidong
2007-04-20 10:37         ` Eli Zaretskii
2007-04-20 10:44           ` David Kastrup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mz1516p8.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.