Instant port code from Visual Designer to Linux/MacOSX

Linux specific forum
StanDan
User
User
Posts: 57
Joined: Sun Feb 26, 2006 3:43 am
Location: Missouri, United States

Instant port code from Visual Designer to Linux/MacOSX

Post by StanDan »

I suppose everybody writes something like this at some point. But here's a script I've been using to design my forms. It converts line endings and adds a CompilerIf #PB_Compiler_OS = #PB_OS_Windows around the BalloonTip code and converts the calls to ToolTips.

Code: Select all

#!/usr/bin/perl

use strict;
# Main project file name.
my $main_pb = 'main.pb';
# Visual Designer's project file.
my $common_pb = 'Common.pb';

# Poor man's dos2unix.
system "/usr/bin/perl", "-pi", '-e', 's/\r\n/\n/g', $main_pb, $common_pb;

my $common;
my $inside_balloontip = undef;
my $balloontip_src;
open COMMON, "< $common_pb"
	or die "Error: Unable to open common file: $common_pb: $!\n";
while (my $line = <COMMON>) {
	if ($line =~ m/^Procedure BalloonTip/) {
		$inside_balloontip = 1;
		$balloontip_src .= $line;
		$balloontip_src .= "\n\tCompilerIf #PB_Compiler_OS = #PB_OS_Windows\n";
		next;
	}
	if ($inside_balloontip) {
		if ($line =~ m/^EndProcedure/) {
			my $balloontip_otheros =<<OTHEROS;
	CompilerElse
		GadgetToolTip(Gadget, Text\$)
	CompilerEndIf
OTHEROS
			$common .= $balloontip_src . $balloontip_otheros . "\n$line";
			$inside_balloontip = undef;
		} else {
			$balloontip_src .= "\t$line";
		}
		next;
	}
# Uncomment this line to turn a Frame3DGadget (given id #Calendar) in 
# your source into a CalendarGadget. This way you can place it using the 
# Visual Designer even though it doesn't support calendar gadgets.
#	$line =~ s/^(\s*)Frame3DGadget(\(#Calendar)/${1}CalendarGadget$2/;
	$common .= $line;
}
close COMMON;

open COMMON, "> $common_pb"
	or die "Error: Unable to open Common file for writing: $common_pb: $!\n";
print COMMON $common;
close COMMON;

dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Cool thanks for sharing!
Post Reply