;
; Installer script for Amiga shared libraries
;
; Copyright © 1997 Kai Hofmann
; All rights reserved!
; Released as Giftware without any explicit or implicit warranty!
;
; EMail: i07m@informatik.uni-bremen.de
; WWW  : http://home.pages.de/~i07m/
;
; $VER: Lib-Install 43.0 (12.12.97)
;
; -----------------------------------------------------------------------------
; WrapGuide is copyright © 1994-1995 Udo Schuermann
; -----------------------------------------------------------------------------
;
; Archive structure:
;
; <name>Lib/<name>Lib.pi					(recommended)
; <name>Lib/<name>Lib.readme
; <name>Lib/<name>Lib.readme.info
; <name>Lib/Lib-Install
; <name>Lib/Lib-Install.info
; <name>Lib/Install/English.info				(optional)
; <name>Lib/Install/...						(optional)
;
; <name>Lib/Libs/<name>.library					(optional)
; <name>Lib/Libs/<name>000.library				(optional)
; <name>Lib/Libs/<name>010.library				(optional)
; <name>Lib/Libs/<name>020.library				(optional)
; <name>Lib/Libs/<name>020f.library				(optional)
; <name>Lib/Libs/<name>030.library				(optional)
; <name>Lib/Libs/<name>030f.library				(optional)
; <name>Lib/Libs/<name>040.library				(optional)
; <name>Lib/Libs/<name>040f.library				(optional)
; <name>Lib/Libs/<name>060.library				(optional)
; <name>Lib/Locale/Catalogs/.../<name>_lib.catalog		(optional)
; <name>Lib/Developer/C/Include/Libraries/<name>.h
; <name>Lib/Developer/C/Include/Proto/<name>.h
; <name>Lib/Developer/C/Include/CLib/<name>_protos.h
; <name>Lib/Developer/C/Include/Pragmas/<name>_pragmas.h
; <name>Lib/Developer/Amiga-E/Modules/<name>_pragmas.m	 	(optional)
; <name>Lib/Developer/Amiga-E/Modules/Libraries/<name>.e 	(optional)
; <name>Lib/Developer/Modula/Defs/<name>D.def 			(optional)
; <name>Lib/Developer/Modula/Defs/<name>L.def	 		(optional)
; <name>Lib/Developer/Oberon/Interfaces/<name>.mod 		(optional)
; <name>Lib/Developer/Assembler/Include/Libraries/<name>.i	(optional)
; <name>Lib/Developer/Assembler/Include/lvo/<name>.i		(optional)
; <name>Lib/Developer/Rexx/Include/<name>.rexx			(optional)
;
; -----------------------------------------------------------------------------
; TODO:
;
; <name>Lib/Developer/Autodocs/<name>.doc
; <name>Lib/Developer/BB2/Include/Libraries/<name>.asc		(optional)
; <name>Lib/Developer/BB2/blitzlibs/amigalibs/<name>.library1	(optional)
; <name>Lib/Developer/BB2/Examples/<name>Lib-Demo.asc		(optional)
; <name>Lib/Developer/Cluster/txt/<name>.def			(optional)
; <name>Lib/Developer/Cluster/txt/<name>.mod			(optional)
; <name>Lib/Developer/Cluster/txt/<name>LibDemo.mod		(optional)
; <name>Lib/Developer/Rexx/Examples/<name>Lib-Demo.rexx		(optional)
; <name>Lib/Developer/Oberon/Examples/<name>LibDemo.mod		(optional)
; <name>Lib/Developer/Modula/Demo/<name>LibDemo.mod		(optional)
; <name>Lib/Developer/Amiga-E/Examples/<name>Lib-Demo.e		(optional)
; <name>Lib/Developer/Assembler/Examples/<name>Lib-Demo.s 	(optional)
; <name>Lib/Developer/C/Examples/<name>Lib-Demo.c 		(optional)
; <name>Lib/Developer/Source/<name>Lib/...			(optional)
; <name>Lib/Docs/english/<name>Lib.guide
; <name>Lib/Docs/english/<name>Lib.guide.info
; <name>Lib/Docs/english/<name>Lib.doc				(optional)
; <name>Lib/Docs/english/<name>Lib.doc.info			(optional)
; <name>Lib/Docs/english/<name>_home.html			(optional)
; <name>Lib/Docs/english/<name>_home.html.info 			(optional)
; <name>Lib/Docs/english/<name>_<pagename>.html			(optional)
; <name>Lib/Docs/english/<name>_<pagename>.html.info		(optional)
; <name>Lib/Docs/......./<name>Lib.guide			(optional)
; <name>Lib/Docs/......./<name>Lib.guide.info 			(optional)
; <name>Lib/Docs/......./<name>Lib.doc				(optional)
; <name>Lib/Docs/......./<name>Lib.doc.info			(optional)
; <name>Lib/Docs/......./<name>_home.html			(optional)
; <name>Lib/Docs/......./<name>_home.html.info 			(optional)
; <name>Lib/Docs/......./<name>_<pagename>.html			(optional)
; <name>Lib/Docs/......./<name>_<pagename>.html.info		(optional)
; <name>Lib/Demos/<name>Lib-Demo				(optional)
; <name>Lib/Demos/<name>Lib-Demo.info				(optional)
; <name>Lib/C/WrapGuide						(optional)
;
; Support for more languages
; C++
; Support for more assemblers (OMA is the only one for the moment)
;
; --- Custom initialisation ---------------------------------------------------

 ; Copyright
 (set #copyright "Copyright © 1994-1998 Kai Hofmann")

 ; Minimum OS version required for installation
 (set #min_os_version 33)
 (set #min_os_revision 0)

 ; Bultin language
 ; Bit	0 = English
 ; Bit	1 = German
 ; Bit	2 = French
 ; Bit	3 = Spanish
 ; Bit	4 = Portuguese (European)
 ; Bit	5 = Danish
 ; Bit	6 = Italian
 ; Bit	7 = Dutch
 ; Bit	8 = Norwegian
 ; Bit	9 = Swedish
 ; Bit 10 = Polish
 ; Bit 11 = Finnish
 ; Bit 12 = Hungarian
 ; Bit 13 = Greek
 ; Bit 14 = Esperanto
 ; Bit 15 = Turkish
 ; Bit 16 = Latin
 ; Bit 17 = Russian
 ; Bit 18 = Czech
 ; Bit 19 = Catalonian
 ; Bit 20 = Croatian
 ; Bit 21 = Serbian
 ; Bit 22 = Slovak
 ; Bit 23 = Slovenian
 ; Bit 24 = Portuguese (Brazilian)

 (set #language %0001011111111111111111111) ; LANGUAGE

; --- Custom installation procedures ------------------------------------------

 (procedure P_CustomExists
  ; Params:
  ;
  ; Results:
  ;
  ; Used Vars:
  ;

 )

 (procedure P_CustomInstall
  ; Params:
  ;
  ; Results:
  ;
  ; Used Vars:
  ;

 )

 (procedure P_CustomUninstall
  ; Params:
  ;
  ; Results:
  ;
  ; Used Vars:
  ;

 )

; -----------------------------------------------------------------------------
; --- Do not change anything below this line ----------------------------------
; -----------------------------------------------------------------------------

 (set @default-dest "Libs:")

 (if (= @installer-version 0)
   (
    ; old Installer
    (set #prop "")
   )
   (
    ; new Installer
    (set #prop "\x1b[2p")
   )
 )

; --- Installer script strings ------------------------------------------------

 (set #i 0)
 (while (<> @language (select #i "deutsch" @language)) ; LANGUAGE
   (set #i (+ #i 1))
 )
 (if (= #i 1) ; LANGUAGE
   (set #language "english")
   (set #language @language)
 )

 (set #i 0)
 (set #language_default %1000000000000000000000000) ; LANGUAGE
 (while (<> #language (select #i "português-brasil" "slovensko" "Slovak" "srpski" "Croatian" "catalonian" "ÃeÓtina" "russian" "latina" "türkçe" "esperanto" "greek" "magyar" "suomi" "polski" "svenska" "norsk" "nederlands" "italiano" "dansk" "português" "español" "français" "deutsch" #language)) ; LANGUAGE
   (
    (set #language_default (shiftright #language_default 1))
    (set #i (+ #i 1))
   )
 )
 (select #i ; LANGUAGE
   ( ; Portuguese (Brazilian)
    (complete 0)
   )
   ( ; Slovenian
    (complete 0)
   )
   ( ; Slovak
    (complete 0)
   )
   ( ; Serbian
    (complete 0)
   )
   ( ; Croatian
    (complete 0)
   )
   ( ; Catalonian
    (complete 0)
   )
   ( ; Czech
    (complete 0)
   )
   ( ; Russian
    (complete 0)
   )
   ( ; Latina
    (complete 0)
   )
   ( ; Türkçe
    (complete 0)
   )
   ( ; Esperanto
    (complete 0)
   )
   ( ; Greek
    (complete 0)
   )
   ( ; Magyar
    (complete 0)
   )
   ( ; Finnish
    (complete 0)
   )
   ( ; Polish
    (complete 0)
   )
   ( ; Swedish
    (complete 0)
   )
   ( ; norsk
    (complete 0)
   )
   ( ; nederlands
    (complete 0)
   )
   ( ; italiano
    (complete 0)
   )
   ( ; dansk
    (complete 0)
   )
   ( ; português (European)
    (complete 0)
   )
   ( ; español
    (complete 0)
   )
   ( ; français
    (complete 0)
   )
   ( ; deutsch
    (if (= @installer-version 0)
      (
       (set #help_askoptions "Mit einem Installer der älter als Version 42.6 ist, kann es passieren, daß Checkbox-Knöpfe ohne Labels zu sehen sind. Das Setzen dieser Knöpfe wird ignoriert.\n\n")
       (set #help_askchoice  "Mit einem Installer der älter als Version 42.6 ist, kann es passieren, daß Radio-Knöpfe ohne Labels zu sehen sind. Das Setzen dieser Knöpfe entspricht der nächst kleineren Auswahl.\n\n")
      )
    )
    (set #unknown	      "unbekannt")
    (set #choice_english      "Englisch")
    (set #choice_german       "Deutsch")
    (set #choice_french       "Französisch")
    (set #choice_spanish      "Spanisch")
    (set #choice_portuguese   "Portugiesisch")
    (set #choice_danish       "Dänisch")
    (set #choice_italian      "Italienisch")
    (set #choice_dutch	      "Niederländisch")
    (set #choice_norwegian    "Norwegisch")
    (set #choice_swedish      "Schwedisch")
    (set #choice_polish       "Polnisch")
    (set #choice_finnish      "Finnisch")
    (set #choice_hungarian    "Ungarisch")
    (set #choice_turkish      "Türkisch")
    (set #choice_greek	      "Griechisch")
    (set #choice_latin	      "Latein")
    (set #choice_esperanto    "Esperanto")
    (set #choice_russian      "Russisch")
    (set #choice_czech	      "Tschechisch")
    (set #choice_catalonian   "Katalanisch")
    (set #choice_croatian     "Kroatisch")
    (set #choice_serbian      "Serbisch")
    (set #choice_slovak       "Slowakisch")
    (set #choice_slovenian    "Slawisch")
    (set #choice_portuguesebr "Portugiesisch (Br)") ; LANGUAGE

    (set #choice_catalogs   "Kataloge")
    (set #choice_docs	    "Dokumentation")
    (set #choice_developer  "Entwickler-Material")
    (set #choice_source     "Quellcode")
    (set #choice_images     "Bilder")
    (set #choice_install    "Installieren")
    (set #choice_update     "Updaten")
    (set #choice_uninstall  "Deinstallieren")
    (set #prompt_askcpufpu (cat "Bitte wählen Sie die CPU/FPU Konfiguration, für die die " @app-name ".library installiert werden soll."))
    (set #prompt_info (cat "\nWillkommen zur " @app-name ".library\n" #copyright "\n\n"))
    (set #prompt_install_uninstall (cat #prompt_info "Wollen Sie die Library installieren oder deinstallieren?"))
    (set #abort_nocpu (cat "Die " @app-name ".library kann leider nicht installiert werden, da Ihre CPU-Konfiguration nicht unterstützt wird.\n"))
    (set #prompt_uninstall_parts "Welche Teile wollen Sie deinstallieren?\n")
    (set #prompt_uninstall_all (cat "Wollen Sie alles was mit der " @app-name ".library zu tun hat deinstallieren?"))
    (set #help_uninstall_all "Wenn Sie nicht alles deinstallieren wollen, werden Sie gefragt welche Teile deinstalliert werden sollen.")
    (set #abort_oldversion (cat "Der Installer hat die bereits installierte Version %ld.%ld von der " @app-name ".library gefunden.\n\n"
				"Wenn Sie die ältere Version %ld.%ld wieder installieren wollen, deinstallieren Sie die neuere Version bitte zuerst."
			   )
    )
    (set #prompt_update (cat "Welche Teile wollen Sie zur " @app-name ".library Installation hinzufügen?"))
    (set #help_install_demo (cat "Die Demo ist ein kleines Programm, welches die Benutzung der " @app-name ".library zeigt."))
    (set #help_install_source (cat "Der Quellcode der " @app-name ".library kann als Beispiel benutzt werden, oder aber um eigene (korrigierte) Binärfiles zu erzeugen.\nSeien Sie vorsichtig - der Quellcode kann in einer beliebigen Sprache vorliegen!"))
    (set #prompt_copy "Wollen Sie die folgende(n) Datei(en) kopieren?")
    (set #prompt_makedir "Das folgende Verzeichnis wurde nicht gefunden, deshalb muß es erzeugt werden:")
    (set #exit_uninstall_finished (cat "Deinstallation abgeschlossen!\n"
				       '"'
				       @app-name
				       '"'
				       " wurde aus Ihrer Schublade (oder Partition) "
				       '"'
				       @default-dest
				       '"'
				       " entfernt."
				  )
    )
    (set #button_abort "Deinstallation abbrechen")
; ---
    (set #abort_oldos  (cat "Um die " @app-name ".library zu installieren wird mindestens OS %s benötigt.\n\n"
			    "Der Installer konnte aber nur OS %s finden.\n"
		       )
    )
    (set #prompt_install_demo	"Wollen Sie die mitgelieferte Demo installieren?")
    (set #prompt_install_source "Wollen Sie den Quellcode installieren?")

    (set #welcome_install   (cat "Willkommen zum Library Installations-Werkzeug.\n"
				 "Bitte geben Sie an, wie die Installation geschehen soll (basierend auf Ihrem Wissen über den Amiga Computer)."
			    )
    )
    (set #welcome_uninstall (cat "Willkommen zum Library deinstallations Werkzeug.\n"
				 "Bitte geben Sie an, wie die Deinstallation geschehen soll (basierend auf Ihrem Wissen über den Amiga Computer)."
			    )
    )

    (set #prompt_install_plangs   "Unterstützung für welche Programmiersprache wollen Sie installieren?")
    (set #prompt_uninstall_plangs "Unterstützung für welche Programmiersprache wollen Sie deinstallieren?")

    (set #prompt_install_catalogs	(cat "Welche Kataloge für die " @app-name ".library wollen Sie installieren?"))
    (set #prompt_uninstall_catalogs (cat "Welche Katalog von der " @app-name ".library wollen Sie deinstallieren?"))

    (set #prompt_install_docs	"Welche Art von Dokumenten wollen Sie installieren?")
    (set #prompt_uninstall_docs "Welche Art von Dokumenten wollen Sie deinstallieren?")

    (set #prompt_install_asciidocs   "Für welche Sprachen wollen Sie die ASCII Dokumentation installieren?")
    (set #prompt_uninstall_asciidocs "Für welche Sprachen wollen Sie die ASCII Dokumentation deinstallieren?")
    (set #prompt_install_agdocs      "Für welche Sprachen wollen Sie die AmigaGuide® Dokumentation installieren?")
    (set #prompt_uninstall_agdocs    "Für welche Sprachen wollen Sie die AmigaGuide® Dokumentation deinstallieren?")
    (set #prompt_install_htmldocs    "Für welche Sprachen wollen Sie die HTML Dokumentation installieren?")
    (set #prompt_uninstall_htmldocs  "Für welche Sprachen wollen Sie die HTML Dokumentation deinstallieren?")
   )
   ( ; english
    (if (= @installer-version 0)
      (
       (set #help_askoptions "With an Installer prior to version 42.6 it can happen that you see checkbox-buttons without labels. Selecting these buttons will be ignored.\n\n")
       (set #help_askchoice  "With an Installer prior to version 42.6 it can happen that you see radio-buttons without labels. Selecting these buttons will result in the next lower available selection.\n\n")
      )
    )
    (set #unknown	      "unknown")
    (set #choice_english      "English")
    (set #choice_german       "German")
    (set #choice_french       "French")
    (set #choice_spanish      "Spanish")
    (set #choice_portuguese   "Portuguese")
    (set #choice_danish       "Danish")
    (set #choice_italian      "Italian")
    (set #choice_dutch	      "Dutch")
    (set #choice_norwegian    "Norwegian")
    (set #choice_swedish      "Swedish")
    (set #choice_polish       "Polish")
    (set #choice_finnish      "Finnish")
    (set #choice_hungarian    "Hungarian")
    (set #choice_turkish      "Turkish")
    (set #choice_greek	      "Greek")
    (set #choice_latin	      "Latin")
    (set #choice_esperanto    "Esperanto")
    (set #choice_russian      "Russian")
    (set #choice_czech	      "Czech")
    (set #choice_catalonian   "Catalonian")
    (set #choice_croatian     "Croatian")
    (set #choice_serbian      "Serbian")
    (set #choice_slovak       "Slovak")
    (set #choice_slovenian    "Slovenian")
    (set #choice_portuguesebr "Portuguese (Br)") ; LANGUAGE

    (set #choice_catalogs   "Catalogs")
    (set #choice_docs	    "Documentation")
    (set #choice_developer  "Developer material")
    (set #choice_source     "Source code")
    (set #choice_images     "Images")
    (set #choice_install    "Install")
    (set #choice_update     "Update")
    (set #choice_uninstall  "Uninstall")
    (set #prompt_askcpufpu	   (cat "Please select the CPU/FPU configuration for which you want to install " @app-name ".library"))
    (set #prompt_info		   (cat "\nWelcome to the " @app-name ".library\n" #copyright "\n\n"))
    (set #prompt_install_uninstall (cat #prompt_info "Do you want to install or uninstall the library?"))
    (set #abort_nocpu ( cat "Sorry, the script is unable to install the " @app-name ".library, because your CPU configuration is not supported.\n"))
    (set #prompt_uninstall_parts "Which parts do you want to uninstall?\n")
    (set #prompt_uninstall_all (cat "Do you want to uninstall all things related with the " @app-name ".library?"))
    (set #help_uninstall_all "If you do not want to uninstall all, you will be asked which parts you want to uninstall.")
    (set #abort_oldversion (cat "The Installer found that version %ld.%ld of the " @app-name ".library is already installed.\n\n"
				"If you want to reinstall the older version %ld.%ld then please uninstall the newer version first."
			   )
    )
    (set #prompt_update (cat "Which parts of the " @app-name ".library do you want to add to the installation?"))
    (set #help_install_demo (cat "The demo is a small program that demonstrates the usage of the " @app-name ".library."))
    (set #help_install_source (cat "The source code of the " @app-name ".library can be used as an example or you can create your own (bug fixed) binaries.\nBe careful - the source code can be in any language!"))
    (set #prompt_copy "Do you want to copy the following file(s)?")
    (set #prompt_makedir "The following directory was not found, so it must be created:")
    (set #exit_uninstall_finished (cat "Uninstallation complete!\n"
				       '"'
				       @app-name
				       '"'
				       " is removed from your "
				       '"'
				       @default-dest
				       '"'
				       " drawer (or partition)."
				  )
    )
    (set #button_abort "Abort Uninstall")
; ---
    (set #abort_oldos  (cat "To install the " @app-name ".library you need OS %s as a minimum.\n\n"
			    "The installer has found that only OS %s is installed.\n"
		       )
    )
    (set #prompt_install_demo	"Do you want to install the supplied demo?")
    (set #prompt_install_source "Do you want to install the source code?")

    (set #welcome_install   (cat "Welcome to the library installation utility.\n"
				 "Please indicate how the installation should proceed (based upon your knowledge of the Amiga computer)."
			    )
    )
    (set #welcome_uninstall (cat "Welcome to the library uninstallation utility.\n"
				 "Please indicate how the uninstallation should proceed (based upon your knowledge of the Amiga computer)."
			    )
    )

    (set #prompt_install_plangs   "Support for which programming languages do you want to install?")
    (set #prompt_uninstall_plangs "Support for which programming languages do you want to uninstall?")

    (set #prompt_install_catalogs	(cat "Which catalogs for the " @app-name ".library do you want to install?"))
    (set #prompt_uninstall_catalogs (cat "Which catalogs for the " @app-name ".library do you want to uninstall?"))

    (set #prompt_install_docs	"Which type of documents do you want to install?")
    (set #prompt_uninstall_docs "Which type of documents do you want to uninstall?")

    (set #prompt_install_asciidocs   "For which languages do you want to install the ASCII documentation?")
    (set #prompt_uninstall_asciidocs "For which languages do you want to uninstall the ASCII documentation?")
    (set #prompt_install_agdocs      "For which languages do you want to install the AmigaGuide® documentation?")
    (set #prompt_uninstall_agdocs    "For which languages do you want to uninstall the AmigaGuide® documentation?")
    (set #prompt_install_htmldocs    "For which languages do you want to install the HTML documentation?")
    (set #prompt_uninstall_htmldocs  "For which languages do you want to uninstall the HTML documentation?")
   )
 )
 (if (> @installer-version 0)
   (
    (set #help_askoptions "")
    (set #help_askchoice "")
   )
 )

; --- BitToLanguage -----------------------------------------------------------

 (procedure P_BitToLanguage
  ; Params:
  ; #langmask
  ;
  ; Results:
  ; #langmask #lang
  ;
  ; Used Vars:
  ; #i #bitmask

  (set #i 0)
  (set #bitmask %11111111111111111111111110) ; LANGUAGE
  (while (AND (< #i 25) (NOT (IN #langmask #i))) ; LANGUAGE
    (
     (set #bitmask (BITOR (shiftleft #bitmask 1) %00000000000000000000000001)) ; LANGUAGE
     (set #i (+ #i 1))
    )
  )
  (set #langmask (BITAND #langmask #bitmask))
  (set #lang (select #i "english" "deutsch" "français" "español" "português" "dansk" "italiano" "nederlands" "norsk" "svenska" "polski" "suomi" "magyar" "greek" "esperanto" "türkçe" "latina" "russian" "ÃeÓtina" "catalonian" "Croatian" "srpski" "Slovak" "slovensko" "português-brasil" "")) ; LANGUAGE
 )

; --- GetVersion --------------------------------------------------------------

 (procedure P_GetVersion
  ; Param:
  ; #file
  ;
  ; Results:
  ; #ver #rev
  ;
  ; Vars used:
  ; #vernum

  (set #vernum (getversion (cat #file)))
  (set #ver (/ #vernum 65536))
  (set #rev (- #vernum (* #ver 65536)))
 )

; --- CompareVersions ---------------------------------------------------------

 (procedure P_CompareVersions
  ; Param:
  ; #ver #rev #ver2 #rev2
  ;
  ; Results:
  ; #result
  ; -1 : #ver.#rev < #ver2.#rev2
  ;  0 : #ver.#rev = #ver2.#rev2
  ;  1 : #ver.#rev > #ver2.#rev2
  ;
  ; Used Vars:

  (if (< #ver #ver2)
    (set #result -1)
    (if (> #ver #ver2)
      (set #result 1)
      (if (< #rev #rev2)
	(set #result -1)
	(if (> #rev #rev2)
	  (set #result 1)
	  (set #result 0)
	)
      )
    )
  )
 )

; --- GetOSVersionStr ---------------------------------------------------------

 (procedure P_GetOSVersionStr
  ; Param:
  ; #ver #rev
  ;
  ; Results:
  ; #str
  ;
  ; Used Vars:
  ; #i

  (set #i 0)
  (while (<> #ver (select #i 30 31 32 33 34 36 37 38 39 40 #ver)) ; OS
    (set #i (+ #i 1))
  )
  (set #str (select #i "1.0" "1.1 NTSC" "1.1 PAL" "1.2" "1.3" "2.0pre" "2.0" "2.1" "3.0" "3.1" #unknown)) ; OS
 )

; --- GetOSVersion ------------------------------------------------------------

 (procedure P_GetOSVersion
  ; Param:
  ;
  ; Results:
  ; #os_ver #os_rev #os_str
  ;
  ; Used Vars:
  ; #file #ver #rev #vernum #i #str

  (set #file "libs:version.library")
  (P_GetVersion)
  (set #os_ver #ver)
  (set #os_rev #rev)

  (P_GetOSVersionStr)
  (set #os_str #str)
 )

; --- GetCPU ------------------------------------------------------------------

 (procedure P_GetCPUFPU
  ; Param:
  ;
  ; Results:
  ; #cpu #cpu_str
  ; -1 = unknown; 0 = 68000; 1 = 68010; 2 = 68020; 3 = 68030; 4 = 68040;
  ;		  5 = 68060
  ; #fpu #fpu_str
  ; -1 = unknown; 0 = NOFPU; 1 = 68881; 2 = 68882; 3 = FPU40
  ;
  ; Used Vars:

  (set #cpu_str (database "cpu"))
  (set #cpu 0)
  (while (<> #cpu_str (select #cpu "68000" "68010" "68020" "68030" "68040""68060" #cpu))
    (set #cpu (+ #cpu 1))
  )
  (if (= #cpu 6)
    (
     (set #cpu -1)
     (set #cpu_str #unknown)
    )
  )

  (if @installer-version
    (
     (set #fpu_str (database "fpu"))
     (set #fpu 0)
     (while (<> #fpu_str (select #fpu "NOFPU" "68881" "68882" "FPU40" #fpu_str))
       (set #fpu (+ #fpu 1))
     )
     (if (= #fpu 4)
       (
	(set #fpu -1)
	(set #fpu_str #unknown)
       )
     )
    )
    (
     (set #fpu -1)
     (set #fpu_str #unknown)
    )
  )
 )

; --- AskLanguages ------------------------------------------------------------

 (procedure P_AskLanguages
  ; Params:
  ; #prompt #langmask #defaultmask
  ;
  ; Results:
  ; #langmask
  ;
  ; Used Vars:
  ; #bitmask

  (set #langmask (BITAND #langmask %1111111111111111111111111)) ; LANGUAGE
  (if #langmask
    (
     (set #bitmask (askoptions (prompt #prompt)
			       (help #help_askoptions @askoptions-help)
			       (default (BITAND #defaultmask #langmask))
			       (choices
				 (if (IN #langmask 0)
				   (cat #prop #choice_english)
				   ("")
				 )
				 (if (IN #langmask 1)
				   (cat #prop #choice_german)
				   ("")
				 )
				 (if (IN #langmask 2)
				   (cat #prop #choice_french)
				   ("")
				 )
				 (if (IN #langmask 3)
				   (cat #prop #choice_spanish)
				   ("")
				 )
				 (if (IN #langmask 4)
				   (cat #prop #choice_portuguese)
				   ("")
				 )
				 (if (IN #langmask 5)
				   (cat #prop #choice_danish)
				   ("")
				 )
				 (if (IN #langmask 6)
				   (cat #prop #choice_italian)
				   ("")
				 )
				 (if (IN #langmask 7)
				   (cat #prop #choice_dutch)
				   ("")
				 )
				 (if (IN #langmask 8)
				   (cat #prop #choice_norwegian)
				   ("")
				 )
				 (if (IN #langmask 9)
				   (cat #prop #choice_swedish)
				   ("")
				 )
				 (if (IN #langmask 10)
				   (cat #prop #choice_polish)
				   ("")
				 )
				 (if (IN #langmask 11)
				   (cat #prop #choice_finnish)
				   ("")
				 )
				 (if (IN #langmask 12)
				   (cat #prop #choice_hungarian)
				   ("")
				 )
				 (if (IN #langmask 13)
				   (cat #prop #choice_greek)
				   ("")
				 )
				 (if (IN #langmask 14)
				   (cat #prop #choice_esperanto)
				   ("")
				 )
				 (if (IN #langmask 15)
				   (cat #prop #choice_turkish)
				   ("")
				 )
				 (if (IN #langmask 16)
				   (cat #prop #choice_latin)
				   ("")
				 )
				 (if (IN #langmask 17)
				   (cat #prop #choice_russian)
				   ("")
				 )
				 (if (IN #langmask 18)
				   (cat #prop #choice_czech)
				   ("")
				 )
				 (if (IN #langmask 19)
				   (cat #prop #choice_catalonian)
				   ("")
				 )
				 (if (IN #langmask 20)
				   (cat #prop #choice_croatian)
				   ("")
				 )
				 (if (IN #langmask 21)
				   (cat #prop #choice_serbian)
				   ("")
				 )
				 (if (IN #langmask 22)
				   (cat #prop #choice_slovak)
				   ("")
				 )
				 (if (IN #langmask 23)
				   (cat #prop #choice_slovenian)
				   ("")
				 )
				 (if (IN #langmask 24)
				   (cat #prop #choice_portuguesebr)
				   ("")
				 )
				 ; LANGUAGE
			       )
		   )
     )
     (set #langmask (BITAND #langmask #bitmask))
    )
  )
 )

; --- AskDocFormat ------------------------------------------------------------

 (procedure P_AskDocFormats
  ; Params:
  ; #prompt #docmask #defaultmask
  ;
  ; Results:
  ; #docmask
  ;
  ; Used Vars:
  ; #bitmask

  (set #docmask (BITAND #docmask %111))
  (if #docmask
    (
     (set #bitmask (askoptions (prompt #prompt)
			       (help #help_askoptions @askoptions-help)
			       (default (BITAND #defaultmask #docmask))
			       (choices
				 (if (IN #docmask 0)
				   (cat #prop "ASCII")
				   ("")
				 )
				 (if (IN #docmask 1)
				   (cat #prop "AmigaGuide®")
				   ("")
				 )
				 (if (IN #docmask 2)
				   (cat #prop "HTML")
				   ("")
				 )
			       )
		   )
     )
     (set #docmask (BITAND #docmask #bitmask))
    )
  )
 )

; --- AskProgLang -------------------------------------------------------------

 (procedure P_AskProgLangs
  ; Params:
  ; #prompt #plangmask #defaultmask
  ;
  ; Results:
  ; #plangmask
  ;
  ; Used Vars:
  ; #bitmask

  (set #plangmask (BITAND #plangmask %001111101))
  (if #plangmask
    (
     (set #bitmask (askoptions (prompt #prompt)
			       (help #help_askoptions @askoptions-help)
			       (default (BITAND #defaultmask #plangmask))
			       (choices
				 (if (IN #plangmask 0)
				   (cat #prop "C")
				   ("")
				 )
				 (if (IN #plangmask 1)
				   (cat #prop "C++")
				   ("")
				 )
				 (if (IN #plangmask 2)
				   (cat #prop "Assembler")
				   ("")
				 )
				 (if (IN #plangmask 3)
				   (cat #prop "Amiga-E")
				   ("")
				 )
				 (if (IN #plangmask 4)
				   (cat #prop "Modula-II")
				   ("")
				 )
				 (if (IN #plangmask 5)
				   (cat #prop "Oberon")
				   ("")
				 )
				 (if (IN #plangmask 6)
				   (cat #prop "ARexx")
				   ("")
				 )
				 (if (IN #plangmask 7)
				   (cat #prop "Cluster")
				   ("")
				 )
				 (if (IN #plangmask 8)
				   (cat #prop "Blitz Basic 2")
				   ("")
				 )
			       )
		   )
     )
     (set #plangmask (BITAND #plangmask #bitmask))
    )
  )
 )

; --- DelEmptyDir -------------------------------------------------------------

 (procedure P_DelEmptyDir
  ; Params:
  ; #dir
  ;
  ; Results:
  ;
  ; Used Vars:
  ; #i

  (set #i 0)
  (if (exists #dir (noreq))
    (
     (foreach #dir "#?"
       (set #i (+ #i 1))
     )
     (if (NOT #i)
       (
	(delete #dir (optional "force"))
	(delete (cat #dir ".info") (optional "force"))
       )
     )
    )
  )
 )

; --- DelDirRecursiv ----------------------------------------------------------

 (procedure P_DelDirRecursive
  ; Params:
  ; #dir
  ;
  ; Results:
  ;
  ; Used Vars:
  ;

  (foreach #dir "#?"
    (if (< @each-type 0)
      (delete (tackon #dir @each-name) (optional "force"))
      (
       (set #dir (tackon #dir @each-name))
       (P_DelDirRecursive)
       (set #dir (pathonly #dir))
      )
    )
  )
  (delete #dir (optional "force"))
  (delete (cat #dir ".info") (optional "force"))
 )

; --- DeleteLanguages ---------------------------------------------------------

 (procedure P_DeleteLanguages
  ; Params:
  ; #dir #file #langmask
  ;
  ; Results:
  ; #langmask
  ;
  ; Used Vars:
  ; #i #lang

  (while (P_BitToLanguage)
    (
     (delete (tackon (tackon #dir #lang) #file) (optional "force"))
     (delete (tackon (tackon #dir #lang) (cat #file ".info")) (optional "force"))
     (set #i 0)
     (foreach (tackon #dir #lang) "#?"
       (set #i (+ #i 1))
     )
     (if (NOT #i)
       (
	(delete (tackon #dir #lang) (optional "force"))
	(delete (tackon #dir (cat #lang ".info")) (optional "force"))
       )
     )
    )
  )
 )

; --- MkDirInfo ---------------------------------------------------------------

 (procedure P_MkDirInfo
  ; Params:
  ; #dir #infos #dest-dir
  ;
  ; Results:
  ;
  ; Used Vars:

  (if (NOT (exists (tackon #dest-dir #dir) (noreq)))
    (if #infos
      (makedir (tackon #dest-dir #dir) (prompt #prompt_makedir "\n\n" (tackon #dest-dir #dir)) (help @makedir-help) (infos) (confirm "expert"))
      (makedir (tackon #dest-dir #dir) (prompt #prompt_makedir "\n\n" (tackon #dest-dir #dir)) (help @makedir-help) (confirm "expert"))
    )
  )
 )

; --- CpFile ------------------------------------------------------------------

 (procedure P_CpFile
  ; Params:
  ; #dir #file #infos #dest-dir #src-dir #pattern
  ;
  ; Results:
  ;
  ; Used Vars:

  (if #pattern
    (if #infos
      (copyfiles (prompt #prompt_copy)
		 (help @copyfiles-help)
		 (source (tackon #src-dir #dir))
		 (dest (tackon #dest-dir #dir))
		 (pattern #file)
		 (files)
		 (infos)
		 (optional "nofail" "force")
		 (confirm "expert")
      )
      (copyfiles (prompt #prompt_copy)
		 (help @copyfiles-help)
		 (source (tackon #src-dir #dir))
		 (dest (tackon #dest-dir #dir))
		 (pattern #file)
		 (files)
		 (optional "nofail" "force")
		 (confirm "expert")
      )
    )
    (if #infos
      (copyfiles (prompt #prompt_copy)
		 (help @copyfiles-help)
		 (source (tackon (tackon #src-dir #dir) #file))
		 (dest (tackon #dest-dir #dir))
		 (files)
		 (infos)
		 (optional "nofail" "force")
		 (confirm "expert")
      )
      (copyfiles (prompt #prompt_copy)
		 (help @copyfiles-help)
		 (source (tackon (tackon #src-dir #dir) #file))
		 (dest (tackon #dest-dir #dir))
		 (files)
		 (optional "nofail" "force")
		 (confirm "expert")
      )
    )
  )
 )

; --- AskCPUFPU ---------------------------------------------------------------

 (procedure P_AskCPUFPU
  ; Params:
  ; #src-dir
  ;
  ; Results:
  ; #cpu #cpu_str #lib_cpu_file_extension #src-dir
  ;
  ; Used Vars:
  ; #i #file #bitmask #filetype #f #lib_cpus #lib_fpus #dir
  ; #defaultcpu #lib_cpu_counter #fpu #fpu_str #cpu2

  (set #dir (tackon #src-dir "libs"))
  (P_CheckAvailableCPUs)
  (P_GetCPUFPU)
  (set #defaultcpu -1)
  (while (AND (>= #cpu 0) (= #defaultcpu -1))
    (
     (if (AND #fpu (IN #lib_fpus #cpu))
       (set #defaultcpu (select #cpu -1 -1 3 5 7 -1))
       (if (IN #lib_cpus #cpu)
	 (set #defaultcpu (select #cpu 0 1 2 4 6 8))
       )
     )
     (set #cpu (- #cpu 1))
    )
  )

  (if (AND (> #lib_cpu_counter 1) (= @user-level 2))
    (
     (set #cpu (askchoice (prompt #prompt_askcpufpu)
			  (help #help_askchoice @askchoice-help)
			  (default #defaultcpu)
			  (choices
			    (if (IN #lib_cpus 0)
			      (cat #prop "68000")
			      ("")
			    )
			    (if (IN #lib_cpus 1)
			      (cat #prop "68010")
			      ("")
			    )
			    (if (IN #lib_cpus 2)
			      (cat #prop "68020")
			      ("")
			    )
			    (if (IN #lib_fpus 2)
			      (cat #prop "68020+fpu")
			      ("")
			    )
			    (if (IN #lib_cpus 3)
			      (cat #prop "68030")
			      ("")
			    )
			    (if (IN #lib_fpus 3)
			      (cat #prop "68030+fpu")
			      ("")
			    )
			    (if (IN #lib_cpus 4)
			      (cat #prop "68040")
			      ("")
			    )
			    (if (IN #lib_fpus 4)
			      (cat #prop "68040+fpu")
			      ("")
			    )
			    (if (IN #lib_cpus 5)
			      (cat #prop "68060")
			      ("")
			    )
			  )
	       )
     )
    )
    (set #cpu #defaultcpu)
  )
  (if (<> #cpu -1)
    (
     ; select lower cpu if not available
     (set #cpu2 (select #cpu 0 1 2 2 3 3 4 4 5))
     (set #fpu2 (select #cpu 0 0 0 1 0 1 0 1 0))
     (while (NOT (OR (AND #fpu2 (AND #fpu (IN #lib_fpus #cpu2))) (AND (NOT #fpu2) (IN #lib_cpus #cpu2))))
       (
	(set #cpu (- #cpu 1))
	(set #cpu2 (select #cpu 0 1 2 2 3 3 4 4 5))
	(set #fpu2 (select #cpu 0 0 0 1 0 1 0 1 0))
       )
     )

     (set #cpu_str (select #cpu "68000" "68010" "68020" "68020+fpu" "68030" "68030+fpu" "68040" "68040+fpu" "68060"))
     (set #lib_cpu_file_extension (select #cpu (if (exists (tackon #dir (cat @app-name "000.lib")) (noreq)) ("000") ("")) "010" "020" "020f" "030" "030f" "040" "040f" "060"))
     (set #cpu #cpu2)
    )
    (
     (set #cpu2 -1)
     (set #fpu2 0)
     (set #cpu_str "")
     (set #lib_cpu_file_extension "")
    )
  )
  (if (= #cpu -1)
    (abort #abort_nocpu)
  )
 )

; --- AskParts ----------------------------------------------------------------

 (procedure P_AskParts
  ; Params:
  ; #prompt #defaultmask #existsmask
  ;
  ; Results:
  ; #parts
  ;
  ; Used Vars:

  (set #existsmask (if (= @user-level 2)
		     #existsmask
		     (BITAND #existsmask %00111)
		   )
  )
  (if #existsmask
    (
     (set #parts (askoptions (prompt #prompt)
			     (help #help_askoptions @askoptions-help)
			     (default (BITAND #defaultmask #existsmask))
			     (choices
				(if (IN #existsmask 0)
				  (cat #prop #choice_catalogs)
				  ("")
				)
				(if (IN #existsmask 1)
				  (cat #prop #choice_docs)
				  ("")
				)
				(if (IN #existsmask 2)
				  (cat #prop @app-name "-Demo")
				  ("")
				)
				(if (IN #existsmask 3)
				  (cat #prop #choice_developer)
				  ("")
				)
				(if (IN #existsmask 4)
				  (cat #prop #choice_source)
				  ("")
				)
			     )
		 )
     )
     (set #parts (BITAND #parts #existsmask))
    )
    (set #parts 0)
  )
 )

; --- CheckAvailableCPUs ------------------------------------------------------

 (procedure P_CheckAvailableCPUs
  ; Params:
  ; #dir @app-name
  ;
  ; Results:
  ; #lib_cpus #lib_fpus #lib_cpu_counter
  ;
  ; Used Vars:
  ; #i #file #bitmask #filetype #f

  (set #lib_cpus %000000)
  (set #lib_fpus %000000)
  (set #lib_cpu_counter 0)
  (if (OR
	(OR
	  (OR
	    (OR
	      (exists (tackon #dir (cat @app-name ".library")) (noreq))
	      (exists (tackon #dir (cat @app-name "000.library")) (noreq))
	    )
	    (OR
	      (exists (tackon #dir (cat @app-name "010.library")) (noreq))
	      (exists (tackon #dir (cat @app-name "020.library")) (noreq))
	    )
	  )
	  (OR
	    (OR
	      (exists (tackon #dir (cat @app-name "030.library")) (noreq))
	      (exists (tackon #dir (cat @app-name "040.library")) (noreq))
	    )
	    (exists (tackon #dir (cat @app-name "060.library")) (noreq))
	  )
	)
	(OR
	  (OR
	    (exists (tackon #dir (cat @app-name "020f.library")) (noreq))
	    (exists (tackon #dir (cat @app-name "030f.library")) (noreq))
	  )
	  (exists (tackon #dir (cat @app-name "040f.library")) (noreq))
	)
      )
    (foreach #dir (cat @app-name "(%|0(0|1|2|3|4|6)0)(%|f).library")
      (
       (set #i 0)
       (set #file (substr @each-name (strlen @app-name)))
       (set #f (patmatch "#?f.library" #file))
       (if #f
	 (set #file (cat (substr #file 0 (- (strlen #file) 9)) ".library"))
       )
       (set #bitmask %000001)
       (while (NOT (patmatch (select #i "(%|000).library" "010.library" "020.library" "030.library" "040.library" "060.library") #file))
	 (
	  (set #bitmask (shiftleft #bitmask 1))
	  (set #i (+ #i 1))
	 )
       )
       (if #f
	 (set #lib_fpus (BITOR #lib_fpus #bitmask))
	 (set #lib_cpus (BITOR #lib_cpus #bitmask))
       )
       (set #lib_cpu_counter (+ #lib_cpu_counter 1))
      )
    )
  )
 )

; --- CheckExists -------------------------------------------------------------

 (procedure P_CheckExists
   ; Param:
   ; #dir
   ;
   ; Results:
   ; #chk_lib #chk_demo #chk_catalogs #chk_agdocs #chk_proglang
   ; #chk_autodoc #chk_c_h #chk_c_example #chk_asm_i #chk_asm_example #chk_e_e
   ; #chk_e_example #chk_modula_def #chk_modula_mod #chk_modula_demo
   ; #chk_oberon_mod #chk_oberon_example #chk_existsmask
   ; #chk_docs #chk_progdirs #chk_asciidocs #chk_source
   ; #chk_htmldocs #chk_rexx #chk_rexx_example #chk_cluster_def
   ; #chk_cluster_mod #chk_cluster_demo #chk_bb2 #chk_bb2_example
   ;
   ; Vars used:
   ; #i #lang

   ; Custom Class
   (set #chk_lib (exists (tackon (tackon #dir "Libs") (cat @app-name ".library")) (noreq)))

   ; Demo
   (set #chk_demo (exists (tackon (tackon #dir "Demos") (cat @app-name "-Demo")) (noreq)))

   ; Catalogs + Documentation
   (set #chk_catalogs  %0000000000000000000000000) ; LANGUAGE
   (set #chk_asciidocs %0000000000000000000000000) ; LANGUAGE
   (set #chk_agdocs    %0000000000000000000000000) ; LANGUAGE
   (set #chk_htmldocs  %0000000000000000000000000) ; LANGUAGE
   (set #langmask      %1111111111111111111111111) ; LANGUAGE
   (while (P_BitToLanguage)
     (
      ; Catalogs
      (if (exists (tackon (tackon (tackon #dir "locale/catalogs") #lang) (cat @app-name "_lib.catalog")) (noreq))
	(
	 (set #chk_catalogs (BITOR #chk_catalogs %10000000000000000000000000)) ; LANGUAGE
	 (set #chk_catalogs (shiftright #chk_catalogs 1))
	)
	(set #chk_catalogs (shiftright #chk_catalogs 1))
      )

      ; Docs/ASCII
      (if (exists (tackon (tackon (tackon #dir "Docs") #lang) (cat @app-name "Lib.doc")) (noreq))
	(
	 (set #chk_asciidocs (BITOR #chk_asciidocs %10000000000000000000000000)) ; LANGUAGE
	 (set #chk_asciidocs (shiftright #chk_asciidocs 1))
	)
	(set #chk_asciidocs (shiftright #chk_asciidocs 1))
      )

      ; Docs/AmigaGuide
      (if (exists (tackon (tackon (tackon #dir "Docs") #lang) (cat @app-name "Lib.guide")) (noreq))
	(
	 (set #chk_agdocs (BITOR #chk_agdocs %10000000000000000000000000)) ; LANGUAGE
	 (set #chk_agdocs (shiftright #chk_agdocs 1))
	)
	(set #chk_agdocs (shiftright #chk_agdocs 1))
      )

      ; Docs/HTML
      (if (exists (tackon (tackon (tackon #dir "Docs") #lang) (cat @app-name "_home.html")) (noreq))
	(
	 (set #chk_htmldocs (BITOR #chk_htmldocs %10000000000000000000000000)) ; LANGUAGE
	 (set #chk_htmldocs (shiftright #chk_htmldocs 1))
	)
	(set #chk_htmldocs (shiftright #chk_htmldocs 1))
      )

     )
   )
   (set #chk_docs (BITOR
		    (if #chk_htmldocs  %100 %000)
		    (BITOR
		      (if #chk_agdocs	 %010 %000)
		      (if #chk_asciidocs %001 %000)
		    )
		  )
   )

   ; Developer
   (set #chk_proglang %0000000000)
   (set #chk_progdirs %0000000000)
   (set #chk_autodoc (exists (tackon (tackon #dir "Developer/Autodocs") (cat @app-name ".doc")) (noreq)))
   ; C
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/C") (noreq)) %0000000001 %0000000000)))
   (set #chk_c_h       (exists (tackon (tackon #dir "Developer/C/Include/Libraries") (cat @app-name ".h")) (noreq)))
   (set #chk_c_example (exists (tackon (tackon #dir "Developer/C/Examples") (cat @app-name "-Demo.c")) (noreq)))
   (if #chk_c_h
     (set #chk_proglang (BITOR #chk_proglang %0000000001))
   )
   ; C++

   ; Assembler
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/Assembler") (noreq)) %0000000100 %0000000000)))
   (set #chk_asm_i	 (exists (tackon (tackon #dir "Developer/Assembler/Include/Libraries") (cat @app-name ".i")) (noreq)))
   (set #chk_asm_example (exists (tackon (tackon #dir "Developer/Assembler/Examples") (cat @app-name "-Demo.s")) (noreq)))
   (if #chk_asm_i
     (set #chk_proglang (BITOR #chk_proglang %0000000100))
   )
   ; Amiga-E
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/Amiga-E") (noreq)) %0000001000 %0000000000)))
   (set #chk_e_e       (exists (tackon (tackon #dir "Developer/Amiga-E/Modules/Libraries") (cat @app-name ".e")) (noreq)))
   (set #chk_e_example (exists (tackon (tackon #dir "Developer/Amiga-E/Examples") (cat @app-name "-Demo.e")) (noreq)))
   (if #chk_e_e
     (set #chk_proglang (BITOR #chk_proglang %0000001000))
   )
   ; Modula-II
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/Modula") (noreq)) %0000010000 %0000000000)))
   (set #chk_modula_def  (exists (tackon (tackon #dir "Developer/Modula/Defs") (cat @app-name "D.def")) (noreq)))
   (set #chk_modula_mod  (exists (tackon (tackon #dir "Developer/Modula/Defs") (cat @app-name "L.def")) (noreq)))
   (set #chk_modula_demo (exists (tackon (tackon #dir "Developer/Modula/Demo") (cat @app-name "Demo.mod")) (noreq)))
   (if (AND #chk_modula_def #chk_modula_mod)
     (set #chk_proglang (BITOR #chk_proglang %0000010000))
   )
   ; Oberon
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/Oberon") (noreq)) %0000100000 %0000000000)))
   (set #chk_oberon_mod     (exists (tackon (tackon #dir "Developer/Oberon/Interfaces") (cat @app-name ".mod")) (noreq)))
   (set #chk_oberon_example (exists (tackon (tackon #dir "Developer/Oberon/Examples") (cat @app-name "Demo.mod")) (noreq)))
   (if #chk_oberon_mod
     (set #chk_proglang (BITOR #chk_proglang %0000100000))
   )
   ; ARexx
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/Rexx") (noreq)) %0001000000 %0000000000)))
   (set #chk_rexx  (exists (tackon (tackon #dir "Developer/Rexx/Include") (cat @app-name ".rexx")) (noreq)))
   (set #chk_rexx_example (exists (tackon (tackon #dir "Developer/Rexx/Examples") (cat @app-name "-Demo.rexx")) (noreq)))
   (if #chk_rexx
     (set #chk_proglang (BITOR #chk_proglang %0001000000))
   )
   ; Cluster
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/Cluster") (noreq)) %0010000000 %0000000000)))
   (set #chk_cluster_def  (exists (tackon (tackon #dir "Developer/Cluster/txt") (cat @app-name ".def")) (noreq)))
   (set #chk_cluster_mod  (exists (tackon (tackon #dir "Developer/Cluster/txt") (cat @app-name ".mod")) (noreq)))
   (set #chk_cluster_demo (exists (tackon (tackon #dir "Developer/Cluster/txt") (cat @app-name "Demo.mod")) (noreq)))
   (if (AND #chk_cluster_def #chk_cluster_mod)
     (set #chk_proglang (BITOR #chk_proglang %0010000000))
   )
   ; Blitz Basic 2
   (set #chk_progdirs (BITOR #chk_progdirs (if (exists (tackon #dir "Developer/BB2") (noreq)) %0100000000 %0000000000)))
   (set #chk_bb2  (exists (tackon (tackon #dir "Developer/BB2/Include/Libraries") (cat @app-name ".asc")) (noreq)))
   (set #chk_bb2_example (exists (tackon (tackon #dir "Developer/BB2/Examples") (cat @app-name "-Demo.asc")) (noreq)))
   (if #chk_bb2
     (set #chk_proglang (BITOR #chk_proglang %0100000000))
   )

   ; Source
   (if (= (exists (tackon (tackon #dir "Developer/Source") (cat @app-name "Lib")) (noreq)) 2)
     (set #chk_source 1)
     (set #chk_source 0)
   )

   (set #chk_existsmask (BITOR
			  (if #chk_catalogs %00001 %00000)
			  (BITOR
			    (if #chk_docs %00010 %00000)
			    (BITOR
			      (if #chk_demo %00100 %00000)
			      (BITOR
			        (if #chk_proglang %01000 %00000)
			        (if #chk_source %10000 %00000)
			      )
			    )
			  )
			)
   )
 )

; --- CheckInstalled ----------------------------------------------------------

 (procedure P_CheckInstalled
   ; Param:
   ; #dir
   ;
   ; Results:
   ; #old_lib #old_demo #old_catalogs #old_proglang
   ; #old_c_h #old_asm_i #old_e_e
   ; #old_modula_def #old_modula_mod
   ; #old_oberon_mod #old_existsmask
   ; #old_progdirs
   ; #old_rexx #old_cluster_def
   ; #old_cluster_mod #old_bb2
   ;
   ; Vars used:
   ; #i #lang

   ; Custom Class
   (set #old_lib (exists (tackon "Libs:" (cat @app-name ".library")) (noreq)))

   ; Catalogs + Documentation
   (set #old_catalogs  %0000000000000000000000000) ; LANGUAGE
   (set #langmask      %1111111111111111111111111) ; LANGUAGE
   (while (P_BitToLanguage)
     (
      ; Catalogs
      (if (exists (tackon (tackon "Locale:catalogs" #lang) (cat @app-name "_lib.catalog")) (noreq))
	(
	 (set #old_catalogs (BITOR #old_catalogs %10000000000000000000000000)) ; LANGUAGE
	 (set #old_catalogs (shiftright #old_catalogs 1))
	)
	(set #old_catalogs (shiftright #old_catalogs 1))
      )

     )
   )

   ; Developer
   (set #old_proglang %0000000000)
   ; C
   (set #old_c_h       (exists (tackon "Include:Libraries" (cat @app-name ".h")) (noreq)))
   (if #old_c_h
     (set #old_proglang (BITOR #old_proglang %0000000001))
     (set #old_progdirs (BITOR #old_progdirs %0000000001))
   )
   ; C++

   ; Assembler

   (set #old_asm_i	 (exists (tackon "AINC:Libraries" (cat @app-name ".i")) (noreq)))
   (if #old_asm_i
     (set #old_proglang (BITOR #old_proglang %0000000100))
     (set #old_progdirs (BITOR #old_progdirs %0000000100))
   )
   ; Amiga-E
   (set #old_e_e       (exists (tackon "EModules:Libraries" (cat @app-name ".e")) (noreq)))
   (if #old_e_e
     (set #old_proglang (BITOR #old_proglang %0000001000))
     (set #old_progdirs (BITOR #old_progdirs %0000001000))
   )
   ; Modula-II
   (set #old_modula_def  (exists (tackon "M2:Defs" (cat @app-name "D.def")) (noreq)))
   (set #old_modula_mod  (exists (tackon "M2:Defs" (cat @app-name "L.def")) (noreq)))
   (if (AND #old_modula_def #old_modula_mod)
     (set #old_proglang (BITOR #old_proglang %0000010000))
     (set #old_progdirs (BITOR #old_progdirs %0000010000))
   )
   ; Oberon
   (set #old_oberon_mod     (exists (tackon "Oberon:Interfaces" (cat @app-name ".mod")) (noreq)))
   (if #old_oberon_mod
     (set #old_proglang (BITOR #old_proglang %0000100000))
     (set #old_progdirs (BITOR #old_progdirs %0000100000))
   )
   ; ARexx
   (set #old_rexx  (exists (tackon "Rexx:" (cat @app-name ".rexx")) (noreq)))
   (if #old_rexx
     (set #old_proglang (BITOR #old_proglang %0001000000))
     (set #old_progdirs (BITOR #old_progdirs %0001000000))
   )
   ; Cluster
 ;   (set #old_cluster_def  (exists (tackon "Cluster:txt" (cat @app-name ".def")) (noreq)))
 ;   (set #old_cluster_mod  (exists (tackon "Cluster:txt" (cat @app-name ".mod")) (noreq)))
 ;   (if (AND #old_cluster_def #old_cluster_mod)
 ;     (set #old_proglang (BITOR #old_proglang %0010000000))
 ;     (set #old_progdirs (BITOR #old_progdirs %0010000000))
 ;   )
   ; Blitz Basic 2
 ;   (set #old_bb2  (exists (tackon "BLITZ2:Include/Libraries" (cat @app-name ".asc")) (noreq)))
 ;   (if #old_bb2
 ;     (set #old_proglang (BITOR #old_proglang %0100000000))
 ;     (set #old_progdirs (BITOR #old_progdirs %0100000000))
 ;   )

   (set #old_existsmask (BITOR
			  (if #old_catalogs %00001 %00000)
			  (BITOR
			    (if #old_docs %00010 %00000)
			    (BITOR
			      (if #old_demo %00100 %00000)
			      (if #old_proglang %01000 %00000)
			    )
			  )
			)
   )
 )

; --- Install -----------------------------------------------------------------

 (procedure P_Install
  ; Params:
  ; #chk_lib #chk_demo #chk_catalogs #chk_docs
  ; #chk_asciidocs #chk_agdocs #chk_proglang #chk_progdirs #chk_autodoc
  ; #old_lib #old_demo #old_catalogs #old_docs
  ; #old_asciidocs #old_agdocs #old_proglang #old_progdirs #old_autodoc
  ; #update #lib_cpu_counter #chk_source #chk_existsmask #src-dir #dest-dir
  ; #chk_htmldocs
  ;
  ; Results:
  ;
  ; Used Vars:
  ; #dir #file #result #update #defaultmask
  ; #parts #prompt #langmask #install_catalogs
  ; #docmask #install_docs #install_asciidocs #install_agdocs #install_demo
  ; #plangmask #install_proglang #infos #existsmask #install_htmldocs

  ; Update existing version or install newer one

  (if (= #update 1)
    (
     (set #prompt #prompt_update)
     (set #existsmask (BITAND #chk_existsmask (BITOR
						(if (AND (NOT #old_demo) #chk_demo) %01001 %01001)
					        (if (AND (NOT #old_source) #chk_source) %01001 %01001)
					      )
			  )
     )
     (set #defaultmask %0000000)
     (P_AskParts)
    )
  )

  ; (P_AskCPUFPU)
  (if (NOT #update)
    (P_AskCPUFPU)
    (set #lib_cpu_counter 0)
  )

  ; lib (P_AskLanguages)
  (if (OR (NOT #update) (AND #update (IN #parts 0)))
    (
     (set #prompt #prompt_install_catalogs)
     (set #langmask (if #update (BITAND #chk_catalogs (BITNOT #old_catalogs)) #chk_catalogs))
     (set #defaultmask (if #update (BITAND #language_default (BITNOT #old_catalogs)) (BITOR #language_default #old_catalogs)))
     (P_AskLanguages)
     (set #install_catalogs #langmask)
    )
    (set #install_catalogs 0)
  )

  ; (P_AskProgLangs)
  (if (OR (AND (NOT #update) (= @user-level 2)) (AND #update (IN #parts 3)))
    (
     (set #prompt #prompt_install_plangs)
     (set #plangmask (if #update (BITAND #chk_proglang (BITNOT #old_proglang)) #chk_proglang))
     (set #defaultmask #old_progdirs)
     (P_AskProgLangs)
     (set #install_proglang #plangmask)
    )
    (set #install_proglang 0)
  )

  (complete 0)

  ; lib
  (if (AND (> #lib_cpu_counter 0) (NOT #update))
    (copyfiles (prompt #prompt_copy "\n\n" @app-name #lib_cpu_file_extension ".library")
	       (help @copylib-help)
	       (confirm "expert")
	       (source (tackon (tackon #src-dir "libs") (cat @app-name #lib_cpu_file_extension ".library")))
	       (dest "Libs:")
	       (newname (cat @app-name ".library"))
	       (optional "oknodelete" "force")
    )
  )
  (complete 11)

  ; lib catalogs
  (if #install_catalogs
    (
     (set #infos 0)
     (set #pattern 0)
     (set #langmask #install_catalogs)
     (set #src-dir  "Locale")
     (set #dest-dir "Locale:")
     (while #langmask
       (
	(P_BitToLanguage)
	(set #dir (tackon "Catalogs" #lang))
	(P_MkDirInfo)
	(set #file (cat @app-name "_lib.catalog"))
	(P_CpFile)
       )
     )
    )
  )
  (complete 33)

  (if #install_proglang
    (
     ; C
     (if (IN #install_proglang 0)
       (
        (set #src-dir  "Developer/C/Include")
        (set #dest-dir "Include:")
	(set #infos 0)
	(set #dir "Libraries")
	(set #pattern 0)
	(set #file (cat @app-name ".h"))
	(P_CpFile)
	(set #dir "Proto")
	(set #file (cat @app-name ".h"))
	(P_CpFile)
	(set #dir "CLib")
	(set #file (cat @app-name "_protos.h"))
	(P_CpFile)
	(set #dir "Pragmas")
	(set #file (cat @app-name "_pragmas.h"))
	(P_CpFile)
       )
     )

     ; C++
     (if (IN #install_proglang 1)
     )

     ; Asm
     (if (IN #install_proglang 2)
       (
        (set #src-dir  "Developer/Assembler/Include")
        (set #dest-dir "AINC:") ; OMA
	(set #infos 0)
	(set #dir "Libraries")
	(set #file (cat @app-name ".i"))
	(set #pattern 0)
	(P_CpFile)
	(set #dir "lvo")
	(set #file (cat @app-name ".i"))
	(P_CpFile)
       )
     )

     ; Amiga-E
     (if (IN #install_proglang 3)
       (
        (set #src-dir  "Developer/Amiga-E/Modules")
        (set #dest-dir "EMODULES:")
	(set #infos 0)
	(set #dir "")
	(set #file (cat @app-name "_pragmas.m"))
	(set #pattern 0)
	(P_CpFile)
	(set #dir "Libraries")
	(set #file (cat @app-name ".e"))
	(P_CpFile)
       )
     )

     ; Modula-II
     (if (IN #install_proglang 4)
       (
        (set #src-dir  "Developer/Modula")
        (set #dest-dir "M2:")
	(set #infos 0)
	(set #dir "Defs")
	(set #pattern 0)
	(set #file (cat @app-name "D.def"))
	(P_CpFile)
	(set #file (cat @app-name "L.def"))
	(P_CpFile)
       )
     )

     ; Oberon
     (if (IN #install_proglang 5)
       (
        (set #src-dir  "Developer/Oberon")
        (set #dest-dir "Oberon:")
	(set #infos 0)
	(set #dir "Interfaces")
	(set #file (cat @app-name ".mod"))
	(set #pattern 0)
	(P_CpFile)
       )
     )

     ; ARexx
     (if (IN #install_proglang 6)
       (
        (set #src-dir  "Developer/Rexx/Include")
        (set #dest-dir "Rexx:")
	(set #infos 0)
	(set #dir "")
	(set #pattern 0)
	(set #file (cat @app-name ".rexx"))
	(P_CpFile)
       )
     )

     ; Cluster
     (if (IN #install_proglang 7)
 ;     (
 ;	(set #src-dir  "Developer/Cluster/txt")
 ;	(set #dest-dir "Cluster:Modules")
 ;	(set #infos 0)
 ;	(set #dir "")
 ;	(set #pattern 0)
 ;	(set #file (cat @app-name ".def"))
 ;	(P_CpFile)
 ;	(set #file (cat @app-name ".mod"))
 ;	(P_CpFile)
 ;     )
     )

     ; Blitz Basic 2
     (if (IN #install_proglang 8)
 ;     (
 ;	(set #src-dir  "Developer/BB2")
 ;	(set #dest-dir "BLITZ2:")
 ;	(set #infos 0)
 ;	(set #dir "Include/Libraries")
 ;	(set #pattern 0)
 ;	(set #file (cat @app-name ".asc"))
 ;	(P_CpFile)
 ;	(set #dir "blitzlibs/amigalibs")
 ;	(set #file (cat @app-name ".library1"))
 ;	(P_CpFile)
 ;     )
     )

    )
  )

  (P_CustomInstall)
  (complete 100)
 )

; --- Uninstall ---------------------------------------------------------------

 (procedure P_Uninstall
  ; Params:
  ; #old_catalogs #old_docs #old_proglang #old_lib
  ; #old_asciidocs #old_agdocs #old_demo
  ; #old_c_h #old_c_example #old_asm_i #old_asm_example #old_e_e #old_e_example
  ; #old_modula_def #old_modula_mod #old_modula_demo #old_oberon_mod
  ; #old_oberon_example #old_autodoc #old_source #old_existsmask #dest-dir
  ; #old_htmldocs #old_rexx #old_rexx_example #old_cluster_def
  ; #old_cluster_mod #old_cluster_demo #old_bb2 #old_bb2_example
  ;
  ; Results:
  ;
  ; Used Vars:
  ; #all #prompt #parts #defaultmask #langmask #uninstall_catalogs
  ; #docmask #uninstall_asciidocs #uninstall_agdocs
  ; #plangmask #uninstall_proglang #dir #file #existsmask #oldlangmask

  (set #existsmask #old_existsmask)
  (set #all (askbool (prompt #prompt_uninstall_all)
		     (help #help_uninstall_all)
		     (default 1)
	    )
  )
  (if (NOT #all)
    (
     (set #prompt #prompt_uninstall_parts)
     (set #defaultmask %0000000)
     (P_AskParts)
     (if (IN #parts 0)
       (
	(set #prompt #prompt_uninstall_catalogs)
	(set #langmask #old_catalogs)
	(set #defaultmask %0000000000000000000000000) ; LANGUAGE
	(P_AskLanguages)
	(set #uninstall_catalogs #langmask)
       )
     )

     (if (IN #parts 3)
       (
	(set #prompt #prompt_uninstall_plangs)
	(set #plangmask #old_proglang)
	(set #defaultmask %0000000000)
	(P_AskProgLangs)
	(set #uninstall_proglang #plangmask)
       )
     )
    )
  )
  (complete 0)

  ; lib
  (if (AND #old_lib #all)
    (delete (tackon #dest-dir (cat @app-name ".library")) (optional "force"))
  )
  (complete 13)

  ; Catalogs
  (if (AND #old_catalogs (OR #all (IN #parts 0)))
    (
     (if #old_catalogs
       (
	(set #dir "Locale:Catalogs")
	(set #file (cat @app-name "_lib.catalog"))
	(set #langmask (if #all #old_catalogs #uninstall_catalogs))
	(P_DeleteLanguages)
       )
     )
    )
  )
  (complete 38)

   ; Developer
  (if (AND #old_proglang (OR #all (IN #parts 3)))
    (

     ; C
     (if (OR #all (IN #uninstall_proglang 0))
       (
	(if #old_c_h
	  (
	   (set #dest-dir "Include:")
	   (set #dir (tackon #dest-dir "Libraries"))
	   (delete (tackon #dir (cat @app-name ".h")) (optional "force"))
	   (set #dir (tackon #dest-dir "Proto"))
	   (delete (tackon #dir (cat @app-name ".h")) (optional "force"))
	   (set #dir (tackon #dest-dir "CLib"))
	   (delete (tackon #dir (cat @app-name "_protos.h")) (optional "force"))
	   (set #dir (tackon #dest-dir "Pragmas"))
	   (delete (tackon #dir (cat @app-name "_pragmas.h")) (optional "force"))
	  )
	)
       )
     )

     ; C++
;    (if (OR #all (IN #uninstall_proglang 1))
;    )

     ; Asm
     (if (OR #all (IN #uninstall_proglang 2))
       (
	(if #old_asm_i
	  (
	   (set #dest-dir "AINC:")
	   (set #dir (tackon #dest-dir "Libraries"))
	   (delete (tackon #dir (cat @app-name ".i")) (optional "force"))
	   (set #dir (tackon #dest-dir "lvo"))
	   (delete (tackon #dir (cat @app-name ".i")) (optional "force"))
	  )
	)
       )
     )

     ; Amiga-E
     (if (OR #all (IN #uninstall_proglang 3))
       (
	(if #old_e_e
	  (
	   (set #dest-dir "EMODULES:")
	   (set #dir (tackon #dest-dir "Libraries"))
	   (delete (tackon #dir (cat @app-name ".e")) (optional "force"))
	   (set #dir (tackon #dest-dir ""))
	   (delete (tackon #dir (cat @app-name "_pragmas.m")) (optional "force"))
	  )
	)
       )
     )

     ; Modula-II
     (if (OR #all (IN #uninstall_proglang 4))
       (
        (set #dest-dir "M2:")
	(set #dir (tackon #dest-dir "Defs"))
	(if #old_modula_def
	  (delete (tackon #dir (cat @app-name "D.def")) (optional "force"))
	)
	(if #old_modula_mod
	  (delete (tackon #dir (cat @app-name "L.def")) (optional "force"))
	)
       )
     )

     ; Oberon
     (if (OR #all (IN #uninstall_proglang 5))
       (
        (set #dest-dir "Oberon:")
	(if #old_oberon_mod
	  (
	   (set #dir (tackon #dest-dir "Interfaces"))
	   (delete (tackon #dir (cat @app-name ".mod")) (optional "force"))
	  )
	)
       )
     )

     ; ARexx
     (if (OR #all (IN #uninstall_proglang 6))
       (
        (set #dest-dir "Rexx:")
	(if #old_rexx
	  (
	   (set #dir (tackon #dest-dir ""))
	   (delete (tackon #dir (cat @app-name ".rexx")) (optional "force"))
	  )
	)
       )
     )

     ; Cluster
 ;   (if (OR #all (IN #uninstall_proglang 7))
 ;     (
 ;      (set #dest-dir "Cluster:")
 ;	(set #dir (tackon #dest-dir "txt"))
 ;	(if #old_cluster_def
 ;	  (delete (tackon #dir (cat @app-name ".def")) (optional "force"))
 ;	)
 ;	(if #old_cluster_mod
 ;	  (delete (tackon #dir (cat @app-name ".mod")) (optional "force"))
 ;	)
 ;     )
 ;   )

     ; Blitz Basic 2
 ; <name>Lib/Developer/BB2/Include/Libraries/<name>.asc		(optional)
 ; <name>Lib/Developer/BB2/blitzlibs/amigalibs/<name>.library1	(optional)
 ;   (if (OR #all (IN #uninstall_proglang 8))
 ;     (
 ;      (set #dest-dir "BLITZ2:")
 ;	(if #old_bb2
 ;	  (
 ;	   (set #dir (tackon #dest-dir "Include/Libraries"))
 ;	   (delete (tackon #dir (cat @app-name ".asc")) (optional "force"))
 ;	   (set #dir (tackon #dest-dir "blitzlibs/amigalibs"))
 ;	   (delete (tackon #dir (cat @app-name ".library1")) (optional "force"))
 ;	  )
 ;	)
 ;     )
 ;   )
    )
   )

  (P_CustomUninstall)
  (complete 100)
 )

; -----------------------------------------------------------------------------

 ; Check OS
 (P_GetOSVersion)
 (set #ver2 #min_os_version)
 (set #rev2 #min_os_revision)
 (P_CompareVersions)
 (if (= #result -1)
   (
    (set #ver #min_os_version)
    (set #rev #min_os_revision)
    (P_GetOSVersionStr)
    (abort (#abort_oldos #str #os_str))
   )
 )

 ; Check if there is an already installed version?
 (if (= (fileonly (pathonly @icon)) "Install")
   (set #src-dir "/")
   (set #src-dir "")
 )
 (set #dest-dir @default-dest)
 (set #dir #dest-dir)
 (P_CheckInstalled)
 ; (P_CustomExists)

 (set #dir #src-dir)
 (P_CheckExists)

 ; Check old version
 (set #file (tackon "Libs:" (cat @app-name ".library")))
 (P_GetVersion)
 (set #ver2 #ver)
 (set #rev2 #rev)

 ; Check archiv
 (set #i 0)
 (set #file "")
 (while (AND (< #i 10) (= (strlen #file) 0))
   (
    (if (exists (tackon (tackon #src-dir "libs") (cat @app-name (select #i "" "000" "010" "020" "020f" "030" "030f" "040" "040f" "060") ".library")) (noreq))
      (set #file (tackon (tackon #src-dir "libs") (cat @app-name (select #i "" "000" "010" "020" "020f" "030" "030f" "040" "040f" "060") ".library")))
    )
    (set #i (+ #i 1))
   )
 )
 (P_GetVersion)

 (P_CompareVersions)
 (if (= #result -1)
   (abort (#abort_oldversion #ver2 #rev2 #ver #rev))
   (if (= #result 0)
     (if (= #ver 0)
       (set #update 0)
       (set #update 1)
     )
     (set #update 0)
   )
 )

 ; Install over old/Update existing
 (select (if #old_lib
	   (askchoice (prompt #prompt_install_uninstall)
		      (help #help_askchoice @askchoice-help)
		      (default 0)
		      (choices
			(cat #prop
			     (if (= #update 0)
			       (
				#choice_install
			       )
			       (
				#choice_update
			       )
			     )
			)
			#choice_uninstall
		      )
	   )
	   (
	    (message #prompt_info)
	    0
	   )
	 )
   ( ; Install
    (welcome #welcome_install)
    (P_Install)
   )
   ( ; Uninstall
    (set @abort-button #button_abort)
    (welcome #welcome_uninstall)
    (P_Uninstall)
    (exit #exit_uninstall_finished (quiet))
   )
 )
