?? RIGHT := 110 ??
*copyc OSD$DEFAULT_PRAGMATS
?? NEWTITLE := 'PMM$CONVERT_64_TO_32_BITS', EJECT ??
MODULE ocm$convert_64_to_32_bits;



{ PURPOSE:  The purpose of this module is to convert a file packed 64 bits in
{           64 bits to a file packed 32 bits in 64 bits.




{ *callc clxspl  }
{ *callc clxgval }
{ *callc amxgfat }
{ *callc amxopen }
{ *callc amxgsgp }
{ *callc amxsete }
{ *callc amxclse }
{ *callc osxssa  }
{ *callc ocdvler }
?? PUSH (LISTEXT := ON) ??
*copyc CLP$SCAN_PARAMETER_LIST
*copyc CLP$GET_VALUE
*copyc AMP$GET_FILE_ATTRIBUTES
*copyc AMP$OPEN
*copyc AMP$GET_SEGMENT_POINTER
*copyc AMP$SET_SEGMENT_EOI
*copyc AMP$CLOSE
*copyc OSP$SET_STATUS_ABNORMAL
*copyc OCE$VE_LINKER_EXCEPTIONS
?? POP ??
?? NEWTITLE := '  PMP$CONVERT_64_TO_32_BITS', EJECT ??

  PROCEDURE [XDCL, #GATE] ocp$convert_64_to_32_bits (parameter_list: clt$parameter_list;
    VAR status: ost$status);


{ pdt convert_pdt (
{   input, i : file = $required
{   output, o : file = $required
{   status)

?? PUSH (LISTEXT := ON) ??

    VAR
      convert_pdt: [STATIC, READ, cls$pdt] clt$parameter_descriptor_table := [^convert_pdt_names,
        ^convert_pdt_params];

    VAR
      convert_pdt_names: [STATIC, READ, cls$pdt_names_and_defaults] array [1 .. 5] of
        clt$parameter_name_descriptor := [['INPUT', 1], ['I', 1], ['OUTPUT', 2], ['O', 2], ['STATUS', 3]];

    VAR
      convert_pdt_params: [STATIC, READ, cls$pdt_parameters] array [1 .. 3] of clt$parameter_descriptor := [

{ INPUT I }
      [[clc$required], 1, 1, 1, 1, clc$value_range_not_allowed, [NIL, clc$file_value]],

{ OUTPUT O }
      [[clc$required], 1, 1, 1, 1, clc$value_range_not_allowed, [NIL, clc$file_value]],

{ STATUS }
      [[clc$optional], 1, 1, 1, 1, clc$value_range_not_allowed, [NIL, clc$variable_reference,
        clc$array_not_allowed, clc$status_value]]];

?? POP ??


    VAR
      input_parameter: clt$value,
      input_identifier: amt$file_identifier,
      input_segment: amt$segment_pointer,
      output_parameter: clt$value,
      output_identifier: amt$file_identifier,
      output_segment: amt$segment_pointer,
      local_file: boolean,
      existing_file: boolean,
      contains_data: boolean,
      length_attribute: [STATIC] array [1 .. 1] of amt$get_item := [[ * , amc$file_length, * ]],
      input_attributes: [STATIC] array [1 .. 1] of amt$access_selection := [[amc$access_mode,
        $pft$usage_selections [pfc$read]]],
      output_attributes: [STATIC] array [1 .. 1] of amt$access_selection := [[amc$access_mode,
        $pft$usage_selections [pfc$read, pfc$shorten, pfc$append, pfc$modify]]],
      input_word_array: ^ARRAY [1 .. * ] of 0 .. 0ffffffff(16),
      output_word_array: ^array [1 .. * ] of integer,
      input_byte_array: ^array [1 .. * ] of 0 .. 0ff(16),
      output_word: ^integer,
      i: integer,
      number_of_half_words: integer,
      number_of_bytes: integer;


    status.normal := TRUE;

    clp$scan_parameter_list (parameter_list, convert_pdt, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;


    clp$get_value ('INPUT', 1, 1, clc$low, input_parameter, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;


    clp$get_value ('OUTPUT', 1, 1, clc$low, output_parameter, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
?? EJECT ??


    IF input_parameter.file.local_file_name = output_parameter.file.local_file_name THEN
      osp$set_status_abnormal ('OC', oce$e_duplicate_file_named, input_parameter.file.local_file_name,
            status);
      RETURN;
    IFEND;


    amp$get_file_attributes (input_parameter.file.local_file_name, length_attribute, local_file,
          existing_file, contains_data, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    number_of_half_words := (length_attribute [1].file_length DIV 4);
    number_of_bytes := (length_attribute [1].file_length - (number_of_half_words * 4));

    amp$open (input_parameter.file.local_file_name, amc$segment, ^input_attributes, input_identifier, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$get_segment_pointer (input_identifier, amc$sequence_pointer, input_segment, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;


    amp$open (output_parameter.file.local_file_name, amc$segment, ^output_attributes, output_identifier,
          status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$get_segment_pointer (output_identifier, amc$sequence_pointer, output_segment, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;
?? EJECT ??


    RESET input_segment.sequence_pointer;
    NEXT input_word_array: [1 .. number_of_half_words] IN input_segment.sequence_pointer;
    IF input_word_array = NIL THEN
      osp$set_status_abnormal ('OC', oce$e_storage_allocation_failed, 'INPUT - 1', status);
      RETURN;
    IFEND;

    RESET output_segment.sequence_pointer;
    NEXT output_word_array: [1 .. number_of_half_words] IN output_segment.sequence_pointer;
    IF output_word_array = NIL THEN
      osp$set_status_abnormal ('OC', oce$e_storage_allocation_failed, 'OUTPUT - 1', status);
      RETURN;
    IFEND;


    FOR i := 1 TO number_of_half_words DO
      output_word_array^ [i] := input_word_array^ [i];
    FOREND;


    IF number_of_bytes > 0 THEN
      NEXT input_byte_array: [1 .. number_of_bytes] IN input_segment.sequence_pointer;
      IF input_byte_array = NIL THEN
        osp$set_status_abnormal ('OC', oce$e_storage_allocation_failed, 'INPUT - 2', status);
        RETURN;
      IFEND;

      NEXT output_word IN output_segment.sequence_pointer;
      IF output_word = NIL THEN
        osp$set_status_abnormal ('OC', oce$e_storage_allocation_failed, 'OUTPUT - 2', status);
        RETURN;
      IFEND;


      output_word^ := 0;

      FOR i := 1 TO number_of_bytes DO
        output_word^ := (output_word^ * 100(16)) + input_byte_array^ [i];
      FOREND;
      FOR i := (number_of_bytes + 1) TO 4 DO
        output_word^ := output_word^ * 100(16);
      FOREND;
    IFEND;
?? EJECT ??


    amp$set_segment_eoi (output_identifier, output_segment, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$close (input_identifier, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    amp$close (output_identifier, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;




  PROCEND ocp$convert_64_to_32_bits;


MODEND ocm$convert_64_to_32_bits.
