#!/usr/bin/wish
#############################################################################
# Visual Tcl v1.20 Project
#
	if {$tcl_platform(platform) == "windows"} {
		button .b -text " This program can only create spec files when run from Wnidows\n\
		Function not ready yet." -command { exit }
		pack .b
	} else {


#################################
# GLOBAL VARIABLES
#

#################################
# USER DEFINED PROCEDURES
#

proc check_user {} {
	upvar 2 tcl_platform(platform) platform
	if {$platform == "unix"} {
		# Check if user is root
		set stream [open "|whoami" r]
		gets $stream user
		close $stream
	
		# if user is not root
		if {$user != "root"} {
			puts "This program need superuser privilege. Run as root"
			exit
		}
	}
}

proc check_rpmbuilderconf {} {
	upvar 2 tcl_platform(platform) platform
	if {$platform == "unix"} {
		# Check whether /etc/rpmbuilder exist
		if ![file exists /etc/rpmbuilder.conf] {
			set msg " File \"/etc/rpmbuiler.conf\" does not exist.\n\
			If you have are using RPM 3.x.x you will need one from the website (http://www.klabs.net/rpmbuilder)."
			puts $msg
	
			#tk_messageBox -icon error -type ok -title Alert -message $msg
		}
	} else {
	}
}

proc init {argc argv} {
	global sourcedir specdir
	global platform
	upvar tcl_platform(platform) platform

	check_user

	# get sourcedir & specdir

	upvar 1 tcl_platform(platform) platform
	if {$platform == "unix"} {
		if ![file exists /etc/rpmbuilder.conf] {
			set stream [open "|rpm --showrc | grep sourcedir" r]
		} else {
			set stream [open "|cat /etc/rpmbuilder.conf | grep sourcedir" r]
		}
		foreach contents [read $stream] {
			if [regexp ^\/ $contents] {
				set sourcedir $contents
				#puts $sourcedir
			}
		}
		close $stream
	
		if ![file exists /etc/rpmbuilder.conf] {
			set stream [open "|rpm --showrc | grep specdir" r]
		} else {
			set stream [open "|cat /etc/rpmbuilder.conf | grep specdir" r]
		}
		
		foreach contents [read $stream] {
			if [regexp ^\/ $contents] {
				set specdir $contents
				#puts $specdir
			}
		}
		close $stream
	} else {
	}	
}

init $argc $argv

proc {main} {argc argv} {
	check_rpmbuilderconf
}



proc new {} {
    	# Clear entry 
	.top.summary.02 delete 0 end
	.top.name.02 delete 0 end
	.top.name.04 delete 0 end
	.top.name.06 delete 0 end
	.top.source.02 delete 0 end
	.top.patch.02 delete 0 end
	.top.patch.05 delete 0 end
	
	# Clear Listbox
	.top.desctext.03 delete 1.0 end

	.top.frmfile.lbfile.01 delete 0 end
	.top.frmfile.execfile.02 delete 0 end
	.top.frmfile.execfiles.01 delete 0 end
	.top.frmfile.docfiles.01 delete 0 end
	.top.frmfile.conffiles.01 delete 0 end
	.top.frmfile.manpages.01 delete 0 end

	# Disable Build button
	.top.frmbtn2.btnbuild configure -state {disabled}

	# Clear global variable
}

proc open_file {} {
	global pathname

	set types {
		{{Gzip Files} {.gz} }
		{{Gzip & Tar Files} {.tgz} }
		{{All Files}    *       }
	}
    
	set pathname [tk_getOpenFile -filetypes $types]
    
	if {$pathname != ""} {
		# Open the file selection box...
		#puts $pathname
		set filename [file tail $pathname]
		#puts $filename

		new
	
		set one [string first - $filename]
		set two [string first _ $filename]

		if {$one > $two} {
			set index_first $one
		} else {
			set index_first $two
		}
		#puts $index_first
	
		# Match both ".tar.gz" and ".tgz"
		set index_second [string last ".t" $filename]
		#puts $index_seconda
	
		# Extract name and version
		
		set name [string range $filename 0 [expr $index_first-1]]
		#puts $name
		.top.name.02 insert 0 $name
		
		set version [string range $filename [expr $index_first+1] \
			[expr $index_second-1]]
		#puts $version
	
		.top.name.04 insert 0 $version
		.top.name.06 insert 0 1
		.top.source.02 insert 0 $filename
	
		# Enable Build button
		.top.frmbtn2.btnbuild configure -state {normal}
		
		# Fill file list box
		set stream [open "|tar tzf $pathname" r]
		foreach file [split [read $stream] \n] {
		    if { $file != ""  } {
			#puts $file
			.top.frmfile.lbfile.01	insert end $file
	
			#fill the man page list box
			if [regexp {\.[1-8ln]$} $file] {
					.top.frmfile.manpages.01 insert end $file
			}
	
		    }
		}
		close $stream
	}
}

proc about {} {
	set msgboxIcon info
	set msgboxType ok
	set button [tk_messageBox -icon $msgboxIcon \
		-type $msgboxType \
		-title About... \
		-message "RPM Builder. 0.5-2\nWritten by Seek3r.\n\
		Seek3r@Klabs.net\nhttp://www.klabs.net/rpmbuilder"]
}

proc patch {} {
	global patchfile_pathname

	set types {
 		{{Patch Files} {.patch} }
		{{All Files}    *       }
	}

	# Open File Selection Box
	set patchfile_pathname [tk_getOpenFile -filetypes $types]

	if {$patchfile_pathname != ""} {
	    	#puts $patchfile_pathname
		set patchfilename [file tail $patchfile_pathname]
		#puts $patchfilename
 
    		# Open the file ...
    		.top.patch.02 delete 0 end
    		.top.patch.02 insert 0 $patchfilename
	}
}

proc icon {} {
	global iconfile_pathname
	
	set types {
    		{{Gif Files} {.gif} }
		{{GIF Files} {} GIFF }
    		{{All Files} * }
	}
	
	# Open File Selection Box
	set iconfile_pathname [tk_getOpenFile -filetypes $types]

	if {$iconfile_pathname != ""} {
    		#puts $iconfile_pathname
		set iconfilename [file tail $iconfile_pathname]
		#puts $iconfilename
 
    		# Open the file ...
    		.top.patch.05 delete 0 end
    		.top.patch.05 insert 0 $iconfilename
		Window show .top17
	}
}


proc build {} {
	global copyright group specdir pathname sourcedir \
	iconfile_pathname patchfile_pathname

	# Get information from entry widget.
	set summary [.top.summary.02 get]
	set name [.top.name.02 get]
	set version [.top.name.04 get] 
	set release [.top.name.06 get]
	set source [.top.source.02 get] 
	set patch [.top.patch.02 get]
	set icon [.top.patch.05 get]

	set description [.top.desctext.03 get 1.0 end]

	set execfiles [.top.frmfile.execfiles.01 get 0 end]
	set docfiles [.top.frmfile.docfiles.01 get 0 end]
	set conffiles [.top.frmfile.conffiles.01 get 0 end] 
	set manpages [.top.frmfile.manpages.01 get 0 end]

	# Write the Spec File
	set specfile "Summary:\t$summary\n"
	append specfile "Name:\t\t$name\n"
	append specfile "Version:\t$version\n"
	append specfile "Release:\t$release\n"
	# if Icon File Exists
	if {$icon != ""} {
		append specfile "Icon:\t\t$icon\n"
	}

	append specfile "Copyright:\t$copyright\n"
	append specfile "Group:\t$group\n"
	append specfile "Source:\t$source\n"

	# Set bindir
	if [regexp ^X11 $group] {
		set bindir /usr/X11/bin
	} else {
		set bindir /usr/bin
	}
	
	if {$patch != ""} {
		append specfile "Patch:\t$patch\n"
	}
	
	append specfile "%description\n"
	append specfile "$description\n"
	append specfile "%prep\n"
	append specfile "%setup\n"
	
	if {$patch != ""} {
	    append specfile "%patch -p1\n"
	}
	
	append specfile "\n%build\n"
	
	set filelist [.top.frmfile.lbfile.01 get 0 end]
	
	
	foreach file [split $filelist " "] {
		# if "./configure" File Exists
		# add ".configure" to install script
		if [string match *configure $file] {
			append specfile "./configure -prefix=/usr\n"
			append specfile "make RPM_OPT_FLAGS=\"\$RPM_OPT_FLAGS\"\n"
			#puts "./configure included"
		# if "./configure" File Exists
			# add "make..." to install script
		} elseif [string match *Makefile $file] {
			append specfile "make RPM_OPT_FLAGS=\"\$RPM_OPT_FLAGS\"\n"
			#puts "./configure included"
		}
	}							
	
	append specfile "%install\n"
	
	# Install Executive File 
	foreach file $execfiles {
		append specfile "install -s -m 755 -o 0 -g 0 $file $bindir/$file\n"
	}
	
	# Install Manual Pages
	foreach file $manpages {
		set category [string index [file extension $file] 1]
		append specfile "install -m 644 -o 0 -g 0 $file /usr/man/man$category/$file\n"
	}
	
	# Install Configuration Files
	foreach file $conffiles {
		append specfile "install -c -m 644 $file /etc/$file\n"
	}
	
	# Add File List
	append specfile "\n%files\n"
	
	if {$docfiles != ""} {
		append specfile "%doc $docfiles\n"
	}
	
	if {$conffiles != ""} {
		append specfile "%config"
	
		foreach file $conffiles {
			append specfile " /etc/$file"
		}
		append specfile "\n"
	}
	
	append specfile "\n"
	
	foreach file $execfiles {
		append specfile "$bindir/$file\n"
	}
	
	foreach file $manpages {
		set category [string index [file extension $file] 1]
		append specfile "/usr/man/man$category/$file\n"
	}
	#puts $specfile
	
	# Construct Specfilename
	set specfilename "$name-$version-$release.spec"
	#puts $specfilename
	
	# Write to Specfile
	set stream [open "$specdir/$specfilename" w]
	puts $stream $specfile
	close $stream
	
	# Copy tar file to source dir
	exec cp $pathname $sourcedir
	
	   
	# Copy Icon file to source dir
	if [info exists iconfile_pathname] {
		exec cp $iconfile_pathname $sourcedir
	}
	
	# Copy Patch file to source dir
	if [info exists patchfile_pathname] {
		exec cp $patchfile_pathname $sourcedir
	}
	
	# Build package
	
	set curdir [exec pwd]
	cd $specdir 
	set d [exec rpm -ba $specfilename 2> /var/log/rpmbuilder]
	#puts $d
	# Display Build Result Dialog Box
	tk_messageBox -icon info -type ok -title "Build Result"\
	-message "Package is built successfully."
	cd $curdir

}

# Clipboard Procedure
proc copy {} {
	if [catch {selection get} sel] {
		if [catch {selection get -selection CLIPBOARD} sel] {
			# no selection or clipboard data
			return
		}
	}
											
	clipboard clear
	clipboard append [selection get]
}

proc paste {} {
	if [catch {selection get} sel] {
		if [catch {selection get -selection CLIPBOARD} sel] {
			# no selection or clipboard data
			return
		}
	}
	[focus] insert insert $sel
}

proc {Window} {args} {
	global vTcl
	set cmd [lindex $args 0]
	set name [lindex $args 1]
	set newname [lindex $args 2]
	set rest [lrange $args 3 end]
	if {$name == "" || $cmd == ""} {return}
	if {$newname == ""} {
		set newname $name
    	}
	set exists [winfo exists $newname]
	switch $cmd {
	        show {
			if {$exists == "1" && $name != "."} {wm deiconify $name; return}
			if {[info procs vTclWindow(pre)$name] != ""} {
				eval "vTclWindow(pre)$name $newname $rest"
			}
	        	if {[info procs vTclWindow$name] != ""} {
				eval "vTclWindow$name $newname $rest"
			}	
			if {[info procs vTclWindow(post)$name] != ""} {
				eval "vTclWindow(post)$name $newname $rest"
			}
	        }
	        hide    { if $exists {wm withdraw $newname; return} }
	        iconify { if $exists {wm iconify $newname; return} }
	        destroy { if $exists {destroy $newname; return} }
    	}
}

#################################
# VTCL GENERATED GUI PROCEDURES
#

proc vTclWindow. {base} {
    if {$base == ""} {
        set base .
    }
    ###################
    # CREATING WIDGETS
    ###################
    wm focusmodel $base passive
    wm geometry $base 1x1+0+0
    wm maxsize $base 1009 738
    wm minsize $base 1 1
    wm overrideredirect $base 0
    wm resizable $base 1 1
    wm withdraw $base
    wm title $base "vt.tcl"
    ###################
    # SETTING GEOMETRY
    ###################
}

proc vTclWindow.top {base} {

	global copyright group

    if {$base == ""} {
        set base .top
    }
    if {[winfo exists $base]} {
        wm deiconify $base; return
    }
    ###################
    # CREATING WIDGETS
    ###################
    toplevel $base -class Toplevel
    wm focusmodel $base passive
    wm geometry $base 600x730+165+43
    wm maxsize $base 1009 738
    wm minsize $base 1 1
    wm overrideredirect $base 0
    wm resizable $base 1 1
    wm deiconify $base
    wm title $base "RPM Builder"
	wm protocol $base WM_DELETE_WINDOW { destroy . }
    frame $base.menu \
        -borderwidth {1} -height {30} -relief {raised} -width {30} 
    menubutton $base.menu.01 \
        -anchor {w} -menu {.top.menu.01.02} -padx {4} -pady {3} \
        -text {File} -width {4} -underline 0
    menu $base.menu.01.02 \
        -cursor {} -tearoff {0}
	$base.menu.01.02 add command \
		-accelerator {Ctrl-N} -command {new} -label {New} -underline 0
    $base.menu.01.02 add command \
        -accelerator {Ctrl-O} -command {open_file} \
        -label {Open...} -underline 0
    $base.menu.01.02 add separator
    $base.menu.01.02 add command \
        -accelerator {Ctrl-B} -command {build} \
        -label {Build} -underline 0
    $base.menu.01.02 add separator
    $base.menu.01.02 add command \
        -accelerator {Ctrl-X} -command {exit} -label {Exit} -underline 1
    menubutton $base.menu.03 \
        -anchor {w} -menu {.top.menu.03.04} -padx {4} -pady {3} \
        -text {Edit} -width {4} -underline 0
    menu $base.menu.03.04 \
        -tearoff {0}
    $base.menu.03.04 add command \
        -label {Copy} -command {copy}
    $base.menu.03.04 add command \
        -label {Paste} -command {paste}
    menubutton $base.menu.05 \
        -anchor {w} -menu {.top.menu.05.06} -padx {4} -pady {3} \
        -text {Help} -width {4} -underline 0
    menu $base.menu.05.06 \
        -cursor {} -tearoff {0}
    $base.menu.05.06 add command \
        -accelerator {Crtl-A} -label {About...} -state {active} \
		-underline 0 \
        -command {about}
    frame $base.fileinfo \
        -borderwidth {1} -height {30} -relief {flat} -width {30} 
    label $base.fileinfo.01 \
        -anchor {w} -text {File Information} -width {330} 
    frame $base.summary \
        -borderwidth {1} -height {30} -relief {raised} -width {30} 
    label $base.summary.01 \
        -anchor {w} -text {Summary} 
    entry $base.summary.02 \
        -cursor {} -highlightthickness {0} -width {217} 
    frame $base.name \
        -borderwidth {1} -height {30} -relief {raised} -width {30} 
    label $base.name.01 \
        -anchor {w} -text {Name} 
    entry $base.name.02 \
        -cursor {} -highlightthickness {0} -width {30} 
    label $base.name.03 \
        -anchor {w} -text {Version} 
    entry $base.name.04 \
        -cursor {} -highlightthickness {0} -width {20} 
    label $base.name.05 \
        -anchor {w} -text {Release} 
    entry $base.name.06 \
        -cursor {} -highlightthickness {0} -width {10} 
    frame $base.copyright \
        -borderwidth {1} -height {30} -relief {raised} -width {30} 
    label $base.copyright.01 \
        -anchor {w} -text {Copyright} 
    tk_optionMenu $base.copyright.copyright copyright \
	GPL BSD MIT "Public Domain" Distributable Commercial
    label $base.copyright.03 \
        -anchor {w} -text {Group} 
	tk_optionMenu $base.copyright.group group \
		Applications \
		Applications/Communications \
		Applications/Editors \
		Applications/Editors/Emacs \
		Applications/Engineering \
		Applications/Spreadsheets \
		Applications/Databases \
		Applications/Graphics \
		Applications/Networking \
		Applications/Mail \
		Applications/Math \
		Applications/News \
		Applications/Publishing \
		Applications/Publishing/TeX \
		Base \
		Base/Kernel \
		Utilities \
		Utilities/Archiving \
		Utilities/Console \
		Utilities/File \
		Utilities/System \
		Utilities/Terminal \
		Utilities/Text \
		Daemons \
		Documentation \
		X11 \
		X11/XFree86 \
		X11/XFree86/Servers \
		X11/Applications \
		X11/Applications/Graphics \
		X11/Applications/Networking \
		X11/Games \
		X11/Games/Strategy \
		X11/Games/Video \
		X11/Amusements \
		X11/Utilities \
		X11/Libraries \
		"X11/Window Managers" \
		Libraries \
		Networking \
		Networking/Admin \
		Networking/Daemons \
		Networking/News \
		Networking/Utilities \
		Development \
		Development/Debuggers \
		Development/Libraries \
		Development/Libraries/Libc \
		Development/Languages \
		Development/Languages/Fortran \
		Development/Languages/Tcl \
		Development/Building \
		"Development/Version Control" \
		Development/Tools \
		Shells \
		Games

    frame $base.source \
        -borderwidth {1} -height {30} -relief {raised} -width {30} 
    label $base.source.01 \
        -anchor {w} -text {Source} 
    entry $base.source.02 \
        -cursor {} -highlightthickness {0} -width {207} 
    frame $base.patch \
        -borderwidth {1} -height {30} -relief {raised} -width {30} 
    label $base.patch.01 \
        -anchor {w} -text {Patch} 
    entry $base.patch.02 \
        -cursor {} -highlightthickness {0} -width {20}
    button $base.patch.03 \
        -command {patch} \
        -padx {9} -pady {3} -text {Browse...}
    label $base.patch.04 \
        -anchor {w} -text {Icon} 
    entry $base.patch.05 \
        -cursor {} -highlightthickness {0} -width {20}
    button $base.patch.06 \
        -command {icon} \
        -padx {9} -pady {3} -text {Browse...} 
    frame $base.description \
        -borderwidth {1} -height {30} -relief {flat} -width {30} 
    label $base.description.01 \
        -anchor {w} -text {Description} -width {237} 
    frame $base.desctext \
        -borderwidth {1} -height {46} -relief {raised} -width {191} 
    scrollbar $base.desctext.01 \
        -borderwidth {1} -command {.top.desctext.03 xview} -orient {horiz} \
        -width {10} 
    scrollbar $base.desctext.02 \
        -borderwidth {1} -command {.top.desctext.03 yview} -orient {vert} \
        -width {10} 
    text $base.desctext.03 \
        -font {-Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*} \
        -height {6} -width {118} -xscrollcommand {.top.desctext.01 set} \
        -yscrollcommand {.top.desctext.02 set} 
    frame $base.files \
        -borderwidth {1} -height {30} -relief {flat} -width {241} 
    label $base.files.01 \
        -anchor {w} -text {Files} -width {198} 
    frame $base.frmfile \
        -borderwidth {2} -height {415} -relief {groove} -width {125} 
    frame $base.frmfile.lbfile \
        -borderwidth {1} -height {20} -relief {raised} -width {20} 
    listbox $base.frmfile.lbfile.01 \
        -font {-Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*} \
        -height {10} -width {33} -xscrollcommand {.top.frmfile.lbfile.02 set} \
        -yscrollcommand {.top.frmfile.lbfile.03 set} 
    scrollbar $base.frmfile.lbfile.02 \
        -borderwidth {1} -command {.top.frmfile.lbfile.01 xview} \
        -orient {horiz} -width {10} 
    scrollbar $base.frmfile.lbfile.03 \
        -borderwidth {1} -command {.top.frmfile.lbfile.01 yview} \
        -orient {vert} -width {10} 
    frame $base.frmfile.frmbtn \
        -borderwidth {2} -height {75} -relief {groove} -width {79} 
    button $base.frmfile.frmbtn.but51 \
        -padx {9} -pady {3} -text {-->} \
		-command {
		set curfile [.top.frmfile.lbfile.01 get active]
			if {$curfile != ""} {
				.top.frmfile.execfiles.01 insert end \
					[file tail $curfile]
			}
		}
    button $base.frmfile.frmbtn.but52 \
        -padx {9} -pady {3} -text {-->} \
		-command {
		set curfile [.top.frmfile.lbfile.01 get active]
			if {$curfile != ""} {
				.top.frmfile.docfiles.01 insert end \
					[file tail $curfile]
			}
		}
    button $base.frmfile.frmbtn.but53 \
        -padx {9} -pady {3} -text {-->} \
		-command {
		set curfile [.top.frmfile.lbfile.01 get active]
			if {$curfile != ""} {
				.top.frmfile.conffiles.01 insert end \
					[file tail $curfile]
			}
		}
    button $base.frmfile.frmbtn.but54 \
        -padx {9} -pady {3} -text {-->}
	frame $base.frmfile.execfile \
		-borderwidth {1} -relief {raised} 
	label $base.frmfile.execfile.01 \
		-anchor {w} -text {Execution Files} 
	entry $base.frmfile.execfile.02 \
		-cursor {} -highlightthickness {0} -width {217}
    frame $base.frmfile.execfiles \
        -borderwidth {1} -relief {raised} -width {30} 
    listbox $base.frmfile.execfiles.01 \
        -font {-Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*} \
        -height {2} -xscrollcommand {.top.frmfile.execfiles.02 set} \
        -yscrollcommand {.top.frmfile.execfiles.03 set} 
    scrollbar $base.frmfile.execfiles.02 \
        -borderwidth {1} -command {.top.frmfile.execfiles.01 xview} \
        -orient {horiz} -width {10} 
    scrollbar $base.frmfile.execfiles.03 \
        -borderwidth {1} -command {.top.frmfile.execfiles.01 yview} \
        -orient {vert} -width {10} 
    label $base.frmfile.lab41 \
        -borderwidth {1} -relief {raised} \
		-padx {3} -pady {3} -text {Document Files} 
    frame $base.frmfile.docfiles \
        -borderwidth {1} -relief {raised} -width {30} 
    listbox $base.frmfile.docfiles.01 \
        -font {-Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*} \
        -height {2} -xscrollcommand {.top.frmfile.docfiles.02 set} \
        -yscrollcommand {.top.frmfile.docfiles.03 set} 
    scrollbar $base.frmfile.docfiles.02 \
        -borderwidth {1} -command {.top.frmfile.docfiles.01 xview} \
        -orient {horiz} -width {10} 
    scrollbar $base.frmfile.docfiles.03 \
        -borderwidth {1} -command {.top.frmfile.docfiles.01 yview} \
        -orient {vert} -width {10} 
    label $base.frmfile.lab43 \
        -borderwidth {1} -relief {raised} \
		-padx {3} -pady {3} -text {Configuration Files} 
    frame $base.frmfile.conffiles \
        -borderwidth {1} -relief {raised} -width {30} 
    listbox $base.frmfile.conffiles.01 \
        -font {-Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*} \
        -height {2} -xscrollcommand {.top.frmfile.conffiles.02 set} \
        -yscrollcommand {.top.frmfile.conffiles.03 set} 
    scrollbar $base.frmfile.conffiles.02 \
        -borderwidth {1} -command {.top.frmfile.conffiles.01 xview} \
        -orient {horiz} -width {10} 
    scrollbar $base.frmfile.conffiles.03 \
        -borderwidth {1} -command {.top.frmfile.conffiles.01 yview} \
        -orient {vert} -width {10} 
    label $base.frmfile.lab45 \
        -borderwidth {1} -relief {raised} \
		-padx {3} -pady {3} -text {Manual Pages} 
    frame $base.frmfile.manpages \
        -borderwidth {1} -relief {raised} -width {30} 
    listbox $base.frmfile.manpages.01 \
        -font {-Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-*} \
        -height {2} -xscrollcommand {.top.frmfile.manpages.02 set} \
        -yscrollcommand {.top.frmfile.manpages.03 set} 
    scrollbar $base.frmfile.manpages.02 \
        -borderwidth {1} -command {.top.frmfile.manpages.01 xview} \
        -orient {horiz} -width {10} 
    scrollbar $base.frmfile.manpages.03 \
        -borderwidth {1} -command {.top.frmfile.manpages.01 yview} \
        -orient {vert} -width {10}
    frame $base.frmbtn2 \
        -borderwidth {2} -height {100} -relief {groove} -width {125} 
    button $base.frmbtn2.btnbuild \
        -padx {9} -pady {3} -text {Build} -underline 0 -command {build} \
		-state {disabled}
    button $base.frmbtn2.btnreset \
        -padx {9} -pady {3} -text {Reset} -underline 0 -command {new}
    ###################
    # SETTING GEOMETRY
    ###################
    pack $base.menu \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.menu.01 \
        -in {.top.menu} -anchor {center} -expand {0} -fill {none} \
        -side {left} 
    pack $base.menu.03 \
        -in {.top.menu} -anchor {center} -expand {0} -fill {none} \
        -side {left} 
    pack $base.menu.05 \
        -in {.top.menu} -anchor {center} -expand {0} -fill {none} \
        -side {right} 
    pack $base.fileinfo \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.fileinfo.01 \
        -in {.top.fileinfo} -anchor {center} -expand {0} -fill {x} -padx {2} \
        -pady {2} -side {left} 
    pack $base.summary \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.summary.01 \
        -in {.top.summary} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.summary.02 \
        -in {.top.summary} -anchor {center} -expand {1} -fill {x} -padx {2} \
        -pady {2} -side {right} 
    pack $base.name \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.name.01 \
        -in {.top.name} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.name.02 \
        -in {.top.name} -anchor {center} -expand {1} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.name.03 \
        -in {.top.name} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.name.04 \
        -in {.top.name} -anchor {center} -expand {1} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.name.05 \
        -in {.top.name} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.name.06 \
        -in {.top.name} -anchor {center} -expand {1} -fill {none} \
        -padx {2} -pady {2} -side {right} 
    pack $base.copyright \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.copyright.01 \
        -in {.top.copyright} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.copyright.copyright -anchor {center} -expand {1} -fill {none} \
	    -padx {2} -pady {2} -side {left}
    pack $base.copyright.03 \
        -in {.top.copyright} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.copyright.group -anchor {center} -expand {1} -fill {none} \
	    -padx {2} -pady {2} -side {right}

    pack $base.source \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.source.01 \
        -in {.top.source} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.source.02 \
        -in {.top.source} -anchor {center} -expand {1} -fill {x} -padx {2} \
        -pady {2} -side {right} 
    pack $base.patch \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.patch.01 \
        -in {.top.patch} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.patch.02 \
        -in {.top.patch} -anchor {center} -expand {1} -fill {none} -padx {2} \
        -pady {2} -side {left} 
    pack $base.patch.03 \
        -in {.top.patch} -anchor {center} -expand {0} -fill {none} -padx {2} \
        -pady {2} -side {left}
    pack $base.patch.04 \
        -in {.top.patch} -anchor {center} -expand {0} -fill {none} \
        -padx {2} -pady {2} -side {left} 
    pack $base.patch.05 \
        -in {.top.patch} -anchor {center} -expand {1} -fill {none} -padx {2} \
        -pady {2} -side {left} 
    pack $base.patch.06 \
        -in {.top.patch} -anchor {center} -expand {0} -fill {none} -padx {2} \
        -pady {2} -side {right}
    pack $base.description \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.description.01 \
        -in {.top.description} -anchor {center} -expand {0} -fill {x} -padx {2} \
        -pady {2} -side {left} 
    pack $base.desctext \
        -in {.top} -anchor {center} -expand {0} -fill {none} -side {top} 
    grid columnconf $base.desctext 0 -weight 1
    grid rowconf $base.desctext 0 -weight 1
    grid $base.desctext.01 \
        -in {.top.desctext} -column {0} -row {1} -columnspan {1} -rowspan {1} \
        -sticky {ew} 
    grid $base.desctext.02 \
        -in {.top.desctext} -column {1} -row {0} -columnspan {1} -rowspan {1} \
        -sticky {ns} 
    grid $base.desctext.03 \
        -in {.top.desctext} -column {0} -row {0} -columnspan {1} -rowspan {1} \
        -sticky {nesw} 
    pack $base.files \
        -in {.top} -anchor {center} -expand {0} -fill {x} -side {top} 
    pack $base.files.01 \
        -in {.top.files} -anchor {center} -expand {0} -fill {x} -padx {2} \
        -pady {2} -side {left} 
    pack $base.frmfile \
        -in {.top} -anchor {n} -expand {0} -fill {x} -side {top} 
    pack $base.frmfile.lbfile \
        -in {.top.frmfile} -anchor {center} -expand {0} -fill {both} \
        -side {left} 
    grid columnconf $base.frmfile.lbfile 0 -weight 1
    grid rowconf $base.frmfile.lbfile 0 -weight 1
    grid $base.frmfile.lbfile.01 \
        -in {.top.frmfile.lbfile} -column {0} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {nesw} 
    grid $base.frmfile.lbfile.02 \
        -in {.top.frmfile.lbfile} -column {0} -row {1} -columnspan {1} \
        -rowspan {1} -sticky {ew} 
    grid $base.frmfile.lbfile.03 \
        -in {.top.frmfile.lbfile} -column {1} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {ns} 
    pack $base.frmfile.frmbtn \
        -in {.top.frmfile} -anchor {center} -expand {0} -fill {y} \
        -side {left} 
    grid $base.frmfile.frmbtn.but51 \
        -in {.top.frmfile.frmbtn} -column {0} -row {0} -columnspan {1} \
        -rowspan {1} -pady {25} 
    grid $base.frmfile.frmbtn.but52 \
        -in {.top.frmfile.frmbtn} -column {0} -row {1} -columnspan {1} \
        -rowspan {1} -pady {25} 
    grid $base.frmfile.frmbtn.but53 \
        -in {.top.frmfile.frmbtn} -column {0} -row {2} -columnspan {1} \
        -rowspan {1} -pady {25} 
    grid $base.frmfile.frmbtn.but54 \
        -in {.top.frmfile.frmbtn} -column {0} -row {3} -columnspan {1} \
        -rowspan {1} -pady {25}
	pack $base.frmfile.execfile \
		-in {.top.frmfile} -anchor {center} -expand {0} -fill {x} -side {top}
	pack $base.frmfile.execfile.01 \
		-in {.top.frmfile.execfile} -anchor {center} -expand {0} -fill {none} \
		-padx {2} -pady {2} -side {left} 
	pack $base.frmfile.execfile.02 \
		-in {.top.frmfile.execfile} -anchor {center} -expand {1} -fill {x} -padx {2} \
		-pady {2} -side {right} 
    pack $base.frmfile.execfiles \
        -in {.top.frmfile} -anchor {center} -expand {0} -fill {x} -side {top} 
    grid columnconf $base.frmfile.execfiles 0 -weight 1
    grid rowconf $base.frmfile.execfiles 0 -weight 1
    grid $base.frmfile.execfiles.01 \
        -in {.top.frmfile.execfiles} -column {0} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {nesw} 
    grid $base.frmfile.execfiles.02 \
        -in {.top.frmfile.execfiles} -column {0} -row {1} -columnspan {1} \
        -rowspan {1} -sticky {ew} 
    grid $base.frmfile.execfiles.03 \
        -in {.top.frmfile.execfiles} -column {1} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {ns} 
    pack $base.frmfile.lab41 \
        -in {.top.frmfile} -anchor {w} -expand {0} -fill {none} -side {top} 
    pack $base.frmfile.docfiles \
        -in {.top.frmfile} -anchor {center} -expand {0} -fill {x} -side {top} 
    grid columnconf $base.frmfile.docfiles 0 -weight 1
    grid rowconf $base.frmfile.docfiles 0 -weight 1
    grid $base.frmfile.docfiles.01 \
        -in {.top.frmfile.docfiles} -column {0} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {nesw} 
    grid $base.frmfile.docfiles.02 \
        -in {.top.frmfile.docfiles} -column {0} -row {1} -columnspan {1} \
        -rowspan {1} -sticky {ew} 
    grid $base.frmfile.docfiles.03 \
        -in {.top.frmfile.docfiles} -column {1} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {ns} 
    pack $base.frmfile.lab43 \
        -in {.top.frmfile} -anchor {w} -expand {0} -fill {none} -side {top} 
    pack $base.frmfile.conffiles \
        -in {.top.frmfile} -anchor {center} -expand {0} -fill {x} -side {top} 
    grid columnconf $base.frmfile.conffiles 0 -weight 1
    grid rowconf $base.frmfile.conffiles 0 -weight 1
    grid $base.frmfile.conffiles.01 \
        -in {.top.frmfile.conffiles} -column {0} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {nesw} 
    grid $base.frmfile.conffiles.02 \
        -in {.top.frmfile.conffiles} -column {0} -row {1} -columnspan {1} \
        -rowspan {1} -sticky {ew} 
    grid $base.frmfile.conffiles.03 \
        -in {.top.frmfile.conffiles} -column {1} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {ns} 
    pack $base.frmfile.lab45 \
        -in {.top.frmfile} -anchor {w} -expand {0} -fill {none} -side {top} 
    pack $base.frmfile.manpages \
        -in {.top.frmfile} -anchor {center} -expand {0} -fill {x} -side {top} 
    grid columnconf $base.frmfile.manpages 0 -weight 1
    grid rowconf $base.frmfile.manpages 0 -weight 1
    grid $base.frmfile.manpages.01 \
        -in {.top.frmfile.manpages} -column {0} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {nesw} 
    grid $base.frmfile.manpages.02 \
        -in {.top.frmfile.manpages} -column {0} -row {1} -columnspan {1} \
        -rowspan {1} -sticky {ew} 
    grid $base.frmfile.manpages.03 \
        -in {.top.frmfile.manpages} -column {1} -row {0} -columnspan {1} \
        -rowspan {1} -sticky {ns}
		
	bind $base.frmfile.execfile.02 <Return> \
		{
			.top.frmfile.execfiles.01 insert end [.top.frmfile.execfile.02 get]
			.top.frmfile.execfile.02 delete 0 end
		}
	
	bind $base.frmfile.execfiles.01 <Double-1> \
		{.top.frmfile.execfiles.01 delete active}
	bind $base.frmfile.docfiles.01 <Double-1> \
		{.top.frmfile.docfiles.01 delete active}
	bind $base.frmfile.conffiles.01 <Double-1> \
		{.top.frmfile.conffiles.01 delete active}
	
    pack $base.frmbtn2 \
        -in {.top} -anchor {center} -expand {1} -fill {both} -side {top} 
    pack $base.frmbtn2.btnbuild \
        -in {.top.frmbtn2} -anchor {center} -expand {0} -fill {none} \
        -padx {10} -pady {10} -side {left} 
    pack $base.frmbtn2.btnreset \
        -in {.top.frmbtn2} -anchor {center} -expand {0} -fill {none} \
        -padx {10} -pady {10} -side {right} 
}

proc vTclWindow.top17 {base} {
	global iconfile_pathname
	
    if {$base == ""} {
        set base .top17
    }
    if {[winfo exists $base]} {
        wm deiconify $base; return
    }
    ###################
    # CREATING WIDGETS
    ###################
    toplevel $base -class Toplevel
    wm focusmodel $base passive
    wm geometry $base 72x72+100+100
    wm maxsize $base 1009 738
    wm minsize $base 1 1
    wm overrideredirect $base 0
    wm resizable $base 1 1
    wm deiconify $base
    wm title $base "Icon Preview"
	image create photo image2a
	image2a configure -file $iconfile_pathname

	frame $base.fra22 \
		-borderwidth {2} -height [image height image2a] \
		-relief {groove} -width [image width image2a]
	label $base.fra22.image -image image2a
    ###################
    # SETTING GEOMETRY
    ###################
    pack $base.fra22 \
        -in {.top17} -anchor {center} -expand {1} -fill {both} -side {top}
	pack $base.fra22.image -anchor center
}

Window show .
Window show .top

main $argc $argv

}