?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter: Put Line Command' ??
MODULE clm$put_line_command;

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

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$parameter_list
*copyc ost$status
?? POP ??
*copyc amp$put_next
*copyc amv$nil_file_identifier
*copyc clp$evaluate_parameters
*copyc fsp$close_file
*copyc fsp$open_file
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
?? TITLE := 'clp$_put_line', EJECT ??

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

{ PROCEDURE (osm$putl) put_line, put_lines, putl (
{   lines, line, l: any of list 0..clc$max_list_size of string
{                          array of string
{                   anyend = $required
{   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 .. 6] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$union_type_qualifier,
        type_size_1: clt$type_specification_size,
        element_type_spec_1: record
          header: clt$type_specification_header,
          qualifier: clt$list_type_qualifier_v2,
          element_type_spec: record
            header: clt$type_specification_header,
            qualifier: clt$string_type_qualifier,
          recend,
        recend,
        type_size_2: clt$type_specification_size,
        element_type_spec_2: record
          header: clt$type_specification_header,
          qualifier: clt$array_type_qualifier,
          element_type_spec: record
            header: clt$type_specification_header,
            qualifier: clt$string_type_qualifier,
          recend,
        recend,
      recend,
      type2: record
        header: clt$type_specification_header,
        default_value: string (7),
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [94, 2, 7, 5, 12, 24, 617],
    clc$command, 6, 3, 1, 0, 0, 0, 3, 'OSM$PUTL'], [
    ['L                              ',clc$abbreviation_entry, 1],
    ['LINE                           ',clc$alias_entry, 1],
    ['LINES                          ',clc$nominal_entry, 1],
    ['O                              ',clc$abbreviation_entry, 2],
    ['OUTPUT                         ',clc$nominal_entry, 2],
    ['STATUS                         ',clc$nominal_entry, 3]],
    [
{ PARAMETER 1
    [3, 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, 76, clc$required_parameter, 0, 0],
{ PARAMETER 2
    [5, 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 3
    [6, 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$union_type], [[clc$array_type,
    clc$list_type],
    FALSE, 2],
    24, [[1, 0, clc$list_type], [8, 0, clc$max_list_size, 0, FALSE, FALSE],
        [[1, 0, clc$string_type], [0, clc$max_string_size, FALSE]]
      ],
    32, [[1, 0, clc$array_type], [8, FALSE],
        [[1, 0, clc$string_type], [0, clc$max_string_size, FALSE]]
      ]
    ],
{ PARAMETER 2
    [[1, 0, clc$file_type],
    '$output'],
{ PARAMETER 3
    [[1, 0, clc$status_type]]];

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

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

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

?? 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);


      fsp$close_file (file_id, handler_status);
      handler_status.normal := TRUE;

    PROCEND abort_handler;
?? OLDTITLE, EJECT ??

    CONST
      list_unknown = 'LIST_UNKNOWN                   ';

    VAR
      attachment_options: array [1 .. 3] of fst$attachment_option,
      current_line: ^clt$data_value,
      default_creation_attributes: array [1 .. 2] of fst$file_cycle_attribute,
      file_id: amt$file_identifier,
      ignore_byte_address: amt$file_byte_address,
      ignore_status: ^ost$status,
      validation_attributes: array [1 .. 9] of fst$file_cycle_attribute;


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

    attachment_options [1].selector := fsc$access_and_share_modes;
    attachment_options [1].access_modes.selector := fsc$specific_access_modes;
    attachment_options [1].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
    attachment_options [1].share_modes.selector := fsc$specific_share_modes;
    attachment_options [1].share_modes.value := $fst$file_access_options [];
    attachment_options [2].selector := fsc$access_and_share_modes;
    attachment_options [2].access_modes.selector := fsc$specific_access_modes;
    attachment_options [2].access_modes.value := $fst$file_access_options [fsc$append];
    attachment_options [2].share_modes.selector := fsc$specific_share_modes;
    attachment_options [2].share_modes.value := $fst$file_access_options [];
    attachment_options [3].selector := fsc$open_share_modes;
    attachment_options [3].open_share_modes := -$fst$file_access_options [];

    default_creation_attributes [1].selector := fsc$file_contents_and_processor;
    default_creation_attributes [1].file_contents := fsc$legible_data;
    default_creation_attributes [1].file_processor := osc$null_name;
    default_creation_attributes [2].selector := fsc$page_format;
    default_creation_attributes [2].page_format := amc$untitled_form;

    validation_attributes [1].selector := fsc$file_contents_and_processor;
    validation_attributes [1].file_contents := fsc$list;
    validation_attributes [1].file_processor := osc$null_name;
    validation_attributes [2].selector := fsc$file_contents_and_processor;
    validation_attributes [2].file_contents := fsc$legible_data;
    validation_attributes [2].file_processor := osc$null_name;
    validation_attributes [3].selector := fsc$file_contents_and_processor;
    validation_attributes [3].file_contents := fsc$legible_scl_procedure;
    validation_attributes [3].file_processor := osc$null_name;
    validation_attributes [4].selector := fsc$file_contents_and_processor;
    validation_attributes [4].file_contents := fsc$legible_scl_include;
    validation_attributes [4].file_processor := osc$null_name;
    validation_attributes [5].selector := fsc$file_contents_and_processor;
    validation_attributes [5].file_contents := fsc$legible_scl_job;
    validation_attributes [5].file_processor := osc$null_name;
    validation_attributes [6].selector := fsc$file_contents_and_processor;
    validation_attributes [6].file_contents := list_unknown;
    validation_attributes [6].file_processor := osc$null_name;
    validation_attributes [7].selector := fsc$file_contents_and_processor;
    validation_attributes [7].file_contents := amc$legible;
    validation_attributes [7].file_processor := osc$null_name;
    validation_attributes [8].selector := fsc$file_contents_and_processor;
    validation_attributes [8].file_contents := fsc$data;
    validation_attributes [8].file_processor := osc$null_name;
    validation_attributes [9].selector := fsc$file_contents_and_processor;
    validation_attributes [9].file_contents := fsc$unknown_contents;
    validation_attributes [9].file_processor := osc$null_name;

    file_id := amv$nil_file_identifier;
    #SPOIL (file_id);
    osp$establish_block_exit_hndlr (^abort_handler);

    fsp$open_file (pvt [p$output].value^.file_value^, amc$record, ^attachment_options,
          ^default_creation_attributes, NIL, ^validation_attributes, NIL, file_id, status);
    IF NOT status.normal THEN
      osp$disestablish_cond_handler;
      RETURN;
    IFEND;

    current_line := pvt [p$lines].value;

  /put/
    WHILE (current_line <> NIL) AND (current_line^.element_value <> NIL) DO
      amp$put_next (file_id, current_line^.element_value^.string_value,
            STRLENGTH (current_line^.element_value^.string_value^), ignore_byte_address, status);
      IF NOT status.normal THEN
        EXIT /put/;
      IFEND;
      current_line := current_line^.link;
    WHILEND /put/;

    IF status.normal THEN
      fsp$close_file (file_id, status);
    ELSE
      PUSH ignore_status;
      fsp$close_file (file_id, ignore_status^);
    IFEND;

    osp$disestablish_cond_handler;

  PROCEND clp$_put_line;

MODEND clm$put_line_command;
