home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxtt33.zip / INSTALL.CMD next >
OS/2 REXX Batch file  |  2000-12-31  |  9KB  |  235 lines

  1. /* ------------------------------------------------------------------ */
  2. /* CMD to create (or update) the object for REXX Tips & Tricks        */
  3. /*                                                                    */
  4. /* The default is on the desktop, but if you have already an object   */
  5. /* for an older version of RXT&T this program will update that        */
  6. /* object.                                                            */
  7. /*                                                                    */
  8. /* Usage: INSTALL {os2BootDrive}                                      */
  9. /*                                                                    */
  10. /* where: os2BootDrive - drive specifier for the boot drive           */
  11. /*                       (e.g. C:, default: Search the boot drive)    */
  12. /*                                                                    */
  13. /*                                                                    */
  14. /* Initial Release: 26.12.1995 /bs                                    */
  15. /*                                                                    */
  16. /* Last update:     24.10.1997 /bs                                    */
  17. /*                  29.12.2000 /bs                                    */
  18. /*                   - added more error checking                      */
  19. /*                                                                    */
  20. /*                                                                    */
  21. /* ------------------------------------------------------------------ */
  22.  
  23.                         /* check & process the parameter              */
  24.   parse arg OS2BootDrive
  25.   OS2BootDrive = substr( translate( strip( OS2BootDrive ) ),1,2 )
  26.   if OS2BootDrive <> '' then
  27.   do
  28.     if stream( OS2BootDrive || '\CONFIG.SYS', 'c', 'QUERY EXIST' ) = '' then
  29.     do
  30.                         /* show the usage                             */
  31.       say 'Usage: INSTALL {os2BootDrive}'
  32.       say ''
  33.       say 'Default: Search the OS/2 boot drive'
  34.       exit 253
  35.     end /* if stream( ... */
  36.   end /* if OS2BootDrive <> '' then */
  37.  
  38.                         /* init the return code                       */
  39.   thisRC = 255
  40.  
  41.                         /* init some global variables                 */
  42.   fileMask =          'RXTT*.INF'
  43.   fixedName =         'RXTT'
  44.   defaultTitle =      'REXX Tips & Tricks'
  45.   curObjectID =       '<RXTT>'
  46.   defaultLocation =   '<WP_DESKTOP>'
  47.  
  48.                         /* show the logo                              */
  49.   say ''
  50.   say center( 'Installation program for REXX Tips & Tricks', 79 )
  51.   say center( '===========================================', 79 )
  52.   say ''
  53.  
  54.                         /* install some error handler                 */
  55.   signal on halt name UserAbort
  56.   signal on syntax name RexxUtilNotFound
  57.  
  58.   say ' Loading REXXUTIL ... '
  59.   
  60.                         /* load REXXUTIL                              */
  61.   call rxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  62.   call SysLoadFuncs
  63.  
  64.                         /* turn on the default error handler again    */
  65.   signal off Syntax
  66.  
  67.                         /* search the OS/2 boot drive                 */
  68.   if OS2BootDrive = '' then
  69.   do
  70.     say ' Searching the boot drive. Please wait ...'
  71.     OS2BootDrive = SearchbootDrive()
  72.  
  73.     say ' ... the OS/2 bootdrive is "' || OS2BootDrive || '".'
  74.   end /* if OS2BootDrive = '' then */
  75.  
  76.  
  77.   say ' Searching the newest version of ' || defaultTitle || ' ...'
  78.   say ' (only in the current directory!)'
  79.  
  80.                         /* search RXTT*.INF                           */
  81.   call SysFileTree fileMask, 'infFileStem' , 'FO'
  82.  
  83.                         /* get the newest version                     */
  84.   curInfFileVersion = '00'
  85.  
  86.   do i = 1 to infFileStem.0
  87.     parse upper var infFileStem.i (fixedName) infFileVersion '.' .
  88.     if infFileVersion > curInfFileVersion then
  89.     do
  90.       curInfFile = infFileStem.i
  91.       curInfFileVersion = infFileVersion
  92.     end /* infFileVersion > curInfFileVersion then */
  93.   end /* do i = 1 to infFileStem.0 */
  94.  
  95.                         /* check, if we found a version of RXT&T      */  
  96.   if curInfFileVersion <> '00' then
  97.   do
  98.     curtitle = strip( getTitle( '"' || curInfFile || '"' ) )
  99.     if curTitle <> '' then 
  100.     do
  101.  
  102.       say ' ... "' || curTitle || '" found.'
  103.       say ''
  104.       say ' Should I create an object for "' || curTitle || '" (Y/n)? '
  105.       userResponse = substr( strip( translate( SysGetKey( 'NOECHO' ) ) ),1,1 )
  106.       if UserResponse = 'N' then 
  107.         signal UserAbort
  108.  
  109.       curTitle = translate( curTitle, '^', ',' )
  110.   
  111.       say ' Creating the object ...'
  112.  
  113.                         /* create the object                          */
  114.       tempRC = SysCreateObject( 'WPProgram' ,,
  115.                                 curTitle ,,
  116.                                 defaultLocation ,,
  117.                                'EXENAME=' || OS2BootDrive || '\OS2\VIEW.EXE;' || ,
  118.                                'PARAMETERS="' || curInfFile || '";' || ,
  119.                                'STARTUPDIR=' || OS2BootDrive || '\;' || ,
  120.                                'TITLE=' || curTitle || ';' || ,
  121.                                'OBJECTID=' || curObjectID || ';' ,,
  122.                                'U' )
  123.  
  124.       if tempRC = 1 then
  125.       do
  126.         thisRC = 0
  127.         say ' ... object created.'
  128.       end /* if tempRC = 1 then */
  129.       else
  130.         say 'Error creating the object!'
  131.  
  132.     end /* if curTitle <> '' then */
  133.     else
  134.     do
  135.       say '07'x
  136.       say ' Error: Error reading the file'
  137.       say
  138.       say '  "' || curInfFile || '"!'
  139.       say
  140.       say ' Please close RXT&T if it''s open and try it again.'
  141.     end /* else */
  142.   end /* if curInfFileVersion <> '00' then */
  143.   else
  144.   do
  145.     say '07'x
  146.     say ' Error: ' || defaultTitle || ' not found!'
  147.     say 
  148.     say ' Please make sure that the file RXTT*.INF is in the current directory'
  149.     say ' and try it again.'
  150.   end /* else */
  151. exit thisRC
  152.  
  153. /* ------------------------------------------------------------------ */
  154. /* function:   search the boot drive                                  */
  155. /*                                                                    */
  156. /* parameters: none                                                   */
  157. /*                                                                    */
  158. /* returns:    boot drive (e.g. "C:")                                 */
  159. /*                                                                    */
  160. SearchBootDrive: PROCEDURE 
  161.  
  162.                         /* install a local error handler              */
  163.   signal on syntax name BootDriveNotFound
  164.  
  165.                     /* try the new function from the new REXXUTIL DLL */
  166.   OS2BootDrive = SysBootDrive()
  167.  
  168. BootDriveNotFound:
  169.  
  170.   if symbol( 'OS2BootDrive' ) <> 'VAR' then
  171.   do
  172.                         /* new REXXUTIL DLL not found  --             */
  173.                         /* use the old method                         */
  174.     OS2BootDrive = substr( value( 'RUNWORKPLACE' ,, 'OS2ENVIRONMENT' ), 1,2 )
  175.  
  176.     if OS2BootDrive = '' then
  177.       OS2BootDrive = substr( value( 'COMSPEC' ,, 'OS2ENVIRONMENT' ), 1,2 )
  178.  
  179.     if OS2BootDrive = '' then
  180.       OS2BootDrive = 'C:'
  181.  
  182.   end /* if symbol( 'OS2BootDrive' ) <> 'VAR' then */  
  183. RETURN OS2BootDrive
  184.  
  185. /* ------------------------------------------------------------------ */
  186. /* function:   get the title of an INF file                           */
  187. /*                                                                    */
  188. /* parameters: fully qualified path of the INF file                   */
  189. /*                                                                    */
  190. /* returns:    the title of the INF file                              */
  191. /*             or an empty string in case of an error                 */
  192. /*                                                                    */
  193. GetTitle: PROCEDURE
  194.   parse arg '"' infFile '"'
  195.  
  196.                         /* init the return code                       */
  197.   thisTitle = ''
  198.          
  199.                         /* read the header of the INF file            */
  200.   thisRC = stream( infFile, 'c', 'OPEN READ' )
  201.   if thisRC = 'READY:' then
  202.   do
  203.     infHeader = charIn( infFile, 1,500 )
  204.     thisRC = stream( infFile, 'c', 'CLOSE' )
  205.  
  206.                         /* search the title                           */
  207.     startPos = x2d( '6B' )
  208.  
  209.     do i = 1 to 100
  210.       curChar = substr( infHeader, startPos+i, 1 )
  211.       if curChar = '00'x then
  212.         leave
  213.       else
  214.        thisTitle = thisTitle || curChar
  215.     end /* do i=0 to 100 */
  216.   end /* if */
  217.  
  218. RETURN thisTitle 
  219.  
  220. /* ------------------------------------------------------------------ */
  221. /* Error handler (called if the DLL REXXUTIL is not found)            */
  222. /*                                                                    */
  223. RexxUtilNotFound:
  224.   say ''
  225.   say 'Error: REXXUTIL.DLL not found!'
  226. exit 255
  227.  
  228. /* ------------------------------------------------------------------ */
  229. /* Error handler (called if the user presses CTRL-BREAK)              */
  230. /*                                                                    */
  231. UserAbort:
  232.   say ''
  233.   say ' Installation aborted by the user.'
  234. exit 254
  235.