example2.cmd      29.11.2002 16:04:11


/* The corresponding OS/2 REXX procedure of
   the example2.nrx (see that).
   Note: The pure REXX version is 5.5
   times faster on my system:
   486dx4-120, 32meg RAM, 2xFireball 1.2g HD. */

/***********************************************************/
/* cannot recall where I got this example from */
/* timing added, Th. Schneider, 01.08.2001 */
/* note that RexxFile.charin() reads a bunch af chars */
/* at once to get efficient IO ! */
/***********************************************************/

 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..'
 do until length(fname) \= 0
   say ' '
   say 'Please enter a valid file name..'
   say ' '
   say 'Example: c:\filename.exe'
   say ' '
   ok=charout(,"File name>")
   fname = linein()
   if length(stream(fname,"c", "query exists")) = 0 then
   do
     fname = ""
     say "That file doesn't exists."
   end
 end

 "@del temp.bin"
 time1=time('R') /* reset timer */
 ok = stream(fname,"c","open read")
 ok = stream("temp.bin","c","open write")

 count = 0

 do while chars(fname) > 0
  bytes = charin(fname)

  /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
  /* here is the difference: in RexxFile, the method */
  /* charin(file) reads by default a bunch (chunk) */
  /* of characters, not a single character, at once !! */
  /* the differenes in run-time are significant !!*/
  /* The Rexx to NetRexx converter will give an appropriate */
  /* attention-message to warn the user !!*/
  /* Th. Schneider, 02.11.2001 */
  /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/

  count = count + length(bytes)

  remaining = charout("temp.bin", bytes)
  if remaining > 0 then do
    say 'cannot copy:' count'.th byte:' bytes
    exit 99
  end
 end
 call close("temp.bin")
 say count 'bytes copied.'
 time2=time('E') /* get elapsed time */
 elapsed= format(time2-time1,4,3) /* get elapsed time */
 say 'copying used:' elapsed 'seconds.'