From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: using libmagic in Emacs? Date: Wed, 19 Aug 2009 16:20:21 -0700 (PDT) Message-ID: <200908192320.n7JNKLRZ003050@godzilla.ics.uci.edu> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1250726770 25433 80.91.229.12 (20 Aug 2009 00:06:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Aug 2009 00:06:10 +0000 (UTC) Cc: Stefan Monnier , Emacs Development To: joakim@verona.se Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 20 02:06:03 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 1MdvA2-0002jF-5Q for ged-emacs-devel@m.gmane.org; Thu, 20 Aug 2009 02:06:01 +0200 Original-Received: from localhost ([127.0.0.1]:60527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mdv9y-0005hR-Ev for ged-emacs-devel@m.gmane.org; Wed, 19 Aug 2009 20:05:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MduTq-0006ii-A6 for emacs-devel@gnu.org; Wed, 19 Aug 2009 19:22:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MduTk-0006hp-Ur for emacs-devel@gnu.org; Wed, 19 Aug 2009 19:22:09 -0400 Original-Received: from [199.232.76.173] (port=33711 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MduTk-0006hm-Pd for emacs-devel@gnu.org; Wed, 19 Aug 2009 19:22:04 -0400 Original-Received: from sallyv2.ics.uci.edu ([128.195.1.120]:37519) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MduTj-00070R-GF for emacs-devel@gnu.org; Wed, 19 Aug 2009 19:22:04 -0400 Original-Received: from godzilla.ics.uci.edu (godzilla.ics.uci.edu [128.195.10.101]) by sallyv2.ics.uci.edu (8.13.8+Sun/8.13.8) with ESMTP id n7JNKLkn009567; Wed, 19 Aug 2009 16:20:21 -0700 (PDT) Original-Received: (from dann@localhost) by godzilla.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id n7JNKLRZ003050; Wed, 19 Aug 2009 16:20:21 -0700 (PDT) In-Reply-To: (joakim@verona.se's message of "Thu, 20 Aug 2009 00:49:53 +0200") Original-Lines: 101 X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: n7JNKLkn009567 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@godzilla.ics.uci.edu X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) 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:114421 Archived-At: joakim@verona.se writes: > Stefan Monnier writes: > > > > I think it's a good idea. It may require some non-trivial changes on > > the Lisp side, since libmagic's information is not quite the same as > > what Emacs currently uses: we'll probably want to use libmagic to get > > a MIME-type and then have a table mapping mime-types to major modes or > > some such. > > > > > > Stefan > > I attach an early draft filemagic patch. > > Some notes: > > - The mime type info usualy is less granular than the free > text info: > > file --mime /tmp/tst.xcf > /tmp/tst.xcf: application/octet-stream; charset=binary > > file /tmp/tst.xcf > /tmp/tst.xcf: GIMP XCF image data, version 0, 640 x 480, RGB Color > > This is dependent on the file magic info file used. > > - We can probably have much fun debating what the interface should look > like at the lisp level. Any ideas? > > diff --git a/configure.in b/configure.in > index f4096db..cb74523 100644 > --- a/configure.in > +++ b/configure.in > @@ -137,6 +137,8 @@ OPTION_DEFAULT_ON([xft],[don't use XFT for anti aliased fonts]) > OPTION_DEFAULT_ON([libotf],[don't use libotf for OpenType font support]) > OPTION_DEFAULT_ON([m17n-flt],[don't use m17n-flt for text shaping]) > > +OPTION_DEFAULT_ON([filemagic],[don't compile with filemagic support]) > + > OPTION_DEFAULT_ON([toolkit-scroll-bars],[don't use Motif or Xaw3d scroll bars]) > OPTION_DEFAULT_ON([xaw3d],[don't use Xaw3d]) > OPTION_DEFAULT_ON([xim],[don't use X11 XIM]) > @@ -2223,6 +2225,19 @@ if test x"$ac_cv_func_alloca_works" != xyes; then > AC_MSG_ERROR( [a system implementation of alloca is required] ) > fi > > + > +HAVE_LIBMAGIC=no > +if test "${with_filemagic}" != "no"; then > + #libmagic support > + AC_CHECK_HEADERS(magic.h, [ AC_CHECK_LIB(magic,magic_open,HAVE_LIBMAGIC=yes) ]) > +fi > + > +if test "${HAVE_LIBMAGIC}" = "yes"; then > + LIBMAGIC=-lmagic > + AC_SUBST(LIBMAGIC) > + AC_DEFINE(HAVE_LIBMAGIC, 1, [Define to 1 if using libmagic.]) > +fi > + > # fmod, logb, and frexp are found in -lm on most systems. > # On HPUX 9.01, -lm does not contain logb, so check for sqrt. > AC_CHECK_LIB(m, sqrt) > @@ -2954,6 +2969,7 @@ echo " Does Emacs use -lpng? ${HAVE_PNG}" > echo " Does Emacs use -lrsvg-2? ${HAVE_RSVG}" > echo " Does Emacs use -lgpm? ${HAVE_GPM}" > echo " Does Emacs use -ldbus? ${HAVE_DBUS}" > +echo " Does Emacs use -lmagic? ${HAVE_LIBMAGIC}" > > echo " Does Emacs use -lfreetype? ${HAVE_FREETYPE}" > echo " Does Emacs use -lm17n-flt? ${HAVE_M17N_FLT}" > diff --git a/src/Makefile.in b/src/Makefile.in > index 425cf98..b80255a 100644 > --- a/src/Makefile.in > +++ b/src/Makefile.in > @@ -420,6 +420,7 @@ LIBX= $(LIBXMENU) LD_SWITCH_X_SITE > #endif /* not HAVE_LIBRESOLV */ > > LIBSOUND= @LIBSOUND@ > +LIBMAGIC= @LIBMAGIC@ > CFLAGS_SOUND= @CFLAGS_SOUND@ > > RSVG_LIBS= @RSVG_LIBS@ > @@ -511,6 +512,12 @@ MSDOS_OBJ = dosfns.o msdos.o w16select.o xmenu.o > #endif > #endif > > +#ifdef HAVE_LIBMAGIC > +FILEMAGIC_OBJ = filemagic.o > +#else > +FILEMAGIC_OBJ = > +#endif Can you please avoid adding new #ifdefs here? (we are trying to get rid of them). Maybe use @FILEMAGIC_OBJ@ ? Or even use the file unconditionally, just add the proper #ifdefs to make it be empty if not HAVE_LIBMAGIC ?