?? RIGHT := 110 ??
?? NEWTITLE := 'MODULE nfm$create_t_record_file' ??
MODULE nfm$create_t_record_file;

{ PURPOSE:    To create a file with a "T" record type and a record delimiting
{              character of US.
{
{ DESCRIPTION: This routine uses accepts the values for the file name, page
{              length and page width of the file to be created. At then attempts
{              to create the file using the values.
{
{ INPUT PARAMETERS: PARAMETER_LIST, created and initialized by the SCL procedure call.
{
{ OUTPUT PARAMETERS: STATUS.
{
{ NOTES: Unlike the standard NOS/VE command CREATE_FILE, this procedure will not
{        attempt to create the next higher cycle of the file name passed to it.
{        If a file cycle already exists, this procedure will return an error.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$work_area
?? POP ??
*copyc amp$get_file_attributes
*copyc clp$evaluate_parameters
*copyc fsp$open_file
*copyc osp$append_status_parameter
*copyc osp$set_status_abnormal

?? OLDTITLE ??
?? NEWTITLE := 'PROCEDURE nfp$create_t_record_file', EJECT ??

  PROCEDURE [XDCL] nfp$create_t_record_file
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE create_t_record_file (
{   file, f: file = $required
{   page_length, pl: integer 1..4398046511103 = $required
{   page_width, pw: integer 1..65535 = $required
{   status)

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 7] of clt$pdt_parameter_name,
      parameters: array [1 .. 4] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        recend,
        type2: record
          header: clt$type_specification_header,
          qualifier: clt$integer_type_qualifier,
          recend,
          type3: record
            header: clt$type_specification_header,
            qualifier: clt$integer_type_qualifier,
            recend,
            type4: record
              header: clt$type_specification_header,
              recend,
    recend := [
    [1,
    [90, 8, 9, 16, 19, 54, 33],
    clc$command, 7, 4, 3, 0, 0, 0, 4, ''], [
    ['F                              ',clc$abbreviation_entry, 1],
    ['FILE                           ',clc$nominal_entry, 1],
    ['PAGE_LENGTH                    ',clc$nominal_entry, 2],
    ['PAGE_WIDTH                     ',clc$nominal_entry, 3],
    ['PL                             ',clc$abbreviation_entry, 2],
    ['PW                             ',clc$abbreviation_entry, 3],
    ['STATUS                         ',clc$nominal_entry, 4]],
    [
{ 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$required_parameter, 0
  , 0],
{ PARAMETER 2
    [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, 20, clc$required_parameter,
  0, 0],
{ PARAMETER 3
    [4, 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, 20, clc$required_parameter,
  0, 0],
{ PARAMETER 4
    [7, 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]],
{ PARAMETER 2
    [[1, 0, clc$integer_type], [1, 4398046511103, 10]],
{ PARAMETER 3
    [[1, 0, clc$integer_type], [1, 65535, 10]],
{ PARAMETER 4
    [[1, 0, clc$status_type]]];

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

    CONST
      p$file = 1,
      p$page_length = 2,
      p$page_width = 3,
      p$status = 4;

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

    VAR
      attachment_options: ^fst$attachment_options,
      cycle_attributes: ^fst$file_cycle_attributes,
      file_previously_opened: boolean,
      ignored_attributes: array [1..1] of amt$get_item,
      ignored_file_contains_data: boolean,
      ignored_file_exists: boolean,
      ignored_file_id: amt$file_identifier;

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

    ignored_attributes[1].key := amc$null_attribute;
    amp$get_file_attributes (pvt [p$file].value^.file_value^, ignored_attributes, ignored_file_exists,
      file_previously_opened, ignored_file_contains_data, status);
    IF NOT status.normal THEN
      RETURN;
    ELSEIF file_previously_opened THEN
      osp$set_status_abnormal('PF', pfe$duplicate_cycle, pvt[p$file].value^.file_value^, status);
      osp$append_status_parameter (osc$status_parameter_delimiter, 'specified', status);
      RETURN;
    IFEND;

    PUSH attachment_options: [1..1];
    attachment_options^ [1].selector := fsc$create_file;
    attachment_options^ [1].create_file := TRUE;

    PUSH cycle_attributes: [1..6];
    cycle_attributes^ [1].selector := fsc$file_contents_and_processor;
    cycle_attributes^ [1].file_contents := 'LIST';
    cycle_attributes^ [1].file_processor := osc$null_name;

    cycle_attributes^ [2].selector := fsc$page_format;
    cycle_attributes^ [2].page_format := amc$continuous_form;

    cycle_attributes^ [3].selector := fsc$page_length;
    cycle_attributes^ [3].page_length := pvt [p$page_length].value^.integer_value.value;

    cycle_attributes^ [4].selector := fsc$page_width;
    cycle_attributes^ [4].page_width := pvt [p$page_width].value^.integer_value.value;

    cycle_attributes^ [5].selector := fsc$record_delimiting_character;
    cycle_attributes^ [5].record_delimiting_character :=  $char(31);

    cycle_attributes^ [6].selector := fsc$record_type;
    cycle_attributes^ [6].record_type := amc$trailing_char_delimited;

    fsp$open_file (pvt[p$file].value^.file_value^, amc$record, attachment_options, cycle_attributes,
        cycle_attributes, NIL, NIL, ignored_file_id, status);

  PROCEND nfp$create_t_record_file;
MODEND nfm$create_t_record_file;
