Topic: Convert to UTF-8 (1 of 12), Read 22 times, 1 File Attachment
Conf: Converting, Translating
From: Ian Binnie
Date: Wednesday, February 25, 2009 08:41 PM

I have written a macro to translate UTF-16LE (little-endian), usually used in Windows, to UTF-8.
This could be used after the Vedit {EDIT, Translate, ASCII to Unicode} to convert ASCII to UTF-8.

This is an algorithmic conversion, requiring no table lookup, and is a companion to my macro utf8conv.vdm.

I have made a minor change to the previously posted macro (as well as corrected the misleading name).
I included a label "NoPrompt" to facilitate chaining macros.



So to convert ANSI/OEM to UTF-8:-
CALLF(100,"ansi-utf.vdm")
CALLF(100,"utf16-8conv.vdm","NoPrompt")

 
UTF16-8CONV.VDM (2KB)

 


Topic: Convert to UTF-8 (2 of 12), Read 17 times
Conf: Converting, Translating
From: Pauli Lindgren
Date: Thursday, February 26, 2009 08:50 AM

On 2/25/2009 8:41:48 PM, Ian Binnie wrote:
> I have written a macro to
> translate UTF-16LE
> (little-endian), usually used
> in Windows, to UTF-8.
> This could be used after the
> Vedit {EDIT, Translate, ASCII
> to Unicode} to convert ASCII
> to UTF-8.

Maybe this could be combined with ansi-udf.vdm, and let the user to choose the format from the dialog box.
Option to convert to UTF-16BE could be added, too. (Now it only converts to UTF-16LE).

--
Pauli

 


Topic: Convert to UTF-8 (3 of 12), Read 13 times
Conf: Converting, Translating
From: Ian Binnie
Date: Thursday, February 26, 2009 04:12 PM

On 2/26/2009 8:50:00 AM, Pauli Lindgren wrote:
>On 2/25/2009 8:41:48 PM, Ian Binnie
>wrote:

>Maybe this could be combined with
>ansi-udf.vdm, and let the user to choose
>the format from the dialog box.
>Option to convert to UTF-16BE could be
>added, too. (Now it only converts to
>UTF-16LE).

I much prefer macros that do a single job.
I would rather have several macros than one with dialog boxes.

 


Topic: Re: Convert to UTF-8 (4 of 12), Read 14 times
Conf: Converting, Translating
From: Ted Green
Date: Thursday, February 26, 2009 10:41 PM

At 04:12 PM 2/26/2009, you wrote:
>From: Ian Binnie
>
>On 2/26/2009 8:50:00 AM, Pauli Lindgren wrote:
>>On 2/25/2009 8:41:48 PM, Ian Binnie
>>wrote:
>
>>Maybe this could be combined with
>>ansi-udf.vdm, and let the user to choose
>>the format from the dialog box.
>>Option to convert to UTF-16BE could be
>>added, too. (Now it only converts to
>>UTF-16LE).
>
>I much prefer macros that do a single job.
>I would rather have several macros than one with dialog boxes.

I would prefer one macro that can be called from a menu system. Perhaps there is a way to call the macro with our without parameters in order to meet both of our preferences.

I agree that from a command-line/batch-file several macro that don't need dialog boxes is preferred.

Or, perhaps a "main" macro with dialog boxes which calls the appropriate function-specific macros.

Just my thoughts. I am confident you and Pauli will come up with a great solution.

And, of course, I want to thank you for your work.

Ted.

 


Topic: Convert to UTF-8 (5 of 12), Read 13 times
Conf: Converting, Translating
From: Pauli Lindgren
Date: Friday, February 27, 2009 12:04 PM

On 2/26/2009 4:12:11 PM, Ian Binnie wrote:
>
>I much prefer macros that do a single job.
>I would rather have several macros than
>one with dialog boxes.

Converting from ANSI to Unicode is a single job.
It makes no sense to have different macros just for converting to slightly different formats of Unicode.

I already have so many macros in my user-mac directory that it is difficult to find the right macro.

It is easier to select the macro directly from a menu than to search for it using file open dialog box. But there is limited room in the User and Tools menus. And in Edit menu, too.

If you want to call macro functions directly from a .bat file without using dialog boxes, you can use labels to call a specific function. I have done this in most of my macros, including Wildfilew, ctags, utags and aspell.
In fact, sometimes I have even combined multiple different functions in a single macro file. For example in my Wiki Tools package (not yet published), a single .vdm file contains routines for inserting tables, lists, headings etc. These functions are then called from the wikiTools menu.

Of course you could have a separate macro for UTF-16 to UTF-8 conversion, too. Such function may be needed sometimes. But it could as well be just a label inside the more general macro.

--
Pauli

 


Topic: Re: Convert to UTF-8 (6 of 12), Read 13 times
Conf: Converting, Translating
From: Ted Green
Date: Friday, February 27, 2009 12:15 PM

At 12:04 PM 2/27/2009, you wrote:
>From: "Pauli Lindgren"
>
>On 2/26/2009 4:12:11 PM, Ian Binnie wrote:
>>
>>I much prefer macros that do a single job.
>>I would rather have several macros than
>>one with dialog boxes.
>
>Converting from ANSI to Unicode is a single job.
>It makes no sense to have different macros just for converting to slightly different formats of Unicode.

I agree with keeping the number of macros down.

One solution for handling automation is to implement the macro similar to our supplied convert.vdm. Normally it prompts with a dialog box, but if you use (e.g. a batch file) to invoke VEDIT with a parameter and the macro, it performs the requested function without a dialog box.

// From OS: VPW -X CONVERT filename
//
// This will prompt for the desired conversion and then
// convert the entire file. It will remain in VEDIT.
//
// -OR- VPW -Nn -X CONVERT filename
//
// n < 7 - Perform conversion number 'n' on the entire file;
// save the file and exit.
//

Ted.

 


Topic: Re: Convert to UTF-8 (7 of 12), Read 16 times
Conf: Converting, Translating
From: Christian Ziemski
Date: Friday, February 27, 2009 02:22 PM

Hi!

I think related conversions should be collected in few macros.
These macro(s) should be callable from other macros, from VEDIT menu and
from commandline as well with human-readable controlling parameters.


Example:

One macro (perhaps UTF-CONV.VDM) contains all UTF related converions.

One text register is used for parameter transfer (e.g. TReg 120)

If that register is empty on startup the macro tries to find out what
kind of file is loaded and starts the appropriate conversion dialog.

Otherwise the text register 120 controls the function:
"UTF8-UTF16"
"UTF8-ANSI"
"UTF8-ASCII"
"UTF16-UTF8"
...

Perhaps the -N parameter can be used additionally for (de)activating the
dialogs (-N0 and -N1).


From commandline:
vpw.exe -x "UTF-CONF.VDM" -c "RS(120, 'UTF8-UTF16')" -N1 filename.txt


From macro or menu:
// N_Option(1)
RS(120, 'UTF8-UTF16')
Call_File(101, "UTF-CONF.VDM")



Christian

 


Topic: Re: Convert to UTF-8 (8 of 12), Read 17 times
Conf: Converting, Translating
From: Pauli Lindgren
Date: Thursday, March 05, 2009 12:02 PM

On 2/27/2009 2:22:41 PM, Christian Ziemski wrote:
>
>One macro (perhaps UTF-CONV.VDM) contains all UTF
>related converions.

Yes, that would make sense, since big part of the macros ansi-utf.vdm and utf-ansi.vdm are already the same (such as creating the conversion table).

The Edit/Translate menu needs to be changed anyway since the new macros are no more limited to UTF-16.

>
>One text register is used for
>parameter transfer (e.g. TReg
>120)
>
>If that register is empty on
>startup the macro tries to
>find out what
>kind of file is loaded and
>starts the appropriate
>conversion dialog.

This would have the problem that the register is probably not empty. Each text register contains whatever is left there last time.

So, calling a label is probably needed anyway.

>
>Perhaps the -N parameter can
>be used additionally for
>(de)activating the
>dialogs (-N0 and -N1).

N_Option is one possible way to pass information, but you could as well use any numeric register.

In current versions of the UTF macros, dialog boxes are skipped if the macro was started from command line using -x invocation option. But that only works from command line, not when calling from menu or another macro.

In many of my macros, I have used label "BATCH" to execute the macro in batch mode.

--
Pauli

 


Topic: Re: Convert to UTF-8 (9 of 12), Read 18 times
Conf: Converting, Translating
From: Christian Ziemski
Date: Thursday, March 05, 2009 02:26 PM

On 05.03.2009 18:03 in vtech-convert Pauli Lindgren wrote:
>
> On 2/27/2009 2:22:41 PM, Christian Ziemski wrote:
>
>> One text register is used for parameter transfer (e.g. TReg 120)
>>
>> If that register is empty on startup the macro tries to find out
>> what kind of file is loaded and starts the appropriate conversion
>> dialog.
>
> This would have the problem that the register is probably not empty.
> Each text register contains whatever is left there last time.

Correct, but there is full control about the registers when the call is
invoked, so I don't see a real problem here.


> So, calling a label is probably needed anyway.

Do you know an easy way to call a macro from command line *with* a label
like Call_File(r, "file", "label") from macros does?

I tried to emulate something like that with the above TReg usage.
Or possibly the -u option and the CMD_LINE string value could be used.


>> Perhaps the -N parameter can be used additionally for
>> (de)activating the dialogs (-N0 and -N1).
>
> N_Option is one possible way to pass information, but you could as
> well use any numeric register.

Yes, I used TReg 120 because it doesn't interfere with user registers
and other internal registers. It's emptied with any keystroke anyway.

Probably Numeric Register 120 can be used that way too.


> In current versions of the UTF macros, dialog boxes are skipped if
> the macro was started from command line using -x invocation option.
> But that only works from command line, not when calling from menu or
> another macro.

I would like to have a simple solution for command line and macro cmd
calls. Generally, not only for the current UTF-macros.

(So this discussion can be sort of "brainstorming".)


Christian

 


Topic: Re: Convert to UTF-8 (10 of 12), Read 17 times
Conf: Converting, Translating
From: Pauli Lindgren
Date: Friday, March 06, 2009 11:22 AM

On 3/5/2009 2:26:23 PM, Christian Ziemski wrote:
>On 05.03.2009 18:03 in vtech-convert
>Pauli Lindgren wrote:
>>
>> This would have the problem that the register is probably not empty.
>> Each text register contains whatever is left there last time.
>
>Correct, but there is full control about
>the registers when the call is
>invoked, so I don't see a real problem
>here.

If the user runs the macro with "Misc" -> "Load/exec macro", then there is no control over the registers.

Therefore, the default entry (from the beginning of macro) should be interactive mode with dialog boxes etc, and a label is to be used when calling from another macro, menu or command line and predefined settings are given. I have used this method in many of my macros.

Of course, Is_Auto_Execution could be used to override this.

>
>> So, calling a label is probably needed anyway.
>
>Do you know an easy way to call a macro
>from command line *with* a label
>like Call_File(r, "file", "label") from
>macros does?

At least this seems to work:
vpw -c 'Call_File(100,"Aspell.vdm","OPTIONS_DIALOG")'

>
>> N_Option is one possible way to pass information, but you could as
>> well use any numeric register.

Another thing about N_Option. If you set it in one call, will it be set after that in all the other macro calls after that? This might cause surprises.

--
Pauli

 


Topic: Re: Convert to UTF-8 (11 of 12), Read 18 times
Conf: Converting, Translating
From: Ted Green
Date: Friday, March 06, 2009 11:48 AM

At 11:23 AM 3/6/2009, you wrote:

>Another thing about N_Option. If you set it in one call, will it be set after that in all the other macro calls after that? This might cause surprises.

The N_Option is set during invocation and never changes in that instance of VEDIT.

Ted.

 


Topic: Re: Convert to UTF-8 (12 of 12), Read 18 times
Conf: Converting, Translating
From: Christian Ziemski
Date: Friday, March 06, 2009 12:01 PM

On 06.03.2009 17:23 vtech-convert Listmanager wrote:
> From: "Pauli Lindgren"
>
> On 3/5/2009 2:26:23 PM, Christian Ziemski wrote:
>>
>> [...] there is full control about the registers when the call is
>> invoked, so I don't see a real problem here.
>
> If the user runs the macro with "Misc" -> "Load/exec macro",
> then there is no control over the registers.

Pauli, you are right!

I'm obviously out of practice regarding Vedit. :-(

(Or are clicking "send" too early...)


Christian