; xref.install
;
; $VER: xref.install 1.12 (15.01.95)
;
; by
;
; Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
;
; (C) Copyright 1994,1995
; All Rights Reserved !
;

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

; root path for the application to install

(set gpath
(cat "/"
))

(if (= @language "english")
    (
        (set default_lang 2)

        (set #author
        (cat "Stefan Ruppert\n"
             "Windthorststraße 5\n"
             "65439 Flörsheim am Main\n"
             "GERMANY\n"
             "EMail : ruppert@vs3.informatik.fh-wiesbaden.de\n"
        ))

        (set #bad-kick
        (cat "You must be using Kickstart 2.04 to use the xref.library system"
        ))

        (set #install-remove
        (cat "Would you install or remove the XRef-System ?"
        ))

        (set #install
        (cat "Install"
        ))

        (set #remove
        (cat "Remove"
        ))

        (set #which-disk
        (cat "Please select the directory to install the XRef-System to :"
        ))

        (set #which-disk-help
        (cat "\nYou enter here the disk and direcotry , you want to install"
             " the XRef-System.\n\n\n"
             @askdir-help
        ))

        (set #disk-ok
        (cat "Would you install into this direcory :\n"
        ))

        (set #disk-ok-help
        (cat "If you would not install in this directory,\n"
             "select no. And select the right one !\n"
        ))

        (set #install-dir
        (cat "Please select topics to install :"
        ))

        (set #install-dir-help
        (cat "Tools : command line tools for handling with the xref.library. "
             "These tools and the xref.library are the basic parts "
             "of the XRef-System. Need about 120K.\n\n"
             "Tools-Source : C source of the command tools. Need about 400K.\n\n"
             "Documentation : ASCII-Documentation for all tools, XRef-System and the "
             "xref.library. Need about 120K.\n\n"
             "AmigaGuide Doc. : AmigaGuide Documentation for all tools, XRef-System and "
             "the xref.library. Need about 180K.\n\n"
             "V40 XRef-Files : XReffiles for all V40 includes and AutoDocs. Need about "
             "180K.\n\n"
             "Programmer-Files : include and link-library files. Need about 70K.\n\n"
             "Projects/Scripts : some example scripts to generate system xreffiles and guides. "
             "Need about 1K.\n\n"
             "AReexx-Scripts  : some examples. Need about 10K.\n\n"
             "Goodies : Some usefull stuff. Need about 60K.\n\n"
             "Config-Files : Configuration files are copied to Sys:Config/XRef directrory "
             "these files are needed by the xref.library and some tools. The files are set "
             "up correctly for you with this installation! Need about 5K in your Sys: partition.\n"
        ))

        (set #copy-config-files-help
        (cat "This copies the xref.prefs file and the xrefconvert def-files"
             "to the Sys:Config directory. The xref.library uses the xref.prefs"
             "file to setup some values (see docs...). The xrefconvert tool uses"
             "some files,which contain some convert definitions"
        ))

        (set #select-include-dir
        (cat "Please select include directory for xref-inlcudes"
        ))

        (set #select-include-dir-help
        (cat "Select here the include directoy, in which the xref-includes are "
             "copied. The includes are copied to <your-include>/libraries, "
             "<your-include>/clib, <your-include>/pragmas, <your-include>/proto "
             "and <your-include>/fd directories "
        ))

        (set #copy-config-to-sys
        (cat "Use \"Sys:Config/XRef\" as the xref config directory ?"
        ))

        (set #copy-config-to-sys-help
        (cat "The config directory is needed by the xref.library ! "
             "If you don`t want in the Sys: partition just anwser with "
             "No and select a directory of your choice !"
        ))

        (set #xreffiles-dir
        (cat "XRefFiles diretory to %s ?"
        ))

        (set #xreffiles-dir-help
        (cat "If you don`t want this location, choose No and select an other "
             "directory !"
        ))

        (set #which-xreffiles-dir
        (cat "Select the directory to hold all XRefFiles !"
        ))

        (set #which-xreffiles-dir-help
        (cat "This directory is set up in the xref.prefs file, so the library "
             "can locate any xreffile accessed only via the filename !"
        ))

        (set #which-config-dir
        (cat "Please select the xref config dir !"
        ))

        (set #which-config-dir-help
        (cat "This directory is needed by the xref.library and the tools !"
        ))

        (set #backup-config
        (cat "Making a backup of your old XRef settings :"
        ))

        (set #copy-golded-scripts
        (cat "Copy GoldEd ARexx scripts to GoldEd:ARexx ?"
        ))

        (set #copy-golded-scripts-help
        (cat "Copies all ARexx scripts of the XRef-System for\n"
             "GoldEd (at the moment only one) !"
        ))

        (set #copy-golded-xrefapi
        (cat "Install the GoldED XRefAPI-Client to GoldED:API/XRef ?"
        ))

        (set #copy-golded-xrefapi-help
        (cat "This GoldED API-Client uses the xref.library to complete "
             "phrases ! It provides a new ARexx command to do this !"
        ))

        (set #xref-library
        (cat "Install xref.library"
        ))

        (set #rexxxref-library
        (cat "Install rexxxref.library"
        ))

        (set #install-german-catalog
        (cat "Install german xref-tools.catalog ?"
        ))

        (set #install-german-catalog-help
        (cat "This catalog is currently used by the AGuideXRefV39 program !"
        ))

        (set #have-fun
        (cat "Just have fun with the XRef-System !\n"
             "If you have any idea or suggestions\nplease contact me !\n"
             #author
        ))

        (set #remove-really
        (cat "Oh, You would not use the XRef-System ?\n\n"
             "So I can`t help you ! But if you only missed a\n"
             "absolutely needed feature contact me :\n"
             #author
        ))

        (set #remove-xrefdir
        (cat "Where is the XRef-System main directory\n"
             "on your system ?"
        ))

        (set #remove-dir
        (cat "Are you sure to delete this directoy :\n"
        ))

        (set #removed-all
        (cat "So the XRef-System no more waste space\n"
             "on your system !"
        ))
    )
) ; end of language english

; ROM >= 2.04 ?

(set sys-version (/ (getversion) 65536))

(if (< sys-version 37)
    (abort #bad-kick)
)

; check if the XRef-System is installed
(if (exists "Libs:xref.library")
    (set install (askchoice (prompt #install-remove)
                            (help @askchoice-help)
                            (choices #remove
                                     #install)
                            (default 1)
                 )
    )
    ; else
    (set install 1)
)

(if (= install 1)
    (
        (set target "Work:")
        (set install 0)
        (while (= install 0)
            (
                ; get the destination directory !
                (set target (askdir (prompt #which-disk)
                                    (help #which-disk-help)
                                    (default target)
                            )
                )
                (set install (askbool (prompt (cat #disk-ok target))
                                      (help #disk-ok-help)
                                      (default 1)
                             )
                )
            )
        )

        ; get what to install ?
        (set sel_basedir     0)
        (set sel_toolsdir    1)
        (set sel_arexxscript 2)
        (set sel_toolssrcdir 3)
        (set sel_docdir      4)
        (set sel_guidedir    5)
        (set sel_xrefdir     6)
        (set sel_prgdir      7)
        (set sel_exampledir  8)

        (set dirs (askoptions (prompt #install-dir)
                              (help #install-dir-help)
                              (choices "Config files and library (needed)"
                                       "Tools"
                                       "ARexx scripts"
                                       "Tools-Source"
                                       "Documentation (#?.doc)"
                                       "AmigaGuide Doc. (#?.guide)"
                                       "V40 - XRefFiles"
                                       "Programmer-Files (#?.h,#?.lib)"
                                       "Example generation scripts/icons"
                              )
                  )
        )

        ; install german catalog ?
        (if (IN dirs sel_toolsdir)
            (if (>= sys-version 39)
                (set install-catalog 
                     (askbool (prompt #install-german-catalog)
                              (help #install-german-catalog-help))
                )
            )
        )

        ; get include directoy !
        (if (IN dirs sel_prgdir)
            (if (exists "include:" (noreq))
                ; TRUE if condition
                (
                    (set inc-dir (askdir (prompt #select-include-dir)
                                         (help #select-include-dir-help)
                                         (default "include:")
                                 )
                    )
                )
                ; else
                (
                    (set inc-dir (tackon target "include"))
                )
            )
        )

        (if (IN dirs sel_basedir)
            (
                ; get configdir !
                (if (askbool (prompt #copy-config-to-sys)
                             (help #copy-config-to-sys-help))
                    (
                        (set configdir ("Sys:Config/XRef"))
                    )
                ;   else
                    (
                        (set envvariable 1)
                        (set configdir (askdir (prompt #which-config-dir)
                                               (help #which-config-dir-help)
                                               (default target)
                                       )
                        )
                    )
                )

                ; get xreffiles dir !
                (if (askbool (prompt (#xreffiles-dir (tackon target "XRef")))
                             (help #xreffiles-dir-help))
                    (
                        (set xreffilesdir (tackon target "XRef"))
                    )
                ;     else
                    (
                        (set xreffilesdir (askdir (prompt  #which-xreffiles-dir)
                                                  (help #which-xreffiles-dir-help)
                                                  (default target)
                                          )
                        )
                    )
                )

                ; get golded stuff !

                (if (exists "GoldEd:" (noreq))
                    (
                        (set golded-arexx (askbool (prompt #copy-golded-scripts)
                                                   (help #copy-golded-scripts-help)
                                          )
                        )

                        (set golded-api   (askbool (prompt #copy-golded-xrefapi)
                                                   (help #copy-golded-xrefapi-help)
                                          )
                        )
                    )
                )
            )
        )

        (complete 10)

        (if (IN dirs sel_toolsdir)
            (
                (makedir (tackon target "Tools"))
                (copyfiles (source (tackon gpath "Tools.info"))
                           (dest target)
                )
                (copyfiles (source (cat gpath "tools/c"))
                           (dest (tackon target "Tools/c"))
                           (all)
                           (infos)
                )
                (copyfiles (source (cat gpath "tools/icons"))
                           (dest (tackon target "Tools/Icons"))
                           (all)
                           (infos)
                )

                (if install-catalog
                        (copyfiles (source (cat gpath "catalogs/deutsch/xref-tools.catalog"))
                                   (dest "locale:catalogs/deutsch")
                        )
                )
            )
        )

        (if (IN dirs sel_arexxscript)
            (
                (copyfiles (source gpath)
                           (dest target)
                           (pattern "ARexx#?")
                           (infos)
                )
            )
        )

        (complete 20)

        (if (IN dirs sel_toolssrcdir)
            (
                (makedir (tackon target "Tools"))
                (copyfiles (source (tackon gpath "Tools.info"))
                           (dest target)
                )
                (copyfiles (source (tackon gpath "Tools"))
                           (dest (tackon target "Tools"))
                           (pattern "(Source#?|Lib#?|Rexx#?)")
                           (infos)
                )
                (copyfiles (source gpath)
                           (dest target)
                           (pattern "Goodies#?")
                           (infos)
                )
            )
        )

        (complete 30)

        (if (IN dirs sel_docdir)
            (copyfiles (source gpath)
                       (dest target)
                       (pattern "Doc#?")
                       (infos)
            )
        )

        (complete 40)

        (if (IN dirs sel_guidedir)
            (copyfiles (source gpath)
                       (dest target)
                       (pattern "Help#?")
                       (infos)
            )
        )

        (complete 50)

        (if (IN dirs sel_xrefdir)
            (copyfiles (source (tackon gpath "XRef"))
                       (dest xreffilesdir)
                       (pattern "#?")
            )
        )

        (complete 60)

        (if (IN dirs sel_prgdir)
            (
                (copyfiles (source (tackon gpath "include"))
                           (choices "clib" "libraries" "fd" "pragmas" "proto")
                           (dest inc-dir)
                )
                (copyfiles (source gpath)
                           (dest target)
                           (choices "lib" "myinclude")
                )
            )
        )

        (complete 65)

        (if (IN dirs sel_exampledir)
            (
                (copyfiles (source gpath)
                           (dest target)
                           (pattern "Projects#?")
                           (infos)
                )
            )
        )

        (complete 70)

        (if (IN dirs sel_basedir)
            (
                ; make configuration
                (if envvariable
                    (
                        (textfile (dest "ENVARC:XREFCONFIGDIR")
                                  (append configdir)
                        )
                        (textfile (dest "ENV:XREFCONFIGDIR")
                                  (append configdir)
                        )
                    )
                )

                ; backup old config

                (if (exists (tackon configdir "xref.prefs"))
                    (
                        (working #backup-config)
                        (rename configdir (cat configdir "_Old"))
                    )
                )

                (copyfiles (source (cat gpath "config/xref"))
                           (dest configdir)
                           (all)
                )

                ; generate new config file

                (textfile (dest (tackon configdir "xref.prefs"))
                          (append (cat "XREFDIR DIR " xreffilesdir "\n"))
                          (include (tackon gpath "config/xref/xref_std.prefs"))
                )
                (delete (tackon configdir "xref_std.prefs" (optional "force")))


                (complete 80)

                ; copy GoldED support stuff

                (if (exists "GoldEd:" (noreq))
                    (
                        (if golded-arexx
                            (copyfiles (source (cat gpath "arexx"))
                                       (dest "GoldED:ARexx")
                                       (pattern "#?.ged")
                                       (infos)
                            )
                        )
                        (if golded-api
                            (
                                (makedir "GoldED:API/XRef" (infos))
                                (copyfiles (source (tackon gpath "tools/golded"))
                                           (dest "GoldED:API/XRef")
                                           (all)
                                           (infos)
                                )
                            )
                        )
                    )
                )

                (complete 90)

                ; check , which of the library fits best

                (if (< sys-version 39)
                    (
                        (set library (tackon gpath "libs/v37/xref.library"))
                    )
                    ; else
                    (
                        (set library (tackon gpath "libs/v39/xref.library"))
                    )
                )


                (copylib (prompt #xref-library)
                         (source library)
                         (dest "LIBS:")
                )                       

                (copylib (prompt #rexxxref-library)
                         (source (tackon gpath "libs/rexxxref.library"))
                         (dest "LIBS:")
                )

                (copyfiles (source (cat gpath "readme/english"))
                           (dest target)
                           (newname "ReadMe")
                           (infos)
                           (files)
                           (noposition)
                )
            )
        )

        (complete 100)

        (set @default-dest target)

        ; show ReadMe file if this is a base installation
        (if (IN dirs sel_basedir)
            (run (cat "run >NIL: <NIL: Sys:Utilities/MultiView " (tackon target "ReadMe")))
        )

        ; end of installation
        (exit (#have-fun))
    ) ; else remove
    (
        (set install 0)
        (if (askbool (prompt #remove-really)
                     (help @askbool-help))

            (
                (set xrefdir (askdir (prompt #remove-xrefdir)
                                     (help @askdir-help)
                                     (default "XRef:")))

                (if (askbool (prompt (cat #remove-dir xrefdir))
                             (help @askbool-help))
                    (
                        (run (cat "delete >NIL: <NIL: " (tackon xrefdir "#?") " all"))

                        (if (NOT (= (trap 5 (getenv "XREFCONFIGDIR")) 5))
                            (
                                (set xrefconfigdir (getenv "XREFCONFIGDIR"))
                                (trap 4 (delete "ENVARC:XREFCONFIGDIR"))
                                (trap 4 (delete "ENV:XREFCONFIGDIR"))
                                (run (cat "delete >NIL: <NIL: " (tackon xrefconfigdir "#?") " ALL "))
                            )
                        )

                        (if (NOT (= (trap 5 (set xrefdir (getenv "XREFDIR"))) 5))
                            (
                                (trap 4 (delete "ENV:XREFDIR"))
                                (run (cat "delete >NIL: <NIL: " (tackon xrefdir "#?") " ALL "))
                            )
                        )
                        (trap 4 (delete "LIBS:xref.library"))
                        (trap 4 (delete "LIBS:rexxxref.library"))

                        (message #removed-all)
                    )
                )
            )
        )
        ; end of deletion
    )
)
(exit (quiet))

