
      $set ans85 noosvs vsc2 mf
      ************************************************************************
      *
      * Copyright (C) 1986-2005 Micro Focus International Limited.
      * All rights reserved.
      *
      * The software and information contained herein are proprietary to, and
      * comprise valuable trade secrets of, Micro Focus International Ltd., 
      * which intends to preserve as trade secrets such software and 
      * information. This software is an unpublished copyright of Micro Focus  
      * and may not be used, copied, transmitted, or stored in any manner.  
      * This software and information or any other copies thereof may not be
      * provided or otherwise made available to any other person.
      *
      * Micro Focus Client-Server Bindings (CSBind)
      *
      * Source Module netxcli.cbl
      *
      * Last Modified on $Date: 2005/12/20 15:34:47 $
      *
      ************************************************************************
      *
      * Start of source module netxcli.cbl
      *
      ************************************************************************
       IDENTIFICATION DIVISION.
       PROGRAM-ID. netxcli.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.

       WORKING-STORAGE SECTION.
       01 SCCS-ID PIC X(40) VALUE "@(#)netxcli.cbl $Revision: 1.4 $".

       01  Input-File-Name             PIC X(20).
       01  ws-rdt-len                  PIC 99.
           88 rdt-ok VALUE 64.

       01  Locals.
           03  Access-Mode             PIC X       COMP-5 VALUE 1.
           03  Buffer-Size             PIC X(4)    COMP-5.
           03  Byte-Count              PIC X(4)    COMP-X.
           03  Prog-Test-State         PIC X       COMP-5 VALUE 0.
               78  Prog-Passed         VALUE       0.
               78  Prog-Failed         VALUE       1.
           03  Deny-Mode               PIC X       COMP-5 VALUE 3.
           03  Device                  PIC X       COMP-5 VALUE 0.
           03  Eof-Flag                PIC X       COMP-5.
           03  File-Details.
               05  File-Size           PIC X(8)    COMP-X.
               05  FILLER              PIC X(8).
           03  File-Handle             PIC X(4).
           03  File-Offset             PIC X(8)    COMP-X VALUE 0.
           03  Flags                   PIC X       COMP-5 VALUE 0.
           03  Transfer-Count          PIC XX      COMP-X VALUE 0.

       COPY "mfclisrv.cpy".

       LINKAGE SECTION.

       01  Input-Rec                   PIC X(1024).

       PROCEDURE DIVISION.

      *-----------------------------------------------------------------
      * Prompt for name of file to be used
      *-----------------------------------------------------------------
           DISPLAY SPACES AT 0101
           DISPLAY "Enter File Name: " WITH NO ADVANCING
           ACCEPT Input-File-Name
           DISPLAY SPACES

           IF Input-File-Name NOT = SPACES
               CALL "CBL_CHECK_FILE_EXIST" USING Input-File-Name
                                                 File-Details

               IF RETURN-CODE NOT = 0
                   DISPLAY "Input file does not exist"
                   MOVE Prog-Failed TO Prog-Test-State
                   EXIT PROGRAM
                   STOP RUN
               END-IF
           ELSE
               DISPLAY
               "Cannot run NETXCLI without a file name being specified"
               EXIT PROGRAM
               STOP RUN
           END-IF

      *-----------------------------------------------------------------
      * 'lnk-client' holds the name 'mfclient'
      * The first time through we initialize the system and establish
      * contact with the server.
      *-----------------------------------------------------------------

           CALL lnk-client USING lnk-param-block

      *-----------------------------------------------------------------
      * Make the user data block (Input-Rec)
      * accesible by assigning them address allocated by 'mfclient'.
      *-----------------------------------------------------------------
           IF start-connection
              SET ADDRESS OF Input-Rec TO lnk-dblock-ptr
           ELSE
              DISPLAY "Error starting connection with server"
              DISPLAY SPACES
              STOP RUN
           END-IF
      *-----------------------------------------------------------------
      * By defaut, the entire buffer is passed from client to server
      * which for this program is 1024 bytes. As most transfers are
      * sending much less data than this, the bulk of the buffer is
      * wasted. To overcme this, we use a feature called Reduced Data
      * Transfer (RDT) to specify just how much of the buffer we wish to
      * use for each transfer.
      *-----------------------------------------------------------------

      *-----------------------------------------------------------------
      * Send contents of user specified file to server application
      * NETXSERV using 1024 byte records
      *-----------------------------------------------------------------
           DISPLAY "Using 1024 byte records"
           DISPLAY SPACES
           MOVE 1024 TO Buffer-Size
           PERFORM Prog-Test
      *-----------------------------------------------------------------
      * Send indicator that we are about to disconnect, and then
      * terminate the client. The server responds by sending the name
      * of the directory into which the file was copied.
      *-----------------------------------------------------------------
           SET use-rdt TO TRUE
           MOVE "END-DEMO" TO  Input-Rec
           MOVE 8 TO lnk-data-length
           MOVE 2 TO lnk-usr-retcode
           PERFORM Write-Record
           MOVE lnk-data-length TO ws-rdt-len
           DISPLAY "Input File: " Input-File-Name
           DISPLAY SPACES
           DISPLAY "Copied To: netxcpfl.dat"
           DISPLAY SPACES
           DISPLAY "Located In: " Input-Rec(1:64)
           DISPLAY SPACES
           DISPLAY "Using: " Transfer-Count " Transfer Operation(s)"
           DISPLAY SPACES
           STOP "Press <Enter> To Terminate Program "
           DISPLAY SPACES
           SET client-ending TO TRUE
           PERFORM Write-Record
      *-----------------------------------------------------------------
      * Normal termination
      *-----------------------------------------------------------------
           DISPLAY "NETXCLI terminated successfully"
           DISPLAY SPACES
           IF rdt-ok
              DISPLAY "USING RDT"
           ELSE
              DISPLAY "RDT NOT USED"
           END-IF
           DISPLAY SPACES
           EXIT PROGRAM
           STOP RUN
           .
      ******************************************************************
       Prog-Test SECTION.
           MOVE 0 TO File-Offset
           MOVE Prog-Passed TO Prog-Test-State
      *-----------------------------------------------------------------
      * Open user specified file. Exit if error.
      *-----------------------------------------------------------------
           CALL "CBL_OPEN_FILE" USING Input-File-Name
                                      Access-Mode
                                      Deny-Mode
                                      Device
                                      File-Handle

           IF RETURN-CODE NOT = 0
               DISPLAY "Could not open input file"
               MOVE Prog-Failed TO Prog-Test-State
               EXIT SECTION
           END-IF
      *-----------------------------------------------------------------
      * File opened OK. Read first record.
      *-----------------------------------------------------------------
           MOVE 0 TO Eof-Flag
           PERFORM Read-Input-File
      *-----------------------------------------------------------------
      * Loop sending records until end of file, using RDT to transfer
      * just the bytes specified in byte-count rather than the whole
      * buffer.
      *-----------------------------------------------------------------
           PERFORM UNTIL Eof-Flag NOT = 0
               SET use-rdt TO TRUE
               MOVE Byte-Count TO lnk-data-length
               MOVE 2 TO lnk-usr-retcode
               PERFORM Write-Record
               IF Prog-Test-State NOT = Prog-Failed
                   PERFORM Read-Input-File
               END-IF
           END-PERFORM
      *-----------------------------------------------------------------
      * Close user specified file
      *-----------------------------------------------------------------
           CALL "CBL_CLOSE_FILE" USING File-Handle
           .
      *-----------------------------------------------------------------
      * Read user specified file using varying sized byte counts
      *-----------------------------------------------------------------
       Read-Input-File SECTION.
           IF File-Offset < File-Size
               MOVE File-Size TO Byte-Count
               SUBTRACT File-Offset FROM Byte-Count

               IF Byte-Count > Buffer-Size
                   MOVE Buffer-Size TO Byte-Count
               END-IF

               CALL "CBL_READ_FILE" USING File-Handle
                                          File-Offset
                                          Byte-Count
                                          Flags
                                          Input-Rec
               ADD Byte-Count TO File-Offset
               ADD 1 TO Transfer-Count
           ELSE
               MOVE 1 TO Eof-Flag
           END-IF
           .
      *-----------------------------------------------------------------
      * Send data to the server program
      *-----------------------------------------------------------------
       Write-Record SECTION.
           CALL lnk-client USING lnk-param-block
           .
      * End of source module netxcli.cbl
