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