Switch off Hex Mode on opening a file

Switch off Hex Mode on opening a file

1
NewbieNewbie
1

    May 04, 2006#1

    Hi,

    I have a little problem with a protocol file we generate in another program.
    There we generate sometimes unprintable characters in case of programming errors and if I understand the help correctly, UE will open these files always in hex mode.

    So my question is: Is there any option I can enable to prevent UE from this behavior?

    Greetings,

    Kunzara

    6,602548
    Grand MasterGrand Master
    6,602548

      May 04, 2006#2

      First enable the option Allow editing of text files with HEX 00's without converting them to spaces at Configuration - Editor - Advanced. If this solves your problem - fine.

      But maybe best method would be to create a macro which is executed on every file load which detects protocol files with the invalid bytes lower 0x20, fixes these bytes and last automatically switches to normal mode. Well, you could simple have the command HexOff in the macro specified at Macro - Set Macro for File Load/Save for run on load 1 times. The macro can be written to run HexOff only for specific file extensions (case-insensitive):

      Code: Select all

      IfExtIs "txt"
      HexOff
      ExitMacro
      EndIf
      IfExtIs "log"
      HexOff
      ExitMacro
      EndIf
      IfExtIs "lst"
      HexOff
      ExitMacro
      EndIf
      Note: If you have specified a macro file to be automatically loaded on startup of UltraEdit, the macros executed at every file load and/or save must be also in this macro file.

      What is a binary file?

      A binary file is a file which
      1. is not a UTF-16 Little Endian or Big Endian encoded text file.
      2. contains 1 or more bytes with a value lower than 32 decimal (0020 hexadecimal) with the exception of
        • code value 0009 ... horizontal tab
        • code value 000A ... line-feed
        • code value 000B ... vertical tab (very rare in text files)
        • code value 000C ... form-feed (page break)
        • code value 000D ... carriage return
      A Perl regular expression Find in Files with search string \x00{2,}|[\x01-\x08\x0E-\x1F]+ which returns found files containing 2 null bytes in series or at least 1 single byte in the other 2 code value ranges is definitely not a valid text file. Single null bytes detection in a text file is more difficult as UTF-16 encoded text files contain usually lots of null bytes.

      4
      NewbieNewbie
      4

        Aug 14, 2008#3

        I'm having the same problem (and just want to turn the HEX open feature off). Can you point me to the right place?

        I tried the macro suggestion found here, but it hasn't worked for me.

        6,602548
        Grand MasterGrand Master
        6,602548

          Aug 14, 2008#4

          The binary file detection cannot be disabled. Your text files are not text files, they are binary files because they contain surely binary bytes. Upload whole or a part (test this part file too) of one of your files in a ZIP archive which always open in hex edit mode, and I will look into it and tell you why it is opened as binary file and what the program make wrong which creates this "text" file which is not a text file.

          4
          NewbieNewbie
          4

            Aug 14, 2008#5

            I'm using UE (14.10.0.1024) to open a (text) *.log file being generated by another program (Linux script). The file is on a Linux file server.

            The file is continuously updated unless I stop the other task. Sometimes I open it via a double click from Windows; other times I get the "the file has been updated, would you like to refresh/reload?" message in UE if it's already open. In any of these these cases, the file time *sometimes* opens/displays cleanly as text and sometimes opens/displays as hex and I have to switch modes. As far as I can tell, the file *always* opens as text if I shut down the other application so that the file is static and only UE is opening it.

            It's possible that the issue is that UE may be opening the file in mid-update so that it's seeing odd characters and thinks it's a binary file. Opening, closing, opening, etc. the file multiple times in a row shows the binary, text, text/binary+... behavior.

            As you say, there's no way to just turn off hex mode entirely ( :- ). I don't know if one of the macro scripts would allow me to do this (always open *.log files as text-only) but I haven't had luck with this so far.

            Notepad has no problems with this file (always text, and NP has no hex mode).

            6,602548
            Grand MasterGrand Master
            6,602548

              Aug 16, 2008#6

              Notepad has no hex edit mode, so it must show you the file content always in text mode even when it is a binary file. You can turn off in UltraEdit Disable automatic detection of HEX file format on reload. But if the application on your Linux server writes really only ASCII bytes into the file, UltraEdit should never think the file is a binary file, independent if the Linux application is writing to the file when UltraEdit is reloading it or not. I guess, this is more a problem on data transmission from the Linux server to your computer while the Linux application is writing to the file and UltraEdit reloads it.

              Well, UltraEdit analyzes only the first 9 KB (UE v11.20a) or 64 KB (UE v14.00b) of the file if it contains 2 or more NULL bytes. If this is the case, it opens the file in binary mode. Does your Linux application always insert the text data at top of the file or append it at the end?

              4
              NewbieNewbie
              4

                Aug 19, 2008#7

                Yes, I'm aware that Notepad doesn't have a Hex mode. I was just pointing out the NP had no problem displaying this file and it was a shame that I had to resort to NP to view the files easily.

                I already had "Disable automatic detection of HEX file format on reload." I'm not sure if I want to say it didn't work *or* if I had just gotten in the habit of always opening the file from scratch.

                I don't know how the Linux box is writing out the files (it's just a script >> redirecting to a file). I would have assumed it would append them (from the end) but something was confusing UE, even if it was looking for the binary character at the beginning.

                I finally played around with the macro setup and seem to have gotten a "run on load" macro that forces text (hex disable) mode for *.log files (the way I'm naming these files from the Linux box). That seems to be working OK.

                I still think that UE should include a way to disable the hex mode.

                Thanks,
                G-