emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using libmagic in Emacs?


From: Eli Zaretskii
Subject: Re: using libmagic in Emacs?
Date: Fri, 21 Aug 2009 14:01:35 +0300

> From: address@hidden
> Date: Fri, 21 Aug 2009 11:55:45 +0200
> Cc: Stefan Monnier <address@hidden>,
>       Emacs Development <address@hidden>
> 
> Is autoheader supposed to generate config.in?

Yes.

> When does that happen?

Either run autoheader by hand, or run autoreconf (which AFAIK is
supposed to run autoheader as well).

> +DEFUN ("libmagic-file-internal", Flibmagic_file_internal, 
> Slibmagic_file_internal, 1,1,0,
> +       doc: /* Return (MIME_TYPE MIME_ENCODING DESCRIPTION) for 
> FILENAME_OR_BUFFER.
> +Return nil on error. */)

This doc string "needs work"(TM).  Please use the doc string of
visited-file-name as an example.

> +  (filename_or_buffer)
> +     Lisp_Object filename_or_buffer;

Using a `_' in an argument is un-Lisp'y (IMO).

> +{
> +  CHECK_STRING_OR_BUFFER (filename_or_buffer);
> +  magic_t cookie=NULL;
> +  char* f = NULL;
> +  const char* rvs;
> +
> +  if (STRINGP (filename_or_buffer))
> +    f = SDATA (filename_or_buffer);
> +  if (BUFFERP (filename_or_buffer))
> +    f = SDATA (XBUFFER (filename_or_buffer)->filename);
> +  cookie = magic_open (MAGIC_ERROR);
> +  if (cookie == NULL) goto libmagic_error;  
> +  magic_load (cookie, NULL); //load default database
> +
> +  magic_setflags (cookie, MAGIC_MIME_TYPE | MAGIC_ERROR);  
> +  rvs = magic_file (cookie, f);

You need to encode file names before you pass them to C APIs.  Use
ENCODE_FILE to do that; see file-attributes for an example of how this
is done.

> +  if (rvs == NULL) goto libmagic_error;
> +  Lisp_Object file_mime = intern (rvs);

You cannot declare variables in the middle of a block: Emacs does not
require a C99 compiler yet and need to support C90 or even older
compilers, which will reject this code.

> +  magic_setflags (cookie, MAGIC_MIME_ENCODING | MAGIC_ERROR);
> +  rvs=magic_file (cookie, f);
> +  if (rvs == NULL) goto libmagic_error;
> +  Lisp_Object file_encoding = intern(rvs);  

Is file_encoding supposed to be a valid encoding, one of those for
which Emacs has a coding-system?  If so, perhaps you should make sure
you indeed return a valid coding-system or its alias, or otherwise
tell in the doc string that it's not guaranteed to be valid (so that
the caller should validate it before using).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]