?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Program Management : Display Active Tasks Command' ??
MODULE pmm$display_active_tasks;

{
{ PURPOSE:
{   This module contains the display task status command.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$parameter_list
*copyc ost$status
?? POP ??
*copyc clp$evaluate_parameters
*copyc clp$convert_integer_to_string
*copyc clp$convert_integer_to_rjstring
*copyc clp$open_display_reference
*copyc clp$close_display
*copyc clp$put_partial_display
*copyc clv$nil_display_control
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*copyc pmp$acquire_raw_task_statistics

?? TITLE := 'pmp$_display_active_tasks', EJECT ??

  PROCEDURE [XDCL] pmp$_display_active_tasks
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (osm$disat) display_active_tasks, disat (
{   output, o: file = $output
{   status)

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        default_value: string (7),
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [88, 12, 12, 14, 17, 44, 227],
    clc$command, 3, 2, 0, 0, 0, 0, 2, 'OSM$DISAT'], [
    ['O                              ',clc$abbreviation_entry, 1],
    ['OUTPUT                         ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ 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, 3,
  clc$optional_default_parameter, 0, 7],
{ PARAMETER 2
    [3, 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$file_type],
    '$output'],
{ PARAMETER 2
    [[1, 0, clc$status_type]]];

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

    CONST
      p$output = 1,
      p$status = 2;

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


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

    pmp$display_active_tasks (pvt [p$output].value^.file_value^, status);

  PROCEND pmp$_display_active_tasks;
?? TITLE := 'pmp$display_active_tasks', EJECT ??
*copyc pmh$display_active_tasks

  PROCEDURE [XDCL] pmp$display_active_tasks
    (    output: fst$file_reference;
     VAR status: ost$status);

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

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

      clp$close_display (display_control, ignore_status);

    PROCEND abort_handler;
?? TITLE := 'put_partial_display', EJECT ??

    PROCEDURE [INLINE] put_partial_display
      (    str: string ( * );
           trim_option: clt$trim_display_text_option;
           term_option: amt$term_option);

      clp$put_partial_display (display_control, str, trim_option, term_option, status);
      IF NOT status.normal THEN
        EXIT pmp$display_active_tasks;
      IFEND;

    PROCEND put_partial_display;
?? OLDTITLE, EJECT ??

    VAR
      active_task_count: 0 .. pmc$max_task_id,
      active_task_statistics: array [1 .. 100] of pmt$raw_task_statistics,
      default_ring_attributes: amt$ring_attributes,
      display_control: clt$display_control,
      ignore_status: ost$status,
      local_status: ost$status,
      milliseconds: integer,
      statistics: string (103),
      strng: ost$string,
      task: 1 .. pmc$max_task_id,
      task_name: ost$name,
      task_count: ost$string;


    status.normal := TRUE;
    display_control := clv$nil_display_control;
    #SPOIL (display_control);
    osp$establish_block_exit_hndlr (^abort_handler);

  /display_active_tasks/
    BEGIN

      default_ring_attributes.r1 := #RING (^default_ring_attributes);
      default_ring_attributes.r2 := #RING (^default_ring_attributes);
      default_ring_attributes.r3 := #RING (^default_ring_attributes);

      clp$open_display_reference (output, NIL, fsc$list, default_ring_attributes, display_control, status);
      IF NOT status.normal THEN
        EXIT /display_active_tasks/;
      IFEND;

      pmp$acquire_raw_task_statistics (active_task_count, active_task_statistics);

      put_partial_display ('ACTIVE TASKS = ', clc$no_trim, amc$start);
      clp$convert_integer_to_string (active_task_count, 10, FALSE, task_count, ignore_status);
      put_partial_display (task_count.value (1, task_count.size), clc$trim, amc$terminate);

      IF (active_task_count > UPPERBOUND (active_task_statistics)) THEN
        active_task_count := UPPERBOUND (active_task_statistics);
      IFEND;

      FOR task := 1 TO active_task_count DO
        statistics (1, 31) := active_task_statistics [task].task_name;

        statistics (32, * ) := ' job time =      0.000  monitor time =      0.000  page faults = ******';
        milliseconds := active_task_statistics [task].cp_time.task_time DIV 1000;
        clp$convert_integer_to_rjstring (milliseconds DIV 1000, 10, FALSE, ' ', statistics (43, 7),
              ignore_status);
        clp$convert_integer_to_rjstring (milliseconds MOD 1000, 10, FALSE, '0', statistics (51, 3),
              ignore_status);
        milliseconds := active_task_statistics [task].cp_time.monitor_time DIV 1000;
        clp$convert_integer_to_rjstring (milliseconds DIV 1000, 10, FALSE, ' ', statistics (70, 7),
              ignore_status);
        clp$convert_integer_to_rjstring (milliseconds MOD 1000, 10, FALSE, '0', statistics (78, 3),
              ignore_status);
        clp$convert_integer_to_string (active_task_statistics [task].page_fault_count, 10, FALSE, strng,
              ignore_status);
        IF ignore_status.normal THEN
          statistics (97, 6) := strng.value (1, strng.size);
        IFEND;

        put_partial_display (statistics, clc$no_trim, amc$terminate);
      FOREND;
    END /display_active_tasks/;

    clp$close_display (display_control, local_status);
    IF status.normal AND NOT local_status.normal THEN
      status := local_status;
    IFEND;

    osp$disestablish_cond_handler;

  PROCEND pmp$display_active_tasks;

MODEND pmm$display_active_tasks;
