[Geany-devel] Binary files - a hangup fix and some more

Алексей Антипов 1a_antipov at xxxxx
Sat Feb 6 01:26:37 UTC 2010


Hi,

I have been recently playing around handling binary files with Geany. At least Notepad++, which is also Scintilla-based, is able to do that (opens and saves binaries correctly). This feature looks very promising for me, as there are sometimes files with mixed content (e.g. Outlook forms, resource files or malformed e-mails).

First, I've found a problem (seems that was partially due to my charset handling patch http://lists.uvena.de/geany-devel/2009-October/001480.html): when opening a binary (or malformed) file Geany would hang eating 100% CPU. My 1st patch is to fix that (tested for some cases, all worked... but should be checked once more).

Then, I tried to make Geany open binaries correctly (the 2nd patch). What I did was:
 - Made encodings_convert_to_utf8 attempt to convert with "fast" flag set if nothing else succeeded (if Unicode checks failed while conversion itself succeeded)
 - Made encodings_convert_to_utf8 (in fact, its duplicate) return not only converted text, but also its length ('cause if a binary file contains nulls it would be truncated instead)
 - Made document_open_file_full use SCI_ADDTEXT instead of SCI_SETTEXT when showing file contents. The former is able to handle NULLs while the latter isn't

Finally, I was able to view, edit and correctly save a binary file with NULLs. I've attached 2 screenshots for you to see what it looks like.

I should underline that this feature (and this patch) is HIGHLY experimental and I didn't perform any more or less satisfactory testing (just opened a file with NULLs, added "ABCDEF" and saved). So using any advanced features (search and replace etc) may lead to unpredictable behaviour. At least there should be a choice how to handle binary files (allow open or open a new empty file as before). I'll make some testing in a regular working environment and, if necessary, issue other patches (of course, if someone is interested in that feature).

Regards,
Alexey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 02_binary_files_(EXPERIMENTAL).patch
Type: application/x-patch
Size: 5870 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/devel/attachments/20100206/13945008/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01_binary_files_hangup_fix.patch
Type: application/x-patch
Size: 844 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/devel/attachments/20100206/13945008/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: outlook_form.png
Type: image/png
Size: 178302 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/devel/attachments/20100206/13945008/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_file.png
Type: image/png
Size: 46867 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/devel/attachments/20100206/13945008/attachment-0001.png>


More information about the Devel mailing list