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

set dirs "./unix ./generic ./tests ./library"
set package "i"
set version "4.1"
set date "6/11/96"

#
# 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
#			NICI (Nijmegen Institute of Cognition and Information)
#			email: nijtmans@nici.kun.nl
#			url:   http://www.nici.kun.nl/~nijtmans/

set patchlevel ""
set dfiles ""

set file [open ipatch.orig w]
close $file
catch "exec diff -c ipatch.orig ipatch >ipatch.diff"

foreach dir $dirs {
    set files [eval exec ls $dir]
    foreach file $files {
	if {[regexp ".*\.orig" $file]} {
	    set file [file join $dir [string range $file 0 [expr [string length $file]-6]]]
	    if {$file=="$dir/patchlevel.h"} {
		set patchlevel $file.diff
	    } else {
		lappend dfiles $file.diff
	    }
	    set file [string range $file 2 [string length $file]]
	    puts stdout "creating $file.diff"
	    catch "exec diff -c $file.orig $file >$file.diff"
	}
    }
}

puts stdout "creating tk${version}${package}.patch"
set file [open tk${version}${package}.patch w]
puts $file ""
puts $file "tk${version}${package}.patch -   $date"
puts $file ""
puts $file "This patch file updates from Tcl ${version} (or Tcl ${version}+ or Tcl ${version}dash)"
puts $file "to Tcl ${version}${package}. It should be applied by running the \"patch\" program"
puts $file "in the top-level directory of a clean Tk ${version} or Tk ${version}+ or"
puts $file "Tk ${version}dash release, using the command \"patch -p <tk${version}${package}.patch\""
puts $file ""
puts $file [eval exec cat $patchlevel ipatch.diff $dfiles]
close $file

exec rm -f ipatch.orig ipatch.diff
