PROCEDURE activate_scfs (
  application_name, an: name = $optional
  control_facility_name, cfn: name = $optional
  system_task_name, stn: name = $optional
  logging, l: boolean = $optional
  load_map, lm: file = $optional
  ntf_system_list, nsl: file = $optional
  dump_file, df: file = $optional
  status)


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

"    This request activates SCFS.
"
"    The parameters APPLICATION_NAME, CONTROL_FACILITY_NAME and
"SYSTEM_TASK_NAME can only be used in the following manner.
"
"    1.  Specify none of the parameters and allow the defaults to
"        be used.
"    2.  Specify all three parameters.
"    3.  Specify only the parameter APPLICATION_NAME and the value
"        will be used for all three names.
"
"NOTE:  You cannot specify any of the defaults when doing 2 or 3.

*IFEND


  "$FORMAT=OFF
  VAR
    abort_file_commands: file = $SYSTEM.BATCH_DEVICE_SUPPORT.SCFS_ABORT_FILE_COMMANDS
    application_name_value: string  = 'OSA$STATUS_CONTROL_FAC_SERVER'
    control_facility_name_value: string = 'STATION_CONTROLLER_1'
    dump_file_specified: boolean = $specified(dump_file)
    dump_file_value: string = ''
    local_status: status
    load_map_options: name = NONE
    load_map_value: file = $NULL
    logging_value: string = 'FALSE'
    ntf_systems: string = ' '
    scfs_library: file = $SYSTEM.BATCH_DEVICE_SUPPORT.OSF$BATCH_DEVICE_SUPPORT
    system_task_name_value: string = 'SCF_SERVER'
  VAREND
  "$FORMAT=ON"

  IF $specified(application_name) THEN
    application_name_value = $string(application_name)

    IF $specified(control_facility_name) AND $specified(system_task_name) THEN
      control_facility_name_value = $string(control_facility_name)
      system_task_name_value = $string(system_task_name)
    ELSEIF NOT $specified(control_facility_name) AND NOT $specified(system_task_name) THEN
      control_facility_name_value = application_name_value
      system_task_name_value = application_name_value
    ELSE
      put_line lines=(' ', ' --ERROR-- The APPLICATION_NAME parameter was incorrectly', ..
            ' specified with only one of the CONTROL_FACILITY_NAME or', ..
            ' SYSTEM_TASK_NAME parameters, either eliminate that parameter' ..
            ' or add the other parameter.') output=$response
      EXIT_PROC
    IFEND

    IF (application_name_value = 'OSA$STATUS_CONTROL_FAC_SERVER') OR ..
          (control_facility_name_value = 'STATION_CONTROLLER_1') OR ..
          (system_task_name_value = 'SCF_SERVER') THEN
      IF application_name_value = 'OSA$STATUS_CONTROL_FAC_SERVER' THEN
        put_line lines=(' ', ' --ERROR-- The APPLICATION_NAME parameter can not specify', ..
              ' the default value of OSA$STATUS_CONTROL_FAC_SERVER') output=$response
      IFEND
      IF control_facility_name_value = 'STATION_CONTROLLER_1' THEN
        put_line lines=(' ', ' --ERROR-- The CONTROL_FACILITY_NAME parameter can not specify', ..
              ' the default value of STATION_CONTROLLER_1') output=$response
      IFEND
      IF system_task_name_value = 'SCF_SERVER' THEN
        put_line lines=(' ', ' --ERROR-- The SYSTEM_TASK_NAME parameter can not specify', ..
              ' the default value of SCF_SERVER') output=$response
      IFEND
      EXIT_PROC
    IFEND
  ELSEIF $specified(control_facility_name) AND $specified(system_task_name) THEN
    put_line lines=(' ', ' --ERROR-- The APPLICATION_NAME parameter must be specified if both', ..
          ' the APPLICATION_NAME and SYSTEM_TASK_NAME parameters are specified.') output=$response
    EXIT_PROC
  ELSEIF $specified(control_facility_name) THEN
    put_line lines=(' ', ' --ERROR-- The CONTROL_FACILITY_NAME parameter can only be specified', ..
          ' with both the APPLICATION_NAME and SYSTEM_TASK_NAME parameters.') output=$response
    EXIT_PROC
  ELSEIF $specified(system_task_name) THEN
    put_line lines=(' ', ' --ERROR-- The SYSTEM_TASK_NAME parameter can only be specified', ..
          ' with both the APPLICATION_NAME and CONTROL_FACILITY_NAME parameters.') output=$response
    EXIT_PROC
  IFEND

  IF $specified(load_map) THEN
    load_map_value = load_map
    load_map_options = ALL
  IFEND

  IF $specified(logging) THEN
    logging_value = $string(logging)
  IFEND

  IF $specified(ntf_system_list) THEN
    ntf_systems = ' NSL='//$string(ntf_system_list)
  IFEND

  IF $specified(dump_file) THEN
    dump_file_value = $string(dump_file)
  IFEND

  IF $file(abort_file_commands, permanent) THEN
    REPEAT
      delete_file file=abort_file_commands status=local_status
    UNTIL NOT local_status.normal
  IFEND

  TASK ring=11
COLLECT_TEXT output=abort_file_commands until='** END OF ABORT COMMANDS **' substitution_mark='#' status=local_status

  VAR
    abort_commands_status: (UTILITY) status
    dump_file: (UTILITY) file = $fname('$system.batch_device_support.scfs_dump_'//$date('Y2M2D2')//'_'//$time('H24MMSS'))
  VAREND

  create_command_list_entry entry=$system.osf$command_library status=abort_commands_status

  IF #dump_file_specified# THEN
    dump_file = #dump_file_value#
  IFEND

  display_message message=' ' to=job
  display_message message='**** Please write a PSR against SCFS and provide' to=job
  display_message message='**** as supporting material a permanent file backup' t=job
  display_message message='**** of catalog $SYSTEM.BATCH_DEVICE_SUPPORT.' t=job
  display_message message=' ' to=job

"  The following commands will display the abort information
"  through the use of the debugger.

  set_file_attributes dump_file fc=list pf=continuous
  put_line '1***** ABORT DUMP OF SCFS - CFN:#control_facility_name_value#' o=dump_file
  put_line '       '//$date(iso)//' '//$time(millisecond) o=dump_file.$eoi
  put_line '       '//$job(os_version)//' - '//$default_family//' - CYBER '//..
$processor(model_number, 0)//' Serial '//$processor(serial_number, 0) o=dump_file.$eoi
  put_lines ('', ' ***** ENVIRONMENT:', '') output=dump_file.$eoi
  display_debugging_environment display_option=user_address output=dump_file.$eoi
  display_debug_task_status task_number=all output=dump_file.$eoi
  put_lines ('', ' ***** TRACEBACK:', '') output=dump_file.$eoi
  display_call count=all start=1 display_option=all_calls output=dump_file.$eoi
  put_lines ('', ' ***** JOB LOG:', '') output=dump_file.$eoi
  display_log display_option=200 output=dump_file.$eoi
  put_lines ('', ' ***** REGISTERS:', '') output=dump_file.$eoi
  display_register kind=all_program number=all type=hex output=dump_file.$eoi
  put_lines ('', ' ***** STACK FRAMES:', '') output=dump_file.$eoi
  display_stack_frame count=all start=1 display_option=all output=dump_file.$eoi
  put_lines ('', ' ***** STATIC SECTION:', '') output=dump_file.$eoi
  display_memory section=$static module=$name($current_module) byte_offset=0 byte_count=16 repeat_count=all ..
        output=dump_file.$eoi
  IF $variable(nfv$appl_def_segment_for_scfs, declared) = 'LOCAL' THEN
    put_lines ( '-***** NFV$APPL_DEF_SEGMENT_FOR_SCFS:', '') output=dump_file.$eoi
    display_memory address=?nfv$appl_def_segment_for_scfs byte_offset=0 byte_count=16 ..
          repeat_count=0FFFFF(16) output=dump_file.$eoi
    delete_variable name=nfv$appl_def_segment_for_scfs status=abort_commands_status
  IFEND

  IF $variable(nfv$notify_after_aborting, defined) THEN
    IF nfv$notify_after_aborting THEN
      send_operator_message m='SCFS task failed, see system job log.' oc=system_operator
    IFEND
  IFEND
** END OF ABORT COMMANDS **
    IF NOT local_status.normal THEN
      IF local_status.condition = ame$file_not_known THEN
        local_status=$status(false 'PF' pfe$unknown_permanent_file $string(abort_file_commands))
      IFEND
      EXIT PROCEDURE WITH local_status
    IFEND
  TASKEND

  delete_system_task name=$name(system_task_name_value) status=local_status
  IF NOT local_status.normal AND ($condition(local_status.condition) <> 'OSE$SYSTEM_TASK_NOT_DEFINED') THEN
    EXIT_PROC WITH local_status
  IFEND

  define_system_task name=$name(system_task_name_value) library=(scfs_library, $system.debug.bound_product, ..
        $system.tdu.bound_product) starting_procedure=nfp$status_control_fac_server ..
        parameters='CF='//control_facility_name_value//' S='//application_name_value//' L='//logging_value//ntf_systems ..
        abort_file=abort_file_commands automatic_restart=false restart_after_idle=true ..
        deactivate_task_option=terminate idle_task_option=terminate load_map=load_map_value ..
        load_map_options=load_map_options termination_error_level=error status=local_status

  EXIT_PROC WITH local_status WHEN NOT local_status.normal

  activate_system_task task_name=$name(system_task_name_value) status=local_status

  EXIT_PROC WITH local_status

PROCEND activate_scfs
