Topic: UTF-CONV.VDM, the combined Unicode conversion macr (1 of 2), Read 14 times, 1 File Attachment
Conf: Converting, Translating
From: Pauli Lindgren
Date: Thursday, March 19, 2009 01:40 PM

Here is the first version of UTF-CONV.VDM, which combines UTF-ANSI.VDM and ANSI-UTF.VDM.

The macro can be run in fully interactive mode with dialog boxes, or silently in batch mode, or something in between.
If you call the macro from the beginning, it will run in interactive mode.
It first checks if the file is an UTF file and selects one of the two main dialogs (UTF to ANSI/OEM or ANSI/OEM to UTF) based on that. These dialogs then work pretty much the same as in the old macros.

If you call label FROM_UTF, the macro starts directly from UTF to ANSI/OEM dialog box and works like UTF-ANSI.VDM.
Calling label TO_UTF works like ANSI-UTF.VDM.
Example:
Call_File(100,"utf-conv.vdm","TO_UTF")
The above line can be included for example in your User or Tools menu.

Batch mode can be started by calling one of the several labels:
UTF_ANSI, ANSI_UTF8, ANSI_UTF16, UTF_OEM, OEM_UTF8, OEM_UTF16
When these labels are called, no dialog boxes are displayed, except in case of some errors. (This can easily be changed to never display any dialog boxes.)

You can also call the label BATCH. In this case, you must set the options in numregs #101...#105 before calling the macro. The registers set the following options:
#101 = Interactivity level (0-3)
#102 = Operation to perform (0 = Auto, 1 = UTF to ANSI/OEM, 2 = ANSI/OEM to UTF)
#103 = Unicode format: 0 = auto detect/last used, 1 = UTF-8, 2 = UTF-16LE, 3 = UTF-16BE
#104 = "ANSI" format: 0 = Vedit font, 1 = ANSI, 2 = OEM
#105 = options (bitmask): 1 = Insert BOM, 2 = Convert HTML codes, 4 = convert OEM control codes to UTF
For more details, see comments in the macro code.

If the macro is called from command line or .BAT file either with -x option or with -q option, it will run in batch mode and exit Vedit at the end.
If the macro is called without label, UTF to ANSI conversion is assumed.
Example:
vpw -w -s0 -q -x utf-conv.vdm file.txt

To call a label, you need to use -c option. In this case, -q option must be set in order to exit Vedit at the end.
Example:
vpw -w -s0 -q -c'Call_File(100,"utf-conv.vdm","ANSI_UTF8")' file.txt -a file_utf8.txt

When interactive mode is used, the options selected in dialog boxes are remembered by storing them in utfconv.ini.

In addition this macro contains some other enhancements compared to UTF-ANSI.VDM and ANSI-UTF.VDM.
- Gives a warning if the file has not been saved when you start the macro.
- A checkbox to select if OEM control characters are to be converted to UTF. (The checkbox is only displayed if OEM font is active.)
- UTF-16 detection uses stricter limits for ANSI than OEM conversion. However, both have stricter limits for "wrong" endianes than the old macros had.

The zip file contains an example menu, UTF_TOOLS.MNU, that can be used to test some of the options of the macro. (I loaded it as Tools menu.)

--
Pauli

 
UTF_CONV10.ZIP (13KB)

 


Topic: UTF-CONV.VDM, the combined Unicode conversion macr (2 of 2), Read 11 times, 1 File Attachment
Conf: Converting, Translating
From: Pauli Lindgren
Date: Friday, April 17, 2009 09:45 AM

Here is new version of UTF-CONV.VDM, v1.1

Changes:

- Added keyboard shortcut to [ To UTF ] / [ To ANSI ] buttons.

- If a block is highlighted, only the block is converted. This allows you for example to convert a block copied from another file that uses other coding. The format is checked only whithin the highlighted block, too.

- It is now possible to call the macro for just to check the UTF/ASCII format without doing any conversion.
To check the format of current file or highlighted block, call the label CHEK_FORMAT.
The format is returned in Return_Value as follows:

0 = ASCII (7-bit)
1 = ASCII + NULL character(s)
4 = ASCII + Graphics character(s) (maybe ANSI/OEM)
10 = UTF-8 (BOM), 11 = UTF-8 (guessed)
20 = UTF-16LE (BOM), 21 = UTF-16LE (guessed)
30 = UTF-16BE (BOM), 31 = UTF-16BE (guessed)

The zip file contains an additional macro UTF_chk.vdm which is an example of how to call utf-conv.vdm to check the format. It displays the detected format on status line.

--
Pauli

 
UTF_CONV11.ZIP (13KB)