; $VER: Vahunz-Tschak 1.2 (16.8.98)
;
; Copyright 1998,99 Thomas Aglassinger. All rights reserved.
;
; A case tool to create a script that runs Vahunz. The user can select a
; basic mode for vahunzation. The file list is generated automatically
; and the dignorary can be selected. On request, Vahunz can create the
; dictionary and the editor is launched immediately after creation.
;
; Additionally you can create or update dignoraries with it.

; TODO: make a more clear interface flow by first offering to vahunz
;       source code or create a dignorary
; TODO: expose more options when in mode "custom"
; TODO: when JDK's index-?.html does not exist, offer to retry with a
;       new name instead of terminating whole script

; Specify minimum installer version

(debug "set version")
(set #minimum-installer-version 43)
(set #minimum-installer-revision 3)
(set #minimum-installer-id
   (+ #minimum-installer-revision
       (* #minimum-installer-version 65536)
   )
)
(debug "  minimum-installer-id = " #minimum-installer-id)
(debug "  current-installer-id = " @installer-version)

; Figure full path name of vahunz executable
(debug "expand vahunz path")
(set #expanded-vahunz
   (cat "\"" (expandpath "vahunz") "\"")
)
(debug "  " #expanded-vahunz)

; Filename for the CLI script to be created. Later on the source
; directory is inserted at the beginning of this name.
(set #file-vahunz-it "Vahunz it!")

; Texts for messages, prompts and help

(
(set #message-welcome
(cat "Welcome to Vahunz-Tschak, the script generator for Vahunz.\n"
))

(set #message-wrong-installer
(cat "You have an old version of the program 'Installer' on your Amiga!\n\n"
     "The installation procedure needs at least Installer "
     #minimum-installer-version "." #minimum-installer-revision ".\n\n"
     "Please obtain a newer version!\n\n"
     "(Check Aminet or "
     "the WWW site of the current owner of the rights for Amiga.)"
))

(set #message-wrong-list
(cat "This script requires the standard 'c:list' command to be installed.\n\n"
     "It seems you are using some incompatible replacement."
))

(set #message-overview
(cat "Vahunz-Tschak is a frontend for Vahunz to spare you fiddling with "
     "command line options.\n\n"
     "It asks you some questions concerning "
     "the location of your source code and options for vahunz. After that "
     "it creates a CLI-script \"" #file-vahunz-it "\" you can invoke at "
     "any time to perform the vahunzation.\n\n"
     "If you are unsure about the meaning of a question, click the \"Help\" "
     "button or take a look at the manual."
))

; Choices for basic vahunz mode
(set #choice-vahunz-standard "Standard")
(set #choice-vahunz-exchange "Exchange")
(set #choice-vahunz-rename   "The Great Renaming")
(set #choice-vahunz-custom   "Custom")
(set #choice-create-c        "Create C/C++ dignorary")
(set #choice-create-java     "Create Java dignorary")
              
              

(set #prompt-vahunz-mode "Select the kind of vahunzation you want to perform:")
(set #help-vahunz-mode
(cat "This specifies what vahunz should do with your sources.\n\n"
     #choice-vahunz-standard " - Perform a standard vahunzation mostly using "
     "default options. This gives you a reasonably unreadable source code "
     "without comments and indention you can use to distribute to normal "
     "users who only want to compile it and nothing else."
     "\n\n"
     #choice-vahunz-exchange " - Works like \"" #choice-vahunz-standard "\", "
     "but preserves line numbers in the vahunzed source. This gives accurate "
     "line numbers referring to your original source if users report source "
     "code related errors like problems during compilation."
     "\n\n"
     #choice-vahunz-rename " - Does not remove any data from your original "
     "code but only creates a dictionary prepared for "
     "\"The Great Renaming\"."
     "\n\n"
     #choice-vahunz-custom " - Asks you all options to be specified manually. "
     "This is useful for maximum control over the vahunzation."
     "\n\n"
     #choice-create-c " - Lets you specify your include directory and creates "
     "a dignorary from it."
     "\n\n"
     #choice-create-java " - Lets you specify your Javadoc directory and "
     "creates a dignorary from it."
))

; Choices for source type
(set #choice-source-c    "C/C++")
(set #choice-source-java "Java")

(set #prompt-source-type
     "Select the type of source codes that should be vahunzed:"
)
(set #help-source-type
(cat "The source type decides for which file pattern the source directory is "
     "scanned."
))

(set #prompt-source-directory
(cat "Select source directory to scan for source codes and where the support "
     "files for vahunz will be stored:"
))
(set #help-source-directory
(cat "The directory you selected and all its sub-directories are scanned for "
     "source codes to be vahunzed.\n\n"
     "Support files like \"vahunz.files\" and the dictionaries are also "
     "stored there. This includes the \"" #file-vahunz-it "\" CLI-script "
     "created by Vahunz-Tschak at the end."
))
(set #prompt-source-pattern
     "Enter pattern for source file to be vahunzed:"
)
(set #help-source-pattern
(cat "Here you can specify a AmigaDOS pattern the files in the source "
     "directory have to match to be considered for vahunzation."
     "\n\n"
     "For example, #?.(c|h) specifies all C sources and headers."
     "\n\n"
     "All sub-directories within the source directory are also scanned."
))

(set #prompt-dignorary
     "Select default dignorary to be used by vahunz:"
)
(set #help-dignorary
(cat "The dignorary is a special dictionary containing names you know that "
     "you don't want them to vahunz already beforehand. It usually "
     "contains names of functions and constants of standard and system "
     "libraries.\n\n"
     "If you do not want to use a dignorary, choose \"empty.ignore\"."
))

(set #prompt-custom-switches "Select the switches you want to enable")
(set #help-custom-switches
(cat "Here you can enable switches that will influence the output Vahunz "
     "creates."
))

(set #message-create-vahunz-files-1
     "Creating \""
)
(set #message-create-vahunz-files-2
     "\" using the following command:"
)
(set #help-create-vahunz-files
(cat "This command creates the \"vahunz.files\" containing all source files "
     "vahunz should take into account."
))

(set #message-create-vahunz-ignore-1
     "Creating \""
)
(set #message-create-vahunz-ignore-2
     "\" using the following command:"
)
(set #help-create-vahunz-ignore
(cat "This command creates dignorary \"vahunz.ignore\" containig all names "
     "to be ignored."
))

(set #prompt-create-vahunz-it
(cat "Writing \"" #file-vahunz-it "\""
))
(set #help-vahunz-it
(cat "\"" #file-vahunz-it "\" is the CLI-script created by Vahunz-Tschak "
     "that actually performs the vahunzation. "
     "\n\n"
     "You can call it whenever you updated your original source code and "
     "want to create a new vahunzed version."
))

(set #prompt-target-directory
(cat "Select target directory where the vahunzed source code should be "
     "stored:"
))
(set #help-target-directory
(cat "To preserve your original source code, the vahunzed one is written "
     "to a different directory, but with the same filenames."
     "\n\n"
     "This usually allows you to use the same scripts and Makefile for "
     "compilation as for the original."
))

(set #work-create-script  "Creating script")
(set #work-copy-dignorary "Copying dignorary from")

(set #prompt-launch-vahunz
(cat "The script has been created. To also create the dictionary it has to be "
     "executed.\n\n"
     "Do you want me to start the script now?"
))
(set #help-launch-vahunz
(cat "You can execute the script now to make vahunz extract all names of your "
     "source code and create the dictionary.\n\n"
     "If you do not want to do that right now, you can skip this part and "
     "execute the script later from Workbench or CLI."
))

(set #status-vahunzing
(cat "Vahunzing...\n\n"
     "(This can take a while)"
))

(set #prompt-editor
(cat "The dictionary has been created.\n\n"
     "It can now be loaded into your editor. There you can and modify the "
     "lines  want to vahunz/rename."
))
(set #help-editor
(cat "Your editor according to the environment variable EDITOR will be "
     "started and load the dictionary.\n\n"
     "Mark words you want to vahunz with plus (+) and those you want to "
     "ignore with minus (-).\n\n"
     "To rename a name, leave the first character blank and specify the "
     "new name after an equal sign (=), for example:\n\n"
     "\" rdcfg=read_settings\""
))

(set #message-exit
(cat "A CLI-script has been created in \"%s\"."
     "\n\n"
     "You can perform the vahunzation by executing this script from CLI "
     "or by double-clicking it from the Workbench."
     "\n\n"
     "As the script automatically goes to the source directory and also "
     "restores the current directory upon exit, you can safely invoke it "
     "from other scripts, Makefiles or similar."
     "\n\n"
     "Happy Vahunzing!"
))
)

(set #prompt-include-directory "Select C/C++ include directory")
(set #help-include-directory
(cat "The include directory contains all your header files with names you want "
     "to ignore when vahunzing source codes."
))

(set #working-list-include-files  "Creating include file list")
(set #working-scan-include-files  "Scanning include files")
(set #working-translate-dignorary "Replacing blanks by hyphens")
(set #working-cleanup-dignorary   "Cleaning up dignorary")

(set #prompt-javadoc-directory "Select include directory")
(set #help-javadoc-directory
(cat "The include directory contains your system header files."
     "\n\n"
     "They usually contain variables, prototypes and macros you do not "
     "want to vahunz."
))

(set #prompt-javadoc-directory "Select Javadoc directory")
(set #help-javadoc-directory
(cat "The Javadoc directory contains the API documentation in HTML format. All "
     "documents matching the file pattern \"[a-z]-index.html\" in this "
     "directory are scanned for references."
     "\n\n"
     "That means, a file named \"a-index.html\" has to exist in the directory "
     "you select, otherwise it will be rejected."
))
(set #message-bad-javadoc-directory
(cat "The directory selected does not contain a file named \"index-1.html\". "
     "Therefor this is not considered to be a directory containing API "
     "documentation in JavaDoc format."
     "\n\n"
     "Select a proper directory next time."
))

(set #working-scan-javadoc "Scanning \"%s\"")
(set #working-cleanup-javadoc "Cleaning temporary dignorary using vahunz")

(set #prompt-target-dignorary "Specify target dignorary to create")
(set #help-target-dignorary
(cat "Specify directory and filename of the target directory."
     "\n\n"
     "Preferably, it should be stored in the standard dignorary directory "
     "and should have the suffix \".ignore\"."
))

(set #message-exit-dignorary
(cat "The new dignorary has been stored in \"%s\"."
     "\n\n"
     "It is ready for your next vahunzation."
))
;----------------------------------------------------------------------------
; Run a command and check for a certain return code
;----------------------------------------------------------------------------
(procedure P-run #name #expected-result #command
(
   (debug "  name = " #name)
   (debug "  expt = " #expected-result)
   (debug "  comd = " #command)

   (set #real-result (run #command))
   (if (<> #expected-result #real-result)
      (
         (abort #name " returned " #real-result " instead of "
                #expected-result ":\n\n"
                #command)
      )
   )
))

;----------------------------------------------------------------------------
; Execute a script and check for a certain return code
;----------------------------------------------------------------------------
(procedure P-execute #name #expected-result #command
(
   (debug "  name = " #name)
   (debug "  expt = " #expected-result)
   (debug "  comd = " #command)

   (set #real-result (execute #command))
   (if (<> #expected-result #real-result)
      (
         (abort #name " returned " #real-result " instead of "
                #expected-result ":\n\n"
                #command)
      )
   )
))

;----------------------------------------------------------------------------
; Load certain file into editor
;----------------------------------------------------------------------------
(procedure P-edit #file #prompt #help
(
   ; Get editor from $EDITOR or use c:Ed

   (set #editor (getenv "editor"))
   (if (= "" #editor) ((set #editor "c:Ed")))

   (debug "editor = " #editor)

   ; Run editor

   (set #command-editor (cat #editor " \"" #file "\""))
   (run #command-editor
      (prompt #prompt)
      (help #help)
      (confirm "average")
   )
))

;----------------------------------------------------------------------------
; Check requirements
;----------------------------------------------------------------------------

; Check installer version to piss people off and make them
; download a new one or dump the whole filetype (He he he).
; (The script should work with older versions, but how am I
; supposed to test this?)

(procedure P-check-requirements
   (debug "check version")
   (if (< @installer-version #minimum-installer-id)
     (
       (debug "installer too old")
       (abort #message-wrong-installer)
     )
   )

   (debug "check list")
   (if (run "list >nil: lformat=%p%n all pat=#?")
     (
       (debug "no/wrong list")
       (abort #message-wrong-list)
     )

))

;----------------------------------------------------------------------------
; Welcome user
;----------------------------------------------------------------------------

(procedure P-welcome
   (debug "welcome")
   (welcome #message-welcome)

   (message #message-overview)
)

;----------------------------------------------------------------------------
; Ask for basic vahunz mode
;----------------------------------------------------------------------------

(procedure P-ask-vahunz-mode
   (debug "ask vahunz mode")

   (set #vahunz-mode
      (askchoice
          (choices
              #choice-vahunz-standard
              #choice-vahunz-exchange
              #choice-vahunz-rename
              #choice-vahunz-custom
              #choice-create-c
              #choice-create-java
          )
          (prompt #prompt-vahunz-mode)
          (help #help-vahunz-mode)
      )
   )
   (debug "vahunz-mode = " #vahunz-mode)

   (select #vahunz-mode

      ; Standard
      (set #vahunz-options "")

      ; Exchange
      (set #vahunz-options "--line --random-seed=1 --store")

      ; The Great Renaming
      (set #vahunz-options "--comment --indent --line --no-unused")

      ; Custom
      (set #vahunz-options "*custom*")

      ; Create C dignorary
      (set #vahunz-options "*create-c*")

      ; Create C dignorary
      (set #vahunz-options "*create-java*")

   )
   (debug "vahunz-options = " #vahunz-options)
)

;----------------------------------------------------------------------------
; Ask for source type
;----------------------------------------------------------------------------

(procedure P-ask-source-type
   (debug "ask source type")

   (set #source-type
      (askchoice
          (choices
              #choice-source-c
              #choice-source-java
          )
          (prompt #prompt-source-type)
          (help #help-source-type)
      )
   )
   (debug "source-type = " #source-type)
)

;----------------------------------------------------------------------------
; Ask for source directory
;----------------------------------------------------------------------------

(procedure P-ask-source-directory
   (debug "ask source directory")

   (if (= @app-name "debug")
   (
       set #source-directory "prog:SmartReadArgs"
   )
   (
       (set #source-directory
       (askdir
          (prompt #prompt-source-directory)
          (help #help-source-directory)
          (default "Work:")
       ))
   )
   ) ;if

   (debug "source directory = " #source-directory)
)

;----------------------------------------------------------------------------
; Ask for source pattern
;----------------------------------------------------------------------------

(procedure P-ask-source-pattern
   (debug "choose source pattern")

   (select #source-type

      ; C/C++
      (
         (set #source-pattern "#?.(c|h|c++|cxx|cpp|cc)")
         (set #default-dignorary "amiga.ignore")
      )

      ; Java
      (
         (set #source-pattern "#?.(java|jav)")
         (set #default-dignorary "java.ignore")
      )

      ; Others (currently disabled)
      (
          (set #source-pattern
          (askstring
             (prompt #prompt-source-pattern)
             (help #help-source-pattern)
             (default "#?.(c|h|c++|cxx|cpp|cc)")
          ))
      )
   )

   (debug "source pattern = " #source-pattern)
)

;----------------------------------------------------------------------------
; Ask for dignorary
;----------------------------------------------------------------------------

(procedure P-ask-dignorary
   (debug "ask dignorary")

   (set #dignorary
   (askfile
      (prompt #prompt-dignorary)
      (help #help-dignorary)
      (default (tackon "dignorary" #default-dignorary))
   ))

   (debug "dignorary = " #dignorary)
)

;----------------------------------------------------------------------------
; Ask for target directory
;----------------------------------------------------------------------------

(procedure P-ask-target-directory
   (debug "ask target directory")

   (set #target-directory
   (askdir
      (prompt #prompt-target-directory)
      (help #help-target-directory)
      (default "ram:")
   ))

   (debug "dignorary = " #target-directory)
)

;----------------------------------------------------------------------------
; Ask options in case of vahunz mode set to "Custom"
;----------------------------------------------------------------------------
(procedure P-ask-custom-switches
   (if (= #vahunz-options "*custom*")
      (
         ; Ask for switches

         (set #options
         (askoptions
            (prompt #prompt-custom-switches)
            (help #help-custom-switches)
            (default 0)
            (choices
               "Preserve comments (--comment)"
               "Preserve indention (--indent)"
               "Preserve line numbers (--line)"
               "Remove unused names from dictionary (--no-unused)"
               "Store vahunzed names in dictionary (--store)"
               "Suppress warning messages (--no-warning)"
            )
         ))
         (set #vahunz-options "")
         (if (IN #options 0) (set #vahunz-options (cat #vahunz-options " --comment")))
         (if (IN #options 1) (set #vahunz-options (cat #vahunz-options " --indent")))
         (if (IN #options 2) (set #vahunz-options (cat #vahunz-options " --line")))
         (if (IN #options 3) (set #vahunz-options (cat #vahunz-options " --no-unused")))
         (if (IN #options 4) (set #vahunz-options (cat #vahunz-options " --store")))
         (if (IN #options 5) (set #vahunz-options (cat #vahunz-options " --no-warning")))
      )
   )
)

;----------------------------------------------------------------------------
; Create "vahunz.files"
;----------------------------------------------------------------------------

(procedure P-create-vahunz.files
   (set #vahunz-files (tackon #source-directory "vahunz.files"))
   (set #file-command-list "t:vahunz-tschack-list.tmp")

   (working "Creating \"" #vahunz-files "\"")

   (set #command-sequence-list
   (cat "cd \"" #source-directory "\"\n"
        "list lformat=%p%n all "
           "pat=\"" #source-pattern "\" "
           ">\"" #vahunz-files "\"\n"
   ))

   (debug "command: " #command-sequence-list)

   (textfile
      (dest #file-command-list)
      (append #command-sequence-list)
   )

   (P-execute "#file-command-list" 0 #file-command-list)
   (delete #file-command-list)

)

;----------------------------------------------------------------------------
; Create "vahunz.ignore"
;----------------------------------------------------------------------------

(procedure P-create-vahunz.ignore
   (set #vahunz-ignore (tackon #source-directory "vahunz.ignore"))

   (set #command-copy-dignorary
   (cat "copy quiet clone "
        "from=\"" #dignorary "\" "
        "to=\"" #vahunz-ignore "\""
   ))

   (debug "command: " #command-copy-dignorary)

   (working #work-copy-dignorary " \"" #vahunz-ignore "\"")

   (P-run "#command-copy-dignorary" 0 #command-copy-dignorary)
)

;----------------------------------------------------------------------------
; Create "Vahunz it!"
;----------------------------------------------------------------------------

(procedure P-create-vahunz-it
   (set #vahunz-it (tackon #source-directory #file-vahunz-it))
   (set #vahunz-it-icon (cat #vahunz-it ".info"))

   (working #work-create-script " \"" #vahunz-it "\"")

   (set #command-vahunz-it
   (cat "assign vahunz-cd-<$$>: \"\"\n"
        "cd \"" #source-directory "\"\n"
        #expanded-vahunz
            " " #vahunz-options
            " \"--output=" #target-directory "\" "
        "\n"
        "cd vahunz-cd-<$$>:\n"
        "assign vahunz-cd-<$$>: remove\n"
   ))

   (debug "vahunz-it contents:\n---\n"
          #command-vahunz-it
          "---")

   (textfile
      (prompt #promp-create-vahunz-it)
      (help #help-vahunz-it)
      (dest #vahunz-it)
      (append #command-vahunz-it)
   )

   (set #command-copy-icon
   (cat "copy quiet clone "
        "from=tschak/def_vahunz.info "
        "to=\"" #vahunz-it-icon "\""
   ))

   (P-run "#command-copy-icon" 0 #command-copy-icon)

   ; Set "S" protection bit of "Vahunz it!"
   (set #command-protect-vahunz-it
   (cat "protect \"" #vahunz-it "\" +s"
   ))

   (P-run "#command-protect-vahunz-it" 0 #command-protect-vahunz-it)
)

;----------------------------------------------------------------------------
; Invoke "Vahunz it!"
;----------------------------------------------------------------------------

(procedure P-invoke-vahunz-it
   (set #vahunz-launched
   (askbool
      (prompt #prompt-launch-vahunz)
      (help #help-launch-vahunz)
      (default 1)
   ))

   (debug "launch vahunz = " #vahunz-launched)

   (if #vahunz-launched
      (
         (working #status-vahunzing)
         (P-run "#vahunz-it" 0 (cat "execute \"" #vahunz-it "\""))

         ; We can't use P-execute here because it does not quote the name
      )
   )
)

;----------------------------------------------------------------------------
; Edit "vahunz.names"
;----------------------------------------------------------------------------

(procedure P-edit-vahunz.names
   (set #vahunz-names (tackon #source-directory "vahunz.names"))
   (if #vahunz-launched (P-edit #vahunz-names #prompt-editor #help-editor))
)

;----------------------------------------------------------------------------
; Exit message
;----------------------------------------------------------------------------

(procedure P-exit
   (exit
       (#message-exit #vahunz-it)
       (quiet)
))

;----------------------------------------------------------------------------
; Ask for include directory
;----------------------------------------------------------------------------

(procedure P-ask-include-directory
(
   (debug "ask include directory")

   (set #include-directory
   (askdir
      (prompt #prompt-include-directory)
      (help #help-include-directory)
      (default "include:")
   ))
))

;----------------------------------------------------------------------------
; Create include file list
;----------------------------------------------------------------------------

(procedure P-create-include-files
(
   (debug "list include files")

   (working #working-list-include-files)

   (set #command-list-include
   (cat "list >t:temporary.files lformat=%p%n all pat=#?.h "
        #include-directory
   ))

   (P-run "#command-list-include" 0 #command-list-include)
))

;----------------------------------------------------------------------------
; Scan include file
;----------------------------------------------------------------------------

(procedure P-scan-include-files
(
   (debug "scan include files")

   (working #working-scan-include-files)

   (delete "t:temporary.names"  (optional "force"))
   (delete "t:temporary.ignore" (optional "force"))

   (set #command-scan-include "vahunz --base-name t:temporary")

   (P-run "#command-scan-include" 0 #command-scan-include)
))

;----------------------------------------------------------------------------
; Translate and append include dignorary
;----------------------------------------------------------------------------

(procedure P-translate-dignorary
(
   (debug "translate dignorary")

   (working #working-translate-dignorary)

   (set #command-translate-dignorary
   (cat "tschak/blank-to-hyphen"
        " <t:temporary.names"
        " >>t:temporary.ignore"
   ))

   (P-run "#command-translate-dignorary" 0 #command-translate-dignorary)

   ; Delete the name list and launch vahunz again to sort the whole mess
   ; and kick out possible duplicates
   (debug "cleanup dignorary")

   (working #working-cleanup-dignorary)
   (delete "t:temporary.names" (optional "force"))

   (set #command-cleanup-dignorary "vahunz --base-name t:temporary")
   (P-run "#command-cleanup-dignorary" 0 #command-cleanup-dignorary)
))



;----------------------------------------------------------------------------
; Ask for target dignorary name
;----------------------------------------------------------------------------

(procedure P-ask-target-dignorary #name
(
   (debug "ask target dignorary")

   (set #target-dignorary
   (askfile
      (prompt #prompt-target-dignorary)
      (help #help-target-dignorary)
      (default (tackon "dignorary" #name))
   ))

   (debug "target dignorary = " #target-dignorary)
))

;----------------------------------------------------------------------------
; Move temporary dignorary to standard dignorary directory
;----------------------------------------------------------------------------
(procedure P-move-dignorary #source-dignorary
(
   (debug "move dignorary")
   (debug "  source = \"" #source-dignorary "\"")
   (debug "  target = \"" #target-dignorary "\"")

   (copyfiles
      (source #source-dignorary)
      (dest (pathonly #target-dignorary))
      (newname (fileonly #target-dignorary))
      (optional "askuser")
   )

   (delete #source-dignorary (optional "force"))
))


;----------------------------------------------------------------------------
; Ask for JavaDoc directory
;----------------------------------------------------------------------------

(procedure P-ask-javadoc-directory
(
   (debug "ask javadoc directory")

   (set #javadoc-exists 0)

   (set #javadoc-directory
   (askdir
      (prompt #prompt-javadoc-directory)
      (help #help-javadoc-directory)
      (default "jdk:jdk1.2.2/docs/api/index-files")
   ))

   ; Check, if "a-index.html" exists in this directory
   (set #javadoc-exist (exists (tackon #javadoc-directory "index-1.html")))

   (debug "#javadoc-exist = " #javadoc-exist)

   ; If not, annoy user
   (if (= 0 #javadoc-exist) (abort #message-bad-javadoc-directory))
))

;----------------------------------------------------------------------------
; Scan JavaDoc index file and append references to dignorary
;----------------------------------------------------------------------------
(procedure P-scan-javadoc #filename #complete2
(
   ; Compute name of index file to scan
   (set #javadoc-filename (tackon #javadoc-directory #filename))

   (debug "scan " #javadoc-filename)

   (complete #complete2)
   (working (#working-scan-javadoc #javadoc-filename))

   ; Compute command to scan
   (set #command-scan-javadoc
   (cat "tschak/scan_javadoc <\"" #javadoc-filename "\" >>\"t:java.ignore\""
   ))

   (P-run "#command-scan-javadoc" 0 #command-scan-javadoc)
))


;----------------------------------------------------------------------------
; Scan JavaDoc directory and create dignorary from it
;----------------------------------------------------------------------------
(procedure P-scan-javadoc-directory #complete
(
   (debug "scan javadoc directory")

   (set #script-cleanup-dignorary "t:cleanup-dignorary")

   ; Setup temporary files
   (P-run "#command-reset-scan" 0 "echo \"\" >t:java.ignore noline")
   (P-run "#command-reset-scan" 0 "echo \"\" >t:dummy.java")
   (P-run "#command-reset-scan" 0 "echo \"dummy.java\" >t:java.files")
   (delete "t:java.names")

   (set #scan-complete 0)
   (foreach #javadoc-directory "index-#?.html"
      (
         (set #scan-complete (+ #scan-complete 1))
         (P-scan-javadoc @each-name (+ #complete #scan-complete))
      )
   )

   (complete (+ #complete 30))
   (working #working-cleanup-javadoc)

   (set #command-cleanup-dignorary
   (cat "cd t:\n"
        #expanded-vahunz " --base-name java --no-warning --quiet\n"
   ))

   (textfile
      (dest #script-cleanup-dignorary)
      (append #command-cleanup-dignorary)
   )

   (P-execute "#script-cleanup-dignorary" 0 #script-cleanup-dignorary)
   (delete #script-cleanup-dignorary)

   (debug "cleanup temporary files")
   (delete "t:java.(files|names)"  (optional "force"))
   (delete "t:dummy.java" (optional "force"))
))

;----------------------------------------------------------------------------
; Exit message for created dignoraries
;----------------------------------------------------------------------------

(procedure P-exit-dignorary
   (debug "cleanup temporary files for dignoraries")
   (delete "t:temporary.(files|ignore|names)"  (optional "force"))
   (exit
       (#message-exit-dignorary #target-dignorary)
       (quiet)
))

;----------------------------------------------------------------------------
; "Wollt ihr das totale Programm?"
;----------------------------------------------------------------------------

(complete   0) (P-check-requirements)
(complete   5) (P-welcome)

(complete  10) (P-ask-vahunz-mode)

(set #flow-selector 0)
(if (= #vahunz-options "*create-c*")    (set #flow-selector 1))
(if (= #vahunz-options "*create-java*") (set #flow-selector 2))

(select #flow-selector
   (
      ; Vahunz source code
      (complete  20) (P-ask-custom-switches)
      (complete  25) ; (P-ask-custom-name-length)
      (complete  30) ; (P-ask-custom-prefix)
      (complete  35) ; (P-ask-custom-random-seed)
      (complete  40) ; (P-ask-custom-vahunz-length)
      (complete  45) (P-ask-source-type)
      (complete  50) (P-ask-source-directory)
      (complete  55) (P-ask-source-pattern)
      (complete  60) (P-ask-dignorary)
      (complete  65) (P-ask-target-directory)

      (complete  75) (P-create-vahunz.files)
      (complete  80) (P-create-vahunz.ignore)
      (complete  85) (P-create-vahunz-it)
      (complete  90) (P-invoke-vahunz-it)
      (complete  95) (P-edit-vahunz.names)
      (complete 100) (P-exit)
   )
   (
      ; Create C/C++ dignorary
      (complete  30) (P-ask-include-directory)
      (complete  50) (P-ask-target-dignorary "amiga.ignore")
      (complete  70) (P-create-include-files)
      (complete  80) (P-scan-include-files)
      (complete  90) (P-translate-dignorary)
      (complete  95) (P-move-dignorary "t:temporary.ignore")
      (complete 100) (P-exit-dignorary)
   )
   (
      ; Create Java dignorary
      (complete  30) (P-ask-javadoc-directory)
      (complete  50) (P-ask-target-dignorary "java.ignore")
      (complete  60) (P-scan-javadoc-directory 60)
      (complete  95) (P-move-dignorary "t:java.ignore")
      (complete 100) (P-exit-dignorary)
   )
)

