?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Accounting and Validation: Compress Validation File' ??
MODULE avm$compress_validation_file;

?? NEWTITLE := 'Global Declarations referenced by this module', EJECT ??
*copyc ave$validation_interface_errors
*copyc avp$check_for_served_family
*copyc avp$family_administrator
*copyc avp$reorganize_validation_file
*copyc avp$system_administrator
*copyc clp$evaluate_file_reference
*copyc clp$evaluate_parameters
*copyc clp$trimmed_string_size
*copyc clv$user_identification
*copyc fsp$path_element
*copyc ofe$error_codes
*copyc osp$set_status_abnormal

?? NEWTITLE := 'avp$compress_validation_file', EJECT ??

{ PURPOSE:
{   This procedure compresses the validation file.

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

{     PROCEDURE (osm$comvf) compress_validation_file, comvf (
{       old_validation_file, ovf: file = $optional
{       new_validation_file, nvf: file = $optional
{       status)

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 5] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
      type3: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [92, 12, 18, 14, 20, 26, 155],
    clc$command, 5, 3, 0, 0, 0, 0, 3, 'OSM$COMVF'], [
    ['NEW_VALIDATION_FILE            ',clc$nominal_entry, 2],
    ['NVF                            ',clc$abbreviation_entry, 2],
    ['OLD_VALIDATION_FILE            ',clc$nominal_entry, 1],
    ['OVF                            ',clc$abbreviation_entry, 1],
    ['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, 3, clc$optional_parameter, 0, 0],
{ PARAMETER 2
    [1, 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_parameter, 0, 0],
{ PARAMETER 3
    [5, 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$file_type]],
{ PARAMETER 3
    [[1, 0, clc$status_type]]];

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

    CONST
      p$old_validation_file = 1,
      p$new_validation_file = 2,
      p$status = 3;

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

    VAR
      new_evaluated_file_reference: fst$evaluated_file_reference,
      new_validation_file: string (fsc$max_path_size),
      old_evaluated_file_reference: fst$evaluated_file_reference,
      old_validation_file: string (fsc$max_path_size),
      served_family: boolean;

    status.normal := TRUE;

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

    IF NOT avp$system_administrator () AND NOT avp$family_administrator () THEN
      osp$set_status_abnormal ('OF', ofe$sou_not_active, 'system_administration or family_administration',
            status);
      RETURN;
    IFEND;

    old_validation_file := ' ';
    new_validation_file := ' ';
    IF pvt [p$old_validation_file].specified THEN

{ Determine the family name from the specified path.

      clp$evaluate_file_reference (pvt [p$old_validation_file].value^.file_value^,
            $clt$file_ref_parsing_options [], TRUE, old_evaluated_file_reference, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

{ Verify that a family administrator is only changing the family in which it is in.

      IF NOT avp$system_administrator () THEN
        IF fsp$path_element (^old_evaluated_file_reference, 1) ^ (1,
              clp$trimmed_string_size(fsp$path_element (^old_evaluated_file_reference, 1) ^)) <>
              clv$user_identification.family.value (1, clv$user_identification.family.size) THEN
          osp$set_status_abnormal ('AV', ave$insufficient_authority, '', status);
          RETURN;
        IFEND;
      IFEND;

{ Don't allow COMPRESS_VALIDATON_FILE on the client.

      avp$check_for_served_family (fsp$path_element (^old_evaluated_file_reference, 1) ^, served_family);
      IF served_family THEN
        osp$set_status_abnormal ('AV', ave$not_allowed_on_client, 'COMPRESS_VALIDATION_FILE', status);
        RETURN;
      IFEND;

      old_validation_file := pvt [p$old_validation_file].value^.file_value^;
    ELSE

{ Don't allow COMPRESS_VALIDATON_FILE on the client.

      avp$check_for_served_family (clv$user_identification.family.
            value (1, clv$user_identification.family.size), served_family);
      IF served_family THEN
        osp$set_status_abnormal ('AV', ave$not_allowed_on_client, 'COMPRESS_VALIDATION_FILE', status);
        RETURN;
      IFEND;
      old_validation_file := ':';
      old_validation_file (2, clv$user_identification.family.size) :=
            clv$user_identification.family.value (1, clv$user_identification.family.size);
      old_validation_file (2 + clv$user_identification.family.size, 21) := '.$SYSTEM.$VALIDATIONS';
    IFEND;

    IF pvt [p$new_validation_file].specified THEN

{ Determine the family name from the specified path.

      clp$evaluate_file_reference (pvt [p$new_validation_file].value^.file_value^,
            $clt$file_ref_parsing_options [], TRUE, new_evaluated_file_reference, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

{ Verify that a family administrator is only changing the family in which it is in.

      IF NOT avp$system_administrator () THEN
        IF fsp$path_element (^new_evaluated_file_reference, 1) ^ (1,
              clp$trimmed_string_size(fsp$path_element (^new_evaluated_file_reference, 1) ^)) <>
              clv$user_identification.family.value (1, clv$user_identification.family.size) THEN
          osp$set_status_abnormal ('AV', ave$insufficient_authority, '', status);
          RETURN;
        IFEND;
      IFEND;

{ Don't allow COMPRESS_VALIDATON_FILE on the client.

      avp$check_for_served_family (fsp$path_element (^new_evaluated_file_reference, 1) ^, served_family);
      IF served_family THEN
        osp$set_status_abnormal ('AV', ave$not_allowed_on_client, 'COMPRESS_VALIDATION_FILE', status);
        RETURN;
      IFEND;

      new_validation_file := pvt [p$new_validation_file].value^.file_value^;
    ELSE

      new_validation_file := ':';
      new_validation_file (2, clv$user_identification.family.size) :=
            clv$user_identification.family.value (1, clv$user_identification.family.size);
      new_validation_file (2 + clv$user_identification.family.size, 27) := '.$SYSTEM.$VALIDATIONS.$NEXT';
    IFEND;

    IF new_validation_file = old_validation_file THEN
      osp$set_status_abnormal ('AV', ave$new_file_same_as_old_file, '', status);
      RETURN;
    IFEND;
    avp$reorganize_validation_file (old_validation_file, new_validation_file, status);

  PROCEND avp$compress_validation_file;

MODEND avm$compress_validation_file;
