/* hd Filecopy-test */

/* My First attempt at AREXX !!!                                           */
/* This is an example of AREXX used as a scripting language.  As you can   */  
/* see it's a lot more powerful than AmigaDOS scripts!  By the way, AREXX  */
/* is a LOT MORE than just a scripting language.  Give it a TRY !!         */
/* Bob Trembler (OLS717) Feb. 1988                                         */

/* trace ?r */        /* uncomment this line to trace the program */


signal on break_c     /* Set up a break on ctrl - c */

address command       /* shell out to a HOST environment (DOS in this case)*/


call intro            /* function call see below */

call GetFname         /* function call see below */
call Get#Times        /* function call see below */
call FindF_Name       /* function call see below */

do i = 1 to times     /* Main file copying loop  */

   if i > 1 then say 'Here we go again .............'

   say i 'times'

   say 'Now copying' filename 'to dh0:t'
       'copy' filename 'to dh0:t'  /* copy is the DOS copy comand passed  */
   say ' '                         /* out to the HOST address             */

   say 'Now copying file back to dh1:tmp'
   'copy dh0:t/'file 'to dh1:tmp'
   say ' '

   say 'Now removing 'file 'from dh0:'
   'delete dh0:t/'file
   say ' '

   say 'Now removing 'file 'from dh1:tmp'
   'delete dh1:tmp/'file
   say ' '

   say ' '
end
say '................ ALL DONE ...............'
exit                  /* end of main program */

/*==============*/
/* Functions    */
/*==============*/

Intro:
'cls'                 /* or 'echo' '"*'||'0c'x||'"' */

say '-------------- HDISK test ------------'
say 'This program will test file copying on you Amiga Hardisk'
say 'It will copy the file you disgnate back and forth (dh1: to dh0: etc)'
say 'the number of times you request.  A very "Dumb Program", YES, but I' 
say 'learned a lot about AREXX by playing around with it.'
say ' '
say 'It assumes that you have a dh0: and a second partition called dh1:'
say 'You must also have a directory on partition dh1: called TMP'
say ' '
say 'If you do not have a TMP dir on dh1:,'
say 'hit CTRL-C now to ABORT the program  '
return

GetFName:
   DROP filename
   say 'What file do you want to USE for the HDtest?'
   say 'PLEASE use the COMPLETE path name'; pull filename .
   if ~exists(filename) then do;
      say ' '
      say 'The FILE ====>' filename 'does NOT exist try again!! '
      say ' '
      call GetFName   /* recursion ? */
      end
   return filename

Get#Times:
   say ' '
   say 'How many times do you want to copy the file back and forth ?'
   say 'Enter a number 1 to 25'; pull times .
   return times

FindF_Name:
   pos# = lastpos("/",filename) + 1 /* Built-in AREXX function lastpos() */

   if pos# = 1 then
      pos# = lastpos(":",filename) + 1

   file = substr(filename,pos#)     /* Built-in AREXX function substr()  */
   return file

break_c:
   say 'Control-C break'
   exit
