[Gambas-user] gambas3 search/replace global - really inconvenient
Doriano Blengino
doriano.blengino at ...1909...
Thu Jul 1 06:55:03 CEST 2010
Jussi Lahtinen ha scritto:
>> Yes, but how can I detect a "binary" file?
>>
>
> I'm not sure what would be easy way to do it.
>
> Gedit gives following error message from binary files:
> "gedit has not been able to detect the character encoding.
> Please check that you are not trying to open a binary file.
> Select a character encoding from the menu and try again."
>
> So, maybe with "file" command?
> I think there should be some library for this, as so many programs
> needs this kind of functionality
> (Ubuntu Desktop, browsers, editors, ... ).
>
> Or, if file has ".dat" etc at end, it is considered as binary.
>
Gedit says so (unable to...) because it tries to convert the file
contents to unicode in order to display it. It tries different
conversions (configurable if one wants to) until success or fail. This
method is very effective, even if not particularly elegant. KDE has some
library call, I believe, which can deduct the correct type of a file by
peeking at its contents, similarly at file(1) unix command. I don't know
if this function is part of KDE or QT (probably the former).
Using the file extension to gather information about a file is
deprecated in unix, while using the file(1) command would add another
dependency to gambas, and would require a routine to parse the file(1)
output. Moreover, there are certain kinds of file which are plain text
files, but have other special meanings, like the graphics file of type
"can't remember... pbm/pgm/ppm? "; even postscript/pdf files can be
plain text.
Perhaps, trying to convert to unicode could be the more effective way
for an IDE.
Regards,
Doriano
More information about the User
mailing list