#!/usr/bin/perl # Copyright 2008 Laszlo Systems. Use according to license terms. # # convert_required.pl # Helps to make required conversions of 4.1 lzx files # that: # 1) use deprecated form of 'new' and 'instanceof' within scripts, # for example, # 'new LzText' is converted to 'new lz.text' # 'new myclass' is converted to 'new lz.myclass' # 2) use old names for services # for example, # 'LzTimer' is converted to 'lz.Timer' (wherever it is seen) # # Warnings: # # - PLEASE BACK UP your entire work directory before starting. # # - Please compare the end result of each changed file with the # version before changing (filename.bak) and verify that the # changes make sense. # # Should work with Perl 5 or greater. # tested on OSX 10.5.3 with perl v5.8.8 # Author: Don Anderson ################ # Conversions: # # On script lines that contain references to classes such # as LzAudio, LzBrowser, ... (the complete list is in # convert_class_name_changes()): # # - change the name from Lz to lz. # # On script lines that are of the form 'new classname...' or # 'instanceof classname...': # # - if classname already has lz. , no change # # - if classname is a class/interface defined in one of the input # files (e.g. via lz.view) # # - new global[...] is converted to new lz[...] # # - otherwise, no change (this includes Object, Array, ...). # use File::Basename; use File::Copy; use Getopt::Std; ################ my $VERSION = "1.0.0"; my $PROG = basename($0); my $USAGE = < "lz.node", LzView => "lz.view", LzText => "lz.text", LzInputText => "lz.inputtext", LzCanvas => "lz.canvas", LzScript => "lz.script", LzAnimatorGroup => "lz.animatorgroup", LzAnimator => "lz.animator", LzLayout => "lz.layout", LzState => "lz.state", LzCommand => "lz.command", LzSelectionManager => "lz.selectionmanager", LzDataSelectionManager => "lz.dataselectionmanager", LzDatapointer => "lz.datapointer", LzDataProvider => "lz.dataprovider", LzDatapath => "lz.datapath", LzDataset => "lz.dataset", LzDatasource => "lz.datasource", LzHTTPDataProvider => "lz.lzhttpdataprovider", LzLibrary => "lz.import", LzDelegate => "lz.Delegate", LzParam => "lz.Param", # service classes LzTimer => "lz.Timer", LzTrack => "lz.Track", LzGlobalMouse => "lz.GlobalMouse", LzKeys => "lz.Keys", LzIdle => "lz.Idle", LzCursor => "lz.Cursor", LzModeManager => "lz.ModeManager", LzInstantiator => "lz.Instantiator", LzFocus => "lz.Focus", LzBrowser => "lz.Browser", LzHistory => "lz.History", LzAudio => "lz.Audio", ); # This list of known classes. We add to it each time # we see a class definition. my %lzsclassname = (); ## # debug(level, string); # debugln(level, string); # Show the string if the level is less or equal to # the current debug level. debug(1, '...') is more likely # to appear, and debug(9, '...') least likely. ## sub debug { my $level = $_[0]; my $str = $_[1]; if ($level <= $DEBUGLEVEL) { print STDOUT $str; } } sub debugln { debug($_[0], $_[1] . "\n"); } ## # debugentry(level, funcname, @_); # Show the function entry with args if level is <= current debug level. ## sub debugentry { my $n = $#_; my $argstr = ""; my $i = 2; while ($i <= $n) { if ($i != 2) { $argstr .= ", "; } $argstr .= $_[$i]; $i++; } debugln($_[0], $_[1] . "(" . $argstr . ")"); } ## # warning(string) # Show a warning to user. ## sub warning { print STDERR "$curfile: Warning: " . $_[0] . "\n"; } ## # create_test(filename); # Put a test file into place. ## sub create_test { my $file = $_[0]; unlink($file); open OUT, ">$file" || die("Cannot create $file"); # basic tests, also with '' delimiter print OUT "" . "\n" . "\n" . "