?? RIGHT := 110 ??
?? NEWTITLE := 'PACKAGE_SOFTWARE Utility: Module RAM$TEST_CYCLES.' ??
MODULE ram$test_cycles;

{ PURPOSE:
{   This module contains the procedure to test the cycles on a file.
{
{ DESIGN:
{   If a file cycle exists that should not exist or
{   a file cycle does not exist that should exist,
{   VALIDATION_ERRORS is set to TRUE and passed back to the caller.
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rac$installation_cycles
*copyc rae$package_software_cc
*copyc ost$status
*copyc pft$checksum
*copyc rat$subproduct_info_types
*copyc rat$validation_selections
?? POP ??
*copyc osp$append_status_file
*copyc osp$generate_error_message
*copyc osp$set_status_abnormal
*copyc pfp$find_cycle_array
*copyc pfp$find_cycle_array_extended
*copyc pfp$find_cycle_directory
*copyc pfp$find_cycle_label
*copyc pfp$find_direct_info_record
*copyc rap$sort_cycles

?? TITLE := 'Global Declarations Declared by This Module', EJECT ??

?? TITLE := '[XDCL] rap$test_cycles', EJECT ??

{ PURPOSE:
{   This procedure tests a file for proper file cycles.
{
{ DESIGN:
{   If a file cycle exists that should not exist or
{   a file cycle does not exist that should exist,
{   VALIDATION_ERRORS is set to TRUE and passed back to the caller.
{
{ NOTES:
{
{

  PROCEDURE [XDCL] rap$test_cycles
    (    validation_selections: rat$validation_selections;
         element_ref_p: ^fst$file_reference;
         info_record_p: pft$p_info_record;
         info_offset: pft$info_offset;
     VAR cycles_p: pft$p_cycle_array;
     VAR validation_errors: boolean;
     VAR attributes_checksum: integer;
     VAR status: ost$status);

    VAR
      cycle_directory_p: pft$p_cycle_directory_array,
      cycle_in_error_p: ^string ( * ),
      cycle_label_seq_p: ^SEQ ( * ),
      cycle_label_checksum_p: ^pft$checksum,
      cycle_length: integer,
      cycle_label_p: pft$p_info_record,
      cycle_record_extended_p: pft$p_info_record,
      cycle_record_p: pft$p_info_record,
      i: pft$array_index,
      ignore_status: ost$status,
      local_status: ost$status,
      max_cycle: string (10),
      message_status: ost$status;


    pfp$find_direct_info_record (^info_record_p^.body, info_offset, cycle_record_p, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    pfp$find_cycle_array_extended (cycle_record_p, cycle_record_extended_p, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    pfp$find_cycle_directory (cycle_record_extended_p, cycle_directory_p, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    pfp$find_direct_info_record (^cycle_record_extended_p^.body,
            cycle_directory_p^ [UPPERBOUND (cycle_directory_p^)].info_offset, cycle_label_p, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    pfp$find_cycle_label (cycle_label_p, cycle_label_seq_p, local_status);
    IF local_status.normal THEN
      RESET cycle_label_seq_p;
      NEXT cycle_label_checksum_p IN cycle_label_seq_p;
      attributes_checksum := cycle_label_checksum_p^;
    ELSE
      osp$set_status_abnormal ('RA', rae$file_never_opened, '', message_status);
      osp$append_status_file (osc$status_parameter_delimiter, element_ref_p^, message_status);
      osp$generate_error_message (message_status, ignore_status);
      validation_errors := TRUE;
    IFEND;

    pfp$find_cycle_array (cycle_record_p, cycles_p, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    rap$sort_cycles (cycles_p);

    STRINGREP (max_cycle, cycle_length, pfc$maximum_cycle_number);
    PUSH cycle_in_error_p: [cycle_length];

    IF rac$loading_cycle_empty IN validation_selections THEN

      IF rac$loading_cycle = cycles_p^ [UPPERBOUND (cycles_p^)].cycle_number THEN
        STRINGREP (cycle_in_error_p^, cycle_length, rac$loading_cycle);
        osp$set_status_abnormal ('RA', rae$cycle_not_empty, cycle_in_error_p^ (1,cycle_length),
              message_status);
        osp$append_status_file (osc$status_parameter_delimiter, element_ref_p^, message_status);
        osp$generate_error_message (message_status, ignore_status);
        validation_errors := TRUE;
      IFEND;

    IFEND;

    IF rac$staging_cycle_empty IN validation_selections THEN

    /validate_staging_cycle/
      FOR i := UPPERBOUND (cycles_p^) DOWNTO LOWERBOUND (cycles_p^) DO

        IF rac$staging_cycle = cycles_p^ [i].cycle_number THEN
          STRINGREP (cycle_in_error_p^, cycle_length, rac$staging_cycle);
          osp$set_status_abnormal ('RA', rae$cycle_not_empty, cycle_in_error_p^ (1,cycle_length),
                message_status);
          osp$append_status_file (osc$status_parameter_delimiter, element_ref_p^, message_status);
          osp$generate_error_message (message_status, ignore_status);
          validation_errors := TRUE;
          EXIT /validate_staging_cycle/;
        IFEND;

      FOREND /validate_staging_cycle/;

    IFEND;

    IF rac$max_active_cycle_empty IN validation_selections THEN

      IF rac$max_active_cycle = cycles_p^ [LOWERBOUND (cycles_p^)].cycle_number THEN
        STRINGREP (cycle_in_error_p^, cycle_length, rac$max_active_cycle);
        osp$set_status_abnormal ('RA', rae$cycle_not_empty, cycle_in_error_p^ (1,cycle_length),
              message_status);
        osp$append_status_file (osc$status_parameter_delimiter, element_ref_p^, message_status);
        osp$generate_error_message (message_status, ignore_status);
        validation_errors := TRUE;
      IFEND;

    IFEND;

    IF rac$loading_cycle_only IN validation_selections THEN

      IF UPPERBOUND (cycles_p^) > 1 THEN
        STRINGREP (cycle_in_error_p^, cycle_length, rac$loading_cycle);
        osp$set_status_abnormal ('RA', rae$loading_cycle_only, cycle_in_error_p^ (1,cycle_length),
              message_status);
        osp$append_status_file (osc$status_parameter_delimiter, element_ref_p^, message_status);
        osp$generate_error_message (message_status, ignore_status);
        validation_errors := TRUE;
      IFEND;

      IF NOT (rac$loading_cycle = cycles_p^ [UPPERBOUND (cycles_p^)].cycle_number) THEN
        STRINGREP (cycle_in_error_p^, cycle_length, rac$loading_cycle);
        osp$set_status_abnormal ('RA', rae$loading_cycle_only, cycle_in_error_p^ (1,cycle_length),
              message_status);
        osp$append_status_file (osc$status_parameter_delimiter, element_ref_p^, message_status);
        osp$generate_error_message (message_status, ignore_status);
        validation_errors := TRUE;
      IFEND;

    IFEND;

  PROCEND rap$test_cycles;

MODEND ram$test_cycles;
