Tommaso Cucinotta wrote:

> Hi,
> 
> I think this whole format detection logic in LyX is relatively "fragile".

Yes. It is not nice at all.
 
> FileName.cpp should not know about formats, but it actually has this
> guessFormatFromContents() method that returns format names (I guess they
> may be looked up into the registered formats somewhere).

LyX should not know at all how to determine formats based on the file 
contents. There are tools for that that are much better.

> Also, now that a format may have more extensions associated, the last
> part of the guess seems to be wrong, because in the end the file
> extension is returned. Instead, the extension should be looked up into
> the registered Formats, in order to find a format with that extension.

Actually, detecting formats based on extension goes wrong in many cases 
anyway. It should only be a last resort fallback. If possible, the format 
should be detected from contents, because in many cases one does not use 
default extensions.

> Isn't it possible to encode these format-detection binary strings, as
> well as text strings (e.g., in form of regular expressions) directly
> inside the format specification in a "\Format" line (e.g., similarly to
> the libmagic configuration file) ? (not that I intend to spend any time
> on such things now :-) ).

I have a half-finished patch to use libmagic for format detection that I 
started a long time ago. With this patch, LyX would use the file format 
knowledge of libmagic. If you are interested, I can dig it out.


Georg

Reply via email to