unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
       [not found]   ` <87tzvitz4z.fsf@zip.com.au>
@ 2007-04-19  1:41     ` Kevin Ryde
  2007-04-19  2:01       ` Kevin Ryde
  2007-04-19 23:17       ` Richard Stallman
  0 siblings, 2 replies; 16+ messages in thread
From: Kevin Ryde @ 2007-04-19  1:41 UTC (permalink / raw)
  To: emacs-devel

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-19  1:41     ` arc-lzh-exe.el -- archive-mode on lzh self-extracting exes Kevin Ryde
@ 2007-04-19  2:01       ` Kevin Ryde
  2007-04-19 23:17       ` Richard Stallman
  1 sibling, 0 replies; 16+ messages in thread
From: Kevin Ryde @ 2007-04-19  2:01 UTC (permalink / raw)
  To: emacs-devel

Oh, forgot:

2007-04-19  Kevin Ryde  <user42@zip.com.au>

	* arc-mode.el (archive-find-type): lzh-exe for lzh self-extracting exe.
	(archive-lzh-summarize): Add optional start arg for where to start
	looking at the archive.
	(archive-lzh-exe-summarize, archive-lzh-exe-extract): New functions.

	* files.el (magic-mode-alist): Add archive-exe-p to select
	archive-mode.
	* international/mule.el (auto-coding-alist): no-conversion for .exe
	and .EXE.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-19  1:41     ` arc-lzh-exe.el -- archive-mode on lzh self-extracting exes Kevin Ryde
  2007-04-19  2:01       ` Kevin Ryde
@ 2007-04-19 23:17       ` Richard Stallman
  2007-04-19 23:58         ` Chong Yidong
  2007-04-20 10:37         ` Eli Zaretskii
  1 sibling, 2 replies; 16+ messages in thread
From: Richard Stallman @ 2007-04-19 23:17 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: emacs-devel

This change looks totally safe, so would someone please install it?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-19 23:17       ` Richard Stallman
@ 2007-04-19 23:58         ` Chong Yidong
  2007-04-20  1:05           ` Stefan Monnier
                             ` (2 more replies)
  2007-04-20 10:37         ` Eli Zaretskii
  1 sibling, 3 replies; 16+ messages in thread
From: Chong Yidong @ 2007-04-19 23:58 UTC (permalink / raw)
  To: rms; +Cc: Kevin Ryde, emacs-devel

Richard Stallman <rms@gnu.org> writes:

> This change looks totally safe, so would someone please install it?

I installed the arc-mode.el and mule.el changes.  Could we put off the
changes to auto-mode-alist till after the release?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-19 23:58         ` Chong Yidong
@ 2007-04-20  1:05           ` Stefan Monnier
  2007-04-20  1:42           ` Kevin Ryde
  2007-04-20 21:53           ` Richard Stallman
  2 siblings, 0 replies; 16+ messages in thread
From: Stefan Monnier @ 2007-04-20  1:05 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Kevin Ryde, rms, emacs-devel

> Could we put off the changes to auto-mode-alist till after the release?

Yes, please,


        Stefan

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  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
  2 siblings, 1 reply; 16+ messages in thread
From: Kevin Ryde @ 2007-04-20  1:42 UTC (permalink / raw)
  To: Chong Yidong; +Cc: rms, emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:
>
> Could we put off the changes to auto-mode-alist till after the
> release?

You'll notice .exe hasn't had any sort of handler before, so this is
purely an addition.  (Or that's the intention, if anyone wants to
critique archive-exe-p.)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-19 23:17       ` Richard Stallman
  2007-04-19 23:58         ` Chong Yidong
@ 2007-04-20 10:37         ` Eli Zaretskii
  2007-04-20 10:44           ` David Kastrup
  1 sibling, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2007-04-20 10:37 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

> From: Richard Stallman <rms@gnu.org>
> Date: Thu, 19 Apr 2007 19:17:37 -0400
> Cc: emacs-devel@gnu.org
> 
> This change looks totally safe, so would someone please install it?

Why are we making changes, no matter how safe they look, during the
pretest version that is finally thought to be ready for a release?
Are we forcibly looking for trouble?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-20  1:42           ` Kevin Ryde
@ 2007-04-20 10:40             ` Eli Zaretskii
  0 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2007-04-20 10:40 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: cyd, rms, emacs-devel

> From: Kevin Ryde <user42@zip.com.au>
> Date: Fri, 20 Apr 2007 11:42:15 +1000
> Cc: rms@gnu.org, emacs-devel@gnu.org
> 
> Chong Yidong <cyd@stupidchicken.com> writes:
> >
> > Could we put off the changes to auto-mode-alist till after the
> > release?
> 
> You'll notice .exe hasn't had any sort of handler before, so this is
> purely an addition.

And why do you think additions cannot cause trouble?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-20 10:37         ` Eli Zaretskii
@ 2007-04-20 10:44           ` David Kastrup
  0 siblings, 0 replies; 16+ messages in thread
From: David Kastrup @ 2007-04-20 10:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Richard Stallman <rms@gnu.org>
>> Date: Thu, 19 Apr 2007 19:17:37 -0400
>> Cc: emacs-devel@gnu.org
>> 
>> This change looks totally safe, so would someone please install it?
>
> Why are we making changes, no matter how safe they look, during the
> pretest version that is finally thought to be ready for a release?

Because we can! [Evil laugh]

> Are we forcibly looking for trouble?

Nah.  Just offering it an invitation.  It will come all by itself.

We desperately need somebody to pry Emacs from the fingers of the
programmers and release it.

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-19 23:58         ` Chong Yidong
  2007-04-20  1:05           ` Stefan Monnier
  2007-04-20  1:42           ` Kevin Ryde
@ 2007-04-20 21:53           ` Richard Stallman
  2007-04-20 22:44             ` Chong Yidong
  2007-04-21  9:38             ` Eli Zaretskii
  2 siblings, 2 replies; 16+ messages in thread
From: Richard Stallman @ 2007-04-20 21:53 UTC (permalink / raw)
  To: Chong Yidong; +Cc: user42, emacs-devel

    I installed the arc-mode.el and mule.el changes.  Could we put off the
    changes to auto-mode-alist till after the release?

If that change is to simply recognize a new kind of archive, why delay
it?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-20 21:53           ` Richard Stallman
@ 2007-04-20 22:44             ` Chong Yidong
  2007-04-21  9:38             ` Eli Zaretskii
  1 sibling, 0 replies; 16+ messages in thread
From: Chong Yidong @ 2007-04-20 22:44 UTC (permalink / raw)
  To: rms; +Cc: user42, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     I installed the arc-mode.el and mule.el changes.  Could we put off the
>     changes to auto-mode-alist till after the release?
>
> If that change is to simply recognize a new kind of archive, why delay
> it?

Since magic-mode-alist is called for *every* file opened in Emacs, an
error in any function we add to it can lead to a non-localized bug.

With the parts that are currently installed, a user can manually call
archive-mode, so it's hardly a major inconvenience.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  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
  1 sibling, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2007-04-21  9:38 UTC (permalink / raw)
  To: rms; +Cc: cyd, user42, emacs-devel

> From: Richard Stallman <rms@gnu.org>
> Date: Fri, 20 Apr 2007 17:53:39 -0400
> Cc: user42@zip.com.au, emacs-devel@gnu.org
> 
>     I installed the arc-mode.el and mule.el changes.  Could we put off the
>     changes to auto-mode-alist till after the release?
> 
> If that change is to simply recognize a new kind of archive, why delay
> it?

Because .exe files are much more widespread than LZH archive in .exe
disguise.  So the change in point might adversely affect many files.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  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
  0 siblings, 2 replies; 16+ messages in thread
From: Richard Stallman @ 2007-04-21 18:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: cyd, user42, emacs-devel

    > If that change is to simply recognize a new kind of archive, why delay
    > it?

    Because .exe files are much more widespread than LZH archive in .exe
    disguise.  So the change in point might adversely affect many files.

Indeed, nost files named .exe are not LZH archives.
It would not be right at all to treat them as LZH archives.

I see only two ways to handle the .exe LZH archives:

1. Detect them automatically (probably complex).

2. Have users say explicitly when they want to treat a .exe file
that way.

#2 is probably best.  Does that currently work?
Does it work to visit the .exe file normally and then
do M-x archive-mode?

If so, this isalready exactly as it should be.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-21 18:25               ` Richard Stallman
@ 2007-04-21 19:22                 ` Chong Yidong
  2007-04-22 23:46                 ` Kevin Ryde
  1 sibling, 0 replies; 16+ messages in thread
From: Chong Yidong @ 2007-04-21 19:22 UTC (permalink / raw)
  To: rms; +Cc: Eli Zaretskii, user42, emacs-devel

Richard Stallman <rms@gnu.org> writes:

> 2. Have users say explicitly when they want to treat a .exe file
> that way.
>
> #2 is probably best.  Does that currently work?
> Does it work to visit the .exe file normally and then
> do M-x archive-mode?

Yes.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  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
  1 sibling, 1 reply; 16+ messages in thread
From: Kevin Ryde @ 2007-04-22 23:46 UTC (permalink / raw)
  To: emacs-devel

Richard Stallman <rms@gnu.org> writes:
>
> 1. Detect them automatically (probably complex).

The files have a nice marker early on, so the archive-exe-p I proposed
is
	- only .exe filename
	- "MZ", which is a DOS exe
	- "LHA's SFX", as tested by the "file" command

It'd be possible to add the search through the file looking for
"-lh5-" which is the start of the archive part proper (per
archive-lzh-exe-summarize), but I expect "LHA's SFX" is enough (it's
in a spot which I think is normally either "reserved" or relocation
table).

Can my archive-exe-p func go in, even if it's not enabled, so that
those who are confident about that test can customize it into the
magic alist?

> M-x archive-mode

In which case could .exe or lzh .exe or whatever get a mention in
files.texi, so that it's not a secret?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: arc-lzh-exe.el -- archive-mode on lzh self-extracting exes
  2007-04-22 23:46                 ` Kevin Ryde
@ 2007-04-23 14:25                   ` Chong Yidong
  0 siblings, 0 replies; 16+ messages in thread
From: Chong Yidong @ 2007-04-23 14:25 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: emacs-devel

Kevin Ryde <user42@zip.com.au> writes:

> In which case could .exe or lzh .exe or whatever get a mention in
> files.texi, so that it's not a secret?

I added a note about this in files.texi.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-04-23 14:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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     ` arc-lzh-exe.el -- archive-mode on lzh self-extracting exes Kevin Ryde
2007-04-19  2:01       ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).