PROCEDURE (hidden) rap$create_operator_environment (
  output_file, of: file = $job_log
)

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

" PURPOSE:
"   This procedure creates the operator's environment by setting up the command list, the local files
"   and the library list.
"
" DESIGN:
"   The degree to which this procedure can setup the environment depends on the state of the system at
"   the time of execution.  RAP$CREATE_OPERATOR_ENVIRONMENT will setup the environment as complete as
"   possible.  Bad status will only be displayed to OUTPUT_FILE.
"
" NOTES:
"   The path variable RAV$BUILTIN_LIBRARY allows for internal checkout.
"   The variables RAV$SET_OPERATOR_COMMAND_LIST and RAV$SET_OPERATOR_LIBRARY_LIST
"   allow the site to retain their modifications to the command list and library list
"   even when we reset them.
"   This procedure does not exit with status since it is designed handle all errors
"   itself and need not communicate with the caller via a STATUS variable.
*IFEND


  WHEN any_fault DO
    $system.put_line ' '//$strrep(osv$status) o=output_file
  WHENEND

  "$FORMAT=OFF
  VAR
    rav$accounting_utils_library: (XREF) file
    rav$builtin_library: (XREF) file
    ignore_status: status
    local_status: status
  VAREND
  "$FORMAT=ON"

  PUSH file_connections
  $system.delete_file_connection sf=$errors f=$local.output
  $system.create_file_connection sf=$errors f=output_file

  create_command_list_block: ..
  BLOCK
    $system.set_command_list delete=all
    $system.set_command_list add=($local, $system.osf$operator_command_library, $system.osf$sou_library, ..
          rav$builtin_library, $system) system_command_library=$system.osf$command_library status=local_status
    IF local_status.normal THEN
      EXIT create_command_list_block
    ELSE
      $system.put_line ' '//$strrep(local_status) o=output_file
      IF osv$deadstart_phase <> 'INSTALL' THEN
        $system.put_line ' ' o=$local.$output
        $system.put_line ' WARNING:  Errors occurred while trying to create the operator command list.'  o=$local.$output
        $system.put_line ' See NOS/VE system job log for details.'  o=$local.$output
        rap$press_next
      IFEND
      $system.delete_command_list_entry e=all

" Try adding the system command library to the command list.

      IF NOT $FILE_ATTRIBUTES($system.osf$operator_command_library registered) THEN
        $system.set_command_list add=($local, $system.osf$sou_library, rav$builtin_library, $system) ..
              system_command_library=$system.osf$command_library status=local_status
        IF local_status.normal THEN
          EXIT create_command_list_block
        ELSE
          $system.put_line ' '//$strrep(local_status) o=output_file
          $system.delete_command_list_entry e=all
        IFEND
      IFEND

" Add the minimum known library set.  This includes osf$sou_library and osf$builtin_library which reside
" on the deadstart tape.

      $system.create_command_list_entry e=($local, $system.osf$sou_library, rav$builtin_library, $system)
    IFEND
  BLOCKEND create_command_list_block

  IF $file(rav$accounting_utils_library, permanent) THEN
    $system.create_command_list_entry e=rav$accounting_utils_library p=after status=ignore_status
  IFEND

  IF $variable(rav$set_operator_command_list, nonlocal) THEN
    "$FORMAT=OFF
    VAR
      rav$set_operator_command_list: (XREF) string
    VAREND
    "$FORMAT=ON"
    $system.include_command c=rav$set_operator_command_list status=local_status
    IF NOT local_status.normal THEN
      $system.put_line (' '//..
$strrep($status(false, 'RA', rae$errors_occurred_warning, 'RAV$SET_OPERATOR_COMMAND_LIST')) ' '//..
$strrep(local_status)) o=output_file
    IFEND
  IFEND

  $system.detach_file $local.cyf$run_time_library status=ignore_status
  $system.attach_file $system.cybil.cyf$run_time_library

  $system.detach_file $local.smf$library status=ignore_status
  $system.attach_file $system.sort.smf$library

  $system.detach_file $local.aaf$44d_library status=ignore_status
  $system.attach_file $system.aam.aaf$44d_library am=execute

  $system.detach_file $local.aaf$4dd_library status=ignore_status
  $system.attach_file $system.aam.aaf$4dd_library am=(read execute)

  $system.detach_file $local.mlf$library status=ignore_status
  $system.attach_file $system.common.mlf$library am=(read execute)

  $system.set_program_attributes delete_library=all
  $system.set_program_attributes add_library=($local.aaf$44d_library, $local.aaf$4dd_library)

  IF $variable(rav$set_operator_library_list, nonlocal) THEN
    "$FORMAT=OFF
    VAR
      rav$set_operator_library_list: (XREF) string
    VAREND
    "$FORMAT=ON"
    $system.include_command c=rav$set_operator_library_list status=local_status
    IF NOT local_status.normal THEN
      $system.put_line (' '//..
$strrep($status(false, 'RA', rae$errors_occurred_warning, 'RAV$SET_OPERATOR_LIBRARY_LIST')) ' '//..
$strrep(local_status)) o=output_file
    IFEND
  IFEND

  POP file_connections


PROCEND rap$create_operator_environment
