On 18/09/2011 4:43 PM, Tommaso Cucinotta wrote:
Il 17/09/2011 17:29, Julien Rioux ha scritto:
I think the logic about formats should be in Format.cpp, not in
FileName.cpp. FileName.cpp does not know about formats.

Hi,

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

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).


It's quite true that it is fragile. It relies on format names being in sync between FileName.cpp and configure.py.

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.


That's done already, when guessFormatFromContents did not return anything useful, we check the file extension against defined formats. We do check multiple extensions for one format.

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 :-) ).

T.



Some of these are bytes, and endianness matters for some of them, and I don't think it is worth our trouble! I actually didn't know that we played such guessing game before looking at your work, and I doubt that we lose much functionality in LyX if we would remove most of what is in guessFileFromContents. Perhaps only keeping the (g)zip detection would matter.

--
Julien

Reply via email to