; $VER: Update-term4.6 1.1 (14.6.96)

(complete 0)

(message (cat "This script will update `term' v4.6 to v4.6a. Before the program "
              "is updated, a backup copy of your old v4.6 release will be made "
              "just in case something goes wrong. This requires that you have "
              "at least 600K bytes free storage space available on your hard "
              "disk drive. The script can tell the plain 68k version and the 030 "
              "version apart, so you do not need to worry about picking the wrong "
              "version."
))

(set original (askfile (prompt "Please locate the `term' v4.6 program")
                       (default "TERM:")
                       (help (cat "Before the installation can proceed "
                                  "you need to indicate where `term' 4.6 "
                                  "was installed."
                       ))
))

(if (<> (exists original (noreq)) 1)
(
    (abort (cat "Could not locate file " original))
))

(set size (getsize original))
(set vers (getversion original))
(set version (/ vers 65536))
(set revision (- vers (* version 65536)))
(set spaceleft (getdiskspace original))

(if (< spaceleft 600000)
(
    (abort (cat ("Not enough storage space left, %ld bytes are available, we need at least 600,000 bytes." spaceleft)))
))

(if (= 0 version)
(
    (abort (cat ("Sorry, %s cannot be patched." original)))
))

(if (and (<> size 582252) (<> size 576732))
(
    (abort (cat ("Hm... %s does not look like `term' v4.6." original)))
))

(if (or (<> version 4) (and (= version 4) (<> revision 6)))
(
    (abort (cat ("Who do you think you're fooling, this is v%ld.%ld, not v4.6." version revision)))
))

(set @default-dest (pathonly original))

(rename original (tackon @default-dest "term-4.6-old"))

(if (= size 576732)
    (set patchfile "term46a030.pch")
    (set patchfile "term46a68k.pch")
)

(working "Updating `term' to v4.6a")

(run ("spatch -o%s -p%s %s" (tackon @default-dest "term") patchfile (tackon @default-dest "term-4.6-old")))

(complete 100)

(exit ("Your old %s file was renamed to %s." original (tackon @default-dest "term-4.6-old")))
