MODULE pfm$archive_retrieve_control;
?? RIGHT := 110 ??

?? NEWTITLE := 'Global Declarations Referenced By This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc cle$ecc_command_processing
*copyc pfe$selection_errors
*copyc ost$wait
*copyc pft$password
?? POP ??
*copyc clp$include_line
*copyc ofp$display_status_message
*copyc ofp$get_display_status_message
*copyc pfp$convert_pf_cy_path_to_strng
*copyc pmp$get_job_names
?? TITLE := '*** PFP$RETRIEVE_ARCHIVED_FILE ***', EJECT ??
*copy pfh$retrieve_archived_file

  PROCEDURE [XDCL, #GATE] pfp$retrieve_archived_file
    (    path: pft$path;
         cycle_number: fst$cycle_number;
         password: pft$password;
         wait: ost$wait;
     VAR status: ost$status);

    VAR
      original_display_message: oft$display_message,
      password_value: pft$password,
      path_string: ost$string,
      retrieve_call: string (500),
      retrieve_call_length: integer,
      wait_value: boolean;

    status.normal := TRUE;
    wait_value := wait = osc$nowait;
    IF wait_value THEN
      get_current_display_message (original_display_message);
      display_retrieval_message (path [UPPERBOUND (path)], cycle_number);
    IFEND;

    pfp$convert_pf_cy_path_to_strng (path, cycle_number, path_string);

    IF password = osc$null_name THEN
      password_value := 'none';
    ELSE
      password_value := password;
    IFEND;

    STRINGREP (retrieve_call, retrieve_call_length, '$system.osf$command_library.retrieve_file', ' file=',
          path_string.value (1, path_string.size), ' password=', password_value, ' wait=', wait_value);

    clp$include_line (retrieve_call (1, retrieve_call_length), { enable_echoing } TRUE,
          { utility } osc$null_name, status);

    IF NOT status.normal AND (status.condition = cle$file_dot_cmnd_not_allowed) THEN

{ If we cannot call $system.osf$command_library.retrieve_file, try to call
{ it using a simple retrieve_file call.  This is done so a site can have a
{ fence defined for their users and still be able to make implicit calls
{ to retrieve_file.

      STRINGREP (retrieve_call, retrieve_call_length, 'retrieve_file', ' file=', path_string.
            value (1, path_string.size), ' password=', password_value, ' wait=', wait_value);

      clp$include_line (retrieve_call (1, retrieve_call_length), { enable_echoing } TRUE,
            { utility } osc$null_name, status);
    IFEND;

    IF wait_value THEN
      clear_wait_message (original_display_message);
    IFEND;

  PROCEND pfp$retrieve_archived_file;

?? TITLE := '*** CLEAR_WAIT_MESSAGE ***', EJECT ??

  PROCEDURE [inline] clear_wait_message
    (    original_display_message: oft$display_message);

    CONST
      continuing_message = 'Continuing: ',
      continuing_message_size = 12;

    VAR
      ignored_status: ost$status,
      message_length: integer,
      message_string: string (ofc$max_display_message);

    IF original_display_message.text (1, continuing_message_size) = continuing_message THEN
      message_length := original_display_message.size;
      message_string := original_display_message.text (1, message_length);
    ELSE
      STRINGREP (message_string, message_length, continuing_message, original_display_message.
            text (1, original_display_message.size));
    IFEND;

    ofp$display_status_message (message_string (1, message_length), ignored_status);

  PROCEND clear_wait_message;

?? TITLE := '*** DISPLAY_RETRIEVAL_MESSAGE ***', EJECT ??

  PROCEDURE [inline] display_retrieval_message
    (    file_name: pft$name;
         cycle_number: fst$cycle_number);

    VAR
      ignored_status: ost$status,
      message_length: integer,
      message_string: string (ofc$max_display_message);

    STRINGREP (message_string, message_length, 'Retrieving cycle ', cycle_number, ' of file ', file_name);
    ofp$display_status_message (message_string (1, message_length), ignored_status);

  PROCEND display_retrieval_message;

?? TITLE := '*** GET_CURRENT_DISPLAY_MESSAGE ***', EJECT ??

  PROCEDURE [inline] get_current_display_message
    (VAR current_display_message: oft$display_message);

    VAR
      local_status: ost$status,
      system_supplied_name: jmt$system_supplied_name,
      user_name: jmt$user_supplied_name;

    pmp$get_job_names (user_name, system_supplied_name, local_status);
    ofp$get_display_status_message (system_supplied_name, current_display_message, local_status);
    IF NOT local_status.normal THEN
      current_display_message.size := 7;
      current_display_message.text := 'UNKNOWN';
    IFEND;

  PROCEND get_current_display_message;

MODEND pfm$archive_retrieve_control;

