#!/usr/bin/perl -d:Slides
# SLIDES - SLIck's DEvelopment Suite

# Copyright (c) 2001 Matt Ficken. All rights reserved.
# Any use of this program is subject to explicit permission of Matt Ficken.
# (Thus if Matt gives you a copy, you can't just go give it to someone else)

# AUTHOR: Slick aka - Matt Ficken
# DATE: 26 September 2001
# DESCRIPTION: This launches the Slides module without the user needing to enter in
#								complex command-line options to the perl interpreter

# tell DB that this program is the Starter, (not a script to be debugged)
DB->SetStarter; # needs to be the first line executed!
# if the -? or -h command-line option was used (@ARGV contains command-line options)
if ( lc($ARGV[0]) eq "-\?" or lc($ARGV[0]) eq "-h" ) {
	# show the HELP message then exit
	print <<MSG_END;
Slides - SLIck's DEvelopment Suite

USAGE: slides [options and optional filename]
OPTIONS:
	-h Displays this message and exits
	-? Displays this message and exits
	-i[interface name]  Specifies Interface
	-in[filename] Installs the interface contained within [filename]
	-r[filename]  Sets [filename] to record into
	-noi  States that no interface is to be used
	-p[filename]  Plays PPR recording specified in [filename]
	-li     Shows List Of Interfaces And Exits
	-si[type] Lets User Specify Types Of Interfaces To Select From, ex: Tk
	[filename] Loads [filename] for Recording
EXAMPLES:
	slides -iTk::VCR foo.pl       (runs foo.pl using the Tk::VCR interface)
	slides -inTk::VTR             (installs the interface Tk::VTR)
	slides -rtape.ppr -noi foo.pl (records execution of foo.pl into tape.ppr)
	slides -ptape.ppr -noi        (plays tape.ppr back so execution can be viewed)
	slides -li                    (shows interfaces, then exits)
	slides -siTk                  (opens Tk interface selector)
	slides -siWin32-GUI           (opens Win32::GUI interface selector)
FOR MORE: see 'man Slides' or 'perldoc Slides'
MSG_END
	exit;
	
} # end of if statement checking for -h or -? option
my %args; # variable storing settings to be passed to the Engine
my $filename; # the filename to be loaded
# parse options
foreach my $arg (@ARGV) {
	if ( lc(substr($arg,0,4)) eq "-noi") { $args{-noi} = 1;
	} elsif ( lc(substr($arg,0,3)) eq "-in") {
		# install interface
	} elsif ( lc(substr($arg,0,2)) eq "-i" ) {
		# load interface
	} elsif ( -e $arg ) {
		if ( $filename ) { print STDERR "Slides: Only One File Can Be Loaded At A Time!\n";
		} else { $filename = $arg; }
	} else { print STDERR "Slides: Invalid Parameter $arg!\n"; }
}

# set configuration options
DB->Configure(%args);
while (1) {
	# use eval { } not eval ( ) !!
	eval { require ($filename); };
# >> the file is recompiled each time so any changes will take effect without restarting program!!
	if ($@) {
		# ignore the error if it is just not returning a true value
		if ( $@ =~ /$filename did not return a true value/i ) {
			$@ = substr($@,index($@,/$filename did not return a true value/i),);
			$@ = substr($@,index($@,"line"),);
			$@ = substr($@,index($@,".")+1,);
			chomp ($@);
			if ( $@ eq " " ) { $@ = ''; }
		}
		if ( $@ ) {
			print "error: '$@'\n";
			# load interfaces to fix the problem!
		}
	}
	DB->R; # reset to beginning of tape
	print "Slides: Restarting!\n";
}

# TODO
	# 1 - get variable types
	# 2 - get swapping to work
	# 3 - load TAPE for playback (as part of Slides::PPR)
	# 4 - Detecting Tk Events
# BUGLIST
	# 1 - Tk windows canvas stay up after restart!!
		# get Tk hashes for Visual Tk
		# destroy them on restart!
		
# FEATURES
	# 1 - no standard interface, U make your own
	# 2 - set subs/modules as 'INTERESTING' otherwise they are skipped over
	# 3 - records programs
1;