From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: using libmagic in Emacs? Date: Tue, 25 Aug 2009 23:36:04 +0300 Organization: JURTA Message-ID: <87ljl73a2z.fsf@mail.jurta.org> References: <87ocqco7fi.fsf@mail.jurta.org> <87y6pb8lqh.fsf@mail.jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1251233073 9448 80.91.229.12 (25 Aug 2009 20:44:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Aug 2009 20:44:33 +0000 (UTC) Cc: monnier@IRO.UMontreal.CA, joakim@verona.se, emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 25 22:44:26 2009 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 1Mg2sR-00008o-Gr for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2009 22:44:23 +0200 Original-Received: from localhost ([127.0.0.1]:52389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mg2sQ-0004cr-JT for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2009 16:44:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mg2qy-0003zb-4i for emacs-devel@gnu.org; Tue, 25 Aug 2009 16:42:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mg2qr-0003wB-82 for emacs-devel@gnu.org; Tue, 25 Aug 2009 16:42:49 -0400 Original-Received: from [199.232.76.173] (port=51477 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mg2qr-0003w6-4K for emacs-devel@gnu.org; Tue, 25 Aug 2009 16:42:45 -0400 Original-Received: from smtp-out2.starman.ee ([85.253.0.4]:49775 helo=mx2.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mg2qj-0005DM-IO; Tue, 25 Aug 2009 16:42:38 -0400 X-Virus-Scanned: by Amavisd-New at mx2.starman.ee Original-Received: from mail.starman.ee (82.131.53.219.cable.starman.ee [82.131.53.219]) by mx2.starman.ee (Postfix) with ESMTP id 86A3C3F40CA; Tue, 25 Aug 2009 23:42:25 +0300 (EEST) In-Reply-To: (Richard Stallman's message of "Sun, 23 Aug 2009 20:07:18 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by monty-python.gnu.org: GNU/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:114594 Archived-At: > The problem is that `image-jpeg-p' in image.el refuses to accept > non-JFIF JPEG image files whereas Emacs can correctly display them > when tests in `image-jpeg-p' are ignored. > > Using libmagic means looking only for 2 bytes 0xffd8 (a magic number > of JPEG files) as described by the magic number file: > > 0 beshort 0xffd8 JPEG image data > > It seems this is enough to determine JPEG files. But I'm not confident > about removing additional tests from `image-jpeg-p'. We could keep the > current rules in image.el as a fall-back when libmagic is not available. > > Whatever we do with the function `image-jpeg-p', we could easily make > Emacs test these two bytes. It makes no sense to install code to link > with libmagic just to handle that and a few other similar things. The following patch changes `image-type-header-regexps' to test only two bytes of the JPEG magic number: Index: lisp/image.el =================================================================== RCS file: /sources/emacs/emacs/lisp/image.el,v retrieving revision 1.87 diff -u -r1.87 image.el --- lisp/image.el 24 Feb 2009 10:29:00 -0000 1.87 +++ lisp/image.el 25 Aug 2009 20:33:16 -0000 @@ -43,7 +43,7 @@ static \\(unsigned \\)?char \\1_bits" . xbm) ("\\`\\(?:MM\0\\*\\|II\\*\0\\)" . tiff) ("\\`[\t\n\r ]*%!PS" . postscript) - ("\\`\xff\xd8" . (image-jpeg-p . jpeg)) + ("\\`\xff\xd8" . jpeg) (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)") (comment-re (concat "\\(?:!--" incomment-re "*-->[ \t\r\n]*<\\)"))) (concat "\\(?:<\\?xml[ \t\r\n]+[^>]*>\\)?[ \t\r\n]*<" -- Juri Linkov http://www.jurta.org/emacs/