PROCEDURE (HIDDEN) rap$run_initiation_commands (
  initiation_commands_name, icn: name = $required
  status)


*IF $variable(rav$proc_doc,declared)<>'UNKNOWN'

" PURPOSE:
"   This procedure executes the specified command file.  The command file is expected to be either a
"   prolog or an epilog from the PROLOGS_AND_EPILOGS catalog.
"
" DESIGN:
"   To allow all the commands to be executed a procedure with a when block is built around the commands.
"   The procedure is then executed.
"
" NOTES:
"   The initiation commands name is translated into the initiation commands phrase to be used in logging
"   begining and ending messages.  The translation involves replacing all underscores with blanks and
"   changing all upper case characters to lower case.  The status variable RAV$STATUS is reserved
"   and cannot be used within the initiation command file.
"
"   Margins have been turned off (set to 0) until all messages can be properly aligned together.  To
"   turn the margins back on replace the 0's with a 2.
*IFEND


*copy rav$margin
*copy rav$system_paths

  "$FORMAT=OFF
  VAR
    ignore_status: status
    initiation_commands: file = $unique($local)
    initiation_commands_file: file = rav$system.prologs_and_epilogs//initiation_commands_name
    initiation_commands_name: string 0 .. $max_name = $translate(upper_to_lower, $string($value(initiation_commands_name)))
    initiation_commands_phrase: string 0 .. $max_name = ''
    local_status: status
  VAREND
  "$FORMAT=ON"


  FOR i = 1 TO $size(initiation_commands_name) DO
    char=$substring(initiation_commands_name, i, 1)
    IF char = '_' THEN
      char=' '
    IFEND
    initiation_commands_phrase=initiation_commands_phrase // char
  FOREND

  rap$display_message mm=initiation_messages mn=executing_initiation_commands mp=initiation_commands_phrase ..
        m=rav$margin t=$response status=ignore_status

  IF $file(initiation_commands_file, assigned) THEN

COLLECT_TEXT initiation_commands until='END_COLLECT' sm='?'
PROC initiation_commands (
  status : var of status = $optional
  )


  WHEN any_fault DO
    IF NOT rav$event_message.normal THEN
      $system.put_line ' '//$strrep(rav$event_message) o=$response
      rav$event_message.normal = TRUE
    IFEND
    $system.put_line ' '//$strrep(osv$status) o=$response

    rav$status = ..
          $status(false, 'RA', rae$errors_occurred_warning, '?initiation_commands_name?')
  WHENEND


  create_variable rav$event_message k=status s=xdcl

  create_variable ignore_status k=status
  create_variable local_status k=status
  create_variable rav$status k=status

END_COLLECT

    $system.copy_file i=initiation_commands_file o=initiation_commands.$eoi status=local_status
    IF local_status.normal THEN

COLLECT_TEXT initiation_commands.$eoi until='END_COLLECT'

  EXIT_PROC WITH rav$status WHEN NOT rav$status.normal

PROCEND initiation_commands
END_COLLECT

      rav$margin=rav$margin + 0

      $system.include_command c=$string(initiation_commands) status=local_status

      rav$margin=rav$margin - 0

      IF local_status.normal THEN
        "Capitalize first letter.
        initiation_commands_phrase=$translate(lower_to_upper, $substring(initiation_commands_phrase, 1))// ..
              $substring(initiation_commands_phrase, 2, $size(initiation_commands_phrase)-1)
        rap$display_message mm=initiation_messages mn=initiation_commands_executed mp=initiation_commands_phrase ..
              m=rav$margin t=$response status=ignore_status
      IFEND
    IFEND
    $system.detach_file f=initiation_commands status=ignore_status

  ELSE
    $system.put_line l=' '//$strrep($status(false, 'PF', pfe$unknown_permanent_file, initiation_commands_file)) o=$response
    local_status = ..
          $status(false, 'RA', rae$errors_occurred_warning, $string(initiation_commands_name))
  IFEND

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND rap$run_initiation_commands
