#!/bin/sh
# The next line restarts using tclsh8.2 \
exec tclsh8.2 $0 ${1+"$@"}

set dirs ". ./unix ./generic ./doc ./tests"
set date [clock format [clock seconds] -format "%m/%d/%Y"]

#
# This is a tcl-script that will search a list of directories
# for ".orig"-files. For all of these it will make a "diff",
# and create a patch-file.
#
#	Written by:	Jan Nijtmans
#			CMG (Computer Management Group) Arnhem B.V.
#			email: j.nijtmans@chello.nl (private)
#			       jan.nijtmans@cmg.nl (work)
#			url:   http://purl.oclc.org/net/nijtmans/

set file [open imgpatch.orig w]
close $file

puts stdout "creating patch.tk82"
set file [open patch.tk82 w]
puts $file "patch.tk82 -   $date

This patch file fixes Tk8.2 for use with the Img package. It
should be applied by running the \"patch\" program in the top-
level directory of a clean Tk8.2 release, using the command
\"patch -p0 <patch.tk82\". This patch can safely be used in
combination with the \"dash-\" and \"plus-\"patches for Tk8.2,
as well as any other patch that doesn't influence the \"image\"
command or any of the photo format handlers.

Unfortunately the patch utility supplied by Solaris does not work
with this patch file. This is a known Solaris problem. Better
install GNU patch version 2.1 or later.
"

close $file
set filelist {}
foreach dir $dirs {
    set files [eval exec ls $dir]
    foreach file $files {
	if {[regexp ".*\.orig" $file]} {
	    set file [file join $dir [file rootname $file]]
	    set file [string range $file 2 [string length $file]]
	    lappend filelist $file
	    puts stdout "diff -c $file.orig and $file"
	    catch [list exec diff -c $file.orig $file >>patch.tk82]
	}
    }
}

file delete imgpatch.orig

puts stdout "creating patchtk8.tgz"
eval exec tar cf patchtk8.tar $filelist
exec gzip patchtk8.tar
exec mv patchtk8.tar.gz patchtk8.tgz
puts stdout "creating patchtk8.zip"
eval exec zip patchtk8.zip $filelist
