home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxlbox13.zip / sample2.cmd < prev    next >
OS/2 REXX Batch file  |  1998-03-01  |  6KB  |  153 lines

  1. /* ------------------------------------------------------------------ */
  2. /*                                                                    */
  3. /*             sample program to show the use of RXLBOX               */
  4. /*                                                                    */
  5. /*   This program uses the queue to create dynamic menus on the fly   */
  6. /*                                                                    */
  7. /* 26.04.1997 /bs                                                     */
  8. /*  - changed a bug in the handling of filenames with imbedded blanks */
  9. /*                                                                    */
  10. /*                                                                    */
  11. /* ------------------------------------------------------------------ */
  12.  
  13.                     /* load REXXUTIL                                  */
  14.                     /* note: REXXUTIL is only necessary for the       */
  15.                     /*       functions to get the data for the        */
  16.                     /*       dynamic menus!                           */
  17.                     /*       RXLBOX does not use REXXUTIL!            */
  18.  
  19.   call rxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  20.   call SysLoadFuncs
  21.  
  22.                     /* search the program                             */
  23.                     /* The routine SearchPrograms sets the variables  */
  24.                     /* MENUPROG and MENUPROGPATH.                     */
  25.   menuProgName = 'RXLBOX.CMD'
  26.   call SearchProgram
  27.  
  28.                     /* collect the data for the menus                 */
  29.   say 'Collecting the data for the menus. Please wait ...'
  30.  
  31.                     /* the nain menu is a menu of the existing drives */
  32.   driveString = SysDriveMap()
  33.   driveStem.0 = 0
  34.  
  35.                     /* ignore drives which are not ready              */
  36.   do i = 1 to words( driveString )
  37.     curDrive = word( driveString,i )
  38.     driveDesc = SysDriveInfo( curDrive )
  39.     if driveDesc <> '' then
  40.     do
  41.       j = driveStem.0 +1
  42.       driveStem.j = driveDesc
  43.       driveStem.0 = j
  44.     end /* if driveDesc <> '' then */
  45.   end /* do i = 1 to words( driveString ) */
  46.  
  47.                     /* the sub menus contain the files in the current */
  48.                     /* directories of the existing drives             */
  49.   do i = 1 to driveStem.0
  50.     curDrive = word( driveStem.i, 1 )
  51.     dirStemName = 'dirStem.' || curDrive || '.'
  52.     call SysFileTree curDrive || '\*.*', dirStemName
  53.   end /* do i = 1 to driveStem.0 */
  54.  
  55.                     /* flush the queue                                */
  56.   do while queued() <> 0
  57.     parse pull
  58.   end /* do while queued() <> 0 */
  59.  
  60.                     /* create the menu definition for the main menu   */
  61.   queue '[*DriveMenu*]'
  62.   queue 'Title1=Detected drives on your system'
  63.   queue 'Title2=Note that there is no help available'
  64.   queue 'StatusLine=This is a dynamicly created menu'
  65.   queue 'Title3 = Drv Free bytes   total bytes  volume label                       ' || 'FF'x
  66.  
  67.  
  68.   do i = 1 to driveStem.0
  69.     curDrive = word( driveStem.i, 1 )
  70.     driveMenuName = 'Drive_' || curDrive
  71.  
  72.     queue 'MenuItem.# = ' || driveStem.i
  73.     queue 'Action.# = ' || '#GOTOMenu() ' driveMenuName
  74.   end /* do i = 1 to driveStem.0 */
  75.  
  76.                     /* create the menus for the directory listings    */
  77.   do i = 1 to driveStem.0
  78.     curDrive = word( driveStem.i, 1 )
  79.     driveMenuName = 'Drive_' || curDrive
  80.  
  81.     queue '[*' || driveMenuName || '*]'
  82.     queue 'Title1=Directory listing of the current directory of drive' curDrive
  83.     queue 'Title2=Note that there is no help available'
  84.  
  85.     call setlocal
  86.     tCurDir = directory( curDrive || '\' )
  87.  
  88.     if length( tCurDir ) > 50 then
  89.       tTitle3 = 'Current dir is "' || substr( tCurDir, 50 ) || '"'
  90.     else
  91.       tTitle3 = 'Current dir is "' || directory( curDrive ) || '"'
  92.  
  93.     queue 'Title3=' tTitle3
  94.  
  95.     tStatusLine = "{'Current entry is ' || fileSpec( 'N', !curMenuEntry ) || ' (Attr.: ' || word( !curMenuAction,4 ) || ')' }"
  96.  
  97.     call endlocal
  98.     queue 'StatusLine='tstatusLine
  99.  
  100.     do j = 1 to dirStem.curDrive.0
  101.       queue 'MenuItem.# = ' || substr( dirStem.curDrive.j,38 )
  102.       queue 'Action.# = ' || dirStem.curDrive.j
  103.     end /* do j = 1 to dirStem.curDrive.0 */
  104.  
  105.   end /* do i = 1 to driveStem.0 */
  106.  
  107.                     /* temporary change the PATH                      */
  108.                     /* (external REXX routines must be in a directory */
  109.                     /*  in the PATH!)                                 */
  110.   oldPath = value( 'PATH', , 'OS2ENVIRONMENT' )
  111.   call value 'PATH', menuProgPath || ';' || oldPath, 'OS2ENVIRONMENT'
  112.  
  113.   userInput = RXLBOX( 'QUEUE:', 'DriveMenu' )
  114.  
  115.                     /* restore the PATH                               */
  116.   call value 'PATH', oldPath, 'OS2ENVIRONMENT'
  117.  
  118.   say ''
  119.   say 'Result of RxLBox is '
  120.   say '  "' || userInput || '"'
  121.  
  122.                     /* flush the queue                                */
  123.   do while queued() <> 0
  124.     parse pull
  125.   end /* do while queued() <> 0 */
  126. exit
  127.  
  128. /* ------------------------------------------------------------------ */
  129. /* sub routine to search the program RXLBOX.CMD                       */
  130.  
  131. SearchProgram:
  132.  
  133.                     /* search the program RXLBOX.CMD                  */
  134.   menuProg = directory() || menuProgName
  135.   if stream( menuProg , 'c', 'QUERY EXIST' ) = '' then
  136.   do
  137.     parse source . . thisProgram
  138.     menuProg = fileSpec( 'D', thisProgram ) || ,
  139.                fileSpec( 'P', thisProgram ) || ,
  140.                menuProgName
  141.   end /* if stream( menuProg , 'c', 'QUERY EXIST' ) = '' then */
  142.  
  143.   if stream( menuProg , 'c', 'QUERY EXIST' ) = '' then
  144.   do 
  145.     say 'Error: ' || menuProgName || ' not found!'
  146.     exit 255
  147.   end  /* if stream( menuProg , 'c', 'QUERY EXIST' ) = '' then */
  148.   else
  149.     menuProgPath = fileSpec( 'D', menuProg ) || ,
  150.                    fileSpec( 'P', menuProg )
  151.  
  152. RETURN
  153. /* ------------------------------------------------------------------ */