[Gambas-user] vb2gb.pl - VB conversion tool
Nelson Ferraz
nferraz at ...184...
Mon Jul 21 18:18:57 CEST 2003
Here's the latest version of vb2gb. Just copy the three files to one
directory.
The most important change is that vb2gb will create both .form and
.class files automatically. (Please note that it won't translate the VB
code yet).
Usage:
./vb2gb.pl <filename.frm>
You can translate many VB forms at once:
./vb2gb.pl *.frm
Let me know how it works!
[]s
Nelson
-------------- next part --------------
package Frm2Class;
use strict;
### Variables
# Strings to translate (vb format => gb format)
my %trans = (
'\r' => '',
'Caption' => 'Text',
'Command' => 'Button',
'CommandButton' => 'Button',
'ButtonButton' => 'Button',
'Label' => 'TextLabel',
);
# Twips properties that must be converted to pixels
my @twips = qw (Top Left Width Height);
# Strings we don't know how to translate
my @nontrans = qw (
LinkTopic MaxButton MinButton ScaleHeight ScaleMode
ScaleWidth ShowInTaskbar TabIndex Picture
StartUpPosition Alignment BackStyle
);
### Subs
sub Translate_line {
# Returns translated line
my $input = shift;
# Return if non translatable
foreach my $nontrans (@nontrans) {
return if $input =~ /$nontrans/;
}
# Translate
foreach my $re (keys %trans) {
my $regexp = "\$input =~ s/$re/$trans{$re}/g";
eval ($regexp);
}
# Convert twips
foreach my $t (@twips) {
if ($input =~ /$t\s+\=\s+(\d+)/) {
my $old_val = $1;
my $new_val = int($old_val * 10 / 144);
$input =~ s/$old_val/$new_val/g;
}
}
return $input;
}
###
sub Translate {
# Returns translated line by line
my $output;
while (my $line = shift) {
if ($line =~ /Attribute/) {
$line = "' $line";
}
$output .= &Translate_line($line);
}
# Last touches
{
local $/;
# Remove anything until first Attribute
$output =~ s/.+?Attribute/Attribute/gs;
# Remove attributes
$output =~ s/Attribute.+?\n//gs;
}
return $output;
}
1;
-------------- next part --------------
package Frm2Form;
use strict;
### Variables
# Strings to translate (vb format => gb format)
my %trans = (
'\r' => '',
'VERSION (.+)' => '# Gambas Form File 1.0',
'VB\.(.+)\s+(.+)' => '$2 $1',
'Client(\w+)' => '$1',
'Begin\b' => '{',
'End\b' => '}',
'BorderStyle' => 'Border',
'Caption' => 'Text',
'Command' => 'Button',
'CommandButton' => 'Button',
'ButtonButton' => 'Button',
'Label' => 'TextLabel',
'\"(.+)\"' => '("$1")',
'VScrollBar' => 'Button' # really ugly hack
);
# Twips properties that must be converted to pixels
my @twips = qw (Top Left Width Height);
# Strings we don't know how to translate
my @nontrans = qw (
LinkTopic MaxButton MinButton ScaleHeight ScaleMode
ScaleWidth ShowInTaskbar TabIndex Picture
StartUpPosition Alignment BackStyle
);
### Subs
sub Translate_line {
# Returns translated line
my $input = shift;
# Return if non translatable
foreach my $nontrans (@nontrans) {
return if $input =~ /$nontrans/;
}
# Translate
foreach my $re (keys %trans) {
my $regexp = "\$input =~ s/$re/$trans{$re}/g";
eval ($regexp);
}
# Convert twips
foreach my $t (@twips) {
if ($input =~ /$t\s+\=\s+(\d+)/) {
my $old_val = $1;
my $new_val = int($old_val * 10 / 144);
$input =~ s/$old_val/$new_val/g;
}
}
return $input;
}
###
sub Translate {
# Returns translated line by line
my $output;
while (my $line = shift) {
last if $line =~ /Attribute/;
$output .= &Translate_line($line);
}
# Last touches
{
local $/;
# Remove BeginProperty...EndProperty entire region
$output =~ s/BeginProperty.+?EndProperty//gs;
}
return $output;
}
1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vb2gb.pl
Type: text/x-perl
Size: 858 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20030721/be551cab/attachment.pl>
More information about the User
mailing list