home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / NJBRIDGE / NSJAVA.CMD < prev    next >
OS/2 REXX Batch file  |  1997-09-02  |  5KB  |  158 lines

  1. /*
  2.  * nsjava.cmd - Select the JVM for Netscape Navigator 2.02
  3.  * Arguments:
  4.  *      <none> or java11        Activates java11
  5.  *      java102                 Activates java102
  6.  *
  7.  * Works by modifying LIBPATH and CLASSPATH in CONFIG.SYS.
  8.  * You must reboot after running.
  9.  *
  10.  * Warning: contains untranslated English usage and error messages.
  11.  *
  12.  * Implementation:
  13.  *
  14.  * To switch from java102 to java11:
  15.  * 1. Backup config.sys
  16.  * 2. Add x:\netscape\java11 to beginning of LIBPATH and CLASSPATH
  17.  *
  18.  * To switch from java11 to java102:
  19.  * 1. Backup config.sys
  20.  * 2. Remove x:\netscape\java11 from LIBPATH and CLASSPATH
  21.  */
  22.  
  23. Call RxFuncAdd 'SysSearchPath', 'RexxUtil', 'SysSearchPath'
  24. /* Set debug to 1 for debug print lines */
  25. debug = 0
  26. tmpcfg = '.\cf_tempx.f00'
  27. jemzip = '\JEMPCL10.ZIP'
  28. ziplen = Length(jemzip)
  29.  
  30. /* Get parameters */
  31. Arg whichjava
  32. If whichjava = '' Then whichjava = 'JAVA11'
  33. If debug Then Say 'whichjava =' whichjava
  34. If whichjava <> '' & whichjava <> 'JAVA11' & whichjava <> 'JAVA102' Then Do
  35.     Say 'Usage: nsjava [java11 | java102]'
  36.     Exit 0
  37. End
  38.  
  39. /* Find CONFIG.SYS */
  40. '@bootdrv | rxqueue'
  41. Parse Pull bootDrive
  42. dspec = bootDrive':'
  43. cfgsys = dspec'\CONFIG.SYS'
  44. cfgbase = dspec'\CONFIG'
  45. If debug Then Say 'cfgsys =' cfgsys
  46. If Stream(cfgsys, 'Command', 'Query Exists') = '' Then Do
  47.         Say 'Could not find CONFIG.SYS'
  48.         Exit 1
  49. End
  50.  
  51. /* Find NETSCAPE install directory */
  52. fspec = SysSearchPath('PATH', 'NETSCAPE.EXE')
  53. If debug Then Say 'netscape.exe =' fspec
  54. If fspec = '' Then Do
  55.         Say 'Could not find NETSCAPE install directory'
  56.         Exit 1
  57. End
  58. nsdir = FileSpec("drive", fspec) || FileSpec("path", fspec) || 'JAVA11'
  59. nsdir = Translate(nsdir)
  60. If debug Then Say 'nsdir =' nsdir
  61. dirlen = Length(nsdir)
  62.  
  63. /* Delete temp file if it exists */
  64. '@del' tmpcfg '> NUL: 2>&1'
  65.  
  66. /* Add or remove netscape java11 dir from LIBPATH and CLASSPATH */
  67. updated = 0
  68. Do While Lines(cfgsys)
  69.         line = LineIn(cfgsys)
  70.         capline = Translate(line)
  71.         libpathpos = Pos("LIBPATH", capline)
  72.         classpathpos = Pos("SET CLASSPATH", capline)
  73.  
  74.         /* Assumes commands appear at char 1 */
  75.         /* Won't update REM'ed out commands */
  76.  
  77.         If libpathpos = 1 | classpathpos = 1 Then Do
  78.                 If debug Then Say 'Found path:' SubStr(capline, 1, 20)'...'
  79.                 dirpos = Pos(nsdir, capline)
  80.                 startpos = Pos("=", capline) + 1
  81.  
  82.                 /* Add netscape dir to paths */
  83.                 If whichjava = 'JAVA11' & dirpos = 0 Then Do
  84.                         tmpline = SubStr(line, 1, startpos-1) || nsdir
  85.                         If classpathpos = 1 Then tmpline = tmpline || jemzip
  86.                         line = tmpline';'SubStr(line, startpos)
  87.                         updated = 1
  88.                         If debug Then Say line
  89.                 End
  90.                 /* Or remove netscape dir from paths */
  91.                 Else If whichjava = 'JAVA102' & dirpos <> 0 Then Do
  92.                         tmpline = SubStr(line, 1, dirpos-1)
  93.                         extralen = 0
  94.                         If classpathpos = 1 Then extralen = ziplen
  95.                         /* Skip over the nsdir string by adding nsdir length,
  96.                            plus zipfile len if this is classpath, plus
  97.                            one for the semicolon */
  98.                         rest = dirpos + dirlen + extralen + 1
  99.                         line = tmpline || SubStr(line, rest)
  100.                         updated = 1
  101.                         If debug Then Say line
  102.                 End
  103.         End
  104.  
  105.         Call LineOut tmpcfg, line
  106. End
  107.  
  108. Call Stream cfgsys, 'Command', 'Close'
  109. Call Stream tmpcfg, 'Command', 'Close'
  110.  
  111. If debug Then Say 'Updated =' updated
  112.  
  113. /*
  114.  * Make a copy of this system's config.sys, in a similar manner to Software Installer
  115.  * (i.e., config.xxx, where xxx is 000, 001, etc.)
  116.  */
  117. If updated Then Do
  118.         i = 0
  119.         Do Forever
  120.                 cfgbak = cfgbase'.'nto3ascii(i)
  121.                 If debug Then Say 'Query Exists:' cfgbak
  122.                 /* Exit loop when we find an unused extension */
  123.                 If Stream(cfgbak, 'Command', 'Query Exists') = '' | i = 999 Then
  124.                         Leave
  125.                 i = i + 1;
  126.         End
  127.  
  128.         /* Copy current config to a backup, temp config to current config, and delete temp config */
  129.         If debug Then Do
  130.                 'copy' cfgsys cfgbak
  131.                 'copy' tmpcfg cfgsys
  132.         End
  133.         Else Do
  134.                 '@copy' cfgsys cfgbak '> NUL: 2>&1'
  135.                 '@copy' tmpcfg cfgsys '> NUL: 2>&1'
  136.         End
  137. End
  138.  
  139. If debug Then
  140.         'del' tmpcfg
  141. Else
  142.         '@del' tmpcfg '> NUL: 2>&1'
  143.  
  144. Exit 0
  145.  
  146. /* Convert the decimal value i to a 3 character string with leading (ASCII) '0's */
  147. nto3ascii: Procedure Expose i
  148.   test1 = Trunc(i//10)
  149.   test100 = Trunc(i/100)
  150.   test10 = Trunc((i-(test100*100)-test1)/10)
  151.   strnum100 = d2c(test100+48)
  152.   strnum10 = d2c(test10+48)
  153.   strnum1 = d2c(test1+48)
  154.   strnum = strnum100||strnum10||strnum1
  155.   strnum = SubStr(strnum, 1, 3);
  156. Return strnum
  157.  
  158.