?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Interactive Facility: Pause Utility' ??
MODULE iim$pause_utility;

{
{ PURPOSE:
{   This module contains the "pause utility" which is invoked as part
{   of the default processing for "pause break" and "terminal reconnect"
{   conditions.
{   It provides commands for resuming or terminating the current activity,
{   as well as allowing access to other SCL commands.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$parameter_list
*copyc ife$error_codes
*copyc oss$job_paged_literal
*copyc ost$status
?? POP ??
*copyc clp$begin_utility
*copyc clp$evaluate_parameters
*copyc clp$include_file
*copyc clp$put_job_output
*copyc ifv$pause_utility_count
*copyc iip$report_status_error
*copyc osp$establish_condition_handler
*copyc osp$set_status_condition
*copyc pmp$continue_to_cause
*copyc pmp$exit
?? EJECT ??

  CONST
    pause_name = 'Pause_Utility                  ';

{ table iiv$pause_commands t=command s=local sn=oss$job_paged_literal
{ command (resume_command                 ,resc) ifp$_resume_command
{ command (terminate_command              ,terc) ifp$_terminate_command
{ tablend

?? PUSH (LISTEXT := ON) ??

  VAR
    iiv$pause_commands: [STATIC, READ, oss$job_paged_literal] ^clt$command_table :=
          ^iiv$pause_commands_entries,

    iiv$pause_commands_entries: [STATIC, READ, oss$job_paged_literal] array [1 .. 4] of
          clt$command_table_entry := [
          {} ['RESC                           ', clc$abbreviation_entry, clc$normal_usage_entry, 1,
          clc$automatically_log, clc$linked_call, ^ifp$_resume_command],
          {} ['RESUME_COMMAND                 ', clc$nominal_entry, clc$normal_usage_entry, 1,
          clc$automatically_log, clc$linked_call, ^ifp$_resume_command],
          {} ['TERC                           ', clc$abbreviation_entry, clc$normal_usage_entry, 2,
          clc$automatically_log, clc$linked_call, ^ifp$_terminate_command],
          {} ['TERMINATE_COMMAND              ', clc$nominal_entry, clc$normal_usage_entry, 2,
          clc$automatically_log, clc$linked_call, ^ifp$_terminate_command]];

?? POP ??

?? TITLE := 'iip$pause_utility', EJECT ??

  PROCEDURE [XDCL, #GATE] iip$pause_utility
    (    ignore_program_parameters: pmt$program_parameters;
     VAR status: ost$status);

    VAR
      suspended_message: string (17),
      suspended_message_size: integer,
      utility_attributes: array [1 .. 4] of clt$utility_attribute;

?? NEWTITLE := 'condition_handler', EJECT ??

    PROCEDURE condition_handler
      (    condition: pmt$condition;
           condition_info: ^pmt$condition_information;
           stack_frame_save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);


      CASE condition.selector OF

      = ifc$interactive_condition =
        IF condition.interactive_condition = ifc$pause_break THEN
          RETURN {ignore pause breaks while in the "pause utility"} ;
        IFEND;

      = pmc$block_exit_processing =
        RETURN;

      ELSE
        ;
      CASEND;

      pmp$continue_to_cause (pmc$execute_standard_procedure, handler_status);

    PROCEND condition_handler;
?? TITLE := 'error', EJECT ??

    PROCEDURE [INLINE] error;


      iip$report_status_error (status, 'error in pause utility');
      pmp$exit (status);

    PROCEND error;
?? TITLE := 'interactive_include_processor', EJECT ??

    PROCEDURE interactive_include_processor
      (    interaction_style: ost$interaction_style;
       VAR status: ost$status);


{ Do nothing so the utility always runs in line mode.

      status.normal := TRUE;

    PROCEND interactive_include_processor;
?? OLDTITLE, EJECT ??

    STRINGREP (suspended_message, suspended_message_size, ' *Suspended - ', ifv$pause_utility_count, '*');
    clp$put_job_output (suspended_message (1, suspended_message_size), status);
    IF NOT status.normal THEN
      error;
    IFEND;

    utility_attributes [1].key := clc$utility_command_table;
    utility_attributes [1].command_table := iiv$pause_commands;
    utility_attributes [2].key := clc$utility_termination_command;
    utility_attributes [2].termination_command := 'RESUME_COMMAND';
    utility_attributes [3].key := clc$utility_interactive_include;
    utility_attributes [3].interactive_include_processor.call_method := clc$linked_call;
    utility_attributes [3].interactive_include_processor.proc := ^interactive_include_processor;
    utility_attributes [4].key := clc$utility_prompt;
    utility_attributes [4].prompt.size := 1;
    utility_attributes [4].prompt.value := 'p';
    clp$begin_utility (pause_name, utility_attributes, status);
    IF NOT status.normal THEN
      error;
    IFEND;

    osp$establish_condition_handler (^condition_handler, FALSE);

    clp$include_file (':$LOCAL.COMMAND.1', 'p', pause_name, status);

    pmp$exit (status);

  PROCEND iip$pause_utility;
?? TITLE := 'ifp$_resume_command', EJECT ??

  PROCEDURE ifp$_resume_command
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (osm$p_resc) resume_command, resc (
{   status)

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 1] of clt$pdt_parameter_name,
      parameters: array [1 .. 1] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [90, 3, 1, 17, 45, 17, 769],
    clc$command, 1, 1, 0, 0, 0, 0, 1, 'OSM$P_RESC'], [
    ['STATUS                         ',clc$nominal_entry, 1]],
    [
{ PARAMETER 1
    [1, 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$status_type]]];

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

    CONST
      p$status = 1;

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


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

    pmp$exit (status);

  PROCEND ifp$_resume_command;
?? TITLE := 'ifp$_terminate_command', EJECT ??

  PROCEDURE ifp$_terminate_command
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (osm$p_terc) terminate_command, terc (
{   status)

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 1] of clt$pdt_parameter_name,
      parameters: array [1 .. 1] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [90, 3, 1, 17, 44, 11, 274],
    clc$command, 1, 1, 0, 0, 0, 0, 1, 'OSM$P_TERC'], [
    ['STATUS                         ',clc$nominal_entry, 1]],
    [
{ PARAMETER 1
    [1, 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$status_type]]];

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

    CONST
      p$status = 1;

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


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

    osp$set_status_condition (ife$terminate_break_received, status);
    pmp$exit (status);

  PROCEND ifp$_terminate_command;

MODEND iim$pause_utility;
