?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Append File Parameter to Status' ??
MODULE osm$append_status_file;

{
{ PURPOSE:
{   This module contains the routine to append a path name to the text of a status record.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc fst$file_reference
*copyc fst$path
*copyc fst$path_index
*copyc fst$path_size
*IF NOT $true(osv$unix)
*copyc osc$compression_identifier
*IFEND
?? POP ??
*copyc clp$trimmed_string_size
*copyc osp$append_status_parameter

*IF NOT $true(osv$unix)
*copyc clv$user_identification
*IFEND
*copyc osv$lower_to_upper

  CONST
    local_path = ':$LOCAL.',
    local_path_size = 8,
*IF NOT $true(osv$unix)
    minimum_file_reference_length = 3,
    system_path = ':$SYSTEM.$SYSTEM.',
    system_path_size = 17;
*ELSE
    minimum_file_reference_length = 3;
*IFEND

?? TITLE := 'osp$append_status_file', EJECT ??
*copyc osh$append_status_file

  PROCEDURE [XDCL, #GATE] osp$append_status_file
    (    delimiter: char;
         file: fst$file_reference;
     VAR status {input, output} : ost$status);

    VAR
      allowed_path_size: ost$string_size,
      compressed_file_reference_size: fst$path_size,
      ignore_status: ost$status,
      status_text_size: ost$string_size;

    IF status.normal THEN
      RETURN;
    IFEND;

    status_text_size := status.text.size; {prevent value from changing.}
    allowed_path_size := (osc$max_string_size - status_text_size) DIV 2;
    IF allowed_path_size < minimum_file_reference_length THEN
      RETURN;
    IFEND;

    status_text_size := status_text_size + 1;
    status.text.value (status_text_size) := delimiter;
    osp$compress_file_reference (file, status.text.value (status_text_size + 1, allowed_path_size),
          compressed_file_reference_size, ignore_status);
    status.text.size := status_text_size + compressed_file_reference_size;

  PROCEND osp$append_status_file;

?? TITLE := 'osp$compress_file_reference', EJECT ??
*copyc osh$compress_file_reference

  PROCEDURE [XDCL, #GATE] osp$compress_file_reference
    (    file_reference: fst$file_reference;
     VAR compressed_file_reference: fst$file_reference;
     VAR compressed_file_reference_size: fst$path_size;
     VAR status: ost$status);

    VAR
      compressed_length: fst$path_size,
      compressed_file_index: fst$path_index,
      compression_character: char,
      remaining_compressed_length: fst$path_size,
      remaining_path_size: fst$path_size,
      file_reference_length: fst$path_size,
      path: fst$path,
      replaced_path_size: fst$path_size,
      split_size: fst$path_size;

    status.normal := TRUE;
*IF NOT $true(osv$unix)
    #TRANSLATE (osv$lower_to_upper, file_reference, path);
*ELSE
    path := file_reference;
*IFEND
    file_reference_length := clp$trimmed_string_size (file_reference);
    compressed_length := STRLENGTH (compressed_file_reference);

    IF compressed_length < minimum_file_reference_length THEN
      IF compressed_length > 0 THEN
        compressed_file_reference := '?';
        compressed_file_reference_size := 1;
      ELSE
        compressed_file_reference_size := 0;
      IFEND;
      RETURN;
    IFEND;

*IF NOT $true(osv$unix)
    IF (file_reference_length >= local_path_size) AND (path (1, local_path_size) = local_path) THEN
      compression_character := 'L';
      replaced_path_size := local_path_size;
    ELSEIF (file_reference_length >= system_path_size) AND (path (1, system_path_size) = system_path) THEN
      compression_character := 'S';
      replaced_path_size := 17;
    ELSEIF (file_reference_length >= (clv$user_identification.family.size + 2)) AND (path (1) = ':') AND
          (path (2, clv$user_identification.family.size) = clv$user_identification.family.
          value (1, clv$user_identification.family.size)) AND
          (path (clv$user_identification.family.size + 2, 1) = '.') THEN
      compression_character := 'F';
      replaced_path_size := clv$user_identification.family.size + 2;
      IF (file_reference_length >= (clv$user_identification.family.size + clv$user_identification.user.size +
            3)) AND (path (clv$user_identification.family.size + 3,
            clv$user_identification.user.size) = clv$user_identification.user.
            value (1, clv$user_identification.user.size)) AND
            (path (clv$user_identification.family.size + clv$user_identification.user.size + 3) = '.') THEN
        compression_character := 'U';
        replaced_path_size := clv$user_identification.family.size + clv$user_identification.user.size + 3;
      IFEND;
    ELSE
*IFEND
      compression_character := ' ';
      replaced_path_size := 0;
*IF NOT $true(osv$unix)
    IFEND;
*IFEND

*IF NOT $true(osv$unix)
    IF (file_reference_length > compressed_length) AND (compression_character = ' ') THEN
      compression_character := 'C';
    IFEND;
*IFEND

*IF NOT $true(osv$unix)
    IF compression_character <> ' ' THEN
      compressed_file_reference (1, 1) := osc$compression_identifier;
      compressed_file_reference (2, 1) := compression_character;
      compressed_file_index := 3;
      remaining_compressed_length := compressed_length - 2;
    ELSE
*IFEND
      compressed_file_index := 1;
      remaining_compressed_length := compressed_length;
*IF NOT $true(osv$unix)
    IFEND;
*IFEND

    remaining_path_size := (file_reference_length - replaced_path_size);

    IF (remaining_compressed_length >= remaining_path_size) THEN
      compressed_file_reference (compressed_file_index, remaining_path_size) :=
            path (replaced_path_size + 1, remaining_path_size);
      compressed_file_reference_size := remaining_path_size + compressed_file_index - 1;
    ELSE
      compressed_file_reference_size := compressed_length;
      IF remaining_compressed_length >= 4 THEN
        split_size := (remaining_compressed_length - 2) DIV 2;
        compressed_file_reference (compressed_file_index, split_size) :=
              path (replaced_path_size + 1, split_size);
        compressed_file_reference (compressed_file_index + split_size, 2) := '..';
        compressed_file_index := compressed_file_index + split_size + 2;
        compressed_file_reference (compressed_file_index, compressed_length - compressed_file_index + 1) :=
              path (file_reference_length - split_size + 1, compressed_length - compressed_file_index + 1);
      ELSE
        compressed_file_reference (compressed_file_index, remaining_compressed_length) :=
              path (replaced_path_size + 1, remaining_compressed_length);
      IFEND;
    IFEND;

  PROCEND osp$compress_file_reference;

?? TITLE := 'osp$expand_file_reference', EJECT ??
*copyc osh$expand_file_reference

  PROCEDURE [XDCL, #GATE] osp$expand_file_reference
    (    file_reference: fst$file_reference;
     VAR expanded_file_reference: fst$file_reference;
     VAR expanded_file_reference_size: fst$path_size;
     VAR status: ost$status);

    VAR
      expanded_length: fst$path_size,
      file_reference_length: fst$path_size;

    status.normal := TRUE;
    expanded_length := STRLENGTH (expanded_file_reference);
    file_reference_length := clp$trimmed_string_size (file_reference);

    IF (file_reference_length < 1) OR (expanded_length < 1) THEN
      expanded_file_reference_size := 0;
      RETURN;
    IFEND;

*IF NOT $true(osv$unix)
    IF (file_reference (1) = osc$compression_identifier) AND (file_reference_length > 2) THEN
      CASE file_reference (2) OF
      = 'S' =
        IF (expanded_length >= system_path_size + file_reference_length - 2) THEN
          expanded_file_reference (1, system_path_size) := system_path;
          expanded_file_reference (system_path_size + 1, file_reference_length - 2) :=
                file_reference (3, file_reference_length - 2);
          expanded_file_reference_size := system_path_size + file_reference_length - 2;
          RETURN;
        IFEND;
      = 'U' =
        IF expanded_length >= (clv$user_identification.family.size + clv$user_identification.user.size +
              file_reference_length + 1) THEN
          expanded_file_reference (1, 1) := ':';
          expanded_file_reference (2, clv$user_identification.family.size) :=
                clv$user_identification.family.value (1, clv$user_identification.family.size);
          expanded_file_reference (clv$user_identification.family.size + 2, 1) := '.';
          expanded_file_reference (clv$user_identification.family.size + 3,
                clv$user_identification.user.size) := clv$user_identification.user.
                value (1, clv$user_identification.user.size);
          expanded_file_reference (clv$user_identification.family.size + clv$user_identification.user.size +
                3, 1) := '.';
          expanded_file_reference (clv$user_identification.family.size + clv$user_identification.user.size +
                4, file_reference_length - 2) := file_reference (3, file_reference_length - 2);
          expanded_file_reference_size := (clv$user_identification.family.size +
                clv$user_identification.user.size + file_reference_length + 1);
          RETURN;
        IFEND;
      = 'L' =
        IF expanded_length >= (local_path_size + file_reference_length - 2) THEN
          expanded_file_reference (1, local_path_size) := local_path;
          expanded_file_reference (local_path_size + 1, file_reference_length - 2) :=
                file_reference (3, file_reference_length - 2);
          expanded_file_reference_size := local_path_size + file_reference_length - 2;
          RETURN;
        IFEND;
      = 'F' =
        IF expanded_length >= (clv$user_identification.family.size + file_reference_length) THEN
          expanded_file_reference (1, 1) := ':';
          expanded_file_reference (2, clv$user_identification.family.size) :=
                clv$user_identification.family.value (1, clv$user_identification.family.size);
          expanded_file_reference (clv$user_identification.family.size + 2, 1) := '.';
          expanded_file_reference (clv$user_identification.family.size + 3,
                file_reference_length - 2) := file_reference (3, file_reference_length - 2);
          expanded_file_reference_size := (clv$user_identification.family.size + file_reference_length);
          RETURN;
        IFEND;
      = 'C' =
        IF expanded_length >= (file_reference_length - 2) THEN
          expanded_file_reference (1, (file_reference_length - 2)) :=
                file_reference (3, (file_reference_length - 2));
          expanded_file_reference_size := file_reference_length - 2;
          RETURN;
        IFEND;
      ELSE
      CASEND;
    IFEND;
*IFEND

    IF expanded_length >= file_reference_length THEN
      expanded_file_reference (1, file_reference_length) := file_reference (1, file_reference_length);
      expanded_file_reference_size := file_reference_length;
    ELSE
      expanded_file_reference (1, expanded_length) := file_reference (1, expanded_length);
      expanded_file_reference_size := expanded_length;
    IFEND;

  PROCEND osp$expand_file_reference;

MODEND osm$append_status_file;




