?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Configuration Management : VED PA Display' ??
MODULE cmm$ved_display;

{ PURPOSE:
{   This Module allows the use of the VED display command to display PP assignment in NOS/VE.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
*copyc clp$close_display
*copyc clp$convert_integer_to_string
*copyc clp$put_display
*copyc dpp$put_next_line
*copyc dpp$clear_window
*copyc ofp$open_display
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
?? EJECT ??
*copyc cmv$logical_pp_table_p
*copyc cmv$sci_dft_pp
?? OLDTITLE ??
?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??

  TYPE
    t$display_line = RECORD
      CASE boolean OF
      = TRUE =
        line: string (80),
      = FALSE =
        iou: string (3),
        space_1: string (2),
        pp: string (5),
        space_2: string (2),
        state: string (5),
        space_3: string (2),
        ssn: string (31),
        space_4: string (2),
        iou_program: string (11),
        space_5: string (2),
        line_end: t$end_of_display_line,
      CASEND,
    RECEND,

    t$end_of_display_line = RECORD
      CASE boolean OF
      = TRUE =
        data: string (15),
      = FALSE =
        channel: string (6),
        space_6: string (1),
        message: string (8),
      CASEND,
    RECEND;
?? OLDTITLE ??
?? NEWTITLE := 'put_display_line ', EJECT ??

{ PURPOSE:
{   This procedure builds a line containing the PP information and places the line on the display.

  PROCEDURE put_display_line
     (   pp_index: iot$pp_number;
         window_id: dpt$window_id;
     VAR display_control: clt$display_control;
     VAR status: ost$status);

    VAR
      active_unit: boolean,
      channel_size: 0 .. 0ff(16),
      display_line: t$display_line,
      ignore_status: ost$status,
      index: iot$logical_unit,
      integer_string: ost$string,
      ppit_p: ^iot$pp_interface_table;

    display_line.line := ' ';
    clp$convert_integer_to_string (cmv$logical_pp_table_p^ [pp_index].pp_info.physical_pp.iou_number,
          8, FALSE, integer_string, ignore_status);
    display_line.iou := integer_string.value (1, integer_string.size);

    clp$convert_integer_to_string (cmv$logical_pp_table_p^ [pp_index].pp_info.physical_pp.number,
          8, FALSE, integer_string, ignore_status);
    IF cmv$logical_pp_table_p^ [pp_index].pp_info.physical_pp.channel_protocol = dsc$cpt_cio THEN
      display_line.pp := 'CPP';
      display_line.pp (4, 2) := integer_string.value (1, integer_string.size);
    ELSE
      display_line.pp := 'PP';
      display_line.pp (3, 2) := integer_string.value (1, integer_string.size);
    IFEND;

    display_line.state := 'ON';
    IF cmv$logical_pp_table_p^ [pp_index].flags.entry_reserved_by_nosve THEN
      display_line.ssn := '$SYSTEM';
    ELSEIF cmv$logical_pp_table_p^ [pp_index].flags.entry_reserved_by_other THEN
      display_line.ssn := cmv$logical_pp_table_p^ [pp_index].task_info.reserved_job_name;
    ELSE
      display_line.ssn := ' ';
    IFEND;
    display_line.iou_program := cmv$logical_pp_table_p^ [pp_index].pp_info.driver_name;

    IF cmv$logical_pp_table_p^ [pp_index].flags.entry_reserved_by_nosve OR
          cmv$logical_pp_table_p^ [pp_index].flags.reservd_by_other_has_ch_present THEN
      channel_size := 1;
      IF cmv$logical_pp_table_p^ [pp_index].pp_info.channel.channel_protocol = dsc$cpt_cio THEN
        display_line.line_end.channel (channel_size, 3) := 'CCH';
        channel_size := channel_size + 3;
      ELSE
        display_line.line_end.channel (channel_size, 2) := 'CH';
        channel_size := channel_size + 2;
      IFEND;
      clp$convert_integer_to_string (cmv$logical_pp_table_p^ [pp_index].pp_info.channel.number,
            8, FALSE, integer_string, ignore_status);
      display_line.line_end.channel (channel_size, integer_string.size) :=
            integer_string.value (1, integer_string.size);
      channel_size := channel_size + integer_string.size;

      IF NOT cmv$logical_pp_table_p^ [pp_index].flags.pp_hung AND
            ((cmv$logical_pp_table_p^ [pp_index].pp_info.pp_type = cmc$lpt_disk_pp_type) OR
            (cmv$logical_pp_table_p^ [pp_index].pp_info.pp_type = cmc$lpt_tape_pp_type)) THEN
        active_unit := FALSE;
        ppit_p := cmv$logical_pp_table_p^ [pp_index].pp_info.pp_interface_table_p;

       /search_for_active_unit/
        FOR index := LOWERBOUND (ppit_p^.unit_descriptors) TO UPPERBOUND (ppit_p^.unit_descriptors) DO
          IF ppit_p^.unit_descriptors [index].unit_interface_table_rma <> 0 THEN
            active_unit := TRUE;
            EXIT /search_for_active_unit/;
          IFEND;
        FOREND /search_for_active_unit/;
        IF NOT active_unit THEN
          display_line.line_end.message := 'Inactive';
        IFEND;
      IFEND;
    IFEND;

    IF cmv$logical_pp_table_p^ [pp_index].flags.pp_hung THEN
      display_line.line_end.message := 'PP Hung';
    IFEND;

    IF window_id = 0 THEN
      clp$put_display (display_control, display_line.line, clc$trim, status);
    ELSE
      dpp$put_next_line (window_id, display_line.line, status);
    IFEND;

  PROCEND put_display_line;
?? OLDTITLE ??
?? NEWTITLE := 'put_standard_pp_line ', EJECT ??

{ PURPOSE:
{   This procedure builds a line containing the PP information for DFT and SCI and places the line on
{   the display.

  PROCEDURE put_standard_pp_line
     (   pp: dst$iou_resource;
         driver_name: dst$driver_name;
         window_id: dpt$window_id;
     VAR display_control: clt$display_control;
     VAR status: ost$status);

    CONST
      c$job_name = '$SYSTEM';

    VAR
      display_line: t$display_line,
      ignore_status: ost$status,
      integer_string: ost$string;

    display_line.line := ' ';
    clp$convert_integer_to_string (pp.iou_number, 8, FALSE, integer_string, ignore_status);
    display_line.iou := integer_string.value (1, integer_string.size);

    clp$convert_integer_to_string (pp.number, 8, FALSE, integer_string, ignore_status);
    IF pp.channel_protocol = dsc$cpt_cio THEN
      display_line.pp := 'CPP';
      display_line.pp (4, 2) := integer_string.value (1, integer_string.size);
    ELSE
      display_line.pp := 'PP';
      display_line.pp (3, 2) := integer_string.value (1, integer_string.size);
    IFEND;

    display_line.state := 'ON';
    display_line.ssn := c$job_name;
    display_line.iou_program := driver_name;

    IF window_id = 0 THEN
      clp$put_display (display_control, display_line.line, clc$trim, status);
    ELSE
      dpp$put_next_line (window_id, display_line.line, status);
    IFEND;

  PROCEND put_standard_pp_line;
?? OLDTITLE ??
?? NEWTITLE := 'cmp$ved_display_pp', EJECT ??

{ PURPOSE:
{   This procedure displays NOS/VE PP assignment to the System Console.

  PROCEDURE [XDCL, #GATE] cmp$ved_display_pp
    (    window_id: dpt$window_id;
         display_name: ost$name;
         file_name: amt$local_file_name;
         initial_call: boolean;
     VAR status: ost$status);

?? NEWTITLE := 'abort_handler', EJECT ??

{ PURPOSE:
{   This procedure provides clean-up processing when a task abort occurs.

    PROCEDURE abort_handler
      (    condition: pmt$condition;
           condition_information: ^pmt$condition_information;
           save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);

      VAR
        ignore_status: ost$status;

      IF window_id = 0 THEN
        clp$close_display (display_control, ignore_status);
      IFEND;

    PROCEND abort_handler;
?? OLDTITLE, EJECT ??

    CONST
      c$dft_driver_name = 'DFT    ',
      c$dfts_driver_name = 'DFT-S  ',
      c$sci_driver_name = 'SCI    ';

    VAR
      display_control: clt$display_control,
      display_line: t$display_line,
      ignore_status: ost$status,
      index: iot$pp_number,
      title: t$display_line;

    status.normal := TRUE;

    IF window_id = 0 THEN
      osp$establish_block_exit_hndlr (^abort_handler);
    IFEND;

    IF initial_call THEN
      title.line := ' ';
      title.iou := 'IOU';
      title.pp := 'PP(8)';
      title.state := 'State';
      title.ssn := 'SSN';
      title.iou_program := 'IOU Program';
      title.line_end.data := 'Channel(8)';
      ofp$open_display (file_name, window_id, dpc$wc_sharing, dpc$wk_table, title.line, display_control,
            status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

  /display_opened/
    BEGIN
      IF window_id = 0 THEN
        display_line.line := ' ';
        clp$put_display (display_control, display_line.line, clc$trim, status);
      ELSE
        dpp$clear_window (window_id, status);
      IFEND;
      IF NOT status.normal THEN
        EXIT /display_opened/;
      IFEND;

      { Display the SCI PP information.

      put_standard_pp_line (cmv$sci_dft_pp.sci_pp, c$sci_driver_name, window_id, display_control, status);
      IF NOT status.normal THEN
        EXIT /display_opened/;
      IFEND;

      { Display the DFT PP information, if such information exists.

      IF cmv$sci_dft_pp.primary_dft_available THEN
        put_standard_pp_line (cmv$sci_dft_pp.primary_dft_pp, c$dft_driver_name, window_id, display_control,
              status);
        IF NOT status.normal THEN
          EXIT /display_opened/;
        IFEND;
      IFEND;

      { Display the secondary DFT PP information, if such information exists.

      IF cmv$sci_dft_pp.secondary_dft_available THEN
        put_standard_pp_line (cmv$sci_dft_pp.secondary_dft_pp, c$dfts_driver_name, window_id, display_control,
              status);
        IF NOT status.normal THEN
          EXIT /display_opened/;
        IFEND;
      IFEND;

      { Display the other PP information.  Search Logical PP Table for the information.

      FOR index := LOWERBOUND (cmv$logical_pp_table_p^) TO UPPERBOUND (cmv$logical_pp_table_p^) DO
        IF cmv$logical_pp_table_p^ [index].flags.configured AND
              cmv$logical_pp_table_p^ [index].flags.resources_acquired THEN
          put_display_line (index, window_id, display_control, status);
          IF NOT status.normal THEN
            EXIT /display_opened/;
          IFEND;
        IFEND;
      FOREND;

    END /display_opened/;

    IF window_id = 0 THEN
      clp$close_display (display_control, ignore_status);
      osp$disestablish_cond_handler;
    IFEND;

  PROCEND cmp$ved_display_pp;
MODEND cmm$ved_display;
