/*****************************************************************************/
/* Test case name :  NEXTFREE.CMD       Find Next free network drive         */
/*                                                                           */
/* Author : Dan Kinnunen                                                     */
/*                                                                           */
/* Test case description :                                                   */
/*      Find the next unused drive available, starting with the C drive .    */
/*      The 'L:' drive and the 'T:' drives will NOT be returned by this      */
/*      routine.  They are special purpose drives that are to be used        */
/*      only to link to the log drive and the testcase drive.                */
/*                                                                           */
/* Hardware configuration requirements :                                     */
/*      Any OS/2 system                                                      */
/*                                                                           */
/* Software configuration requirements :                                     */
/*      Any OS/2 system                                                      */
/*                                                                           */
/* Dependencies (if applicable)                                              */
/*      To call this routine from another REXX exec, this file must          */
/*      be in a directory pointed to by the PATH statemment, OR be in        */
/*      the current directory.                                               */
/*                                                                           */
/* Execution instructions :                                                  */
/*      Here is an example of how you might call this function               */
/*      from a REXX exec.                                                    */
/*                                                                           */
/*            ndrive = nextfree()                                            */
/*            if ndrive = 0 then                                             */
/*               say 'There are NO free drives for the NET USE '             */
/*            else                                                           */
/*               'NET USE 'ndrive' FILE_ALIAS'                               */
/*                                                                           */
/*                                                                           */
/* Success Criteria :                                                        */
/*      One of these outcomes will occur when issuing the above              */
/*      command:                                                             */
/*                                                                           */
/*       returned value = 0  - if no drive was found                         */
/*                      = 'drive_letter:'                                    */
/*                           - where drive_letter represents the actual      */
/*                             drive that was found. (eg. 'M:' might         */
/*                             be the string returned from the call)         */
/*                             (NOTE: the 'L:' and 'T:' drives will          */
/*                             not be returned, even if they are free,       */
/*                             since they are only to be used for            */
/*                             linking to the Testcase and Log drives.       */
/*                                                                           */
/*                                                                           */
/* Change activity : mm/dd/yy and tester's initials                          */
/*      03/07/96  DRK   - Initial version                                    */
/*                                                                           */
/*****************************************************************************/

CALL RxFuncAdd 'SysDriveMap', 'RexxUtil', 'SysDriveMap'

/*------------------------------------------------------------------------------*/
/*  Call SysDriveMap with 'FREE' option. this will                              */
/*  return (in 'map' a string of all available drives, separated by spaces.     */
/*------------------------------------------------------------------------------*/
map = SysDriveMap('C:', 'FREE')

/*------------------------------------------------------------------------------*/
/*  Parse the 1st drive in the list into the NEXT_FREE variable                 */
/*      (THE_REST variable will contain the rest of the list of                 */
/*         available drive letters                                              */
/*------------------------------------------------------------------------------*/
parse upper var map next_free the_rest
next_free = strip(next_free)

/*------------------------------------------------------------------------------*/
/*  If the L: drive was found, then get the next available drive                */
/*     letter from THE_REST                                                     */
/*------------------------------------------------------------------------------*/
if next_free = 'L:' then
do
   parse upper var the_rest next_free the_rest
   next_free = strip(next_free)
end /* do */

/*------------------------------------------------------------------------------*/
/*  If the T: drive was found, then get the next available drive                */
/*     letter from THE_REST                                                     */
/*------------------------------------------------------------------------------*/
if next_free = 'T:' then
do
   parse upper var the_rest next_free the_rest
   next_free = strip(next_free)
end /* do */

/*------------------------------------------------------------------------------*/
/*  If NO Drive was found, set returned value to zero                           */
/*------------------------------------------------------------------------------*/
if next_free = '' then next_free = 0

return(next_free)
