; $VER: Words 4
; Installer script ©1996 Dietmar Eilert

(delopts "oknodelete" "force" "askuser")
(complete 0)

(onerror (

    (if (> @ioerr 0) 

        " Some error has occurred. Please inform a GoldED \n"
        " support site (e.g. dietmar@tomate.tng.oche.de)  \n"
        " AFTER having tried a different Installer release\n"
        " (1.24 is known to work fine).                   \n"
    )
))

(if (exists "GOLDED:" (NOREQ))

    (
        (set vernum (getversion "golded:golded"))

        (set ver (/ vernum 65536))
        (set rev (- vernum (* ver 65536)))

        (set version (+ (* 10 ver) rev))

        (if (< version 47)

            (
                (message "\nSorry, GoldED 4.7.0 or better required")
                (exit (quiet))
            )
        )

        (if (not (exists "libs/ixemul.library"))

            (if (not (exists "libs:ixemul.library"))

                (
                    (message "\nSorry, libs:ixemul.library required (AmiNet).")

                    (exit (quiet))
                )
            )
        )

        (complete 5)

        (message (cat "\n"

            "Words · Spellchecking for GoldED            \n"
            "                                            \n"
            "©'96/ Heinz Knutzen, Martin Schulz, Loren J.\n"
            " '97  Rittle, Jesper Skov, Dietmar Eilert.  \n"
            "                                            \n"
            "      Commercial distribution not permitted.\n"
            "      All files are the property of their   \n"
            "      authors unless stated otherwise.      \n"
            "                                            \n"
            "Requirements:                               \n"
            "                                            \n"
            "GoldED 4.7.0+, ixemul.library, 5 MB RAM     \n"
        ))

        (welcome)

        (complete 10)

        (set action (askoptions

            (prompt "\nSelect parts to be installed\n")

            (help @askoptions-help)

            (default 5)

            (choices

                "Install binaries"
                "Install dictionary: German"
                "Install dictionary: English"
            )
        ))

        (complete 15)

        ; install binaries

        (if (in action 0) (

            (if (not (exists "golded:api"))

                (makedir "golded:api")
            )

            (if (not (exists "golded:syntax"))

                (makedir "golded:syntax")
            )

            ; install registry editor (if not yet installed)

            (if (not (exists "golded:tools"))

                (makedir "golded:tools")
            )

            (if (not (exists "golded:tools/regedit"))

                (makedir "golded:tools/regedit")
            )

            (copylib

                (prompt "Install registry editor ?")
                (source "bin/regedit" )
                (dest   "golded:tools/regedit")
                (confirm)
                (help @copylib-help)
            )

            ; install syntax parser

            (copylib

                (prompt "Install syntax parser ?")
                (source "syntax/warpSPELL.parser")
                (dest   "golded:syntax")
                (confirm)
                (help @copylib-help)
            )

            (if (exists "libs/ixemul.library")

                ; install ixemul.library (required by ISpell)

                (copylib

                    (prompt "Install ixemul.library ?")
                    (source "libs/ixemul.library")
                    (dest "libs:")
                    (help @copylib-help)
                    (confirm)
                )
            )

            ; install ISpell

            (if (exists "ispell:" (quiet))

                (set target (pathonly (expandpath "ispell:")))
                (set target "sys:")
            )

            (set target (askdir

                (prompt

                    (cat "\n"

                        "Select path for ISpell installation. The drawer \n"
                        "'ISpell' is created in the directory you select:\n"
                    )
                )

                (help "A new drawer is created in the path you specify.")

                (default target)
            ))

            ; $HOME is required by ISpell; the GETENV command is broken, so we have to use EXISTS

            (if (not (exists "env:home" (NOREQ)))

                (run "echo >envarc:HOME sys:")
                (run "echo >env:HOME    sys:")
            )

            (complete 20)

            (set target (tackon target "ispell"))

            (if (not (exists target))

                (makedir target)
            )

            (makeassign "ispell" target)

            (if (not (exists "ispell:bin"))

                (makedir "ispell:bin")
            )

            (if (not (exists "ispell:doc"))

                (makedir "ispell:doc")
            )

            (if (not (exists "ispell:lib"))

                (makedir "ispell:lib")
            )

            (working "Installing ISpell...")

            (copyfiles

                (source "ispell-3.1.18bin/bin")
                (dest   "ispell:bin")
                (all)
                (nogauge)
            )

            (copyfiles

                (source "ispell-3.1.18bin/doc")
                (dest   "ispell:doc")
                (all)
                (nogauge)
            )

            (startup "WORDS"

                (prompt "Add ISpell: assign to your user-startup ?")

                (help @startup-help)

                (command ("ASSIGN >NIL: ispell: %s\nPATH ISPELL:BIN ADD" target))
            )

            (complete 25)

            ; install API client

            (copylib

                (prompt "Install API client ?")
                (source "api/words.api")
                (dest   "golded:api")
                (confirm)
                (help @copylib-help)
            )

            (if (not (exists "golded:tools/words"))

                (makedir "golded:tools/words")
            )

            ; install support files

            (copyfiles

                (source "words")
                (dest   "golded:tools/words")
                (all)
                (nogauge)
            )

            (copyfiles

                (source  "")
                (dest    "golded:tools/words")
                (pattern "#?.readme")
                (nogauge)
            )

            ; install toolbar images

            (if (exists "toolbar") (

                (set hicolor

                    (askchoice

                        (prompt "\nSelect toolbar style:\n")

                        (choices

                            "4  colors"
                            "8+ colors"
                        )

                        (default 1)

                        (help (cat "\n"

                            " You can use both styles on all screens. The 4\n"
                            " color style has been optimized for 4-color   \n"
                            " screens. The 8+ style has been optimized for \n"
                            " screens with eight or more colors.           \n"
                        ))
                    )
                )

                (if (not (exists "golded:toolbar"))

                    (makedir "golded:toolbar")
                )

                (if (not (exists "golded:toolbar/words"))

                    (makedir "golded:toolbar/words")
                )

                (copyfiles

                    (source "toolbar")
                    (dest   "golded:toolbar")
                    (all)
                    (nogauge)
                )

                (if (= hicolor 1)

                    (copyfiles

                        (source "toolbar16")
                        (dest   "golded:toolbar")
                        (nogauge)
                        (all)
                    )
                )
            ))

            (complete 30)

        ))

        ; install German dictionary

        (complete 35)

        (if (in action 1) (

            ; set default ISpell options

            (copyfiles

                (source "env/d")
                (dest "env:")
                (all)
                (nogauge)
            )

            (copyfiles

                (source "env/d")
                (dest "envarc:")
                (all)
                (nogauge)
            )

            (set partsA (askoptions

                (prompt "Select German dictionaries to be installed (1/2)")

                (help (cat "\n"

                    " The more dictionaries you select, the more \n"
                    " memory ISpell will use. File sized listed  \n"
                    " are NOT RAM requirements - RAM requirements\n"
                    " are about three times higher.              \n"
                ))

                (choices

                    "Substantive        (250 K)"
                    "Verben             (120 K)"
                    "Adjektive & Co     ( 10 K)"
                    "Zusammensetzungen  (550 K)"
                    "Geographie         ( 15 K)"
                    "Namen              (  5 K)"
                    "Abkuerzungen       (  1 K)"
                    "Imperative         (  1 K)"
                    "Latein             (  1 K)"
                )

                (default 503)
            ))

            (complete 40)

            (set partsB (askoptions

                (prompt "Select German dictionaries to be installed (2/2)")

                (help (cat "\n"

                    " The more dictionaries you select, the more \n"
                    " memory ISpell will use. File sized listed  \n"
                    " are NOT RAM requirements - RAM requirements\n"
                    " are about three times higher.              \n"
                ))

                (choices

                    "Informatik, EDV    ( 25 K)"
                    "Elektronik         ( 10 K)"
                    "Organisationen     (  1 K)"
                    "Marken             (  1 K)"
                    "Griechisch         (  1 K)"
                    "Roemische Zahlen   (  1 K)"
                    "Technik            (  2 K)"
                    "Seltenes           ( 10 K)"
                )

                (default 12)
            ))

            (complete 45)

            (if (or (<> partsA 0) (<> partsB 0)) (

                (working "\nCreating dictionary, sorting entries. May take some minutes.\n")

                (delete "dictionary/deutsch/words/all.words.cnt")
                (delete "dictionary/deutsch/words/all.words.stat")

                (set cmd "bin/joinsorted >con://///AUTO DIR=dictionary/deutsch/words as=dictionary/deutsch/words/all.words ")

                (if (in partsA 0) (set cmd (cat cmd "worte.txt "      )))
                (if (in partsA 1) (set cmd (cat cmd "verben.txt "     )))
                (if (in partsA 2) (set cmd (cat cmd "klein.txt "      )))
                (if (in partsA 2) (set cmd (cat cmd "adjektive.txt "  )))
                (if (in partsA 3) (set cmd (cat cmd "zusammen.txt "   )))
                (if (in partsA 4) (set cmd (cat cmd "geographie.txt " )))
                (if (in partsA 4) (set cmd (cat cmd "geogra2.txt "    )))
                (if (in partsA 5) (set cmd (cat cmd "namen.txt "      )))
                (if (in partsA 5) (set cmd (cat cmd "vornamen.txt "   )))
                (if (in partsA 5) (set cmd (cat cmd "vornam2.txt "    )))
                (if (in partsA 6) (set cmd (cat cmd "abkuerz.txt "    )))
                (if (in partsA 6) (set cmd (cat cmd "abkuerz2.txt "   )))
                (if (in partsA 7) (set cmd (cat cmd "imperat.txt "    )))
                (if (in partsA 8) (set cmd (cat cmd "latein.txt "     )))

                (if (in partsB 0) (set cmd (cat cmd "compeng.txt "    )))
                (if (in partsB 0) (set cmd (cat cmd "infoabk.txt "    )))
                (if (in partsB 0) (set cmd (cat cmd "informatik.txt " )))
                (if (in partsB 1) (set cmd (cat cmd "elektronik.txt " )))
                (if (in partsB 2) (set cmd (cat cmd "orgabk.txt "     )))
                (if (in partsB 3) (set cmd (cat cmd "marken.txt "     )))
                (if (in partsB 4) (set cmd (cat cmd "alphabeta.txt "  )))
                (if (in partsB 5) (set cmd (cat cmd "roemisch.txt "   )))
                (if (in partsB 6) (set cmd (cat cmd "technik.txt "    )))
                (if (in partsB 7) (set cmd (cat cmd "seltenes.txt "   )))

                (run cmd)

                (if (exists "dictionary/deutsch/words/all.words" (noreq))

                    (
                        (working "\nChecking dictionary. May take some minutes.\n")

                        (run "bin/ifilter >con://///AUTO FILE=dictionary/deutsch/words/all.words NOTEX")

                        (complete 50)

                        (if (exists "ispell:lib/deutsch.hash")

                            (set remove (askbool

                                (prompt "\nOverwrite old hash file (ispell:lib/deutsch.hash) ?")

                                (help "You might want to backup your old file :-)")

                                (choices

                                    "overwrite"
                                    "exit"
                                )
                            ))

                            (set remove 1);
                        )

                        (if (= remove 1)

                            (
                                (delete "ispell:lib/deutsch.hash")

                                (working "\nCreating hash file supporting fast data access. May take some minutes and LOTS of RAM.\n")

                                (complete 55)

                                (run "ispell:bin/buildhash >NIL: -s dictionary/deutsch/words/all.words dictionary/deutsch/words/deutsch.aff ispell:lib/deutsch.hash")

                                (complete 60)

                                (if (exists "ispell:lib/deutsch.hash")

                                    (
                                        (copyfiles

                                            (source "dictionary/deutsch/words/deutsch.aff")
                                            (dest "ispell:lib")
                                            (nogauge)
                                        )

                                        (message (cat "\nHash file 'ispell:lib/deutsch.hash' has been created successfully. Hash file size (ISpell RAM usage):\n\n" (getsize "ispell:lib/deutsch.hash") " Bytes"))
                                    )

                                    (

                                        (message "\nFatal error: hash file creation failed (out of RAM ?).\n")

                                        (delete "language/deutsch/words/all.words")

                                        (exit (quiet))
                                    )
                                )
                            )
                        )

                        (complete 65)

                        (delete "dictionary/deutsch/words/all.words")
                    )

                    (
                        (message "\nFatal error - dictionary creation failed.")

                        (exit (quiet))
                    )
                )
            ))
        ))

        ; install English dictionary

        (complete 70)

        (if (in action 2) (

            ; set default ISpell options

            (copyfiles

                (source "env/e")
                (dest "env:")
                (all)
                (nogauge)
            )

            (copyfiles

                (source "env/e")
                (dest "envarc:")
                (all)
                (nogauge)
            )

            (set partsA (askchoice

                (prompt "\nSelect English dictionaries to install\n")

                (help (cat "\n"

                    " The more dictionaries you select, the more \n"
                    " memory ISpell will use. File sized listed  \n"
                    " are NOT RAM requirements - RAM requirements\n"
                    " are about three times higher.              \n"
                ))

                (choices

                    "  none                        "
                    "  Basis             (  205 KB)"
                    "+ Extensions small  (+ 149 KB)"
                    "+ Extensions medium (+ 549 KB)"
                    "+ Extensions large  (+ 722 KB)"
                )

                (default 2)
            ))

            (complete 75)

            (if (<> partsA 0) (

                (working "\nCreating dictionary, sorting entries. May take some minutes.\n")

                (delete "dictionary/english/words/all.words.cnt")
                (delete "dictionary/english/words/all.words.stat")

                (set cmd "bin/joinsorted >con://///AUTO DIR=dictionary/english/words as=dictionary/english/words/all.words ")

                (if (> partsA 0) (set cmd (cat cmd "english.0 american.0 british.0 ")))
                (if (> partsA 1) (set cmd (cat cmd "english.1 american.1 british.1 ")))
                (if (> partsA 2) (set cmd (cat cmd "english.2 american.2 british.2 ")))
                (if (> partsA 3) (set cmd (cat cmd "english.3 ")))

                (run cmd)

                (complete 80)

                (if (exists "dictionary/english/words/all.words" (noreq))

                    (
                        (if (exists "ispell:lib/english.hash")

                            (set remove (askbool

                                (prompt "\nOverwrite old hash file (ispell:lib/english.hash) ?")

                                (help "You might want to backup your old file :-)")

                                (choices

                                    "overwrite"
                                    "exit"
                                )
                            ))

                            (set remove 1);
                        )

                        (if (= remove 1)

                            (
                                (delete "ispell:lib/english.hash")

                                (working "\nCreating hash file supporting fast data access. May take some minutes.\n")

                                (complete 85)

                                (run "ispell:bin/buildhash >NIL: -s dictionary/english/words/all.words dictionary/english/words/english.aff ispell:lib/english.hash")

                                (complete 90)

                                (if (exists "ispell:lib/english.hash")

                                    (
                                        (copyfiles

                                            (source "dictionary/english/words/english.aff")
                                            (dest "ispell:lib")
                                            (nogauge)
                                        )

                                        (message (cat "\nHash file 'ispell:lib/english.hash' has been created successfully. Hash file size (ISpell RAM usage):\n\n" (getsize "ispell:lib/english.hash") " Bytes"))
                                    )

                                    (
                                        (message "\nFatal error: hash file creation failed (out of RAM ?).\n")

                                        (delete "dictionary/english/words/all.words")

                                        (exit (quiet))
                                    )
                                )
                            )
                        )

                        (complete 95)

                        (delete "dictionary/english/words/all.words")
                    )

                    (
                        (message "\nFatal error - dictionary creation failed.")

                        (exit (quiet))
                    )
                )
            ))
        ))

        (if (= @language "deutsch")

            (set language 1)
            (set language 0)
        )

        (set language (askchoice

            (prompt "\nSelect context menu language\n")

            (help @askchoice-help)

            (choices

                "  English"
                "  Deutsch"
            )

            (default language)
        ))

        ; update registry

        (if (in action 0)

            (

                (working "Updating registry...")

                (if (= language 0)

                    (run "golded:tools/regedit/regedit script=install.bat presets/e/words.mouse")
                    (run "golded:tools/regedit/regedit script=install.bat presets/d/words.mouse")
                )
            )
        )

        (complete 100)
    )

    (message (cat "\n"

        " Please install GoldED before attempting to\n"
        " install this package.                     \n"
    ))
)

(exit (quiet))
