
*copyc osd$default_pragmats
?? NEWTITLE := '170 NOS/VE REMOTE HOST' ??
MODULE rhm$get_replace_exec ALIAS 'rhmpfp';

{ Select target 170 operating system.
*IF ($string($name(wev$target_operating_system))='NOS')

  ?VAR rhv$nos_be: boolean := FALSE ?;
*ELSE

  ?VAR rhv$nos_be: boolean := TRUE ?;
*IFEND

?? NEWTITLE := 'GLOBAL TYPE DECLARATIONS' ??
?? SET (LIST := ON) ??
?? EJECT ??
*copyc rhc$constants
*copyc rht$function_status
*copyc mld$memory_link_declarations

?? TITLE := 'EXTERNAL PROCEDURES REFERENCED BY THIS MODULE' ??
?? SET (LIST := ON) ??
?? EJECT ??
*copyc rhp$sign_on_and_off_os
*copyc rhp$add_sender_os
*copyc rhp$confirm_send_os
*copyc rhp$send_message_os
*copyc rhp$receive_message_os
*copyc rhp$log_status
*copyc rhp$wait
*copyc rhp$open_file
*copyc rhp$close_file
*copyc rhp$return_file
*copyc rhp$map_pfm_code_to_rh_code
*copyc zutpsfn
*copyc rhp$cpm_function_request
*copyc pxiotyp
*copyc bizopen
*copyc bizget
*copyc bizclos
*copyc zn7ppfm
*copyc zn7pcio

  PROCEDURE [XREF] pfsend (lfn: integer;
        an170: integer;
        an180: integer;
    VAR detailed_status: integer;
    VAR pfsend_status: integer);

  PROCEDURE [XREF] pfrec (lfn: integer;
        an170: integer;
        an180: integer;
    VAR detailed_status: integer;
    VAR pfsend_status: integer);

?? SET (LIST := ON) ??
{
{ The following variable defines the value of the signal option parameter
{ for all mli send/receive request issued by the irhf c170 pf routines.

    VAR
      signal_record: [STATIC] mlt$signal_record := [0, *, * ],
      rhv$signal: [XDCL, STATIC] mlt$signal := ^signal_record;

?? TITLE := 'RHP$170_PF_FUNCTION_PROCESSOR' ??
?? SET (LIST := ON) ??
?? EJECT ??


  PROGRAM rhp$170_pf_function_processor;

    CONST
      get_pf = rhc$get_pf,
      time_out_limit = 100,
      replace_pf = rhc$replace_pf;

    VAR
      application_names: [STATIC] rht$mli_application_names,
      sender_name: mlt$application_name,
      status: ost$status,
      unique: mlt$application_name, { see note below }
      abnormal_mli_status_message: string (42),
      conf_stat: ost$status,
      time_cnt: 0 .. 100,
      string_length: integer,
      message_info: [STATIC] rht$mli_message_info :=
            [^permanent_file_info, *, *, *],
      permanent_file_info: [STATIC] record
        permanent_file_name: string (31),
        user_or_id: string (9),
        file_cycle: string (3),
        passwords: array [1 .. 2] of string (9),
      recend;

{ Form memory link application names.

    form_application_names (application_names);

{ Sign on to the memory link.

  /ml_sign_on/
    REPEAT
      rhp$sign_on_os (application_names.application.application_name, 0, unique,
            status);
      IF NOT status.normal THEN
        CASE status.condition OF
        = mlc$ant_full, mlc$busy_interlock, mlc$pool_buffer_not_avail =
        ELSE
          abnormal_mli_status_message (1, 31) :=
                'sign on mli abnormal condition =';
          STRINGREP (abnormal_mli_status_message (32, 3), string_length,
                status.condition);
          log_status (dayfile_log_and_display, abnormal_mli_status_message (1,
                31 + string_length));
        CASEND;
        wait (1000);
      IFEND;
    UNTIL status.normal; {ml_sign_on}

{ Give name of sender to the memory link.

  /ml_add_sender/
    REPEAT
      rhp$add_sender_os (application_names.application.application_name,
            application_names.destination.application_name, status);
      IF NOT status.normal THEN
        IF status.condition <> mlc$busy_interlock THEN
          abnormal_mli_status_message (1, 34) :=
                'add sender mli abnormal condition=';
          STRINGREP (abnormal_mli_status_message (35, 3), string_length,
                status.condition);
          log_status (dayfile_log_and_display, abnormal_mli_status_message (1,
                34 + string_length));
        IFEND;
        wait (1000);
      IFEND;
    UNTIL status.normal; {ml_add_sender}

{ Receive function code and call the processor of the function.

    message_info.message_area_length := #SIZE (permanent_file_info);
    time_cnt := 0;
  /process_function/
    REPEAT
      rhp$receive_message_os (application_names.application.application_name,
            message_info.arbitrary_info, rhv$signal, message_info.message_area,
            message_info.message_length, message_info.message_area_length,
            0{index for receive any pending message}, sender_name,
            status);
      IF status.normal OR (status.condition = mlc$signal_failed_ignored) THEN
        CASE message_info.arbitrary_info OF
        = get_pf =
          get_permanent_file (permanent_file_info, application_names);
        = replace_pf =
          replace_permanent_file (permanent_file_info, application_names);
        CASEND;
      ELSE
        CASE status.condition OF
          = mlc$busy_interlock =
            wait (1000);
          = mlc$receive_list_index_invalid =
            time_cnt := time_cnt + 1;
            IF time_cnt = time_out_limit THEN
              rhp$confirm_send_os (application_names.application.application_name,
                                application_names.destination.application_name,conf_stat);
              IF (NOT(conf_stat.normal)) AND
                 (conf_stat.condition = mlc$receiver_not_signed_on) THEN
                EXIT /process_function/;
              ELSE
                time_cnt := 0;
                wait (1000);
              IFEND;
            IFEND;
          = mlc$nosve_not_up =
            EXIT /process_function/;
        ELSE
          abnormal_mli_status_message (1, 39) :=
                  'receive message mli abnormal condition=';
          STRINGREP (abnormal_mli_status_message (40, 3), string_length,
                status.condition);
          log_status (dayfile_log_and_display, abnormal_mli_status_message
                (1, 39 + string_length));
        CASEND;
      IFEND;
    UNTIL status.normal OR (status.condition = mlc$signal_failed_ignored);
          { process_function }

    rhp$sign_off_os (application_names.application.application_name,  status);

  PROCEND rhp$170_pf_function_processor;

?? TITLE := 'GET_PERMANENT_FILE' ??
?? SET (LIST := ON) ??
?? EJECT ??

{ GET_PERMANENT_FILE
{
{       The purpose of this procedure is to perform all work necessary to
{ accomplish an A170/NOS permanent file GET of the file identified by pf_info
{ and transfer that file to the application which is identified by the
{ destination field of application_names.
{
{       GET_PERMANENT_FILE (PERMANENT_FILE_INFO,APPLICATION_NAMES)
{
{ PERMANENT_FILE_INFO: (input) This parameter contains all information
{                      required to identify the permanent file on which
{                      the permanent file function is to be performed.
{
{ APPLICATION_NAMES: (input) This parameter identifies the application
{                    performing the permanent file function and the
{                    application to which the permanent file is transfered.
{

  PROCEDURE get_permanent_file (
    permanent_file_info: record
      permanent_file_name: string (31),
      user_or_id: string (9),
      file_cycle: string (3),
      passwords: array [1 .. 2] of string (9),
    recend;
    VAR application_names: rht$mli_application_names);

    CONST
      file_acquired = rhc$ok;

    VAR
      local_file_info: rht$local_file_info,
      permanent_file_type: rht$permanent_file_types,
      condition: integer,
      state: (send_file, send_condition),
      { message_info: [STATIC] rht$mli_message_info:=[^data_buffer,0,*,*],
      message_info: [STATIC] rht$mli_message_info := [ * , 0, * , * ], { kludge
      abnormal_mli_status_message: string(39),
      string_length: integer,
      data_buffer: integer,
      detailed_status,
      pfsend_status: integer,
      status: ost$status;


{ Acquire the permanent file requested by the GET.

    message_info.message_area := ^data_buffer;

? IF rhv$nos_be = TRUE THEN
      local_file_info.fet.filename := local_file_name1;
      attach_file (permanent_file_info, local_file_info.fet.filename, condition);
? ELSE
    acquire_permanent_file (permanent_file_info, local_file_info.fet,
          permanent_file_type, condition);
? IFEND
    IF condition = file_acquired THEN
      state := send_file;
    ELSE
      message_info.arbitrary_info := condition;
      state := send_condition;
    IFEND;

{ Send data in the permanent file to the 180 side.

    CASE state OF
      = send_file =
        pfsend (local_file_info.fet.filename, application_names.application.
              application_name, application_names.destination.application_name,
              detailed_status, pfsend_status);
        IF pfsend_status = 1 THEN
          log_status (dayfile_log, 'File could not be transferred to the 180 side');
          log_status (dayfile_log, 'due to the file INPUT empty or mispositioned.');
          log_status (dayfile_log, 'check your NOS prolog or call your site analyst.');
        IFEND;
      = send_condition =
        message_info.message_length := 0;
        /send_loop/
        REPEAT
          rhp$send_message_os (application_names.application.application_name,
                message_info.arbitrary_info, rhv$signal, message_info.
                message_area, message_info.message_length, application_names.
                destination.application_name, status);
          IF NOT status.normal THEN
            CASE status.condition OF
            = mlc$busy_interlock, mlc$pool_buffer_not_avail,
              mlc$prior_msg_not_received =
              wait (1000);
            ELSE
              abnormal_mli_status_message (1, 36) :=
                    'send message mli abnormal condition=';
              STRINGREP (abnormal_mli_status_message (37, 3), string_length,
                    status.condition);
              log_status (dayfile_log_and_display, abnormal_mli_status_message
                    (1, 36 + string_length));
              EXIT /send_loop/;
            CASEND;
          IFEND;
        UNTIL status.normal; {send_loop}
      CASEND;

  PROCEND get_permanent_file;

?? TITLE := 'REPLACE_PERMANENT_FILE' ??
?? SET (LIST := ON) ??
?? EJECT ??

{
{       The purpose of this procedure is to receive transmission of a file
{ from the application identified by the destination field of application_
{ names and perform all work necessary to accomplish an A170/NOS permanent
{ file REPLACE of the file identified by pf_info with the transmitted file.
{
{       REPLACE_PERMANENT_FILE (PERMANENT_FILE_INFO,APPLICATION_NAMES)
{
{ PERMANENT_FILE_INFO: (input) This parameter contains all information
{                      required to identify the permanent file on which
{                      the permanent file function is to be performed.
{
{ APPLICATION_NAMES: (input) This parameter identifies the application
{                    performing the permanent file function and the
{                    application to which the permanent file is transfered.
{

  PROCEDURE replace_permanent_file (
    permanent_file_info: record
      permanent_file_name: string (31),
      user_or_id: string (9),
      file_cycle: string (3),
      passwords: array [1 .. 2] of string (9),
    recend;
    VAR application_names: rht$mli_application_names);

    CONST
      file_defined = rhc$ok,
      zero_message_length = 0;

    VAR
      local_file_info: rht$local_file_info,
      permanent_file_type: rht$file_type,
      permanent_file_status: rht$file_status_type,
      condition: integer,
      arbitrary_info: mlt$arbitrary_info,
      sender_application_name: mlt$application_name,
      detailed_status,
      pfrec_status: integer,
      message_length: mlt$message_length,
      status: ost$status,
      tran_status: rht$trans_status_type;

{ Define a file that will receive the data.

? IF rhv$nos_be = TRUE THEN
      local_file_info.fet.filename := local_file_name1;
      local_file_request (local_file_info.fet.filename, condition);
? ELSE
      define_receive_file (permanent_file_info, local_file_info.fet,
            permanent_file_type, permanent_file_status, condition);
? IFEND;

    IF condition = file_defined THEN

{ Copy data from 170 side to a local file on the 180 side.

      pfrec (local_file_info.fet.filename, application_names.application.
            application_name, 0, detailed_status, pfrec_status);
      tran_status := ok;
? IF rhv$nos_be = TRUE THEN
        catalog_file (permanent_file_info, local_file_info.fet.filename, arbitrary_info);
        IF arbitrary_info <> rhc$ok THEN
          tran_status := a170_error;
        IFEND;
? ELSE
        dispose_files (local_file_info.fet, permanent_file_type,
            permanent_file_status, tran_status, arbitrary_info);
? IFEND;
    ELSE
      arbitrary_info := condition;
      tran_status := a170_error;
    IFEND;

{ If error occurred on 170 side transfer error to 180 side.

    IF tran_status <> c180_error THEN

    /send_condition/
      REPEAT
        rhp$send_message_os (application_names.application.application_name,
              arbitrary_info, rhv$signal, ^condition, zero_message_length,
              application_names.destination.application_name, status);
        IF NOT status.normal THEN
          CASE status.condition OF
          = mlc$busy_interlock, mlc$pool_buffer_not_avail,
            mlc$prior_msg_not_received =
             wait (1000);
          = mlc$receiver_name_syntax_error =
            log_status (dayfile_log, 'File could not be received from the 180 side');
            log_status (dayfile_log, 'due to the file INPUT empty or mispositioned.');
            log_status (dayfile_log, 'check your NOS prolog or call your site analyst.');
            EXIT /send_condition/;
          ELSE
            EXIT /send_condition/;
          CASEND;
        IFEND;
      UNTIL status.normal; {send_codition}
    IFEND;

  PROCEND replace_permanent_file;

?? TITLE := 'ACQUIRE_PERMANENT_FILE' ??
?? SET (LIST := ON) ??
?? EJECT ??

{
{      The purpose of this procedure is to acquire the permanent file
{ identified by permanent_file_info.
{
{      ACQUIRE_PERMANENT_FILE (PERMANENT_FILE_INFO,FET,PERMANENT_FILE_TYPE,
{           ACQUIRE_CONDITION)
{
{ PERMANENT_FILE_INFO: (input) This parameter contains all information required
{                      to identify the permanent file which is to be acquired.
{
{ FET: (output) This parameter specifies all information pertinent to the
{      identification and access of the acquired (local) permanent file.
{
{ PERMANENT_FILE_TYPE: (output) This parameter identifies the access type of
{                      the permanent file, i.e. indirect or direct.
{                      Permanent_file_type is not set if the file does not
{                      exist as defined by permanent_file_info.
{
{ ACQUIRE_CONDITION: (output) This parameter indicates the condition of the
{                    acquire request.  All conditions are remote host def-
{                    initions of A170/NOS permanent file manager condition
{                    codes.
{

  PROCEDURE acquire_permanent_file (
    permanent_file_info: record
      permanent_file_name: string (31),
      user_or_id: string (9),
      file_cycle: string (3),
      passwords: array [1 .. 2] of string (9),
    recend;
    VAR fet: n7t$fet;
    VAR permanent_file_type: rht$permanent_file_types;
    VAR acquire_condition: integer);

    CONST
      pfm_fet_extension_length = 10;

    TYPE nonfast_attach_set = SET of 1 .. 5;

    VAR
      i: integer,
      dc_file_name: utt$dc_name;

{ Initialize the file enviroment table (fet) to acquire the permanent file.}

    FOR i:=1 TO 22 DO
      fet.fet1_22[i]:=0;
    FOREND;
    fet.completed:=TRUE;
    utp$convert_string_to_file_name(permanent_file_info.permanent_file_name,
          dc_file_name);
    fet.filename:=dc_file_name;
    fet.user_processing:=FALSE;
    fet.error_processing:=TRUE;
    fet.extension_length:=pfm_fet_extension_length;
    fet.pfn:=dc_file_name;

{ Set fill8 to not allow attach of NOS fast attach files.

    fet.fill8 := $nonfast_attach_set [4];
    utp$convert_string_to_file_name(permanent_file_info.user_or_id,
          dc_file_name);
    fet.optional_un:=dc_file_name;
    utp$convert_string_to_file_name(permanent_file_info.passwords [1] (1, 7),
          dc_file_name);
    fet.file_password:=dc_file_name;
    fet.file_mode := n7c$pfm_m_read;

{ Acquire the permanent file.}

    n7p$pfm (n7c$pfm_attach, fet); { Try attaching it first.}
    IF fet.response_code = n7c$pfm_file_not_found THEN
      n7p$pfm (n7c$pfm_get, fet); { Get the file.}
    IFEND;
    map_pfm_code_to_rh_code(fet.response_code,acquire_condition);

  PROCEND acquire_permanent_file;

?? TITLE := 'DEFINE_RECEIVE_FILE' ??
?? SET (LIST := ON) ??
?? EJECT ??

{
{      The purpose of this procedure is to determine the existence and
{ access type of the permanent file to be replaced and define the file
{ to which the transfer of data, from the C180 task, will be made.
{
{      DEFINE_RECEIVE_FILE (PERMANENT_FILE_INFO,FET,PERMANENT_FILE_TYPE,
{                               PERMANENT_FILE_STATUS,DEFINE_CONDITION)
{
{ PERMANENT_FILE_INFO: (input) This parameter contains all information
{                      required to identify the permanent file which is
{                      to be replaced.
{
{ FET (output): This parameter specifies the fet which identifies the file
{     which will receive transmition of the file data from the C180 task.
{
{ PERMANENT_FILE_TYPE: (output) This parameter indicates the access type of
{                      the permanent file, i.e. direct or indirect.
{
{ PERMANENT_FILE_STATUS: (output) This parameter indicates wheather the file
{                        is new or if it already exists.
{
{ DEFINE_CONDITION: (output) This parameter indicates the condition of the
{                   define request.  All conditions are remote host definitions
{                   of A170/NOS permanent file manager condition codes.
{

  PROCEDURE define_receive_file (
    permanent_file_info: record
      permanent_file_name: string (31),
      user_or_id: string (9),
      file_cycle: string (3),
      passwords: array [1 .. 2] of string (9),
    recend;
    VAR fet: n7t$fet;
    VAR permanent_file_type: rht$file_type;
    VAR permanent_file_status: rht$file_status_type;
    VAR define_condition: integer);

    CONST
      pfm_fet_extension_length = 10;

    TYPE nonfast_attach_set = SET of 1 .. 5;

    VAR
      i: integer,
      dc_file_name: utt$dc_name;

{ Initialize the fet that identifies the file to be used as a receiving file.

    FOR i := 1 TO 22 DO
      fet.fet1_22 [i] := 0;
    FOREND;
    fet.completed := TRUE;
    utp$convert_string_to_file_name (permanent_file_info.permanent_file_name, dc_file_name);
    fet.filename := dc_file_name;
    fet.user_processing := FALSE;
    fet.error_processing := TRUE;
    fet.extension_length := pfm_fet_extension_length;

{ Set fill8 to not allow attach of NOS fast attach files.

    fet.fill8 := $nonfast_attach_set [4];
    fet.pfn := dc_file_name;
    utp$convert_string_to_file_name (permanent_file_info.user_or_id,
          dc_file_name);
    fet.optional_un := dc_file_name;
    utp$convert_string_to_file_name (permanent_file_info.passwords [1] (1, 7),
         dc_file_name);
    fet.file_password := dc_file_name;
    fet.file_mode := n7c$pfm_m_write;

{ Determine if the permanent file to be replaced exists.

    n7p$pfm (n7c$pfm_define, fet);
    CASE fet.response_code OF

    = n7c$pfm_ok =         { A new permanent file was created.
      permanent_file_type := direct;
      permanent_file_status := new;

    = n7c$pfm_file_already_permanent =   { Permanent file found in user catalog.
      permanent_file_status := old;
      n7p$pfm (n7c$pfm_attach, fet);
      CASE fet.response_code OF
      = n7c$pfm_ok =
        permanent_file_type := direct;
        permanent_file_status := new;
      = n7c$pfm_file_not_found =
        fet.response_code := n7c$pfm_ok;
        permanent_file_type := indirect;
      ELSE
        ;
      CASEND;

    = n7c$pfm_illegal_user_access =    { User not validated for direct file access use.
      permanent_file_status := old;
      permanent_file_type := indirect;
      fet.response_code := n7c$pfm_ok;

    = n7c$pfm_illegal_request =    { File maybe in alternate user catalog.
      n7p$pfm (n7c$pfm_attach, fet);
      CASE fet.response_code OF
      = n7c$pfm_ok =
        permanent_file_type := direct;
        permanent_file_status := new;
      = n7c$pfm_file_not_found =
        fet.response_code := n7c$pfm_ok;
        permanent_file_type := indirect;
        permanent_file_status := old;
      ELSE
        ;
      CASEND;

    ELSE
      ;
    CASEND;
    map_pfm_code_to_rh_code (fet.response_code, define_condition);

  PROCEND define_receive_file;

?? TITLE := ' DISPOSE_FILES' ??
?? SET (LIST := ON) ??
?? EJECT ??
{
{       The purpose of this procedure is to dispose the file(s) used in
{ replacing a file.  The final disposition of the file(s) is dependent on
{ the transmission status, the file type, and the status of the permanent
{ file.
{
{       DISPOSE_FILES (LF_FET,PERMANENT_FILE_TYPE,PERMANENT_FILE_STATUS,
{                          TRANSMISSION_STATUS,DISPOSE_CONDITION)
{
{ LF_FET: (input) This parameter specifies the fet which identifies the file(s)
{         which is/are to be disposed.
{
{ PERMANENT_FILE_TYPE: (input) This parameter indicates the access type of
{                      the permanent file, i.e. direct or indirect.
{
{ PERMANENT_FILE_STATUS: (input) This parameter indicates wheather the
{                        permanent file is new or if it existed before
{                        the replace invokation.
{
{ TRANSMISSION_STATUS: (input) This parameter indicates the status of the
{                      transfer of the file from the C180 task to the A170
{                      replace receive file.
{
{ DISPOSE_CONDITION: (output) This parameter indicates the condition of
{                    the dispose request.  All conditions are remote host
{                    definitions of A170/NOS permanent file manager cond-
{                    ition codes.
{

  PROCEDURE dispose_files (VAR lf_fet: n7t$fet;
    permanent_file_type: rht$file_type;
    permanent_file_status: rht$file_status_type;
    transmission_status: rht$trans_status_type;
    VAR dispose_condition: integer);

    VAR
      i: integer,
      pf_fet: n7t$fet,
      inpfn: utt$dc_name,
      outfn: utt$dc_name;

{ Initialize the permanent file's fet.

    pf_fet.fet0 := 0;
    FOR i := 1 TO 22 DO
      pf_fet.fet1_22 [i] := 0;
    FOREND;
    pf_fet.completed := TRUE;

    IF permanent_file_type = direct THEN
      IF permanent_file_status = old THEN
        IF transmission_status = ok THEN
          inpfn := lf_fet.filename;
          outfn := lf_fet.pfn;
          dispose_condition := rhc$ok;
        ELSE
          pf_fet.filename := lf_fet.pfn; { File not transmitted.
          n7p$cio (pf_fet, n7c$cio_return); { Return the old attached file.
        IFEND;
      ELSE
        IF transmission_status = ok THEN
          dispose_condition := rhc$ok; { The new file is ok.
        ELSE
          pf_fet.filename := lf_fet.pfn; { The new file was not transmitted ok.
          n7p$pfm (n7c$pfm_purge, pf_fet); { Purge the new file.
        IFEND;
      IFEND;
    ELSE
      IF transmission_status = ok THEN
        n7p$pfm (n7c$pfm_replace, lf_fet); { Replace indirect with new local.
        map_pfm_code_to_rh_code (lf_fet.response_code, dispose_condition);
      IFEND;
    IFEND;
    n7p$cio (lf_fet, n7c$cio_return); { Return the local file.

  PROCEND dispose_files;


?? TITLE := 'EXTERNALS REFERENCED BY NOS/BE PROCEDURES' ??
?? SET (LIST := ON) ??
?? EJECT ??
*copyc zutps2d
*copyc rhc$nosbe_pf_error_codes

  CONST
    local_file_name1 = 32322210241520(8); {ZZRHTMP}

  TYPE
{ Type definition for NOS/BE 9 character display code name.}
    dc_name9 = array [1 .. 1] OF packed array [0 .. 9] OF 0 ..3f(16),
{ Type definition of NOS/BE 3 character display code cycle.}
    dc_cycle = array [1 .. 1] OF packed array [0 .. 9] OF 0 .. 3f(16);

?? TITLE := 'LOCAL_FILE_REQUEST' ??
?? SET (LIST := ON) ??
?? EJECT ??

{     The purpose of this procedure is to create local file to receive
{ data from the C180 partner task.
{
{      LOCAL_FILE_REQUEST (LOCAL_FILE_NAME, REQUEST_STATUS)
{
{ LOCAL_FILE_NAME: (input) This parameter gives the name to be used for
{                  creating a local file.
{
{ REQUEST_STATUS: (output) This parameter indicates the condition of creating
{         a local file.
{

  PROCEDURE local_file_request (
    local_file_name: utt$dc_name;
    VAR request_status: integer);

    TYPE
      request_parameter_block = PACKED RECORD
        local_file_name: utt$dc_name,
        status_returned: 0 .. 1ffff(16),
        complete: boolean,
        flags59_48: 0 .. 0fff(16),
        reserve1: 0 .. 0fff(16),
        flags35_32: 0 .. 0f(16),
        pf_rms_flag: boolean,
        flags30_12: 0 .. 7ffff(16),
        device_type_allocation: 0 .. 0fff(16),
      RECEND;

    VAR
      req_param_block: request_parameter_block,
      abnormal_req_status_msg: string (33),
      string_length: integer;

  PROCEDURE [XREF] request ALIAS 'rhpreq' (rpb: request_parameter_block);


{ initialize the request parameter block to create a local file.

    log_status (dayfile_log_and_display, 'Request a local file.');
    req_param_block.local_file_name := local_file_name;
    req_param_block.status_returned := 0;
    req_param_block.complete := FALSE;
    req_param_block.flags59_48 := 0;
    req_param_block.reserve1 := 0;
    req_param_block.flags35_32 := 0;
    req_param_block.pf_rms_flag := TRUE;
    req_param_block.flags30_12 := 0;
    req_param_block.device_type_allocation := 0;

{ Request a local file

    request (req_param_block);
    IF req_param_block.status_returned <> 0 THEN
      abnormal_req_status_msg (1, 30) := 'REQUEST abnormal condition = ';
      STRINGREP (abnormal_req_status_msg (30, 3), string_length,
            req_param_block.status_returned);
      log_status (dayfile_log_and_display, abnormal_req_status_msg (1,
            29 + string_length));
      request_status := req_param_block.status_returned;
    ELSE
      request_status := rhc$ok;
    IFEND;

  PROCEND local_file_request;

?? TITLE := 'ATTACH FILE' ??
?? SET (LIST := ON) ??
?? EJECT ??

{     The purpose of this procedure is to attach a permanent file.
{
{      ATTACH_FILE (PERMANENT_FILE_INFO, LOCAL_FILE_NAME, ATTACH_CONDITION)
{
{ PERMANENT_FILE_INFO: (input) This parameter contains all information
{                      required to identify the permanent file to attach.
{
{ LOCAL_FILE_NAME: (input) This parameter gives the name of the local file.
{
{ ATTACH_CONDITION (output) This parameter indicates the condition of the
{                   attach request.  All conditions are remote host definitions
{                   of NOS/BE permanent file manager condition codes.
{

  PROCEDURE attach_file (
    permanent_file_info: record
      permanent_file_name: string (31),
      user_or_id: string (9),
      file_cycle: string (3),
      passwords: array [1 .. 2] of string (9),
    recend;
    local_file_name: utt$dc_name;
    VAR attach_condition: integer);

    VAR
      req_permanent_file_name: array [1 .. 4] OF packed
                               array [0 .. 9] OF 0 .. 3f(16),
      req_owner_identification: dc_name9,
      req_password1: dc_name9,
      req_password2: dc_name9,
      req_cycle: dc_cycle,
      return_code: 0 .. 1ff(16),
      dc_string_word_index: integer,
      dc_string_char_index: 0 .. 9,
      source_index: ost$string_index,
      eol: boolean;

  PROCEDURE [XREF] attach ALIAS 'rhpatt' (
    local_file_name: utt$dc_name;
    permanent_file_name: array [1 .. 4] OF packed array [0 .. 9] OF 0 .. 3f(16);
    owner_identification: dc_name9;
    file_cycle: dc_cycle;
    password1: dc_name9;
    password2: dc_name9;
    VAR attach_condition: 0 .. 1ff(16));

{ Convert parameters to display code.

    log_status (dayfile_log_and_display, 'Attach the permanent file.');
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := TRUE;
    utp$convert_string_to_dc_string (utc$ascii64, req_permanent_file_name,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.permanent_file_name,
          source_index, eol);
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64, req_owner_identification,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.user_or_id, source_index, eol);
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64, req_password1,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.passwords [1], source_index, eol);
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64, req_password2,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.passwords [2], source_index, eol);
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64, req_cycle,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.file_cycle, source_index, eol);

{ Attach the file.

    attach (local_file_name, req_permanent_file_name, req_owner_identification,
            req_cycle, req_password1, req_password2, return_code);

    map_pfm_code_to_rh_code (return_code, attach_condition);

  PROCEND attach_file;

?? TITLE := 'CATALOG_FILE' ??
?? SET (LIST := ON) ??
?? EJECT ??

{
{      The purpose of this procedure is to make an existing local file
{ a permanent file by creating entries in permanent file manager tables.
{ A permanent file is known in these tables by a permanent file name unique
{ within an owner ID.  As many as five cycles can exist with the same
{ permanent file name and ID.
{
{      CATALOG_FILE (PERMANENT_FILE_INFO, LOCAL_FILE_NAME, CATALOG_CONDITION)
{
{ PERMANENT_FILE_INFO: (input) This parameter contains all information
{                      required to identify the permanent file to catalog.
{
{ LOCAL_FILE_NAME: (input) This parameter gives the name of the local file.
{
{ CATALOG_CONDITION: (output) This parameter indicates the condition of the
{                   catalog request.  All conditions are remote host definitions
{                   of NOS/BE permanent file manager condition codes.
{

  PROCEDURE catalog_file (
    permanent_file_info: record
      permanent_file_name: string (31),
      user_or_id: string (9),
      file_cycle: string (3),
      passwords: array [1 .. 2] of string (9),
    recend;
    local_file_name: utt$dc_name;
    VAR catalog_condition: integer);


    VAR
      req_permanent_file_name: array [1 ..4] OF packed
                               array [0 .. 9] OF 0 .. 3f(16),

      req_owner_identification: dc_name9,
      req_password1: dc_name9,
      req_password2: dc_name9,
      req_cycle: dc_cycle,
      return_code: 0 .. 1ff(16),
      dc_string_word_index: integer,
      dc_string_char_index: 0 .. 9,
      source_index: ost$string_index,
      eol: boolean;

  PROCEDURE [XREF] catalog ALIAS 'rhpcat' (
    local_file_name: utt$dc_name;
    permanent_file_name: array [1 .. 4] OF packed array [0 .. 9] OF 0 .. 3f(16);
    owner_identification: dc_name9;
    file_cycle: dc_cycle;
    password1: dc_name9;
    password2: dc_name9;
    VAR catalog_condition: 0 .. 1ff(16));

{ Convert parameters to display code.

    log_status (dayfile_log_and_display, 'Catalog the permanent file.');
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := TRUE;
    utp$convert_string_to_dc_string (utc$ascii64, req_permanent_file_name,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.permanent_file_name,
          source_index, eol);
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64,
          req_owner_identification,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.user_or_id, source_index, eol);
    dc_string_word_index :=1;
    dc_string_char_index :=0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64, req_cycle,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.file_cycle, source_index, eol);

{ Initialize passwords.
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64,
          req_password1,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.passwords [1], source_index, eol);
    dc_string_word_index := 1;
    dc_string_char_index := 0;
    source_index := 1;
    eol := FALSE;
    utp$convert_string_to_dc_string (utc$ascii64,
          req_password2,
          dc_string_word_index, dc_string_char_index,
          permanent_file_info.passwords [2], source_index, eol);

    catalog (local_file_name, req_permanent_file_name, req_owner_identification,
            req_cycle, req_password1, req_password2, return_code);
    map_pfm_code_to_rh_code (return_code, catalog_condition);

  PROCEND catalog_file;

?? TITLE := 'FORM_APPLICATION_NAMES' ??
?? SET (LIST := ON) ??
?? EJECT ??
{
{       The purpose of this procedure is to generate the partner job and
{ requesting task application names for use by the partner job.
{
{       FORM_APPLICATION_NAMES (APPLICATION_NAMES)
{
{ APPLICATION_NAMES: (output) This parameter contains the generated partner job
{                    and requesting task application names.
{

  PROCEDURE form_application_names (VAR application_names:
    rht$mli_application_names);

    CONST
      a170_application_name_length = 1,
      cpm_function_code_13 = 11;

    TYPE
      getjn_cpmf13_job_name_word_rec = packed record
        jobname: 0 .. 3ffffffffff(16),
        zero: 0 .. 3ffff(16),
      recend;

    VAR
      task_application_name_file: file,
      getjn_cpmf13_job_name_word: getjn_cpmf13_job_name_word_rec;

    cpmfp (cpm_function_code_13, ^getjn_cpmf13_job_name_word);
    application_names.application.application_name :=
          getjn_cpmf13_job_name_word.jobname;
    bi#open (task_application_name_file, 'input', old#, input#, asis#);
    bi#get (task_application_name_file, ^application_names.destination.
          application_name, a170_application_name_length);
    bi#close (task_application_name_file, first#);

  PROCEND form_application_names;

MODEND rhm$get_replace_exec;
