#!/bin/sh
# the next line restarts using wish \
exec tclsh "$0" "$@"

#    Copyright 2003 Regis Damongeot

#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

set stringTemp ""

set tkdvdinstall [open tkdvd-install.sh w]
set tkdvdmain [open TkDVD.sh r]

proc append_to_file { stringTemp } {
	global tkdvdinstall
	close $tkdvdinstall
	#delete "source" begining line and replace $source_directory
	set stringTemp [exec echo $stringTemp | cut -d / -f 2-]
	
	puts $stringTemp
	exec cat $stringTemp  >> tkdvd-install.sh
	exec echo "" >> tkdvd-install.sh
	set tkdvdinstall [open tkdvd-install.sh {WRONLY APPEND}]
}

#while we arent at the end of the file
while {! [eof $tkdvdmain] } {
	#read line and put into string temp
	gets $tkdvdmain stringTemp
	#contain "source" to other tcl files?
	if {[regexp ^source $stringTemp]} {
		puts "appending sourced tcl"
		append_to_file $stringTemp
	} else {
		#puts "writing tkdvd main line to tkdvd install script"
		puts $tkdvdinstall $stringTemp
	}
}

close $tkdvdinstall
close $tkdvdmain
