?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Main Routine' ??
MODULE clm$interpret_commands;

{
{ PURPOSE:
{   This module contains the main routine of the command language interpreter,
{   i.e. the routine that is called to process the commands for a job.
{
?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clc$compiling_for_test_harness
*copyc clc$copyright
*copyc clc$standard_file_names
*IF NOT $true(osv$unix)
*copyc cle$ecc_messages_and_prompts
*copyc ift$format_effectors
*copyc jme$job_monitor_conditions
*copyc jme$queued_file_conditions
*copyc ofc$page_width
*copyc osc$timesharing_terminal_file
*copyc oss$job_paged_literal
*copyc ost$caller_identifier
*copyc pmd$local_queues
*ELSE
*copyc amt$local_file_name
*copyc clt$standard_files
*copyc ost_standard_file_name
*IFEND
?? POP ??
*IF NOT $true(osv$unix)
*copyc amp$get_file_attributes
*copyc bap$file_command
*IFEND
*copyc clp$add_file_to_command_list
*IF NOT $true(osv$unix)
*copyc clp$begin_utility
*copyc clp$create_variable
*ELSE
*copyc clp$create_heap
*copyc clp$free_heap
*copyc clp$init_builtin_msg_templates
*copyc ost_c_integer
*copyc ost_c_string_p
*copyc osp$default_signal_handler
*copyc osp_delete_screen_output
*IFEND
*copyc clp$define_initial_application
*IF NOT $true(osv$unix)
*copyc clp$end_include
*copyc clp$end_utility
*copyc clp$establish_sys_command_lib
*copyc clp$evaluate_parameters
*copyc clp$get_date_string
*copyc clp$get_time_string
*copyc clp$find_current_block
*copyc clp$find_task_block
*copyc clp$get_user_identification
*copyc clp$include_file
*copyc clp$include_line
*copyc clp$internal_cre_file_connect
*copyc clp$login
*copyc clp$put_job_output
*IFEND
*copyc clp$read_command_file
*IF NOT $true(osv$unix)
*copyc clp$request_log_device
*copyc clp$set_processing_phase
*copyc clp$set_working_catalog
*copyc clp$store_std_path_handle_names
*IFEND
*copyc clp$store_system_file_id
*IF NOT $true(osv$unix)
*copyc clp$system_prolog_phase_1
*copyc clp$system_prolog_phase_2
*copyc clp$trimmed_string_size
*IFEND
*copyc clv$initial_application
*copyc clv$standard_files
*IF NOT $true(osv$unix)
*copyc clv$user_identification
*IFEND
*copyc fsp$close_file
*copyc fsp$open_file
*IF NOT $true(osv$unix)
*copyc iip$xt_create_xterm_files
*copyc iip$xt_execute_xterm_command
*copyc iip$xt_initialize_xterm
*copyc jmp$cluster_attach_job_enabled
*copyc jmp$get_job_status
*copyc jmp$get_result_size
*copyc jmp$is_dual_state_job
*copyc jmp$is_xterm_job
*copyc jmp$job_begin
*copyc jmp$job_initialized
*copyc jmp$logout
*copyc jmp$set_job_termination_status
*copyc jmp$system_job
*copyc jmp$timesharing
*copyc ofp$enable_stop_key
*copyc ofp$report_status_error
*copyc osp$append_status_parameter
*copyc osp$check_for_desired_mf_class
*copyc osp$enforce_exception_policies
*copyc osp$file_access_condition
*copyc osp$generate_log_message
*copyc osp$generate_message
*copyc osp$generate_output_message
*copyc osp$get_job_template_name
*copyc osp$idle_resume_system_job
*copyc osp$initialize_virtual_system
*copyc osp$job_template_init_ph1
*copyc osp$job_template_init_ph2
*copyc osp$job_template_init_ph3
*copyc osp$run_virtual_system
*copyc osp$set_status_abnormal
*copyc osp$set_status_condition
*copyc osp$system_error
*IF NOT $true(osv$unix)
*copyc osv$initial_exception_context
*copyc osf$use_site_welcome_banner
*IFEND
*copyc pmf$job_mode
*copyc pmp$continue_to_cause
*copyc pmp$exit
*copyc pmp$find_executing_task_xcb
*copyc pmp$find_stack_segment
*copyc pmp$get_cpu_attributes
*copyc pmp$get_os_version
*copyc pmp$log
*copyc pmp$outward_call
*copyc rap$establish_variables
*copyc rap$intervene_in_deadstart
*copyc rmp$request_null_device
*copyc pmv$debug_logging_enabled
*ELSE
*IFEND

*IF NOT $true(osv$unix)
?? TITLE := 'P$DISPLAY_DETACHED_JOBS', EJECT ??

{I mean, this should go somewhere else, to allow the display_detached_job command

  PROCEDURE p$display_detached_jobs
    (VAR status: ost$status);

    VAR
      job_count: ost$non_negative_integers,
      job_index: jmt$job_status_count,
      job_status_count: jmt$job_status_count,
      job_status_options_p: ^jmt$job_status_options,
      job_status_results_keys_p: ^jmt$results_keys,
      job_status_results_p: ^jmt$job_status_results,
      job_status_results_seq_p: ^jmt$work_area,
      message_status: ost$status,
      size_of_sequence: ost$segment_length;

    PUSH job_status_options_p: [1 .. 5];
    job_status_options_p^ [1].key := jmc$job_mode_set;
    job_status_options_p^ [1].job_mode_set := $jmt$job_mode_set
          [jmc$interactive_cmnd_disconnect, jmc$interactive_line_disconnect, jmc$interactive_sys_disconnect];
    job_status_options_p^ [2].key := jmc$job_state_set;
    job_status_options_p^ [2].job_state_set := $jmt$job_state_set [jmc$initiated_job];
    job_status_options_p^ [3].key := jmc$login_user;
    job_status_options_p^ [3].login_user := clv$user_identification.user.value;
    job_status_options_p^ [4].key := jmc$login_family;
    job_status_options_p^ [4].login_family := clv$user_identification.family.value;
    job_status_options_p^ [5].key := jmc$continue_request_to_servers;
    job_status_options_p^ [5].continue_request_to_servers := jmp$cluster_attach_job_enabled ();

    PUSH job_status_results_keys_p: [1 .. 1];
    job_status_results_keys_p^ [1] := jmc$system_job_name;

    job_count := #SIZE (message_status.text.value) DIV #SIZE (jmt$system_supplied_name);
    jmp$get_result_size (job_count, #SEQ (job_status_results_keys_p^), size_of_sequence);
    PUSH job_status_results_seq_p: [[REP size_of_sequence OF cell]];
    jmp$get_job_status (job_status_options_p, job_status_results_keys_p, job_status_results_seq_p,
          job_status_results_p, job_status_count, status);
    WHILE (NOT status.normal) AND (status.condition = jme$work_area_too_small) DO
      jmp$get_result_size (job_status_count + 2, #SEQ (job_status_results_keys_p^), size_of_sequence);
      PUSH job_status_results_seq_p: [[REP size_of_sequence OF cell]];
      jmp$get_job_status (job_status_options_p, job_status_results_keys_p, job_status_results_seq_p,
            job_status_results_p, job_status_count, status);
    WHILEND;

    IF NOT status.normal THEN
      IF status.condition = jme$no_jobs_were_found THEN
        status.normal := TRUE;
      IFEND;
      RETURN; {----->
    IFEND;

    message_status.normal := TRUE;
    FOR job_index := 1 TO job_status_count DO
      IF message_status.normal THEN
        osp$set_status_abnormal ('CL', cle$detached_jobs, job_status_results_p^ [job_index]^ [1].
              system_job_name, message_status)
      ELSE
        osp$append_status_parameter (' ', job_status_results_p^ [job_index]^ [1].system_job_name,
              message_status);
      IFEND;
    FOREND;

    osp$generate_output_message (message_status, status);

  PROCEND p$display_detached_jobs;
?? TITLE := 'clp$job_boot', EJECT ??

  PROCEDURE [XDCL] clp$job_boot;

{ This procedure is called by pmp$task_begin.  It is always called in ring 3.
{ It's purpose is to perform as much job initialization as possible that
{ does not require user specific information.  The results of job initialization
{ up to the call to jmp$initialize_job_mode is captured and replicated
{ into future jobs, allowing those jobs to skip most of this procedure.

    VAR
      scope: [STATIC, READ, oss$job_paged_literal] clt$variable_scope := [clc$job_variable],
      job_mode: jmt$job_mode,
      initial_ring: ost$ring,
      stack_segment: ^pmt$stack_segment,
      original_caller_cbp: ^ost$external_code_base_pointer,
      converter: record
        case 0 .. 1 of
        = 0 =
          procedure_pointer: ^procedure,
        = 1 =
          code_base_pointer: ^ost$external_code_base_pointer,
        casend,
      recend,
      gtid_converter: record
        case boolean of
        = false =
          global_task_id: ost$global_task_id,
        = true =
          integer_value: 0..0ffffff(16),
        casend,
      recend,
      status: ost$status,
      executing_within_system_job: boolean,
      osv$status: clt$variable_reference;

    clp$get_user_identification (status);

    {Skip job initialization if it has been replicated for this job

    IF NOT jmp$job_initialized () THEN

      IF status.normal THEN
        executing_within_system_job := jmp$system_job ();
        job_mode := pmf$job_mode ();
        clp$set_working_catalog ('$LOCAL', status);
      IFEND;

      IF status.normal THEN
        initialize_command_list (executing_within_system_job, status);
      IFEND;

      IF status.normal THEN
        clp$create_variable ('OSV$STATUS', clc$status_value, 0, 1, 1, scope, osv$status, status);
      IFEND;

      IF status.normal AND executing_within_system_job THEN
        osp$job_template_init_ph1;
      IFEND;

      IF status.normal AND (NOT executing_within_system_job) THEN
        clp$system_prolog_phase_1 (status);
      IFEND;

      IF status.normal AND ((job_mode = jmc$batch) OR
            jmp$timesharing ()) THEN
        {Do for batch and standalone interactive
        {Skip for dualstate and xterm interactive
        initialize_standard_files (job_mode, executing_within_system_job, {first_time=} TRUE, status);
      IFEND;

      IF status.normal AND (job_mode <> jmc$batch) AND
            jmp$timesharing () THEN
        {Do for standalone interactive
        {Skip for batch, dualstate and xterm interactive
        initialize_standard_files (job_mode, executing_within_system_job, {first_time=} FALSE, status);
      IFEND;

    IFEND; {NOT job initialized}

    IF status.normal THEN
      jmp$job_begin (initial_ring);

      {Must now transfer control to the correct ring for the
      {job monitor task.

      pmp$find_stack_segment (initial_ring, stack_segment);
      converter.procedure_pointer := ^clp$interpret_commands;
      original_caller_cbp := converter.code_base_pointer;
      pmp$outward_call (original_caller_cbp, initial_ring, NIL,
            NIL, stack_segment); { does not return }
      osp$system_error ('outward call error', NIL);
    ELSE
      osp$system_error ('Job boot error', ^status);
    IFEND;

  PROCEND clp$job_boot;
*IFEND

?? TITLE := 'clp$interpret_commands', EJECT ??

*IF NOT $true(osv$unix)
  PROCEDURE [XDCL] clp$interpret_commands;
*ELSE
  PROCEDURE [XDCL] clp_interpret_commands (
    VAR command_line: string (256);
    VAR stat: ost_c_integer);
*IFEND

    VAR
      continue_after_initial_command: boolean,
*IF $true(osv$unix)
      initial_application: ^clt$command_line,
*IFEND
      initial_command: ^clt$command_line;

    VAR
*IF NOT $true(osv$unix)
      scope: [STATIC, READ, oss$job_paged_literal] clt$variable_scope := [clc$job_variable],
      job_mode: jmt$job_mode,
*ELSE
      handler_stat: boolean,
      heap_name: ost$name,
      signal_number : 1 .. 31,
*IFEND
      system_restart: boolean,
      status: ost$status;

    VAR
*IF NOT $true(osv$unix)
      deadstart_phase: ost$deadstart_phase,
      deadstart_intervention: boolean,
      executing_within_system_job: boolean,
*ELSE
      executing_within_system_job: boolean;
*IFEND
*IF NOT $true(osv$unix)
      ignore_status: ost$status,
      osv$status: clt$variable_reference,
      restricted_mainframe: boolean;
*IFEND


    status.normal := TRUE;
*IF NOT $true(osv$unix)
    executing_within_system_job := jmp$system_job ();
*ELSE
    executing_within_system_job := FALSE;
    heap_name := 'OSV$TASK_SHARED_HEAP';

    FOR signal_number := 1 to 31 DO
      IF (signal_number <> 9) AND       {sigkill}
            (signal_number <> 18) AND   {sigchld}
            (signal_number <> 20) THEN  {sigstop}
        IF NOT #establish_condition_handler (signal_number, ^osp$default_signal_handler) THEN
{??? Doesn't compile, but is this really the correct action?
{         stringrep (ps_line, ps_length, 'Unable to establish a handler for signal number ', signal_number);
{         print_string (ps_line, ps_length);
        IFEND;
      IFEND;
    FOREND;

    clp$create_heap(heap_name);
    clp$init_builtin_msg_templates;
*IFEND
*IF NOT $true(osv$unix)
    job_mode := pmf$job_mode ();
    restricted_mainframe := FALSE;

    IF jmp$is_xterm_job () THEN

{ Xterm files must be created before standard files are initialized so that the
{ standard files are assigned to a terminal device.

      iip$xt_create_xterm_files (status);
    IFEND;

    ?IF clc$compiling_for_test_harness THEN
      IF status.normal THEN
        clp$get_user_identification (status);
      IFEND;

      IF status.normal THEN
        clp$set_working_catalog ('$LOCAL', status);
      IFEND;
*IFEND

      IF status.normal THEN
        initialize_command_list (executing_within_system_job, status);
      IFEND;

*IF NOT $true(osv$unix)
      IF status.normal THEN
        clp$create_variable ('OSV$STATUS', clc$status_value, 0, 1, 1, scope, osv$status, status);
      IFEND;

      IF status.normal THEN
        clp$store_std_path_handle_names (executing_within_system_job, {first_time=} TRUE, status);
      IFEND;
    ?IFEND;

    IF status.normal AND ((job_mode <> jmc$batch) AND (jmp$is_dual_state_job () OR
          jmp$is_xterm_job ())) THEN

{ Do for dualstate interactive, xterm job.

      initialize_standard_files (job_mode, executing_within_system_job, {first_time=} TRUE, status);

    IFEND;

    IF status.normal AND ((job_mode = jmc$batch) OR jmp$is_dual_state_job ()
          OR jmp$is_xterm_job ()) THEN

{ Do for batch, dualstate interactive, xterm job.

     initialize_standard_files (job_mode, executing_within_system_job, {first_time=} FALSE, status);
*ELSE
    IF status.normal THEN
      initialize_standard_files (status);
*IFEND
    IFEND;

*IF NOT $true(osv$unix)
    IF status.normal AND jmp$is_xterm_job () THEN

{ Standard files must be open before the xterm task  begins execution.  The xterm task
{ uses standard files.

       iip$xt_initialize_xterm (status);
    IFEND;

    IF status.normal AND executing_within_system_job THEN
      osp$check_for_desired_mf_class (osc$mc_china_or_soviet_class, restricted_mainframe);

      { For the Soviet Nuclear Safety Systems and China Weather Systems, do not enable the stop key now.
      { It is done later.

      IF NOT restricted_mainframe THEN
        ofp$enable_stop_key;
      IFEND;
      clp$include_line ('$system.change_scl_options prompt_for_parameter_correction=no', FALSE,
            'DEADSTART                      ', ignore_status);
    IFEND;

    IF status.normal AND executing_within_system_job THEN
      osp$job_template_init_ph2 (deadstart_intervention, deadstart_phase);
      rap$establish_variables (ignore_status);
      IF deadstart_intervention THEN
        IF NOT restricted_mainframe THEN

          { For the Soviet Nuclear Safety Systems, don't allow this.

          rap$intervene_in_deadstart (ignore_status);
        IFEND;
      IFEND;
    IFEND;

    IF status.normal AND (job_mode <> jmc$batch) AND (NOT jmp$is_xterm_job ()) THEN
      put_welcome_banner (status);
    IFEND;

    IF NOT status.normal THEN
      osp$system_error ('job init failed', ^status);
    IFEND;

    IF status.normal AND jmp$is_xterm_job () THEN
      iip$xt_execute_xterm_command (status);
    IFEND;

    IF status.normal AND (NOT executing_within_system_job) THEN
      clp$system_prolog_phase_2 (status);
    IFEND;

    IF status.normal AND (NOT executing_within_system_job) THEN
      clp$login (status);
    IFEND;

    IF status.normal AND executing_within_system_job THEN
      osp$job_template_init_ph3;
      clp$system_prolog_phase_1 (ignore_status);
      clp$set_processing_phase (clc$command_phase, ignore_status);
      osp$initialize_virtual_system (deadstart_phase);
      pmp$log (' ---- SYSTEM DEADSTART COMPLETE ----', ignore_status);
      system_restart := FALSE;

    /system_loop/
      WHILE TRUE DO
        osp$run_virtual_system (system_restart, status);
        IF NOT status.normal THEN
          osp$generate_message (status, ignore_status);
        IFEND;

        osp$idle_resume_system_job (status);
        IF NOT status.normal THEN
          osp$generate_message (status, ignore_status);
        IFEND;

        { Control from a RESUMEing system will then return to this point. }
        system_restart := TRUE;
      WHILEND /system_loop/;

      status.normal := TRUE;
    IFEND;

    IF status.normal THEN

    /command_processing_phase/
      BEGIN
*ELSE
    stat := 0;

    initial_application := ^command_line;
    clp$define_initial_application (initial_application, TRUE, status);
    IF NOT status.normal THEN
      stat := status.condition;
      RETURN;
    IFEND;
*IFEND
        IF clv$initial_application.defined THEN
          initial_command := clv$initial_application.application;
          continue_after_initial_command := NOT clv$initial_application.logout_upon_termination;
        ELSE
          initial_command := NIL;
          continue_after_initial_command := FALSE;
        IFEND;
        clp$read_command_file (':$LOCAL.COMMAND.1', osc$null_name, '', TRUE, initial_command,
              continue_after_initial_command, status);
*IF NOT $true(osv$unix)
      END /command_processing_phase/;
    IFEND;

    IF NOT status.normal THEN
      jmp$set_job_termination_status (status);
    IFEND;

    jmp$logout (ignore_status);
*ELSE
    IF NOT status.normal THEN
      stat := status.condition;
    IFEND;
    clp$free_heap (heap_name);

    FOR signal_number := 1 to 31 DO
      IF (signal_number <> 9) AND       {sigkill}
            (signal_number <> 18) AND   {sigchld}
            (signal_number <> 20) THEN  {sigstop}
        IF NOT #disestablish_condition_handler (signal_number) THEN
{ ??? doesn't compile, but maybe we don't care if we can't disestablish a handler?
{         stringrep (ps_line, ps_length, 'Unable to disestablish a handler for signal number ',
{               signal_number);
{         print_string (ps_line, ps_length);
        IFEND;
      IFEND;
    FOREND;

    osp_delete_screen_output;
*IFEND

*IF NOT $true(osv$unix)
  PROCEND clp$interpret_commands;
*ELSE
  PROCEND clp_interpret_commands;
*IFEND
?? TITLE := 'initialize_command_list', EJECT ??

  PROCEDURE initialize_command_list
    (    executing_within_system_job: boolean;
     VAR status: ost$status);

    VAR
*IF NOT $true(osv$unix)
      command_entry_file: clt$command_list_entry_file,
      context: ^ost$ecp_exception_context,
      local_catalog: [STATIC, READ, oss$job_paged_literal] string (7) := ':$LOCAL',
      test_harness_sys_cmnd_lib: [STATIC, READ, oss$job_paged_literal] string (27) :=
            ':$LOCAL.OSF$COMMAND_LIBRARY';
*ELSE
      command_entry_file: clt$command_list_entry_file;
*IFEND


    command_entry_file.kind := clc$command_list_entry_$system;
*IF NOT $true(osv$unix)
    context := NIL;

{Add this back in when $SYSTEM is a command list entry
    REPEAT
      clp$add_file_to_command_list (command_entry_file, FALSE, status);
*IFEND
*IF NOT $true(osv$unix)
      IF NOT status.normal THEN
        IF context = NIL THEN
          PUSH context;
          context^ := osv$initial_exception_context;
        IFEND;
        context^.condition_status := status;
        osp$enforce_exception_policies (context^);
        status := context^.condition_status;
      IFEND;
    UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
*ELSE
    status.normal := TRUE;
{   UNTIL status.normal;
*IFEND
    IF NOT status.normal THEN
      RETURN;
    IFEND;

*IF NOT $true(osv$unix)
    command_entry_file.kind := clc$command_list_entry_path;
    IF executing_within_system_job THEN
      command_entry_file.path := ^local_catalog;
      REPEAT
        clp$add_file_to_command_list (command_entry_file, FALSE, status);
        IF NOT status.normal THEN
          IF context = NIL THEN
            PUSH context;
            context^ := osv$initial_exception_context;
            context^.file.selector := osc$ecp_file_reference;
            context^.file.file_reference := command_entry_file.path;
          IFEND;
          context^.condition_status := status;
          osp$enforce_exception_policies (context^);
          status := context^.condition_status;
        IFEND;
      UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
    ELSE

      ?IF clc$compiling_for_test_harness THEN
        command_entry_file.path := ^test_harness_sys_cmnd_lib;
        REPEAT
          clp$establish_sys_command_lib (command_entry_file.path, status);
          IF NOT status.normal THEN
            IF context = NIL THEN
              PUSH context;
              context^ := osv$initial_exception_context;
              context^.file.selector := osc$ecp_file_reference;
              context^.file.file_reference := command_entry_file.path;
            IFEND;
            context^.condition_status := status;
            osp$enforce_exception_policies (context^);
            status := context^.condition_status;
          IFEND;
        UNTIL status.normal OR (NOT osp$file_access_condition (status)) OR (NOT context^.wait);
      ?IFEND;
    IFEND;
*IFEND

  PROCEND initialize_command_list;
*IF NOT $true(osv$unix)
?? TITLE := 'initialize_standard_files', EJECT ??
{
{  PURPOSE:
{    This procedure will initialize file attributes, create file connections, and open standard files.
{    Listed below are the possible options for each file.
{
{
{  $JOB_LOG                                       $NULL
{  --------                                       -----
{  access modes = append, read                    access modes = read, append, modify, shorten
{  share modes = none                             share modes = none
{  open share modes = all                         open share modes = all
{  ring attributes = 13,13,13                     ring attributes = 13,13,13
{  file contents = unknown_unknown                file contents = unknown_unknown
{  file processor = unknown                       file processor = unknown
{  page format = continuous
{  page width = 132 - 16
{
{  INPUT, $INPUT                                  OUTPUT, $OUTPUT, $ERRORS
{  -------------                                  ------------------------
{  access modes = read                            access modes = append, shorten
{  share modes = none                             share modes = none
{  open share modes = read, execute               open share modes = all
{  ring attributes = 13,13,13                     ring attributes = 13,13,13
{  file contents = legible_data                   file contents = list_data
{  file processor = unknown                       file processor = unknown
{  page width = 79  (INPUT only and system job)   page format = continuous or burstable
{  page length = 30 (INPUT only and system job)   open position = no positioning (OUTPUT and $ERRORS only)
{  connected files = INPUT ($INPUT only)          page width = 79  (OUTPUT only and system job)
{                                                 page length = 30 (OUTPUT only and system job)
{                                                 connected files = OUTPUT ($OUTPUT and $ERRORS only)
{                                                                   $JOB_LOG ($ERRORS only in system job)
{
{  $LIST                                          $ECHO, $RESPONSE
{  -----                                          ----------------
{  access modes = append, shorten                 access modes = append, shorten
{  share modes = none                             share modes = none
{  open share modes = all                         open share modes = all
{  ring attributes = 13,13,13                     ring attributes = 13,13,13
{  file contents = list_data                      file contents = list_data
{  file processor = unknown                       file processor = scl
{  page format = burstable                        page format = continuous
{  connected files = OUTPUT or none               open position = no positioning
{                                                 connected files = none ($ECHO only)
{                                                                   $JOB_LOG and possibly
{                                                                   OUTPUT ($RESPONSE only)
{
{  COMMAND                                        DISPLAY_A, DISPLAY_B (system job files only)
{  -------                                        --------------------
{  access modes = read, execute                   file contents = list
{  file contents = legible_data                   page format = continuous
{  file processor = scl                           user info = 'LOG'
{  page width = 79 (system job)                   page width = 79
{  page length = 30 (system job)                  page length = 30
{
*IFEND

  PROCEDURE initialize_standard_files
*IF NOT $true(osv$unix)
    (    job_mode: jmt$job_mode;
         executing_within_system_job: boolean;
         first_time: boolean;
     VAR status: ost$status);
*ELSE
    (VAR status: ost$status);
*IFEND

*IF NOT $true(osv$unix)
    CONST
      osc$display_a = 'DISPLAY_A                      ',
      osc$display_b = 'DISPLAY_B                      ',
      standard_listing_page_width = 132,
      job_log_entry_header_size = 16,
      operator_file_page_length = 30;
*IFEND

    VAR
*IF NOT $true(osv$unix)
      standard_file_names: [STATIC, READ, oss$job_paged_literal] array [clt$standard_files] of
            amt$local_file_name := [clc$job_log, clc$null_file, clc$job_input, clc$standard_input,
            clc$job_output, clc$standard_output, clc$error_output, clc$listing_output, clc$echoed_commands,
            clc$job_command_response, clc$job_command_input, osc$timesharing_terminal_file, osc$display_a,
            osc$display_b, osc$null_name],
*ELSE
      standard_file_names: [STATIC, READ] array [clt$standard_files] of
            amt$local_file_name := [clc$null_file, clc$job_input, clc$standard_input,
            clc$job_output, clc$standard_output, clc$error_output,
            clc$job_command_input, osc$null_name],
*IFEND
      file_attachment: array [1 .. 4] of fst$attachment_option,
*IF NOT $true(osv$unix)
      mandated_creation_attributes: array [1 .. 5] of fst$file_cycle_attribute,
      file_attributes: array [1 .. 6] of amt$file_item,
      connected_file_names: array [1 .. 2] of amt$local_file_name,
*IFEND
      file: clt$standard_files,
      file_name: amt$local_file_name,
*IF NOT $true(osv$unix)
      file_id: amt$file_identifier,
      setfa_attribute: array [1 .. 1] of amt$file_item,
      standard_file: fst$path_handle_name,
*ELSE
      standard_file: ost_standard_file_name,
*IFEND
*IF NOT $true(osv$unix)
      target_file_open_position: fst$open_position,
      page_format: amt$page_format,
      fap_name: pmt$entry_point_reference,
      index: 1 .. 6,
      error_message: string (61),
      message_length: integer,
*IFEND
      open_file: boolean,
      close_file: boolean,
      system_file: boolean,
*IF NOT $true(osv$unix)
      operator_file: boolean,
      number_of_mandated_attributes: 2 .. 5,
      number_of_file_attributes: 0 .. 6,
      number_of_connected_files: 0 .. 2;
*ELSE
      file_id: amt$file_identifier;
*IFEND


*IF NOT $true(osv$unix)
    IF executing_within_system_job OR (job_mode <> jmc$batch) THEN
      page_format := amc$continuous_form;
    ELSE
      page_format := amc$burstable_form;
    IFEND;

    setfa_attribute [1].key := amc$access_mode;
*IFEND

    file_attachment [1].selector := fsc$create_file;
    file_attachment [1].create_file := TRUE;
    file_attachment [2].selector := fsc$access_and_share_modes;
    file_attachment [2].access_modes.selector := fsc$specific_access_modes;
    file_attachment [2].share_modes.selector := fsc$specific_share_modes;
    file_attachment [2].share_modes.value := $fst$file_access_options [];
    file_attachment [3].selector := fsc$open_share_modes;

*IF NOT $true(osv$unix)
    mandated_creation_attributes [1].selector := fsc$ring_attributes;
    mandated_creation_attributes [1].ring_attributes.r1 := osc$user_ring_2;
    mandated_creation_attributes [1].ring_attributes.r2 := osc$user_ring_2;
    mandated_creation_attributes [1].ring_attributes.r3 := osc$user_ring_2;
    mandated_creation_attributes [2].selector := fsc$file_contents_and_processor;
*IFEND

    system_file := FALSE;
    open_file := TRUE;
    close_file := FALSE;
*IF NOT $true(osv$unix)
    target_file_open_position.specified := FALSE;
*IFEND

  /initialize_files/
*IF NOT $true(osv$unix)
    FOR file := clc$sf_job_log_file TO clc$sf_display_b_file DO
*ELSE
    FOR file := clc$sf_null_file TO clc$sf_command_file DO
*IFEND

*IF NOT $true(osv$unix)
      IF NOT first_time THEN
        IF file <> clc$sf_command_file THEN
          CYCLE /initialize_files/;
        IFEND;
      IFEND;
*ELSE
      IF file <> clc$sf_null_file THEN
        CYCLE /initialize_files/;
      IFEND;
*IFEND

*IF NOT $true(osv$unix)
      standard_file := clv$standard_files [file].path_handle_name;
      operator_file := FALSE;
*ELSE
      standard_file := clv$standard_files [file].unix_file_name;
*IFEND
      file_name := standard_file_names [file];

      CASE file OF

*IF NOT $true(osv$unix)
        {  $JOB_LOG

      = clc$sf_job_log_file =
        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$read, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        mandated_creation_attributes [2].file_contents := fsc$unknown_contents;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := amc$continuous_form;
        mandated_creation_attributes [4].selector := fsc$page_width;
        mandated_creation_attributes [4].page_width := standard_listing_page_width -
              job_log_entry_header_size;
        number_of_mandated_attributes := 4;

        ?IF NOT clc$compiling_for_test_harness THEN
          clp$request_log_device (status);
          IF NOT status.normal THEN
            osp$system_error ('open failed', ^status);
            RETURN;
          IFEND;
        ?IFEND;

        number_of_connected_files := 0;
        close_file := TRUE;
*IFEND

        {  $NULL

      = clc$sf_null_file =
*IF NOT $true(osv$unix)
        rmp$request_null_device (clc$null_file, status);
        IF NOT status.normal THEN
          osp$system_error ('open failed', ^status);
          RETURN;
        IFEND;

        setfa_attribute [1].access_mode := $pft$usage_selections
              [pfc$read, pfc$shorten, pfc$append, pfc$modify];
*IFEND

        file_attachment [2].access_modes.value := $fst$file_access_options
              [fsc$read, fsc$append, fsc$modify, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

*IF NOT $true(osv$unix)
        mandated_creation_attributes [2].file_contents := fsc$unknown_contents;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        number_of_mandated_attributes := 2;

        number_of_connected_files := 0;

        {  INPUT

      = clc$sf_job_input_file =
        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$read];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$read];
        file_attachment [3].open_share_modes := $fst$file_access_options [fsc$read, fsc$execute];

        mandated_creation_attributes [2].file_contents := fsc$legible_data;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        number_of_mandated_attributes := 2;

        number_of_connected_files := 0;
        operator_file := executing_within_system_job;

        {  $INPUT
        { Access modes, open share modes, file_contents, and file processor are used
        {from the previous open of file INPUT.

      = clc$sf_standard_input_file =
        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$read];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$read];
        file_attachment [3].open_share_modes := $fst$file_access_options [fsc$read, fsc$execute];

        mandated_creation_attributes [2].file_contents := fsc$legible_data;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        number_of_mandated_attributes := 2;
        connected_file_names [1] := clv$standard_files [clc$sf_job_input_file].path_handle_name;
        number_of_connected_files := 1;

        {  OUTPUT

      = clc$sf_job_output_file =
        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$shorten, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        mandated_creation_attributes [2].file_contents := fsc$list;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := page_format;
        number_of_mandated_attributes := 3;

        number_of_connected_files := 0;
        operator_file := executing_within_system_job;
        system_file := TRUE;

        {  $OUTPUT
        { Access modes, open share modes, file contents, file processor,
        {and page format are used from the previous open of file OUTPUT.

      = clc$sf_standard_output_file =
        mandated_creation_attributes [2].file_contents := fsc$list;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := page_format;
        number_of_mandated_attributes := 3;
        connected_file_names [1] := clv$standard_files [clc$sf_job_output_file].path_handle_name;
        number_of_connected_files := 1;

        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$shorten, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        {  $ERRORS
        { Access modes, open share modes, file contents, file processor,
        {and page format are used from the previous open of file OUTPUT.

      = clc$sf_error_file =
        mandated_creation_attributes [2].file_contents := fsc$list;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := page_format;
        number_of_mandated_attributes := 3;
        IF executing_within_system_job THEN
          connected_file_names [1] := clv$standard_files [clc$sf_job_output_file].path_handle_name;
          connected_file_names [2] := clv$standard_files [clc$sf_job_log_file].path_handle_name;
          number_of_connected_files := 2;
        ELSE
          connected_file_names [1] := clv$standard_files [clc$sf_job_output_file].path_handle_name;
          number_of_connected_files := 1;
        IFEND;

        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$shorten, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        system_file := TRUE;

        {  $LIST
        { Access modes, open share modes, file contents, and file processor
        {are used from the previous open of file OUTPUT.

      = clc$sf_list_file =
        mandated_creation_attributes [2].file_contents := fsc$list;
        mandated_creation_attributes [2].file_processor := fsc$unknown_processor;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := amc$burstable_form;
        number_of_mandated_attributes := 3;

        IF (job_mode = jmc$batch) AND (NOT executing_within_system_job) THEN
          connected_file_names [1] := clv$standard_files [clc$sf_job_output_file].path_handle_name;
        ELSE
          connected_file_names [1] := osc$null_name;
        IFEND;
        number_of_connected_files := 1;

        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$shorten, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        {  $ECHO
        { Access modes and open share modes are used from the previous open
        {of file OUTPUT.

      = clc$sf_echo_file =
        mandated_creation_attributes [2].file_contents := fsc$list;
        mandated_creation_attributes [2].file_processor := fsc$scl;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := amc$continuous_form;
        number_of_mandated_attributes := 3;

        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$shorten, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        connected_file_names [1] := osc$null_name;
        number_of_connected_files := 1;

        system_file := TRUE;

        {  $RESPONSE
        { Access modes, open share modes, file contents, file processor,
        {and page format are used from the previous open of file $ECHO.

      = clc$sf_response_file =
        mandated_creation_attributes [2].file_contents := fsc$list;
        mandated_creation_attributes [2].file_processor := fsc$scl;
        mandated_creation_attributes [3].selector := fsc$page_format;
        mandated_creation_attributes [3].page_format := amc$continuous_form;
        number_of_mandated_attributes := 3;

        IF executing_within_system_job OR (job_mode <> jmc$batch) THEN
          connected_file_names [1] := clv$standard_files [clc$sf_job_output_file].path_handle_name;
          connected_file_names [2] := clv$standard_files [clc$sf_job_log_file].path_handle_name;
          number_of_connected_files := 2;
        ELSE
          connected_file_names [1] := clv$standard_files [clc$sf_job_log_file].path_handle_name;
          number_of_connected_files := 1;
        IFEND;

        setfa_attribute [1].access_mode := $pft$usage_selections [pfc$shorten, pfc$append];

        file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
        file_attachment [3].open_share_modes := -$fst$file_access_options [];

        system_file := TRUE;

        {  COMMAND

      = clc$sf_command_file =
        IF first_time THEN
          CYCLE /initialize_files/;
        IFEND;
        file_attributes [1].key := amc$access_mode;
        file_attributes [1].access_mode := $pft$usage_selections [pfc$read, pfc$execute];
        file_attributes [2].key := amc$file_contents;
        file_attributes [2].file_contents := amc$legible;
        file_attributes [3].key := amc$file_processor;
        file_attributes [3].file_processor := amc$scl;
        file_attributes [4].key := amc$file_structure;
        file_attributes [4].file_structure := amc$data;
        number_of_file_attributes := 4;

        operator_file := executing_within_system_job;
        open_file := FALSE;

        {  DISPLAY_A

      = clc$sf_display_a_file =
        IF NOT executing_within_system_job THEN
          CYCLE /initialize_files/;
        IFEND;

        file_attributes [1].key := amc$file_contents;
        file_attributes [1].file_contents := amc$list;
        file_attributes [2].key := amc$page_format;
        file_attributes [2].page_format := amc$continuous_form;
        file_attributes [3].key := amc$user_info;
        file_attributes [3].user_info := 'LOG';
        number_of_file_attributes := 3;

        operator_file := TRUE;
        open_file := FALSE;

        {  DISPLAY _B
        { File contents, page format, and user info are used from the previous attribute
        {initialization of file DISPLAY_A.

      = clc$sf_display_b_file =
        IF NOT executing_within_system_job THEN
          CYCLE /initialize_files/;
        IFEND;

        number_of_file_attributes := 3;
        operator_file := TRUE;
        open_file := FALSE;

      = clc$sf_terminal_file =
        CYCLE /initialize_files/;
*IFEND

      CASEND;

*IF NOT $true(osv$unix)
      IF operator_file THEN
        rmp$request_null_device (standard_file, status);
        IF NOT status.normal THEN
          STRINGREP (error_message, message_length, 'rmp$request_null_device on file ', file_name);
          ofp$report_status_error (status, error_message (1, message_length));
          osp$system_error ('open failed', ^status);
          RETURN;
        IFEND;

        IF open_file THEN
          number_of_mandated_attributes := number_of_mandated_attributes + 1;
          mandated_creation_attributes [number_of_mandated_attributes].selector := fsc$page_width;
          mandated_creation_attributes [number_of_mandated_attributes].page_width := ofc$page_width - 1;
          number_of_mandated_attributes := number_of_mandated_attributes + 1;
          mandated_creation_attributes [number_of_mandated_attributes].selector := fsc$page_length;
          mandated_creation_attributes [number_of_mandated_attributes].page_length :=
                operator_file_page_length;
        ELSE
          number_of_file_attributes := number_of_file_attributes + 1;
          file_attributes [number_of_file_attributes].key := amc$page_width;
          file_attributes [number_of_file_attributes].page_width := ofc$page_width - 1;
          number_of_file_attributes := number_of_file_attributes + 1;
          file_attributes [number_of_file_attributes].key := amc$page_length;
          file_attributes [number_of_file_attributes].page_length := operator_file_page_length;
        IFEND;
      IFEND;

      IF system_file THEN
        file_attachment [4].selector := fsc$open_position;
        file_attachment [4].open_position := amc$open_no_positioning;
      ELSE
        file_attachment [4].selector := fsc$null_attachment_option;
      IFEND;
*IFEND

      IF open_file THEN
*IF NOT $true(osv$unix)
        FOR index := number_of_mandated_attributes + 1 TO UPPERBOUND (mandated_creation_attributes) DO
          mandated_creation_attributes [index].selector := fsc$null_attribute;
        FOREND;

        FOR index := 1 TO number_of_connected_files DO
          clp$internal_cre_file_connect (standard_file, connected_file_names [index],
                target_file_open_position, status);
          IF NOT status.normal THEN
            osp$system_error ('file connection failed', ^status);
            RETURN;
          IFEND;
        FOREND;

        fsp$open_file (standard_file, amc$record, ^file_attachment, NIL, ^mandated_creation_attributes, NIL,
              NIL, file_id, status);
*ELSE
        fsp$open_file (standard_file, amc$record, ^file_attachment, file_id, status);
*IFEND
        IF NOT status.normal THEN
*IF NOT $true(osv$unix)
          IF operator_file THEN
            STRINGREP (error_message, message_length, 'fsp$open_file on file ', file_name);
            ofp$report_status_error (status, error_message (1, message_length));
          IFEND;
          osp$system_error ('open failed', ^status);
*ELSE
          RETURN;
*IFEND
        IFEND;

*IF NOT $true(osv$unix)
        IF system_file THEN
*IFEND
          clp$store_system_file_id (file_name, file_id);
*IF NOT $true(osv$unix)
          system_file := FALSE;
        ELSEIF close_file THEN
          fsp$close_file (file_id, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          close_file := FALSE;
        IFEND;

        bap$file_command (standard_file, ^setfa_attribute, status);
        IF NOT status.normal THEN
          IF operator_file THEN
            STRINGREP (error_message, message_length, 'bap$file_command on file ', file_name);
            ofp$report_status_error (status, error_message (1, message_length));
          IFEND;
          osp$system_error ('file_command failed', ^status);
          RETURN;
        IFEND;
*IFEND

      ELSE { NOT open_file
*IF NOT $true(osv$unix)
        FOR index := number_of_file_attributes + 1 TO UPPERBOUND (file_attributes) DO
          file_attributes [index].key := amc$null_attribute;
        FOREND;

        bap$file_command (standard_file, ^file_attributes, status);
        IF NOT status.normal THEN
          IF operator_file THEN
            STRINGREP (error_message, message_length, 'bap$file_command on file ', file_name);
            ofp$report_status_error (status, error_message (1, message_length));
          IFEND;
          osp$system_error ('open failed', ^status);
          RETURN;
        IFEND;
        open_file := TRUE;
*IFEND
      IFEND;
    FOREND /initialize_files/;

  PROCEND initialize_standard_files;
*IF NOT $true(osv$unix)
?? TITLE := 'put_welcome_banner', EJECT ??

  PROCEDURE put_welcome_banner
    (VAR status: ost$status);

    CONST
      max_job_template_msg_part_size = 3 + osc$max_name_size + 1 {'  (name)'} ;

    VAR
      cpu_attributes: pmt$cpu_attributes,
      cpu_index: 0 .. osc$maximum_processor_number,
      date: ost$string,
      site_welcome_banner_exists: boolean,
      first_cpu: boolean,
      job_template_message_part: ^string ( * <= max_job_template_msg_part_size),
      job_template_name: ost$name,
      message_status: ost$status,
      os_name: pmt$os_name,
      time: ost$string;

?? TITLE := 'put_site_welcome_banner', EJECT ??

    PROCEDURE put_site_welcome_banner
      (VAR site_welcome_banner_exists: boolean);

      CONST
        max_job_template_msg_part_size = 3 + osc$max_name_size + 1 {'  (name)'} ,
        site_welcome_banner_file = ':$SYSTEM.$SYSTEM.PROLOGS_AND_EPILOGS.WELCOME_BANNER';

      VAR
        contains_data: boolean,
        file_attributes: array [1 .. 1] of amt$get_item,
        ignore_file_previously_opened: boolean,
        status: ost$status;

{ Check first for a site-defined welcome banner.  If the file is not empty, include it.
{ If it is empty, that's OK, just put out the copyright message.  If the file doesn't exist
{ or something went wrong in the include process, then put out the standard welcome banner.

      file_attributes [1].key := amc$null_attribute;
      amp$get_file_attributes (site_welcome_banner_file, file_attributes, site_welcome_banner_exists,
            ignore_file_previously_opened, contains_data, status);
      IF status.normal AND contains_data THEN
        clp$include_file (site_welcome_banner_file, '', osc$null_name, status);
      IFEND;

      IF status.normal AND site_welcome_banner_exists THEN
        clp$put_job_output (clc$copyright, status);
      IFEND;

    PROCEND put_site_welcome_banner;
?? OLDTITLE ??
?? EJECT ??

    site_welcome_banner_exists := FALSE;
    IF osf$use_site_welcome_banner () THEN
      put_site_welcome_banner (site_welcome_banner_exists);
    IFEND;

    IF NOT site_welcome_banner_exists THEN
      pmp$get_cpu_attributes (cpu_attributes, status);
      IF NOT status.normal THEN
        RETURN; {----->
      IFEND;

      pmp$get_os_version (os_name, status);
      IF NOT status.normal THEN
        RETURN; {----->
      IFEND;
      clp$get_date_string (date, status);
      IF NOT status.normal THEN
        RETURN; {----->
      IFEND;
      clp$get_time_string (time, status);
      IF NOT status.normal THEN
        RETURN; {----->
      IFEND;
      osp$get_job_template_name (job_template_name);

      osp$set_status_abnormal ('CL', cle$welcome_banner, cpu_attributes.cpu [0].
            model_type (1, clp$trimmed_string_size (cpu_attributes.cpu [0].model_type)), message_status);
      first_cpu := TRUE;

      FOR cpu_index := 0 TO cpu_attributes.highest_defined_cpu_number DO
        IF cpu_attributes.cpu [cpu_index].state = pmc$processor_state_on THEN
          IF first_cpu THEN
            first_cpu := FALSE;

            osp$append_status_parameter (osc$status_parameter_delimiter,
                  cpu_attributes.cpu [cpu_index].serial_number (1,
                  clp$trimmed_string_size (cpu_attributes.cpu [cpu_index].serial_number)), message_status);
          ELSE

            osp$append_status_parameter (',', cpu_attributes.cpu [cpu_index].
                  serial_number (1, clp$trimmed_string_size (cpu_attributes.cpu [cpu_index].serial_number)),
                  message_status);
          IFEND;
        IFEND;
      FOREND;

      osp$append_status_parameter (osc$status_parameter_delimiter, os_name, message_status);
      IF job_template_name <> '' THEN
        PUSH job_template_message_part: [3 + clp$trimmed_string_size (job_template_name) + 1];
        job_template_message_part^ (1, 3) := '  (';
        job_template_message_part^ (4, * ) := job_template_name;
        job_template_message_part^ (STRLENGTH (job_template_message_part^)) := ')';
        osp$append_status_parameter (' ', job_template_message_part^, message_status);
      IFEND;
      osp$append_status_parameter (osc$status_parameter_delimiter, date.value, message_status);
      osp$append_status_parameter (osc$status_parameter_delimiter, time.value, message_status);

      osp$generate_output_message (message_status, status);
    IFEND;

    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    ?IF NOT clc$compiling_for_test_harness THEN
      p$display_detached_jobs (status);
    ?IFEND;

  PROCEND put_welcome_banner;
?? TITLE := 'clp$operator_intervention', EJECT ??

  CONST
    operator_intervention_utility = 'OPERATOR_INTERVENTION          ',
    operator_intervention_prompt = 'OI',
    operator_interventn_prompt_size = 2;


  PROCEDURE [XDCL] clp$operator_intervention
    (VAR status: ost$status);

{ table op_intervention_cmnds t=c s=local section_name=oss$job_paged_literal
{ command go                             end_operator_intervention cm=local
{ tablend

?? PUSH (LISTEXT := ON) ??

    VAR
      op_intervention_cmnds: [STATIC, READ, oss$job_paged_literal] ^clt$command_table :=
          ^op_intervention_cmnds_entries,

      op_intervention_cmnds_entries: [STATIC, READ, oss$job_paged_literal] array [1 .. 1] of
          clt$command_table_entry := [
            {} ['GO                             ', clc$nominal_entry, clc$advertised_entry, 1,
            clc$automatically_log, clc$linked_call, ^end_operator_intervention]];

?? POP ??

    VAR
      ignore_status: ost$status,
      utility_attributes: array [1 .. 4] of clt$utility_attribute;

    status.normal := TRUE;
    clp$put_job_output (' Processing operator commands......', ignore_status);
    clp$put_job_output (' Enter GO to continue initialization', ignore_status);

    utility_attributes [1].key := clc$utility_command_search_mode;
    utility_attributes [1].command_search_mode := clc$global_command_search;
    utility_attributes [2].key := clc$utility_command_table;
    utility_attributes [2].command_table := op_intervention_cmnds;
    utility_attributes [3].key := clc$utility_termination_command;
    utility_attributes [3].termination_command := 'go';
    utility_attributes [4].key := clc$utility_prompt;
    utility_attributes [4].prompt.value := operator_intervention_prompt;
    utility_attributes [4].prompt.size := operator_interventn_prompt_size;
    clp$begin_utility (operator_intervention_utility, utility_attributes, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
    clp$include_file (':$LOCAL.COMMAND.1', operator_intervention_prompt, operator_intervention_utility,
          status);
    clp$end_utility (operator_intervention_utility, ignore_status);

  PROCEND clp$operator_intervention;
?? TITLE := 'end_operator_intervention', EJECT ??

  PROCEDURE end_operator_intervention
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (osm$oi_endoi) go, end_operator_intervention

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
    recend := [
    [1,
    [89, 7, 10, 14, 47, 22, 935],
    clc$command, 0, 0, 0, 0, 0, 0, 0, 'OSM$OI_ENDOI']];

?? FMT (FORMAT := ON) ??
?? POP ??

    clp$evaluate_parameters (parameter_list, #SEQ (pdt), NIL, NIL, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    clp$end_include (operator_intervention_utility, status);

  PROCEND end_operator_intervention;
?? TITLE := 'clp$_define_initial_application', EJECT ??

  PROCEDURE [XDCL] clp$_define_initial_application
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (osm$defia) define_initial_application, defia (
{   application, a: string = $required
{   logout_upon_termination, lut: (BY_NAME) boolean = no
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 5] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
        default_value: string (2),
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [89, 7, 10, 14, 17, 53, 942],
    clc$command, 5, 3, 1, 0, 0, 0, 3, 'OSM$DEFIA'], [
    ['A                              ',clc$abbreviation_entry, 1],
    ['APPLICATION                    ',clc$nominal_entry, 1],
    ['LOGOUT_UPON_TERMINATION        ',clc$nominal_entry, 2],
    ['LUT                            ',clc$abbreviation_entry, 2],
    ['STATUS                         ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 8, clc$required_parameter, 0
  , 0],
{ PARAMETER 2
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_default_parameter, 0, 2],
{ PARAMETER 3
    [5, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$string_type], [0, clc$max_string_size, FALSE]],
{ PARAMETER 2
    [[1, 0, clc$boolean_type],
    'no'],
{ PARAMETER 3
    [[1, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$application = 1,
      p$logout_upon_termination = 2,
      p$status = 3;

    VAR
      pvt: array [1 .. 3] of clt$parameter_value;


    clp$evaluate_parameters (parameter_list, #SEQ (pdt), NIL, ^pvt, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    clp$define_initial_application (pvt [p$application].value^.string_value,
         pvt [p$logout_upon_termination].value^.boolean_value.value, status);

  PROCEND clp$_define_initial_application;
*IFEND

MODEND clm$interpret_commands;
