#!/bin/sh
# fix applets for 1.4.1

tmpfile=/tmp/fixapplets141.tmp

for file in $@
do
	echo $file
	# move setting _ns6 to before setting _ns because _ns6 might not
	# have java.lang.System.getProperty set.
	egrep -v 'var _ns6 = .*_ns == true' $file |
	awk '{ if ($0 ~ /var _ns = \(/ && noNeedToAdd == 0) {
                   print "        var _ns6 = (_info.indexOf(\"Mozilla/5\") >= 0);"
               }
               if ($0 ~ /var _ns6 = / && $0 ~ /Mozilla/ && $0 !~ /_ns == true/) {
                   # Make this idempotent
                   noNeedToAdd = 1
               }
               print $0
            }' | 
	sed \
	    -e 's@codebase="http://java.sun.com/products/plugin/1.3.1/jinstall-131-win32.cab#Version=1,3,1,0">@codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_02-windows-i586.cab#Version=1,4,1,02">@' \
	    -e 's@codebase="http://java.sun.com/products/plugin/1.4.1/jinstall-14-win32#Version=1,4,1,0">@codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_02-windows-i586.cab#Version=1,4,1,02">@' \
	    -e 's@VALUE = "application/x-java-applet;version=1.4.1" >@VALUE = "application/x-java-applet;jpi-version=1.4.1_02" >@' \
	    -e 's@VALUE = "application/x-java-applet;jpi-version=1.3.1" >@VALUE = "application/x-java-applet;jpi-version=1.4.1_02" >@' \
	    -e 's@application/x-java-applet;jpi-version=1.3.1@application/x-java-applet;jpi-version=1.4.1_02@' \
            -e 's@type = "application/x-java-applet;version=1.4.1"@type = "application/x-java-applet;jpi-version=1.4.1_02"@' \
	    -e 's@pluginspage = "http://java.sun.com/products/plugin/1.4.1/plugin-install.html">@pluginspage = "http://java.sun.com/j2se/1.4.1/download.html">@' \
	    -e 's@pluginspage = "http://java.sun.com/products/plugin/1.3.1/plugin-install.html">@pluginspage = "http://java.sun.com/j2se/1.4.1/download.html">@' \
	    -e 's@else if (_ns == true && _ns6 == false)@else if (_ns == true || _ns6 == true)@' \
	> $tmpfile
#	| grep -v '</OBJECT> \\' > $tmpfile

	diff $file $tmpfile
	cp $file $file.bak
	cp $tmpfile $file


done

#           -e 's@if (_ie == true) document.writeln(@if (_ie == true) { document.writeln(@' \


#	    -e "s@else if (_ns == true && _ns6 == false)@if (_ns6 != true) document.writeln('</OBJECT>'); } else if (_ns == true || _ns6 == true)@" \
