LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-29-2003, 12:52 AM   #1
CanadianPenguin
Member
 
Registered: Oct 2003
Distribution: Ubuntu "Hoary" - The best distro around by a long shot.
Posts: 116

Rep: Reputation: 15
Tcl help anyone?


So I'm writing this little program in Tcl to join files (you know, like binaries downloaded from newsgroups split into .001 .002 etc), as there is a lack of linux splitters/joiners that are any good. I have it working on the commandline and I'm trying to build a Tk interface (mostly for my own learning, but also because I might like to release it at some point). The problem I run into is with variables. When I run the joinFiles procedure by clicking the Join button, it tells me that the global variables don't exist, when clearly they do and I've defined them as global.

So, here's my code. Anyone see the problem?

Code:
#!/usr/bin/tclsh

package require Tk;

##################################################  #####################
# Adam Wolfe Gordon                                                   #
# Joiner (maybe splitter at some point)                               #
# 12/28/2003                                                          #
# Purpose: To join split files                                        #
##################################################  #####################

# Interface ##################################################  #########
# Set window information
wm title . "Joiner";
wm resizable . false false;
wm geometry . 375x150;

# Create a frame
variable top;
set top [frame .top -borderwidth 10 -width 375 -height 150];
place $top -in . -relx 0 -rely 0;

# Filename, number of parts, deletion option, skip option
variable filename, parts, delete, skip;
# And boxes/labels for them
variable filenameBox, filenameLabel, partsBox, partsLabel, deleteBox, skipBox, action, quit;

# Define the interface objects
set filenameBox [entry .top.filenameBox -width 40 -textvariable filename -bg white];
set filenameLabel [label .top.filenameLabel -text Filename:];

set partsBox [entry .top.partsBox -width 4 -textvariable parts -bg white]
set partsLabel [label .top.partsLabel -text {Number of last part:}];

set deleteBox [checkbutton .top.deleteBox -text {Delete parts files} -variable delete];
set skipBox [checkbutton .top.skipBox -text {Skip missing files} -variable skip];
set action [button .top.action -text {Join!} -command joinFiles -default active];
set quit [button .top.quit -text {Exit} -command exit];

# Place the interface objects and set defaults
place $filenameLabel -in $top -x 0 -y 0 -anchor nw;
place $filenameBox -in $top -x 65 -y 0 -anchor nw;
place $partsLabel -in $top -x 0 -y 25 -anchor nw;
place $partsBox -in $top -x 130 -y 25 -anchor nw;
place $deleteBox -in $top -x 0 -y 50 -anchor nw;
place $skipBox -in $top -x 0 -y 75 -anchor nw;
place $action -in $top -x 0 -y 100 -anchor nw;
place $quit -in $top -x 350 -y 100 -anchor ne;

# Guts ##################################################  ##############
proc joinFiles {} {
	# Previous Variables
	global filename, parts, delete, skip;
	
	# For the joining loop
	variable i, ext;
	set i 1;
	
	while {$i <= $parts} {
		# Change the extension
		if {$i < 10} {
			set ext "00$i";
		} elseif {$i < 100} {
			set ext "0$i";
		} else {
			set ext "$i";
		}
		
		# Filenames with extension
		variable filewext;
		set filewext "$filename.$ext";
		
		# Check whether each file exists
		if {[file exists $filewext]} {
			# Add it using cat if it does
			exec /bin/cat $filewext >> $filename;
			puts "Adding part $i";
			
			# Delete parts if requested
			if {$delete == "y"} {
				file delete -force $filewext;
			}
		} else {
			# Tell the user if the file doesn't exist ... Exit if they chose not to skip parts
			if {$skip != "n"} {
				puts "Missing part $i";
			} else {
				puts "Missing part $i ... Exiting!";
				break;
			}
		}
		
		# Duh...  This is important
		incr i;
	}
}
TIA all!
 
Old 12-29-2003, 03:48 AM   #2
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Rep: Reputation: 45
______________________________________________________________________________
# Filename, number of parts, deletion option, skip option
variable filename, parts, delete, skip;
______________________________________________________________________________

I guess that u missed out a global decleration here.
 
Old 12-29-2003, 01:55 PM   #3
CanadianPenguin
Member
 
Registered: Oct 2003
Distribution: Ubuntu "Hoary" - The best distro around by a long shot.
Posts: 116

Original Poster
Rep: Reputation: 15
Nope, that shouldn't be a global declaration, in Tcl global declarations go insice a procedure in order to adopt a variable defined in global scope.

Anyway, I figured out the problem thanks to someone on another board. Shouldn't have the commas between the variable names in the global declaration. It works perfectly now
 
Old 12-30-2003, 02:00 AM   #4
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Rep: Reputation: 45
OK. Thanks for sharing that
 
Old 12-30-2003, 05:42 PM   #5
CanadianPenguin
Member
 
Registered: Oct 2003
Distribution: Ubuntu "Hoary" - The best distro around by a long shot.
Posts: 116

Original Poster
Rep: Reputation: 15
NP, thought I should post the solution so that this thread can help others in the future.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tcl/Tk 8.4.7 dakota rob Solaris / OpenSolaris 3 10-27-2004 02:51 PM
What is tcl.h? divoibs Red Hat 3 09-25-2004 09:37 AM
Tcl/tk wasabi Fedora 0 06-03-2004 09:42 AM
TCL/TK vs. Qt liguorir Linux - Software 1 02-12-2004 04:54 AM
Tcl/tk ccarrieta28 Linux - Software 0 09-10-2003 02:49 PM


All times are GMT -5. The time now is 02:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration