MODULE dsm$display_resource_table;
?? RIGHT := 110 ??

{ Module purpose.
{Initially, we simply output this thing to where we are. Lateron, we want to be able to
{display the table to a file or an open console window after DS is completed.
{
{We will have 2 entry points:
{  dsp$display_resource_table_item : displays one entry of the table. This request can be
{                                    called from TESRR
{  dsp$display_resource_table      : displays the complete table. This request can be
{                                    called from TESRR and VED

?? NEWTITLE := 'Global Declarations Referenced By This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc dst$channel_protocol_type
*copyc dst$iou_number
*copyc dst$physical_resource_number
*copyc ost$halfword
*copyc ost$status
?? POP ??
*copyc fip#addl_initialize
*copyc fip#addl_string

*copyc clp$convert_integer_to_rjstring
*copyc clp$convert_integer_to_string
*copyc dpp$put_next_line
*copyc dsp$close_ssr
*copyc dsp$get_data_from_ssr
*copyc dsp$open_ssr
*copyc dsp$retrieve_iou_information
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
?? OLDTITLE ??
?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??

  TYPE
    t$channel_protocol_types = set of dst$channel_protocol_type,

    t$iou_resource_table_value = 0 .. 0ff(16),

    t$iou_resource_table_entry = record
      channel: t$iou_resource_table_value,
      pp: t$iou_resource_table_value,
    recend,
    t$iou_resource_table = array [0 .. * ] of array [dst$channel_protocol_type] of
          array [dst$physical_resource_number] of t$iou_resource_table_entry;

?? OLDTITLE ??
?? NEWTITLE := 'P$ADDL_INTEGER', EJECT ??

  PROCEDURE [INLINE] p$addl_integer
    (VAR line: ost$string;
         integer_value: integer;
         radix: 2 .. 16;
         include_radix: boolean;
     VAR status: ost$status);

    VAR
      int_string: ost$string;

    status.normal := TRUE;
    clp$convert_integer_to_string (integer_value, radix, include_radix, int_string, status);
    IF status.normal THEN
      fip#addl_string (line, int_string.value (1, int_string.size));
    IFEND;

  PROCEND p$addl_integer;
?? OLDTITLE ??
?? NEWTITLE := 'P$ADDL_RJINTEGER', EJECT ??

  PROCEDURE [INLINE] p$addl_rjinteger
    (VAR line: ost$string;
         integer_value: integer;
         radix: 2 .. 16;
         include_radix: boolean;
         integer_size: 1 .. osc$max_string_size;
         fill_character: char;
     VAR status: ost$status);

    VAR
      string_p: ^string ( * );

    status.normal := TRUE;
    PUSH string_p: [integer_size];
    clp$convert_integer_to_rjstring (integer_value, radix, include_radix, fill_character, string_p^, status);
    IF status.normal THEN
      fip#addl_string (line, string_p^);
    IFEND;

  PROCEND p$addl_rjinteger;
?? OLDTITLE ??
?? NEWTITLE := 'P$FORMAT_RESOURCE_TABLE_ENTRY', EJECT ??

  PROCEDURE p$format_resource_table_entry
    (    iou: dst$number_of_ious;
         resource: dst$physical_resource_number;
         selected_protocol_types: t$channel_protocol_types;
         table_p: ^t$iou_resource_table;
     VAR str: ost$string;
     VAR status: ost$status);

    VAR
      cio_entry_p: ^t$iou_resource_table_entry,
      nio_entry_p: ^t$iou_resource_table_entry;

    fip#addl_initialize (str, 'IOU=');
    p$addl_integer (str, iou, 10, FALSE, status);
    fip#addl_string (str, ', CHANNEL=');
    p$addl_rjinteger (str, resource, 8, TRUE, 5, ' ', status);

    IF dsc$cpt_cio IN selected_protocol_types THEN
      cio_entry_p := ^table_p^ [iou] [dsc$cpt_cio] [resource];
      fip#addl_string (str, ', CIO: CHANNEL=');
      p$addl_rjinteger (str, cio_entry_p^.channel, 16, FALSE, 2, '0', status);
      fip#addl_string (str, ', PP=');
      p$addl_rjinteger (str, cio_entry_p^.pp, 16, FALSE, 2, '0', status);
    IFEND;

    IF dsc$cpt_nio IN selected_protocol_types THEN
      nio_entry_p := ^table_p^ [iou] [dsc$cpt_nio] [resource];
      fip#addl_string (str, ', NIO: CHANNEL=');
      p$addl_rjinteger (str, nio_entry_p^.channel, 16, FALSE, 2, '0', status);
      fip#addl_string (str, ', PP=');
      p$addl_rjinteger (str, nio_entry_p^.pp, 16, FALSE, 2, '0', status);
    IFEND;

  PROCEND p$format_resource_table_entry;
?? OLDTITLE ??
?? NEWTITLE := '[xdcl, #gate] DSP$FORMAT_RESOURCE_TABLE', EJECT ??

  PROCEDURE [XDCL, #GATE] dsp$format_resource_table
    (VAR display_seq: ^SEQ ( * );
     VAR status: ost$status);

    TYPE
      t$count = 0 .. 0ffff(16),
      t$line_size = 0 .. 0ff(16),
      t$line = string ( * <= 0ff(16));

    VAR
      count_p: ^t$count,
      iou: dst$number_of_ious,
      iou_information_table: dst$iou_information_table,
      iou_resource_table_p: ^t$iou_resource_table,
      iou_resource_table_seq_p: ^SEQ ( * ),
      line_p: ^t$line,
      line_size_p: ^t$line_size,
      number_of_ious: dst$number_of_ious,
      resource: dst$physical_resource_number,
      ssr_segment_number: ost$segment,
      str: ost$string;

    status.normal := TRUE;

{ Add the SSR to the caller's segment table.
    dsp$open_ssr (ssr_segment_number, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

{ Get a pointer to the resource assignment area in the SSR.
    dsp$retrieve_iou_information (number_of_ious, iou_information_table);
    PUSH iou_resource_table_p: [0 .. (number_of_ious - 1)];
    iou_resource_table_seq_p := #SEQ (iou_resource_table_p^);
    dsp$get_data_from_ssr (dsc$ssr_resource_assignment, iou_resource_table_seq_p);
    dsp$close_ssr (ssr_segment_number, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    RESET display_seq;
    NEXT count_p IN display_seq;
    IF count_p = NIL THEN
      RETURN; {----->
    IFEND;
    count_p^ := 0;

    resource := 0;
    FOR iou := LOWERBOUND (iou_resource_table_p^) TO UPPERBOUND (iou_resource_table_p^) DO
      FOR resource := LOWERVALUE (resource) TO UPPERVALUE (resource) DO
        p$format_resource_table_entry (iou, resource, -$t$channel_protocol_types [], iou_resource_table_p,
              str, status);
        IF NOT status.normal THEN
          RETURN; {----->
        IFEND;

        NEXT line_size_p IN display_seq;
        NEXT line_p: [str.size] IN display_seq;
        IF line_p = NIL THEN
          RETURN; {----->
        IFEND;

        line_size_p^ := str.size;
        line_p^ := str.value (1, str.size);
        count_p^ := count_p^ +1;
      FOREND;
    FOREND;

  PROCEND dsp$format_resource_table;
?? OLDTITLE ??
?? NEWTITLE := '[xdcl] DSP$DISPLAY_RESOURCE_TABLE_ITEM', EJECT ??

  PROCEDURE [XDCL] dsp$display_resource_table_item
    (    iou: dst$number_of_ious;
         resource: dst$physical_resource_number;
         selected_protocol_types: t$channel_protocol_types;
         wid: dpt$window_id;
     VAR status: ost$status);

    VAR
      iou_information_table: dst$iou_information_table,
      iou_resource_table_p: ^t$iou_resource_table,
      iou_resource_table_seq_p: ^SEQ ( * ),
      number_of_ious: dst$number_of_ious,
      ssr_segment_number: ost$segment,
      str: ost$string;

    status.normal := TRUE;

{ Add the SSR to the caller's segment table.
    dsp$open_ssr (ssr_segment_number, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

{ Get a pointer to the resource assignment area in the SSR.
    dsp$retrieve_iou_information (number_of_ious, iou_information_table);
    PUSH iou_resource_table_p: [0 .. (number_of_ious - 1)];
    iou_resource_table_seq_p := #SEQ (iou_resource_table_p^);
    dsp$get_data_from_ssr (dsc$ssr_resource_assignment, iou_resource_table_seq_p);
    dsp$close_ssr (ssr_segment_number, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    p$format_resource_table_entry (iou, resource, selected_protocol_types, iou_resource_table_p, str, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    dpp$put_next_line (wid, str.value (1, str.size), status);

  PROCEND dsp$display_resource_table_item;
?? OLDTITLE ??
MODEND dsm$display_resource_table;
