?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter: Display Working Catalog' ??
MODULE clm$display_working_catalog;

{
{ PURPOSE:
{   This module contains the processor for the display_working_catalog command.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$parameter_list
*copyc ost$status
?? POP ??
*copyc bap$get_path_string
*copyc clp$build_path_subtitle
*copyc clp$build_standard_title
*copyc clp$close_display
*copyc clp$convert_integer_to_string
*copyc clp$evaluate_parameters
*copyc clp$find_working_catalog
*copyc clp$horizontal_tab_display
*copyc clp$new_display_line
*copyc clp$open_display_reference
*copyc clp$put_display
*copyc clp$put_partial_display
*copyc clp$reset_for_next_display_page
*copyc osp$establish_block_exit_hndlr
*copyc osp$disestablish_cond_handler
*copyc clv$nil_display_control

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

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

{ PROCEDURE (osm$diswc) display_working_catalog, diswc (
{   output, o: file = $output
{   status)

?? PUSH (LISTEXT := ON) ??

    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, [87, 10, 23, 12, 42, 58, 957], clc$command, 3, 2, 0, 0, 0, 0, 2, 'OSM$DISWC'],
            [['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]]];

?? POP ??

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

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

*copy clv$display_variables
?? NEWTITLE := 'abort_handler', EJECT ??

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


      IF output_open THEN
        clp$close_display (display_control, handler_status);
        output_open := FALSE;
      IFEND;
      handler_status.normal := TRUE;

    PROCEND abort_handler;
*copy clp$new_page_procedure
?? TITLE := 'put_subtitle', EJECT ??

    PROCEDURE [INLINE] put_subtitle
      (VAR display_control: clt$display_control;
       VAR status: ost$status);


      { The display_working_catalog command has no subtitles,
      { this is merely a dummy routine used to keep
      { the module consistent with those that do produce subtitles.

    PROCEND put_subtitle;
?? TITLE := 'put_path_chunks', EJECT ??

    PROCEDURE put_path_chunks
      (    path_name: string ( * );
           display_chunks: clt$path_display_chunks;
           chunk_count: 0 .. fsc$max_path_elements;
           column: amt$page_width;
       VAR status: ost$status);

      VAR
        i: 0 .. fsc$max_path_elements,
        term_option: amt$term_option,
        terminate_string: string (2);

      terminate_string := '..';
      term_option := amc$terminate;
      FOR i := 1 TO chunk_count DO
        clp$horizontal_tab_display (display_control, column, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        IF i = chunk_count THEN
          terminate_string := '  ';
          term_option := amc$terminate;
        IFEND;
        clp$put_partial_display (display_control, path_name
              (display_chunks [i].position, display_chunks [i].length), clc$trim, amc$continue, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        clp$put_partial_display (display_control, terminate_string, clc$trim, term_option, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
      FOREND;

    PROCEND put_path_chunks;
?? OLDTITLE, EJECT ??

    VAR
      chunk_count: 0 .. fsc$max_path_elements,
      default_ring_attributes: amt$ring_attributes,
      display_chunks: clt$path_display_chunks,
      display_control: clt$display_control,
      local_status: ost$status,
      output_open: boolean,
      path: fst$path,
      path_size: fst$path_size,
      working_catalog: ^^clt$working_catalog;

    status.normal := TRUE;

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

    display_control := clv$nil_display_control;
    #SPOIL (display_control);
    default_ring_attributes.r1 := #RING (^default_ring_attributes);
    default_ring_attributes.r2 := #RING (^default_ring_attributes);
    default_ring_attributes.r3 := #RING (^default_ring_attributes);
    output_open := FALSE;

    osp$establish_block_exit_hndlr (^abort_handler);

    clp$open_display_reference (pvt [p$output].value^.file_value^, ^clp$new_page_procedure, fsc$list,
          default_ring_attributes, display_control, status);
    IF NOT status.normal THEN
      osp$disestablish_cond_handler;
      RETURN;
    IFEND;
    output_open := TRUE;
    clv$titles_built := FALSE;
    clv$command_name := 'display_working_catalog';

    clp$find_working_catalog (working_catalog);
    IF working_catalog^ <> NIL THEN
      bap$get_path_string (working_catalog^^.evaluated_file_reference.path_handle_info.path_handle, path,
            path_size, status);
      IF status.normal THEN
        clp$build_path_subtitle (path, path_size, display_control.page_width, chunk_count, display_chunks);
        put_path_chunks (path, display_chunks, chunk_count, 1, status);
      IFEND;
    IFEND;

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

    osp$disestablish_cond_handler;

  PROCEND clp$_display_working_catalog;

MODEND clm$display_working_catalog;

