example2.nrx      29.11.2002 16:04:11


/*====================================================================*/
/* generated by the classic REXX to NetRexx converter */
/* (c) Thomas.Schneider@Donauland.at */
/*====================================================================*/
/* orig. REXX source: example2 */
/* generated at: 2002-09-29 23:42:17 */
/* with: rex_nrx.nrx vs. 4.00 */
/* Rexx2Nrx options: */
/* Vars Localized: NO */
/* IO-method used : 3 ( RexxFile Object oriented ) */
/*====================================================================*/
import Rexx2Nrx.Rexx2RT.SysCmd
import Rexx2Nrx.Rexx2RT.RexxFile
import Rexx2Nrx.Rexx2RT.RexxTime
class example2 uses RexxFile
properties public static
   /* ... Declare Global Exposed File-Descriptors */
      FD_fname = RexxFile Null
      FD_temp_bin= RexxFile.FD("temp.bin")
   /* ... Declare Global File-Names */
   fname = Rexx ''
   /* ... Declare Global Numbers */
   count = int 0
   remaining = int 0
   /* ... Declare Global Strings */
   ok = Rexx ''
   time1 = Rexx ''
   bytes = Rexx " "
   time2 = Rexx ''
   elapsed = Rexx ''
method main(args=String[]) static
arg=Rexx(args) -- program arguments as single string
arg=arg -- avoid NetRexx warning
   say ' '
   say 'This program creates a copy of an existing'
   say 'binary file.'
   say 'The result file of the copy is placed in'
   say 'this directory, under the name TEMP.BIN.'
   say ' '
   say 'WARNING! This example takes forever to execute'
   say 'with large files..'
   loop until fname.length() \= 0
      say ' '
      say 'Please enter a valid file name..'
      say ' '
      say 'Example: c:\\filename.exe'
      say ' '
      ok = RexxFile.FD().charout("File name>")
      fname = RexxFile.FD().linein()
      FD_fname = RexxFile.FD(fname)
      if FD_fname.query_exists().length() = 0 then do
         fname = ""
         FD_fname = RexxFile.FD(fname)
         say "That file doesn't exists."
      end /*if*/
   end /* loop */
   RexxFile.FD("temp.bin").delete() /* == '@del'... */
   time1 = RexxTime.time('R')
   ok = FD_fname.open("read")
   ok = FD_temp_bin.open("write")
   count = 0
   loop while FD_fname.chars() > 0
      bytes = FD_fname.charin()
      count = count + bytes.length()
      remaining = FD_temp_bin.charout(bytes)
      if remaining > 0 then do
         say 'cannot copy:' count||'.th byte:' bytes
         exit 99
      end /*if*/
   end /* loop */
   FD_temp_bin.close()
   say count 'bytes copied.'
   time2 = RexxTime.time('E')
   elapsed = (time2 - time1).format(4,3)
   say 'copying used:' elapsed 'seconds.'